:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #EFECE5;
  --ink: #1F2A2E;
  --ink-2: #5D686B;
  --ink-3: #8D9799;
  --line: #E3DFD6;
  --primary: #1F6F6B;
  --primary-soft: #DCEBE8;
  --on-primary: #FFFFFF;
  --accent: #D9982E;
  --ok: #3F8F5E;
  --warn: #C98A1E;
  --danger: #BF4F47;
  --danger-soft: #F6E1DE;
  --track: #E8E4DB;
  --shadow: 0 1px 2px rgba(31,42,46,.05), 0 6px 20px rgba(31,42,46,.06);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141A1C; --surface: #1D2528; --surface-2: #253033; --ink: #ECEFEC; --ink-2: #A9B3B3; --ink-3: #788486;
    --line: #2E393C; --primary: #5FB8AF; --primary-soft: #21393A; --on-primary: #0E1B1A; --accent: #E5AE52;
    --ok: #6CC08A; --warn: #E3A94A; --danger: #E57D74; --danger-soft: #3A2624; --track: #2B3538;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num, .amount { font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 28px; font-weight: 750; }
h2 { font-size: 17px; font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.view { max-width: 640px; margin: 0 auto; padding: calc(var(--safe-t) + 18px) 16px calc(var(--safe-b) + 110px); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head .eyebrow { font-size: 13px; color: var(--ink-2); margin-bottom: 2px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.card-title a, .linkbtn { color: var(--primary); font-size: 14px; font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0; cursor: pointer; }
.section-label { font-size: 13px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; margin: 22px 4px 8px; }

/* ---------- Period switcher ---------- */
.period { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); padding: 3px; }
.period button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; display: grid; place-items: center; }
.period button:disabled { opacity: .25; }
.period button svg { width: 18px; height: 18px; fill: var(--ink); }
.period span { font-size: 14px; font-weight: 600; padding: 0 6px; white-space: nowrap; }

/* ---------- Hero ---------- */
.hero { display: grid; grid-template-columns: 132px 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring .pct { font-size: 26px; font-weight: 750; }
.ring .pct-sub { font-size: 11px; color: var(--ink-2); }
.hero-main .label { font-size: 13px; color: var(--ink-2); }
.hero-main { min-width: 0; }
.hero-main .big { font-size: clamp(22px, 7.2vw, 30px); white-space: nowrap; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; margin: 2px 0 8px; }
.hero-main .big.neg { color: var(--danger); }
.pill { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 600; }
.pill.warn { background: var(--danger-soft); color: var(--danger); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--ink-2); }
.stat .v { font-size: 15px; font-weight: 650; }
.stat .v.pos { color: var(--ok); } .stat .v.neg { color: var(--danger); }

/* ---------- Category bars ---------- */
.catbar { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: center; padding: 8px 0; }
.catbar + .catbar { border-top: 1px solid var(--line); }
.catbar .ic { font-size: 20px; text-align: center; }
.catbar .name { font-size: 15px; font-weight: 550; display: flex; justify-content: space-between; gap: 8px; }
.catbar .name small { color: var(--ink-2); font-weight: 400; font-size: 13px; white-space: nowrap; }
.track { height: 7px; background: var(--track); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.fill { height: 100%; border-radius: 99px; transition: width .5s ease; }
.catbar .rest { font-size: 13px; font-weight: 650; white-space: nowrap; }
.catbar .sub { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.catbar .rest.neg { color: var(--danger); }

/* ---------- Template chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 9px 12px; cursor: pointer; text-align: left; }
.chip:active { transform: scale(.97); }
.chip .ic { font-size: 18px; }
.chip b { display: block; font-size: 14px; font-weight: 600; }
.chip small { color: var(--ink-2); font-size: 12px; }

/* ---------- Transactions ---------- */
.tx { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; cursor: pointer; }
.tx + .tx { border-top: 1px solid var(--line); }
.tx .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--surface-2); }
.tx .t { font-weight: 550; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .s { font-size: 13px; color: var(--ink-2); }
.tx .amount { font-weight: 650; }
.tx .amount.in { color: var(--ok); }
.daygroup { font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 16px 4px 4px; }
.empty { text-align: center; color: var(--ink-2); padding: 26px 10px; }
.empty .em { font-size: 34px; margin-bottom: 6px; }

/* ---------- Tips ---------- */
.tips-card { background: linear-gradient(160deg, var(--primary-soft), var(--surface) 70%); }
.tip { padding: 10px 0; }
.tip + .tip { border-top: 1px solid var(--line); }
.tip b { display: block; font-size: 15px; margin-bottom: 2px; }
.tip p { margin: 0; font-size: 14px; color: var(--ink-2); }
.badge { font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); }

/* ---------- History ---------- */
.hbar-chart { width: 100%; height: auto; display: block; overflow: visible; }
.filter { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin: -4px -2px 8px; scrollbar-width: none; }
.filter::-webkit-scrollbar { display: none; }
.filter button { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.filter button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.swing { display: grid; grid-template-columns: 30px 1fr auto auto; gap: 10px; align-items: center; padding: 10px 0; cursor: pointer; }
.swing + .swing { border-top: 1px solid var(--line); }
.swing .ic { font-size: 20px; text-align: center; }
.swing .t { font-weight: 600; font-size: 15px; }
.swing .s { font-size: 12px; color: var(--ink-2); }
.swing .r { font-weight: 700; font-size: 14px; min-width: 64px; text-align: right; }
.swing .r small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-2); }
.up { color: var(--danger); font-weight: 650; } .down { color: var(--ok); font-weight: 650; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-budget, .lg-avg { display: inline-block; width: 16px; height: 0; border-top: 2px dashed var(--ink); }
.lg-avg { border-top-color: var(--accent); }
.hrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; cursor: pointer; }
.hrow + .hrow { border-top: 1px solid var(--line); }
.hrow .m { font-weight: 650; }
.hrow .d { font-size: 13px; color: var(--ink-2); grid-column: 1; }
.hrow .s { text-align: right; font-weight: 700; }
.hrow .s.pos { color: var(--ok); } .hrow .s.neg { color: var(--danger); }
.hrow .b { text-align: right; font-size: 12px; color: var(--ink-2); }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; font-weight: 550; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 13px; font-size: 16px; outline: none; appearance: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px; padding: 13px 18px; font-weight: 650; cursor: pointer; background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn svg { width: 20px; height: 20px; fill: currentColor; }
.err { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.note { background: var(--primary-soft); color: var(--ink); border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 14px; }

/* Segmented */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; border-radius: 10px; padding: 9px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* Amount entry */
.amount-entry { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 4px 0 14px; }
.amount-entry .cur { font-size: 20px; color: var(--ink-2); font-weight: 600; }
.amount-entry input { width: 62%; border: 0; background: transparent; font-size: 44px; font-weight: 750; text-align: center; outline: none; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.catgrid button { border: 1.5px solid transparent; background: var(--surface-2); border-radius: 14px; padding: 9px 4px 7px; cursor: pointer; display: grid; justify-items: center; gap: 2px; }
.catgrid button .ic { font-size: 22px; }
.catgrid button small { font-size: 11px; line-height: 1.15; color: var(--ink-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catgrid button.on { border-color: var(--primary); background: var(--primary-soft); }
.catgrid button.on small { color: var(--ink); }

.scanbox { border: 1.5px dashed var(--line); border-radius: 14px; padding: 12px; display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; margin-bottom: 14px; }
.scanbox img { width: 64px; height: 84px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.progress { height: 6px; background: var(--track); border-radius: 9px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.hl { animation: hl 1.6s ease; }
@keyframes hl { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }
details.ocr { margin-top: 6px; font-size: 13px; color: var(--ink-2); }
details.ocr pre { white-space: pre-wrap; font-size: 12px; max-height: 160px; overflow: auto; background: var(--surface-2); border-radius: 10px; padding: 8px; }

/* Settings lists */
.list-item { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 11px 0; cursor: pointer; }
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-item .ic { font-size: 20px; text-align: center; }
.list-item .sub { font-size: 13px; color: var(--ink-2); }
.list-item .val { font-weight: 600; font-size: 15px; }
.budget-row { display: grid; grid-template-columns: 30px 1fr 120px; gap: 10px; align-items: center; padding: 6px 0; }
.budget-row .input { padding: 9px 10px; text-align: right; }
.budget-sum { display: flex; justify-content: space-between; font-weight: 700; padding-top: 12px; margin-top: 6px; border-top: 1px solid var(--line); }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.emoji-pick button { width: 40px; height: 40px; font-size: 20px; border-radius: 10px; border: 1.5px solid transparent; background: var(--surface-2); cursor: pointer; }
.emoji-pick button.on { border-color: var(--primary); }
.color-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.color-pick button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.color-pick button.on { box-shadow: 0 0 0 2px var(--ink); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: end;
  padding: 6px 8px calc(var(--safe-b) + 6px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--line);
}
.tab { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 4px 0; cursor: pointer; color: var(--ink-3); font-size: 10.5px; font-weight: 600; }
.tab svg { width: 24px; height: 24px; fill: currentColor; }
.tab.on { color: var(--primary); }
.fab { justify-self: center; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 18px color-mix(in srgb, var(--primary) 45%, transparent); transform: translateY(-14px); cursor: pointer; display: grid; place-items: center; }
.fab svg { width: 28px; height: 28px; fill: currentColor; }
.fab:active { transform: translateY(-14px) scale(.94); }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10,15,16,.42); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 16px calc(var(--safe-b) + 18px);
  animation: up .26s cubic-bezier(.2,.9,.3,1);
}
.sheet .grip { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head .x { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; font-size: 18px; line-height: 1; }
.sheet-actions { display: grid; gap: 10px; margin-top: 6px; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 16px; right: 16px; margin: 0 auto; width: fit-content; max-width: 560px; bottom: calc(var(--safe-b) + 96px); z-index: 60; background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 550; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); animation: fade .2s; }
.toast button { white-space: nowrap; }
.toast button { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; }

/* ---------- Auth ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: calc(var(--safe-t) + 60px) 20px 40px; }
.auth .logo { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 18px; }
.auth h1 { margin-bottom: 6px; }
.auth p.lead { color: var(--ink-2); margin: 0 0 24px; }

.splash { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 120px; border-radius: var(--radius); background: var(--surface); opacity: .6; margin-bottom: 14px; }

@media (min-width: 700px) { .view { padding-top: 32px; } }
@media (max-width: 360px) { .hero { grid-template-columns: 110px 1fr; } .ring { width: 110px; height: 110px; } .hero-main .big { font-size: 25px; } .catgrid { grid-template-columns: repeat(3, 1fr); } }

/* Benutzer verwalten */
.admin-user { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 11px 0; }
.admin-user + .admin-user { border-top: 1px solid var(--line); }
.admin-user .t { font-weight: 600; }
.admin-user .s { font-size: 13px; color: var(--ink-2); }
.btn.small-btn { padding: 8px 12px; font-size: 14px; border-radius: 11px; }
.temp-pw { font: 700 26px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .06em; text-align: center; background: var(--surface); border: 1.5px dashed var(--primary); border-radius: 14px; padding: 18px 10px; margin: 6px 0 14px; user-select: all; }

/* Kategorie-Symbole: Anfangsbuchstabe */
.letter-ic { display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; border-radius: 30%; font: 750 .78em/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; vertical-align: middle;
  color: var(--lc, var(--primary)); background: color-mix(in srgb, var(--lc, var(--primary)) 20%, transparent); }
.icon-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.icon-preview { font-size: 26px; line-height: 1; }
.emoji-scroll { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 14px; padding: 10px 10px 2px; margin-bottom: 14px; background: var(--surface); }
.emoji-group > small { display: block; font-size: 12px; font-weight: 650; color: var(--ink-2); margin: 0 0 6px; }
.emoji-pick .letter-btn { width: auto; padding: 0 12px; font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.emoji-pick .letter-btn .letter-ic { font-size: 22px; }

/* Einstellungen als Akkordeon */
.settings-acc { display: grid; gap: 10px; }
details.set { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); scroll-margin-top: 12px; overflow: hidden; }
details.set > summary { list-style: none; display: grid; grid-template-columns: 38px 1fr 20px; gap: 12px; align-items: center; padding: 14px 16px; cursor: pointer; }
details.set > summary::-webkit-details-marker { display: none; }
details.set > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: var(--radius); }
.set-ic { width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; }
.set-t { display: grid; min-width: 0; }
.set-t b { font-size: 16px; font-weight: 650; }
.set-t small { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { width: 9px; height: 9px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); justify-self: center; margin-top: -4px; transition: transform .2s; }
details.set[open] .chev { transform: rotate(-135deg); margin-top: 4px; }
details.set[open] > summary { border-bottom: 1px solid var(--line); }
.set-body { padding: 14px 16px 16px; }
.set-body.list { padding: 2px 16px 6px; }

/* Budgetvorschlag */
.suggest-btn { margin-bottom: 12px; background: var(--primary-soft); color: var(--primary); }
.sg-list { padding: 2px 14px; }
.sg-row { display: grid; grid-template-columns: 30px 1fr 96px; gap: 10px; align-items: center; padding: 9px 0; }
.sg-row + .sg-row { border-top: 1px solid var(--line); }
.sg-row .ic { font-size: 20px; text-align: center; }
.sg-row .t { font-weight: 600; font-size: 15px; }
.sg-row .s { font-size: 12px; color: var(--ink-2); line-height: 1.35; }
.sg-row .input { padding: 9px 10px; text-align: right; }
.sg-sum { display: grid; gap: 6px; background: var(--surface); border-radius: 14px; padding: 12px 14px; margin: 4px 0 10px; box-shadow: var(--shadow); }
.sg-sum > div { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.sg-sum > div:last-child { border-top: 1px solid var(--line); padding-top: 6px; font-weight: 650; }
.sheet a { color: var(--primary); font-weight: 600; }
