/* ==========================================================================
   Embalses España — sistema visual técnico
   Papel y tinta, reglas de 1 px, sin radios ni sombras. Cifras en monoespaciada.
   ========================================================================== */

/* IBM Plex Sans (variable 400–700) e IBM Plex Mono (400, 600), subconjunto
   latino, alojadas en `fonts/` para no depender de Google Fonts. */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("fonts/ibm-plex-sans-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-600-latin.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;

  --paper: #f2f1ec;
  --paper-2: #e7e5dd;
  --paper-3: #dcd9cf;
  --ink: #111214;
  --ink-soft: #3b4045;
  --muted: #6b7076;
  --rule: #111214;
  --rule-soft: #c5c2b8;

  --accent: #123bb0;
  --accent-ink: #ffffff;

  --good: #0e6b3e;
  --good-soft: #dce9e0;
  --warn: #8a5300;
  --warn-soft: #f0e4cd;
  --bad: #a9241a;
  --bad-soft: #f2ddd9;
  --nodata: #7b8087;

  --map-bg: #dedbd2;
  --grid: rgba(17, 18, 20, .045);

  --header-h: 64px;
  --gutter: clamp(16px, 3vw, 36px);

  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", "Cascadia Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;

  --paper: #0d0e10;
  --paper-2: #16181b;
  --paper-3: #202328;
  --ink: #edede7;
  --ink-soft: #c2c4c1;
  --muted: #8f9499;
  --rule: #edede7;
  --rule-soft: #3a3d41;

  --accent: #8aa4ff;
  --accent-ink: #0d0e10;

  --good: #5fd39a;
  --good-soft: #14322a;
  --warn: #e6b455;
  --warn-soft: #33280f;
  --bad: #ff8578;
  --bad-soft: #3a1a16;
  --nodata: #8a8f95;

  --map-bg: #14161a;
  --grid: rgba(237, 237, 231, .035);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-font-smoothing: antialiased;
}

body.no-scroll {
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 2000;
  top: 8px;
  left: 8px;
  transform: translateY(-160%);
  padding: 10px 14px;
  border: 1px solid var(--rule);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

/* --- Cabecera ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 900;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.topbar-inner {
  width: min(1480px, 100%);
  min-height: var(--header-h);
  margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover {
  background: none;
  color: var(--ink);
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 1px solid var(--rule);
  background: var(--ink);
  color: var(--paper);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  line-height: 1.1;
}

.brand-text strong {
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-text small {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  min-width: 0;
}

.data-updated {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .56rem;
  letter-spacing: .05em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.data-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 270px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

.pulse {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  background: var(--good);
  animation: blink 1.6s steps(2, end) infinite;
}

@keyframes blink {
  50% { opacity: .2; }
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--ink);
  color: var(--paper);
}

.icon-moon {
  display: none;
}

[data-theme="dark"] .icon-sun {
  display: none;
}

[data-theme="dark"] .icon-moon {
  display: block;
}

main {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* --- Pestañas de sección ------------------------------------------------- */

.section-tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0 var(--gutter);
  border-bottom: 1px solid var(--rule);
}

.section-tab {
  padding: 13px 18px;
  border-right: 1px solid var(--rule-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}

.section-tab:first-child {
  border-left: 1px solid var(--rule-soft);
}

.section-tab:hover {
  background: var(--paper-2);
  color: var(--ink);
}

.section-tab.is-active {
  background: var(--ink);
  color: var(--paper);
}

.section-tab.is-disabled {
  color: var(--muted);
  cursor: default;
  opacity: .6;
}

.section-tab.is-disabled:hover {
  background: none;
  color: var(--muted);
}

.section-tab small {
  margin-left: 6px;
  color: inherit;
  font-size: .56rem;
  letter-spacing: .12em;
  opacity: .7;
}

/* --- Portada ------------------------------------------------------------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, .9fr);
  gap: clamp(24px, 4vw, 56px);
  align-items: end;
  padding: clamp(30px, 4.5vw, 56px) 0 clamp(26px, 3.5vw, 40px);
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  background: currentColor;
}

.hero h1 {
  margin: 0;
  max-width: 16ch;
  font-size: clamp(2.1rem, 4.4vw, 3.9rem);
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: .94;
  text-transform: uppercase;
}

.hero h1 span {
  color: var(--accent);
  white-space: nowrap;
}

.hero-sub {
  margin: 20px 0 24px;
  max-width: 60ch;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.55;
}

.hero-bar {
  position: relative;
  height: 12px;
  border: 1px solid var(--rule);
  background-color: var(--paper-2);
  background-image: repeating-linear-gradient(to right, transparent 0 calc(25% - 1px), var(--rule-soft) calc(25% - 1px) 25%);
  overflow: hidden;
}

.hero-bar > span:first-child {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width .8s cubic-bezier(.2, .8, .2, 1);
}

.hero-bar-marker {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: left .8s cubic-bezier(.2, .8, .2, 1), opacity .2s;
}

.hero-bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .08em;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--rule);
  background: var(--rule);
}

.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 118px;
  padding: 14px 16px;
  background: var(--paper);
}

.stat-label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: clamp(1.3rem, 2.1vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.35;
}

.stat-value.is-good { color: var(--good); }
.stat-value.is-bad { color: var(--bad); }

/* --- Explorador ---------------------------------------------------------- */

.workspace {
  display: grid;
  grid-template-columns: 384px minmax(0, 1fr);
  gap: 14px;
  height: clamp(560px, calc(100vh - 190px), 820px);
  margin-bottom: 40px;
}

.panel {
  border: 1px solid var(--rule);
  background: var(--paper);
  overflow: hidden;
}

.list-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.filters {
  padding: 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--rule-soft);
  background: var(--paper);
  color: var(--muted);
}

.search-field:focus-within {
  border-color: var(--ink);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.search-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: .85rem;
}

.search-field input::placeholder {
  color: var(--muted);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.select-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.select-field span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.select-field select {
  width: 100%;
  height: 32px;
  padding: 0 22px 0 7px;
  border: 1px solid var(--rule-soft);
  border-radius: 0;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7076' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  color: var(--ink);
  font-size: .74rem;
  cursor: pointer;
  appearance: none;
}

.select-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.list-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--rule-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.text-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-button:hover {
  background: none;
  color: var(--ink);
}

.reservoir-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-soft) transparent;
}

.reservoir-list::-webkit-scrollbar {
  width: 10px;
}

.reservoir-list::-webkit-scrollbar-thumb {
  background: var(--rule-soft);
  border: 2px solid var(--paper);
}

.reservoir-item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--rule-soft);
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.reservoir-item:hover {
  background: var(--paper-2);
}

.reservoir-item.is-selected {
  border-left-color: var(--accent);
  background: var(--paper-2);
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--c, var(--nodata));
}

.item-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.item-name {
  overflow: hidden;
  color: var(--ink);
  font-size: .84rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-sub {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .02em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.mini-bar {
  width: 100%;
  height: 3px;
  margin-top: 4px;
  background: var(--paper-3);
  overflow: hidden;
}

.mini-bar span {
  display: block;
  height: 100%;
  background: var(--c, var(--accent));
}

.item-value {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding-left: 6px;
  font-variant-numeric: tabular-nums;
}

.item-value strong {
  font-family: var(--mono);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: -.03em;
}

.item-value small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .6rem;
  white-space: nowrap;
}

.loading-row,
.empty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 180px;
  padding: 24px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  text-align: center;
}

.spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 2px solid var(--rule-soft);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Mapa ---------------------------------------------------------------- */

.map-panel {
  position: relative;
  min-height: 0;
  background: var(--map-bg);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.map-topbar {
  position: absolute;
  z-index: 500;
  top: 10px;
  left: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}

.chip:hover {
  background: var(--ink);
  color: var(--paper);
}

.map-legend {
  position: absolute;
  z-index: 500;
  left: 10px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 216px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .02em;
}

.map-legend strong {
  margin-bottom: 2px;
  color: var(--ink);
  font-size: .58rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.map-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.map-legend small {
  margin-top: 4px;
  color: var(--muted);
  font-size: .58rem;
  line-height: 1.4;
}

.swatch {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
}

.swatch-bad { background: var(--bad); }
.swatch-warn { background: var(--warn); }
.swatch-good { background: var(--good); }

.map-loading {
  position: absolute;
  z-index: 400;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--map-bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  pointer-events: none;
  transition: opacity .25s;
}

.map-loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.leaflet-container {
  background: var(--map-bg);
  font-family: var(--font);
}

.leaflet-tile-pane {
  transition: filter .25s ease;
}

[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(.72) saturate(.5) contrast(.9);
}

.leaflet-control-attribution {
  background: var(--paper) !important;
  color: var(--muted) !important;
  font-family: var(--mono) !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.leaflet-bar {
  border: 1px solid var(--rule) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  overflow: hidden;
}

.leaflet-bar a {
  background: var(--paper) !important;
  color: var(--ink) !important;
  border-bottom-color: var(--rule-soft) !important;
  border-radius: 0 !important;
}

.leaflet-bar a:hover {
  background: var(--ink) !important;
  color: var(--paper) !important;
}

.leaflet-tooltip {
  padding: 6px 9px;
  border: 1px solid var(--rule) !important;
  border-radius: 0 !important;
  background: var(--paper) !important;
  color: var(--ink) !important;
  box-shadow: none !important;
  font-family: var(--mono);
  font-size: .66rem;
}

.leaflet-tooltip::before {
  display: none;
}

.leaflet-tooltip strong {
  display: block;
  font-size: .68rem;
}

.leaflet-tooltip span {
  color: var(--muted);
}

.community-tooltip {
  text-align: center;
}

/* --- Sobre el proyecto --------------------------------------------------- */

.about {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
  padding: 26px 0 34px;
}

.about > div {
  padding-top: 12px;
  border-top: 2px solid var(--ink);
}

.about h2 {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.about p {
  margin: 0;
  color: var(--ink-soft);
  font-size: .8rem;
  line-height: 1.6;
}

.footer {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px var(--gutter) 34px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.55;
}

.footer p {
  margin: 0 0 5px;
}

.footer-small {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .02em;
}

/* --- Ficha lateral ------------------------------------------------------- */

.backdrop {
  position: fixed;
  z-index: 1000;
  inset: 0;
  background: rgba(10, 11, 12, .5);
  opacity: 0;
  transition: opacity .2s ease;
}

.backdrop.is-open {
  opacity: 1;
}

.detail {
  position: fixed;
  z-index: 1100;
  top: 0;
  right: 0;
  width: min(430px, 100%);
  height: 100%;
  padding: 22px;
  border-left: 1px solid var(--rule);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), visibility .25s;
}

.detail.is-open {
  transform: translateX(0);
  visibility: visible;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--ink);
}

.detail-head h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.05;
  text-transform: uppercase;
}

.detail-location {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .04em;
  line-height: 1.5;
  text-transform: uppercase;
}

.detail-level {
  padding: 16px;
  border: 1px solid var(--rule);
}

.detail-level-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-level-value strong {
  font-family: var(--mono);
  font-size: 2.6rem;
  font-weight: 600;
  letter-spacing: -.06em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.status-pill {
  padding: 3px 7px;
  border: 1px solid var(--rule-soft);
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: .56rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-pill.is-good { border-color: var(--good); color: var(--good); }
.status-pill.is-warn { border-color: var(--warn); color: var(--warn); }
.status-pill.is-bad { border-color: var(--bad); color: var(--bad); }

.progress {
  height: 8px;
  background: var(--paper-3);
  overflow: hidden;
}

.progress > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--ink);
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}

.progress-large {
  height: 12px;
  border: 1px solid var(--rule);
  background: var(--paper-2);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--rule-soft);
  border-left: 1px solid var(--rule-soft);
}

.detail-grid > div {
  padding: 10px 12px;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
}

.detail-grid dt {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .56rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 5px 0 0;
  font-size: .84rem;
  font-weight: 700;
  line-height: 1.35;
}

.detail-note {
  margin: 0;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.55;
}

.source-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: auto;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rule);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-decoration: none;
}

.source-link:hover {
  background: var(--accent);
  color: var(--accent-ink);
}

.noscript {
  margin: 20px;
  padding: 16px;
  border: 1px solid var(--rule);
  background: var(--paper);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Estadísticas -------------------------------------------------------- */

.stats-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr);
  gap: clamp(20px, 4vw, 48px);
  align-items: start;
  padding: clamp(26px, 4vw, 46px) 0 clamp(20px, 3vw, 32px);
}

.stats-hero h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -.025em;
  line-height: .95;
  text-transform: uppercase;
}

.stats-sub {
  margin: 16px 0 0;
  max-width: 60ch;
  color: var(--ink-soft);
  font-size: .95rem;
  line-height: 1.6;
}

.stats-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border: 1px solid var(--rule);
  background: var(--rule);
}

.stats-kpis .stat-card {
  min-height: 104px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 14px;
  margin-bottom: 30px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--rule);
  background: var(--paper);
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-head {
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-soft);
}

.chart-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.chart-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.45;
}

.chart-foot {
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--rule-soft);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  line-height: 1.5;
}

/* Distribución por nivel */

.band-chart {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
  min-height: 216px;
}

.band-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.band-count {
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.band-track {
  display: flex;
  align-items: flex-end;
  width: 100%;
  max-width: 58px;
  height: 152px;
  border: 1px solid var(--rule-soft);
  background-color: var(--paper-2);
  background-image: repeating-linear-gradient(to top, transparent 0 calc(25% - 1px), var(--rule-soft) calc(25% - 1px) 25%);
  overflow: hidden;
}

.band-fill {
  display: block;
  width: 100%;
  min-height: 2px;
  background: var(--ink);
  transition: height .5s cubic-bezier(.2, .8, .2, 1);
}

.band-fill.is-bad { background: var(--bad); }
.band-fill.is-warn { background: var(--warn); }
.band-fill.is-good { background: var(--good); }
.band-fill.is-none { background: var(--nodata); }

.band-label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Barras horizontales */

.hbar-chart {
  display: grid;
  gap: 12px;
}

@media (min-width: 1200px) {
  .hbar-chart {
    grid-template-columns: 1fr 1fr;
    column-gap: 28px;
  }
}

.hbar {
  min-width: 0;
}

.hbar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: .78rem;
  font-weight: 700;
}

.hbar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hbar-value {
  color: var(--ink);
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hbar-track {
  height: 8px;
  margin: 5px 0 4px;
  background: var(--paper-3);
  overflow: hidden;
}

.hbar-fill {
  display: block;
  height: 100%;
  background: var(--ink);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}

.hbar-fill.is-bad { background: var(--bad); }
.hbar-fill.is-warn { background: var(--warn); }
.hbar-fill.is-good { background: var(--good); }

.hbar-meta,
.cap-meta {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mayores embalses */

.cap-chart {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 28px;
}

.cap-row {
  min-width: 0;
}

.cap-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: .78rem;
  font-weight: 700;
}

.cap-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cap-pct {
  color: var(--ink);
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cap-track {
  height: 10px;
  margin: 5px 0 4px;
  background: var(--paper-3);
  overflow: hidden;
}

.cap-fill {
  display: block;
  height: 100%;
  background: var(--ink);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}

.cap-fill.is-bad { background: var(--bad); }
.cap-fill.is-warn { background: var(--warn); }
.cap-fill.is-good { background: var(--good); }

/* Variación semanal */

.change-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.change-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule-soft);
}

.change-row:last-child {
  border-bottom: 0;
}

.change-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.change-name {
  overflow: hidden;
  font-size: .78rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.change-sub {
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .02em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.change-value {
  font-family: var(--mono);
  font-size: .76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.change-row.is-up .change-value { color: var(--good); }
.change-row.is-down .change-value { color: var(--bad); }

.change-empty {
  padding: 18px 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .68rem;
  text-transform: uppercase;
  text-align: center;
}

/* Evolución histórica (reservado) */

.placeholder-card p {
  margin: 0;
  max-width: 76ch;
  color: var(--ink-soft);
  font-size: .8rem;
  line-height: 1.6;
}

.placeholder-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 92px;
  border-bottom: 1px solid var(--rule);
}

.placeholder-chart span {
  flex: 1;
  border: 1px solid var(--rule-soft);
  border-bottom: 0;
  background-image: repeating-linear-gradient(45deg, transparent 0 6px, var(--rule-soft) 6px 7px);
}

.stats-source {
  margin: 0 0 30px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .62rem;
  line-height: 1.6;
}

/* --- Adaptación ---------------------------------------------------------- */

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 336px minmax(0, 1fr);
  }

  .hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .hero-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stats-hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .stats-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  :root {
    --header-h: 58px;
  }

  .brand-text small {
    display: none;
  }

  .data-badge {
    max-width: 160px;
  }

  .data-updated {
    font-size: .54rem;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    gap: 12px;
  }

  .map-panel {
    order: 1;
    height: 52vh;
    min-height: 360px;
  }

  .list-panel {
    order: 2;
    max-height: 70vh;
  }

  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .about {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cap-chart {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar-inner {
    padding: 8px 14px;
    gap: 10px;
  }

  .brand-icon {
    width: 36px;
    height: 36px;
  }

  .brand {
    gap: 8px;
  }

  .brand-icon svg {
    width: 26px;
    height: 26px;
  }

  .brand-text strong {
    font-size: .72rem;
    letter-spacing: 0;
  }

  .data-badge {
    max-width: 150px;
    padding: 6px 7px;
    font-size: .52rem;
  }

  .data-updated {
    font-size: .48rem;
    letter-spacing: .02em;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  main {
    padding: 0 14px;
  }

  .section-tabs {
    margin: 0 -14px;
    padding: 0 14px;
    overflow-x: auto;
  }

  .section-tab {
    padding: 11px 12px;
    font-size: .6rem;
  }

  .section-tab.is-disabled small {
    display: none;
  }

  .hero {
    padding-top: 26px;
  }

  .hero h1 {
    max-width: none;
    font-size: clamp(1.8rem, 9.6vw, 2.5rem);
  }

  .hero-sub {
    margin: 14px 0 18px;
    font-size: .9rem;
  }

  .filter-row {
    grid-template-columns: 1fr 1fr;
  }

  .filter-row .select-field:last-child {
    grid-column: 1 / -1;
  }

  .detail {
    top: auto;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 88vh;
    border-left: 0;
    border-top: 2px solid var(--ink);
    padding: 18px 16px 26px;
    transform: translateY(105%);
  }

  .detail.is-open {
    transform: translateY(0);
  }

  .detail-level-value strong {
    font-size: 2.2rem;
  }

  .map-legend {
    left: 8px;
    bottom: 12px;
    padding: 8px 10px;
  }

  .map-legend small {
    display: none;
  }

  .about {
    padding-top: 20px;
  }

  .stats-hero {
    padding-top: 24px;
  }

  .chart-card {
    padding: 14px;
    gap: 14px;
  }

  .band-chart {
    gap: 6px;
    min-height: 190px;
  }

  .band-track {
    height: 126px;
  }

  .band-label {
    font-size: .52rem;
  }

  .band-count {
    font-size: .68rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* --- Histórico ----------------------------------------------------------- */

.chart-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid var(--rule);
}

.range-button {
  padding: 7px 10px;
  border: 0;
  border-right: 1px solid var(--rule-soft);
  background: var(--paper);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
}

.range-button:last-child {
  border-right: 0;
}

.range-button:hover {
  background: var(--paper-2);
  color: var(--ink);
}

.range-button.is-active {
  background: var(--ink);
  color: var(--paper);
}

.history-readout {
  min-height: 18px;
  margin: 0;
  color: var(--ink);
  font-family: var(--mono);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.history-chart {
  position: relative;
  min-width: 0;
}

.history-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid {
  stroke: var(--rule-soft);
  stroke-width: 1;
}

.chart-axis {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .04em;
}

.chart-note {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .03em;
}

.chart-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line-muted {
  stroke: var(--rule-soft);
  stroke-width: 1.4;
}

.chart-line.chart-current {
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-area {
  fill: var(--paper-2);
  opacity: .8;
}

.chart-dot {
  fill: var(--accent);
}

.chart-cross {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-rule {
  stroke: var(--rule-soft);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.chart-band-outer {
  fill: var(--paper-3);
  opacity: .55;
}

.chart-band-inner {
  fill: var(--rule-soft);
  opacity: .7;
}

.chart-bar {
  fill: var(--ink);
}

.chart-bar.is-muted {
  fill: var(--paper-3);
}

.chart-bar.is-current {
  fill: var(--accent);
}

.chart-avg {
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.history-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.history-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-band {
  width: 18px;
  height: 8px;
  background: var(--rule-soft);
  opacity: .7;
}

.legend-line {
  width: 18px;
  height: 2px;
  background: var(--ink);
}

.legend-current {
  width: 18px;
  height: 2px;
  background: var(--accent);
}

.history-table {
  display: grid;
  gap: 0;
}

.history-teaser {
  max-width: 72ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: .85rem;
  line-height: 1.6;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.3fr) minmax(140px, 2.6fr) 60px 60px 48px;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: .74rem;
}

.history-row:last-child {
  border-bottom: 0;
}

.history-row-head {
  padding-top: 0;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--mono);
  font-size: .56rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.history-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-track {
  position: relative;
  height: 8px;
  background: var(--paper-3);
}

.history-fill {
  display: block;
  height: 100%;
  background: var(--ink);
}

.history-average {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 1px;
  background: var(--accent);
}

.history-value,
.history-average-value,
.history-delta {
  font-family: var(--mono);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.history-average-value {
  color: var(--muted);
}

.history-delta.is-up {
  color: var(--good);
}

.history-delta.is-down {
  color: var(--bad);
}

.history-select-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.history-select {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: min(360px, 100%);
}

.history-select span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.history-select select {
  width: 100%;
  height: 36px;
  padding: 0 24px 0 9px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7076' stroke-width='1.4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  color: var(--ink);
  font-size: .78rem;
  cursor: pointer;
  appearance: none;
}

@media (max-width: 820px) {
  .history-row {
    grid-template-columns: minmax(96px, 1.3fr) minmax(60px, 1.6fr) 52px 52px 42px;
    gap: 7px;
  }

  .history-value,
  .history-average-value,
  .history-delta {
    font-size: .62rem;
  }
}

@media (max-width: 560px) {
  .chart-head-row {
    flex-direction: column;
  }

  .history-row {
    grid-template-columns: minmax(80px, 1.2fr) minmax(56px, 1.4fr) 50px 42px;
  }

  .history-row > :nth-child(4),
  .history-row-head > :nth-child(4) {
    display: none;
  }

  .history-legend {
    gap: 8px 12px;
    font-size: .54rem;
  }

  .history-select-row {
    align-items: stretch;
    flex-direction: column;
  }

  .history-select {
    width: 100%;
  }
}
