* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: 'Segoe UI', system-ui, sans-serif; }
body { display: flex; flex-direction: column; }

#cabecera {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #1a2c4e; color: #fff; padding: 8px 16px; min-height: 58px; flex-shrink: 0;
}
#cabecera h1 { margin: 0; font-size: 1.1rem; }
#subtitulo { margin: 2px 0 0; font-size: .78rem; opacity: .85; }
#btn-panel {
  background: none; border: 1px solid rgba(255,255,255,.4); color: #fff;
  font-size: 1.1rem; border-radius: 6px; padding: 4px 10px; cursor: pointer; flex-shrink: 0;
}

#contenedor { display: flex; flex: 1; min-height: 0; }
#mapa { flex: 1; min-width: 0; }

#panel {
  width: 340px; overflow-y: auto; background: #f7f8fa;
  border-right: 1px solid #d8dde5; padding: 12px; flex-shrink: 0;
}
#panel.oculto { display: none; }

.bloque { background: #fff; border: 1px solid #e2e6ec; border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.bloque h2 { margin: 0 0 8px; font-size: .95rem; color: #1a2c4e; }
.nota { font-size: .75rem; color: #667; margin: 0 0 8px; }

.info-evento { font-size: .82rem; line-height: 1.5; }
.info-evento .mag { font-size: 1.5rem; font-weight: 700; color: #d7191c; }

.capa-check { display: block; font-size: .85rem; margin: 4px 0; cursor: pointer; }

.pestanas { display: flex; gap: 6px; margin-bottom: 8px; }
.pestana {
  flex: 1; padding: 6px; border: 1px solid #c9d2de; background: #eef1f6;
  border-radius: 6px; cursor: pointer; font-size: .82rem;
}
.pestana.activa { background: #1a2c4e; color: #fff; border-color: #1a2c4e; }

#buscar, #filtro-nivel, #filtro-depto, #filtro-org, #origen-texto {
  width: 100%; padding: 7px 9px; margin-bottom: 8px; font-size: .85rem;
  border: 1px solid #c9d2de; border-radius: 6px;
}

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 4px; }
.kpi { background: #f2f5fa; border: 1px solid #e2e6ec; border-radius: 8px; padding: 7px 9px; }
.kpi b { display: block; font-size: 1.05rem; color: #1a2c4e; }
.kpi span { display: block; font-size: .68rem; color: #556; line-height: 1.25; }
.subtitulo-tabla { font-size: .8rem; margin: 8px 0 4px; color: #445; }
.tabla-mini { width: 100%; border-collapse: collapse; font-size: .72rem; }
.tabla-mini th { text-align: left; color: #445; border-bottom: 1px solid #d8dde5; padding: 3px 4px; font-weight: 600; }
.tabla-mini td { padding: 3px 4px; border-bottom: 1px solid #eef1f5; }
.tabla-mini th:nth-child(n+2), .tabla-mini td:nth-child(n+2) { text-align: right; white-space: nowrap; }

#ranking { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
#ranking li {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; margin-bottom: 5px;
  background: #fbfcfe; border: 1px solid #e6eaf0; border-left-width: 5px;
  border-radius: 6px; cursor: pointer; font-size: .8rem;
}
#ranking li:hover { background: #eef3fb; }
#ranking li.seleccionado { outline: 2px solid #1a2c4e; }
#ranking .indice {
  min-width: 42px; text-align: center; font-weight: 700; border-radius: 5px;
  padding: 3px 0; color: #fff; font-size: .78rem;
}
#ranking .detalle { flex: 1; }
#ranking .detalle small { color: #667; display: block; }

.ruta-destino { font-size: .8rem; margin-bottom: 8px; }
.fila-origen { display: flex; gap: 6px; }
.fila-origen input { flex: 1; }
.fila-origen button { border: 1px solid #c9d2de; background: #eef1f6; border-radius: 6px; cursor: pointer; margin-bottom: 8px; }
.fila-botones { display: flex; gap: 6px; margin-bottom: 8px; }
.fila-botones button {
  flex: 1; padding: 6px; font-size: .75rem; border: 1px solid #c9d2de;
  background: #eef1f6; border-radius: 6px; cursor: pointer;
}
.fila-botones button.activo { background: #d7e3f7; border-color: #1a2c4e; }
#btn-calcular-ruta {
  width: 100%; padding: 9px; background: #1a6b3c; color: #fff; border: none;
  border-radius: 6px; font-size: .88rem; cursor: pointer;
}
#btn-calcular-ruta:disabled { background: #9db3a6; cursor: not-allowed; }
#ruta-resultado { font-size: .8rem; margin-top: 8px; line-height: 1.5; }
#ruta-resultado .aviso { color: #8a5a00; background: #fff7e0; border: 1px solid #f0dfa8; border-radius: 6px; padding: 6px; display: block; margin-top: 6px; }

#acerca summary { cursor: pointer; list-style: none; }
#acerca summary::-webkit-details-marker { display: none; }
#acerca summary h2 { display: inline; }
#acerca summary::after { content: ' ▸'; color: #667; font-size: .8rem; }
#acerca[open] summary::after { content: ' ▾'; }
.lista-notas { margin: 8px 0; padding-left: 18px; font-size: .75rem; color: #445; }
.lista-notas li { margin-bottom: 6px; line-height: 1.45; }

#leyenda { font-size: .78rem; }
#leyenda .item { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
#leyenda .cuadro { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); flex-shrink: 0; }
#leyenda .epicentro-simbolo {
  border-radius: 50%; border: 1.5px solid #d7191c; background: #c11212;
  color: #fff; font-size: 9px; display: flex; align-items: center;
  justify-content: center;
}
#leyenda h3 { font-size: .8rem; margin: 8px 0 4px; color: #445; }

.creditos { font-size: .7rem; color: #778; padding: 4px 2px 8px; }
.creditos a { color: #1a5eb8; }

/* Solo la estrella captura clics: las ondas no deben bloquear los
 * marcadores de comunidades cercanos al epicentro. */
.epicentro-icono { position: relative; pointer-events: none !important; }
.epicentro-icono .estrella {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; z-index: 2; color: #fff; font-size: 22px;
  text-shadow: 0 1px 3px rgba(0,0,0,.9), 0 0 8px rgba(0,0,0,.55);
  pointer-events: auto; cursor: pointer;
}
.epicentro-icono .onda {
  position: absolute; inset: 0; border: 3.5px solid #b40b0e; border-radius: 50%;
  box-shadow: 0 0 3px rgba(255,255,255,.9), inset 0 0 3px rgba(255,255,255,.9);
  opacity: 0; animation: onda 4s linear infinite;
}
.epicentro-icono .onda:nth-child(2) { animation-delay: 1s; }
.epicentro-icono .onda:nth-child(3) { animation-delay: 2s; }
.epicentro-icono .onda:nth-child(4) { animation-delay: 3s; }
@keyframes onda {
  0%   { transform: scale(.08); opacity: .95; }
  60%  { opacity: .4; }
  100% { transform: scale(1); opacity: 0; }
}

#velo-carga {
  position: fixed; inset: 0; z-index: 1500;
  background: rgba(26,44,78,.12);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
#velo-carga.visible { opacity: 1; visibility: visible; transition: opacity .35s ease; }

#cargador-ruta {
  position: fixed; top: 76px; left: 50%; z-index: 1600;
  max-width: min(92vw, 480px); white-space: nowrap;
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.96); color: #1a2c4e;
  padding: 10px 18px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  border: 1px solid #e2e6ec; box-shadow: 0 4px 18px rgba(26,44,78,.25);
  opacity: 0; transform: translate(-50%, -14px); pointer-events: none;
  transition: opacity .35s ease, transform .35s ease;
}
#cargador-ruta.visible { opacity: 1; transform: translate(-50%, 0); }
#cargador-ruta .anillo {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  border: 3px solid #d7e3d9; border-top-color: #1a6b3c;
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.leaflet-popup-content { font-size: .82rem; }
.popup-titulo { font-weight: 700; margin-bottom: 4px; }
.popup-nivel { display: inline-block; padding: 2px 8px; border-radius: 10px; color: #fff; font-size: .75rem; margin: 3px 0; }
.nota-privacidad { display: block; margin-top: 6px; color: #667; font-size: .68rem; line-height: 1.35; }
.popup-btn-ruta {
  display: block; margin-top: 7px; padding: 6px 10px; background: #1a6b3c; color: #fff;
  border: none; border-radius: 5px; cursor: pointer; width: 100%; font-size: .8rem;
}

#cargador-texto { overflow: hidden; text-overflow: ellipsis; }

/* Tabletas: panel más angosto para dar aire al mapa */
@media (min-width: 721px) and (max-width: 1024px) {
  #panel { width: 300px; }
}

/* Móviles: mapa arriba, panel como hoja inferior desplazable */
@media (max-width: 720px) {
  #cabecera { padding: 6px 12px; min-height: 0; }
  #cabecera h1 { font-size: .95rem; }
  #subtitulo { font-size: .68rem; }

  #contenedor { flex-direction: column; }
  #mapa { order: 1; flex: 1 1 auto; min-height: 0; }
  #panel {
    order: 2; width: 100%; flex: 0 0 auto; max-height: 46%;
    border-right: none; border-top: 1px solid #d8dde5;
    padding: 10px;
  }

  /* 16px evita el auto-zoom de iOS al enfocar campos */
  #buscar, #filtro-nivel, #filtro-depto, #filtro-org, #origen-texto { font-size: 16px; }

  #ranking { max-height: 34vh; }
  #ranking li { padding: 9px 8px; }
  .pestana { padding: 9px 6px; font-size: .85rem; }
  .fila-botones button { padding: 10px 6px; font-size: .85rem; }
  .fila-origen button { padding: 0 14px; font-size: 1rem; }
  #btn-calcular-ruta { padding: 12px; font-size: .95rem; }
  .popup-btn-ruta { padding: 10px; font-size: .88rem; }

  #cargador-ruta { top: 60px; font-size: .8rem; padding: 9px 14px; }
}
