/* Dunkles, ruhiges Dashboard-Design (Kundenwunsch) — tablet-tauglich (große Touch-Ziele) */
:root {
  --sidebar-w: 250px;
  --bg: #14171c;
  --bg-panel: #1c2027;
  --bg-panel-2: #232830;
  --border: #2c323c;
  --accent: #e8a33d;        /* warmes Brötchen-Gold (Flächen, Buttons) */
  --accent-2: #d97d2a;
  --accent-text: #f2b75a;   /* hellere Gold-Variante für Links auf dunklem Grund */
  --text: #e6e8eb;
  --muted: #8b93a1;
  --schatten: 0 1px 2px rgba(0, 0, 0, .25), 0 2px 6px rgba(0, 0, 0, .18);
  /* Sidebar nutzt dieselbe dunkle Palette */
  --s-bg: #1c2027;
  --s-bg-2: #232830;
  --s-border: #2c323c;
  --s-text: #e6e8eb;
  --s-muted: #8b93a1;
}
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 1rem; -webkit-font-smoothing: antialiased; }
a { color: var(--accent-text); }
a:hover { color: var(--accent); }

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

/* --- Navigation --- */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w); background: var(--s-bg); border-right: 1px solid var(--s-border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; color: var(--s-text);
}
.brand { display: flex; align-items: center; gap: .75rem; padding: 1.1rem 1.25rem; text-decoration: none; color: var(--s-text); border-bottom: 1px solid var(--s-border); }
.brand:hover { color: var(--s-text); }
.brand-icon { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; font-size: 1.35rem; color: #1a1a1a; }
.brand-text { line-height: 1.1; font-size: .95rem; }
.sidebar .nav { padding: .75rem .75rem; flex: 1; }
.sidebar .nav-heading { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--s-muted); padding: 1rem .75rem .35rem; }
.sidebar .nav-link { color: var(--s-text); border-radius: 10px; padding: .7rem .85rem; display: flex; align-items: center; gap: .7rem; font-size: 1rem; }
.sidebar .nav-link i { width: 1.25rem; text-align: center; color: var(--s-muted); }
.sidebar .nav-link:hover { background: var(--s-bg-2); color: var(--s-text); }
.sidebar .nav-link.active { background: rgba(232,163,61,.14); color: var(--accent); }
.sidebar .nav-link.active i { color: var(--accent); }
.sidebar-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--s-border); }
.sidebar .text-secondary { color: var(--s-muted) !important; }
.sidebar .text-secondary-emphasis { color: #aab2bf !important; }

/* --- Inhaltsbereich --- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { padding: .9rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--bg-panel); position: sticky; top: 0; z-index: 10; }
.content { padding: 1.5rem; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: calc(-1 * var(--sidebar-w)); z-index: 100; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .content { padding: 1rem; }
}

/* Auf dem Handy passen Überschrift und Aktionsknöpfe nicht nebeneinander: Ohne Umbruch
   wurde die Kopfzeile breiter als der Bildschirm und schob die ganze Seite nach rechts. */
@media (max-width: 767.98px) {
  .topbar { flex-wrap: wrap; padding: .75rem 1rem; }
  .topbar h1 { font-size: 1.05rem; min-width: 0; }
}

/* Panels / Karten */
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--schatten); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); font-weight: 600; }
.card-footer { background: transparent; border-top: 1px solid var(--border); }
.kpi { padding: 1.1rem 1.25rem; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi .value { font-size: 1.9rem; font-weight: 700; line-height: 1.2; }
.kpi .value.warn { color: #f0b14a; }
.kpi .value.danger { color: #ef6b6b; }
.kpi .value.ok { color: #58c98f; }

.table { --bs-table-bg: transparent; --bs-table-border-color: var(--border); --bs-table-color: var(--text); }
.table th { color: var(--muted); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.table th .sortlink { color: var(--muted); text-decoration: none; }
.table th .sortlink:hover { color: var(--text); }
.table th .sortlink .bi { color: var(--accent); }
.table td, .table th { vertical-align: middle; }
.table-hover tbody tr:hover { --bs-table-hover-bg: var(--bg-panel-2); --bs-table-hover-color: var(--text); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Warn-/Gefahr-Zeilen (OP-Liste): helle Bootstrap-Flächen — Links und gedämpfte Texte
   erben dort die dunkle Zeilenfarbe, sonst verschwimmen sie auf dem hellen Grund */
.table-danger a, .table-warning a, .table-danger .text-secondary, .table-warning .text-secondary { color: inherit !important; }

.btn { border-radius: 10px; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.15rem; }
.btn-primary { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-color: #1a1a1a; --bs-btn-hover-bg: #f2b75a; --bs-btn-hover-border-color: #f2b75a; --bs-btn-hover-color: #1a1a1a; --bs-btn-active-bg: var(--accent-2); --bs-btn-active-border-color: var(--accent-2); --bs-btn-disabled-bg: #7a6238; --bs-btn-disabled-border-color: #7a6238; --bs-btn-disabled-color: #2a2a2a; font-weight: 600; }
/* Sekundärbuttons: helle Kontur auf dunklem Grund (ehemals btn-outline-light) */
.btn-outline-secondary { --bs-btn-color: var(--text); --bs-btn-border-color: #49515e; --bs-btn-hover-bg: var(--bg-panel-2); --bs-btn-hover-border-color: #5a6373; --bs-btn-hover-color: var(--text); --bs-btn-active-bg: var(--bg-panel-2); --bs-btn-active-border-color: #5a6373; --bs-btn-active-color: var(--text); --bs-btn-disabled-color: var(--muted); --bs-btn-disabled-border-color: var(--border); }
.form-control, .form-select { background: #12151a; border-color: var(--border); color: var(--text); }
.form-control:focus, .form-select:focus { background: #12151a; color: var(--text); border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(232,163,61,.2); }
.form-check-input { background-color: #12151a; border-color: #49515e; }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus { border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(232,163,61,.2); }
.badge { font-weight: 600; }
.dropdown-menu { --bs-dropdown-bg: var(--bg-panel); --bs-dropdown-border-color: var(--border); --bs-dropdown-link-color: var(--text); --bs-dropdown-link-hover-bg: var(--bg-panel-2); --bs-dropdown-link-hover-color: var(--text); --bs-dropdown-divider-bg: var(--border); }
.modal-content { background: var(--bg-panel); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }

/* Statussymbole der Rechnungsübersicht (nach dem Vorbild von WISO Mein Büro):
   blauer Enter-Pfeil = Entwurf · gelb = Rechnung geschrieben · rot = überfällig ·
   rotes ! = Mahnung fällig · schwarz = uneinbringbar · grün = bezahlt */
.ampel { display: inline-block; width: 14px; height: 14px; border-radius: 50%; vertical-align: -2px; }
.ampel-erwartet { background: #e3b724; }
.ampel-ueberfaellig { background: #e05252; }
.ampel-uneinbringbar { background: #0a0c0f; border: 1.5px solid #8b93a1; }
.ampel-bezahlt { background: #2eb875; }
.symbol-entwurf { color: #5b8def; font-size: 1.15rem; }
.symbol-mahnung { color: #ff6b6b; font-size: 1.25rem; -webkit-text-stroke: .6px #ff6b6b; }
/* Zahlungs-Badges der Rechnungsübersicht: einheitliche Breite (längster Text „Uneinbringbar“), kompakt */
.badge-zahlung { display: inline-block; min-width: 6.25rem; text-align: center; }
/* Filter-Popup im Tabellenkopf: die uppercase-Vererbung des th neutralisieren */
.filter-menue .dropdown-menu { text-transform: none; letter-spacing: 0; font-size: .9rem; }

/* Status-Badges */
.status-entwurf { background: #4b5563; }
.status-offen, .status-abgeschickt { background: #2f6fed; }
.status-teilbezahlt { background: #b8860b; }
.status-bezahlt, .status-erledigt, .status-abgerechnet { background: #1f9d61; }
.status-storniert { background: #7f1d1d; }
.status-uneinbringbar { background: #0a0c0f; border: 1px solid #49515e; }

/* Bestellmaske (Tablet) */
.bestell-zeile { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--border); }
.bestell-zeile:last-child { border-bottom: 0; }
.bestell-name { font-size: 1.35rem; font-weight: 600; }
.bestell-name small { display: block; color: var(--muted); font-size: .85rem; font-weight: 400; }
.stepper { display: flex; align-items: center; gap: .5rem; }
.stepper button { width: 64px; height: 64px; font-size: 1.9rem; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-panel-2); color: var(--text); touch-action: manipulation; }
.stepper button:active { background: var(--accent); color: #1a1a1a; }
.stepper input { width: 96px; height: 64px; font-size: 1.8rem; text-align: center; font-weight: 700; border-radius: 14px; }
@media (max-width: 575.98px) { .stepper button { width: 54px; height: 54px; } .stepper input { width: 80px; height: 54px; font-size: 1.5rem; } .bestell-name { font-size: 1.15rem; } }

/* Produktionstafel — aus einigen Metern lesbar */
.produktion-tafel .zeile { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: .55rem 1.25rem; border-bottom: 1px solid var(--border); }
.produktion-tafel .zeile:last-child { border-bottom: 0; }
.produktion-tafel .name { font-size: 2.1rem; font-weight: 600; }
.produktion-tafel .name small { font-size: 1rem; color: var(--muted); margin-left: .75rem; }
.produktion-tafel .menge { font-size: 3.2rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); min-width: 3ch; text-align: right; }
.produktion-tafel .menge.null { color: var(--muted); opacity: .5; }
.produktion-tafel .gesamt { font-size: 1.5rem; }
.produktion-tafel .gesamt .menge { font-size: 2.6rem; }
.neu-badge { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.zeile.geaendert { background: rgba(232,163,61,.12); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 420px; }
.login-card .form-control { height: 56px; font-size: 1.15rem; }

/* Positions-Formset */
.positionen th, .positionen td { padding: .3rem .35rem; }
.positionen .zeilensumme { font-variant-numeric: tabular-nums; white-space: nowrap; }
.positionen tr.geloescht { opacity: .35; text-decoration: line-through; }
.positionen tr.liefertag td { background: var(--bg-panel-2); border-top: 2px solid var(--accent); padding: .45rem .5rem; }
.positionen tr.liefertag .bi-calendar3 { color: var(--accent); }
/* Artikel mit festem Steuersatz: Auswahl sichtbar, aber nicht umstellbar */
.positionen select.satz-fest { pointer-events: none; opacity: .75; }

/* Sonstiges */
.text-muted, .text-secondary { color: var(--muted) !important; }
pre.text-wrap { white-space: pre-wrap; font-family: inherit; }
.alters-tile { border-radius: 12px; padding: .8rem 1rem; background: var(--bg-panel-2); }
.hinweis-platzhalter { border-left: 4px solid var(--accent); }
.list-group-item { background: transparent; border-color: var(--border); color: var(--text); }
.pagination .page-link { background: var(--bg-panel); border-color: var(--border); color: var(--text); }
.pagination .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #1a1a1a; }
.dl-kompakt dt { color: var(--muted); font-weight: 500; }

/* Kassenbuch */
.text-bg-orange { color: #1a1a1a !important; background-color: #fd7e14 !important; }
.text-bg-violett { color: #fff !important; background-color: #6f42c1 !important; }
.kb-status { min-width: 6.5rem; text-align: center; }
.kb-vorschau { width: 7rem; height: 9rem; object-fit: cover; border-radius: .4rem; border: 1px solid var(--bs-border-color); background: rgba(255,255,255,.04); }
.kb-foto { cursor: grab; }
.kb-foto-name { max-width: 7rem; }

/* Auf dem Handy fuellen die Vorschaubilder die Kartenbreite aus — man muss erkennen
   koennen, ob der Bon vollstaendig und scharf im Bild ist, bevor er hochgeht. */
@media (max-width: 767.98px) {
  #kb-gruppen .card-body { gap: .5rem; }
  /* min-width:0 — sonst hält der Dateiname die Kachel auf ihrer Inhaltsbreite fest */
  #kb-gruppen .kb-foto { flex: 1 1 calc(50% - .25rem); min-width: 0; max-width: calc(50% - .25rem); }
  #kb-gruppen .kb-vorschau { width: 100%; height: auto; aspect-ratio: 3 / 4; }
  #kb-gruppen .kb-foto-name { max-width: 100%; }
  #kb-aktion .card-body { flex-direction: column; align-items: stretch; }
  #kb-aktion .btn { width: 100%; }
}
.kb-thumbs img { width: 4.5rem; height: 6rem; object-fit: cover; border-radius: .35rem; border: 1px solid var(--bs-border-color); }
.kb-ampel-rot { border-left: 4px solid var(--bs-danger) !important; }
.kb-ampel-gelb { border-left: 4px solid var(--bs-warning) !important; }
.kb-ampel-gruen { border-left: 4px solid var(--bs-success) !important; }
.kb-feld-rot { border-color: var(--bs-danger) !important; box-shadow: 0 0 0 .15rem rgba(220,53,69,.25); }
.kb-feld-gelb { border-color: var(--bs-warning) !important; }
.kb-bildbox { max-height: 75vh; overflow: auto; }
.kb-vorschau-tabelle td, .kb-vorschau-tabelle th { padding: .25rem .5rem; }

/* --- Startseite: Aktionen, Kennzahlen, Diagramme --------------------------------- */
.dash-aktion {
  display: flex; flex-direction: column; gap: .15rem; height: 100%; text-decoration: none; color: var(--text);
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem 1.25rem;
  box-shadow: var(--schatten); transition: border-color .15s, transform .15s, background .15s;
}
.dash-aktion:hover { color: var(--text); background: var(--bg-panel-2); border-color: var(--accent); transform: translateY(-2px); }
.dash-aktion .ikon {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; margin-bottom: .5rem;
  background: rgba(232,163,61,.14); color: var(--accent); font-size: 1.3rem;
}
.dash-aktion .titel { font-weight: 600; line-height: 1.25; }
.dash-aktion .hinweis { color: var(--muted); font-size: .85rem; }

.kpi { display: flex; flex-direction: column; }
.kpi .value .einheit { font-size: 1.1rem; font-weight: 600; color: var(--muted); }
.kpi .kpi-fuss { color: var(--muted); font-size: .82rem; line-height: 1.35; margin-top: .35rem; }
a.kpi-link { text-decoration: none; color: var(--text); transition: border-color .15s, background .15s; }
a.kpi-link:hover { color: var(--text); background: var(--bg-panel-2); border-color: var(--accent); }
.trend { font-weight: 600; white-space: nowrap; }
.trend-hoch { color: #58c98f; }
.trend-runter { color: #ef6b6b; }
.trend-gleich { color: var(--muted); }

/* Umsatzverlauf: reine CSS-Balken, damit keine Diagramm-Bibliothek nötig ist */
.balken-diagramm { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .75rem; align-items: end; min-height: 200px; }
.balken-spalte { display: flex; flex-direction: column; align-items: center; gap: .4rem; height: 100%; }
.balken-wert { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.balken-schiene { flex: 1; width: 100%; max-width: 52px; display: flex; align-items: flex-end; background: rgba(255,255,255,.035); border-radius: 8px; overflow: hidden; }
.balken { width: 100%; min-height: 3px; border-radius: 8px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); }
.balken-spalte.aktuell .balken { background: linear-gradient(180deg, #5b8def, #3a63c0); }
.balken-spalte.aktuell .balken-label { color: var(--text); font-weight: 600; }
.balken-label { font-size: .8rem; color: var(--muted); }

.alters-zeile + .alters-zeile { margin-top: .85rem; }
.alters-schiene { height: 8px; border-radius: 6px; background: var(--bg-panel-2); margin-top: .3rem; overflow: hidden; }
.alters-balken { height: 100%; border-radius: 6px; min-width: 3px; }
.alters-balken.stufe-1 { background: #e3b724; }
.alters-balken.stufe-2 { background: #e2913c; }
.alters-balken.stufe-3 { background: #e06a4a; }
.alters-balken.stufe-4 { background: #e05252; }

.kb-zahlen .wert { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.kb-zahlen .wert.warn { color: #f0b14a; }
.kb-zahlen .wert.danger { color: #ef6b6b; }
.kb-zahlen .label { color: var(--muted); font-size: .82rem; }

@media (max-width: 575.98px) {
  .kpi .value { font-size: 1.5rem; }
  .balken-diagramm { min-height: 150px; gap: .35rem; }
  .balken-wert { font-size: .68rem; }
}

/* --- Serienkamera: Vollbild, bleibt zwischen den Aufnahmen offen --- */
body.kb-kamera-offen { overflow: hidden; }
.kb-kamera { position: fixed; inset: 0; z-index: 1080; background: #000; color: #fff; display: flex; flex-direction: column; }
.kb-kamera-kopf { display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .6rem .9rem; padding-top: calc(.6rem + env(safe-area-inset-top)); background: rgba(0,0,0,.9); }
.kb-kamera-buehne { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }
.kb-kamera-buehne video { width: 100%; height: 100%; object-fit: contain; display: block; }
.kb-kamera-blende { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.kb-kamera-blende.an { animation: kb-blitz .18s ease-out; }
@keyframes kb-blitz { from { opacity: .85; } to { opacity: 0; } }
.kb-kamera-fehler { position: absolute; inset: auto 1rem 1rem; padding: .75rem 1rem; border-radius: .5rem;
  background: rgba(176,42,55,.95); font-size: .9rem; }
.kb-kamera-streifen { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem .75rem; background: rgba(0,0,0,.85); }
.kb-kamera-streifen:empty { display: none; }
.kb-kamera-streifen figure { position: relative; flex: 0 0 auto; margin: 0; }
.kb-kamera-streifen img { width: 3.4rem; height: 4.6rem; object-fit: cover; border-radius: .35rem; border: 2px solid transparent; }
.kb-kamera-streifen figure.neu img { border-color: var(--bs-warning); }
.kb-kamera-streifen figcaption { position: absolute; left: .2rem; bottom: .2rem; font-size: .65rem;
  background: rgba(0,0,0,.65); padding: 0 .25rem; border-radius: .2rem; }
.kb-kamera-weg { position: absolute; top: -.35rem; right: -.35rem; width: 1.4rem; height: 1.4rem;
  padding: 0; line-height: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.kb-kamera-leiste { display: flex; flex-direction: column; gap: .6rem;
  padding: .75rem; padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); background: rgba(0,0,0,.95); }
/* Auslöser bleibt mittig, auch wenn der Licht-Knopf fehlt */
.kb-kamera-reihe { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .6rem; }
.kb-kamera-reihe #kb-kamera-blitz { grid-column: 1; justify-self: start; }
.kb-kamera-reihe #kb-kamera-ausloeser { grid-column: 2; }
.kb-kamera-reihe #kb-kamera-fertig { grid-column: 3; justify-self: end; }
.kb-ausloeser { width: 4.2rem; height: 4.2rem; flex: 0 0 auto; border-radius: 50%; background: #fff;
  border: .28rem solid rgba(255,255,255,.45); background-clip: padding-box; cursor: pointer; }
.kb-ausloeser:active { transform: scale(.94); }
.kb-ausloeser:disabled { opacity: .45; }
.kb-kamera-leiste .btn.active { background: var(--bs-warning); color: #000; border-color: var(--bs-warning); }

/* --- Eingang: auf dem Handy je Bon eine Karte statt einer Tabellenzeile ---
   Sieben Spalten passen nicht auf ein iPhone; waagerechtes Schieben versteckt
   genau die Angaben, auf die es ankommt (Datum, Hinweis, Schaltfläche). */
@media (max-width: 767.98px) {
  .kb-eingang thead { display: none; }
  .kb-eingang, .kb-eingang tbody, .kb-eingang tr, .kb-eingang td { display: block; }
  .kb-eingang tr {
    display: grid; grid-template-columns: 1fr auto; gap: .1rem .6rem;
    padding: .75rem .9rem; border-bottom: 1px solid var(--bs-border-color);
  }
  .kb-eingang tr:last-child { border-bottom: 0; }
  .kb-eingang td { border: 0; padding: 0; }
  .kb-e-datum   { grid-area: 1 / 1; font-weight: 600; }
  .kb-e-filiale { grid-area: 1 / 2; justify-self: end; }
  .kb-e-znr     { grid-area: 2 / 1; }
  .kb-e-znr::before { content: "Z-Nr. "; color: var(--muted); }
  .kb-e-status  { grid-area: 2 / 2; justify-self: end; }
  .kb-e-zeit    { grid-area: 3 / 1 / auto / span 2; justify-self: end; text-align: right; color: var(--muted); }
  .kb-e-zeit::before { content: "erfasst am "; }
  .kb-e-zeit br { display: none; }
  .kb-e-zeit span::before { content: " · "; }
  .kb-e-hinweis { grid-area: 4 / 1 / auto / span 2; }
  .kb-e-hinweis:empty { display: none; }
  .kb-e-aktion  { grid-area: 5 / 1 / auto / span 2; margin-top: .5rem; }
  .kb-e-aktion .btn { width: 100%; }
  /* Die Karte trägt ihren eigenen Rahmen — der Tabellenrahmen stört */
  .kb-eingang > tbody > tr > td { border-bottom: 0; }
}
