:root {
    --bg: #f4f5f7;
    --karte: #ffffff;
    --text: #1d2330;
    --text-2: #5b6474;
    --linie: #e2e5ea;
    --akzent: #2457c5;
    --akzent-hell: #e8eefb;
    --gruen: #1f8a4c;
    --gruen-hell: #e5f4ec;
    --rot: #c2372b;
    --rot-hell: #fbeae8;
    --gelb: #9a6700;
    --gelb-hell: #fff4d6;
    --grau-hell: #f0f1f4;
    --radius: 8px;
    --schatten: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--akzent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.klein { font-size: .85em; color: var(--text-2); }
.mono { font-family: var(--mono); font-size: .92em; }
.rechts { text-align: right; }
.zentriert { text-align: center; }
.nowrap { white-space: nowrap; }
.neg { color: var(--rot); }
.pos { color: inherit; }
.gedimmt { color: var(--text-2); }
.durch { text-decoration: line-through; }

/* Kopf */
.kopf { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: #1d2330; color: #fff; }
.kopf a { color: #fff; }
.logo { font-weight: 700; font-size: 1.1rem; }
.firma-wahl { background: rgba(255,255,255,.1); padding: .3rem .7rem; border-radius: 6px; font-weight: 600; }
.firma-wahl .klein { color: #b9c1d0; margin-left: .3rem; }
.monat-wahl { display: flex; align-items: center; gap: .2rem; margin: 0; }
.monat-wahl select { width: auto; padding: .25rem .5rem; font-weight: 600; background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.monat-wahl select option { color: #1d2330; background: #fff; }
.monat-pfeil { background: none; border: 0; color: #fff; font-size: 1.2rem; cursor: pointer; padding: 0 .3rem; }
.kopf-aktionen { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.kopf .klein { color: #b9c1d0; }
.menu-knopf { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
.postfach-link { position: relative; font-size: 1.1rem; }
.hintergrund-status { background: rgba(255,255,255,.12); padding: .25rem .6rem; border-radius: 6px; font-size: .85rem; white-space: nowrap; }
.hintergrund-status[hidden] { display: none; }
.hintergrund-status.fertig { background: var(--gruen); }

/* Rahmen */
.rahmen { display: flex; min-height: calc(100vh - 52px); }
.seitenleiste { width: 220px; flex-shrink: 0; background: var(--karte); border-right: 1px solid var(--linie); padding: .75rem 0; }
.seitenleiste a { display: block; padding: .38rem 1.1rem; color: var(--text); font-size: .95rem; }
.seitenleiste a:hover { background: var(--grau-hell); text-decoration: none; }
.seitenleiste a.aktiv { background: var(--akzent-hell); color: var(--akzent); font-weight: 600; border-right: 3px solid var(--akzent); }
.nav-gruppe { padding: .9rem 1.1rem .3rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.inhalt { flex: 1; min-width: 0; padding: 1.25rem 1.5rem 3rem; }
.inhalt.schmal { max-width: 460px; margin: 3rem auto; }

/* Karten, Raster */
.karte { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: var(--schatten); padding: 1rem 1.25rem; margin-bottom: 1rem; }
.karte > h2:first-child, .karte > h3:first-child { margin-top: 0; }
.karte.fehler { border-color: var(--rot); }
.raster { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.raster-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kachel { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--schatten); }
.kachel .titel { font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.kachel .wert { font-size: 1.45rem; font-weight: 700; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.kachel .unter { font-size: .85rem; color: var(--text-2); }
.kachel.warn { border-left: 4px solid var(--gelb); }
.kachel.krit { border-left: 4px solid var(--rot); }
.kachel.ok { border-left: 4px solid var(--gruen); }
a.kachel { color: inherit; display: block; }
a.kachel:hover { text-decoration: none; border-color: var(--akzent); }

.kopfzeile { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.kopfzeile h1 { margin: 0; }
.werkzeuge { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Tabellen */
.tabelle-wrap { overflow-x: auto; background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: var(--schatten); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .5rem .65rem; border-bottom: 1px solid var(--linie); text-align: left; vertical-align: top; }
th { background: #fafbfc; font-weight: 600; font-size: .8rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfd; }
td.betrag, th.betrag { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.ausgeblendet td { color: var(--text-2); }
tr.ausgeblendet td.betrag, tr.ausgeblendet td.text { text-decoration: line-through; }
tr.summe td { font-weight: 700; background: #fafbfc; }
.zweck { max-width: 420px; font-size: .85rem; color: var(--text-2); overflow-wrap: anywhere; }
.matrix td, .matrix th { padding: .35rem .5rem; font-size: .85rem; }
.matrix td.gruppe { font-weight: 600; }

/* Badges */
.badge { display: inline-block; min-width: 1.3rem; padding: .05rem .4rem; border-radius: 10px; font-size: .75rem; font-weight: 600; background: var(--akzent); color: #fff; text-align: center; }
.badge.warn { background: var(--gelb); }
.badge.info { background: #6b7280; }
.tag { display: inline-block; padding: .08rem .45rem; border-radius: 4px; font-size: .75rem; font-weight: 600; background: var(--grau-hell); color: var(--text-2); white-space: nowrap; }
.tag.gruen { background: var(--gruen-hell); color: var(--gruen); }
.tag.rot { background: var(--rot-hell); color: var(--rot); }
.tag.gelb { background: var(--gelb-hell); color: var(--gelb); }
.tag.blau { background: var(--akzent-hell); color: var(--akzent); }

/* Meldungen */
.meldung { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.meldung.ok { background: var(--gruen-hell); border-color: #b9e0c9; color: #14532d; }
.meldung.fehler { background: var(--rot-hell); border-color: #f1c0bb; color: #7f1d1d; }
.meldung.info { background: var(--akzent-hell); border-color: #c7d5f5; color: #1e3a8a; }
.meldung.warn { background: var(--gelb-hell); border-color: #f0dca0; color: #713f12; }

/* Formulare */
label { display: block; font-weight: 600; font-size: .88rem; margin: .7rem 0 .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
    width: 100%; padding: .48rem .6rem; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; background: #fff; color: inherit;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--akzent-hell); border-color: var(--akzent); }
.inline { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.inline select, .inline input { width: auto; }
.form-raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.checkbox { display: flex; gap: .45rem; align-items: center; font-weight: 400; }
.checkbox input { width: auto; margin: 0; }
.hilfe { font-size: .82rem; color: var(--text-2); margin-top: .2rem; }

.knopf, button.knopf, input[type=submit] {
    display: inline-block; padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--akzent); background: var(--akzent); color: #fff;
    font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.knopf:hover { filter: brightness(1.07); text-decoration: none; }
.knopf.zweit { background: #fff; color: var(--akzent); }
.kopf .knopf.zweit { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.knopf.klein { padding: .2rem .55rem; font-size: .8rem; }
.knopf.rot { background: var(--rot); border-color: var(--rot); }
.knopf.gruen { background: var(--gruen); border-color: var(--gruen); }
.knopf:disabled { opacity: .5; cursor: default; }
.link-knopf { background: none; border: 0; padding: 0; color: var(--akzent); cursor: pointer; font: inherit; }

/* Filterleiste */
.filter { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filter label { margin: 0 0 .2rem; font-size: .75rem; color: var(--text-2); }
.filter > div { min-width: 120px; }
.filter select, .filter input { padding: .35rem .5rem; }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--linie); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; color: var(--text-2); border-bottom: 2px solid transparent; }
.tabs a.aktiv { color: var(--akzent); border-color: var(--akzent); font-weight: 600; }

/* Monatskacheln */
.monate { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.monat-kachel { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--schatten); color: inherit; }
.monat-kachel:hover { border-color: var(--akzent); text-decoration: none; }
.monat-kachel h3 { margin: 0 0 .4rem; display: flex; justify-content: space-between; align-items: center; }
.monat-kachel dl { display: grid; grid-template-columns: 1fr auto; gap: .1rem .5rem; margin: 0; font-size: .85rem; }
.monat-kachel dt { color: var(--text-2); }
.monat-kachel dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* Upload */
.dropzone { border: 2px dashed #b8c2d3; border-radius: var(--radius); padding: 2rem 1rem; text-align: center; background: #fbfcfe; cursor: pointer; transition: .15s; }
.dropzone.drueber { border-color: var(--akzent); background: var(--akzent-hell); }
.dropzone input[type=file] { display: none; }
.upload-liste { margin-top: .75rem; font-size: .9rem; }
.upload-liste div { padding: .25rem 0; border-bottom: 1px solid var(--linie); }

/* Diagramme */
.diagramm svg { width: 100%; height: auto; display: block; }
.diagramm text { font-size: 11px; fill: var(--text-2); font-family: inherit; }
.legende { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; margin-top: .4rem; }
.legende span::before { content: ""; display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; background: var(--farbe); }
.balken-liste .zeile { display: grid; grid-template-columns: 180px 1fr 110px; gap: .6rem; align-items: center; padding: .25rem 0; font-size: .88rem; }
.balken-liste .spur { background: var(--grau-hell); border-radius: 4px; height: 14px; overflow: hidden; }
.balken-liste .fuell { background: var(--akzent); height: 100%; }

/* Details */
dl.daten { display: grid; grid-template-columns: 180px 1fr; gap: .35rem 1rem; margin: 0; }
dl.daten dt { color: var(--text-2); font-size: .88rem; }
dl.daten dd { margin: 0; overflow-wrap: anywhere; }
.vorschau-pdf { width: 100%; height: 75vh; border: 1px solid var(--linie); border-radius: var(--radius); background: #fff; }
.vorschau-bild { max-width: 100%; border: 1px solid var(--linie); border-radius: var(--radius); }

details.karte summary { cursor: pointer; font-weight: 600; }
.leer { padding: 2rem; text-align: center; color: var(--text-2); }
.seiten { display: flex; gap: .3rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
.seiten a, .seiten span { padding: .25rem .6rem; border: 1px solid var(--linie); border-radius: 5px; background: #fff; font-size: .85rem; }
.seiten span { background: var(--akzent); color: #fff; border-color: var(--akzent); }

/* Handy */
@media (max-width: 860px) {
    .menu-knopf { display: block; }
    .seitenleiste { position: fixed; top: 52px; left: 0; bottom: 0; z-index: 15; transform: translateX(-100%); transition: transform .2s; overflow-y: auto; box-shadow: var(--schatten); }
    body.menu-offen .seitenleiste { transform: none; }
    .inhalt { padding: 1rem; }
    .benutzer-name, .kopf-aktionen .klein { display: none; }
    .firma-wahl .klein { display: none; }
    .balken-liste .zeile { grid-template-columns: 110px 1fr 90px; }
    dl.daten { grid-template-columns: 1fr; }
    .kopf { gap: .5rem; padding: .5rem .75rem; }
    .kopf .knopf { padding: .35rem .6rem; }
}
@media print {
    .kopf, .seitenleiste, .werkzeuge, .filter { display: none !important; }
    .inhalt { padding: 0; }
}
.werkzeuge select, .werkzeuge input:not([type=checkbox]) { width: auto; }
.aktionsleiste { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: .6rem .8rem; background: #fafbfc; border-bottom: 1px solid var(--linie); }
.aktionsleiste select, .aktionsleiste input:not([type=checkbox]) { width: auto; max-width: 260px; }

/* Beleg per Drag & Drop auf eine Zeile */
tr[data-beleg-ziel] { transition: background .15s; }
tr.drop-ziel-aktiv td { background: var(--akzent-hell) !important; }
tr.drop-ziel-aktiv { outline: 2px dashed var(--akzent); outline-offset: -2px; }
tr.beleg-laedt td { opacity: .7; }
tr.beleg-erledigt td { background: var(--gruen-hell); }
.beleg-status { margin-top: .3rem; }
.beleg-status > div { padding: .1rem 0; }
.bueroklammer { background: none; border: 1px solid var(--linie); border-radius: 6px; cursor: pointer; padding: .15rem .45rem; font-size: .95rem; }
.bueroklammer:hover { border-color: var(--akzent); background: var(--akzent-hell); }
#drop-overlay { position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; background: rgba(36, 87, 197, .12); border: 4px dashed var(--akzent); pointer-events: none; }
#drop-overlay > div { background: #fff; padding: 1.5rem 2rem; border-radius: 12px; box-shadow: var(--schatten); font-size: 1.3rem; font-weight: 700; text-align: center; }
#drop-overlay span { font-size: .9rem; font-weight: 400; color: var(--text-2); }
#upload-toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 40; width: min(420px, calc(100vw - 2rem)); max-height: 50vh; overflow: auto; background: #fff; border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.15); font-size: .88rem; }
#upload-toast .toast-kopf { display: flex; justify-content: space-between; padding: .5rem .8rem; font-weight: 700; border-bottom: 1px solid var(--linie); }
#upload-toast .toast-kopf button { background: none; border: 0; font-size: 1.2rem; cursor: pointer; }
#upload-toast .toast-liste > div { padding: .4rem .8rem; border-bottom: 1px solid var(--linie); }
.upload-knoepfe { display: flex; gap: .5rem; justify-content: center; margin-top: .75rem; flex-wrap: wrap; }

/* Auswahl Kamera / Fotos / Dateien (Handy) */
#quellen-menue { position: fixed; inset: 0; z-index: 60; background: rgba(15, 20, 30, .45); display: flex; align-items: flex-end; justify-content: center; }
#quellen-menue .qm-blatt { background: #fff; width: 100%; max-width: 480px; border-radius: 14px 14px 0 0; padding: .75rem .75rem calc(.75rem + env(safe-area-inset-bottom)); display: grid; gap: .5rem; }
#quellen-menue .qm-titel { text-align: center; font-size: .85rem; color: var(--text-2); padding: .25rem 0 .4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#quellen-menue button { font: inherit; font-size: 1.05rem; padding: .85rem 1rem; border-radius: 10px; border: 1px solid var(--linie); background: #fafbfc; text-align: left; cursor: pointer; }
#quellen-menue button:active { background: var(--akzent-hell); }
#quellen-menue .qm-abbrechen { text-align: center; font-weight: 600; color: var(--akzent); background: #fff; }
@media (pointer: fine) { .nur-handy { display: none !important; } }

/* Handy: breite Tabellen in Karten scrollen innerhalb der Karte, Nebenspalten ausblenden */
.karte { min-width: 0; }
@media (max-width: 600px) {
    .karte > table, .karte > form > table { display: block; overflow-x: auto; }
    .mobil-aus { display: none; }
    .karte { padding: .8rem .8rem; }
}
.karte { overflow-wrap: anywhere; }
.mitte { text-align: center; }

/* Verlauf & Rückgängig */
.ruecknahme-leiste { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .5rem .8rem; margin-bottom: 1rem;
    border: 1px dashed var(--linie); border-radius: var(--radius); background: var(--karte); color: var(--text-2); }
.ruecknahme-leiste strong { color: var(--text); }
.ruecknahme-leiste .schliessen { margin-left: auto; font-size: 1.1rem; text-decoration: none; color: var(--text-2); }
.upload-ruecknahme { margin-top: .4rem; padding-top: .4rem; border-top: 1px dashed var(--linie); }
table.verlauf td { vertical-align: top; }
table.verlauf tr.zurueckgenommen { color: var(--text-2); }
.verlauf-liste { margin: .3rem 0 .2rem; padding-left: 1.1rem; }
.verlauf-liste li { margin-bottom: .2rem; }
.grau { color: var(--text-2); }

/* Fenster „Beleg per E-Mail anfordern“ */
.mail-dialog { border: 0; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(16, 24, 40, .25); padding: 1.2rem; width: min(640px, 92vw); color: var(--text); background: var(--karte); }
.mail-dialog::backdrop { background: rgba(16, 24, 40, .45); }
.mail-dialog h3 { margin: 0 0 .2rem; }
.mail-dialog label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .15rem; }
.mail-dialog input, .mail-dialog textarea { width: 100%; }
.mail-dialog textarea { font-family: inherit; line-height: 1.45; }
.mail-dialog-knoepfe { display: flex; gap: .5rem; margin-bottom: 0; }
.mail-arten { display: flex; gap: .4rem; flex-wrap: wrap; margin: .6rem 0 .3rem; }
.mail-status { min-height: 1.1em; margin-bottom: .4rem; }

/* Beleg-Ampel: farbiger Balken vorne in der Buchungszeile */
:root { --orange: #d9730d; --orange-hell: #fdefe0; --grau-balken: #b8bec9; }
tr[class*="ampel-"] > td:first-child { box-shadow: inset 5px 0 0 var(--ampel-farbe, transparent); padding-left: 1rem; }
tr.ampel-gruen { --ampel-farbe: var(--gruen); }
tr.ampel-rot { --ampel-farbe: var(--rot); }
tr.ampel-orange { --ampel-farbe: var(--orange); }
tr.ampel-grau { --ampel-farbe: var(--grau-balken); }
tr.beleg-erledigt { --ampel-farbe: var(--gruen); }
.tag.orange { background: var(--orange-hell); color: var(--orange); }
.ampel-legende { display: flex; gap: .4rem 1rem; flex-wrap: wrap; align-items: center; padding: .4rem .8rem; border-bottom: 1px solid var(--linie); }
.ampel-punkt { display: inline-block; width: 5px; height: 1em; border-radius: 2px; margin-right: .25rem; vertical-align: -.15em; }
.ampel-punkt.gruen { background: var(--gruen); }
.ampel-punkt.rot { background: var(--rot); }
.ampel-punkt.orange { background: var(--orange); }
.ampel-punkt.grau { background: var(--grau-balken); }

/* Maileingang: links die Liste, rechts die geöffnete Mail */
.mail-split { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 1rem; align-items: start; }
.mail-liste { background: var(--karte); border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: var(--schatten); overflow: auto; max-height: calc(100vh - 210px); position: sticky; top: 62px; }
.mail-zeile { display: block; padding: .5rem .7rem; border-bottom: 1px solid var(--linie); color: inherit; }
.mail-zeile:last-child { border-bottom: 0; }
.mail-zeile:hover { background: #fafbfd; text-decoration: none; }
.mail-zeile.aktiv { background: var(--akzent-hell); box-shadow: inset 3px 0 0 var(--akzent); }
.mz-kopf { display: flex; justify-content: space-between; gap: .5rem; }
.mz-von { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mz-betreff { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mz-fuss { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin-top: .2rem; }
.mail-detail { min-width: 0; }
.mail-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; max-height: 60vh; overflow: auto; }
@media (max-width: 1000px) {
    .mail-split { grid-template-columns: 1fr; }
    .mail-liste { position: static; max-height: 45vh; }
}
.mail-zahlwege { gap: .3rem; margin: .2rem 0 .2rem; }
.mail-zahlwege .knopf.gruen { box-shadow: inset 0 0 0 2px rgba(255,255,255,.4); }
.mail-detail dl.daten dd .link-knopf { margin-left: .3rem; }
