/* Estilo inspirado en las tarjetas de Nomad List (levelsio) sin copiarlo: tarjetas oscuras donde el
   agua sube hasta el % lleno del embalse. Fuente del sistema: no se descarga nada. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #e2e7ee;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --card: #0f1b2d;
  --card-text: #ffffff;
  /* estado del embalse: lleno, normal, bajo, muy bajo, sin dato */
  --s-full: #2563eb;
  --s-good: #0d9488;
  --s-low: #d97706;
  --s-verylow: #dc2626;
  --s-na: #475569;
  --s-full-soft: #dbeafe;
  --s-good-soft: #ccfbf1;
  --s-low-soft: #fef3c7;
  --s-verylow-soft: #fee2e2;
  --s-na-soft: #e2e8f0;
  --s-full-ink: #1e3a8a;
  --s-good-ink: #134e4a;
  --s-low-ink: #78350f;
  --s-verylow-ink: #7f1d1d;
  --s-na-ink: #334155;
  --good: #16a34a;
  --bad: #dc2626;
  --mid: #d97706;
  --radius: 18px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #070b13;
    --surface: #0f1623;
    --surface-2: #162032;
    --border: #22304a;
    --text: #e8eef7;
    --muted: #93a3b8;
    --accent: #38bdf8;
    --card: #111c30;
    --s-full-soft: #172554;
    --s-good-soft: #0f2f2c;
    --s-low-soft: #33240b;
    --s-verylow-soft: #3a1414;
    --s-na-soft: #1e293b;
    --s-full-ink: #bfdbfe;
    --s-good-ink: #99f6e4;
    --s-low-ink: #fde68a;
    --s-verylow-ink: #fecaca;
    --s-na-ink: #cbd5e1;
    --good: #4ade80;
    --bad: #f87171;
    --mid: #fbbf24;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #070b13;
  --surface: #0f1623;
  --surface-2: #162032;
  --border: #22304a;
  --text: #e8eef7;
  --muted: #93a3b8;
  --accent: #38bdf8;
  --card: #111c30;
  --s-full-soft: #172554;
  --s-good-soft: #0f2f2c;
  --s-low-soft: #33240b;
  --s-verylow-soft: #3a1414;
  --s-na-soft: #1e293b;
  --s-full-ink: #bfdbfe;
  --s-good-ink: #99f6e4;
  --s-low-ink: #fde68a;
  --s-verylow-ink: #fecaca;
  --s-na-ink: #cbd5e1;
  --good: #4ade80;
  --bad: #f87171;
  --mid: #fbbf24;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.55; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); font-weight: 800; margin: 0 0 0.5rem; }
h2 { font-size: 1.35rem; font-weight: 750; margin: 2rem 0 0.75rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main { max-width: 1240px; margin: 0 auto; padding: 0 16px 48px; }
small { font-size: 0.75em; }

/* --- Cabecera y pie --- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark svg { width: 22px; height: 22px; fill: #38bdf8; display: block; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.topbar nav a { color: var(--muted); font-weight: 600; font-size: 0.92rem; padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.i-sun { display: none; }
:root[data-theme='dark'] .i-sun { display: block; }
:root[data-theme='dark'] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .i-sun { display: block; }
  :root:not([data-theme='light']) .i-moon { display: none; }
}
.footer { max-width: 1240px; margin: 0 auto; padding: 24px 16px 40px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); }
.footer p { margin: 0.3rem 0; }

/* --- Cabecera de página --- */
.hero { padding: 28px 0 8px; }
.lede { font-size: 1.08rem; color: var(--muted); max-width: 760px; margin: 0 0 0.75rem; }
.lede strong { color: var(--text); }
.updated { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.88rem; margin: 0.25rem 0 1rem; }
.updated.stale { color: var(--bad); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 25%, transparent); flex: none; }
.crumbs { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--muted); padding-top: 18px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 0.75rem 0 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 1.45rem; font-weight: 800; }
.tile-value small { color: var(--muted); font-weight: 600; }
.tile-note { font-size: 0.78rem; color: var(--muted); }
.tile.s-full .tile-value { color: var(--s-full); }
.tile.s-good .tile-value { color: var(--s-good); }
.tile.s-low .tile-value { color: var(--s-low); }
.tile.s-verylow .tile-value { color: var(--s-verylow); }
.tile.good .tile-value { color: var(--good); }
.tile.mid .tile-value { color: var(--mid); }
.tile.bad .tile-value { color: var(--bad); }

/* --- Barra de filtros --- */
.toolbar { position: sticky; top: 57px; z-index: 10; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 0; background: var(--bg); }
.search input { width: 220px; max-width: 100%; height: 38px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 0 16px; font: inherit; }
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 0.86rem; font-weight: 600; cursor: pointer; display: inline-block; }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.rank-links { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* --- Tarjetas --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin: 8px 0 24px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.lake-card { position: relative; display: block; aspect-ratio: 1 / 1; border-radius: var(--radius); overflow: hidden; background: var(--card); color: var(--card-text); isolation: isolate; transition: transform 0.15s ease; }
.lake-card:hover { transform: translateY(-2px); }
.lake-card .card-link { position: absolute; inset: 0; color: inherit; }
.lake-card .card-link:hover { text-decoration: none; }
.lake-card .water { position: absolute; left: 0; right: 0; bottom: 0; background: var(--s-na); z-index: -1; transition: height 0.6s ease; }
.lake-card .wave, .tank .wave { position: absolute; left: 0; top: -9px; width: 100%; height: 10px; display: block; }
.lake-card .wave path, .tank .wave path { fill: var(--s-na); }
.s-na .water { background: var(--s-na); }
.s-full .water, .s-full .wave path { background: var(--s-full); fill: var(--s-full); }
.s-good .water, .s-good .wave path { background: var(--s-good); fill: var(--s-good); }
.s-low .water, .s-low .wave path { background: var(--s-low); fill: var(--s-low); }
.s-verylow .water, .s-verylow .wave path { background: var(--s-verylow); fill: var(--s-verylow); }
/* Silueta del lago (USGS NHD) detrás del texto, como la foto de fondo de una tarjeta de Nomad List */
.lake-card .shape { position: absolute; inset: 14% 10% 22%; width: 80%; height: 64%; object-fit: contain; pointer-events: none; }
.lake-card .face { position: absolute; inset: 0; padding: 14px 16px; display: flex; flex-direction: column; text-shadow: 0 1px 3px rgb(0 0 0 / 0.45); }
.lake-card .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.lake-card .top { font-size: 0.85rem; font-weight: 700; flex-wrap: wrap; }
.lake-card .rank { border-bottom: 2px solid currentColor; min-width: 1.4em; }
.lake-card .top .trend { margin-left: auto; }
.lake-card .trend-label { width: 100%; text-align: right; margin-top: -6px; opacity: 0.85; font-weight: 600; }
.lake-card .mid { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.lake-name { font-size: 1.35rem; font-weight: 800; margin: 0; line-height: 1.15; }
.lake-card .mid p { margin: 2px 0 0; font-size: 0.82rem; opacity: 0.9; font-weight: 600; }
.lake-card .bottom { align-items: flex-end; }
.small-stat { font-weight: 700; font-size: 0.95rem; display: flex; flex-direction: column; }
.big-stat { font-weight: 800; font-size: 1.6rem; line-height: 1; display: flex; flex-direction: column; align-items: flex-end; }
.lake-card small { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.9; }
.lake-card .back { background: rgb(8 13 24 / 0.94); opacity: 0; justify-content: center; gap: 10px; transition: opacity 0.15s ease; text-shadow: none; }
@media (hover: hover) {
  .lake-card:hover .back, .lake-card .card-link:focus-visible .back { opacity: 1; }
}
/* En pantallas táctiles no hay hover: el botón ⓘ da la vuelta a la tarjeta (app.js pone .flipped) */
.lake-card.flipped .back { opacity: 1; justify-content: flex-start; padding: 40px 12px 8px; gap: 4px; }
.lake-card.flipped .bar-row { grid-template-columns: 54px 1fr 34px; gap: 6px; font-size: 0.74rem; }
.lake-card.flipped .back-note { font-size: 0.72rem; }
.card-info { display: none; position: absolute; left: 44px; top: 11px; z-index: 2; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid rgb(255 255 255 / 0.7); background: rgb(8 13 24 / 0.45); color: #fff; font: italic 700 0.95rem/1 Georgia, serif; cursor: pointer; padding: 0; }
.lake-card.flipped .card-info { font: 700 1rem/1 system-ui, sans-serif; font-style: normal; background: rgb(255 255 255 / 0.15); }
@media (hover: none) {
  .card-info { display: block; }
}
.bar-row { display: grid; grid-template-columns: 70px 1fr 46px; align-items: center; gap: 8px; font-size: 0.82rem; font-weight: 600; }
.bar-row b { text-align: right; }
.bar { height: 12px; border-radius: 6px; background: #2a3550; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; }
.bar i.good { background: #22c55e; }
.bar i.mid { background: #f59e0b; }
.bar i.bad { background: #ef4444; }
.bar i.info { background: #38bdf8; }
.bar i.na { background: #64748b; }
.back-note { margin: 4px 0 0; font-size: 0.78rem; color: #cbd5e1; }
.lake-card.stale::after { content: 'Outdated'; position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #000a; padding: 2px 8px; border-radius: 999px; font-size: 0.7rem; }
.empty-msg { color: var(--muted); }
.trend.up { color: inherit; }
.trend.down { color: inherit; }

/* --- Página de embalse --- */
.lake-hero { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; padding: 20px 0 8px; }
.tank { position: relative; height: 300px; border-radius: 26px; background: var(--card); overflow: hidden; isolation: isolate; border: 4px solid var(--border); }
.tank .water { position: absolute; left: 0; right: 0; bottom: 0; z-index: -1; }
.tank-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-shadow: 0 1px 4px rgb(0 0 0 / 0.5); }
.tank-label b { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.tank-label span { text-transform: uppercase; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.08em; }
.shape-gauge { margin: 0; position: relative; background: var(--card); border-radius: 26px; padding: 18px; border: 4px solid var(--border); }
.shape-gauge svg { width: 100%; height: auto; max-height: 300px; display: block; }
.shape-gauge .shape-empty { fill: #22304a; }
.shape-gauge .shape-water { fill: var(--s-na); }
.s-full .shape-water { fill: var(--s-full); }
.s-good .shape-water { fill: var(--s-good); }
.s-low .shape-water { fill: var(--s-low); }
.s-verylow .shape-water { fill: var(--s-verylow); }
.shape-gauge .shape-line { stroke: #dbe4f0; stroke-width: 1.2; stroke-opacity: 0.7; }
.shape-gauge .tank-label { position: static; margin-top: 10px; color: #fff; }
.shape-gauge figcaption { font-size: 0.7rem; color: #93a3b8; text-align: center; margin-top: 6px; }
.sat-grid { display: grid; gap: 12px; }
.sat-grid.two { grid-template-columns: 1fr 1fr; }
.sat-fig { margin: 0; }
.sat-fig img { width: 100%; height: auto; display: block; border-radius: 12px; background: var(--surface-2); }
.sat-fig figcaption { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.sat-fig figcaption b { color: var(--text); margin-right: 4px; }
.credit { font-size: 0.75rem; color: var(--muted); margin: 10px 0 0; }
.badge-line { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 0.5rem; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 0.82rem; font-weight: 700; }
.badge.status, .pill { border-radius: 999px; padding: 3px 10px; font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.pill.s-full, .badge.s-full { background: var(--s-full-soft); color: var(--s-full-ink); }
.pill.s-good, .badge.s-good { background: var(--s-good-soft); color: var(--s-good-ink); }
.pill.s-low, .badge.s-low { background: var(--s-low-soft); color: var(--s-low-ink); }
.pill.s-verylow, .badge.s-verylow { background: var(--s-verylow-soft); color: var(--s-verylow-ink); }
.pill.s-na { background: var(--s-na-soft); color: var(--s-na-ink); }
.lake-hero .tiles .trend.up { color: var(--good); }
.lake-hero .tiles .trend.down { color: var(--bad); }
.lake-table .trend.up { color: var(--good); }
.lake-table .trend.down { color: var(--bad); }
.source-line { font-size: 0.82rem; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 16px 0; }
.card h2 { margin-top: 0; font-size: 1.15rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col .card { margin: 0; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; font-weight: 750; font-size: 1.05rem; display: flex; flex-direction: column; }
.facts dd small { color: var(--muted); font-weight: 500; font-size: 0.8rem; }

.chart-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.85rem; font-weight: 700; padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .gridline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 12px; font-family: var(--font); }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; }
.chart .band { fill: color-mix(in srgb, var(--s-good) 18%, transparent); stroke: none; }
.chart .normal { fill: none; stroke: var(--s-good); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .fullline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .last { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-legend { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin: 6px 0 0; }
.key { display: inline-block; width: 18px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.key.series { background: var(--accent); height: 3px; }
.key.band { background: color-mix(in srgb, var(--s-good) 25%, transparent); }
.key.normal { border-top: 2px dashed var(--s-good); height: 0; }

/* --- Tablas --- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.sortable th { cursor: pointer; user-select: none; }
.sortable th.asc::after { content: ' ▲'; }
.sortable th.desc::after { content: ' ▼'; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
.month-table td, .month-table th { text-align: center; padding: 7px 6px; font-size: 0.85rem; }
.month-table td.s-full { background: var(--s-full-soft); color: var(--s-full-ink); }
.month-table td.s-good { background: var(--s-good-soft); color: var(--s-good-ink); }
.month-table td.s-low { background: var(--s-low-soft); color: var(--s-low-ink); }
.month-table td.s-verylow { background: var(--s-verylow-soft); color: var(--s-verylow-ink); }
.month-table td.na { color: var(--muted); }
.tag { font-size: 0.72rem; background: var(--s-verylow-soft); color: var(--s-verylow-ink); padding: 1px 6px; border-radius: 999px; font-weight: 700; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }

.map { height: 420px; border-radius: var(--radius); border: 1px solid var(--border); margin: 8px 0; z-index: 0; }
.legend { font-size: 0.85rem; color: var(--muted); display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 2px; }
.dot.s-full { background: var(--s-full); }
.dot.s-good { background: var(--s-good); }
.dot.s-low { background: var(--s-low); }
.dot.s-verylow { background: var(--s-verylow); }

/* --- Texto --- */
.prose { max-width: 760px; }
.prose p, .prose li { color: var(--text); }
.page { padding-top: 24px; }
.faq-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin: 8px 0; }
.faq-item h3 { font-size: 1rem; margin: 0; }
.faq p { margin: 6px 0 0; color: var(--muted); }

@media (max-width: 760px) {
  /* Menú en una segunda fila a lo ancho (desliza en horizontal); logo y tema arriba */
  .topbar { flex-wrap: wrap; gap: 4px 12px; padding: 8px 16px 6px; }
  .logo { flex: 1; min-width: 0; }
  .topbar nav { order: 3; flex: 1 0 100%; margin: 0 -10px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile-value { font-size: 1.25rem; }
  .lake-hero { grid-template-columns: 1fr; }
  .tank { height: 180px; max-width: 360px; }
  .shape-gauge { max-width: 360px; }
  .shape-gauge svg { max-height: 220px; }
  .sat-grid.two { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .toolbar { top: 89px; } /* alto de la cabecera en dos filas */
  .search input { width: 100%; }
  .search { flex: 1 1 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .lake-name { font-size: 1.1rem; }
  .big-stat { font-size: 1.3rem; }
  .facts { grid-template-columns: 1fr; }
}
