/* ==========================================================================
   Rechnungsgenerator: Design-Tokens angelehnt an Untitled UI (Teal),
   Aufbau angelehnt an Qonto (Schritte, Karten, Vorschau rechts). Hell = Standard.
   ========================================================================== */

@font-face { font-family: "Inter"; src: url("../fonts/inter-var.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../fonts/jetbrains-mono-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --surface-2: #F2F4F7;
  --surface-3: #EAECF0;
  --border: #EAECF0;
  --border-strong: #D0D5DD;
  --text: #101828;
  --text-2: #344054;
  --text-3: #667085;
  --primary: #107569; /* Teal 700: weiße Schrift erreicht 5,3 : 1 (WCAG AA) */
  --primary-hover: #125D56;
  --primary-soft: #F0FDF9;
  --primary-soft-2: #CCFBEF;
  --on-primary: #FFFFFF;
  --ring: 0 0 0 4px #CCFBEF;
  --error: #D92D20;
  --error-text: #B42318;
  --error-soft: #FEF3F2;
  --error-border: #FDA29B;
  --success-text: #067647;
  --success-soft: #ECFDF3;
  --warning-text: #B54708;
  --warning-soft: #FFFAEB;
  --preview-bg: #EEF0F3;
  --ink: #1D2939; /* Akzent auf der Rechnung (Tabellenkopf), unabhängig vom App-Design */

  --shadow-xs: 0 1px 2px rgb(16 24 40 / .05);
  --shadow-sm: 0 1px 3px rgb(16 24 40 / .1), 0 1px 2px rgb(16 24 40 / .06);
  --shadow-lg: 0 12px 16px -4px rgb(16 24 40 / .08), 0 4px 6px -2px rgb(16 24 40 / .03);
  --shadow-xl: 0 20px 24px -4px rgb(16 24 40 / .1), 0 8px 8px -4px rgb(16 24 40 / .04);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tap: 40px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0C0D0F;
  --surface: #16171A;
  --surface-2: #1E1F23;
  --surface-3: #2A2B30;
  --border: #26272C;
  --border-strong: #36373D;
  --text: #F4F4F5;
  --text-2: #D4D4D8;
  --text-3: #A1A1AA;
  --primary: #2ED3B7;
  --primary-hover: #5FE9D0;
  --primary-soft: rgb(46 211 183 / .1);
  --primary-soft-2: rgb(46 211 183 / .22);
  --on-primary: #06201C;
  --ring: 0 0 0 4px rgb(46 211 183 / .25);
  --error: #F97066;
  --error-text: #FDA29B;
  --error-soft: rgb(240 68 56 / .1);
  --error-border: rgb(249 112 102 / .55);
  --success-text: #75E0A7;
  --success-soft: rgb(18 183 106 / .12);
  --warning-text: #FEC84B;
  --warning-soft: rgb(247 144 9 / .12);
  --preview-bg: #08090A;
  --shadow-xs: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / .5);
  --shadow-lg: 0 12px 16px -4px rgb(0 0 0 / .5);
  --shadow-xl: 0 20px 24px -4px rgb(0 0 0 / .6);
  color-scheme: dark;
}
@media (pointer: coarse) { :root { --tap: 44px; } }

/* ---------- Basis ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
a { color: var(--primary); text-underline-offset: 2px; }
button { font: inherit; color: inherit; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
[hidden] { display: none !important; }
.sprite { position: absolute; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: none; box-shadow: var(--ring); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
html.scroll-locked, html.scroll-locked body { overflow: hidden; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border-radius: var(--radius-md); border: 1px solid transparent;
  font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn .icon { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-3); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.is-invalid { border-color: var(--error-border); color: var(--error-text); box-shadow: 0 0 0 4px var(--error-soft); }
.icon-btn {
  position: relative; display: grid; place-items: center; flex: none;
  width: var(--tap); height: var(--tap); border: 0; border-radius: var(--radius-md);
  background: none; color: var(--text-3); cursor: pointer; transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--error-soft); color: var(--error-text); }
.onboarding {
  display: flex; align-items: center; gap: 16px; padding: 16px;
  background: var(--primary-soft); border: 1px solid var(--primary-soft-2); border-radius: var(--radius-xl);
}
/* Abgeschlossene Rechnung */
.locked-note {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin-bottom: 20px;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-xl);
}
.locked-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--surface); color: var(--text-2); box-shadow: var(--shadow-xs); }
.locked-text { flex: 1; min-width: 0; }
.locked-text strong { display: block; font-size: 15px; }
.locked-text p { font-size: 13px; color: var(--text-3); }
.locked-note .btn { flex: none; }
/* Gesperrte Felder lesbar halten (nicht ausgegraut), aber klar als nicht editierbar zeigen */
.is-locked .input:disabled { background: var(--surface-2); color: var(--text); -webkit-text-fill-color: var(--text); opacity: 1; cursor: default; border-style: dashed; }
.is-locked select.input:disabled { background-image: none; }
.is-locked #add-item, .is-locked [data-action="remove"], .is-locked [data-action="add-discount"], .is-locked [data-action="remove-discount"], .is-locked #save-defaults, .is-locked #onboarding { display: none !important; }
.is-locked .chip:disabled:not(.is-active) { opacity: .45; cursor: default; }
.is-locked .chip:disabled.is-active { cursor: default; }
.is-locked .switch { cursor: default; }
.is-locked .switch:has(#save-customer) { display: none; }
.locked-note { flex-wrap: wrap; }
.locked-note .btn { flex: 1 1 100%; }

/* Bestätigungsdialog */
dialog.modal {
  width: min(440px, calc(100vw - 32px)); max-width: none; padding: 0; border: 0; border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 48px -12px rgb(16 24 40 / .25);
}
dialog.modal::backdrop { background: rgb(12 17 29 / .5); backdrop-filter: blur(4px); }
dialog.modal[open] { animation: pop-in .18s var(--ease); }
@keyframes pop-in { from { transform: scale(.96); opacity: 0; } }
.modal-body { display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.modal-body h2 { font-size: 18px; font-weight: 700; }
.modal-body p { font-size: 14px; color: var(--text-2); }
.modal-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary-soft) 50%, transparent); margin-bottom: 4px; }
.modal-actions { display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1 1 auto; min-width: 0; max-width: 100%; min-height: 44px; white-space: normal; text-align: center; line-height: 1.25; padding-block: 8px; }
@media (max-width: 480px) {
  /* Handy: beide Knöpfe gleich breit untereinander, Hauptaktion oben */
  .modal-actions { flex-direction: column-reverse; flex-wrap: nowrap; }
  .modal-actions .btn { flex: none; width: 100%; }
}

.onboarding-icon { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--surface); color: var(--primary); box-shadow: var(--shadow-xs); }
.onboarding-text { flex: 1; min-width: 0; }
.onboarding-text strong { display: block; font-size: 15px; }
.onboarding-text p { font-size: 14px; color: var(--text-2); }
.icon-btn.needs-setup::after { content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 2px var(--surface); }
.icon-btn.has-error::after { content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--error); box-shadow: 0 0 0 2px var(--surface); }
.link-btn { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; min-height: 32px; padding: 0 4px; border: 0; background: none; color: var(--primary); font-size: 14px; font-weight: 600; cursor: pointer; border-radius: var(--radius-sm); }
.link-btn .icon { width: 16px; height: 16px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Formularfelder ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 14px; font-weight: 500; color: var(--text-2); }
.optional { font-weight: 400; color: var(--text-3); }
.field-hint { font-size: 13px; color: var(--text-3); }
.input {
  width: 100%; min-width: 0; min-height: var(--tap); padding: 8px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s;
}
.input.mono { font-size: 16px; } /* < 16 px würde iOS beim Antippen hineinzoomen */
.input:focus-visible { border-color: var(--primary); box-shadow: var(--shadow-xs), var(--ring); }
.input::placeholder { color: var(--text-3); opacity: .8; }
.input:disabled { background: var(--surface-2); color: var(--text-3); }
textarea.input { resize: vertical; line-height: 1.45; }
select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px 18px;
}
[data-theme="dark"] select.input { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
select.input:disabled { cursor: not-allowed; opacity: .7; }
select.input::-ms-expand { display: none; }
.input[aria-invalid="true"] { border-color: var(--error-border); background: var(--error-soft); }
.input[aria-invalid="true"]:focus-visible { border-color: var(--error); box-shadow: 0 0 0 4px var(--error-soft); }
.field-error { display: flex; gap: 6px; align-items: flex-start; margin: 0; font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--error-text); }
.field-error::before {
  content: "!"; flex: none; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 1px; border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--error);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-2 { grid-column: 1 / -1; }
.input-group { display: flex; }
.input-group > .input { border-radius: 0; }
.input-group > .input:first-child { border-top-left-radius: var(--radius-md); border-bottom-left-radius: var(--radius-md); }
/* rechte Ecken nur am letzten Feld der Gruppe: dahinter kann noch ein Icon-Button stehen */
.input-group > .input:not(:has(+ .input)) { border-top-right-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }
.input-group > .input + .input { margin-left: -1px; }
.input-group > .input:hover, .input-group > .input:focus { position: relative; z-index: 1; }
.input-group > select.input { flex: 0 0 auto; width: auto; min-width: 96px; }
.input-group > .icon-btn { margin-left: 4px; }

/* Schalter (Untitled-UI-Toggle) */
.switch { position: relative; display: flex; gap: 12px; align-items: flex-start; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-2); }
/* Das echte Kontrollkästchen liegt unsichtbar genau über dem Schalter. Wichtig: Bezug ist .switch (position: relative):
   sonst hängt es am Seitenfenster, und beim Antippen scrollt das ganze Fenster zu seiner „falschen“ Position ins Leere. */
.switch input { position: absolute; top: 1px; left: 0; width: 36px; height: 20px; margin: 0; opacity: 0; pointer-events: none; }
.switch-track { flex: none; position: relative; width: 36px; height: 20px; margin-top: 1px; border-radius: 99px; background: var(--surface-3); transition: background-color .2s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: translate .2s var(--ease); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { translate: 16px 0; }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch strong { display: block; font-weight: 500; color: var(--text); }
.switch small { display: block; font-size: 13px; font-weight: 400; color: var(--text-3); }
.switch.is-disabled { cursor: not-allowed; }
.switch.is-disabled .switch-track, .switch.is-disabled strong, .switch.is-disabled small:not(.giro-warning) { opacity: .5; }

/* Chips (Zahlungsfrist) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: max(38px, var(--tap)); padding: 0 14px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2);
  font-size: 14px; font-weight: 500; transition: background-color .15s, color .15s, border-color .15s;
}
.chip:hover { background: var(--surface-2); }
/* Zahlungsfrist: gleichmäßiges Raster statt unruhigem Umbruch */
#payment-chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
#payment-chips .chip { padding: 0 6px; }
#payment-chips [data-days="custom"] { grid-column: span 2; }
.chip.is-active { background: var(--text); border-color: var(--text); color: var(--bg); }

.more summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--primary); list-style: none; padding: 4px 0; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: "+ "; }
.more[open] summary::before { content: "− "; }
.more[open] { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Adressvorschläge ---------- */
.ac-field { position: relative; }
.ac-pop {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); /* genaue Höhe: direkt unter dem Eingabefeld (address.js) */
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); overflow: hidden;
}
.ac-list { list-style: none; margin: 0; padding: 4px; max-height: 280px; overflow-y: auto; }
.ac-option { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.ac-option strong { font-size: 14px; font-weight: 600; color: var(--text); }
.ac-option span { font-size: 13px; color: var(--text-3); }
.ac-option:hover, .ac-option[aria-selected="true"] { background: var(--primary-soft); }
.ac-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 2px 12px; border-top: 1px solid var(--border); background: var(--surface-2); }
.ac-note { margin: 0; font-size: 11px; color: var(--text-3); }
.ac-near { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--primary); font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.ac-near .icon { width: 14px; height: 14px; }
.ac-near:hover { background: var(--primary-soft); }
.modal-text { display: flex; flex-direction: column; gap: 10px; font-size: 14px; color: var(--text-2); }
.modal-text ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.modal-legal { font-size: 12px !important; color: var(--text-3) !important; }
.ac-note a { color: inherit; }
.field-warn { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin: 0; font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--warning-text); }
.field-warn-action { min-height: 24px; padding: 0 2px; font-size: 13px; }
html.pdf-busy #next-step, html.pdf-busy #export-pdf, html.pdf-busy #sumbar-action { opacity: .6; pointer-events: none; cursor: progress; }

/* ---------- Kopfzeile ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-title > div { min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary); flex: none; }
.brand-mark .icon { width: 22px; height: 22px; }
h1 { font-size: 18px; font-weight: 700; letter-spacing: -.015em; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.topbar-actions { display: flex; justify-content: flex-end; gap: 4px; }

.stepper { display: flex; align-items: center; gap: 4px; }
.step {
  display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px;
  border: 0; border-radius: var(--radius-md); background: none; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--text-3); white-space: nowrap;
}
.step:hover { background: var(--surface-2); color: var(--text); }
.step-no { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--border-strong); font-size: 12px; font-weight: 600; }
.step.is-active { color: var(--text); font-weight: 600; }
.step.is-active .step-no { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.step.is-done .step-no { background: var(--primary-soft); border-color: var(--primary-soft-2); color: var(--primary); }
.step.has-error .step-no { background: var(--error); border-color: var(--error); color: #fff; }
.step-sep { width: 16px; height: 16px; color: var(--border-strong); }

.view-switch { display: none; }
.view-switch-tabs { display: contents; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(400px, 560px) minmax(0, 1fr); gap: 32px;
  max-width: 1680px; margin: 0 auto; padding: 24px 24px 0; align-items: start;
}
.editor { min-width: 0; display: flex; flex-direction: column; }
#invoice-form { padding-bottom: 24px; }
.step-panel { display: flex; flex-direction: column; gap: 16px; }
.panel-title { font-size: 17px; font-weight: 700; letter-spacing: -.01em; margin-top: 8px; }
.card {
  display: flex; flex-direction: column; gap: 16px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-xs);
}

/* Aktionsleiste unten im Formular (wie Qonto) */
.actionbar {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 -24px; padding: 16px 24px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.actionbar { container: actionbar / inline-size; }
.actionbar-nav { display: flex; align-items: center; gap: 8px; min-width: 0; }
.actionbar .btn { min-height: 44px; padding: 0 18px; font-size: 14px; white-space: nowrap; flex: none; }
/* Wird die Spalte schmal, zeigen Nebenaktionen nur ihr Symbol: nichts ragt in die Vorschau */
@container actionbar (max-width: 700px) {
  .actionbar .collapse-narrow { width: 44px; padding: 0; }
  .actionbar .collapse-narrow .btn-label { display: none; }
}
@container actionbar (max-width: 480px) {
  .actionbar .collapse-tight { width: 44px; padding: 0; }
  .actionbar .collapse-tight .btn-label { display: none; }
}
.actionbar .btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.mobile-only { display: none !important; }

/* ---------- Leistungen ---------- */
.items { display: flex; flex-direction: column; gap: 12px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-xs); }
.item-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; }
.item-toggle { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; min-height: 40px; padding: 0 4px; border: 0; background: none; cursor: pointer; text-align: left; border-radius: var(--radius-sm); }
.item-toggle .icon { width: 18px; height: 18px; color: var(--text-3); transition: rotate .2s var(--ease); }
.item.is-collapsed .item-toggle .icon { rotate: -90deg; }
.item-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-total { font-size: 14px; color: var(--text-2); white-space: nowrap; }
.item-body { display: flex; flex-direction: column; gap: 14px; padding: 4px 20px 20px; }
.item.is-collapsed .item-body { display: none; }
.item-discount { display: flex; flex-direction: column; gap: 6px; }
.item-discount .input-group > .input:first-child { flex: 1; }

/* ---------- Zahlung & Export ---------- */
.bank-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-lg); }
.bank-summary p.mono { font-size: 14px; margin-top: 2px; }
.export { gap: 10px; }
.export-option {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  transition: border-color .15s, background-color .15s;
}
.export-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.export-option strong { display: block; font-size: 15px; }
.export-option small { display: block; font-size: 13px; color: var(--text-3); }
.export-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary); flex: none; }

/* ---------- Vorschau ---------- */
.preview-wrap { position: sticky; top: calc(var(--header-h, 65px) + 24px); height: calc(100dvh - var(--header-h, 65px) - 48px); min-height: 420px; min-width: 0; }
.paper-fit {
  position: relative; height: 100%; min-width: 0; display: flex; align-items: flex-start; padding: 16px; overflow: hidden;
  background: var(--preview-bg); border: 1px solid var(--border); border-radius: var(--radius-xl);
}
.paper-fit.is-zoomed { overflow: auto; overscroll-behavior: contain; }
.zoom {
  position: absolute; right: 16px; top: 50%; translate: 0 -50%; z-index: 5;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); overflow: hidden;
}
.zoom-btn, .zoom-level { display: grid; place-items: center; min-width: 52px; height: 40px; padding: 0 6px; border: 0; background: none; cursor: pointer; color: var(--text-2); }
.zoom-btn .icon { width: 18px; height: 18px; }
.zoom-level { font-family: var(--mono); font-size: 11px; border-block: 1px solid var(--border); }
.zoom-level.is-fit { color: var(--primary); }
.zoom-btn:hover:not(:disabled), .zoom-level:hover { background: var(--surface-2); color: var(--text); }
.zoom-btn:disabled { color: var(--border-strong); cursor: default; }

/* Das Blatt: immer hell, egal welches App-Design */
.paper {
  --paper-zoom: 1;
  zoom: var(--paper-zoom);
  flex: none; margin: 0 auto; width: 210mm; min-height: 297mm;
  padding: 15mm 20mm 12mm 25mm; display: flex; flex-direction: column;
  --ink-fill: #1D2939; --ink-on: #fff; --ink-soft: #E8EAEB; --ink-line: #C7CACE;
  background: #fff; color: #1d2939; color-scheme: light;
  font-family: var(--font); font-size: 9.5pt; line-height: 1.45;
  border-radius: 2px; box-shadow: 0 12px 32px rgb(16 24 40 / .14), 0 0 0 1px rgb(16 24 40 / .06);
}
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10mm; min-height: 18mm; }
.inv-title { font-size: 24pt; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.inv-logo { display: block; flex: none; width: auto; height: 24mm; max-width: 55mm; object-fit: contain; } /* genaue Größe setzt app.js */
.inv-brand { font-size: 13pt; font-weight: 700; color: var(--ink); text-align: right; max-width: 70mm; }
.inv-return { margin-top: 8mm; font-size: 7pt; color: #667085; border-bottom: 1px solid #d0d5dd; align-self: flex-start; padding-bottom: 1px; }
.inv-address-row { display: flex; justify-content: space-between; gap: 12mm; margin: 4mm 0 8mm; min-height: 24mm; }
.inv-recipient strong { display: block; margin-bottom: .5mm; }
.inv-recipient p { color: #344054; }
.inv-meta { display: grid; grid-template-columns: auto auto; gap: 1.8mm 8mm; align-content: start; }
.inv-meta dt { font-weight: 600; color: var(--ink); }
.inv-meta dd { color: #344054; text-align: left; }
.inv-intro { white-space: pre-line; margin-bottom: 5mm; }
.paper table { width: 100%; border-collapse: collapse; }
.paper .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-items th { background: var(--ink-fill); color: var(--ink-on); font-size: 8.5pt; font-weight: 600; text-align: left; padding: 2.5mm 3mm; }
/* Zahlenspalten mit deutlichem Abstand zueinander: die Beschreibung bekommt den restlichen Platz */
.inv-items .num { padding-left: 4.5mm; }
.inv-items th.num { text-align: right; }
.inv-items td { padding: 2.6mm 3mm; border-bottom: 1px solid #eaecf0; vertical-align: top; }
.inv-items .pos { width: 11mm; color: #667085; }
.inv-items th.pos { color: var(--ink-on); }
/* Variante „Hell“: getönter Kopf mit Linie in der gewählten Farbe */
.head-light .inv-items th { background: var(--ink-soft); color: var(--ink); border-bottom: 1.5px solid var(--ink-fill); }
.inv-details { display: block; font-size: 8.5pt; color: #667085; margin-top: 1mm; white-space: pre-line; }
.inv-sum { width: 50% !important; margin: 3mm 0 0 auto; }
.inv-sum td { padding: 1.6mm 3mm; }
.inv-sum tr:first-child td { padding-top: 0; }
.inv-sum .grand td { background: var(--ink-soft); font-weight: 700; font-size: 10.5pt; color: var(--ink); padding: 3mm; }
.inv-sum .grand:not(:first-child) td { border-top: 4px solid #fff; } /* etwas Abstand zur letzten Steuerzeile */
.inv-pay { display: flex; justify-content: space-between; align-items: flex-start; gap: 12mm; margin-top: 7mm; }
.inv-pay p + p { margin-top: 3mm; }
.inv-qr { flex: none; display: flex; flex-direction: column; align-items: center; gap: 1.5mm; padding: 2.2mm 2.2mm 1.8mm; border: 1px solid #eaecf0; border-radius: 2mm; }
.giro-qr { width: 24mm; height: 24mm; }
/* Platzhalter nur am Bildschirm: zeigt, warum der GiroCode fehlt */
.inv-qr-missing {
  flex: none; width: 34mm; display: flex; flex-direction: column; align-items: center; gap: 1.5mm; padding: 3mm 2mm;
  border: 1px dashed #f79009; border-radius: 2mm; background: #fffaeb; color: #93370d; font: inherit; font-size: 7pt; line-height: 1.3; text-align: center; cursor: pointer;
}
.inv-qr-missing .icon { width: 8mm; height: 8mm; color: #dc6803; }
.inv-qr-missing strong { font-size: 7.5pt; }
.inv-qr-missing:hover { background: #fef0c7; }
.giro-warning { color: var(--warning-text) !important; font-weight: 500; }
.bank-summary.is-invalid { background: var(--warning-soft); }
.bank-summary.is-invalid .mono, .bank-missing { color: var(--warning-text); font-weight: 500; }
.inv-qr figcaption { max-width: 28mm; font-size: 6.8pt; line-height: 1.3; color: #475467; text-align: center; }
.inv-note { margin-top: 5mm; white-space: pre-line; }
.inv-foot {
  margin-top: auto; padding-top: 3.5mm; border-top: 1px solid #eaecf0;
  display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 8mm; font-size: 7.5pt; line-height: 1.5; color: #667085;
}
.inv-foot strong { color: #344054; }
.inv-body-end { height: 4mm; flex: none; }

/* ---------- Seitenfenster (Rechnungen, Einstellungen) ---------- */
.drawer {
  overflow: hidden; /* gescrollt wird nur .drawer-body */
  position: fixed; inset: 0 0 0 auto; margin: 0; width: min(540px, 100vw); max-width: 100vw; height: 100dvh; max-height: none;
  padding: 0; border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow-xl);
}
.drawer::backdrop { background: rgb(12 13 15 / .45); backdrop-filter: blur(2px); }
.drawer[open] { display: flex; flex-direction: column; animation: slide-in .25s var(--ease); }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 16px 24px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 18px; font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 16px; padding: 20px 24px calc(24px + env(safe-area-inset-bottom)); background: var(--bg); }
.drawer-intro { font-size: 14px; color: var(--text-3); }
.settings-card { display: flex; flex-direction: column; gap: 16px; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); }
.settings-card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-card-head h3 { font-size: 16px; font-weight: 700; }
.settings-status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--warning-soft); color: var(--warning-text); white-space: nowrap; }
.settings-status.is-ok { background: var(--success-soft); color: var(--success-text); }
.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 12px; }
.form-grid .col-full { grid-column: span 6; }
.form-grid .col-half { grid-column: span 3; }
.form-grid .col-zip { grid-column: span 2; }
.form-grid .col-city { grid-column: span 4; }
.req { color: var(--error); font-weight: 600; }
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-text { color: var(--error-text); }
.danger-text:hover { background: var(--error-soft); color: var(--error-text); }

/* Rechnungsdesign */
.design-row { display: flex; gap: 20px; align-items: flex-start; }
.design-controls { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  position: relative; width: 36px; height: 36px; flex: none; border-radius: 50%; cursor: pointer; padding: 0;
  border: 0; background: var(--swatch); box-shadow: inset 0 0 0 1px rgb(16 24 40 / .12);
  transition: transform .15s;
}
.swatch::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; transition: border-color .15s; }
.swatch:hover { transform: scale(1.06); }
.swatch.is-active::after { border-color: var(--text); }
.swatch:focus-visible { box-shadow: inset 0 0 0 1px rgb(16 24 40 / .12), var(--ring); }
/* Eigene Farbe: Farbrad, darin die gewählte Farbe */
.swatch-custom { display: grid; place-items: center; background: conic-gradient(from 0deg, #f04438, #f79009, #fac515, #17b26a, #06aed4, #2e90fa, #7a5af8, #ee46bc, #f04438); }
.swatch-custom::before { content: ''; width: 16px; height: 16px; border-radius: 50%; background: var(--swatch, transparent); box-shadow: 0 0 0 2px #fff; opacity: 0; transition: opacity .15s; }
.swatch-custom.is-active::before { opacity: 1; }
.swatch-custom[aria-expanded="true"]::after { border-color: var(--text); }
/* Farbrad: Farbton rundherum (conic), Sättigung zur Mitte hin weiß (radial); Helligkeit regelt der Schieber */
.wheel-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 20px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); }
.wheel {
  position: relative; flex: none; width: min(200px, 100%); aspect-ratio: 1; border-radius: 50%; cursor: crosshair; touch-action: none;
  background: radial-gradient(circle closest-side, #fff, rgb(255 255 255 / 0)), conic-gradient(from 90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
  box-shadow: inset 0 0 0 1px rgb(16 24 40 / .1);
}
.wheel-handle {
  position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; border: 3px solid #fff; cursor: grab;
  box-shadow: 0 0 0 1px rgb(16 24 40 / .35), 0 2px 6px rgb(16 24 40 / .35);
}
.wheel-handle:focus-visible { box-shadow: 0 0 0 1px rgb(16 24 40 / .35), var(--ring); }
.wheel-side { flex: 1 1 180px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.value-range {
  --range-to: #fff; -webkit-appearance: none; appearance: none; width: 100%; height: 14px; margin: 8px 0; border-radius: 99px; cursor: pointer;
  background: linear-gradient(to right, #000, var(--range-to)); box-shadow: inset 0 0 0 1px rgb(16 24 40 / .12);
}
.value-range::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 1px rgb(16 24 40 / .25), 0 2px 6px rgb(16 24 40 / .3); }
.value-range::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0; box-shadow: 0 0 0 1px rgb(16 24 40 / .25), 0 2px 6px rgb(16 24 40 / .3); }
.value-range:focus-visible { box-shadow: inset 0 0 0 1px rgb(16 24 40 / .12), var(--ring); }
.wheel-preview { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.wheel-swatch { width: 32px; height: 32px; border-radius: var(--radius-sm); box-shadow: inset 0 0 0 1px rgb(16 24 40 / .15); }
.wheel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.wheel-actions .btn { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0 10px; }
.hex-field { position: relative; display: block; width: 132px; margin-top: 10px; }
.hex-field .input { padding-left: 36px; text-transform: uppercase; }
.hex-field .input.is-invalid { border-color: var(--error); }
.hex-dot { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; margin-top: -8px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgb(16 24 40 / .15); pointer-events: none; }
/* Mini-Vorschau: immer hell wie das echte Blatt */
.design-sample {
  --ink: #1D2939; --ink-fill: #1D2939; --ink-on: #fff; --ink-soft: #E8EAEB;
  flex: none; width: 148px; display: flex; flex-direction: column; gap: 5px; padding: 12px;
  background: #fff; color: #344054; color-scheme: light; border-radius: var(--radius-md);
  box-shadow: 0 0 0 1px rgb(16 24 40 / .08), 0 4px 12px rgb(16 24 40 / .08); font-size: 8px; line-height: 1.2;
}
.ds-title { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 4px; letter-spacing: -.01em; }
.ds-head, .ds-row, .ds-total { white-space: nowrap; display: flex; justify-content: space-between; gap: 8px; padding: 4px 5px; }
.ds-head { background: var(--ink-fill); color: var(--ink-on); font-weight: 600; border-radius: 1px; }
.head-light .ds-head { background: var(--ink-soft); color: var(--ink); box-shadow: inset 0 -1.5px 0 var(--ink-fill); }
.ds-row { border-bottom: 1px solid #eaecf0; }
.ds-row i { display: block; height: 4px; border-radius: 2px; background: #e4e7ec; }
.ds-row i:first-child { width: 55%; }
.ds-row i:last-child { width: 22%; }
.ds-total { margin-left: 30%; background: var(--ink-soft); color: var(--ink); font-weight: 700; }

.logo-row { display: flex; gap: 16px; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.logo-preview { position: relative; display: grid; place-items: center; width: 112px; height: 72px; flex: none; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); background: #fff; color: #98a2b3; overflow: hidden; }
/* Logo vollständig zeigen: Bild füllt die Box, object-fit verkleinert es ohne Beschnitt */
.logo-preview img { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.logo-buttons { display: flex; flex-wrap: wrap; gap: 8px; }

.invoice-list, .customer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.invoice-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "open amount actions" "open badge actions"; gap: 2px 12px; align-items: center;
  padding: 8px 8px 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
}
.invoice-row.is-current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.invoice-open { grid-area: open; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; padding: 4px 0; border: 0; background: none; text-align: left; cursor: pointer; }
.invoice-number { font-size: 13px; color: var(--text-3); }
.invoice-customer { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invoice-date { font-size: 13px; color: var(--text-3); }
.invoice-amount { grid-area: amount; font-size: 14px; text-align: right; }
.invoice-row .badge { grid-area: badge; justify-self: end; }
.invoice-actions { grid-area: actions; display: flex; }
.badge { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge-entwurf { background: var(--warning-soft); color: var(--warning-text); }
.badge-erstellt { background: var(--success-soft); color: var(--success-text); gap: 4px; }
.badge .icon { width: 12px; height: 12px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; background: none; }
.customer-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 8px 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.customer-list li span { display: flex; flex-direction: column; min-width: 0; }
.customer-list small { color: var(--text-3); font-size: 13px; }
.customer-list .empty { color: var(--text-3); font-size: 14px; border-style: dashed; padding: 14px; }

/* ---------- Toast & Footer ---------- */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; translate: -50% 16px; opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px); padding: 10px 12px 10px 16px; border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500; color: #fff; background: #101828; box-shadow: var(--shadow-lg);
  transition: translate .25s var(--ease), opacity .25s;
}
[data-theme="dark"] .toast { background: #F4F4F5; color: #101828; }
.toast.show { translate: -50% 0; opacity: 1; }
.toast-action { flex: none; border: 0; background: none; color: #5FE9D0; font-weight: 600; min-height: 32px; padding: 0 6px; border-radius: var(--radius-sm); cursor: pointer; }
[data-theme="dark"] .toast-action { color: #107569; } /* 4,9 : 1 auf dem hellen Toast (WCAG AA) */
.sumbar { display: none; }
.footer { text-align: center; color: var(--text-3); font-size: 13px; padding: 24px; }

/* ==========================================================================
   Tablet & Mobil: App-Layout: nur der Inhalt scrollt (Leiste unten wackelt nicht)
   ========================================================================== */
@media (max-width: 1100px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { display: flex; flex-direction: column; height: 100dvh; }
  .scroller { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }

  .topbar { position: static; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title actions" "steps steps"; padding: 10px 16px 8px; gap: 8px 12px; }
  .topbar-title { grid-area: title; }
  .topbar-actions { grid-area: actions; }
  .stepper { grid-area: steps; justify-content: space-between; gap: 0; }
  .step { padding: 0 6px; gap: 6px; font-size: 13px; }
  .step-sep { width: 14px; height: 14px; }

  .view-switch {
    position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
    padding: 8px 16px; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  }
  .tab {
    display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; cursor: pointer;
    font-size: 14px; font-weight: 600; color: var(--text-3); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
    -webkit-tap-highlight-color: transparent;
  }
  .tab .icon { width: 18px; height: 18px; }
  .tab[aria-selected="true"] { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 0; gap: 0; }
  .layout[data-view="edit"] .preview-wrap { display: none; }
  .layout[data-view="preview"] .editor { display: none; }
  .preview-wrap { position: static; height: auto; min-height: 0; padding-bottom: 16px; }
  .paper-fit { height: auto; padding: 0; background: none; border: 0; border-radius: 0; overflow: hidden; }
  .zoom { display: none; }
  .actionbar { display: none; }
  .mobile-only { display: flex !important; }
  h2.mobile-only { display: block !important; }

  .sumbar {
    position: relative; z-index: 30; flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -8px 16px -4px rgb(16 24 40 / .06);
  }
  .sumbar-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-3); }
  .sumbar-total { display: block; font-family: var(--mono); font-size: 20px; font-weight: 500; white-space: nowrap; }
  .toast { bottom: calc(88px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  .onboarding, .locked-note { flex-wrap: wrap; }
  .onboarding .btn, .locked-note .btn { width: 100%; }
  .form-grid .col-half { grid-column: span 6; }
  .settings-card { padding: 14px; }
  .design-row { flex-direction: column-reverse; gap: 14px; }
  .design-sample { width: 100%; max-width: 240px; }
  .logo-row { align-items: flex-start; }
  .title-prefix { display: none; }
  .step-label { font-size: 12px; }
  .step:not(.is-active) .step-label { display: none; }
  .save-state { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: var(--radius-lg); }
  .item-body { padding: 4px 14px 16px; }
  .drawer { width: 100vw; border-left: 0; }
  .drawer-body { padding: 16px; }
  .invoice-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "open amount" "actions badge"; }
  .invoice-actions { justify-self: start; }
}

@media (max-width: 400px) {
  .topbar .brand-mark { display: none; }
  .topbar-actions { gap: 0; }
  /* Galaxy Fold (zugeklappt) & sehr schmale Handys */
  .locked-note { flex-wrap: wrap; padding: 14px; }
  .locked-note .btn { width: 100%; }
  .modal-body { padding: 20px 16px; }
  #payment-chips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #payment-chips [data-days="custom"] { grid-column: 1 / -1; }
  .onboarding { padding: 14px; gap: 12px; }
  .onboarding-icon { display: none; }
  .bank-summary { flex-direction: column; align-items: flex-start; }
  .drawer-head { padding: 12px 12px 12px 16px; }
  .drawer-body { padding: 16px 12px calc(20px + env(safe-area-inset-bottom)); gap: 12px; }
  .settings-card { padding: 14px 12px; gap: 14px; }
  .settings-card-head { flex-wrap: wrap; gap: 6px 12px; }
  .logo-row { flex-direction: column; align-items: flex-start; gap: 10px; }
  .logo-preview { width: 100%; height: 64px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid > .field { grid-column: 1 / -1 !important; }
  .switch { gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > * { grid-column: 1 / -1; }
  .item-body { padding: 4px 12px 14px; }
}

@media (max-width: 360px) {
  .topbar { padding: 8px 12px; }
  h1 { font-size: 15px; letter-spacing: -.02em; }
  .topbar-actions .icon-btn { width: 36px; }
  .view-switch { padding: 8px 12px; }
  .layout { padding: 12px 12px 0; }
  .card { padding: 14px 12px; }
  .chip { padding: 0 10px; font-size: 13px; }
  .sumbar { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  .sumbar-total { font-size: 17px; }
  .sumbar .btn { padding: 0 12px; }
  .sumbar .btn .icon { display: none; }
  .input-group > select.input { min-width: 72px; }
}

/* ---------- Druck / PDF ---------- */
@page { size: A4; margin: 15mm 20mm 12mm 25mm; }
@media print {
  .inv-qr-missing { display: none !important; }
  html, body { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; }
  .scroller { overflow: visible !important; height: auto !important; }
  .no-print, .sumbar, .drawer, .toast { display: none !important; }
  .layout { display: block !important; padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .layout .preview-wrap { display: block !important; position: static !important; height: auto !important; padding: 0 !important; }
  .paper-fit { display: block !important; height: auto !important; padding: 0 !important; background: none !important; border: 0 !important; overflow: visible !important; }
  /* Ränder kommen von @page: so hat auch Seite 2 oben einen Rand; einseitig sitzt die Fußzeile unten */
  .paper { zoom: 1 !important; box-shadow: none !important; border-radius: 0 !important; width: auto; height: auto; min-height: calc(297mm - 27mm - 1mm); padding: 0 !important; margin: 0 !important; }
  .inv-items thead { display: table-header-group; }
  .inv-items tr, .inv-sum, .inv-pay, .inv-note, .inv-foot, .inv-qr { break-inside: avoid; }
  .inv-sum, .inv-pay { break-before: avoid-page; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Wer reduzierte Bewegung eingestellt hat, bekommt keine Animationen */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Ergänzungen: Warnungen, Preisart, Abschläge, Leistungsdatum ---------- */
.field-warning { display: flex; gap: 6px; align-items: flex-start; margin: 0; font-size: 13px; font-weight: 500; line-height: 1.4; color: var(--warning-text); }
.field-warning::before {
  content: "!"; flex: none; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 1px; border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #fff; background: var(--warning-text);
}
.input.has-warning { border-color: color-mix(in srgb, var(--warning-text) 55%, transparent); }
.price-mode { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.price-basis { font-weight: 400; color: var(--text-3); }
#service-chips, #price-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.prepayments { display: flex; flex-direction: column; gap: 12px; }
.prepayments:empty { display: none; }
.prepayment { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.prepayment .field { min-width: 0; }
.prepayment-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.prepayment-actions .input { flex: 1 1 220px; width: auto; }
.locked-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.inv-tax-notes { display: flex; flex-direction: column; gap: 1.5mm; }
.badge-storno { background: var(--error-soft); color: var(--error-text); }
@media (max-width: 720px) {
  .prepayment { grid-template-columns: 1fr 1fr; }
  .prepayment > .icon-btn { justify-self: end; }
}

/* ---------- Info-Knopf (Standard-Icon) und Sprechblase ---------- */
.settings-card-head { justify-content: flex-start; }
.settings-card-head .settings-status, .settings-card-head #design-reset { margin-left: auto; }
.info-btn {
  position: relative; flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; padding: 0;
  margin: 0 0 0 2px; border: 0; border-radius: 50%; background: none; color: var(--text-3); cursor: help; vertical-align: -4px;
}
.info-btn .icon { width: 18px; height: 18px; stroke-width: 2; }
.info-btn:hover, .info-btn[aria-describedby] { color: var(--primary); }
.info-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.info-btn::after { content: ""; position: absolute; inset: -12px; } /* Trefferfläche 44 × 44 px */
.tooltip {
  position: fixed; inset: auto; margin: 0; z-index: 1000; max-width: min(260px, calc(100vw - 16px)); padding: 8px 11px;
  border: 0; border-radius: 8px; background: #1D2939; color: #fff; box-shadow: 0 6px 20px rgb(16 24 40 / 0.2);
  font: 500 13px/1.45 var(--font); text-align: left; white-space: normal; overflow: visible; pointer-events: none;
}
[data-theme="dark"] .tooltip { background: #F4F4F5; color: #18181B; }
.tooltip::after {
  content: ""; position: absolute; left: calc(var(--arrow-x, 50%) - 6px); width: 12px; height: 12px;
  background: inherit; transform: rotate(45deg); border-radius: 2px;
}
.tooltip[data-side="top"]::after { bottom: -5px; }
.tooltip[data-side="bottom"]::after { top: -5px; }
@media (prefers-reduced-motion: no-preference) {
  .tooltip { animation: tip-in 120ms ease-out; }
  @keyframes tip-in { from { opacity: 0; transform: translateY(2px); } }
}
.panel-title .info-btn, legend .info-btn, .field-label .info-btn { margin-left: 4px; }
.hint-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0; }
.hint-row .link-btn { min-height: 24px; font-size: 13px; }
.saved-customer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.saved-customer .field-hint { margin: 0; flex: 1 1 220px; }

/* ---------- Kunden in den Einstellungen bearbeiten ---------- */
.customer-list li.is-editing { flex-direction: column; align-items: stretch; padding: 14px; }
.customer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.customer-row > span { display: flex; flex-direction: column; min-width: 0; }
.customer-row .row-actions { display: flex; gap: 4px; }
.customer-edit { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ---------- Aktionsleiste immer an derselben Stelle (unten im Fenster) ---------- */
@media (min-width: 1101px) {
  .editor { min-height: calc(100dvh - var(--header-h, 65px) - 24px); }
  #invoice-form { flex: 1; }
}
