/* =========================================================================
   WETTERBLICK -- Design-System & Styles
   Ein eigenständiges WeeWX-Skin. Reines CSS/JS, keine externen Requests,
   automatischer Dark/Light-Mode über prefers-color-scheme + manueller
   Override per [data-theme] (siehe app.js).
   ========================================================================= */

/* ---------- 1. Fundament -------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
}

/* ---------- 2. Tokens ------------------------------------------------------ */

:root {
  color-scheme: light;

  /* Neutrale Chrome-Farben (Karten, Text, Diagramm-Flächen) */
  --page-bg:        #f9f9f7;
  --surface:        #fcfcfb;
  --surface-2:      #f2f2ef;
  --ink:            #0b0b0b;
  --ink-secondary:  #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --shadow:         0 1px 2px rgba(20,20,15,.04), 0 10px 24px -14px rgba(20,20,15,.16);

  /* Markenfarben -- Header/Hero, unabhängig vom Hell/Dunkel-Modus */
  --brand-navy:     #0f2540;
  --brand-navy-2:   #16324f;
  --accent-amber:   #e8a33d;

  /* Metrik-Farben (feste Zuordnung, aus dem validierten Kategorial-Set) */
  --m-regen:        #2a78d6;
  --m-temp:         #eb6834;
  --m-feuchte:      #1baf7a;
  --m-sonne:        #eda100;
  --m-wind:         #4a3aa7;
  --m-boe:          #e34948;
  --m-druck:        #008300;

  /* Status (fest, nie thematisiert) */
  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  /* Typografie */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page-bg:        #0d0d0d;
    --surface:        #1a1a19;
    --surface-2:      #222221;
    --ink:            #ffffff;
    --ink-secondary:  #c3c2b7;
    --ink-muted:      #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --shadow:         0 0 0 1px rgba(255,255,255,.05);

    --brand-navy:     #0a1830;
    --brand-navy-2:   #0f2136;

    --m-regen:        #3987e5;
    --m-temp:         #d95926;
    --m-feuchte:      #199e70;
    --m-sonne:        #c98500;
    --m-wind:         #9085e9;
    --m-boe:          #e66767;
    --m-druck:        #16a316;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg:        #0d0d0d;
  --surface:        #1a1a19;
  --surface-2:      #222221;
  --ink:            #ffffff;
  --ink-secondary:  #c3c2b7;
  --ink-muted:      #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --shadow:         0 0 0 1px rgba(255,255,255,.05);

  --brand-navy:     #0a1830;
  --brand-navy-2:   #0f2136;

  --m-regen:        #3987e5;
  --m-temp:         #d95926;
  --m-feuchte:      #199e70;
  --m-sonne:        #c98500;
  --m-wind:         #9085e9;
  --m-boe:          #e66767;
  --m-druck:        #16a316;
}

/* ---------- 3. Basis -------------------------------------------------------- */

body {
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wb-container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

h1, h2, h3 { font-weight: 650; letter-spacing: -.01em; margin: 0; }
p { margin: 0; }

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- 4. Kopfzeile / Navigation --------------------------------------- */

.wb-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--brand-navy) 92%, transparent);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.wb-header-row {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 60px;
}

.wb-brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  white-space: nowrap;
  text-decoration: none;
  color: #fff;
  margin-right: auto;
}
.wb-brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.wb-brand-loc { font-size: 11px; color: rgba(255,255,255,.55); }

.wb-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.wb-nav > a, .wb-nav-dropdown-trigger {
  flex: none;
  text-decoration: none;
  color: rgba(255,255,255,.68);
  font-size: 13.5px;
  font-weight: 550;
  padding: 8px 12px;
  border-radius: 999px;
  transition: color .15s ease, background-color .15s ease;
  white-space: nowrap;
  background: transparent;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.wb-nav > a:hover, .wb-nav-dropdown-trigger:hover { color: #fff; background: rgba(255,255,255,.08); }
.wb-nav > a[aria-current="page"], .wb-nav-dropdown-trigger[aria-current="page"] {
  color: var(--brand-navy);
  background: var(--accent-amber);
}

.wb-nav-dropdown { position: relative; }

.wb-nav-caret { width: 13px; height: 13px; flex: none; transition: transform .15s ease; }
.wb-nav-dropdown[data-open="true"] .wb-nav-caret { transform: rotate(180deg); }

.wb-nav-dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .12s ease, transform .12s ease, visibility 0s linear .12s;
  z-index: 50;
}
.wb-nav-dropdown[data-open="true"] .wb-nav-dropdown-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity .12s ease, transform .12s ease;
}
.wb-nav-dropdown-panel a {
  text-decoration: none;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 550;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}
.wb-nav-dropdown-panel a:hover { background: var(--surface-2); }
.wb-nav-dropdown-panel a[aria-current="page"] {
  color: var(--m-temp);
  background: var(--surface-2);
}

.wb-theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
  cursor: pointer;
  color: #fff;
}
.wb-theme-toggle svg { width: 16px; height: 16px; }
.wb-theme-toggle:hover { background: rgba(255,255,255,.14); }

/* ---------- 5. Himmelsband (Hero) ------------------------------------------- */

.wb-hero {
  position: relative;
  overflow: hidden;
  color: #fff;
  padding: 34px 0 26px;
}

/* Himmelsszenen -- serverseitig aus Sonnenstand / Strahlung / Regenrate gewählt */
.sky--night      { background: linear-gradient(180deg,#050b1a 0%,#0c1a33 45%,#152a4a 100%); }
.sky--dawn-dusk  { background: linear-gradient(180deg,#1a1a3d 0%,#4a3a6b 40%,#c97b5a 100%); }
.sky--clear      { background: linear-gradient(180deg,#1c5c9e 0%,#3a86c8 55%,#8fc3ea 100%); }
.sky--partly     { background: linear-gradient(180deg,#3c5673 0%,#5c7996 50%,#9fb2bf 100%); }
.sky--overcast   { background: linear-gradient(180deg,#3a3f47 0%,#5b6169 55%,#818790 100%); }
/* Regen wird nicht als eigene Szene ersetzt, sondern als Overlay (.wb-rain-streaks)
   über die tageszeit-passende Szene gelegt -- so bleibt Tag/Nacht erkennbar. */

.wb-hero::before {
  /* Sternenfeld -- nur in der Nachtszene sichtbar */
  content: "";
  position: absolute; inset: 0;
  opacity: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, #fff, transparent),
    radial-gradient(1px 1px at 22% 55%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 35% 15%, #fff, transparent),
    radial-gradient(1px 1px at 48% 40%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 62% 65%, #fff, transparent),
    radial-gradient(1px 1px at 75% 25%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 85% 50%, #fff, transparent),
    radial-gradient(1px 1px at 93% 12%, #fff, transparent);
  transition: opacity .6s ease;
}
.sky--night::before { opacity: .8; }

.wb-hero::after {
  /* Sonnen-Glanz -- nur in der Klarhimmel-Szene */
  content: "";
  position: absolute;
  top: -60px; right: 8%;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,236,180,.65) 0%, rgba(255,236,180,0) 70%);
  opacity: 0;
  transition: opacity .6s ease;
}
.sky--clear::after { opacity: 1; }

.wb-rain-streaks {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    115deg,
    rgba(255,255,255,.09) 0px,
    rgba(255,255,255,.09) 1px,
    transparent 1px,
    transparent 14px
  );
  animation: wb-rain-fall 0.7s linear infinite;
}
@keyframes wb-rain-fall {
  from { background-position: 0 0; }
  to   { background-position: -28px 40px; }
}

.wb-hero-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,.32) 100%);
}

.wb-hero-content {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.wb-hero-main { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.wb-hero-temp {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(52px, 9vw, 84px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.02em;
}
.wb-hero-sub { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: rgba(255,255,255,.85); }
.wb-hero-condition { font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,.9); }
.wb-hero-updated { font-size: 12.5px; color: rgba(255,255,255,.65); text-align: right; }

.wb-hero-minmax {
  display: flex; gap: 18px; font-size: 13.5px; color: rgba(255,255,255,.85);
}
.wb-hero-minmax b { font-family: var(--font-mono); font-weight: 600; }

/* ---------- 6. KPI-Kacheln -------------------------------------------------- */

.wb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 22px 0;
}
@media (max-width: 900px) { .wb-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .wb-grid { grid-template-columns: 1fr; } }

.wb-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .15s ease, border-color .15s ease;
}
.wb-tile:hover { transform: translateY(-2px); border-color: var(--baseline); }
.wb-tile:focus-visible { outline: 2px solid var(--accent-amber); outline-offset: 2px; }

.wb-tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wb-tile-label {
  font-size: 12.5px; font-weight: 600; color: var(--ink-secondary);
  text-transform: uppercase; letter-spacing: .05em;
  display: flex; align-items: center; gap: 6px;
}
.wb-tile-label svg { width: 15px; height: 15px; flex: none; }
.wb-tile-value { font-family: var(--font-mono); font-size: 30px; font-weight: 600; letter-spacing: -.01em; }
.wb-tile-value small { font-size: 15px; font-weight: 500; color: var(--ink-secondary); margin-left: 2px; }
.wb-tile-meta { font-size: 12.5px; color: var(--ink-muted); display: flex; justify-content: space-between; gap: 8px; }
.wb-tile-spark { height: 34px; margin-top: -2px; }
.wb-tile-arrow { font-family: var(--font-mono); }

/* Statusfarbige Kacheln (Blitz, UV) -- immer mit Icon + Textlabel, nie Farbe allein */
.wb-status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 650;
  padding: 3px 9px; border-radius: 999px;
}
.wb-status-badge svg { width: 12px; height: 12px; }
.wb-status-good     { color: #075c07; background: color-mix(in srgb, var(--status-good) 16%, var(--surface)); }
.wb-status-warning  { color: #6b4c00; background: color-mix(in srgb, var(--status-warning) 24%, var(--surface)); }
.wb-status-serious  { color: #7a2f13; background: color-mix(in srgb, var(--status-serious) 24%, var(--surface)); }
.wb-status-critical { color: #ffffff; background: var(--status-critical); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wb-status-good    { color: #b7f0b7; }
  :root:not([data-theme="light"]) .wb-status-warning { color: #ffe1a3; }
  :root:not([data-theme="light"]) .wb-status-serious { color: #ffcbb8; }
}
:root[data-theme="dark"] .wb-status-good    { color: #b7f0b7; }
:root[data-theme="dark"] .wb-status-warning { color: #ffe1a3; }
:root[data-theme="dark"] .wb-status-serious { color: #ffcbb8; }

/* ---------- 7. Seitenkopf / Abschnitte -------------------------------------- */

.wb-main { padding-bottom: 60px; }

.wb-page-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 10px; margin: 28px 0 18px;
}
.wb-page-head h1 { font-size: 26px; }
.wb-breadcrumb { font-size: 13px; color: var(--ink-muted); text-decoration: none; }
.wb-breadcrumb:hover { color: var(--ink); }

.wb-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.wb-card-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.wb-card-title {
  font-size: 15px; font-weight: 650;
  display: inline-flex; align-items: center; gap: 6px;
}
.wb-card-title svg { width: 16px; height: 16px; flex: none; }

.wb-stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.wb-stat { display: flex; flex-direction: column; gap: 2px; }
.wb-stat-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.wb-stat-value { font-family: var(--font-mono); font-size: 19px; font-weight: 600; }
.wb-stat-value small { font-size: 12px; color: var(--ink-muted); font-weight: 500; }

/* ---------- 8. Zeitraum-Tabs ------------------------------------------------- */

.wb-tabs {
  display: inline-flex; gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.wb-tabs button {
  border: 0; background: transparent; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--ink-secondary);
  padding: 6px 13px; border-radius: 999px;
  font-family: var(--font-sans);
}
.wb-tabs button[aria-selected="true"] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}

/* ---------- 9. Diagramme ----------------------------------------------------- */

.wb-chart-wrap { position: relative; }
.wb-chart-wrap canvas { width: 100%; display: block; touch-action: pan-y; }

.wb-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px; font-size: 12.5px; color: var(--ink-secondary); }
.wb-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.wb-legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.wb-legend-line { width: 14px; height: 2px; border-radius: 2px; flex: none; }

.wb-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--page-bg);
  font-size: 12px;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .1s ease;
  z-index: 5;
}
.wb-tooltip.is-visible { opacity: 1; }
.wb-tooltip-row { display: flex; align-items: center; gap: 6px; }
.wb-tooltip-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.wb-tooltip-time { font-family: var(--font-mono); font-size: 11px; opacity: .75; margin-bottom: 3px; }

.wb-empty-state {
  padding: 26px 10px; text-align: center; color: var(--ink-muted); font-size: 13.5px;
}

/* ---------- 10. Tabellen ----------------------------------------------------- */

table.wb-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.wb-table th, table.wb-table td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border);
}
table.wb-table th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-muted); font-weight: 600;
}
table.wb-table td.num, table.wb-table th.num { text-align: right; }
table.wb-table tbody tr:hover { background: var(--surface-2); }

/* ---------- 11. Windrose ------------------------------------------------------ */

.wb-windrose-wrap { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.wb-windrose-wrap canvas { flex: none; }
.wb-windrose-legend { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }

/* ---------- 12. Fußzeile ------------------------------------------------------ */

.wb-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0 40px;
  color: var(--ink-muted);
  font-size: 12.5px;
  display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between;
}
.wb-footer a { color: var(--ink-secondary); text-decoration: none; }
.wb-footer a:hover { text-decoration: underline; }

/* ---------- 13. Zugänglichkeit / Bewegungsreduktion --------------------------- */

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

@media (prefers-reduced-motion: reduce) {
  .wb-rain-streaks { animation: none; }
  .wb-tile, .wb-hero::before, .wb-hero::after, .wb-tooltip,
  .wb-nav-dropdown-panel, .wb-nav-caret { transition: none; }
}

/* ---------- 14. Sichtbar nur für Screenreader --------------------------------- */

.wb-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
