/* Debitorenkonto – gemeinsames Design (Hell/Dunkel, ohne externe Ressourcen) */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --text: #1c1c1e;
  --text-muted: #55555c;
  --line: #d6d6dc;          /* dekorative Trennlinien */
  --control-line: #85858c;  /* Rahmen von Eingabefeldern (>= 3:1) */
  --accent: #0054bd;
  --on-accent: #ffffff;
  --accent-soft: #e4eefc;
  --danger: #b3001b;
  --on-danger: #ffffff;
  --danger-soft: #fde8e8;
  --debit: #a8001a;         /* offene Forderung */
  --credit: #14692b;        /* Guthaben / Gutschrift */
  --ok-bg: #e2f3e7;   --ok-fg: #0d5524;
  --warn-bg: #fff0cc; --warn-fg: #6f3b00;
  --bad-bg: #fde8e8;  --bad-fg: #8f1226;
  --info-bg: #e4eefc; --info-fg: #0a439a;
  --neutral-bg: #ececf1; --neutral-fg: #3a3a40;
  --radius: 14px;
  --radius-s: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-base: 1.0625rem;   /* 17 px */
  --tap: 48px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0e;
    --surface: #1c1c1f;
    --surface-2: #26262a;
    --text: #f2f2f7;
    --text-muted: #a9a9b2;
    --line: #3a3a40;
    --control-line: #8e8e96;
    --accent: #6cb4ff;
    --on-accent: #00172e;
    --accent-soft: #11263f;
    --danger: #ff8f88;
    --on-danger: #2a0006;
    --danger-soft: #3a1417;
    --debit: #ff9a93;
    --credit: #6fd68d;
    --ok-bg: #12301d;   --ok-fg: #8fe0a6;
    --warn-bg: #3b2a05; --warn-fg: #ffd37a;
    --bad-bg: #3d1519;  --bad-fg: #ffb0aa;
    --info-bg: #11263f; --info-fg: #a6d0ff;
    --neutral-bg: #2d2d33; --neutral-fg: #d4d4dc;
    --shadow: none;
  }
}
@media (prefers-contrast: more) {
  :root { --line: var(--control-line); --text-muted: var(--text); }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .5rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.3rem; line-height: 1.3; margin: 0 0 .75rem; font-weight: 650; }
h3 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--text-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -100px; background: var(--surface); padding: .75rem 1rem; border-radius: var(--radius-s); z-index: 20; }
.skip-link:focus { top: 8px; }

/* Kopfleiste */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header-inner {
  max-width: 1100px; margin: 0 auto; padding: .5rem 16px;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
}
.brand { font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.main-nav { display: flex; flex-wrap: wrap; gap: .25rem; margin: 0; padding: 0; list-style: none; flex: 1 1 auto; }
.main-nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .9rem;
  border-radius: var(--radius-s); color: var(--text); text-decoration: none; font-weight: 500;
}
.main-nav a:hover { background: var(--surface-2); }
.main-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.user-box { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.user-name { color: var(--text-muted); font-size: .95rem; }
.user-box form { margin: 0; }

/* Seite */
.page { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.page-narrow { max-width: 640px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.breadcrumb { margin: 0 0 .75rem; }
.breadcrumb a { display: inline-flex; align-items: center; min-height: 44px; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.card > :last-child { margin-bottom: 0; }

/* Meldungen */
.messages { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: .5rem; }
.message { padding: .85rem 1rem; border-radius: var(--radius-s); border: 1px solid transparent; border-left-width: 6px; font-weight: 500; }
.message-label { font-weight: 700; margin-right: .35rem; }
.message-success { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-fg); }
.message-info    { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-fg); }
.message-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-fg); }
.message-error   { background: var(--bad-bg); color: var(--bad-fg); border-color: var(--bad-fg); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: 0 1.25rem; border-radius: var(--radius-s);
  border: 2px solid var(--accent); background: var(--accent); color: var(--on-accent);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn-secondary { background: transparent; color: var(--accent); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-small { min-height: 44px; padding: 0 1rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--text); padding: 0 .9rem; min-height: 44px; font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--radius-s); }
.btn-link:hover { background: var(--surface-2); }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.actions form { margin: 0; }

/* Kennzahlen */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.stat-label { color: var(--text-muted); font-size: 1rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .95rem; color: var(--text-muted); }

/* Geldbeträge */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.debit { color: var(--debit); font-weight: 600; }
.credit { color: var(--credit); font-weight: 600; }
.balance-big { font-size: 2.25rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin: 0; }
.balance-caption { display: block; font-size: 1rem; font-weight: 600; margin-top: .15rem; }

/* Tabellen */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; }
table.data caption { text-align: left; }
table.data th, table.data td { padding: .75rem .75rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.data th { font-size: .95rem; font-weight: 650; color: var(--text-muted); white-space: nowrap; }
table.data th.num, table.data td.num { text-align: right; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
.row-actions { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center; }
.row-actions a { display: inline-flex; align-items: center; min-height: 44px; font-weight: 500; }
td.empty { text-align: center; color: var(--text-muted); padding: 1.5rem .75rem; }

@media (max-width: 760px) {
  table.data.stackable, table.data.stackable tbody, table.data.stackable tr, table.data.stackable td { display: block; width: 100%; }
  table.data.stackable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data.stackable tr { border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); margin-bottom: .75rem; padding: .25rem 0; }
  table.data.stackable tbody tr:hover { background: var(--surface); }
  table.data.stackable td { border: 0; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .4rem .9rem; text-align: right; }
  table.data.stackable td::before { content: attr(data-label); flex: 0 0 auto; color: var(--text-muted); font-weight: 600; font-size: .95rem; text-align: left; }
  table.data.stackable td.cell-actions { display: block; text-align: left; padding-top: .5rem; }
  table.data.stackable td.cell-actions::before { content: none; }
  table.data.stackable td.empty { display: block; text-align: center; }
  table.data.stackable td.empty::before { content: none; }
}

/* Badges */
.badge { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .95rem; font-weight: 600; line-height: 1.5; white-space: nowrap; border: 1px solid currentColor; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-bad { background: var(--bad-bg); color: var(--bad-fg); }
.badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

/* Formulare */
.form-card { max-width: 640px; }
.field { margin-bottom: 1.25rem; }
.field label, .field .label { display: block; font-weight: 600; margin-bottom: .35rem; }
.req { color: var(--danger); margin-left: .15rem; }
.help { color: var(--text-muted); font-size: .95rem; margin: .3rem 0 0; }
.field input[type=text], .field input[type=password], .field input[type=email], .field input[type=number],
.field input[type=date], .field input[type=search], .field select, .field textarea {
  display: block; width: 100%; min-height: var(--tap); padding: .6rem .8rem; font: inherit;
  color: var(--text); background: var(--surface); border: 2px solid var(--control-line); border-radius: var(--radius-s);
}
.field textarea { min-height: 7.5rem; resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field-check { display: flex; align-items: center; gap: .75rem; min-height: var(--tap); }
.field-check input[type=checkbox] { width: 28px; height: 28px; flex: 0 0 auto; accent-color: var(--accent); margin: 0; }
.field-check label { margin: 0; font-weight: 600; }
.field-error { color: var(--danger); font-weight: 600; margin: .35rem 0 0; padding: 0; list-style: none; }
.field-error li::before { content: "Fehler: "; }
.error-summary { background: var(--bad-bg); color: var(--bad-fg); border: 2px solid var(--bad-fg); border-radius: var(--radius-s); padding: .85rem 1rem; margin-bottom: 1.25rem; }
.error-summary p { margin: 0; font-weight: 700; }
.error-summary ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.form-note { color: var(--text-muted); font-size: .95rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.5rem; }

/* Ratenplan / Gefahrenzone */
.plan-box { border-left: 6px solid var(--info-fg); }
.danger-zone { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--danger); }
.danger-zone p { margin-bottom: .75rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 600; }

/* Login */
.auth-card { max-width: 440px; margin: 2rem auto; }

@media (max-width: 520px) {
  .user-box { width: 100%; justify-content: space-between; }
  h1 { font-size: 1.5rem; }
  .stat-value { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .btn:active { transform: none; }
}
@media (forced-colors: active) {
  .btn, .badge, .message { border: 2px solid ButtonText; }
}
.site-header nav { display: contents; }

/* Filterleiste der Kundenliste */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.filter-checks { border: 0; margin: 0 0 .5rem; padding: 0; min-width: 0; }
.filter-checks legend { font-weight: 600; padding: 0; margin-bottom: .25rem; }
.filter-card .form-actions { margin-top: .75rem; }

/* Kontoauszug-Zeitraum */
.statement-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 1rem; }
.statement-form .field { flex: 1 1 180px; max-width: 240px; }
.statement-form .btn { margin-bottom: 1.25rem; }
.tx-note { display: block; font-size: .95rem; color: var(--text-muted); font-weight: 500; }
.badge-reschedule { background: var(--info-bg); color: var(--info-fg); }
.auth-links { margin: 1rem 0 0; text-align: center; }
.auth-links a { display: inline-flex; align-items: center; min-height: 44px; }

/* PayPal-Eingänge */
.pp-filter { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; }
.pp-filter a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 1rem; border: 2px solid var(--control-line); border-radius: 999px; color: var(--text); text-decoration: none; font-weight: 500; }
.pp-filter a[aria-current="true"] { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
.pp-sub { display: block; font-size: .95rem; color: var(--text-muted); }
.raw-text { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .95rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 1rem; max-height: 28rem; overflow: auto; }

/* Balkendiagramme (Werte stehen immer auch als Text in der Tabelle) */
table.barchart th[scope=row] { font-size: 1rem; font-weight: 500; color: var(--text); white-space: normal; }
.bar-cell { width: 40%; min-width: 120px; }
.bar { display: block; height: 18px; border-radius: 4px; background: var(--accent); min-width: 0; }
.bar-bad { background: var(--debit); }
@media (max-width: 520px) { .bar-cell { width: 25%; min-width: 60px; } }

/* Interne Notizen */
.note-list { list-style: none; margin: 1.25rem 0 0; padding: 0; display: grid; gap: .75rem; }
.note-list li { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .85rem 1rem; }
.note-text { margin: 0 0 .35rem; overflow-wrap: anywhere; }
.note-meta { margin: 0 0 .6rem; color: var(--text-muted); font-size: .95rem; }
.note-list form { margin: 0; }

/* GiroCode */
.giro-layout { display: flex; flex-wrap: wrap; gap: 1.25rem; align-items: flex-start; }
.giro-layout img { background: #fff; padding: 8px; border-radius: var(--radius-s); border: 1px solid var(--line); max-width: 100%; height: auto; }
.giro-layout > div { flex: 1 1 260px; min-width: 0; }
.giro-box .kv dd { overflow-wrap: anywhere; }

/* Auswahlgruppen (Export) */
.choice-group { border: 0; margin: 0 0 1rem; padding: 0; min-width: 0; }
.choice-group legend { font-weight: 600; padding: 0; margin-bottom: .25rem; }
.field-check input[type=radio] { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--accent); margin: 0; }

/* Seitenaktionen, Gefahrenbereich, Löschlink */
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
@media (max-width: 520px) { .page-actions { width: 100%; } .page-actions .btn { flex: 1 1 100%; } }
.link-danger { color: var(--danger); }
.danger-zone-card { max-width: 640px; border-color: var(--danger); }
.danger-zone-card h2 { color: var(--danger); }
