:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #1c2230;
  --muted: #5d6474;
  --line: #dedad2;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --accent: #b8352b;
  --rep: #c8382e;
  --dem: #2a5ea8;
  --oth: #6f7684;
  --ok: #1f7a4d;
  --ok-bg: #e5f3eb;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --err: #a12a22;
  --err-bg: #fbe7e5;
  --info-bg: #e7eef8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 25, 40, .06), 0 2px 8px rgba(20, 25, 40, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --surface: #1b1f29; --surface-2: #222734; --ink: #e9ecf2; --muted: #a1a8b8;
    --line: #2f3545; --brand: #172a45; --accent: #ef6b5f; --rep: #e5574c; --dem: #5b8fe0; --oth: #8f97a6;
    --ok: #59c48c; --ok-bg: #173126; --warn: #f0be5a; --warn-bg: #3a2e12; --err: #ff8a80; --err-bg: #3d1c1a;
    --info-bg: #1b2a40; --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--dem); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.inline { display: inline; }
code { font-size: .85em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* ---- masthead ---- */
.masthead { background: var(--brand); color: var(--brand-ink); border-bottom: 4px solid var(--accent); }
.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.brand { color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.brand-county { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; opacity: .8; }
.brand-title { font-size: 1.3rem; font-weight: 700; letter-spacing: .01em; }
.nav { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; font-size: .93rem; }
.nav a, .nav .linklike { color: var(--brand-ink); text-decoration: none; opacity: .9; }
.nav a:hover, .nav .linklike:hover { opacity: 1; text-decoration: underline; }
.nav-user { padding-left: 12px; border-left: 1px solid rgba(255,255,255,.3); }
.nav-user small { opacity: .7; margin-left: 4px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

main.wrap { padding-top: 20px; padding-bottom: 32px; min-height: 60vh; }
.footer { color: var(--muted); font-size: .85rem; padding-bottom: 24px; }

/* ---- flash ---- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 14px; border: 1px solid transparent; }
.flash ul { margin: 6px 0 0 18px; padding: 0; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--err-bg); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.flash-info { background: var(--info-bg); }
.flash-temp { background: var(--warn-bg); color: var(--warn); font-weight: 600; border-color: var(--warn); font-size: 1.05rem; }

/* ---- hero & summary ---- */
.hero { text-align: center; padding: 8px 0 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .8rem; color: var(--muted); margin: 0 0 4px; }
.hero h1 { font-size: 2.1rem; }
.unofficial { display: inline-block; color: var(--accent); border: 2px solid var(--accent); font-weight: 800; letter-spacing: .16em; font-size: .78rem; padding: 3px 10px; border-radius: 3px; margin: 2px 0 10px; }
.hero-note { color: var(--muted); max-width: 640px; margin: 0 auto; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat-label { display: block; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { display: block; font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .95rem; color: var(--muted); font-weight: 500; }
.stat-small { font-size: 1.1rem; padding-top: 6px; }
.meter { display: block; height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--ok); }

.jump { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 2; }
.jump a { text-decoration: none; color: var(--ink); background: var(--surface); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; font-size: .85rem; }
.jump a:hover { border-color: var(--brand); }
@media (max-width: 640px) { .jump { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; } .jump a { flex: 0 0 auto; } }

.category { margin-bottom: 26px; scroll-margin-top: 56px; }
.category > h2 { border-bottom: 2px solid var(--line); padding-bottom: 6px; }
.race-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
@media (max-width: 420px) { .race-grid { grid-template-columns: 1fr; } }

/* ---- race card ---- */
.race { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.race-complete { border-top: 3px solid var(--ok); }
.race-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.race-head h3 { margin: 0; }
.race-head h3 a { color: var(--ink); text-decoration: none; }
.race-head h3 a:hover { text-decoration: underline; }
.race-meta { display: flex; gap: 8px; align-items: center; }
.reporting { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.reporting-done { color: var(--ok); font-weight: 600; }
.race-note { font-size: .82rem; color: var(--muted); margin: 4px 0 0; }
.pill { font-size: .72rem; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 7px; border-radius: 999px; white-space: nowrap; }

.tally { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.tally td { padding: 6px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tally .cand { padding-right: 8px; }
.cand-name { font-weight: 600; }
.cand-party { display: block; font-size: .76rem; color: var(--muted); margin-left: 16px; }
.lead-mark { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; background: var(--ok-bg); color: var(--ok); padding: 1px 6px; border-radius: 3px; margin-left: 6px; font-weight: 700; }
.writein .cand-name { font-weight: 400; font-style: italic; }
.bar-cell { width: 28%; padding-right: 8px !important; }
.bar { display: block; height: 10px; border-radius: 2px; min-width: 1px; background: var(--oth); }
.bar-rep { background: var(--rep); } .bar-dem { background: var(--dem); } .bar-oth, .bar-none { background: var(--oth); }
.pct { width: 52px; text-align: right; color: var(--muted); font-size: .9rem; }
.votes { width: 70px; text-align: right; font-weight: 700; }
.tally tfoot td { border-bottom: 0; font-size: .82rem; color: var(--muted); padding-top: 6px; }
.tally tfoot .votes { color: var(--ink); }
.leading .cand-name { color: var(--ink); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; background: var(--oth); }
.dot-rep { background: var(--rep); } .dot-dem { background: var(--dem); } .dot-none { background: transparent; border: 1px solid var(--line); }

.refresh-note, .empty { color: var(--muted); text-align: center; font-size: .88rem; }
.stale { opacity: .65; }

/* ---- badges ---- */
.badge { display: inline-block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 7px; border-radius: 3px; white-space: nowrap; }
.badge-reported { background: var(--ok-bg); color: var(--ok); }
.badge-draft { background: var(--warn-bg); color: var(--warn); }
.badge-none { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---- page chrome ---- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.crumb { margin: 0 0 6px; font-size: .9rem; }
.crumb a { text-decoration: none; }
.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.toggle a { padding: 6px 12px; text-decoration: none; color: var(--ink); font-size: .88rem; }
.toggle a.on { background: var(--brand); color: #fff; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 24px auto; }
.card.danger { border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 18px; border-bottom: 1px solid var(--line); }
.subnav a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.subnav a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.kv { list-style: none; margin: 0 0 8px; padding: 0; }
.kv li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }

/* ---- forms ---- */
label { display: block; font-size: .9rem; font-weight: 600; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; width: 100%; margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--dem) 60%, transparent); outline-offset: 1px; border-color: var(--dem); }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.wrap-row { flex-wrap: wrap; }
.wrap-row label { flex: 1 1 160px; }
.wrap-row label.check { flex: 0 0 auto; padding-bottom: 10px; }
label.check { font-weight: 400; display: flex; align-items: center; }
.num-input { max-width: 120px; text-align: right; }
.short { max-width: 90px; }
.filter { max-width: 280px; }
.btn {
  display: inline-block; font: inherit; font-weight: 600; font-size: .92rem; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-danger { background: var(--err); color: #fff; border-color: var(--err); }
.btn-danger-text { color: var(--err); }
.btn-small { padding: 4px 9px; font-size: .8rem; }
.switch-row { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: var(--radius); background: var(--err-bg); font-weight: 400; }
.switch-row.is-on { background: var(--ok-bg); }
.switch-row input { margin-top: 4px; transform: scale(1.3); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 6px 14px; }

/* ---- tables ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.card .list { margin: 0; }
table.list, table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th, .list td, .grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.list th, .grid th { background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.list td input, .list td select { margin-top: 0; padding: 5px 8px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.grid th.num { white-space: normal; min-width: 90px; }
.grid tfoot td { font-weight: 700; background: var(--surface-2); }
.grid .pct-row td { font-weight: 400; color: var(--muted); }
.grid .sticky { position: sticky; left: 0; background: var(--surface); min-width: 210px; }
.grid thead .sticky, .grid tfoot .sticky { background: var(--surface-2); }
.not-shown td { color: var(--muted); }
.inactive td { opacity: .55; }
.audit .detail { max-width: 560px; font-size: .85rem; }
.act-results td:first-child { border-left: 3px solid var(--ok); }
.act-login td:first-child { border-left: 3px solid var(--line); }

/* ---- status board & picker ---- */
.board { margin-bottom: 22px; }
.board-grid, .pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.board-cell, .pick { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); border-left-width: 5px; text-decoration: none; color: var(--ink); }
a.board-cell:hover, .pick:hover { border-color: var(--brand); }
.st-reported { border-left-color: var(--ok); }
.st-draft { border-left-color: var(--warn); }
.st-none { border-left-color: var(--line); }
.board-name, .pick-name { font-weight: 600; }
.board-meta, .pick-meta { font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.pick-code { font-size: .75rem; color: var(--muted); font-weight: 700; letter-spacing: .05em; }
.pick { min-height: 88px; }

/* ---- entry form ---- */
.entry { max-width: 760px; }
.ballots-calc { display: block; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.ballots-source { border-left: 4px solid var(--brand); }
.entry-ballots .ballots input { font-size: 1.4rem; max-width: 220px; text-align: right; font-weight: 700; }
.entry-race { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 10px; margin: 0 0 12px; }
.entry-race legend { font-weight: 700; padding: 0 6px; margin-left: -6px; }
.entry-race.over { border-color: var(--err); background: color-mix(in srgb, var(--err-bg) 60%, var(--surface)); }
.entry-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-weight: 400; }
.entry-row:last-of-type { border-bottom: 0; }
.entry-cand { flex: 1; }
.entry-row input { width: 130px; flex: 0 0 130px; margin: 0; text-align: right; font-size: 1.15rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.entry-row input.invalid { border-color: var(--err); background: var(--err-bg); }
.entry-row input:disabled { background: var(--surface-2); color: var(--ink); }
.entry-total { text-align: right; font-size: .88rem; color: var(--muted); padding-top: 6px; }
.entry-warn { color: var(--err); font-weight: 700; margin-left: 8px; }
.entry-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); }
.entry-actions .btn { padding: 11px 18px; font-size: 1rem; }
.confirm { font-weight: 600; color: var(--err); display: flex; align-items: center; margin-right: auto; }


/* ---- voter data page ---- */
.stat-wide { grid-column: span 2; }
@media (max-width: 560px) { .stat-wide { grid-column: auto; } }
.stat-xl { font-size: 2.6rem; }
.chg { font-variant-numeric: tabular-nums; white-space: nowrap; }
.chg small { font-weight: 500; }
.chg .arrow { font-size: .7em; color: var(--muted); margin-right: 3px; vertical-align: 1px; }
.stat .chg { font-size: 1.5rem; }
.hbars { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.hbars th, .hbars td { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.hbars th { text-align: left; font-weight: 600; white-space: nowrap; padding-right: 10px; }
.hbars td.num { width: 70px; padding-left: 8px; }
.hbar-track { width: 55%; }
.hbar-track .bar { height: 12px; }
.split { display: flex; height: 26px; border-radius: 4px; overflow: hidden; margin: 6px 0 14px; background: var(--surface-2); }
.split span { display: block; height: 100%; }
.split-female { background: #7a4f9e; }
.split-male { background: #2f8f83; }
.split-not-specified { background: var(--line); }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 7px; vertical-align: middle; }
.sex-kv li > span { display: flex; align-items: center; }
.trend-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px 24px; margin-bottom: 8px; }
.trend h3 { font-size: .95rem; margin-bottom: 6px; }
.trend-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-variant-numeric: tabular-nums; font-size: .9rem; }
.trend-year { width: 40px; color: var(--muted); }
.trend-row .hbar-track { flex: 1; }
.trend-row .num { width: 60px; }
.bar.yr-1 { opacity: .45; } .bar.yr-2 { opacity: .7; } .bar.yr-3 { opacity: 1; }
.compare td small { font-size: .75rem; }
.compare tfoot td { font-weight: 700; background: var(--surface-2); }


/* ---- ties ---- */
.race-tied { border: 2px solid var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.tie-badge { display: inline-block; background: var(--warn); color: #fff; font-size: .7rem; font-weight: 800; letter-spacing: .1em; padding: 2px 8px; border-radius: 3px; }
@media (prefers-color-scheme: dark) { .tie-badge { color: #1b1f29; } }
.tie-note { background: var(--warn-bg); color: var(--warn); font-size: .85rem; padding: 6px 10px; border-radius: 6px; margin: 8px 0 0; }
.tie-banner { font-size: .95rem; padding: 10px 14px; margin-bottom: 12px; }
.tally tr.tied td { background: var(--warn-bg); }
.tally tr.tied td:first-child { box-shadow: inset 3px 0 0 var(--warn); padding-left: 6px; }
.lead-mark, .tie-mark { display: inline-block; white-space: nowrap; margin-top: 3px; }
.tie-mark { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; background: var(--warn); color: #fff; padding: 1px 6px; border-radius: 3px; margin-left: 6px; font-weight: 700; }
@media (prefers-color-scheme: dark) { .tie-mark { color: #1b1f29; } }
.grid .tied-col { background: var(--warn-bg); }

@media print {
  .masthead, .nav, .jump, .toggle, .subnav, .entry-actions, .refresh-note { display: none !important; }
  body { background: #fff; color: #000; }
  .race, .card, .stat { box-shadow: none; break-inside: avoid; }
}
