@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg:      #111827;
  --surface: #1F2937;
  --surface2:#283548;
  --surface3:#334155;
  --border:  rgba(255,255,255,.12);
  --border2: rgba(255,255,255,.20);

  --text:  #F8FAFC;
  --text2: #CBD5E1;
  --text3: #94A3B8;
  --text4: #64748B;

  --accent:  #FF6B6B;
  --accent2: #FFAA5C;
  --accent3: #FFD93D;
  --accent4: #6EE7B7;
  --p:       #C4B5FD;
  --p2:      #8B5CF6;

  --shadow:  0 2px 12px rgba(0,0,0,.3);
  --shadow2: 0 8px 30px rgba(0,0,0,.45);
  --r:  12px;
  --rs:  8px;
  --rx:  5px;
  --tr:  .2s ease;
  --f:  'Outfit', system-ui, sans-serif;
  --fm: 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--f);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.header {
  height: 62px;
  padding: 0 16px;
  background: linear-gradient(135deg, #1a1f35, #2d1b5e 50%, #1a1f35);
  border-bottom: 2px solid var(--p2);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}
.header-brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-logo  { height: 46px; width: auto; filter: drop-shadow(0 0 12px rgba(167,139,250,.5)); }

.header-texts { display: flex; flex-direction: column; gap: 0; }
.header-title { font: 700 .82rem var(--f); color: #fff; letter-spacing: -.01em; }
.header-sub   { font: 400 .52rem var(--f); color: rgba(255,255,255,.35); letter-spacing: .08em; text-transform: uppercase; }

.header-stats { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.stat-chip {
  display: flex; flex-direction: column; align-items: center;
  padding: 3px 10px; border-radius: 6px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.07);
}
.stat-num   { font: 700 .78rem var(--fm); line-height: 1.2; }
.stat-label { font: 400 .42rem var(--f); color: rgba(255,255,255,.35); text-transform: uppercase; letter-spacing: .04em; }
.stat-chip.green .stat-num { color: #86efac; }
.stat-chip.amber .stat-num { color: #fde68a; }
.stat-chip.blue  .stat-num { color: var(--p); }

.btn-icon {
  width: 34px; height: 34px; border-radius: var(--rx);
  border: 1px solid rgba(255,255,255,.12);
  background: transparent; color: rgba(255,255,255,.45);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: var(--tr); flex-shrink: 0;
}
.btn-icon:hover { color: var(--p); border-color: var(--p); }

/* Ocultar el botón hamburguesa del header en desktop */
@media (min-width: 769px) {
  #btnPanel { display: none; }
}

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
.layout {
  display: flex;
  height: calc(100vh - 62px);
  height: calc(100dvh - 62px);
  position: relative;
}

/* ══════════════════════════════════════
   PANEL — Floating overlay en todas las pantallas
══════════════════════════════════════ */
.panel {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 320px;
  z-index: 20;
  background: rgba(31,41,55,.97);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border2);
  border-radius: 0 var(--r) var(--r) 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--p2) transparent;
  box-shadow: 6px 0 32px rgba(0,0,0,.5);
  transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .22s ease;
  transform: translateX(0);
}
.panel.collapsed {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Botón flotante para abrir/cerrar el panel en desktop */
.panel-toggle-fab {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 21;
  width: 28px;
  height: 56px;
  background: rgba(13,13,22,.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border2);
  border-left: none;
  border-radius: 0 10px 10px 0;
  color: var(--text2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--tr);
  box-shadow: 3px 0 14px rgba(0,0,0,.35);
}
.panel-toggle-fab:hover { color: var(--p); background: rgba(20,16,40,.97); }
.panel-toggle-fab.open { left: 320px; }
.panel-toggle-fab svg { transition: transform .25s ease; }
.panel-toggle-fab.open svg { transform: rotate(180deg); }
.panel::-webkit-scrollbar { width: 3px; }
.panel::-webkit-scrollbar-thumb { background: var(--p2); border-radius: 3px; }

.panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

/* Búsqueda */
.search-box {
  position: relative; display: flex; align-items: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--rs); overflow: hidden;
}
.search-icon { position: absolute; left: 8px; color: var(--text3); pointer-events: none; }
.search-box input {
  width: 100%; border: none; background: transparent;
  color: var(--text); font: 400 .8rem var(--f);
  padding: 9px 10px 9px 28px; outline: none;
}
.search-box input::placeholder { color: var(--text3); font-size: .75rem; }
.search-box:focus-within { border-color: var(--p); box-shadow: 0 0 0 2px rgba(124,58,237,.15); }

.search-results {
  display: none;
  background: var(--surface); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--rs) var(--rs);
  max-height: 260px; overflow-y: auto;
  box-shadow: var(--shadow2); z-index: 20; position: relative;
}
.search-results.show { display: block; }
.sr-item {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid rgba(255,255,255,.03);
}
.sr-item:hover    { background: var(--surface2); }
.sr-item:active   { background: var(--surface3); }
.sr-icon          { font-size: 11px; flex-shrink: 0; }
.sr-info          { flex: 1; min-width: 0; }
.sr-name          { font: 500 .72rem var(--f); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-name mark, .sr-detail mark { background: rgba(167,139,250,.25); color: var(--p); padding: 0 1px; border-radius: 2px; }
.sr-detail        { font: 400 .58rem var(--f); color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-empty         { padding: 14px; text-align: center; color: var(--text3); font-size: .72rem; }

/* Filtros */
.filter-label {
  font: 600 .58rem var(--f); color: var(--text3);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 5px; display: block;
}
.filter-select {
  width: 100%; padding: 8px 28px 8px 10px;
  border: 1px solid var(--border); border-radius: var(--rx);
  background: var(--surface2); color: var(--text);
  font: 400 .78rem var(--f); outline: none; cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394A3B8'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
  transition: var(--tr);
}
.filter-select:focus { border-color: var(--p); box-shadow: 0 0 0 2px rgba(139,92,246,.15); }

/* Sliders */
.slider-row {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
}
.slider {
  flex: 1; height: 4px; appearance: none;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent2) 50%, var(--accent3) 100%);
  border-radius: 10px; outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--text);
  border: 2px solid var(--accent2); cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--accent2); cursor: pointer;
}
.slider-val  { font: 700 .62rem var(--fm); color: var(--accent2); min-width: 42px; text-align: right; }
.slider-hint { font: 400 .5rem var(--fm); color: var(--text4); margin-top: 4px; letter-spacing: .02em; }

/* Leyenda gradiente */
.legend-gradient {
  height: 8px; border-radius: 10px; margin: 6px 0 4px;
  background: linear-gradient(to right,
    #000000 0%,
    #0a0a14 10%,
    #1a0a2e 20%,
    #3b0764 32%,
    #7c1d6f 44%,
    #c2185b 56%,
    #ff5722 68%,
    #ff9800 80%,
    #ffeb3b 90%,
    #ffffff 100%
  );
}
.legend-labels {
  display: flex; justify-content: space-between; margin-bottom: 5px;
}
.legend-lbl { font: 400 .48rem var(--fm); color: var(--text3); }
.legend-bands { display: flex; gap: 3px; }
.legend-band {
  flex: 1; text-align: center;
  font: 600 .46rem var(--f); padding: 2px 3px; border-radius: 3px;
}
.band-1 { background: rgba(124,29,111,.3);  color: #d891c8; }
.band-2 { background: rgba(194,24,91,.3);   color: #f48fb1; }
.band-3 { background: rgba(255,87,34,.3);   color: #ffab91; }
.band-4 { background: rgba(255,235,59,.3);  color: #fff176; }

/* Stats panel */
.stat-row {
  display: flex; align-items: baseline;
  justify-content: space-between; padding: 4px 0;
}
.stat-lbl   { font: 400 .65rem var(--f); color: var(--text3); }
.stat-val   { font: 700 .66rem var(--fm); color: var(--text); }
.stat-val.accent { color: var(--accent2); }

/* Layer toggles */
.layer-toggles { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.layer-toggle {
  display: flex; align-items: center; gap: 7px;
  font: 500 .7rem var(--f); color: var(--text);
  cursor: pointer; padding: 5px 7px; border-radius: var(--rx);
  transition: background var(--tr); user-select: none;
}
.layer-toggle:hover { background: var(--surface2); }
.layer-toggle input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--p); cursor: pointer; flex-shrink: 0; }
.layer-swatch { width: 14px; height: 10px; border-radius: 2px; border: 1.5px solid; flex-shrink: 0; }
.layer-swatch-circle { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid; flex-shrink: 0; }

/* Leyenda de puntos por intervalo (paleta dinámica) */
.lp-subtitle { font: 400 .52rem var(--f); color: var(--text4); margin-bottom: 5px; letter-spacing: .03em; }
.legenda-puntos { display: flex; flex-direction: column; gap: 3px; margin-top: 2px; }
.lp-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 7px; border-radius: var(--rx);
  background: var(--surface2); border: 1px solid var(--border);
  transition: background var(--tr);
}
.lp-row:hover { background: var(--surface3); }
.lp-dot {
  width: 11px; height: 11px; border-radius: 50%;
  flex-shrink: 0;
}
.lp-label {
  font: 500 .63rem var(--fm); color: var(--text2);
  letter-spacing: .01em; flex: 1;
}
.lp-rank {
  font: 600 .48rem var(--f); color: var(--text4);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface3); padding: 1px 5px; border-radius: 3px;
}

/* ══════════════════════════════════════
   LEYENDA FLOTANTE DENTRO DEL MAPA
══════════════════════════════════════ */
/* ── Stats FAB (superior derecha) ── */
.map-stats-fab {
  position: absolute;
  top: 10px; right: 10px;
  z-index: 12;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.map-stats-btn {
  width: 42px; height: 42px;
  background: #1e293b;
  border: 1.5px solid #475569;
  border-radius: 10px;
  color: #6ee7b7;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  transition: all .2s ease;
  flex-shrink: 0;
}
.map-stats-btn:hover  { background: #334155; border-color: #2dd4bf; }
.map-stats-btn.active { border-color: #2dd4bf; background: #0f2a26;
  box-shadow: 0 0 0 2px rgba(45,212,191,.3), 0 4px 16px rgba(0,0,0,.5); }
.map-stats-panel {
  display: none;
  background: #0f172a;
  border: 1.5px solid #334155;
  border-radius: 14px;
  width: 340px;
  max-height: calc(100vh - 220px);
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin; scrollbar-color: #334155 transparent;
  box-shadow: 0 12px 40px rgba(0,0,0,.7);
  animation: legendIn .18s ease;
}
.map-stats-panel.open { display: block; }
.ms-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 9px;
  background: #1e293b;
  border-bottom: 1.5px solid #334155;
  position: sticky; top: 0; z-index: 2;
}
.ms-title {
  font: 800 .68rem var(--f); color: #f1f5f9;
  letter-spacing: .1em; text-transform: uppercase; flex: 1;
}
.ms-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; }

/* Tarjetas full-width apiladas */
.ms-body .es-metric { width: 100%; }
.es-m-wide { margin-bottom: 0; }

/* ── Legend FAB (inferior derecha) ── */
.map-legend-fab {
  position: absolute;
  bottom: 36px; right: 10px;
  z-index: 12;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.map-legend-btn {
  width: 42px; height: 42px;
  background: #1e293b;
  border: 1.5px solid #475569;
  border-radius: 10px;
  color: #C4B5FD;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  transition: all .2s ease;
  flex-shrink: 0;
}
.map-legend-btn:hover { background: #334155; border-color: #8B5CF6; color: #ddd6fe; }
.map-legend-btn.active { border-color: #8B5CF6; background: #2d2060; box-shadow: 0 0 0 2px rgba(139,92,246,.35), 0 4px 16px rgba(0,0,0,.5); }

.map-legend-panel {
  display: none;
  background: #0f172a;
  border: 1.5px solid #475569;
  border-radius: 14px;
  padding: 0;
  min-width: 220px;
  max-width: 248px;
  box-shadow: 0 12px 40px rgba(0,0,0,.7);
  overflow: hidden;
  animation: legendIn .18s ease;
}
.map-legend-panel.open { display: block; }
@keyframes legendIn { from { opacity:0; transform: translateY(6px) scale(.97); } to { opacity:1; transform: none; } }

/* Cabecera leyenda */
.ml-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 9px;
  background: #1e293b;
  border-bottom: 1.5px solid #334155;
}
.ml-header-title {
  font: 800 .78rem var(--f);
  color: #f1f5f9;
  letter-spacing: .12em;
  text-transform: uppercase;
}

/* Bloques internos */
.ml-block {
  padding: 10px 14px;
  border-bottom: 1px solid #1e293b;
}
.ml-block:last-child { border-bottom: none; }
.ml-block-title {
  font: 700 .58rem var(--f);
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 7px;
}

/* Barra KDE */
.ml-kde-bar {
  height: 12px; border-radius: 8px; margin-bottom: 3px;
  border: 1px solid rgba(255,255,255,.08);
}
.ml-kde-axis {
  display: flex; justify-content: space-between;
  font: 400 .46rem var(--fm); color: var(--text4);
  margin-bottom: 3px; letter-spacing: -.01em;
}
.ml-kde-unit {
  font: 400 .44rem var(--fm); color: rgba(94,234,212,.6);
  margin-bottom: 6px; letter-spacing: .01em;
}
/* Bandas científicas */
.ml-kde-bands { display: flex; flex-direction: column; gap: 3px; }
.ml-kde-band {
  display: grid; grid-template-columns: 12px 1fr auto auto;
  gap: 5px; align-items: center;
}
.ml-kde-sw {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}
.ml-kde-bname { font: 500 .54rem var(--f); color: var(--text2); }
.ml-kde-density {
  font: 400 .46rem var(--fm); color: var(--text4);
  text-align: right; white-space: nowrap;
}
.ml-kde-hab-pct {
  font: 700 .52rem var(--fm); color: #5eead4;
  min-width: 34px; text-align: right;
}

/* Filas de puntos */
.ml-rows { display: flex; flex-direction: column; gap: 4px; }
.ml-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
}
.ml-dot {
  width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.25);
}
.ml-lbl { font: 600 .62rem var(--fm); color: #e2e8f0; flex: 1; }
.ml-q   {
  font: 700 .46rem var(--f); color: #94a3b8;
  background: #0f172a; padding: 2px 5px;
  border-radius: 3px; border: 1px solid #334155;
  letter-spacing: .04em;
}


/* Créditos clickeables */
.map-credit {
  position: absolute; bottom: 6px; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font: 500 .55rem var(--f); color: rgba(240,237,255,.55);
  background: rgba(15,23,42,.82); backdrop-filter: blur(6px);
  padding: 4px 12px; border-radius: 8px;
  cursor: pointer; user-select: none;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden; text-overflow: ellipsis;
  border: 1px solid rgba(167,139,250,.18);
  transition: var(--tr);
}
.map-credit:hover { color: #C4B5FD; border-color: rgba(139,92,246,.4); background: rgba(30,41,59,.9); }
.map-credit strong { font-weight: 700; color: rgba(240,237,255,.8); }
@media (max-width: 600px) {
  .map-credit { font-size: .48rem; padding: 3px 8px; }
}

/* Modal de créditos */
.credits-modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 250;
  background: rgba(0,0,0,.65); backdrop-filter: blur(5px);
  align-items: center; justify-content: center;
  padding: 16px;
}
.credits-modal-overlay.open { display: flex; }
.credits-modal {
  background: #0f172a; border: 1.5px solid #334155;
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.7);
  padding: 24px 20px; max-width: 420px; width: 100%;
  position: relative; text-align: center;
  animation: mIn .22s ease;
  max-height: 90vh; overflow-y: auto;
}
.credits-close {
  position: absolute; top: 12px; right: 12px;
  width: 26px; height: 26px; border-radius: 6px;
  background: #1e293b; border: 1px solid #334155;
  color: #94a3b8; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--tr);
}
.credits-close:hover { color: #FF6B6B; border-color: #FF6B6B; }
.credits-logo img { height: 48px; width: auto; margin-bottom: 8px; }
.credits-logo-wrap {
  display: flex; justify-content: center; margin-bottom: 10px;
}
.credits-logo-img {
  height: 52px; width: auto;
  filter: drop-shadow(0 0 12px rgba(167,139,250,.55));
}
.credits-title { font: 800 .95rem var(--f); color: #f1f5f9; margin-bottom: 3px; }
.credits-sub   { font: 400 .62rem var(--f); color: #64748b; margin-bottom: 16px; }
.credits-people { display: flex; flex-direction: column; gap: 0; }
.credits-person { padding: 12px 0; }
.credits-name { font: 700 .78rem var(--f); color: #e2e8f0; margin-bottom: 3px; line-height: 1.3; }
.credits-role { font: 400 .6rem var(--f); color: #64748b; margin-bottom: 6px; }
.credits-email {
  display: inline-block; font: 500 .62rem var(--fm);
  color: #C4B5FD; text-decoration: none;
  background: rgba(139,92,246,.12); border: 1px solid rgba(139,92,246,.3);
  padding: 3px 10px; border-radius: 20px;
  transition: var(--tr); word-break: break-all;
}
.credits-email:hover { background: rgba(139,92,246,.25); color: #ddd6fe; }
.credits-divider { height: 1px; background: #1e293b; margin: 0 10px; }
.map-area { flex: 1; width: 100%; position: relative; background: var(--bg); }
#map      { width: 100%; height: 100%; z-index: 1; }

/* Búsqueda flotante móvil */
.float-search {
  display: none; position: absolute;
  top: 10px; left: 10px; right: 60px; z-index: 12;
  flex-direction: column;
}
.float-search.show { display: flex; }
.float-search input {
  width: 100%; padding: 10px 38px 10px 12px;
  border: 1px solid var(--border); border-radius: var(--rs);
  background: var(--surface); color: var(--text);
  font: 400 .82rem var(--f); outline: none; box-shadow: var(--shadow2);
}
.float-search input:focus { border-color: var(--p); }
.float-close {
  position: absolute; right: 6px; top: 6px;
  width: 28px; height: 28px; border: none;
  background: var(--surface2); border-radius: 4px;
  color: var(--text3); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.float-results { margin-top: 3px; border-radius: var(--rs); box-shadow: var(--shadow2); }

.mob-btn-search {
  display: none; position: absolute; top: 10px; right: 10px; z-index: 11;
  width: 40px; height: 40px; border-radius: var(--rs);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer;
  align-items: center; justify-content: center;
  box-shadow: var(--shadow); transition: var(--tr);
}
.mob-btn-search:hover { color: var(--p); border-color: var(--p); }

/* Watermark */
.map-watermark {
  position: absolute; bottom: 8px; left: 8px;
  z-index: 10;
  pointer-events: none; opacity: .25;
}

/* ══════════════════════════════════════
   LEAFLET OVERRIDES
══════════════════════════════════════ */
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text2) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--surface2) !important; color: var(--text) !important; }
.leaflet-control-attribution { display: none !important; }
.leaflet-interactive { cursor: pointer; outline: none !important; }
.leaflet-interactive:focus, .leaflet-container *:focus { outline: none !important; }

/* Popup */
.pp-popup .leaflet-popup-content-wrapper {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 14px; box-shadow: var(--shadow2);
  padding: 0; overflow: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,92,246,.4) transparent;
}
.pp-popup .leaflet-popup-content-wrapper::-webkit-scrollbar { width: 4px; }
.pp-popup .leaflet-popup-content-wrapper::-webkit-scrollbar-track { background: transparent; }
.pp-popup .leaflet-popup-content-wrapper::-webkit-scrollbar-thumb {
  background: rgba(139,92,246,.4); border-radius: 4px;
}
.pp-popup .leaflet-popup-content-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(139,92,246,.7);
}
.pp-popup .leaflet-popup-content { margin: 0 !important; width: 100% !important; }
.pp-popup .leaflet-popup-tip { background: var(--surface); border: 1px solid var(--border); }
.pp-popup .leaflet-popup-close-button {
  top: 10px !important; right: 10px !important;
  color: #94a3b8 !important; font-size: 16px !important;
  width: 26px !important; height: 26px !important;
  display: flex !important; align-items: center !important;
  justify-content: center !important; line-height: 1 !important;
  background: rgba(15,12,30,.95) !important;
  border: 1.5px solid rgba(139,92,246,.35) !important;
  border-radius: 50% !important;
  box-shadow: 0 0 8px rgba(0,0,0,.6) !important;
  z-index: 999 !important;
  transition: all .15s !important;
}
.pp-popup .leaflet-popup-close-button:hover {
  color: #fff !important;
  background: rgba(239,68,68,.2) !important;
  border-color: rgba(239,68,68,.6) !important;
  box-shadow: 0 0 10px rgba(239,68,68,.3) !important;
}

.pp-card { font-family: var(--f); width: 100%; }
.pp-header {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.pp-title    { font: 700 .88rem var(--f); color: var(--text); line-height: 1.2; }
.pp-subtitle { font: 400 .6rem var(--f); color: var(--text3); margin-top: 2px; }
.pp-stats    { display: flex; gap: 1px; background: var(--border); }
.pp-stat     { flex: 1; background: var(--surface); padding: 10px 8px; text-align: center; }
.pp-stat-val { font: 800 1rem var(--fm); color: var(--text); line-height: 1; }
.pp-stat-lbl { font: 400 .48rem var(--f); color: var(--text4); text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; }

/* Barra de habilitados en popup */
.pp-hab-section { padding: 10px 14px; }
.pp-hab-label   { font: 600 .58rem var(--f); color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; display: block; }
.pp-hab-bar-bg  { height: 10px; background: var(--surface2); border-radius: 10px; overflow: hidden; margin-bottom: 4px; }
.pp-hab-bar-fill { height: 100%; border-radius: 10px; transition: width .5s ease; }
.pp-hab-val     { font: 700 .75rem var(--fm); color: var(--text); }
.pp-hab-pct     { font: 500 .58rem var(--f); color: var(--text3); float: right; }

/* ══════════════════════════════════════
   MODAL
══════════════════════════════════════ */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 14px; box-shadow: var(--shadow2);
  max-width: 460px; width: 88vw; max-height: 65vh;
  display: flex; flex-direction: column;
  animation: mIn .25s ease;
}
@keyframes mIn { from { transform: translateY(20px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.modal-logo      { height: 24px; width: auto; flex-shrink: 0; }
.modal-head-info { flex: 1; min-width: 0; }
.modal-title     { font: 700 .75rem var(--f); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-sub       { font: 400 .5rem var(--f); color: var(--text3); }
.modal-x {
  width: 24px; height: 24px; border: 1px solid var(--border); border-radius: var(--rx);
  background: transparent; color: var(--text3); font-size: 13px;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: var(--tr);
}
.modal-x:hover { color: var(--accent); border-color: var(--accent); }
.modal-body {
  padding: 12px; overflow-y: auto; flex: 1; min-height: 0;
  scrollbar-width: thin; scrollbar-color: var(--p2) transparent;
}
.modal-body::-webkit-scrollbar { width: 3px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--p2); border-radius: 3px; }
.modal-credit {
  flex-shrink: 0; text-align: right; padding: 3px 10px;
  font: 400 .4rem var(--f); color: var(--text4);
  border-top: 1px solid var(--border); opacity: .5;
}

/* Modal contenido */
.m-card-title { font: 700 .65rem var(--f); color: var(--text3); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.m-stats { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.m-stat {
  flex: 1; min-width: 60px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--rs);
  padding: 8px 6px; text-align: center; display: flex; flex-direction: column; align-items: center;
}
.m-stat-v { font: 700 .8rem var(--fm); color: var(--text); line-height: 1.1; }
.m-stat-l { font: 400 .42rem var(--f); color: var(--text4); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.m-stat.highlight { border-color: var(--accent2); }
.m-stat.highlight .m-stat-v { color: var(--accent2); }

/* Barra habilitados en modal */
.m-hab-section { margin-bottom: 12px; }
.m-hab-label   { font: 600 .6rem var(--f); color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; display: flex; justify-content: space-between; align-items: center; }
.m-hab-pct-txt { font: 700 .65rem var(--fm); color: var(--accent2); }
.m-hab-bg      { height: 12px; background: var(--surface2); border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.m-hab-fill    { height: 100%; border-radius: 10px; transition: width .6s ease; }

/* Rankin nacional */
.m-rank-section { margin-bottom: 0; }
.m-rank-label   { font: 600 .6rem var(--f); color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; display: block; }
.m-rank-row     { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.m-rank-row:last-child { border-bottom: none; }
.m-rank-pos     { font: 700 .58rem var(--fm); color: var(--text3); min-width: 20px; }
.m-rank-name    { font: 500 .65rem var(--f); color: var(--text); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-rank-val     { font: 700 .62rem var(--fm); color: var(--accent2); }

/* ══════════════════════════════════════
   LOADER & TOAST
══════════════════════════════════════ */
.loader-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,.65); backdrop-filter: blur(3px);
  align-items: center; justify-content: center; flex-direction: column; gap: 12px;
}
.loader-overlay.show { display: flex; }
.loader-ring {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,.1);
  border-top-color: var(--accent2); border-radius: 50%;
  animation: spin .7s linear infinite;
}
.loader-text { color: #fff; font: 500 .75rem var(--f); }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 16px; right: 16px; z-index: 400;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--rs); padding: 10px 14px;
  display: none; align-items: center; gap: 8px;
  box-shadow: var(--shadow2); font: 500 .72rem var(--f);
  color: var(--text); max-width: 320px; animation: toastIn .25s ease;
}
.toast.show    { display: flex; }
.toast.success { border-left: 3px solid #86efac; }
.toast.error   { border-left: 3px solid var(--accent); }
.toast-icon    { font-size: 15px; }
@keyframes toastIn { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 1024px) {
  .panel { width: 268px; }
  .panel-toggle-fab.open { left: 268px; }
}
@media (max-width: 768px) {
  .header { height: 58px; padding: 0 10px; gap: 8px; }
  .header-logo { height: 42px; }
  .header-sub { display: none; }
  .header-title { font-size: .75rem; }
  .stat-chip { padding: 2px 6px; }
  .stat-num { font-size: .65rem; }
  .stat-label { display: none; }
  .layout { height: calc(100vh - 58px); height: calc(100dvh - 58px); }
  .panel {
    width: 82%; max-width: 300px;
    border-radius: 0 14px 14px 0;
  }
  .panel-toggle-fab.open { left: min(82%, 300px); }
  .panel.collapsed { transform: translateX(-110%); }
  .mob-btn-search { display: flex; }
  .modal { width: 92vw; max-height: 62vh; border-radius: 12px; }
  .map-credit { font-size: .5rem; }
}
@media (max-width: 480px) {
  .header { height: 54px; padding: 0 8px; }
  .header-logo { height: 38px; }
  .header-stats { gap: 3px; }
  .layout { height: calc(100vh - 54px); height: calc(100dvh - 54px); }
  .modal { width: 94vw; max-height: 60vh; }
  .m-stat-v { font-size: .7rem; }
}
@media (max-width: 375px) {
  .header-stats { display: none; }
  .header { height: 50px; }
  .layout { height: calc(100vh - 50px); height: calc(100dvh - 50px); }
}
@media (max-height: 500px) and (orientation: landscape) {
  .header { height: 38px; }
  .header-logo { height: 26px; }
  .layout { height: calc(100vh - 38px); }
  .modal { max-height: 55vh; }
}

/* ══════════════════════════════════════
   TABS NAV
══════════════════════════════════════ */
.tabs-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  padding: 6px 13px;
  border-radius: 8px;
  border: 1.5px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: rgba(255,255,255,.5);
  font: 600 .68rem var(--f);
  cursor: pointer;
  white-space: nowrap;
  transition: all .18s ease;
  letter-spacing: .02em;
  flex-shrink: 0;
}
.tab-btn:hover { color: #fff; border-color: rgba(255,255,255,.28); background: rgba(255,255,255,.08); }
.tab-btn.active {
  color: #fff;
  border-color: var(--p2);
  background: rgba(139,92,246,.22);
  box-shadow: 0 0 12px rgba(139,92,246,.3);
}

/* En móvil, ocultar tabs del header y mostrar selector en panel */
@media (max-width: 900px) {
  .tabs-nav { display: none; }
  .panel-tabs-section { display: block !important; }
}
@media (min-width: 901px) {
  .panel-tabs-section { display: none !important; }
}

/* ══════════════════════════════════════
   PARTY LEGEND
══════════════════════════════════════ */
.party-legend {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--p2) transparent;
}
.pl-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 7px;
  border-radius: var(--rx);
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: background var(--tr);
}
.pl-row:hover { background: var(--surface3); }
.pl-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.2);
}
.pl-name {
  font: 600 .66rem var(--fm);
  color: var(--text2);
  flex: 1;
}
.pl-count {
  font: 700 .6rem var(--fm);
  color: var(--text3);
  background: var(--surface3);
  padding: 1px 5px;
  border-radius: 3px;
}
.pl-pct {
  font: 700 .58rem var(--fm);
  color: var(--accent2);
  min-width: 34px;
  text-align: right;
}

/* Barra de votos en popup */
.vote-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.vote-bar-label {
  font: 600 .62rem var(--fm);
  color: var(--text2);
  min-width: 68px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.vote-bar-bg {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.853);
  border-radius: 8px;
  overflow: hidden;
}
.vote-bar-fill {
  height: 100%;
  border-radius: 8px;
  transition: width .4s ease;
}
.vote-bar-val {
  font: 700 .58rem var(--fm);
  color: var(--text3);
  min-width: 30px;
  text-align: right;
}
.vote-bar-pct {
  font: 600 .56rem var(--f);
  color: var(--accent2);
  min-width: 32px;
  text-align: right;
}

/* ══════════════════════════════════════
   FILTROS GEOGRÁFICOS
══════════════════════════════════════ */
.filter-geo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.filter-geo-count {
  font: 700 .62rem var(--fm);
  color: var(--accent2);
}
.btn-clear-filtro {
  font: 600 .58rem var(--f);
  color: var(--text3);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--rx);
  padding: 3px 8px;
  cursor: pointer;
  transition: var(--tr);
}
.btn-clear-filtro:hover { color: var(--accent); border-color: var(--accent); }
.btn-clear-filtro.hidden { display: none; }

/* ══════════════════════════════════════
   POPUP ANCHO — Override Leaflet
══════════════════════════════════════ */
.pp-popup .leaflet-popup-content-wrapper {
  width: 320px !important;
  max-width: 92vw !important;
  overflow: hidden !important;
}
.pp-popup .leaflet-popup-content {
  width: 100% !important;
  overflow: hidden !important;
  max-height: none !important;
}
/* pp-card: header+stats fijos, barras con altura fija y scroll */
.pp-card { display: flex; flex-direction: column; overflow: hidden; }
.pp-bars-scroll {
  max-height: 168px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,92,246,.4) transparent;
}
.pp-bars-scroll::-webkit-scrollbar { width: 4px; }
.pp-bars-scroll::-webkit-scrollbar-thumb { background: rgba(139,92,246,.4); border-radius: 4px; }
.pp-stat-val { font-size: 1.05rem !important; }

/* Barras de votos más anchas en popup */
.vote-bar-label { min-width: 78px !important; font-size: .62rem !important; }
.vote-bar-row   { padding: 3px 0 !important; gap: 6px !important; }
.vote-bar-val   { min-width: 34px !important; text-align: right; font-size: .60rem !important; }
.vote-bar-pct   { min-width: 38px !important; text-align: right; font-size: .60rem !important; }

/* ══════════════════════════════════════
   STATS GRID
══════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-bottom: 4px;
}
.sg-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--rx);
  padding: 7px 8px;
  text-align: center;
}
.sg-val {
  font: 700 .82rem var(--fm);
  color: var(--text);
  line-height: 1.2;
}
.sg-val.accent { color: var(--accent2); }
.sg-lbl {
  font: 400 .46rem var(--f);
  color: var(--text4);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-top: 2px;
}

/* ══════════════════════════════════════
   RANKING DE PARTIDOS
══════════════════════════════════════ */
.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rk-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--rx);
}
.rk-pos {
  font: 700 .56rem var(--fm);
  color: var(--text4);
  min-width: 14px;
  text-align: center;
}
.rk-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.2);
}
.rk-name { font: 600 .64rem var(--fm); color: var(--text2); flex: 1; }
.rk-bar-wrap { width: 52px; height: 5px; background: var(--surface3); border-radius: 4px; overflow: hidden; }
.rk-bar-fill { height: 100%; border-radius: 4px; }
.rk-pct { font: 700 .58rem var(--fm); color: var(--accent2); min-width: 32px; text-align: right; }
.rk-cnt { font: 400 .54rem var(--f); color: var(--text4); min-width: 28px; text-align: right; }

/* ══════════════════════════════════════
   ESTADÍSTICAS — nuevo diseño
══════════════════════════════════════ */
.es-panel { padding: 12px 12px 14px; position: relative; }

/* Cabecera */
.es-head {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 11px;
}
.es-head-icon {
  width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0;
  background: linear-gradient(135deg,#7c3aed,#4f46e5);
  display: flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: 0 2px 8px rgba(124,58,237,.4);
}
.es-head-title {
  font: 600 .72rem var(--f); color: var(--text); flex: 1;
  letter-spacing: .01em;
}
.es-scope {
  font: 600 .56rem var(--fm); color: var(--p);
  background: rgba(139,92,246,.15); border: 1px solid rgba(139,92,246,.35);
  padding: 2px 8px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .05em;
  max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ══════════════════════════════════════
   TOOLTIP BANDA KDE
══════════════════════════════════════ */
.kde-band-tooltip {
  position: fixed; z-index: 900;
  width: 270px;
  background: rgba(15,12,30,.97);
  border: 1px solid rgba(167,139,250,.3);
  border-radius: 12px;
  padding: 12px 14px 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.6), 0 0 20px rgba(139,92,246,.15);
  backdrop-filter: blur(8px);
  animation: mIn .18s ease;
}
.kde-tt-close {
  position: absolute; top: 7px; right: 8px;
  background: none; border: none; color: #64748b;
  font-size: 16px; cursor: pointer; line-height: 1; padding: 2px 5px;
  transition: color .15s;
}
.kde-tt-close:hover { color: #f87171; }
.kde-tt-title {
  font: 700 .78rem var(--f); margin-bottom: 2px;
  text-transform: uppercase; letter-spacing: .06em;
}
.kde-tt-colorname {
  font: 400 .54rem var(--f); margin-bottom: 10px;
  opacity: .85;
}
.kde-tt-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 5px; gap: 8px;
}
.kde-tt-lbl { font: 400 .54rem var(--f); color: var(--text4); flex-shrink: 0; }
.kde-tt-val { font: 600 .58rem var(--fm); color: var(--text2); text-align: right; }
.kde-tt-pct { font-size: .72rem !important; color: #5eead4 !important; }
.kde-tt-desc {
  margin-top: 10px; padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.07);
  font: 400 .56rem var(--f); color: var(--text2); line-height: 1.7;
  max-height: 160px; overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,92,246,.3) transparent;
}
/* Hover en filas de banda */
.ml-kde-band { cursor: pointer; border-radius: 6px; padding: 2px 4px; transition: background .15s; }
.ml-kde-band:hover { background: rgba(167,139,250,.1); }

/* Métricas 2×2 */
.es-metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
  margin-bottom: 6px;
}
.es-metric {
  border-radius: 10px; padding: 7px 9px 7px 9px;
  position: relative; overflow: hidden;
  border: 1px solid transparent;
}
.es-metric::after { content: none; }

.es-m-purple {
  background: rgba(139,92,246,.07);
  border-color: rgba(167,139,250,.18);
  box-shadow: 0 0 18px rgba(139,92,246,.18), inset 0 0 20px rgba(139,92,246,.06);
}
.es-m-blue {
  background: rgba(59,130,246,.07);
  border-color: rgba(96,165,250,.18);
  box-shadow: 0 0 18px rgba(59,130,246,.18), inset 0 0 20px rgba(59,130,246,.06);
}
.es-m-green {
  background: rgba(16,185,129,.07);
  border-color: rgba(52,211,153,.18);
  box-shadow: 0 0 18px rgba(16,185,129,.18), inset 0 0 20px rgba(16,185,129,.06);
}
.es-m-teal {
  background: rgba(20,184,166,.07);
  border-color: rgba(45,212,191,.18);
  box-shadow: 0 0 18px rgba(20,184,166,.18), inset 0 0 20px rgba(20,184,166,.06);
}
.es-m-teal .es-m-val { color: #5eead4; }
.es-m-rose {
  background: rgba(244,63,94,.06);
  border-color: rgba(251,113,133,.18);
  box-shadow: 0 0 18px rgba(244,63,94,.18), inset 0 0 20px rgba(244,63,94,.06);
}
.es-m-rose .es-m-val { color: #fda4af; }

.es-m-wide { margin-bottom: 8px; }

/* ── Tarjeta: layout sin solapamiento ── */
.es-metric { position: relative; padding-top: 18px; }
.es-m-info {
  position: absolute; top: 5px; right: 5px;
  font: 800 .58rem var(--fm); color: #fff;
  background: rgba(139,92,246,.6);
  border: 1.5px solid rgba(167,139,250,.9);
  border-radius: 50%; width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; padding: 0;
  box-shadow: 0 0 6px rgba(139,92,246,.5);
  transition: background .15s, box-shadow .15s, transform .12s;
  flex-shrink: 0;
}
.es-m-info:hover {
  background: #7c3aed;
  box-shadow: 0 0 14px rgba(139,92,246,.8);
  transform: scale(1.18);
}

/* Valor secundario */
.es-m-secondary {
  font: 500 .52rem var(--fm); color: var(--text3);
  margin-top: 1px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

/* ── Modal overlay — cubre toda la pantalla ── */
.es-modal-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(4,2,18,.72);
  backdrop-filter: blur(6px) brightness(.6);
  -webkit-backdrop-filter: blur(6px) brightness(.6);
  display: flex; align-items: center; justify-content: center;
}

/* ── Popup centrado ── */
.es-popup {
  width: 320px; max-width: calc(100vw - 40px);
  max-height: 80vh;
  background: rgba(13,10,28,.98);
  border: 1px solid rgba(139,92,246,.4);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.8), 0 0 30px rgba(139,92,246,.2);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: popupIn .18s ease;
}
@keyframes popupIn {
  from { opacity:0; transform: scale(.92); }
  to   { opacity:1; transform: scale(1); }
}
.es-popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 12px 16px;
  border-bottom: 1px solid rgba(139,92,246,.2);
  background: rgba(139,92,246,.1);
  flex-shrink: 0;
  gap: 8px;
}
.es-popup-title {
  font: 700 .82rem var(--fm); color: #c4b5fd;
  letter-spacing: .02em;
}
.es-popup-close {
  font: 700 1rem var(--fm); color: #94a3b8;
  background: rgba(15,12,30,.95);
  border: 1.5px solid rgba(139,92,246,.35);
  width: 28px; height: 28px; min-width: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0;
  line-height: 1; transition: all .15s;
  position: relative; z-index: 2;
  box-shadow: 0 0 8px rgba(0,0,0,.6);
  margin-left: 8px;
}
.es-popup-close:hover {
  color: #fff;
  background: rgba(239,68,68,.2);
  border-color: rgba(239,68,68,.6);
  box-shadow: 0 0 10px rgba(239,68,68,.3);
}
/* Cuerpo con scroll oscuro */
.es-popup-body {
  overflow-y: auto; overflow-x: hidden;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: rgba(139,92,246,.4) transparent;
}
.es-popup-body::-webkit-scrollbar { width: 4px; }
.es-popup-body::-webkit-scrollbar-track { background: transparent; }
.es-popup-body::-webkit-scrollbar-thumb {
  background: rgba(139,92,246,.4);
  border-radius: 4px;
}
.es-popup-body::-webkit-scrollbar-thumb:hover { background: rgba(139,92,246,.7); }
.es-popup-block {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.es-popup-ej-block { border-bottom: none; padding-bottom: 18px; }
.es-popup-lbl {
  font: 700 .48rem var(--fm); color: var(--text4);
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: 5px;
}
.es-popup-formula {
  font: 500 .68rem var(--fm); color: #a5f3fc; line-height: 1.5;
}
.es-popup-calc {
  font: 700 .72rem var(--fm); color: #6ee7b7;
  line-height: 1.5; font-variant-numeric: tabular-nums;
}
.es-popup-ej {
  font: 400 .65rem var(--f); color: var(--text2); line-height: 1.6;
}

.es-m-val {
  font: 700 .82rem var(--fm); line-height: 1.1;
  letter-spacing: -.02em; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.es-m-purple .es-m-val { color: #c4b5fd; }
.es-m-blue   .es-m-val { color: #93c5fd; }
.es-m-green  .es-m-val { color: #6ee7b7; }
.es-m-amber  .es-m-val { color: #fde68a; }
.es-m-lbl {
  font: 400 .48rem var(--f); color: var(--text4);
  text-transform: uppercase; letter-spacing: .07em; margin-top: 2px;
}

/* Barra participación */
.es-part-bar-wrap {
  height: 3px; background: rgba(255,255,255,.07);
  border-radius: 3px; margin-bottom: 13px; overflow: hidden;
}
.es-part-bar-fill {
  height: 100%; border-radius: 3px;
  background: linear-gradient(90deg,#059669,#34d399);
  transition: width .55s cubic-bezier(.4,0,.2,1);
}

/* Separador top partidos */
.es-sep {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 7px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.es-sep > span:first-child {
  font: 700 .6rem var(--f); color: var(--text4);
  text-transform: uppercase; letter-spacing: .09em;
}
.es-sep-count {
  font: 500 .6rem var(--fm); color: var(--p);
}

/* Ranking rows */
.es-ranking {
  display: flex; flex-direction: column; gap: 4px;
}
.es-ranking::-webkit-scrollbar { width: 2px; }
.es-ranking::-webkit-scrollbar-thumb { background: var(--p2); border-radius: 2px; }

.es-rk-row {
  display: grid;
  grid-template-columns: 18px 9px 1fr 46px 68px;
  align-items: center; gap: 5px;
  padding: 6px 7px; border-radius: 7px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.05);
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.es-rk-row:hover {
  background: rgba(139,92,246,.14);
  border-color: rgba(167,139,250,.4);
  box-shadow: 0 0 14px rgba(139,92,246,.22), inset 0 0 12px rgba(139,92,246,.08);
  transform: translateX(2px);
  transition: all .18s ease;
}

/* Tarjetas de estadísticas */
.es-m-purple:hover {
  background: rgba(139,92,246,.14);
  border-color: rgba(167,139,250,.4);
  box-shadow: 0 0 28px rgba(139,92,246,.35), inset 0 0 28px rgba(139,92,246,.12);
}
.es-m-blue:hover {
  background: rgba(59,130,246,.14);
  border-color: rgba(96,165,250,.4);
  box-shadow: 0 0 28px rgba(59,130,246,.35), inset 0 0 28px rgba(59,130,246,.12);
}
.es-m-green:hover {
  background: rgba(16,185,129,.14);
  border-color: rgba(52,211,153,.4);
  box-shadow: 0 0 28px rgba(16,185,129,.35), inset 0 0 28px rgba(16,185,129,.12);
}
.es-m-teal:hover {
  background: rgba(20,184,166,.14);
  border-color: rgba(45,212,191,.4);
  box-shadow: 0 0 28px rgba(20,184,166,.35), inset 0 0 28px rgba(20,184,166,.12);
}
.es-m-rose:hover {
  background: rgba(244,63,94,.12);
  border-color: rgba(251,113,133,.4);
  box-shadow: 0 0 28px rgba(244,63,94,.35), inset 0 0 28px rgba(244,63,94,.12);
}
.es-metric { transition: background .2s ease, border-color .2s ease, box-shadow .2s ease; }

.es-rk-pos {
  font: 700 .56rem var(--fm); color: var(--text4); text-align: center;
}
.es-rk-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,.18);
}
.es-rk-info { min-width: 0; }
.es-rk-name {
  font: 600 .66rem var(--fm); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.es-rk-bar-wrap {
  height: 3px; background: rgba(255,255,255,.07);
  border-radius: 2px; margin-top: 3px; overflow: hidden;
}
.es-rk-bar-fill { height: 100%; border-radius: 2px; transition: width .4s ease; }
.es-rk-pct {
  font: 700 .63rem var(--fm); color: var(--text2); text-align: right;
  display: flex; flex-direction: column; align-items: flex-end; gap: 1px;
}
.es-rk-pct-rec {
  font: 500 .52rem var(--fm); color: var(--text4);
}
.es-rk-cnt {
  font: 400 .55rem var(--fm); color: var(--text4); text-align: right;
  white-space: nowrap; display: flex; flex-direction: column;
  align-items: flex-end; gap: 1px;
}
.es-rk-cnt-vot { color: var(--accent2); font-weight: 600; }
.es-rk-cnt-lbl { font: 400 .48rem var(--fm); color: var(--text4); }

/* ── Blanco/Nulo y Totales usan es-rk-row — solo necesitan el separador ── */
.es-bn-block  { display: flex; flex-direction: column; gap: 4px; }
.es-tot-block { display: flex; flex-direction: column; gap: 4px; }
.es-tot-divider { border: none; border-top: 1px solid rgba(255,255,255,.1); margin: 2px 0; }
.es-rk-total {
  margin-top: 4px;
  border-color: rgba(139,92,246,.35) !important;
  background: rgba(139,92,246,.08) !important;
  border-top: 2px solid rgba(139,92,246,.3) !important;
}

/* ══════════════════════════════════════
   MODO DE VISUALIZACIÓN
══════════════════════════════════════ */
.modo-btns {
  display: flex; flex-direction: column; gap: 4px; margin-top: 4px;
}
.modo-btn {
  width: 100%; padding: 7px 10px; text-align: left;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--rx); color: var(--text3);
  font: 500 .7rem var(--f); cursor: pointer; transition: var(--tr);
}
.modo-btn:hover { color: var(--text); border-color: var(--border2); }
.modo-btn.active {
  color: #fff; border-color: var(--p2);
  background: rgba(139,92,246,.18);
  box-shadow: 0 0 8px rgba(139,92,246,.25);
}
.modo-leyenda { margin-top: 8px; }
.modo-ley-grad {
  height: 8px; border-radius: 4px; width: 100%;
}
.modo-ley-labels {
  display: flex; justify-content: space-between;
  font: 400 .52rem var(--f); color: var(--text4); margin-top: 3px;
}
.modo-ley-items {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font: 400 .58rem var(--f); color: var(--text3);
}
.modo-ley-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
  display: inline-block;
}

/* Gradiente en leyenda flotante */
.ml-grad-bar {
  height: 8px; border-radius: 4px; width: 100%; margin: 4px 0 2px;
}
.ml-grad-labels {
  display: flex; justify-content: space-between;
  font: 400 .5rem var(--f); color: var(--text4); margin-bottom: 4px;
}

/* Watermark texto */
.map-wm-text {
  font: 500 .58rem var(--f); color: rgba(255,255,255,.18);
  text-transform: uppercase; letter-spacing: .1em;
}

/* ═══════════════════════════════════════════════════════════════
   TOUR ONBOARDING
═══════════════════════════════════════════════════════════════ */
.tour-overlay {
  position: fixed; inset: 0; z-index: 99000;
  display: none;
}
.tour-card {
  pointer-events: all !important;
}

/* Capa oscura con hueco (se dibuja vía clip-path en JS) */
.tour-backdrop {
  position: absolute; inset: 0; z-index: 1;
  background: rgba(0,0,0,.72);
  transition: clip-path .35s ease;
  pointer-events: none;
}

/* Borde brillante alrededor del elemento destacado */
.tour-spotlight-ring {
  position: absolute; z-index: 2;
  border: 2px solid #C4B5FD;
  border-radius: 10px;
  box-shadow: 0 0 0 4px rgba(196,181,253,.18), 0 0 20px rgba(196,181,253,.35);
  pointer-events: none;
  transition: all .35s ease;
}

/* Card del tooltip */
.tour-card {
  position: absolute; z-index: 3;
  background: #1F2937;
  border: 1px solid rgba(196,181,253,.35);
  border-radius: 14px;
  padding: 16px 18px 14px;
  width: min(280px, 88vw);
  box-shadow: 0 8px 32px rgba(0,0,0,.55);
  transition: all .3s ease;
}
.tour-card-step {
  font: 500 .62rem 'Outfit', sans-serif;
  color: #7C3AED; letter-spacing: .08em;
  text-transform: uppercase; margin-bottom: 6px;
}
.tour-card-title {
  font: 700 .95rem 'Outfit', sans-serif;
  color: #F8FAFC; margin-bottom: 5px; line-height: 1.25;
}
.tour-card-desc {
  font: 400 .8rem 'Outfit', sans-serif;
  color: #94A3B8; line-height: 1.5; margin-bottom: 14px;
}
.tour-card-actions {
  display: flex; gap: 8px; justify-content: flex-end; align-items: center;
}
.tour-btn-skip {
  background: none; border: none; cursor: pointer;
  font: 500 .75rem 'Outfit', sans-serif; color: #64748B;
  padding: 4px 8px; border-radius: 6px;
  transition: color .2s;
}
.tour-btn-skip:hover { color: #94A3B8; }
.tour-btn-next {
  background: linear-gradient(135deg,#7C3AED,#6D28D9);
  border: none; cursor: pointer;
  font: 600 .8rem 'Outfit', sans-serif; color: #fff;
  padding: 7px 16px; border-radius: 8px;
  transition: opacity .2s;
}
.tour-btn-next:hover { opacity: .88; }

/* Flecha del tooltip */
.tour-arrow {
  position: absolute; width: 0; height: 0;
}
.tour-arrow.up {
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 10px solid #1F2937;
  top: -10px; left: 50%;
  transform: translateX(-50%);
}
.tour-arrow.down {
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 10px solid #1F2937;
  bottom: -10px; left: 50%;
  transform: translateX(-50%);
}
.tour-arrow.left {
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-right: 10px solid #1F2937;
  left: -10px; top: 50%;
  transform: translateY(-50%);
}
.tour-arrow.right {
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  border-left: 10px solid #1F2937;
  right: -10px; top: 50%;
  transform: translateY(-50%);
}
