/* SIGA-Visor — visor hidrológico del río Túa */
:root {
  --bg: #eef2f7;
  --glass: rgba(255, 255, 255, .78);
  --glass-strong: rgba(255, 255, 255, .92);
  --stroke: rgba(15, 23, 42, .10);
  --stroke-2: rgba(15, 23, 42, .18);
  --ink: #0b1220;
  --ink-2: #475569;
  --ink-3: #64748b;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, .12);
  --rain: #2a78d6;
  --flow: #0284c7;
  --band: rgba(2, 132, 199, .16);
  --wrf: #eb6834;
  --m-ifs: #2a78d6; --m-aifs: #1baf7a; --m-gfs: #eda100; --m-icon: #e87ba4;
  --shadow: 0 10px 40px -12px rgba(15, 23, 42, .25);
  --ok: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --font: "Inter Tight", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #060a12; --glass: rgba(13, 19, 31, .72); --glass-strong: rgba(13, 19, 31, .9);
    --stroke: rgba(148, 163, 184, .12); --stroke-2: rgba(148, 163, 184, .22);
    --ink: #e8eef7; --ink-2: #a3b1c6; --ink-3: #74839a;
    --accent: #38bdf8; --accent-soft: rgba(56, 189, 248, .14);
    --rain: #3987e5; --flow: #38bdf8; --band: rgba(56, 189, 248, .18); --wrf: #d95926;
    --m-ifs: #3987e5; --m-aifs: #199e70; --m-gfs: #c98500; --m-icon: #d55181;
    --shadow: 0 16px 50px -12px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #060a12; --glass: rgba(13, 19, 31, .72); --glass-strong: rgba(13, 19, 31, .9);
  --stroke: rgba(148, 163, 184, .12); --stroke-2: rgba(148, 163, 184, .22);
  --ink: #e8eef7; --ink-2: #a3b1c6; --ink-3: #74839a;
  --accent: #38bdf8; --accent-soft: rgba(56, 189, 248, .14);
  --rain: #3987e5; --flow: #38bdf8; --band: rgba(56, 189, 248, .18); --wrf: #d95926;
    --m-ifs: #3987e5; --m-aifs: #199e70; --m-gfs: #c98500; --m-icon: #d55181;
  --shadow: 0 16px 50px -12px rgba(0, 0, 0, .6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, select { font: inherit; color: inherit; }
h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.app {
  --w-left: 340px; --w-right: 420px;
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: var(--w-left) 1fr var(--w-right);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top top top" "left . right" "left tl right";
  gap: 12px; padding: 12px;
  pointer-events: none;
}
.app > * { pointer-events: auto; }
#map { position: fixed; inset: 0; z-index: 0; }
.glass {
  background: var(--glass); border: 1px solid var(--stroke); border-radius: 18px;
  backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: var(--shadow); z-index: 2;
}

/* --- Topbar --- */
.topbar { grid-area: top; display: flex; align-items: center; gap: 20px; padding: 10px 14px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; flex: none; }
/* Logos: fondo claro fijo para que se lean igual en tema claro y oscuro */
.logo-pill { display: inline-flex; align-items: center; justify-content: center; background: #fff; border-radius: 10px; padding: 5px 8px; box-shadow: 0 0 0 1px var(--stroke); flex: none; }
.logo-pill img { display: block; height: 32px; width: auto; }
.logo-socio { padding: 4px 6px; border-radius: 8px; opacity: .8; }
.logo-socio img { height: 18px; }
.logo-socio:hover { opacity: 1; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-name span { font-weight: 500; color: var(--ink-2); }
.brand-sub { font-size: 12px; color: var(--ink-3); }
.run-info { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(12, 163, 12, .6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }
.badge-info { font-size: 11px; font-weight: 600; letter-spacing: .03em; padding: 3px 9px; border-radius: 999px; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); cursor: help; white-space: nowrap; }
.modes { margin-left: auto; display: flex; padding: 3px; border-radius: 12px; background: var(--accent-soft); }
.modes button { white-space: nowrap; border: 0; background: none; padding: 6px 12px; border-radius: 9px; cursor: pointer; color: var(--ink-2); font-weight: 500; font-size: 13px; }
.modes button[aria-selected="true"] { background: var(--glass-strong); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.tools { display: flex; gap: 6px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--stroke); background: transparent; cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: var(--ink-2); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: var(--accent-soft); }
.icon-btn:hover { color: var(--ink); }

/* --- Paneles --- */
.panel { overflow: auto; scrollbar-width: thin; }
.left { grid-area: left; display: flex; flex-direction: column; padding: 14px; gap: 12px; min-height: 0; }
.right { grid-area: right; padding: 16px; min-height: 0; }
.detail-empty { color: var(--ink-3); padding: 40px 10px; text-align: center; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { padding: 10px 12px; border-radius: 14px; background: var(--accent-soft); border: 1px solid var(--stroke); }
.kpi .k-label { font-size: 11.5px; color: var(--ink-3); }
.kpi .k-val { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.kpi .k-val small { font-size: 12px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.kpi .k-sub { font-size: 11.5px; color: var(--ink-2); }

.list-head { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.list-head select { background: transparent; border: 1px solid var(--stroke); border-radius: 8px; padding: 4px 6px; font-size: 12px; }
.list-head select option { background: var(--glass-strong); color: var(--ink); }
.basin-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; overflow: auto; min-height: 0; }
.basin { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 2px 10px; padding: 9px 10px 8px 12px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; position: relative; transition: background .15s, border-color .15s; }
.basin::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--st, var(--ok)); }
.basin:hover { background: var(--accent-soft); }
.basin[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.b-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-meta { font-size: 11.5px; color: var(--ink-3); }
.b-q { text-align: right; font-size: 13px; }
.b-spark { grid-column: 2; grid-row: 2; width: 84px; height: 22px; }

.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 999px; background: color-mix(in srgb, var(--st) 16%, transparent); color: var(--ink); border: 1px solid color-mix(in srgb, var(--st) 45%, transparent); white-space: nowrap; }
.chip svg { width: 12px; height: 12px; fill: var(--st); }

/* --- Detalle --- */
.d-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.d-title { font-size: 20px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.d-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.d-close { border: 0; background: none; cursor: pointer; color: var(--ink-3); font-size: 20px; line-height: 1; padding: 2px 6px; border-radius: 8px; }
.d-close:hover { background: var(--accent-soft); color: var(--ink); }
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; margin: 14px 0 10px; }
.hero-main { padding: 12px 14px; border-radius: 16px; background: linear-gradient(135deg, var(--accent-soft), transparent); border: 1px solid var(--stroke); }
.hero-main .h-label { font-size: 12px; color: var(--ink-3); }
.hero-main .h-val { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; margin-top: 2px; }
.hero-main .h-val small { font-size: 15px; font-weight: 500; color: var(--ink-3); margin-left: 4px; }
.hero-main .h-trend { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }
.hero-side { display: flex; flex-direction: column; gap: 8px; }
.mini { padding: 8px 12px; border-radius: 12px; border: 1px solid var(--stroke); }
.mini .m-label { font-size: 11.5px; color: var(--ink-3); }
.mini .m-val { font-size: 17px; font-weight: 600; }
.mini .m-val small { font-size: 11px; color: var(--ink-3); font-weight: 500; }

.chart-wrap { margin: 6px -6px 0; }
.chart { width: 100%; height: 330px; }
.chart-sm { height: 190px; }
.ch-title { margin: 14px 0 0; font-size: 11.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11.5px; color: var(--ink-2); margin: 2px 0 12px; }
.legend i { display: inline-block; vertical-align: middle; margin-right: 5px; }
.lg-line { width: 16px; height: 2px; background: var(--flow); }
.lg-dash { width: 16px; height: 0; border-top: 2px dashed var(--flow); }
.lg-band { width: 14px; height: 10px; background: var(--band); border-radius: 2px; }
.lg-bar { width: 8px; height: 10px; background: var(--rain); border-radius: 2px; }
.lg-th { width: 16px; height: 0; border-top: 1.5px dashed var(--c); }
.lg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.lg-wrf { width: 16px; height: 2px; background: var(--wrf); }
.lg-m { width: 16px; height: 2px; background: var(--c); }
.lg-mm { width: 16px; height: 3px; background: var(--ink); border-radius: 2px; }
.lg-dot-line { width: 16px; height: 0; border-top: 1.5px dotted var(--ink-3); }

.prob h2 { margin: 6px 0 8px; }
.prob-row { display: grid; grid-template-columns: 80px 1fr 44px; align-items: center; gap: 10px; margin: 6px 0; font-size: 12.5px; }
.prob-bar { height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.prob-bar span { display: block; height: 100%; border-radius: 4px; background: var(--c); }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.fact { font-size: 11.5px; color: var(--ink-3); }
.fact b { display: block; color: var(--ink); font-size: 14px; font-weight: 600; }
.note { margin-top: 14px; font-size: 11.5px; color: var(--ink-3); border-top: 1px solid var(--stroke); padding-top: 10px; }

/* --- Timeline --- */
.timeline { grid-area: tl; display: flex; gap: 14px; align-items: center; padding: 10px 16px 8px 10px; align-self: end; }
.play { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; cursor: pointer; background: var(--accent); display: grid; place-items: center; box-shadow: 0 6px 20px -6px var(--accent); }
.play svg { width: 20px; height: 20px; fill: var(--bg); }
.play .i-pause, .play.on .i-play { display: none; }
.play.on .i-pause { display: block; }
.tl-body { flex: 1; min-width: 0; }
.tl-top { display: flex; align-items: center; gap: 10px; }
.tl-time { font-weight: 600; font-size: 14px; }
.tl-tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tl-tag.past { background: rgba(148, 163, 184, .16); color: var(--ink-2); }
.tl-rain { font-size: 11px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tl-now { margin-left: auto; border: 1px solid var(--stroke); background: none; border-radius: 8px; font-size: 12px; padding: 3px 9px; cursor: pointer; color: var(--ink-2); }
.tl-track { position: relative; height: 38px; margin-top: 6px; }
#tl-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#tl-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
#tl-range::-webkit-slider-runnable-track { height: 100%; background: transparent; }
#tl-range::-moz-range-track { height: 100%; background: transparent; }
#tl-range::-webkit-slider-thumb { -webkit-appearance: none; width: 3px; height: 38px; background: var(--ink); border-radius: 2px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 18%, transparent); }
#tl-range::-moz-range-thumb { width: 3px; height: 38px; background: var(--ink); border: 0; border-radius: 2px; }
#tl-range:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.tl-days { position: relative; height: 16px; font-size: 10.5px; color: var(--ink-3); }
.tl-days span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

/* --- Tooltip y mapa --- */
.tooltip { position: fixed; z-index: 20; pointer-events: none; padding: 9px 11px; border-radius: 12px; font-size: 12px; min-width: 170px; background: var(--glass-strong); }
.tooltip .t-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
.tooltip .t-row b { color: var(--ink); font-weight: 600; }
.maplibregl-ctrl-group { background: var(--glass-strong) !important; border-radius: 12px !important; border: 1px solid var(--stroke); box-shadow: var(--shadow) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--stroke) !important; }
:root[data-theme="dark"] .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { background: var(--glass) !important; color: var(--ink-3); font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--ink-2) !important; }
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { z-index: 1; }
.maplibregl-ctrl-top-right { top: 72px; right: calc(var(--w-right, 420px) + 20px); }
.st-marker { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 5px; border-radius: 999px; border: 1px solid var(--stroke-2); background: var(--glass-strong); color: var(--ink); box-shadow: var(--shadow); cursor: pointer; font: 500 11.5px/1.2 var(--font); white-space: nowrap; }
.st-marker svg { width: 18px; height: 18px; padding: 2px; border-radius: 50%; color: var(--bg); background: var(--accent); flex: none; }
.st-marker .st-name { font-weight: 600; }
.st-marker .st-val { color: var(--ink-2); font-size: 11px; }
.st-marker:hover, .st-marker.on { border-color: var(--accent); }
.st-marker.on { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.st-marker:focus-visible { outline: 2px solid var(--accent); }
.map-legend .ml-st svg { width: 14px; height: 14px; padding: 2px; border-radius: 50%; color: var(--bg); background: var(--accent); display: block; }
.station .b-q { font-size: 12px; }
#station-list { flex: none; overflow: visible; }

.map-legend { position: absolute; z-index: 2; left: calc(var(--w-left, 340px) + 24px); bottom: 116px; padding: 10px 12px; font-size: 11.5px; min-width: 150px; }
.map-legend .ml-title { font-weight: 600; color: var(--ink-2); margin-bottom: 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.map-legend .ml-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; color: var(--ink-2); }
.map-legend .ml-sw { width: 14px; height: 10px; border-radius: 3px; }
.map-legend .ml-ramp { height: 8px; border-radius: 4px; margin: 4px 0 2px; }
.map-legend .ml-scale { display: flex; justify-content: space-between; color: var(--ink-3); font-size: 10.5px; }

/* --- Responsivo --- */
/* Con la barra de módulos (2026-10-02) el texto de la corrida solo cabe en pantallas anchas */
@media (max-width: 1560px) {
  .run-info #run-label { display: none; }
}
@media (max-width: 1400px) {
  .topbar .brand-sub { display: none; }
}
@media (max-width: 1100px) and (min-width: 901px) {
  .topbar .run-info { display: none; }
}
@media (max-width: 1180px) {
  .app { --w-left: 300px; --w-right: 360px; }
  .modes button { padding: 6px 8px; }
  .run-info #run-label { display: none; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { position: static; display: flex; flex-direction: column; padding: 0 16px 16px; gap: 12px; }
  #map { position: relative; height: 58vh; margin: 0 -16px; order: 1; }
  .topbar { order: 0; flex-wrap: wrap; gap: 10px; margin: 12px 0 0; position: relative; }
  .modes { margin-left: 0; order: 3; width: 100%; }
  .modes button { flex: 1; }
  .run-info { display: none; }
  .tools { margin-left: auto; }
  .timeline { order: 2; }
  .right { order: 3; }
  .left { order: 4; }
  .map-legend { left: 10px; bottom: 28px; padding: 7px 9px; min-width: 0; font-size: 10.5px; }
  .map-legend .ml-row { margin: 1px 0; }
  .tl-now { white-space: nowrap; }
  .tl-time { font-size: 13px; }
  .maplibregl-ctrl-top-right { top: 10px; right: 10px; }
  .hero { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

/* --- Paneles redimensionables --- */
.resizer { position: fixed; z-index: 5; top: 90px; bottom: 12px; width: 12px; cursor: col-resize; touch-action: none; }
.resizer[data-lado="left"] { left: calc(12px + var(--w-left) - 6px); }
.resizer[data-lado="right"] { right: calc(12px + var(--w-right) - 6px); }
.resizer::after { content: ""; position: absolute; left: 5px; top: 50%; width: 2px; height: 44px; margin-top: -22px; border-radius: 2px; background: var(--stroke-2); transition: background .15s, height .15s; }
.resizer:hover::after, .resizer:focus-visible::after, .resizer.activo::after { background: var(--accent); height: 80px; margin-top: -40px; }
.resizer:focus-visible { outline: none; }
body.redimensionando { cursor: col-resize; user-select: none; }
body.redimensionando #map, body.redimensionando .chart { pointer-events: none; }
@media (max-width: 900px) { .resizer { display: none; } .logo-socio { order: 2; } }
