:root {
  --hg: #f6f5f2;
  --flaeche: #ffffff;
  --text: #1d1d1f;
  --leise: #6e6e73;
  --rand: #e3e1dc;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --fehler: #c62828;
  --raster: rgba(0, 0, 0, 0.07);
  /* Kategorische Reihen, feste Reihenfolge (dataviz-Referenzpalette, geprüft) */
  --serie-1: #2a78d6;
  --serie-2: #eb6834;
  --serie-3: #1baf7a;
  /* Temperaturstufen der Kacheln, wie die Ofen-Flamme am Display */
  --kalt: #2a78d6;
  --warm: #e0a100;
  --heiss: #e3661c;
  --sehr-heiss: #d93a2b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --hg: #151517;
    --flaeche: #1f1f22;
    --text: #ececef;
    --leise: #9a9aa2;
    --rand: #2e2e33;
    --ok: #5cc28a;
    --warn: #f0a63a;
    --fehler: #ef6b6b;
    --raster: rgba(255, 255, 255, 0.08);
    --serie-1: #3987e5;
    --serie-2: #d95926;
    --serie-3: #199e70;
    --kalt: #3987e5;
    --warm: #d9a20f;
    --heiss: #f07224;
    --sehr-heiss: #ef5a4a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--hg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rand);
}

h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--leise); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
section { margin-bottom: 28px; }

.status { font-size: 13px; padding: 3px 10px; border-radius: 999px; border: 1px solid currentColor; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.fehler { color: var(--fehler); }

.kacheln {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.kachel {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 10px;
  padding: 10px 12px;
}

.kachel { border-top: 4px solid var(--rand); }
.kachel.kalt { border-top-color: var(--kalt); }
.kachel.warm { border-top-color: var(--warm); }
.kachel.heiss { border-top-color: var(--heiss); }
.kachel.sehr_heiss { border-top-color: var(--sehr-heiss); }
.kachel.kalt .wert { color: var(--kalt); }
.kachel.warm .wert { color: var(--warm); }
.kachel.heiss .wert { color: var(--heiss); }
.kachel.sehr_heiss .wert { color: var(--sehr-heiss); }
.kacheln.veraltet .kachel { border-top-color: var(--rand); }

.kachel .name { font-size: 13px; color: var(--leise); }
.kachel .wert { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kachel .einheit { font-size: 15px; color: var(--leise); margin-left: 2px; font-weight: 400; }
.kachel .fehlertext { font-size: 15px; color: var(--fehler); padding: 6px 0; }
.kachel.gross .wert { font-size: 38px; }
.kacheln.veraltet .wert { color: var(--leise); }

.kopf { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }

.zeitraum button {
  background: var(--flaeche);
  color: var(--text);
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.zeitraum button.aktiv { border-color: var(--text); font-weight: 600; }

.diagramm {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 10px;
  padding: 10px 6px 4px;
  margin-bottom: 12px;
}
.diagramm h3 { font-size: 14px; margin: 0 8px 4px; }

.uplot, .u-legend { color: var(--text); font-family: inherit; }
.u-legend { font-size: 13px; }

/* --- Kopf: Burger-Menü mit Navigation und Anmeldung --- */
header { position: relative; flex-wrap: nowrap; }
h1 { margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seitentitel { color: var(--leise); font-weight: 400; }
.marke + .seitentitel::before { content: " · "; }
/* schmal: nur der Seitenname, damit Status und Menüknopf Platz haben */
@media (max-width: 480px) {
  .marke { display: none; }
  .marke + .seitentitel::before { content: none; }
  .seitentitel { color: var(--text); font-weight: 600; }
}
.status { white-space: nowrap; }
button.burger { display: flex; flex-direction: column; justify-content: center; gap: 4px; width: 40px; height: 36px; padding: 0 9px; }
button.burger span { display: block; height: 2px; background: currentColor; border-radius: 1px; transition: transform 0.15s, opacity 0.15s; }
button.burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
button.burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
button.burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
@media (prefers-reduced-motion: reduce) { button.burger span { transition: none; } }
.menue {
  position: absolute; top: calc(100% + 4px); right: 16px; z-index: 10;
  min-width: 220px; max-width: calc(100vw - 32px);
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 6px;
}
.menue[hidden] { display: none; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  color: var(--text);
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 6px;
}
nav a:hover { background: var(--hg); }
nav a.aktiv { background: var(--hg); border: 1px solid var(--rand); font-weight: 600; }
.anmeldung { display: flex; flex-direction: column; gap: 6px; font-size: 14px; margin-top: 6px; padding: 10px 12px 6px; border-top: 1px solid var(--rand); }
.anmeldung strong { margin-top: -4px; }
.anmeldung button { align-self: flex-start; }

button {
  background: var(--flaeche);
  color: var(--text);
  border: 1px solid var(--rand);
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
}
button.link { background: none; border: none; padding: 0; color: var(--text); text-decoration: underline; }
button.haupt { border-color: var(--text); font-weight: 600; }
button.gefahr { color: var(--fehler); }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.leise { color: var(--leise); }
.fehlertext { color: var(--fehler); }

/* --- Anmeldedialog und Formulare --- */
dialog {
  background: var(--flaeche);
  color: var(--text);
  border: 1px solid var(--rand);
  border-radius: 10px;
  padding: 18px;
  width: min(340px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
label { display: block; font-size: 13px; color: var(--leise); margin: 10px 0 4px; }
input:not([type=checkbox]) {
  display: block;
  width: 100%;
  margin: 0;
  padding: 7px 9px;
  font: inherit;
  font-size: 16px;  /* unter 16 px zoomt Safari auf dem iPhone beim Antippen hinein */
  color: var(--text);
  background: var(--hg);
  border: 1px solid var(--rand);
  border-radius: 6px;
}
.knoepfe { margin-top: 14px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

/* --- Kamin: Phase als Text, Störung, Bedienung --- */
.kachel .wert.text { font-size: 22px; }
.kachel.gross .wert.text { font-size: 30px; }
.kachel.stoerung { border-top-color: var(--fehler); }
.kachel.stoerung .wert { color: var(--fehler); }

.bedienung .knoepfe { justify-content: flex-start; margin: 0 0 10px; }
button.befehl {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 160px;
  padding: 12px 16px;
  border-radius: 10px;
}
button.befehl .titel { font-size: 20px; font-weight: 600; }
button.befehl .hinweis { font-size: 13px; color: var(--leise); }
.antwort { margin-top: 8px; font-size: 14px; }
.antwort.ok { color: var(--ok); }
.antwort.fehler { color: var(--fehler); }

/* --- Tür --- */
button.befehl.halten { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button.befehl.halten .balken { position: absolute; left: 0; bottom: 0; height: 5px; width: 0; background: var(--warm); }
.schlossflaeche {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-top: 4px solid var(--rand);
  border-radius: 10px;
  padding: 14px 16px;
}
.schlossflaeche .zustand { font-size: 30px; font-weight: 600; overflow-wrap: anywhere; }
.schlossflaeche .details { margin-top: 4px; font-size: 15px; color: var(--leise); }
.schlossflaeche.abgeschlossen { border-top-color: var(--ok); }
.schlossflaeche.abgeschlossen .zustand { color: var(--ok); }
.schlossflaeche.offen { border-top-color: var(--warn); }
.schlossflaeche.offen .zustand { color: var(--warn); }
.schlossflaeche.stoerung { border-top-color: var(--fehler); }
.schlossflaeche.stoerung .zustand { color: var(--fehler); font-size: 20px; }
/* drei gleich breite Knöpfe, am Handy untereinander */
.bedienung.tuer .knoepfe { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.bedienung.tuer button.befehl { min-width: 0; }

/* --- Benutzer --- */
table { width: 100%; border-collapse: collapse; background: var(--flaeche); border: 1px solid var(--rand); border-radius: 10px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rand); vertical-align: top; }
th { font-size: 13px; color: var(--leise); font-weight: 600; }
.rollen { display: flex; flex-wrap: wrap; gap: 4px 14px; }
label.haken { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--text); font-size: 14px; }
td.aktionen { white-space: nowrap; text-align: right; }
td input.email { min-width: 180px; padding: 4px 7px; }
td.aktionen button { margin-left: 6px; font-size: 13px; padding: 4px 9px; }
form.neu {
  margin-top: 18px;
  max-width: 420px;
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 10px;
  padding: 14px;
}
form.neu h3 { margin: 0 0 10px; font-size: 14px; }
form.neu .rollen { margin: 4px 0 12px; }

/* --- Rollos --- */
.rollos { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 12px; margin-top: 8px; }
.rollo {
  background: var(--flaeche);
  border: 1px solid var(--rand);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 0;
}
.rollo h3 { margin: 0; font-size: 17px; }
/* Schalter eingeschaltet: Rand in der Akzentfarbe */
.schalter.an { border-color: var(--ok); }
.schalter .wert.text { margin: 8px 0 2px; }
/* Motor läuft (faehrt aus dem Backend): pulsierender Rand */
.rollo.faehrt { border-color: var(--warn); animation: faehrt 1.2s ease-in-out infinite; }
@keyframes faehrt { 50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 35%, transparent); } }
@media (prefers-reduced-motion: reduce) { .rollo.faehrt { animation: none; box-shadow: 0 0 0 2px var(--warn); } }
/* Hinweis, kein Fehler: Info-Zeichen, dann Text */
.rollo .info { margin: 6px 0 2px; font-size: 14px; color: var(--leise); }
.rollo .info::before { content: "i"; display: inline-block; width: 1.25em; height: 1.25em; line-height: 1.25em; margin-right: 6px; border: 1.5px solid currentColor; border-radius: 50%; text-align: center; font-size: 12px; font-weight: 700; font-style: italic; font-family: Georgia, serif; vertical-align: 1px; }
.rollo .knoepfe { justify-content: flex-start; margin: 10px 0; }
.rollo .knoepfe button { min-width: 72px; padding: 8px 14px; }
.regler { margin: 12px 0; }
.regler.unbekannt .reglerwert { font-weight: 400; color: var(--leise); }
/* Ohne Wert kein Griff: Safari stylt den Griff nur mit appearance none, daher Regler unsichtbar, Platz bleibt */
.regler.unbekannt input[type=range] { visibility: hidden; }
.reglerkopf { display: flex; justify-content: space-between; font-size: 14px; }
.reglerwert { font-variant-numeric: tabular-nums; font-weight: 600; }
.regler input[type=range] { display: block; width: 100%; padding: 0; margin: 6px 0 2px; background: none; border: none; accent-color: var(--text); }
.skala { display: flex; justify-content: space-between; font-size: 12px; color: var(--leise); }

@media (max-width: 600px) {
  td.aktionen { white-space: normal; }
  td.aktionen button { margin: 0 0 4px 0; }
}

/* --- Wetter: Prognose je Stunde, waagerecht scrollbar --- */
.prognose { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x proximity; }
.prognose .stunde {
  flex: 0 0 64px; scroll-snap-align: start;
  background: var(--flaeche); border: 1px solid var(--rand); border-radius: 10px;
  padding: 8px 4px; text-align: center;
}
.prognose .zeit { font-size: 12px; color: var(--leise); }
.prognose .symbol { font-size: 24px; line-height: 1.4; }
.prognose .temp { font-weight: 600; font-variant-numeric: tabular-nums; }
.prognose .regen { font-size: 12px; color: var(--leise); min-height: 1.2em; }
.prognose.veraltet .temp { color: var(--leise); }

/* Display Settings */
.einstellungen section { max-width: 560px; }
.einstellungen label.haken { font-size: 15px; }
.zahl-einheit { display: flex; align-items: center; gap: 8px; }
.zahl-einheit input { width: 90px; }
.zahl-einheit input[type=datetime-local] { width: auto; }
.zahl-einheit button.vorzeichen { min-width: 44px; padding: 6px 10px; font-size: 18px; }
.knoepfe.links { justify-content: flex-start; align-items: center; }
.knoepfe.links .antwort { margin: 0; }
/* Sollwert zwischen − und + (Seite Thermostat) */
.bedienung .sollwert { font-size: 38px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 130px; text-align: center; }
.bedienung .sollwert .einheit { font-size: 15px; color: var(--leise); margin-left: 2px; font-weight: 400; }

/* Seite Heizung: Prognose Speicher oben, Stunde des Duschens hervorgehoben */
.prognose .marke { font-size: 12px; min-height: 2.4em; }
.urteil .ok { color: var(--ok); }
.urteil .warn { color: var(--warn); }
.urteil .fehler { color: var(--fehler); }
.prognose .dusche.ok { border-color: var(--ok); }
.prognose .dusche.fehler { border-color: var(--fehler); }
.prognose .dusche.ok .temp, .prognose .dusche.ok .marke { color: var(--ok); }
.prognose .dusche.fehler .temp, .prognose .dusche.fehler .marke { color: var(--fehler); }

/* Kamin: Einstellungen der Steuerung, zugeklappt (kamin.js) */
details.einstellungen > summary { cursor: pointer; font-size: 15px; font-weight: 600; color: var(--leise); padding: 6px 0; }
details.einstellungen h3 { font-size: 15px; margin: 16px 0 6px; }
details.einstellungen .stand { font-size: 13px; color: var(--leise); margin-bottom: 6px; }
details.einstellungen td.wert { white-space: nowrap; }
details.einstellungen details.roh { margin-top: 6px; font-size: 13px; color: var(--leise); }
details.einstellungen details.roh pre { margin: 4px 0; }
details.einstellungen input.einstellung { width: 76px; padding: 4px 7px; }
details.einstellungen .schreibstatus { font-size: 13px; margin-top: 4px; white-space: normal; text-align: right; }
details.einstellungen .schreibstatus .ok { color: var(--ok, inherit); }
