/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f172a;
  --bg2:      #1e293b;
  --bg3:      #0d1a2e;
  --border:   #334155;
  --text1:    #f1f5f9;
  --text2:    #94a3b8;
  --text3:    #64748b;

  --vermelho: #ef4444;
  --laranja:  #f97316;
  --azul:     #3b82f6;
  --verde:    #22c55e;
  --cinza:    #475569;

  --radius:   10px;
  --shadow:   0 4px 24px #00000044;
  --h-header: 60px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text1);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--h-header);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text1);
  flex-shrink: 0;
}

.logo-icon { font-size: 1.4rem; line-height: 1; }

.logo-text {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  display: block;
  color: var(--text1);
}

.logo-sub {
  font-size: .68rem;
  color: var(--text2);
  display: block;
  letter-spacing: .02em;
}

.header-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  flex-shrink: 0;
}

nav.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  flex: 1;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  letter-spacing: .04em;
  text-transform: uppercase;
}

select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-family: inherit;
  font-size: .8rem;
  padding: 5px 10px;
  cursor: pointer;
  outline: none;
  transition: border-color .2s;
}
select:hover { border-color: var(--azul); }
select:focus { border-color: var(--azul); box-shadow: 0 0 0 2px #3b82f622; }

/* Toggle switch */
.toggle-wrap { cursor: pointer; user-select: none; }

.toggle-switch {
  position: relative;
  display: flex;
  align-items: center;
}
.toggle-switch input { display: none; }

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background .2s;
  display: block;
}
.toggle-switch input:checked ~ .toggle-track { background: var(--azul); }

.toggle-thumb {
  position: absolute;
  left: 3px;
  width: 14px;
  height: 14px;
  background: var(--text1);
  border-radius: 50%;
  transition: left .2s;
  pointer-events: none;
}
.toggle-switch input:checked ~ .toggle-track ~ .toggle-thumb { left: 19px; }

/* Botão toggle visão */
.btn-visao {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-family: inherit;
  font-size: .78rem;
  font-weight: 500;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .2s, background .2s;
}
.btn-visao:hover { border-color: var(--azul); background: #1e293b; }

/* ── Barra de resumo ──────────────────────────────────────────────────────── */
#resumo-estadual {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resumo-cargo {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: .03em;
}

.resumo-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.rst {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
}

.rst-num {
  font-size: 1.1rem;
  font-weight: 700;
  min-width: 1.4em;
  text-align: right;
}

.rst.vermelho { color: var(--vermelho); }
.rst.laranja  { color: var(--laranja);  }
.rst.azul     { color: var(--azul);     }
.rst.verde    { color: var(--verde);    }

.resumo-geral {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--text2);
}

.resumo-pct {
  font-size: .9rem;
  font-weight: 700;
  color: var(--azul);
}

/* ── Layout principal ─────────────────────────────────────────────────────── */
main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--h-header));
  overflow: hidden;
}

.grid-principal {
  display: grid;
  grid-template-columns: 1fr 320px;
  flex: 1;
  overflow: hidden;
}

/* ── Mapa ─────────────────────────────────────────────────────────────────── */
#mapa-container {
  background: var(--bg3);
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#mapa-container svg {
  flex: 1;
  min-height: 0;
}

/* ── Legenda ──────────────────────────────────────────────────────────────── */
#legenda {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .76rem;
  color: var(--text2);
  white-space: nowrap;
}

.leg-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Painel lateral ───────────────────────────────────────────────────────── */
#painel-lateral {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}

#painel-lateral.aberto {
  transform: translateX(0);
}

.painel-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.painel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text1);
  margin-bottom: 2px;
}

.painel-cargo {
  font-size: .72rem;
  color: var(--text2);
  font-weight: 500;
}

#btn-fechar {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  cursor: pointer;
  font-size: .85rem;
  padding: 4px 8px;
  flex-shrink: 0;
  transition: all .15s;
}
#btn-fechar:hover { color: var(--text1); border-color: var(--text2); }

.painel-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 16px 6px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .78rem;
  font-weight: 600;
}

.badge-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.painel-bloco {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.painel-sub {
  font-size: .68rem;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 10px;
}

.painel-linha {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  font-size: .8rem;
  border-bottom: 1px solid #ffffff08;
}
.painel-linha:last-child { border-bottom: none; }
.painel-linha span { color: var(--text2); }
.painel-linha strong { color: var(--text1); font-weight: 600; text-align: right; }

.inp-votos {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text1);
  font-family: inherit;
  font-size: .8rem;
  padding: 4px 8px;
  width: 100px;
  text-align: right;
  outline: none;
  transition: border-color .2s;
}
.inp-votos:focus { border-color: var(--azul); box-shadow: 0 0 0 2px #3b82f622; }

/* ── Barras de progresso ──────────────────────────────────────────────────── */
.barra-wrap {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.barra-prog {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease, background .3s;
}

/* ── Botões ───────────────────────────────────────────────────────────────── */
.btn-primario {
  display: block;
  width: calc(100% - 32px);
  margin: 14px 16px 0;
  padding: 10px;
  background: var(--azul);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}
.btn-primario:hover  { background: #2563eb; }
.btn-primario:active { transform: scale(.98); }

.painel-hint {
  text-align: center;
  font-size: .7rem;
  color: var(--text3);
  padding: 6px 16px 16px;
}
.painel-obs {
  font-size: .7rem;
  color: var(--text3);
  font-style: italic;
  margin: 2px 0 4px;
}

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  z-index: 500;
  display: none;
  background: #1e293bed;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: .78rem;
  color: var(--text1);
  pointer-events: none;
  max-width: 240px;
  line-height: 1.6;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

#tooltip strong { font-weight: 700; display: block; margin-bottom: 4px; }

.tt-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: .75rem;
  color: var(--text2);
}
.tt-row b { color: var(--text1); font-weight: 600; }
.tt-hist { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* ── Painel de bairros (visão Boa Vista) ──────────────────────────────────── */
.painel-bairros-list {
  padding: 0 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.painel-bairro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: .76rem;
  color: var(--text2);
  background: var(--bg3);
  cursor: default;
  transition: background .15s;
}
.painel-bairro:hover { background: #ffffff08; }

.painel-bairro-nome { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.painel-bairro-zona {
  font-size: .68rem;
  font-weight: 600;
  color: var(--text3);
  background: var(--bg2);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ── Responsivo ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .grid-principal { grid-template-columns: 1fr; }

  #painel-lateral {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: 65vh;
    border-left: none;
    border-top: 2px solid var(--border);
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
    z-index: 200;
  }
  #painel-lateral.aberto { transform: translateY(0); }

  header { gap: 10px; padding: 0 14px; }
  .logo-sub { display: none; }
  nav.controls { gap: 10px; }
}

@media (max-width: 600px) {
  header { flex-wrap: wrap; height: auto; padding: 10px 14px; }
  .header-divider { display: none; }
  nav.controls { width: 100%; gap: 8px; }
  .ctrl-label { display: none; }
  #resumo-estadual { padding: 8px 14px; }
  #legenda { padding: 8px 14px; gap: 10px; }
}
