/* Hausseite – Kern: Grundgerüst, Kopf, Raster, Bausteine für Module (Kachel, Knopf, Reiter), Tür, Vollbild-Dialoge.
   Nur dunkel (Dauerbetrieb an der Wand). Modul-eigene Regeln stehen in module/<id>/modul.css (Klassen .m-<id>). */
@font-face { font-family: "Barlow"; src: url("/fonts/barlow-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlowcondensed-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Barlow Condensed"; src: url("/fonts/barlowcondensed-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  color-scheme: dark;
  --grund: #0c1116;
  --flaeche: #151c23;
  --flaeche-2: #1c252e;
  --linie: #26313b;
  --raster: #222c35;
  --text: #eef2f5;
  --text-2: #a9b5bf;
  --text-3: #74818c;
  /* Diagramm-Reihen (Kategorie-Palette, dunkel; geprüft gegen #151c23) */
  --reihe-1: #3987e5;   /* Haus  / Außen  */
  --reihe-2: #d95926;   /* PV    / Warmwasser */
  --reihe-3: #199e70;   /* WP */
  /* Status (nur mit Symbol + Wort) */
  --gut: #0ca30c;
  --warn: #fab219;
  --ernst: #ec835a;
  --kritisch: #d03b3b;
  --gut-text: #4cc94c;
  --ernst-text: #f09a77;
  --rand: 16px;
  --abstand: clamp(8px, 1.1vw, 14px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--grund);
  color: var(--text);
  font-family: "Barlow", system-ui, sans-serif;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

/* Nachtdimmung: Overlay ist billiger als filter() auf der ganzen Seite */
#nacht { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 50; transition: opacity 2s; }
body.nacht #nacht { opacity: .5; }

/* ---------- Login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: var(--rand); }
.loginkarte { width: min(420px, 100%); padding: 28px; display: grid; gap: 12px; }
.loginkarte h1 { margin: 0; font-family: "Barlow Condensed"; font-weight: 600; font-size: 40px; }
.loginkarte label { color: var(--text-2); font-size: 15px; }
.loginkarte input { font: inherit; font-size: 20px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--linie);
  background: var(--grund); color: var(--text); user-select: text; }
.loginkarte button { font-size: 20px; padding: 12px; border-radius: 10px; border: 0; background: var(--reihe-1); color: #fff; cursor: pointer; }
.leise { color: var(--text-2); margin: 0; }
.fehler { color: var(--ernst-text); margin: 0; min-height: 1.3em; }

/* ---------- Seite: Querformat füllt genau den Bildschirm ---------- */
#seite {
  height: 100vh; height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--abstand);
  padding: var(--abstand) max(var(--rand), env(safe-area-inset-right)) var(--abstand) max(var(--rand), env(safe-area-inset-left));
}
.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 16px; }

.kopf { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; min-width: 0; }
.uhr { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
#uhrzeit { font-family: "Barlow Condensed"; font-weight: 600; font-size: clamp(40px, 6.2vh, 64px); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
#datum { color: var(--text-2); font-size: clamp(16px, 2.6vh, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kopf-rechts { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hinweis { color: var(--warn); font-size: clamp(14px, 2vh, 19px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Touch-Ziele ≥ 48 px (Wandtablet, Finger) */
.tuerknopf { position: relative; display: flex; align-items: center; gap: 8px; background: var(--flaeche-2); border: 1px solid var(--linie);
  border-radius: 12px; padding: 6px 16px; min-height: 48px; font-size: clamp(16px, 2.2vh, 20px); cursor: pointer; }
.tuerknopf.rund { padding: 6px 10px; min-width: 48px; justify-content: center; }
.tuerpunkt { position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%; background: var(--warn); border: 2px solid var(--grund); }
.stand { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: clamp(14px, 2vh, 19px); white-space: nowrap; min-width: 0; }
#standtext { overflow: hidden; text-overflow: ellipsis; }   /* lange Meldung am Handy: kürzen statt seitlich überlaufen */
.stand .punkt { flex: none; }
.stand .punkt { width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); }
.stand.ok .punkt { background: var(--gut); }
.stand.warn { color: var(--warn); }
.stand.warn .punkt { background: var(--warn); }
/* Hinweisband der Module (kern/hinweise.js): quer neben dem Datum, höchstens 2 Zeilen → Kopf bleibt so hoch wie die Knöpfe */
.kopfband { flex: 0 50 auto; min-width: 0; max-width: 50%; margin-right: auto; align-self: center; display: flex; align-items: center;
  gap: 8px; min-height: 48px; padding: 3px 12px; border-radius: 12px; border: 1px solid var(--linie); background: var(--flaeche-2);
  color: var(--text); font-size: clamp(14px, 2.2vh, 20px); line-height: 1.2; text-align: left; cursor: pointer; }
.kopfband .s-ic { width: 1.2em; height: 1.2em; flex: none; }
.kopfband.warn { border-color: var(--warn); background: #2a2413; }
.kopfband.warn .s-ic { color: var(--warn); }
.kopfband.info .s-ic { color: #86b6ef; }
.kopfband-text { min-width: 0; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.kopfband-zahl { flex: none; color: var(--text-2); font-size: .85em; font-variant-numeric: tabular-nums; }
/* quer mit Band: Uhr/Datum und rechte Seite behalten ihre Breite, nur das Band teilt sich den Rest (wird zweizeilig);
   schmal quer (960 px) zusätzlich kein Datum und „Ansichten“ nur als Symbol – Platz für ≤ 80 Zeichen in 2 Zeilen */
@media (min-width: 761px) and (min-aspect-ratio: 1001/1000) {
  body.mit-band .uhr, body.mit-band .kopf-rechts { flex-shrink: 0; }
}
@media (min-width: 761px) and (max-width: 1100px) and (min-aspect-ratio: 1001/1000) {
  body.mit-band #datum { display: none; }
  body.mit-band #ansichten-knopf span { display: none; }
  body.mit-band #ansichten-knopf { padding: 6px 10px; min-width: 48px; justify-content: center; }
}

/* ---------- Raster: quer 12 × 6 Zellen (S 3×2, M 6×2, H 3×4, L 6×4, G 9×4, B 12×2, XL 12×4) ---------- */
#raster {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: var(--zeilen, repeat(6, minmax(0, 1fr)));     /* --zeilen: raster.js (Kachel-Zeilen nach Inhalt) */
  grid-auto-flow: row dense;
  gap: var(--abstand);
  min-height: 0;
}
/* Plätze rechnet raster.js aus (--x/--y/--w/--h); was nicht passt, wird ausgeblendet */
.slot { position: relative; min-width: 0; min-height: 0; overflow: hidden; container: modul / size;
  grid-column: var(--x, auto) / span var(--w, 12); grid-row: var(--y, auto) / span var(--h, 2); }
.slot.passt-nicht { display: none; }
.slot[data-hoehe=inhalt] { container-type: inline-size; }   /* Höhe nach Inhalt (size-Containment hätte Höhe 0) */
.slot-inhalt { height: 100%; min-width: 0; min-height: 0; }
.slot-zustand { position: absolute; top: 8px; right: 10px; z-index: 4; pointer-events: none; font-size: 13px; color: var(--warn);
  background: var(--flaeche-2); border: 1px solid var(--linie); border-radius: 999px; padding: 2px 10px; }
.slot[data-zustand=laedt] > .slot-zustand { color: var(--text-3); }
.fehlerkachel { height: 100%; padding: 14px 18px; display: grid; align-content: center; gap: 6px; overflow: hidden; }
.fehlerkachel h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 19px; color: var(--warn); }
.fehlerkachel p { margin: 0; color: var(--text-2); }
.passt-nicht.hinweis { color: var(--text-3); }

/* ---------- Bausteine für Module: Kachel mit Titel, großer Zahl, Untertext ---------- */
.kachel { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 16px; padding: clamp(10px, 1.6vh, 18px) clamp(12px, 1.4vw, 20px);
  min-width: 0; min-height: 0; display: flex; flex-direction: column; transition: opacity .6s; }
.kachel h2 { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text-2);
  font-size: clamp(15px, 2.2vh, 22px); white-space: nowrap; overflow: hidden; }
.ic { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.marke { margin-left: auto; font-size: .72em; color: var(--text-3); border: 1px solid var(--linie); border-radius: 999px; padding: 1px 9px; overflow: hidden; text-overflow: ellipsis; }
.wert { display: flex; align-items: baseline; gap: 6px; margin-top: auto; padding-top: 4px; min-width: 0; }
.zahl { font-family: "Barlow Condensed"; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gross .zahl { font-size: clamp(44px, 10vh, 104px); }
.klein .zahl { font-size: clamp(30px, 5.6vh, 58px); }
.zahl.wort { font-size: clamp(26px, 4.6vh, 48px); overflow: hidden; text-overflow: ellipsis; }
.einheit { color: var(--text-2); font-size: clamp(18px, 3vh, 32px); white-space: nowrap; }
.unter { margin: 6px 0 0; color: var(--text-2); font-size: clamp(14px, 2vh, 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.unter .s-ic { width: 1em; height: 1em; flex: none; }
.unter.gut { color: var(--gut-text); }
.unter.ernst { color: var(--ernst-text); }
.unter.warn { color: var(--warn); }
.kachel.aus { opacity: .38; }
.kachel.alarm { border-color: var(--warn); }

/* Knöpfe und Reiter */
.knopf { background: var(--flaeche-2); border: 1px solid var(--linie); border-radius: 10px; width: 48px; height: 48px; font-size: 24px; line-height: 1; cursor: pointer; }
.knopf:disabled { opacity: .3; cursor: default; }
.knopf.breit { width: auto; padding: 0 18px; height: 48px; font-size: 18px; }
.reiter { display: flex; background: var(--grund); border: 1px solid var(--linie); border-radius: 10px; padding: 3px; }
.reiter-k { background: none; border: 0; border-radius: 8px; padding: 7px 14px; min-height: 48px; color: var(--text-2); font-size: clamp(15px, 2vh, 18px); cursor: pointer; }
.reiter-k.aktiv { background: var(--flaeche-2); color: var(--text); }
.klein { font-size: 14px; margin-top: 10px; }
.warnung { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--warn); border-radius: 10px; color: var(--text); font-size: 15px; line-height: 1.4; }
.warnung a { color: var(--warn); }
.textknopf { background: none; border: 0; color: var(--text-3); text-decoration: underline; cursor: pointer; padding: 6px 0; font-size: 14px; }

/* ---------- Hochformat / Handy: 2 Spalten, Höhe nach Inhalt, Seite scrollt ---------- */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  #seite { height: auto; min-height: 100dvh; grid-template-rows: auto auto; }
  #raster { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: auto; grid-auto-flow: row; }
  .slot { container-type: inline-size; grid-column: 1 / -1; grid-row: auto; }
  .slot.passt-nicht { display: block; }
  .slot[data-g=S], .slot[data-g=H] { grid-column: span 1; }
  .slot[data-g=L], .slot[data-g=G], .slot[data-g=XL] { min-height: clamp(260px, 70vw, 440px); }
  .unter { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .gross .zahl { font-size: clamp(40px, 11vw, 72px); }
  .klein .zahl { font-size: clamp(30px, 8vw, 52px); }
  .zahl.wort { font-size: clamp(24px, 6.5vw, 40px); }
  #uhrzeit { font-size: clamp(38px, 11vw, 60px); }
  #datum { font-size: clamp(15px, 4vw, 22px); }
  .kopf { flex-wrap: wrap; }
  .kopf-rechts { width: 100%; justify-content: space-between; }
  .hinweis { order: 3; width: 100%; }
  .kopfband { order: 3; max-width: none; width: 100%; margin-right: 0; font-size: clamp(16px, 4.2vw, 20px); }
  .kopfband-text { display: block; }                  /* hochkant ist Platz nach unten: ganzer Text */
}
@media (max-width: 380px) {
  .kachel h2 { font-size: 14px; }
  .marke { display: none; }
}
/* Handy: „Ansichten“ nur als Symbol (aria-label bleibt) – sonst wird „live · vor 7 s“ zu „li…“ gekürzt */
@media (max-width: 520px) {
  #ansichten-knopf span { display: none; }
  #ansichten-knopf { padding: 6px 10px; min-width: 48px; justify-content: center; }
}

/* ---------- Textseiten (Datenschutz) ---------- */
body.textseite { user-select: text; overflow-y: auto; }
main.text { max-width: 760px; margin: 0 auto; padding: 32px var(--rand) 48px; line-height: 1.55; font-size: 17px; }
main.text h1 { font-family: "Barlow Condensed"; font-weight: 600; font-size: 40px; margin: 0 0 4px; }
main.text h2 { font-size: 20px; font-weight: 500; margin: 28px 0 6px; }
main.text p { color: var(--text-2); margin: 0 0 10px; }
main.text a { color: #86b6ef; }

/* ---------- Vollbild-Dialoge (Tür, Einstellungen, eigene Ansichten) ---------- */
.tuer, .vollbild { position: fixed; inset: 0; z-index: 60; background: var(--grund); display: grid; grid-template-rows: auto minmax(0, 1fr);
  gap: var(--abstand); padding: var(--abstand) var(--rand); }
.tuer-kopf { display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap; }
.tuer-kopf h2 { margin: 0; font-family: "Barlow Condensed"; font-weight: 600; font-size: clamp(28px, 4.5vh, 44px); }
.tuer-status { color: var(--text-2); font-size: clamp(15px, 2.2vh, 20px); margin-right: auto; }
.ansicht-inhalt { min-height: 0; overflow: auto; }
.ansicht-modul { height: 100%; }
.ansicht-wahl { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--abstand); align-content: start; }
.ansicht-knopf { display: grid; gap: 6px; text-align: left; background: var(--flaeche); border: 1px solid var(--linie); border-radius: 16px;
  padding: 18px 20px; min-height: 96px; cursor: pointer; }
.ansicht-knopf b { font-weight: 500; font-size: 22px; }
.ansicht-knopf span { color: var(--text-2); font-size: 16px; }

/* ---------- Rückfrage in der Seite (kern/frage.js, statt window.confirm – hält nichts an) ---------- */
.frage { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: var(--rand); background: rgba(6,9,12,.8); }
.frage-karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 18px; padding: 20px 22px; width: min(540px, 100%);
  display: grid; gap: 18px; }
.frage-karte p { margin: 0; font-size: 19px; line-height: 1.45; color: var(--text); }
.frage-knoepfe { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.frage-knoepfe button { min-height: 52px; min-width: 120px; padding: 0 22px; border-radius: 12px; border: 1px solid var(--linie);
  background: var(--flaeche-2); color: var(--text); font-size: 18px; cursor: pointer; }
.frage-knoepfe .frage-ja { background: var(--reihe-1); border-color: var(--reihe-1); color: #fff; }
.frage-knoepfe .frage-ja.gefahr { background: #7a2a1a; border-color: var(--ernst); }
.frage button:focus-visible { outline: 2px solid var(--reihe-1); outline-offset: 2px; }

/* ---------- Haustür (Livebild, Klingel) ---------- */
.tuer.klingelt .tuer-kopf h2 { color: var(--warn); }
.tuer-inhalt { display: grid; grid-template-columns: minmax(0, 1fr) clamp(220px, 22vw, 300px); gap: var(--abstand); min-height: 0; }
.tuer-bild { position: relative; background: #000; border-radius: 16px; overflow: hidden; min-height: 0; }
.tuer-bild video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.tuer-meldung { position: absolute; inset: 0; display: grid; place-content: center; gap: 14px; text-align: center; padding: 20px;
  color: var(--text-2); font-size: 20px; background: rgba(12,17,22,.82); }
.tuer-meldung a, .tuer-meldung button { justify-self: center; background: var(--reihe-1); color: #fff; border: 0; border-radius: 10px;
  padding: 12px 20px; font-size: 18px; text-decoration: none; cursor: pointer; }
.clip-zurueck { position: absolute; left: 12px; bottom: 12px; z-index: 2; }
.tuer-liste { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 16px; padding: 12px 14px; overflow-y: auto; min-height: 0; }
.tuer-liste h3 { margin: 0 0 8px; font-weight: 500; color: var(--text-2); font-size: 18px; }
.tuer-liste ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tuer-liste li { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 8px 10px; border-radius: 10px;
  background: var(--flaeche-2); font-size: 17px; font-variant-numeric: tabular-nums; }
.tuer-liste li button { background: none; border: 1px solid var(--linie); border-radius: 8px; padding: 5px 10px; cursor: pointer; color: var(--text); }
.tuer-liste .leer { color: var(--text-3); background: none; padding: 4px 0; }
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  .tuer { overflow-y: auto; grid-template-rows: auto auto; align-content: start; }
  .tuer-inhalt { align-content: start; }
  .tuer-liste { overflow: visible; }
  .tuer-inhalt { grid-template-columns: 1fr; }
  .tuer-bild { aspect-ratio: 4 / 3; }
}
