:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9ff;
  --border: #e6e8f0;
  --text: #1e2233;
  --text-soft: #5b6178;
  --text-mute: #8a90a6;
  --primary: #6366f1;
  --primary-soft: #eef0ff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 1px 2px rgba(30, 34, 51, .06), 0 8px 24px rgba(30, 34, 51, .06);
  --radius: 14px;
  --radius-sm: 9px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10121c;
    --surface: #191c2b;
    --surface-2: #1f2333;
    --border: #2b3048;
    --text: #eceefb;
    --text-soft: #a9afc8;
    --text-mute: #767d9a;
    --primary: #818cf8;
    --primary-soft: #262a45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px rgba(0, 0, 0, .35);
  }
}

/* ---------- Farbschemata (frei im Kopfbereich wählbar) ----------
   „System" = kein data-theme-Attribut -> :root + prefers-color-scheme oben.
   Die festen Schemata überschreiben die System-Vorgabe (höhere Spezifität). */
:root[data-theme="light"] {
  --bg: #f4f5fb; --surface: #ffffff; --surface-2: #f8f9ff; --border: #e6e8f0;
  --text: #1e2233; --text-soft: #5b6178; --text-mute: #8a90a6;
  --primary: #6366f1; --primary-soft: #eef0ff;
  --success: #10b981; --danger: #ef4444; --warning: #f59e0b;
  --shadow: 0 1px 2px rgba(30, 34, 51, .06), 0 8px 24px rgba(30, 34, 51, .06);
}
:root[data-theme="dark"] {
  --bg: #10121c; --surface: #191c2b; --surface-2: #1f2333; --border: #2b3048;
  --text: #eceefb; --text-soft: #a9afc8; --text-mute: #767d9a;
  --primary: #818cf8; --primary-soft: #262a45;
  --success: #10b981; --danger: #ef4444; --warning: #f59e0b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 30px rgba(0, 0, 0, .35);
}
/* Ozean: kühles Türkis/Cyan */
:root[data-theme="ocean"] {
  --bg: #eaf4f7; --surface: #ffffff; --surface-2: #e2eff3; --border: #cbe3ea;
  --text: #0d2a33; --text-soft: #3d5a63; --text-mute: #6d8992;
  --primary: #0891b2; --primary-soft: #d3eff6;
  --success: #059669; --danger: #e11d48; --warning: #d97706;
  --shadow: 0 1px 2px rgba(8, 42, 51, .06), 0 8px 24px rgba(8, 42, 51, .09);
}
/* Sonnenuntergang: warmes, dunkles Rosé/Koralle */
:root[data-theme="sunset"] {
  --bg: #221824; --surface: #2e1f2e; --surface-2: #3a2733; --border: #4b3242;
  --text: #ffece2; --text-soft: #e6b7a9; --text-mute: #b98a86;
  --primary: #f43f5e; --primary-soft: #48232f;
  --success: #34d399; --danger: #f87171; --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 14px 34px rgba(40, 10, 25, .5);
}
/* Bonbon: kunterbunt, verspielt */
:root[data-theme="candy"] {
  --bg: #fdeaf7; --surface: #ffffff; --surface-2: #fbe6fb; --border: #f3cdec;
  --text: #2a123a; --text-soft: #6b3f79; --text-mute: #9a6fa6;
  --primary: #d81b9e; --primary-soft: #ffe0f6;
  --success: #06b64e; --danger: #ff2e63; --warning: #ff8a00;
  --shadow: 0 1px 2px rgba(120, 20, 90, .08), 0 12px 30px rgba(180, 30, 140, .16);
}
/* Matcha: ruhiges Grün mit Creme */
:root[data-theme="matcha"] {
  --bg: #eef3e6; --surface: #ffffff; --surface-2: #f3f7ec; --border: #dbe5cc;
  --text: #253321; --text-soft: #55684c; --text-mute: #83957a;
  --primary: #65a30d; --primary-soft: #e8f2d8;
  --success: #16a34a; --danger: #dc2626; --warning: #d97706;
  --shadow: 0 1px 2px rgba(37, 51, 33, .06), 0 8px 24px rgba(37, 51, 33, .08);
}
/* Flamingo: Pink mit Türkis-Akzenten */
:root[data-theme="flamingo"] {
  --bg: #fdf2f4; --surface: #ffffff; --surface-2: #fdeef3; --border: #f8d3de;
  --text: #35202b; --text-soft: #6d4a5b; --text-mute: #a37f90;
  --primary: #db2777; --primary-soft: #fde0ec;
  --success: #0d9488; --danger: #e11d48; --warning: #ea8600;
  --shadow: 0 1px 2px rgba(120, 30, 70, .07), 0 10px 26px rgba(190, 50, 110, .12);
}
/* Synthwave: dunkel mit Neon */
:root[data-theme="synthwave"] {
  --bg: #140b2b; --surface: #1d123d; --surface-2: #251a4a; --border: #3a2a68;
  --text: #f3e9ff; --text-soft: #c3b2e3; --text-mute: #8d7bb5;
  --primary: #e879f9; --primary-soft: #33204f;
  --success: #2dd4bf; --danger: #fb7185; --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 14px 34px rgba(90, 30, 160, .45);
}

:root[data-theme="candy"] body {
  background:
    radial-gradient(1200px 600px at 12% -8%, #ffd9f0 0, rgba(255, 217, 240, 0) 60%),
    radial-gradient(1000px 560px at 108% 8%, #d9e4ff 0, rgba(217, 228, 255, 0) 55%),
    radial-gradient(1000px 700px at 60% 108%, #d6fbef 0, rgba(214, 251, 239, 0) 55%),
    var(--bg);
  background-attachment: fixed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Header ----------
   Die Innenabstände berücksichtigen die Safe-Area-Insets (env(...)), damit der
   Header auf Geräten mit Notch/Statusleiste nicht verdeckt wird (Android
   Edge-to-Edge, iOS). Ohne Insets sind die Werte 0 – Desktop bleibt unverändert. */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(22px + env(safe-area-inset-right, 0px))
           14px calc(22px + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; }
/* "Donut-Iris": Donut-Diagramm mit Pupille + Glanzlicht (siehe gen_icon.py) */
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background:
    radial-gradient(circle closest-side at 44% 44%, #ffffff 0 9%, rgba(255, 255, 255, 0) 12%),
    radial-gradient(circle closest-side at 50% 50%, #1e1b4b 0 34%, rgba(30, 27, 75, 0) 37%),
    conic-gradient(#ffffff 0 40%, #34d399 40% 65%, #fbbf24 65% 85%, #f87171 85% 100%);
  box-shadow: inset 0 0 0 6px var(--primary);
}
.brand-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-claim { font-size: .74rem; color: var(--text-soft); letter-spacing: .01em; }
.brand-spar { color: var(--primary); }
/* flex-wrap: sonst schiebt die Bedienleiste auf schmalen Displays die ganze Seite
   in die Breite (horizontales Scrollen) statt umzubrechen. */
.header-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.lang-seg button { padding: 5px 11px; font-size: .8rem; }
.view-filter { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-soft); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px;
  padding: 0 calc(16px + env(safe-area-inset-right, 0px)) 0 calc(16px + env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  border: none; background: none; cursor: pointer;
  padding: 13px 16px; font-size: .93rem; font-weight: 500;
  color: var(--text-soft); border-bottom: 2px solid transparent;
  white-space: nowrap; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Layout ---------- */
.app-main {
  max-width: 1080px; margin: 0 auto;
  padding: 24px calc(20px + env(safe-area-inset-right, 0px))
           calc(64px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; }
.section-head h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.01em; }
.section-head p { margin: 2px 0 0; color: var(--text-mute); font-size: .88rem; }

/* ---------- Cards & KPIs ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 20px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.kpi { padding: 18px 20px; }
.kpi-label { font-size: .8rem; color: var(--text-mute); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.7rem; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi-sub { font-size: .82rem; color: var(--text-soft); margin-top: 3px; }
.kpi.accent .kpi-value { color: var(--primary); }
.kpi.pos .kpi-value { color: var(--success); }
.kpi.neg .kpi-value { color: var(--danger); }

/* Hero-Karte: die eine Zahl, wegen der man die App öffnet (Frei verfügbar) */
.kpi-hero { margin-bottom: 14px; padding: 22px 24px; }
.kpi-hero .kpi-value { font-size: 2.4rem; }

/* Kompaktes Raster für die übrigen Kennzahlen unter der Hero-Karte */
.kpi-mini { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi-mini .kpi { padding: 13px 16px; }
.kpi-mini .kpi-value { font-size: 1.2rem; margin-top: 3px; }
.kpi-mini .kpi-sub { font-size: .76rem; }

.dash-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 780px) { .dash-grid { grid-template-columns: 320px 1fr; align-items: start; } }

/* ---------- Donut ---------- */
.donut-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.donut { position: relative; width: 210px; height: 210px; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; pointer-events: none;
}
.donut-center .big { font-size: 1.25rem; font-weight: 700; }
.donut-center .small { font-size: .72rem; color: var(--text-mute); }
.donut-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: .8rem; color: var(--text-soft); }
.donut-legend > span { display: flex; align-items: center; gap: 6px; }

/* ---------- Category bars ---------- */
.cat-list { display: flex; flex-direction: column; gap: 15px; }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.cat-row.clickable { cursor: pointer; border-radius: 10px; margin: 0 -8px; padding: 4px 8px; }
.cat-row.clickable:hover, .cat-row.clickable:focus-visible { background: var(--surface-2); outline: none; }
.cat-row .name { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.cat-row .amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.cat-row .pct { font-size: .8rem; color: var(--text-mute); text-align: right; }
.bar { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; }

/* ---------- Per-person mini ---------- */
/* Mindestbreite so wählen, dass "Einnahmen 2.800,00 €" in eine Zeile passt –
   auf schmalen Handys stapeln sich die Karten dann einspaltig statt zu quetschen. */
.person-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); margin-top: 20px; }
.person-card { padding: 14px 16px; }
.person-card h4 { margin: 0 0 8px; font-size: .95rem; }
.person-card .line { display: flex; justify-content: space-between; gap: 4px 10px; flex-wrap: wrap; font-size: .85rem; color: var(--text-soft); }
.person-card .line b { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: auto; }
.person-card .line.neg b { color: var(--danger); }

/* ---------- Tables / lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 14px; align-items: center;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.item.inactive { opacity: .55; }
.item .swatch { width: 14px; height: 14px; border-radius: 4px; }
.item .main { min-width: 0; }
.item .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item .meta { font-size: .8rem; color: var(--text-mute); margin-top: 2px; }
.item .value { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.item .value small { display: block; font-weight: 500; color: var(--text-mute); font-size: .72rem; }
.item .actions { display: flex; gap: 6px; }

.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.tag.muted { background: var(--surface-2); color: var(--text-mute); }
.tag.warn { background: rgba(245, 158, 11, .16); color: var(--warning); }
.tag.dyn { background: rgba(16, 185, 129, .16); color: var(--success); }
.tag.vari { background: rgba(59, 130, 246, .16); color: #3b82f6; }

/* Monatswerte (tatsächliche Ausgaben je Monat, z. B. Lebensmittel) */
.mw-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.mw-row { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.mw-row b { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- Bar erfassen (Schnelleingabe für Bargeld) ----------
   Nutzt bewusst nur die vorhandenen Farb-Token, damit alle Farbschemata
   (Hell, Dunkel, Ozean, Bonbon, Matcha …) ohne Zusatzregeln mitziehen. */
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Kopfzeile im Bar-Dialog: Monat + bisherige Bar-Summe, zugleich Weg in die Monatsliste */
.cash-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  width: 100%; padding: 0; border: none; background: none; cursor: pointer;
  font-family: inherit; color: inherit; text-align: left;
}
.cash-head .m { font-size: .82rem; color: var(--text-mute); }
.cash-head .sum { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.cash-head:hover .m, .cash-head:hover .sum { color: var(--primary); }

/* Kategorie-Raster: ein Tipper statt eines Formulars mit zehn Feldern */
.cash-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px 6px; }
.cash-tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  border: none; background: none; padding: 0; cursor: pointer;
  font-family: inherit; color: var(--text-soft);
}
.cash-tile .ico {
  width: 54px; height: 54px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; line-height: 1;
  background: var(--surface-2); border: 1.5px solid var(--border);
}
.cash-tile .ico .dot { width: 16px; height: 16px; }
.cash-tile .lbl { font-size: .71rem; font-weight: 600; line-height: 1.15; text-align: center; }
.cash-tile:hover .ico, .cash-tile:focus-visible .ico { border-color: var(--primary); background: var(--primary-soft); }
.cash-tile:hover .lbl, .cash-tile:focus-visible .lbl { color: var(--text); }
.cash-tile:active .ico { transform: scale(.94); }
.cash-tile.add .ico { border-style: dashed; font-size: 1.3rem; color: var(--text-mute); }

/* Betragsanzeige über dem Zahlenblock */
.cash-amount { text-align: center; padding: 6px 0 2px; }
.cash-amount .cat { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; font-weight: 600; color: var(--text-soft); }
.cash-amount .val { font-size: 2.7rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.cash-amount .val.empty { color: var(--text-mute); }

/* Zahlenblock: große Flächen für den Daumen */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  font-family: inherit; font-size: 1.4rem; font-weight: 600;
  padding: 13px 0; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}
.keypad button:hover { border-color: var(--primary); }
.keypad button:active { background: var(--primary-soft); }

/* Monatsliste: Bar-Einträge je Kategorie, aufklappbar bis zum Einzelbetrag */
.cash-log { display: flex; flex-direction: column; gap: 8px; }
.cash-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.cash-group > summary {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  padding: 11px 14px; list-style: none;
}
.cash-group > summary::-webkit-details-marker { display: none; }
.cash-group > summary .e { font-size: 1.15rem; line-height: 1; }
.cash-group > summary .main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cash-group > summary .n { font-weight: 600; font-size: .92rem; }
.cash-group > summary .s { font-size: .76rem; color: var(--text-mute); margin-top: 1px; }
.cash-group > summary b { font-variant-numeric: tabular-nums; }
.cash-part {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  margin: 0 14px; padding: 7px 0; border-top: 1px solid var(--border);
  font-size: .86rem; color: var(--text-soft);
}
.cash-part b { font-variant-numeric: tabular-nums; color: var(--text); }
.cash-part:last-child { padding-bottom: 11px; }

/* Monatswerte-Verlauf: Posten-Auswahl als Chips */
.mw-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.mw-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft); border-radius: 999px; padding: 6px 13px; font-family: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.mw-chip:hover { color: var(--text); }
.mw-chip.active { background: var(--surface); color: var(--text); border-color: var(--primary); box-shadow: var(--shadow); }
.mw-chip-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* Monatswerte-Diagramm */
.trend-svg { width: 100%; height: auto; display: block; }
.trend-grid { stroke: var(--border); stroke-width: 1; }
.trend-axis { fill: var(--text-mute); font-size: 11px; }

/* Kategorie-Schnellwechsel: klickbarer Farbpunkt + Etikett, Popover-Menü */
.cat-swatch { appearance: none; -webkit-appearance: none; border: none; padding: 0; cursor: pointer; }
.cat-swatch:hover { outline: 2px solid var(--primary); outline-offset: 1px; }
button.cat-chip { border: none; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 5px; }
button.cat-chip:hover { filter: brightness(.96); }
.cat-chip .caret { font-size: .82em; opacity: .55; line-height: 1; }
.cat-menu { position: fixed; z-index: 70; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 190px; max-height: 320px; overflow-y: auto; }
.cat-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: none; cursor: pointer; font-family: inherit; font-size: .9rem; color: var(--text); padding: 9px 10px; border-radius: 8px; }
.cat-item:hover, .cat-item:focus { background: var(--surface-2); outline: none; }
.cat-item.active { font-weight: 700; }
.cat-item .dot { width: 12px; height: 12px; flex: none; }
.cat-item-name { flex: 1 1 auto; }
.cat-item svg { flex: none; color: var(--primary); }

.empty { text-align: center; padding: 46px 20px; color: var(--text-mute); }
.empty svg { opacity: .5; margin-bottom: 8px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit; font-size: .9rem; font-weight: 600; cursor: pointer;
  border-radius: var(--radius-sm); padding: 9px 16px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: background .12s, border-color .12s;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn svg { display: block; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: rgba(239, 68, 68, .1); }
.btn.icon { padding: 7px 9px; line-height: 1; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 6px 11px; font-size: .82rem; }

/* ---------- Forms / modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 20, .5);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; border: 1px solid var(--border);
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.modal.wide { max-width: 620px; }

/* Bank-Import-Vorschau */
.imp-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.imp-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.imp-row input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--primary); }
.imp-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.imp-main input[type="text"] { width: 100%; }
.imp-cat { display: flex; flex-wrap: wrap; gap: 6px; }
.imp-amount { flex: none; font-weight: 700; white-space: nowrap; }
/* Beträge mit gleich breiten Ziffern – Spalten und Listen flackern nicht */
.value, .imp-amount, .kpi-value, .donut-center .big, .mw-row b, .imp-part-amount { font-variant-numeric: tabular-nums; }
.imp-months { font-size: .78rem; color: var(--text-mute); }
.imp-parts { margin-top: 2px; font-size: .85rem; }
.imp-parts summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.imp-part { display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 2px; cursor: pointer; flex-wrap: wrap; }
.imp-part select { width: auto; max-width: 170px; padding: 4px 8px; font-size: .82rem; flex: none; }
.mw-list .imp-parts { margin: 0 0 6px 4px; }
.imp-part input[type="checkbox"] { width: 15px; height: 15px; }
.imp-part-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; color: var(--text-soft); }
.imp-part-amount { flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }

.imp-unmatched { margin-top: 10px; }
.imp-unmatched summary { cursor: pointer; font-weight: 600; color: var(--text-soft); }
.imp-unmatched .imp-list { margin-top: 8px; }
.imp-unmatched select { align-self: flex-start; }
.imp-merchant { font-weight: 600; overflow-wrap: anywhere; }

/* Über-Dialog + Info-Button */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text-soft); cursor: pointer; }
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.about-head { display: flex; align-items: center; gap: 14px; }
.about-head .brand-mark { width: 40px; height: 40px; flex: none; }
.about-name { font-size: 1.25rem; font-weight: 800; }
.about-ver { margin-top: 4px; font-size: .82rem; font-weight: 600; color: var(--primary); }
.about-sub { font-weight: 700; color: var(--text); }
.about-meta { display: flex; flex-direction: column; gap: 6px; }
.settings-btn { position: relative; }
.private-btn.is-on { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

/* Schalter im Einstellungs-Dialog (z. B. Beträge verbergen) */
.switch { display: flex; align-items: center; gap: 10px; font-size: .92rem; font-weight: 600; color: var(--text); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

/* Einstellungs-Dialog und „Mehr“-Menü */
.more-list { gap: 8px; }
.more-list .btn { justify-content: flex-start; width: 100%; padding: 13px 16px; font-size: .95rem; }
.about-link { color: var(--primary); font-weight: 600; text-decoration: none; }
.about-link:hover { text-decoration: underline; }

/* Aufteilung: Umschalter */
.split-toggle { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.split-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.custom-share-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.custom-share-row > span:first-child { min-width: 140px; font-weight: 600; font-size: .9rem; }
.custom-share-row input { width: 90px; }

/* Sparen: Unterüberschriften + Sparziele */
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.sub-head { margin: 6px 2px 12px; font-size: 1.02rem; }
.btn-small { padding: 7px 14px; font-size: .86rem; }
.goal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.goal-card { display: flex; flex-direction: column; gap: 10px; }
.goal-card.done { border-color: var(--success); }
.goal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.goal-name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.goal-bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.goal-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.goal-card.done .goal-bar > span { background: var(--success); }
.goal-figs { display: flex; align-items: baseline; gap: 4px; }
.goal-figs b { font-size: 1.05rem; }
.goal-figs .goal-pct { margin-left: auto; font-weight: 700; color: var(--text-mute); }
.goal-actions { display: flex; align-items: center; gap: 12px; }
.tag.ok { background: rgba(16, 185, 129, .16); color: var(--success); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-soft); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input, select, textarea {
  font-family: inherit; font-size: .95rem; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
textarea { resize: vertical; min-height: 60px; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-picker input[type=radio] { display: none; }
.color-picker label { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; }
.color-picker input:checked + label { border-color: var(--text); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%) translateY(30px);
  background: var(--text); color: var(--bg); padding: 11px 20px; border-radius: 999px;
  font-size: .88rem; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60;
  max-width: min(92vw, 480px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Segmented toggle (Monat/Jahr) ---------- */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: none; background: none; cursor: pointer; font-family: inherit; font-size: .85rem; font-weight: 600; color: var(--text-soft); padding: 6px 15px; border-radius: 999px; }
.seg button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.seg.seg-sm { flex-wrap: wrap; justify-content: center; }
.seg.seg-sm button { padding: 5px 10px; font-size: .78rem; }

/* ---------- Filterleiste ---------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filter-bar select, .filter-bar input { width: auto; }
.filter-bar input.search { flex: 1 1 200px; min-width: 150px; }
.filter-summary { font-size: .83rem; color: var(--text-mute); margin: 0 0 14px; }

/* ---------- Fälligkeiten ---------- */
.due-list { display: flex; flex-direction: column; gap: 12px; }
.due-row { display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 12px; align-items: center; }
.due-main { min-width: 0; }
.due-name { font-weight: 600; }
.due-badge { font-size: .75rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-soft); white-space: nowrap; }
.due-badge.due-near { background: rgba(245, 158, 11, .16); color: var(--warning); }
.due-badge.due-soon { background: rgba(239, 68, 68, .15); color: var(--danger); }
.due-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.hint { font-size: .82rem; color: var(--text-mute); }
/* Warnhinweis, der nicht übersehen werden darf – etwa wenn der Speicher voll ist. */
.hint.warn { color: var(--danger); font-weight: 600; }
.data-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }

/* ---------- Druck / PDF: Ein-Seiten-Zusammenfassung ---------- */
#printRoot { display: none; }
@media print {
  .app-header, .tabs, .bottom-nav, .fab, .app-main, .toast, #modalRoot { display: none !important; }
  body { background: #fff; color: #000; }
  #printRoot { display: block; padding: 0; font-size: 12px; }
  #printRoot h1 { font-size: 20px; margin: 0 0 2px; }
  #printRoot h2 { font-size: 14px; margin: 16px 0 6px; }
  #printRoot .print-meta { color: #555; font-size: 11px; margin: 0 0 14px; }
  #printRoot .print-table { width: 100%; border-collapse: collapse; font-size: 12px; }
  #printRoot .print-table th, #printRoot .print-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid #ccc; }
  #printRoot .print-table th { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #555; }
  #printRoot .print-table th:not(:first-child), #printRoot .print-table td:not(:first-child) { text-align: right; }
  #printRoot .print-footer { margin-top: 18px; font-size: 10px; color: #777; }
}

/* ---------- Handy / kleine Bildschirme ---------- */
@media (max-width: 560px) {
  .app-header {
    padding: calc(12px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px))
             12px calc(16px + env(safe-area-inset-left, 0px));
  }
  .tabs { padding: 0 calc(10px + env(safe-area-inset-right, 0px)) 0 calc(10px + env(safe-area-inset-left, 0px)); }
  .tab { padding: 12px 12px; }

  /* Bedienleiste im Header: enger, Auswahlfelder dürfen schrumpfen */
  .header-controls { gap: 10px 12px; }
  .view-filter select { min-width: 0; max-width: 42vw; }
  .app-main {
    padding: 16px calc(12px + env(safe-area-inset-right, 0px))
             calc(56px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
  }

  .section-head { flex-wrap: wrap; }
  .section-head h2 { font-size: 1.2rem; }
  .kpi-value { font-size: 1.45rem; }
  .kpi { padding: 15px 16px; }
  .card { padding: 16px; }

  /* Listeneinträge: Aktions-Buttons in eigene Zeile (besser tippbar),
     insgesamt kompakter – leere Wert-Spalten (z. B. bei Kategorien)
     erzeugen sonst tote Fläche in der Karte. */
  .item { grid-template-columns: auto 1fr auto; padding: 12px 14px; }
  .item .value:empty { display: none; }
  .item .actions { grid-column: 1 / -1; justify-content: flex-end; margin-top: 0; }
  /* Fingerfreundliche Trefferfläche (~40 px) für die Aktions-Knöpfe */
  .item .actions .btn.icon { padding: 10px 13px; }

  /* Dialoge als Bottom-Sheet: rutschen von unten hoch und liegen in der
     Daumenzone; auf dem Desktop bleiben sie mittig. */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    max-width: none; border-radius: 18px 18px 0 0; border-bottom: none;
    max-height: 88vh; padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: sheet-up .22s ease-out;
  }

  /* +-Knopf beim Scrollen zurücknehmen, damit er keine Beträge verdeckt */
  .fab { transition: opacity .2s; }
  .fab.scrolling { opacity: .3; pointer-events: none; }

  /* Fälligkeiten: Betrag/Badge dürfen umbrechen */
  .due-row { grid-template-columns: auto 1fr auto; }
  .due-amount { grid-column: 2 / -1; text-align: right; }

  /* Dialog-Felder untereinander */
  .field-row { grid-template-columns: 1fr; }
  .modal-body { padding: 18px 16px; }
  .modal-head, .modal-foot { padding-left: 16px; padding-right: 16px; }
}

/* ---------- Emoji-Auswahl (Kategorie-Dialog) ---------- */
.emoji-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-picker input { position: absolute; opacity: 0; pointer-events: none; }
.emoji-picker label {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 38px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  font-size: 1.15rem; cursor: pointer;
}
.emoji-picker label.emoji-none { font-size: .82rem; color: var(--text-soft); font-weight: 600; }
.emoji-picker input:checked + label { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); background: var(--surface); }

/* ---------- Konfetti (Sparziel erreicht) ---------- */
.confetti { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 300; }
.confetti i {
  position: absolute; top: -5vh; width: 9px; height: 14px; border-radius: 2px;
  animation: confetti-fall 2.1s ease-in forwards;
}
@keyframes confetti-fall { to { transform: translateY(112vh) rotate(720deg); } }

/* ---------- Untere Tab-Leiste + Schnelleingabe (nur schmale Bildschirme) ----------
   Auf dem Handy sitzt die Navigation in der Daumenzone; die obere Tab-Leiste
   wird dort ausgeblendet. Desktop (Fenster breiter als 700 px) bleibt unverändert. */
.bottom-nav { display: none; }
.fab { display: none; }

@media (max-width: 700px) {
  .tabs { display: none; }

  .bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px calc(6px + env(safe-area-inset-right, 0px))
             calc(4px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px));
  }
  .bnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 7px 2px 6px; border: none; background: none; cursor: pointer;
    font-family: inherit; font-size: .68rem; font-weight: 600; color: var(--text-mute);
    border-radius: 10px;
  }
  .bnav-item svg { width: 22px; height: 22px; }
  .bnav-item.is-active { color: var(--primary); }

  .fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed; z-index: 49;
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--primary); color: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  }
  .fab svg { width: 26px; height: 26px; }
  .fab:active { transform: scale(.94); }

  /* Inhalt und Toast über der unteren Leiste halten. Der Puffer muss auch den
     +-Knopf einrechnen (ragt bis ~134 px hinein), sonst verdeckt er die
     Aktionen des letzten Listeneintrags. */
  .app-main { padding-bottom: calc(160px + env(safe-area-inset-bottom, 0px)); }
  /* Toast über dem +-Knopf (FAB endet bei ~134 px), sonst verdeckt er die Meldung. */
  .toast { bottom: calc(148px + env(safe-area-inset-bottom, 0px)); }

  /* Kopf-Knöpfe, die dasselbe tun wie der +-Knopf unten rechts, sind auf dem
     Handy doppelt – ausblenden spart Platz und vermeidet zwei gleiche CTAs. */
  .section-head .fab-dup { display: none; }

  /* Header in eine Zeile: das Wort "Ansicht" ist auf dem Handy verzichtbar
     (das Auswahlfeld trägt ein aria-label), dann passen Marke, Filter und
     Zahnrad nebeneinander. */
  .app-header { gap: 8px 12px; }
  .header-controls { gap: 8px; }
  .view-filter > span:first-child { display: none; }
  /* Claim weglassen: auf dem Handy zählt der Platz für Filter und Zahnrad. */
  .brand-claim { display: none; }

  /* Drei Mini-KPIs auf zwei Spalten: die letzte Karte nimmt die volle Breite,
     statt allein mit Loch daneben zu hängen. */
  .kpi-mini .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* ---------- Bottom-Sheet-Animation (Mobil) ---------- */
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }
