:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e1e6ef;
  --text: #121826;
  --text-2: #4b5563;
  --muted: #6b7280;
  --brand: #1e3a7b;
  --brand-2: #29abe2;
  --link: #1f5fbf;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b; --neutral: #9ca3af;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #1c5cab; --seq-6: #0d366b;
  --grid: #e8ebf1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111317; --surface: #1a1a19; --surface-2: #232427; --border: #34363b;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a9a94; --brand: #8fb4ff; --brand-2: #3fb7ea; --link: #8ab4ff;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --grid: #2c2e33; --shadow: none;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111317; --surface: #1a1a19; --surface-2: #232427; --border: #34363b;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a9a94; --brand: #8fb4ff; --brand-2: #3fb7ea; --link: #8ab4ff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --grid: #2c2e33; --shadow: none;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

header.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { display: flex; align-items: center; gap: 18px; padding: 10px 20px; max-width: 1500px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.brand img { height: 22px; }
.brand span { font-weight: 600; color: var(--text-2); border-left: 1px solid var(--border); padding-left: 12px; }
nav.tabs { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
nav.tabs a { padding: 8px 9px; border-radius: 8px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
nav.tabs a.active { background: var(--surface-2); color: var(--text); }
nav.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 10px; background: var(--critical); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px; }
.userbox { color: var(--muted); font-size: 12px; white-space: nowrap; }

main { max-width: 1500px; margin: 0 auto; padding: 16px 20px 60px; }
.banner { border: 1px solid var(--border); background: var(--surface); border-left: 4px solid var(--warning); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: 13px; color: var(--text-2); }
.banner.demo { border-left-color: var(--critical); font-weight: 600; color: var(--text); }
.banner.info { border-left-color: var(--s1); }
h1 { font-size: 20px; margin: 4px 0 2px; }
h2 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 10px 0 14px; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.filters select, .filters input { min-width: 120px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); padding: 4px 9px; border-radius: 14px; cursor: pointer; background: var(--surface); font-size: 12px; user-select: none; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
:root[data-theme="dark"] .chip.on { color: #111; }

.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.card .meta { color: var(--muted); font-size: 11.5px; margin-top: -4px; margin-bottom: 8px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.kpi b { font-size: 18px; display: block; }
.kpi span { font-size: 11px; color: var(--muted); }
.score { font-size: 34px; font-weight: 700; line-height: 1; }
.band { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text); }
.band i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.band.Strong i { background: var(--good); } .band.Healthy i { background: #7cb342; } .band.Watch i { background: var(--warning); }
.band.At.Risk i, .band.AtRisk i { background: var(--serious); } .band.Critical i { background: var(--critical); } .band.NA i { background: var(--neutral); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin-right: 3px; }
.tag.warn { border-color: var(--warning); }
.tag.bad { border-color: var(--critical); color: var(--text); }
.sev { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.sev::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--neutral); }
.sev.Critical::before { background: var(--critical); } .sev.High::before { background: var(--serious); } .sev.Medium::before { background: var(--warning); }
.delta.up { color: var(--good); } .delta.down { color: var(--critical); }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-tools { display: flex; gap: 6px; margin-left: auto; }
.btn { border: 1px solid var(--border); background: var(--surface); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
:root[data-theme="dark"] .btn.primary { color: #111; }
.btn.small { padding: 2px 7px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.empty { color: var(--muted); font-style: italic; padding: 16px; text-align: center; }

table.t { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.t th { text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); padding: 6px; position: sticky; top: 0; background: var(--surface); }
table.t td { border-bottom: 1px solid var(--grid); padding: 5px 6px; vertical-align: top; }
table.t tr:hover td { background: var(--surface-2); }
.scroll { max-height: 420px; overflow: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.heat td.cell { text-align: center; font-weight: 600; min-width: 62px; border: 2px solid var(--surface); border-radius: 4px; }
.heat td.na { color: var(--muted); font-weight: 400; background: var(--surface-2); }

.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 10px; flex-wrap: wrap; }
.subtabs button { border: 0; background: none; padding: 7px 10px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; }
.subtabs button.on { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }

.drawer { position: fixed; inset: 0 0 0 auto; width: min(980px, 100vw); background: var(--bg); border-left: 1px solid var(--border); z-index: 40; overflow: auto; padding: 18px 20px; box-shadow: -8px 0 24px rgba(0,0,0,.15); }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 39; }
.menu { position: relative; display: inline-block; }
.menu .pop { position: absolute; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 30; min-width: 220px; padding: 4px; }
.menu .pop a { display: block; padding: 6px 10px; border-radius: 6px; color: var(--text); }
.menu .pop a:hover { background: var(--surface-2); text-decoration: none; }

.review-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface); margin-bottom: 8px; }
.review-card .excerpt { color: var(--text-2); font-size: 12.5px; margin: 4px 0; border-left: 3px solid var(--border); padding-left: 8px; }
.review-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; align-items: center; }
.review-card select, .review-card input, .form input, .form select, .form textarea { padding: 4px 7px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.form { display: grid; grid-template-columns: 180px 1fr; gap: 6px 10px; align-items: center; }
.form textarea { min-height: 60px; width: 100%; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; z-index: 60; font-size: 13px; }
.legend-note { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.fresh { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.fresh .src { padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.fresh .src.ok::before { content: "●"; color: var(--good); margin-right: 4px; }
.fresh .src.imp::before { content: "●"; color: var(--warning); margin-right: 4px; }
.fresh .src.off::before { content: "○"; color: var(--muted); margin-right: 4px; }
.fresh .src.err::before { content: "▲"; color: var(--critical); margin-right: 4px; }

@media (max-width: 720px) {
  .top-inner { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  nav.tabs { order: 3; width: 100%; flex: none; }
  main { padding: 12px 16px 40px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .userbox { display: none; }
}

table.t td.nowrap { white-space: nowrap; }
table.t td a[href*="/browse/"] { white-space: nowrap; }
table.t th.num { text-align: right; }
.signout { font-size: 12px; margin-left: 8px; color: var(--muted); }
.signout:hover { color: var(--accent, #1e3a7b); }
.neg { color: var(--critical); }
