:root {
  --tinta: #16211c;
  --verde: #1e8e3e;
  --ambar: #f9a825;
  --rojo: #c62828;
  --gris: #5f6b64;
  --fondo: #f4f7f5;
  --panel: #ffffff;
  --borde: #dde5e0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--tinta);
  background: var(--fondo);
}

.cabecera {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: linear-gradient(120deg, #0f4c81, #1273b8);
  color: #fff;
}
.cabecera h1 { margin: 0; font-size: 1.35rem; }
.subtitulo { margin: 0.15rem 0 0; font-size: 0.85rem; opacity: 0.9; }

.nacional { display: flex; gap: 1.4rem; flex-wrap: wrap; }
.dato { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.dato span { font-size: 1.25rem; font-weight: 700; }
.dato small { font-size: 0.7rem; opacity: 0.85; text-transform: uppercase; letter-spacing: 0.04em; }
.dato.destacado span { color: #ffe082; }

.contenedor {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0.8rem;
  padding: 0.8rem;
  height: calc(100vh - 96px);
}
.mapa-caja { position: relative; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.15); }
#map { width: 100%; height: 100%; background: #dfe8e3; }

.aviso-mapa {
  position: absolute; inset: auto 1rem 1rem 1rem; padding: 0.7rem 0.9rem;
  background: #fff8e1; border: 1px solid #f0c040; border-radius: 8px; font-size: 0.85rem;
}
.hidden { display: none !important; }

.capas {
  position: absolute; top: 0.7rem; left: 0.7rem; display: flex; gap: 0.8rem;
  background: rgba(255,255,255,0.95); padding: 0.4rem 0.7rem; border-radius: 8px;
  font-size: 0.85rem; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.capas label { display: flex; gap: 0.3rem; align-items: center; cursor: pointer; }

.leyenda {
  position: absolute; bottom: 0.7rem; left: 0.7rem; background: rgba(255,255,255,0.95);
  padding: 0.5rem 0.7rem; border-radius: 8px; font-size: 0.78rem;
  display: flex; flex-direction: column; gap: 0.2rem; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.leyenda-titulo { font-weight: 700; margin-bottom: 0.15rem; }
.leyenda i { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 0.3rem; }

.leyenda-cuencas { left: auto; right: 0.7rem; bottom: 0.7rem; max-width: 180px; }
.leyenda-cuencas small { color: var(--gris); font-size: 0.66rem; line-height: 1.2; }
.gradiente-cuenca {
  width: 150px; height: 10px; border-radius: 3px; margin: 0.15rem 0 0.15rem;
  background: linear-gradient(90deg, #c62828, #f9a825 50%, #1b5e20);
}
.gradiente-rango {
  display: flex; justify-content: space-between; font-size: 0.7rem; font-weight: 600; color: var(--tinta);
}

.panel { background: var(--panel); border-radius: 12px; padding: 0.9rem; overflow: auto; box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
.panel-cab { display: flex; justify-content: space-between; align-items: baseline; }
.panel-cab h2 { font-size: 1rem; margin: 0; }
.contador { font-size: 0.8rem; color: var(--gris); }
.panel-ayuda { font-size: 0.78rem; color: var(--gris); margin: 0.4rem 0 0.6rem; }

.lista { list-style: none; margin: 0; padding: 0; }
.lista li {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 0.5rem; align-items: center;
  padding: 0.4rem 0.2rem; border-bottom: 1px solid var(--borde); cursor: pointer; font-size: 0.86rem;
}
.lista li:hover { background: #eef4f0; }
.lista .punto { width: 10px; height: 10px; border-radius: 50%; }
.lista .punto.hueco { background: transparent; border: 2px solid var(--gris); }
.lista li.antiguo .nivel { color: var(--gris); font-weight: 600; }
.lista .aviso-dato { color: #a05a00; font-size: 0.7rem; }
.lista .nivel { font-weight: 700; }
.lista .cuenca { color: var(--gris); font-size: 0.72rem; }

.fuente { font-size: 0.72rem; color: var(--gris); margin-top: 0.8rem; line-height: 1.4; }

.ficha { position: fixed; inset: 0; background: rgba(10,20,15,0.55); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.ficha-caja { position: relative; background: #fff; border-radius: 14px; max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; padding: 1.2rem; }
.cerrar { position: absolute; top: 0.6rem; right: 0.8rem; border: 0; background: none; font-size: 1.6rem; cursor: pointer; line-height: 1; }
.ficha h3 { margin: 0 0 0.2rem; }
.ficha .cuenca-txt { color: var(--gris); font-size: 0.85rem; margin: 0 0 0.8rem; }
.ficha-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 0.6rem; margin-bottom: 0.9rem; }
.ficha-grid .caja { background: var(--fondo); border-radius: 8px; padding: 0.5rem 0.6rem; }
.ficha-grid .caja small { display: block; color: var(--gris); font-size: 0.7rem; text-transform: uppercase; }
.ficha-grid .caja b { font-size: 1.1rem; }
.grafica { width: 100%; height: 180px; }
.grafica text { font-size: 9px; fill: var(--gris); }
.positivo { color: var(--verde); }
.negativo { color: var(--rojo); }
.aviso-dato-ficha {
  background: #fff4e0; border: 1px solid #f0b060; color: #7a4a00;
  border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.82rem; margin: 0 0 0.8rem;
}

@media (max-width: 860px) {
  .contenedor { grid-template-columns: 1fr; height: auto; }
  #map { height: 60vh; }
  .nacional { gap: 0.9rem; }
  /* En móvil, leyendas y controles compactos: que tapen lo mínimo del mapa. */
  .leyenda { font-size: 0.68rem; padding: 0.35rem 0.5rem; gap: 0.1rem; }
  .leyenda i { width: 12px; height: 9px; }
  .leyenda-cuencas { max-width: 138px; }
  .gradiente-cuenca { width: 108px; }
  .capas { font-size: 0.78rem; padding: 0.3rem 0.5rem; gap: 0.6rem; }
}
