:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --line: #e4e0d8;
  --text: #1d1f1e;
  --muted: #6b6e6a;
  --accent: #1f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2efeb;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf1d8;
  --ok: #2c7a3f;
  --ok-soft: #e3f3e6;
  --strom: #c78a00;
  --kaltwasser: #2266b8;
  --warmwasser: #c2410c;
  --waerme: #be185d;
  --gas: #6d4ac2;
  --sonstiges: #5b6670;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141615;
    --surface: #1d201f;
    --surface-2: #232726;
    --line: #333836;
    --text: #ecefed;
    --muted: #9ba19e;
    --accent: #5cc0a8;
    --accent-ink: #0d1d19;
    --accent-soft: #1d3530;
    --danger: #f2877e;
    --danger-soft: #3a1f1d;
    --warn: #f0c060;
    --warn-soft: #382c14;
    --ok: #7fd18f;
    --ok-soft: #1c3322;
    --strom: #f0b429;
    --kaltwasser: #6aa8f0;
    --warmwasser: #fb8c55;
    --waerme: #f472b6;
    --gas: #a78bfa;
    --sonstiges: #9aa5ae;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 48px; }
.wrap.wide { max-width: 1080px; }

/* ---------- Kopf */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 16px;
}
.top .logo { width: 40px; height: 40px; border-radius: 12px; flex: none; }
.top h1 { font-size: 1.05rem; margin: 0; line-height: 1.2; }
.top .sub { color: var(--muted); font-size: .88rem; }
.top .spacer { flex: 1; }

/* ---------- Bausteine */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap-row { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
h2 { font-size: 1.15rem; margin: 0 0 4px; }
h3 { font-size: 1rem; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.05rem; border-radius: 14px; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .88rem; border-radius: 10px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 20px; height: 20px; flex: none; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.checkbox { display: flex; gap: 8px; align-items: center; }
.checkbox input { width: 20px; height: 20px; accent-color: var(--accent); }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px;
  font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.neu { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.geprueft { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.auffaellig { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.alert { border-radius: 12px; padding: 12px 14px; font-size: .93rem; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--accent-soft); color: var(--accent); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Zählerkarten */
.meter {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; cursor: pointer;
}
.meter + .meter { margin-top: 10px; }
.mic {
  width: 48px; height: 48px; border-radius: 14px; flex: none; display: grid; place-items: center;
  color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent);
}
.mic svg { width: 26px; height: 26px; }
.meter .val { font-size: 1.15rem; font-weight: 700; }
.meter .chev { color: var(--muted); }
.done-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); display: inline-block; }

/* ---------- Dialoge */
dialog {
  border: none; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, 100vw); max-width: 100vw; max-height: 100dvh;
  border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10,12,11,.55); }
@media (max-width: 600px) {
  dialog { width: 100vw; height: 100dvh; border-radius: 0; margin: 0; }
  dialog.compact { height: auto; margin: auto 0 0; border-radius: 20px 20px 0 0; }
}
.dlg { display: flex; flex-direction: column; max-height: 100dvh; height: 100%; }
.dlg-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--line); padding-top: calc(12px + env(safe-area-inset-top));
}
.dlg-head h2 { margin: 0; flex: 1; font-size: 1.05rem; }
.dlg-body { padding: 18px; overflow-y: auto; flex: 1; }
.dlg-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; }
.dlg-foot .btn { flex: 1; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: none; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.iconbtn svg { width: 22px; height: 22px; }

/* ---------- Erfassung */
.shot-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border: 2px dashed var(--line); border-radius: 18px; padding: 32px 16px; text-align: center; cursor: pointer;
  background: var(--surface-2);
}
.shot-zone svg { width: 54px; height: 54px; color: var(--accent); }
.shot-zone input { display: none; }
.preview { position: relative; border-radius: 14px; overflow: hidden; background: #000; }
.preview img { display: block; width: 100%; max-height: 42dvh; object-fit: contain; }
.preview .scan {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff;
  background: rgba(0,0,0,.45); font-weight: 600; gap: 10px; align-content: center;
}
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
.spinner.dark { border-color: var(--line); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

.value-input { position: relative; }
.value-input input {
  font-size: 1.9rem; font-weight: 700; min-height: 64px; padding-right: 64px; letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.value-input .unit { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }

.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: .9rem; text-align: left; }
.tips li + li { margin-top: 4px; }

.success { text-align: center; padding: 24px 8px; }
.success .check { width: 72px; height: 72px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto 14px; }
.success .check svg { width: 38px; height: 38px; }

/* ---------- Verlauf */
.hist { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: none; }
.thumb { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; cursor: zoom-in; border: 1px solid var(--line); }
.hist .v { font-weight: 700; font-size: 1.05rem; }
.log { margin-top: 6px; font-size: .8rem; color: var(--muted); }
.log div + div { margin-top: 2px; }
.edit-box { margin-top: 10px; padding: 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }

.zoom { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50; display: grid; place-items: center; cursor: zoom-out; }
.zoom img { max-width: 100vw; max-height: 100dvh; object-fit: contain; touch-action: pinch-zoom; }

/* ---------- Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  z-index: 60; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

/* ---------- Login */
.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; }
.login .hero { text-align: center; margin-bottom: 24px; }
.login .hero img { width: 76px; height: 76px; border-radius: 20px; margin-bottom: 12px; }
.code-input { text-align: center; font-size: 1.5rem !important; letter-spacing: .18em; text-transform: uppercase; font-weight: 700; }

/* ---------- Admin */
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 4px; margin-bottom: 16px; overflow-x: auto; }
.tabs button { flex: 1; border: none; background: transparent; padding: 10px 12px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
.unit-card + .unit-card { margin-top: 14px; }
.unit-card .head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.mrow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.mrow .mic { width: 38px; height: 38px; border-radius: 11px; }
.mrow .mic svg { width: 21px; height: 21px; }
.mrow .clickable { cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.code-show { font-size: 1.8rem; font-weight: 800; letter-spacing: .12em; text-align: center; padding: 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); user-select: all; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 99px; font-size: .88rem; cursor: pointer; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.install { font-size: .9rem; }
.install summary { cursor: pointer; font-weight: 600; color: var(--accent); }

/* ---------- Mieter-Übersicht */
.ov-card + .ov-card { margin-top: 14px; }
.ov-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 420px) { .stats { grid-template-columns: 1fr 1fr; } .stats > :first-child { grid-column: 1 / -1; } }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat .l { font-size: .76rem; color: var(--muted); }
.stat .n { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .s { font-size: .74rem; color: var(--muted); }
.chart { margin-top: 14px; position: relative; }
.chart h4 { margin: 0 0 6px; font-size: .82rem; color: var(--muted); font-weight: 600; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--c); }
.chart .bar.dim { opacity: .35; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: .78rem; padding: 6px 9px; border-radius: 8px; white-space: nowrap; transform: translateX(-50%); top: 0; z-index: 3; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.years { margin-top: 12px; font-size: .9rem; }
.years .yr { display: flex; justify-content: space-between; padding: 6px 0; border-top: 1px solid var(--line); gap: 10px; }
.hist-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.hist-item:first-child { border-top: none; }
.hist-item .mic { width: 22px; height: 22px; border-radius: 7px; display: inline-grid; vertical-align: -5px; }
.hist-item .mic svg { width: 14px; height: 14px; }

/* ---------- Ablese-Schritte */
.steps { display: flex; gap: 4px; padding: 10px 18px 0; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps span.done { background: var(--accent); opacity: .5; }
.steps span.on { background: var(--accent); }
.reg-title { font-size: 1.05rem; }
.sum-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.sum-row .thumb { width: 56px; height: 56px; }
.subvals { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.subvals b { color: var(--text); font-weight: 600; }

/* ---------- App-Symbol leicht abheben (helles Logo auf hellem Grund) */
.login .hero img, .top .logo { box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.10); border-radius: 22%; }

.unit-head { font-size: .95rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 4px 8px; }
.unit-head:first-child { margin-top: 4px; }

.unit-head-desc { text-transform: none; letter-spacing: 0; font-weight: 500; }
#unitDesc { font-size: .82rem; }
