:root {
  --gold: #b8944a; --gold-hell: #c9a961; --dunkel: #1a1a1a; --text: #1f1f1f; --grau: #6b6b6b;
  --linie: #e2e0db; --flaeche: #f6f4f0; --rot: #b3372f; --gruen: #2f7a3d; --gelb: #fff6d6;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--flaeche); display: flex; flex-direction: column;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* Kopf */
#kopf {
  background: var(--dunkel); color: var(--gold-hell); display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 8px calc(16px + env(safe-area-inset-left));
}
#kopf h1 { margin: 0; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
#kopf h1 img { width: 34px; height: 34px; border-radius: 7px; }
#kopf h1 span { color: #fff; opacity: .65; font-weight: 400; }
#kopf nav { display: flex; gap: 4px; margin-left: auto; }
#kopf nav button { background: none; border: 0; color: #fff; opacity: .65; padding: 10px 12px; border-radius: 8px; min-height: 44px; }
#kopf nav button.aktiv { opacity: 1; background: rgba(255,255,255,.12); color: var(--gold-hell); font-weight: 600; }
.sicher { border: 1px solid rgba(255,255,255,.3); background: none; color: #cfe8d2; border-radius: 22px; padding: 8px 14px; min-height: 40px; font-size: 14px; white-space: nowrap; }
.sicher.rot { background: var(--rot); border-color: var(--rot); color: #fff; font-weight: 600; }

/* Raster */
#ansicht { flex: 1; min-height: 0; display: grid; }
.ansicht-rechnungen { grid-template-columns: 270px minmax(430px, 1fr) minmax(360px, 1fr); }
.ansicht-kunden { grid-template-columns: 300px 1fr; }
.ansicht-einstellungen { grid-template-columns: 1fr; }
.liste { background: #fff; border-right: 1px solid var(--linie); display: flex; flex-direction: column; min-height: 0; }
.liste-kopf { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--linie); }
.filter { display: flex; gap: 6px; padding: 8px 12px; flex-wrap: wrap; border-bottom: 1px solid var(--linie); }
.filter button { border: 0; background: var(--flaeche); border-radius: 14px; padding: 6px 12px; font-size: 13px; }
.filter button.aktiv { background: var(--dunkel); color: #fff; }
.eintraege { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.eintrag { display: grid; gap: 2px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--linie); border-left: 4px solid transparent; padding: 12px 12px 12px 10px; }
.eintrag.gewaehlt { background: #fbf5e6; border-left-color: var(--gold); }
.eintrag .oben { display: flex; justify-content: space-between; gap: 8px; }
.eintrag .betrag { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; }
.eintrag .wer { color: #444; font-size: 14px; }
.eintrag .unten { color: var(--grau); font-size: 12.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.marke { font-style: normal; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; padding: 1px 7px; border-radius: 9px; background: #e8e8e8; color: #555; }
.m-gestellt { background: #efe3c4; color: #6d5415; } .m-versendet { background: #d6e9f7; color: #1b5a8c; }
.m-bezahlt { background: #d4edd4; color: #256b2f; } .m-storniert { background: #f3d6d4; color: #8c2620; } .m-warn { background: var(--rot); color: #fff; }
.leer { color: var(--grau); text-align: center; padding: 40px 20px; }

.bearbeiten { background: #fff; border-right: 1px solid var(--linie); padding: 16px 18px calc(28px + env(safe-area-inset-bottom)); overflow-y: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.bearbeiten.einzeln { max-width: 860px; width: 100%; margin: 0 auto; border: 0; background: none; }
.bearbeiten h2 { font-size: 19px; margin: 18px 0 8px; }
.bearbeiten h2:first-child, .editor-kopf h2 { margin-top: 0; }
.editor-kopf { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.editor-kopf small { font-weight: 400; color: var(--grau); font-size: 14px; }
fieldset { border: 1px solid var(--linie); border-radius: 10px; margin: 12px 0 0; padding: 10px 12px 12px; min-width: 0; }
legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--grau); padding: 0 6px; }
.feld { display: block; margin-top: 8px; min-width: 0; }
.feld span { display: block; font-size: 12px; color: var(--grau); margin-bottom: 3px; }
input, select { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid #cfccc5; border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--gold-hell); outline-offset: 0; border-color: var(--gold); }
input:disabled, select:disabled { background: #f3f2ef; color: #444; -webkit-text-fill-color: #444; opacity: 1; }
input.falsch { border-color: var(--rot); background: #fdf0ef; }
.zeile2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.zeile3 { display: grid; grid-template-columns: 2fr 1fr 2fr; gap: 10px; }
fieldset .zeile3:has(input[type=date]) { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
details { margin-top: 8px; } summary { color: var(--gold); font-size: 14px; padding: 6px 0; cursor: pointer; }
.umschalter { display: flex; align-items: center; gap: 0; margin: 4px 0 10px; font-size: 14px; }
.umschalter span { margin-right: 10px; color: var(--grau); }
.umschalter button { border: 1px solid #cfccc5; background: #fff; padding: 7px 16px; min-height: 38px; }
.umschalter button:first-of-type { border-radius: 8px 0 0 8px; } .umschalter button:last-of-type { border-radius: 0 8px 8px 0; border-left: 0; }
.umschalter button.aktiv { background: var(--dunkel); color: #fff; border-color: var(--dunkel); }
.pos { display: grid; grid-template-columns: 1fr 1fr 1.3fr 1fr 40px; gap: 6px; align-items: center; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px dashed var(--linie); }
.pos input[data-pf=text] { grid-column: 1 / -1; }
.pos-kopf { font-size: 11.5px; color: var(--grau); font-weight: 600; margin-bottom: 4px; padding-bottom: 0; border: 0; }
.pos input, .pos select { padding: 8px; }
.pos input[data-pf=menge], .pos input[data-pf=preis] { text-align: right; font-variant-numeric: tabular-nums; }
.weg { border: 0; background: none; color: var(--rot); font-size: 26px; line-height: 1; min-height: 44px; }
.weg:disabled { visibility: hidden; }
.summen { margin-top: 10px; background: var(--flaeche); border-radius: 8px; padding: 10px 12px; font-variant-numeric: tabular-nums; }
.summen div { display: flex; justify-content: space-between; padding: 1px 0; }
.summen .brutto { font-weight: 700; font-size: 18px; border-top: 1px solid #d5d2cb; margin-top: 5px; padding-top: 6px; }
.aktionen { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.knopf { border: 1px solid #cfccc5; background: #fff; border-radius: 9px; padding: 10px 16px; min-height: 46px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.knopf.haupt { background: var(--gold); border-color: var(--gold); color: #fff; }
.knopf.gruen { background: var(--gruen); border-color: var(--gruen); color: #fff; }
.knopf.rot { color: var(--rot); border-color: #dcb1ad; }
.knopf.warn { background: var(--rot); border-color: var(--rot); color: #fff; }
.knopf.gestrichelt { border-style: dashed; font-weight: 400; color: var(--grau); }
.knopf.breit { width: 100%; }
.klein-knopf { min-height: 34px; padding: 4px 12px; font-weight: 400; margin-left: 8px; }
.nur-schmal { display: none; }
.hinweis { background: #eef3ee; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 10px 0 0; }
.hinweis.gelb { background: var(--gelb); }
.klein { font-size: 13px; color: var(--grau); }
.rot-text { color: var(--rot); }

/* Vorschau */
.vorschau { display: flex; flex-direction: column; min-height: 0; background: #dedbd4; }
.vorschau-kopf { background: #2a2a2a; color: #bbb; font-size: 12.5px; padding: 8px 14px; display: flex; justify-content: space-between; }
.vorschau-flaeche { flex: 1; overflow: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.blatt { width: 210mm; min-height: 297mm; background: #fff; color: #000; transform-origin: top left; box-shadow: 0 2px 10px rgba(0,0,0,.18);
  padding: 22mm 23mm 18mm 26mm; font: 10.5pt/1.5 "Liberation Sans", Arial, Helvetica, sans-serif; position: relative; overflow: hidden; }
.blatt.entwurf::after { content: "ENTWURF"; position: absolute; left: 0; right: 0; top: 46%; text-align: center; font-size: 80pt; font-weight: 700; color: rgba(0,0,0,.07); transform: rotate(-35deg); pointer-events: none; }
.b-logo { text-align: center; margin-bottom: 12mm; } .b-logo img { width: 47mm; display: block; margin: 0 auto; }
.b-titel div { text-decoration: underline; }
.b-nr { margin-top: 8mm; font-size: 12pt; } .b-nr small { font-size: 9.5pt; }
.b-kunde { margin-top: 7mm; padding-bottom: 2mm; border-bottom: .75pt solid #000; }
.b-adr { margin-top: 4mm; min-height: 1.5em; }
.b-datum { text-align: right; margin-top: 8mm; }
.blatt table { width: 100%; border-collapse: collapse; margin-top: 5mm; font-size: 9.5pt; line-height: 1.45; table-layout: fixed; }
.blatt td { border: .75pt solid #000; padding: 2mm; vertical-align: top; overflow-wrap: anywhere; }
.blatt tr.kopf td { height: 13mm; } .blatt td.re { text-align: right; } .blatt td.mitte { text-align: center; } .blatt tr.fett td { font-weight: 700; }
.b-dank { margin-top: 8mm; font-weight: 700; font-variant: small-caps; font-size: 9pt; }
.b-hinweis { font-style: italic; margin-top: 2.5mm; font-size: 9pt; }
.b-fuss { margin-top: 3.5mm; font-size: 9pt; } .b-fuss b { font-variant: small-caps; }

/* Dialog und Meldung */
dialog { border: 0; border-radius: 14px; padding: 22px; max-width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 8px; font-size: 20px; }
.dialog-inhalt p { margin: 8px 0; } .dialog-inhalt ul { padding-left: 20px; margin: 8px 0; } .dialog-inhalt li { margin: 4px 0; }
.dialog-knoepfe { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px); background: #333; color: #fff; padding: 12px 20px; border-radius: 10px; opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
.toast.zeigen { opacity: 1; transform: translate(-50%, 0); } .toast.gut { background: var(--gruen); } .toast.fehler { background: var(--rot); }

/* iPad hochkant und schmaler: Vorschau als Überlagerung */
@media (max-width: 1150px) {
  #kopf h1 span { display: none; }
  #kopf { gap: 8px; }
  .ansicht-rechnungen { grid-template-columns: 270px 1fr; }
  .nur-schmal { display: inline-flex; }
  .vorschau { display: none; position: fixed; inset: 0; z-index: 20; }
  .vorschau-offen .vorschau { display: flex; }
  .vorschau-kopf { padding: calc(12px + env(safe-area-inset-top)) 16px 12px; font-size: 15px; }
  .vorschau-kopf::after { content: "Schließen ✕"; color: #fff; }
}
@media (max-width: 720px) {
  #ansicht { display: block; overflow-y: auto; }
  .liste { border-right: 0; max-height: 45vh; }
  .bearbeiten { overflow: visible; }
  .zeile2, .zeile3, fieldset .zeile3:has(input[type=date]) { grid-template-columns: 1fr; gap: 0; }
  .pos { grid-template-columns: 1fr 1fr 1fr 1fr 36px; }
}
@media print { #kopf, .liste, .bearbeiten, .vorschau-kopf, .toast { display: none !important; } .vorschau { display: block; position: static; } .blatt { box-shadow: none; transform: none !important; } }
