/* =====================================================================
   FistulMET · Hoja de estilos
   Paleta derivada del escudo del Excmo. Klub Fistula: gris de tormenta,
   azul del rótulo «FistuMet» y naranja de ocaso.
   ===================================================================== */
:root {
  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --page: #EAEFF2;
  --surface: #FFFFFF;
  --surface-2: #F4F7F9;
  --surface-3: #E9EEF2;
  --ink: #10202E;
  --ink-2: #44586A;
  --muted: #74879A;
  --line: #DCE3E9;
  --line-2: #C4D0DA;
  --accent: #1F6AA5;
  --accent-2: #174F7D;
  --accent-ink: #FFFFFF;
  --accent-soft: #E1EDF7;
  --albero: #A45512;
  --albero-strong: #E0862F;
  --albero-fill: rgba(224, 134, 47, 0.15);
  --brand-ink: #1D2631;
  --brand-ink-2: #2C3B4E;
  --brand-blue: #3689C1;
  --brand-orange: #E0862F;
  --snow: #1C8FBF;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #087a08;
  --focus: #1F6AA5;
  --radius: 10px;
  --radius-sm: 6px;
  --gap: 18px;
  --rail-w: 232px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --page: #08111A;
  --surface: #0E1925;
  --surface-2: #132131;
  --surface-3: #192A3C;
  --ink: #E7EEF5;
  --ink-2: #A9B9C9;
  --muted: #7E91A4;
  --line: #1E2E3F;
  --line-2: #2B4054;
  --accent: #6FB1E8;
  --accent-2: #9CCBF2;
  --accent-ink: #08111A;
  --accent-soft: #15304A;
  --albero: #F0A659;
  --albero-strong: #F0A659;
  --albero-fill: rgba(240, 166, 89, 0.15);
  --brand-ink: #0B131C;
  --brand-ink-2: #18263A;
  --snow: #7FD1F0;
  --good-text: #3fcf3f;
  --focus: #9CCBF2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 640; font-stretch: 108%; letter-spacing: -0.01em; }
h1 { font-size: 27px; }
h2 { font-size: 17px; font-weight: 620; }
h3 { font-size: 15px; font-weight: 620; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 12px; }
.micro { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------------- Barra superior (identidad del escudo) ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 22px;
  padding: 10px 22px;
  background: linear-gradient(100deg, var(--brand-ink) 0%, var(--brand-ink-2) 62%, #3a3330 100%);
  color: #F3F6F9;
  border-bottom: 3px solid var(--brand-orange);
  color-scheme: dark;
}
.brand { display: flex; align-items: center; gap: 11px; flex: 0 0 auto; width: calc(var(--rail-w) - 22px); }
.brand-logo { width: 46px; height: 46px; border-radius: 9px; flex: 0 0 auto; box-shadow: 0 0 0 1.5px rgba(255,255,255,.22), 0 3px 10px rgba(0,0,0,.35); object-fit: cover; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 21px; font-weight: 760; font-stretch: 112%; letter-spacing: -0.01em; color: #fff; }
.brand-name span { color: var(--brand-orange); }
.brand-sub { font-size: 11.5px; color: rgba(243,246,249,.68); font-stretch: 92%; }
.topbar .ctx { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.16); color: #F3F6F9; }
.topbar .ctx:hover { border-color: rgba(255,255,255,.32); }
.topbar .ctx-k { color: rgba(243,246,249,.66); }
.topbar .ctx-loc svg { color: var(--brand-orange); }
.topbar .ctx select option { color: #10202E; background: #fff; }
.topbar .ctx-win-row span { color: rgba(243,246,249,.6); }
.topbar .status { color: rgba(243,246,249,.72); }
.topbar .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.2); color: #F3F6F9; }
.topbar .btn:hover { background: rgba(255,255,255,.16); }
.topbar .btn-primary { background: var(--brand-orange); border-color: var(--brand-orange); color: #1b1208; }
.topbar .btn-primary:hover { background: #F09A49; border-color: #F09A49; }
.topbar .status.is-loading::before { border-color: var(--brand-orange); border-right-color: transparent; }
.topbar :focus-visible { outline-color: #F0A659; }

.context { display: flex; align-items: stretch; gap: 10px; flex: 1 1 auto; flex-wrap: wrap; }
.ctx {
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
  padding: 5px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); min-height: 46px;
}
.ctx-k { font-size: 11.5px; color: var(--muted); font-stretch: 92%; }
.ctx-v { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 270px; display: block; }
.ctx-loc { flex-direction: row; align-items: center; justify-content: flex-start; gap: 9px; cursor: pointer; text-align: left; }
.ctx-loc svg { width: 20px; height: 20px; color: var(--accent); flex: 0 0 auto; }
.ctx-loc:hover { border-color: var(--line-2); }
.ctx-text { display: flex; flex-direction: column; min-width: 0; }
.ctx input[type="date"], .ctx select {
  border: 0; background: transparent; padding: 0; font-weight: 600; font-size: 14px; cursor: pointer;
}
.ctx-win-row { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; }
.ctx-win-row span { color: var(--muted); font-weight: 400; }
.ctx-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.status { font-size: 12.5px; color: var(--muted); max-width: 300px; line-height: 1.3; text-align: right; }
.status.is-loading::before {
  content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-radius: 50%;
  border: 2px solid var(--accent); border-right-color: transparent; vertical-align: -1px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer;
  font-size: 14px; font-weight: 560; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-icon { width: 36px; padding: 0; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-sm { height: 30px; font-size: 13px; }
.btn-sm.btn-icon { width: 30px; }
.btn[disabled] { opacity: .55; cursor: progress; }

/* ---------------- Estructura ---------------- */
.layout { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: calc(100vh - 67px); }
.rail {
  position: sticky; top: 67px; align-self: start; height: calc(100vh - 67px);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 18px 12px 16px; border-right: 1px solid var(--line); background: var(--surface);
}
.rail [role="tablist"] { display: flex; flex-direction: column; gap: 3px; }
.rail [role="tab"] {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: transparent;
  text-align: left; cursor: pointer; font-size: 14.5px; font-weight: 520; color: var(--ink-2);
  position: relative;
}
.rail [role="tab"] svg { width: 20px; height: 20px; flex: 0 0 auto; }
.rail [role="tab"]:hover { background: var(--surface-2); color: var(--ink); }
.rail [role="tab"][aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 640; }
.rail [role="tab"][aria-selected="true"]::before {
  content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.rail-foot { font-size: 11.5px; color: var(--muted); line-height: 1.45; padding: 0 8px; }

main { padding: 22px 26px 60px; min-width: 0; }
main:focus { outline: none; }
.tab { display: flex; flex-direction: column; gap: var(--gap); max-width: 1480px; }
.section-head { display: flex; flex-direction: column; gap: 6px; }
.section-head p { color: var(--ink-2); max-width: 78ch; }
.section-head-row { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head-wrap { align-items: flex-start; }
.panel-note { font-size: 13px; color: var(--muted); margin: -2px 0 10px; max-width: 95ch; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.grid-2-wide { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
.tbl-compact th, .tbl-compact td { padding: 6px 7px; font-size: 12.5px; }

.banner {
  border: 1px solid var(--line-2); border-left: 4px solid var(--warning); background: var(--surface);
  border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: var(--gap); font-size: 14px;
}
.banner.is-error { border-left-color: var(--critical); }

/* ---------------- Segmentos y chips ---------------- */
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 13px; font-size: 13.5px; cursor: pointer; color: var(--ink-2); font-weight: 520; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip .dash { width: 14px; height: 0; border-top: 2px dashed currentColor; display: inline-block; }

/* ---------------- Cabecera de la predicción del día ---------------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 520px); gap: var(--gap); align-items: stretch; }
.hero-title { display: flex; flex-direction: column; justify-content: center; gap: 8px; padding: 4px 2px; }
.hero-title h1 { font-size: 34px; font-weight: 680; font-stretch: 112%; letter-spacing: -0.02em; }
.hero-sub { color: var(--ink-2); font-size: 14.5px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.hero-sub .pill { display: inline-flex; align-items: center; gap: 6px; }
.verdict {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px 14px 20px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px; justify-content: center;
}
.verdict::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--muted); }
.verdict[data-level="good"]::before { background: var(--good); }
.verdict[data-level="warning"]::before { background: var(--warning); }
.verdict[data-level="serious"]::before { background: var(--serious); }
.verdict[data-level="critical"]::before { background: var(--critical); }
.verdict-main { display: flex; align-items: center; gap: 16px; }
.verdict-big { font-size: 46px; font-weight: 640; font-stretch: 96%; line-height: 1; letter-spacing: -0.02em; white-space: nowrap; }
.verdict-text { display: flex; flex-direction: column; gap: 3px; }
.verdict-text strong { font-size: 16px; font-weight: 640; display: inline-flex; align-items: center; gap: 7px; }
.verdict-text span { font-size: 13.5px; color: var(--ink-2); }
.verdict-decision { font-size: 13.5px; color: var(--ink-2); border-top: 1px solid var(--line); padding-top: 8px; }
.verdict-text .verdict-snow { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.verdict-text .verdict-snow b { color: var(--snow); font-weight: 680; }
.verdict-decision b { color: var(--ink); font-weight: 640; }

/* ---------------- Franja del cielo ---------------- */
.sky-panel { padding-bottom: 12px; }
.sky-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
:root[data-theme="dark"] .sky-cell { box-shadow: inset 0 0 0 1px rgba(255,255,255,.07); }
.sky { --cols: 24; position: relative; user-select: none; padding-top: 36px; }
.sky-row { display: grid; grid-template-columns: 64px repeat(var(--cols), minmax(0, 1fr)); align-items: center; }
.sky-row > .lab { font-size: 11.5px; color: var(--muted); padding-right: 8px; text-align: right; line-height: 1.15; }
.sky-hours span { font-size: 11.5px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.sky-band { position: relative; height: 78px; margin: 4px 0 2px; }
.sky-band .cells { position: absolute; inset: 0 0 0 64px; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 2px; }
.sky-cell { position: relative; border-radius: 4px; overflow: hidden; }
.sky-cell svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.sky-cell:first-child { border-radius: 7px 4px 4px 7px; }
.sky-cell:last-child { border-radius: 4px 7px 7px 4px; }
.sky-window {
  position: absolute; top: -9px; bottom: -9px; border: 2px solid var(--albero-strong); border-radius: 8px;
  pointer-events: none; box-shadow: 0 0 0 3px var(--albero-fill);
}
.sky-window-label {
  position: absolute; top: -25px; left: -2px; white-space: nowrap;
  font-size: 12.5px; font-weight: 660; color: var(--albero); padding: 0 2px;
}
.sky-sun { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 1.5px solid var(--albero-strong); pointer-events: none; }
.sky-sun span {
  position: absolute; bottom: 6px; left: 4px; font-size: 10.5px; color: #fff; white-space: nowrap; font-weight: 600;
  background: rgba(8, 16, 32, .62); padding: 1px 5px; border-radius: 3px; line-height: 1.3;
}
.sky-hours { margin-top: 5px; }
.sky-icons { margin-top: 4px; }
.sky-icons > div, .sky-temps > div, .sky-prob > div { display: flex; justify-content: center; }
.sky-temps > div { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sky-prob > div { font-size: 11.5px; color: var(--accent); font-variant-numeric: tabular-nums; min-height: 16px; }
.sky-prob .pbar { width: 70%; height: 4px; border-radius: 2px; background: var(--surface-3); position: relative; overflow: hidden; margin-top: 2px; }
.sky-prob .pbar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 2px; }
.sky-col-win { background: var(--albero-fill); }
.sky-snow > div { color: var(--snow); }
.sky-snow .pbar i { background: var(--snow); }
.sky-snow .zero { color: var(--muted); opacity: .55; }
.sky-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 10px; padding-left: 64px; }
.sky-legend i { display: inline-block; width: 22px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }

/* ---------------- KPIs ---------------- */
.kpis {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.kpi { padding: 14px 16px 15px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi + .kpi { border-left: 1px solid var(--line); }
.kpis > .kpi:nth-child(4n+1) { border-left: 0; }
.kpis > .kpi:nth-child(n+5) { border-top: 1px solid var(--line); }
.kpi-snow .meter i.on { background: var(--snow); }
.kpi-k { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.kpi-k svg { width: 17px; height: 17px; color: var(--ink-2); flex: 0 0 auto; }
.kpi-v { font-size: 27px; font-weight: 640; font-stretch: 98%; line-height: 1.05; letter-spacing: -0.015em; display: flex; align-items: center; gap: 8px; }
.kpi-v small { font-size: 15px; font-weight: 560; color: var(--ink-2); }
.kpi-s { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }
.kpi-s b { font-weight: 640; color: var(--ink); }
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.tag .status-icon { flex: 0 0 auto; }
.meter { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; margin-top: 2px; }
.meter i { height: 6px; border-radius: 1.5px; background: var(--surface-3); }
.meter i.on { background: var(--accent); }
.rangebar { position: relative; height: 8px; border-radius: 4px; background: var(--surface-3); margin-top: 3px; }
.rangebar i { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: var(--serious); opacity: .55; }
.rangebar b { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--ink); border-radius: 1px; }
.rangebar em { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--muted); border-radius: 1px; }

/* ---------------- Gráficos ---------------- */
.chart { width: 100%; min-height: 200px; }
.chart-meteo { height: 640px; }
.chart-xl { height: 470px; }
.chart-md { height: 340px; }
.chart-matrix { height: 380px; }
.chart-trend { height: 420px; }
.chart-rose { height: 300px; }
.legend-models { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.legend-models span { display: inline-flex; align-items: center; gap: 6px; }
.legend-models i { display: inline-block; width: 18px; height: 0; border-top: 2.5px solid; }
.legend-models i.ai { border-top-style: dashed; }

/* ---------------- Tablas ---------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tbl th { font-weight: 600; color: var(--ink-2); font-size: 12.5px; background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; font-stretch: 94%; }
.tbl td.c, .tbl th.c { text-align: center; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl .muted { color: var(--muted); }
.tbl-hourly td { white-space: nowrap; }
.tbl-hourly td:first-child, .tbl-hourly th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; }
.tbl-hourly th:first-child { background: var(--surface-2); z-index: 3; }
.tbl-hourly tr.in-win td { background: var(--albero-fill); }
.tbl-hourly tr.in-win td:first-child { box-shadow: inset 3px 0 0 var(--albero-strong); background: color-mix(in srgb, var(--albero-strong) 14%, var(--surface)); }
.tbl-hourly .sky-cell-txt { display: inline-flex; align-items: center; gap: 7px; }
.tbl-hourly .wx-icon { flex: 0 0 auto; }
.tbl .pbar { display: inline-block; width: 46px; height: 6px; background: var(--surface-3); border-radius: 3px; position: relative; vertical-align: middle; margin-right: 7px; overflow: hidden; }
.tbl .pbar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); }
.tbl .pbar-snow i { background: var(--snow); }
.wind-cell { display: inline-flex; align-items: center; gap: 6px; }
.wind-arrow { flex: 0 0 auto; color: var(--ink-2); }
.tbl-review td { vertical-align: top; }
.tbl-review .use { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; display: inline-block; }
.use-det { background: var(--accent-soft); color: var(--accent); }
.use-ens { background: color-mix(in srgb, #1baf7a 16%, var(--surface)); color: #0d7a52; }
:root[data-theme="dark"] .use-ens { color: #4fd3a0; }
.use-no { background: var(--surface-3); color: var(--ink-2); }
.use-ref { background: var(--albero-fill); color: var(--albero); }
.use-ext { background: color-mix(in srgb, #4a3aa7 14%, var(--surface)); color: #4a3aa7; }
:root[data-theme="dark"] .use-ext { color: #a99ff0; }
.ai-badge { font-size: 11px; font-weight: 700; color: #4a3aa7; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 6px; white-space: nowrap; }
:root[data-theme="dark"] .ai-badge { color: #a99ff0; }

/* ---------------- AEMET ---------------- */
.aemet-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: var(--gap); }
.aemet-links { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.aemet-links a { display: inline-flex; align-items: center; gap: 8px; }

/* ---------------- Mapas ---------------- */
.map-shell { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: var(--gap); min-height: 640px; }
.map-ctrl { display: flex; flex-direction: column; gap: 12px; }
.map-ctrl fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 12px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 9px; min-width: 0;
}
.map-ctrl legend { font-weight: 640; font-size: 14px; padding: 0 4px; display: inline-flex; align-items: center; gap: 8px; }
.map-ctrl label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.map-ctrl select, .dlg select, .dlg input[type="number"], .dlg input[type="text"], .dlg input[type="search"], .dlg input[type="password"] {
  height: 34px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); padding: 0 9px; font-size: 14px; color: var(--ink); width: 100%;
}
.time-ctl { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.time-ctl output { font-variant-numeric: tabular-nums; font-weight: 640; font-size: 13.5px; min-width: 44px; text-align: right; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-2); transition: background .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; left: 3px; top: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.legend-bar { display: flex; flex-direction: column; gap: 3px; }
.legend-bar .grad { height: 12px; border-radius: 3px; border: 1px solid var(--line); }
.legend-bar .ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend-bar .unit { font-size: 11.5px; color: var(--muted); }
.map-wrap { position: relative; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; min-height: 640px; background: var(--surface-2); }
.map { position: absolute; inset: 0; }
.map-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.map-readout {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; pointer-events: none;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 150px;
}
.map-readout:empty { display: none; }
.map-pick {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 600;
  background: var(--accent); color: var(--accent-ink); padding: 8px 8px 8px 14px; border-radius: var(--radius-sm); font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.map-pick .btn-ghost { color: var(--accent-ink); }
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-container.picking { cursor: crosshair; }
.wind-ico { pointer-events: none; }
.loc-marker { width: 22px; height: 22px; border-radius: 50%; background: var(--albero-strong); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--ink), 0 2px 6px rgba(0,0,0,.35); }
.leaflet-popup-content { font-size: 13px; }
.leaflet-control-attribution { font-size: 10.5px; }

/* ---------------- Informe ---------------- */
.report-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: var(--gap); align-items: start; }
.report-side { display: flex; flex-direction: column; gap: var(--gap); }
.report { padding: 22px 26px 26px; }
.report h2 { font-size: 22px; font-weight: 680; font-stretch: 110%; margin-bottom: 6px; }
.report h3 { font-size: 16.5px; margin: 22px 0 7px; display: flex; align-items: center; gap: 8px; }
.report p, .report li { font-size: 15px; line-height: 1.62; max-width: 78ch; color: var(--ink); }
.report p + p { margin-top: 8px; }
.report ul { margin: 6px 0 0; padding-left: 20px; }
.report li + li { margin-top: 4px; }
.report .lede { font-size: 16.5px; line-height: 1.55; color: var(--ink); border-left: 3px solid var(--albero-strong); padding: 2px 0 2px 14px; margin: 12px 0 4px; }
.report .meta { font-size: 12.5px; color: var(--muted); }
.report .caveat { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 16px; }
.prose h2 { margin-bottom: 10px; }
.prose h3 { margin: 18px 0 6px; }
.prose p, .prose li { font-size: 14px; line-height: 1.6; color: var(--ink); max-width: 80ch; }
.prose p + p { margin-top: 8px; }
.prose ul, .prose ol { padding-left: 20px; margin: 6px 0; }
.prose li + li { margin-top: 5px; }
.prose code { font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.refs li { font-size: 13px; overflow-wrap: anywhere; }

/* ---------------- Diálogos ---------------- */
dialog {
  border: 1px solid var(--line-2); border-radius: 12px; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 18px 50px rgba(9, 20, 33, .28);
}
dialog::backdrop { background: rgba(9, 20, 33, .45); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.dlg-wide { width: 100%; }
dialog:has(.dlg-wide) { width: min(1020px, calc(100vw - 32px)); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head .btn-icon { font-size: 22px; line-height: 1; }
.dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.dlg-body label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.dlg-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.dlg fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.dlg legend { font-weight: 640; font-size: 14px; padding: 0 4px; }
.dlg legend.sub { padding: 6px 0 0; font-size: 13.5px; }
.dlg-foot { display: flex; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); }
.radio { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--ink) !important; font-size: 13.5px !important; }
.check-list { display: flex; flex-direction: column; gap: 6px; }
.check-list label { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 13.5px; }
.check-list .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
.search-row { display: flex; gap: 8px; }
.loc-presets { display: flex; flex-direction: column; gap: 6px; }
.loc-presets button, .loc-results button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 12px; cursor: pointer;
}
.loc-presets button:hover, .loc-results button:hover { border-color: var(--accent); }
.loc-presets button[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.loc-presets b, .loc-results b { font-size: 14px; font-weight: 620; }
.loc-presets span, .loc-results span { font-size: 12.5px; color: var(--muted); }
.loc-results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.coord-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }

.print-only { display: none; }
.empty { color: var(--muted); font-size: 14px; padding: 18px 4px; }

/* ---------------- Pantalla de bienvenida ---------------- */
.splash {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 25%, #3a4a5e 0%, #1d2631 55%, #11171f 100%);
  transition: opacity .55s ease, visibility .55s ease;
}
.splash.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-card { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 24px; }
.splash-card img { width: 180px; height: 180px; border-radius: 22px; box-shadow: 0 0 0 2px rgba(255,255,255,.18), 0 18px 48px rgba(0,0,0,.5); object-fit: cover; }
.splash-name { font-size: 34px; font-weight: 780; font-stretch: 114%; color: #fff; letter-spacing: -0.01em; margin-top: 6px; }
.splash-sub { font-size: 14px; color: rgba(243,246,249,.75); }
.splash-bar { width: 220px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.14); overflow: hidden; margin-top: 8px; }
.splash-bar i { display: block; width: 40%; height: 100%; background: var(--brand-orange); border-radius: 2px; animation: splashbar 1.3s ease-in-out infinite; }
.splash-gate { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 14px; max-width: 300px; }
.splash-gate label { width: 100%; font-size: 13px; color: rgba(243,246,249,.75); }
.splash-gate input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; font: inherit; letter-spacing: .08em; }
.splash-gate button { padding: 9px 16px; border-radius: 8px; border: 0; background: var(--brand-orange); color: #fff; font: inherit; font-weight: 650; cursor: pointer; }
.splash-gate-err { width: 100%; margin: 0; font-size: 13px; color: #ff9b8a; }
@keyframes splashbar { 0% { transform: translateX(-110%); } 100% { transform: translateX(260%); } }

/* ---------------- Embalses ---------------- */
.res-controls { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.res-sel { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.res-sel select { height: 36px; min-width: 240px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); padding: 0 9px; font-size: 14px; color: var(--ink); }
.res-status { font-size: 13px; color: var(--muted); margin-top: -6px; }
.res-status.is-loading::before {
  content: ''; display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-radius: 50%;
  border: 2px solid var(--accent); border-right-color: transparent; vertical-align: -1px; animation: spin .8s linear infinite;
}
#resBody { display: flex; flex-direction: column; gap: var(--gap); }
.kpis-res { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpis-res > .kpi:nth-child(4n+1) { border-left: 1px solid var(--line); }
.kpis-res > .kpi:first-child { border-left: 0; }
.kpis-res > .kpi:nth-child(n+5) { border-top: 0; }
.res-fill { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: 2px; }
.res-fill i { display: block; height: 100%; border-radius: 4px; }
.res-fill-sm { display: inline-block; width: 70px; height: 7px; vertical-align: middle; margin: 0 8px 0 0; }
.tbl-res td.res-pct { white-space: nowrap; }
.tbl-res tfoot td { background: var(--surface-2); }
.res-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: stretch; }
.res-map-wrap { position: relative; height: 470px; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.res-map { position: absolute; inset: 0; }
.res-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; align-items: center; }
.res-legend span { display: inline-flex; align-items: center; gap: 5px; }
.res-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(11,42,68,.6); }
.res-sources { margin-top: -4px; }
#resSummary p + p { margin-top: 9px; }
.gauge-marker { width: 14px; height: 14px; transform: rotate(45deg); background: var(--brand-orange); border: 2px solid #fff; box-shadow: 0 0 0 1.5px #1d2631; }
.chart-national { height: 520px; }
.panel-tight { padding: 10px 18px; }
#ensFanNote { margin: 8px 0 0; }
.panel-tight .panel-head { margin-bottom: 0; }
.about-logo { width: 72px; height: 72px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,.25); }

/* ---------------- Adaptación a pantallas pequeñas ---------------- */
@media (max-width: 1280px) {
  .dlg-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis-res { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis-res > .kpi:nth-child(4n+1) { border-left: 1px solid var(--line); }
  .kpis-res > .kpi:nth-child(3n+1) { border-left: 0; }
  .kpis-res > .kpi:nth-child(n+4) { border-top: 1px solid var(--line); }
}
@media (max-width: 1100px) {
  .hero { grid-template-columns: 1fr; }
  .report-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .status { display: none; }
}
@media (max-width: 1100px) {
  .res-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis > .kpi:nth-child(4n+1) { border-left: 1px solid var(--line); }
  .kpis > .kpi:nth-child(2n+1) { border-left: 0; }
  .kpis > .kpi:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 920px) {
  :root { --rail-w: 0px; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; position: static; }
  .brand { width: auto; }
  .context { width: 100%; }
  .ctx-actions { margin-left: 0; }
  .layout { grid-template-columns: 1fr; }
  .rail {
    position: sticky; top: 0; height: auto; z-index: 25; padding: 6px 8px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .rail [role="tablist"] { flex-direction: row; gap: 4px; }
  .rail [role="tab"] { width: auto; white-space: nowrap; padding: 8px 11px; font-size: 13.5px; }
  .rail [role="tab"][aria-selected="true"]::before { left: 8px; right: 8px; top: auto; bottom: -6px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
  .rail-foot { display: none; }
  main { padding: 16px 16px 48px; }
  .map-shell { grid-template-columns: 1fr; }
  .map-wrap { min-height: 60vh; order: -1; }
  .dlg-cols { grid-template-columns: 1fr; }
  .sky-row { grid-template-columns: 44px repeat(var(--cols), minmax(0, 1fr)); }
  .sky-band .cells { left: 44px; }
  .sky-legend { padding-left: 44px; }
}
@media (max-width: 640px) {
  h1, .hero-title h1 { font-size: 24px; }
  .kpis, .kpis-res { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { border-left: 0 !important; border-top: 1px solid var(--line); }
  .kpi:nth-child(-n+2) { border-top: 0; }
  .kpi:nth-child(2n) { border-left: 1px solid var(--line) !important; }
  .brand-logo { width: 40px; height: 40px; }
  .kpi-v { font-size: 23px; }
  .verdict-big { font-size: 38px; }
  .ctx { flex: 1 1 140px; }
  .ctx-v { max-width: 200px; }
  .chart-meteo { height: 600px; }
  .sky { min-width: 760px; }
  .sky-band { height: 64px; }
  .coord-row { grid-template-columns: 1fr 1fr; }
  .coord-row .btn { grid-column: span 2; }
  .aemet-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------------- Impresión: informe PDF ---------------- */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .topbar, .rail, .banner, .seg, .chips, #btnCsv, .map-shell, #tab-modelos, #tab-ensembles, #tab-mapas, #tab-embalses, #tab-fuentes, .report-side, #aemetPanel, .splash { display: none !important; }
  .layout { display: block; }
  main { padding: 0; }
  .tab { display: flex !important; }
  #tab-dia, #tab-tendencias { display: flex !important; }
  #tab-tendencias { break-before: page; }
  .panel, .verdict, .kpis { border-color: #bbb; break-inside: avoid; }
  .chart-meteo { height: 560px; }
  .print-only { display: block; }
  .print-head { font-size: 9pt; color: #444; margin-bottom: 6mm; display: flex !important; align-items: center; gap: 10px; }
  .print-head img { border-radius: 6px; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
  .kpis > .kpi { border-left: 1px solid #ccc !important; border-top: 0 !important; padding: 8px 10px; }
  .kpis > .kpi:nth-child(4n+1) { border-left: 0 !important; }
  .kpis > .kpi:nth-child(n+5) { border-top: 1px solid #ccc !important; }
  .kpi-v { font-size: 19px; }
  .kpi-s, .kpi-k { font-size: 8pt; }
  .tbl { font-size: 8.5pt; }
  .tbl th { position: static; }
  a { color: #000; text-decoration: none; }
}
