/* PeruCRIS Alertas — Mobile */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #e8edf2;
  --text: #1a2d3d;
  --muted: #6b7c8d;
  --accent: #0ea5e9;
  --alto: #ef4444;
  --medio: #f59e0b;
  --bajo: #22c55e;
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1a2a;
    --surface: #132636;
    --surface-2: #1a3347;
    --text: #d6e4ef;
    --muted: #7a9bb5;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1a2a;
  --surface: #132636;
  --surface-2: #1a3347;
  --text: #d6e4ef;
  --muted: #7a9bb5;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-2);
  z-index: 10;
  flex-shrink: 0;
}
.topbar img { width: 28px; height: 28px; border-radius: 6px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); flex: 1; min-width: 0; }
.brand-name { font-size: .85rem; font-weight: 700; white-space: nowrap; }
.brand-name b { color: var(--accent); }
.topbar-right { display: flex; gap: 6px; flex-shrink: 0; }
.topbar-link {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: .78rem; font-weight: 600; padding: 4px 8px; border-radius: 6px;
}
.topbar-link:active { background: var(--surface-2); }
.powered-by {
  font-size: .7rem;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  white-space: nowrap;
}
.powered-by b { color: var(--accent); }
.powered-by:active { opacity: .7; }

/* ── Acerca modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: grid; place-items: center;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 400px;
  width: 100%;
  max-height: 80dvh;
  overflow-y: auto;
  position: relative;
  color: var(--text);
  font-size: .88rem;
  line-height: 1.5;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 8px; }
.modal h3 { font-size: .9rem; margin: 14px 0 6px; }
.modal ul { padding-left: 18px; margin: 0; }
.modal li { margin: 4px 0; font-size: .84rem; }
.modal p { margin: 6px 0; font-size: .84rem; }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--surface-2); border: none; color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px;
  cursor: pointer; font-size: .9rem;
  display: grid; place-items: center;
}
.modal-close:active { background: var(--accent); color: #fff; }
.modal-footer {
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--surface-2);
  text-align: center;
}
.modal-footer a {
  font-size: .76rem; color: var(--muted); text-decoration: none;
}
.modal-footer b { color: var(--accent); }

/* ── Map ── */
#map {
  flex: 1;
  position: relative;
  min-height: 0;
}
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { bottom: 0 !important; }
.maplibregl-ctrl-top-right { top: 8px !important; right: 8px !important; }

/* ── Map tool buttons (left side) ── */
.map-tools {
  position: fixed;
  top: 56px;
  left: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}
.map-tools button {
  width: 38px; height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: .72rem;
  font-weight: 700;
}
.map-tools button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}
.map-tools button:active { opacity: .8; }
#btn-sim3d {
  background: #ef4444;
  color: #fff;
  font-size: .6rem;
  font-weight: 800;
  gap: 2px;
}
.sim3d-icon {
  font-size: .9rem;
  line-height: 1;
}

/* ── Bottom sheet ── */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.15);
  transform: translateY(calc(100% - 90px));
  transition: transform .35s cubic-bezier(.4,0,.2,1);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.sheet.open { transform: translateY(0); }
.sheet.mini { transform: translateY(calc(100% - 56px)); }
.handle {
  display: flex; justify-content: center; padding: 10px 0 6px; cursor: grab;
  flex-shrink: 0;
}
.handle span {
  width: 40px; height: 5px; border-radius: 3px; background: var(--muted); opacity: .35;
}
.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Search ── */
.search-section { margin-bottom: 10px; }
.search-section h2 { font-size: .92rem; margin-bottom: 2px; font-weight: 700; }
.search-section .lead { display: none; }
.search-row {
  display: flex; gap: 8px;
}
.search-row input {
  flex: 1;
  padding: 11px 14px;
  border: 2px solid var(--surface-2);
  border-radius: var(--radius);
  font-size: .95rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.search-row input:focus { border-color: var(--accent); }
.cta {
  padding: 11px 18px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.cta:disabled { opacity: .5; }
.cta.secundario { background: var(--surface-2); color: var(--text); }

.dir-sugerencias {
  list-style: none; padding: 0; margin: 4px 0 0;
}
.dir-sugerencias li {
  padding: 10px 12px;
  font-size: .88rem;
  border-radius: 8px;
  cursor: pointer;
  border-bottom: 1px solid var(--surface-2);
}
.dir-sugerencias li:last-child { border-bottom: none; }
.dir-sugerencias li:active { background: var(--surface-2); }

/* ── Results ── */
#resultado { font-size: .88rem; }
.result-header { padding: 6px 0 4px; }
.result-header b { font-size: .92rem; }

/* Storm scenario chips — floating panel right side of map */
.storm-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}
.storm-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 2px solid transparent;
  cursor: pointer;
  color: var(--text);
  font-size: .72rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
  transition: border-color .15s, background .15s;
  white-space: nowrap;
}
.storm-chip:active, .storm-chip.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}
.storm-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.storm-name { font-weight: 600; font-size: .7rem; line-height: 1.2; }
.storm-label {
  font-size: .65rem;
  font-weight: 600;
  color: #ef4444;
  text-align: center;
  padding: 4px 8px;
  border: 1.5px solid #ef4444;
  border-radius: 8px;
  background: transparent;
}

/* Action buttons row */
.result-actions {
  display: flex;
  gap: 8px;
  margin: 4px 0 6px;
}
.result-actions .cta { flex: 1; justify-content: center; padding: 10px 12px; font-size: .84rem; }

.resultado-depth {
  padding: 10px 12px;
  border-radius: var(--radius);
  border-left: 3px solid var(--muted);
  background: var(--surface-2);
  margin: 6px 0;
  font-size: .88rem;
}
.aviso {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: .78rem;
  color: var(--muted);
  margin: 6px 0;
  line-height: 1.4;
}

/* ── Rivers list ── */
.rios-section { margin-top: 8px; }
.rios-section summary {
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  padding: 10px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
}
.rios-section summary::before { content: '▸'; transition: transform .2s; }
.rios-section[open] summary::before { transform: rotate(90deg); }
.rio-lista {
  list-style: none; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.rio-lista li button {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: .82rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rio-lista li button span:last-child { font-size: .7rem; color: var(--muted); }
.rio-lista li button:active { background: var(--accent); color: #fff; }

/* ── Flood result detail ── */
.modelo-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}
.stat {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}
.stat .v { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.stat .k { font-size: .68rem; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.storm-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 2px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-size: .88rem;
}
.small { font-size: .78rem; color: var(--muted); }
h3 { font-size: .9rem; margin: 12px 0 6px; }
.dev-credit {
  text-align: center;
  font-size: .68rem;
  color: var(--muted);
  padding: 16px 0 4px;
  opacity: .7;
}

/* ── Depth legend ── */
.depth-legend {
  position: fixed;
  bottom: 170px;
  right: 8px;
  z-index: 15;
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: .72rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.depth-title { font-weight: 600; display: block; margin-bottom: 4px; }
.depth-bar { display: flex; gap: 2px; }
.depth-swatch { width: 26px; height: 12px; border-radius: 3px; }
.depth-labels { display: flex; justify-content: space-between; font-size: .62rem; color: var(--muted); margin-top: 2px; }

.leyenda { font-size: .78rem; }
.leyenda .fila { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.leyenda .sw { width: 18px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ── Spin ── */
.spin {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 180px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .84rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.22);
  z-index: 30;
}

/* ── PWA safe areas ── */
@supports (padding: env(safe-area-inset-top)) {
  .topbar { padding-top: max(6px, env(safe-area-inset-top)); }
  .map-tools { top: calc(50px + env(safe-area-inset-top, 0px)); }
}

/* ── MapLibre popup ── */
.pop { font-size: .84rem; line-height: 1.4; }
.pop b { display: block; margin-bottom: 2px; }
.maplibregl-popup-content { border-radius: 10px !important; padding: 10px 14px !important; }

/* ── Flood 3D controls ── */
.flood3d-legend {
  position: absolute; top: 60px; right: 8px;
  background: var(--surface); border-radius: 10px; padding: 8px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18); z-index: 10;
  font-size: .72rem; color: var(--text);
}
.flood3d-legend-title { font-weight: 700; margin-bottom: 4px; font-size: .76rem; }
.flood3d-legend-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.flood3d-legend-row span { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }
.flood3d-controls {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  background: var(--surface); border-radius: 12px; padding: 8px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.22); z-index: 10;
  min-width: 260px; max-width: 95vw;
}
.f3d-storm {
  width: 100%; text-align: center;
  font-weight: 700; font-size: .82rem; color: var(--accent);
  padding-bottom: 4px; border-bottom: 1px solid var(--surface-2);
  margin-bottom: 2px;
}
.f3d-btn {
  background: var(--surface-2); border: none; color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: .76rem; cursor: pointer; white-space: nowrap;
}
.f3d-btn:active { background: var(--accent); color: #fff; }
.f3d-btn:disabled { opacity: .5; }
.f3d-scrub { flex: 1; min-width: 50px; accent-color: var(--accent); }
.f3d-time { font-size: .74rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.flood3d-rec {
  position: absolute; top: 60px; left: 8px;
  background: #ef4444; color: #fff; border-radius: 8px; padding: 6px 12px;
  font-size: .76rem; font-weight: 700; z-index: 10;
  display: flex; align-items: center; gap: 6px;
}
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: rec-blink 1s infinite; }
@keyframes rec-blink { 50% { opacity: 0; } }
