/* Tokens: chart chrome and ink from the dataviz reference palette; map marks live in js/colors.js. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.05);
  --bar: #52514e;
  --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 20px rgba(0, 0, 0, 0.08);
  --cls-G: #5598e7; --cls-F: #256abf; --cls-P: #0d366b; --cls-U: #a3a29c;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a998f;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.06);
    --bar: #c3c2b7; --focus: #3987e5; --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
    --cls-G: #2a78d6; --cls-F: #6da7ec; --cls-P: #b7d3f6; --cls-U: #5f5e5a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a998f;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10); --wash: rgba(255, 255, 255, 0.06);
  --bar: #c3c2b7; --focus: #3987e5; --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  --cls-G: #2a78d6; --cls-F: #6da7ec; --cls-P: #b7d3f6; --cls-U: #5f5e5a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: grid; grid-template-rows: auto 1fr; background: var(--page); color: var(--ink);
  font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-size: 12px; }

/* ------------------------------------------------------------ top bar */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 5;
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; }
.seg-label { font-size: 12px; color: var(--muted); padding: 0 6px 0 8px; }
.seg button, .ghost {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.seg button:hover, .ghost:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.ghost { border: 1px solid var(--border); }
select, input[type="search"] {
  height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
input[type="search"] { width: 170px; }
.search { position: relative; }
#search-results {
  position: absolute; right: 0; top: 36px; min-width: 240px; max-height: 320px; overflow: auto; margin: 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 20;
}
#search-results li { padding: 2px; }
#search-results li.muted { padding: 8px; font-size: 12px; }
#search-results button { width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
#search-results button:hover { background: var(--wash); }

/* ------------------------------------------------------------ map area */
main { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.map-foot { position: absolute; left: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100% - 24px)); z-index: 3; }
#legend { padding: 10px 12px; }
.legend-title { margin: 0 0 6px; font-size: 12px; font-weight: 600; }
#legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
#legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
#legend li i, .legend-inline i { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px var(--surface); }
.legend-note { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
#freshness { --df-bg: var(--surface); --df-border: var(--border); --df-text: var(--ink-2); box-shadow: var(--shadow); }
#load-status { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); margin: 0; font-size: 12px; color: var(--ink-2);
  background: var(--surface); border-radius: 999px; padding: 0 10px; z-index: 3; }
#load-status:empty { display: none; }
#hover-tip {
  position: absolute; left: 0; top: 0; pointer-events: none; z-index: 6; display: grid; gap: 1px; max-width: 260px;
  padding: 8px 10px; font-size: 12px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow);
}
#hover-tip b { color: var(--ink); font-weight: 600; }
#error { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 30; padding: 8px 14px; border-radius: 8px;
  background: #d03b3b; color: #fff; font-size: 13px; max-width: 80%; }
.maplibregl-ctrl-group { background: var(--surface) !important; }
:root[data-theme="dark"] .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ------------------------------------------------------------ bridge panel */
#panel {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 392px; overflow-y: auto; z-index: 4; padding: 0 0 8px;
}
.p-head { position: relative; padding: 16px 44px 12px 16px; border-bottom: 1px solid var(--border); }
.p-head h2 { margin: 2px 0 2px; font-size: 17px; font-weight: 650; line-height: 1.25; }
.eyebrow { margin: 0; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.p-place { margin: 0; color: var(--ink-2); }
.p-note { margin: 6px 0 0; font-size: 11px; color: var(--muted); }
.p-close { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border: 0; border-radius: 6px;
  background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-2); }
.p-close:hover { background: var(--wash); }
.panel-loading { padding: 16px; color: var(--muted); }
.p-sec { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.p-sec h3 { margin: 0 0 8px; font-size: 13px; font-weight: 650; }
.p-sec h4 { margin: 12px 0 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.p-sec p { margin: 6px 0 0; }
.p-foot { padding: 10px 16px 4px; }
.cond-line { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-weight: 600; font-size: 13px; }
.chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--cls-U); }
.chip[data-cls="G"] i { background: var(--cls-G); }
.chip[data-cls="F"] i { background: var(--cls-F); }
.chip[data-cls="P"] i { background: var(--cls-P); }
table { border-collapse: collapse; width: 100%; }
.ratings th, .ratings td, .inputs th, .inputs td { padding: 3px 0; border-bottom: 1px solid var(--grid); text-align: left; font-weight: 400; vertical-align: top; }
.ratings th, .inputs th { color: var(--ink-2); width: 42%; }
.ratings td.num { width: 28px; padding-right: 10px; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.inputs td { padding-right: 8px; }
.inputs td.dir { color: var(--muted); width: 56px; padding-right: 0; text-align: right; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { display: grid; gap: 1px; text-align: left; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer; }
.stat:hover { background: var(--wash); }
.stat.is-on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.stat-label { font-size: 12px; color: var(--ink-2); }
.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -0.01em; }
.stat-sub { font-size: 11px; color: var(--muted); }
.drivers { display: grid; gap: 4px; }
.drv-axis { display: grid; grid-template-columns: 132px 1fr 72px; font-size: 11px; color: var(--muted); }
.drv-axis span:first-child { grid-column: 2; }
.drv-axis { position: relative; }
.drv-axis span { grid-row: 1; }
.drv-axis span:last-child { grid-column: 2; text-align: right; }
.drv { display: grid; grid-template-columns: 132px 1fr 72px; align-items: center; gap: 0; font-size: 12px; min-height: 20px; }
.drv-label { color: var(--ink-2); padding-right: 8px; line-height: 1.2; }
.drv-dir { color: var(--muted); text-align: right; font-size: 11px; }
.drv-track { position: relative; height: 12px; }
.drv-track::before { content: ""; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1px; background: var(--axis); }
.drv-bar { position: absolute; top: 1px; height: 10px; background: var(--bar); }
.drv-bar.up { left: calc(50% + 1px); border-radius: 0 4px 4px 0; }
.drv-bar.down { right: calc(50% + 1px); border-radius: 4px 0 0 4px; }
.legend-inline { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--ink-2); }
.legend-inline li { display: flex; align-items: center; gap: 6px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .mark { stroke: var(--axis); stroke-width: 1; }
.chart .mark-label { fill: var(--muted); font-size: 9px; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .tip { position: absolute; top: 0; display: grid; gap: 1px; padding: 6px 8px; font-size: 11px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow); pointer-events: none; min-width: 110px; }
.chart .tip b { color: var(--ink); }
.facts { display: grid; grid-template-columns: 112px 1fr; gap: 4px 10px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ------------------------------------------------------------ about */
#about { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 40; display: grid; place-items: center; padding: 16px; }
.about-card { position: relative; width: min(680px, 100%); max-height: 90vh; overflow: auto; padding: 20px 24px; }
.about-card h2 { margin: 0 0 8px; font-size: 18px; }
.about-card h3 { margin: 16px 0 6px; font-size: 14px; }
.about-card ul { padding-left: 18px; margin: 6px 0; }
.table-wrap { overflow-x: auto; }
.metrics th, .metrics td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; font-size: 12px; }
.metrics th { color: var(--muted); font-weight: 500; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  .top { padding: 8px 10px; gap: 6px; }
  .brand p, .seg-label { display: none; }
  .brand h1 { font-size: 15px; }
  .controls { gap: 6px; font-size: 13px; }
  .seg button, .ghost { padding: 4px 8px; }
  select, input[type="search"] { height: 30px; }
  #state-select { max-width: 150px; }
  input[type="search"] { width: 120px; }
  #panel { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62%; }
  body.has-panel .map-foot { display: none; }
  .drv, .drv-axis { grid-template-columns: 110px 1fr 64px; }
}
