:root {
  --bg: #f4f5f2; --card: #ffffff; --text: #1d2420; --muted: #66706a; --line: #dfe3dd; --field: #fbfcfa;
  --accent: #1f5f4a; --accent-2: #2a7a60; --accent-soft: #e5f0eb; --pos: #1f7a4c; --neg: #b3261e; --warn-bg: #fff6df; --warn-line: #e8c770;
  --info-bg: #e8eef8; --info-line: #9db3d8; --sub: #f7f8f5;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131715; --card: #1b201d; --text: #e6ebe7; --muted: #95a199; --line: #2e3631; --field: #161a18;
    --accent: #5fbf98; --accent-2: #7fd3b0; --accent-soft: #1f3129; --pos: #6fd39e; --neg: #ff8a80; --warn-bg: #2d2817; --warn-line: #6f5d26;
    --info-bg: #1c2433; --info-line: #3b4d6e; --sub: #171b19;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
a { color: var(--accent); }
p { margin: .3rem 0 .6rem; }
.muted { color: var(--muted); } .center { text-align: center; } .small { font-size: .85rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.error { color: var(--neg); min-height: 1em; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 1.25rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .65rem; }
.brand small { display: block; color: var(--muted); font-size: .75rem; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--card); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }
nav { display: flex; align-items: center; gap: .2rem; flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--text); padding: .4rem .7rem; border-radius: 7px; font-size: .92rem; }
nav a:hover { background: var(--accent-soft); }
nav a.active { background: var(--accent); color: var(--card); font-weight: 600; }
#who { color: var(--muted); font-size: .85rem; margin: 0 .4rem 0 .8rem; }
main { max-width: 1500px; margin: 0 auto; padding: 1.25rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; }
.toolbar { display: flex; gap: .6rem 1rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.grid { display: grid; gap: .75rem 1rem; }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.scroll { overflow-x: auto; }

label { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); font-size: .9rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 7px; padding: .45rem .55rem; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
.toolbar select, .toolbar input { width: auto; }
.toolbar input[type=search] { min-width: 14em; }

button { font: inherit; cursor: pointer; border-radius: 7px; padding: .45rem .9rem; border: 1px solid var(--line); background: var(--card); color: var(--text); white-space: nowrap; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; }
button.small { padding: .25rem .6rem; font-size: .82rem; }
button.danger { color: var(--neg); }
button.danger:hover { border-color: var(--neg); }
button.wide { width: 100%; margin-top: .5rem; }
.card.narrow label { margin-bottom: .75rem; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: none; border-radius: 0; border-right: 1px solid var(--line); padding: .45rem .8rem; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: var(--card); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .4rem .45rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .3rem .45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.num { text-align: right; white-space: nowrap; }
th.num { text-align: right; }

/* BWA-Tabelle */
table.bwa td { border-bottom: none; padding: .2rem .45rem; }
table.bwa td.konto { color: var(--muted); width: 4.2em; }
table.bwa td.name { min-width: 14em; }
table.bwa:not(.months) td.name { width: 100%; }
table.bwa tr.bereich td { font-weight: 700; font-size: 1rem; padding-top: 1.1rem; border-bottom: 2px solid var(--accent); color: var(--accent); }
table.bwa tr.part td { font-weight: 600; padding-top: .55rem; }
table.bwa tr.group td { color: var(--muted); font-size: .8rem; padding-top: .45rem; font-style: italic; }
table.bwa tr.line td.name { padding-left: 1.2rem; }
table.bwa tr.line:hover td { background: var(--accent-soft); }
table.bwa tr.line.click { cursor: pointer; }
table.bwa tr.sum td { border-top: 1px solid var(--line); font-weight: 600; }
table.bwa tr.result td { border-top: 1px solid var(--text); font-weight: 700; background: var(--sub); }
table.bwa tr.total td { border-top: 2px solid var(--text); border-bottom: 2px solid var(--text); font-weight: 700; font-size: 1.02rem; background: var(--accent-soft); }
table.bwa tr.space td { height: .6rem; }
table.bwa.months td.num, table.bwa.months th.num { font-size: .82rem; padding: .2rem .3rem; }
table.bwa td.prev, table.bwa th.prev { color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; }
.kpi small { display: block; color: var(--muted); font-size: .78rem; }
.kpi strong { font-size: 1.25rem; }

.badge { display: inline-block; font-size: .72rem; padding: .08rem .5rem; border-radius: 99px; background: var(--sub); border: 1px solid var(--line); margin: 0 .2rem .15rem 0; white-space: nowrap; }
.badge.split { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.badge.intern { background: var(--info-bg); border-color: var(--info-line); }
.badge.moved { background: var(--warn-bg); border-color: var(--warn-line); }
.badge.manual { border-style: dashed; }
.badge.warn { background: var(--warn-bg); border-color: var(--neg); color: var(--neg); }

.banner { background: var(--warn-bg); border: 1px solid var(--warn-line); padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.banner.info { background: var(--info-bg); border-color: var(--info-line); }
.banner ul { margin: .3rem 0 0; padding-left: 1.2rem; }

table.rows td { font-size: .88rem; }
table.rows tr:hover td { background: var(--accent-soft); }
table.rows td.text { min-width: 14em; }
table.rows tr.dim td { color: var(--muted); }

.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: var(--field); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.results li { margin: .25rem 0; }

.saldo { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; padding: .7rem 0; border-bottom: 1px solid var(--line); font-size: 1.05rem; }
.saldo strong { font-size: 1.2rem; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); padding: 1.25rem; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog label { margin-bottom: .7rem; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .9rem; margin: 0 0 1rem; font-size: .9rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .75rem; padding: .6rem .8rem .2rem; }
legend { font-size: .82rem; color: var(--muted); padding: 0 .3rem; }

table.rules td { vertical-align: middle; }
table.rules input, table.rules select { padding: .3rem .4rem; font-size: .85rem; }
table.rules .mands { display: flex; gap: .4rem; flex-wrap: wrap; }
table.rules .mands label { flex-direction: row; gap: .2rem; color: var(--text); font-size: .8rem; margin: 0; }

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; z-index: 20; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.err { background: var(--neg); color: #fff; }
.print-head { display: none; }

@media (max-width: 760px) {
  main { padding: .75rem 16px; }
  .top { padding: .5rem 16px; }
  .brand small, #who { display: none; }
  nav a { padding: .35rem .5rem; font-size: .85rem; }
  .g3 { grid-template-columns: 1fr; }
  .toolbar input[type=search] { min-width: 0; width: 100%; }
  table.bwa td.konto, table.bwa th.konto { display: none; }
  table.bwa td.name { min-width: 10em; }
}

@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; color: #000; font-size: 9pt; }
  .top, .toolbar, .no-print, dialog, .toast, .banner { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; padding: 0; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 3mm; margin-bottom: 4mm; }
  .print-head h1 { font-size: 15pt; margin: 0; }
  .kpis { display: none; }
  .scroll { overflow: visible; }
  table.bwa tr { break-inside: avoid; }
  table.bwa tr.bereich td { color: #000; border-bottom-color: #000; }
  table.bwa tr.total td, table.bwa tr.result td { background: none; }
  table.bwa.months td.num, table.bwa.months th.num { font-size: 7pt; padding: .5mm .8mm; }
  .neg { color: #000; }
}
