@import url('assets/colors_and_type.css');

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--vs-font-sans);
  background: var(--vs-bg-tint);
  color: var(--vs-fg1);
  font-size: var(--vs-text-base);
  line-height: var(--vs-leading-body);
  -webkit-font-smoothing: antialiased;
}

body[data-theme="dark"] {
  background: #07112A;
  color: #E6ECF8;
  --vs-fg1: #E6ECF8;
  --vs-fg2: #A8B6D2;
  --vs-fg3: #7A8AAB;
  --vs-bg: #0A1530;
  --vs-bg-tint: #07112A;
  --vs-surface: #0F1D40;
  --vs-surface-2: #0A1530;
  --vs-border: #1E2D55;
  --vs-border-soft: #16234A;
}

button { font-family: inherit; cursor: pointer; }

/* App shell */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.appbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--vs-navy);
  color: var(--vs-white);
  border-bottom: 4px solid var(--vs-teal);
  position: sticky;
  top: 0;
  z-index: 50;
}
.appbar-title {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1;
}
.appbar-sub {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--vs-teal);
  font-weight: 700;
  margin-top: 2px;
}
.appbar-spacer { flex: 1; }
.appbar-clock {
  font-variant-numeric: tabular-nums;
  font-family: var(--vs-font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.04em;
}
.appbar-clock small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.18em;
  font-family: var(--vs-font-sans);
  color: var(--vs-teal);
  margin-bottom: 2px;
}

.client-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(63,197,225,0.35);
  padding: 6px 12px 6px 8px;
  border-radius: 4px;
}
.client-chip img { height: 32px; width: auto; display: block; }
.client-chip .label {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--vs-teal);
  text-transform: uppercase;
  font-weight: 700;
}
.client-chip .name {
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  background: var(--vs-surface);
  border-bottom: 1px solid var(--vs-border);
  padding: 0 24px;
  position: sticky;
  top: 64px;
  z-index: 40;
}
.tab {
  background: none;
  border: none;
  padding: 14px 20px;
  font-family: var(--vs-font-sans);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vs-fg3);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms, border-color 120ms;
}
.tab:hover { color: var(--vs-navy); }
.tab.active { color: var(--vs-navy); border-bottom-color: var(--vs-teal); }
body[data-theme="dark"] .tab.active { color: var(--vs-teal); }

.tab-count {
  display: inline-block;
  background: var(--vs-grey-200);
  color: var(--vs-navy);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 700;
}
body[data-theme="dark"] .tab-count { background: var(--vs-navy-700); color: var(--vs-teal); }

/* Page content */
.page {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* KPI cards */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--vs-surface);
  border: 1px solid var(--vs-border);
  border-radius: 4px;
  padding: 16px 18px;
  position: relative;
}
.kpi.accent { border-top: 3px solid var(--vs-teal); }
.kpi.lowery { border-top: 3px solid var(--vs-navy); background: linear-gradient(180deg, rgba(63,197,225,0.06), transparent 80%); }
.kpi-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--vs-fg3);
  font-weight: 700;
  margin-bottom: 6px;
}
.kpi-value {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 32px;
  line-height: 1;
  color: var(--vs-navy);
  font-variant-numeric: tabular-nums;
}
body[data-theme="dark"] .kpi-value { color: white; }
.kpi-sub {
  font-size: 12px;
  color: var(--vs-fg3);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi-sub.up { color: var(--vs-success); font-weight: 700; }
.kpi-sub.down { color: var(--vs-danger); font-weight: 700; }

/* Section */
.section {
  background: var(--vs-surface);
  border: 1px solid var(--vs-border);
  border-radius: 4px;
  margin-bottom: 16px;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--vs-border);
}
.section-title {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--vs-navy);
  margin: 0;
}
body[data-theme="dark"] .section-title { color: white; }
.section-spacer { flex: 1; }
.section-body { padding: 16px 18px; }

/* Buttons */
.btn {
  font-family: var(--vs-font-sans);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 3px;
  border: 1px solid transparent;
  background: var(--vs-navy);
  color: white;
  transition: background 120ms, transform 80ms;
}
.btn:hover { background: var(--vs-navy-700); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--vs-navy); border-color: var(--vs-border); }
body[data-theme="dark"] .btn.ghost { color: var(--vs-teal); border-color: var(--vs-border); }
.btn.ghost:hover { background: var(--vs-grey-100); }
body[data-theme="dark"] .btn.ghost:hover { background: var(--vs-navy-700); }
.btn.teal { background: var(--vs-teal); color: var(--vs-navy); }
.btn.teal:hover { background: var(--vs-teal-400); }
.btn.danger { background: transparent; color: var(--vs-danger); border-color: var(--vs-danger); }
.btn.danger:hover { background: var(--vs-danger); color: white; }
.btn.sm { padding: 5px 10px; font-size: 10px; }

/* Inputs */
.input, .select, .textarea {
  font-family: var(--vs-font-sans);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--vs-border);
  border-radius: 3px;
  background: var(--vs-surface);
  color: var(--vs-fg1);
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--vs-teal);
  box-shadow: 0 0 0 2px rgba(63,197,225,0.25);
}
.input.num { font-variant-numeric: tabular-nums; text-align: right; }
.textarea { font-family: var(--vs-font-mono); font-size: 12px; resize: vertical; }

/* Precinct grid heatmap */
.precinct-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 4px;
}
.pcell {
  aspect-ratio: 1;
  border-radius: 3px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 80ms, box-shadow 120ms;
  position: relative;
  overflow: hidden;
}
.pcell:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(18,40,84,0.18);
  z-index: 2;
  border-color: var(--vs-navy);
}
.pcell-id {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 12px;
  line-height: 1;
}
.pcell-pct {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.pcell-foot {
  font-size: 9px;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.pcell.has-data { color: white; }
.pcell.no-data { background: var(--vs-grey-100); color: var(--vs-fg3); border: 1px dashed var(--vs-border); }
body[data-theme="dark"] .pcell.no-data { background: var(--vs-surface-2); border-color: var(--vs-border); }

/* Heatmap colors driven by --pct-vs-base (delta).
   Tuned for WCAG AA against white text (≥4.5:1). */
.pcell.t-low      { background: #8E2D26; }   /* deep red */
.pcell.t-belowmid { background: #A84B28; }   /* burnt orange */
.pcell.t-mid      { background: #4F5C73; }   /* slate */
.pcell.t-abovemid { background: #1F8055; }   /* deep emerald */
.pcell.t-high     { background: #14694A; }   /* darker green */
/* Distinct "too early to compare" — has data + has baseline but expected
   value is < 5 so the delta would be wild noise. */
.pcell.t-tooearly {
  background: #1A3568;
  color: white;
  border: 1px solid rgba(63,197,225,0.6);
}
.pcell.t-tooearly .pcell-foot { font-style: italic; opacity: 0.9; }
.pcard.t-tooearly::before { background: #1A3568; }

.legend {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 11px;
  color: var(--vs-fg3);
  flex-wrap: wrap;
}
.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

/* Table */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.tbl th, .tbl td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--vs-border);
}
.tbl th {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--vs-fg3);
  background: var(--vs-surface-2);
  position: sticky;
  top: 0;
  cursor: pointer;
  user-select: none;
}
.tbl th:hover { color: var(--vs-navy); }
body[data-theme="dark"] .tbl th:hover { color: var(--vs-teal); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl tr:hover td { background: var(--vs-grey-100); }
body[data-theme="dark"] .tbl tr:hover td { background: var(--vs-navy-700); }

.delta-pos { color: var(--vs-success); font-weight: 700; }
.delta-neg { color: var(--vs-danger); font-weight: 700; }
.delta-zero { color: var(--vs-fg3); }

.bar-mini {
  display: inline-block;
  width: 100px;
  height: 6px;
  background: var(--vs-grey-200);
  border-radius: 2px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 6px;
}
body[data-theme="dark"] .bar-mini { background: var(--vs-surface-2); }
.bar-mini-fill { height: 100%; background: var(--vs-teal); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,21,48,0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: var(--vs-surface);
  border-radius: 4px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  border-top: 4px solid var(--vs-teal);
}
.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--vs-border);
  display: flex;
  align-items: center;
}
.modal-head h3 {
  font-family: var(--vs-font-display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: var(--vs-navy);
  margin: 0;
}
body[data-theme="dark"] .modal-head h3 { color: white; }
.modal-body { padding: 18px 20px; }
.modal-foot {
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--vs-border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  background: var(--vs-surface);
  position: sticky;
  bottom: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}
.field label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--vs-fg3);
}

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.muted { color: var(--vs-fg3); }
.tabular { font-variant-numeric: tabular-nums; }

/* Stripes for results bars */
.cand-row {
  display: grid;
  grid-template-columns: 32px 1fr 80px 60px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--vs-border-soft);
}
.cand-name { font-weight: 700; }
.cand-name.lowery { color: var(--vs-navy); }
body[data-theme="dark"] .cand-name.lowery { color: var(--vs-teal); }
.cand-bar-wrap { background: var(--vs-grey-200); height: 12px; border-radius: 2px; overflow: hidden; position: relative; }
body[data-theme="dark"] .cand-bar-wrap { background: var(--vs-surface-2); }
.cand-bar-fill { height: 100%; background: var(--vs-grey-400); transition: width 240ms; }
.cand-bar-fill.lowery { background: var(--vs-teal); }
.cand-num { text-align: right; font-family: var(--vs-font-display); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.cand-pct { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.cand-rank { font-family: var(--vs-font-display); font-weight: 900; color: var(--vs-fg3); text-align: center; }

/* Brand bar footer device */
.brand-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 24px;
  margin-top: auto;
  border-top: 1px solid var(--vs-border);
  background: var(--vs-surface);
}
.brand-bar .navy-bar { height: 8px; background: var(--vs-navy); width: 55%; }
.brand-bar .teal-bar { height: 8px; background: var(--vs-teal); width: 20%; }
.brand-bar .credit {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--vs-fg3);
  margin-left: auto;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--vs-navy);
  color: white;
  padding: 10px 18px;
  border-radius: 3px;
  border-left: 4px solid var(--vs-teal);
  font-weight: 700;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(18,40,84,0.3);
  animation: toast-in 220ms cubic-bezier(0.2,0.7,0.2,1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Sortable controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }

/* History card */
.hist-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 800px) { .hist-card { grid-template-columns: 1fr; } }

.stack-bar {
  display: flex;
  height: 22px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--vs-border);
  width: 100%;
}
.stack-bar > div { min-width: 0; }
.stack-ev { background: var(--vs-teal); }
.stack-ed { background: var(--vs-navy); }
.stack-rest { background: var(--vs-grey-200); }
body[data-theme="dark"] .stack-rest { background: var(--vs-surface-2); }

/* Past-election stack: header + bar + legend below the bar */
.estack { margin-bottom: 18px; }
.estack-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 6px;
}
.estack-title { font-size: 13px; line-height: 1.25; }
.estack-meta { font-size: 12px; color: var(--vs-fg3); }
@media (max-width: 540px) {
  .estack-title { font-size: 13px; flex: 1 1 100%; }
  .estack-meta { font-size: 11px; flex: 1 1 100%; }
}
.estack-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--vs-fg2);
  font-variant-numeric: tabular-nums;
}
.estack-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.estack-legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}
.estack-legend .dot-ev { background: var(--vs-teal); }
.estack-legend .dot-ed { background: var(--vs-navy); }
.estack-legend .dot-rest { background: var(--vs-grey-300); }
body[data-theme="dark"] .estack-legend .dot-rest { background: var(--vs-grey-500); }

/* Drilldown — 6 cells of context (Registered, 2022/2023 EDay, 2022/2023 EV,
   Expected). On wide screens lay them out in a single row; on phones force
   2-column so they don't push the whole modal beyond the viewport. */
.drill {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
  margin: 8px 0 4px;
}
@media (max-width: 640px) {
  .drill { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .drill .cell { padding: 6px 8px; min-width: 0; }
  .drill .cell .val { font-size: 16px; }
}
@media (max-width: 380px) {
  .drill .cell .lbl { font-size: 8px; letter-spacing: 0.08em; }
}
.drill .cell {
  padding: 8px 10px;
  background: var(--vs-surface-2);
  border-radius: 3px;
}
.drill .cell .lbl { font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 700; color: var(--vs-fg3); }
.drill .cell .val { font-family: var(--vs-font-display); font-weight: 900; font-size: 18px; color: var(--vs-navy); font-variant-numeric: tabular-nums; }
body[data-theme="dark"] .drill .cell .val { color: white; }

/* Pace projection chart */
.pace-chart {
  position: relative;
  height: 160px;
  border-left: 1px solid var(--vs-border);
  border-bottom: 1px solid var(--vs-border);
  margin: 16px 0 8px;
}
.pace-chart svg { width: 100%; height: 100%; overflow: visible; }

/* ─── Header refresh ──────────────────────────────────────── */
.appbar {
  background:
    radial-gradient(1200px 200px at 90% -20%, rgba(63,197,225,0.18), transparent 60%),
    linear-gradient(180deg, #0F2050 0%, var(--vs-navy) 100%);
  padding: 12px 24px;
  gap: 18px;
}
.appbar-titleblock { display: flex; flex-direction: column; }
.appbar-title { font-size: 20px; }
.appbar-sub { font-size: 11px; }

.client-chip {
  background: rgba(255,255,255,0.97);
  border: 1px solid rgba(63,197,225,0.4);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(7,17,42,0.3), inset 0 0 0 1px rgba(255,255,255,0.5);
}
.client-chip img {
  height: 38px;
  width: auto;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(18,40,84,0.15));
}

/* ─── Polls Countdown ─────────────────────────────────────── */
.polls-state {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 14px 8px 16px;
  border-radius: 6px;
  border: 1px solid rgba(63,197,225,0.35);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
  min-width: 200px;
}
.polls-flag {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--vs-font-sans);
  font-weight: 800;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--vs-teal);
}
.polls-flag .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #2BD999;
  box-shadow: 0 0 0 0 rgba(43,217,153,0.6);
  animation: pulse-dot 1.6s infinite cubic-bezier(0.2,0.7,0.2,1);
}
.polls-flag.pre-open .dot { background: #E8A33C; box-shadow: 0 0 0 0 rgba(232,163,60,0.6); }
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(43,217,153,0.55); }
  70% { box-shadow: 0 0 0 10px rgba(43,217,153,0); }
  100% { box-shadow: 0 0 0 0 rgba(43,217,153,0); }
}
.polls-closed .polls-flag {
  color: #FFB6B6;
}
.polls-closed .polls-flag .dot {
  background: #D43F3F;
  animation: none;
  box-shadow: 0 0 12px rgba(212,63,63,0.6);
}
.countdown {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-family: var(--vs-font-display);
  font-weight: 900;
  color: white;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.cd-num {
  font-size: 28px;
  background: linear-gradient(180deg, #ffffff 0%, #C9E8F2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 0 rgba(0,0,0,0.25);
  min-width: 38px;
  text-align: center;
  display: inline-block;
}
.cd-sep {
  font-size: 22px;
  color: var(--vs-teal);
  opacity: 0.8;
  animation: blink 1s steps(2, end) infinite;
}
.polls-closed .cd-sep { animation: none; }
@keyframes blink { 50% { opacity: 0.2; } }

.polls-sub {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  font-weight: 600;
}

.polls-closed {
  border-color: rgba(212,63,63,0.55);
  background: linear-gradient(180deg, rgba(212,63,63,0.18), rgba(212,63,63,0.04));
}
.polls-closed .polls-flag span:not(.dot) {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: #FFE4E4;
}
.polls-closed .polls-sub { color: rgba(255,228,228,0.8); }
.polls-pre {
  border-color: rgba(232,163,60,0.45);
  background: linear-gradient(180deg, rgba(232,163,60,0.14), rgba(232,163,60,0.02));
}

/* ─── Baseline toggle ─────────────────────────────────────── */
.baseline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 12px;
  background: var(--vs-grey-100);
  border: 1px solid var(--vs-border);
  border-radius: 999px;
  position: relative;
}
body[data-theme="dark"] .baseline-toggle { background: var(--vs-surface-2); }
.bt-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--vs-fg3);
  margin-right: 2px;
}
.bt-btn {
  border: none;
  background: transparent;
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--vs-fg3);
  cursor: pointer;
  transition: all 160ms;
}
.bt-btn:hover { color: var(--vs-navy); }
body[data-theme="dark"] .bt-btn:hover { color: var(--vs-teal); }
.bt-btn.on {
  background: var(--vs-navy);
  color: white;
  box-shadow: 0 2px 6px rgba(18,40,84,0.25), inset 0 0 0 1px rgba(63,197,225,0.4);
}
body[data-theme="dark"] .bt-btn.on { background: var(--vs-teal); color: var(--vs-navy); }
.bt-sub {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--vs-fg3);
  font-weight: 600;
  margin: 0 10px 0 6px;
  white-space: nowrap;
}

/* ─── No-baseline-for-active-year states ─────────────────────
   When a precinct's row simply isn't in the chosen year's baseline
   (e.g. Bartlett doesn't appear in 2023's Memphis-only race), the
   card needs to be visibly different from "we just haven't gotten
   data yet" — regardless of whether a live count has been entered. */

.pcard.nobase-active {
  background:
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(122,138,171,0.06) 12px 13px),
    var(--vs-surface);
  border-color: var(--vs-border);
  border-style: dashed;
}
body[data-theme="dark"] .pcard.nobase-active {
  background:
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(63,197,225,0.05) 12px 13px),
    var(--vs-surface);
}
.pcard.nobase-active::before {
  background: repeating-linear-gradient(
    180deg,
    var(--vs-grey-400) 0 4px,
    transparent 4px 9px
  );
  opacity: 0.7;
}
.pcard.nobase-active .pcard-name,
.pcard.nobase-active .pcard-num {
  color: var(--vs-fg2);
}
body[data-theme="dark"] .pcard.nobase-active .pcard-name,
body[data-theme="dark"] .pcard.nobase-active .pcard-num { color: #C8D4E8; }
.pcard.nobase-active .pcard-vs-val { color: var(--vs-fg3); font-style: italic; font-weight: 400; }

/* Corner badge — top-right ribbon */
.pcard-corner {
  position: absolute;
  top: 8px;
  right: -28px;
  transform: rotate(35deg);
  background: var(--vs-grey-500);
  color: white;
  font-family: var(--vs-font-sans);
  font-weight: 800;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px 32px;
  pointer-events: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 1;
}
.pcard-corner span { white-space: nowrap; }

/* Live-data + no-baseline keeps the dashed teal stripe but the card
   itself uses the muted nobase-active treatment above. */
.pcard.t-nobase.nobase-active::before {
  background: repeating-linear-gradient(
    180deg,
    var(--vs-teal) 0 6px,
    transparent 6px 10px
  );
  opacity: 0.85;
}

.pcard-delta.nobase {
  background: rgba(63,197,225,0.12);
  color: var(--vs-navy);
  border: 1px dashed rgba(63,197,225,0.55);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 2px 8px;
}
body[data-theme="dark"] .pcard-delta.nobase { color: var(--vs-teal); }

/* Heatmap: live-data + no-baseline */
.pcell.t-nobase {
  background: rgba(63,197,225,0.14);
  color: var(--vs-navy);
  border: 1px dashed rgba(63,197,225,0.55);
}
body[data-theme="dark"] .pcell.t-nobase { color: var(--vs-teal); background: rgba(63,197,225,0.08); }
.pcell.t-nobase .pcell-foot { opacity: 0.75; font-style: italic; }

/* Heatmap: no-data + no-baseline (e.g. Bartlett before any entry on 2023 view) */
.pcell.t-nobase-empty {
  background:
    repeating-linear-gradient(135deg, transparent 0 6px, rgba(122,138,171,0.18) 6px 7px),
    var(--vs-grey-100);
  border: 1px dashed var(--vs-grey-400);
  color: var(--vs-fg3);
}
body[data-theme="dark"] .pcell.t-nobase-empty {
  background:
    repeating-linear-gradient(135deg, transparent 0 6px, rgba(63,197,225,0.10) 6px 7px),
    var(--vs-surface-2);
}
.pcell.t-nobase-empty .pcell-foot { font-style: italic; }

/* History strip: missing-year cell — visibly tells the user
   "this precinct didn't run this race" */
.phist.missing .phist-val {
  color: var(--vs-fg3);
  font-family: var(--vs-font-sans);
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-style: italic;
}
.phist.missing {
  background: repeating-linear-gradient(
    135deg,
    var(--vs-grey-100) 0 6px,
    var(--vs-grey-200) 6px 7px
  );
  border-style: dashed;
}
body[data-theme="dark"] .phist.missing {
  background: repeating-linear-gradient(
    135deg,
    var(--vs-surface-2) 0 6px,
    rgba(63,197,225,0.05) 6px 7px
  );
}
/* If active year is also missing, keep highlight outline but
   inside fill stays striped so user clearly sees "no data here" */
.phist.active.missing {
  background: repeating-linear-gradient(
    135deg,
    var(--vs-navy-700) 0 6px,
    var(--vs-navy) 6px 7px
  );
  border-color: var(--vs-navy);
  box-shadow: 0 0 0 2px rgba(63,197,225,0.3);
}
.phist.active.missing .phist-val { color: rgba(255,255,255,0.6); }
.phist.active.missing .phist-yr { color: var(--vs-teal); }

.kpi-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 2px 6px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--vs-grey-100);
  color: var(--vs-fg3);
  border: 1px solid var(--vs-border);
  vertical-align: middle;
  text-transform: uppercase;
}
body[data-theme="dark"] .kpi-tag { background: var(--vs-surface-2); }
.kpi-cov {
  color: var(--vs-fg3);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: none;
}

/* KPI label info button + popover */
.kpi-label { display: flex; align-items: center; gap: 6px; }
.kpi-info { position: relative; display: inline-flex; }
.kpi-info-btn {
  border: 1px solid var(--vs-border);
  background: var(--vs-grey-100);
  color: var(--vs-fg3);
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 10px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-style: italic;
  transition: all 140ms;
}
body[data-theme="dark"] .kpi-info-btn { background: var(--vs-surface-2); }
.kpi-info-btn:hover {
  background: var(--vs-navy);
  color: white;
  border-color: var(--vs-navy);
}
.kpi-info-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;        /* default: anchor right so rightmost tile doesn't overflow */
  left: auto;
  z-index: 30;
  width: min(320px, 86vw);
  background: var(--vs-navy);
  color: white;
  border-radius: 4px;
  padding: 10px 30px 10px 12px;
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  font-weight: 400;
  text-transform: none;
  font-family: var(--vs-font-sans);
  box-shadow: 0 12px 32px rgba(7,17,42,0.4);
  border-top: 3px solid var(--vs-teal);
}
.kpi-info-close {
  position: absolute;
  top: 4px;
  right: 4px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 18px;
  line-height: 1;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
}
.kpi-info-close:hover { color: white; background: rgba(255,255,255,0.1); }

/* Anchor leftmost two KPI tiles' popovers to the LEFT instead of right
   so they don't fly off-screen on narrow viewports. */
.kpi-row > .kpi:nth-child(1) .kpi-info-pop,
.kpi-row > .kpi:nth-child(2) .kpi-info-pop { left: 0; right: auto; }

/* Polls-closed banner */
.closed-banner {
  background: linear-gradient(90deg, rgba(212,63,63,0.12), rgba(212,63,63,0.04));
  border-bottom: 2px solid rgba(212,63,63,0.45);
  color: var(--vs-navy);
  padding: 10px 24px;
  font-size: 13px;
  text-align: center;
  letter-spacing: 0.02em;
}
body[data-theme="dark"] .closed-banner {
  background: linear-gradient(90deg, rgba(212,63,63,0.32), rgba(212,63,63,0.18));
  color: white;
  border-bottom-color: rgba(212,63,63,0.7);
}
.closed-banner strong {
  font-family: var(--vs-font-display);
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-right: 6px;
}
.app.polls-closed .kpi.accent { filter: saturate(0.7); }

.kpi-sub b { font-weight: 800; }

.kpi-explainer {
  margin: 0 0 16px;
}
.kpi-explainer details {
  background: var(--vs-surface);
  border: 1px solid var(--vs-border);
  border-left: 3px solid var(--vs-teal);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.55;
}
.kpi-explainer summary {
  cursor: pointer;
  font-family: var(--vs-font-sans);
  font-weight: 700;
  color: var(--vs-navy);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
body[data-theme="dark"] .kpi-explainer summary { color: var(--vs-teal); }
.kpi-explainer summary::-webkit-details-marker { display: none; }
.kpi-explainer summary::before {
  content: '?';
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 11px;
  background: var(--vs-teal);
  color: var(--vs-navy);
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-explainer details[open] summary { margin-bottom: 8px; }
.kpi-explainer ul,
.kpi-explainer ol {
  margin: 4px 0 4px 4px;
  padding-left: 18px;
  color: var(--vs-fg2);
}
.kpi-explainer li { margin-bottom: 6px; }
.kpi-explainer li b { color: var(--vs-navy); font-weight: 800; }
body[data-theme="dark"] .kpi-explainer li b { color: var(--vs-teal); }
.kpi-explainer p b { color: var(--vs-navy); font-weight: 800; }
body[data-theme="dark"] .kpi-explainer p b { color: var(--vs-teal); }

/* Entry row in PrecinctModal */
.entry-row {
  display: grid;
  grid-template-columns: 1fr 1.3fr auto;
  gap: 8px;
  align-items: end;
}
.entry-row .field { margin-bottom: 0; }
.entry-row .entry-add { height: 38px; align-self: end; }
@media (max-width: 540px) {
  .entry-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .entry-row .entry-add {
    grid-column: 1 / -1;
    width: 100%;
    height: 44px;
    margin-top: 4px;
  }
  /* Datetime-local renders 'May 5, 2026 at 01:32 AM' — give it the full row */
  .entry-row .field { min-width: 0; }
  .entry-row .input { min-width: 0; width: 100%; }
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 540px) { .results-grid { grid-template-columns: 1fr; } }

.link-btn {
  background: transparent;
  border: none;
  padding: 0 0 0 8px;
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--vs-teal);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover { color: var(--vs-navy); }
body[data-theme="dark"] .link-btn:hover { color: white; }
.field label { display: flex; align-items: baseline; gap: 4px; }

/* Toast - clickable for undo */
.toast.has-action { cursor: pointer; }
.toast.has-action:hover { background: var(--vs-navy-700); }

.filter-input { width: 220px; }
@media (max-width: 640px) {
  .filter-input { width: 100%; }

  /* Legend stacks neatly into 2 columns on phones */
  .legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 14px;
    align-items: start;
  }
  .legend > span:last-child { grid-column: 1 / -1; margin-left: 0 !important; }

  /* Cap explainer height so the precinct grid stays accessible */
  .kpi-explainer details[open] { max-height: 50vh; overflow-y: auto; }
}

/* Focus rings — punchier on dark mode */
body[data-theme="dark"] .pcard:focus-visible,
body[data-theme="dark"] .pcell:focus-visible,
body[data-theme="dark"] .bt-btn:focus-visible,
body[data-theme="dark"] .vbtn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--vs-teal);
}

/* Latest-entry timestamp chip on cards */
.pcard-ts {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--vs-font-sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pcard-ts.fresh {
  background: rgba(31,128,85,0.14);
  color: #14694A;
  border: 1px solid rgba(31,128,85,0.35);
}
body[data-theme="dark"] .pcard-ts.fresh { color: #6FE2A8; background: rgba(31,128,85,0.22); }
.pcard-ts.stale {
  background: rgba(232,163,60,0.14);
  color: #8C5E1B;
  border: 1px solid rgba(232,163,60,0.45);
}
body[data-theme="dark"] .pcard-ts.stale { color: #F4C880; background: rgba(232,163,60,0.22); }

/* Jump-to-next button */
.jump-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: linear-gradient(90deg, rgba(63,197,225,0.10), rgba(63,197,225,0.03));
  border: 1px solid rgba(63,197,225,0.45);
  border-left: 3px solid var(--vs-teal);
  border-radius: 4px;
}
.jump-bar .jump-msg {
  flex: 1;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--vs-fg2);
}
.jump-bar .jump-msg b {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 14px;
  color: var(--vs-navy);
  font-variant-numeric: tabular-nums;
}
body[data-theme="dark"] .jump-bar .jump-msg b { color: var(--vs-teal); }

/* Empty state banner */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  border: 1px dashed var(--vs-border);
  border-radius: 6px;
  background: var(--vs-surface);
  color: var(--vs-fg2);
}
.empty-state h3 {
  font-family: var(--vs-font-display);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 16px;
  color: var(--vs-navy);
  margin: 0 0 6px;
}
body[data-theme="dark"] .empty-state h3 { color: white; }
.empty-state p { margin: 4px auto 0; max-width: 460px; font-size: 13px; }

/* Bulk-entry preview list */
.bulk-preview {
  margin-top: 8px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--vs-border);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: var(--vs-font-mono);
  font-size: 11px;
  background: var(--vs-grey-100);
}
body[data-theme="dark"] .bulk-preview { background: var(--vs-surface-2); }
.bulk-preview-row { display: flex; gap: 8px; padding: 2px 0; align-items: center; }
.bulk-preview-row.ok { color: #14694A; }
body[data-theme="dark"] .bulk-preview-row.ok { color: #6FE2A8; }
.bulk-preview-row.bad { color: #8E2D26; }
body[data-theme="dark"] .bulk-preview-row.bad { color: #F4A8A8; }
.bulk-preview-summary {
  margin-top: 6px;
  font-size: 11px;
  color: var(--vs-fg3);
  letter-spacing: 0.04em;
}

/* ─── View switch ─────────────────────────────────────────── */
.view-switch {
  display: inline-flex;
  background: var(--vs-grey-100);
  border: 1px solid var(--vs-border);
  border-radius: 4px;
  padding: 2px;
  gap: 0;
}
body[data-theme="dark"] .view-switch { background: var(--vs-surface-2); }
.vbtn {
  border: none;
  background: transparent;
  font-family: var(--vs-font-sans);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 7px 12px;
  border-radius: 3px;
  color: var(--vs-fg3);
  cursor: pointer;
  transition: all 140ms;
}
.vbtn:hover { color: var(--vs-navy); }
body[data-theme="dark"] .vbtn:hover { color: var(--vs-teal); }
.vbtn.on {
  background: white;
  color: var(--vs-navy);
  box-shadow: 0 1px 2px rgba(18,40,84,0.12);
}
body[data-theme="dark"] .vbtn.on { background: var(--vs-navy-700); color: white; }

/* ─── Precinct Cards (the pretty grid) ────────────────────── */
.precinct-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.pcard {
  text-align: left;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 14px 12px;
  border-radius: 6px;
  border: 1px solid var(--vs-border);
  background: var(--vs-surface);
  cursor: pointer;
  transition: transform 120ms cubic-bezier(0.2,0.8,0.2,1), box-shadow 160ms, border-color 120ms;
  overflow: hidden;
  font-family: inherit;
  color: inherit;
}
.pcard::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--vs-grey-300);
  transition: background 200ms;
}
.pcard:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(18,40,84,0.14);
  border-color: var(--vs-navy);
}
.pcard.no-data {
  border-style: dashed;
  background: repeating-linear-gradient(135deg, var(--vs-surface) 0 8px, var(--vs-surface-2) 8px 16px);
}
.pcard.no-data::before { background: var(--vs-grey-300); }
.pcard.t-low::before      { background: #8E2D26; }
.pcard.t-belowmid::before { background: #A84B28; }
.pcard.t-mid::before      { background: #4F5C73; }
.pcard.t-abovemid::before { background: #1F8055; }
.pcard.t-high::before     { background: #14694A; }

.pcard-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-left: 4px;
}
.pcard-head-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.pcard-id {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--vs-navy);
  background: var(--vs-grey-100);
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--vs-border);
}
body[data-theme="dark"] .pcard-id { background: var(--vs-surface-2); color: var(--vs-teal); }
.pcard-delta {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.pcard-delta.up   { background: rgba(43,168,114,0.14); color: #1A8B5F; border: 1px solid rgba(43,168,114,0.35); }
.pcard-delta.down { background: rgba(212,63,63,0.12); color: #B0382F; border: 1px solid rgba(212,63,63,0.35); }
.pcard-delta.flat { background: var(--vs-grey-100); color: var(--vs-fg3); border: 1px solid var(--vs-border); }
.pcard-delta.no   { background: transparent; color: var(--vs-fg3); border: 1px dashed var(--vs-border); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; padding: 2px 8px; }

.pcard-name {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 15px;
  line-height: 1.15;
  color: var(--vs-navy);
  margin: 6px 0 0 4px;
  letter-spacing: -0.005em;
  /* show full names; allow up to 2 lines */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body[data-theme="dark"] .pcard-name { color: white; }
.pcard-city {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--vs-fg3);
  margin: 0 0 4px 4px;
  font-weight: 700;
}
.pcard-stats {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 6px 0 0 4px;
}
.pcard-num {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 32px;
  line-height: 0.95;
  color: var(--vs-navy);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
body[data-theme="dark"] .pcard-num { color: white; }
.pcard.no-data .pcard-num { color: var(--vs-fg3); }
.pcard-vs {
  margin-left: auto;
  text-align: right;
  line-height: 1.15;
}
.pcard-vs-lbl {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--vs-fg3);
  font-weight: 700;
}
.pcard-vs-val {
  font-family: var(--vs-font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--vs-fg2);
  font-variant-numeric: tabular-nums;
}
.pcard-bar {
  height: 4px;
  background: var(--vs-grey-200);
  border-radius: 2px;
  overflow: hidden;
  margin: 10px 4px 0;
}
body[data-theme="dark"] .pcard-bar { background: var(--vs-surface-2); }
.pcard-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--vs-teal) 0%, var(--vs-navy) 100%);
  transition: width 320ms cubic-bezier(0.2,0.8,0.2,1);
}

/* Historical EDay strip — always shows both 2022 + 2023 EDay totals */
.pcard-history {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 8px 4px 0;
}
.phist {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid var(--vs-border);
  border-radius: 3px;
  background: var(--vs-grey-100);
  transition: all 180ms;
}
body[data-theme="dark"] .phist { background: var(--vs-surface-2); }
.phist-yr {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--vs-fg3);
  text-transform: uppercase;
}
.phist-val {
  font-family: var(--vs-font-display);
  font-weight: 900;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--vs-fg2);
  letter-spacing: -0.01em;
}
.phist.active {
  background: var(--vs-navy);
  border-color: var(--vs-navy);
  box-shadow: 0 0 0 2px rgba(63,197,225,0.3);
}
.phist.active .phist-yr { color: var(--vs-teal); }
.phist.active .phist-val { color: white; }
body[data-theme="dark"] .phist.active { background: var(--vs-teal); border-color: var(--vs-teal); }
body[data-theme="dark"] .phist.active .phist-yr { color: var(--vs-navy); }
body[data-theme="dark"] .phist.active .phist-val { color: var(--vs-navy); }
.pcard.t-low .pcard-bar-fill   { background: linear-gradient(90deg, #A84B28, #8E2D26); }
.pcard.t-high .pcard-bar-fill  { background: linear-gradient(90deg, #1F8055, #14694A); }
.pcard-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--vs-fg2);
  margin: 6px 4px 0;
  font-variant-numeric: tabular-nums;
}

/* Slight focus ring for keyboard nav */
.pcard:focus-visible,
.bt-btn:focus-visible,
.vbtn:focus-visible {
  outline: 2px solid var(--vs-teal);
  outline-offset: 2px;
}

/* ─── Responsive / Mobile ─────────────────────────────────── */

/* Tablet */
@media (max-width: 900px) {
  .page { padding: 16px; }
  .appbar { padding: 10px 16px; gap: 12px; }
  .tabs { padding: 0 16px; top: auto; position: static; }
  .appbar { position: static; }
  .kpi-row { gap: 8px; }
  .kpi { padding: 14px 14px; }
  .kpi-value { font-size: 26px; }
  .section-head { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .section-head .row { width: 100%; }
  .section-head .input { flex: 1; min-width: 160px; width: auto !important; }
  .section-body { padding: 14px; }
  .precinct-cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
  .pcard { padding: 12px 12px 10px; }
  .pcard-name { font-size: 14px; }
  .pcard-num { font-size: 28px; }
  .baseline-toggle { padding: 4px 4px 4px 10px; }
  .bt-sub { display: none; } /* keep on title attribute, free up space */
  .modal { max-width: 100% !important; max-height: 100vh; border-radius: 0; border-top-width: 4px; }
  .modal-backdrop { padding: 0; }
  .modal-head { padding: 12px 14px; gap: 8px; flex-wrap: wrap; }
  .modal-head h3 { font-size: 14px; word-break: break-word; }
  .modal-body { padding: 14px; }
  .legend { font-size: 10px; gap: 8px; }
  .brand-bar { padding: 16px; }
}

/* Phone */
@media (max-width: 640px) {
  .page { padding: 12px; }
  .appbar {
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
    border-bottom-width: 3px;
  }
  .appbar-titleblock { order: 2; flex: 1 1 auto; min-width: 0; }
  .appbar-title { font-size: 17px; line-height: 1.05; }
  .appbar-sub { font-size: 10px; letter-spacing: 0.1em; }
  .client-chip { order: 1; padding: 4px 10px; }
  .client-chip img { height: 32px; }
  .appbar-spacer { display: none; }
  .polls-state {
    order: 3;
    flex: 1 0 100%;
    align-items: stretch;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 8px 12px;
    min-width: 0;
  }
  .polls-flag { flex: 0 0 auto; }
  .countdown { flex: 1 1 auto; justify-content: flex-end; }
  .cd-num { font-size: 24px; min-width: 32px; }
  .cd-sep { font-size: 18px; }
  .polls-sub { flex: 1 0 100%; text-align: right; }
  .polls-closed .polls-flag span:not(.dot) { font-size: 16px; }
  .tabs {
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 12px 14px; font-size: 12px; flex-shrink: 0; }
  .tab-count { font-size: 9px; padding: 1px 5px; }

  .kpi-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-label { font-size: 9px; letter-spacing: 0.12em; }
  .kpi-value { font-size: 22px; }
  .kpi-sub { font-size: 11px; }
  .kpi-tag { font-size: 8px; padding: 1px 4px; }

  .section-head { padding: 12px; }
  .section-title { font-size: 13px; }
  .section-head .row {
    gap: 6px;
    flex-wrap: wrap;
  }
  .baseline-toggle {
    padding: 3px 4px 3px 8px;
    flex: 1 1 auto;
    justify-content: center;
  }
  .bt-label { font-size: 9px; letter-spacing: 0.1em; }
  .bt-btn { padding: 5px 12px; font-size: 12px; }
  .view-switch { flex: 1 1 auto; justify-content: center; }
  .vbtn { padding: 6px 10px; font-size: 10px; flex: 1; }
  .section-head .btn { flex: 1 1 100%; }
  .section-head .input { flex: 1 1 100%; min-width: 0; }

  .legend {
    font-size: 10px;
    gap: 8px 14px;
    line-height: 1.5;
  }
  .legend > span:last-child { flex: 1 0 100%; margin-left: 0 !important; }

  .precinct-cards { grid-template-columns: 1fr 1fr; gap: 6px; }
  .pcard { padding: 10px 10px 8px; gap: 2px; }
  .pcard-id { font-size: 11px; padding: 1px 6px; }
  .pcard-delta { font-size: 11px; padding: 2px 6px; }
  .pcard-delta.no, .pcard-delta.nobase { font-size: 9px; padding: 2px 6px; }
  .pcard-name { font-size: 13px; line-height: 1.1; -webkit-line-clamp: 2; }
  .pcard-city { font-size: 10px; letter-spacing: 0.1em; }
  .pcard-num { font-size: 24px; }
  .pcard-vs-lbl { font-size: 8px; letter-spacing: 0.1em; }
  .pcard-vs-val { font-size: 13px; }
  .pcard-foot { font-size: 9px; }

  /* heatmap cells: smaller minimum */
  .precinct-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 3px; }
  .pcell { padding: 4px; }
  .pcell-id { font-size: 11px; }
  .pcell-pct { font-size: 12px; }
  .pcell-foot { font-size: 8px; }

  /* tables: convert to horizontally scrollable */
  .tbl { font-size: 11px; }
  .tbl th, .tbl td { padding: 6px 8px; }

  .toast { left: 12px; right: 12px; transform: none; bottom: 12px; }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .brand-bar { padding: 14px 12px; }
  .brand-bar .credit { font-size: 9px; letter-spacing: 0.12em; }

  /* hist-card / drill: stack */
  .drill { grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
  .drill .cell { padding: 6px 8px; }
  .drill .cell .val { font-size: 15px; }
}

/* Small phone */
@media (max-width: 420px) {
  .precinct-cards { grid-template-columns: 1fr; }
  .pcard-name { -webkit-line-clamp: 3; }
  .kpi-row { grid-template-columns: 1fr; }
  .appbar-sub { display: none; }
  .countdown { gap: 1px; }
  .cd-num { font-size: 22px; min-width: 28px; }
  .cd-sep { font-size: 16px; }
}

/* Touch devices: bigger hit targets, no hover lift */
@media (hover: none) {
  .pcard:hover, .pcell:hover { transform: none; box-shadow: none; }
  .tab, .vbtn, .bt-btn, .btn { min-height: 40px; }
}

/* JumpToNext bar stacks on small phones so the button is easy to tap */
@media (max-width: 540px) {
  .jump-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .jump-bar .btn {
    width: 100%;
    min-height: 44px;
  }
  .jump-bar .jump-msg { text-align: center; }

  /* Modal body gets bottom padding so the textarea / fields scroll clear
     of the now-sticky modal footer when the soft keyboard is up */
  .modal-body { padding-bottom: 24px; }
}

/* Hide the latest-entry chip on small phones — the delta pill is the
   primary glance signal; freshness is still visible in the modal/footer */
@media (max-width: 420px) {
  .pcard-ts { display: none; }

  /* Replace the rotated ribbon with a flat top-right tag at small widths
     so the "no '23 race" copy never gets clipped */
  .pcard-corner {
    top: 6px;
    right: 6px;
    transform: none;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 8px;
    letter-spacing: 0.1em;
  }
}

/* Force info popovers to anchor left on tiny phones so a right-anchored
   popover on a full-width KPI tile doesn't flutter against the right edge */
@media (max-width: 380px) {
  .kpi-info-pop,
  .kpi-row > .kpi:nth-child(1) .kpi-info-pop,
  .kpi-row > .kpi:nth-child(2) .kpi-info-pop {
    left: 0;
    right: auto;
    width: min(300px, 92vw);
  }
}
