:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #16201b;
  --ink-2: #4b5650;
  --ink-3: #7d8681;
  --line: #e2ded5;
  --accent: #1d6b4b;
  --accent-ink: #ffffff;
  --accent-soft: #dcebe2;
  --pos: #1f7a4f;
  --neg: #b4432f;
  --warn: #a86a12;
  --warn-soft: #f6ead3;
  --shadow: 0 1px 2px rgba(22, 32, 27, .05), 0 6px 24px rgba(22, 32, 27, .06);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1714;
    --surface: #17211d;
    --surface-2: #1f2a25;
    --ink: #eef2ef;
    --ink-2: #b5c0ba;
    --ink-3: #7f8b85;
    --line: #26332d;
    --accent: #5fcf98;
    --accent-ink: #0b1a13;
    --accent-soft: #1d3a2c;
    --pos: #6ad3a0;
    --neg: #f08a73;
    --warn: #e7b25a;
    --warn-soft: #3a2f1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.num, .amount, .big { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.error { color: var(--neg); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.icon-btn svg, .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font: 650 28px/1.1 var(--font-display); letter-spacing: -.02em; margin: 18px 0 6px; }
.login-card .muted { margin: 0 0 28px; }
.brand-mark { color: var(--accent); }
.brand-mark svg { width: 52px; height: 52px; stroke: none; }
.brand-mark svg path { stroke: var(--bg); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 550; }
input[type=text], input[type=password], input[type=number], input[type=search], select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); outline: none;
}
input:focus-visible, select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink);
  transition: transform .12s ease, background-color .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--neg); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; padding: 13px 16px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- Shell ---------- */
.app { max-width: 760px; margin: 0 auto; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar-title { display: flex; align-items: center; gap: 10px; font: 650 19px/1 var(--font-display); letter-spacing: -.01em; }
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  position: relative; width: 40px; height: 40px; display: grid; place-items: center; border: 0;
  background: transparent; border-radius: 12px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.badge {
  position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--neg); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.demo-banner { margin: 0 16px 4px; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 600; }

.view { padding: 4px 16px 24px; outline: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; text-decoration: none; color: var(--ink-3); font-size: 11px; font-weight: 600; border-radius: 12px;
}
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.2; }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2, h2.section { font: 650 15px/1.2 var(--font); margin: 0; letter-spacing: -.005em; }
h2.section { margin: 22px 2px 10px; color: var(--ink-2); }
.card-head .link { font-size: 13px; font-weight: 600; text-decoration: none; }

.hero { padding: 18px 18px 14px; }
.hero-label { font-size: 13px; color: var(--ink-3); font-weight: 550; }
.big { font: 680 38px/1.05 var(--font-display); letter-spacing: -.03em; margin: 4px 0 6px; }
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 650; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); }
.delta.pos { background: var(--accent-soft); }
.split { display: flex; gap: 18px; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.split b { display: block; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.spark { display: block; width: 100%; height: 70px; margin-top: 12px; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.kpi span { display: block; font-size: 12px; color: var(--ink-3); font-weight: 550; }
.kpi b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.left-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 14px 0 6px; display: flex; }
.left-bar i { display: block; height: 100%; }

.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list > .row:first-child { border-top: 0; }
.row.tap { cursor: pointer; }
.row-icon {
  flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface-2); font-size: 17px; font-weight: 700; color: var(--ink-2);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; flex: none; }
.amount { font-weight: 650; white-space: nowrap; }
.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }

.inst-logo { font-size: 12px; letter-spacing: .02em; color: #fff; }

.date-head { font-size: 12px; font-weight: 650; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 4px; }

.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 3px; }
.bar.over i { background: var(--neg) !important; }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1 1 0; width: auto; min-width: 0; }
.toolbar select { flex: 0 0 42%; width: auto; min-width: 0; }
.row-sub.wrap { white-space: normal; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); white-space: nowrap;
}
.chip.active { background: var(--ink); color: var(--bg); border-color: transparent; }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav b { font: 650 17px/1 var(--font-display); }

.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 140px; height: 140px; flex: none; }
.donut svg { width: 100%; height: 100%; }
.legend { flex: 1; min-width: 0; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.legend i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.legend span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }

.chart { width: 100%; display: block; }
.chart text { font-size: 10px; fill: var(--ink-3); font-family: var(--font); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.switch-row:first-child { border-top: 0; }
.switch-row small { display: block; color: var(--ink-3); font-size: 12px; }
.switch-row input[type=number] { width: 96px; text-align: right; padding: 8px 10px; }
.toggle { position: relative; width: 46px; height: 28px; flex: none; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle i { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: background .15s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s ease; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(18px); }

.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; background: var(--surface-2); padding: 10px 12px; border-radius: 10px; word-break: break-all; user-select: all; }
.note { font-size: 13px; color: var(--ink-2); background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.empty { text-align: center; padding: 34px 16px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s infinite; margin-bottom: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Bottom-Sheet & Toast ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 14, 11, .45); animation: fade .15s ease; }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--surface);
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); animation: up .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { font: 650 18px/1.2 var(--font-display); margin: 0 0 4px; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.cat-grid button { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-align: left; font-size: 13.5px; font-weight: 600; }
.cat-grid button.active { border-color: var(--accent); background: var(--accent-soft); }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100% - 32px); animation: up .2s ease;
}
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
.toast { animation-name: toastIn; }
@keyframes toastIn { from { transform: translate(-50%, 12px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

@media (min-width: 720px) {
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid-2 { margin-bottom: 14px; }
  .big { font-size: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
