:root {
  --bg: #f5f6f4; --card: #fff; --text: #1d2420; --muted: #66706a; --line: #dfe3df;
  --accent: #0f5c4c; --accent-soft: #e3f0ec; --warn: #9a5b00; --warn-soft: #fdf1dc;
  --err: #a12a2a; --err-soft: #fbe5e5; --ok: #23703f; --ok-soft: #e2f3e7;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --card: #1b201d; --text: #e7ece8; --muted: #9aa49e; --line: #2c332f;
    --accent: #5cc3a8; --accent-soft: #1d332c; --warn: #f0b75a; --warn-soft: #3a2d15;
    --err: #f08a8a; --err-soft: #3a1c1c; --ok: #7bd69a; --ok-soft: #1a3323;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 96px env(safe-area-inset-left);
}
header {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; gap: 6px; align-items: center; padding: 12px 12px; border-bottom: 1px solid var(--line);
}
header h1 { font-size: 16px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header button, header select { font-size: 14px; padding: 6px 9px; }
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px; }
button, select, input, textarea {
  font: inherit; color: inherit; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); padding: 8px 12px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { button.primary { color: #0d1512; } }
button.danger { color: var(--err); }
button:disabled { opacity: .5; cursor: default; }
/* Filter umbrechen statt seitlich scrollen */
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0 12px; }
.chips button { white-space: nowrap; padding: 6px 12px; border-radius: 999px; }
.chips button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.summen { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; width: 100%;
  padding: 0; border: 0; background: none; text-align: left; }
.summe { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.summen-mehr { grid-column: 1 / -1; justify-self: end; color: var(--accent); font-size: 13px; margin-top: -2px; }
.summen:hover .summe { border-color: var(--accent); }
/* Jahresübersicht: schmal nur Jahr/Person, Rechnungen, Erstattet, Eigenanteil - kein seitliches Scrollen */
.tabelle { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabelle th, .tabelle td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tabelle th { font-size: 12px; color: var(--muted); font-weight: 600; }
.tabelle th:first-child, .tabelle td:first-child { text-align: left; white-space: normal; overflow-wrap: anywhere; }
.tabelle td small { display: block; color: var(--warn); font-size: 12px; }
.tabelle td strong { font-weight: 600; }
.tabelle .breit { display: none; }
@media (min-width: 600px) { .tabelle .breit { display: table-cell; } }
#uebersicht h3 { margin: 6px 0 0; font-size: 15px; }
.summe span { display: block; color: var(--muted); font-size: 13px; }
.summe strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.liste { display: flex; flex-direction: column; gap: 8px; }
.karte {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.karte input[type=checkbox] { width: 22px; height: 22px; grid-row: span 2; }
.karte .titel { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.karte .betrag { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.karte .meta { color: var(--muted); font-size: 14px; grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.leer { text-align: center; color: var(--muted); padding: 40px 0; }
.aktionsleiste {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card);
  border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.aktionsleiste[hidden] { display: none; }
.aktionsleiste #auswahl-anzahl { align-self: center; }
.aktionsleiste .aktionen { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.aktionsleiste [aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.aktionsleiste [aria-pressed="true"]::before { content: "✓ "; }
.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 4;
  border-radius: 999px; padding: 14px 20px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  width: min(760px, 100vw - 24px); max-height: calc(100vh - 24px); padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 16px; display: grid; gap: 10px; }
dialog h2 { margin: 0; font-size: 18px; }
.feld { display: grid; gap: 4px; }
.feld label { font-size: 13px; color: var(--muted); }
.zeile { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
dialog input, dialog select, dialog textarea { width: 100%; min-width: 0; }
.hinweise { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.hinweise ul { margin: 4px 0 0; padding-left: 18px; }
.info { color: var(--muted); font-size: 14px; }
.position { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.position .kopf { font-weight: 600; }
.position .zahlen, .position .info { color: var(--muted); font-size: 14px; }
.position .ok { color: var(--ok); font-size: 14px; }
.position .hinweis { color: var(--warn); font-size: 14px; }
.zahlung { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 0; display: grid; gap: 10px; }
.zahlung legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.mitknopf { display: flex; gap: 6px; }
.mitknopf input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.karte .zahlzeile { grid-column: 2 / 4; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pruefung { border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.pruefung.ok { background: var(--ok-soft); color: var(--ok); }
.pruefung.warn { background: var(--warn-soft); color: var(--warn); }
.pruefung.err { background: var(--err-soft); color: var(--err); }
.pruefung { padding: 6px 10px; font-size: 13px; }
.pruefung details { display: inline; }
.pruefung summary { display: inline; cursor: pointer; text-decoration: underline; margin-left: 4px; }
.pruefung ul { margin: 4px 0 0; padding-left: 18px; }
.girocode { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.girocode[hidden], .pruefung[hidden] { display: none; }
/* Weißer Hintergrund und Ruhezone gehören zum Code - auch im dunklen Modus, sonst scannt er nicht. */
.girocode canvas { background: #fff; border-radius: 6px; width: 96px; height: 96px; image-rendering: pixelated; flex: none; }
.girocode-text { display: grid; gap: 2px; font-size: 13px; min-width: 0; flex: 1; align-content: start; }
.girocode-quelle { font-weight: 600; }
.girocode-quelle.erstellt { color: var(--warn); }
.iban { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.wizard-kopf { font-size: 13px; color: var(--accent); font-weight: 600; }
#fortschritt progress { width: 100%; }
.vorschau[hidden] { display: none; }
/* ------------------------------------------------------------------ Dialog ohne Scrollen
   Der Dialog ist so hoch wie der Bildschirm und fest aufgeteilt: Kopf, Belegvorschau, Felder, Knöpfe.
   Handy: Felder in Reitern. Breit: Beleg links, Rechnung/Erstattung und Zahlung nebeneinander.
   Nur falls ein Bildschirm sehr klein ist, scrollt notfalls der Feldbereich selbst. */
dialog.rahmen { width: min(760px, 100vw - 16px); height: min(100dvh - 16px, 920px); max-height: none; }
.rahmen-form { height: 100%; display: grid; gap: 6px; padding: 12px;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto; grid-template-areas: "kopf" "vorschau" "reiter" "teil" "fuss"; }
#abrechnung .rahmen-form { grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "kopf" "vorschau" "positionen" "fuss"; }
.rahmen-form .kopf { grid-area: kopf; }
.rahmen-form .vorschau { grid-area: vorschau; }
.rahmen-form .reiter { grid-area: reiter; }
.rahmen-form .teil { grid-area: teil; }
#abrechnung .positionen { grid-area: positionen; }
.rahmen-form .knoepfe.fuss { grid-area: fuss; }
.rahmen-form .kopf { display: grid; gap: 4px; }
.rahmen-form .hinweise { font-size: 13px; padding: 6px 10px; max-height: 5.8em; overflow: auto; }
.rahmen-form .hinweise ul { margin: 0; padding-left: 16px; }
.rahmen-form .feld { gap: 2px; }
.rahmen-form .feld label { font-size: 12px; }
.rahmen-form input, .rahmen-form select, .rahmen-form textarea { padding: 6px 10px; }
.teil { display: grid; gap: 6px; align-content: start; min-height: 0; overflow: auto; }
.teil h3 { display: none; margin: 0; font-size: 14px; color: var(--muted); }
.reiter { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.reiter button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 6px 10px; font-size: 14px; }
.reiter button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.reiter button.markiert::after { content: " •"; color: var(--warn); }
.rahmen-form .teil:not(.aktiv):not(.positionen) { display: none; }
.knoepfe.fuss { margin: 0; flex-wrap: nowrap; }
.knoepfe .luecke { flex: 1; }
.klein { font-size: 12px; }
.haken { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.haken input { width: auto; }
.haken[hidden] { display: none; }
.zahlfelder { display: grid; gap: 6px; }
.teil.direkt .zahlfelder, .teil.direkt #d-girocode, .teil.direkt #d-zahlung-bestaetigen { display: none; }
.karte .offen-grund { grid-column: 2 / 4; font-size: 12px; color: var(--muted); }
.rahmen-form textarea { height: 48px; resize: vertical; }
.rahmen-form input.fehlt { border-color: var(--warn); background: var(--warn-soft); }
#d-nachreichen { display: grid; gap: 4px; padding: 4px 10px; }
.nachreichen-zeile { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nachreichen-zeile button { padding: 4px 10px; font-size: 13px; }
#d-nachreichen[hidden] { display: none; }

/* Vorschau: kleine Bilder, die sich den Platz teilen - mehr Seiten, kleinere Bilder. */
.vorschau { display: flex; gap: 6px; height: 72px; background: var(--line); border-radius: 8px; padding: 4px; overflow: hidden; }
.vorschau[hidden] { display: none; }
.vorschau img { flex: 1 1 0; min-width: 0; height: 100%; object-fit: contain; background: #fff; border-radius: 4px; cursor: zoom-in; }

@media (min-width: 900px) {
  dialog.rahmen { width: min(1280px, 100vw - 32px); }
  dialog.rahmen.mit-vorschau .rahmen-form {
    grid-template-columns: 220px minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) minmax(0, auto) auto;
    grid-template-areas: "kopf kopf kopf" "vorschau rechnung zahlung" "vorschau erstattung zahlung" "fuss fuss fuss";
    column-gap: 16px;
  }
  dialog.rahmen:not(.mit-vorschau) .rahmen-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) minmax(0, auto) auto;
    grid-template-areas: "kopf kopf" "rechnung zahlung" "erstattung zahlung" "fuss fuss";
    column-gap: 16px;
  }
  .rahmen-form .kopf { grid-area: kopf; }
  .rahmen-form .vorschau { grid-area: vorschau; flex-direction: column; height: auto; }
  .rahmen-form .vorschau img { width: 100%; height: auto; min-height: 0; }
  .rahmen-form .reiter { display: none; }
  .rahmen-form .teil, .rahmen-form .teil:not(.aktiv):not(.positionen) { display: grid; }
  .rahmen-form .teil h3 { display: block; }
  .rahmen-form .teil[data-teil="rechnung"] { grid-area: rechnung; }
  .rahmen-form .teil[data-teil="zahlung"] { grid-area: zahlung; }
  .rahmen-form .teil[data-teil="erstattung"] { grid-area: erstattung; }
  .rahmen-form .fuss { grid-area: fuss; }
  /* Bescheid: Positionen neben dem Beleg */
  #abrechnung .rahmen-form { grid-template-areas: "kopf kopf kopf" "vorschau positionen positionen" "vorschau positionen positionen" "fuss fuss fuss"; }
  #abrechnung:not(.mit-vorschau) .rahmen-form { grid-template-areas: "kopf kopf" "positionen positionen" "positionen positionen" "fuss fuss"; }
  #abrechnung .positionen { grid-area: positionen; }
}

/* Lupe: eine Seite groß */
#lupe { width: min(1000px, 100vw - 16px); height: min(100dvh - 16px, 1300px); max-height: none; }
.lupe { height: 100%; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; padding: 8px; }
.lupe img { width: 100%; height: 100%; object-fit: contain; background: #fff; border-radius: 6px; }
.lupe .knoepfe { margin: 0; align-items: center; flex-wrap: nowrap; }
.lupe .luecke { flex: 1; }
.knoepfe { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; margin-top: 6px; }
.status { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; z-index: 10;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; }
.status[hidden] { display: none; }
.login { text-align: center; padding: 80px 16px; }
