:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --surface-2: #f3f3f0;
  --text: #1c1c1a;
  --text-2: #6b6b66;
  --text-3: #9a9a93;
  --line: #e5e5e0;
  --line-2: #d2d2cb;
  --accent: #1d6f56;
  --accent-bg: #e6f2ee;
  --danger: #b4302f;
  --danger-bg: #fbeceb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1e;
    --surface-2: #2a2a28;
    --text: #ececea;
    --text-2: #a1a19b;
    --text-3: #74746e;
    --line: #303030;
    --line-2: #3d3d3b;
    --accent: #4cbf95;
    --accent-bg: #16302a;
    --danger: #e8706e;
    --danger-bg: #331d1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 80px; }

/* ---------- Kopf ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px 20px; padding: 10px 16px;
}
.top-row { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 600; letter-spacing: -.02em; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.brand svg { width: 20px; height: 20px; }
nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav button {
  border: 0; background: none; color: var(--text-2); cursor: pointer;
  padding: 7px 11px; border-radius: 8px; font-size: 14px; white-space: nowrap;
}
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button.active { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- Bausteine ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--text-2); }
.stat .value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.grid { display: grid; gap: 12px; }
.g3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { margin-left: auto; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 14px; font-weight: 600; margin: 20px 0 8px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--accent); }
.neg { color: var(--danger); }
.empty { color: var(--text-3); font-size: 14px; padding: 24px 0; text-align: center; }

button.btn {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 7px 13px; cursor: pointer; font-size: 14px;
}
button.btn:hover { background: var(--surface-2); }
button.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
button.btn.primary:hover { opacity: .88; }
button.btn.danger { color: var(--danger); border-color: var(--line-2); }
button.btn.ghost { border-color: transparent; background: none; color: var(--text-2); }
button.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
button.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }

.seg { display: flex; gap: 3px; background: var(--surface-2); padding: 3px; border-radius: 9px; }
.seg button {
  flex: 1; border: 0; background: none; padding: 7px; border-radius: 7px;
  cursor: pointer; color: var(--text-2); font-size: 14px;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chip {
  border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.on { border-color: transparent; }
.chip.dashed { border-style: dashed; color: var(--text-2); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 0 0 8px; }
td { padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tr.clickable td { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }

.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.neg-badge { background: var(--danger-bg); color: var(--danger); }
tr.off td { opacity: .55; }
td.clickable { cursor: pointer; }
tr:hover td.clickable { background: var(--surface-2); }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; padding: 18px 20px 20px;
}
.sheet.wide { max-width: 620px; }
.sheet-head { display: flex; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; margin-right: auto; }
.amount-input { font-size: 26px; font-weight: 600; padding: 10px 12px; letter-spacing: -.02em; }
.err { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }

.fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  width: 52px; height: 52px; border-radius: 50%; border: 0;
  background: var(--text); color: var(--bg); font-size: 26px; line-height: 1;
  cursor: pointer; box-shadow: var(--shadow);
}

/* ---------- Login ---------- */
.login { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login .card { width: 100%; max-width: 320px; text-align: center; }

@media (max-width: 640px) {
  .brand span { display: none; }
  td, th { font-size: 13px; }
}
