/* UI v3 „Cockpit" — Token-Set + Komponenten (UI-v3-Auftrag 26.10.2026, Schritt 3).
 * Eine Card-Komponente, drei Schriftstufen (Titel 20/600 · Wert 28/600 · Meta 13/400, nichts unter 12 px),
 * ein Radius, eine Schattenstufe, eine Badge-Familie. Rot nur für überfällig/fehlgeschlagen/blockiert.
 * Statt 7 <style>-Blöcken + Inline-Styles in today-v2: alles hier, als Variablen.
 */
:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-2: #f2f1ec;
  --line: #e6e4dc;
  --text: #1c1c1a;
  --text-2: #5c5b55;
  --text-3: #6f6e67;          /* kleinste Meta-Farbe, Kontrast >= 4.5:1 auf --surface */
  --accent: #1e4d8c;
  --accent-soft: #e8eef7;
  --ok: #2f6b2f;
  --ok-soft: #e7f2e4;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --bad: #a32d2d;             /* NUR überfällig / fehlgeschlagen / blockiert */
  --bad-soft: #fbe9e9;
  --neutral-soft: #efeee9;

  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  --fs-title: 20px;  --fw-title: 600;
  --fs-value: 28px;  --fw-value: 600;
  --fs-body: 14px;
  --fs-meta: 13px;   --fw-meta: 400;
  --fs-min: 12px;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 15, .06), 0 1px 1px rgba(20, 20, 15, .04);
  --gap: 16px;
  --pad: 16px;
  --bar-h: 52px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: var(--fs-body); line-height: 1.45; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
button { font: inherit; }
.v3-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ─── Kopf: Navigation + Kontextleiste (beide sticky) ─────────────────────── */
.v3-top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.v3-nav { display: flex; align-items: center; gap: 4px; height: var(--bar-h); padding: 0 var(--pad); max-width: 1320px; margin: 0 auto; }
.v3-brand { font-weight: 600; margin-right: 12px; white-space: nowrap; }
.v3-nav a.v3-area { padding: 8px 12px; border-radius: var(--radius); color: var(--text-2); text-decoration: none; white-space: nowrap; }
.v3-nav a.v3-area:hover { background: var(--surface-2); color: var(--text); }
.v3-nav a.v3-area[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.v3-nav .v3-spacer { flex: 1; }
.v3-sub { display: flex; gap: 2px; padding: 0 var(--pad) 8px; max-width: 1320px; margin: 0 auto; flex-wrap: wrap; }
.v3-sub a { padding: 4px 10px; border-radius: 999px; font-size: var(--fs-meta); color: var(--text-2); text-decoration: none; }
.v3-sub a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.v3-sub:empty { display: none; }

.v3-ctx { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px var(--pad); max-width: 1320px; margin: 0 auto;
  border-top: 1px solid var(--line); font-size: var(--fs-meta); color: var(--text-2); }
.v3-ctx select { font: inherit; font-size: var(--fs-meta); padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.v3-ctx .v3-stand { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.v3-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: var(--fs-meta); text-decoration: none; white-space: nowrap; }
.v3-btn:hover { background: var(--surface-2); }
.v3-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.v3-btn.primary:hover { filter: brightness(1.08); }
.v3-btn[disabled] { opacity: .5; cursor: default; }

.v3-menu { position: relative; }
.v3-menu-list { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; display: none; }
.v3-menu.open .v3-menu-list { display: block; }
.v3-menu-list a, .v3-menu-list button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px;
  color: var(--text); text-decoration: none; cursor: pointer; font-size: var(--fs-body); }
.v3-menu-list a:hover, .v3-menu-list button:hover { background: var(--surface-2); }

/* ─── Seite + Raster ──────────────────────────────────────────────────────── */
.v3-main { max-width: 1320px; margin: 0 auto; padding: var(--pad); display: grid; gap: var(--gap); }
.v3-grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.v3-grid-4 { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.v3-grid-2 > #zahlen .v3-grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
#zahlen { min-width: 0; }
@media (max-width: 700px) { .v3-grid-2 { grid-template-columns: 1fr; } }

/* ─── EINE Card-Komponente ────────────────────────────────────────────────── */
.v3-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0; scroll-margin-top: 140px; }
.v3-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px var(--pad) 8px; }
.v3-card-title { margin: 0; font-size: var(--fs-title); font-weight: var(--fw-title); line-height: 1.25; }
.v3-card-meta { font-size: var(--fs-meta); font-weight: var(--fw-meta); color: var(--text-3); text-align: right; }
.v3-card-body { padding: 4px var(--pad) 12px; flex: 1; min-width: 0; }
.v3-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px var(--pad); border-top: 1px solid var(--line); font-size: var(--fs-meta); color: var(--text-3); }
.v3-card-foot a { text-decoration: none; }
.v3-card.is-stale .v3-card-body { opacity: .55; }
.v3-card.is-stale .v3-stale-note { display: flex; }
.v3-stale-note { display: none; gap: 8px; align-items: center; margin: 0 var(--pad) 10px; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); font-size: var(--fs-meta); color: var(--text-2); }
details.v3-card > summary { list-style: none; cursor: pointer; }
details.v3-card > summary::-webkit-details-marker { display: none; }
details.v3-card > summary .v3-card-title::before { content: "▸ "; color: var(--text-3); }
details.v3-card[open] > summary .v3-card-title::before { content: "▾ "; }

/* Zustände: Skeleton in Kartenform, Leer mit nächster Aktion, Unbekannt ≠ Null */
.v3-skel { display: grid; gap: 10px; }
.v3-skel i { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), #e9e8e2, var(--surface-2)); background-size: 200% 100%; animation: v3-shimmer 1.2s infinite; }
.v3-skel i.big { height: 28px; width: 40%; }
.v3-skel i:nth-child(3n) { width: 70%; }
@keyframes v3-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .v3-skel i { animation: none; } }
.v3-empty { padding: 14px 0; color: var(--text-2); }
.v3-empty .v3-btn { margin-top: 8px; }
.v3-unknown { color: var(--text-3); font-style: italic; }

/* ─── Werte, Zeilen, Tabellen ─────────────────────────────────────────────── */
.v3-value { font-size: var(--fs-value); font-weight: var(--fw-value); line-height: 1.1; font-variant-numeric: tabular-nums; }
.v3-meta { font-size: var(--fs-meta); color: var(--text-3); }
.v3-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.v3-row:first-child { border-top: 0; }
.v3-row-main { flex: 1; min-width: 0; }
.v3-row-title { font-weight: 600; overflow-wrap: anywhere; }
.v3-row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.v3-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.v3-table th { text-align: left; font-size: var(--fs-meta); font-weight: 600; color: var(--text-3); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.v3-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.v3-table tr:last-child td { border-bottom: 0; }
.v3-table .num { text-align: right; }
.v3-scroll-x { overflow-x: auto; }

/* ─── EINE Badge-Familie ─────────────────────────────────────────────────── */
.v3-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: var(--fs-min); font-weight: 600; line-height: 1.5; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  background: var(--neutral-soft); color: var(--text-2); }
.v3-badge.ok { background: var(--ok-soft); color: var(--ok); }
.v3-badge.warn { background: var(--warn-soft); color: var(--warn); }
.v3-badge.bad { background: var(--bad-soft); color: var(--bad); }
.v3-badge.info { background: var(--accent-soft); color: var(--accent); }
.v3-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.v3-dot.ok { background: var(--ok); } .v3-dot.warn { background: #c08825; } .v3-dot.bad { background: var(--bad); } .v3-dot.none { background: transparent; border: 1px solid var(--text-3); }

/* Kennzahl mit Miniverlauf */
.v3-kpi .v3-card-body { display: grid; gap: 6px; }
.v3-delta { font-size: var(--fs-meta); color: var(--text-2); }
.v3-spark { width: 100%; height: 34px; display: block; }
.v3-spark path { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.v3-spark circle { fill: var(--accent); }

/* Zeitleiste */
.v3-day { font-size: var(--fs-meta); font-weight: 600; color: var(--text-2); padding: 12px 0 4px; }
.v3-day:first-child { padding-top: 0; }
.v3-time { width: 52px; flex: none; font-size: var(--fs-meta); color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ─── Chat-Panel rechts ───────────────────────────────────────────────────── */
.v3-chat { position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100vw); background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0,0,0,.08); z-index: 40; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s ease; visibility: hidden; }
.v3-chat.open { transform: none; visibility: visible; }
.v3-chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px var(--pad); border-bottom: 1px solid var(--line); }
.v3-chat-body { flex: 1; min-height: 0; padding: 8px; overflow: auto; }
.v3-chat #karli-chat-root { height: calc(100vh - 80px) !important; min-height: 0 !important; grid-template-columns: 180px 1fr !important; }
@media (prefers-reduced-motion: reduce) { .v3-chat { transition: none; } }

/* Kompatibilität: die eingebettete Umami-Karte (public/js/umamiCard.js) nutzt ov-*-Klassen aus today-v2 */
#ov-umami .ov-card-title { font-size: var(--fs-body); font-weight: 600; margin-bottom: 10px; }
#ov-umami .ov-card-title small { font-weight: 400; color: var(--text-3); font-size: var(--fs-min); }
#ov-umami .ov-row-label { font-size: var(--fs-min); color: var(--text-3); }
#ov-umami .ov-empty { padding: 12px; color: var(--text-2); }

.v3-toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius); z-index: 60; font-size: var(--fs-body); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Schmale Bildschirme: Bereiche in eigene, seitlich scrollbare Zeile, keine Seitenbreite über 100 % */
@media (max-width: 760px) {
  .v3-top { position: static; } /* klebend wäre der Kopf hier ein Drittel des Bildschirms */
  .v3-nav { flex-wrap: wrap; height: auto; padding: 8px var(--pad); row-gap: 6px; }
  #v3-areas { order: 3; width: 100%; overflow-x: auto; }
  #v3-chat-open .v3-meta { display: none; }
  .v3-ctx .v3-stand { margin-left: 0; }
}

/* ─── Filter-Chips, Auswahl in Zeilen, Gruppen-Zeilen (Unterbereiche, 29.10.2026) ─── */
.v3-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.v3-chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  font-size: var(--fs-meta); color: var(--text-2); text-decoration: none; background: var(--surface); }
.v3-chip:hover { background: var(--surface-2); }
.v3-chip[aria-current="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.v3-select { font: inherit; font-size: var(--fs-meta); padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: 100%; }
.v3-select[aria-invalid="true"] { border-color: var(--warn); }
.v3-table tr.v3-group th { background: var(--surface-2); color: var(--text-2); font-size: var(--fs-meta); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.v3-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap); margin-bottom: 12px; }
@media (max-width: 720px) { .v3-grid-3 { grid-template-columns: 1fr; } }
.v3-kpi-mini { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.v3-kpi-mini .v3-value { font-size: 22px; margin: 2px 0 4px; }
.v3-row.is-muted { opacity: .72; }

/* ─── Wissen: Suche, Liste mit Detail, Formular, Aufklapp-Einträge (29.10.2026) ─── */
.v3-suche { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.v3-suche input { flex: 1 1 220px; min-width: 0; font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
a.v3-row-link { color: inherit; text-decoration: none; }
a.v3-row-link:hover, a.v3-row-link[aria-current="true"] { background: var(--surface-2); }
.v3-split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@media (min-width: 1100px) { .v3-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } .v3-split-detail { position: sticky; top: 8px; } }
.v3-split-detail:empty { display: none; }
.v3-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.v3-form { display: grid; gap: 10px; }
.v3-form label { display: grid; gap: 4px; font-size: var(--fs-meta); color: var(--text-2); }
.v3-form input, .v3-form textarea { font: inherit; font-size: var(--fs-body); padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); min-width: 0; }
.v3-form-zeile { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.v3-aufklapp { border-top: 1px solid var(--line); padding: 10px 0; }
.v3-aufklapp:first-of-type { border-top: 0; }
.v3-aufklapp summary { cursor: pointer; list-style: revert; }
.v3-aufklapp[open] .v3-text { margin-top: 8px; }
.v3-row-main .v3-meta, .v3-row-main > div { overflow-wrap: anywhere; }
.v3-table tr.is-muted td { opacity: .72; }
.v3-kpi-mini .v3-value-text { font-size: var(--fs-body); font-weight: 600; line-height: 1.4; }
.v3-card-head { flex-wrap: wrap; row-gap: 4px; } .v3-card-meta { min-width: 0; }
