:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --fg: #1a1d21;
  --muted: #6b7280;
  --border: rgba(0, 0, 0, 0.08);
  --pill-bg: rgba(255, 255, 255, 0.95);
  --pill-stroke: rgba(0, 0, 0, 0.1);
  --tile-bg: #ffffff;
  --tile-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.08);

  --schema-bg: linear-gradient(180deg, #ffffff 0%, #f7f9fb 100%);
  --comp-bg: rgba(255, 255, 255, 0.75);
  --comp-stroke: rgba(60, 72, 88, 0.18);

  --hot: #d32f2f;
  --warm: #f57c00;
  --cold: #1565c0;
  --pv-gen: #2e7d32;
  --pv-use: #c62828;
  --led-off: #bbbfc5;
  --led-on: #00c853;

  --pipe-hot: #d32f2f;
  --pipe-cold: #1565c0;
  --pipe-pv: #f9a825;
  --pipe-neutral: #2a2f36;

  --tank-cap: #b9c1cc;
  --tank-cap-stroke: rgba(30, 40, 55, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --fg: #e8eaed;
    --muted: #9aa0a6;
    --border: rgba(255, 255, 255, 0.08);
    --pill-bg: rgba(15, 20, 25, 0.85);
    --pill-stroke: rgba(255, 255, 255, 0.22);
    --tile-bg: #1a1f25;
    --tile-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.5);

    --schema-bg: linear-gradient(180deg, #181d23 0%, #12161b 100%);
    --comp-bg: rgba(255, 255, 255, 0.04);
    --comp-stroke: rgba(255, 255, 255, 0.14);

    --led-off: #3a3f45;

    --tank-cap: #3c4452;
    --tank-cap-stroke: rgba(255, 255, 255, 0.18);

    --pipe-neutral: #cfd3d9;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
header h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.stand { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stand.stale { color: var(--warm); }
.stand.error { color: var(--hot); }
.stand.live::before {
  content: "● ";
  color: var(--led-on);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

main {
  max-width: 1640px;
  margin: 0 auto;
  padding: 16px max(20px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

/* =================== SVG-SCHEMA =================== */

.schema-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--tile-shadow);
  background: var(--schema-bg);
}
.schema {
  width: 100%;
  height: auto;
  display: block;
  background: transparent;
  padding: 0;
}

/* Component boxes */
.schema .comp-box {
  fill: var(--comp-bg);
  stroke: var(--comp-stroke);
  stroke-width: 1.2;
  transition: stroke 0.4s, stroke-width 0.4s;
}

/* === Aktive-Komponenten: pulsierende, farbige Glows ===
   Statische Keyframes (zuverlässig in allen Browsern).
   Zusätzlich .glow-strong für dynamisch verstärkten Pulse (PV/Stromnetz Volllast). */
@keyframes glow-pulse-green {
  0%, 100% { filter: drop-shadow(0 0  6px rgba(46, 125, 50, 0.7)); }
  50%      { filter: drop-shadow(0 0 22px rgba(46, 125, 50, 1)); }
}
@keyframes glow-pulse-orange {
  0%, 100% { filter: drop-shadow(0 0  6px rgba(245, 124, 0, 0.7)); }
  50%      { filter: drop-shadow(0 0 22px rgba(245, 124, 0, 1)); }
}
@keyframes glow-pulse-red {
  0%, 100% { filter: drop-shadow(0 0  6px rgba(211, 47, 47, 0.7)); }
  50%      { filter: drop-shadow(0 0 22px rgba(211, 47, 47, 1)); }
}
@keyframes glow-pulse-yellow {
  0%, 100% { filter: drop-shadow(0 0  6px rgba(255, 179, 0, 0.7)); }
  50%      { filter: drop-shadow(0 0 22px rgba(255, 179, 0, 1)); }
}
/* Verstärkter Pulse bei hoher Leistung (PV > 5 kW, Stromnetz > 4 kW) */
@keyframes glow-pulse-yellow-strong {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(255, 179, 0, 0.85)); }
  50%      { filter: drop-shadow(0 0 36px rgba(255, 179, 0, 1)); }
}
@keyframes glow-pulse-green-strong {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(46, 125, 50, 0.85)); }
  50%      { filter: drop-shadow(0 0 36px rgba(46, 125, 50, 1)); }
}
@keyframes glow-pulse-red-strong {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(211, 47, 47, 0.85)); }
  50%      { filter: drop-shadow(0 0 36px rgba(211, 47, 47, 1)); }
}
.schema .comp.glow-yellow.glow-strong .comp-box { animation: glow-pulse-yellow-strong 2s ease-in-out infinite; }
.schema .comp.glow-green.glow-strong  .comp-box { animation: glow-pulse-green-strong  2s ease-in-out infinite; }
.schema .comp.glow-red.glow-strong    .comp-box { animation: glow-pulse-red-strong    2s ease-in-out infinite; }

/* Aktiv-Klassen → kräftige Strokefarbe + pulsierender Halo */
.schema .comp.glow-green   .comp-box {
  stroke: rgba(46, 125, 50, 0.9);
  stroke-width: 2.2;
  animation: glow-pulse-green 2.4s ease-in-out infinite;
}
.schema .comp.glow-orange  .comp-box {
  stroke: rgba(245, 124, 0, 0.9);
  stroke-width: 2.2;
  animation: glow-pulse-orange 2.4s ease-in-out infinite;
}
.schema .comp.glow-red     .comp-box {
  stroke: rgba(211, 47, 47, 0.9);
  stroke-width: 2.2;
  animation: glow-pulse-red 2.4s ease-in-out infinite;
}
.schema .comp.glow-yellow  .comp-box {
  stroke: rgba(255, 179, 0, 0.9);
  stroke-width: 2.2;
  animation: glow-pulse-yellow 2.4s ease-in-out infinite;
}
.schema .comp-title {
  fill: var(--fg);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  dominant-baseline: central;
}
.schema .comp-sub {
  fill: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}
.schema .comp-hint {
  fill: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  dominant-baseline: central;
}

/* Icons — colored via currentColor on the <use> element */
.schema .icon { color: var(--muted); }
.schema .icon.hot  { color: var(--hot);    }
.schema .icon.warm { color: var(--warm);   }
.schema .icon.cold { color: var(--cold);   }
.schema .icon.pv   { color: var(--pv-gen); }

/* Value pills */
.schema .pill {
  fill: var(--pill-bg);
  stroke: var(--pill-stroke);
  stroke-width: 1;
}
.schema .value {
  font-weight: 600;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  dominant-baseline: central;
  fill: var(--fg);
}
.schema .value.hot  { fill: var(--hot);    }
.schema .value.warm { fill: var(--warm);   }
.schema .value.cold { fill: var(--cold);   }
.schema .value.pv   { fill: var(--pv-gen); }
.schema .value.use  { fill: var(--pv-use); }

/* Tank cylinders */
.schema .tank-top, .schema .tank-bot {
  fill: var(--tank-cap);
  stroke: var(--tank-cap-stroke);
  stroke-width: 1.2;
}
.schema .tank-body {
  stroke: var(--tank-cap-stroke);
  stroke-width: 1.2;
}
.schema .tank-label text {
  font-weight: 700;
  font-size: 18px;
  fill: #ffffff;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 3;
  stroke-linejoin: round;
  font-variant-numeric: tabular-nums;
}
.schema .tank-label .tank-key {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  stroke-width: 2.5;
}

/* Pipes */
.schema .pipe {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.schema .pipe.hot     { stroke: var(--pipe-hot);     }
.schema .pipe.cold    { stroke: var(--pipe-cold);    }
.schema .pipe.neutral { stroke: var(--pipe-neutral); }

.schema .arrow.hot  { fill: var(--pipe-hot);  }
.schema .arrow.cold { fill: var(--pipe-cold); }

/* Flow animation — active when pump is on (class added from JS) */
.schema .pipe.flowing,
.schema .heat-coil.flowing {
  stroke-dasharray: 14 10;
  animation: flow 1.6s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -24; } }

/* Solar-Heizspirale im 800L-Tank */
.schema .heat-coil {
  fill: none;
  stroke: var(--pipe-hot);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

/* PV ↔ Grid: Sankey-Stream, Strichstärke skaliert mit Leistung */
.schema .pv-stream {
  fill: none;
  stroke: var(--pipe-pv);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 14 10;
  animation: flow 1.6s linear infinite;
  transition: stroke-width 0.5s ease, stroke 0.3s;
}
.schema .pv-stream.feeding   { stroke: var(--pv-gen); }
.schema .pv-stream.consuming { stroke: var(--pv-use); animation-direction: reverse; }

/* Solar-Batterie-Symbol: realistisches Glasgefäß mit Metallpolen */

/* Pluspol-Nub oben + breiter Boden-Sockel: silbrig-metallisch */
.schema .batt-term,
.schema .batt-base {
  fill: url(#battMetal);
  filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.35));
}

/* Hauptkörper: Glas-Optik mit vertikalem Farbverlauf */
.schema .batt-body {
  fill: url(#battGlass);
}

/* Metallischer Rahmen ringsum (auf Gloss gelegt für klare Kante) */
.schema .batt-body-rim {
  stroke: url(#battMetal);
  stroke-width: 1.8;
}

/* Lichtreflexe-Streifen auf dem Glas */
.schema .batt-body-gloss {
  fill: url(#battGloss);
}

/* Füllstand (farblich dynamisch per JS via socColor) */
.schema .batt-fill {
  fill: hsl(120, 70%, 45%);
  transition: height 0.9s ease, y 0.9s ease, fill 0.4s;
}

/* Flüssigkeits-Schein über dem Fill: heller Meniskus + dunkler Boden */
.schema .batt-fill-sheen {
  fill: url(#battFillSheen);
}

/* SoC-Prozentzahl: kräftiger Halo für Lesbarkeit auf Glas/Fill */
.schema .batt-percent {
  font-weight: 700;
  font-size: 22px;
  fill: var(--fg);
  dominant-baseline: central;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 3.5;
  stroke-linejoin: round;
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) {
  .schema .batt-percent { stroke: rgba(15, 19, 24, 0.85); }
}
.schema .batt-power {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  fill: var(--muted);
  dominant-baseline: central;
  font-variant-numeric: tabular-nums;
}
.schema .batt-power.charging    { fill: var(--pv-gen); }
.schema .batt-power.discharging { fill: var(--pv-use); }

/* Batterie-Link: horizontale Linie Akku → pv-stream-Kreuzung.
   Animationsrichtung kehrt sich je nach Laden/Entladen um. */
.schema .batt-flow .batt-link {
  display: none;
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 14 10;
  animation: flow 1.6s linear infinite;
  transition: stroke-width 0.5s ease, stroke 0.3s;
}
.schema .batt-flow.charging    .batt-link {
  display: inline;
  stroke: var(--pv-gen);
  animation-direction: reverse;    /* Fluss pv-stream → Akku (links → rechts) */
}
.schema .batt-flow.discharging .batt-link {
  display: inline;
  stroke: var(--pv-use);
                                   /* Fluss Akku → pv-stream → Grid (rechts → links) */
}
/* Status LEDs */
.schema .led {
  fill: var(--led-off);
  transition: fill 0.25s, filter 0.25s;
}
.schema .led.on {
  fill: var(--led-on);
  filter: drop-shadow(0 0 6px var(--led-on));
}

/* =================== KACHELN =================== */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.tile {
  background: var(--tile-bg);
  border-radius: 12px;
  padding: 16px 14px;
  box-shadow: var(--tile-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  min-height: 86px;
}
.tile .cap {
  font-size: 13px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500;
}
.tile .val {
  font-size: 32px; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  line-height: 1.1;
}
.tile.hot  .val { color: var(--hot);    }
.tile.cold .val { color: var(--cold);   }
.tile.warm .val { color: var(--warm);   }
.tile.pv   .val { color: var(--pv-gen); }
.tile.use  .val { color: var(--pv-use); }

/* =================== TAGESBILANZ-STREIFEN =================== */

.daily-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--tile-bg);
  border-radius: 12px;
  box-shadow: var(--tile-shadow);
}
.daily-strip .stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  text-align: center;
}
.daily-strip .stat-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500;
}
.daily-strip .stat-value {
  font-size: 24px; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.daily-strip .stat-value.pv   { color: var(--pv-gen); }
.daily-strip .stat-value.use  { color: var(--pv-use); }
.daily-strip .stat-value.warm { color: var(--warm);   }

/* =================== SONNENSTAND-WIDGET =================== */

.sun-widget { width: 100%; height: auto; display: block; }
.sun-widget .sun-path {
  fill: none; stroke: var(--muted); stroke-width: 1;
  stroke-dasharray: 3 4; opacity: 0.55;
}
.sun-widget .sun-horizon {
  stroke: var(--muted); stroke-width: 1.2; opacity: 0.6;
}
.sun-widget .sun {
  fill: #ffb74d; stroke: #f57c00; stroke-width: 2;
  filter: drop-shadow(0 0 8px #ffb74d);
  transition: cx 30s linear, cy 30s linear;
}
.sun-widget .sun-time {
  fill: var(--muted); font-size: 11px; font-weight: 500;
  font-family: inherit; font-variant-numeric: tabular-nums;
}
.sun-widget .sun-now { fill: var(--fg); font-weight: 600; }

/* =================== EMBED (Regenradar) =================== */

.chart-card .iframe-embed {
  width: 100%; height: 320px; border: 0; display: block;
  border-radius: 6px;
}

/* =================== HOVER-TOOLTIP (Komponente → Werte + 24h-Chart) =================== */

.comp-tooltip {
  position: fixed;
  z-index: 50;
  background: var(--tile-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  width: 264px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.comp-tooltip[hidden] { display: none; }
.comp-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}
.comp-tooltip .ct-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.comp-tooltip .ct-rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.comp-tooltip .ct-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.comp-tooltip .ct-row b {
  color: var(--fg);
  font-weight: 600;
}
.comp-tooltip .ct-chart {
  width: 100% !important;
  height: 80px !important;
  display: block;
}

/* SVG-Komponenten klickbar/hoverbar machen */
.schema .comp { cursor: pointer; }
.schema .comp .comp-box { pointer-events: all; }

/* Auf Mobile keine Tooltips (Tap zeigt sie aber kurz) */
@media (max-width: 640px) {
  .comp-tooltip { width: 220px; padding: 10px; font-size: 11px; }
  .comp-tooltip .ct-chart { height: 60px !important; }
}

/* =================== DACHÜBERSICHT (3D-stilisiert) =================== */

.chart-card.house-card {
  grid-column: 1 / -1;
}
.house-view {
  width: 100%;
  max-width: 520px;
  height: auto;
  display: block;
  margin: 8px auto 4px;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.pv-config-legend {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--fg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pv-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 10px;
  align-items: center;
}
.pv-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.pv-kwp {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--fg);
  white-space: nowrap;
}

/* Mobile: Legende einspaltig, kompakt */
@media (max-width: 640px) {
  .pv-config-legend { font-size: 11px; gap: 4px; padding: 9px 12px; }
  .pv-row          { grid-template-columns: 14px 1fr auto; gap: 8px; }
  .pv-swatch       { width: 12px; height: 12px; }
}

/* =================== HEATMAP (umschaltbar: Woche / Monat / Jahr) =================== */

.chart-card.heatmap-card {
  grid-column: 1 / -1;          /* volle Breite, auch im 2-Spalten-Charts-Layout */
  overflow-x: auto;
}

/* Header: Titel links, Toggle rechts */
.heatmap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.heatmap-header h2 { margin: 0; }

/* Segment-Control-Stil-Toggle */
.heatmap-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--border);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}
.heatmap-toggle button {
  background: transparent;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  font-family: inherit;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.heatmap-toggle button:hover { color: var(--fg); }
.heatmap-toggle button.active {
  background: var(--tile-bg);
  color: var(--fg);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* Grid: eine Reihe aus aggregierten Zellen (Woche/Monat/Jahr) */
.heatmap-grid {
  display: grid;
  grid-template-rows: 1fr;
  gap: 4px;
  padding: 10px 0 8px;
  min-height: 88px;
}
.heatmap-grid.mode-days  {
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: minmax(12px, 1fr);
  gap: 3px;
  min-height: 220px;
}
.heatmap-grid.mode-week  { min-height: 72px; gap: 2px; }
.heatmap-grid.mode-month { min-height: 88px; }
.heatmap-grid.mode-year  { min-height: 104px; }

.heatmap-cell {
  background: var(--border);
  border-radius: 6px;
  cursor: help;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 2px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  overflow: hidden;
}
.heatmap-cell:hover:not(.empty) {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
  z-index: 2;
}
.heatmap-cell.empty { background: transparent; cursor: default; }

/* Zell-Beschriftung: weiß mit dunklem Halo, lesbar auf jeder Temperaturfarbe */
.heatmap-label,
.heatmap-value {
  color: rgba(255, 255, 255, 0.96);
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.85),
               0 1px 2px rgba(0, 0, 0, 0.6);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.heatmap-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.92;
}
.heatmap-value {
  font-size: 15px;
  font-weight: 700;
}

/* Jahr-Modus: größere Zellen → größere Beschriftung */
.heatmap-grid.mode-year .heatmap-label { font-size: 12px; }
.heatmap-grid.mode-year .heatmap-value { font-size: 19px; }

/* Woche- und Tage-Modus: zu eng für Inline-Text, nur farbige Zelle + Tooltip */
.heatmap-grid.mode-week .heatmap-label,
.heatmap-grid.mode-week .heatmap-value,
.heatmap-grid.mode-days .heatmap-label,
.heatmap-grid.mode-days .heatmap-value { display: none; }
.heatmap-grid.mode-week .heatmap-cell,
.heatmap-grid.mode-days .heatmap-cell   { padding: 0; border-radius: 3px; aspect-ratio: 1 / 1; }
.heatmap-legend {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.heatmap-legend .legend-bar {
  flex: 1; height: 10px; border-radius: 5px;
  background: linear-gradient(to right,
    hsl(220,80%,22%)  0%,    /* −15 °C */
    hsl(220,80%,45%)  18%,   /*   0 °C */
    hsl(180,72%,48%)  28%,   /*   5 °C */
    hsl(120,72%,48%)  42%,   /*  15 °C */
    hsl( 60,80%,50%)  56%,   /*  22 °C */
    hsl( 30,90%,50%)  70%,   /*  27 °C */
    hsl(  0,95%,50%)  82%,   /*  30 °C */
    hsl(  0,100%,45%) 100%); /* ≥35 °C */
}

/* =================== CHARTS =================== */

.forecast-legend { font-weight: 400; color: var(--muted); font-size: 11px; margin-left: 4px; }

.charts {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.chart-card {
  background: var(--tile-bg);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--tile-shadow);
}
.chart-card h2 {
  margin: 0 0 10px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.chart-card canvas {
  width: 100% !important;
  height: 220px !important;
  display: block;
}
@media (min-width: 1000px) { .charts { grid-template-columns: 1fr 1fr; } }

/* =================== RESPONSIVE =================== */

/* --- Tablet / schmaler Desktop --- */
@media (max-width: 900px) {
  .tiles        { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .daily-strip  { grid-template-columns: repeat(auto-fit,  minmax(150px, 1fr)); }
}

/* --- Phone (iPhone 17 Pro Max = 440 px Portrait als Leitgerät) --- */
@media (max-width: 640px) {
  header {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }
  header h1    { font-size: 16px; }
  .stand       { font-size: 12px; }
  .btn-icon    {
    padding: 6px 10px;
    font-size: 15px;
    margin-left: 6px;
    -webkit-tap-highlight-color: transparent;
  }

  main { padding: 12px 14px calc(28px + env(safe-area-inset-bottom)); }

  /* Schema: Horizontal scrollbar, damit die Komponenten lesbar bleiben.
     min-width so gewählt, dass SVG-Skalierung bei 440 px Viewport ≈ 0,38
     real-Pixel/SVG-Unit bleibt – Texte & Pipes gut erkennbar. */
  .schema-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  /* Schema-min-width so gewählt, dass die Batterie (endet bei viewBox x=511)
     auf iPhone 17 Pro Max (440 CSS px) vollständig sichtbar ist.
     Sichtbar bei default-Scroll: 440/1000 × 1220 = 537 viewBox-Units. */
  .schema { min-width: 1000px; }
  /* SVG-Texte ausgewogen nachgezogen. Label-Texte (comp-sub / comp-hint)
     bleiben bewusst kleiner als die Werte, damit Wert klar dominiert. */
  .schema .comp-title        { font-size: 20px; }
  .schema .comp-sub          { font-size: 17px; }
  .schema .value             { font-size: 29px; }
  .schema .comp-hint         { font-size: 15px; }
  .schema .tank-label text   { font-size: 24px; }
  .schema .batt-percent      { font-size: 28px; }
  .schema .batt-power        { font-size: 23px; }

  /* Kacheln: 2 Spalten bei 440 px (je ~205 px breit) */
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
  }
  .tile         { padding: 14px 12px; min-height: 82px; gap: 6px; }
  .tile .cap    { font-size: 12px; letter-spacing: 0.04em; }
  .tile .val    { font-size: 26px; }

  /* Tagesbilanz: 2 Spalten */
  .daily-strip {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 14px 16px;
    margin-top: 14px;
  }
  .daily-strip .stat         { gap: 4px; }
  .daily-strip .stat-label   { font-size: 11px; }
  .daily-strip .stat-value   { font-size: 22px; }

  /* Charts kompakt, aber nutzen die 956 px Höhe des Pro Max sinnvoll aus */
  .charts                   { gap: 14px; margin-top: 18px; }
  .chart-card               { padding: 14px 14px 10px; }
  .chart-card h2            { font-size: 13px; margin-bottom: 8px; }
  .chart-card canvas        { height: 200px !important; }
  .chart-card .iframe-embed { height: 300px; }
  .forecast-legend          { display: block; margin-left: 0; margin-top: 2px; font-size: 10px; }

  /* Heatmap auf Mobile etwas kompakter */
  .heatmap-grid.mode-days    { min-height: 160px; gap: 2px; }
  .heatmap-grid.mode-week    { min-height: 60px; }
  .heatmap-grid.mode-month   { min-height: 76px; }
  .heatmap-grid.mode-year    { min-height: 92px; }
  .heatmap-value             { font-size: 13px; }
  .heatmap-grid.mode-year .heatmap-value { font-size: 17px; }
  .heatmap-label             { font-size: 9px; }
  .heatmap-grid.mode-year .heatmap-label { font-size: 11px; }
  .heatmap-toggle button     { padding: 6px 10px; font-size: 13px; }
}

/* --- kleinere iPhones (15/14/13 Regular, Mini, SE Plus) --- */
@media (max-width: 430px) {
  /* Bei 393 px Viewport braucht es min-width ≤ 938 damit Batterie sichtbar.
     940 gibt knapp Luft, Schema skaliert insgesamt mit. */
  .schema                   { min-width: 940px; }
  .schema .comp-title       { font-size: 21px; }
  .schema .comp-sub         { font-size: 18px; }
  .schema .comp-hint        { font-size: 16px; }
  .schema .value            { font-size: 30px; }
  .tile .val                { font-size: 22px; }
  .tile                     { padding: 12px 10px; min-height: 74px; }
  .daily-strip .stat-value  { font-size: 20px; }
  .chart-card canvas        { height: 180px !important; }
  .chart-card .iframe-embed { height: 260px; }
}

/* --- iPhone SE / sehr schmal --- */
@media (max-width: 380px) {
  header h1                 { font-size: 14px; }
  .stand                    { font-size: 11px; }
  .tile .val                { font-size: 20px; }
  .daily-strip .stat-value  { font-size: 18px; }
  .chart-card canvas        { height: 150px !important; }
  .chart-card .iframe-embed { height: 220px; }
}

/* --- Landscape-Smartphones (z. B. iPhone quer im Auto/Küche) --- */
@media (max-width: 900px) and (orientation: landscape) {
  .chart-card .iframe-embed { height: 240px; }
  .chart-card canvas        { height: 170px !important; }
}

/* --- Hohe iPhone-Pro-Max-Klasse: Landscape = 956×440 --- */
@media (min-width: 800px) and (max-height: 500px) and (orientation: landscape) {
  main                      { padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); }
  header                    { padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .chart-card canvas        { height: 180px !important; }
}

/* ============ Header-Action-Button ============ */

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--fg);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  font-family: inherit;
  margin-left: 8px;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--tile-bg); }

/* ============ Kiosk-Modus ============ */

body.kiosk header {
  padding: 4px 14px;
  border-bottom: none;
}
body.kiosk header h1 { font-size: 13px; }
body.kiosk header .stand { font-size: 11px; }
body.kiosk main {
  max-width: none;
  padding: 4px 10px;
}
body.kiosk .tiles,
body.kiosk .charts { display: none; }

/* ============ Alarm-Banner ============ */

.alarm {
  position: sticky;
  top: 0;
  margin: 0;
  padding: 12px 22px;
  background: linear-gradient(90deg, #c62828 0%, #e53935 100%);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  z-index: 20;
  animation: alarm-pulse 1.5s ease-in-out infinite;
}
.alarm[hidden] { display: none; }
.alarm-icon { font-size: 22px; line-height: 1; }
@keyframes alarm-pulse { 50% { filter: brightness(1.15); } }

/* ============ Flammen-Animation (Atmos, Kessel > 80 °C) ============ */

.schema .comp.flaming use[href="#ic-flame"] {
  color: #ff6f28;
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: flame-flicker 0.22s ease-in-out infinite alternate;
}
@keyframes flame-flicker {
  from { transform: scale(1, 1);      }
  to   { transform: scale(0.94, 1.14); }
}

/* ============ Dampfwolke (Gas-Therme, Abgas > 120 °C) ============ */

.schema .steam { display: none; }
body.steaming .schema .steam { display: block; }
.schema .puff {
  fill: rgba(205, 210, 215, 0.75);
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: steam-rise 2.4s ease-out infinite;
}
.schema .puff.p1 { animation-delay: 0s;   }
.schema .puff.p2 { animation-delay: 0.8s; }
.schema .puff.p3 { animation-delay: 1.6s; }
@keyframes steam-rise {
  0%   { transform: translate(0, 0)   scale(0.4); opacity: 0; }
  15%  {                                          opacity: 0.85; }
  100% { transform: translate(6px, -26px) scale(1.5); opacity: 0; }
}
