:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --cold: #3987e5; --hot: #e34948;
  --band: rgba(235, 104, 52, 0.10);
  --pipe: #c3c2b7;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --good-text: #0ca30c;
    --band: rgba(217, 89, 38, 0.16);
    --pipe: #4a4a47;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --good-text: #0ca30c;
  --band: rgba(217, 89, 38, 0.16);
  --pipe: #4a4a47;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 110px; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }

/* Kopf */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px 6px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-status { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 600; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.brennt .dot { background: var(--s2); box-shadow: 0 0 0 3px var(--band); }
.pill.bereit .dot { background: var(--good); }
.pill.stoerung .dot { background: var(--critical); }
.icon-btn { background: none; border: 0; color: var(--ink-2); cursor: pointer; padding: 6px; border-radius: 8px; line-height: 0; font-size: 16px; }
.icon-btn:hover { background: var(--surface-2); }
.tabs { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs a { color: var(--ink-2); text-decoration: none; font-size: 13.5px; padding: 8px 10px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover, .tabs a.active { color: var(--ink); border-bottom-color: var(--ink); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
section { margin-bottom: 36px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0 12px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.grid2, .grid3 { margin-bottom: 14px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.chart { position: relative; width: 100%; }
.h140 { height: 140px; } .h180 { height: 180px; } .h240 { height: 240px; } .h260 { height: 260px; } .h320 { height: 320px; }

/* Segment-Umschalter */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 13px; padding: 4px 12px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 14px; }
.kpis .card { margin-bottom: 0; }
@media (max-width: 900px) { .kpis { grid-template-columns: 1fr 1fr; } .kpis .hero { grid-column: 1 / -1; } }
.kpi-label { font-size: 13px; color: var(--ink-2); }
.kpi-value { font-size: 26px; font-weight: 600; margin-top: 2px; }
.kpi.hero .kpi-value { font-size: 44px; line-height: 1.1; }
.kpi-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.hinweise { display: grid; gap: 8px; margin-top: 14px; }
.hinweis { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-size: 13.5px; }
.hinweis .ic { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; }
.hinweis.warning .ic { background: var(--warning); color: #0b0b0b; }
.hinweis.critical .ic { background: var(--critical); }
.hinweis.info .ic { background: var(--s1); }
.hinweis b { font-weight: 600; }

/* Schema */
.schema-card { overflow: hidden; }
#schema svg { width: 100%; height: auto; display: block; }
#schema text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--ink); }
#schema .lbl { font-size: 13px; font-weight: 600; }
#schema .val { font-size: 22px; font-weight: 600; }
#schema .sm { font-size: 12px; fill: var(--ink-2); }
#schema .mut { font-size: 11px; fill: var(--muted); }
#schema .box { fill: var(--surface-2); stroke: var(--border); }
#schema .pipe { fill: none; stroke: var(--pipe); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
#schema .flow { fill: none; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 2 12; opacity: 0; }
#schema .flow.on { opacity: .9; animation: flow 1.1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -14; } }
@media (prefers-reduced-motion: reduce) { #schema .flow.on { animation: none; stroke-dasharray: none; opacity: .5; } }
#schema .pump { fill: var(--surface); stroke: var(--muted); stroke-width: 2; }
#schema .pump.on { stroke: var(--good); }
#schema .pump-tri { fill: var(--muted); }
#schema .pump.on + .pump-tri { fill: var(--good); }
#schema .flame { fill: var(--s2); opacity: 0; transition: opacity .3s; }
#schema .flame.on { opacity: 1; animation: flicker 1.4s ease-in-out infinite alternate; transform-origin: center bottom; transform-box: fill-box; }
@keyframes flicker { from { transform: scaleY(.9); } to { transform: scaleY(1.08); } }
@media (max-width: 700px) { #schema { overflow-x: auto; } #schema svg { min-width: 720px; } }

/* Effizienz-Kacheln */
.eff-tiles, .tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-content: start; }
.tiles { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile .kpi-value { font-size: 24px; }
.tile .explain { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.tile.wide { grid-column: 1 / -1; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--good-text); }
.status.warning { color: var(--ink-2); } .status.warning::before { background: var(--warning); }
.status.critical { color: var(--critical); }

/* Häuser */
.houses { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 14px; }
.house { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.house-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.house-head .key { width: 12px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 6px; vertical-align: middle; }
.house .typ { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.house dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; font-size: 13px; }
.house dt { color: var(--ink-2); }
.house dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pumpstate { white-space: nowrap; font-size: 12px; font-weight: 600; display: inline-flex; gap: 5px; align-items: center; }
.pumpstate::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pumpstate.on::before { background: var(--good); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th { text-align: right; font-weight: 600; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
table.data td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tr.sum td { font-weight: 600; border-top: 1px solid var(--axis); }
table.data tr.season td { background: var(--surface-2); font-weight: 600; color: var(--ink-2); }
.bar-cell { display: inline-block; height: 8px; border-radius: 0 4px 4px 0; background: var(--s1); vertical-align: middle; margin-right: 6px; }

.note { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.legend-band { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.legend-band i { width: 14px; height: 10px; background: var(--band); border-radius: 2px; display: inline-block; }
.foot { padding: 12px 0 30px; border-top: 1px solid var(--border); }

/* Dialog */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 18px 20px; width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 18px 0 6px; color: var(--ink); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin: 0; }
.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 10px 0; }
.form-row label { display: flex; flex-direction: column; font-size: 12.5px; color: var(--ink-2); gap: 3px; }
.form-row label.grow { flex: 1; min-width: 160px; }
input { font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--axis); border-radius: 8px; background: var(--page); color: var(--ink); min-width: 0; }
.btn { font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 8px; border: 0; background: var(--ink); color: var(--surface); cursor: pointer; }
.btn.ghost { background: none; color: var(--critical); padding: 2px 6px; }
#s-msg.err { color: var(--critical); } #s-msg.ok { color: var(--good-text); }
