/*
 * KiKi Admin Theme v2
 * ────────────────────
 * Gemeinsame Design- UND Komponentengrundlage für alle KiKi-Betreiber-/
 * Admin-Oberflächen (Steuerzentrale, künftige Panels). Palette-Herkunft:
 * franchise-ecosystem.html / modules.html (mediaprog, Projekt
 * kiki-ai-platform) -- dunkler Grund, Teal als Hauptakzent, Bricolage
 * Grotesque für Überschriften, IBM Plex Mono für Labels/Badges, IBM Plex
 * Sans als Fließtext.
 *
 * Einbindung in einer neuen Admin-Seite:
 *   <link rel="preconnect" href="https://fonts.googleapis.com">
 *   <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
 *   <link href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,600;12..96,700;12..96,800&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
 *   <link rel="stylesheet" href="/admin/theme.css">
 *
 * Nur ein Theme (dunkel) -- die Referenzseite hat ebenfalls keinen
 * hell/dunkel-Umschalter.
 *
 * v2 (Erweiterung): Ab hier lebt auch wiederkehrendes Komponenten-CSS hier
 * statt in jeder Seite neu -- Grid/Tabelle, Doppelklick-Editierzellen,
 * Kennzahlen-Kacheln mit Sparkline (Vorbild: pwa/index.html aus
 * PWA-GambioOrdersDashboard, Farben auf Teal umgesetzt statt Indigo),
 * Filterleiste, Balkenliste. Grund: Nutzer-Vorgabe "zukünftig alle Kiki
 * Plattformen Admin Bereiche" -- jedes neue Panel soll das hier
 * mitbekommen, nicht neu erfinden. Was WIRKLICH seitenspezifisch bleibt
 * (Login-Gate, o.ä. Einzelstücke) bleibt weiterhin seitenlokal.
 */

:root {
  --ground:      #0d141b;
  --surface:     #151f28;
  --surface-2:   #1a2530;
  --line:        #2b3b47;
  --ink:         #e7eef2;
  --ink-muted:   #9eafb9;
  --deep:        #08151f;
  --teal:        #35c9b4;
  --mint:        #3b8f86;
  --gold:        #f1bf63;
  --orange:      #e79a64;
  --purple:      #a78bfa;
  --blue:        #78b6df;
  --red:         #e2685c;
  --accent:      var(--teal);
  --accent-ink:  #06151a;
  --accent-soft: rgba(53, 201, 180, .14);
  --good:        var(--teal);
  --good-soft:   rgba(53, 201, 180, .14);
  --warn:        var(--gold);
  --warn-soft:   rgba(241, 191, 99, .14);
  --bad:         var(--red);
  --bad-soft:    rgba(226, 104, 92, .14);
  --code-bg:     var(--deep);
  --code-fg:     #cfe3df;
  --sans: "IBM Plex Sans", -apple-system, "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --display: "Bricolage Grotesque", var(--sans);
  --radius: 3px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
}

html { height: 100%; }
* { box-sizing: border-box; }
body {
  display: flex; flex-direction: column; height: 100vh; margin: 0; color: var(--ink);
  background: radial-gradient(circle at 50% 0%, rgba(25, 94, 87, .20), transparent 30rem), var(--ground);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

/* ───────────────────────── Chrome-Bausteine ───────────────────────── */
.eyebrow {
  margin: 0 0 6px; color: var(--teal); font: 600 .68rem var(--mono);
  letter-spacing: .16em; text-transform: uppercase;
}
.brand-icon {
  display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px;
  border: 1px solid currentColor; color: var(--teal); font: 600 .74rem var(--mono);
}
.mono { font-family: var(--mono); }
code.diff { font-family: var(--mono); font-size: 11.5px; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 2px; }

/* ───────────────────────── Buttons ───────────────────────── */
.btn-sm {
  padding: 7px 13px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); cursor: pointer; font-size: 12.5px;
}
.btn-sm:hover { border-color: var(--teal); color: var(--teal); }
.btn-sm.primary { background: var(--teal); border-color: var(--teal); color: var(--accent-ink); font-weight: 600; }
.btn-sm.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn-sm.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-sm:disabled { opacity: .5; cursor: default; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────────────────── Karten (Kennzahlen, einfach) ───────────────────────── */
.stat-n { font: 800 1.7rem/1 var(--display); font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-l { color: var(--ink-muted); font: 600 .68rem var(--mono); letter-spacing: .05em; text-transform: uppercase; margin-top: 7px; }
.stat-n.warn { color: var(--warn); } .stat-n.bad { color: var(--bad); } .stat-n.good { color: var(--good); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card {
  background: linear-gradient(145deg, rgba(21, 31, 40, .92), rgba(8, 21, 31, .85));
  border: 1px solid var(--line); border-top: 3px solid var(--teal); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: 0 10px 24px rgba(0, 0, 0, .18);
}
.card .stat-n { display: block; }
.card.warn { border-top-color: var(--warn); } .card.warn .stat-n { color: var(--warn); }
.card.bad  { border-top-color: var(--bad);  } .card.bad .stat-n  { color: var(--bad); }
.card.good { border-top-color: var(--good); } .card.good .stat-n { color: var(--good); }

/* ───────────────────────── Pills / Status ───────────────────────── */
.pill { display: inline-block; font-family: var(--mono); font-size: 10.5px; font-weight: 600; padding: 3px 8px; border: 1px solid transparent; letter-spacing: .03em; text-transform: uppercase; }
.pill.rate    { background: var(--bad-soft);  color: var(--bad);  border-color: rgba(226, 104, 92, .3); }
.pill.stale   { background: var(--warn-soft); color: var(--warn); border-color: rgba(241, 191, 99, .3); }
.pill.user    { background: var(--warn-soft); color: var(--warn); border-color: rgba(241, 191, 99, .3); }
.pill.amount  { background: var(--bad-soft);  color: var(--bad);  border-color: rgba(226, 104, 92, .3); }
.pill.credited,
.pill.on      { background: var(--good-soft); color: var(--good); border-color: rgba(53, 201, 180, .3); }
.pill.off     { background: var(--surface-2); color: var(--ink-muted); border-color: var(--line); }
button.pill { appearance: none; -webkit-appearance: none; cursor: pointer; font-family: var(--mono); }
button.pill:hover { filter: brightness(1.15); }

/* ───────────────────────── Kunden-Profil (aufklappbare Zeile) ─────────────────────────
   Erste Fassung (2026-08-29) liess die Tabellen INNERHALB der Boxen umbrechen (white-space:
   normal), um das Aufsprengen der Boxen zu stoppen -- Betreiberin-Korrektur direkt danach:
   "falsch verstanden, volle Spalten, volle Informationen will ich haben". Jetzt umgekehrt: die
   Tabellen bleiben bei voller Spaltenbreite/nowrap wie die grosse Kunden-Liste, und die Boxen
   selbst sind per Ziehen am rechten Rand in der BREITE vergroesserbar (natives CSS `resize`,
   gleiches Prinzip wie die schon vorhandene Hoehen-Ziehbarkeit von `.grid-wrap.short`) --
   .profile-grid ist dafuer von CSS-Grid auf Flexbox umgestellt, weil ein Grid-Item eine manuelle
   Breite ignoriert (die Spaltenbreite kommt vom Grid-Template, nicht vom Element selbst); ein
   Flex-Item mit `flex: 0 0 <basis>` respektiert dagegen eine per `resize` gesetzte Breite. Ist
   eine Box (noch) nicht breitgezogen, faengt `.grid-wrap`s `overflow-x:auto` die volle
   Tabellenbreite trotzdem ohne Aufsprengen der Box ab (eigener Scrollbalken statt Umbruch). */
.profile-grid { display: flex; flex-wrap: wrap; gap: 12px; }
/* flex:0 0 260px (fester Flex-Basis) statt `flex:none; width:260px` haette hier NICHT
   funktioniert: eine feste Flex-Basis wird bei jedem Layout-Durchlauf von Flexbox neu
   berechnet und ueberschreibt damit staendig die per `resize` gezogene Breite -- getestet
   2026-08-29, ein echter Playwright-Maus-Zug aenderte die Breite nachweislich NICHT. `flex:
   none` (kein Wachsen/Schrumpfen) mit einer eigenen `width` statt Flex-Basis laesst Flexbox die
   von `resize` gesetzte Breite dagegen in Ruhe. */
.profile-section {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
  padding: 10px 12px; flex: none; width: 260px; min-width: 260px; max-width: 100%;
  overflow: hidden; resize: horizontal;
}
.profile-section h4 { margin: 0 0 8px; font: 600 .68rem var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--teal); }
.kv-list { display: flex; flex-direction: column; gap: 5px; }
.kv-list > div { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }
.kv-list > div > span:first-child { color: var(--ink-muted); }

/* ───────────────────────── Filterleiste ───────────────────────── */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar input[type="search"], .filter-bar input[type="text"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground);
  color: var(--ink); font-size: 12.5px; min-width: 200px;
}
.filter-bar select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground);
  color: var(--ink); font-size: 12.5px;
}
.filter-bar input:focus-visible, .filter-bar select:focus-visible { outline: 2px solid var(--teal); }
.filter-bar .count { margin-left: auto; font: 600 11px var(--mono); color: var(--ink-muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.filter-bar input[type="date"] {
  padding: 6px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground);
  color: var(--ink); font-size: 12.5px; color-scheme: dark;
}
.filter-bar input[type="date"]:focus-visible { outline: 2px solid var(--teal); }
.range-result { display: inline-flex; align-items: baseline; gap: 6px; font-size: 12.5px; color: var(--ink-muted); }
.range-result strong { font: 700 13px var(--mono); color: var(--teal); font-variant-numeric: tabular-nums; }

/* ───────────────────────── Grid (dichte Tabelle, eigener Scroll) ─────────────────────────
   Sticky-Header bezieht sich auf den EIGENEN Scrollcontainer (top:0), nicht auf die Seite --
   das ist die eigentliche Reparatur gegenüber der ersten Fassung: ein seitenweiter Sticky-
   Header lässt sich nur mit einer exakt gemessenen Pixel-Offset korrekt stapeln, und genau
   das lief hier auseinander. Ein lokal scrollender Container braucht kein Offset-Raten.

   min-height: 400px sichert, dass Listen mit Paginationen auch bei wenigen Zeilen noch
   eine brauchbare Höhe haben. flex:1 sorgt dafür, dass die volle verfügbare Höhe genutzt wird. */
.grid-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); flex: 1; overflow-y: auto; overflow-x: auto; min-height: 400px; }
/* Per Ziehen am Eck unten rechts vergroesserbar (natives CSS `resize`, kein eigenes DnD-JS
   noetig -- Betreiberin-Vorgabe 2026-08-29: "Boxen sollten sich per DnD vergroessern"). Jede
   Box merkt ihre eigene Groesse einzeln (siehe data-boxkey/wireBoxResize() in index.html), statt
   eines einzigen globalen Reglers fuer alle Boxen -- Kaeufe braucht selten viel Platz,
   Verbrauchsverlauf oft schon. */
.grid-wrap.short { flex: 0 0 auto; height: 300px; min-height: 80px; max-height: 900px; resize: vertical; }
.grid { width: 100%; min-width: 1200px; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.grid th, .grid td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.grid thead th {
  position: sticky; top: 0; z-index: 2; background: var(--deep); font-family: var(--mono); font-size: 10px;
  font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-muted);
}
.grid thead th.sortable { cursor: pointer; user-select: none; }
.grid thead th.sortable:hover { color: var(--teal); }
.grid thead th .sort-arrow { margin-left: 4px; opacity: .35; }
.grid thead th.sorted .sort-arrow { opacity: 1; color: var(--teal); }
.grid tbody tr:hover { background: var(--surface-2); }
.grid tbody tr.expanded { background: var(--surface-2); }
.grid tbody tr.sub-row td { background: var(--ground); padding: 0; border-bottom: 1px solid var(--line); }
.grid td.num { text-align: right; }
.grid td.mono, .grid th.mono { font-family: var(--mono); }
.empty { text-align: center; padding: 44px 20px; color: var(--ink-muted); font-size: 13px; }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 12px; font-size: 12.5px; }
.pagination button { padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); cursor: pointer; }
.pagination button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.pagination button:disabled { opacity: .3; cursor: default; }
.pagination .page-info { color: var(--ink-muted); padding: 0 8px; }

/* ───────────────────────── Editierbare Zelle: Doppelklick -> Feld -> Autosave ─────────────────────────
   Standardzustand ist reiner Text, kein offenes Eingabefeld. Erst ein Doppelklick tauscht
   die Zelle gegen ein <input>; Enter/Blur speichert per AJAX, Escape verwirft. Der jeweilige
   Save-Callback lebt seitenlokal (unterschiedliche Endpunkte pro Panel), diese Klassen sind
   nur die Optik/den Zustand dazu. .cell-edit steht direkt auf <td> -- display:inline-flex wuerde
   die Zelle aus dem Tabellen-Spaltenraster nehmen und alle Spalten danach nach links verschieben,
   deshalb bleibt td table-cell; vertical-align:middle kommt schon von .grid td. */
.cell-edit { min-height: 20px; cursor: pointer; padding: 2px 4px; border: 1px solid transparent; border-radius: 3px; transition: all .1s; }
.cell-edit:hover { background: var(--surface-2); border-color: var(--line); }
.cell-edit .cell-value { color: var(--ink); font-family: var(--mono); font-size: 12.5px; }
.cell-edit .cell-value + .save-state { margin-left: 8px; }
.cell-edit .cell-input {
  width: 100px; padding: 6px 8px; border: 1px solid var(--teal); border-radius: 3px;
  background: var(--ground); color: var(--ink); font-family: var(--mono); font-size: 12.5px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2);
}
.cell-edit .cell-input:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2), 0 0 0 2px rgba(53, 201, 180, .2); }
.cell-edit .group-input, .cell-edit .role-select {
  padding: 6px 8px; border: 1px solid var(--teal); border-radius: 3px; background: var(--ground); color: var(--ink); font-family: var(--mono); font-size: 12.5px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2);
}
.cell-edit .group-input:focus, .cell-edit .role-select:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2), 0 0 0 2px rgba(53, 201, 180, .2); }

/* Eigenstaendige Variante von .cell-edit .role-select fuer Selects ausserhalb der Tabellenzelle
   (z. B. im Kundenprofil) -- gleiche Optik, ohne den .cell-edit-Elternkontext zu brauchen. */
.select-inline {
  padding: 6px 8px; border: 1px solid var(--teal); border-radius: 3px; background: var(--ground);
  color: var(--ink); font-family: var(--mono); font-size: 12.5px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2); cursor: pointer;
}
.select-inline:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2), 0 0 0 2px rgba(53, 201, 180, .2); }
.cell-edit .save-state { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; }
.cell-edit .save-state.ok  { color: var(--good); }
.cell-edit .save-state.err { color: var(--bad); }

.switch { position: relative; display: inline-flex; width: 34px; height: 19px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; pointer-events: none; }
.switch .thumb { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; background: var(--ink); border-radius: 50%; transition: transform .15s; pointer-events: none; }
.switch input:checked + .track { background: var(--teal); }
.switch input:checked + .track .thumb { transform: translateX(15px); background: var(--accent-ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ───────────────────────── Personalisierbares Dashboard: Kachel-Grid ─────────────────────────
   Fester Raster (kein Freiform-Positionieren): jede Kachel ist ein .widget mit
   grid-column:span N, ziehbar zum Umsortieren (native HTML5 Drag&Drop, keine Bibliothek).
   Aus einem Pool wählbar (.widget-pool-menu), per × wieder entfernbar -- Auswahl+Reihenfolge
   wird je Betreiber gespeichert (dashboard-widgets.php). */
.widget-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.widget {
  background: linear-gradient(145deg, rgba(21, 31, 40, .92), rgba(8, 21, 31, .85));
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .18); display: flex; flex-direction: column; cursor: grab;
}
.widget.dragging { opacity: .4; }
.widget.drag-over { border-color: var(--teal); }
.widget-head { display: flex; align-items: center; gap: 8px; padding: 8px 11px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .02); }
.widget-drag { color: var(--ink-muted); font-size: 13px; }
.widget-title { flex: 1; font: 600 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.widget-remove { background: none; border: none; color: var(--ink-muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 2px 4px; }
.widget-remove:hover { color: var(--bad); }
.widget-body { flex: 1; }
.widget-body.pad { padding: 15px 16px; }
.widget.open .widget-body { padding-bottom: 0; }
@media (max-width: 900px) { .widget-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .widget-grid { grid-template-columns: 1fr; } .widget { grid-column: span 1 !important; } }

.widget-pool { position: relative; display: inline-block; }
.widget-pool-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 10; width: 290px; max-height: 340px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px;
}
.widget-pool-item { display: block; width: 100%; text-align: left; padding: 9px 10px; border: none; border-radius: 2px; background: none; color: var(--ink); cursor: pointer; }
.widget-pool-item:hover { background: var(--surface-2); }
.widget-pool-item strong { display: block; font-size: 12.5px; }
.widget-pool-item span { display: block; margin-top: 2px; font-size: 11px; color: var(--ink-muted); }
.widget-pool-empty { padding: 14px; color: var(--ink-muted); font-size: 12px; text-align: center; }

/* ───────────────────────── Aktivitäts-Feed ───────────────────────── */
.activity-feed { display: flex; flex-direction: column; }
.activity-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.activity-row:last-child { border-bottom: none; }
.activity-row .prov { flex: 1; color: var(--ink-muted); }
.activity-time { margin-left: auto; color: var(--ink-muted); font-family: var(--mono); font-size: 11px; white-space: nowrap; }

/* ───────────────────────── Kennzahlen-Kachel mit Sparkline (Inhalt einer .widget) ─────────────────────────
   Muster aus pwa/index.html (PWA-GambioOrdersDashboard): Zeitraum, Wert, Delta, Mini-
   Sparkline; Klick klappt eine Flächenchart samt zwei Statzellen auf. Reines SVG, keine
   Chart-Bibliothek -- Farben auf Teal statt Indigo. Traegt kein eigenes Kaestchen mehr
   (kein border/background) -- das liefert jetzt die umgebende .widget einheitlich fuer
   jede Kachelart. */
.kpi-row { display: flex; align-items: center; padding: 14px 15px; gap: 12px; cursor: pointer; }
.kpi-period { width: 56px; flex-shrink: 0; }
.kpi-period-label { font: 600 10.5px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--teal); }
.kpi-period-sub { font-size: 10.5px; color: var(--ink-muted); margin-top: 2px; }
.kpi-main { flex: 1; min-width: 0; }
.kpi-value { font: 800 1.25rem/1.1 var(--display); font-variant-numeric: tabular-nums; color: var(--ink); letter-spacing: -.02em; }
.kpi-meta { display: flex; gap: 6px; align-items: center; margin-top: 3px; font-size: 11px; color: var(--ink-muted); flex-wrap: wrap; }
.kpi-delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }
.kpi-spark { width: 58px; height: 28px; flex-shrink: 0; }
.kpi-chev { width: 15px; height: 15px; color: var(--ink-muted); flex-shrink: 0; transition: transform .18s; }
.kpi.open .kpi-chev { transform: rotate(180deg); }
.kpi-detail { max-height: 0; overflow: hidden; transition: max-height .22s ease; }
.kpi.open .kpi-detail { max-height: 230px; }
.kpi-detail-in { padding: 0 15px 16px; }
.kpi-chart-wrap { background: var(--ground); border: 1px solid var(--line); border-radius: 2px; padding: 10px 10px 6px; }
.kpi-stats-row { display: flex; gap: 16px; margin-top: 11px; }
.kpi-stat { flex: 1; min-width: 0; }
.kpi-stat-label { font: 600 9.5px var(--mono); color: var(--ink-muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-stat-val { font-size: 13px; font-weight: 700; color: var(--ink); margin-top: 2px; font-variant-numeric: tabular-nums; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpis { grid-template-columns: 1fr; } }

/* ───────────────────────── Balkenliste (z.B. Anbieter-Mix) ───────────────────────── */
.barlist { display: flex; flex-direction: column; gap: 9px; }
.barlist-row { display: grid; grid-template-columns: 96px 1fr auto; gap: 10px; align-items: center; font-size: 12px; }
.barlist-label { font-family: var(--mono); color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; }
.barlist-track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.barlist-fill { height: 100%; background: var(--teal); border-radius: 4px; }
.barlist-val { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }

/* ───────────────────────── App-Gerüst: Login-Gate ─────────────────────────
   Jedes KiKi-Panel nutzt denselben Magic-Link-Login (kein eigenes Auth pro
   Panel) -- die Gate-Optik gehört deshalb hierher, nicht in jede Seite neu. */
#gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(145deg, rgba(21, 31, 40, .96), rgba(8, 21, 31, .92));
  border: 1px solid var(--line); border-radius: 8px; padding: 34px 32px; box-shadow: var(--shadow);
}
.gate-card .brand-icon { width: 32px; height: 32px; font-size: .85rem; margin-bottom: 18px; }
.gate-card h1 { font: 800 1.55rem/1.05 var(--display); letter-spacing: -.03em; margin: 0 0 4px; }
.gate-card .sub { color: var(--ink-muted); font-size: 12.5px; margin: 0 0 26px; }
.field { margin-bottom: 14px; }
.field label { display: block; font: 600 10.5px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--ground); color: var(--ink); font-family: var(--sans);
}
.field input:focus-visible, button:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius); border: 1px solid var(--teal);
  background: var(--teal); color: var(--accent-ink); cursor: pointer; font-weight: 600; font-size: 13.5px;
  width: 100%;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: transparent; color: var(--teal); }
.msg { font-size: 12.5px; margin-top: 12px; padding: 8px 10px; border-radius: var(--radius); display: none; border: 1px solid transparent; }
.msg.show { display: block; }
.msg.err { background: var(--bad-soft); color: var(--bad); border-color: rgba(226, 104, 92, .3); }
.msg.ok  { background: var(--good-soft); color: var(--good); border-color: rgba(53, 201, 180, .3); }

/* ───────────────────────── App-Gerüst: Kopfzeile + Navigation ───────────────────────── */
#app { display: none; }
#app.show { display: block; }
.topbar { background: var(--deep); color: var(--ink-muted); font: 600 .66rem var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.topbar-inner { max-width: 1180px; margin: 0 auto; display: flex; justify-content: space-between; gap: 18px; padding: 9px 20px; }
.topbar-inner span:first-child { color: #b9ded5; }
header.top {
  flex: 0 0 auto; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 12px 20px; display: flex; align-items: center; gap: 16px;
}
header.top .brand { display: flex; align-items: center; gap: 9px; font: 800 1.05rem var(--display); letter-spacing: -.02em; }
header.top .brand .dim { color: var(--ink-muted); font-weight: 500; }
header.top nav { display: flex; gap: 6px; margin-left: 8px; flex: 1; overflow-x: auto; }
header.top nav button {
  background: none; border: 1px solid var(--line); padding: 8px 13px; border-radius: var(--radius); color: var(--ink-muted);
  cursor: pointer; font-size: 12.5px; white-space: nowrap;
}
header.top nav button.active { background: var(--teal); color: var(--accent-ink); border-color: var(--teal); font-weight: 600; }
header.top nav button:not(.active):hover { border-color: var(--teal); color: var(--teal); }
header.top .who { font: 12px var(--mono); color: var(--ink-muted); white-space: nowrap; }
header.top .logout { background: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 11px; color: var(--ink-muted); cursor: pointer; font-size: 12px; }
header.top .logout:hover { border-color: var(--bad); color: var(--bad); }

/* ───────────────────────── KiKi 3D Avatar (Floating Panel) ───────────────────────── */
#kiki-avatar-panel {
  position: fixed; right: 20px; bottom: 20px; z-index: 999;
  width: 240px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
  display: flex; flex-direction: column; gap: 0;
  overflow: hidden; transition: opacity 0.3s ease;
}
#kiki-avatar-panel.hidden {
  opacity: 0; pointer-events: none;
}

#kiki-avatar-container {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 240px;
  background: linear-gradient(135deg, rgba(0, 210, 180, .12) 0%, rgba(0, 150, 130, .06) 100%);
  border-bottom: 1px solid var(--line);
  position: relative;
}

#kiki-avatar-canvas {
  display: block; width: 100%; height: 100%;
}

#kiki-avatar-info {
  padding: 12px 14px;
  background: var(--surface-2);
  text-align: center;
}

#kiki-avatar-status {
  margin: 0; font-size: 11px; color: var(--ink-muted);
  font-family: var(--mono); text-transform: uppercase; letter-spacing: .03em;
}
#kiki-avatar-status.thinking { color: var(--gold); font-weight: 600; }
#kiki-avatar-status.speaking { color: var(--teal); font-weight: 600; }

/* ───────────────────────── Traffic-Simulation (Floating Panel, nur lokal) ───────────────────────── */
#traffic-sim-panel {
  position: fixed; left: 20px; bottom: 20px; z-index: 999;
  width: 240px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
  overflow: hidden;
}
#traffic-sim-panel[hidden] { display: none; }
.traffic-sim-head {
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; cursor: move; user-select: none;
}
.traffic-sim-head strong { font-size: 12.5px; }
.traffic-sim-head .hint { font-size: 10px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .03em; margin-right: auto; }
.traffic-sim-close {
  appearance: none; border: none; background: transparent; color: var(--ink-muted);
  font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.traffic-sim-close:hover { color: var(--bad); }
.traffic-sim-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.traffic-sim-label { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--ink-muted); }
.traffic-sim-label input[type="range"] { width: 100%; }
.traffic-sim-label input[type="number"] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 3px;
  background: var(--ground); color: var(--ink); font-family: var(--mono); font-size: 12.5px;
}
.traffic-sim-checkbox { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-muted); }
.traffic-sim-actions { display: flex; gap: 8px; }
.traffic-sim-actions button { flex: 1; }
.traffic-sim-countdown {
  text-align: center; font-family: var(--mono); font-size: 15px; font-weight: 700;
  color: var(--teal); letter-spacing: .02em;
}
.traffic-sim-status { margin: 0; font-size: 11px; color: var(--ink-muted); line-height: 1.5; }
.traffic-sim-row { display: flex; justify-content: space-between; gap: 8px; }
.traffic-sim-row dt { color: var(--ink-muted); }
.traffic-sim-row dd { margin: 0; color: var(--ink); font-family: var(--mono); text-align: right; transition: color .15s ease; }

/* Persistenter "läuft"-Hinweis (immer sichtbar, solange die Simulation aktiv ist) +
   kurzes Aufblinken je Zeile, sobald neue Zahlen ankommen -- zwei unterschiedliche Signale:
   "läuft gerade" vs. "hier ist gerade etwas passiert". */
.traffic-sim-live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: 0 0 auto;
  animation: tsim-pulse 1.1s ease-in-out infinite;
}
@keyframes tsim-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.75); }
}
#tsim-stop:not([hidden]) { animation: tsim-btn-pulse 1.4s ease-in-out infinite; }
@keyframes tsim-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226, 104, 92, .5); }
  50% { box-shadow: 0 0 0 4px rgba(226, 104, 92, 0); }
}
.traffic-sim-row.flash dd { color: var(--teal); }
#tsim-report-btn { margin-top: 2px; }

/* ───────────────────────── Simulations-Report (grosses Popup) ───────────────────────── */
.tsim-report-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, .6);
  display: flex; align-items: center; justify-content: center;
}
.tsim-report-overlay[hidden] { display: none; }
.tsim-report-modal {
  width: min(900px, 92vw); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5); overflow: hidden;
}
.tsim-report-head {
  padding: 14px 18px; background: var(--surface-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.tsim-report-head strong { font: 800 1rem var(--display); letter-spacing: -.02em; }
.tsim-report-body { padding: 18px; overflow-y: auto; font-size: 13px; }
.tsim-report-section { margin-bottom: 22px; }
.tsim-report-section h4 {
  font: 800 .85rem var(--display); letter-spacing: -.01em; margin: 0 0 10px;
  color: var(--ink-muted); text-transform: uppercase; font-size: 11px;
}
.tsim-report-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tsim-report-kpi {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px;
}
.tsim-report-kpi .label { font-size: 10.5px; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .03em; }
.tsim-report-kpi .value { font: 700 1.1rem var(--mono); margin-top: 2px; }
.tsim-report-kpi .value.good { color: var(--good); }
.tsim-report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.tsim-report-table th, .tsim-report-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tsim-report-table th { color: var(--ink-muted); font-weight: 600; }
.tsim-report-table td.num, .tsim-report-table th.num { text-align: right; font-family: var(--mono); }
.tsim-report-table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; }

main { display: flex; flex-direction: column; flex: 1; overflow: hidden; padding: 0; }
section.view { display: none; }
section.view.active { display: flex; flex-direction: column; flex: 1; overflow: hidden; padding: 28px 20px; }
h2 { font: 800 1.6rem/1.1 var(--display); letter-spacing: -.03em; margin: 0 0 4px; }
.view-sub { color: var(--ink-muted); font-size: 13px; margin: 0 0 20px; max-width: 640px; }
.section-title { font: 800 1rem var(--display); letter-spacing: -.02em; margin: 0 0 12px; }

/* ───────────────────────── Sonstiges ───────────────────────── */
.note { font-size: 12px; color: var(--ink-muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; margin-bottom: 14px; }
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 50; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--good);
  border-radius: var(--radius); padding: 12px 14px; font-size: 12.5px; box-shadow: var(--shadow);
  display: none; animation: slidein .15s ease-out;
}
.toast.show { display: block; }
.toast.err { border-left-color: var(--bad); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

form.inline-add {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  background: linear-gradient(145deg, rgba(21, 31, 40, .92), rgba(8, 21, 31, .85));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
form.inline-add .f { display: flex; flex-direction: column; gap: 5px; }
form.inline-add label { font: 600 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
form.inline-add input, form.inline-add select {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--ground); color: var(--ink);
  font-size: 12.5px; min-width: 90px;
}
form.inline-add input:focus-visible, form.inline-add select:focus-visible { outline: 2px solid var(--teal); }

/* ───────────────────────── Schulung (Auswertung im Betreiberbereich) ─────────────────────────
   Die Lernsoftware selbst liegt unter /schulung/ und bringt ihre eigene Gestaltung
   mit; hier steht nur die Auswertung für den Betrieb. */
.cert-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cert-kpi { padding: 13px 15px; }
.cert-kpi .kpi-value { margin: 4px 0 2px; font-size: 1.5rem; }
.cert-domains { padding: 4px 15px 15px; }
.cert-dom { margin-bottom: 12px; }
.cert-dom:last-child { margin-bottom: 0; }
.cert-dom-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 5px; }
.cert-dom-head b { font-size: 13px; font-weight: 600; }
.cert-dom-head span { font: 600 12px var(--mono); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.cert-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.cert-bar i { display: block; height: 100%; border-radius: 4px; background: var(--teal); transition: width .5s ease; }
.cert-bar i.mid { background: var(--gold); }
.cert-bar i.weak { background: var(--bad); }
.grid td.num.ok { color: var(--good); }
.grid td.num.warn { color: var(--gold); }
