:root {
  --ink: #1a1a1a;
  --muted: #5b6166;
  --panel: rgba(255, 255, 255, 0.97);
  --line: rgba(0, 0, 0, 0.12);
  --accent: #1f6feb;
}

* { box-sizing: border-box; }

/* The hidden attribute has to beat the display rules further down:
   an id selector like #painel-topo-corpo { display: block } otherwise wins over
   the browser's own [hidden] { display: none }, and the element shows up anyway. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #eef1f3;
  -webkit-text-size-adjust: 100%;
}

#map {
  position: absolute;
  inset: 0;
  background: #eef1f3;
}

#erro {
  position: absolute;
  inset: auto 12px 90px 12px;
  z-index: 1400;
  padding: 12px 14px;
  border-radius: 10px;
  background: #b3261e;
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
}

/* the circles are SVG; keep them from getting a fat outline when zooming */
.leaflet-interactive { vector-effect: non-scaling-stroke; cursor: pointer; }

/* zoom buttons above the collapsed bottom bar */
.leaflet-bottom.leaflet-right { bottom: 74px; }
.leaflet-control-zoom a { width: 38px; height: 38px; line-height: 38px; font-size: 20px; }

/* ---------- shared panel chrome ---------- */

#painel-topo,
#painel-baixo {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 1100;
  background: var(--panel);
  backdrop-filter: blur(6px);
}

#painel-topo { top: 0; border-bottom: 1px solid var(--line); }
#painel-baixo { bottom: 19px; border-top: 1px solid var(--line); }

#painel-topo-toggle,
#painel-baixo-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}

#painel-topo-titulo {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

/* the "tap for the legend" hint, inside the bar, gone once the panel is open */
.rotulos {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#painel-topo-dica {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.2;
  color: var(--muted);
}

#painel-baixo-resumo {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.2;
}

.chev {
  margin-left: auto;
  font-size: 20px;
  line-height: 1;
  color: var(--ink);
}

#painel-topo-corpo {
  max-height: 52vh;
  overflow-y: auto;
  padding: 0 14px 14px;
}

#painel-baixo-corpo {
  max-height: 56vh;
  overflow-y: auto;
  padding: 0 14px 14px;
}

/* ---------- top panel content ---------- */

#painel-topo .subtitulo {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

#painel-topo .aviso {
  margin: 3px 0 12px;
  font-size: 12.5px;
  font-style: italic;
  color: var(--muted);
}

#painel-topo .titulo {
  margin: 10px 0 5px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

#lista-candidatos {
  list-style: none;
  margin: 0;
  padding: 0;
}

#lista-candidatos li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
}

#lista-candidatos .nome { flex: 1 1 auto; }
#lista-candidatos .det { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ramp { display: inline-flex; gap: 2px; }

.dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

.faixa,
.nota {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.nota { color: var(--muted); }

.fonte {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.fonte .titulo { margin-top: 0; }

.links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.links li {
  padding: 0;
  font-size: 13px;
  line-height: 1.35;
}

.links a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 0;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(31, 111, 235, 0.4);
  text-underline-offset: 2px;
}

.links a:hover { text-decoration-color: var(--accent); }

.fonte .detalhe {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- bottom panel content ---------- */

#zonas {
  display: flex;
  gap: 6px;
  padding: 2px 0 12px;
}

#zonas button {
  flex: 1 1 0;
  min-height: 44px;
  padding: 10px 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: #f1f3f5;
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}

#zonas button.ativo {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* the tap hint under the bottom bar, always visible */
#painel-baixo-dica {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--muted);
}

#numeros-titulo {
  margin: 0 0 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

/* the candidate list scrolls on its own, so the zone buttons stay put */
#tabela-scroll {
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  border-bottom: 1px solid var(--line);
}

#tabela-totais {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#tabela-totais th,
#tabela-totais td { padding: 7px 4px; text-align: left; }

#tabela-totais .cabecalho th {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

#tabela-totais tbody td { border-bottom: 1px solid #eff1f3; }
#tabela-totais tbody tr:nth-child(even) { background: #f7f9fb; }
#tabela-totais tbody tr:last-child td { border-bottom: 0; }

#tabela-totais .num { text-align: right; white-space: nowrap; }
#tabela-totais .cand { display: flex; align-items: center; gap: 7px; }
#tabela-totais tr.destaque td { font-weight: 600; }

#numeros-rodape {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- always-visible credits strip ---------- */

#creditos {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  margin: 0;
  padding: 2px 10px calc(2px + env(safe-area-inset-bottom));
  font-size: 10.5px;
  line-height: 15px;
  color: var(--muted);
  background: var(--panel);
  text-align: center;
}

/* ---------- base map fallback notice ---------- */

#map.sem-base { background: #e6e9ea; }

#aviso-base {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1150;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  width: min(340px, calc(100% - 32px));
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.18);
  font-size: 13.5px;
  text-align: center;
}

#reportar {
  display: inline-block;
  padding: 11px 14px;
  min-height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

/* ---------- floating sources button ---------- */

#botao-fontes {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 1050;
  min-height: 40px;
  padding: 0 15px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  cursor: pointer;
}

#botao-fontes:hover { background: #f1f3f5; }

/* ---------- polling place modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 1500;
}

.modal-fundo {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-caixa {
  position: absolute;
  top: auto; bottom: 0; left: 0;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: #fff;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
}

.modal-fechar {
  position: absolute;
  top: 10px; right: 10px;
  width: 42px; height: 42px;
  font-size: 17px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.modal-conteudo h2 {
  margin: 0 32px 5px 0;
  font-size: 17px;
  line-height: 1.25;
}

.modal-conteudo .endereco {
  margin: 0 0 11px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

.modal-conteudo .resumo {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 14px;
  margin: 0 0 12px;
  padding: 9px 11px;
  border-radius: 9px;
  background: #f4f6f8;
  font-size: 12.5px;
}

.modal-conteudo .vencedor {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.35;
}

.modal-conteudo .vencedor .dot { width: 18px; height: 18px; }
.modal-conteudo .vencedor .sem { color: var(--muted); }

.modal-conteudo table { width: 100%; border-collapse: collapse; font-size: 14px; }

/* the candidate list in the place card scrolls on its own */
.tabela-rolavel {
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.modal-conteudo th {
  padding: 6px 4px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.modal-conteudo td { padding: 7px 4px; border-bottom: 1px solid #eff1f3; }
.modal-conteudo tbody tr:nth-child(even) { background: #f7f9fb; }
.modal-conteudo tr.ganhou td { font-weight: 700; background: #eef4fb; }
.modal-conteudo .num { text-align: right; white-space: nowrap; }
.modal-conteudo .cand { display: flex; align-items: center; gap: 7px; }

.modal-conteudo .rodape-modal {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- roomier screens ---------- */

@media (min-width: 700px) {
  #painel-topo-titulo { font-size: 18px; }
  .modal-caixa {
    top: 50%; bottom: auto; left: 50%;
    transform: translate(-50%, -50%);
    width: min(460px, calc(100% - 32px));
    border-radius: 14px;
  }
  .leaflet-bottom.leaflet-right { bottom: 30px; }
}
