:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0f7a3d;
  --good-bg: #e3f4e9;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --bad: #c22d2c;
  --grid: #e6e5e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --good: #5fd08a;
    --good-bg: #16301f;
    --warn: #f0b552;
    --warn-bg: #33270f;
    --bad: #f07373;
    --grid: #2c2c29;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #2f2f2c;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --good: #5fd08a; --good-bg: #16301f; --warn: #f0b552; --warn-bg: #33270f;
  --bad: #f07373; --grid: #2c2c29; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .75rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; color: var(--text-2); margin-top: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.err { color: var(--bad); }
.ok { color: var(--good); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; white-space: nowrap; padding: 14px 0; }
#nav { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a {
  padding: 14px 10px; color: var(--text-2); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
#nav a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; margin-right: auto; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { color: var(--text-2); font-size: .82rem; }
.kpi-value { font-size: 1.45rem; font-weight: 650; margin-top: 2px; }
.kpi-sub { color: var(--muted); font-size: .78rem; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.split { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: center; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } .donut-wrap { max-width: 240px; margin: 0 auto; } }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 12px; font-size: .9rem;
}
.banner.good { background: var(--good-bg); border-color: transparent; }
.banner.warn { background: var(--warn-bg); border-color: transparent; }
.banner .badge { font-weight: 600; font-size: .8rem; }
.banner.good .badge { color: var(--good); }
.banner.warn .badge { color: var(--warn); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { color: var(--muted); font-weight: 500; font-size: .8rem; }
.table tfoot th, .table tfoot td { border-bottom: 0; }
.num { text-align: right !important; white-space: nowrap; }
.pos { color: var(--good); }
.negv { color: var(--text); }
tr.neg td { color: var(--bad); }
tr.future td { opacity: .65; }
tr.interest-row td { background: var(--surface-2); }
tr.current td { font-weight: 600; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: 0; flex: none; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions select { width: auto; padding: 4px 6px; font-size: .82rem; }
.tag {
  display: inline-block; font-size: .74rem; padding: 1px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.tag.int, .tag.ok { background: var(--good-bg); color: var(--good); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.chip { display: inline-flex; align-items: center; margin: 1px 10px 1px 0; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--text-2); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; }

/* ---------- Formulare ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
input, select, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=color]), select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); min-height: 38px;
}
label.inline input:not([type=checkbox]) { width: auto; }
.card-head select { width: auto; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] { width: 38px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); flex: none; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 14px; align-items: end; }
.grid-form .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; }
.hint { margin: 0; color: var(--muted); font-size: .82rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .82rem; }
.icon {
  border: 0; background: transparent; cursor: pointer; width: 32px; height: 32px; border-radius: 6px;
  color: var(--muted); font-size: 1rem;
}
.icon:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon:disabled { opacity: .3; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-size: .85rem; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }

/* ---------- Kategorien ---------- */
.cat-list { list-style: none; margin: 0 0 12px; padding: 0; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cat-row input:not([type=color]) { flex: 1; min-width: 0; }
.cat-row .num { min-width: 110px; }
.cat-row.add { border-bottom: 0; }
@media (max-width: 600px) {
  .cat-row { flex-wrap: wrap; }
  .cat-row input:not([type=color]) { flex-basis: calc(100% - 50px); }
  .cat-row .num { min-width: 0; margin-right: auto; }
}

/* ---------- Diagramme ---------- */
.chart-host { position: relative; }
.donut { width: 100%; height: auto; display: block; }
.donut-seg { stroke: var(--surface); stroke-width: 2px; }
.donut-empty { stroke: var(--surface-2); }
.donut-total { font-size: 19px; font-weight: 650; fill: var(--text); }
.donut-sub { font-size: 12px; fill: var(--muted); }
.timeline { display: block; overflow: visible; }
.timeline .grid line { stroke: var(--grid); stroke-width: 1; }
.axis-label { font-size: 11px; fill: var(--muted); }
.area { stroke: var(--surface); stroke-width: 1; }
.area-total { fill: var(--accent); fill-opacity: .12; }
.line-total { stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.cross-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart-tip {
  position: absolute; display: none; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: .8rem; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 170px;
}
.tip-date { color: var(--muted); margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 4px; }
.tip-row b { margin-left: auto; padding-left: 12px; font-weight: 600; }
.tip-total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px;
  transition: .2s; pointer-events: none; max-width: calc(100% - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); color: #fff; }

/* ---------- Login ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-card form { display: grid; gap: 12px; }
.auth-card .btn { width: 100%; margin-top: 4px; }

@media (max-width: 600px) {
  .container { padding: 14px 12px 60px; }
  .card { padding: 14px; }
  .topbar { gap: .75rem; padding: 0 12px; }
  .table th, .table td { padding: 7px 5px; }
  .tx-table td:nth-child(4), .tx-table th:nth-child(4) { display: none; }
}
