:root {
  --bg: #0d1522;
  --card: #16202f;
  --card2: #1b2940;
  --ink: #e8eef7;
  --muted: #94a6bd;
  --accent: #4f8dff;
  --accent2: #38c3ea;
  --good: #34d399;
  --bad: #f87171;
  --border: #243349;
}

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

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

.topbar {
  background: linear-gradient(135deg, #0a1424, #12305e);
  border-bottom: 1px solid var(--border);
  color: #fff;
  padding: 2.4rem 0 2rem;
}
.topbar-inner { display: flex; align-items: center; justify-content: flex-start; gap: 1.6rem; }
.topbar-logo img { height: 52px; width: auto; display: block; }
.topbar-logo { flex-shrink: 0; }
.topbar h1 { font-size: 1.7rem; font-weight: 650; display: flex; gap: .6rem; align-items: center; color: #fff; }
.badge {
  background: rgba(79,141,255,.18);
  border: 1px solid rgba(79,141,255,.5);
  color: #bcd4ff;
  font-size: .8rem; padding: .2rem .6rem; border-radius: 999px; letter-spacing: .08em;
}
.topbar .sub { color: #9db4d4; margin-top: .4rem; font-size: .95rem; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1rem; }

main.wrap { padding-top: 1.6rem; padding-bottom: 3rem; }


/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .9rem;
  margin-bottom: 1.4rem;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .85rem 1.1rem .7rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.kpi .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin-top: 0; color: var(--ink); }
.kpi .delta { font-size: .75rem; margin-top: .12rem; color: var(--muted); }
.kpi .delta.pos { color: var(--good); }
.kpi .delta.neg { color: var(--bad); }
.kpi-spark {
  margin-top: .45rem;
  padding-top: .4rem;
  border-top: 1px solid var(--border);
  height: 40px;
  overflow: hidden;
}
.kpi-spark svg { width: 100%; height: 100%; display: block; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.3rem 1.4rem 1.5rem;
  margin-bottom: 1.4rem;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.card h2 { font-size: 1.12rem; font-weight: 650; margin-bottom: .15rem; color: var(--ink); }
.card h2.con-boton { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }

.share-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: .28rem .7rem;
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.share-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: rgba(79,141,255,.08); }
.share-btn:disabled { opacity: .5; cursor: wait; }
.note { color: var(--muted); font-size: .85rem; margin-bottom: .8rem; }
.src { color: var(--muted); font-size: .78rem; margin-top: .6rem; }

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

.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 420px; }
.chart-box.tall.shrink { height: 300px; }
.chart-box.shrink { height: 300px; }
.grid-2.compact .chart-box { height: 222px; }
@media (max-width: 900px) { .grid-2.compact .chart-box { height: 224px; } }
@media (max-width: 600px) { .grid-2.compact .chart-box { height: 192px; } }

@media (max-width: 900px) {
  .chart-box { height: 280px; }
  .chart-box.shrink { height: 262px; }
  .chart-box.tall { height: 360px; }
  .chart-box.tall.shrink { height: 288px; }
  .card { padding: 1rem 1rem 1.2rem; }
}
@media (max-width: 600px) {
  .chart-box { height: 240px; }
  .chart-box.shrink { height: 225px; }
  .chart-box.tall { height: 320px; }
  .chart-box.tall.shrink { height: 256px; }
  .topbar h1 { font-size: 1.3rem; flex-wrap: wrap; }
  .kpi .value { font-size: 1.3rem; }
  .topbar-inner { flex-direction: column; align-items: flex-start; }
  .topbar-logo img { height: 36px; }
}

/* Barra de período presidencial */
.periodo-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: nowrap;
  background: rgba(13,21,34,.92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .7rem 1rem;
  margin-bottom: 1.4rem;
}
.periodo-titulo { font-size: .82rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.tit-corto, .lbl-corto { display: none; }
.periodo-bar .chip { white-space: nowrap; }
.periodo-bar .chip small { opacity: .75; font-weight: 400; }
.periodo-nota { margin-left: auto; font-size: .78rem; color: var(--muted); font-style: italic; }
@media (max-width: 900px) {
  .periodo-bar { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  .periodo-bar { flex-wrap: nowrap; gap: .3rem; padding: .5rem .6rem; }
  .periodo-titulo { font-size: .72rem; }
  .tit-largo { display: none; }
  .tit-corto { display: inline; }
  .periodo-bar .chip { font-size: .8rem; padding: .35rem .6rem; }
  .lbl-largo { display: none; }
  .lbl-corto { display: inline; }
  .periodo-bar .chip small { display: none; }
}

.chart-fixed-tip {
  position: absolute;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .4rem .65rem;
  font-size: .78rem;
  color: var(--ink);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  opacity: 0;
  transition: opacity .08s;
  pointer-events: none;
  z-index: 5;
  max-width: 300px;
  line-height: 1.35;
}
.cft-t { color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.cft-row { display: flex; align-items: center; gap: 5px; }
.cft-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.cft-val { font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.cft-lbl { flex: 1; min-width: 0; }

@media (max-width: 600px) {
  #btnFecPlay, #btnRamPlay, #fechSlider, #ramSlider { display: none; }
  .mapa-izq { display: none; }
  #card-mapa #btnFecAnt, #card-mapa #fechaActual, #card-mapa #btnFecSig, #card-mapa #fecPeriodo { display: none; }
}

/* Mapa por provincia */
.mapa-wrap {
  display: grid;
  grid-template-columns: minmax(0, 46%) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
}
@media (max-width: 900px) {
  .mapa-wrap { grid-template-columns: 1fr; }
}
#mapa-svg-box { display: flex; justify-content: center; }
#mapa-svg-box svg { width: auto; height: 560px; max-height: 75vh; max-width: 100%; display: block; }
@media (max-width: 900px) {
  #mapa-svg-box svg { height: auto; width: min(100%, 340px); max-height: none; }
}
.prov-path {
  stroke: #0d1522;
  stroke-width: 1.2;
  cursor: pointer;
  transition: opacity .12s;
}
.prov-path:hover, .prov-path.hl { stroke: #fff; stroke-width: 1.8; }

#mapa-leyenda {
  display: flex; flex-wrap: wrap; gap: .45rem .9rem;
  margin-top: .5rem; font-size: .72rem; color: var(--muted);
  align-items: center;
}
.leyenda-item { display: flex; align-items: center; gap: .3rem; }
.leyenda-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,.15); }

.rank-titulo { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .6rem; }
.rank-row {
  display: grid;
  grid-template-columns: 1.1rem 9.5rem 1fr 4.6rem;
  align-items: center;
  gap: .5rem;
  padding: .16rem 0;
  cursor: pointer;
  border-radius: 6px;
}
.rank-row:hover, .rank-row.hl { background: rgba(79,141,255,.12); }
.rank-num { color: var(--muted); font-size: .78rem; text-align: right; }
.rank-nom { font-size: .82rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar-bg { background: var(--card2); border-radius: 4px; height: 12px; overflow: hidden; }
.rank-bar { height: 100%; border-radius: 4px; }
.rank-val { font-size: .78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

#fechSlider, #ramSlider {
  flex: 1; min-width: 130px; accent-color: #4f8dff;
  cursor: pointer; height: 30px;
}
.fecha-btn {
  width: 30px; height: 30px;
  background: var(--card2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: .9rem; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: color .12s, border-color .12s;
}
.fecha-btn:hover { color: var(--ink); border-color: #4f8dff; }
#fechaActual {
  min-width: 4.6rem; text-align: center;
  font-size: .85rem; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.periodo-mes {
  background: var(--card2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  width: 5.4rem; text-align: center;
  padding: .2rem .6rem;
  font-size: .72rem; white-space: nowrap;
  line-height: 1;
}

.controls { display: flex; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; align-items: center; }
.chip {
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--muted);
  border-radius: 999px;
  padding: .35rem .9rem;
  font-size: .8rem;
  cursor: pointer;
  transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* Mapa provincial */
#mapa-card .controls { align-items: center; }
.map-mes {
  border: 1px solid var(--border);
  background: var(--card2);
  color: var(--ink);
  border-radius: 999px;
  padding: .35rem .8rem;
  font-size: .8rem;
  cursor: pointer;
}
.mapa-wrap {
  display: grid;
  grid-template-columns: minmax(0, 35%) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: stretch;
}
.mapa-canvas-box { position: relative; min-height: 520px; }
.mapa-ranking {
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .4rem .5rem;
  font-size: .8rem;
}
.rank-row {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 9.5rem) 1fr 4.2rem;
  gap: .5rem;
  align-items: center;
  padding: .18rem .3rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}
.rank-row:hover, .rank-row.hover { background: rgba(79,141,255,.10); color: var(--ink); }
.rank-num { text-align: right; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 10px; background: rgba(148,163,184,.12); border-radius: 5px; overflow: hidden; }
.rank-fill { display: block; height: 100%; border-radius: 5px; }
.rank-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.mapa-leyenda { display: flex; align-items: center; gap: .5rem; margin-top: .8rem; font-size: .78rem; color: var(--muted); flex-wrap: wrap; }
.mapa-leyenda .grad-bar { display: inline-block; width: 140px; height: 10px; border-radius: 5px; }
@media (max-width: 900px) {
  .mapa-wrap { grid-template-columns: 1fr; }
  .mapa-canvas-box { min-height: 440px; }
}

/* Table */
.table-wrap { overflow-x: auto; max-height: 480px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .82rem; color: var(--ink); }
th, td { padding: .4rem .7rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--card2); z-index: 1; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
td:first-child, th:first-child { text-align: left; }
td.neg { color: var(--bad); }
td.pos { color: var(--good); }

footer {
  color: var(--muted);
  font-size: .8rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}
footer p { margin-bottom: .4rem; }
footer strong { color: var(--ink); }
footer .gen { opacity: .7; font-style: italic; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
