:root {
  --azul: #0F2A43;
  --azul-2: #1E3A5F;
  --texto: #0F172A;
  --texto-2: #475569;
  --borde: #E2E8F0;
  --fondo: #F8FAFC;
  --blanco: #FFFFFF;
  --acento: #16A34A;
  --acento-suave: #DCFCE7;
  --radio: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* `hidden` debe ocultar siempre, incluso frente a reglas display de clases */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  line-height: 1.5;
  font-size: 16px;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* Header */
.site-header { background: var(--azul); color: #fff; padding: 14px 0; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand-mark { width: 12px; height: 12px; background: var(--acento); border-radius: 3px; }
.brand-name { font-weight: 700; font-size: 1.05rem; }
.brand-sub { color: #bcd0e4; font-size: 0.8rem; }
.header-link { color: #dbe7f3; font-size: 0.85rem; text-decoration: none; border-bottom: 1px solid transparent; }
.header-link:hover { border-bottom-color: var(--acento); }

/* Intro */
.intro { padding: 32px 0 20px; }
.intro h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 800; letter-spacing: -0.02em; }
.lede { color: var(--texto-2); margin-top: 6px; max-width: 60ch; }

/* Filtros */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 16px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(15,23,42,.05);
}
.filter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filtros-nota { font-size: 0.78rem; color: var(--texto-2); line-height: 1.5; margin: 0 0 16px; }
.filters .filtros-nota { grid-column: 1 / -1; margin: 0; }
.filter label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--texto-2); }
.filter select, .filter input {
  font: inherit; font-size: 0.95rem;
  padding: 9px 12px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--blanco);
  color: var(--texto);
  width: 100%;
}
.filter select:focus, .filter input:focus { outline: 2px solid var(--acento); outline-offset: 1px; border-color: var(--acento); }

/* Modo y ficha */
.modo { display: flex; gap: 8px; margin: 20px 0 16px; }
.modo-btn { font: inherit; font-size: 0.9rem; font-weight: 600; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--borde); background: var(--blanco); color: var(--texto-2); cursor: pointer; }
.modo-btn.activo { background: var(--azul); color: #fff; border-color: var(--azul); }
.ficha-titulo { font-size: 1.2rem; margin: 8px 0 14px; }
.ficha-seccion { margin-bottom: 20px; }
.ficha-seccion h3 { font-size: 0.95rem; font-weight: 700; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--borde); }
.ficha-chart-wrap { position: relative; height: 200px; background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 10px; margin-bottom: 12px; }
.ficha-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.ficha-card { display: flex; flex-direction: column; gap: 4px; text-align: left; font: inherit; padding: 14px 16px; background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); cursor: pointer; box-shadow: 0 1px 3px rgba(15,23,42,.04); transition: border-color .15s, box-shadow .15s; }
.ficha-card:hover { border-color: var(--acento); box-shadow: 0 2px 8px rgba(15,23,42,.08); }
.ficha-elec { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--texto-2); }
.ficha-ganador { font-weight: 700; font-size: 1rem; color: var(--texto); }
.ficha-meta { font-size: 0.82rem; color: var(--texto-2); }
.ficha-card-wrap { display: flex; flex-direction: column; }
.ficha-card-wrap .ficha-card { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.ficha-detalle { background: var(--blanco); border: 1px solid var(--borde); border-top: 0; border-radius: 0 0 var(--radio) var(--radio); padding: 10px 14px; }
.ficha-top3-titulo { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--texto-2); margin-bottom: 6px; }
.ficha-top3-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 0.85rem; }
.ficha-top3-row .swatch { flex: none; }
.ficha-puesto { flex: none; width: 16px; height: 16px; border-radius: 50%; background: var(--azul); color: #fff; font-size: 0.66rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.ficha-top3-nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--texto); }
.ficha-top3-votos { flex: none; color: var(--texto-2); font-size: 0.8rem; white-space: nowrap; }
.ficha-curul { flex: none; font-weight: 700; color: var(--azul); font-size: 0.8rem; white-space: nowrap; }
.ficha-preconteo { margin-top: 8px; padding: 6px 10px; background: #FFF7E6; border: 1px solid #F2E0B8; border-radius: 6px; font-size: 0.72rem; color: #8a6d1a; line-height: 1.4; }

/* Histórico (comparador) */
.hist-panel {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(15,23,42,.05);
}
.hist-grupo { margin-bottom: 16px; }
.hist-grupo:last-child { margin-bottom: 0; }
.hist-label { display: block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--texto-2); margin-bottom: 8px; }
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; background: var(--fondo); border: 1px solid var(--borde); border-radius: 999px; padding: 4px; }
.seg-btn { font: inherit; font-size: 0.86rem; font-weight: 600; padding: 7px 16px; border-radius: 999px; border: 0; background: transparent; color: var(--texto-2); cursor: pointer; }
.seg-btn.activo { background: var(--azul); color: #fff; }
.hist-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.agregar-item {
  margin-top: 12px; font: inherit; font-size: 0.86rem; font-weight: 600;
  padding: 8px 16px; border-radius: 8px; border: 1px dashed var(--borde);
  background: var(--fondo); color: var(--azul); cursor: pointer;
}
.agregar-item:hover { border-color: var(--acento); color: var(--acento); }
.hist-mapa { position: relative; height: 360px; border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; box-shadow: 0 1px 3px rgba(15,23,42,.05); background: #eef2f7; }
.hist-terr-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; align-items: start; }
.hist-indicadores { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 18px; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.hist-indicadores .ind-head h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 2px; color: var(--texto); }
.hist-indicadores .ind-sub { font-size: 0.76rem; color: var(--texto-2); margin-bottom: 14px; }
.hist-indicadores .ind-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.hist-indicadores .ind-card { background: var(--fondo); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.hist-indicadores .ind-card-val { font-size: 1.45rem; font-weight: 800; color: var(--acento); letter-spacing: -0.01em; line-height: 1.1; }
.hist-indicadores .ind-card-label { font-size: 0.72rem; color: var(--texto-2); text-transform: uppercase; letter-spacing: 0.04em; }
.hist-indicadores .ind-tables { display: grid; grid-template-columns: 1fr; gap: 14px; }
.hist-indicadores .ind-table h4 { font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--texto-2); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.hist-indicadores .ind-fuente { font-weight: 600; opacity: .65; font-size: .68rem; flex-shrink: 0; }
.hist-indicadores table { width: 100%; border-collapse: collapse; font-size: 0.8rem; table-layout: fixed; }
.hist-indicadores th, .hist-indicadores td { text-align: right; padding: 6px 12px; border-bottom: 1px solid var(--borde); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-indicadores th { font-weight: 600; color: var(--texto-2); font-size: 0.72rem; }
.hist-indicadores .ind-nota { font-size: 0.72rem; color: var(--texto-2); margin-top: 16px; line-height: 1.45; border-top: 1px solid var(--borde); padding-top: 10px; }
.hist-aviso {
  font-size: 0.85rem; color: #8a6d1a; background: #FFF7E6; border: 1px solid #F2D98C;
  border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; line-height: 1.5;
}
.hist-mapa-titulo {
  position: absolute; top: 10px; right: 12px; z-index: 600;
  background: var(--azul); color: #fff; font-size: 0.8rem; font-weight: 700;
  padding: 4px 12px; border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.25);
  pointer-events: none;
}
.hist-chart-wrap { position: relative; height: 340px; background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
#histTabla .tabla-card { border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; }
.nota-nombres { font-size: 0.82rem; color: var(--texto-2); background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; }

/* Búsqueda con autocompletado (escribe y ve los 5 más cercanos) */
.search { position: relative; min-width: 0; }
.search input {
  font: inherit; font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid var(--borde);
  border-radius: 8px;
  background: var(--blanco);
  color: var(--texto);
  width: 100%;
}
.search input:focus { outline: 2px solid var(--acento); outline-offset: 1px; border-color: var(--acento); }
.search-drop {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--blanco); border: 1px solid var(--borde); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15,23,42,.14); overflow: hidden;
}
.search-item { padding: 9px 12px; font-size: 0.9rem; cursor: pointer; border-bottom: 1px solid var(--borde); color: var(--texto); }
.search-item:last-child { border-bottom: 0; }
.search-item:hover { background: var(--acento-suave); }
.search-item .sub { display: block; font-size: 0.74rem; color: var(--texto-2); }

/* Ejemplo guía */
.hist-ejemplo {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radio);
  padding: 14px 16px; margin-bottom: 20px; font-size: 0.9rem; color: var(--texto);
}
.hist-ejemplo h3 { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--azul); margin-bottom: 8px; }
.hist-ejemplo p { margin: 0 0 8px; }
.hist-ejemplo .ej-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.ej-tag {
  font-size: 0.8rem; font-weight: 600; padding: 4px 12px; border-radius: 999px;
  background: var(--blanco); border: 1px solid var(--borde); color: var(--azul); cursor: pointer;
}
.ej-tag:hover { border-color: var(--acento); color: var(--acento); }

/* Acciones de consulta */
.acciones { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.accion-btn { font: inherit; font-size: 0.88rem; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--borde); background: var(--blanco); color: var(--texto-2); cursor: pointer; }
.accion-btn:hover { border-color: var(--azul); color: var(--azul); }
.accion-btn--primario { background: var(--azul); color: #fff; border-color: var(--azul); }
.accion-btn--primario:hover { background: var(--azul-2); color: #fff; }

/* Voto en el exterior */
.exterior-card { background: var(--blanco); border: 1px solid var(--borde); border-left: 4px solid var(--acento); border-radius: var(--radio); padding: 14px 18px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.exterior-card h3 { font-size: 0.85rem; font-weight: 700; margin-bottom: 6px; }
.exterior-card .exterior-ganador { font-weight: 700; }
.exterior-card .exterior-detalle { color: var(--texto-2); font-size: 0.85rem; margin-top: 4px; }

/* Mapa */
.mapa-wrap { margin-bottom: 24px; position: relative; }
.drill-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--azul); color: #fff; border-radius: var(--radio) var(--radio) 0 0; padding: 8px 14px; font-size: 0.85rem; font-weight: 600; }
.drill-volver { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: 4px 10px; font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.drill-volver:hover { background: rgba(255,255,255,.28); }
#mapa { position: relative; height: 420px; border-radius: 0 0 var(--radio) var(--radio); border: 1px solid var(--borde); box-shadow: 0 1px 3px rgba(15,23,42,.05); z-index: 0; background: #eef2f7; }
#inset { position: absolute; top: 14px; right: 14px; width: 200px; height: 200px; border: 2px solid #ffffff; border-radius: 8px; box-shadow: 0 2px 10px rgba(15,23,42,.25); z-index: 500; background: #cfe3f5; overflow: hidden; }
#inset .leaflet-container { background: #eef2f7; }
.inset-tag { position: absolute; top: 4px; left: 4px; z-index: 501; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--texto-2); background: rgba(255,255,255,.85); border-radius: 4px; padding: 2px 6px; pointer-events: none; }
.leyenda { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.leyenda-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--texto-2); background: var(--blanco); border: 1px solid var(--borde); border-radius: 6px; padding: 4px 8px; }
.leyenda-item i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }

/* Resultado */
.resultado { min-height: 200px; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--texto-2);
  border: 1px dashed var(--borde); border-radius: var(--radio); background: var(--blanco);
}

.ganador-card {
  background: var(--blanco);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(15,23,42,.05);
}
.ganador-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--acento); }
.ganador-nombre { font-size: clamp(1.5rem, 4vw, 2.2rem); font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
.ganador-meta { color: var(--texto-2); margin-top: 4px; font-size: 0.95rem; }
.ganador-votos { font-size: 1.9rem; font-weight: 800; margin-top: 12px; }
.ganador-pct { font-size: 1rem; font-weight: 600; color: var(--acento); margin-top: 2px; }
.margen { margin-top: 10px; font-size: 0.9rem; color: var(--texto-2); }
.contexto { color: var(--texto-2); font-size: 0.85rem; margin-bottom: 10px; }

/* Tabla */
.tabla-card { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); overflow-x: auto; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.tabla-card table { min-width: 560px; }
.tabla-card h2 { font-size: 0.9rem; font-weight: 700; padding: 14px 18px; border-bottom: 1px solid var(--borde); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: right; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--texto-2); padding: 10px 18px; border-bottom: 1px solid var(--borde);
}
thead th:first-child, tbody td:first-child { text-align: left; }
tbody td { padding: 11px 18px; border-bottom: 1px solid var(--fondo); text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.ganador-fila { background: var(--acento-suave); }
td.nombre { font-weight: 500; }
td.partido { color: var(--texto-2); font-size: 0.85rem; }
td.votos { font-weight: 600; }
td.pct { font-weight: 700; color: var(--azul); }
.barra { display: inline-block; height: 8px; border-radius: 4px; background: var(--acento); vertical-align: middle; margin-right: 8px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; vertical-align: middle; flex: none; }
.badge-partido { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 5px; border-radius: 50%; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.02em; color: #fff; margin-right: 8px; vertical-align: middle; text-shadow: 0 1px 1px rgba(0,0,0,.2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }

/* Torta (distribución del voto) */
.torta-wrap { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.torta-titulo { font-size: 0.9rem; font-weight: 700; margin-bottom: 10px; }
#resultChart { height: 300px; max-height: 300px; }

/* Quién ha ganado más veces (ficha) */
.mas-ganadores { background: var(--blanco); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px 18px; margin-top: 18px; box-shadow: 0 1px 3px rgba(15,23,42,.05); }
.mas-ganadores h3 { font-size: 0.95rem; margin-bottom: 12px; }
.mg-seccion { margin-bottom: 12px; }
.mg-seccion:last-child { margin-bottom: 0; }
.mg-seccion h4 { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--texto-2); margin-bottom: 6px; }
.mg-fila { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.mg-nombre { flex: 0 0 auto; font-weight: 600; font-size: 0.9rem; max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-barra { flex: 1; height: 6px; background: var(--fondo); border-radius: 3px; overflow: hidden; }
.mg-barra i { display: block; height: 100%; border-radius: 3px; }
.mg-num { flex: 0 0 auto; font-size: 0.8rem; color: var(--texto-2); font-variant-numeric: tabular-nums; }

.especiales { padding: 12px 18px; color: var(--texto-2); font-size: 0.85rem; border-top: 1px solid var(--borde); }
.especiales span { margin-right: 18px; white-space: nowrap; }

/* Fuentes */
.fuentes { padding: 32px 0 8px; }
.fuentes h2 { font-size: 1.05rem; margin-bottom: 8px; }
.fuentes p { color: var(--texto-2); font-size: 0.9rem; max-width: 70ch; }
.fuentes ul { list-style: none; margin-top: 12px; }
.fuentes li { padding: 10px 0; border-bottom: 1px solid var(--borde); }
.fuentes li strong { display: block; color: var(--texto); font-size: 0.9rem; }
.fuentes li p { margin-top: 2px; }
.fuente-nota { font-size: 0.8rem; color: var(--texto-2); margin-top: 12px; font-style: italic; }
.fuentes a { color: var(--azul); }

/* Footer */
.site-footer { border-top: 1px solid var(--borde); margin-top: 40px; padding: 20px 0; background: var(--blanco); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--texto-2); font-size: 0.85rem; }
.footer-inner strong { color: var(--texto); }

/* Responsive */
@media (max-width: 760px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filter--territorio { grid-column: 1 / -1; }
  .ganador-card { padding: 18px; }
  tbody td { padding: 9px 12px; }
  thead th { padding: 8px 12px; }
  #mapa { height: 320px; }
  #inset { width: 150px; height: 150px; top: 10px; right: 10px; }
  .ficha-chart-wrap { height: 170px; }
  .acciones { gap: 8px; }
  .hist-terr-grid { grid-template-columns: 1fr; }
  .hist-indicadores .ind-cards { grid-template-columns: 1fr; }
  .hist-indicadores .ind-tables { grid-template-columns: 1fr; }
  .hist-mapa { height: 280px; }
}
@media (max-width: 460px) {
  .filters { grid-template-columns: 1fr; }
  .intro { padding-top: 24px; }
  .modo { flex-wrap: wrap; }
  .accion-btn { flex: 1 1 100%; }
  #mapa { height: 260px; }
  #inset { width: 130px; height: 130px; }
  .inset-tag { font-size: 0.55rem; }
  .ficha-cards { grid-template-columns: 1fr; }
  .ganador-votos { font-size: 1.5rem; }
  .mg-nombre { max-width: 45%; }
}
