:root {
  --bg: #f4f5f7; --flaeche: #ffffff; --flaeche2: #f8f9fb; --linie: #e2e5ea; --text: #1c2330; --text2: #5b6575;
  --akzent: #0f5c6e; --akzent-hell: #e3f0f2; --plus: #1d7a46; --minus: #b3361f; --warn: #a86a00; --warn-hell: #fff4dd;
  --nav: #13202b; --nav-text: #c6d0da; --radius: 8px;
  --schrift: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--schrift); font-size: 14px; color: var(--text); background: var(--bg); }
#app { display: flex; min-height: 100vh; }
a { color: var(--akzent); }

/* Navigation */
#nav { width: 228px; flex: none; background: var(--nav); color: var(--nav-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.marke { display: flex; gap: 10px; align-items: center; padding: 0 8px 16px; }
.marke-zeichen { width: 34px; height: 34px; border-radius: 8px; background: #2a8a9e; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.marke strong { color: #fff; display: block; font-size: 15px; }
.marke small { font-size: 11px; opacity: .7; }
.jahr-wahl { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 8px 14px; font-size: 12px; }
.jahr-wahl select { background: #22323f; color: #fff; border: 1px solid #33485a; border-radius: 6px; padding: 4px 6px; font: inherit; }
#nav nav a { display: block; color: var(--nav-text); text-decoration: none; padding: 7px 10px; border-radius: 6px; margin: 1px 0; }
#nav nav a:hover { background: #1d2e3b; color: #fff; }
#nav nav a.aktiv { background: #23404f; color: #fff; font-weight: 600; }
.nav-titel { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .55; margin: 16px 10px 4px; }

main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.kopf { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.kopf .unter { color: var(--text2); margin-top: 3px; }
.leiste { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.karte { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.karte.eng { padding: 0; overflow: hidden; }
.karte.eng > h2 { padding: 14px 16px 0; }
.raster { display: grid; gap: 16px; }
.raster.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.raster.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--flaeche); border: 1px solid var(--linie); border-radius: var(--radius); padding: 14px 16px; }
.kpi .titel { color: var(--text2); font-size: 12px; }
.kpi .wert { font-size: 22px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .zusatz { color: var(--text2); font-size: 12px; margin-top: 2px; }

/* Tabellen */
.tab-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--linie); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text2); background: var(--flaeche2); position: sticky; top: 0; }
td.z, th.z { text-align: right; font-variant-numeric: tabular-nums; }
td.lang { white-space: normal; min-width: 180px; }
tr.klick { cursor: pointer; }
tr.klick:hover td { background: #f1f6f7; }
tr.summe td { font-weight: 650; background: var(--flaeche2); }
tr.gruppe td { font-weight: 600; background: #f0f3f6; color: var(--text2); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.plus { color: var(--plus); } .minus { color: var(--minus); }
.leer { color: #a0a8b4; }
.hinweis { color: var(--text2); font-size: 12px; }

.marke-tag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #edf0f3; color: var(--text2); font-weight: 600; }
.marke-tag.u { background: #e2f3e8; color: var(--plus); }
.marke-tag.k { background: #fbe9e5; color: var(--minus); }
.marke-tag.a { background: var(--warn-hell); color: var(--warn); }
.marke-tag.ok { background: #e2f3e8; color: var(--plus); }
.marke-tag.offen { background: var(--warn-hell); color: var(--warn); }

/* Formular */
button, .knopf { font: inherit; border: 1px solid var(--linie); background: var(--flaeche); color: var(--text); padding: 7px 13px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .knopf:hover { border-color: #c3c9d2; background: #fafbfc; }
button.primaer, .knopf.primaer { background: var(--akzent); border-color: var(--akzent); color: #fff; }
button.primaer:hover { background: #0c4d5c; }
button.gefahr { color: var(--minus); }
button.klein, .knopf.klein { padding: 4px 9px; font-size: 12px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #ccd2da; border-radius: 6px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc7d1; border-color: var(--akzent); }
input[type=checkbox] { width: auto; }
.suche { width: 240px; }
.felder { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 14px; }
.feld label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.feld.breit { grid-column: 1 / -1; }
.feld.check label { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text); margin-top: 22px; }
.feld-gruppe { border: 1px solid var(--linie); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.feld-gruppe > legend { font-weight: 600; padding: 0 6px; }

.werte { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.werte dt { color: var(--text2); }
.werte dd { margin: 0; }

dialog { border: none; border-radius: 12px; padding: 0; width: min(760px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 25, 35, .45); }
dialog form { padding: 20px 22px; }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
.dialog-fuss { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }
.vorschau { background: var(--akzent-hell); border-radius: 6px; padding: 10px 12px; margin-top: 12px; font-variant-numeric: tabular-nums; }

#meldung { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: #13202b; color: #fff; padding: 10px 16px; border-radius: 8px; transition: transform .2s; z-index: 99; }
#meldung.zeigen { transform: translateX(-50%) translateY(0); }
#meldung:not(.zeigen) { visibility: hidden; }
#meldung.fehler { background: var(--minus); }

.tabs { display: flex; gap: 4px; background: #e8ebef; padding: 3px; border-radius: 7px; }
.tabs button { border: none; background: transparent; padding: 5px 11px; }
.tabs button.aktiv { background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }

/* Kunden-Auswertung */
.feld-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); }
.feld-inline input[type=date] { width: auto; }
th.sortier { cursor: pointer; user-select: none; }
th.sortier:hover { color: var(--text); }
.balken { width: 90px; height: 6px; background: #edf0f3; border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.balken i { display: block; height: 100%; background: #2a8a9e; }
tr.unterzeile > td { background: var(--flaeche2); padding: 4px 10px 10px; }
table.innen th { background: none; position: static; }
table.innen td { border-bottom-color: #eceff3; }

/* Diagramm */
.diagramm svg { width: 100%; display: block; }
.legende { display: flex; gap: 14px; font-size: 12px; color: var(--text2); margin-top: 6px; }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  #nav { width: auto; height: auto; position: static; padding: 10px; }
  #nav nav { display: flex; overflow-x: auto; gap: 2px; }
  #nav nav a { white-space: nowrap; }
  .nav-titel { display: none; }
  .marke { padding-bottom: 8px; }
  main { padding: 16px; }
  .raster.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .raster.k2 { grid-template-columns: 1fr; }
  .suche { width: 100%; }
}

/* ---------- Druckansichten (A4) ---------- */
body.druck { background: #e9ebee; }
body.druck #nav { display: none; }
body.druck main { padding: 20px 0; }
.druck-leiste { width: 210mm; margin: 0 auto 12px; display: flex; gap: 8px; justify-content: space-between; }
.blatt { width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; padding: 18mm 18mm 16mm 22mm; box-shadow: 0 2px 12px rgba(0,0,0,.12); color: #111; font-size: 10.5pt; position: relative; display: flex; flex-direction: column; }
.blatt table th { background: none; color: #111; border-bottom: 1.5px solid #111; font-size: 9.5pt; position: static; }
.blatt table td { border-bottom: 1px solid #ddd; padding: 5px 6px; white-space: normal; }
.blatt th { padding: 5px 6px; }
.b-kopf { display: flex; justify-content: space-between; align-items: flex-start; }
.b-firma { text-align: right; font-size: 9pt; line-height: 1.45; }
.b-firma strong { font-size: 17pt; display: block; letter-spacing: .02em; margin-bottom: 4px; }
.b-logo { display: block; height: 30mm; max-width: 70mm; object-fit: contain; object-position: left top; margin-top: -5mm; }
.b-kopf.mit-logo .b-absender { margin-top: 6mm; }
.logo-vorschau { height: 64px; max-width: 220px; object-fit: contain; border: 1px solid var(--linie); border-radius: 6px; padding: 4px; background: #fff; }
.b-absender { font-size: 7.5pt; text-decoration: underline; margin-top: 18mm; color: #333; }
.b-anschrift { margin-top: 3mm; line-height: 1.45; min-height: 30mm; }
.b-meta { display: grid; grid-template-columns: max-content max-content; gap: 2px 14px; font-size: 9.5pt; align-self: flex-end; }
.b-titel { font-size: 13pt; font-weight: 700; margin: 8mm 0 4mm; }
.b-zeilen { line-height: 1.6; margin-bottom: 6mm; }
.b-summen { margin-left: auto; width: 80mm; margin-top: 5mm; }
.b-summen div { display: flex; justify-content: space-between; padding: 2px 0; }
.b-summen .gesamt { border-top: 1.5px solid #111; font-weight: 700; margin-top: 3px; padding-top: 4px; }
.b-text { margin-top: 10mm; line-height: 1.5; }
.b-fuss { margin-top: auto; border-top: 1px solid #999; padding-top: 3mm; font-size: 7.8pt; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; color: #333; line-height: 1.5; }
.blatt td.nw { white-space: nowrap; font-size: 9pt; }
.blatt .klein-info { font-size: 8pt; color: #555; }
.b-unterschrift { display: flex; gap: 20mm; margin-top: 22mm; }
.b-unterschrift div { flex: 1; border-top: 1px solid #111; padding-top: 2mm; font-size: 9pt; }
@page { size: A4; margin: 0; }
@media print {
  body.druck { background: #fff; }
  .druck-leiste, #meldung { display: none !important; }
  body.druck main { padding: 0; }
  .blatt { box-shadow: none; margin: 0; width: 210mm; min-height: 296mm; }
}

/* Drucken normaler Seiten (EÜR, USt) ohne Navigation */
@media print {
  #nav { display: none !important; }
  main { padding: 0 !important; }
  .kopf button, .kopf .leiste { display: none !important; }
  .karte, .kpi { break-inside: avoid; }
  th { position: static; }
}
.schritte { margin: 8px 0 10px; padding-left: 20px; line-height: 1.7; }
.scan-ablage { border: 2px dashed #b9c6d2; background: var(--flaeche2); text-align: center; padding: 22px 16px; transition: background .15s; }
.scan-ablage.ueber { background: var(--akzent-hell); border-color: var(--akzent); }
#scan-lauf { text-align: left; margin-top: 10px; }
.scan-zeile { padding: 4px 0; border-bottom: 1px solid var(--linie); font-size: 13px; }
.drehen { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--akzent); border-right-color: transparent; border-radius: 50%; animation: drehen .8s linear infinite; vertical-align: -1px; }
@keyframes drehen { to { transform: rotate(360deg); } }
.warn-zeile { color: var(--warn); margin-top: 4px; }
.scan-liste { display: flex; flex-direction: column; }
.scan-karte { display: grid; grid-template-columns: minmax(170px, 1.1fr) minmax(220px, 1.6fr) minmax(200px, 1fr) auto; gap: 8px 14px; padding: 10px 0; border-bottom: 1px solid var(--linie); align-items: start; }
.scan-karte:last-child { border-bottom: none; }
.scan-beleg a { word-break: break-word; }
.scan-auftrag select { width: 100%; }
.scan-knoepfe { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
details.karte summary { cursor: pointer; }
.status-tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 9px; margin-left: 4px; }
.status-tag.ok { background: #e2f3e8; color: var(--plus); }
.status-tag.offen { background: var(--warn-hell); color: var(--warn); }
@media (max-width: 900px) {
  .scan-karte { grid-template-columns: 1fr; }
  .scan-knoepfe { justify-content: flex-start; }
  .scan-knoepfe button { padding: 8px 12px; font-size: 14px; }
  .kopf .leiste button { padding: 9px 12px; }
}

/* Hinweis nach dem Beenden über das Dock-Symbol */
.beendet { min-height: 100vh; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--text2); }
.beendet h1 { color: var(--text); margin-bottom: 8px; }

/* ---------- iPhone / Home-Bildschirm-App (1.11) ---------- */
#leiste-mobil, #menue-schleier, .nur-mobil { display: none; }
.nur-server { display: none !important; }
body.modus-server .nur-server { display: block !important; }
@media (max-width: 760px) {
  body { font-size: 15px; -webkit-text-size-adjust: 100%; }
  input, select, textarea { font-size: 16px; }            /* verhindert das Hineinzoomen auf dem iPhone */
  .nur-mobil { display: inline-flex; }
  #leiste-mobil { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40;
    background: var(--nav); color: #fff; padding: calc(8px + env(safe-area-inset-top)) 12px 8px calc(12px + env(safe-area-inset-left)); }
  #menue-knopf { background: none; border: none; color: #fff; font-size: 22px; padding: 4px 8px; }
  .leiste-titel { font-weight: 650; font-size: 16px; }
  #app { display: block; }
  #nav { position: fixed; top: 0; bottom: 0; left: 0; width: min(280px, 82vw); height: auto; z-index: 60;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-105%); transition: transform .2s ease; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #nav nav { display: block; overflow: visible; }
  #nav nav a { padding: 11px 12px; font-size: 15px; }
  .nav-titel { display: block; }
  body.menue-offen #nav { transform: none; }
  body.menue-offen #menue-schleier { display: block; position: fixed; inset: 0; background: rgba(10,18,25,.45); z-index: 50; }
  main { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
  h1 { font-size: 19px; }
  .kopf { margin-bottom: 12px; }
  .kopf .leiste { width: 100%; }
  .raster { gap: 10px; }
  .raster.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .wert { font-size: 18px; }
  .karte { padding: 12px; }
  th, td { padding: 8px 8px; }
  .felder { grid-template-columns: 1fr; }
  .werte { grid-template-columns: 1fr; gap: 2px; }
  .werte dd { margin-bottom: 8px; }
  dialog { width: 100vw; max-width: 100vw; height: 100%; max-height: 100%; margin: 0; border-radius: 0; }
  dialog form { padding: calc(16px + env(safe-area-inset-top)) 14px calc(24px + env(safe-area-inset-bottom)); }
  .dialog-fuss { position: sticky; bottom: 0; background: #fff; padding-top: 10px; flex-wrap: wrap; }
  button, .knopf { padding: 9px 13px; }
  .scan-ablage > div:first-child strong { display: none; }
  #meldung { bottom: calc(20px + env(safe-area-inset-bottom)); max-width: 92vw; }
  body.druck #leiste-mobil { display: none; }
  .druck-leiste { width: auto; padding: calc(8px + env(safe-area-inset-top)) 10px 0; }
  .blatt { width: 210mm; transform-origin: top left; }
  body.druck main { overflow-x: auto; }
}

/* Anmeldeseite */
body.anmelde-seite { min-height: 100vh; display: grid; place-items: center; background: var(--nav); padding: 20px; }
.anmelde-karte { width: min(360px, 100%); background: var(--flaeche); border-radius: 14px; padding: 22px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.anmelde-karte .marke { padding: 0 0 6px; }
.anmelde-karte .marke strong { color: var(--text); }
.anmelde-karte .marke small { color: var(--text2); opacity: 1; }
.anmelde-karte input { font-size: 16px; padding: 10px; }
.anmelde-karte button { justify-content: center; padding: 11px; font-size: 16px; }
.anmelde-fehler { color: var(--minus); min-height: 1em; font-size: 14px; }

/* Passwort anzeigen/verbergen */
.pw-feld { display: flex; gap: 6px; align-items: stretch; width: 100%; }
.pw-feld input { flex: 1; min-width: 0; }
.pw-feld .pw-zeigen { flex: none; font-size: 13px; padding: 6px 10px; }

/* Anhang-Vorschau (iPhone) */
body.anhang-offen { overflow: hidden; }
.anhang { position: fixed; inset: 0; z-index: 200; background: #2b333c; display: flex; flex-direction: column; }
.anhang-leiste { display: flex; align-items: center; gap: 8px; background: var(--nav); color: #fff;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left)); }
.anhang-titel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; text-align: center; }
.anhang-leiste button, .anhang-leiste .knopf { flex: none; padding: 7px 11px; font-size: 14px; }
.anhang-zu { background: transparent; color: #fff; border-color: #4a5b6a; }
.anhang-inhalt { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 8px 8px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; }
.anhang-seite, .anhang-bild { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.35); max-width: 100%; height: auto; }
.anhang-hinweis { color: #dfe6ec; text-align: center; padding: 18px 12px; max-width: 420px; }
.anhang-hinweis .knopf { margin-top: 6px; }
