/* ===================================================== Tokens */
:root {
  color-scheme: light;
  --bg: #eef1f6;
  --bg-grad-1: #dfe7f3;
  --bg-grad-2: #f5f2ec;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #fcfcfb;
  --surface-2: rgba(15, 23, 42, 0.05);
  --border: rgba(15, 23, 42, 0.08);
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --grid: rgba(15, 23, 42, 0.08);
  --series-obs: #2a78d6;   /* Messung  = Slot 1 (blau)   */
  --series-fc: #eb6834;    /* Vorhersage = Slot 2 (orange) */
  --series-obs-band: rgba(42, 120, 214, 0.16);
  --pos: #eb6834;
  --neg: #2a78d6;
  --sun: #f5b300;
  --cloud: #c9d3e3;
  --rain: #2a78d6;
  --hero-1: #3a7bd5;
  --hero-2: #6aa9f0;
  --hero-text: #ffffff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 18px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c111b;
    --bg-grad-1: #0f1a2e;
    --bg-grad-2: #0b0f17;
    --surface: rgba(26, 31, 42, 0.72);
    --surface-solid: #1a1a19;
    --surface-2: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --grid: rgba(255, 255, 255, 0.08);
    --series-obs: #3987e5;
    --series-fc: #d95926;
    --series-obs-band: rgba(57, 135, 229, 0.22);
    --pos: #d95926;
    --neg: #3987e5;
    --cloud: #9aa8bd;
    --rain: #3987e5;
    --hero-1: #1d3d72;
    --hero-2: #2d5fa8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c111b;
  --bg-grad-1: #0f1a2e;
  --bg-grad-2: #0b0f17;
  --surface: rgba(26, 31, 42, 0.72);
  --surface-solid: #1a1a19;
  --surface-2: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;
  --grid: rgba(255, 255, 255, 0.08);
  --series-obs: #3987e5;
  --series-fc: #d95926;
  --series-obs-band: rgba(57, 135, 229, 0.22);
  --pos: #d95926;
  --neg: #3987e5;
  --cloud: #9aa8bd;
  --rain: #3987e5;
  --hero-1: #1d3d72;
  --hero-2: #2d5fa8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.25);
}

/* ===================================================== Basis */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 10% -10%, var(--bg-grad-1), transparent 60%),
                    radial-gradient(900px 500px at 110% 10%, var(--bg-grad-2), transparent 60%);
  background-attachment: fixed;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

main { max-width: 1240px; margin: 0 auto; padding: 8px 16px 24px; }

.card {
  background: var(--surface);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }

/* ===================================================== Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  max-width: 1240px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand-icon { width: 34px; height: 34px; flex: none; }
.brand-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--text-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 999px;
  color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 14px;
}
.tab svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 20px; line-height: 1;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.icon-btn:hover { background: var(--surface-2); }

/* ===================================================== Dashboard */
.grid-dash {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
}
.hero { grid-column: span 5; }
.tiles { grid-column: span 7; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); }
.hours { grid-column: span 12; }
.days { grid-column: span 8; }
.rainsums { grid-column: span 4; }

.hero {
  color: var(--hero-text);
  background: linear-gradient(145deg, var(--hero-1), var(--hero-2));
  border: none;
  display: flex; flex-direction: column; justify-content: space-between; gap: 16px;
  position: relative; overflow: hidden;
}
.hero::after { /* weicher Lichtfleck */
  content: ""; position: absolute; width: 320px; height: 320px; right: -120px; top: -140px;
  background: radial-gradient(circle, rgba(255,255,255,.28), transparent 65%); pointer-events: none;
}
.hero.night { --hero-1: #141c3a; --hero-2: #2b3768; }
.hero.rainy { --hero-1: #3b4a5f; --hero-2: #5b6f8a; }
.hero.cloudy { --hero-1: #4a6487; --hero-2: #7891b3; }
.hero.snowy { --hero-1: #5d7fa8; --hero-2: #9db8d8; }
.hero.storm { --hero-1: #2b2f45; --hero-2: #4b4f72; }
.hero-top { display: flex; justify-content: space-between; gap: 12px; position: relative; z-index: 1; }
.hero-label { font-size: 13px; opacity: .85; font-weight: 500; }
.hero-temp { font-size: 76px; font-weight: 300; line-height: 1; letter-spacing: -2px; margin: 6px 0 4px; }
.hero-temp .unit { font-size: 30px; vertical-align: top; margin-left: 4px; letter-spacing: 0; opacity: .85; }
.hero-cond { font-size: 17px; font-weight: 600; }
.hero-meta { font-size: 13.5px; opacity: .9; margin-top: 2px; }
.hero-icon { width: 120px; height: 120px; flex: none; filter: drop-shadow(0 8px 18px rgba(0,0,0,.18)); }
.hero-icon svg { width: 100%; height: 100%; }
.hero-spark { position: relative; z-index: 1; }
.spark-head { display: flex; justify-content: space-between; font-size: 12.5px; opacity: .85; margin-bottom: 4px; }
.spark-wrap { height: 80px; position: relative; }

.tile { display: flex; flex-direction: column; gap: 4px; }
.tile-head { font-size: 12.5px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile-value { font-size: 28px; font-weight: 600; line-height: 1.15; }
.tile-value small { font-size: 14px; font-weight: 500; color: var(--text-2); }
.tile-sub { font-size: 13px; color: var(--text-2); margin-top: auto; }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .6s ease; }

#tile-wind .tile-value { font-size: 24px; }
.wind-wrap { display: flex; align-items: center; gap: 12px; }
.compass { width: 72px; height: 72px; flex: none; }
.compass-ring { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.5; }
.compass-ticks line { stroke: var(--text-3); stroke-width: 1; }
.compass-ticks line.major { stroke: var(--text-2); stroke-width: 2; }
.compass-n { font-size: 10px; font-weight: 700; fill: var(--text-2); text-anchor: middle; }
.compass-arrow { fill: var(--accent); }
#wind-arrow { transform-origin: 50px 50px; transition: transform 1s cubic-bezier(.3,1.4,.5,1); }

.sun-times { display: flex; flex-direction: column; gap: 4px; font-size: 17px; font-weight: 600; }
.sun-times div { display: flex; align-items: center; gap: 8px; }
.sun-times svg { width: 22px; height: 22px; fill: none; stroke: var(--sun); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hour-strip { display: flex; gap: 4px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 6px; scrollbar-width: thin; }
.hour {
  flex: 0 0 64px; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px; border-radius: 14px; font-size: 13px;
}
.hour.now { background: var(--surface-2); }
.hour .h-time { color: var(--text-2); }
.hour .h-icon { width: 34px; height: 34px; }
.hour .h-temp { font-weight: 600; font-size: 15px; }
.hour .h-prob { color: var(--rain); font-size: 12px; min-height: 16px; font-weight: 600; }

.day-list { display: grid; gap: 4px; }
.day {
  display: grid; grid-template-columns: 110px 44px 1fr 92px; align-items: center; gap: 12px;
  padding: 8px 6px; border-radius: 12px;
}
.day + .day { border-top: 1px solid var(--border); border-radius: 0; }
.day .d-name { font-weight: 600; }
.day .d-name small { display: block; color: var(--text-2); font-weight: 400; font-size: 12px; }
.day .d-icon { width: 40px; height: 40px; }
.day .d-range { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.day .d-range .lo { color: var(--text-2); width: 40px; text-align: right; }
.day .d-range .hi { width: 40px; }
.range-bar { flex: 1; height: 6px; border-radius: 999px; background: var(--surface-2); position: relative; }
.range-bar span { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, #3987e5, #eda100, #eb6834); }
.day .d-rain { text-align: right; font-size: 13px; color: var(--text-2); }
.day .d-rain b { color: var(--rain); font-weight: 600; }

.sum-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.sum-val { font-size: 24px; font-weight: 600; }
.sum-val small { font-size: 13px; color: var(--text-2); font-weight: 500; }

/* ===================================================== Filter */
.filters { display: flex; flex-direction: column; gap: 12px; margin-bottom: var(--gap); }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; align-self: flex-start; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  padding: 7px 12px; border-radius: 9px; font: inherit; font-weight: 500; cursor: pointer;
}
.seg button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }
.seg-small button { padding: 5px 10px; font-size: 13.5px; }
.custom-range { display: flex; gap: 12px; flex-wrap: wrap; }
.custom-range label { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
input[type="date"], select {
  font: inherit; color: var(--text); background: var(--surface-solid);
  border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px;
}
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-ui { width: 38px; height: 22px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); position: relative; transition: background .2s; }
.switch-ui::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-3); transition: transform .2s, background .2s; }
.switch input:checked + .switch-ui { background: var(--series-fc); border-color: transparent; }
.switch input:checked + .switch-ui::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-btns { display: flex; gap: 6px; margin-left: auto; }
.explain { margin: 0; max-width: 760px; }

.range-title { font-weight: 600; font-size: 17px; margin: 4px 2px 12px; }

/* ===================================================== KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.kpi .k-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi .k-val { font-size: 24px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.kpi .k-val small { font-size: 13px; font-weight: 500; color: var(--text-2); }
.kpi .k-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }

/* ===================================================== Diagramme */
.chart-card { margin-bottom: var(--gap); }
.chart-wrap { position: relative; height: 320px; }
.chart-short { height: 240px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid; }
.legend i.dash { border-top-style: dashed; }
.legend i.box { height: 10px; border: 0; border-radius: 3px; }
.legend i.outline { height: 10px; border: 2px solid; border-radius: 3px; background: transparent; }

.table-card summary { cursor: pointer; font-weight: 600; }
.table-scroll { overflow: auto; max-height: 420px; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface-solid); color: var(--text-2); font-weight: 600; }

/* ===================================================== Vorhersage-Check */
.lead-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); margin-bottom: var(--gap); }
.lead-card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.lead-card h3 small { display: block; color: var(--text-2); font-weight: 400; font-size: 12px; }
.lead-card dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13.5px; }
.lead-card dt { color: var(--text-2); }
.lead-card dd { margin: 0; font-weight: 600; text-align: right; }
.lead-card .big { font-size: 28px; font-weight: 600; margin-bottom: 8px; }
.lead-card .big small { font-size: 13px; color: var(--text-2); font-weight: 500; }
.score { height: 6px; border-radius: 999px; background: var(--surface-2); margin-bottom: 12px; overflow: hidden; }
.score span { display: block; height: 100%; background: var(--series-fc); border-radius: 999px; }

/* ===================================================== Tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-solid); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 13px; max-width: 260px;
}

/* ===================================================== Fußzeile */
.foot {
  max-width: 1240px; margin: 0 auto; padding: 8px 16px 24px;
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between;
  font-size: 12px; color: var(--text-3);
}
.foot a { color: inherit; }

/* ===================================================== Responsive */
@media (max-width: 1080px) {
  .hero { grid-column: span 12; }
  .tiles { grid-column: span 12; }
  .days, .rainsums { grid-column: span 12; }
  .lead-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  :root { --gap: 12px; }
  body { font-size: 14.5px; }
  main { padding: 4px 16px calc(84px + env(safe-area-inset-bottom)); }
  /* backdrop-filter würde die fixierte Tab-Leiste an die Kopfzeile binden */
  .topbar { gap: 10px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  /* Tabs wandern als Leiste nach unten */
  .tabs {
    position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 30; justify-content: space-around; border-radius: 20px; padding: 6px;
    background: var(--surface-solid); border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0,0,0,.2);
  }
  .tab { flex-direction: column; gap: 2px; font-size: 11.5px; padding: 6px 10px; border-radius: 14px; flex: 1; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { box-shadow: none; background: var(--surface-2); color: var(--accent); }
  .foot { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  .hero-temp { font-size: 64px; }
  .hero-icon { width: 92px; height: 92px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #tile-wind, #tile-sun { grid-column: span 2; }
  .compass { width: 76px; height: 76px; }
  .sun-times { flex-direction: row; gap: 20px; }
  .tile-value { font-size: 24px; }
  .day { grid-template-columns: 66px 32px 1fr 54px; gap: 8px; padding: 8px 2px; }
  .day .d-range { gap: 6px; }
  .day .d-icon { width: 34px; height: 34px; }
  .day .d-range .lo, .day .d-range .hi { width: 28px; }
  .day .d-rain small { display: none; }
  .chart-wrap { height: 260px; }
  .chart-short { height: 200px; }
  .lead-cards { grid-template-columns: 1fr 1fr; }
  .nav-btns { margin-left: 0; }
  .seg button { padding: 6px 9px; }
}

@media (max-width: 400px) {
  .lead-cards { grid-template-columns: 1fr; }
  .sum-val { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
