/* Familienfinanzen 360° – Design-Tokens und Komponenten
   Ziel: WCAG 2.2 AA (Kontrast ≥ 4.5:1 Text, ≥ 3:1 Bedienelemente), Touch-Ziele ≥ 44 px. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-accent: #e3f1f2;
  --ink: #1c2738;
  --ink-2: #4a5566;          /* 7.4:1 auf weiss */
  --muted: #5b6573;          /* 5.9:1 auf weiss */
  --line: #d3dce6;
  --line-strong: #8a96a5;    /* 3.1:1 für Rahmen von Eingabefeldern */
  --accent: #14646f;         /* 6.3:1 auf weiss */
  --accent-ink: #ffffff;
  --accent-soft: #d7ecee;
  --ok: #23703f;             /* 5.9:1 */
  --ok-soft: #e1f2e6;
  --warn: #8a4f00;           /* 6.2:1 */
  --warn-soft: #fbebd3;
  --bad: #b3261e;            /* 6.0:1 */
  --bad-soft: #fbe3e1;
  --info: #1f5a85;
  --info-soft: #e3eef7;
  --focus: #0b57d0;
  --shadow: 0 1px 2px rgba(28, 39, 56, .06), 0 2px 8px rgba(28, 39, 56, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;
  --gutter: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151d; --surface: #17202b; --surface-2: #1e2935; --surface-accent: #15343a;
    --ink: #e8edf3; --ink-2: #c3ccd7; --muted: #a7b2bf; --line: #2b3846; --line-strong: #6f7d8d;
    --accent: #5cc3cf; --accent-ink: #0b1d21; --accent-soft: #173f45;
    --ok: #6fd08f; --ok-soft: #173826; --warn: #f2b45c; --warn-soft: #3a2a12;
    --bad: #ff8a80; --bad-soft: #3d1c1a; --info: #8cc4f0; --info-soft: #172d40; --focus: #8ab4ff;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f151d; --surface: #17202b; --surface-2: #1e2935; --surface-accent: #15343a;
  --ink: #e8edf3; --ink-2: #c3ccd7; --muted: #a7b2bf; --line: #2b3846; --line-strong: #6f7d8d;
  --accent: #5cc3cf; --accent-ink: #0b1d21; --accent-soft: #173f45;
  --ok: #6fd08f; --ok-soft: #173826; --warn: #f2b45c; --warn-soft: #3a2a12;
  --bad: #ff8a80; --bad-soft: #3d1c1a; --info: #8cc4f0; --info-soft: #172d40; --focus: #8ab4ff;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .8125rem; }
.strong { font-weight: 700; }
.right { text-align: right; }
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden-mobile { display: none; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--surface); padding: 10px 14px; z-index: 100; border-radius: 8px; }
.skip-link:focus { top: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Layout / Shell ---------- */
.app { min-height: 100vh; }
.main { padding: 16px var(--gutter) calc(152px + env(safe-area-inset-bottom)); max-width: 1440px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; min-height: 56px; }
.topbar .title { font-weight: 700; font-size: 1.05rem; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); z-index: 30; }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; text-decoration: none; color: var(--muted); font-size: .75rem; position: relative; }
.bottom-nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
.bottom-nav a[aria-current="page"] .nav-icon { background: var(--accent-soft); }
.nav-icon { width: 44px; height: 28px; border-radius: 14px; display: grid; place-items: center; }
.nav-badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; font-size: .72rem; font-weight: 700; display: grid; place-items: center; padding: 0 5px; }
.fab { position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 28px; border: 0; background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 12px rgba(0,0,0,.2); display: grid; place-items: center; z-index: 25; cursor: pointer; }
.sidebar { display: none; }

@media (min-width: 600px) {
  .hidden-mobile { display: initial; }
  .only-mobile { display: none !important; }
  .bottom-nav { display: none; }
  .fab { bottom: 24px; right: 24px; }
  .app { display: grid; grid-template-columns: 88px minmax(0, 1fr); }
  .sidebar { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 12px 8px; }
  .sidebar .brand { display: none; }
  .sidebar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-size: .72rem; text-align: center; min-height: var(--tap); position: relative; }
  .sidebar a .label-long { display: none; }
  .sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
  .sidebar .nav-badge { left: auto; right: 8px; top: 4px; }
  .sidebar .group-label { display: none; }
  .main { padding: 24px 24px 48px; }
  .topbar { display: none; }
}
@media (min-width: 1024px) {
  .app { grid-template-columns: 248px minmax(0, 1fr); }
  .sidebar { padding: 16px 12px; }
  .sidebar .brand { display: block; font-weight: 800; padding: 6px 10px 12px; font-size: 1.05rem; }
  .sidebar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; }
  .sidebar a { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .9375rem; padding: 10px 12px; text-align: left; }
  .sidebar a .label-short { display: none; }
  .sidebar a .label-long { display: inline; }
  .sidebar .nav-badge { position: static; margin-left: auto; }
  .sidebar .group-label { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 12px 4px; }
}

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.grid { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-hero { grid-template-columns: minmax(300px, 0.9fr) 1.6fr; }
}

/* ---------- Karten ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.accent { background: var(--surface-accent); border-color: var(--accent); }
.card.warn { background: var(--warn-soft); border-color: var(--warn); }
.card.bad { background: var(--bad-soft); border-color: var(--bad); }
.card.flat { box-shadow: none; }
.card h2 { font-size: 1rem; margin-bottom: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

.hero-value { font-size: clamp(2rem, 8vw, 2.75rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 8px; }
.hero-label { font-weight: 700; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: var(--tap); height: var(--tap); border-radius: 10px; border: 1px solid transparent; background: transparent; display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }
.link-btn { background: none; border: 0; padding: 10px 0; min-height: var(--tap); color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }

/* ---------- Status / Chips ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 700; border: 1px solid currentColor; background: var(--surface); }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); } .pill.info { color: var(--info); } .pill.muted { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: var(--tap); padding: 0 14px; border-radius: 22px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.status-text { font-size: .875rem; font-weight: 600; }
.status-text.ok { color: var(--ok); } .status-text.warn { color: var(--warn); } .status-text.bad { color: var(--bad); } .status-text.muted { color: var(--muted); }

/* ---------- Fortschritt ---------- */
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.ok > span { background: var(--ok); } .bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); } .bar.muted > span { background: var(--line-strong); }

/* ---------- Listen ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; min-height: 52px; width: 100%; background: none; border: 0; text-align: left; cursor: default; }
button.list-row, a.list-row { cursor: pointer; text-decoration: none; color: inherit; }
button.list-row:hover, a.list-row:hover { background: var(--surface-2); }
.list-row .meta { font-size: .8125rem; color: var(--muted); }
.day-head { position: sticky; top: 56px; background: var(--bg); padding: 8px 0 4px; font-size: .8125rem; font-weight: 700; color: var(--muted); z-index: 5; }
@media (min-width: 600px) { .day-head { top: 0; } }

.budget-row { padding: 12px 0; }
.budget-row .line1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; }
.budget-row .line3 { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.data { border-collapse: collapse; width: 100%; font-size: .9375rem; }
table.data th, table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { background: var(--surface-2); font-size: .8125rem; color: var(--ink-2); position: sticky; top: 0; z-index: 1; }
table.data td.num, table.data th.num { text-align: right; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr[aria-selected="true"] { background: var(--accent-soft); }
table.data .sticky-col { position: sticky; left: 0; background: inherit; z-index: 2; }
table.grid-year td input { width: 88px; min-height: 36px; text-align: right; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 4px 6px; }
table.grid-year td input:hover, table.grid-year td input:focus { border-color: var(--line-strong); background: var(--surface); }
table.grid-year th.sticky-col, table.grid-year td.sticky-col { background: var(--surface); min-width: 180px; }

/* ---------- Formulare ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .label { font-weight: 600; font-size: .9375rem; }
.field .hint { font-size: .8125rem; color: var(--muted); }
.field .error { font-size: .875rem; color: var(--bad); font-weight: 600; }
.input, select.input, textarea.input { min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); width: 100%; }
textarea.input { min-height: 96px; }
.input[aria-invalid="true"] { border-color: var(--bad); border-width: 2px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.form-grid { display: grid; gap: 14px; }
@media (min-width: 600px) { .form-grid.two { grid-template-columns: 1fr 1fr; } }

/* ---------- Sheet (unten mobil, rechts Desktop) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 24, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px rgba(0,0,0,.2); }
.sheet-grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: -8px; background: var(--surface); padding: 6px 0; z-index: 2; }
.sheet-head h2 { margin: 0; }
@media (min-width: 900px) {
  .sheet-backdrop { justify-content: flex-end; align-items: stretch; }
  .sheet { width: 480px; max-height: 100vh; height: 100vh; border-radius: 0; padding: 16px 20px; }
  .sheet-grab { display: none; }
}

/* ---------- Toast ---------- */
.toast-region { position: fixed; left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none; align-items: center; }
@media (min-width: 600px) { .toast-region { bottom: 24px; left: auto; right: 24px; align-items: flex-end; } }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 8px 8px 8px 14px; display: flex; align-items: center; gap: 12px; max-width: 520px; width: 100%; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.toast.error { background: var(--bad); color: #fff; }
.toast .btn { min-height: 40px; background: transparent; border-color: transparent; color: #8fd3db; }
:root[data-theme="dark"] .toast .btn { color: var(--accent-ink); }

/* ---------- Prüfen (Kartenstapel) ---------- */
.review-card { max-width: 560px; margin: 0 auto; }
.review-amount { font-size: 2rem; font-weight: 800; }
.review-actions { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; margin-top: 16px; }
.notice { border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: .9375rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--info-soft); color: var(--info); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Diagramm ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .series { stroke: var(--accent); fill: none; stroke-width: 2.5; }
.chart .area { fill: var(--accent-soft); opacity: .6; }
.chart .threshold { stroke: var(--warn); stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart .min-dot { fill: var(--bad); }
.chart .min-label { fill: var(--bad); font-size: 12px; font-weight: 700; }

/* ---------- Herleitung ---------- */
.derivation dt { font-weight: 600; }
.derivation .comp { padding: 10px 0; border-bottom: 1px solid var(--line); }
.derivation .comp:last-child { border-bottom: 0; }
.derivation details summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; justify-content: space-between; gap: 8px; list-style: none; }
.derivation details summary::-webkit-details-marker { display: none; }
.derivation .items { padding: 4px 0 4px 12px; font-size: .875rem; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; min-height: 18px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.kbd { font-family: ui-monospace, monospace; font-size: .8rem; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 440px; }
.steps { display: flex; gap: 6px; margin-bottom: 12px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); }
.steps span.done { background: var(--accent); border-color: var(--accent); }
.month-switch { display: flex; align-items: center; gap: 4px; }
.month-switch .label { min-width: 150px; text-align: center; font-weight: 700; font-size: 1.1rem; }
.hub-grid { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.hub-grid a { display: flex; flex-direction: column; gap: 6px; padding: 14px; min-height: 88px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); font-weight: 600; }
.hub-grid a .muted { font-weight: 400; font-size: .8125rem; }

/* ---------- Ergänzungen nach Browser-Prüfung ---------- */
.app > div { min-width: 0; }
.card .review-amount { font-size: 2rem; margin: 4px 0; }
.card-head a, .notice a, .page-head a.small { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); min-width: var(--tap); padding: 0 4px; }
.budget-row > a { display: block; padding: 6px 0; min-height: var(--tap); }
.warn-list { display: grid; gap: 12px; list-style: none; margin: 0; padding: 0; }
.warn-list > li { border: 0; }
@media (min-width: 900px) { .warn-list { grid-template-columns: repeat(3, 1fr); } .warn-list .card { height: 100%; } }
.chip-del { width: 40px; height: 40px; }
@media print {
  .sidebar, .bottom-nav, .fab, .topbar, .page-head .row, .toast-region, button { display: none !important; }
  .app { display: block; } .main { padding: 0; } .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
/* Screenreader-Texte bleiben im Scrollbereich der Tabelle (sonst entsteht Seiten-Scrollbreite) */
.table-wrap, .money { position: relative; }
/* Programmatischer Fokus auf Seitentitel (für Screenreader) ohne sichtbaren Rahmen */
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus, main[tabindex="-1"]:focus { outline: none; }
