/* Tema comum da página inicial e das telas do 2º turno: cores (claro/escuro), fontes, cartões, faixa de status, escalas.
   Regra de cor: mais intensidade = cor mais escura e mais saturada, nos dois temas (a escala não se inverte no escuro). */
:root {
  --bg: #eef1f6; --surface: #ffffff; --ink: #0e1a30; --muted: #5b6884; --line: #d8dfeb; --bar: #cdd6e6;
  --lead: #1d4a9c; --sun: #e9ad00; --sun-soft: #fbefc6; --on-sun: #1a1300;
  --good: #17804f; --good-soft: #dcf1e6; --warn: #9a5b00; --warn-soft: #fbecd2;
  /* blocos e candidatos: Lula = --esq (vermelho), Flávio = --dir (azul) */
  --esq: #e34948; --cen: #eda100; --dir: #2a78d6; --nc: #c4c0b6;
  --on-esq: #ffffff; --on-cen: #1a1300; --on-dir: #ffffff; --on-nc: #1a1300;
  /* vencedor por margem (4 tons de cada cor) */
  --esq-1: #f6c9c6; --esq-2: #eb8f8b; --esq-3: #d6403e; --esq-4: #8f1f1f;
  --dir-1: #c9dcf6; --dir-2: #82b2ec; --dir-3: #2a78d6; --dir-4: #133f7a;
  /* margem divergente: vermelho ↔ neutro ↔ azul, mais escuro nas pontas */
  --m-3: #8f1f1f; --m-2: #d6403e; --m-1: #f2a8a5; --m0: #e2ded6; --m1: #a9c9f2; --m2: #2a78d6; --m3: #133f7a;
  /* % apurado */
  --q1: #cde2fb; --q2: #86b6ef; --q3: #3987e5; --q4: #1c5cab; --q5: #0d366b;
  --perda: #b9bcc4; --none: #e3e7ef;
  --map-bg: #f7f9fc; --map-stroke: #ffffff;
  --display: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1222; --surface: #101b2f; --ink: #e6ebf4; --muted: #93a0b9; --line: #223150; --bar: #2a3a59;
    --lead: #7ea5ef; --sun: #f4c232; --sun-soft: #3a3010; --on-sun: #1a1300;
    --good: #5fcf96; --good-soft: #12301f; --warn: #f0b45a; --warn-soft: #36270d;
    --esq: #c93a3a; --cen: #c98500; --dir: #3987e5; --nc: #4a5163;
    --on-esq: #ffffff; --on-cen: #140e00; --on-dir: #ffffff; --on-nc: #e6ebf4;
    --esq-1: #e8b3b0; --esq-2: #d9726e; --esq-3: #c03634; --esq-4: #7d1c1c;
    --dir-1: #b3cdef; --dir-2: #6f9fdf; --dir-3: #2f6fc4; --dir-4: #163f78;
    --m-3: #7d1c1c; --m-2: #c03634; --m-1: #e58f8c; --m0: #cfcac0; --m1: #8fb5e8; --m2: #2f6fc4; --m3: #163f78;
    --q1: #b9d2f2; --q2: #7aa8e3; --q3: #3f7cc9; --q4: #275a9c; --q5: #163a6b;
    --perda: #59617a; --none: #1c2842;
    --map-bg: #16223a; --map-stroke: #a9b6cc;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1222; --surface: #101b2f; --ink: #e6ebf4; --muted: #93a0b9; --line: #223150; --bar: #2a3a59;
  --lead: #7ea5ef; --sun: #f4c232; --sun-soft: #3a3010; --on-sun: #1a1300;
  --good: #5fcf96; --good-soft: #12301f; --warn: #f0b45a; --warn-soft: #36270d;
  --esq: #c93a3a; --cen: #c98500; --dir: #3987e5; --nc: #4a5163;
  --on-esq: #ffffff; --on-cen: #140e00; --on-dir: #ffffff; --on-nc: #e6ebf4;
  --esq-1: #e8b3b0; --esq-2: #d9726e; --esq-3: #c03634; --esq-4: #7d1c1c;
  --dir-1: #b3cdef; --dir-2: #6f9fdf; --dir-3: #2f6fc4; --dir-4: #163f78;
  --m-3: #7d1c1c; --m-2: #c03634; --m-1: #e58f8c; --m0: #cfcac0; --m1: #8fb5e8; --m2: #2f6fc4; --m3: #163f78;
  --q1: #b9d2f2; --q2: #7aa8e3; --q3: #3f7cc9; --q4: #275a9c; --q5: #163a6b;
  --perda: #59617a; --none: #1c2842;
  --map-bg: #16223a; --map-stroke: #a9b6cc;
  color-scheme: dark;
}

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.45; overflow-wrap: break-word; }
.wrap { max-width: 1320px; margin: 0 auto; padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); padding-block: 20px max(48px, env(safe-area-inset-bottom)); display: grid; gap: 18px; }
@media (min-width: 1700px) { .wrap { max-width: 1560px; } }
@media (max-width: 480px) { .wrap { gap: 14px; padding-top: 14px; } }
a { color: var(--lead); }

/* topo e faixa de status */
header.top { display: grid; gap: 10px; border-top: 6px solid var(--sun); padding-top: 14px; }
.voltar { font-size: 13px; font-weight: 600; text-decoration: none; justify-self: start; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { font-family: var(--display); font-weight: 700; font-size: clamp(32px, 5.5vw, 48px); line-height: .95; margin: 0; }
h1 span { color: var(--lead); }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: 13px; color: var(--muted); }
.status b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.live { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--good); animation: pulse 2s infinite; }
.live.late .dot { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.faixa-sim { position: sticky; top: 0; z-index: 20; background: var(--sun); color: var(--on-sun); text-align: center; font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .08em; padding: 6px 16px; }
.sim-ctl { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.sim-ctl [role="group"] { display: inline-flex; gap: 4px; }
.sim-ctl input[type="range"] { width: min(260px, 60vw); accent-color: var(--sun); }
.sim-ctl b { font-family: var(--mono); font-size: 14px; }

/* controles */
button, .btn { font: inherit; font-size: 13px; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn.primario { background: var(--ink); color: var(--surface); border-color: var(--ink); }
@media (hover: hover) { button:hover, .btn:hover { border-color: var(--lead); } }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, select:focus-visible, input:focus-visible, .btn:focus-visible, summary:focus-visible { outline: 2px solid var(--lead); outline-offset: 2px; }
button[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
select, input[type="search"] { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; min-width: 0; max-width: 100%; }
@media (pointer: coarse) { button, select, .btn, input[type="search"] { min-height: 40px; } button, .btn { padding-inline: 14px; } }
.modes { display: flex; gap: 6px; flex-wrap: wrap; }
.banner { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: 8px; padding: 12px 14px; }
.banner p { margin: 0; }

/* cartões */
section.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: clamp(12px, 3vw, 16px); display: grid; gap: 14px; min-width: 0; align-content: start; }
section.card > * { min-width: 0; }   /* filhos da grade encolhem: as tabelas rolam dentro de si */
h2 { font-family: var(--display); font-weight: 700; font-size: clamp(24px, 6vw, 28px); line-height: 1; margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
h2 small, h3 small, h4 small { font-family: var(--body); font-size: 13px; font-weight: 500; color: var(--muted); }
h3 { font-family: var(--display); font-weight: 600; font-size: 22px; line-height: 1.05; margin: 0; }
h4 { font-family: var(--display); font-size: 17px; font-weight: 600; margin: 0; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chip { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--sun-soft); color: var(--warn); white-space: nowrap; }
.chip.def { background: var(--good-soft); color: var(--good); }
.chip.esq { background: var(--esq); color: var(--on-esq); } .chip.cen { background: var(--cen); color: var(--on-cen); }
.chip.dir { background: var(--dir); color: var(--on-dir); } .chip.nc { background: var(--nc); color: var(--on-nc); }
.tse { font-size: 12px; white-space: nowrap; }
.state-name { font-family: var(--display); font-size: clamp(28px, 7vw, 34px); font-weight: 700; line-height: 1; }

/* placar */
.br { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 20px; align-items: center; }
@media (max-width: 760px) { .br { grid-template-columns: minmax(0, 1fr); } }
.hero-pct { font-family: var(--display); font-size: clamp(44px, 12vw, 56px); font-weight: 700; line-height: .9; font-variant-numeric: tabular-nums; }
.hero-sub { font-size: 13px; color: var(--muted); }
.prog { display: grid; gap: 6px; }
.prog-line { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.prog-line .big { font-family: var(--display); font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1; font-variant-numeric: tabular-nums; }
.track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--sun); transition: width .6s ease; }
.totais { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding-block: 10px; margin: 0; }
.totais div { display: grid; gap: 1px; }
.totais dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.totais dd { margin: 0; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.cands { list-style: none; margin: 0; padding: 0; display: grid; gap: 11px; }
.cand { display: grid; gap: 4px; }
.cand.eleito { padding: 6px 8px 6px 12px; margin-inline: -8px; border-radius: 6px; background: color-mix(in srgb, var(--good) 11%, transparent); box-shadow: inset 4px 0 0 var(--good); }
.cand-top { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.cand-name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.cand-name small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 7px; }
.sw { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; margin-right: 6px; vertical-align: 0; }
.cand-pct { font-family: var(--display); font-weight: 700; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-v { font-family: var(--mono); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; }
.bar { position: relative; height: 12px; background: var(--bg); border-radius: 3px; }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--bar); transition: width .6s ease; }
.bar .half { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--sun); }
.tag { display: inline-block; font-family: var(--mono); font-size: 10.5px; font-weight: 500; letter-spacing: .05em; text-transform: uppercase; line-height: 1.5; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.tag.el { background: var(--good); color: var(--surface); }
.note { font-size: 12px; color: var(--muted); margin: 0; max-width: 100ch; }
.note b { color: var(--ink); font-weight: 600; }
.ref { font-size: 13px; margin: 0; padding: 8px 10px; border-left: 4px solid var(--sun); background: var(--sun-soft); border-radius: 0 6px 6px 0; }

/* tabelas */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: bottom; white-space: nowrap; background: var(--surface); }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.n, th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.nome { font-weight: 600; min-width: 8em; }
td.nome small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl-scroll { max-height: 520px; overflow: auto; }
.tbl-scroll thead th { position: sticky; top: 0; z-index: 1; }
tr.click { cursor: pointer; }
@media (hover: hover) { tr.click:hover td { background: color-mix(in srgb, var(--lead) 7%, transparent); } }
tr.cursel td { background: color-mix(in srgb, var(--sun) 18%, transparent); }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }
.split { display: flex; height: 10px; min-width: 80px; border-radius: 3px; overflow: hidden; gap: 1px; background: var(--bg); }
.split i { display: block; }
.rank, .lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; font-size: 14px; }
.rank { counter-reset: r; }
.rank li, .lista li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.rank li::before { counter-increment: r; content: counter(r); font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 2em; }
.rank li span, .lista li span { flex: 1; min-width: 0; }
.rank small, .lista small { color: var(--muted); font-size: 12px; }
.rank b, .lista b { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.duas { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 760px) { .duas { grid-template-columns: minmax(0, 1fr); } }

/* mapa */
.map-wrap { position: relative; container-type: inline-size; }
svg.map { width: 100%; height: auto; display: block; max-height: min(640px, 85vh); touch-action: manipulation; background: var(--map-bg); border-radius: 8px; }
svg.map path { stroke: var(--map-stroke); stroke-width: 1.2; cursor: pointer; transition: fill .4s ease; vector-effect: non-scaling-stroke; }
svg.map.mun path { stroke-width: .4; }
svg.map path.contorno { fill: none !important; stroke: var(--map-stroke); stroke-width: 1.6; pointer-events: none; }
@media (hover: hover) { svg.map path:hover { stroke: var(--ink); stroke-width: 2; } }
svg.map path.sel { stroke: var(--ink); stroke-width: 3; }
svg.map path:focus { outline: none; }
svg.map path:focus-visible { stroke: var(--sun); stroke-width: 3; }
svg.map text { font-family: var(--mono); font-size: 10px; font-weight: 500; pointer-events: none; text-anchor: middle; dominant-baseline: central; fill: var(--ink); paint-order: stroke; stroke: color-mix(in srgb, var(--surface) 75%, transparent); stroke-width: 2.5px; }
@container (max-width: 560px) { svg.map text { font-size: 13px; stroke-width: 3px; } }
@container (max-width: 420px) { svg.map text { font-size: 16px; stroke-width: 3.5px; } }
@media (prefers-reduced-motion: reduce) { svg.map path, .track i, .bar i { transition: none; } .live.on .dot { animation: none; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid color-mix(in srgb, var(--ink) 15%, transparent); }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--ink); color: var(--surface); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 180px; max-width: calc(100% - 8px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.tip strong { display: block; font-family: var(--display); font-size: 17px; font-weight: 600; }
.tip .row { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.tip .row.sub { opacity: .75; }

/* aviso (virada) */
.alerta { position: fixed; z-index: 30; top: calc(env(safe-area-inset-top, 0px) + 14px); right: 16px; width: min(440px, calc(100% - 32px)); background: var(--sun); color: var(--on-sun); border-radius: 12px; padding: 14px 16px 12px; display: grid; gap: 8px; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.alerta strong { font-family: var(--display); font-size: 22px; }
.alerta ul { margin: 0; padding-left: 18px; }
.alerta button { justify-self: end; }

.empty { display: grid; gap: 6px; padding: 12px 2px; color: var(--muted); }
.empty strong { color: var(--ink); font-family: var(--display); font-size: 20px; font-weight: 600; }
.skel { height: 12px; border-radius: 3px; background: var(--bg); }
footer { font-size: 12px; color: var(--muted); max-width: 100ch; display: grid; gap: 6px; }
