:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --grid: #e8e6e1;
  --accent: #2a78d6;
  --s-erloes: #2a78d6;
  --s-prognose: #9ec5f4;
  --s-kosten: #eb6834;
  --s-eigen: #6250d6;
  --s-sperre: #a3a29c;
  --s-vorjahr: #b8b6af;
  --s-neg: #e34948;
  --frei-we: #ebe9e4;
  --frei: #f6f5f2;
  --good: #006300;
  --bad: #b42323;
  --heat-0: #f6f5f2;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928b;
    --grid: #2a2a28;
    --accent: #3987e5;
    --s-erloes: #3987e5;
    --s-prognose: #1c5cab;
    --s-kosten: #d95926;
    --s-eigen: #9085e9;
    --s-sperre: #5d5c57;
    --s-vorjahr: #55544f;
    --s-neg: #e66767;
    --frei-we: #262624;
    --frei: #1f1f1d;
    --good: #4cc24c;
    --bad: #ef7c7c;
    --heat-0: #1f1f1d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #93928b; --grid: #2a2a28;
  --accent: #3987e5; --s-erloes: #3987e5; --s-prognose: #1c5cab;
  --s-kosten: #d95926; --s-eigen: #9085e9; --s-sperre: #5d5c57;
  --s-vorjahr: #55544f; --s-neg: #e66767; --frei-we: #262624; --frei: #1f1f1d;
  --good: #4cc24c; --bad: #ef7c7c; --heat-0: #1f1f1d;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 22px; margin-bottom: 4px; }
h3 { font-size: 14px; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.klein { font-size: 12px; color: var(--text-3); font-weight: 400; }

/* ---------- Kopfzeile ---------- */
.kopf {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.kopf-innen {
  max-width: 1280px; margin: 0 auto; padding: 10px 16px;
  display: flex; gap: 12px 24px; align-items: center; flex-wrap: wrap;
}
.titel { display: flex; flex-direction: column; }
.stand { font-size: 12px; color: var(--text-3); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: var(--text-2); text-decoration: none; padding: 6px 10px;
  border-radius: 6px; font-size: 13px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.steuerung { display: flex; gap: 8px; align-items: center; }
select, input, button { font: inherit; color: inherit; }
select, input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; min-width: 0;
}
.umschalter { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.umschalter button {
  background: var(--surface); border: 0; padding: 6px 10px; cursor: pointer; color: var(--text-2);
}
.umschalter button.aktiv { background: var(--text); color: var(--surface); }

main { max-width: 1280px; margin: 0 auto; padding: 16px 16px 64px; }
.meldung {
  background: #fff4d6; color: #5a4300; border: 1px solid #f0d78a;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 16px;
}
.abschnitt { margin-top: 40px; }
.hinweis { color: var(--text-2); margin: 0 0 14px; max-width: 80ch; }

/* ---------- Kacheln ---------- */
.kacheln {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}
.kachel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px;
}
.kachel .label { font-size: 12px; color: var(--text-2); }
.kachel .wert { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.kachel .unter { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- Karten ---------- */
.karte {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; min-width: 0;
}
.karte-kopf {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
.raster-2 { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.raster-2 > .karte { margin-bottom: 0; }
.raster-2 { margin-bottom: 16px; }
.raster-2.links-breit { grid-template-columns: 1fr 1.4fr; }
@media (max-width: 700px) {
  .kopf-innen { gap: 8px; }
  .titel { flex: 1; }
  .nav { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav a { white-space: nowrap; padding: 4px 8px; }
}
@media (max-width: 900px) {
  .raster-2, .raster-2.links-breit { grid-template-columns: 1fr; }
}
.diagramm { position: relative; height: 260px; }
.diagramm.hoch { height: 320px; }

/* ---------- Tabellen ---------- */
.tabelle-scroll { overflow-x: auto; max-height: 460px; overflow-y: auto; }
.tabelle { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabelle th {
  text-align: left; font-weight: 500; color: var(--text-2); font-size: 12px;
  border-bottom: 1px solid var(--border); padding: 6px 8px; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface);
}
.tabelle td { padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.tabelle tr:last-child td { border-bottom: 0; }
.tabelle.zahlen td:not(:first-child), .tabelle.zahlen th:not(:first-child),
.tabelle td.z, .tabelle th.z { text-align: right; }
.tabelle tr.summe td { font-weight: 600; border-top: 1px solid var(--border); }
.tabelle tr.zukunft td { color: var(--text-3); }
.tabelle td.leer { color: var(--text-3); }
.tag {
  display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px;
  background: var(--surface-2); color: var(--text-2);
}
.tag.neu { background: color-mix(in srgb, var(--s-erloes) 18%, transparent); color: var(--text); }
.tag.storno { background: color-mix(in srgb, var(--s-neg) 18%, transparent); color: var(--text); }
.tag.prog { background: color-mix(in srgb, var(--s-prognose) 40%, transparent); color: var(--text); }
.aktion { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0 4px; font-size: 12px; }
.aktion.loeschen { color: var(--bad); }

/* Bruecke (Wasserfall als Tabelle) */
.bruecke td:nth-child(2) { text-align: right; width: 110px; }
.bruecke td:nth-child(3) { width: 45%; }
.bruecke .balken { height: 10px; border-radius: 3px; background: var(--s-erloes); }
.bruecke .balken.minus { background: var(--s-kosten); }
.bruecke .balken.ergebnis { background: var(--text-2); }
.bruecke .balken.negativ { background: var(--s-neg); }
.bruecke tr.zwischen td { font-weight: 600; border-top: 1px solid var(--border); }
.bruecke td:first-child { white-space: normal; }

/* Heatmap */
.heatmap { border-collapse: separate; border-spacing: 2px; font-size: 12px; width: 100%; }
.heatmap th { font-weight: 500; color: var(--text-2); padding: 2px 4px; }
.heatmap td {
  text-align: center; padding: 5px 2px; border-radius: 4px; min-width: 34px;
  cursor: default;
}
.heatmap td.jahr { text-align: left; color: var(--text-2); font-weight: 500; }

/* Kalender */
.kalender { display: grid; grid-template-columns: 42px repeat(31, minmax(18px, 1fr)); gap: 2px; min-width: 700px; }
.kalender .kz { font-size: 11px; color: var(--text-3); text-align: center; }
.kalender .mz { font-size: 12px; color: var(--text-2); align-self: center; }
.kalender .t { height: 20px; border-radius: 3px; background: var(--frei); }
.kalender .t.we { background: var(--frei-we); }
.kalender .t.B { background: var(--s-erloes); }
.kalender .t.E { background: var(--s-eigen); }
.kalender .t.S {
  background: repeating-linear-gradient(45deg, var(--s-sperre) 0 3px, transparent 3px 6px);
}
.kalender .t.heute { outline: 2px solid var(--text); outline-offset: 1px; }
.kalender .t.an { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.legende { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }
.legende i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Formulare */
.formular { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-content: start; }
.formular .karte-kopf, .formular .breit { grid-column: 1 / -1; }
.formular label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.formular p { margin: 0; color: var(--text-2); }
.knoepfe { display: flex; gap: 8px; }
button.primaer, button.abbrechen {
  border-radius: 6px; padding: 7px 14px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2);
}
button.primaer { background: var(--accent); border-color: var(--accent); color: #fff; }
pre { white-space: pre-wrap; background: var(--surface-2); padding: 8px; border-radius: 6px; margin: 0; }
@media (max-width: 520px) { .formular { grid-template-columns: 1fr; } }

/* Tooltip */
.tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--text); color: var(--surface); font-size: 12px;
  padding: 6px 8px; border-radius: 6px; max-width: 260px; white-space: pre-line;
}

/* Dokumente */
.klein-text { color: var(--text-2); }
.klein-text p { margin: 0 0 6px; }
#export-log { max-height: 320px; overflow: auto; margin-top: 8px; }
.beleg-link { display: inline-flex; align-items: center; gap: 2px; margin-right: 8px; white-space: nowrap; }
.beleg-link a { text-decoration: none; }
.status-ok { color: var(--good); font-weight: 600; }
.status-fehler { color: var(--bad); font-weight: 600; }
.status-laeuft { color: var(--accent); font-weight: 600; }
.eingang { margin: 0; padding-left: 18px; }

.badge { background: var(--s-kosten); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; margin-left: 2px; }
#posteingang .aktionen { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
#posteingang select { padding: 2px 4px; font-size: 12px; max-width: 220px; }
#posteingang tr.ignoriert td { color: var(--text-3); }
.beleg-hinweis { background: var(--surface-2); padding: 6px 8px; border-radius: 6px; }

label.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
label.check input { margin: 0; }
#objekt-wahl:empty { display: none; }
.steuerung { flex-wrap: wrap; }
@media (max-width: 700px) {
  .steuerung { flex: 1 1 100%; gap: 6px; }
  .umschalter button { padding: 5px 8px; }
}

#nacht-tabelle td { min-width: 44px; font-size: 11px; }
#nacht-tabelle td.vorkauf, #nacht-tabelle th.vorkauf { font-style: italic; }
#nacht-tabelle tr.summe td { font-weight: 600; border-top: 1px solid var(--border); }

/* Monatsdetails */
#monat-dialog {
  width: min(1000px, calc(100% - 32px)); max-height: calc(100% - 48px);
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--text);
}
#monat-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.md-kopf {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between;
  align-items: center; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.md-zu { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--text-2); }
#md-inhalt { padding: 6px 18px 18px; }
#md-inhalt h3 { margin: 18px 0 6px; }
#md-inhalt .md-summe { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 10px 0 4px; font-size: 13px; color: var(--text-2); }
#md-inhalt .md-summe strong { color: var(--text); }
#md-inhalt input.korr { width: 110px; text-align: right; }
#md-inhalt input.korr-k { width: 100%; min-width: 140px; }
#md-inhalt tr.ist-korr td { background: color-mix(in srgb, var(--s-kosten) 10%, transparent); }
#md-inhalt tr.aus td { color: var(--text-3); text-decoration: line-through; }
#md-inhalt tr.aus td:last-child { text-decoration: none; }
.tag.korr { background: color-mix(in srgb, var(--s-kosten) 25%, transparent); color: var(--text); }
button.md-auf { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }

.zweifach-m { display: flex; gap: 6px; }
.zweifach-m input { flex: 1; min-width: 0; }
details.bh-felder summary { cursor: pointer; }

.ich { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.ich a { color: var(--text-2); text-decoration: none; }
.qr-inline { display: inline-grid; place-items: center; background: #fff; border-radius: 8px; padding: 6px; }
.qr-inline svg { width: 180px; height: 180px; }
.codes-inline { display: grid; grid-template-columns: repeat(2, max-content); gap: 4px 18px; font-family: ui-monospace, monospace; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; margin: 6px 0; }

/* Aufteilung eines Postens auf mehrere Konten */
tr.aufteil-info td { font-size: .82rem; color: var(--text-3); padding-top: 0; border-top: none; }
tr.aufteil-info span { display: inline-block; margin-right: 1.1em; white-space: nowrap; }
#dlg-aufteilung { border: 1px solid var(--border); border-radius: 10px; padding: 1.2rem; box-sizing: border-box; width: max-content; max-width: min(820px, calc(100vw - 32px)); overflow: auto;
  background: var(--surface); color: inherit; }
#dlg-aufteilung::backdrop { background: rgba(0, 0, 0, .35); }
#dlg-aufteilung h3 { margin-top: 0; }
.aufteil-tab input, .aufteil-tab select { width: 100%; box-sizing: border-box; }
.aufteil-tab input.a-konto { min-width: 6em; }
.aufteil-tab input.a-text { min-width: 9em; }
.aufteil-tab input.z { min-width: 6em; }
.aufteil-tab select { min-width: 5em; }
.aufteil-tab input.z { text-align: right; }
.aufteil-tab tfoot td { font-weight: 600; }
#dlg-aufteilung .knoepfe { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }

label.upload-knopf { cursor: pointer; display: inline-block; }

.fest-hinweis { color: var(--s-kosten); }

/* Tabs (Dashboard und Buchhaltung) */
.nav.tabs a.aktiv { background: var(--text); color: var(--surface); }
main > section.abschnitt[hidden] { display: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
/* Drill-down */
.kachel.klickbar, [data-dd], td[data-md] { cursor: pointer; }
.kachel.klickbar:hover { border-color: var(--accent); }
.kachel.klickbar .label::after { content: " ›"; color: var(--accent); }
a.dd-link { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--text-3); cursor: pointer; }
a.dd-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
td[data-dd]:hover, td[data-md]:hover { color: var(--accent); text-decoration: underline dotted; }
#dlg-detail { border: 1px solid var(--border); border-radius: 10px; padding: 0; width: min(1000px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); background: var(--surface); color: inherit; }
#dlg-detail::backdrop { background: rgba(0, 0, 0, .35); }
#dlg-detail .dd-kopf { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px 8px;
  position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); }
#dlg-detail .dd-kopf h3 { margin: 0; }
#dlg-detail .dd-inhalt { padding: 10px 18px 18px; }
#dlg-detail table td.hl, #dlg-detail table th.hl { background: color-mix(in srgb, var(--accent) 12%, transparent); }
#dlg-detail tr.gruppe td { font-weight: 600; background: var(--surface-2); }
#dlg-detail .dd-hinweis { margin: 0 0 10px; }
#dlg-detail { overflow: auto; }
#dlg-detail .tabelle-scroll { max-height: none; }
#dlg-detail .tabelle td { white-space: normal; }
#dlg-detail .tabelle td.z, #dlg-detail .tabelle.zahlen td { white-space: nowrap; }
@media (max-width: 600px) { #dlg-detail .tabelle td .tag { display: none; } #dlg-detail .dd-inhalt { padding: 8px 10px 14px; } }
