:root {
  --blau: #0B31AE;
  --blau-hell: #e8edfb;
  --blau-mittel: #c9d4f5;
  --text: #1c2333;
  --grau: #6b7280;
  --grau-hell: #9aa1ad;
  --linie: #e3e6ee;
  --flaeche: #f5f6fa;
  --weiss: #fff;
  --gruen: #1e7e34;
  --gruen-hell: #e3f4e8;
  --rot: #b42318;
  --rot-hell: #fdecea;
  --gelb: #9a6700;
  --gelb-hell: #fff6dc;
  --radius: 8px;
  --schatten: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--flaeche);
}
a { color: var(--blau); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--grau); }
code, .mono { font-family: var(--mono); font-size: 12px; }

/* ---------- Layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.seitenleiste { background: var(--weiss); border-right: 1px solid var(--linie); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.marke { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; }
.marke-logo { width: 30px; height: 30px; border-radius: 7px; background: var(--blau); color: #fff; display: grid; place-items: center; font-size: 15px; }
.marke small { display: block; font-weight: 400; color: var(--grau); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text); margin-bottom: 2px; }
.nav a:hover { background: var(--flaeche); text-decoration: none; }
.nav a.aktiv { background: var(--blau-hell); color: var(--blau); font-weight: 600; }
.nav .gruppe { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--grau-hell); padding: 14px 10px 6px; }
.nav .zaehler { margin-left: auto; background: var(--rot); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.haupt { min-width: 0; }
.kopf { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--weiss); border-bottom: 1px solid var(--linie); position: sticky; top: 0; z-index: 5; }
.kopf .suche { flex: 1; max-width: 480px; }
.kopf .rechts { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--grau); font-size: 13px; }
.inhalt { padding: 24px; max-width: 1280px; }
.dummy-band { background: repeating-linear-gradient(45deg, #fff6dc, #fff6dc 10px, #fdeec0 10px, #fdeec0 20px); color: var(--gelb); font-size: 12px; text-align: center; padding: 4px; font-weight: 600; }
.knopf.menue-knopf { display: none; }

/* ---------- Bausteine */
.karte { background: var(--weiss); border: 1px solid var(--linie); border-radius: var(--radius); box-shadow: var(--schatten); padding: 16px; }
.karte + .karte { margin-top: 16px; }
.raster > .karte + .karte { margin-top: 0; }
.raster { display: grid; gap: 16px; }
.raster-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.raster-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.raster-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.raster-detail { grid-template-columns: minmax(0, 1fr) 420px; align-items: start; }
.seitenkopf { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.seitenkopf .untertitel { color: var(--grau); }
.seitenkopf .aktionen { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.kennzahl { display: block; color: inherit; }
.kennzahl:hover { text-decoration: none; border-color: var(--blau-mittel); }
.kennzahl .wert { font-size: 26px; font-weight: 700; }
.kennzahl .label { color: var(--grau); font-size: 13px; }
.kennzahl.warn .wert { color: var(--rot); }
.leer { color: var(--grau); padding: 24px; text-align: center; }
.hinweis { border-radius: 6px; padding: 10px 12px; font-size: 13px; background: var(--blau-hell); color: #1f3a8a; }
.hinweis.gelb { background: var(--gelb-hell); color: var(--gelb); }
.hinweis.rot { background: var(--rot-hell); color: var(--rot); }
.hinweis.gruen { background: var(--gruen-hell); color: var(--gruen); }
.grau { color: var(--grau); }
.klein { font-size: 12px; }
.rechts { text-align: right; }
.nowrap { white-space: nowrap; }
.zeile { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.trenner { height: 1px; background: var(--linie); margin: 14px 0; }

/* ---------- Tabellen */
.tabelle-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--grau); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--linie); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--linie); vertical-align: top; }
tr.klickbar { cursor: pointer; }
tr.klickbar:hover td { background: #fafbfe; }
td.betrag, th.betrag { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- Badges */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--flaeche); color: var(--grau); white-space: nowrap; border: 1px solid var(--linie); }
.badge.blau { background: var(--blau-hell); color: var(--blau); border-color: var(--blau-mittel); }
.badge.gruen { background: var(--gruen-hell); color: var(--gruen); border-color: #bfe3c9; }
.badge.rot { background: var(--rot-hell); color: var(--rot); border-color: #f5c2bd; }
.badge.gelb { background: var(--gelb-hell); color: var(--gelb); border-color: #f1dc9a; }

/* ---------- Formulare */
input, select, textarea { font: inherit; color: inherit; border: 1px solid #cfd4df; border-radius: 6px; padding: 7px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blau-mittel); border-color: var(--blau); }
input[type=checkbox] { width: auto; }
label.feld { display: block; margin-bottom: 12px; }
label.feld > span { display: block; font-size: 12px; color: var(--grau); margin-bottom: 4px; font-weight: 600; }
label.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 10px; cursor: pointer; }
label.check input { margin-top: 3px; }
.filter { display: grid; grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)) minmax(0, 1.8fr); gap: 8px; margin-bottom: 14px; }
.filter input[type=date] { min-width: 0; }
.feld-hilfe { font-size: 12px; color: var(--grau); margin-top: 4px; }

.knopf { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 6px; border: 1px solid #cfd4df; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.knopf:hover { background: var(--flaeche); text-decoration: none; }
.knopf.primaer { background: var(--blau); border-color: var(--blau); color: #fff; }
.knopf.primaer:hover { background: #0a2a94; }
.knopf.gefahr { color: var(--rot); border-color: #f0b8b2; }
.knopf.klein { padding: 4px 10px; font-size: 12px; }
.knopf:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Detail */
.pdf-rahmen { width: 100%; height: 760px; border: 1px solid var(--linie); border-radius: 6px; background: #eef0f5; }
.reiter { display: flex; gap: 2px; border-bottom: 1px solid var(--linie); margin: -4px 0 14px; }
.reiter button { font: inherit; border: none; background: none; padding: 8px 12px; cursor: pointer; color: var(--grau); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.reiter button.aktiv { color: var(--blau); border-bottom-color: var(--blau); font-weight: 600; }
dl.daten { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
dl.daten dt { color: var(--grau); }
dl.daten dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.zeitleiste { list-style: none; margin: 0; padding: 0; }
.zeitleiste li { position: relative; padding: 0 0 14px 22px; }
.zeitleiste li::before { content: ""; position: absolute; left: 5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--grau-hell); }
.zeitleiste li::after { content: ""; position: absolute; left: 8.5px; top: 16px; bottom: 0; width: 1px; background: var(--linie); }
.zeitleiste li:last-child::after { display: none; }
.zeitleiste li.versand::before { background: var(--blau); }
.zeitleiste li.fehler::before { background: var(--rot); }
.zeitleiste li.zahlung::before { background: var(--gruen); }
.zeitleiste li.hinweis::before, .zeitleiste li.storno::before { background: var(--gelb); }
.zeitleiste .wann { font-size: 12px; color: var(--grau); }
.zeitleiste .text { overflow-wrap: anywhere; }

.versand-zeile { border: 1px solid var(--linie); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; }
.versand-zeile .kopfzeile { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.versand-zeile .antwort { font-family: var(--mono); font-size: 11.5px; color: var(--grau); margin-top: 4px; overflow-wrap: anywhere; }

pre.protokoll { background: #10162a; color: #d7def2; font-family: var(--mono); font-size: 12px; padding: 12px; border-radius: 6px; overflow-x: auto; margin: 0; max-height: 420px; }
pre.protokoll .aus { color: #8fb4ff; }
pre.protokoll .ein { color: #9fe0b0; }
pre.json { background: var(--flaeche); border: 1px solid var(--linie); padding: 12px; border-radius: 6px; font-family: var(--mono); font-size: 12px; overflow-x: auto; margin: 0; }

/* ---------- Modal & Toast */
.modal-hg { position: fixed; inset: 0; background: rgba(16, 22, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.breit { max-width: 940px; }
.modal-kopf { padding: 16px 20px; border-bottom: 1px solid var(--linie); font-weight: 700; display: flex; align-items: center; }
.modal-kopf button { margin-left: auto; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--grau); }
.modal-inhalt { padding: 16px 20px; }
.modal-fuss { padding: 12px 20px; border-top: 1px solid var(--linie); display: flex; justify-content: flex-end; gap: 8px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: #10162a; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--schatten); max-width: 360px; font-size: 13px; }
.toast.rot { background: var(--rot); }
.toast.gruen { background: var(--gruen); }

.balken { display: flex; align-items: flex-end; gap: 4px; height: 80px; }
.balken div { flex: 1; background: var(--blau-mittel); border-radius: 3px 3px 0 0; min-height: 4px; }
.balken div:last-child { background: var(--blau); }

.lade { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--blau-mittel); border-top-color: var(--blau); border-radius: 50%; animation: dreh 0.8s linear infinite; vertical-align: middle; }
@keyframes dreh { to { transform: rotate(360deg); } }

.port-ok td:first-child { border-left: 3px solid var(--gruen); }
.port-nein td:first-child { border-left: 3px solid var(--grau-hell); }
.empfohlen { background: var(--gruen-hell); }

/* ---------- Schmal */
@media (max-width: 1100px) {
  .raster-detail { grid-template-columns: 1fr; }
  .raster-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter { grid-template-columns: 1fr 1fr; }
  .filter > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .seitenleiste { position: fixed; z-index: 40; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--schatten); }
  .seitenleiste.offen { transform: none; }
  .knopf.menue-knopf { display: inline-flex; }
  .inhalt { padding: 16px; }
  .kopf { padding: 10px 16px; }
  .kopf .rechts .wer { display: none; }
  .raster-3, .raster-2, .raster-4 { grid-template-columns: 1fr; }
  .filter { grid-template-columns: 1fr; }
  .pdf-rahmen { height: 480px; }
  dl.daten { grid-template-columns: 1fr; gap: 0 0; }
  dl.daten dt { margin-top: 8px; }
}

/* Testinstanz: dauerhaft sichtbarer Hinweis auf die Mail-Umleitung */
.test-band { background: var(--rot); color: #fff; padding: 8px 16px; font-size: 14px; }
.test-band a { color: #fff; text-decoration: underline; margin-left: 8px; }
