/* ============================================================
   VARIABLES Y RESET
   ============================================================ */
:root {
  --naranja:    #FF7D00;
  --rojo:       #F8395A;
  --morado:     #4A007A;
  --morado-light: #9B4DCA;
  --negro:      #000000;
  --blanco:     #FFFFFF;

  /* Superficies */
  --bg:         #000000;
  --surface-1:  #0A0A0A;
  --surface-2:  #111111;
  --surface-3:  #1A1A1A;
  --border:     rgba(255,255,255,0.08);
  --border-med: rgba(255,255,255,0.14);

  /* Texto */
  --text:       #F0F0F0;
  --text-muted: #888888;
  --text-dim:   #555555;

  /* Colores por tipo de evento */
  --ev-vehiculos:   #FF7D00;
  --ev-bloqueo:     #F8395A;
  --ev-incendio:    #FF4500;
  --ev-detonacion:  #4A007A;
  --ev-enfrent:     #8B0000;
  --ev-psicosis:    #2D00A0;
  --ev-fallecida:   #FFFFFF;

  /* Layout */
  --header-h:   64px;
  --kpi-h:      72px;
  --filtros-h:  88px;
  --footer-h:   44px;
  --charts-w:   40%;
  --gap:        1px;

  /* Tipografia */
  --sans:       'IBM Plex Sans', system-ui, sans-serif;
  --serif:      'IBM Plex Serif', Georgia, serif;
  --mono:       'IBM Plex Mono', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ============================================================
   SCROLLBAR GLOBAL
   ============================================================ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--surface-1); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 2px; }

/* ============================================================
   HEADER
   ============================================================ */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: var(--header-h);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-med);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 16px;
}

.header-left {
  flex: 0 0 auto;
}

#logo {
  height: 36px;
  width: auto;
  display: block;
  object-fit: contain;
  /* fallback si no existe el logo */
  min-width: 40px;
}

.header-center {
  flex: 1;
  text-align: center;
}

#titulo-principal {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--blanco);
  letter-spacing: -0.01em;
  line-height: 1.1;
}

#subtitulo {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

#live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rojo);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

.live-text {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--rojo);
  letter-spacing: 0.12em;
  font-weight: 500;
}

#timestamp-wrap {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: var(--mono);
}

#timestamp-label {
  margin-right: 4px;
}

#timestamp {
  color: var(--text-muted);
}

/* ============================================================
   KPIs
   ============================================================ */
#kpis {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  z-index: 900;
  height: var(--kpi-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.kpi-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  padding: 8px 12px;
}

.kpi-card:last-child { border-right: none; }

.kpi-number {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 700;
  color: var(--blanco);
  line-height: 1;
  transition: all 0.4s ease;
}

.kpi-confirmado { color: var(--naranja); }
.kpi-naranja    { color: var(--naranja); }
.kpi-morado     { color: var(--morado-light); }

.kpi-label {
  font-size: 0.63rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 3px;
}

/* ============================================================
   BARRA DE FILTROS
   ============================================================ */
#filtros-bar {
  position: fixed;
  top: calc(var(--header-h) + var(--kpi-h));
  left: 0; right: 0;
  z-index: 800;
  height: var(--filtros-h);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

#filtros-inner {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  gap: 6px 18px;
  padding: 7px 16px;
  height: 100%;
}

.filtro-grupo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Fila 1 completa: tipo de evento + sus checkboxes */
#filtro-evento-wrap {
  flex-basis: 100%;
  width: 100%;
}

.filtro-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

/* Checkboxes de eventos */
#filtro-checkboxes {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.ev-checkbox {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  transition: all 0.15s ease;
  user-select: none;
}

.ev-checkbox input {
  display: none;
}

.ev-checkbox .ev-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ev-checkbox .ev-nombre {
  font-size: 0.62rem;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color 0.15s ease;
}

.ev-checkbox.activo {
  border-color: var(--border-med);
}

.ev-checkbox.activo .ev-nombre {
  color: var(--text);
}

.ev-checkbox:hover {
  border-color: var(--border-med);
}

/* Select dropdowns */
.filtro-select {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
  min-width: 130px;
}

.filtro-select:focus {
  border-color: var(--border-med);
}

/* Toggle de estatus */
.toggle-group {
  display: flex;
  gap: 2px;
}

.toggle-btn {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 9px;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.04em;
}

.toggle-btn:hover { color: var(--text-muted); border-color: var(--border-med); }

.toggle-btn.active {
  background: var(--surface-1);
  border-color: var(--naranja);
  color: var(--naranja);
}

/* Acciones */
.filtro-acciones {
  margin-left: auto;
  gap: 12px;
}

.btn-limpiar {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: all 0.15s ease;
}

.btn-limpiar:hover {
  color: var(--rojo);
  border-color: var(--rojo);
}

#contador-filtro {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
#main-layout {
  position: fixed;
  top: calc(var(--header-h) + var(--kpi-h) + var(--filtros-h));
  bottom: var(--footer-h);
  left: 0; right: 0;
  display: flex;
  gap: 0;
}

/* Mapa */
#mapa-wrap {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* Panel de graficas */
#charts-panel {
  flex: 0 0 var(--charts-w);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Cards de graficas */
.chart-card {
  border-bottom: 1px solid var(--border);
  padding: 14px 16px 10px;
  flex-shrink: 0;
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chart-title {
  font-family: var(--serif);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--blanco);
  line-height: 1.2;
}

.chart-subtitle {
  font-size: 0.63rem;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* Boton exportar grafica */
.btn-export {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-dim);
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.btn-export:hover {
  color: var(--naranja);
  border-color: var(--naranja);
}

/* ============================================================
   GRAFICA: ESTATUS (contadores)
   ============================================================ */
#chart-estatus {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 6px 0;
}

.estatus-block {
  flex: 1;
  text-align: center;
  padding: 10px 8px;
  background: var(--surface-2);
  border-radius: 4px;
  border: 1px solid var(--border);
}

.estatus-numero {
  font-family: var(--serif);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
}

.estatus-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-top: 4px;
}

.estatus-pct {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 3px;
}

/* ============================================================
   GRAFICAS D3 — SVG BASE
   ============================================================ */
.chart-svg {
  display: block;
  width: 100%;
}

/* Tooltip D3 */
.d3-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--surface-2);
  border: 1px solid var(--border-med);
  border-radius: 4px;
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text);
  max-width: 220px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.12s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

.d3-tooltip.visible {
  opacity: 1;
}

.tooltip-label {
  font-weight: 600;
  margin-bottom: 2px;
}

.tooltip-val {
  color: var(--naranja);
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ============================================================
   LEAFLET — SOBREESCRITURAS
   ============================================================ */
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(0,0,0,0.7) !important;
  color: #555 !important;
}

.leaflet-control-attribution a { color: #666 !important; }

.leaflet-popup-content-wrapper {
  background: #0D0D0D !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: 6px !important;
  color: var(--text) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.8) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: auto !important;
}

.leaflet-popup-tip {
  background: #0D0D0D !important;
}

.leaflet-popup-close-button {
  color: var(--text-dim) !important;
  top: 8px !important;
  right: 8px !important;
  font-size: 16px !important;
}

.leaflet-popup-close-button:hover {
  color: var(--rojo) !important;
}

/* Cluster personalizado */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(74, 0, 122, 0.5) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(74, 0, 122, 0.8) !important;
  color: #fff !important;
  font-family: var(--mono) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
}

/* Leyenda del mapa */
.leyenda-mapa {
  background: rgba(10, 10, 10, 0.92) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: 5px !important;
  padding: 10px 13px !important;
  font-family: var(--sans) !important;
}

.leyenda-titulo {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 7px;
}

.leyenda-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  cursor: pointer;
  transition: color 0.15s;
}

.leyenda-item:hover { color: var(--text); }

.leyenda-item:last-child { margin-bottom: 0; }

.leyenda-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Popup de mapa */
.popup-wrap {
  padding: 12px 14px;
  min-width: 200px;
  max-width: 280px;
  font-family: var(--sans);
}

.popup-tipo {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 5px;
}

.popup-municipio {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  color: var(--blanco);
  line-height: 1.2;
  margin-bottom: 6px;
}

.popup-hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 7px 0;
}

.popup-campo {
  margin-bottom: 5px;
}

.popup-campo-label {
  font-size: 0.58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  display: block;
}

.popup-campo-val {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.popup-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 2px;
  margin-top: 2px;
}

.badge-confirmado {
  background: rgba(255,125,0,0.15);
  color: var(--naranja);
  border: 1px solid rgba(255,125,0,0.3);
}

.badge-preliminar {
  background: rgba(255,255,255,0.07);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.12);
}

.popup-media-x {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 9px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.popup-media-x:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.25);
}

.popup-media-x-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: var(--naranja);
  flex-shrink: 0;
}

.popup-media-x-texto {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}

.popup-media-x-label {
  font-size: 0.8rem;
  color: var(--text);
  font-family: var(--sans);
}

.popup-media-x-logo {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--sans);
}

/* ============================================================
   FOOTER
   ============================================================ */
#footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 700;
  height: var(--footer-h);
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

#footer-left {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.footer-creditos strong {
  color: var(--text-muted);
}

.footer-sep {
  color: var(--text-dim);
  margin: 0 8px;
}

.footer-autores {
  display: inline-flex;
  align-items: center;
  gap: 0;
}

.footer-sep-dot {
  color: var(--text-dim);
  margin: 0 6px;
}

.footer-autor {
  color: var(--naranja);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  transition: color 0.15s ease;
}

.footer-autor:hover {
  color: var(--blanco);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-descarga {
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 6px 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.04em;
  transition: all 0.15s ease;
}

.btn-descarga:hover {
  color: var(--naranja);
  border-color: var(--naranja);
}

/* ============================================================
   BARRAS D3 — EJES Y TEXTO
   ============================================================ */
.axis-label {
  fill: var(--text-dim);
  font-family: var(--sans);
  font-size: 11px;
}

.bar-value {
  fill: var(--text-muted);
  font-family: var(--mono);
  font-size: 10px;
}

.tick text {
  fill: var(--text-dim) !important;
  font-family: var(--sans) !important;
  font-size: 10px !important;
}

.tick line,
.domain {
  stroke: rgba(255,255,255,0.06) !important;
}

/* ============================================================
   DONUT CHART — LEYENDA
   ============================================================ */
.donut-wrap {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.donut-leyenda {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

.donut-leyenda-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
}

.donut-leyenda-item:hover { color: var(--text); }

.donut-leyenda-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.donut-leyenda-nombre {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.donut-leyenda-val {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
}

/* ============================================================
   ANIMACION ENTRADA NUMEROS KPI
   ============================================================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.kpi-in { animation: fadeInUp 0.5s ease forwards; }

/* ============================================================
   ESTADO VACIO / CARGA
   ============================================================ */
.loading-msg {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}

/* ============================================================
   RESPONSIVE — TABLET  (769px – 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  :root {
    --header-h:  56px;
    --kpi-h:     60px;
    --filtros-h: 88px;
    --charts-w:  44%;
  }

  #titulo-principal { font-size: 1.1rem; }
  #subtitulo        { display: none; }
  #timestamp-label  { display: none; }

  .kpi-number { font-size: 1.6rem; }
  .kpi-label  { font-size: 0.58rem; }

  #filtros-inner { gap: 5px 14px; padding: 6px 14px; }
  .filtro-select { min-width: 110px; }
}

/* ============================================================
   RESPONSIVE — MÓVIL  (≤ 768px)
   Estrategia: romper el app-shell fijo y pasar a flujo normal
   ============================================================ */
@media (max-width: 768px) {

  /* ── Reset global de overflow ───────────────────────────── */
  html, body {
    height: auto;
    min-height: 100%;
    overflow: auto;
    overflow-x: hidden;
  }

  /* ── Variables móvil ─────────────────────────────────────── */
  :root {
    --header-h:  52px;
    --kpi-h:     auto;
    --filtros-h: auto;
    --footer-h:  auto;
    --charts-w:  100%;
  }

  /* ── HEADER: sticky, simplificado ──────────────────────── */
  #header {
    position: sticky;
    top: 0;
    height: var(--header-h);
    padding: 0 12px;
    gap: 10px;
    z-index: 1000;
  }

  #logo { height: 28px; }

  #titulo-principal {
    font-size: 0.88rem;
    letter-spacing: 0;
  }

  #subtitulo { display: none; }

  /* Ocultar timestamp completo en móvil, solo dot live */
  #timestamp-wrap  { display: none; }
  .live-text       { display: none; }

  /* ── KPIs: grid 2×2 ──────────────────────────────────────── */
  #kpis {
    position: static;
    height: auto;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    border-bottom: 1px solid var(--border);
  }

  /* Grid 2×2: columnas pares sin borde derecho, segunda fila con borde superior */
  .kpi-card:nth-child(1) { border-right: 1px solid var(--border); }
  .kpi-card:nth-child(2) { border-right: none; }
  .kpi-card:nth-child(3) { border-right: 1px solid var(--border); border-top: 1px solid var(--border); }
  .kpi-card:nth-child(4) { border-right: none; border-top: 1px solid var(--border); }

  .kpi-card   { padding: 10px 8px; }
  .kpi-number { font-size: 1.7rem; }
  .kpi-label  { font-size: 0.6rem; }

  /* ── FILTROS: flujo normal, altura auto ──────────────────── */
  #filtros-bar {
    position: static;
    height: auto;
    overflow: visible;
    border-bottom: 1px solid var(--border);
  }

  #filtros-inner {
    gap: 8px 12px;
    padding: 10px 12px;
    height: auto;
    align-content: flex-start;
  }

  /* Checkboxes: targets mínimos de 32px para touch */
  .ev-checkbox {
    padding: 5px 9px;
    min-height: 32px;
  }

  .ev-checkbox .ev-nombre { font-size: 0.65rem; }

  .toggle-btn    { padding: 6px 10px; min-height: 32px; }
  .filtro-select { min-height: 32px; min-width: 120px; }
  .btn-limpiar   { min-height: 32px; padding: 6px 12px; }

  /* Contador en su propia línea */
  .filtro-acciones { flex-basis: 100%; width: 100%; justify-content: flex-end; }
  #contador-filtro { margin-left: auto; }

  /* ── LAYOUT PRINCIPAL: columna única, flujo normal ──────── */
  #main-layout {
    position: static !important;
    top: auto !important;
    bottom: auto !important;
    flex-direction: column;
    height: auto;
  }

  /* Mapa: altura fija adecuada para touch */
  #mapa-wrap {
    width: 100%;
    height: min(70vw, 420px);
    min-height: 260px;
    flex: none;
  }

  #map {
    width: 100%;
    height: 100%;
  }

  /* Panel de gráficas: ancho completo, altura auto */
  #charts-panel {
    flex: none;
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
    overflow: visible;
  }

  /* Cards de gráficas más compactas */
  .chart-card { padding: 12px 12px 10px; }

  /* Estatus: bloques más pequeños */
  .estatus-numero { font-size: 2rem; }

  /* Donut: apilar en columna si el contenedor es angosto */
  .donut-wrap {
    flex-direction: column;
    align-items: center;
  }

  .donut-leyenda {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px 14px;
    justify-content: flex-start;
    margin-top: 8px;
  }

  .donut-leyenda-nombre { white-space: normal; }

  /* ── FOOTER: flujo normal, apilado ──────────────────────── */
  #footer {
    position: static;
    height: auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
  }

  #footer-right { width: 100%; }

  .btn-descarga {
    width: 100%;
    justify-content: center;
    min-height: 38px;
  }

  /* Tooltip: no se desborde en móvil */
  .d3-tooltip { max-width: 180px; font-size: 0.7rem; }

  /* Leyenda del mapa: más compacta */
  .leyenda-mapa { padding: 8px 10px !important; }
  .leyenda-item { font-size: 0.65rem; }

  /* Popup: ancho adaptado */
  .popup-wrap { min-width: 160px; max-width: 240px; }
}

/* ============================================================
   RESPONSIVE — MÓVIL PEQUEÑO  (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {

  #titulo-principal { font-size: 0.78rem; }

  .header-left { display: none; } /* ocultar logo en pantallas muy pequeñas */

  .header-center { text-align: left; }

  #mapa-wrap { height: min(65vw, 320px); }

  .kpi-number { font-size: 1.45rem; }
  .kpi-label  { font-size: 0.55rem; letter-spacing: 0.04em; }

  /* Filtros: checkboxes más compactos */
  .ev-checkbox .ev-nombre { font-size: 0.6rem; }
  .ev-checkbox { padding: 4px 7px; }

  /* Gráficas: márgenes mínimos */
  .chart-card { padding: 10px 8px 8px; }
  .chart-title { font-size: 0.82rem; }
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: opacity 0.4s ease;
}

#loading-overlay.oculto {
  opacity: 0;
  pointer-events: none;
}

#loading-overlay p {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.loading-dots {
  display: flex;
  gap: 8px;
}

.loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--naranja);
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1.1); }
}

/* ============================================================
   ERROR BANNER
   ============================================================ */
#error-banner {
  position: fixed;
  top: calc(var(--header-h) + var(--kpi-h) + var(--filtros-h));
  left: 0; right: 0;
  z-index: 750;
  background: rgba(248, 57, 90, 0.1);
  border-bottom: 1px solid rgba(248, 57, 90, 0.4);
  padding: 7px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--rojo);
}

#error-banner.oculto {
  display: none;
}

#btn-reintentar {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--rojo);
  background: transparent;
  border: 1px solid rgba(248, 57, 90, 0.5);
  border-radius: 3px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

#btn-reintentar:hover {
  background: rgba(248, 57, 90, 0.15);
  border-color: var(--rojo);
}

@media (max-width: 768px) {
  #error-banner {
    position: static;
    border-bottom: none;
    border-top: 1px solid rgba(248, 57, 90, 0.4);
  }
}
