/* Heizungs-Tagebuch – Gestaltung (hell/dunkel automatisch, optimiert für Tablet & Smartphone) */
:root {
  --bg: #F5F4F0; --card: #FFFFFF; --ink: #1D2125; --mute: #5B6168; --line: #E1DED6; --soft: #EFEDE7;
  --heat: #B93C0B; --heatbg: #FDE8DA; --heatlt: #F2A779;
  --luk: #7A5200; --lukbg: #FBF0D3;
  --cold: #1D5FA8; --coldbg: #E2EDF9;
  --ok: #1E6B3A; --err: #B42318; --errbg: #FDECEA;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141619; --card: #1E2125; --ink: #ECEDEE; --mute: #A6ACB3; --line: #33373D; --soft: #272B30;
    --heat: #F7A06B; --heatbg: #3B2216; --heatlt: #8A4A25;
    --luk: #E9C46A; --lukbg: #332A12;
    --cold: #86BBF2; --coldbg: #182A3D;
    --ok: #7DD3A0; --err: #F7A59C; --errbg: #3A1815;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; text-decoration: none; }
h2 { margin: 0; font-size: 17px; }
h3 { margin: 8px 0 0; font-size: 15px; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.block { display: block; }
.center { text-align: center; }
.unit { font-weight: 500; color: var(--mute); font-size: 14px; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--cold); outline-offset: 2px; }

/* ---------- Kopfzeile ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.flame { color: var(--heat); display: inline-flex; }
.flame.big svg { width: 36px; height: 36px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 15px; color: var(--mute); }
.nav a.on { background: var(--ink); color: var(--bg); }
.top-extra { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.datenav { display: flex; align-items: center; gap: 8px; }
.datepick { display: flex; flex-direction: column; align-items: center; min-width: 150px; }
.datepick .wd { font-size: 12px; color: var(--mute); }
.datepick input { border: 0; background: transparent; font-weight: 700; font-size: 16px; text-align: center; min-height: 28px; }

/* ---------- Bausteine ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 18px 20px 32px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; justify-content: space-between; }
.row { display: flex; flex-wrap: wrap; gap: 18px; align-items: stretch; }
.grow { flex: 999 1 520px; }
.side-card { flex: 1 1 280px; }
.link-card .more { font-weight: 600; font-size: 15px; }
.link-card:hover { border-color: var(--mute); }
.label { font-size: 13px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.big small { font-size: 15px; font-weight: 500; color: var(--mute); }
.big-text { font-size: 19px; font-weight: 700; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.primary { background: var(--heat); border-color: var(--heat); color: var(--card); }
.btn.big { min-height: 50px; font-size: 16px; width: 100%; }
.icon-btn { width: 44px; height: 44px; flex: 0 0 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 20px; line-height: 1; padding: 0; touch-action: manipulation; }
.icon-btn.disabled { opacity: .35; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.field input, input.num, .form-grid input {
  height: 44px; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  padding: 0 10px; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums;
}
input.num { text-align: center; }
input.num.left { text-align: left; }
input.invalid { border-color: var(--err); background: var(--errbg); }
input::placeholder { color: var(--mute); opacity: .6; font-weight: 500; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--soft); padding: 4px; border-radius: 12px; }
.seg button { min-height: 40px; min-width: 56px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--mute); font-weight: 700; font-size: 15px; touch-action: manipulation; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

.delta { font-weight: 600; font-size: 14px; white-space: nowrap; }
.delta.up { color: var(--heat); }
.delta.down { color: var(--cold); }
.delta.flat { color: var(--mute); }

/* ---------- Erfassung ---------- */
.cols { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.side { flex: 1 1 290px; max-width: 100%; display: flex; flex-direction: column; gap: 16px; }
.circuit { display: flex; flex-direction: column; gap: 8px; }
.circuit h3 { margin: 0; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gasrow { display: flex; gap: 10px; align-items: flex-end; }
.gasrow .grow { flex: 1 1 auto; }
.gasrow .time { flex: 0 0 104px; }
.gasrow .time input { font-size: 15px; padding: 0 6px; }
.summary { background: var(--soft); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 5px; font-size: 14px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; }
.sum-row strong, .sum-row span:last-child { white-space: nowrap; }
.warn { color: var(--err); font-weight: 600; }
#yesterday-card { gap: 6px; }

.rooms { flex: 999 1 600px; }
.slots button { min-width: 104px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 12px; min-height: 48px; }
.slots button b { font-size: 15px; }
.slots button small { font-size: 12px; font-weight: 500; }
.rooms-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.rooms-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; font-size: 14px; }
.inline-time { display: inline-flex; align-items: center; gap: 8px; color: var(--mute); font-weight: 600; }
.inline-time input { height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 0 6px; }
.status { margin-left: auto; font-weight: 600; color: var(--mute); }
.status.ok { color: var(--ok); }
.status.error { color: var(--err); }
.room-labels { display: flex; flex-wrap: wrap; gap: 8px 16px; padding: 0 2px 8px; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.room-labels .c-hk { flex: 1 1 220px; }
.room { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 8px 2px 12px; border-bottom: 1px solid var(--line); }
.c-name { flex: 0 0 140px; display: flex; flex-direction: column; }
.c-name strong { font-size: 16px; }
.c-name small { font-size: 13px; color: var(--mute); }
.c-temp, .c-th { flex: 0 0 152px; }
.c-heaters { flex: 1 1 400px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.heater { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.heater.none { color: var(--mute); }
.hk-label { font-size: 13px; font-weight: 700; color: var(--mute); width: 38px; }
.seg.hk { flex: 1 1 220px; background: transparent; padding: 0; gap: 6px; flex-wrap: nowrap; }
.seg.hk button { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 6px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.seg.hk button.hk-kalt.on { background: var(--coldbg); color: var(--cold); border-color: var(--cold); box-shadow: none; }
.seg.hk button.hk-lauwarm.on { background: var(--lukbg); color: var(--luk); border-color: var(--luk); box-shadow: none; }
.seg.hk button.hk-warm.on { background: var(--heatbg); color: var(--heat); border-color: var(--heat); box-shadow: none; }
.stepper { display: flex; gap: 4px; align-items: center; }
.stepper input.num { width: 56px; flex: 0 0 56px; padding: 0 2px; }
.foot { margin: 0; }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.kpi { gap: 6px; }
.kpi .delta { white-space: normal; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; }
table.data th, table.data td { padding: 11px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; vertical-align: top; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { font-size: 13px; font-weight: 600; color: var(--mute); }
table.data td.strong { font-weight: 700; font-size: 16px; }
table.data.compact td, table.data.compact th { padding: 8px; }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 12px; font-size: 15px; }
.bar-name { flex: 0 0 118px; }
.bar { flex: 1; height: 14px; background: var(--soft); border-radius: 7px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--heat); border-radius: 7px; }
.bar-val { flex: 0 0 66px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-th { flex: 0 0 118px; text-align: right; font-size: 13px; }

/* ---------- Diagramme ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.toolbar #period-switch { margin-right: auto; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 600; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--heat); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-bar { width: 14px; height: 14px; border-radius: 3px; background: var(--heatlt); display: inline-block; }
.lg-line { width: 18px; height: 3px; display: inline-block; }
.lg-line.heat { background: var(--heat); }
.lg-line.cold { background: var(--cold); }
.lg-line.dash { background: repeating-linear-gradient(90deg, var(--mute) 0 5px, transparent 5px 8px); }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart text { font-size: 13px; fill: var(--mute); }
.chart .grid { stroke: var(--line); stroke-width: 1; fill: none; }
.chart .grid.dash { stroke-dasharray: 4 4; }
.chart .axis { stroke: var(--mute); stroke-width: 1; }
.chart .bars { fill: var(--heatlt); }
.chart .dots { fill: var(--heatlt); fill-opacity: .85; }
.chart .line { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.heat { stroke: var(--heat); }
.chart .line.cold { stroke: var(--cold); stroke-width: 2; }
.chart .line.dash { stroke-dasharray: 10 6; }
.chart .line.dash:not(.heat) { stroke: var(--mute); stroke-width: 2; }
.chart .cursor { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-info { min-height: 22px; font-size: 14px; color: var(--mute); }
.empty { color: var(--mute); padding: 30px 0; text-align: center; }
.facts { margin: 0; display: flex; flex-direction: column; gap: 14px; }
.facts dt { font-size: 13px; font-weight: 600; color: var(--mute); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 2px 0 0; font-size: 20px; font-weight: 700; }
.facts dd small { display: block; font-size: 13px; font-weight: 400; color: var(--mute); }

/* ---------- Einstellungen ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.form-grid .btn { grid-column: 1 / -1; justify-self: start; }
.form-grid input[type="date"] { font-size: 16px; }
.calc-box { margin: 0; background: var(--soft); border-radius: 10px; padding: 12px; }
.flash { padding: 12px 16px; border-radius: 10px; font-weight: 600; }
.flash.ok { background: var(--coldbg); color: var(--cold); }
.flash.error { background: var(--errbg); color: var(--err); }
td form { display: inline; }

/* ---------- Anmeldung ---------- */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 30px; display: flex; flex-direction: column; gap: 16px; }
.auth-title { display: flex; align-items: center; gap: 12px; }
.auth-title h1 { margin: 0; font-size: 23px; }
.auth-card p { margin: 0; }
.error { color: var(--err); font-weight: 600; }

/* ---------- Smartphone ---------- */
@media (max-width: 700px) {
  .top { padding: 8px 12px; gap: 8px; }
  .brand span:last-child { display: none; }
  .nav a { padding: 0 11px; font-size: 14px; }
  .top-extra { margin-left: 0; width: 100%; justify-content: center; }
  .wrap { padding: 12px 10px 24px; gap: 12px; }
  .card { padding: 14px; }
  .room-labels { display: none; }
  .c-name { flex: 1 1 100%; flex-direction: row; align-items: baseline; gap: 8px; }
  .c-temp { flex: 1 1 100%; }
  .c-temp .stepper::before { content: "Temp. °C"; font-size: 13px; color: var(--mute); font-weight: 600; margin-right: auto; }
  .c-th .stepper::before { content: "Thermostat"; font-size: 13px; color: var(--mute); font-weight: 600; margin-right: auto; }
  .c-th { flex: 1 1 100%; }
  .c-heaters { flex-basis: 100%; }
  .slots { width: 100%; }
  .slots button { flex: 1 1 0; min-width: 0; }
  .status { margin-left: 0; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .bar-th { display: none; }
  .bar-name { flex-basis: 96px; }
}
.legend b { font-weight: inherit; }
