:root {
  color-scheme: light;
  --page: #f4f5f2;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.08);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.05);

  --brand: #0b1b2b;
  --brand-ink: #ffffff;
  --brand-ink-2: #b9c6d4;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --link: #1c5cab;
  --series: #2a78d6;
  --series-dim: #c9c8c1;

  --good: #0ca30c;
  --good-ink: #006300;
  --good-wash: rgba(12, 163, 12, 0.11);
  --warn: #fab219;
  --warn-ink: #7a4f00;
  --warn-wash: rgba(250, 178, 25, 0.2);
  --bad: #d03b3b;
  --bad-ink: #a12424;
  --bad-wash: rgba(208, 59, 59, 0.11);
  --violet: #6250d6;
  --violet-wash: rgba(98, 80, 214, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9d9b94;
    --hairline: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.08);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --brand: #101e2c;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --link: #86b6ef;
    --series: #3987e5;
    --series-dim: #45443f;
    --good-ink: #2fc22f;
    --good-wash: rgba(12, 163, 12, 0.18);
    --warn-ink: #fab219;
    --warn-wash: rgba(250, 178, 25, 0.16);
    --bad-ink: #f07a7a;
    --bad-wash: rgba(208, 59, 59, 0.2);
    --violet: #9085e9;
    --violet-wash: rgba(144, 133, 233, 0.18);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9d9b94;
  --hairline: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --brand: #101e2c;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --link: #86b6ef;
  --series: #3987e5;
  --series-dim: #45443f;
  --good-ink: #2fc22f;
  --good-wash: rgba(12, 163, 12, 0.18);
  --warn-ink: #fab219;
  --warn-wash: rgba(250, 178, 25, 0.16);
  --bad-ink: #f07a7a;
  --bad-wash: rgba(208, 59, 59, 0.2);
  --violet: #9085e9;
  --violet-wash: rgba(144, 133, 233, 0.18);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 120px; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
a { color: var(--link); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); margin: 0; }
.small { font-size: 12px; }
.src { color: var(--muted); font-size: 12px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 14px 24px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { display: grid; grid-template-columns: repeat(2, 10px); gap: 3px; }
.brand-mark i { width: 10px; height: 10px; border-radius: 2px; background: #3987e5; }
.brand-mark i:nth-child(2) { background: #6da7ec; }
.brand-mark i:nth-child(3) { background: #9ec5f4; }
.brand-mark i:nth-child(4) { background: #eda100; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: 0.01em; }
.brand-sub { font-size: 12px; color: var(--brand-ink-2); }
.topbar-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; min-height: 32px; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); font-size: 13px; font-weight: 600; }
.pill-quiet { background: transparent; border: 1px solid rgba(255, 255, 255, 0.18); font-weight: 500; color: var(--brand-ink-2); }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.18); background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }
.section-nav { max-width: 1320px; margin: 0 auto; padding: 0 16px 8px; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.section-nav a { color: var(--brand-ink-2); text-decoration: none; font-size: 13px; font-weight: 500; padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.section-nav a:hover, .section-nav a.active { color: var(--brand-ink); background: rgba(255, 255, 255, 0.1); }

/* Layout */
.page { max-width: 1320px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 40px; }
.section { display: flex; flex-direction: column; gap: 16px; }
.section-head { display: flex; flex-direction: column; gap: 4px; }
.section-head h2 { font-size: 22px; font-weight: 700; }
.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--ring); padding: 20px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.eyebrow { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.chart-title { font-size: 14px; font-weight: 600; margin: 4px 0 8px; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

/* Overview */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: stretch; }
.hero-card { display: flex; flex-direction: column; gap: 12px; }
.hero-row { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; padding-bottom: 8px; border-bottom: 1px solid var(--hairline); }
.hero-figure { font-size: 72px; font-weight: 700; line-height: 0.9; letter-spacing: -0.03em; }
.hero-side { display: flex; flex-direction: column; gap: 4px; padding-bottom: 6px; }
.hero-rank { font-weight: 600; font-size: 15px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tiles-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.tile { background: var(--surface); border-radius: 14px; border: 1px solid var(--ring); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tile-label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.tile-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.tile-note { font-size: 13px; color: var(--ink-2); }
.tile-src { font-size: 11px; color: var(--muted); margin-top: auto; padding-top: 6px; }
.tile-meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.tile-meter > span { display: block; height: 100%; border-radius: 999px; }

/* Status */
.status { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px 3px 8px; white-space: nowrap; }
.status svg { flex: none; }
.status.good { background: var(--good-wash); color: var(--good-ink); }
.status.warn { background: var(--warn-wash); color: var(--warn-ink); }
.status.bad { background: var(--bad-wash); color: var(--bad-ink); }
.delta { font-size: 13px; font-weight: 600; }
.delta.good { color: var(--good-ink); }
.delta.bad { color: var(--bad-ink); }

/* Flags */
.legend-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.chip-safety { background: var(--brand); color: #fff; }
.chip-turned { background: var(--bad-wash); color: var(--bad-ink); }
.chip-stuck { background: var(--bad); color: #fff; }
.chip-heading { background: var(--warn-wash); color: var(--warn-ink); }
:root[data-theme="dark"] .chip-safety { background: #f0efec; color: #0b0b0b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip-safety { background: #f0efec; color: #0b0b0b; } }
.flag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 12px; }
.flag { text-align: left; background: var(--surface); border: 1px solid var(--ring); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.flag:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgba(11, 11, 11, 0.06), 0 12px 28px rgba(11, 11, 11, 0.08); }
.flag-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.flag-loc { font-weight: 700; font-size: 16px; }
.flag-ind { font-size: 13px; color: var(--ink-2); }
.flag-body { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.flag-now { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.flag-goal { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.flag-impact { font-size: 13px; color: var(--ink-2); border-top: 1px solid var(--hairline); padding-top: 10px; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--hairline); white-space: nowrap; vertical-align: bottom; background: var(--surface); }
th .th-sub { display: block; font-weight: 400; color: var(--muted); font-size: 11px; margin-top: 2px; }
td { font-size: 14px; padding: 10px 14px; border-bottom: 1px solid var(--hairline); white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.row-btn { border: 0; background: transparent; padding: 6px 0; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left; display: inline-flex; gap: 6px; align-items: center; min-height: 36px; }
.row-btn:hover { color: var(--link); }
.row-btn svg { color: var(--muted); }
tbody tr:hover td { background: var(--surface-2); }
.cell { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; font-weight: 600; min-width: 84px; }
.cell.good { background: var(--good-wash); }
.cell.warn { background: var(--warn-wash); }
.cell.bad { background: var(--bad-wash); }
.cell.good svg { color: var(--good-ink); }
.cell.warn svg { color: var(--warn-ink); }
.cell.bad svg { color: var(--bad-ink); }
.score-badge { display: inline-grid; place-items: center; min-width: 44px; height: 32px; border-radius: 8px; font-weight: 700; color: #fff; padding: 0 8px; }
.inline-bar { display: flex; align-items: center; gap: 10px; min-width: 140px; }
.inline-bar .track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 999px; position: relative; min-width: 70px; }
.inline-bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--series); }
.inline-bar .goal { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); border-radius: 1px; }
.inline-bar .val { min-width: 48px; text-align: right; font-weight: 600; }
.ph { color: var(--muted); font-style: italic; }

/* Small multiples */
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 12px; }
.mini { background: var(--surface); border-radius: 14px; border: 1px solid var(--ring); box-shadow: var(--shadow); padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 4px; }
.mini-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mini-name { font-weight: 600; font-size: 14px; }
.mini-val { font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.mini-sub { font-size: 12px; color: var(--ink-2); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Table view toggles */
.table-view { font-size: 13px; }
.table-view summary { cursor: pointer; color: var(--link); font-weight: 600; padding: 6px 0; width: max-content; min-height: 32px; }
.table-view table { margin-top: 8px; background: var(--surface); border-radius: 10px; overflow: hidden; }

.callout { margin: 0; background: var(--surface); border: 1px solid var(--ring); border-left: 4px solid var(--bad); border-radius: 12px; padding: 14px 16px; font-size: 14px; }

/* Gaps */
.gap-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 10px; }
.gap { background: var(--surface); border: 1px dashed var(--axis); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.gap-area { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.gap-metric { font-weight: 600; font-size: 14px; }
.gap-need { font-size: 13px; color: var(--ink-2); }

.footer { max-width: 1320px; margin: 0 auto; padding: 8px 24px 40px; color: var(--muted); font-size: 12px; }

/* Chart text */
.axis-text { fill: var(--muted); font-size: 11px; }
.label-text { fill: var(--ink); font-size: 12px; font-weight: 600; }
.label-sub { fill: var(--ink-2); font-size: 12px; }
.grid-line { stroke: var(--hairline); stroke-width: 1; }
.base-line { stroke: var(--axis); stroke-width: 1; }
.goal-line { stroke: var(--ink-2); stroke-width: 1.5; }
.hit { fill: transparent; cursor: pointer; }
.bar { transition: opacity 0.15s ease; }
.hover-dim .bar:not(.is-hover) { opacity: 0.55; }

/* Tooltip */
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--ring); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); border-radius: 10px; padding: 8px 12px; font-size: 13px; min-width: 120px; }
.tooltip .tt-title { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .tt-val { font-weight: 700; }
.tooltip .tt-name { color: var(--ink-2); }

/* Dialog */
dialog { border: 0; padding: 0; border-radius: 18px; width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 48px); background: var(--page); color: var(--ink); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35); }
dialog::backdrop { background: rgba(11, 27, 43, 0.55); backdrop-filter: blur(2px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; background: var(--brand); color: var(--brand-ink); }
.dialog-head .eyebrow { color: var(--brand-ink-2); }
.dialog-head h2 { font-size: 24px; }
#loc-body { padding: 20px 22px 24px; display: flex; flex-direction: column; gap: 16px; }
.loc-hero { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.loc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); gap: 12px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--hairline); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv b { font-weight: 700; }
.card h3 { font-size: 15px; margin-bottom: 6px; }

@media (max-width: 900px) {
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page { padding: 16px; gap: 32px; }
  .topbar-inner { padding: 12px 16px; }
  .hero-figure { font-size: 56px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile-value { font-size: 24px; }
  .pill-quiet { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .flag, .bar { transition: none; }
}

.total-row th, .total-row td { border-top: 2px solid var(--hairline); background: var(--surface-2); font-weight: 600; }

/* Live data chrome */
.select { min-height: 36px; border-radius: 999px; padding: 4px 30px 4px 14px; font: inherit; font-size: 13px; font-weight: 600; color: var(--brand-ink); background: rgba(255, 255, 255, 0.12) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center; border: 1px solid rgba(255, 255, 255, 0.18); appearance: none; cursor: pointer; }
.select option { color: #0b0b0b; }
.freshness { background: var(--surface); border-bottom: 1px solid var(--hairline); }
.fresh-inner { max-width: 1320px; margin: 0 auto; padding: 8px 24px; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.fresh-item { display: inline-flex; gap: 6px; align-items: center; }
.push { margin-left: auto; }
.state-card { background: var(--surface); border: 1px solid var(--ring); border-radius: 16px; padding: 40px 24px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.state-title { font-size: 20px; font-weight: 700; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 28px 0; text-align: center; }
.tag { font-size: 11px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border-radius: 6px; padding: 2px 6px; }
.good-callout { border-left-color: var(--good); }

.cell-empty { display: inline-block; min-width: 84px; padding: 5px 10px; color: var(--muted); }
