:root {
  --bg: #14161c;
  --surface: #1d2029;
  --surface-2: #262a35;
  --border: #323746;
  --text: #e8e6e1;
  --muted: #9a9ca6;
  --accent: #5c9cff;
  --accent-text: #0b1526;
  --danger: #e57373;
  /* Anteile im Balken (Palette, dunkle Stufen) */
  --c-fixed: #3987e5;
  --c-budget: #d95926;
  --c-free: #199e70;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 1.25rem; font-weight: 650; letter-spacing: 0.01em; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: transparent; font-size: 1.4rem; }
.icon-btn:active { background: var(--surface-2); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 46px; min-width: 190px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; }
.menu button:active, .menu button:hover { background: var(--surface); }

/* Ansichtswahl */
.views {
  display: flex; gap: 4px; margin: 0 16px 12px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.views button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; color: var(--muted); }
.views button[aria-selected="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-title { font-size: 0.95rem; color: var(--muted); font-weight: 600; margin: 0 0 10px; }

/* Übersicht */
.summary-label { color: var(--muted); font-size: 0.9rem; }
.summary-value { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; margin: 2px 0; }
.summary-sub { color: var(--muted); font-size: 0.9rem; }
.split { display: flex; gap: 2px; height: 10px; margin: 14px 0 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.split span { display: block; height: 100%; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.legend b { color: var(--text); font-weight: 600; }

.empty { color: var(--muted); text-align: center; padding: 8px 12px 4px; }

/* Gruppen */
.group { margin: 18px 0 8px; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 6px; }
.group-head h2 { font-size: 1rem; margin: 0; }
.group-sum { color: var(--muted); font-size: 0.95rem; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.items:empty { display: none; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item-main { flex: 1; min-width: 0; }
.item-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-amount { font-weight: 600; white-space: nowrap; text-align: right; }
.item-amount small { display: block; color: var(--muted); font-weight: 400; font-size: 0.75rem; }
.item.inactive { opacity: 0.5; }
.add-btn { width: 100%; margin-top: 8px; padding: 11px; border: 1px dashed var(--border); background: transparent; border-radius: 12px; color: var(--accent); font-weight: 550; }

/* Vorschau */
.preview { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.preview th, .preview td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.preview th:first-child, .preview td:first-child { text-align: left; }
.preview th { color: var(--muted); font-weight: 500; }
.preview tr.tight td { font-weight: 600; }
.preview .tag { font-size: 0.72rem; color: var(--muted); margin-left: 4px; font-weight: 400; }
.hint { color: var(--muted); font-size: 0.82rem; margin: 8px 0 0; }
#reserve .big { font-size: 1.5rem; font-weight: 700; }

/* Dialog */
dialog {
  width: min(560px, 100vw); max-width: 100vw; max-height: 92vh; margin: auto auto 0;
  padding: 0; border: 0; border-radius: 20px 20px 0 0;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog form { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
dialog h2 { margin: 0 0 12px; font-size: 1.15rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 12px 0 4px; }
input, select { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
#f-amount { font-size: 1.4rem; font-weight: 650; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--bg); border-radius: 10px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 8px; color: var(--muted); font-size: 0.92rem; }
.seg button[aria-checked="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
details { margin-top: 12px; }
summary { color: var(--accent); cursor: pointer; font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; font-size: 0.9rem; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.btn { padding: 10px 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); font-weight: 550; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); background: transparent; }

/* Hinweis unten */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; z-index: 10;
}
.toast button { border: 0; background: none; color: #1f5fd1; font-weight: 700; padding: 4px; }
