/*
 * Design-System (UI1a, docs/design.md) – Stil „Klar & sachlich“ (Gründer 2026-11-17): hell, feine Linien statt Schatten,
 * mittlere Dichte, Hell/Dunkel automatisch. Gemeinsam für Dashboard, Landingpage und spätere App; ausgeliefert als
 * /design.css (core/vite-design.ts). Nur Systemschriften (CSP und DSGVO: keine fremden Schriftquellen).
 *
 * Marke: Die Seite setzt zur Laufzeit nur Roh-Werte (--brand, --brand-fg, --brand-bg, --brand-ink, --brand-text-light,
 * --brand-text-dark) aus core/design-brand.ts. Alle übrigen Tokens leiten sich hier ab. Komponenten tragen das Präfix
 * ui-, damit sie neben den alten Seitenstilen (public/style.css) bestehen, bis UI1b/UI1c umbauen.
 */

:root {
  /* Marke (Standard = operator.yaml dashboard.*; die Seite überschreibt per style.setProperty) */
  --brand: #1f4e79;
  --brand-fg: #ffffff;
  --brand-bg: #f6f7f9;
  --brand-ink: #1b1f24;
  --brand-text-light: #1f4e79;
  --brand-text-dark: #6d8ca8;

  /* Schrift */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --fs-xs: 0.75rem;   /* 12 px: Kennzeichen, Tabellenköpfe */
  --fs-sm: 0.8125rem; /* 13 px: Nebeninfo */
  --fs-md: 0.875rem;  /* 14 px: Standard im Dashboard */
  --fs-lg: 1rem;      /* 16 px: Standard auf der Website */
  --fs-xl: 1.125rem;
  --fs-2xl: 1.375rem; /* Seitentitel */
  --fs-3xl: 1.75rem;
  --fs-4xl: clamp(2rem, 4.5vw, 2.625rem); /* Website-Kopf */
  --lh-tight: 1.15;
  --lh: 1.5;

  /* Abstände (4-px-Raster) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 56px;

  /* Radien und Schatten */
  --r-sm: 4px; --r: 6px; --r-md: 8px; --r-lg: 12px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.12);

  /* Flächen und Text (hell) */
  --bg: var(--brand-bg);
  --surface: #ffffff;
  --surface-2: #f2f4f7;
  --fg: var(--brand-ink);
  --muted: #5b6472;
  --line: #e4e7ec;
  --line-strong: #c4cad3;
  --brand-text: var(--brand-text-light);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, var(--surface));
  --focus: var(--brand-text);

  /* Zustände (unabhängig von der Markenfarbe) */
  --ok: #1e7a46; --ok-soft: #e5f4ea;
  --warn: #8a5d00; --warn-soft: #fdf3d7;
  --crit: #b42318; --crit-soft: #fdeceb; --on-crit: #ffffff;

  /* Ampel (CRM4) */
  --light-red: #d92d20; --light-yellow: #e9a900; --light-green: #12a150; --light-white: #ffffff;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318; --surface: #161b22; --surface-2: #1c222b; --fg: #e6e9ee; --muted: #9aa4b1;
    --line: #262d37; --line-strong: #3a4352;
    --brand-text: var(--brand-text-dark);
    --brand-soft: color-mix(in srgb, var(--brand) 28%, var(--surface));
    --ok: #4cc38a; --ok-soft: #12291e; --warn: #f0b429; --warn-soft: #2b2410; --crit: #ff7b70; --crit-soft: #331a18; --on-crit: #1a0a08;
    --light-white: #e6e9ee;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318; --surface: #161b22; --surface-2: #1c222b; --fg: #e6e9ee; --muted: #9aa4b1;
  --line: #262d37; --line-strong: #3a4352;
  --brand-text: var(--brand-text-dark);
  --brand-soft: color-mix(in srgb, var(--brand) 28%, var(--surface));
  --ok: #4cc38a; --ok-soft: #12291e; --warn: #f0b429; --warn-soft: #2b2410; --crit: #ff7b70; --crit-soft: #331a18; --on-crit: #1a0a08;
  --light-white: #e6e9ee;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ---------- Grundlage ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-family: var(--font-sans); font-size: 100%; line-height: var(--lh); color: var(--fg); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--fg); }
h1, h2, h3 { line-height: var(--lh-tight); text-wrap: balance; letter-spacing: -0.01em; }
a { color: var(--brand-text); text-underline-offset: 3px; }
img { max-width: 100%; }
input, select, textarea, button { font: inherit; color: inherit; }
::selection { background: var(--brand-soft); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Sprungmarke zum Inhalt (Tastatur) */
.ui-skip-link { position: absolute; left: var(--sp-4); top: -100px; z-index: 100; background: var(--surface); color: var(--fg); padding: var(--sp-2) var(--sp-3); border-radius: var(--r); box-shadow: var(--shadow-md); }
.ui-skip-link:focus { top: var(--sp-4); }
.ui-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Knopf ---------- */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 36px; padding: 0 var(--sp-3); border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--fg); font-size: var(--fs-md); font-weight: 500; line-height: 1.2;
  white-space: nowrap; text-decoration: none; cursor: pointer; transition: background-color 0.12s, border-color 0.12s;
}
.ui-btn:hover { background: var(--surface-2); }
.ui-btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-fg); }
.ui-btn--primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.ui-btn--quiet { background: transparent; border-color: transparent; color: var(--brand-text); }
.ui-btn--quiet:hover { background: var(--brand-soft); }
.ui-btn--danger { background: var(--crit); border-color: var(--crit); color: var(--on-crit); }
.ui-btn--sm { min-height: 30px; padding: 0 var(--sp-2); font-size: var(--fs-sm); }
.ui-btn--lg { min-height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-lg); }
.ui-btn:disabled, .ui-btn[aria-disabled="true"] { opacity: 0.55; cursor: default; }

/* ---------- Karte ---------- */
.ui-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.ui-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.ui-card__title { margin: 0; font-size: var(--fs-md); font-weight: 600; }
.ui-card__body { padding: var(--sp-4); }
.ui-card__row { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.ui-card__row:last-child { border-bottom: 0; }

/* Kennzahl */
.ui-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); }
.ui-kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); }
.ui-kpi__label { color: var(--muted); font-size: var(--fs-xs); }
.ui-kpi__value { display: block; font-size: var(--fs-2xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.ui-kpi__detail { color: var(--muted); font-size: var(--fs-sm); }
/* DASH5: Kachel als Link auf die gefilterte Liste */
.ui-kpi--link { width: 100%; display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; text-align: left; cursor: pointer; }
.ui-kpi--link:hover { border-color: var(--brand-text); }

/* ---------- Tabelle ---------- */
.ui-table-wrap { overflow-x: auto; }
.ui-table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
.ui-table th { text-align: left; font-weight: 500; font-size: var(--fs-xs); color: var(--muted); padding: var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--line); white-space: nowrap; }
.ui-table td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.ui-table tr:last-child td { border-bottom: 0; }
.ui-table .num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Formular ---------- */
.ui-field { display: grid; gap: var(--sp-1); margin: 0 0 var(--sp-4); }
.ui-label { font-size: var(--fs-sm); font-weight: 500; }
.ui-input, .ui-select, .ui-textarea {
  width: 100%; min-height: 38px; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--fg); font-size: var(--fs-md);
}
.ui-textarea { min-height: 96px; resize: vertical; }
.ui-input:focus-visible, .ui-select:focus-visible, .ui-textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.ui-hint { color: var(--muted); font-size: var(--fs-sm); }
.ui-error { color: var(--crit); font-size: var(--fs-sm); }
/* PCC34: Fortschrittsbalken (Kampagnen-Liste) – Text daneben trägt die Zahl, der Balken nur die Anschauung */
.ui-progress-row { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); align-items: center; }
.ui-progress { flex: 1 1 120px; max-width: 320px; height: 8px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.ui-progress__fill { height: 100%; background: var(--brand-text); border-radius: inherit; }
.ui-field--invalid .ui-input, .ui-field--invalid .ui-select, .ui-field--invalid .ui-textarea { border-color: var(--crit); }
.ui-check { display: flex; gap: var(--sp-2); align-items: flex-start; font-size: var(--fs-md); }
.ui-check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }

/* ---------- Navigation ---------- */
.ui-sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: var(--sp-4) var(--sp-3); display: grid; align-content: start; gap: var(--sp-1); }
.ui-brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 650; padding: var(--sp-1) var(--sp-2) var(--sp-4); }
.ui-brand img { height: 28px; max-width: 140px; object-fit: contain; }
.ui-nav { display: grid; gap: 2px; }
.ui-nav-item {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 7px var(--sp-3); border: 0; border-radius: var(--r);
  background: transparent; color: var(--muted); font-size: var(--fs-md); text-align: left; text-decoration: none; cursor: pointer;
}
.ui-nav-item:hover { background: var(--surface-2); color: var(--fg); }
.ui-nav-item[aria-current="page"], .ui-nav-item[aria-current="true"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.ui-nav-item__count { margin-left: auto; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
/* PDB34: Ungelesen-Zähler als Pille in Markenfarbe */
.ui-nav-item__count--badge { min-width: 1.5em; padding: 0 6px; border-radius: 999px; background: var(--brand); color: var(--brand-fg); font-weight: 600; line-height: 1.5; text-align: center; }
.ui-topbar { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-3) var(--sp-6); background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* ---------- Hinweis ---------- */
.ui-notice { display: grid; gap: var(--sp-1); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2); font-size: var(--fs-md); }
.ui-notice--info { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand-text) 30%, transparent); }
.ui-notice--ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.ui-notice--warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.ui-notice--crit { background: var(--crit-soft); border-color: color-mix(in srgb, var(--crit) 35%, transparent); }
.ui-notice__title { font-weight: 600; }

/* ---------- Kennzeichen und Ampel ---------- */
.ui-badge { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 1px var(--sp-2); border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.ui-badge--info { background: var(--brand-soft); color: var(--brand-text); }
.ui-badge--ok { background: var(--ok-soft); color: var(--ok); }
.ui-badge--warn { background: var(--warn-soft); color: var(--warn); }
.ui-badge--crit { background: var(--crit-soft); color: var(--crit); }
.ui-light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ui-light--red { background: var(--light-red); }
.ui-light--yellow { background: var(--light-yellow); }
.ui-light--green { background: var(--light-green); }
.ui-light--white { background: var(--light-white); border: 1px solid var(--line-strong); }

/* ---------- UI1b: Bausteine für Listen, Reiter, Menü (Dashboard, später App) ---------- */
/* Liste: Einträge als Zeilen in einer Fläche (Anrufe, Anliegen, Aufgaben, Verlauf) */
.ui-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.ui-list__item { display: grid; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); min-width: 0; }
.ui-list__item:last-child { border-bottom: 0; }
.ui-list__head { display: flex; gap: var(--sp-2) var(--sp-3); align-items: center; justify-content: space-between; flex-wrap: wrap; }
.ui-list__item--off { opacity: 0.65; }
.ui-list__item--off strong { text-decoration: line-through; }
.ui-meta { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); align-items: center; font-size: var(--fs-sm); color: var(--muted); min-width: 0; }
.ui-meta strong { color: var(--fg); font-weight: 600; }
.ui-text { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.ui-section-title { margin: var(--sp-2) 0 0; font-size: var(--fs-lg); font-weight: 600; }
.ui-subtitle { margin: 0; font-size: var(--fs-md); font-weight: 600; }
/* Reiter / Zeitraum-Umschalter: Knöpfe mit aria-pressed bzw. aria-selected */
.ui-segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); max-width: 100%; }
.ui-segmented button { min-height: 32px; padding: 0 var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 500; cursor: pointer; }
.ui-segmented button:hover { color: var(--fg); }
.ui-segmented button[aria-pressed="true"], .ui-segmented button[aria-selected="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow-sm); }
/* Text-Knopf (z. B. Firmenname öffnet die Kundenkarte) */
.ui-btn--link { min-height: 0; padding: 0; border: 0; background: none; color: var(--brand-text); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; white-space: normal; text-align: left; }
.ui-btn--link:hover { background: none; color: var(--fg); }
/* Beschreibungsliste (Angaben) */
.ui-dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); margin: 0; }
.ui-dl dt { color: var(--muted); font-size: var(--fs-sm); }
.ui-dl dd { margin: 0; overflow-wrap: anywhere; }
/* Mittig gestellte Einzelkarte (Anmeldung, Meldungen, öffentliche Seiten) */
.ui-center { min-height: 100vh; display: grid; place-content: center; gap: var(--sp-4); padding: var(--sp-6) var(--sp-4); }
.ui-center > .ui-card { width: min(420px, calc(100vw - 2 * var(--sp-4))); }
.ui-center > .ui-brand { justify-content: center; padding: 0; }
/* SEC17b: QR-Code der Zwei-Faktor-Einrichtung immer auf Weiß (auch im Dunkelmodus lesbar), Schlüssel umbrechbar */
.ui-mfa-qr { background: #fff; padding: var(--sp-2); border-radius: var(--r-md); justify-self: center; }
.ui-mfa-secret { overflow-wrap: anywhere; font-family: ui-monospace, monospace; }
/* Seitenleiste: Kopf mit Menü-Knopf (nur mobil), Fuß mit Mandant und Abmelden */
.ui-sidebar__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.ui-sidebar__head .ui-brand { padding-bottom: var(--sp-1); min-width: 0; }
.ui-sidebar__foot { display: grid; gap: var(--sp-2); margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); font-size: var(--fs-sm); }
.ui-sidebar__foot .ui-muted { overflow-wrap: anywhere; }
.ui-menu-toggle { display: none; }
@media (min-width: 761px) {
  .ui-shell > .ui-sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
@media (max-width: 760px) {
  .ui-menu-toggle { display: inline-flex; }
  .ui-sidebar--collapsible { padding: var(--sp-2) var(--sp-3); }
  .ui-sidebar.ui-sidebar--collapsible .ui-nav, .ui-sidebar--collapsible .ui-sidebar__foot { display: none; }
  .ui-sidebar--collapsible.is-open .ui-nav { display: grid; overflow: visible; padding-top: var(--sp-2); }
  .ui-sidebar--collapsible.is-open .ui-sidebar__foot { display: grid; }
  .ui-sidebar--collapsible.is-open .ui-nav-item { width: 100%; }
  /* Tabelle stapeln: jede Zeile als Block, Spaltenname aus data-label */
  .ui-table--stack thead { display: none; }
  .ui-table--stack tr { display: grid; gap: var(--sp-1); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
  .ui-table--stack tr:last-child { border-bottom: 0; }
  .ui-table--stack td { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--sp-2); padding: 0; border: 0; text-align: left; }
  .ui-table--stack td::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-xs); }
  .ui-table--stack .num { text-align: left; }
}
/* Fließtext mit Absätzen und Listen (z. B. Antwort des KI-Assistenten) und aufklappbarer Bereich */
.ui-prose { display: grid; gap: var(--sp-2); margin: 0; overflow-wrap: anywhere; }
.ui-prose p { margin: 0; white-space: pre-line; }
.ui-prose ul, .ui-prose ol, ul.ui-prose, ol.ui-prose { margin: 0; padding-left: var(--sp-5); display: grid; gap: var(--sp-1); }
.ui-disclosure summary { cursor: pointer; font-weight: 600; font-size: var(--fs-md); }
.ui-disclosure[open] summary { margin-bottom: var(--sp-2); }
.ui-table td.ui-text { min-width: 16rem; }
.ui-table time { white-space: nowrap; }
@media (max-width: 760px) { .ui-table td.ui-text { min-width: 0; } }

/* ---------- Seitengerüst ---------- */
.ui-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.ui-main { padding: var(--sp-6) var(--sp-8); display: grid; gap: var(--sp-5); align-content: start; min-width: 0; }
.ui-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); align-items: start; }
@media (max-width: 760px) {
  .ui-shell { grid-template-columns: 1fr; align-content: start; }
  .ui-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .ui-sidebar .ui-nav { display: flex; overflow-x: auto; }
  .ui-sidebar .ui-nav-item { width: auto; white-space: nowrap; }
  .ui-main { padding: var(--sp-4); }
  .ui-grid-2 { grid-template-columns: 1fr; }
}
.ui-page-title { margin: 0; font-size: var(--fs-2xl); font-weight: 650; }
.ui-muted { color: var(--muted); }
.ui-stack { display: grid; gap: var(--sp-4); }
.ui-row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.ui-grow { flex: 1; min-width: 0; }
/* PCRM21a: Summenzeile (Bezeichnung links, Betrag rechts), auch bei 375 px in einer Zeile */
.ui-row--between { justify-content: space-between; flex-wrap: nowrap; }
/* PVA2: Gesprächsdetail – Eckdaten als Liste, Transkript als Gesprächsverlauf (mobil einspaltig) */
.ui-facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-1) var(--sp-3); margin: 0; }
.ui-facts dt { color: var(--muted); }
.ui-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ui-transcript { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.ui-transcript li { display: grid; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); max-width: 48rem; }
.ui-transcript__assistant { background: var(--surface-2); }
.ui-transcript__user { border: 1px solid var(--line); justify-self: end; }
@media (max-width: 480px) { .ui-facts { grid-template-columns: 1fr; } .ui-transcript__user { justify-self: stretch; } }
/* PDB8: Aufnahme im Gesprächsdetail – Player über die volle Kartenbreite, höchstens so breit wie der Verlauf */
.ui-audio { display: block; width: 100%; max-width: 48rem; }
