:root {
  --bg: #f4f5f2; --surface: #ffffff; --surface-2: #eef0ec; --line: #e0e3dd;
  --text: #1b2421; --muted: #6b7570; --accent: #1f7a5c; --accent-2: #d99a2b; --accent-soft: #e3f1eb;
  --in: #1f8a5a; --out: #c2483a; --warn: #d9822b;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --nav-h: 62px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --line: #2a3530;
    --text: #e6ece9; --muted: #8e9a95; --accent: #3fb489; --accent-2: #e8b04a; --accent-soft: #1d3a30;
    --in: #4cc38a; --out: #ef7564; --warn: #f0a050; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.in { color: var(--in); } .out { color: var(--out); } .muted { color: var(--muted); } .small { font-size: 13px; }

/* ---------- Gerüst ---------- */
.shell { display: flex; min-height: 100vh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: calc(12px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; min-height: 40px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: .3px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; height: var(--nav-h);
  color: var(--muted); font-size: 11px; gap: 2px; }
.tabbar a .ico { font-size: 20px; line-height: 1; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  .tabbar { display: none; }
  .side { display: flex; flex-direction: column; gap: 2px; width: 210px; padding: 22px 12px; position: sticky; top: 0; height: 100vh;
    border-right: 1px solid var(--line); background: var(--surface); }
  .side .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
  .side .brand img { width: 32px; height: 32px; border-radius: 8px; }
  .side a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text); }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .side a:hover:not(.on) { background: var(--surface-2); }
  .main { padding: 24px 32px 48px; }
}

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .grow { flex: 1; }
.grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
.grid > .card { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hero { background: linear-gradient(135deg, #1f3a34, #2b5a4b); color: #fff; border: 0; }
.hero .label { opacity: .75; font-size: 13px; }
.hero .big { font-size: 32px; font-weight: 700; letter-spacing: .3px; }
.hero .sub { display: flex; gap: 18px; margin-top: 10px; flex-wrap: wrap; font-size: 13px; opacity: .9; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 17px; font-weight: 650; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--out); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }

input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=month], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 11px; outline: none; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; min-height: 70px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > * { color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.chip { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 9px; font-size: 12px;
  background: var(--surface-2); color: var(--text); border: 1px solid transparent; white-space: nowrap; }
.chip .x { cursor: pointer; opacity: .6; margin-left: 2px; }
.chip.tag { background: color-mix(in srgb, var(--c, #5b8def) 16%, transparent); color: color-mix(in srgb, var(--c, #5b8def) 80%, var(--text)); }
.chip.click { cursor: pointer; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }

.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.over > i { background: var(--out); }

/* ---------- Listen ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); border-radius: 10px; }
.avatar { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; flex-shrink: 0;
  background: color-mix(in srgb, var(--c, #8a8f98) 18%, transparent); }
.item .title { font-weight: 550; }
.item .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item .amount { font-weight: 650; text-align: right; white-space: nowrap; }
.item.sel { background: var(--accent-soft); border-radius: 10px; }
.day-head { font-size: 12px; color: var(--muted); padding: 14px 4px 4px; font-weight: 600; display: flex; justify-content: space-between; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.t td.r, table.t th.r { text-align: right; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Diagramme ---------- */
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart text { fill: var(--muted); font-size: 10px; }
svg.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.donut-wrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.donut-wrap svg { width: 150px; height: 150px; flex-shrink: 0; }
.legend { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 180px; }
.legend .l { display: flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ---------- Sheet (Detail-Dialog) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: -6px auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; }
.cat-grid button { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11.5px; }
.cat-grid button .e { font-size: 18px; }
.cat-grid button.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.section-title { font-size: 12px; color: var(--muted); font-weight: 600; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .5px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 100; opacity: 0;
  pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: .95; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto 6px; }
.login input { text-align: center; padding: 12px; font-size: 16px; }
.err { color: var(--out); font-size: 14px; min-height: 20px; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px - var(--nav-h)); min-height: 380px; }
@media (min-width: 900px) { .chat { height: calc(100vh - 120px); } }
.chat .msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant table { border-collapse: collapse; margin: 6px 0; font-size: 13px; display: block; overflow-x: auto; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--line); padding: 4px 7px; }
.msg.assistant p { margin: 0 0 8px; } .msg.assistant p:last-child { margin: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 8px; padding-left: 20px; }
.chat form { display: flex; gap: 8px; align-items: flex-end; padding-top: 8px; }
.chat textarea { min-height: 44px; max-height: 160px; flex: 1; }
.typing { color: var(--muted); font-size: 13px; padding: 4px 6px; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; }
.drop { border: 2px dashed var(--line); border-radius: 14px; padding: 22px; text-align: center; cursor: pointer; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
