:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: rgba(255, 255, 255, 0.10);
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --series-1: #3987e5;   /* Einnahmen / Hauptserie */
  --series-2: #d95926;   /* Ausgaben */
  --good: #0ca30c;
  --critical: #e66767;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface-1: #fcfcfb;
    --surface-2: #f0efec;
    --border: rgba(11, 11, 11, 0.10);
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --good: #006300;
    --critical: #d03b3b;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 18px; margin: 0; flex: 1; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav span { min-width: 120px; text-align: center; font-weight: 600; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; width: 36px; height: 36px;
}

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.view[hidden] { display: none; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--text-secondary); font-weight: 600; }

/* Stat-Kacheln */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat .label { font-size: 13px; color: var(--text-secondary); }
.stat .value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
@media (max-width: 480px) { .stat .value { font-size: 16px; } }

.hint {
  display: block; width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; color: var(--text-primary);
}

/* Kleine Utilities */
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.strong { font-weight: 600; }
.muted { color: var(--text-muted); }
.muted-text { color: var(--text-secondary); font-size: 13px; margin: 0 0 8px; }
.small { font-size: 12px; }
.indent { padding-left: 22px; }
.ellip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.err { color: var(--critical); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { margin: 0; }

/* Budget */
:root { --warning: #fab219; --status-critical: #d03b3b; }
.b-total { padding-bottom: 12px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.b-row { padding: 8px 0; cursor: pointer; }
.b-row.sub { padding: 6px 0 6px 18px; }
.b-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 14px; margin-bottom: 6px; }
.b-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { display: inline-block; width: 16px; color: var(--text-muted); }
.meter { position: relative; height: 10px; background: var(--surface-2); border-radius: 5px; }
.meter.small { height: 6px; }
.meter .fill { height: 100%; border-radius: 5px; background: var(--series-1); min-width: 2px; }
.meter .fill.warn { background: var(--warning); }
.meter .fill.over { background: var(--status-critical); }
.meter .pace { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-primary); border-radius: 1px; opacity: .7; }
.b-status, .b-summary { font-size: 12px; margin-top: 4px; color: var(--text-secondary); display: flex; gap: 6px; align-items: center; }
.b-status .ico, .b-summary .ico { font-weight: 700; width: 14px; text-align: center; }
.b-status.ok .ico { color: var(--good); }
.b-status.warn .ico { color: var(--warning); }
.b-status.over, .b-summary.over { color: var(--text-primary); }
.b-status.over .ico, .b-summary.over .ico { color: var(--critical); }
.b-summary { margin-top: 8px; font-size: 13px; }
.link { background: none; border: 0; color: var(--series-1); padding: 4px 0 8px 18px; font-size: 13px; }

/* Donut + Legende */
.donut-wrap { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: start; }
@media (max-width: 560px) { .donut-wrap { grid-template-columns: 1fr; } .donut { max-width: 220px; margin: 0 auto; } }
.donut svg { width: 100%; height: auto; display: block; }
.donut .slice { stroke: var(--surface-1); stroke-width: 2; cursor: pointer; transition: opacity .15s; }
.donut .slice.dim { opacity: .35; }
.donut .d-value { fill: var(--text-primary); font-size: 20px; font-weight: 700; }
.donut .d-label { fill: var(--text-secondary); font-size: 12px; }
.l-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; font-size: 14px; border-bottom: 1px solid var(--border); }
.l-item:last-child .l-row { border-bottom: 0; }
.l-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.l-pct { width: 42px; text-align: right; }
.l-subs { padding: 2px 0 8px 22px; }
.l-sub { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--text-secondary); padding: 5px 0; cursor: pointer; }
.l-sub:hover span:first-child { color: var(--text-primary); text-decoration: underline; }

/* Verlauf: gruppierte Säulen */
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.trend { position: relative; }
.trend svg { width: 100%; height: 200px; display: block; overflow: visible; }
.trend .grid line { stroke: var(--grid); stroke-width: 1; }
.trend .baseline { stroke: var(--baseline); stroke-width: 1; }
.trend text { fill: var(--text-muted); font-size: 11px; }
.trend .hit { fill: transparent; }
.trend .group:hover .hit { fill: var(--text-primary); fill-opacity: 0.05; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.3);
  white-space: nowrap;
}
.tooltip[hidden] { display: none; }
.tooltip .t-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip .t-row b { color: var(--text-primary); margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Tabellenansicht */
details.table-view { margin-top: 12px; font-size: 13px; color: var(--text-secondary); }
details.table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; }
details.table-view td, details.table-view th { padding: 4px 0; text-align: left; font-variant-numeric: tabular-nums; }
details.table-view td:not(:first-child), details.table-view th:not(:first-child) { text-align: right; }

/* Filter & Liste */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input, .filters select {
  flex: 1; min-width: 0; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-day { font-size: 12px; color: var(--text-muted); padding: 12px 4px 4px; }
.tx {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer;
}
.tx .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.tx .amt.pos { color: var(--good); }
.tx .meta { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip.none { color: var(--critical); }
.empty { color: var(--text-muted); text-align: center; padding: 32px 0; }

/* Kategorien & Regeln */
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .kind { font-size: 12px; color: var(--text-muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.del { background: none; border: 0; color: var(--text-muted); font-size: 18px; padding: 4px 8px; }
.form-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.form-row input[type=text], .form-row input[type=password], .form-row select {
  flex: 1; min-width: 120px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.form-row input[type=color] { width: 42px; height: 38px; border: 1px solid var(--border); border-radius: 8px; background: none; padding: 2px; }
.btn {
  background: var(--series-1); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600;
}
.btn.secondary { background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); }

/* Bottom-Sheet zum Kategorisieren */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  background: var(--surface-1); border-radius: 16px 16px 0 0; width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 4px; }
.sheet .sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 12px; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.cat-grid button {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}
.cat-grid button.active { outline: 2px solid var(--series-1); }
.sheet input[type=text] { width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

/* Listen, Formulare, Regeln */
.cat-group { border-bottom: 1px solid var(--border); padding: 4px 0; }
.cat-group:last-child { border-bottom: 0; }
.cat-group .list-row { border-bottom: 0; cursor: pointer; }
.list-row.sub { padding-left: 22px; font-size: 14px; }
.list-row.rule { cursor: pointer; align-items: flex-start; }
.list-row.rule .grow > div { margin-bottom: 3px; }
.order { display: flex; flex-direction: column; gap: 2px; }
.mini {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; padding: 3px 8px; color: var(--text-secondary);
}
.mini:disabled { opacity: .3; }
.btn.danger { background: var(--status-critical); }
.auto { font-size: 11px; }
.grp-title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 12px; }
.sheet .cat-grid { margin: 6px 0 4px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.stack input[type=text], .stack input[type=number], .stack select, .sheet select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; color: var(--text-primary); width: 100%;
}
.sheet input[type=number] { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.sheet label.check { flex-direction: row; display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text-primary); margin: 8px 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-label { font-size: 13px; color: var(--text-secondary); margin-top: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; }
.swatches button.active { border-color: var(--text-primary); box-shadow: 0 0 0 2px var(--surface-1) inset; }
.preview { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.pv-row { display: flex; gap: 10px; padding: 3px 0; color: var(--text-secondary); }
.pv-row .grow { flex: 1; min-width: 0; }

.notify-form { margin-top: 12px; gap: 4px; }
.notify-form label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text-primary); flex-wrap: wrap; }
.notify-form input[type=number] {
  width: 90px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; color: var(--text-primary);
}

/* Navigation */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--surface-1); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1; background: none; border: 0; padding: 12px 0 14px; color: var(--text-muted); font-size: 13px;
}
nav.tabs button.active { color: var(--text-primary); font-weight: 600; }
nav.tabs button span { display: block; font-size: 20px; margin-bottom: 2px; }

.status { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
}
.toast[hidden] { display: none; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 100%; max-width: 320px; }
.login input { width: 100%; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 12px 0; }
.login .btn { width: 100%; padding: 12px; }
.login .passkey-btn { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 0 4px; }
.login .passkey-btn span { font-size: 20px; }
.login .or { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; margin: 12px 0 0; }
.login .or::before, .login .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.login .or[hidden], .login .passkey-btn[hidden] { display: none; }
.login .err { color: var(--critical); font-size: 14px; min-height: 20px; }
