:root {
  --magenta: #C50742;
  --magenta-dunkel: #9e0535;
  --magenta-hell: #fdeef2;
  --bg: #f4f5f7;
  --karte: #ffffff;
  --text: #1c1e21;
  --text-leise: #6b7280;
  --rand: #e5e7eb;
  --gruen: #1a8a4a;
  --rot: #c0392b;
  --gelb: #b7791f;
  --schatten: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --schatten-gross: 0 8px 30px rgba(0,0,0,.12);
  --radius: 14px;
  --radius-klein: 9px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font-family: inherit; font-size: 1rem; }
a { color: inherit; text-decoration: none; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--magenta) 0%, var(--magenta-dunkel) 100%); padding: 1rem; }
.login-karte { background: #fff; border-radius: 18px; box-shadow: var(--schatten-gross); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-karte h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.login-karte .marke { color: var(--magenta); font-weight: 700; letter-spacing: .5px; font-size: .8rem; text-transform: uppercase; margin-bottom: 1.5rem; }
.login-karte label { display: block; font-size: .85rem; color: var(--text-leise); margin: 1rem 0 .35rem; }
.login-karte input { width: 100%; padding: .8rem; border: 1px solid var(--rand); border-radius: var(--radius-klein); }
.login-karte input:focus { outline: none; border-color: var(--magenta); }
.login-fehler { color: var(--rot); font-size: .85rem; margin-top: 1rem; min-height: 1.2em; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--rand); padding: 1.25rem 0; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.sidebar .marke { padding: 0 1.5rem 1.25rem; }
.sidebar .marke .logo { color: var(--magenta); font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; }
.sidebar .marke .sub { color: var(--text-leise); font-size: .75rem; text-transform: uppercase; letter-spacing: 1px; }
.nav { flex: 1; padding: 0 .75rem; }
.nav a { display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem; border-radius: var(--radius-klein); color: var(--text-leise); font-weight: 500; margin-bottom: .15rem; cursor: pointer; }
.nav a .ico { width: 20px; text-align: center; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.aktiv { background: var(--magenta-hell); color: var(--magenta); font-weight: 600; }
.nav .gruppe { font-size: .7rem; text-transform: uppercase; letter-spacing: 1px; color: #9ca3af; padding: 1rem 1rem .4rem; }
.user-box { padding: 1rem 1.5rem 0; border-top: 1px solid var(--rand); margin-top: .5rem; }
.user-box .name { font-weight: 600; font-size: .9rem; }
.user-box .rolle { font-size: .75rem; color: var(--text-leise); }
.user-box button { margin-top: .6rem; background: none; border: 1px solid var(--rand); border-radius: var(--radius-klein); padding: .45rem .8rem; cursor: pointer; color: var(--text-leise); width: 100%; }
.user-box button:hover { border-color: var(--magenta); color: var(--magenta); }

.main { padding: 2rem 2.5rem; max-width: 1400px; }
.seiten-kopf { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: 1rem; }
.seiten-kopf h1 { font-size: 1.6rem; }
.seiten-kopf .unter { color: var(--text-leise); font-size: .9rem; margin-top: .2rem; }

/* ---------- Buttons / Pillen ---------- */
.btn { background: var(--magenta); color: #fff; border: none; border-radius: var(--radius-klein); padding: .7rem 1.2rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem; }
.btn:hover { background: var(--magenta-dunkel); }
.btn.sekundaer { background: #fff; color: var(--text); border: 1px solid var(--rand); }
.btn.sekundaer:hover { border-color: var(--magenta); color: var(--magenta); }
.btn.klein { padding: .45rem .8rem; font-size: .85rem; }
.pille { display: inline-block; padding: .25rem .7rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pille.gruen { background: #e6f4ec; color: var(--gruen); }
.pille.rot { background: #fbeae8; color: var(--rot); }
.pille.gelb { background: #fdf3e2; color: var(--gelb); }
.pille.grau { background: #eef0f2; color: var(--text-leise); }

/* ---------- Karten / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.75rem; }
.kpi { background: var(--karte); border-radius: var(--radius); padding: 1.25rem 1.35rem; box-shadow: var(--schatten); border-left: 4px solid var(--magenta); }
.kpi .label { color: var(--text-leise); font-size: .82rem; font-weight: 500; }
.kpi .wert { font-size: 1.7rem; font-weight: 700; margin-top: .4rem; letter-spacing: -.5px; }
.kpi .zusatz { font-size: .8rem; color: var(--text-leise); margin-top: .25rem; }
.kpi.gut { border-left-color: var(--gruen); }
.kpi.warn { border-left-color: var(--gelb); }
.kpi.schlecht { border-left-color: var(--rot); }
.wert.pos { color: var(--gruen); }
.wert.neg { color: var(--rot); }

.karte { background: var(--karte); border-radius: var(--radius); box-shadow: var(--schatten); padding: 1.5rem; margin-bottom: 1.5rem; }
.karte h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.zwei-spalten { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 1000px) { .zwei-spalten { grid-template-columns: 1fr; } }

/* ---------- Tabellen ---------- */
.tabelle-wrap { background: var(--karte); border-radius: var(--radius); box-shadow: var(--schatten); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-leise); padding: .9rem 1rem; border-bottom: 1px solid var(--rand); background: #fafbfc; }
td { padding: .85rem 1rem; border-bottom: 1px solid var(--rand); font-size: .92rem; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
td.zahl, th.zahl { text-align: right; font-variant-numeric: tabular-nums; }
.zeilen-aktion { display: flex; gap: .4rem; justify-content: flex-end; }
.icon-btn { background: none; border: none; cursor: pointer; padding: .35rem .5rem; border-radius: 6px; color: var(--text-leise); font-size: .95rem; }
.icon-btn:hover { background: var(--bg); color: var(--magenta); }
.leer { padding: 3rem; text-align: center; color: var(--text-leise); }

/* ---------- Balken / Fortschritt ---------- */
.balken { height: 8px; background: var(--rand); border-radius: 999px; overflow: hidden; }
.balken > span { display: block; height: 100%; background: var(--magenta); border-radius: 999px; }
.balken > span.gut { background: var(--gruen); }
.balken > span.warn { background: var(--gelb); }
.balken > span.schlecht { background: var(--rot); }
.bar-chart { display: flex; flex-direction: column; gap: .8rem; }
.bar-row { display: grid; grid-template-columns: 160px 1fr auto; align-items: center; gap: .8rem; font-size: .88rem; }
.bar-row .track { height: 22px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-row .track > span { display: block; height: 100%; background: var(--magenta); }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 16px; box-shadow: var(--schatten-gross); width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; }
.modal-kopf { padding: 1.3rem 1.5rem; border-bottom: 1px solid var(--rand); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: #fff; }
.modal-kopf h3 { font-size: 1.15rem; }
.modal-body { padding: 1.5rem; }
.modal-fuss { padding: 1rem 1.5rem; border-top: 1px solid var(--rand); display: flex; justify-content: flex-end; gap: .75rem; position: sticky; bottom: 0; background: #fff; }
.feld { margin-bottom: 1rem; }
.feld label { display: block; font-size: .82rem; color: var(--text-leise); margin-bottom: .35rem; font-weight: 500; }
.feld input, .feld select, .feld textarea { width: 100%; padding: .7rem; border: 1px solid var(--rand); border-radius: var(--radius-klein); }
.feld input:focus, .feld select:focus, .feld textarea:focus { outline: none; border-color: var(--magenta); }
.feld-reihe { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--text); color: #fff; padding: .8rem 1.2rem; border-radius: var(--radius-klein); box-shadow: var(--schatten-gross); font-size: .9rem; animation: rein .2s ease; }
.toast.fehler { background: var(--rot); }
.toast.ok { background: var(--gruen); }
@keyframes rein { from { transform: translateY(10px); opacity: 0; } }

.versteckt { display: none !important; }
.filter-leiste { display: flex; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-leiste select, .filter-leiste input { padding: .6rem .8rem; border: 1px solid var(--rand); border-radius: var(--radius-klein); background: #fff; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .nav { display: flex; flex-wrap: wrap; }
  .main { padding: 1.25rem; }
  .bar-row { grid-template-columns: 110px 1fr auto; }
}

/* ---------- Druck (Bankenauskunft als PDF) ---------- */
@media print {
  .sidebar, .seiten-kopf .btn, .user-box, #toasts { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  .karte { box-shadow: none; border: 1px solid var(--rand); break-inside: avoid; page-break-inside: avoid; }
  body { background: #fff; }
}

/* ---------- Logo (Schambeck Group) ---------- */
.marke .logo-img { height: 32px; width: auto; max-width: 100%; display: block; object-fit: contain; align-self: flex-start; }
.login-karte .logo-img { height: 44px; width: auto; object-fit: contain; margin-bottom: 1.25rem; }
.sidebar .marke { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; }
.sidebar .marke .sub { color: var(--text-leise); font-size: .72rem; text-transform: uppercase; letter-spacing: 1px; }

/* ---------- Schnellaktionen / Buch-Buttons ---------- */
.aktion-leiste { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn.gruen { background: var(--gruen); }
.btn.gruen:hover { filter: brightness(.92); }
.btn.warnung { background: var(--gelb); }
.btn.warnung:hover { filter: brightness(.92); }
.mono { font-variant-numeric: tabular-nums; }
.klein-leise { font-size: .78rem; color: var(--text-leise); }
.einheit { color: var(--text-leise); font-weight: 400; font-size: .82em; }

/* Reichweite-Ampel als Punkt */
.ampel { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .5rem; vertical-align: middle; }
.ampel.gut { background: var(--gruen); }
.ampel.warn { background: var(--gelb); }
.ampel.schlecht { background: var(--rot); }

/* Segment-Umschalter (Meter/Glieder) */
.segment { display: inline-flex; border: 1px solid var(--rand); border-radius: var(--radius-klein); overflow: hidden; }
.segment button { background: #fff; border: none; padding: .55rem .9rem; cursor: pointer; font-size: .85rem; color: var(--text-leise); }
.segment button.aktiv { background: var(--magenta); color: #fff; }

textarea.csv { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .8rem; white-space: pre; }

/* ---------- Sortierbare / filterbare Tabelle ---------- */
th.sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.sort:hover { color: var(--magenta); }
th.sort .pfeil { color: var(--magenta); font-size: .8em; margin-left: .25rem; }
tr.filter-zeile th { background: #fff; padding: .4rem .6rem .7rem; }
tr.filter-zeile input, tr.filter-zeile select { width: 100%; padding: .4rem .5rem; border: 1px solid var(--rand); border-radius: 7px; font-size: .82rem; font-weight: 400; }
tr.filter-zeile input:focus, tr.filter-zeile select:focus { outline: none; border-color: var(--magenta); }

/* ---------- Lieferplan (Tagesübersicht) ---------- */
.tag-karte { background: var(--karte); border-radius: var(--radius); box-shadow: var(--schatten); margin-bottom: 1.25rem; overflow: hidden; }
.tag-kopf { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.35rem; background: var(--magenta-hell); border-bottom: 1px solid var(--rand); flex-wrap: wrap; }
.tag-kopf .datum { font-size: 1.1rem; font-weight: 700; color: var(--magenta-dunkel); }
.tag-kopf .summe { font-size: .9rem; color: var(--text); }
.tag-kopf .summe b { font-size: 1.15rem; }
