:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --text: #15202b;
    --muted: #5b6b7c;
    --line: #dde3ea;
    --primary: #0f6cbd;
    --primary-ink: #ffffff;
    --primary-soft: #e6f1fb;
    --danger: #b3261e;
    --danger-soft: #fdeceb;
    --warn: #8a5a00;
    --warn-soft: #fff4d6;
    --ok: #1b7f4b;
    --marker: #e8a317;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
    --m-waerme: #d9531e;
    --m-strom: #c79100;
    --m-wasser: #1f77b4;
    --m-abwasser: #2a8a7e;
    --m-sonst: #6b7785;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f151c;
        --surface: #17202a;
        --surface-2: #1c2733;
        --text: #e8eef4;
        --muted: #92a3b5;
        --line: #2a3745;
        --primary: #4da3ee;
        --primary-ink: #06111c;
        --primary-soft: #14304a;
        --danger: #ff8a80;
        --danger-soft: #3a1c1a;
        --warn: #ffd37a;
        --warn-soft: #3a2f12;
        --ok: #5fd694;
        --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); margin: .25rem 0 0; }

/* ---------- Kopfzeile ---------- */
.app-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .75rem clamp(1rem, 3vw, 2rem);
    background: var(--surface); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: inherit; }
.brand-logo { height: 34px; width: auto; }
.brand-name { font-weight: 650; font-size: 1.1rem; display: flex; flex-direction: column; line-height: 1.15; }
.brand-name small { font-weight: 400; color: var(--muted); font-size: .78rem; }
.user-box { display: flex; align-items: center; gap: .75rem; margin: 0; }
.user-name { color: var(--muted); font-size: .95rem; }

main { padding: clamp(1rem, 3vw, 2rem); max-width: 1680px; margin: 0 auto; }

/* ---------- Karten / Layout ---------- */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }
.card-head { display: flex; align-items: center; gap: .65rem; margin-bottom: .9rem; }
.step {
    display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: .9rem;
}

/* Drei Spalten nebeneinander: Liegenschaft | Zähler | Eingabe */
.shell {
    display: grid; gap: 1.25rem; align-items: start;
    grid-template-columns: minmax(230px, 310px) minmax(230px, 310px) minmax(380px, 1fr);
}
/* Nur eine freigegebene Liegenschaft: erste Spalte entfällt */
.shell.single-lieg { grid-template-columns: minmax(230px, 340px) minmax(380px, 1fr); }
.shell.single-lieg .pane-lieg { display: none; }

.pane-lieg, .pane-zaehler { position: sticky; top: 5rem; max-height: calc(100vh - 6.5rem); overflow: auto; padding-right: 2px; }

/* mittlere Breite: Auswahl nebeneinander, Eingabe darunter */
@media (max-width: 1100px) {
    .shell { grid-template-columns: 1fr 1fr; }
    .shell.single-lieg { grid-template-columns: 1fr; }
    .pane-form { grid-column: 1 / -1; }
    .pane-lieg, .pane-zaehler { position: static; max-height: none; }
}
@media (max-width: 700px) {
    .shell, .shell.single-lieg { grid-template-columns: 1fr; }
}

.empty, .placeholder { text-align: center; color: var(--muted); }
.placeholder { padding: 3rem 1.5rem; }
.placeholder-icon { font-size: 2.2rem; margin-bottom: .5rem; }

/* ---------- Auswahllisten ---------- */
.choice-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.choice {
    width: 100%; text-align: left; display: flex; align-items: center; gap: .7rem;
    padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 10px;
    background: var(--surface-2); color: inherit; font: inherit; cursor: pointer;
    transition: border-color .12s, background .12s, transform .05s;
}
.choice:hover { border-color: var(--primary); }
.choice:active { transform: scale(.995); }
.choice[aria-selected="true"] { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.choice-main { flex: 1; min-width: 0; }
.choice-title { display: block; font-weight: 600; overflow-wrap: anywhere; }
.choice-sub { display: block; color: var(--muted); font-size: .85rem; }
.marker {
    flex: none; width: .7rem; height: .7rem; border-radius: 50%; background: var(--marker);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--marker) 25%, transparent);
}
.legend { margin: .8rem 0 0; font-size: .82rem; color: var(--muted); display: flex; align-items: center; gap: .5rem; }

.group-title {
    display: flex; align-items: center; gap: .5rem; margin: 1rem 0 .5rem;
    font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 650;
}
.group-title:first-child { margin-top: 0; }
.dot { width: .65rem; height: .65rem; border-radius: 3px; background: var(--m-sonst); }
.m-0 .dot, .dot.m-0 { background: var(--m-waerme); }
.m-1 .dot, .dot.m-1 { background: var(--m-strom); }
.m-2 .dot, .dot.m-2 { background: var(--m-wasser); }
.m-4 .dot, .dot.m-4 { background: var(--m-abwasser); }
.badge {
    flex: none; font-size: .72rem; padding: .1rem .5rem; border-radius: 99px;
    background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}

/* ---------- Formular ---------- */
.zaehler-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.zaehler-head h2 { font-size: 1.4rem; }
.eyebrow { margin: 0 0 .15rem; font-size: .78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); }

.last-box {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem;
    margin: 0 0 1.25rem; padding: .9rem 1rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
}
.last-box .last-action { display: flex; align-items: flex-end; }
.btn-small { padding: .3rem .7rem; font-size: .85rem; }
.alert-info { background: var(--primary-soft); border: 1px solid var(--primary); border-radius: 8px; padding: .6rem .8rem; margin: .8rem 0; }
.last-box dt { font-size: .78rem; color: var(--muted); }
.last-box dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.grid .field { margin-bottom: 0; }
.field > span { font-size: .88rem; font-weight: 600; }
.unit { font-style: normal; font-weight: 400; color: var(--muted); }
.hint { color: var(--muted); min-height: 1.1em; }

input[type="text"], input[type="password"], input[type="date"], textarea {
    width: 100%; padding: .65rem .8rem; font: inherit; color: inherit;
    background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
}
input:focus, textarea:focus, .btn:focus-visible, .choice:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: 1px; border-color: var(--primary);
}
input.invalid, textarea.invalid { border-color: var(--danger); }
input[inputmode="decimal"] { font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.25rem; }
.btn {
    font: inherit; font-weight: 600; border-radius: 9px; padding: .65rem 1.1rem; cursor: pointer;
    border: 1px solid transparent; transition: filter .12s, background .12s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; margin-top: .5rem; }

.alert { padding: .7rem .9rem; border-radius: 9px; margin-top: 1rem; font-size: .95rem; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Dialoge ---------- */
dialog {
    border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--text);
    width: min(560px, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(10, 15, 20, .55); }
.dlg { padding: 1.5rem; }
.dlg h3 { font-size: 1.2rem; margin-bottom: .75rem; }
.summary { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.toast {
    position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
    background: var(--text); color: var(--bg); padding: .75rem 1.2rem; border-radius: 99px;
    box-shadow: var(--shadow); font-weight: 600; z-index: 20; max-width: calc(100vw - 2rem);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
.login-wrap { min-height: 60vh; display: grid; place-items: center; }
.login-card { width: min(420px, 100%); }
.login-card h1 { margin-bottom: .25rem; }
.login-card .field { margin-top: 1rem; margin-bottom: 0; }

/* Eingabespalte: keine Zusatz-Abstände zwischen Platzhalter und Formular */
.pane-form .card { margin-top: 0; }
.pane-zaehler .card, .pane-lieg .card:first-child { margin-top: 0; }
