/* ============================================================================
   caudal.puaj.club · monitor de los ríos Paraná y Uruguay
   La página adopta la estética de puaj.club: papel gris de los primeros
   navegadores (Mosaic/Netscape) en claro y modo texto de BBS/DOS con paleta CGA
   en oscuro; monoespaciada, botones entre corchetes, secciones como #canales.
   Los gráficos siguen siendo figuras de matplotlib incrustadas: panel propio,
   ejes en caja negra fina, marcas afuera, DejaVu Sans.
   ========================================================================== */

:root {
  color-scheme: light;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --plot: "DejaVu Sans", "Bitstream Vera Sans", Verdana, Geneva, sans-serif; /* texto dentro de las figuras */
  --sb-h: 34px;

  /* página (puaj.club, claro) */
  --bg: #ffffff;             /* el mismo fondo que las figuras */
  --ink: #000000;
  --ink-2: #404040;          /* --muted */
  --ink-3: #555555;
  --rule: #808080;
  --accent: #000080;
  --link: #0000ee;
  --link-visited: #551a8b;
  --code-bg: #f0f0f0;        /* cajitas y fila elegida: gris muy suave sobre blanco */
  --code-ink: #000000;
  --strong: #000000;

  /* figuras (matplotlib) */
  --fig: #ffffff;
  --surface: var(--fig);
  --map-bg: var(--fig);
  --halo: var(--fig);
  --frame: #000000;
  --legend-edge: #b0b0b0;
  --grid: #e6e6e6;
  --water-faint: #a6c8e0;
  --lake: #c6dbef;
  --coast: #555555;
  --band: #d9d9d9;
  --median: #444444;
  --q: #1f77b4;              /* C0 */
  --q-fc: #1f77b4;
  --fc-band: #c7ddec;
  --model: #ff7f0e;          /* C1 */
  --low-2: #b40426;          /* coolwarm */
  --low-1: #f4987a;
  --mid: #bdbdbd;
  --high-1: #7b9ff9;
  --high-2: #3b4cc0;

  --st-good: #008000;
  --st-warning: #e07000;
  --st-critical: #c00000;
}

/* oscuro: BBS / DOS en modo texto, paleta CGA */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000; --ink: #aaaaaa; --ink-2: #aaaaaa; --ink-3: #808080; --rule: #555555;
    --accent: #ffff55; --link: #55ffff; --link-visited: #ff55ff; --code-bg: #0000aa; --code-ink: #ffffff; --strong: #ffffff;
    --fig: #000000; --frame: #aaaaaa; --legend-edge: #555555; --grid: #1a1a1a;
    --water-faint: #0000aa; --lake: #00006e; --coast: #555555;
    --band: #222222; --median: #aaaaaa; --q: #55ffff; --q-fc: #55ffff; --fc-band: #003b4a; --model: #ffff55;
    --low-2: #ff5555; --low-1: #aa5500; --mid: #555555; --high-1: #5555ff; --high-2: #55ffff;
    --st-good: #55ff55; --st-warning: #ffff55; --st-critical: #ff5555;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000; --ink: #aaaaaa; --ink-2: #aaaaaa; --ink-3: #808080; --rule: #555555;
  --accent: #ffff55; --link: #55ffff; --link-visited: #ff55ff; --code-bg: #0000aa; --code-ink: #ffffff; --strong: #ffffff;
  --fig: #000000; --frame: #aaaaaa; --legend-edge: #555555; --grid: #1a1a1a;
  --water-faint: #0000aa; --lake: #00006e; --coast: #555555;
  --band: #222222; --median: #aaaaaa; --q: #55ffff; --q-fc: #55ffff; --fc-band: #003b4a; --model: #ffff55;
  --low-2: #ff5555; --low-1: #aa5500; --mid: #555555; --high-1: #5555ff; --high-2: #55ffff;
  --st-good: #55ff55; --st-warning: #ffff55; --st-critical: #ff5555;
}

/* ---------- base */
* { box-sizing: border-box; }
html { background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 var(--mono); }
a { color: var(--link); text-underline-offset: 0.2em; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2 { margin: 0; color: var(--strong); }
h1 { font-size: clamp(24px, 2.6vw, 32px); line-height: 1.1; letter-spacing: -0.02em; }
h2 { font-size: 15px; }
h3 { color: var(--ink-2); }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
/* secciones nombradas como canales de IRC */
.kicker { margin: 0 0 2px; font-size: 13px; color: var(--ink-2); }
.kicker::before { content: "#"; color: var(--accent); }
.cursor { color: var(--accent); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }

/* ---------- botones: texto entre corchetes, como en puaj.club */
.btn, .sb-btn, .seg button {
  font: inherit; font-weight: 600; color: var(--ink); background: none;
  border: 0; border-radius: 0; padding: 0 2px; cursor: pointer; white-space: nowrap;
  height: auto; width: auto;
}
.btn::before, .sb-btn::before, .seg button::before { content: "[ "; }
.btn::after, .sb-btn::after, .seg button::after { content: " ]"; }
.btn:hover, .sb-btn:hover, .seg button:hover { text-decoration: underline; }
.btn:disabled { color: var(--ink-3); cursor: default; text-decoration: none; }
.seg { display: inline-flex; gap: 10px; }
.seg button { color: var(--ink-2); font-weight: normal; }
.seg button[aria-selected="true"] { color: var(--accent); font-weight: 600; }
select {
  font: inherit; font-size: 13px; color: var(--code-ink); background: var(--code-bg);
  border: 2px inset var(--rule); border-radius: 0; padding: 2px 4px; max-width: 50%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 8px 0 2px; }

/* ---------- barra de estado */
.statusbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--sb-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 14px 0 16px;
  background: var(--bg);
  border-bottom: 2px groove var(--rule);
  font-size: 12.5px; color: var(--ink-2);
}
.sb-brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.sb-name { color: var(--strong); font-weight: 600; }
.sb-name .prompt { color: var(--ink-2); font-weight: normal; }
.sb-sub { color: var(--accent); }
.sb-sources {
  flex: 1; min-width: 0; display: flex; gap: 16px; margin: 0; padding: 0; list-style: none;
  overflow-x: auto; scrollbar-width: none;
}
.sb-sources::-webkit-scrollbar { display: none; }
.sb-sources li { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.sb-sources b { color: var(--strong); font-weight: normal; }
.sb-right { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.sb-clock { font-variant-numeric: tabular-nums; }

/* íconos de estado: forma + color + texto */
.ico { width: 9px; height: 9px; display: inline-block; flex: none; }
.ico.ok { background: var(--st-good); border-radius: 50%; }
.ico.alerta { background: var(--st-warning); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.ico.evac { background: var(--st-critical); }

/* ---------- layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr);
  min-height: calc(100vh - var(--sb-h));
}
.map-col {
  position: sticky; top: var(--sb-h); height: calc(100vh - var(--sb-h));
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 8px 12px 16px;
}
.prompt-line { margin: 0; color: var(--ink-2); }
.title h1 { margin-top: 2px; }
.tagline { margin: 3px 0 0; color: var(--accent); }
.title .lede { margin: 6px 0 0; max-width: 52ch; }

/* el mapa es una figura de matplotlib: panel propio, eje en caja, marcas de lon/lat afuera */
.map-wrap { flex: 1; min-height: 0; position: relative; padding: 4px 6px 26px 50px; background: var(--fig); }
#map { width: 100%; height: 100%; display: block; background: var(--map-bg); border: 1px solid var(--frame); }
.map-axes { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.map-axes text { font: 11px var(--plot); fill: var(--ink); }
.coords {
  position: absolute; left: 56px; bottom: 32px; pointer-events: none;
  font: 11px var(--mono); color: var(--code-ink); font-variant-numeric: tabular-nums;
  background: var(--code-bg); padding: 1px 5px;
}
.coords:empty { display: none; }

/* leyenda del mapa: colorbar + recuadro de leyenda (dentro de la figura) */
.legend {
  display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: flex-end;
  background: var(--fig); padding: 4px 6px 8px 50px; margin-top: -8px;
  font: 12px var(--plot); color: var(--ink);
}
.cbar { margin: 0; }
.cbar figcaption { font-size: 12px; margin-bottom: 3px; }
.cbar svg { display: block; overflow: visible; }
.cbar text { font: 11px var(--plot); fill: var(--ink); }
.mpl-legend {
  display: inline-flex; flex-wrap: wrap; gap: 4px 14px; align-items: center;
  border: 1px solid var(--legend-edge); border-radius: 3px; padding: 3px 8px; background: var(--fig);
}

.panel { padding: 12px 18px 32px 12px; display: flex; flex-direction: column; }
.card { background: none; border: 0; border-top: 2px groove var(--rule); padding: 12px 0 10px; margin-top: 10px; }
.card h2 + p { margin: 3px 0 8px; }

/* ---------- tablero de situación: cajitas como los bloques de código de puaj */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.kpi {
  font: inherit; text-align: left; margin: 0;
  color: var(--code-ink); background: var(--code-bg); border: 2px groove var(--rule); border-radius: 0;
  padding: 6px 9px; display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.kpi .kicker { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--code-ink); font-weight: 600; }
.kpi .kicker::before { content: none; }
.kpi ol { margin: 3px 0 0; padding-left: 3ch; font-size: 12.5px; line-height: 1.5; }
.kpi ol.many { columns: 2; column-gap: 3ch; }
.kpi li { break-inside: avoid; }
.kpi li::marker { color: var(--ink-3); }
.kpi .none { margin: 3px 0 0; font-size: 12.5px; color: var(--ink-3); }
/* cada nombre es un link a su dato */
.kpi-link {
  font: inherit; color: var(--link); background: none; border: 0; padding: 0; margin: 0;
  text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em;
  vertical-align: top; /* el número del ítem queda en el primer renglón aunque el nombre ocupe dos */
}
.kpi-link:hover { text-decoration-thickness: 2px; }
/* al llegar desde el tablero: el destino queda visible bajo las barras fijas y se resalta un momento */
#detail, .gauge-row, .dam { scroll-margin-top: calc(var(--sb-h) + 110px); }
.flash { animation: flash 1.8s ease-out; }
@keyframes flash { 0%, 35% { background: var(--code-bg); box-shadow: 0 0 0 3px var(--accent); } 100% { background: transparent; box-shadow: 0 0 0 3px transparent; } }
@media (prefers-reduced-motion: reduce) { .flash { animation: none; outline: 2px solid var(--accent); } }

/* ---------- tiempo */
.time {
  position: sticky; top: var(--sb-h); z-index: 5;
  background: var(--bg);
  padding: 8px 0;
  border-top: 2px groove var(--rule);
}
.time-head { display: flex; align-items: center; gap: 12px; }
.time-label { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.time-label strong { font-size: 14px; color: var(--strong); }
#date-rel { font-size: 12px; color: var(--accent); }
.time-scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-2); }

/* ---------- figuras (matplotlib) */
.chart { width: 100%; height: auto; display: block; overflow: visible; background: var(--fig); padding: 6px 4px 2px; }
.chart text, #map text { font-family: var(--plot); }
.axis text { fill: var(--ink); font-size: 11px; }
.axis .ax-label { font-size: 12px; }
.spine { fill: none; stroke: var(--frame); stroke-width: 0.8; vector-effect: non-scaling-stroke; }
.tick { stroke: var(--frame); stroke-width: 0.8; vector-effect: non-scaling-stroke; }
.card-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.head-ctl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.head-ctl select { max-width: none; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 10px 0 8px; }
.stat .k { font-size: 12px; color: var(--ink-2); }
.stat .v { font-size: 18px; line-height: 1.3; font-weight: 600; color: var(--strong); font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--ink-2); }
/* leyenda en recuadro, como plt.legend(), dentro del panel de la figura */
.series-key {
  display: flex; flex-wrap: wrap; gap: 3px 14px;
  background: var(--fig); padding: 0 4px 6px 74px; color: var(--ink); font: 12px var(--plot);
}
.series-key::before { content: none; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 18px; height: 9px; }
.sw.line { height: 1.5px; }
.sw.dash { height: 0; border-top: 1.5px dashed; background: none; }
.note { margin: 4px 0 10px; color: var(--ink-2); font-size: 12.5px; }
.note .chip { margin-right: 2px; }

/* ---------- tabla (como /stats de puaj.club) */
.table-wrap { overflow-x: auto; margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-weight: normal; color: var(--ink-2); padding: 3px 12px 3px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th.num { text-align: right; }
td { padding: 2px 12px 2px 0; white-space: nowrap; }
td.num { padding-right: 12px; }
tbody tr { cursor: pointer; }
tbody tr:hover td, tbody tr.sel td { background: var(--code-bg); color: var(--code-ink); }
td .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 0; }
td.trib { padding-left: 16px; color: var(--ink-2); }
tr.river-row th { padding-top: 12px; color: var(--strong); border-bottom: 1px solid var(--rule); cursor: default; }
tr.river-row th::before { content: "# "; color: var(--accent); }

.foot { margin-top: 14px; border-top: 2px groove var(--rule); padding-top: 12px; color: var(--ink-2); }
.foot p { margin: 0 0 6px; }
.foot a, .foot a:visited { color: inherit; }

/* ---------- tooltip (bloque de código) */
.tip {
  position: fixed; z-index: 40; pointer-events: none;
  background: var(--code-bg); color: var(--code-ink);
  border: 2px outset var(--rule);
  padding: 4px 7px; font: 12px/1.45 var(--mono);
  max-width: 270px;
}
.tip .muted { color: inherit; opacity: 0.75; }
.tip .row { display: flex; justify-content: space-between; gap: 12px; }
.tip .row span:last-child { font-variant-numeric: tabular-nums; }

/* ---------- mapa */
.st-label { font-size: calc(16px / var(--kt, 1)); fill: var(--ink); paint-order: stroke; stroke: var(--halo); stroke-width: calc(4px / var(--kt, 1)); stroke-linejoin: round; }
:root[data-theme="dark"] .st-label { fill: #ffffff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .st-label { fill: #ffffff; } }
.st-label.sub { fill: var(--ink-3); font-size: calc(13px / var(--kt, 1)); }
.st-label.sel { font-weight: bold; }
.riv-label { font-size: calc(14px / var(--kt, 1)); font-style: italic; fill: var(--ink-3); paint-order: stroke; stroke: var(--halo); stroke-width: calc(4px / var(--kt, 1)); }
.st-dot { fill: var(--fig); stroke: var(--ink); stroke-width: calc(1.5px / var(--k, 1)); cursor: pointer; }
.st-dot.sel { fill: var(--accent); stroke: var(--accent); }
.hit { fill: transparent; cursor: pointer; }
.ring { fill: none; stroke-width: calc(3px / var(--k, 1)); pointer-events: none; }
#map { cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
#map.panning { cursor: grabbing; }
#map:not([data-zoomed]) .st-label.z2 { display: none; }
#map.sat-on .net { opacity: 0.25; }
#map.sat-on .riv-label { fill: var(--ink-2); }
#map.sat-on.deep .river-g { opacity: 0.45; }
.map-ctl {
  position: absolute; top: 10px; right: 14px; z-index: 2;
  display: flex; flex-direction: column; align-items: flex-end; gap: 0;
  background: var(--fig); padding: 2px 4px; font-size: 13px;
}
.map-ctl .btn { line-height: 1.6; }
.map-ctl .btn-sat[aria-pressed="true"] { color: var(--accent); }

/* ---------- alturas, satélite, represas */
.sub-block { margin: 12px 0 4px; padding-top: 10px; border-top: 1px dashed var(--rule); }
.sub-block h3 { font-size: 13.5px; font-weight: 600; margin: 0 0 2px; }
.gauge-row { margin-top: 10px; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12.5px; }
.gauge-head .h { font-size: 15px; font-weight: 600; color: var(--strong); font-variant-numeric: tabular-nums; }
.gauge { width: 100%; height: auto; display: block; overflow: visible; margin-top: 4px; background: var(--fig); padding: 4px 4px 2px; }
.gauge text { font-family: var(--plot); fill: var(--ink); }
.gauge rect[rx] { rx: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; white-space: nowrap; }
.chip .ico { width: 10px; height: 10px; }
.chip.alerta .ico { background: var(--st-warning); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.chip.evac .ico { background: var(--st-critical); }
.sat .frame { position: relative; overflow: hidden; background: var(--band); margin-top: 8px; border: 2px inset var(--rule); }
.sat .frame img { display: block; width: 100%; height: auto; }
.sat .frame img.overlay { position: absolute; inset: 0; height: 100%; }
.sat figcaption { margin-top: 6px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; }
.sat label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.sat select { max-width: none; }
.dam { margin-top: 12px; }
.dam + .dam { border-top: 1px dashed var(--rule); padding-top: 12px; }
.dam h3 { font-size: 13.5px; margin: 0; color: var(--strong); }

/* ---------- pantallas medianas y chicas */
@media (max-width: 1100px) {
  .sb-sub { display: none; }
}
@media (max-width: 900px) {
  .statusbar { gap: 12px; padding: 0 10px 0 12px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .map-col { position: static; height: auto; padding: 12px 12px 0; }
  .map-wrap { height: auto; aspect-ratio: 1000 / 1080; max-height: 88vh; flex: none; }
  .legend { padding-left: 8px; }
  .panel { padding: 8px 12px 24px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .sb-clock { display: none; }
  .kpi .v { font-size: 17px; }
  .map-wrap { padding: 4px 4px 24px 42px; }
  .series-key { padding-left: 8px; }
  .st-label { font-size: calc(28px / var(--kt, 1)); stroke-width: calc(6px / var(--kt, 1)); }
  .st-label.sub { font-size: calc(22px / var(--kt, 1)); }
  .st-label.sub, .st-label.minor { display: none; }
  #map[data-zoomed] .st-label.sub, #map[data-zoomed] .st-label.minor { display: inline; }
  .riv-label { font-size: calc(22px / var(--kt, 1)); stroke-width: calc(6px / var(--kt, 1)); }
  select { max-width: 45%; }
}

/* ---------- /stats (privada) */
main.stats-main { max-width: 86ch; margin: 0 auto; padding: 24px 16px 40px; }
main.stats-main .card { margin-top: 18px; }
h1 a.home, h1 a.home:visited { color: inherit; text-decoration: none; }
h1 a.home:hover { text-decoration: underline; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 3ch; margin: 6px 0 0; }
dl.kv dt { color: var(--ink-2); }
dl.kv dd { margin: 0; font-weight: 600; color: var(--strong); }
td.bar { color: var(--accent); width: 100%; padding-right: 0; letter-spacing: -1px; }
.stats-page tbody tr { cursor: default; }
.stats-page tbody tr:hover td { background: none; color: inherit; }
