/* Finanzen – Design: mobile-first, Hell/Dunkel, System-Schrift */
:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #121627;
  --muted: #6a7188;
  --border: #e4e7f0;
  --primary: #3b5bfd;
  --primary-2: #6f4dff;
  --primary-soft: #e9edff;
  --income: #0f9d6b;
  --income-soft: #e2f6ee;
  --expense: #e5484d;
  --expense-soft: #fdeaea;
  --warn: #f59e0b;
  --warn-soft: #fef3dc;
  --shadow: 0 1px 2px rgba(18, 22, 39, .04), 0 6px 20px rgba(18, 22, 39, .06);
  --radius: 18px;
  --nav-h: 64px;
  --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:not([data-theme="light"]) {
    --bg: #0b0d13; --surface: #151924; --surface-2: #1d2230; --text: #eef0f7; --muted: #8e96ae;
    --border: #262c3d; --primary: #6b85ff; --primary-2: #8f74ff; --primary-soft: #1e2544;
    --income: #2cc48f; --income-soft: #12302a; --expense: #ff6b70; --expense-soft: #3a1c22;
    --warn: #fbbf24; --warn-soft: #3a2f14;
    --shadow: 0 0 0 1px rgba(255,255,255,.03); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d13; --surface: #151924; --surface-2: #1d2230; --text: #eef0f7; --muted: #8e96ae;
  --border: #262c3d; --primary: #6b85ff; --primary-2: #8f74ff; --primary-soft: #1e2544;
  --income: #2cc48f; --income-soft: #12302a; --expense: #ff6b70; --expense-soft: #3a1c22;
  --warn: #fbbf24; --warn-soft: #3a2f14;
  --shadow: 0 0 0 1px rgba(255,255,255,.03); color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .75rem; }
.right { text-align: right; }
.grow { flex: 1; min-width: 0; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.main { padding: calc(var(--safe-t) + 12px) 16px calc(var(--nav-h) + var(--safe-b) + 28px); max-width: 720px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; min-height: 44px; }
.topbar h1 { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; font-weight: 700;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  display: inline-grid; place-items: center; font-size: 1.1rem; line-height: 1; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b); display: grid; grid-template-columns: 1fr 1fr 78px 1fr 1fr; align-items: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: saturate(1.6) blur(16px);
  -webkit-backdrop-filter: saturate(1.6) blur(16px); border-top: 1px solid var(--border);
}
.nav a.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .68rem;
  font-weight: 600; padding: 6px 0; text-decoration: none;
}
.nav a.tab svg { width: 24px; height: 24px; }
.nav a.tab.active { color: var(--primary); }
.fab {
  width: 58px; height: 58px; border-radius: 50%; border: 0; margin: -26px auto 0; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 22px rgba(59, 91, 253, .45); font-size: 1.9rem; line-height: 1; transition: transform .12s;
}
.fab:active { transform: scale(.94); }
.fab svg { width: 28px; height: 28px; }
.side { display: none; }

@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: 250px 1fr; }
  .nav { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; padding: 22px 14px;
    border-right: 1px solid var(--border); background: var(--surface);
  }
  .side .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; padding: 0 10px 18px; letter-spacing: -.02em; }
  .side .brand img { width: 32px; height: 32px; border-radius: 9px; }
  .side a.tab {
    display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--text);
    font-weight: 600; text-decoration: none;
  }
  .side a.tab svg { width: 22px; height: 22px; color: var(--muted); }
  .side a.tab:hover { background: var(--surface-2); }
  .side a.tab.active { background: var(--primary-soft); color: var(--primary); }
  .side a.tab.active svg { color: var(--primary); }
  .side .btn-primary { margin: 10px 0 14px; }
  .side .spacer { flex: 1; }
  .main { max-width: 1080px; padding: 32px 36px 48px; width: 100%; }
  .fab-mobile { display: none; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid-2 + .card, .grid-2 + .grid-2 { margin-top: 16px; }
}

/* ---------- Karten & Listen ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid transparent; }
:root[data-theme="dark"] .card { border-color: var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card { border-color: var(--border); } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { font-size: 1rem; font-weight: 700; }
.card-head a, .link-btn { font-size: .85rem; font-weight: 600; color: var(--primary); background: none; border: 0; padding: 4px 0; }
.card.flush { padding: 4px 0; }

.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%); color: #fff; border: 0;
  box-shadow: 0 10px 30px rgba(59, 91, 253, .3);
}
.hero .label { color: rgba(255,255,255,.82); text-transform: none; letter-spacing: 0; margin: 0; font-size: .85rem; font-weight: 600; }
.hero .big { font-size: 2.2rem; font-weight: 800; letter-spacing: -.03em; margin: 2px 0 14px; }
.hero .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero .stat { background: rgba(255, 255, 255, .16); border-radius: 14px; padding: 10px 10px 9px; min-width: 0; }
.hero .stat .s-label { font-size: .7rem; opacity: .85; font-weight: 600; }
.hero .stat .s-val { font-size: 1rem; font-weight: 750; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.month-switch { display: inline-flex; align-items: center; gap: 2px; }
.month-switch button { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; font-size: 1.2rem; color: var(--muted); }
.month-switch button:active { background: var(--surface-2); }
.month-switch .m-label { min-width: 150px; white-space: nowrap; text-align: center; font-weight: 700; font-size: 1rem; background: none; border: 0; }

.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 16px; width: 100%; background: none; border: 0;
  text-align: left; border-radius: 0;
}
button.row:active { background: var(--surface-2); }
.row + .row { border-top: 1px solid var(--border); }
.dot { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 1.2rem; flex: none; }
.row .t1 { font-weight: 600; }
.row .t2 { color: var(--muted); font-size: .82rem; }
.amt { font-weight: 700; white-space: nowrap; }
.day-head { display: flex; justify-content: space-between; padding: 14px 6px 6px; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.day-head:first-child { padding-top: 4px; }

.hscroll { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px 14px; padding: 2px 16px 6px; scroll-snap-type: x proximity; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.acc-card {
  flex: none; min-width: 148px; padding: 13px 14px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
  border: 1px solid var(--border); scroll-snap-align: start; text-align: left;
}
.acc-card .a-name { font-size: .8rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.acc-card .a-dot { width: 8px; height: 8px; border-radius: 50%; }
.acc-card .a-bal { font-weight: 750; font-size: 1.1rem; margin-top: 4px; }

/* ---------- Formulare ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span, .label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  font-size: 1rem; outline: none; appearance: none; -webkit-appearance: none; min-height: 48px;
}
select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e96ae' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[type="date"].input { min-width: 0; }
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pw-wrap { position: relative; }
.pw-wrap .pw-toggle { position: absolute; right: 6px; top: 6px; height: 36px; padding: 0 10px; border: 0; background: none; color: var(--muted); font-size: .8rem; font-weight: 700; }
.error-msg { background: var(--expense-soft); color: var(--expense); padding: 10px 12px; border-radius: 10px; font-size: .9rem; margin-bottom: 14px; }
.ok-msg { background: var(--income-soft); color: var(--income); padding: 10px 12px; border-radius: 10px; font-size: .9rem; margin-bottom: 14px; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 13px;
  border: 1.5px solid var(--border); background: var(--surface); font-weight: 700; min-height: 48px; text-decoration: none; color: var(--text);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(59, 91, 253, .3); }
.btn-danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 35%, var(--border)); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.seg { display: flex; background: var(--surface-2); padding: 4px; border-radius: 13px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 10px; font-weight: 700; font-size: .9rem; color: var(--muted); min-height: 40px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }
.seg.expense button.active[data-type="expense"] { color: var(--expense); }
.seg.income button.active[data-type="income"] { color: var(--income); }
.seg.transfer button.active[data-type="transfer"] { color: var(--primary); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; margin-bottom: 12px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); font-size: .88rem; font-weight: 650; color: var(--muted); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface); font-size: .72rem; font-weight: 600; min-width: 0; }
.cat-btn .ci { font-size: 1.4rem; line-height: 1.2; }
.cat-btn span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-btn.active { border-color: var(--primary); background: var(--primary-soft); }

.amount-input { text-align: center; font-size: 2.4rem; font-weight: 800; border: 0; background: transparent; width: auto; flex: 0 1 62%; padding: 6px 0; outline: none; letter-spacing: -.02em; min-width: 0; }
.amount-wrap { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 0 14px; }
.amount-wrap .cur { font-size: 1.6rem; font-weight: 700; color: var(--muted); }
.amount-wrap.expense .amount-input { color: var(--expense); }
.amount-wrap.income .amount-input { color: var(--income); }

/* ---------- Fortschritt ---------- */
.bar { height: 9px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--income); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.bar.warn > i { background: var(--warn); }
.bar.over > i { background: var(--expense); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .7rem; font-weight: 700; background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--expense-soft); color: var(--expense); }
.badge.good { background: var(--income-soft); color: var(--income); }

/* ---------- Charts ---------- */
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.donut { width: 168px; height: 168px; flex: none; }
.legend { flex: 1; min-width: 170px; display: grid; gap: 6px; }
.legend button { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px 2px; text-align: left; font-size: .88rem; width: 100%; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart-cap { text-align: center; font-size: .82rem; color: var(--muted); min-height: 1.4em; margin-top: 4px; }
.bar-hit { cursor: pointer; }
.key { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); justify-content: center; margin-top: 6px; }
.key i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

/* ---------- Sheet & Toast ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 20, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 520px; max-height: 94dvh; overflow-y: auto; border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(18px + var(--safe-b)); animation: up .24s cubic-bezier(.2, .8, .2, 1); overscroll-behavior: contain;
}
.sheet .grab { width: 40px; height: 4px; background: var(--border); border-radius: 4px; margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 1.15rem; }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 24px; max-height: 90vh; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 18px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
@media (min-width: 960px) { #toast-root { bottom: 24px; } }
.toast { background: #1b1f2e; color: #fff; padding: 11px 16px; border-radius: 14px; font-weight: 600; font-size: .92rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); animation: up .2s; max-width: 90vw; pointer-events: auto; }
.toast.err { background: var(--expense); }
.toast button { background: none; border: 0; color: #9db0ff; font-weight: 700; margin-left: 12px; }

/* ---------- Sonstiges ---------- */
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty .big-emoji { font-size: 2.6rem; margin-bottom: 8px; }
.banner { display: flex; gap: 10px; align-items: center; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-weight: 600; font-size: .88rem; margin-bottom: 14px; }
.search { position: relative; margin-bottom: 10px; }
.search .input { padding-left: 40px; }
.search svg { position: absolute; left: 13px; top: 14px; width: 20px; height: 20px; color: var(--muted); }
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border-radius: 16px; padding: 13px 14px; box-shadow: var(--shadow); border: 1px solid transparent; }
:root[data-theme="dark"] .kpi { border-color: var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .kpi { border-color: var(--border); } }
.kpi .k-label { font-size: .74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi .k-val { font-size: 1.25rem; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; }
.menu-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; text-decoration: none; color: var(--text); width: 100%; border: 0; background: none; text-align: left; }
.menu-row + .menu-row { border-top: 1px solid var(--border); }
.menu-row:active { background: var(--surface-2); }
.menu-row .m-ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); font-size: 1.1rem; flex: none; }
.menu-row .chev { color: var(--muted); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.swatch.active { border-color: var(--text); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-grid button { font-size: 1.3rem; padding: 6px 0; border-radius: 10px; border: 1.5px solid transparent; background: var(--surface); }
.emoji-grid button.active { border-color: var(--primary); background: var(--primary-soft); }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(900px 500px at 10% -10%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 60%),
  radial-gradient(700px 400px at 100% 110%, color-mix(in srgb, var(--primary-2) 22%, transparent), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 410px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand img { width: 68px; height: 68px; border-radius: 20px; box-shadow: 0 10px 30px rgba(59, 91, 253, .35); }
.auth-brand h1 { font-size: 1.9rem; font-weight: 850; letter-spacing: -.03em; margin-top: 10px; }
.auth-brand p { color: var(--muted); margin-top: 2px; }
.table { width: 100%; border-collapse: collapse; }
.spin { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: rot .8s linear infinite; margin: 40px auto; }
@keyframes rot { to { transform: rotate(360deg); } }
.user-card { padding: 14px 16px; }
.user-card + .user-card { border-top: 1px solid var(--border); }
.user-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.user-actions select { min-height: 36px; padding: 6px 30px 6px 10px; font-size: .85rem; width: auto; border-radius: 10px; }
.preview { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; font-size: .78rem; margin-top: 10px; }
.preview table { border-collapse: collapse; min-width: 100%; }
.preview td, .preview th { padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; }
.preview th { background: var(--surface-2); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
.only-desktop { display: none; }
@media (min-width: 960px) { .only-mobile { display: none !important; } .only-desktop { display: inline-flex; } }
.donut .seg { transition: opacity .15s; }
.donut text { fill: var(--muted); }
.donut text[style*="800"] { fill: var(--text); }
