:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --line: #e2e0d9;
  --text: #121211;
  --text-2: #55544f;
  --muted: #85847d;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #d23f3e;
  --ok: #1f8a3a;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  --radius: 16px;
  --cat-lebensmittel: #2a78d6;
  --cat-restaurant: #eb6834;
  --cat-mobilitaet: #1baf7a;
  --cat-drogerie: #eda100;
  --cat-freizeit: #e87ba4;
  --cat-haushalt: #008300;
  --cat-kleidung: #6250d6;
  --cat-sonstiges: #8f8e87;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1d1d1c;
    --surface-2: #272725;
    --line: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --danger: #e66767;
    --ok: #3fb35c;
    --shadow: none;
    --cat-lebensmittel: #3987e5;
    --cat-restaurant: #d95926;
    --cat-mobilitaet: #199e70;
    --cat-drogerie: #c98500;
    --cat-freizeit: #d55181;
    --cat-haushalt: #0ca30c;
    --cat-kleidung: #9085e9;
    --cat-sonstiges: #7c7b74;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 14px) 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
}
.topbar h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; font-weight: 750; }

main {
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 96px);
  max-width: 640px; margin: 0 auto; outline: none;
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-top: 0.5px solid var(--line);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; font-weight: 600;
}
.tabbar button.active { color: var(--accent); }
.ti svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Karten & Listen */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; border-bottom: 0.5px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row .sub.overdue { color: var(--danger); }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--surface-2); }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty-inline { color: var(--muted); margin: 6px 0; }

/* To-Do */
.add-todo { display: flex; gap: 8px; margin-bottom: 14px; }
.add-todo input {
  flex: 1; min-width: 0; border: 0; border-radius: 14px; padding: 14px 16px;
  background: var(--surface); box-shadow: var(--shadow); outline: none;
}
.add-todo input:focus { box-shadow: 0 0 0 2px var(--accent); }
.check {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--muted); background: none; display: grid; place-items: center; padding: 0;
}
.check svg { width: 15px; height: 15px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; }
.row.done .title { color: var(--muted); text-decoration: line-through; }
.chev { color: var(--muted); flex: none; }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 650;
  background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: none; color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: var(--surface-2); color: var(--accent); width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.fab {
  position: fixed; right: 18px; z-index: 7;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  border: 0; border-radius: 30px; padding: 15px 22px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22);
  display: flex; align-items: center; gap: 8px;
}
.fab svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-row > * { flex: 1 1 28%; padding-left: 10px; padding-right: 10px; }

/* Dashboard */
.month-switch { display: flex; align-items: center; justify-content: space-between; margin: 0 0 10px; }
.month-switch .label { font-weight: 650; }
.hero .label { color: var(--text-2); font-size: 14px; }
.hero .value { font-size: 40px; font-weight: 750; letter-spacing: -0.02em; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.hero .delta { font-size: 14px; color: var(--text-2); }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .axis.strong { fill: var(--text); font-weight: 650; }
.chart .val { fill: var(--text); font-size: 12px; font-weight: 650; }
.chart .bar path { fill: color-mix(in srgb, var(--accent) 38%, var(--surface)); transition: fill .15s; }
.chart .bar.sel path { fill: var(--accent); }
.chart .bar { cursor: pointer; outline: none; }
.cat-row { margin: 12px 0; }
.cat-row:first-child { margin-top: 2px; }
.cat-row:last-child { margin-bottom: 2px; }
.cat-head { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; margin-bottom: 6px; }
.cat-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.cat-val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cat-track { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.cat-fill { height: 100%; border-radius: 4px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; font-size: 22px; }

/* Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: calc(100% - var(--safe-t) - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(var(--safe-b) + 20px);
  max-width: 640px; margin: 0 auto;
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.sheet .grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 4px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin: 0 4px 5px; font-weight: 600; }
.field input, .field textarea {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 14px; background: var(--surface);
  outline: none; box-shadow: var(--shadow); -webkit-appearance: none; appearance: none; min-height: 48px;
}
.field input:focus, .field textarea:focus { box-shadow: 0 0 0 2px var(--accent); }
.field input.big { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: var(--surface); border-radius: 20px; padding: 8px 12px; font-size: 14px; }
.chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); font-weight: 650; }
.receipt-photo { width: 100%; max-height: 260px; object-fit: contain; border-radius: 14px; background: var(--surface-2); display: block; margin-bottom: 12px; }
.hint { font-size: 13px; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-radius: 12px; margin-bottom: 12px; }
details.raw summary { color: var(--muted); font-size: 13px; margin: 6px 4px 12px; }
details.raw pre { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 10px; max-height: 200px; overflow: auto; }

.progress { text-align: center; padding: 30px 10px; }
.progress .bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 14px 0 8px; }
.progress .bar div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--surface-2); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.search { width: 100%; border: 0; border-radius: 12px; padding: 11px 14px; background: var(--surface-2); outline: none; margin-bottom: 12px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--danger); }
.small { font-size: 13px; }

/* Ideen */
.filter { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.filter .chip { white-space: nowrap; }
.idea-card { cursor: pointer; }
.idea-card h3 { margin: 0 0 4px; font-size: 17px; }
.idea-card p { margin: 0; color: var(--text-2); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.idea-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.badge { font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.badge.st-aktiv { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent); }
.badge.st-erledigt { background: color-mix(in srgb, var(--ok) 16%, var(--surface)); color: var(--ok); }
.tag { font-size: 12px; color: var(--muted); }
