/* ============================================================
   Propósito Voto — tokens + layout
   Paleta: fundo escuro roxo-azulado com acentos vivos (violeta/ciano).
   Suporte dark/light via prefers-color-scheme, com toggle manual
   que grava a preferência em localStorage.
   ============================================================ */

:root {
  --bg: #f4f3fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #eeecfa;
  --border: #ddd8f2;
  --border-soft: #e8e5f7;
  --text: #211a3a;
  --text-muted: #635f80;
  --text-faint: #8b87a6;

  --accent: #7c3aed;       /* violeta vivo */
  --accent-2: #06b6d4;     /* ciano vivo */
  --accent-3: #f43f5e;     /* rosa/coral p/ contraste */
  --accent-warm: #f59e0b;  /* âmbar */
  --accent-soft: #ede9fe;

  --good: #10b981;
  --bad: #f43f5e;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-num: "SF Mono", "Roboto Mono", ui-monospace, monospace;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 3px rgba(33, 26, 58, 0.08), 0 8px 24px rgba(33, 26, 58, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131022;
    --bg-elevated: #1a1630;
    --surface: #1a1630;
    --surface-2: #221c3d;
    --border: #322b52;
    --border-soft: #241f3e;
    --text: #f2f0fb;
    --text-muted: #ada7cc;
    --text-faint: #7c76a0;

    --accent: #a78bfa;
    --accent-2: #22d3ee;
    --accent-3: #fb7185;
    --accent-warm: #fbbf24;
    --accent-soft: #2c2452;

    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #131022;
  --bg-elevated: #1a1630;
  --surface: #1a1630;
  --surface-2: #221c3d;
  --border: #322b52;
  --border-soft: #241f3e;
  --text: #f2f0fb;
  --text-muted: #ada7cc;
  --text-faint: #7c76a0;

  --accent: #a78bfa;
  --accent-2: #22d3ee;
  --accent-3: #fb7185;
  --accent-warm: #fbbf24;
  --accent-soft: #2c2452;

  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}

body {
  min-height: 100vh;
}

.tabular { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

a { color: var(--accent-2); }

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

/* ---------- Header ---------- */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
}
.brand .dot { color: var(--accent); }
.brand small {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-faint);
}

nav.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: thin;
}

nav.tabs button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
nav.tabs button:hover { background: var(--surface-2); color: var(--text); }
nav.tabs button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #100b23;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 100px;
  padding: 7px 12px;
  font-size: 13px;
  flex-shrink: 0;
}

/* ---------- Layout ---------- */

main {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 20px 60px;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 16px;
  align-items: start;
}
.layout.no-right { grid-template-columns: 260px 1fr; }
.layout.no-left { grid-template-columns: 1fr 280px; }
.layout.single { grid-template-columns: 1fr; }

@media (max-width: 1100px) {
  .layout, .layout.no-right, .layout.no-left {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 700;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Form controls ---------- */

label.field {
  display: block;
  margin-bottom: 12px;
}
label.field .lbl {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 5px;
  font-weight: 600;
}

select, input[type="text"], input[type="search"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 100px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.cand-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}
.cand-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.cand-row:hover { background: var(--surface-2); }
.cand-row.selected { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.cand-row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-row .v { color: var(--text-faint); font-family: var(--font-num); }

/* ---------- Stat tiles ---------- */

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.stat:last-child { border-bottom: none; }
.stat .k { font-size: 11.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 20px; font-weight: 800; font-family: var(--font-num); }
.stat .sub { font-size: 12px; color: var(--text-muted); }

.rank-row {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
.rank-row .pos { color: var(--text-faint); font-family: var(--font-num); font-size: 12px; }
.rank-row .party-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.rank-row .votos { font-family: var(--font-num); color: var(--text-muted); }

/* ---------- Map ---------- */

.map-wrap {
  position: relative;
  background: var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
}
svg.rsmap { width: 100%; height: auto; display: block; }
svg.rsmap path.mun {
  stroke: var(--bg);
  stroke-width: 0.6;
  cursor: pointer;
  transition: opacity 0.1s;
}
svg.rsmap path.mun:hover { opacity: 0.75; stroke: var(--text); stroke-width: 1.2; }

.map-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: 220px;
  display: none;
}

.legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}
.legend .bar {
  height: 10px;
  flex: 1;
  border-radius: 6px;
}

.compare-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.compare-toggle button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 7px;
  font-size: 12.5px;
  font-weight: 700;
}
.compare-toggle button.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---------- Cards / generic ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 17px;
}
.card .desc { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
table.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--border-soft); }
table.tbl tr:hover td { background: var(--surface-2); }
table.tbl td.num { font-family: var(--font-num); text-align: right; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge.eleito { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  color: var(--text-faint);
  font-size: 13px;
}

.note {
  font-size: 12px;
  color: var(--text-faint);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  border-left: 3px solid var(--accent-warm);
}

footer.site-footer {
  max-width: 1500px;
  margin: 20px auto 40px;
  padding: 0 20px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}
