/* Heizplan Boltenhagen
   Ostsee-Schiefer für „Passiv“, Bernstein für „Bewohnt“. Eine Schrift: Schibsted Grotesk. */

@font-face {
  font-family: "Schibsted Grotesk";
  src: url("schibsted-grotesk.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #edf1f2;
  --raised: #f8fafa;
  --ink: #13232e;
  --muted: #5b6d76;
  --line: #d2dbde;
  --sea: #24414f;
  --sea-soft: #dbe5e9;
  --sea-ink: #e9f1f3;
  --amber: #e39a2d;
  --amber-deep: #c27717;
  --amber-ink: #2b1904;
  --amber-text: #94560a;
  --amber-soft: #f6e3c4;
  --signal: #b23a2a;
  --signal-soft: #f5dcd7;
  --radius-control: 14px;
  --radius-sheet: 22px;
  --col: 560px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1a21;
    --raised: #15252e;
    --ink: #e4ebed;
    --muted: #8fa2aa;
    --line: #24363f;
    --sea: #1d3644;
    --sea-soft: #1a2d38;
    --sea-ink: #e3edf0;
    --amber: #e8a440;
    --amber-deep: #cf8524;
    --amber-ink: #2b1904;
    --amber-text: #f0b45c;
    --amber-soft: #3a2a12;
    --signal: #f08b7b;
    --signal-soft: #3a1f1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, output, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: 0 1.25rem;
  border-radius: 999px; border: 1px solid transparent;
  font-weight: 650; cursor: pointer;
  transition: transform .08s ease, background-color .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
a.btn { text-decoration: none; color: inherit; }
.btn-amber, a.btn-amber { background: var(--amber); color: var(--amber-ink); }
.btn-amber:hover { background: var(--amber-deep); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-small { min-height: 40px; padding: 0 1rem; font-size: .9375rem; }
.btn-danger { color: var(--signal); border-color: var(--signal-soft); background: transparent; }
.btn[disabled] { opacity: .5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.linkish { background: none; border: 0; padding: 0; color: var(--amber-text); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Anmeldung ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--sea); }
.gate-card { width: 100%; max-width: 380px; border-radius: var(--radius-sheet); overflow: hidden; background: var(--raised); box-shadow: 0 20px 60px rgba(0, 20, 30, .35); }
.gate-field { padding: 2rem 1.5rem 1.5rem; background: var(--sea); color: var(--sea-ink); border-bottom: 1px solid rgba(255, 255, 255, .08); }
.gate-mark { width: 56px; height: 56px; margin-bottom: 1rem; }
.gate-mark .sun { fill: var(--amber); }
.gate-mark .sea { fill: none; stroke: var(--sea-ink); stroke-width: 3; stroke-linecap: round; opacity: .7; }
.gate-field h1 { font-size: 1.5rem; font-weight: 750; letter-spacing: -.01em; line-height: 1.2; }
.gate-field p { margin-top: .4rem; opacity: .8; }
.gate-form { padding: 1.5rem; display: grid; gap: 1rem; }
.gate-form label { display: grid; gap: .35rem; font-weight: 600; font-size: .9375rem; }
.gate-error { background: var(--signal-soft); color: var(--signal); padding: .7rem .9rem; border-radius: 10px; }
.gate-note { background: var(--amber-soft); color: var(--ink); padding: .8rem .9rem; border-radius: 10px; }
.gate-text { color: var(--muted); }
.gate-text strong { color: var(--ink); overflow-wrap: anywhere; }
.gate-hint { font-size: .875rem; color: var(--muted); margin-top: -.5rem; }
.gate-links { text-align: center; font-size: .9375rem; }
.gate-links a { color: var(--amber-text); font-weight: 600; text-underline-offset: 3px; }

input[type=password], input[type=text], input[type=email], input[type=date], input[type=time], input[type=number], input[type=url], select {
  width: 100%; min-height: 48px; padding: .6rem .8rem;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--paper); color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 30%, transparent); }

/* ---------- Kopf ---------- */
.top {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: max(12px, env(safe-area-inset-top)) 16px 4px;
  background: var(--sea); color: var(--sea-ink);
  transition: background-color .7s ease, color .7s ease;
}
.place { min-width: 0; }
.place h1 { font-size: 1.0625rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccu { display: flex; align-items: center; gap: .45rem; font-size: .8125rem; opacity: .85; }
.ccu .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .5; flex: none; }
.ccu[data-state=online] .dot { background: #6fd39a; opacity: 1; box-shadow: 0 0 0 3px rgba(111, 211, 154, .25); }
.ccu[data-state=offline] .dot { background: #ff8a76; opacity: 1; }
body[data-phase=occupied] .top { background: var(--amber); color: var(--amber-ink); }
body[data-phase=paused] .top { background: #4b585e; }

/* ---------- Hero: der Zustand der Wohnung als Farbfläche ---------- */
.hero {
  position: relative; isolation: isolate;
  padding: 1rem 16px 3.25rem;
  background: var(--sea); color: var(--sea-ink);
  transition: color .7s ease;
}
.hero::before, .hero::after {
  content: ""; position: absolute; inset: 0; z-index: -1;
  opacity: 0; transition: opacity .7s ease;
}
.hero::before { background: var(--amber); }
.hero::after { background: linear-gradient(160deg, var(--sea) 0%, var(--sea) 30%, #7a6a4a 70%, var(--amber) 115%); }
.hero[data-phase=occupied] { color: var(--amber-ink); }
.hero[data-phase=occupied]::before { opacity: 1; }
.hero[data-phase=preheat]::after { opacity: 1; }
.hero[data-phase=paused] { background: #4b585e; }
.hero > * { max-width: var(--col); margin-left: auto; margin-right: auto; }

.hero-mode { font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; margin-top: .5rem; }
.hero-temp {
  font-size: clamp(5.5rem, 30vw, 8.5rem); font-weight: 800; line-height: .9;
  letter-spacing: -.055em; margin: .6rem auto .35rem;
  display: flex; align-items: flex-start;
}
.hero-deg { font-size: .45em; font-weight: 600; margin-top: .14em; letter-spacing: 0; opacity: .8; }
.hero-sub { font-size: .9375rem; opacity: .8; }
.hero-note { margin-top: 1rem; font-size: 1.0625rem; line-height: 1.4; max-width: 34ch; font-weight: 500; }
.hero-note strong { font-weight: 750; }
.hero-wave { position: absolute; left: 0; right: 0; bottom: -1px; width: 100%; height: 24px; max-width: none; margin: 0; }
.hero-wave path { fill: var(--paper); }

/* Thermometer-Band 10–25 °C */
.ribbon { position: relative; height: 46px; margin-top: 1.4rem; }
.ribbon-track, .ribbon-fill { position: absolute; left: 0; top: 10px; height: 8px; border-radius: 999px; }
.ribbon-track { right: 0; background: currentColor; opacity: .18; }
.ribbon-fill { width: 0; background: currentColor; opacity: .55; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.hero[data-phase=preheat] .ribbon-fill { background: var(--amber); opacity: 1; }
.ribbon-now, .ribbon-target { position: absolute; top: 14px; width: 0; height: 0; transition: left .8s cubic-bezier(.2, .8, .2, 1); }
.ribbon-now::before {
  content: ""; position: absolute; left: -10px; top: -10px; width: 20px; height: 20px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 22%, transparent);
}
.ribbon-target::before {
  content: ""; position: absolute; left: -2px; top: -14px; width: 4px; height: 28px; border-radius: 2px;
  background: var(--amber);
}
.hero[data-phase=occupied] .ribbon-target::before { background: var(--amber-ink); }
.ribbon-target[hidden], .ribbon-now[hidden] { display: none; }
.ribbon-scale { position: absolute; left: 0; right: 0; top: 26px; font-size: .75rem; opacity: .65; }
.ribbon-scale span { position: absolute; transform: translateX(-50%); }
.ribbon-scale span:nth-child(1) { left: 13.33%; }
.ribbon-scale span:nth-child(2) { left: 40%; }
.ribbon-scale span:nth-child(3) { left: 66.67%; }
.ribbon-scale span:nth-child(4) { left: 93.33%; }

/* ---------- Hauptbereich ---------- */
.main { max-width: calc(var(--col) + 32px); margin: 0 auto; padding: .5rem 16px calc(3rem + env(safe-area-inset-bottom)); }

.control { margin-top: .25rem; }
.switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch button {
  display: grid; justify-items: start; gap: .05rem;
  min-height: 72px; padding: .75rem 1rem;
  border-radius: var(--radius-control);
  border: 1.5px solid var(--line); background: var(--raised);
  text-align: left; cursor: pointer;
  transition: background-color .25s, border-color .25s, color .25s, transform .08s;
  touch-action: manipulation;
}
.switch button:active { transform: scale(.98); }
.switch-name { font-size: 1.1875rem; font-weight: 750; letter-spacing: -.01em; }
.switch-temp { font-size: .875rem; color: var(--muted); }
.switch button[data-mode=passive][aria-checked=true] { background: var(--sea); border-color: var(--sea); color: var(--sea-ink); }
.switch button[data-mode=occupied][aria-checked=true] { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.switch button[aria-checked=true] .switch-temp { color: inherit; opacity: .8; }
.switch button[disabled] { opacity: .55; }

.target {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-top: 14px; padding: .5rem 0 .5rem .25rem;
}
.target[hidden] { display: none; }
.target-label { font-weight: 600; min-width: 0; }
.stepper { display: flex; align-items: center; gap: .25rem; }
.stepper output { min-width: 5.5ch; text-align: center; font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; white-space: nowrap; }
.step {
  width: 48px; height: 48px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--raised);
  font-size: 1.5rem; line-height: 1; cursor: pointer;
  display: grid; place-items: center; touch-action: manipulation;
  transition: transform .08s;
}
.step:active { transform: scale(.92); }
.stepper.big output { font-size: 2rem; min-width: 7ch; }

.sync-note { margin-top: .5rem; font-size: .875rem; color: var(--muted); display: flex; gap: .5rem; align-items: center; }
.sync-note::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--amber); border-right-color: transparent; animation: spin 1s linear infinite; flex: none; }
.sync-note.warn { color: var(--signal); }
.sync-note.warn::before { animation: none; border-color: var(--signal); }
@keyframes spin { to { transform: rotate(360deg); } }
.last-change { margin-top: .5rem; font-size: .875rem; color: var(--muted); }

.block { margin-top: 2.25rem; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.block-head h2 { font-size: 1.25rem; font-weight: 750; letter-spacing: -.015em; }

/* Aufenthalte: echte Zeitfolge, daher als Zeitleiste */
.stays { list-style: none; margin: 0; padding: 0; }
.stay {
  position: relative; padding: .25rem 0 1.25rem 1.75rem;
}
.stay.editable { cursor: pointer; }
.stay-by { font-size: .8125rem; color: var(--muted); }
.stay::before { content: ""; position: absolute; left: 6px; top: 1.1rem; bottom: 0; width: 2px; background: var(--line); }
.stay:last-child::before { display: none; }
.stay::after {
  content: ""; position: absolute; left: 0; top: .45rem; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); background: var(--paper);
}
.stay[data-status=active]::after, .stay[data-status=preheat]::after { border-color: var(--amber); background: var(--amber); }
.stay-when { font-size: 1.0625rem; font-weight: 700; }
.stay-until { color: var(--ink); }
.stay-meta { font-size: .875rem; color: var(--muted); margin-top: .1rem; }
.stay-meta .live { color: var(--amber-text); font-weight: 650; }
.stay-actions { display: flex; gap: .75rem; margin-top: .4rem; }
.empty { color: var(--muted); padding: .25rem 0 .5rem; }

/* Räume */
.rooms { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.room {
  display: grid; grid-template-columns: 1fr auto; gap: .15rem 1rem; align-items: center;
  padding: .85rem 0; border-bottom: 1px solid var(--line);
}
.room-name { font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.room-dev { font-size: .8125rem; color: var(--muted); }
.room-temp { text-align: right; font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.room-temp small { font-size: .55em; font-weight: 600; color: var(--muted); }
.room-set { grid-column: 2; text-align: right; font-size: .8125rem; color: var(--muted); }
.room-set.off-plan { color: var(--amber-text); }
.room-flags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .25rem .75rem; font-size: .8125rem; }
.room-flags:empty { display: none; }
.flag-warn { color: var(--signal); font-weight: 600; }
.flag-info { color: var(--muted); }
.valve { display: inline-block; width: 38px; height: 6px; border-radius: 3px; background: var(--line); vertical-align: middle; margin-left: .3rem; overflow: hidden; }
.valve i { display: block; height: 100%; background: var(--amber); }
.room.follower .room-temp { color: var(--muted); }

/* Diagramm */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .band { fill: var(--amber); opacity: .16; }
.chart .act { fill: none; stroke: var(--ink); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .tgt { fill: none; stroke: var(--amber-deep); stroke-width: 2; stroke-dasharray: 5 4; }
.chart-legend { display: flex; gap: 1.25rem; font-size: .8125rem; color: var(--muted); margin-top: .5rem; }
.chart-legend span::before { content: ""; display: inline-block; width: 16px; height: 0; border-top: 2.25px solid var(--ink); vertical-align: middle; margin-right: .4rem; }
.chart-legend span.t::before { border-top: 2px dashed var(--amber-deep); }
.chart-legend span.b::before { height: 10px; border: 0; background: var(--amber); opacity: .3; }

/* ---------- Sheets (Dialoge) ---------- */
.sheet {
  border: 0; padding: 0; margin: 0;
  width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh;
  position: fixed; inset: auto 0 0 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--raised); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(0, 20, 30, .25);
  overflow: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-in .28s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: rgba(10, 25, 33, .45); }
.sheet-full { height: 100vh; height: 100dvh; max-height: none; border-radius: 0; }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
.sheet-body { padding: 1rem 16px calc(1.5rem + env(safe-area-inset-bottom)); max-width: var(--col); margin: 0 auto; }
.sheet-full .sheet-body { padding-top: max(1rem, env(safe-area-inset-top)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.sheet-head h2 { font-size: 1.375rem; font-weight: 750; letter-spacing: -.015em; }
.sheet fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; min-width: 0; }
.sheet legend { font-weight: 700; padding: 0; margin-bottom: .5rem; font-size: 1.0625rem; }
.optional { font-weight: 400; color: var(--muted); font-size: .9375rem; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row2 label, .field label, label.field { display: grid; gap: .3rem; font-size: .875rem; color: var(--muted); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: .75rem; }
.chip {
  min-height: 38px; padding: 0 .9rem; border-radius: 999px;
  border: 1.5px solid var(--line); background: transparent; cursor: pointer; font-size: .9375rem; font-weight: 550;
}
.chip[aria-pressed=true] { border-color: var(--amber); background: var(--amber-soft); }
.hint { font-size: .875rem; color: var(--muted); margin-top: .4rem; }
.form-error { background: var(--signal-soft); color: var(--signal); padding: .6rem .8rem; border-radius: 10px; margin-bottom: 1rem; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 1.25rem; }
.sheet-actions .btn-amber { flex: 1; }

/* Einstellungen */
.set-group { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.set-group:first-child { border-top: 0; padding-top: .25rem; }
.set-group h3 { font-size: 1.0625rem; font-weight: 750; margin-bottom: .75rem; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .4rem 0; }
.set-row > span { min-width: 0; }
.set-row .stepper output { font-size: 1.125rem; min-width: 6ch; }
.set-row .step { width: 40px; height: 40px; font-size: 1.25rem; }
.set-text { font-size: .9375rem; color: var(--muted); }
.set-text strong { color: var(--ink); font-weight: 650; }
.set-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: .75rem; }
.toggle { position: relative; width: 52px; height: 32px; flex: none; appearance: none; -webkit-appearance: none; border-radius: 999px; background: var(--line); cursor: pointer; transition: background-color .2s; margin: 0; }
.toggle::after { content: ""; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.toggle:checked { background: var(--amber); }
.toggle:checked::after { transform: translateX(20px); }
.ch-row { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.ch-row:last-child { border-bottom: 0; }
.ch-top { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.ch-name { font-weight: 650; }
.ch-sub { font-size: .8125rem; color: var(--muted); }
.ch-row select { width: auto; min-height: 40px; padding: .3rem 2rem .3rem .7rem; font-size: .9375rem; flex: none; }
.ch-row .set-row { padding: .3rem 0; }
.diag { font-size: .875rem; color: var(--muted); display: grid; gap: .2rem; }
.diag code, .code { font-size: .8125rem; background: var(--paper); border: 1px solid var(--line); padding: .1rem .35rem; border-radius: 6px; overflow-wrap: anywhere; }
.diag .err { color: var(--signal); }
.steps-list { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .9375rem; }
.steps-list li { margin-bottom: .35rem; }

/* Personen */
.person { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.person:last-of-type { border-bottom: 0; }
.person-actions { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin-top: .45rem; }
.linkish.danger { color: var(--signal); }
.warn-text { color: var(--signal); }
.user-form { display: grid; gap: .6rem; margin-top: .6rem; padding: .85rem; border-radius: 12px; background: var(--paper); border: 1px solid var(--line); }
.user-form select { min-height: 44px; }
.user-form .form-error { margin: 0; }
.user-form .set-actions { margin-top: .25rem; justify-content: flex-end; }
.invite { display: grid; gap: .45rem; padding: .85rem; border-radius: 12px; background: var(--amber-soft); margin-bottom: .75rem; }
.invite.warn { background: var(--signal-soft); }
.invite-head { font-weight: 650; }
.invite input { font-size: .8125rem; background: var(--raised); }
.invite .set-actions { margin-top: 0; }
.log { list-style: none; margin: 0; padding: 0; font-size: .9375rem; }
.log li { display: flex; justify-content: space-between; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log-time { color: var(--muted); font-size: .8125rem; white-space: nowrap; flex: none; }
.steps-list li::marker { font-variant-numeric: normal; }

/* Meldung */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: .7rem 1.1rem; border-radius: 999px;
  background: var(--ink); color: var(--paper); font-weight: 550; font-size: .9375rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--signal); color: #fff; }

@media (min-width: 700px) {
  .sheet { inset: 0; margin: auto; width: min(520px, calc(100% - 32px)); max-height: 88vh; border-radius: var(--radius-sheet); height: auto; }
  .sheet-full { height: min(820px, 92vh); }
  .hero { padding-top: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
