:root {
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --ink: #15181c;
  --ink-2: #4a5059;
  --muted: #9aa0a8;
  --line: #e2e0da;
  --track: #ebe9e3;
  --accent: #15181c;
  --hatch-bg: #f1efea;
  --hatch-line: #d6d3cb;
  --ok: #1d8a4e;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1013; --surface: #161a1f; --ink: #eef0f2; --ink-2: #b4bac2; --muted: #6f7782;
    --line: #262c33; --track: #232930; --accent: #eef0f2; --hatch-bg: #1b2026; --hatch-line: #2e353d;
    --ok: #38b26c; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1013; --surface: #161a1f; --ink: #eef0f2; --ink-2: #b4bac2; --muted: #6f7782;
  --line: #262c33; --track: #232930; --accent: #eef0f2; --hatch-bg: #1b2026; --hatch-line: #2e353d;
  --ok: #38b26c; --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: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
[hidden] { display: none !important; }

/* Cabeçalho */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top-in { display: flex; align-items: center; gap: 16px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand h1 { font-size: 20px; }
.brand p { margin: 0; }
.logo { display: inline-flex; align-items: flex-end; gap: 3px; height: 28px; }
.logo i { width: 7px; border-radius: 2px; }
.logo i:nth-child(1) { height: 14px; background: #1f5fc8; }
.logo i:nth-child(2) { height: 26px; background: #c8102e; }
.logo i:nth-child(3) { height: 19px; background: var(--ink); }
.rounds { display: inline-flex; background: var(--track); border-radius: 999px; padding: 3px; }
.rounds button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.rounds button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.top-actions { display: flex; gap: 8px; }
.ghost { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.ghost:hover { border-color: var(--muted); }
.ghost.icon { width: 36px; padding: 6px 0; display: inline-grid; place-items: center; }
.ghost.small { padding: 3px 10px; font-size: 13px; }

/* Status */
.status-bar { margin: 20px 0 16px; }
.status-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #c8102e; }
.live.on i { animation: pulse 1.6s infinite; }
.live.done i { background: var(--ok); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(200 16 46 / .5); } 70% { box-shadow: 0 0 0 8px rgb(200 16 46 / 0); } 100% { box-shadow: 0 0 0 0 rgb(200 16 46 / 0); } }
@media (prefers-reduced-motion: reduce) { .live.on i { animation: none; } }
.big-prog-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.big-prog-head b { font-size: 28px; letter-spacing: -.02em; }
.big-track { display: block; height: 10px; background: var(--track); border-radius: 999px; overflow: hidden; }
.big-bar { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 999px; transition: width .8s ease; }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { margin-bottom: 14px; }
.card-head p { margin: 4px 0 0; }
section.card, .map-grid, .charts { margin-bottom: 16px; }

/* Placar */
.cands { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cand { display: flex; gap: 14px; align-items: center; border-left: 4px solid var(--pc); padding-left: 14px; }
.cand.right { flex-direction: row-reverse; text-align: right; border-left: 0; border-right: 4px solid var(--pc); padding-left: 0; padding-right: 14px; }
.cand img { width: 72px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--track); flex: none; }
.cand-name { font-weight: 700; font-size: 18px; }
.cand-pct { font-size: 44px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; margin-top: 4px; }
.badge-elected { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--ok); color: #fff; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.split { position: relative; display: flex; gap: 2px; height: 22px; margin: 18px 0 8px; border-radius: 6px; overflow: hidden; background: var(--track); }
.split .seg { display: block; height: 100%; min-width: 0; transition: width .8s ease; }
.split { overflow: visible; }
.split .seg:first-child { border-radius: 6px 0 0 6px; }
.split .seg:last-of-type { border-radius: 0 6px 6px 0; }
.split .half { position: absolute; left: 50%; top: -5px; bottom: -5px; width: 2px; background: var(--ink); opacity: .55; transform: translateX(-1px); border-radius: 1px; }
.lead-line { margin: 0; text-align: center; color: var(--ink-2); }
#cand-list { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }

/* Barras horizontais */
.hbars, .prog, .margins, .regions, .legend, .cmp { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 64px; gap: 10px; align-items: center; padding: 4px 0; }
.hb-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-track, .pg-track, .mg-track, .cmp-track { position: relative; display: block; height: 10px; background: var(--track); border-radius: 4px; overflow: hidden; }
.hb-bar, .pg-bar, .cmp-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; transition: width .8s ease; }
.hb-val, .pg-val, .mg-val, .rg-val { text-align: right; font-size: 14px; font-weight: 600; }

/* Mapa */
.map-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.map { position: relative; }
.map-svg { display: block; width: 100%; height: auto; }
.uf { stroke: var(--surface); stroke-width: 1.4; cursor: pointer; transition: fill-opacity .4s; }
.uf:hover, .uf:focus-visible { stroke: var(--ink); stroke-width: 2; outline: none; }
.uf.sel { stroke: var(--ink); stroke-width: 3; }
.hatch-bg { fill: var(--hatch-bg); }
.hatch-line { stroke: var(--hatch-line); stroke-width: 3; }
.leaders line { stroke: var(--ink-2); stroke-width: 1; }
.labels { pointer-events: none; }
.lbl { text-anchor: middle; font-size: 17px; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.lbl.small { font-size: 15px; text-anchor: start; }
.lbl-uf { font-weight: 800; }
.lbl-pct { font-weight: 500; font-size: .9em; }
.map-legend { display: grid; gap: 4px; margin-top: 10px; font-size: 12px; width: max-content; max-width: 100%; }
.ml-row, .ml-scale { display: grid; grid-template-columns: 52px repeat(5, 30px); gap: 2px; align-items: center; }
.ml-row:last-child { grid-template-columns: 30px auto; gap: 8px; }
.ml-p { font-weight: 700; }
.ml-sw { height: 12px; border-radius: 3px; display: block; }
.ml-scale span { color: var(--ink-2); font-size: 10px; text-align: center; }
.hatch, .ml-sw.hatch { background: repeating-linear-gradient(45deg, var(--hatch-bg) 0 3px, var(--hatch-line) 3px 5px); }

/* Municípios */
.map-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.map-head > div { min-width: 0; }
#map-back { flex: none; }
.mun-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: -4px 0 12px; }
.mun-tools input { font: inherit; font-size: 14px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; flex: 0 1 260px; min-width: 0; }
.mun { stroke: var(--surface); stroke-width: .6; cursor: pointer; vector-effect: non-scaling-stroke; }
.mun:hover { stroke: var(--ink); stroke-width: 1.5; }
.mun.sel { stroke: var(--ink); stroke-width: 2.5; }
.map-loading { padding: 80px 0; text-align: center; }
.mun-wins { margin-top: 14px; }
.mun-wins .tile-l { margin-bottom: 6px; }
svg.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Painel lateral */
.side { position: sticky; top: 84px; }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.side-head h2 { font-size: 20px; }
.side-prog { display: grid; gap: 6px; margin-bottom: 14px; font-weight: 600; }
.side-prog .pg-bar { background: var(--ink); }
.side .tiles { grid-template-columns: repeat(2, 1fr); margin-top: 14px; }
.side .hbars li { grid-template-columns: minmax(90px, 42%) 1fr 62px; }

/* Grade de gráficos */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.charts .wide { grid-column: 1 / -1; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; font-size: 13px; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; margin-right: 6px; vertical-align: -1px; }
.legend .dot { margin-right: 0; }

.waffle { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
.cell { aspect-ratio: 1.3; display: grid; place-items: center; border-radius: 4px; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.cell.empty { background: repeating-linear-gradient(45deg, var(--hatch-bg) 0 3px, var(--hatch-line) 3px 5px); color: var(--muted); }

.regions li { display: grid; grid-template-columns: 96px 1fr 110px; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.rg-track { display: flex; gap: 2px; height: 16px; border-radius: 4px; overflow: hidden; background: var(--track); }
.rg-track.empty { background: none; color: var(--muted); font-size: 12px; height: auto; }
.rg-track .seg { display: block; height: 100%; }

.mg-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; padding: 0 52px 0 40px; }
.margins li, .prog li { display: grid; grid-template-columns: 30px 1fr 52px; gap: 10px; align-items: center; padding: 2px 0; font-size: 13px; }
.mg-track { background: none; overflow: visible; }
.mg-track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line); }
.mg-bar { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.mg-uf, .pg-uf { font-weight: 700; font-size: 12px; color: var(--ink-2); }
.pg-bar { background: var(--ink-2); }

.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.tile { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.tile-l { font-size: 12px; color: var(--ink-2); }
.tile-v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }

.cmp li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.cmp li:last-child { border: 0; }
.cmp-name { font-weight: 700; margin-bottom: 6px; }
.cmp-row { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; align-items: center; font-size: 13px; padding: 2px 0; }
.cmp-row b { text-align: right; }
.cmp-bar { background: var(--pc); }
.cmp-bar.faint { opacity: .4; }
.cmp-delta { font-size: 12px; margin-top: 4px; }

.evo-wrap { width: 100%; }
.evo { width: 100%; height: auto; display: block; touch-action: pan-y; }
.evo .grid { stroke: var(--line); stroke-width: 1; }
.evo .ref { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.evo .ax { fill: var(--ink-2); font-size: 11px; }
.evo .cross { stroke: var(--ink-2); stroke-width: 1; }

/* Tabela */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th button { border: 0; background: none; font-weight: 600; color: var(--ink-2); padding: 0; }
.tbl th button.on { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: var(--bg); }

/* Tooltip */
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; box-shadow: 0 6px 24px rgb(0 0 0 / .14); max-width: 260px; }
.tip-row { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; margin-top: 4px; }
.tip-row .dot { margin: 0; }
.tip-foot { margin-top: 6px; font-size: 12px; }

/* Anúncios */
.ad { margin: 0 0 16px; min-height: 90px; text-align: center; }
.ad-label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 4px; }

.foot { padding: 8px 16px 40px; }
.foot p { margin: 4px 0; }

/* Celular */
@media (max-width: 900px) {
  .map-grid { grid-template-columns: 1fr; }
  .side { position: static; }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .top-in { gap: 10px; }
  .brand h1 { font-size: 17px; }
  .rounds { order: 3; width: 100%; }
  .rounds button { flex: 1; }
  #share { display: none; }
  .cands { gap: 10px; }
  .cand, .cand.right { flex-direction: column; align-items: flex-start; text-align: left; gap: 8px; }
  .cand.right { align-items: flex-end; text-align: right; }
  .cand img { width: 56px; height: 75px; }
  .cand-name { font-size: 15px; }
  .cand-pct { font-size: 32px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .regions li { grid-template-columns: 78px 1fr 84px; font-size: 13px; }
  .lbl { font-size: 22px; }
  .lbl.small { font-size: 19px; }
  .card { padding: 14px; }
}

/* Rolar até o mapa sem o cabeçalho fixo cobrir o título */
#map-card { scroll-margin-top: 80px; }
@media (max-width: 600px) { #map-card { scroll-margin-top: 120px; } }

.stale { margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid #c77700; font-size: 14px; }
