/* NAR Insights - application design system (redesign branch).
   App shell (sidebar + header + content), cards, controls, data components.
   Chart colors are the validated set from the original design. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8a94a3;
  --rule: #e5e7eb;
  --rule-soft: #f0f2f5;
  --brand: #006bb7;   /* REALTOR® blue */
  --brand-ink: #ffffff;
  --brand-soft: #e8f0fb;
  --accent: #1f6fc0;          /* selection series */
  --bench: #c07a2c;           /* statewide / benchmark series */
  --seq-0: #eef1f5; --seq-1: #dbe8f6; --seq-2: #a9c9ec; --seq-3: #6fa3de; --seq-4: #3a78c4; --seq-5: #1d4f91;
  --good: #1f7a4d; --bad: #b3261e; --warn: #9a6700;
  --tile-ink-strong: #ffffff;
  --u-harddem: #1d4f91; --u-leandem: #6fa3de; --u-swing: #8a8f98; --u-leangop: #e0857c; --u-hardgop: #a8201a; --u-unknown: #c3c8cf;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --sidebar: 248px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1c2128; --ink: #e8ebef; --ink-2: #b1bac6; --ink-3: #7f8a97;
    --rule: #2a3039; --rule-soft: #21262e; --brand: #6aa6ec; --brand-ink: #0b1420; --brand-soft: #1b2a3d;
    --accent: #4d8fd6; --bench: #c8843a;
    --seq-0: #22272e; --seq-1: #b9d3f2; --seq-2: #86b1e6; --seq-3: #5389d4; --seq-4: #2f63b0; --seq-5: #173f7d;
    --good: #5cc28d; --bad: #f08a80; --warn: #e3b341; --tile-ink-strong: #0b1420;
    --u-harddem: #3a78c4; --u-leandem: #9cc2ee; --u-swing: #a3a8b0; --u-leangop: #f0a39b; --u-hardgop: #dd4a40; --u-unknown: #5d646e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1c2128; --ink: #e8ebef; --ink-2: #b1bac6; --ink-3: #7f8a97;
    --rule: #2a3039; --rule-soft: #21262e; --brand: #6aa6ec; --brand-ink: #0b1420; --brand-soft: #1b2a3d;
    --accent: #4d8fd6; --bench: #c8843a;
    --seq-0: #22272e; --seq-1: #b9d3f2; --seq-2: #86b1e6; --seq-3: #5389d4; --seq-4: #2f63b0; --seq-5: #173f7d;
    --good: #5cc28d; --bad: #f08a80; --warn: #e3b341; --tile-ink-strong: #0b1420;
    --u-harddem: #3a78c4; --u-leandem: #9cc2ee; --u-swing: #a3a8b0; --u-leangop: #f0a39b; --u-hardgop: #dd4a40; --u-unknown: #5d646e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--brand); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 18px 14px 10px;
  background: var(--surface); border-right: 1px solid var(--rule); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; text-decoration: none; color: var(--ink); }
.brand-mark { display: block; width: 34px; height: 34px; flex: none; border-radius: 4px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; letter-spacing: -.01em; }
.brand-text { min-width: 0; }
.brand-text span { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-label { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink-2);
  text-decoration: none; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; color: var(--ink-3); }
.nav a:hover { background: var(--rule-soft); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav a[aria-current="page"] svg { color: var(--brand); }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--rule); font-size: 12px; color: var(--ink-3); }
.main { min-width: 0; display: flex; flex-direction: column; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 24px 32px 16px; }
.eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 600; color: var(--brand); }
.page-head h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -.02em; }
.page-head .sub { margin: 4px 0 0; color: var(--ink-2); }
.page-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.content { padding: 0 32px 40px; display: flex; flex-direction: column; gap: 20px; }

/* ---------------------------------------------------------------- toolbar (filters) */
.toolbar { position: sticky; top: 0; z-index: 1000; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
  margin: 0 32px 20px; padding: 14px 16px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); }
.control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.control.grow { flex: 1 1 320px; }
.label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.hint { color: var(--ink-3); font-size: 12px; font-weight: 400; }
select, input[type="search"], input[type="text"] { height: 36px; min-width: 150px; padding: 0 10px; border: 1px solid var(--rule);
  border-radius: var(--radius-sm); background: var(--surface); }
select:focus, input:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; }
select:disabled { opacity: .55; }
.segmented { display: inline-flex; padding: 3px; gap: 3px; background: var(--rule-soft); border-radius: 9px; }
.segmented button { height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2); cursor: pointer; font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
/* Snapshot: the five partisan segments always sit on one line. The group sizes to its chips; when the row is
   too narrow it moves down as a whole, and on a phone the chips scroll sideways instead of wrapping. */
.seg-control { flex: 0 1 auto; min-width: 0; max-width: 100%; }
.seg-control .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.seg-control .chips::-webkit-scrollbar { display: none; }
.seg-control .chip { flex: none; white-space: nowrap; }
/* Snapshot toolbar: everything on one row at desktop widths (Clear all + Filters at the right end) */
.toolbar:has(.seg-control) { gap: 12px 10px; }
.toolbar:has(.seg-control) > label.control { flex: 1 1 92px; max-width: 150px; }   /* District: short values ("CD 02") */
.toolbar:has(.seg-control) > label.control:has(#state) { flex-basis: 132px; max-width: 180px; }   /* State: fits "Massachusetts" */
.toolbar:has(.seg-control) > label.control select { min-width: 0; width: 100%; }
.toolbar:has(.seg-control) .segmented button { padding: 0 9px; font-size: 13px; }
.seg-control .chips { gap: 3px; }
.seg-control .chip { padding: 0 7px 0 5px; font-size: 13px; }
.seg-control .chip .order { margin-right: 0; }
/* the dot and the order badge take the same 18px, so picking segments never widens the row */
.seg-control .u-chip { gap: 5px; }
.seg-control .u-chip .u-dot { flex: none; width: 13px; height: 13px; background: radial-gradient(circle, var(--uc) 4.5px, transparent 5px); }
.seg-control .u-chip .order { flex: none; width: 13px; height: 13px; font-size: 9px; }
.toolbar:has(.seg-control) .fb-toggle b { min-width: 17px; height: 17px; padding: 0 5px; font-size: 10px; }
.tb-clear.icon { position: relative; width: 36px; padding: 0; justify-content: center; }
.tb-clear.icon span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.chip { height: 32px; padding: 0 12px; border: 1px solid var(--rule); border-radius: 16px; background: var(--surface); cursor: pointer; color: var(--ink-2); font-weight: 500; }
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chip .order { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px; border-radius: 50%;
  background: var(--brand); color: var(--brand-ink); font-size: 11px; }
.btn, button.primary { text-decoration: none; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; cursor: pointer; }
button.primary, a.btn.primary { background: var(--brand); color: var(--brand-ink); }
button.primary:hover, a.btn.primary:hover { filter: brightness(1.06); }
button.primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-secondary, button.secondary { background: var(--surface); border: 1px solid var(--rule); color: var(--ink); height: 34px; padding: 0 12px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; }
.btn svg { width: 16px; height: 16px; }
.check { display: inline-flex; gap: 8px; align-items: center; }
.export-wrap { align-items: flex-end; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card-head .desc { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.card-body { padding: 16px 20px 20px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }
/* under a row of 3 stat cards: the same 3 columns and gap, so the gutters line up (first card spans 2) */
.grid-2.align-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.stats:has(+ .grid-2.align-stats) { gap: 20px; }   /* same gutter as the space between the rows: an even cross */
.grid-2.align-stats > :first-child { grid-column: span 2; }
.grid-halves { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.note { color: var(--ink-3); font-size: 12px; margin: 10px 0 0; }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat { padding: 16px 18px; }
.stat-label { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.stat-value, .kpi-value { margin-top: 6px; font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat-sub { margin-top: 4px; font-size: 12px; color: var(--ink-3); }
.kpi-label { font-size: 12px; font-weight: 500; color: var(--ink-2); }

/* tabs */
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--rule); }
.tabs button { height: 44px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--ink-2);
  font-weight: 500; cursor: pointer; margin-bottom: -1px; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tab-panel { padding: 18px 20px 22px; }
/* bolder underline tabs (Snapshot audience details) */
.tabs.bold { gap: 8px; padding: 0 16px; }
.tabs.bold button { display: inline-flex; align-items: center; gap: 8px; height: 54px; padding: 0 14px; font-size: 15px; font-weight: 600;
  color: var(--ink-2); border-bottom-width: 3px; border-radius: 8px 8px 0 0; transition: color .12s, background .12s; }
.tabs.bold button svg { width: 17px; height: 17px; opacity: .7; }
.tabs.bold button:hover { color: var(--ink); background: var(--surface-2); }
.tabs.bold button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700; background: none; }
.tabs.bold button[aria-selected="true"] svg { opacity: 1; }

/* ---------------------------------------------------------------- data components (shared with page scripts) */
.legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--ink-2); font-size: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.bars svg { display: block; width: 100%; height: auto; overflow: visible; }
.bars text { fill: var(--ink-2); font-size: 11px; font-family: var(--font); }
.bars .tick { fill: var(--ink-3); font-size: 10px; }
.bars .cat { fill: var(--ink-2); font-weight: 500; }
.bars .grid { stroke: var(--rule-soft); stroke-dasharray: 2 3; }
.bars .b-sel { fill: var(--accent); }
.bars .b-bench { fill: var(--bench); opacity: .55; }
.bars .val { fill: var(--ink); font-size: 9px; font-weight: 700; }   /* fits within the bar's own width */
.bars .axis { stroke: var(--rule); }
.demo-card { display: flex; flex-direction: column; padding: 14px 14px 12px; }
.demo-card h3 { margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--ink); text-align: center; }
.demo-note { margin: 8px 0 0; padding-top: 10px; border-top: 1px solid var(--rule-soft); text-align: center; font-size: 12px; color: var(--ink-3); }
.demo-note b { font-weight: 700; margin-right: 4px; }
.demo-note b.up { color: var(--good); }
.demo-note b.down { color: var(--bad); }
.demo-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 16px; }
.leg-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border-radius: 14px; border: 1px solid var(--rule); background: var(--surface-2);
  font-size: 12px; font-weight: 500; color: var(--ink-2); }
.leg-chip i { width: 10px; height: 10px; border-radius: 3px; }
.leg-chip + .leg-chip i { opacity: .55; }
.demo-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; }

.hbar-row { display: grid; grid-template-columns: 140px 1fr 72px; align-items: center; gap: 12px; padding: 7px 0; }
.hbar-row .name { color: var(--ink-2); }
.hbar-track { position: relative; height: 10px; background: var(--rule-soft); border-radius: 5px; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.hbar-row .pct { font-weight: 600; text-align: right; }
/* stretch to the map card's height (Top counties lives in its own card now) and spread the rows */
#partyPanel { display: flex; flex-direction: column; }
#partyPanel .card-body { flex: 1; display: flex; flex-direction: column; }
#party { flex: 1; display: flex; flex-direction: column; }
.party-bars { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px 14px; margin-bottom: 20px;
  padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-2); }
.party-cap { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.party-stack { display: flex; overflow: hidden; border-radius: 6px; background: var(--rule-soft); }
.party-stack span { flex: 0 0 auto; min-width: 0; overflow: hidden; white-space: nowrap; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; text-shadow: 0 1px 1px rgba(0,0,0,.2); }
.party-stack span + span { border-left: 2px solid var(--surface-2); }
.party-stack.sel { height: 30px; }
.party-stack.nat { height: 22px; opacity: .72; }
.party-stack.nat span { font-size: 11px; font-weight: 600; }
.party-rows { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; }
.party-row { display: flex; flex-direction: column; gap: 10px; padding: 14px 6px; border-top: 1px solid var(--rule-soft); }
.party-row:first-child { border-top: 0; }
.party-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 14px; }
.party-name { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; min-width: 0; }
.party-name i { width: 12px; height: 12px; border-radius: 3px; background: var(--pc); flex: none; }
.party-pct { display: flex; align-items: baseline; gap: 8px; }
.party-pct b { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.party-pct small { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.party-track { position: relative; height: 18px; border-radius: 9px; background: color-mix(in srgb, var(--pc) 13%, var(--surface-2)); }
.party-fill { display: block; height: 100%; border-radius: 9px; background: var(--pc); }
.party-mark { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1px; border-radius: 2px; background: var(--ink); }
.party-mark em { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-style: normal; font-size: 10px; font-weight: 600;
  color: var(--ink-2); white-space: nowrap; opacity: 0; transition: opacity .12s; }
.party-row:hover .party-mark em { opacity: 1; }
.delta { justify-self: end; min-width: 76px; text-align: center; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--rule-soft); color: var(--ink-2); }
.delta.up { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.delta.down { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.party-key { display: flex; align-items: center; gap: 8px; margin: auto 0 0; padding-top: 12px; font-size: 11px; color: var(--ink-3); }
.party-mark-key { width: 3px; height: 12px; border-radius: 2px; background: var(--ink); }
.county-grid { display: grid; grid-auto-flow: column; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 40px; }
.county-row { display: grid; grid-template-columns: 22px 150px minmax(0, 1fr) 64px; align-items: center; gap: 12px; padding: 8px 6px; border-radius: 6px;
  border-bottom: 1px solid var(--rule-soft); }
.county-row:hover { background: var(--surface-2); }
.county-row .rk { font-size: 11px; font-weight: 700; color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.county-row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.county-track { height: 10px; border-radius: 5px; background: var(--rule-soft); overflow: hidden; }
.county-track span { display: block; height: 100%; border-radius: 5px; background: var(--accent); }
.county-row .n { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: right; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); border-bottom: 1px solid var(--rule); }
th:first-child, td:first-child { text-align: left; }
tbody tr + tr td { border-top: 1px solid var(--rule-soft); }
tbody tr:hover td { background: var(--surface-2); }
.vh-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 20px; }
.vh-card { --vh: var(--brand); --vh-soft: var(--brand-soft); border: 1px solid var(--rule); border-top: 3px solid var(--vh); border-radius: var(--radius-sm);
  padding: 16px 18px 10px; background: var(--surface); min-width: 0; }
.vh-card.vh-primary { --vh: #7a4fc4; --vh-soft: #f1ebfb; }
.vh-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.vh-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.vh-head p { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.vh-tag { flex: none; padding: 3px 9px; border-radius: 10px; background: var(--vh-soft); color: var(--vh); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; }
.vh-row { display: grid; grid-template-columns: minmax(84px, 1fr) 110px 72px 64px; align-items: center; gap: 6px 12px; padding: 10px 6px; border-radius: 6px; }
.vh-row + .vh-row { border-top: 1px solid var(--rule-soft); }
.vh-row:not(.vh-cols):hover { background: var(--surface-2); }
.vh-cols { font-size: 11px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; padding-top: 0; white-space: nowrap; }
.vh-label { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 7px; height: 7px; border-radius: 50%; background: var(--rule); }
.pips i.on { background: var(--vh); }
.vh-bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--vh-soft); overflow: hidden; }
.vh-bar span { display: block; height: 100%; border-radius: 4px; background: var(--vh); }
.vh-num { text-align: right; font-variant-numeric: tabular-nums; }
.vh-num b { font-weight: 600; }
.vh-num small { font-size: 11px; color: var(--ink-3); margin-left: 4px; }
:root[data-theme="dark"] .vh-card.vh-primary { --vh: #a98be6; --vh-soft: #2a2140; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .vh-card.vh-primary { --vh: #a98be6; --vh-soft: #2a2140; } }

.turnout { display: grid; grid-template-columns: 112px repeat(5, minmax(0, 1fr)); gap: 8px; }
.turnout .corner { align-self: end; font-size: 11px; color: var(--ink-3); padding-bottom: 8px; }
.turnout .colhead { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0 0 8px; border-top: 4px solid var(--u);
  border-radius: 2px; padding-top: 8px; text-align: center; }
.turnout .colhead span { font-weight: 700; font-size: 13px; color: var(--ink); }
.turnout .colhead small { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.turnout .colhead.off { opacity: .45; }
.turnout .rowhead { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 13px; }
.turnout .rowhead small { display: block; margin-top: 2px; font-weight: 400; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tier-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 16px; }
.tier-bars i { width: 4px; border-radius: 1px; background: var(--rule); }
.tier-bars i:nth-child(1) { height: 6px; } .tier-bars i:nth-child(2) { height: 11px; } .tier-bars i:nth-child(3) { height: 16px; }
.tier-bars i.on { background: var(--ink-2); }
.cell { position: relative; border-radius: var(--radius-sm); padding: 14px 10px 12px; text-align: center; overflow: hidden;
  background: color-mix(in srgb, var(--u) var(--heat, 0%), var(--surface)); border: 1px solid color-mix(in srgb, var(--u) 35%, var(--rule-soft));
  transition: transform .12s, box-shadow .12s; }
.cell:not(.off):hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.cell .v { font-size: 19px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.cell .share { display: inline-block; margin: 3px 0 6px; padding: 1px 7px; border-radius: 9px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--surface) 75%, transparent); color: var(--ink-2); }
.cell .s { color: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.cell.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 6px, var(--surface) 6px 12px); border-color: var(--rule-soft);
  display: grid; place-items: center; min-height: 86px; }
.cell.off .v { font-weight: 400; color: var(--ink-3); }

.media-cards { margin-bottom: 4px; }
.vh-card.mc-tv { --vh: #7a4fc4; --vh-soft: #f1ebfb; }
.vh-card.mc-audio { --vh: #12816f; --vh-soft: #e2f4f0; }
.vh-card.mc-other { --vh: var(--ink-3); --vh-soft: var(--surface-2); }
:root[data-theme="dark"] .vh-card.mc-tv { --vh: #a98be6; --vh-soft: #2a2140; }
:root[data-theme="dark"] .vh-card.mc-audio { --vh: #4cc3ad; --vh-soft: #15302b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .vh-card.mc-tv { --vh: #a98be6; --vh-soft: #2a2140; }
  :root:not([data-theme="light"]) .vh-card.mc-audio { --vh: #4cc3ad; --vh-soft: #15302b; }
}

/* map */
.geo-map { position: relative; z-index: 0; isolation: isolate; height: 440px; border-radius: var(--radius-sm); overflow: hidden; background: var(--rule-soft); }
.geo-map .leaflet-control-attribution { font-size: 10px; }
.map-wrap { position: relative; }
.map-back { position: absolute; z-index: 5; top: 10px; right: 10px; display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px 0 8px;
  border: 1px solid var(--rule); border-radius: 16px; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(6px);
  color: var(--ink); font-size: 12px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-lg); }
.map-back svg { width: 16px; height: 16px; color: var(--brand); }
.map-back:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--rule)); color: var(--brand); }
.map-bar { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.check.small { font-size: 12px; color: var(--ink-2); }
.legend-seq { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; row-gap: 4px; margin-top: 10px; color: var(--ink-3); font-size: 11px; }
.legend-seq span { white-space: nowrap; }
.legend-seq i { width: 22px; height: 8px; border-radius: 2px; display: inline-block; }
.legend-seq .none-swatch { display: inline-flex; align-items: center; gap: 6px; margin-left: 10px; }
.legend-seq .none-swatch i { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-3); }
.dot-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.dot-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot-legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px var(--surface), 0 0 0 2px var(--rule); }
.dot-legend b { color: var(--ink); font-weight: 600; }
.leaflet-tooltip.map-tip { background: var(--ink); color: var(--surface); border: 0; border-radius: 6px; font-size: 12px; box-shadow: none; font-family: var(--font); }
.leaflet-tooltip.map-tip::before { display: none; }
.leaflet-container { font-family: var(--font); }

/* ---------------------------------------------------------------- overlays */
.loading { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(4px); }
.loading-card { width: min(420px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-lg); }
.loading-card p { margin: 0 0 8px; font-weight: 600; }
.loading-card ol { margin: 0; padding-left: 18px; color: var(--ink-3); font-size: 12px; }
.spinner { width: 24px; height: 24px; margin-bottom: 12px; border: 3px solid var(--rule); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tooltip { position: fixed; z-index: 3000; pointer-events: none; max-width: 260px; background: var(--ink); color: var(--surface);
  padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1.4; box-shadow: var(--shadow-lg); }

dialog { border: 1px solid var(--rule); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--ink);
  width: min(600px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(10, 16, 24, .45); backdrop-filter: blur(2px); }
.dialog { padding: 22px 24px; }
.dialog h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.file-name { margin: 0 0 16px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--ink-3); word-break: break-all; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field select { width: 100%; }
.dialog > .check { margin-bottom: 14px; }
.extras { margin: 0 0 14px; display: flex; flex-direction: column; gap: 6px; }
.extras select { width: 100%; }
.extra-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.extra-list li { display: grid; grid-template-columns: 78px 1fr auto auto 28px; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--rule); border-radius: var(--radius-sm); }
.extra-list .col { color: var(--ink-3); font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.extra-list .name { font-weight: 600; }
.extra-list .remove { border: 0; background: none; color: var(--ink-3); cursor: pointer; }
.extra-list .remove:hover { color: var(--bad); }
.ex-body { min-height: 80px; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--rule-soft); border-radius: var(--radius-sm); }
.ex-body .big { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.ex-body .spinner { margin: 4px 0 8px; }
.ex-body ol.hint { padding-left: 18px; margin: 8px 0 0; }
.checks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
.ex-done, .ex-working { display: flex; align-items: flex-start; gap: 12px; }
.ex-done p, .ex-working p { margin: 4px 0 0; }
.ex-working .spinner { margin: 2px 0 0; flex: none; }
.ex-tick { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--good); color: #fff; font-weight: 700; }
.ex-problems { margin: 8px 0 0; padding-left: 18px; }
.ex-file { margin: 12px 0 0; overflow-wrap: anywhere; }
.ex-body .cut-note { margin-top: 4px; }
.checks .ok { color: var(--good); font-weight: 700; }
.checks .fail, p.fail { color: var(--bad); font-weight: 600; }
details { margin: 12px 0 0; color: var(--ink-2); }
pre { max-height: 220px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: var(--radius-sm); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions button:not(.primary) { height: 36px; padding: 0 14px; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; font-weight: 500; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .grid-2, .grid-2.align-stats { grid-template-columns: minmax(0, 1fr); }
  .grid-2.align-stats > :first-child { grid-column: auto; }
  .county-grid { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); grid-template-rows: none !important; }
  .county-row { grid-template-columns: 22px 110px minmax(0, 1fr) 56px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .brand { padding: 0 8px 0 0; }
  .brand-text span, .nav-label, .sidebar-foot { display: none; }
  .nav { display: flex; gap: 2px; overflow-x: auto; }
  .nav a { padding: 6px 8px; white-space: nowrap; }
  .page-head { padding: 18px 16px 12px; flex-direction: column; align-items: flex-start; }
  .content { padding: 0 16px 32px; }
  .toolbar { margin: 0 16px 16px; position: static; }
  .grid-halves, .vh-pair { grid-template-columns: minmax(0, 1fr); }
  .vh-row { grid-template-columns: minmax(0, 1fr) 104px 64px 56px; gap: 6px 8px; }
  .turnout { grid-template-columns: 58px repeat(5, minmax(0, 1fr)); gap: 4px; }
  .cell .v { font-size: 14px; }
  .cell .s, .tier-bars, .turnout .corner, .turnout .colhead small { display: none; }
  .cell { padding: 10px 4px; }
  .turnout .colhead span { font-size: 11px; }
  .hbar-row { grid-template-columns: 96px 1fr 60px; }
  .party-line { gap: 8px; }
  .party-pct small { display: none; }
  .party-bars { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .geo-map { height: 320px; }
}

/* ---------------------------------------------------------------- collapsible sidebar */
.app { transition: grid-template-columns .2s ease; }
.app.no-anim, .app.no-anim * { transition: none !important; }
.collapse-btn { position: absolute; top: 22px; right: 12px; display: grid; place-items: center; width: 28px; height: 28px;
  border: 1px solid transparent; border-radius: 7px; background: none; color: var(--ink-3); cursor: pointer; }
.collapse-btn:hover { background: var(--rule-soft); color: var(--ink); border-color: var(--rule); }
.collapse-btn svg { width: 16px; height: 16px; transition: transform .2s ease; }
.brand { padding-right: 40px; }

.app.collapsed { grid-template-columns: 68px minmax(0, 1fr); }
.app.collapsed .sidebar { padding: 18px 10px; align-items: center; }
.app.collapsed .brand { padding: 4px 0 6px; }
.app.collapsed .brand-text, .app.collapsed .nav-label, .app.collapsed .nav-text { display: none; }
.app.collapsed .collapse-btn { position: static; margin: 4px 0 14px; }
.app.collapsed .collapse-btn svg { transform: rotate(180deg); }
.app.collapsed .nav { display: flex; flex-direction: column; gap: 4px; }
.app.collapsed .nav a { justify-content: center; width: 44px; height: 40px; padding: 0; }
.app.collapsed .sidebar-foot { width: 100%; display: flex; justify-content: center; padding: 12px 0 0; }

@media (max-width: 860px) {
  .collapse-btn { display: none; }
  .app.collapsed { grid-template-columns: minmax(0, 1fr); }
  .app.collapsed .nav-text, .app.collapsed .brand-text { display: inline; }
}

/* ---------------------------------------------------------------- user menu (sidebar foot) */
.user-box { position: relative; margin-bottom: 0; }
.user-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px; border: 0; border-radius: var(--radius-sm); background: none; cursor: pointer; text-align: left; }
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--rule-soft); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px; }
.user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-text b { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-text small { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu { position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; z-index: 1500; padding: 6px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.user-menu a, .user-menu button { padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--ink); text-decoration: none; text-align: left; font-size: 13px; cursor: pointer; }
.user-menu a:hover, .user-menu button:hover, .user-menu a[aria-current="page"] { background: var(--rule-soft); }
.user-menu .sign-out { color: var(--bad); border-top: 1px solid var(--rule-soft); border-radius: 0 0 6px 6px; margin-top: 4px; padding-top: 10px; }
.app.collapsed .user-text { display: none; }
.app.collapsed .user-btn { justify-content: center; padding: 4px; }
.app.collapsed .user-menu { left: 0; right: auto; width: 180px; }
.app.collapsed .sidebar-foot { flex-direction: column; align-items: center; }
.empty-card { max-width: 560px; margin: 24px auto; padding: 40px 32px; text-align: center; }
.empty-card svg { width: 40px; height: 40px; color: var(--ink-3); }
.empty-card h2 { margin: 12px 0 6px; font-size: 17px; }
.empty-card p { color: var(--ink-2); }
@media (max-width: 860px) { .user-box { display: none; } }

/* ---------------------------------------------------------------- light/dark-only images (hide-only rules, so any display value works) */
:root[data-theme="dark"] .light-only, :root[data-theme="light"] .dark-only { display: none !important; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .light-only { display: none !important; } }
@media not (prefers-color-scheme: dark) { :root:not([data-theme="dark"]) .dark-only { display: none !important; } }

/* ---------------------------------------------------------------- toast */
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 3000; max-width: 380px; padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--rule)); color: var(--ink); box-shadow: var(--shadow-lg); font-size: 13px; }

/* ---------------------------------------------------------------- snapshot KPI cards */
.kpi { --kc: var(--brand); --kc-soft: var(--brand-soft); display: flex; align-items: flex-start; gap: 16px; padding: 18px 20px; border-top: 3px solid var(--kc); }
.kpi.k2 { --kc: #7a4fc4; --kc-soft: #f1ebfb; }
.kpi.k3 { --kc: #12816f; --kc-soft: #e2f4f0; }
.kpi.k4 { --kc: #b8650f; --kc-soft: #fbefe0; }
:root[data-theme="dark"] .kpi.k2 { --kc: #a98be6; --kc-soft: #2a2140; }
:root[data-theme="dark"] .kpi.k3 { --kc: #4cc3ad; --kc-soft: #15302b; }
:root[data-theme="dark"] .kpi.k4 { --kc: #e3a24b; --kc-soft: #33260f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .kpi.k2 { --kc: #a98be6; --kc-soft: #2a2140; }
  :root:not([data-theme="light"]) .kpi.k3 { --kc: #4cc3ad; --kc-soft: #15302b; }
  :root:not([data-theme="light"]) .kpi.k4 { --kc: #e3a24b; --kc-soft: #33260f; }
}
.kpi-icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--kc-soft); color: var(--kc); }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-body { min-width: 0; }
.kpi .kpi-label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { margin-top: 4px; font-size: clamp(22px, 1.6vw + 12px, 30px); font-variant-numeric: tabular-nums; }   /* 7-digit national totals fit narrow cards */
.kpi-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 8px; font-size: 12px; color: var(--ink-3); }
.kpi-pill { padding: 1px 8px; border-radius: 10px; background: var(--kc-soft); color: var(--kc); font-weight: 700; font-size: 11px; font-variant-numeric: tabular-nums; }

/* universe chips: each in its partisan color */
.u-chip { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px 0 11px; transition: background .12s, border-color .12s; }
.u-chip .u-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--uc); }
.u-chip:hover { border-color: var(--uc); background: color-mix(in srgb, var(--uc) 6%, var(--surface)); }
.u-chip[aria-pressed="true"] { border-color: var(--uc); background: color-mix(in srgb, var(--uc) 14%, var(--surface)); color: var(--ink); }
.u-chip .order { margin-right: 0; background: var(--uc); color: #fff; }

/* ---------------------------------------------------------------- association picker (first sign-in + Profile) */
.assoc-picker { width: min(560px, calc(100vw - 32px)); }
.assoc-picker .sub { margin: 0 0 14px; color: var(--ink-2); font-size: 13px; }
.ap-search { position: relative; margin-bottom: 10px; }
.ap-search svg { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.ap-search input { width: 100%; height: 40px; padding-left: 34px; }
.ap-list { height: min(46vh, 380px); overflow-y: auto; border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 4px; }
.ap-group { position: sticky; top: -4px; z-index: 1; padding: 8px 10px 4px; background: var(--surface); font-size: 11px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.ap-item { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 0; border-radius: 6px;
  background: none; color: var(--ink); text-align: left; cursor: pointer; font-size: 13px; }
.ap-item small { flex: none; color: var(--ink-3); font-size: 11px; }
.ap-item:hover { background: var(--surface-2); }
.ap-item.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.ap-actions { align-items: center; }
.ap-spacer { flex: 1; }
.ap-msg { margin: 10px 0 0; color: var(--bad); font-size: 13px; }

/* ---------------------------------------------------------------- export: Tag / Cut per extra universe */
.segmented.mini { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--rule); }
.segmented.mini button { height: 24px; padding: 0 9px; border: 0; border-radius: 5px; background: none; color: var(--ink-2); font-size: 12px; font-weight: 600; cursor: pointer; }
.segmented.mini button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.extra-list li.is-cut { background: color-mix(in srgb, var(--brand) 7%, transparent); border-radius: 6px; }
.extra-list li.is-cut .segmented.mini button[data-use="cut"] { color: var(--brand); }
.cut-mode { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.cut-note { margin: 2px 0 4px; font-size: 13px; color: var(--brand); }

/* ---------------------------------------------------------------- print / save as PDF */
.print-header { display: none; }
body.print-prep .sidebar, body.print-prep .toolbar, body.print-prep .page-actions, body.print-prep .mt-panel,
body.print-prep .map-back, body.print-prep .rank-card .more, body.print-prep .leaflet-control-zoom,
body.print-prep .user-box, body.print-prep .toast, body.print-prep .tooltip, body.print-prep .page-head { display: none !important; }
body.print-prep { background: #fff; }
body.print-prep .app { display: block; }
body.print-prep .main { width: 7.5in; height: auto; margin: 0 auto; }
body.print-prep.print-landscape .main { width: 10in; }
body.print-prep .content, body.print-prep .mapping { padding: 0 !important; }
body.print-prep .card { box-shadow: none; break-inside: avoid; }
body.print-prep .kpi { padding: 12px 14px; gap: 0; }
body.print-prep .kpi-icon { display: none; }
body.print-prep .kpi .kpi-label { font-size: 10px; }
body.print-prep .kpi .kpi-value { font-size: 24px; }
body.print-prep .stats { gap: 10px; }
body.print-prep .print-header { display: flex; align-items: center; gap: 14px; padding: 0 0 12px; margin-bottom: 14px; border-bottom: 2px solid var(--brand); }
.print-header img { flex: none; border-radius: 4px; }
.print-header .ph-text { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.print-header .ph-eyebrow { font-size: 11px; font-weight: 600; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.print-header b { font-size: 18px; color: var(--ink); }
.print-header .ph-details { font-size: 12px; color: var(--ink-2); }
.print-header .ph-meta { flex: none; text-align: right; font-size: 10px; color: var(--ink-3); line-height: 1.4; }
/* mapping tool: the map takes the page */
body.print-prep .mapping { display: block; }
body.print-prep .mt-map-wrap { height: 6.2in; }
body.print-prep .map-float { box-shadow: none; }
@page { size: letter portrait; margin: 0.45in; }
@page landscape { size: letter landscape; margin: 0.4in; }
@media print {
  body.print-landscape .app { page: landscape; }
  body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rank-card, .kpi, .reg-row, .party-row, .county-row, .vh-card { break-inside: avoid; }
  .card-head, h2, h3 { break-after: avoid; }
}

/* ---------------------------------------------------------------- Snapshot filters (second row of the toolbar) */
.tb-divider { flex-basis: 100%; height: 1px; margin: 2px 0; background: var(--rule-soft); }
.fb-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; flex: 1 1 100%; }
.fb-control { min-width: 128px; }
.fb-select { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 36px; min-width: 128px; padding: 0 10px;
  border: 1px solid var(--rule); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.fb-select:hover:not(:disabled) { border-color: var(--ink-3); }
.fb-select[aria-expanded="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.fb-select.on { border-color: color-mix(in srgb, var(--brand) 55%, var(--rule)); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
.fb-select.on .fb-value { color: var(--brand); font-weight: 600; }
.fb-select .placeholder { color: var(--ink-3); }
.fb-select svg { flex: none; width: 14px; height: 14px; opacity: .6; }
.fb-select:disabled { opacity: .5; cursor: not-allowed; }
.fb-value { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex-basis: 100%; }
.fb-chips:empty { display: none; }
.fb-chip { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: 13px; background: var(--brand-soft); color: var(--brand); font-size: 12px; font-weight: 600; }
.fb-chip button { border: 0; background: none; color: inherit; cursor: pointer; opacity: .7; padding: 0 4px; }
.fb-chip button:hover { opacity: 1; }
.fb-chip.off { background: var(--rule-soft); color: var(--ink-3); text-decoration: line-through; }
.fb-mode { font-size: 12px; color: var(--ink-3); }
.fb-note { flex-basis: 100%; margin: 0; font-size: 12px; color: var(--ink-3); }
.fb-pop { position: absolute; z-index: 2500; width: 280px; max-width: calc(100vw - 24px); padding: 10px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.fb-search { width: 100%; height: 34px; margin-bottom: 8px; }
.fb-list { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; }
.fb-opt { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.fb-opt:hover { background: var(--surface-2); }
.fb-opt[hidden] { display: none; }
/* universe filter: collapsible topic and category sections */
.fb-group, .fb-subgroup { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: none; cursor: pointer; text-align: left; font-family: inherit; }
.fb-group { position: sticky; top: 0; z-index: 1; margin: 0; padding: 9px 6px 7px; background: var(--surface); border-bottom: 1px solid var(--rule-soft);
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--brand); }
.fb-subgroup { padding: 7px 6px 3px; font-size: 11px; font-weight: 600; color: var(--ink-3); }
.fb-group span, .fb-subgroup span { flex: 1; min-width: 0; }
.fb-group small, .fb-subgroup small { font-size: 10.5px; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--ink-3); }
.fb-group:hover, .fb-subgroup:hover { background: var(--surface-2); }
.fb-group .chev, .fb-subgroup .chev { flex: none; width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.fb-sec.open > .fb-group .chev, .fb-cat.open > .fb-subgroup .chev { transform: rotate(90deg); }
.fb-sec:not(.open) > .fb-sec-body, .fb-cat:not(.open) > .fb-cat-body { display: none; }
.fb-list.searching .fb-sec-body, .fb-list.searching .fb-cat-body { display: block !important; }   /* search shows every match */
.fb-sec[hidden], .fb-cat[hidden] { display: none; }
.fb-cat-body { padding-left: 4px; }
.user-menu .menu-admin { display: flex; align-items: center; gap: 8px; }
.user-menu .menu-admin svg { width: 15px; height: 15px; color: var(--brand); }
.fb-xu-mode { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule-soft); font-size: 12px; color: var(--ink-2); }
.fb-pop-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule-soft); }
.fb-pop-foot .primary { height: 30px; padding: 0 14px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--brand); font-weight: 600; font-size: 13px; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- favorite audiences (Snapshot header) */
.fav-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; }
.fav-btn svg { width: 16px; height: 16px; flex: none; }
.fav-btn:hover { border-color: var(--ink-3); }
.fav-btn[aria-expanded="true"] { border-color: var(--brand); }
.fav-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); font-size: 11px; line-height: 18px; text-align: center; }
.fav-star[aria-pressed="true"] { border-color: color-mix(in srgb, #e0a100 60%, var(--rule)); background: color-mix(in srgb, #e0a100 10%, var(--surface)); }
.fav-star[aria-pressed="true"] svg { fill: #e0a100; stroke: #c48a00; }
.fav-pop { width: 340px; }
.fav-name { display: flex; flex-direction: column; gap: 6px; }
.fav-name input { width: 100%; height: 36px; }
.fav-desc { margin: 8px 0 0; font-size: 12px; color: var(--ink-3); }
.fav-error { margin: 8px 0 0; padding: 6px 8px; border-radius: 6px; font-size: 12px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.fav-head { margin: 2px 4px 6px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.fav-empty { margin: 6px 4px; font-size: 13px; color: var(--ink-2); }
.fav-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.fav-item { display: flex; align-items: center; gap: 4px; border-radius: 6px; }
.fav-item:hover, .fav-item.current { background: var(--surface-2); }
.fav-item.current .fav-open b::after { content: " · open"; font-weight: 500; color: var(--ink-3); }
.fav-open { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; border: 0; background: none; text-align: left; cursor: pointer; }
.fav-open b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-open small { font-size: 11px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-del { flex: none; width: 28px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--ink-3); cursor: pointer; }
.fav-del:hover { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
@media (max-width: 860px) { .page-actions { flex-wrap: wrap; } }
.media-unfiltered { padding: 8px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--warn, #b8650f) 10%, transparent); color: var(--ink-2); }
.toolbar .fb-clear { height: auto; padding: 0 4px; border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; }
.toolbar .fb-clear:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- Snapshot: instant feedback while a request runs.
   Both only appear if the update takes more than a moment, so cached answers don't flicker. */
.busy-bar { position: fixed; top: 0; left: 0; right: 0; z-index: 3000; height: 3px; overflow: hidden; opacity: 0; pointer-events: none; transition: opacity .15s; }
.busy-bar::after { content: ""; position: absolute; top: 0; bottom: 0; left: -40%; width: 40%; background: var(--brand); border-radius: 2px; }
body.is-updating .busy-bar { opacity: 1; transition-delay: .12s; }
body.is-updating .busy-bar::after { animation: busy-slide 1s ease-in-out infinite; }
@keyframes busy-slide { from { left: -40%; } to { left: 100%; } }
#report .kpi-value, #report .card-body, #report .tab-panel { transition: opacity .2s; }
body.is-updating #report .kpi-value, body.is-updating #report .card-body, body.is-updating #report .tab-panel { opacity: .55; transition-delay: .18s; }
@media (prefers-reduced-motion: reduce) { body.is-updating .busy-bar::after { animation: none; left: 0; width: 100%; } }

/* "Filters" toggle: the extra filter row folds away under it */
.fb-toggle { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 10px 0 12px; border: 1px solid var(--rule);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.fb-toggle > svg:first-child { width: 15px; height: 15px; color: var(--brand); }
.fb-toggle .chev { width: 14px; height: 14px; opacity: .6; transition: transform .15s; }
.fb-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.fb-toggle:hover { border-color: var(--ink-3); }
.fb-toggle.on { border-color: color-mix(in srgb, var(--brand) 55%, var(--rule)); background: color-mix(in srgb, var(--brand) 6%, var(--surface)); }
.fb-toggle b { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-size: 11px; }
.fb-panel { flex-basis: 100%; display: flex; flex-direction: column; gap: 12px; }
.fb-panel[hidden] { display: none; }
/* Filters button: right end of the toolbar row (wraps to its own line, still right-aligned, when narrow);
   active chips get their own line below only when something is picked */
.fb-toggle-wrap { margin-left: auto; }
.fb-toggle-wrap .label { visibility: hidden; }
.tb-actions { display: flex; align-items: center; gap: 8px; }
.tb-clear { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border: 1px solid var(--rule); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-2); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.tb-clear svg { width: 14px; height: 14px; }
.tb-clear:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.tb-clear:disabled { opacity: .45; cursor: default; }

/* ---------------------------------------------------------------- Custom grid (chip + popover) */
.seg-control .custom-chip { display: inline-flex; align-items: center; gap: 5px; padding: 0 9px 0 7px; }
.custom-chip svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.custom-chip svg circle { fill: var(--surface); }
.custom-chip[aria-pressed="true"] svg circle { fill: var(--brand-soft); }
.custom-pop { width: 380px; padding: 14px; }
.custom-head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 12px; }
.custom-head b { font-size: 14px; }
.custom-head span { font-size: 12px; color: var(--ink-3); }
.custom-row { margin-bottom: 14px; }
.custom-label { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.dual { position: relative; height: 22px; margin: 0 9px; }
.dual-track { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--rule); }
.dual-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--brand); }
.dual input[type="range"] { position: absolute; left: -9px; width: calc(100% + 18px); top: 0; height: 22px; margin: 0; background: none;
  pointer-events: none; -webkit-appearance: none; appearance: none; }
.dual input[type="range"]::-webkit-slider-runnable-track { background: none; border: 0; }
.dual input[type="range"]::-moz-range-track { background: none; border: 0; }
.dual input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: auto; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand); box-shadow: var(--shadow); cursor: grab; }
.dual input[type="range"]::-moz-range-thumb { pointer-events: auto; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand); box-shadow: var(--shadow); cursor: grab; }
.dual input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
.dual-ticks { position: relative; height: 15px; margin: 4px 9px 0; font-size: 11px; color: var(--ink-3); }
.dual-ticks span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.dual-ticks span:first-child { transform: translateX(-9px); }
.dual-ticks span:last-child { transform: translateX(calc(-100% + 9px)); }
.custom-mini { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; margin: 4px 0 2px; }
.custom-mini i { height: 14px; border-radius: 3px; background: var(--rule-soft); }
.custom-mini i.on { background: color-mix(in srgb, var(--u) 55%, transparent); }
.rowhead.off { opacity: .55; }
/* the Custom chip costs ~85px: below ~1500px trim the row so Clear all / Filters still fit on one line */
@media (max-width: 1500px) {
  .custom-chip svg { display: none; }
  .seg-control .custom-chip { padding: 0 9px; }
  .toolbar:has(.seg-control) > label.control { flex-basis: 84px; }
  .toolbar:has(.seg-control) > label.control:has(#state) { flex-basis: 120px; }
  .toolbar:has(.seg-control) .segmented button[data-audience] { padding: 0 7px; }
}
