/*
 * Tema único: tarjeta blanca rota #f1f0ea sobre mapa gris, texto casi negro, titulares en grotesca
 * muy apretada (Inter Tight) y etiquetas en mono mayúsculas (IBM Plex Mono).
 */
:root {
  color-scheme: light;
  /* Superficies de la tarjeta. */
  --paper: #f1f0ea;
  --ivory: #e8e7e0;
  --beige: #e2e1d9;
  --sheet: #f1f0ea;
  --surface: #faf9f5;
  /* Canales RGB para tintes (hover, bordes) y superficies translúcidas (campos, tarjetas). */
  --surface-rgb: 250, 249, 245;
  --tint-rgb: 17, 17, 17;
  --glass: rgba(241, 240, 234, 0.8);
  --glass-strong: rgba(241, 240, 234, 0.94);
  /* Mapa en grises. */
  --map-filter: grayscale(1) brightness(0.96);
  --map-sea: #c7c7c7;
  --map-vignette: rgba(199, 199, 199, 0.5);
  --labels-filter: none;
  --labels-opacity: 0.75;
  /* Estaciones del mapa: con datos y sin datos (mismos tonos en map.js). */
  --station: #a05ddc;
  --station-idle: #9a9a9a;
  /* Texto y neutros. */
  --ink: #111111;
  --ink-soft: #3a3a36;
  --muted: #6a6962;
  --grey: #8a8982;
  --stone: #d9d8d0;
  --line: rgba(17, 17, 17, 0.1);
  --line-strong: rgba(17, 17, 17, 0.18);
  --border: rgba(17, 17, 17, 0.1);
  /* Acción principal: negro sobre la tarjeta clara. */
  --primary: #111111;
  --primary-hover: #000;
  --on-primary: #fff;
  /* Acento morado para enlaces, foco y detalles; -ink es la versión de texto, más oscura para leerse sobre blanco. */
  --accent: #a05ddc;
  --accent-strong: #8f4bcc;
  --accent-ink: #7a3bb5;
  --accent-soft: rgba(160, 93, 220, 0.12);
  --on-accent: #fff;
  /* Datos: rojo para lo cálido, azul para lo fresco, turquesa para la lluvia. -ink es la versión de texto. */
  --warm: #f7394b;
  --warm-ink: #d41f33;
  --warm-soft: rgba(247, 57, 75, 0.12);
  --cool: #029dff;
  --cool-ink: #006bb8;
  --cool-soft: rgba(2, 157, 255, 0.12);
  --rain: #05e1cf;
  --rain-ink: #00796f;
  /* Módulo de donación y botón «0,75 €». */
  --kofi-bg: #fff3e6;
  --kofi-bg-hover: #ffe7cc;
  --kofi-ink: #b85208;
  --kofi-icon: #e8711a;
  /* Las sombras de algunos elementos se multiplican por este factor. */
  --shadow-strength: 1;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
  --radius: 18px;
  --radius-small: 12px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Inter Tight", "Inter", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --gap: 16px;
  --topbar-height: 64px;
}

/*
 * Tipografía. Con :root delante para ganar a las reglas de cada componente, que fijan su propio peso y espaciado.
 * Titulares: grotesca grande, pesada y con el espaciado muy cerrado.
 */
:root .welcome-head h1,
:root .panel-header h2,
:root .share-header h2,
:root .donate h3,
:root #donate-title {
  font-weight: 600;
  line-height: 0.95;
}

:root .welcome-head h1 {
  font-size: 2.9rem;
}

:root .panel-header h2 {
  font-size: 2.4rem;
}

/* Etiquetas y textos de apoyo: mono en mayúsculas con algo de aire entre letras. */
:root .eyebrow,
:root .card h3,
:root .kpi-label,
:root .cost-label,
:root .station-badge,
:root .panel-sub,
:root .welcome-source,
:root .quick-picks > span,
:root .tab,
:root .hint,
:root .foot-attribution,
:root .beta-tag,
:root .chip-btn small,
:root .kpi-sub,
:root .stripes-axis {
  font-family: var(--font-mono);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

:root .kpi-value,
:root .cost-value {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
}

/* El cuadradito turquesa delante de la etiqueta de la portada. */
:root .eyebrow::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  background: var(--rain);
  vertical-align: 1px;
}

:root .welcome-hero .eyebrow {
  color: #fff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--map-sea);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.kpi-value,
.panel-sub,
.stripes-axis,
.fact-list dd,
.search-meta,
td {
  font-variant-numeric: tabular-nums;
}

button,
input {
  font: inherit;
  color: inherit;
}

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

[hidden] {
  display: none !important;
}

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

.map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--map-sea);
}

.map .leaflet-tile-pane {
  filter: var(--map-filter);
}

.map .leaflet-labels-pane {
  filter: var(--labels-filter);
  opacity: var(--labels-opacity);
}

.map::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 500;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, var(--map-vignette) 100%);
}

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

.leaflet-control-attribution {
  background: var(--glass-strong) !important;
  color: var(--muted) !important;
  font-size: 10px;
}

/* Atribución del mapa por encima del banner de cookies y de la barra inferior del móvil. */
.map .leaflet-bottom {
  bottom: calc(var(--consent-h) + var(--bar-h));
}

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

.station-tip {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--glass-strong);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.station-tip::before {
  display: none;
}

.station-tip strong {
  display: block;
  font-weight: 600;
}

.station-tip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.station-tip em {
  display: block;
  margin-top: 2px;
  color: var(--accent-ink);
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
}

.station-selected span {
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent-ink);
  border-radius: 50%;
  background: var(--accent-soft);
  animation: ring 1.8s var(--ease) infinite;
}

.station-selected span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-ink);
}

@keyframes ring {
  0% {
    transform: scale(0.55);
    opacity: 1;
  }
  100% {
    transform: scale(1.15);
    opacity: 0.15;
  }
}

/* ---------- Cristal ---------- */

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(2px) saturate(1.4);
}

/* ---------- Barra superior ---------- */

/* La barra no tiene caja propia: sus piezas se colocan en la rejilla de .home. */
.topbar {
  display: contents;
  padding: 4px 8px;
  background: var(--ivory);
  border: 1px solid red;

}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 4px 8px 4px 4px;
  margin: -4px 0 -4px -4px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}

.brand:hover {
  background: rgba(var(--tint-rgb), 0.05);
}

.brand:hover .brand-mark {
  transform: rotate(-6deg) scale(1.06);
}

.brand-mark {
  transition: transform 0.35s var(--ease);
}

.brand-help {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.brand-help::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    #029dff 0 12.5%,
    #4db9ff 12.5% 25%,
    #9ad6ff 25% 37.5%,
    #efefef 37.5% 50%,
    #fbb3ba 50% 62.5%,
    #f9808b 62.5% 75%,
    #f85c6a 75% 87.5%,
    #f7394b 87.5%
  );
  box-shadow: inset 0 0 0 1px rgba(var(--tint-rgb), 0.15);
}

.brand-text {
  display: grid;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text > span {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-text > span a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}

.brand-text > span a:hover {
  text-decoration-color: currentColor;
}

.brand-text .beta-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background-color: var(--ink);
  color: var(--paper);
  font-size: 0.62rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  vertical-align: 2px;
}

.search {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 460px;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 42px;
  padding: 0 52px 0 36px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.7);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

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

.search input:focus {
  outline: none;
  border-color: var(--accent-ink);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-kbd {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  padding: 2px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.search input:not(:placeholder-shown) ~ .search-kbd {
  display: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: var(--radius-small);
  background: var(--glass-strong);
  max-height: min(60vh, 420px);
  overflow-y: auto;
  animation: drop 0.18s var(--ease);
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes drop-up {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.search-heading {
  padding: 8px 10px 6px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.search-item.active,
.search-item:hover {
  background: var(--accent-soft);
}

.search-name {
  font-weight: 500;
}

.search-meta {
  grid-column: 1;
  color: var(--muted);
  font-size: 11px;
}

.search-badge {
  grid-column: 2;
  grid-row: 1 / span 2;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 500;
}

.bg-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
  animation: fade-in 0.3s var(--ease);
}

.bg-pill-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
    transform: scale(0.7);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 16px rgba(0, 0, 0, calc(0.16 * var(--shadow-strength)));
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-ghost {
  border-color: var(--line-strong);
  background: rgba(var(--surface-rgb), 0.6);
  color: var(--ink);
}

.btn-ghost:hover {
  border-color: var(--accent-ink);
  color: var(--accent-ink);
}

.btn-small {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(var(--surface-rgb), 0.6);
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.icon-btn:hover {
  border-color: var(--accent-ink);
  background: var(--surface);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Bienvenida ---------- */

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-head h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 400;
  line-height: 1.05;
}

.welcome-text {
  margin: 0 0 16px;
  color: var(--ink-soft);
}

.legend {
  display: grid;
  gap: 4px;
  margin: 16px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Panel ---------- */

/* El panel es la última fila de .home: la caja de cristal es la de la barra. */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sheet-handle {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  padding: 20px 22px 14px;
}

.panel-heading {
  min-width: 0;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 400;
  line-height: 1.05;
}

/* Bajo el nombre, en una línea: badge de la estación y cómo se calcula el dato. */
.panel-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 8px;
}

.panel-meta .panel-sub {
  margin: 0;
}

/* Código y provincia de la estación: badge gris que abre los datos de la estación. */
.station-info {
  position: relative;
  z-index: 5;
}

.station-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  border: 0;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
  flex-shrink: 0;
  margin: 0;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.07);
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.station-badge:hover {
  background: rgba(var(--tint-rgb), 0.12);
  color: var(--ink);
}

.station-badge[aria-expanded="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.station-badge svg {
  width: 13px;
  height: 13px;
  margin-right: -2px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.25s var(--ease);
}

.station-badge[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.station-warn {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f4b011;
}

/* Se abre hacia abajo desde la badge, alineado a su izquierda y algo más ancho que el de la toolbar. */
.popover.station-pop {
  left: 0;
  right: auto;
  width: min(460px, calc(100vw - 32px));
  transform-origin: top left;
}

.panel-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-progress {
  padding: 12px 22px 0;
}

.progress {
  height: 4px;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.08);
  overflow: hidden;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 0.5s var(--ease);
}

.status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 22px 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* Sin esto, las filas con overflow:hidden se encogen a 0 cuando el contenido no cabe. */
  grid-auto-rows: max-content;
  gap: 14px;
  align-content: start;
  transition: opacity 0.3s var(--ease);
}

.panel-body.is-loading > * {
  opacity: 0.45;
}

.panel-body.is-loading .kpi-value {
  color: transparent;
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(var(--tint-rgb), 0.06) 25%, rgba(var(--tint-rgb), 0.12) 50%, rgba(var(--tint-rgb), 0.06) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.headline {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.35;
  color: var(--ink);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  border-radius: var(--radius-small);
  background: var(--ivory);
  overflow: hidden;
}

.kpi {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  animation: rise 0.45s var(--ease) both;
}

.kpi:nth-child(2) {
  animation-delay: 40ms;
}
.kpi:nth-child(3) {
  animation-delay: 80ms;
}
.kpi:nth-child(4) {
  animation-delay: 120ms;
}
.kpi:nth-child(5) {
  animation-delay: 160ms;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.kpi:last-child {
  border-right: 0;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.kpi-sub {
  color: var(--muted);
  font-size: 11px;
}

.kpi.tone-warm .kpi-value {
  color: var(--warm-ink);
}

.kpi.tone-cool .kpi-value {
  color: var(--cool-ink);
}

.card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.55);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px 12px;
  margin-bottom: 10px;
}

.card h3 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.hint {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.stripes {
  display: flex;
  height: 54px;
  border-radius: 8px;
  overflow: hidden;
  animation: fade-in 0.6s var(--ease);
}

.stripes span {
  flex: 1;
  min-width: 1px;
  transition: transform 0.2s var(--ease);
}

.stripes span:hover {
  transform: scaleY(1.08);
}

.stripes .stripe-missing {
  background: repeating-linear-gradient(135deg, transparent 0 3px, rgba(var(--tint-rgb), 0.1) 3px 5px);
}

.stripes-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.series-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.series-toggles button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

/* Cada serie con su color: fondo tintado y texto del mismo tono, sin borde. Apagada, vuelve al gris. */
.series-toggles button[data-series="tmax"] {
  --series-rgb: 247, 57, 75;
  --series-ink: var(--warm-ink);
}

.series-toggles button[data-series="tmin"] {
  --series-rgb: 2, 157, 255;
  --series-ink: var(--cool-ink);
}

.series-toggles button[data-series="prec"] {
  --series-rgb: 5, 225, 207;
  --series-ink: var(--rain-ink);
}

.series-toggles button[aria-pressed="true"] {
  background: rgba(var(--series-rgb), 0.14);
  color: var(--series-ink);
}

.series-toggles button[aria-pressed="true"]:hover {
  background: rgba(var(--series-rgb), 0.2);
}

.series-toggles button[aria-pressed="false"]:hover {
  background: rgba(var(--tint-rgb), 0.09);
  color: var(--ink-soft);
}

.series-toggles button[aria-pressed="false"] .swatch {
  opacity: 0.4;
}

.swatch {
  width: 10px;
  height: 3px;
  border-radius: 2px;
}

.swatch-warm {
  background: var(--warm);
}

.swatch-cool {
  background: var(--cool);
}

.swatch-rain {
  height: 8px;
  width: 8px;
  background: var(--rain);
}

.chart-wrap {
  position: relative;
  height: clamp(300px, 42vh, 420px);
}

.facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 4px 24px;
}

.fact-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  margin: 0 0 10px;
  font-size: 12px;
}

.fact-list dt {
  color: var(--muted);
}

.fact-list dd {
  margin: 0;
  text-align: right;
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(120px, auto) minmax(140px, 1fr));
  margin-bottom: 14px;
}

.stats-grid dd {
  text-align: left;
}

.table-wrap {
  max-height: 360px;
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  font-variant-numeric: tabular-nums;
}

/* ---------- Consentimiento ---------- */

/*
 * --consent-h lo escribe js/analytics.js con la altura del banner (0 si no se ve). Todo lo que se ancla abajo
 * parte de --bottom, que ya descuenta el banner y, si este no se ve, el área segura del móvil.
 * --bar-h lo escribe app.js: en móvil, la altura de la barra inferior de inicio (0 en el resto de estados).
 */
body {
  --consent-h: 0px;
  --bar-h: 0px;
  --inset-b: env(safe-area-inset-bottom, 0px);
  --bottom: calc(var(--gap) + var(--inset-b) + var(--consent-h));
  --stack: calc(var(--bottom) + var(--bar-h));
}

body.has-consent {
  --inset-b: 0px;
}

.consent {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px 20px;
  flex-wrap: wrap;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: #000;
  color: #fff;
  font-size: 13.5px;
  line-height: 1.35;
  animation: consent-in 0.3s var(--ease);
}

.consent[hidden] {
  display: none;
}

@keyframes consent-in {
  from {
    transform: translateY(100%);
  }
}

.consent-text {
  margin: 0;
}

.consent-actions {
  display: flex;
  gap: 8px;
}

.consent-btn {
  min-width: 96px;
  height: 40px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-small);
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.consent-btn:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.consent-btn-primary {
  border-color: #22c55e;
  background: #22c55e;
  color: #04210f;
}

.consent-btn-primary:hover {
  border-color: #4ade80;
  background: #4ade80;
}

.consent-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.consent-reopen {
  display: inline;
  margin-left: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-ink);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

@media (max-width: 760px) {
  .consent {
    justify-content: space-between;
    gap: 10px;
    padding-top: 12px;
  }

  .consent-text {
    flex: 1 1 100%;
  }

  .consent-actions {
    flex: 1 1 100%;
  }

  .consent-btn {
    flex: 1;
  }
}

/* ---------- Aviso ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--stack) + 8px);
  z-index: 1000;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 16px 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 16px 40px rgba(0, 0, 0, calc(0.2 * var(--shadow-strength)));
  transform: translateX(-50%);
  cursor: pointer;
  animation: toast-in 0.3s var(--ease);
}

.toast.toast-error {
  border-left-color: var(--warm);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
}

/* ---------- Movil ---------- */

@media (max-width: 1100px) and (min-width: 761px) {
  .brand-text > span,
  .search-kbd {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --gap: 10px;
  }

  .brand-text > span,
  .brand-name,
  .search-kbd {
    display: none;
  }

  .brand-mark {
    width: 24px;
    height: 24px;
  }

  .search {
    flex: 1 1 0;
    max-width: none;
  }

  .search input {
    height: 40px;
    font-size: 16px;
  }

  .search input {
    padding-right: 12px;
  }

  .bg-pill {
    grid-column: 1 / -1;
    max-width: none;
    margin-left: 0;
    justify-content: center;
  }

  .welcome-head h1 {
    font-size: 2.1rem;
  }

  body.has-selection .sheet-handle {
    display: grid;
    place-items: center;
    width: 100%;
    height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
  }

  .sheet-handle span {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--line-strong);
  }

  .panel-header {
    flex-wrap: wrap;
    padding: 4px 16px 12px;
  }

  .panel-heading {
    flex: 1 1 200px;
  }

  .panel-header h2 {
    font-size: 1.45rem;
  }

  .panel-progress {
    padding: 10px 16px 0;
  }

  .panel-body {
    padding: 14px 16px 20px;
  }

  .headline {
    font-size: 1.05rem;
  }

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

  .kpi {
    border-bottom: 1px solid var(--line);
  }

  .kpi:nth-child(2n) {
    border-right: 0;
  }

  .kpi:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    border-bottom: 0;
  }

  .chart-wrap {
    height: 280px;
  }

  #expand-btn {
    display: none;
  }

  body.has-selection .toast {
    bottom: calc(66dvh + 12px);
  }
}

/* ---------- Navegador de días ---------- */

.day-nav {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.7);
}

.day-arrow {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}

.day-arrow svg,
.day-caret {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.day-arrow:hover {
  background: var(--accent-soft);
}

.day-arrow:active {
  transform: scale(0.9);
}

#prev-day:active svg {
  transform: translateX(-2px);
}

#next-day:active svg {
  transform: translateX(2px);
}

.day-arrow svg {
  transition: transform 0.15s var(--ease);
}

.day-label {
  display: inline-flex;
  flex: 1;
  justify-content: center;
  min-width: 0;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s var(--ease);
}

.day-label:hover {
  background: rgba(var(--tint-rgb), 0.05);
}

.day-caret {
  width: 15px;
  height: 15px;
  stroke: var(--muted);
  stroke-width: 1.6;
}

.day-viewport {
  position: relative;
  display: grid;
  min-width: 112px;
  overflow: hidden;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

.day-text {
  display: grid;
}

.day-text-inner {
  grid-area: 1 / 1;
}

.day-short {
  display: none;
}

.enter-next {
  animation: day-in-next 0.26s var(--ease);
}

.enter-prev {
  animation: day-in-prev 0.26s var(--ease);
}

.leave-next {
  animation: day-out-next 0.26s var(--ease) forwards;
}

.leave-prev {
  animation: day-out-prev 0.26s var(--ease) forwards;
}

@keyframes day-in-next {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
}

@keyframes day-in-prev {
  from {
    opacity: 0;
    transform: translateX(-18px);
  }
}

@keyframes day-out-next {
  to {
    opacity: 0;
    transform: translateX(-18px);
  }
}

@keyframes day-out-prev {
  to {
    opacity: 0;
    transform: translateX(18px);
  }
}

.date-native {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.today-btn {
  flex-shrink: 0;
  white-space: nowrap;
  height: 28px;
  margin: 0 3px 0 4px;
  padding: 0 10px;
  border: 1px solid var(--accent-ink);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}

.today-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.today-btn.is-today {
  border-color: transparent;
  background: var(--accent-soft);
  cursor: default;
}

.today-btn.is-today::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

.today-btn.is-today:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------- Atribución ---------- */

.attribution {
  position: fixed;
  left: var(--gap);
  bottom: var(--stack);
  z-index: 12;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass-strong);
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
  text-decoration: none;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.attribution:hover {
  border-color: var(--accent-ink);
  color: var(--accent-ink);
}

/* ---------- Bienvenida ---------- */

.btn svg {
  width: 16px;
  height: 16px;
  margin-right: 6px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn.is-busy svg {
  animation: spin 1.2s linear infinite;
}

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

.quick-picks {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  text-align: center;
}

.quick-picks > span {
  color: var(--muted);
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.chip-btn {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(var(--surface-rgb), 0.7);
  font-size: 13px;
  font-weight: 500;
  line-height: 30px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.chip-btn small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.chip-btn:hover {
  border-color: var(--accent-ink);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* Aviso: fondo tintado en rojo, sin borde, icono de alerta y la idea clave en negrita. */
.disclaimer {
  display: flex;
  gap: 12px;
  margin: 16px 0 0;
  padding: 16px 18px;
  border-radius: 14px;
  background: var(--warm-soft);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.disclaimer strong {
  color: var(--ink);
  font-weight: 600;
}

.disclaimer svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  fill: none;
  stroke: var(--warm-ink);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.disclaimer a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(var(--tint-rgb), 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.welcome-source a,
.popover a {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: rgba(var(--tint-rgb), 0.25);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.disclaimer a:hover,
.welcome-source a:hover,
.popover a:hover {
  text-decoration-color: currentColor;
}

.welcome-source {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------- Dock (sin estación elegida) ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(var(--stack) + 36px);
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 8px 8px 16px;
  border-radius: 999px;
  background: var(--glass-strong);
  transform: translate(-50%, 0);
  transition: opacity 0.35s var(--ease), transform 0.45s var(--ease);
}

body.has-selection .dock,
body.welcome-open .dock {
  opacity: 0;
  transform: translate(-50%, 20px);
  pointer-events: none;
}

.dock-text {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
}

.dock-strong {
  color: var(--ink);
  font-weight: 600;
}

.dock-dot {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--station);
  box-shadow: 0 0 0 1px rgba(23, 23, 23, 0.6);
}

.dock-dot::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 2px solid var(--station);
  border-radius: 50%;
  animation: ring 1.8s var(--ease) infinite;
}

.dock .btn {
  flex-shrink: 0;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Panel: pestañas, cabecera y pie ---------- */

.panel {
  overflow: hidden;
}

.panel-header {
  border-bottom: 0;
  padding-bottom: 8px;
}

.rigor {
  position: relative;
}

#rigor-btn[aria-expanded="true"] {
  border-color: var(--accent-ink);
  background: var(--accent-soft);
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: -44px;
  z-index: 40;
  width: min(340px, calc(100vw - 32px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--paper);
  box-shadow: 0 18px 44px rgba(0, 0, 0, calc(0.2 * var(--shadow-strength)));
  font-size: 12.5px;
  line-height: 1.45;
  animation: pop-in 0.22s var(--ease);
  transform-origin: top right;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.97);
  }
}

.popover h4 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.popover ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 16px;
  color: var(--ink-soft);
}

.popover li::marker {
  color: var(--accent);
}

.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 6px;
  margin-right: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}

.tab:hover,
.tab[aria-selected="true"] {
  color: var(--ink);
}

.tab-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.07);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.tab-count:empty {
  display: none;
}

.tab-indicator {
  position: absolute;
  left: 22px;
  bottom: -1px;
  height: 2px;
  width: 76px;
  border-radius: 2px;
  background: var(--accent-ink);
  transition: transform 0.35s var(--ease), width 0.35s var(--ease);
}

.refresh-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.2s;
}

.refresh-bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: sweep 0.9s linear infinite;
}

@keyframes sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(400%);
  }
}

.panel.is-refreshing .refresh-bar {
  opacity: 1;
}

.panel.is-refreshing .panel-body {
  opacity: 0.82;
}

.tab-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: max-content;
  gap: 14px;
  animation: fade-in 0.3s var(--ease);
}

.panel-body {
  display: block;
}

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 22px;
  border-top: 1px solid var(--line);
  background: var(--glass-strong);
}

.foot-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Aporte: pastilla pequeña junto a «Compartir»; los colores, con .btn-coffee más abajo. */
.donate-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.donate-btn svg {
  width: 16px;
  height: 16px;
}

.foot-attribution {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  text-decoration: none;
}

.foot-attribution:hover {
  color: var(--accent-ink);
}

body.has-selection .attribution {
  opacity: 0;
  pointer-events: none;
}

.panel-foot .btn {
  border-radius: 999px;
}

/* Compartir: mismo estilo que la pastilla «Hoy» (fondo morado suave, texto morado). */
#share-btn {
  height: 30px;
  padding: 0 12px;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: none;
}

#share-btn:hover:not(:disabled) {
  background: rgba(160, 93, 220, 0.22);
}

#share-btn svg {
  width: 14px;
  height: 14px;
  margin-right: 5px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Titular ---------- */

.hero {
  display: grid;
  gap: 6px;
}

.headline {
  font-size: 1.3rem;
  line-height: 1.32;
  text-wrap: pretty;
}

.delta {
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.delta.is-warm {
  color: var(--warm-ink);
}

.delta.is-cool {
  color: var(--cool-ink);
}

.subline {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-wrap: pretty;
}

.subline:empty {
  display: none;
}

.nudge-next {
  animation: nudge-next 0.4s var(--ease);
}

.nudge-prev {
  animation: nudge-prev 0.4s var(--ease);
}

@keyframes nudge-next {
  from {
    opacity: 0.35;
    transform: translateX(10px);
  }
}

@keyframes nudge-prev {
  from {
    opacity: 0.35;
    transform: translateX(-10px);
  }
}

.kpi {
  transition: background 0.3s var(--ease);
}

.kpi-value {
  transition: color 0.3s var(--ease);
}

/* ---------- Gráfico ---------- */

.segmented {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: 10px;
  background: rgba(var(--tint-rgb), 0.06);
}

.segmented::before {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, calc(0.14 * var(--shadow-strength)));
  transition: transform 0.3s var(--ease);
}

.segmented[data-value="day"]::before,
.segmented[data-value="story"]::before {
  transform: translateX(100%);
}

.segmented button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}

.segmented button[aria-checked="true"] {
  color: var(--ink);
}

.chart-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11.5px;
}

/* ---------- Franjas ---------- */

.stripes {
  position: relative;
  touch-action: pan-y;
  cursor: crosshair;
}

.stripes span {
  transition: background-color 0.45s var(--ease), opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.stripes.has-hot span {
  opacity: 0.55;
}

.stripes.has-hot span.is-hot {
  opacity: 1;
  transform: scaleY(1.12);
  box-shadow: 0 0 0 1px var(--ink);
  position: relative;
  z-index: 1;
}

.stripes span:hover {
  transform: none;
}

.stripes-hover {
  color: var(--ink);
  font-weight: 600;
}

.hint-warm {
  color: var(--warm-ink);
}

.hint-cool {
  color: var(--cool-ink);
}

/* ---------- Donación ---------- */

/*
 * El módulo de donación invierte los colores (fondo amarillo, texto oscuro) para destacar sobre la tarjeta negra.
 * Se redefinen los tokens dentro del módulo y todo lo de dentro los hereda.
 */
.donate {
  --ink: #161513;
  --ink-soft: #3d3b37;
  --muted: #6b6964;
  --tint-rgb: 22, 21, 19;
  --line: rgba(22, 21, 19, 0.1);
  --donate-cells: #f4f2ec;
  --primary: #161513;
  --primary-hover: #000;
  --on-primary: #fff;
  display: grid;
  gap: 12px;
  border-color: transparent;
  background: #f6be33;
  color: var(--ink);
}

#donate-title {
  font-size: 2rem;
  font-weight: bold;
}

/* Título del módulo como titular: serif y más grande, sin las mayúsculas de las demás tarjetas. */
.donate h3 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-transform: none;
  color: var(--ink);
}

.donate-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.donate-head p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

/* Gastos como barra de KPIs en horizontal: una celda por concepto, separadas por líneas finas. */
.cost-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin: 0;
  padding: 0;
  border-radius: var(--radius-small);
  background: #fff;
  list-style: none;
  overflow: hidden;
}

.cost-list li {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
}

.cost-list li + li {
  border-left: 1px solid var(--line);
}

.cost-label {
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cost-value {
  font-size: 1.25rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Texto a la izquierda y botón a la derecha del módulo. */
.donate-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
}

.donate-foot .btn-coffee {
  order: 2;
  margin-left: auto;
}

/* Botón de aporte del módulo: la acción principal (negro en claro), en pastilla y con icono de moneda. */
.btn-coffee {
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
}

/* «0,75 €» del pie: fondo melocotón, texto naranja y moneda. */
.donate-btn {
  border: 0;
  border-radius: 999px;
  background: var(--kofi-bg);
  color: var(--kofi-ink);
  font-weight: 600;
}

.donate-btn:hover {
  background: var(--kofi-bg-hover);
}

.btn-coffee svg,
.donate-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.donate-btn svg {
  stroke: var(--kofi-icon);
}

.donate-eq {
  color: var(--muted);
  font-size: 12px;
}

.donate-visit {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.5;
}

/* Al llegar desde el botón de la cantidad, el módulo se ilumina un instante. */
.donate.is-flash {
  animation: donate-flash 1.4s var(--ease);
}

@keyframes donate-flash {
  0%,
  40% {
    box-shadow: 0 0 0 3px var(--accent-soft);
    border-color: var(--accent-ink);
  }
}

/* ---------- Tabla ---------- */

.table-head {
  align-items: center;
  margin-bottom: 0;
}

.table-caption {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

#tab-table .stats-grid {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.55);
  margin: 0;
}

#tab-table .table-wrap {
  max-height: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.55);
}

#results-table th[scope="row"] {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
}

#results-table thead th:first-child {
  left: 0;
  z-index: 2;
}

#results-table tbody tr {
  transition: background 0.15s;
}

#results-table tbody tr:hover,
#results-table tbody tr:hover th {
  background: rgba(var(--tint-rgb), 0.05);
}

.col-anomaly {
  min-width: 150px;
}

td.col-anomaly {
  display: flex;
  align-items: center;
  gap: 8px;
}

.anomaly {
  position: relative;
  flex: 1;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent calc(50% - 0.5px), var(--line-strong) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.anomaly i {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 3px;
}

td.col-anomaly b {
  width: 34px;
  font-weight: 500;
  text-align: right;
}

.is-missing {
  color: var(--grey);
}

tr.is-gap th,
tr.is-gap td {
  background-color: transparent;
  background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(var(--tint-rgb), 0.05) 6px 9px);
  color: var(--muted);
  font-style: italic;
}

tr.is-gap td {
  text-align: center;
}

.row-tag {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 600;
}

tr.is-warmest th::after,
tr.is-coldest th::after {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
}

tr.is-warmest th::after {
  content: "más cálido";
  background: var(--warm-soft);
  color: var(--warm-ink);
}

tr.is-coldest th::after {
  content: "más fresco";
  background: var(--cool-soft);
  color: var(--cool-ink);
}

/* ---------- Diálogo de compartir ---------- */

.share-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, calc(0.25 * var(--shadow-strength)));
}

.share-dialog[open] {
  animation: dialog-in 0.35s var(--ease);
}

.share-dialog::backdrop {
  background: rgba(var(--tint-rgb), 0.35);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.3s var(--ease);
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
}

.share-inner {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.share-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.share-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  line-height: 1.05;
}

.share-formats {
  justify-self: start;
}

.share-formats button {
  height: 32px;
  padding: 0 14px;
}

.fmt-icon {
  display: inline-block;
  border: 1.6px solid currentColor;
  border-radius: 2px;
}

.fmt-square {
  width: 11px;
  height: 11px;
}

.fmt-story {
  width: 8px;
  height: 13px;
}

.share-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  height: min(52dvh, 440px);
  padding: 14px;
  border-radius: var(--radius-small);
  background: repeating-linear-gradient(45deg, var(--ivory) 0 10px, var(--beige) 10px 11px);
}

.share-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, calc(0.18 * var(--shadow-strength)));
}

.share-canvas.is-swapping {
  animation: card-swap 0.4s var(--ease);
}

@keyframes card-swap {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
}

.share-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.share-actions .btn {
  flex: 1 1 140px;
  white-space: nowrap;
}

.btn.is-done {
  border-color: var(--accent-ink);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) and (min-width: 761px) {
  .day-viewport {
    min-width: 64px;
  }

  .day-long {
    display: none;
  }

  .day-short {
    display: inline;
  }
}

@media (max-width: 760px) {
  .brand {
    padding: 0;
    margin: 0;
  }

  .beta-tag {
    display: none !important;
  }

  .day-nav {
    justify-content: space-between;
    height: 40px;
  }

  .day-label {
    flex: 1;
    justify-content: center;
  }

  .day-viewport {
    min-width: 0;
  }

  .dock {
    left: var(--gap);
    right: var(--gap);
    justify-content: space-between;
    transform: none;
    border-radius: var(--radius);
    bottom: calc(var(--stack) + 46px);
  }

  body.has-selection .dock,
  body.welcome-open .dock {
    transform: translateY(20px);
  }

  .dock-text {
    white-space: normal;
    font-size: 12.5px;
    line-height: 1.3;
  }

  .attribution {
    left: 50%;
    bottom: calc(var(--stack) + 8px);
    transform: translateX(-50%);
    white-space: nowrap;
  }

  .tabs {
    padding: 0 16px;
  }

  .tab-indicator {
    left: 16px;
  }

  .panel-foot {
    padding: 8px 16px;
  }

  /* «Cómo leer estos datos» se abre bajo el botón de información, arriba de la pantalla. */
  .popover {
    position: fixed;
    top: calc(16px + 48px + 8px + env(safe-area-inset-top, 0px));
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    transform-origin: top right;
  }

  .popover.station-pop {
    left: 12px;
    right: 12px;
    width: auto;
  }

  .headline {
    font-size: 1.12rem;
  }

  .chart-card .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-card .segmented {
    display: grid;
  }

  .share-inner {
    padding: 16px;
  }

  .share-stage {
    height: min(50dvh, 420px);
  }

  .share-formats {
    justify-self: stretch;
  }

  .col-anomaly {
    min-width: 110px;
  }

  body.has-selection .toast {
    bottom: calc(70dvh + 12px);
  }
}

/* ---------- Inicio: barra y bienvenida en un solo objeto ---------- */

/*
 * Un solo contenedor con tres estados que comparten marca, buscador y día:
 *   body.welcome-open  · tarjeta con la explicación
 *   body.has-selection · buscador y día arriba, «Volver» debajo y el panel de resultado
 *   ninguno            · barra compacta con la marca (móvil, explorando el mapa)
 */
.home {
  position: fixed;
  top: calc(var(--gap) + env(safe-area-inset-top, 0px));
  right: var(--gap);
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "brand search day pill";
  align-items: center;
  gap: 14px;
  width: min(720px, 56vw);
  min-height: var(--topbar-height);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--glass-strong);
}

.brand {
  grid-area: brand;
}

.toolbar {
  grid-area: back;
}

/* Encima del selector de día y del resto de la tarjeta cuando se despliegan los resultados. */
.search {
  z-index: 3;
  grid-area: search;
  max-width: none;
}

.day-nav {
  grid-area: day;
}

.bg-pill {
  grid-area: pill;
  margin-left: 0;
}

.welcome-head {
  grid-area: head;
}

.welcome-foot {
  grid-area: foot;
}

.panel {
  grid-area: panel;
}

.sheet-handle {
  grid-area: handle;
}

.welcome-head,
.welcome-foot,
.toolbar {
  display: none;
}

body.has-selection .toolbar {
  display: flex;
}

body:not(.has-selection) .panel {
  display: none;
}

/*
 * Con la tarjeta abierta o con estación es un panel blanco opaco. La marca va en una cabecera
 * separada por una línea: ::before ocupa la primera fila de la rejilla y su borde inferior
 * llega a los bordes del panel gracias a los márgenes negativos.
 */
body.welcome-open .home,
body.has-selection .home {
  --pad-x: 22px;
  border-color: var(--border);
  background: var(--sheet);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: var(--shadow);
}

body.welcome-open .home::before,
body.has-selection .home::before {
  content: "";
  grid-row: 1;
  grid-column: 1 / -1;
  align-self: stretch;
  margin: -14px calc(-1 * var(--pad-x)) -7px;
}

/* Estación elegida: el panel ocupa toda la altura y el resultado llena lo que queda bajo la barra. */
body.has-selection .home {
  bottom: var(--bottom);
  /* Dos columnas iguales: buscador y día miden lo mismo. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas:
    "brand back"
    "search day"
    "panel panel";
  gap: 14px;
  padding: 14px var(--pad-x) 0;
  /* clip y no hidden: el foco o scrollIntoView dentro del panel no deben desplazar la caja entera. */
  overflow: clip;
  transition: width 0.45s var(--ease);
}

body.has-selection .home:has(.panel.expanded) {
  width: calc(100vw - 2 * var(--gap));
}

body.has-selection .panel {
  align-self: stretch;
  margin: 0 calc(-1 * var(--pad-x));
  border-radius: 0 0 var(--radius) var(--radius);
}

body.has-selection .bg-pill {
  justify-self: end;
  min-width: 0;
}

/* Con estación la marca es solo firma: «Volver» es la salida. */
body.has-selection .brand {
  cursor: default;
}

body.has-selection .brand:hover {
  background: transparent;
}

body.has-selection .brand:hover .brand-mark {
  transform: none;
}

body.has-selection .brand-help {
  display: none;
}

body.has-selection .panel-header {
  padding-top: 14px;
}

/* La pastilla de descarga en segundo plano, cuando aparece, ocupa su propia fila bajo la marca. */
@media (min-width: 761px) {
  body.has-selection .home:has(.bg-pill:not([hidden])) {
    grid-template-rows: auto auto auto minmax(0, 1fr);
    grid-template-areas:
      "brand back"
      "pill pill"
      "search day"
      "panel panel";
  }
}

/* Tarjeta abierta */
body.welcome-open .home {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "head head"
    "search day"
    "foot foot";
  /* Un solo ritmo en toda la bienvenida: 16px en vertical y 8px en horizontal, sin márgenes sueltos dentro. */
  gap: 16px 8px;
  width: 560px;
  padding: 16px;
  max-height: calc(100dvh - 2 * var(--gap) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  /* La última fila absorbe el alto sobrante para que la caja blanca llegue abajo sin abrir huecos entre filas. */
  grid-template-rows: auto auto 1fr;
  align-content: start;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

body.welcome-open .welcome-head,
body.welcome-open .welcome-foot {
  display: block;
}

/* El pie llena la última fila: acciones arriba, aviso y fuente abajo del todo. */
body.welcome-open .welcome-foot {
  display: flex;
  flex-direction: column;
  align-self: stretch;
  gap: 16px;
}

body.welcome-open .welcome-foot .disclaimer {
  margin-top: auto;
}

body.welcome-open .welcome-foot .quick-picks,
body.welcome-open .welcome-foot .disclaimer,
body.welcome-open .welcome-source {
  margin: 0;
}

/* En escritorio la tarjeta ocupa todo el alto, como con estación. En móvil deja ver el mapa debajo. */
@media (min-width: 761px) {
  /*
   * El pie se deshace (display: contents) para colocar sus piezas en la rejilla. La portada se estira
   * con todo el alto que sobra; debajo van buscador, sugerencias, aviso y fuente, ajustados al fondo.
   */
  body.welcome-open .home {
    bottom: var(--bottom);
    grid-template-rows: 1fr auto auto auto auto;
    grid-template-areas:
      "head head"
      "search day"
      "picks picks"
      "note note"
      "source source";
  }

  body.welcome-open .home:has(.bg-pill:not([hidden])) {
    grid-template-rows: auto 1fr auto auto auto auto;
    grid-template-areas:
      "pill pill"
      "head head"
      "search day"
      "picks picks"
      "note note"
      "source source";
  }

  body.welcome-open .welcome-foot {
    display: contents;
  }

  body.welcome-open .quick-picks {
    grid-area: picks;
    margin: 0;
  }

  body.welcome-open .welcome-foot .disclaimer {
    grid-area: note;
  }

  body.welcome-open .welcome-source {
    grid-area: source;
  }
}

body.welcome-open .day-nav {
  justify-self: stretch;
}

/* Buscador y día comparten fila: el atajo de teclado le quitaría sitio al texto de ayuda. */
body.welcome-open .search-kbd {
  display: none;
}

body.welcome-open .bg-pill {
  justify-self: end;
}

/* En la bienvenida la marca va dentro de la portada, que queda a 16px del borde superior: sin cabecera ni línea. */
body.welcome-open .brand,
body.welcome-open .home::before {
  display: none;
}

/* Bienvenida: buscador y día más altos, con «Usar mi ubicación» dentro del buscador. En móvil van uno debajo del otro. */

body.welcome-open .search input {
  height: 52px;
  padding: 0 52px 0 44px;
  border-width: 1.5px;
  font-size: 16px;
}

body.welcome-open .search-icon {
  left: 16px;
  width: 18px;
  height: 18px;
  stroke: var(--ink-soft);
}

.search-locate {
  display: none;
}

body.welcome-open .search-locate {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

body.welcome-open .search-locate:hover {
  background: rgba(var(--tint-rgb), 0.07);
  color: var(--ink);
}

.search-locate svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-locate.is-busy svg {
  animation: spin 1.2s linear infinite;
}

/* Día junto al buscador, con su caja, flechas y «Hoy», a la misma altura que el buscador. */
body.welcome-open .day-nav {
  height: 52px;
}

body.welcome-open .brand {
  cursor: default;
}

body.welcome-open .brand:hover {
  background: transparent;
}

body.welcome-open .brand:hover .brand-mark {
  transform: none;
}

body.welcome-open .brand-help {
  display: none;
}

/* Portada: imagen de fondo a sangre, más alta, con degradado oscuro a la izquierda para leer el texto. */
.welcome-hero {
  position: relative;
  overflow: hidden;
  min-height: 290px;
  border-radius: var(--radius-small);
  /* Negro morado, el mismo tono que el fondo del vídeo. */
  background: #1c1726;
  color: #fff;
}

/* La portada va a sangre: anula el relleno de la tarjeta (16px) y comparte sus esquinas, dentro del borde de 1px. */
body.welcome-open .welcome-hero {
  display: flex;
  /*
   * Se alarga por debajo de su fila (margen negativo, más el hueco de 16px entre filas) hasta cubrir
   * buscador y día, que quedan dentro de la imagen. --hero-inputs es lo que ocupan con el relleno inferior.
   * Todo dentro de la imagen va a 24px de sus bordes.
   */
  --hero-pad: 24px;
  --hero-inputs: calc(52px + var(--hero-pad));
  min-height: calc(290px + var(--hero-inputs));
  align-self: stretch;
  margin: -16px -16px calc(-1 * (var(--hero-inputs) + 16px));
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}

body.welcome-open .welcome-hero-content {
  padding: var(--hero-pad) var(--hero-pad) calc(var(--hero-inputs) + var(--hero-pad));
}

/* Buscador y día por encima de la portada, opacos para leerse sobre el vídeo. La tarjeta ya da 16px; faltan 8px. */
body.welcome-open .search,
body.welcome-open .day-nav {
  z-index: 3;
  margin-bottom: 24px;
}

body.welcome-open .search {
  margin-left: 8px;
}

body.welcome-open .day-nav {
  margin-right: 8px;
}

body.welcome-open .search input,
body.welcome-open .day-nav {
  background: var(--surface);
}


/*
 * El vídeo viene recortado a la zona que se ve (la parte izquierda y superior del original), así pesa mucho menos.
 * En ese recorte el centro del globo cae al 75,65% del ancho y al 65,3% del alto, y su radio mide el 57,1% del alto.
 * Se coloca para que el globo tenga el centro al 83% del ancho y al 68,8% del alto de la portada, con radio del 62,6% del alto.
 */
.welcome-video {
  transform:translate3d(0,0,0);
  position: absolute;
  top: 68.8%;
  left: 72%;
  height: 105%;
  aspect-ratio: 846 / 490;
  transform: translate(-75.65%, -65.3%);
  mix-blend-mode: exclusion;
  /*
   * El tinte morado viene ya en el vídeo (sacado del original en grises): Safari no aplica bien filtros SVG
   * ni modos de fusión sobre vídeo.
   */
  pointer-events: none;
}

/* .welcome-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(14, 20, 17, 0.75) 0%, rgba(14, 20, 17, 0.35) 55%, transparent 80%);
} */

.welcome-hero-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 100%;
  padding: 16px;
}

/* Marca arriba a la izquierda de la portada; margin-bottom: auto empuja el texto al fondo. */
.hero-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 auto;
  padding-bottom: 16px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.hero-brand .brand-mark {
  width: 26px;
  height: 26px;
}

.hero-brand .beta-tag {
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
}

.welcome-hero .eyebrow {
  margin: 0 0 6px;
  color: #d9b8ff;
}

.welcome-hero h1 {
  max-width: 16ch;
  color: #fff;
}

.welcome-hero .welcome-text {
  max-width: 34ch;
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.2;
}

.welcome-foot .quick-picks {
  margin-top: 16px;
}

/*
 * Toolbar del resultado, a la derecha de la marca: info y ampliar como iconos sin caja,
 * una línea fina y «Volver» con texto. Todo a 32px de alto para que lea como una sola pieza.
 */
.toolbar {
  justify-self: end;
  align-items: center;
  gap: 2px;
}

.toolbar .icon-btn {
  width: 32px;
  height: 32px;
  border-color: transparent;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--ink-soft);
}

.toolbar .icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

.toolbar .icon-btn:hover {
  border-color: transparent;
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--ink);
}

.toolbar .icon-btn[aria-expanded="true"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: var(--line-strong);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: rgba(var(--surface-rgb), 0.7);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.15s var(--ease);
}

.back-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s var(--ease);
}

.back-btn:hover {
  border-color: var(--accent-ink);
  background: var(--accent-soft);
}

.back-btn:hover svg {
  transform: translateX(-2px);
}

.back-btn:active {
  transform: scale(0.96);
}

@media (max-width: 1100px) and (min-width: 761px) {
  body.welcome-open .day-long {
    display: inline;
  }

  body.welcome-open .day-short {
    display: none;
  }
}

@media (max-width: 760px) {
  /* Barra inferior (al alcance del pulgar): el día arriba, la marca y el buscador debajo. */
  .home {
    top: auto;
    bottom: var(--bottom);
    left: var(--gap);
    right: var(--gap);
    width: auto;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "day day"
      "brand search";
    gap: 8px;
    padding: 8px;
  }

  body:not(.has-selection):not(.welcome-open) .home:has(.bg-pill:not([hidden])) {
    grid-template-areas:
      "pill pill"
      "day day"
      "brand search";
  }

  /* El buscador queda abajo: los resultados se abren hacia arriba. */
  body:not(.welcome-open) .search-results {
    top: auto;
    bottom: calc(100% + 8px);
    max-height: min(50dvh, 380px);
    animation-name: drop-up;
  }

  /* Bienvenida: hoja a todo el ancho pegada abajo, como la del resultado. */
  body.welcome-open .home {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--consent-h);
    width: 100%;
    padding-bottom: calc(16px + var(--inset-b));
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .map .leaflet-bottom {
    bottom: calc(var(--stack) - var(--gap) + 6px);
  }

  body.welcome-open .home {
    width: auto;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "head head"
      "search search"
      "day day"
      "foot foot";
    gap: 16px 8px;
    max-height: min(76dvh, calc(100dvh - var(--consent-h) - var(--gap) - env(safe-area-inset-top, 0px)));
    --pad-x: 18px;
  }

  /* Con la descarga en segundo plano visible, la pastilla tiene su fila encima de la portada (sin ella, crea columnas de más). */
  body.welcome-open .home:has(.bg-pill:not([hidden])) {
    grid-template-areas:
      "pill pill"
      "head head"
      "search search"
      "day day"
      "foot foot";
  }

  body.welcome-open .bg-pill {
    justify-self: stretch;
    justify-content: center;
  }

  body.welcome-open .brand-name {
    display: inline;
  }

  body.welcome-open .brand-mark {
    width: 28px;
    height: 28px;
  }

  .welcome-hero {
    min-height: 300px;
  }

  /* En móvil buscador y día van en dos filas, ambas dentro de la portada. */
  body.welcome-open .welcome-hero {
    --hero-inputs: calc(2 * 52px + 16px + var(--hero-pad));
    min-height: calc(300px + var(--hero-inputs));
  }

  body.welcome-open .search {
    margin-bottom: 0;
  }

  body.welcome-open .search,
  body.welcome-open .day-nav {
    margin-inline: 8px;
  }

  body.welcome-open .day-nav {
    justify-self: stretch;
  }

  /* En móvil la caja con estación es una hoja inferior: buscador arriba, «Volver» junto al día. */
  /*
   * Hoja inferior: asa arriba, el resultado ocupa el centro y buscador, «Volver» y día quedan fijos
   * abajo, al alcance del pulgar. Sube desde la misma posición que la barra de inicio.
   */
  body.has-selection .home {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--consent-h);
    width: 100%;
    height: calc(70dvh - var(--consent-h));
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      "handle"
      "panel"
      "pill"
      "search"
      "day";
    gap: 8px;
    --pad-x: 14px;
    padding: 0 var(--pad-x) calc(10px + var(--inset-b));
    border-radius: var(--radius) var(--radius) 0 0;
    transition: height 0.45s var(--ease);
  }

  body.has-selection .home:has(.panel.expanded) {
    width: 100%;
    height: calc(100dvh - var(--gap) - var(--consent-h) - env(safe-area-inset-top, 0px));
    /* Deja libre la franja donde flotan Volver e información. */
    padding-top: 56px;
  }

  body.has-selection .panel {
    border-bottom: 1px solid var(--line);
  }

  /* Un día con flechas y «Hoy» necesita sitio: el buscador va a todo el ancho y el día comparte fila con Volver. */
  body.has-selection .search input,
  body.has-selection .day-nav,
  body.has-selection .back-btn,
  body.has-selection .toolbar .icon-btn {
    min-height: 44px;
  }

  body.has-selection .toolbar .icon-btn {
    min-width: 44px;
  }

  body.has-selection .brand {
    display: none;
  }

  /* En la hoja no hay cabecera con marca: el asa ya separa. */
  body.has-selection .home::before {
    display: none;
  }

  body.has-selection .panel {
    border-radius: 0;
  }

  /*
   * Volver e información flotan en el borde superior de la pantalla, a 16px de los lados y del techo,
   * fuera de la hoja. Más grandes que el resto de iconos para alcanzarlos bien.
   */
  body.has-selection .toolbar,
  body.has-selection .rigor {
    display: contents;
  }

  body.has-selection .back-btn,
  body.has-selection #rigor-btn {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0px));
    z-index: 30;
    width: 48px;
    height: 48px;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-small);
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow);
  }

  body.has-selection .back-btn {
    left: 16px;
    justify-content: center;
  }

  body.has-selection #rigor-btn {
    right: 16px;
  }

  body.has-selection .back-btn svg,
  body.has-selection #rigor-btn svg {
    width: 22px;
    height: 22px;
  }

  body.has-selection .sheet-handle {
    align-self: stretch;
    height: auto;
  }

  /* El nombre de la estación, más pequeño. :root le da más peso a la regla de escritorio. */
  :root .panel-header h2 {
    font-size: 1.3rem;
  }

  .toolbar-divider {
    display: none;
  }

  .toolbar .icon-btn {
    width: 36px;
    height: 40px;
  }

  body.has-selection .panel-header {
    padding-top: 12px;
  }

  .back-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
  }

  .back-btn span {
    display: none;
  }
}

/* ---------- Transición entre estados (View Transitions) ---------- */

/* Los nombres solo existen durante el cambio, para no alterar el apilado del resto del tiempo. */
html.is-morphing .home {
  view-transition-name: home;
  /* El ancho y el alto los anima la transición; una transición CSS a la vez los desfasaría. */
  transition: none;
}

html.is-morphing .brand {
  view-transition-name: home-brand;
}

html.is-morphing .toolbar {
  view-transition-name: home-back;
}

html.is-morphing .search {
  view-transition-name: home-search;
}

html.is-morphing .day-nav {
  view-transition-name: home-day;
}

html.is-morphing .bg-pill {
  view-transition-name: home-pill;
}

html.is-morphing .welcome-head {
  view-transition-name: home-head;
}

html.is-morphing .welcome-foot {
  view-transition-name: home-foot;
}

html.is-morphing .panel {
  view-transition-name: home-panel;
}

/* El mapa no se funde: sigue vivo debajo mientras la tarjeta cambia de forma. */
::view-transition-old(root) {
  display: none;
}

::view-transition-new(root) {
  animation: none;
}

::view-transition-group(*) {
  animation-duration: 0.5s;
  animation-timing-function: cubic-bezier(0.32, 0.72, 0, 1);
}

/* La caja de cristal se dibuja en el propio grupo para que sus esquinas no se deformen al cambiar de tamaño. */
::view-transition-group(home) {
  box-sizing: border-box;
  /* Mismo panel blanco que .home: sin cristal. */
  border-radius: var(--radius);
  background: var(--sheet);
}

::view-transition-image-pair(home) {
  display: none;
}

/* Lo que entra y sale con la explicación: se apaga enseguida y vuelve cuando la caja ya ha crecido. */
::view-transition-old(home-head),
::view-transition-old(home-hint),
::view-transition-old(home-foot),
::view-transition-old(home-panel),
::view-transition-old(home-brand):only-child,
::view-transition-old(home-back):only-child {
  animation: morph-out 0.16s var(--ease) both;
}

::view-transition-new(home-head),
::view-transition-new(home-hint),
::view-transition-new(home-foot),
::view-transition-new(home-panel) {
  animation: morph-in 0.34s var(--ease) 0.2s both;
}

::view-transition-new(home-brand):only-child,
::view-transition-new(home-back):only-child {
  animation: morph-in 0.3s var(--ease) 0.14s both;
}

/* Buscador y día viajan como una sola pieza: la copia vieja se retira enseguida para que no se vea doble. */
::view-transition-old(home-search),
::view-transition-old(home-day) {
  animation: morph-fade 0.12s linear both;
}

::view-transition-new(home-search),
::view-transition-new(home-day) {
  animation: none;
}

@keyframes morph-fade {
  to {
    opacity: 0;
  }
}

@keyframes morph-out {
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}

@keyframes morph-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
