/* Song Ngữ admin dashboard. Chrome uses the app's teal; data marks use the validated chart palette
   (blue slot 1, one-hue blue ramps). Dark mode is its own set of steps, not an automatic flip. */
:root {
  color-scheme: light;
  --page: #f6f7f6;
  --surface: #ffffff;
  --surface-2: #f3f4f2;
  --surface-3: #e9ebe8;
  --ink: #101413;
  --ink-2: #4c5553;
  --muted: #7b8482;
  --line: #e2e5e2;
  --line-strong: #cdd2ce;
  --grid: #e8eae6;
  --axis: #c3c7c2;
  --accent: #007f74;
  --accent-ink: #00665d;
  --accent-wash: #e3f4f1;
  --on-accent: #ffffff;
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.10);
  --deemph: #b9bfbb;
  --good-ink: #006300;
  --bad-ink: #b42323;
  --critical: #d03b3b;
  --warning: #fab219;
  --tooltip-bg: #101413;
  --tooltip-ink: #ffffff;
  --shadow: 0 1px 2px rgba(16, 20, 19, 0.05), 0 8px 24px rgba(16, 20, 19, 0.05);
  --ramp-0: #f0f1ee;
  --ramp-1: #cde2fb; --ramp-2: #9ec5f4; --ramp-3: #6da7ec; --ramp-4: #3987e5; --ramp-5: #256abf; --ramp-6: #184f95; --ramp-7: #0d366b;
  --ord-1: #104281; --ord-2: #1c5cab; --ord-3: #2a78d6; --ord-4: #5598e7; --ord-5: #86b6ef;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --line: #2c2c2a; --line-strong: #383835; --grid: #2c2c2a; --axis: #383835;
    --accent: #3fb9ab; --accent-ink: #6fd3c6; --accent-wash: #12302d; --on-accent: #06201d;
    --series-1: #3987e5; --series-1-wash: rgba(57, 135, 229, 0.14); --deemph: #55554f;
    --good-ink: #0ca30c; --bad-ink: #ff8a80; --tooltip-bg: #f0efec; --tooltip-ink: #0d0d0d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --ramp-0: #232321;
    --ramp-1: #0d366b; --ramp-2: #104281; --ramp-3: #184f95; --ramp-4: #256abf; --ramp-5: #3987e5; --ramp-6: #6da7ec; --ramp-7: #b7d3f6;
    --ord-1: #b7d3f6; --ord-2: #86b6ef; --ord-3: #5598e7; --ord-4: #2a78d6; --ord-5: #1c5cab;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --surface-3: #2c2c2a;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781; --line: #2c2c2a; --line-strong: #383835; --grid: #2c2c2a; --axis: #383835;
  --accent: #3fb9ab; --accent-ink: #6fd3c6; --accent-wash: #12302d; --on-accent: #06201d;
  --series-1: #3987e5; --series-1-wash: rgba(57, 135, 229, 0.14); --deemph: #55554f;
  --good-ink: #0ca30c; --bad-ink: #ff8a80; --tooltip-bg: #f0efec; --tooltip-ink: #0d0d0d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ramp-0: #232321;
  --ramp-1: #0d366b; --ramp-2: #104281; --ramp-3: #184f95; --ramp-4: #256abf; --ramp-5: #3987e5; --ramp-6: #6da7ec; --ramp-7: #b7d3f6;
  --ord-1: #b7d3f6; --ord-2: #86b6ef; --ord-3: #5598e7; --ord-4: #2a78d6; --ord-5: #1c5cab;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- sign-in / full-page states ---------- */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card { width: min(420px, 100%); padding: 36px 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); text-align: center; }
.gate-card img { width: 64px; height: 64px; border-radius: 16px; }
.gate-card h1 { margin: 18px 0 6px; font-size: 22px; letter-spacing: -0.01em; }
.gate-card p { margin: 0 0 22px; color: var(--ink-2); }
.gate-error { margin-top: 16px !important; color: var(--bad-ink) !important; }
.google-button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 46px; padding: 0 18px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); font-weight: 600; cursor: pointer; }
.google-button:hover { background: var(--surface-2); }
.google-button svg { width: 18px; height: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; text-decoration: none; color: inherit; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand strong { display: block; font-size: 14px; line-height: 1.2; }
.brand span { display: block; color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me img, .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-3); }
.me div { min-width: 0; }
.me div > strong, .me div > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me div > span { color: var(--muted); font-size: 12px; }
.foot-actions { display: flex; gap: 6px; }
.ghost { flex: 1; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 13px; }
.ghost:hover { background: var(--surface-2); color: var(--ink); }

.main { min-width: 0; padding: 22px 28px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: -0.015em; }
.topbar p { margin: 2px 0 0; color: var(--muted); }
.freshness { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--ink); font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; }
.button:hover { background: var(--surface-2); }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.button.primary:hover { filter: brightness(1.06); }
.button:disabled { opacity: 0.55; cursor: progress; }
.loading-content { opacity: 0.45; pointer-events: none; transition: opacity 0.2s; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.segmented button { min-height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 13px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.select, .search { min-height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.select { padding-right: 30px; }
.search { min-width: min(320px, 100%); }
.filter-label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding: 14px 16px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.tile-meta { color: var(--muted); font-size: 12px; min-height: 18px; }
.delta-up { color: var(--good-ink); font-weight: 600; }
.delta-down { color: var(--bad-ink); font-weight: 600; }
.tile svg { display: block; width: 100%; height: 28px; margin-top: 4px; }

/* ---------- cards & charts ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.card { min-width: 0; padding: 16px 18px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; letter-spacing: -0.005em; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.toggle-table { flex: none; min-height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--ink-2); font-size: 12px; cursor: pointer; }
.toggle-table:hover { background: var(--surface-2); }
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart:focus-visible { outline-offset: 4px; border-radius: 6px; }
.axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.bar { fill: var(--series-1); }
.bar.dim { fill: var(--deemph); }
.bar.active { fill: var(--accent-ink); }
.line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area { fill: var(--series-1-wash); }
.dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.crosshair { stroke: var(--ink-2); stroke-width: 1; opacity: 0.5; shape-rendering: crispEdges; }
.end-label { fill: var(--ink); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty { display: grid; place-items: center; min-height: 160px; padding: 20px; color: var(--muted); text-align: center; }
.note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.bars { display: flex; flex-direction: column; gap: 9px; }
.bars-row { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr); align-items: center; gap: 12px; border-radius: 6px; }
.bars-row:hover .bars-fill, .bars-row:focus-visible .bars-fill { filter: brightness(1.12); }
.bars-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.bars-label small { display: block; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 11.5px; }
.bars-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bars-fill { height: 14px; min-width: 2px; border-radius: 0 4px 4px 0; background: var(--series-1); }
.bars-value { flex: none; color: var(--ink-2); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.heat-legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 11.5px; }
.heat-legend span.swatches { display: inline-flex; gap: 2px; }
.heat-legend i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { position: sticky; top: 0; z-index: 1; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--line-strong); color: var(--ink-2); font-weight: 600; text-align: left; white-space: nowrap; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }

#tooltip { position: fixed; z-index: 50; pointer-events: none; padding: 8px 10px; border-radius: 8px; background: var(--tooltip-bg); color: var(--tooltip-ink); font-size: 12px; line-height: 1.35; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); max-width: 260px; }
#tooltip strong { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
#tooltip span { opacity: 0.8; }
#tooltip .key { display: inline-block; width: 12px; height: 2px; margin-right: 6px; vertical-align: middle; background: var(--series-1); }

/* ---------- users table ---------- */
.users-card { padding: 0; overflow: hidden; }
.users-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.users-toolbar .grow { flex: 1; }
.users-scroll { overflow-x: auto; }
.users-table { width: 100%; min-width: 1080px; border-collapse: collapse; font-size: 13px; }
.users-table th { padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); color: var(--ink-2); font-weight: 600; text-align: left; white-space: nowrap; }
.users-table th button { padding: 0; border: 0; background: none; font-weight: 600; color: inherit; cursor: pointer; }
.users-table th button[aria-sort]::after { content: ""; margin-left: 4px; }
.users-table th[aria-sort="descending"] button::after { content: "↓"; margin-left: 4px; }
.users-table th[aria-sort="ascending"] button::after { content: "↑"; margin-left: 4px; }
.users-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.users-table td.num, .users-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.users-table tbody tr { cursor: pointer; }
.users-table tbody tr:hover { background: var(--surface-2); }
.person { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 320px; }
.person div { min-width: 0; }
.person div > strong, .person div > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person div > span { color: var(--muted); font-size: 12px; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 11.5px; white-space: nowrap; }
.chip.warn { border-color: transparent; background: #fdecea; color: #a12a2a; }
.chip.ok { border-color: transparent; background: var(--accent-wash); color: var(--accent-ink); }
:root[data-theme="dark"] .chip.warn { background: #3a1c1b; color: #ffb4ab; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .chip.warn { background: #3a1c1b; color: #ffb4ab; } }
.muted { color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; color: var(--muted); }
.pager div { display: flex; gap: 6px; }

/* ---------- user page ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.back:hover { color: var(--ink); }
.profile { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 18px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.profile .avatar { width: 64px; height: 64px; }
.profile h1 { margin: 0; font-size: 22px; letter-spacing: -0.015em; }
.profile .ids { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 4px; color: var(--ink-2); }
.profile code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font-size: 12px; }
.copy { padding: 0 8px; min-height: 24px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink-2); font-size: 12px; cursor: pointer; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.facts div { margin: 0 -1px -1px 0; padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 550; overflow-wrap: break-word; word-break: break-word; }
.grid.top { align-items: start; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 18px 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { position: relative; padding: 9px 12px; border: 0; background: none; color: var(--ink-2); font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tabs .count { margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 11.5px; }
.privacy-note { display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); color: var(--ink-2); font-size: 13px; }
.raw { max-height: 520px; overflow: auto; padding: 14px; border-radius: 12px; background: var(--surface-2); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- community ---------- */
.feed { display: flex; flex-direction: column; }
.feed-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; }
.feed-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; color: var(--muted); font-size: 12.5px; }
.feed-meta a, .feed-meta strong { color: var(--ink); font-weight: 600; text-decoration: none; }
.feed-meta a:hover { text-decoration: underline; }
.feed-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.letter { display: grid; flex: none; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--surface-3); color: var(--ink-2); font-weight: 650; line-height: 1; }
details.contribution { padding: 14px 0; border-bottom: 1px solid var(--line); }
details.contribution summary { cursor: pointer; font-weight: 600; }
details.contribution p { white-space: pre-wrap; color: var(--ink-2); }

@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .brand span { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .nav a { padding: 7px 10px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
  .me div { display: none; }
  .main { padding: 16px 16px 40px; }
  .grid, .grid.three { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar { flex-direction: column; }
}
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tile-value { font-size: 22px; } .search { min-width: 0; width: 100%; } .segmented { overflow-x: auto; max-width: 100%; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
