:root {
  --bg: #f5f5f4;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #7a7a80;
  --line: rgba(60, 60, 67, 0.12);
  --fill: rgba(120, 120, 128, 0.1);
  --fill-strong: rgba(120, 120, 128, 0.18);
  --accent: #1c1c1e;
  --accent-text: #ffffff;
  --pos: #23845a;
  --neg: #c4472d;
  --bar: #1c1c1e;
  --bar-soft: rgba(28, 28, 30, 0.14);
  --radius: 16px;
  --sheet: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --line: rgba(84, 84, 88, 0.45);
    --fill: rgba(118, 118, 128, 0.2);
    --fill-strong: rgba(118, 118, 128, 0.32);
    --accent: #f2f2f7;
    --accent-text: #000000;
    --pos: #4cc38a;
    --neg: #ff7a5c;
    --bar: #f2f2f7;
    --bar-soft: rgba(242, 242, 247, 0.16);
    --sheet: #1c1c1e;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos, .row .sub.pos { color: var(--pos); }
.neg, .row .sub.neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* ---------- Layout ---------- */
.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 150px);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 44px; margin-bottom: 8px;
}
.topbar h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.section-title {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); margin: 24px 4px 8px;
}

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px;
  position: relative; width: 100%; background: none; border: 0; text-align: left;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 0.5px solid var(--line);
}
.list.plain .row + .row::before { left: 16px; }
.row:active { background: var(--fill); }
.row .grow { flex: 1; min-width: 0; }
.row .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { text-align: right; flex-shrink: 0; }
.row .right .sub { font-size: 12px; }
.chev { color: var(--muted); opacity: 0.6; }

.icon-circle {
  width: 38px; height: 38px; border-radius: 50%; background: var(--fill);
  display: grid; place-items: center; font-size: 19px; flex-shrink: 0;
}

/* ---------- Saldo ---------- */
.balance { text-align: center; padding: 22px 16px 18px; }
.balance .label { font-size: 15px; color: var(--muted); }
.balance .amount { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 12px; }
.balance .actions { display: flex; gap: 8px; justify-content: center; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600;
  background: var(--fill); color: var(--text); min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; }
.btn.small { padding: 7px 12px; min-height: 34px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.4; }
.link { background: none; border: 0; color: var(--text); font-weight: 600; padding: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--fill);
  display: grid; place-items: center;
}
.icon-btn svg, .tab svg { width: 22px; height: 22px; }

.fab {
  position: fixed; right: max(20px, calc(50% - 300px)); bottom: calc(var(--safe-bottom) + 76px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22); display: grid; place-items: center; z-index: 20;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(var(--safe-bottom) + 4px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tab {
  flex: 1; max-width: 120px; background: none; border: 0; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 500; padding: 4px 0;
}
.tab.active { color: var(--text); }

/* ---------- Formulare ---------- */
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-size: 13px; color: var(--muted); margin: 0 4px 6px; }
.input, select.input, textarea.input {
  width: 100%; border: 0; border-radius: 12px; background: var(--fill); padding: 12px 14px; min-height: 46px;
  outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus { box-shadow: 0 0 0 2px var(--fill-strong); }
textarea.input { min-height: 72px; resize: vertical; }
.amount-wrap { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 8px 0 4px; }
.amount-input {
  border: 0; background: none; outline: none; text-align: center;
  font-size: 46px; font-weight: 700; letter-spacing: -0.02em; width: 100%; max-width: 280px; padding: 0;
}
.amount-input::placeholder { color: var(--fill-strong); }
.cur-btn { border: 0; background: var(--fill); border-radius: 999px; padding: 4px 10px; font-weight: 600; font-size: 15px; }
.seg { display: flex; background: var(--fill); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 6px; font-weight: 500; font-size: 15px; min-height: 40px;
}
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); font-weight: 600; }
@media (prefers-color-scheme: dark) { .seg button.on { background: #48484a; } }
.hint { font-size: 14px; text-align: center; margin: 8px 0 2px; min-height: 20px; }

.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat {
  border: 0; background: var(--fill); border-radius: 12px; padding: 8px 2px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 64px;
}
.cat .e { font-size: 22px; line-height: 1.2; }
.cat .n { font-size: 10.5px; line-height: 1.15; text-align: center; color: var(--muted); padding: 0 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cat.on { background: var(--accent); }
.cat.on .n { color: var(--accent-text); }
.auto-tag { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-left: 6px; }

.suggest { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.suggest button { border: 0; background: var(--fill); border-radius: 999px; padding: 6px 12px; font-size: 14px; }

.photo-preview { width: 100%; max-height: 260px; object-fit: cover; border-radius: 12px; display: block; margin-bottom: 8px; }
details.more summary { list-style: none; color: var(--muted); font-size: 14px; padding: 8px 4px; cursor: pointer; }
details.more summary::-webkit-details-marker { display: none; }

/* ---------- Sheet ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.32); z-index: 50;
  opacity: 0; transition: opacity 0.2s;
}
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; margin: 0 auto; max-width: 640px;
  background: var(--sheet); border-radius: 20px 20px 0 0;
  max-height: calc(100dvh - var(--safe-top) - 12px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(var(--safe-bottom) + 20px);
  transform: translateY(100%); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.show { transform: translateY(0); }
.sheet-head {
  position: sticky; top: 0; z-index: 2; background: var(--sheet);
  display: flex; align-items: center; justify-content: space-between; padding: 14px 0 10px;
}
.sheet .card, .sheet .list { background: var(--bg); box-shadow: none; }
@media (prefers-color-scheme: dark) { .sheet .card, .sheet .list { background: #2c2c2e; } .sheet .cat.on .n { color: var(--accent-text); } }
.sheet-head h2 { font-size: 17px; margin: 0; font-weight: 600; }
.sheet-head .link { min-width: 70px; }
.sheet-head .link:last-child { text-align: right; }

/* ---------- Auswertung ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.month-nav .m { font-size: 17px; font-weight: 600; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.kpi .v { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.kpi .l { font-size: 13px; color: var(--muted); }
.bar-track { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar-fill { height: 100%; background: var(--bar); border-radius: 3px; }
.trend { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.trend button {
  flex: 1; border: 0; background: none; height: 100%; padding: 0;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px;
}
.trend .b { width: 100%; border-radius: 4px 4px 2px 2px; background: var(--bar-soft); min-height: 2px; }
.trend button.on .b { background: var(--bar); }
.trend .t { font-size: 10px; color: var(--muted); }
.trend button.on .t { color: var(--text); font-weight: 600; }
.people { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Auth ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: calc(var(--safe-top) + 48px) 20px 40px; }
.auth .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 16px; }
.auth h1 { text-align: center; font-size: 28px; margin: 0 0 4px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 28px; }
.qr { display: block; margin: 0 auto 12px; width: 220px; height: 220px; border-radius: 12px; background: #fff; padding: 8px; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; text-align: center; user-select: all; }
.code-input { text-align: center; font-size: 26px; letter-spacing: 0.3em; font-variant-numeric: tabular-nums; }

/* ---------- Diverses ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 12px); transform: translate(-50%, -150%);
  background: var(--accent); color: var(--accent-text); padding: 10px 16px; border-radius: 12px; z-index: 100;
  font-size: 15px; font-weight: 500; max-width: calc(100% - 32px); transition: transform 0.25s; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast.show { transform: translate(-50%, 0); }
.toast.err { background: var(--neg); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.month-head { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 4px 8px; }
.month-head .section-title { margin: 0; }
.search { margin: 4px 0 4px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--fill); color: var(--muted); margin-left: 6px; vertical-align: 1px; }
.footer-note { text-align: center; font-size: 12px; color: var(--muted); margin-top: 28px; }
.spacer { height: 12px; }
.stack > * + * { margin-top: 8px; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex > .grow { flex: 1; }

/* ---------- Prozent-Schieberegler ---------- */
.pct { margin-top: 12px; padding: 12px 14px 8px; background: var(--fill); border-radius: 12px; }
.pct-labels { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.pct-labels b { font-size: 17px; }
.pct input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; --v: 50%;
}
.pct input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) 0 var(--v), var(--fill-strong) var(--v) 100%);
}
.pct input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--fill-strong); }
.pct input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.pct input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; margin-top: -11px;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
}
.pct input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.pct-ticks { display: flex; justify-content: space-between; padding: 0 13px; margin-top: 2px; }
.pct-ticks i { width: 1px; height: 6px; background: var(--muted); opacity: 0.5; }
.pct-ticks i:nth-child(6) { height: 9px; opacity: 0.9; }

/* ---------- Offline & Rückerstattung ---------- */
.offline-bar {
  position: sticky; top: 0; z-index: 40; text-align: center; font-size: 13px; font-weight: 500;
  padding: calc(var(--safe-top) + 6px) 12px 6px; background: #b8860b; color: #fff;
}
.amount-input.refund { color: var(--neg); }

.guide ol { margin: 0; padding-left: 20px; }
.guide li { margin: 0 0 10px; font-size: 15px; line-height: 1.45; }
.guide code, .card code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--fill); padding: 1px 5px; border-radius: 5px; }
