/* Behatokia — elections dashboard. Light theme only (v1).
   Tokens follow the dataviz reference palette (surfaces, ink, chrome). */
.viz-root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;           /* categorical slot 1 — non-party single series */
  --deemph: #9aa0a6;           /* state reference line, "others" */
  --nodata: #f0efec;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); }
body { font-family: var(--font); color: var(--text-primary); line-height: 1.45; }
.viz-root { max-width: 1240px; margin: 0 auto; padding-block: 0 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
/* every chart scales down to its card; nothing may push the page wider than the screen */
.viz-root svg { max-width: 100%; height: auto; }
.hero h1, .scope-title { overflow-wrap: anywhere; text-wrap: balance; }
a { color: inherit; }

/* masthead */
.masthead { display: flex; justify-content: space-between; align-items: center; padding: 18px 0 8px; }
.brand { font-weight: 700; text-decoration: none; letter-spacing: .01em; }
.brand span { color: var(--text-secondary); font-weight: 500; }
.lang { display: flex; gap: 2px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px; padding: 2px; }
.lang button { font: 600 13px var(--font); border: 0; background: transparent; padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--text-secondary); }
.lang button[aria-pressed="true"] { background: var(--text-primary); color: var(--surface-1); }

/* hero */
.hero { padding: 18px 0 10px; }
.kicker { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-secondary); }
.hero h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); line-height: 1.1; font-weight: 700; }
.dek { margin: 10px 0 0; max-width: 62ch; color: var(--text-secondary); font-size: 17px; }
.countdown { display: inline-block; margin: 14px 0 0; padding: 6px 12px; border-radius: 999px; background: var(--text-primary); color: var(--surface-1); font-weight: 600; font-size: 14px; }
.countdown:empty { display: none; }

.notice { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-left: 3px solid var(--text-secondary); border-radius: 8px; background: var(--surface-1); color: var(--text-secondary); font-size: 14px; }

/* filters: one row above everything they scope */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 22px 0 6px; padding: 14px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-secondary); min-width: 0; flex: 1 1 200px; }
.field select, .field input { font: 15px var(--font); color: var(--text-primary); padding: 8px 10px; border: 1px solid var(--axis); border-radius: 8px; background: #fff; width: 100%; }
.combo { position: relative; display: block; }
.combo .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--text-secondary); }

.content { transition: opacity .15s; }
.content.is-loading { opacity: .55; }      /* hold previous render, no skeleton */
.scope-title { margin: 22px 0 10px; font-size: 22px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .tile .value { font-size: 22px; } .card { padding: 14px 12px 12px; } }
.tile .label { font-size: 13px; color: var(--text-secondary); }
.tile .value { font-size: 28px; font-weight: 600; margin-top: 2px; }
.tile .delta { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.tile .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* cards */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.card { margin: 0; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 14px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card[hidden] { display: none; }
@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 17px; }
.card-head .sub { margin: 2px 0 0; font-size: 13px; color: var(--text-secondary); }
.foot { margin: 10px 0 0; font-size: 12px; color: var(--text-muted); }
.foot:empty { display: none; }
.view-toggle { display: flex; gap: 2px; background: var(--page); border-radius: 8px; padding: 2px; flex: none; }
.view-toggle button { font: 600 12px var(--font); border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--text-secondary); }
.view-toggle button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }
.empty { color: var(--text-muted); font-size: 14px; padding: 18px 0; }

/* results list (bars with labels on every row) */
.results { display: grid; gap: 6px; }
.res-row { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr) 4.2em 2.6em; align-items: center; gap: 10px; padding: 3px 0; border-radius: 6px; }
.res-row:hover, .res-row:focus-visible { background: var(--page); outline: none; }
.res-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.res-name .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.res-name .txt { min-width: 0; }
.res-name .main { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.res-name .lists { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.res-track { position: relative; height: 14px; }
.res-bar { position: absolute; left: 0; top: 0; height: 14px; border-radius: 0 4px 4px 0; min-width: 1px; }
.res-val { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.res-seats { font-size: 13px; text-align: right; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.res-head { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.res-head span:nth-child(3), .res-head span:nth-child(4) { text-align: right; }

/* seats */
.seats-wrap svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 50%; }
.legend b { font-variant-numeric: tabular-nums; }

/* small multiples */
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.panel h4 { margin: 0; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.panel h4 .dot { width: 10px; height: 10px; border-radius: 50%; }
.panel .now { font-size: 12px; color: var(--text-secondary); margin: 1px 0 2px; }
.key { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.multiples > .panel { min-width: 0; }
.multiples { grid-template-columns: repeat(auto-fill, minmax(min(230px, 100%), 1fr)); }
.key .ln { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: 3px; margin-right: 5px; }

/* map */
.party-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { font: 600 12px var(--font); border: 1px solid var(--axis); background: #fff; border-radius: 999px; padding: 4px 10px; cursor: pointer; color: var(--text-primary); display: inline-flex; align-items: center; gap: 6px; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip[aria-checked="true"] { border-color: var(--text-primary); box-shadow: inset 0 0 0 1px var(--text-primary); }
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-wrap path.unit { cursor: pointer; }
.map-wrap path.unit:hover { stroke: var(--text-primary); stroke-width: 1.2px; }
.scale { display: flex; align-items: center; gap: 0; margin-top: 8px; font-size: 11px; color: var(--text-secondary); flex-wrap: wrap; }
.scale .bin { display: flex; flex-direction: column; min-width: 44px; }
.scale .bin i { height: 10px; display: block; margin-right: 2px; }
.scale .bin span { font-variant-numeric: tabular-nums; }
.scale .nd { margin-left: 12px; display: inline-flex; gap: 5px; align-items: center; }
.scale .nd i { width: 14px; height: 10px; background: var(--nodata); display: inline-block; }

/* tables (the accessible twin of every chart) */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 5px 6px; border-bottom: 1px solid var(--grid); text-align: left; }
.tbl th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { max-height: 420px; overflow: auto; }

/* tooltip — values lead, labels follow */
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.08); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 280px; }
.tooltip .tt-title { font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: baseline; gap: 6px; }
.tooltip .tt-row .ln { width: 12px; height: 0; border-top: 2px solid; flex: none; transform: translateY(-3px); }
.tooltip .tt-row b { font-size: 14px; color: var(--text-primary); }
.tooltip .tt-row span { color: var(--text-secondary); }
.tooltip .tt-note { margin-top: 4px; color: var(--text-muted); }

/* Plot text uses ink tokens */
.chart svg [aria-label="tick"] { stroke: var(--axis); }
.chart svg text { fill: var(--text-secondary); }

/* footer */
.colophon { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--grid); color: var(--text-secondary); font-size: 14px; }
.colophon h2 { font-size: 16px; color: var(--text-primary); }
.colophon p { max-width: 80ch; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.button { font: 600 14px var(--font); padding: 8px 14px; border-radius: 8px; border: 1px solid var(--text-primary); background: var(--text-primary); color: var(--surface-1); cursor: pointer; text-decoration: none; }
.button.ghost { background: transparent; color: var(--text-primary); }
.sources { border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.sources td, .sources th { padding: 4px 10px 4px 0; text-align: left; border-bottom: 1px solid var(--grid); }
.build { font-size: 12px; color: var(--text-muted); }

/* ---------------------------------------------------------------- tabs (class · housing · crossings · elections) */
.countdown { border: 0; cursor: pointer; font-family: var(--font); }
.countdown[hidden] { display: none; }
.tabs { display: flex; gap: 4px; margin: 22px 0 0; border-bottom: 1px solid var(--grid); overflow-x: auto; scrollbar-width: none; }
.tabs button { font: 600 15px var(--font); border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--text-primary); }
.tabs button:hover { color: var(--text-primary); }
.tab-panel[hidden], .field[hidden] { display: none; }
.filters { margin-top: 14px; }

/* stacked 100% bars */
.stack { display: grid; gap: 10px; }
.stack .legend { margin: 0 0 2px; }
.legend .sw.sq { border-radius: 2px; }
.stack-row { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr); gap: 10px; align-items: center; }
.stack-label { font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.stack-bar { display: flex; gap: 2px; height: 26px; }
.stack-bar .seg { height: 100%; display: flex; align-items: center; justify-content: center; min-width: 2px; outline: none; }
.stack-bar .seg:first-child { border-radius: 4px 0 0 4px; }
.stack-bar .seg:last-child { border-radius: 0 4px 4px 0; }
.stack-bar .seg:focus-visible { box-shadow: 0 0 0 2px var(--text-primary); }
.stack-bar .seg span { font-size: 11px; font-weight: 600; color: #0b0b0b; background: rgba(252, 252, 251, .82); padding: 0 4px; border-radius: 3px; font-variant-numeric: tabular-nums; }

/* ranking */
.rank { display: grid; gap: 4px; }
.rank-h { margin: 8px 0 2px; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.rank-h:first-child { margin-top: 0; }
.rank-row { grid-template-columns: minmax(96px, 40%) minmax(0, 1fr) 5.6em; cursor: pointer; }
.rank-row.is-hl .main { text-decoration: underline; text-underline-offset: 3px; }

/* crossings */
.axis-pick { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.axis-pick .field { flex: 1 1 220px; }
.multiples.q { grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); }
