/* ---------------------------------------------------------------------------
   Wetter Kaltern - Tokens
   Vollständige Hell-Palette auf blankem :root; im Dunkelmodus werden nur
   Tokens überschrieben, damit keine Farbe ausschließlich in einem
   Media-Block definiert ist.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --surface-0: #f4f2ed;          /* Seitenhintergrund */
  --surface-1: #fcfcfb;          /* Karten / Chartfläche */
  --surface-2: #efece5;          /* Zebrastreifen, Chips */
  --border:    #ddd8ce;
  --border-strong: #c9c2b4;

  --text-primary:   #17160f;
  --text-secondary: #52514e;
  --text-muted:     #86837a;

  --accent:      #2f6d4f;        /* Weinberg-Grün, UI-Akzent */
  --accent-soft: #e3ede6;
  --rain:        #2a78d6;        /* Regenmenge, sequenziell */
  --rain-soft:   #dde9f8;
  --warm:        #c25a2a;        /* Höchsttemperatur */
  --cool:        #4a6fa5;        /* Tiefsttemperatur */
  --storm:       #b3541e;

  /* Kategoriale Slots 1-5, validiert (Hell: worst adjacent CVD ΔE 9.1) */
  --src-suedtirol: #2a78d6;
  --src-yr:        #eb6834;
  --src-icon:      #1baf7a;
  --src-ecmwf:     #eda100;
  --src-gfs:       #e87ba4;

  --shadow: 0 1px 2px rgb(23 22 15 / 0.05), 0 4px 16px rgb(23 22 15 / 0.05);
  --radius: 14px;
  --day-col: 6.5rem;
  --src-col: minmax(7.5rem, 1fr);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #131311;
    --surface-1: #1a1a19;
    --surface-2: #232320;
    --border:    #34342f;
    --border-strong: #47463f;

    --text-primary:   #f6f5ef;
    --text-secondary: #c3c2b7;
    --text-muted:     #8d8b81;

    --accent:      #6fbb8f;
    --accent-soft: #1f2f26;
    --rain:        #3987e5;
    --rain-soft:   #1b2839;
    --warm:        #e08a5c;
    --cool:        #8aa8d8;
    --storm:       #e08a5c;

    /* Dieselben Farbtöne, für die dunkle Fläche neu gestuft */
    --src-suedtirol: #3987e5;
    --src-yr:        #d95926;
    --src-icon:      #199e70;
    --src-ecmwf:     #c98500;
    --src-gfs:       #d55181;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.3);
  }
}

/* ---------------------------------------------------------------------- Base */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding: clamp(0.85rem, 2.5vw, 2rem);
  padding-bottom: 3rem;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 400 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;              /* seitwärts scrollt nur das Raster */
  max-width: 1240px;
  margin-inline: auto;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
a { color: inherit; text-underline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

:where(button, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ------------------------------------------------------------------ Kopfzeile */
.masthead {
  display: flex; flex-wrap: wrap; gap: 0.85rem;
  align-items: flex-end; justify-content: space-between;
  margin-bottom: 1rem;
}
.masthead h1 { font-size: clamp(1.35rem, 4.2vw, 1.9rem); }
.masthead__sub { margin: 0.2rem 0 0; color: var(--text-secondary); font-size: 0.85rem; }
.masthead__actions { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.updated { color: var(--text-muted); font-size: 0.78rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  font: inherit; font-size: 0.82rem; font-weight: 500;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn[data-busy] svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- Quellen-Menü */
.settings { position: relative; }

.btn__count {
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem; font-weight: 600;
}
.btn__count:empty { display: none; }

.settings__panel {
  position: absolute; top: calc(100% + 0.4rem); right: 0; z-index: 20;
  min-width: 14rem;
  padding: 0.7rem;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgb(23 22 15 / 0.14);
  text-align: left;
}
.settings__panel[hidden] { display: none; }

.settings__title {
  margin: 0 0 0.5rem; padding: 0 0.35rem;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-muted);
}
.settings__list { display: flex; flex-direction: column; gap: 0.1rem; }

.settings__row {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.35rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}
.settings__row:hover { background: var(--surface-2); }
.settings__row input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; cursor: pointer; }
.settings__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); flex: none; }
.settings__name { flex: 1; }
.settings__row[data-down] .settings__name { color: var(--text-muted); font-style: italic; }

.settings__reset {
  width: 100%; margin-top: 0.5rem; padding: 0.4rem;
  font: inherit; font-size: 0.78rem;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.settings__reset:hover:not(:disabled) { background: var(--surface-2); color: var(--text-primary); }
.settings__reset:disabled { opacity: 0.45; cursor: default; }

.empty {
  padding: 2.5rem 1.1rem; text-align: center;
  color: var(--text-secondary); font-size: 0.9rem;
}
.empty .btn { margin-top: 0.8rem; }

/* ----------------------------------------------------------------- Messstation */
.station {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.6rem; align-items: baseline;
  padding: 0.85rem 1.1rem;
  margin-bottom: 1.1rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.station:empty { display: none; }
.station__now { display: flex; align-items: baseline; gap: 0.5rem; }
.station__temp { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.03em; white-space: nowrap; }
.station__label { font-size: 0.78rem; color: var(--text-muted); }
.station__metrics { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; font-size: 0.85rem; color: var(--text-secondary); }
.station__metrics b { font-weight: 600; color: var(--text-primary); }

/* ---------------------------------------------------------------- Vergleichsraster
   Tage = Zeilen, Quellen = Spalten. Die Tagesspalte bleibt beim seitlichen
   Scrollen stehen, damit auf dem Handy immer klar ist, welcher Tag gilt. */
.grid-section {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.grid-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
.grid {
  display: grid;
  grid-template-columns: var(--day-col) repeat(var(--n-src, 5), var(--src-col));
  min-width: max-content;
}

.cell {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

/* Kopfzeile der Quellen */
.head {
  position: sticky; top: 0; z-index: 3;
  border-bottom: 1px solid var(--border-strong);
  padding-top: 0.75rem; padding-bottom: 0.7rem;
}
.head__name { display: flex; align-items: center; gap: 0.4rem; font-size: 0.88rem; font-weight: 600; }
.head__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); flex: none; }
.head__sub { margin-top: 0.1rem; font-size: 0.7rem; color: var(--text-muted); }

/* Feststehende Tagesspalte */
.daycol {
  position: sticky; left: 0; z-index: 2;
  border-right: 1px solid var(--border-strong);
}
.head.daycol { z-index: 4; }

.row--even .cell:not(.head) { background: var(--surface-2); }
.row--today .daycol { box-shadow: inset 3px 0 0 var(--accent); }

.day__weekday { font-size: 0.9rem; font-weight: 600; }
.day__date { font-size: 0.72rem; color: var(--text-muted); }
.day__today {
  display: inline-block; margin-top: 0.25rem;
  padding: 0.05rem 0.4rem; border-radius: 999px;
  font-size: 0.62rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft);
}

/* Zelleninhalt: Temperatur + Regen */
.temps { display: flex; align-items: baseline; gap: 0.35rem; font-size: 0.95rem; }
.temps__max { font-weight: 600; color: var(--warm); }
.temps__sep { color: var(--text-muted); font-size: 0.8rem; }
.temps__min { color: var(--cool); font-size: 0.85rem; }

.rain { margin-top: 0.35rem; min-height: 1.35rem; }
.rain__value { font-size: 0.78rem; color: var(--text-secondary); }
.rain--wet .rain__value { color: var(--rain); font-weight: 600; }
.rain__track {
  margin-top: 0.22rem; height: 4px; border-radius: 2px;
  background: var(--rain-soft); overflow: hidden;
}
.rain__fill { height: 100%; border-radius: 2px; background: var(--rain); }
.rain__storm { margin-left: 0.3rem; color: var(--storm); font-size: 0.72rem; font-weight: 600; }

.cell--empty { color: var(--text-muted); }
.cell--empty::after { content: "–"; font-size: 0.95rem; }

.cell--down { color: var(--text-muted); font-size: 0.75rem; font-style: italic; }
.head--down .head__name { color: var(--text-muted); }
.head--down .head__dot { background: var(--border-strong); }

/* Anklickbare Tageszeile */
.row-trigger {
  display: contents;
  cursor: pointer;
}
.row-trigger:hover .cell:not(.head),
.row-trigger[aria-expanded="true"] .cell:not(.head) { background: var(--accent-soft); }
.row-trigger:focus-visible .daycol { outline: 2px solid var(--accent); outline-offset: -2px; }

.chev {
  float: right; margin-top: 0.15rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.row-trigger[aria-expanded="true"] .chev { transform: rotate(90deg); color: var(--accent); }

/* --------------------------------------------------------------- Detailbereich */
.detail {
  grid-column: 1 / -1;
  position: sticky; left: 0;
  width: 100%;   /* per JS auf die sichtbare Breite gesetzt */
  box-sizing: border-box;
  padding: 1rem 1.1rem 1.2rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-strong);
}
.detail__title { font-size: 0.95rem; margin-bottom: 0.15rem; }
.detail__note { font-size: 0.76rem; color: var(--text-muted); margin: 0 0 0.9rem; }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; margin-bottom: 0.85rem; }
.legend__item { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.76rem; color: var(--text-secondary); }
.legend__swatch { width: 14px; height: 3px; border-radius: 2px; background: var(--dot); flex: none; }
.legend__item[data-off] { opacity: 0.4; }

.chart { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart__label { font-size: 0.72rem; font-weight: 600; color: var(--text-secondary); margin: 0.5rem 0 0.1rem; }

/* Viertel-Blöcke des Landeswetterdienstes (keine Stundenwerte verfügbar) */
.quarters { margin-top: 1rem; }
.quarters__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; max-width: 26rem; }
.quarters__cell {
  padding: 0.45rem 0.3rem; text-align: center; border-radius: 6px;
  background: var(--surface-1); border: 1px solid var(--border);
  font-size: 0.72rem; color: var(--text-secondary);
}
.quarters__cell[data-rain="1"] { background: var(--rain-soft); border-color: var(--rain); color: var(--rain); font-weight: 600; }
.quarters__cell[data-rain="null"] { opacity: 0.45; }
.quarters__when { display: block; font-size: 0.65rem; color: var(--text-muted); margin-bottom: 0.15rem; }

/* ------------------------------------------------------------- Hinweis / Fußzeile */
.hint {
  margin: 0; padding: 0.7rem 1.1rem;
  font-size: 0.73rem; line-height: 1.45; color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface-1);
}
.credits {
  margin-top: 1.2rem;
  font-size: 0.72rem; line-height: 1.6; color: var(--text-muted);
}
.credits p { margin: 0; }

.state { padding: 2.5rem 1.1rem; text-align: center; color: var(--text-secondary); font-size: 0.9rem; }

/* ------------------------------------------------------------------- Mobil */
@media (max-width: 640px) {
  :root { --day-col: 4.6rem; --src-col: minmax(6.6rem, 1fr); }
  .cell { padding: 0.5rem 0.55rem; }
  .masthead__actions { width: 100%; justify-content: space-between; }
  .quarters__grid { max-width: none; }
}

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