:root {
  /* Hauptfarbe #dd052b; --blau = dunkle Variante davon (historischer Name, überall als "Brand-Dunkel" genutzt) */
  --blau: #8f031c;
  --blau-hell: #dd052b;
  --akzent: #dd052b;
  --gruen: #16a34a;
  --rot: #a61b1b;
  --gelb: #d97706;
  --grau: #6b7280;
  --bg: #f3f4f6;
  --karte: #ffffff;
  --rand: #e5e7eb;
  --text: #111827;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  overflow-x: hidden;
}
.loading { padding: 40px; text-align: center; color: var(--grau); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--karte); border-radius: var(--radius); padding: 32px 26px;
  width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.12);
}
.login-card .logo { font-size: 30px; font-weight: 800; color: var(--akzent); text-align: center; }
.login-card .sub { text-align: center; color: var(--grau); margin-bottom: 22px; font-size: 13px; }
.login-card .demo { margin-top: 18px; font-size: 12px; color: var(--grau); border-top: 1px solid var(--rand); padding-top: 14px; }
.login-card .demo b { color: var(--text); }

/* ---------- Impersonation-Banner ---------- */
.imp-banner {
  background: #d97706; color: #fff; padding: 9px 14px; font-size: 13px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.imp-banner button {
  background: #fff; color: #b45309; border: none; border-radius: 7px;
  padding: 5px 12px; font-size: 13px; font-weight: 700; cursor: pointer; margin-left: auto;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--akzent); color: #fff; display: flex; align-items: center;
  justify-content: space-between; padding: 12px 16px;
}
.topbar .brand { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.topbar .brand-logo { height: 26px; width: auto; display: block; }
.topbar .user { font-size: 12px; opacity: .85; text-align: right; }
.topbar .user .rolle { display: inline-block; background: rgba(255,255,255,.18); padding: 1px 8px; border-radius: 20px; margin-top: 2px; }

nav.tabs {
  position: sticky; top: 49px; z-index: 25; background: var(--karte);
  border-bottom: 1px solid var(--rand); display: flex; overflow-x: auto; gap: 2px; padding: 0 8px;
}
nav.tabs button {
  background: none; border: none; padding: 13px 14px; font-size: 14px; color: var(--grau);
  white-space: nowrap; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600;
}
nav.tabs button.active { color: var(--blau); border-bottom-color: var(--akzent); }

main { padding: 18px 24px 70px; max-width: 100%; margin: 0; }
@media (max-width: 600px) { main { padding: 14px 14px 70px; } }
h2.view-titel { font-size: 20px; margin-bottom: 14px; color: var(--blau); }

/* ---------- Dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--karte); border: 1px solid var(--rand); border-radius: var(--radius); padding: 14px 16px; position: relative; overflow: hidden; }
.kpi.klick { cursor: pointer; transition: box-shadow .15s, transform .05s; }
.kpi.klick:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.kpi .kpi-num { font-size: 30px; font-weight: 800; line-height: 1.1; color: var(--blau); }
.kpi .kpi-label { font-size: 13px; color: var(--grau); margin-top: 2px; font-weight: 600; }
.kpi .kpi-sub { font-size: 12px; color: var(--grau); margin-top: 4px; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--akzent); }
.kpi.warn::before { background: var(--gelb); } .kpi.warn .kpi-num { color: var(--gelb); }
.kpi.bad::before { background: var(--rot); } .kpi.bad .kpi-num { color: var(--rot); }
.kpi.good::before { background: var(--gruen); }
.kpi.neutral::before { background: #94a3b8; }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; margin-bottom: 14px; }
.dash-karte { background: var(--karte); border: 1px solid var(--rand); border-radius: var(--radius); padding: 16px; }
.dash-karte h3 { font-size: 15px; color: var(--blau); margin-bottom: 4px; }
.dash-karte .h3-sub { font-size: 12px; color: var(--grau); margin-bottom: 10px; }
.chart-legende { display: flex; gap: 16px; font-size: 12px; color: var(--grau); margin-bottom: 8px; }
.chart-legende span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legende i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.chart svg { width: 100%; height: auto; display: block; }

.rw-bar { height: 7px; background: #eef1f6; border-radius: 4px; overflow: hidden; min-width: 60px; }
.rw-bar i { display: block; height: 100%; border-radius: 4px; }

/* ---------- Kanban-Board ---------- */
.kb-toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.kb-toolbar .kb-tt { font-size: 13px; color: var(--grau); font-weight: 600; }
.kb-toolbar label { font-size: 13px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; cursor: pointer; background: var(--karte); border: 1px solid var(--rand); padding: 6px 11px; border-radius: 20px; }
.kb-toolbar input { width: auto; }
.kb-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: stretch; min-height: calc(100vh - 210px); }
.kb-col { flex: 1 0 240px; min-width: 240px; max-width: 360px; background: #eceff4; border-radius: 12px; padding: 8px; display: flex; flex-direction: column; }
.kb-cards { flex: 1; }
.kb-col-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 10px; font-weight: 700; font-size: 13px; color: var(--blau); }
.kb-col-head .kb-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: middle; }
.kb-col-head .kb-count { background: #fff; border-radius: 20px; padding: 1px 9px; font-size: 12px; color: var(--grau); font-weight: 700; }
.kb-cards { display: flex; flex-direction: column; gap: 8px; min-height: 24px; max-height: calc(100vh - 250px); overflow-y: auto; padding: 2px; }
.kb-card { background: #fff; border: 1px solid var(--rand); border-left: 4px solid var(--akzent); border-radius: 9px; padding: 10px 12px; cursor: pointer; transition: box-shadow .12s, transform .04s; }
.kb-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.1); }
.kb-card:active { transform: scale(.99); }
.kb-card-nr { font-weight: 700; font-size: 14px; color: var(--text); }
.kb-card-meta { font-size: 12px; color: var(--grau); margin-top: 2px; }
.kb-col-leer { font-size: 12px; color: #9ca3af; text-align: center; padding: 16px 0; }

/* ---------- Karten / Listen ---------- */
.karte { background: var(--karte); border-radius: var(--radius); border: 1px solid var(--rand); padding: 14px; margin-bottom: 12px; }
.karte.klick { cursor: pointer; transition: box-shadow .15s; }
.karte.klick:active { box-shadow: 0 2px 12px rgba(0,0,0,.1); }
.zeile { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--grau); font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.grid-artikel { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }

.artikel-bild { width: 100%; height: 160px; object-fit: contain; border-radius: 8px; background: #fff; padding: 4px; }
.artikel-bild.platzhalter { display: flex; align-items: center; justify-content: center; color: #b9c0cc; font-size: 30px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.b-grau { background: #e5e7eb; color: #374151; }
.b-blau { background: #dbeafe; color: #1e40af; }
.b-gelb { background: #fef3c7; color: #92400e; }
.b-gruen { background: #dcfce7; color: #166534; }
.b-rot { background: #fee2e2; color: #991b1b; }
.b-orange { background: #ffedd5; color: #9a3412; }
.b-lila { background: #ede9fe; color: #5b21b6; }

/* ---------- Buttons ---------- */
button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--akzent); color: #fff; border: none; border-radius: 10px;
  padding: 11px 16px; font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
button.btn:active { opacity: .85; }
button.btn:disabled { background: #c7cdd6; cursor: not-allowed; }
.btn.sek { background: #f7eef0; color: var(--blau); }
.btn.gruen { background: var(--gruen); }
.btn.rot { background: var(--rot); }
.btn.gelb { background: var(--gelb); }
.btn.klein { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-reihe { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn.block { width: 100%; }

/* ---------- Formulare ---------- */
label.feld { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: #374151; }
label.feld input, label.feld select, label.feld textarea {
  width: 100%; margin-top: 5px; padding: 11px 12px; border: 1px solid var(--rand);
  border-radius: 9px; font-size: 15px; font-family: inherit; background: #fff;
}
input.menge { width: 78px; text-align: center; padding: 8px; border: 1px solid var(--rand); border-radius: 8px; font-size: 15px; }
.fehler { background: #fee2e2; color: #991b1b; padding: 10px 12px; border-radius: 9px; margin-bottom: 12px; font-size: 14px; }
.erfolg { background: #dcfce7; color: #166534; padding: 10px 12px; border-radius: 9px; margin-bottom: 12px; font-size: 14px; }

/* ---------- Tabelle ---------- */
table.tab { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tab th, table.tab td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--rand); }
table.tab th { font-size: 12px; color: var(--grau); text-transform: uppercase; letter-spacing: .03em; }
table.tab td.num, table.tab th.num { text-align: right; }
.abw-pos { color: var(--gruen); font-weight: 700; }
.abw-neg { color: var(--rot); font-weight: 700; }

/* ---------- Warenkorb ---------- */
.korb-bar {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--blau); color: #fff;
  padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; z-index: 40;
}
.variante-zeile { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--rand); }
.variante-zeile .variante-info { font-size: 13px; min-width: 0; }
.variante-zeile .menge-step { width: auto; flex: 0 0 auto; }
.variante-zeile .menge-step input.menge { flex: 0 0 56px; width: 56px; }
.menge-step { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; width: 100%; }
.menge-step button { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--rand); background: #fff; font-size: 18px; cursor: pointer; }
.menge-step input.menge { flex: 1 1 auto; width: auto; min-width: 0; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--karte); width: 100%; max-width: 560px; border-radius: 16px 16px 0 0; padding: 18px; max-height: 92vh; overflow-y: auto; }
.modal.gross { max-width: 880px; padding: 24px 28px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-grid .voll { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-abschnitt { grid-column: 1 / -1; font-weight: 700; font-size: 13px; color: var(--blau); border-bottom: 1px solid var(--rand); padding-bottom: 4px; margin: 10px 0 10px; }

.kat-titel { font-size: 15px; color: var(--blau); margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--akzent); display: inline-block; }
.kat-titel:first-of-type { margin-top: 4px; }

/* ---------- Handbuch (Hilfe) ---------- */
.hb-layout { display: flex; gap: 20px; min-height: 420px; }
.hb-nav { flex: 0 0 220px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--rand); padding-right: 12px; max-height: 68vh; overflow-y: auto; }
.hb-nav button { text-align: left; background: none; border: none; padding: 7px 10px; border-radius: 8px; font-size: 13.5px; color: var(--text); cursor: pointer; line-height: 1.3; }
.hb-nav button:hover { background: #f7eef0; }
.hb-nav button.aktiv { background: var(--akzent); color: #fff; font-weight: 700; }
.hb-inhalt { flex: 1; min-width: 0; max-height: 68vh; overflow-y: auto; font-size: 14px; line-height: 1.65; padding-right: 6px; }
.hb-inhalt h4 { color: var(--blau); font-size: 18px; margin-bottom: 10px; }
.hb-inhalt h5 { color: var(--blau); font-size: 14px; margin: 14px 0 4px; }
.hb-inhalt p { margin: 0 0 10px; }
.hb-inhalt ul, .hb-inhalt ol { margin: 0 0 10px 20px; }
.hb-inhalt li { margin-bottom: 4px; }
.hb-inhalt table.tab { margin: 6px 0 12px; }
.hb-inhalt .muted { font-size: 13px; }
@media (max-width: 700px) {
  .hb-layout { flex-direction: column; min-height: 0; }
  .hb-nav { flex: none; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--rand); padding: 0 0 10px; max-height: none; }
  .hb-inhalt { max-height: 60vh; }
}
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 16px; } }
.modal h3 { margin-bottom: 12px; color: var(--blau); }
.modal-close { float: right; font-size: 22px; color: var(--grau); background: none; border: none; cursor: pointer; }

/* ---------- Signatur ---------- */
.sig-wrap { border: 2px dashed var(--rand); border-radius: 10px; background: #fafbfc; touch-action: none; }
canvas#sig { width: 100%; height: 180px; display: block; }

.leer { text-align: center; color: var(--grau); padding: 40px 10px; }
.pill-link { color: var(--akzent); font-size: 13px; text-decoration: none; font-weight: 600; }
