:root {
  color-scheme: light dark;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --muted: #52525b;
  --accent: #4f46e5;
  --accent-text: #4338ca;
  --accent-soft: #eef2ff;
  --hover: #f4f4f5;
  --grid: #e4e4e7;
  --danger: #b91c1c;
  --good: #15803d;
  --good-soft: #f0fdf4;
  --watch: #b45309;
  --watch-soft: #fffbeb;
  --side-bg: #0f172a;
  --side-text: #cbd5e1;
  --side-muted: #94a3b8;
  --side-active: #1e293b;
  --side-border: #1e293b;
  --radius: 6px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #18181b;
    --surface-2: #1f1f23;
    --border: #2e2e33;
    --border-strong: #3f3f46;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --accent: #818cf8;
    --accent-text: #a5b4fc;
    --accent-soft: #23234a;
    --hover: #222226;
    --grid: #2e2e33;
    --danger: #f87171;
    --good: #4ade80;
    --good-soft: #052e16;
    --watch: #fbbf24;
    --watch-soft: #2a1d05;
    --side-bg: #020617;
    --side-active: #1e293b;
    --side-border: #1e293b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; font-variant-numeric: tabular-nums; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
input, textarea, button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 24px; display: grid; gap: 16px;
}
.brand-inline { display: flex; align-items: center; gap: 10px; }
.brand-inline h1 { font-size: 1.15rem; }
.login-card form { display: grid; gap: 8px; }
.login-card label { font-size: .85rem; font-weight: 600; }
.login-card input {
  width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.code-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.primary-btn {
  padding: 8px 14px; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius);
  font-weight: 600; cursor: pointer;
}
.primary-btn:hover { background: var(--accent-text); }
.primary-btn:disabled { opacity: .6; cursor: default; }
.secondary-btn {
  padding: 6px 12px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); cursor: pointer;
}
.secondary-btn:hover { background: var(--hover); }
.link-btn {
  margin-top: 10px; background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; text-align: left;
}
.status-msg { margin: 8px 0 0; font-size: .85rem; color: var(--muted); min-height: 1.2em; }
.status-msg.error { color: var(--danger); font-weight: 600; }

/* App shell */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 14px 10px; gap: 16px;
}
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid var(--side-border); color: #fff; }
.brand h1 { font-size: 1rem; font-weight: 600; }
.brand-sub { color: var(--side-muted); font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; border-left: 2px solid transparent; border-radius: var(--radius);
  padding: 8px 10px; color: var(--side-text);
}
.nav button:hover { background: var(--side-active); color: #fff; }
.nav button[aria-current=page] { background: var(--side-active); color: #fff; border-left-color: #818cf8; font-weight: 600; }
.account { margin-top: auto; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--side-border); padding: 12px 4px 0; }
.account-email { font-size: .78rem; color: var(--side-muted); overflow-wrap: anywhere; }
.logout-btn {
  padding: 6px 10px; background: var(--side-active); color: #fff; border: 1px solid #334155;
  border-radius: var(--radius); cursor: pointer; text-align: center;
}
.logout-btn:hover { background: #334155; }

.content { min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.page-head h2 { font-size: 1.1rem; }
.status { margin: 0 0 0 auto; min-height: 1.4em; color: var(--muted); font-size: .85rem; }
.status.error { color: var(--danger); font-weight: 600; }
main { padding: 20px 24px 48px; max-width: 1120px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* Feedback */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px;
}
.toolbar input[type=search] {
  width: 280px; max-width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 6px 10px; background: var(--bg);
}
.filter-group { display: inline-flex; gap: 4px; }
.filter-group button {
  padding: 5px 10px; border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius); cursor: pointer; font-size: .85rem;
}
.filter-group button[aria-pressed=true] { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.toolbar .muted { margin-left: auto; }

.feedback-list { display: grid; gap: 12px; }
.feedback-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px;
}
.feedback-card.replied { border-left-color: var(--good); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .85rem; }
.meta { overflow-wrap: anywhere; }
.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; border-radius: 4px; padding: 2px 7px;
}
.badge.src { background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--border-strong); }
.badge.src.guest { background: transparent; color: var(--muted); }
.badge.replied-badge { margin-left: auto; background: var(--good-soft); color: var(--good); border: 1px solid var(--good); }
.feedback-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.replies-box {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; display: grid; gap: 8px;
}
.replies-box h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.reply-item { display: grid; gap: 4px; padding-top: 6px; border-top: 1px solid var(--border); }
.reply-item:first-of-type { padding-top: 0; border-top: 0; }
.reply-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: .85rem; }
.reply-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .9rem; }

.card-foot { display: flex; align-items: center; justify-content: flex-end; }
.reply-form { display: grid; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.reply-form label { font-size: .85rem; font-weight: 600; }
.reply-form input, .reply-form textarea {
  width: 100%; padding: 7px 9px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius);
}
.reply-form textarea { resize: vertical; }
.reply-form p { margin: 0; }
.reply-form .actions { display: flex; justify-content: flex-end; }
.foot-note { margin-top: 16px; }

/* Overview */
.group { margin-top: 24px; }
.group:first-child { margin-top: 0; }
.group h3 { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.tile .label { font-size: .78rem; color: var(--muted); }
.tile .value { font-size: 1.75rem; font-weight: 600; line-height: 1.15; margin-top: 2px; }
.tile .sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.tile .trend { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.tile .trend.up { color: var(--accent-text); }
.tile.attention { border-color: var(--watch); background: var(--watch-soft); }

.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 10px; }
.charts.wide { grid-template-columns: 1fr; margin-top: 10px; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.chart h4 { margin: 0; font-size: .85rem; font-weight: 600; }
.chart svg { width: 100%; height: auto; display: block; margin-top: 6px; overflow: visible; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; }
.chart .col:hover .hit { fill: var(--accent-soft); }
.chart .col:hover .bar { fill: var(--accent-text); }
.chart text { font-size: 9px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border-strong); stroke-width: 1; }
.chart .col { outline: none; }
.chart .tip { visibility: hidden; pointer-events: none; }
.chart .col:hover .tip, .chart .col:focus-visible .tip { visibility: visible; }
.chart .tip rect { fill: var(--text); }
.chart .tip text { fill: var(--surface); font-weight: 600; }
.chart .ghost { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 2; }
.chart .level { stroke: var(--watch); stroke-width: 1.2; stroke-dasharray: 4 3; }
.chart .legend { margin: 4px 0 0; font-size: .72rem; color: var(--muted); }

.assess { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.assess-item { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: var(--radius); padding: 10px 12px; }
.assess-item p { margin: 6px 0 0; font-size: .85rem; line-height: 1.5; }
.assess-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.assess-head .badge { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-strong); }
.assess-item.tone-good { border-left-color: var(--good); }
.assess-item.tone-good .badge { background: var(--good-soft); color: var(--good); border-color: var(--good); }
.assess-item.tone-watch { border-left-color: var(--watch); }
.assess-item.tone-watch .badge { background: var(--watch-soft); color: var(--watch); border-color: var(--watch); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px; }
  .brand { border-bottom: 0; padding: 0; }
  .nav { flex-direction: row; }
  .account { margin-top: 0; margin-left: auto; border-top: 0; padding: 0; flex-direction: row; align-items: center; }
  main { padding: 16px 14px 36px; }
  .page-head { padding: 12px 14px; }
  .charts { grid-template-columns: 1fr; }
}
