:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e7e9f0;
  --line-soft: #f1f3f8;

  --sidebar-1: #0b1220;
  --sidebar-2: #131c31;
  --sidebar-ink: #aeb8cc;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0fe;
  --danger: #e11d48;
  --success: #059669;

  --radius: 14px;
  --radius-s: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 10px 24px -8px rgba(16,24,40,.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }

.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2));
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-mark { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, var(--primary), #7c73ff); display: flex; align-items: center; justify-content: center; color: #fff; flex: none; box-shadow: 0 4px 12px rgba(79,70,229,.4); }
.brand-mark .icon { width: 22px; height: 22px; }
.brand-logo { max-width: 44px; max-height: 44px; border-radius: 9px; background: #fff; padding: 3px; flex: none; }
.brand-text { min-width: 0; }
.brand-name { color: #fff; font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: #7c8aa6; font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; margin-top: 1px; }

.nav { display: flex; flex-direction: column; padding: 14px 12px; gap: 3px;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 8px; }
.nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.28); }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  color: var(--sidebar-ink); text-decoration: none;
  padding: 10px 12px; border-radius: var(--radius-s);
  font-size: 14px; font-weight: 500; transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px -6px rgba(79,70,229,.7); }
.nav a.active .icon { stroke: #fff; }
/* Untergeordnete Einträge (Kunden/Lieferanten unter Geschäftspartner) */
.nav a.nav-sub { margin-left: 19px; padding-left: 16px; gap: 10px; font-size: 13px;
  color: #aab6cd; border-left: 1.5px solid rgba(255,255,255,.12);
  border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.nav a.nav-sub .icon { width: 16px; height: 16px; }
.nav a.nav-sub:hover { color: #fff; }
.nav a.nav-sub.active { color: #fff; border-left-color: var(--primary); }
.nav-sep { height: 1px; background: rgba(255,255,255,.07); margin: 10px 8px; }
/* Aufklappbare Menügruppen */
.nav-group { display: flex; flex-direction: column; gap: 3px; }
.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row > a { flex: 1 1 auto; min-width: 0; }
.nav-toggle { flex: none; width: 30px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer; color: var(--sidebar-ink); border-radius: var(--radius-s); padding: 0; }
.nav-toggle:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-toggle .chev { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; transition: transform .15s; }
.nav-group.collapsed .nav-toggle .chev { transform: rotate(-90deg); }
.nav-children { display: flex; flex-direction: column; gap: 3px; }
.nav-group.collapsed .nav-children { display: none; }
/* Gruppen-Kopf ohne eigene Zielseite (z. B. „Verkauf") – sieht aus wie ein
   normaler Menüpunkt, klappt aber beim Klick nur das Untermenü auf/zu. */
.nav-toggle.nav-head { flex: 1 1 auto; width: auto; height: auto; justify-content: flex-start;
  gap: 12px; padding: 10px 12px; font: inherit; font-size: 14px; font-weight: 500;
  color: var(--sidebar-ink); text-align: left; }
.nav-toggle.nav-head .nav-head-text { flex: 1 1 auto; min-width: 0; }
.nav-toggle.nav-head .chev { flex: none; }

/* Firmen-Umschalter */
.firma-switch { margin: 4px 12px 6px; }
.firma-switch summary { list-style: none; cursor: pointer; display: flex; flex-direction: column; gap: 1px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.09); border-radius: 10px; padding: 8px 12px; position: relative; }
.firma-switch summary::-webkit-details-marker { display: none; }
.fs-cap { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #7c8aa6; }
.fs-current { color: #fff; font-weight: 600; font-size: 13.5px; padding-right: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fs-caret { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: #9fb0cc; font-size: 11px; }
.firma-switch[open] .fs-caret { transform: translateY(-50%) rotate(180deg); }
.fs-menu { display: flex; flex-direction: column; margin-top: 4px; background: rgba(0,0,0,.18); border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 4px; }
.fs-menu a { color: var(--sidebar-ink); text-decoration: none; padding: 8px 10px; border-radius: 7px; font-size: 13.5px; }
.fs-menu a:hover { background: rgba(255,255,255,.08); color: #fff; }
.fs-menu a.active { background: var(--primary); color: #fff; }
.fs-menu .fs-manage { margin-top: 3px; border-top: 1px solid rgba(255,255,255,.08); color: #9fb0cc; font-size: 12.5px; }

/* ---------- Content ---------- */
.content { flex: 1; padding: 28px 26px; max-width: 1520px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 25px; margin: 0; color: var(--ink); letter-spacing: -0.01em; font-weight: 700; }
h2 { font-size: 15.5px; margin: 0 0 16px; color: var(--ink); font-weight: 650; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { display: flex; align-items: center; gap: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .08s, box-shadow .12s; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-ic { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.stat-ic .icon { width: 22px; height: 22px; }
.stat-ic-indigo { background: #eef0fe; color: #4f46e5; }
.stat-ic-blue   { background: #e8f1ff; color: #2563eb; }
.stat-ic-green  { background: #e7f7f0; color: #059669; }
.stat-ic-amber  { background: #fef4e6; color: #d97706; }
.stat-ic-violet { background: #f3ecfe; color: #7c3aed; }
.stat-num { font-size: 27px; font-weight: 750; color: var(--ink); line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .045em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbff; }
.table .right, .right { text-align: right; }
/* Sortierbare Tabellen: anklickbarer Spaltenkopf + Richtungspfeil */
th.th-sort { cursor: pointer; user-select: none; -webkit-user-select: none; white-space: nowrap; }
th.th-sort::after { content: "↕"; margin-left: 5px; font-size: 10px; opacity: .35; }
th.th-sort[aria-sort="ascending"]::after { content: "▲"; opacity: .8; }
th.th-sort[aria-sort="descending"]::after { content: "▼"; opacity: .8; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; background: #fff; color: var(--ink-soft); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 9px 15px; font-size: 14px; font-weight: 550; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, box-shadow .12s, transform .04s; white-space: nowrap; }
.btn:hover { background: #f8f9fc; border-color: #d8dce6; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 6px 14px -6px rgba(79,70,229,.6); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f6cdd6; background: #fff; }
.btn-danger:hover { background: #fdeef1; border-color: #f1b6c3; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #eceef4; }
.btn-small { padding: 6px 11px; font-size: 13px; }

/* ---------- Forms ---------- */
.form .card { max-width: 940px; }
.form-subhead { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .045em; margin: 16px 0 6px; }
.form-row { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.form-row > label { flex: 1 1 0; min-width: 150px; margin-bottom: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 600; }
label.grow { flex: 3 1 0; }
label.shrink { flex: 0 0 120px; min-width: 90px; }
input[type=text], input[type=email], input[type=number], input[type=search],
input[type=date], input[type=file], select, textarea {
  width: 100%; margin-top: 6px; padding: 9px 12px; font-size: 14px; color: var(--ink);
  border: 1px solid #cbd2df; border-radius: var(--radius-s); background: #fff; font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: #9aa3b2; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3.5px rgba(79,70,229,.14); }
textarea { resize: vertical; }
small.muted { font-weight: 500; }
small.muted code { background: #eef0f5; padding: 1px 6px; border-radius: 5px; font-size: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; }
.toolbar input[type=search] { max-width: 380px; margin-top: 0; }
.toolbar select { width: auto; margin-top: 0; }
/* Live-Tabellensuche (Frontend-Filter): Toolbar direkt über der Tabelle */
.toolbar-inline { margin-bottom: 14px; }
.table-search-count { font-size: 13px; white-space: nowrap; }
/* Kosten-Auswertung: Häkchen „zählt als Kosten" + ausgeschlossene Konten */
.kr-check { width: 1%; text-align: center; white-space: nowrap; }
.kr-check input[type=checkbox] { width: auto; margin: 0; cursor: pointer; transform: scale(1.15); }
tr.kr-aus { opacity: .5; }
tr.kr-aus td:nth-child(2) { text-decoration: line-through; }
/* Konto-Zeile aufklappen -> Einzelposten (Detailzeile darunter) */
tr.expandable { cursor: pointer; }
/* Bank-Umsatz-Zeile: anklickbar → Buchungsdetail (neuer Tab) */
tr[data-detail-url] { cursor: pointer; }
/* Kleiner Kopier-Button (Verwendungszweck, VIN …) */
.copy-btn { background: none; border: none; cursor: pointer; padding: 0 3px; margin: 0 1px;
  font-size: 12px; line-height: 1; color: var(--ink-soft, #64748b); opacity: .6;
  vertical-align: baseline; -webkit-user-select: none; user-select: none; }
.copy-btn:hover { opacity: 1; }
.copy-btn.copied { color: #059669; opacity: 1; }
tr.expandable td:nth-child(2) { position: relative; padding-left: 26px; }
tr.expandable td:nth-child(2)::before {
  content: "\25B8"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 11px;
}
tr.expandable.expanded td:nth-child(2)::before { content: "\25BE"; }
tr.detail-row { display: none; }
tr.detail-row > td { padding: 0; background: #f7f9fc; border-bottom: 1px solid var(--line); }
.detail-table { width: 100%; margin: 0; }
.detail-table td { border-bottom: 1px solid var(--line-soft); padding: 7px 12px; font-size: 13px; }
.detail-table tr:last-child td { border-bottom: none; }
.detail-table tbody tr:hover { background: #eef2fb; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.row-actions form { margin: 0; }
/* Aktionsspalte in Tabellen: normale Zelle (kein Flex!), schmal, rechtsbündig */
.actions-cell { width: 1%; white-space: nowrap; text-align: right; }
.actions-cell form { display: inline-block; margin: 0; }
/* Beleg-/Vertragsaktionen am Fahrzeug */
.beleg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.btn-soon { opacity: .45; cursor: default; pointer-events: none; }
/* breite Tabellen auf schmalen Bildschirmen horizontal scrollbar (Balken sichtbar) */
.table-wrap { overflow-x: auto; }
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: #cbd2de; border-radius: 6px; }
.table-wrap::-webkit-scrollbar-track { background: #f1f3f8; border-radius: 6px; }
/* kompaktere Fahrzeugtabelle (viele Spalten) */
.table-vehicles th, .table-vehicles td { padding-left: 8px; padding-right: 8px; }
.table-vehicles th:first-child, .table-vehicles td:first-child { padding-left: 12px; }
.btn-icon { padding: 6px 9px; font-size: 15px; }

/* ---------- Flash ---------- */
.flashes:empty { display: none; }
.flash { padding: 12px 16px; border-radius: var(--radius-s); margin-bottom: 12px; border: 1px solid; font-weight: 500; font-size: 14px; }
.flash-success { background: #ecfdf5; border-color: #b3ecd5; color: #065f46; }
.flash-error { background: #fef2f3; border-color: #f6cdd4; color: #9f1239; }
.flash-info { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5; }
.badge-verfuegbar { background: #ecfdf5; color: #047857; }
.badge-reserviert { background: #fff7ed; color: #c2410c; }
.badge-bestand   { background: #ecfdf5; color: #047857; }
.badge-bestellt  { background: #fefce8; color: #a16207; }
.badge-beteiligung { background: #f5f3ff; color: #6d28d9; }
.badge-abschreibung { background: #f0f9ff; color: #0369a1; }
.badge-rueckerstattet { background: #f1f5f9; color: #475569; }
.badge-angeboten { background: #fff7ed; color: #c2410c; }
.badge-verkauft  { background: #eef2ff; color: #4338ca; }
.badge-kundenfahrzeug { background: #ecfeff; color: #0e7490; }
.badge-entwurf   { background: #f1f5f9; color: #475569; }
.badge-offen     { background: #fef9c3; color: #854d0e; }
.badge-bezahlt   { background: #ecfdf5; color: #047857; }
.badge-angewiesen { background: #dbeafe; color: #1e40af; }
.badge-ausgebucht { background: #f1f5f9; color: #475569; }
.badge-gutschrift { background: #f5f3ff; color: #6d28d9; }
.badge-storniert { background: #fef2f2; color: #b91c1c; }
.badge-gesendet  { background: #ecfdf5; color: #047857; }
.badge-fehler    { background: #fef2f2; color: #b91c1c; }

/* Inline-Statuswechsel direkt in der Rechnungsliste (sieht aus wie ein Badge) */
.status-inline { margin: 0; }
.status-select {
  width: auto; margin: 0; padding: 4px 24px 4px 10px; font-size: 12px; font-weight: 600;
  line-height: 1.5; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
}
.status-select.status-offen     { background: #fef9c3; color: #854d0e; }
.status-select.status-bezahlt   { background: #ecfdf5; color: #047857; }
.status-select.status-storniert { background: #fef2f2; color: #b91c1c; }
.status-select.status-angewiesen { background: #dbeafe; color: #1e40af; }
.status-select.status-ausgebucht { background: #f1f5f9; color: #475569; }
.badge-kunde     { background: #eff6ff; color: #1d4ed8; }
.badge-lieferant { background: #f0fdfa; color: #0f766e; }
.badge-fahrzeug       { background: #eef2ff; color: #4338ca; }
.badge-dienstleistung { background: #fff7ed; color: #c2410c; }
.partner-summary { margin: 0 0 14px; }
.rollen-zelle a.badge { margin-right: 4px; }
a.badge { text-decoration: none; cursor: pointer; transition: filter .12s; }
a.badge:hover { filter: brightness(.94); }
.partner-name { font-weight: 650; color: var(--ink); text-decoration: none; }
.partner-name:hover { color: var(--primary); text-decoration: underline; }

/* Beteiligung (Fahrzeug) */
.check-inline { display: flex; align-items: center; gap: 9px; font-weight: 550; cursor: pointer; }
.check-inline input { width: auto; margin: 0; flex: none; }
.beteiligung-fields { margin-top: 14px; }
.table-sum td { font-weight: 700; border-top: 2px solid var(--line); padding-top: 12px; }
.stat-num-money { font-size: 20px; white-space: nowrap; }

/* Diskret-Modus: sensible Betraege „schwaerzen" (Auge-Knopf im Dashboard; Zustand pro
   Browser in localStorage, schon im <head> gesetzt -> kein Aufblitzen). .geld markiert
   jeden Betrag -> im Modus ein dezenter Balken; faehrt die Maus ueber die Kachel (oder
   den Betrag), erscheint der Wert sanft und verschwindet beim Weggehen wieder. */
html.diskret .geld {
  color: transparent;
  background-color: #e4e7ee;
  border-radius: 6px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  user-select: none;
  transition: color .18s ease, background-color .18s ease;
}
html.diskret .stat:hover .geld,
html.diskret .geld:hover { color: inherit; background-color: transparent; }
[data-diskret-toggle] { cursor: pointer; }
.bet-quote { font-size: 12px; margin-left: 2px; }
.tax-tag { display: inline-block; margin-top: 3px; font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 5px; background: #f1f5f9; color: #475569; letter-spacing: .01em; white-space: nowrap; }

.muted { color: var(--muted); }
.logo-preview img { max-height: 72px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }

/* ---------- Detail-Raster ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 26px; }
.detail-grid > div { display: flex; flex-direction: column; gap: 2px; padding-bottom: 9px; border-bottom: 1px solid var(--line-soft); }
.dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .035em; font-weight: 600; }
.dd { font-size: 14.5px; color: var(--ink); }

/* ---------- Thumbnails / Galerie ---------- */
.thumb-cell { width: 66px; }
.thumb { width: 58px; height: 44px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb-empty { display: flex; align-items: center; justify-content: center; background: #f1f3f8; font-size: 22px; }
tr.clickable, tr[data-href] { cursor: pointer; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.gallery-item { position: relative; }
.gallery-item img { width: 100%; height: 104px; object-fit: cover; border-radius: var(--radius-s); border: 1px solid var(--line); display: block; }
.gallery-item form { position: absolute; top: 5px; right: 5px; margin: 0; }
.gallery-item .gallery-link { display: block; cursor: zoom-in; }
.gallery-hint { font-size: 12px; margin: 0 0 8px; }
.img-del { width: 24px; height: 24px; border-radius: 50%; border: none; background: rgba(15,23,42,.62); color: #fff; cursor: pointer; font-size: 16px; line-height: 1; }
.img-del:hover { background: var(--danger); }
/* Sortier-Buttons (Touch-tauglich) + Drag&Drop-Zustände */
.img-tools { position: absolute; left: 5px; bottom: 5px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.gallery-item:hover .img-tools, .gallery-item:focus-within .img-tools { opacity: 1; }
.img-move { width: 26px; height: 26px; border-radius: 6px; border: none; background: rgba(15,23,42,.62); color: #fff; cursor: pointer; font-size: 13px; line-height: 1; }
.img-move:hover { background: var(--primary); }
.gallery-item { cursor: grab; }
.gallery-item.dragging { opacity: .4; cursor: grabbing; }
.gallery-item.drop-target { outline: 2px dashed var(--primary); outline-offset: 2px; border-radius: var(--radius-s); }
@media (hover: none) { .img-tools { opacity: 1; } }   /* auf Touch immer sichtbar */
.doc-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.doc-actions form { margin: 0; }
/* Lightbox (Bild-Vorschau zum Durchblättern) */
.lightbox { display: none; position: fixed; inset: 0; z-index: 1100; background: rgba(8,12,22,.92); align-items: center; justify-content: center; touch-action: pan-y; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 86vh; object-fit: contain; border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.5); user-select: none; -webkit-user-select: none; }
.lb-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 52px; height: 52px; border-radius: 50%; border: none; background: rgba(255,255,255,.14); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.lb-btn:hover { background: rgba(255,255,255,.28); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-close { position: absolute; top: 14px; right: 18px; width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,.14); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; }
.lb-close:hover { background: rgba(255,255,255,.28); }
.lb-counter { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 14px; font-weight: 600; letter-spacing: .03em; background: rgba(0,0,0,.35); padding: 4px 12px; border-radius: 20px; }
.lb-caption { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); max-width: 90vw; color: #e7e9f0; font-size: 13px; text-align: center; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.lightbox.single .lb-prev, .lightbox.single .lb-next, .lightbox.single .lb-counter { display: none; }
@media (max-width: 640px) { .lb-btn { width: 42px; height: 42px; font-size: 22px; } .lb-prev { left: 6px; } .lb-next { right: 6px; } }
.upload-form { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; padding-top: 12px; border-top: 1px dashed var(--line); }
.dropzone { flex: 1; min-width: 220px; display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0; padding: 16px; border: 2px dashed #c7cdd9; border-radius: var(--radius-s); background: #fafbff; color: var(--muted); cursor: pointer; font-size: 13.5px; font-weight: 500; text-align: center; transition: border-color .12s, background .12s; }
.dropzone:hover { border-color: var(--primary); background: #f3f4fe; }
.dropzone input[type=file] { display: none; }
.dropzone.dragover { border-color: var(--primary); background: #e6e9fe; color: var(--primary); }
.dz-text { pointer-events: none; }
.upload-form .btn { align-self: center; }

label.check { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-weight: 550; }
label.check input { width: auto; margin: 0; }

/* ---------- Rechnungs-Positionen ---------- */
.pos-card { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 14px 16px; margin-bottom: 12px; background: #fcfcfe; position: relative; }
.pos-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pos-badge { background: var(--primary); color: #fff; width: 25px; height: 25px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.pos-betrag { margin-left: auto; font-weight: 700; font-size: 16px; color: var(--ink); }
.pos-card-body { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.pos-card-body label { margin-bottom: 0; }
.pos-card-body label.full { flex: 1 1 100%; }
.pos-card-body label.w-s { flex: 0 0 92px; }
.pos-card-body label.w-m { flex: 0 0 155px; }
.pos-card-actions { margin-left: auto; }
.pos-card-del { position: absolute; top: 13px; right: 16px; margin: 0; }
.pos-card-del button { padding: 4px 9px; }

.add-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 980px) { .add-grid { grid-template-columns: 1fr; } }
.add-box { border: 1.5px dashed #d4d9e4; border-radius: var(--radius-s); padding: 16px; display: flex; flex-direction: column; gap: 9px; background: #fcfcfe; }
.add-box h3 { margin: 0 0 4px; font-size: 14px; color: var(--ink); }
.add-box select, .add-box input { width: 100%; margin: 0; }
.add-box .add-row { display: flex; gap: 8px; }
.add-box label.inline { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 550; }
.add-box label.inline input { width: 84px; }
.add-box button { align-self: flex-start; margin-top: 2px; }

.sumwrap { display: flex; justify-content: flex-end; margin-top: 16px; }
.sumtable { border-collapse: collapse; min-width: 300px; }
.sumtable td { padding: 6px 10px; }
.sumtable td.right { font-variant-numeric: tabular-nums; }
.sumtable .sum-total td { border-top: 2px solid var(--primary); font-weight: 750; font-size: 18px; color: var(--ink); padding-top: 9px; }

/* ---------- VIES USt-IdNr.-Prüfung ---------- */
.vat-check { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 4px 0 2px; }
.vat-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 650; border: 1px solid; }
.vat-badge.vat-gueltig { background: #ecfdf5; border-color: #b3ecd5; color: #065f46; }
.vat-badge.vat-ungueltig { background: #fef2f3; border-color: #f6cdd4; color: #9f1239; }
.vat-badge.vat-fehler { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.vat-date { font-size: 12px; color: var(--muted); }
.vat-info { margin: 2px 0 0; font-size: 13px; color: var(--ink-soft); background: var(--line-soft); border-radius: var(--radius-s); padding: 8px 12px; }
.head-actions { display: flex; align-items: center; gap: 10px; }
.head-actions form { margin: 0; }
.vat-progress { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 16px; }
.vat-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.vat-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #7c73ff); transition: width .4s ease; }
.vat-progress-text { margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
td .vat-badge { font-size: 12px; padding: 2px 8px; }
.vat-historie { margin: 6px 0 2px; }
.vat-historie > summary { cursor: pointer; font-weight: 650; color: var(--ink); padding: 8px 0; font-size: 13.5px; }
.vat-hist-table { margin-top: 8px; font-size: 13px; }
.vat-hist-table code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--line-soft); padding: 2px 6px; border-radius: 6px; }
.search-select { display: block; position: relative; }
.search-select .ss-text { width: 100%; }
.qa-btn { margin-top: 6px; }

/* Eigenes Dropdown der Such-Auswahl (Name + Infozeile Adresse/USt-IdNr.) */
.ss-dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  margin: 0; padding: 4px; max-height: 300px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-s);
  box-shadow: 0 14px 30px -12px rgba(15,23,42,.30); }
.ss-opt { padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.ss-opt:hover, .ss-opt.active { background: #eef2ff; }
.ss-opt-main { font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-opt:hover .ss-opt-main, .ss-opt.active .ss-opt-main { color: var(--primary-dark); }
.ss-opt-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.ss-empty { padding: 8px 10px; color: var(--muted); font-size: 13.5px; }

/* Konto-Vorschläge (Schnellwahl-Chips im Eingangsrechnungs-Formular) */
.konto-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.konto-chips-label { font-size: 12px; color: var(--muted); }
.konto-chip { font-size: 12px; }
/* Inline-Konto-Suchfeld in der Bank-Tabelle: kompakt, Dropdown trotzdem breit genug */
.konto-inline { min-width: 140px; }
.konto-inline .ss-text { padding: 6px 8px; font-size: 13px; }
.konto-inline .ss-dropdown { min-width: 300px; }
.konto-inline.kat-saved .ss-text { border-color: var(--success); box-shadow: 0 0 0 3px rgba(5,150,105,.16); }
.konto-inline.kat-error .ss-text { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.16); }

/* Bank-Buchung (BOB-Art A/L/K) – Zelle in der Umsatztabelle */
.buchung-cell { min-width: 230px; }
.buchung-cell .art-select { width: 100%; padding: 6px 8px; font-size: 13px; margin-bottom: 4px; }
.buchung-cell .buchung-ziel { display: block; }
.buchung-cell .buchung-ziel .ss-text { padding: 6px 8px; font-size: 13px; }
.buchung-cell .buchung-ziel .ss-dropdown { min-width: 300px; }
.buchung-cell .mwst-select { width: 100%; padding: 6px 8px; font-size: 13px; margin-top: 4px; }
.buchung-status { font-size: 13px; font-weight: 600; margin-left: 2px; }
.buchung-status.ok { color: var(--success, #059669); }
.buchung-status.err { color: var(--danger, #dc2626); }
.match-cell { min-width: 200px; }

/* Such-Combobox (eigenes Dropdown mit Substring-Suche) */
.combo { display: block; position: relative; margin-top: 6px; }
.combo .combo-input { margin-top: 0; padding-right: 34px; }
.combo-clear { position: absolute; right: 4px; top: 0; bottom: 0; display: flex; align-items: center;
  border: none; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 8px; }
.combo-clear:hover { color: var(--danger); }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
  margin: 0; padding: 4px; list-style: none; max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-s);
  box-shadow: 0 14px 30px -12px rgba(15,23,42,.30); }
.combo-opt { padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-opt:hover, .combo-opt.active { background: #eef2ff; color: var(--primary-dark); }

/* ---------- Schnell-Anlegen-Modal ---------- */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1000; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg); border: 1px solid var(--line); width: 100%; max-width: 460px; padding: 22px 24px; }
.modal-box h3 { margin: 0 0 16px; font-size: 17px; color: var(--ink); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-error { color: var(--danger); font-size: 13px; font-weight: 600; margin: 10px 0 0; }
.modal-hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.vies-fill { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 2px; }
.vies-status { font-size: 13px; font-weight: 600; }
.vies-status.ok { color: var(--success); }
.vies-status.err { color: var(--danger); }

/* ---------- Zahlungsabgleich ---------- */
.nowrap { white-space: nowrap; }
.abgleich-form { margin: 0; min-width: 300px; }
.abgleich-row { display: flex; gap: 8px; align-items: center; }
.abgleich-row select { margin-top: 0; flex: 1 1 auto; min-width: 130px; }
.abgleich-row .input-betrag { margin-top: 0; width: 104px; flex: 0 0 104px; text-align: right;
  padding: 9px 12px; font-size: 14px; color: var(--ink); border: 1px solid #cbd2df;
  border-radius: var(--radius-s); background: #fff; font-family: inherit; }
.abgleich-row .input-betrag:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3.5px rgba(79,70,229,.14); }
.abgleich-row .btn { flex: none; }
.abgleich-hint { font-size: 11.5px; margin-top: 5px; }

/* Kategorie-Auswahl direkt in den Umsatz-Tabellen (inline per AJAX gespeichert) */
.kat-select { margin-top: 0; width: 100%; min-width: 130px; padding: 6px 8px; font-size: 13px; transition: border-color .12s, box-shadow .12s; }
.kat-select.kat-saved { border-color: var(--success); box-shadow: 0 0 0 3px rgba(5,150,105,.16); }
.kat-select.kat-error { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.16); }

/* Mehrfach-Auswahl „Unterlagen-Paket" (Fahrzeugseite: Belege/Dokumente/Bilder mitschicken) */
td.sel, th.sel { width: 1%; text-align: center; padding-left: 6px; padding-right: 4px; }
.js-sel { width: 16px; height: 16px; vertical-align: middle; cursor: pointer; accent-color: var(--primary); }
.img-sel { position: absolute; top: 5px; left: 5px; z-index: 3; background: rgba(255,255,255,.92); border-radius: 5px; padding: 1px 3px; line-height: 1; box-shadow: 0 1px 3px rgba(0,0,0,.15); cursor: pointer; }
.doc-list { margin: 4px 0 0; padding-left: 20px; }
.doc-list li { margin: 3px 0; }

/* Schwebender Schnell-Knopf „Aufgabe erstellen" (auf jeder Seite) */
.fab-aufgabe {
  position: fixed; right: 22px; bottom: 22px; z-index: 60;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 17px; border-radius: 999px;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 600;
  text-decoration: none; box-shadow: 0 6px 20px rgba(79,70,229,.35);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.fab-aufgabe:hover { filter: brightness(1.07); transform: translateY(-1px); box-shadow: 0 9px 26px rgba(79,70,229,.45); }
.fab-aufgabe .icon { width: 18px; height: 18px; color: #fff; }
@media (max-width: 640px) {
  .fab-aufgabe { right: 14px; bottom: 14px; padding: 13px; }
  .fab-aufgabe span { display: none; }
}
@media print { .fab-aufgabe { display: none; } }

/* „Auswahl senden / als PDF" als schwebender Knopf – auf Desktop UND Handy.
   Sitzt rechts unten ÜBER dem Aufgabe-Knopf (gestapelt), damit nichts kollidiert. */
.fab-unterlagen {
  position: fixed; right: 22px; bottom: 74px; z-index: 30; margin: 0;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--sidebar-1); color: #fff; border: none;
  border-radius: 999px; padding: 11px 17px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); cursor: pointer;
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.fab-unterlagen:hover { filter: brightness(1.12); transform: translateY(-1px); box-shadow: 0 9px 26px rgba(0,0,0,.38); }
@media (max-width: 640px) {
  .fab-unterlagen { right: 14px; bottom: 70px; padding: 12px 15px; font-size: 13.5px; }
}
@media print { .fab-unterlagen { display: none; } }

/* ======================================================================
   Mobile / iPhone – Seitenleiste wird zur ausklappbaren Schublade
   ====================================================================== */
.mobilebar { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 820px) {
  .app { display: block; }

  /* Top-Leiste mit Hamburger (nur mobil) */
  .mobilebar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 40;
    background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2));
    color: #fff;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    box-shadow: 0 2px 10px rgba(0,0,0,.18);
  }
  .mobilebar .burger {
    width: 42px; height: 42px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
    border-radius: 10px; color: #fff; cursor: pointer; padding: 0;
  }
  .mobilebar .burger svg, .mobilebar .mb-back svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .mobilebar .mb-back {
    width: 42px; height: 42px; flex: none;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
    border-radius: 10px; color: #fff; cursor: pointer; padding: 0;
  }
  .mobilebar .mb-title { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Sidebar als Off-Canvas-Schublade */
  .sidebar {
    position: fixed; top: 0; left: 0;
    height: 100vh; height: 100dvh;
    width: 82vw; max-width: 320px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 4px 0 28px rgba(0,0,0,.4);
  }
  .app.nav-open .sidebar { transform: translateX(0); }

  /* Abdunkelnder Hintergrund hinter der offenen Schublade */
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(10,12,18,.5);
    opacity: 0; pointer-events: none; transition: opacity .25s;
  }
  .app.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* Inhalt volle Breite, schmalerer Rand, größere Touch-Ziele */
  .content { padding: 16px 14px; max-width: none; min-width: 0; }
  .nav a, .nav-toggle.nav-head { padding: 12px 12px; font-size: 15px; }
  .nav a.nav-sub { padding-top: 11px; padding-bottom: 11px; }

  /* Kein horizontales Wischen/Wegrutschen: Seite bleibt fest im Fenster. */
  html, body { overflow-x: hidden; max-width: 100%; }
  .app { overflow-x: hidden; max-width: 100%; }
  .content, .card, .panel { max-width: 100%; min-width: 0; }
  /* nur überlange Wörter/URLs umbrechen – normale Wörter NICHT zerhacken */
  .content { overflow-wrap: break-word; }
  img { max-width: 100%; height: auto; }

  /* Kopfzeilen NICHT mehr nebeneinander quetschen, sondern stapeln.
     (Sonst bricht der Titel buchstabenweise um, weil zu wenig Platz bleibt.) */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 18px; }
  .page-head h1 { font-size: 21px; }
  .row-actions { flex-wrap: wrap; justify-content: flex-start; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .toolbar, .form-actions, .beleg-actions { flex-wrap: wrap; }

  /* Breite Tabellen scrollen IN SICH (nicht die ganze Seite verschieben) */
  .content table { display: block; width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ======================================================================
   Dokument-Fenster (Overlay) – wird im iPhone-App-Modus per JS geöffnet,
   damit man Dokumente/PDFs ansehen und immer per „Schließen" zurück kann.
   ====================================================================== */
.doc-overlay { position: fixed; inset: 0; z-index: 200; background: #fff; display: flex; flex-direction: column; }
.doc-overlay-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2)); color: #fff;
}
.doc-overlay-bar .doc-close {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: #fff;
  border-radius: 9px; padding: 9px 13px; font-size: 15px; font-weight: 600; cursor: pointer; flex: none;
}
.doc-overlay-bar .doc-title { flex: 1 1 auto; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-overlay-bar .doc-ext { color: #fff; text-decoration: none; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); border-radius: 9px; padding: 9px 11px; font-size: 13px; flex: none; }
.doc-overlay .doc-frame { flex: 1 1 auto; width: 100%; border: 0; background: #fff; }
