/* ==========================================================================
   dachvox design system  (M7.5 · Task A1)
   Single stylesheet for the unified /app. Tokens + reset + every component.
   No build step, no framework, self-hosted fonts. Theming via [data-theme].
   ========================================================================== */

@import url('fonts/fonts.css');

/* --------------------------------------------------------------------------
   Design tokens
   -------------------------------------------------------------------------- */
:root {
  --font: 'Inter', system-ui, sans-serif;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-press: #4f46e5;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --transition: 150ms ease;
  --sidebar-w: 232px;
  /* AA-safe accent derivatives (review round 1). #6366f1 under white text is
     4.47:1 and #818cf8 is 2.98:1 — both <4.5:1 — so FILLED controls carrying
     white text use this darker, theme-invariant ramp. --accent/--accent-hover/
     --accent-press stay verbatim for borders, rings and non-text marks
     (3:1 non-text bar, which #6366f1 passes everywhere it is used). */
  --accent-fill: #4f46e5;        /* rest:  6.29:1 under #fff */
  --accent-fill-hover: #4338ca;  /* hover: 7.90:1 under #fff */
  --accent-fill-press: #3730a3;  /* press: 9.93:1 under #fff */
}

[data-theme=dark] {
  --bg: #0b0f19;
  --surface: #111827;
  --surface-2: #1f2937;
  --border: #273043;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  /* accent-as-TEXT: dark needs a LIGHTER accent to clear 4.5:1
     (4.92:1 on --surface-2 .. 6.42:1 on --bg; 5.03:1 on the nav tint) */
  --accent-text: #818cf8;
  /* status-as-TEXT (review round 1b): dark base hexes already clear 4.5:1 on
     every dark background (worst case --surface-2: 7.64 / 8.79 / 5.31) */
  --ok-text: #34d399;
  --warn-text: #fbbf24;
  --err-text: #f87171;
  /* dim-as-TEXT (H1 round 2): the .badge--dim 12px text carrier. Dark base
     --text-dim #9ca3af already clears 4.5:1 on --surface-2 (5.78:1), so the
     dark dim-text is the base hex; light needs a darker variant (see below). */
  --dim-text: #9ca3af;
  /* .btn-danger hover fill (round 1c): explicit, LIGHTER in dark theme —
     10.09:1 under the button's --bg text (#0b0f19) */
  --err-fill-hover: #fca5a5;
}

[data-theme=light] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #64748b;
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  /* accent-as-TEXT: light needs a DARKER accent to clear 4.5:1
     (5.15:1 on the nav tint .. 6.29:1 on --surface) */
  --accent-text: #4f46e5;
  /* status-as-TEXT (review round 1b): the light base hexes fail 4.5:1 as small
     text (--ok 3.44..3.77, --warn 2.91..3.19, --err 4.41 on --surface-2), so
     text routes through these darker variants (>=4.58:1 on every light bg).
     Base --ok/--warn/--err stay for dots, borders, tints and fills. */
  --ok-text: #047857;
  --warn-text: #b45309;
  --err-text: #b91c1c;
  /* dim-as-TEXT (H1 round 2): light --text-dim #64748b on --surface-2 (the
     .badge--dim 12px carrier bg) is only 4.34:1 — fails small-text 4.5:1. This
     darker slate #5e6a7d measures 5.00:1 on --surface-2 (and 5.48:1 on
     --surface). Base --text-dim stays for the badge dot + non-text muted UI. */
  --dim-text: #5e6a7d;
  /* .btn-danger hover fill (round 1c): explicit, DARKER in light theme —
     a brightness() filter pushed #dc2626 to 4.21:1 under the near-white --bg
     text; #b91c1c measures 6.18:1 under #f8fafc */
  --err-fill-hover: #b91c1c;
}

/* --------------------------------------------------------------------------
   Reset / base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video, canvas { display: block; max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  --spinner: var(--text);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  color: var(--text);
  transition: background var(--transition), border-color var(--transition),
              color var(--transition), transform var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary { --spinner: #fff; background: var(--accent-fill); color: #fff; }
.btn-primary:hover { background: var(--accent-fill-hover); }
.btn-primary:active { background: var(--accent-fill-press); }

.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-text); }

.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger { --spinner: var(--bg); background: var(--err); color: var(--bg); }
.btn-danger:hover { background: var(--err-fill-hover); }

.btn-sm { min-height: 34px; padding: 0 var(--space-3); font-size: 13px; border-radius: var(--radius-s); }

/* Loading state: hide label, paint a spinner. */
.btn[data-loading] { color: transparent; pointer-events: none; }
.btn[data-loading]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.1em;
  height: 1.1em;
  margin: -0.55em 0 0 -0.55em;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--spinner) 35%, transparent);
  border-top-color: var(--spinner);
  animation: dv-spin 0.6s linear infinite;
}

@keyframes dv-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Form fields
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label { font-size: 14px; font-weight: 500; color: var(--text); }

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px var(--space-3);
  font-size: 16px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field input::placeholder,
.field textarea::placeholder { color: var(--text-dim); }

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

.field select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.field-help { font-size: 13px; color: var(--text-dim); }
.field-error { font-size: 13px; color: var(--err-text); font-weight: 500; }

.field[data-invalid] input,
.field[data-invalid] select,
.field[data-invalid] textarea { border-color: var(--err); }
.field[data-invalid] input:focus,
.field[data-invalid] textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--err) 28%, transparent); }

/* --------------------------------------------------------------------------
   Switch (toggle)
   -------------------------------------------------------------------------- */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; min-height: 44px; }
.switch input {
  appearance: none;
  flex: 0 0 auto;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background var(--transition), border-color var(--transition);
  cursor: pointer;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform var(--transition), background var(--transition);
}
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-5);
}

/* --------------------------------------------------------------------------
   Table
   -------------------------------------------------------------------------- */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
}
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap th,
.table-wrap td { padding: var(--space-3) var(--space-4); text-align: left; overflow-wrap: anywhere; }
.table-wrap thead th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
.table-wrap tbody tr + tr td { border-top: 1px solid var(--border); }
.table-wrap tbody tr:hover td { background: var(--surface-2); }

/* Reusable clamped table cell (calls.js summary, tickets.js): caps width and
   holds long text to 2 lines with an ellipsis so one row can't balloon the
   table. Pair with title=<full text> on the cell for the full value on hover. */
.cell-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  max-width: 420px;
}

/* card-mode: on narrow screens, rows become stacked cards */
@media (max-width: 640px) {
  .table-wrap { border: none; background: transparent; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-m);
    margin-bottom: var(--space-3);
    padding: var(--space-2) var(--space-3);
  }
  .table-wrap td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    border: none !important;
    padding: var(--space-2) 0;
  }
  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-dim);
  }
}

/* dataTable() bespoke mobile cards (Task A2): when dataTable() is handed a
   mobileCard() renderer it emits a parallel .table-cards list beside a
   [data-has-cards] table; swap table↔cards at the 640px breakpoint. Without a
   mobileCard() the plain table falls back to the data-label card mode above. */
.table-cards { display: none; flex-direction: column; gap: var(--space-3); }
@media (max-width: 640px) {
  .table-wrap[data-has-cards] { display: none; }
  .table-wrap[data-has-cards] + .table-cards { display: flex; }
}

/* Operations-page toolbar (Task C4): a search field that grows next to page
   actions (New Customer); wraps the actions below on narrow viewports. */
.list-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.list-toolbar > .field { flex: 1 1 240px; }

/* --------------------------------------------------------------------------
   Filter bar + pager

   .filter-bar is its own class, NOT .list-toolbar: pages select their own
   call-to-action with `.list-toolbar .btn-primary`, and a filter bar sharing
   that class would capture the selector. Same reason the active preset is
   `.is-active` rather than `.btn-primary`.
   -------------------------------------------------------------------------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.filter-bar > .field { flex: 1 1 240px; }

.filter-presets { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.filter-presets .btn.is-active {
  --spinner: #fff;
  background: var(--accent-fill);
  color: #fff;
  border-color: transparent;
}
.filter-presets .btn.is-active:hover { background: var(--accent-fill-hover); }
.filter-custom { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.filter-custom[hidden] { display: none; }

.filter-date {
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  min-height: 34px; /* matches .btn-sm, so the row sits on one baseline */
}
.filter-date:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Pushes the paused hint + Refresh to the trailing edge of the toolbar. */
.filter-right { display: flex; align-items: center; gap: var(--space-3); margin-left: auto; }
.filter-paused { font-size: 12px; color: var(--text-dim); }
.filter-paused[hidden], .filter-right > .btn[hidden] { display: none; }

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
  flex-wrap: wrap;
}
.pager-summary { margin-right: auto; font-size: 13px; color: var(--text-dim); }

@media (max-width: 640px) {
  .filter-right { margin-left: 0; width: 100%; }
  .pager-summary { width: 100%; margin-bottom: var(--space-2); }
}

/* --------------------------------------------------------------------------
   Badge
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}
.badge--ok   { background: color-mix(in srgb, var(--ok) 14%, var(--surface));   border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
.badge--ok::before   { background: var(--ok); }
.badge--warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 45%, var(--border)); }
.badge--warn::before { background: var(--warn); }
.badge--err  { background: color-mix(in srgb, var(--err) 14%, var(--surface));  border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.badge--err::before  { background: var(--err); }
.badge--dim  { color: var(--dim-text); } /* AA small-text carrier (H1 round 2) */
.badge--dim::before  { background: var(--text-dim); } /* dot = non-text (3:1 ok) */

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tab {
  padding: var(--space-3) var(--space-4);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
}
.modal-backdrop[data-open] { display: flex; }
.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-5);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.modal-title { font-size: 18px; margin-bottom: var(--space-3); }
/* Body copy inside a modal/confirm dialog (Task A2 · confirmDialog()). Full
   --text (not dim) so the explanatory line always clears AA. */
.modal-body { font-size: 14px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-5); }

@media (max-width: 640px) {
  .modal-backdrop { padding: 0; }
  .modal { max-width: none; height: 100%; border-radius: 0; border: none; }
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 360px;
  z-index: 200;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-m);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  font-size: 14px;
}
.toast--ok  { border-left-color: var(--ok); }
.toast--err { border-left-color: var(--err); }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-dim);
}
.empty-icon { font-size: 40px; line-height: 1; opacity: 0.6; }
.empty-title { color: var(--text); font-weight: 600; font-size: 16px; }

/* --------------------------------------------------------------------------
   Skeleton (shimmer)
   -------------------------------------------------------------------------- */
.skeleton {
  height: 14px;
  border-radius: var(--radius-s);
  background: linear-gradient(90deg,
    var(--surface-2) 25%,
    color-mix(in srgb, var(--border) 70%, var(--surface-2)) 37%,
    var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: dv-shimmer 1.4s ease infinite;
}
.skeleton + .skeleton { margin-top: var(--space-2); }
.skeleton--title { height: 20px; width: 45%; }
.skeleton--line-sm { width: 70%; }

@keyframes dv-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* --------------------------------------------------------------------------
   KPI stat tile
   -------------------------------------------------------------------------- */
.kpi {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
}
.kpi-label { font-size: 13px; color: var(--text-dim); }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 13px; font-weight: 600; }
.kpi-delta--up { color: var(--ok-text); }
.kpi-delta--down { color: var(--err-text); }

/* --------------------------------------------------------------------------
   Menu (dropdown)
   -------------------------------------------------------------------------- */
.menu {
  min-width: 200px;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: 14px;
  color: var(--text);
  border-radius: var(--radius-s);
  text-align: left;
  transition: background var(--transition);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item--danger { color: var(--err-text); }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }

/* --------------------------------------------------------------------------
   Dropzone
   -------------------------------------------------------------------------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6);
  text-align: center;
  color: var(--text-dim);
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-l);
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.dropzone:hover,
.dropzone[data-drag] {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
/* R4 (D1 review): the file input overlay is opacity:0, so its own focus ring is
   invisible — surface KEYBOARD focus on the dropzone tile itself. Mirrors the
   .field input focus ring so tabbing to the upload target is visible. */
.dropzone:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.dropzone-icon { font-size: 28px; opacity: 0.7; }

/* Knowledge (Wissen) page (Task D1) — structural only. The file input overlays
   the whole dropzone so the entire tile is a click-to-browse target; a
   [data-loading] dropzone dims and stops accepting input while an upload runs
   (the design-system loading signal, mirroring .btn[data-loading]). */
.dropzone { position: relative; }
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.dropzone[data-loading] { pointer-events: none; opacity: 0.6; }
.dropzone[data-loading]::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: dv-spin 0.6s linear infinite;
}

.kb-import { display: grid; gap: var(--space-4); margin-bottom: var(--space-6); }
.kb-crawl-card { display: flex; flex-direction: column; gap: var(--space-3); }
.kb-crawl-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }
.kb-crawl-row > .field { flex: 1 1 200px; }

.kb-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.kb-section-title { font-size: 18px; font-weight: 600; color: var(--text); }

.kb-groups { display: flex; flex-direction: column; gap: var(--space-4); }
.kb-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  overflow: hidden;
  background: var(--surface);
}
.kb-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.kb-group-title { font-weight: 600; color: var(--text); }
.kb-item {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  align-items: start;
  font-size: 14px;
}
.kb-item + .kb-item { border-top: 1px solid var(--border); }
.kb-item-q { color: var(--text); line-height: 1.5; overflow-wrap: anywhere; min-width: 0; }
.kb-item-a { color: var(--text-dim); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.kb-item-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
@media (max-width: 640px) {
  .kb-item { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Bars (audio / activity visualizer)
   -------------------------------------------------------------------------- */
.bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 32px; }
.bars > span {
  width: 4px;
  height: 30%;
  background: var(--accent);
  border-radius: 2px;
  animation: dv-bars 0.9s ease-in-out infinite alternate;
}
.bars > span:nth-child(2) { animation-delay: 0.12s; }
.bars > span:nth-child(3) { animation-delay: 0.24s; }
.bars > span:nth-child(4) { animation-delay: 0.36s; }
.bars > span:nth-child(5) { animation-delay: 0.18s; }
.bars > span:nth-child(6) { animation-delay: 0.06s; }
.bars > span:nth-child(7) { animation-delay: 0.30s; }

@keyframes dv-bars {
  from { height: 20%; }
  to   { height: 100%; }
}

/* --------------------------------------------------------------------------
   Bar chart (data viz — Task A2 · barChart()). Distinct from .bars (the audio
   visualizer above): fixed-height plot whose bar heights encode data. The bar
   height % is the one inline style barChart() is allowed to set.
   -------------------------------------------------------------------------- */
.barchart { display: flex; align-items: flex-end; gap: var(--space-3); height: 160px; padding: var(--space-3); }
.barchart-col { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); flex: 1 1 0; min-width: 0; height: 100%; }
.barchart-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.barchart-bar {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: var(--radius-s) var(--radius-s) 0 0;
  transition: height var(--transition);
}
.barchart-label { font-size: 12px; color: var(--text-dim); }
/* Mobile: the ~14 date labels butt together on a ~340px axis. Shrink them and
   hide every other one so the axis stays legible (halves the visible labels). */
@media (max-width: 640px) {
  .barchart-label { font-size: 10px; }
  .barchart-col:nth-child(even) .barchart-label { visibility: hidden; }
}

/* --------------------------------------------------------------------------
   Insights page (Task E1): KPI grid, card section heading, topic-pill chips.
   Structural only — colours/typography come from existing tokens.
   -------------------------------------------------------------------------- */
.insights-page { display: flex; flex-direction: column; gap: var(--space-5); }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
}
.card-heading { font-size: 16px; margin: 0 0 var(--space-3); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chip-count { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-dim); }
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Overview / Übersicht home (Task E2). Structural only — colours/typography
   come from existing tokens; reuses .kpi/.kpi-grid/.card/.card-heading/.empty/
   .barchart/.field-help. Cards and teasers stack below 640px.
   -------------------------------------------------------------------------- */
.overview-page { display: flex; flex-direction: column; gap: var(--space-5); }
.overview-stamp { margin: 0; }
.teaser-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}
.teaser-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
}
.teaser-head .card-heading { margin: 0; }
.teaser-more { font-size: 13px; white-space: nowrap; }
.teaser-list { display: flex; flex-direction: column; }
.teaser-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}
.teaser-item:first-child { border-top: 0; padding-top: 0; }
.teaser-item-title { font-size: 14px; }
.teaser-item-meta { font-size: 12px; color: var(--text-dim); }
@media (max-width: 640px) {
  .teaser-grid { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   App shell (sidebar + topbar). Responsive: full sidebar / icon rail / drawer.
   -------------------------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 480px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); min-height: 44px; }
.sidebar-brand .wordmark { font-weight: 600; font-size: 15px; }
/* Brand-as-home-link (app shell): wordmark keeps the theme text color, not link accent. */
a.sidebar-brand { color: var(--text); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-title {
  padding: var(--space-2) var(--space-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-s);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); color: var(--accent-text); }
.nav-item-icon { flex: 0 0 auto; width: 20px; text-align: center; font-size: 16px; }
.nav-item[hidden] { display: none; }   /* beats .nav-item's display:flex — used by the optional Orders module gate (C5) */

/* Page-level shell (app.html): the shell IS the viewport, not a boxed demo. */
.shell--page { min-height: 100vh; min-height: 100dvh; border: 0; border-radius: 0; }

/* Footer group (Einstellungen) pinned to the bottom of the sidebar column. */
.sidebar-footer { margin-top: auto; }

.shell-main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding: 0 var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-spacer { flex: 1; }
.shell-body { flex: 1; padding: var(--space-5); overflow: auto; }

.drawer-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;   /* H1 mobile sweep: the hamburger is the primary <640px nav */
  height: 44px;  /* control — meet the 44px touch-target minimum (was 40px). */
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 20px;
}
.drawer-toggle:hover { background: var(--surface-2); }

/* Topbar user menu: anchors the .menu dropdown under its toggle button. */
.user-menu { position: relative; }
.user-menu .menu { position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: 30; }

/* Topbar tenant switcher (Task F1, super-admin only): the same anchored-.menu
   dropdown as .user-menu, plus a search field over a scrollable listbox. The
   long-tenant-name trigger truncates so the topbar never overflows. */
.tenant-menu { position: relative; }
.tenant-menu > .btn {
  display: block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tenant-menu .menu { position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: 30; min-width: 240px; }
.tenant-menu-search { padding: var(--space-1) var(--space-1) var(--space-2); border-bottom: 1px solid var(--border); margin-bottom: var(--space-1); }
.tenant-menu-list { max-height: 280px; overflow: auto; }
.tenant-menu-list .menu-item[aria-selected="true"] { font-weight: 600; }
.tenant-menu-list .field-help { padding: var(--space-2) var(--space-3); }
@media (max-width: 640px) {
  .tenant-menu > .btn { max-width: 110px; }
}

/* Admin (Tenants) page, Task F1: the users list inside the Users modal. */
.admin-users-list { max-height: 340px; overflow: auto; }
.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.admin-user-row:last-child { border-bottom: 0; }
.admin-user-row > div { min-width: 0; }

/* 640–1024px: collapse to an icon rail */
@media (max-width: 1024px) {
  .shell { grid-template-columns: 64px 1fr; }
  .sidebar { padding: var(--space-3) var(--space-2); align-items: center; }
  .nav-item { justify-content: center; padding: var(--space-2); }
  .nav-label,
  .nav-group-title,
  .sidebar-brand .wordmark { display: none; }
}

/* <640px: off-canvas hamburger drawer */
@media (max-width: 640px) {
  .shell { grid-template-columns: 1fr; position: relative; }
  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    padding: var(--space-4);
    align-items: stretch;
    transform: translateX(-100%);
    transition: transform var(--transition);
    z-index: 40;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
  }
  .nav-item { justify-content: flex-start; padding: var(--space-2) var(--space-3); }
  .nav-label,
  .nav-group-title,
  .sidebar-brand .wordmark { display: inline; }
  .shell[data-drawer-open] .sidebar { transform: translateX(0); }
  /* Dim scrim behind the open drawer: sits above page content but below the
     z-index:40 sidebar so tapping it reads as "outside" (the click-outside
     close handler lives in app.html). */
  .shell[data-drawer-open]::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.45);
  }
  .drawer-toggle { display: inline-flex; }
}

/* --------------------------------------------------------------------------
   Auth pages  (Task B1: login / signup / reset-password)
   Desktop split — left brand panel + right form card; single column (form
   only) under 768px. Composes the shared .field/.btn/.card atoms; these are
   the only auth-layout structural additions.
   -------------------------------------------------------------------------- */
.auth {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-8) var(--space-7);
  background: radial-gradient(120% 120% at 0% 0%,
              color-mix(in srgb, var(--accent) 22%, var(--bg)) 0%, var(--bg) 60%);
  border-right: 1px solid var(--border);
}
.auth-brand-logo { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--text); }
.auth-brand-tagline {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  max-width: 22ch;
  color: var(--text);
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-7) var(--space-5);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.auth-card-head { display: flex; justify-content: flex-end; gap: var(--space-2); }
.auth-title { font-size: 24px; }
.auth-sub { color: var(--text-dim); font-size: 15px; margin-top: calc(-1 * var(--space-2)); }

.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-form[hidden] { display: none; }   /* beats .auth-form's display:flex */
.auth-form .btn-primary { margin-top: var(--space-1); }

.auth-alt { text-align: center; font-size: 14px; }
.auth-foot { text-align: center; color: var(--text-dim); font-size: 14px; }
.auth-preview { font-size: 13px; color: var(--text-dim); }
.auth-preview .slug { color: var(--accent-text); font-weight: 600; }
.auth-row { display: flex; gap: var(--space-4); }
.auth-row > .field { flex: 1; min-width: 0; }

@media (max-width: 768px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-panel { align-items: flex-start; padding: var(--space-6) var(--space-4); }
  .auth-row { flex-direction: column; }   /* email + language stack */
}

/* ==========================================================================
   Gallery-only scaffolding  (dev QA page: app/static/app/gallery.html)
   NOT part of the product design system — layout helpers for the demo page.
   Kept here because the task ships no separate gallery stylesheet.
   ========================================================================== */
.gallery { max-width: 1280px; margin: 0 auto; padding: var(--space-5); }
.gallery-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
}
.gallery-bar h1 { font-size: 18px; }
.gallery-bar .topbar-spacer { flex: 1; }
.gallery-panes { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.theme-pane {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-5);
}
.theme-pane > header { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: var(--space-4); text-transform: uppercase; letter-spacing: 0.06em; }
.gallery-sec { margin-bottom: var(--space-6); }
.gallery-sec > h3 { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: var(--space-3); }
.gallery-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.gallery-stack { display: flex; flex-direction: column; gap: var(--space-4); }
.gallery-full { margin-top: var(--space-6); }
/* tiny demo-copy helpers (gallery only — avoids inline styles) */
.g-muted { color: var(--text-dim); }
.g-mt2 { margin-top: var(--space-2); }

@media (max-width: 900px) {
  .gallery-panes { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Operations record card  (Task C1 — tickets; reusable by C2–C5)
   Structure only: the stacked layout for one list row on <640px, built by a
   page's mobileCard() renderer inside dataTable()'s .table-cards list. Colour
   and spacing come from existing tokens — no new colour decisions here. The
   monospaced .rec-id is also reused for the id column cell in the desktop table.
   -------------------------------------------------------------------------- */
.rec-card { display: flex; flex-direction: column; gap: var(--space-2); }
.rec-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.rec-badges { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.rec-title { font-weight: 600; line-height: 1.4; }
.rec-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  font-size: 13px;
  color: var(--text-dim);
}
.rec-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
}

/* --------------------------------------------------------------------------
   Operations detail view  (Task C3 — emails; reusable by later detail modals)
   Structure only: a vertical section stack, a preformatted scrollable text
   block for message/reply bodies, and a wider modal for content-heavy detail
   views (the base .modal caps at 440px; the old email modal was ~700px, which
   an email body plus an editable draft still needs). Colour from tokens only.
   -------------------------------------------------------------------------- */
.detail-stack { display: flex; flex-direction: column; gap: var(--space-4); }
.rec-pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: var(--space-3);
  max-height: 40vh;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.5;
}
.modal:has(> .detail-stack) { max-width: 720px; }

/* --------------------------------------------------------------------------
   Settings form  (Task D2 — assistant; the dirty→sticky-save-bar pattern
   reused by D3 channels, D4 embed, F2 settings)
   Structure only: field rows that stack under 640px, a small avatar preview,
   a disclosure toggle for the Advanced section, and a sticky footer save bar.
   Colour comes from existing tokens — no new colour decisions here.
   -------------------------------------------------------------------------- */
.settings-form { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-heading { font-size: 16px; }
.settings-row { display: flex; gap: var(--space-4); }
.settings-row > .field { flex: 1; min-width: 0; }
.settings-form textarea { min-height: 140px; }
.settings-avatar img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.disclosure-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  align-self: flex-start;
  min-height: 44px;
  padding: var(--space-2) 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.disclosure-toggle::before { content: '\25B8'; transition: transform var(--transition); }
.disclosure-toggle[aria-expanded='true']::before { transform: rotate(90deg); }
.settings-advanced { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-advanced[hidden] { display: none; }   /* beats the display:flex above */
.settings-savebar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  margin-top: var(--space-2);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.settings-savebar[hidden] { display: none; }   /* beats the display:flex above */

@media (max-width: 640px) {
  .settings-row { flex-direction: column; }   /* fields stack on phones */
}

/* --------------------------------------------------------------------------
   Einstellungen page (Task F2). Structure only: stacked section cards, the
   read-only account key/value rows, the language/theme choice rows and the
   change-password submit row. Colour comes from existing tokens — no new
   colour decisions.
   -------------------------------------------------------------------------- */
.settings-page { display: flex; flex-direction: column; gap: var(--space-4); }
.settings-kv { display: flex; gap: var(--space-3); font-size: 14px; }
.settings-kv-label { min-width: 160px; color: var(--text-dim); }
.settings-kv-value { color: var(--text); word-break: break-word; }
.settings-choice { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.settings-submit { display: flex; justify-content: flex-end; }

@media (max-width: 640px) {
  .settings-kv { flex-direction: column; gap: var(--space-1); }   /* rows stack on phones */
}

/* --------------------------------------------------------------------------
   Channels (Kanäle) page — sub-tabbed settings (Task D3). Structure only:
   scrollable sub-tabs, tab-panels, indented sub-capabilities, status lines and
   the action row for the email / data-source Test + Remove buttons. Colour comes
   from existing tokens — no new colour decisions.
   -------------------------------------------------------------------------- */
.channels-tabs { overflow-x: auto; flex-wrap: nowrap; }   /* sub-tabs scroll on narrow screens */
.channels-tabs .tab { white-space: nowrap; }
.channels-panel { margin-top: var(--space-4); }
.channels-panel[hidden] { display: none; }   /* guard: plain-div panels hide on the UA rule; belt-and-braces */
.channels-sub { display: flex; flex-direction: column; gap: var(--space-4); margin-left: var(--space-4); }
.channels-sub[hidden] { display: none; }
.channels-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.channels-status { font-size: 13px; color: var(--text-dim); }
.channels-status--ok { color: var(--ok-text); }
.channels-status--err { color: var(--err-text); }
.channels-status--warn { color: var(--warn-text); }

/* --------------------------------------------------------------------------
   Embed (Einbindung) page (Task D4). Structure only: the go-live checklist
   rows, the colour picker + swatch + hex row, the pure-client live preview box
   (whose colour + radius are the ONLY inline style VALUES the page sets;
   position is this static class), the snippet code block with its overlaid copy
   button, and the action row. Colour comes from existing tokens — no new colour.
   -------------------------------------------------------------------------- */
/* Go-live checklist */
.golive-progress { font-size: 13px; color: var(--text-dim); }
.golive-banner {
  font-size: 14px;
  font-weight: 600;
  color: var(--ok-text);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
}
.golive-banner[hidden] { display: none; }
.checklist { display: flex; flex-direction: column; }
.checklist-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.checklist-row:last-child { border-bottom: none; }
.checklist-dot { flex-shrink: 0; font-weight: 700; line-height: 1.5; }
.checklist-dot.is-done { color: var(--ok-text); }
.checklist-dot.is-todo { color: var(--text-dim); }
.checklist-body { flex: 1; min-width: 0; }
.checklist-label { font-size: 14px; font-weight: 600; color: var(--text); }
.checklist-label.is-done { color: var(--text-dim); text-decoration: line-through; }
.checklist-hint { font-size: 13px; color: var(--text-dim); margin-top: var(--space-1); }
.checklist-action { flex-shrink: 0; align-self: center; }

/* Theme controls + live preview */
.embed-color-row { display: flex; align-items: center; gap: var(--space-3); }
.embed-color-row input[type='color'] {
  width: 44px;
  height: 44px;
  padding: 2px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  cursor: pointer;
}
.embed-color-row input[type='text'] { flex: 1; min-width: 0; }
.embed-color-swatch {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.embed-radius-field { max-width: 220px; }
.embed-preview {
  position: relative;
  height: 140px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;              /* bottom-right (default) */
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface-2);
  overflow: hidden;
}
.embed-preview[data-pos='bottom-left'] { justify-content: flex-start; }
.embed-preview-launcher {
  width: 52px;
  height: 52px;
  border-radius: 50%;                     /* default; overridden inline by radius */
  background: var(--accent);              /* overridden inline by primary colour */
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Snippet code block + overlaid copy button; action rows */
.embed-code { position: relative; }
.embed-snippet {
  margin: 0;
  padding: var(--space-3);
  padding-right: 92px;                    /* room for the overlaid copy button */
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.embed-copy { position: absolute; top: var(--space-2); right: var(--space-2); }
.embed-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }

/* Playground — SA "test any tenant's chatbot" chat surface (pages/playground.js) */
/* Two-pane SA bench: fill the content area (chat + developer log side by side).
   The old single-column 860px cap squeezed the log pane to ~350px (unreadable
   for JSON debug lines); widen it and fill the viewport height so the log has
   room and scrolls in place. Offset = topbar (60) + .shell-body padding (24*2). */
.pg-wrap { display: flex; flex-direction: column; gap: var(--space-3);
           max-width: 1200px; height: calc(100dvh - 108px); min-height: 480px; }
.pg-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.pg-title { font-weight: 600; color: var(--text); margin-right: auto; }
/* Playground actions are always real; keep the risk visible without a mode toggle. */
.pg-actions-banner { padding: 8px 12px; border-radius: var(--radius-2, 8px);
                     font-size: 13px; font-weight: 500; line-height: 1.4;
                     background: color-mix(in srgb, var(--err) 14%, var(--surface));
                     border: 1px solid color-mix(in srgb, var(--err) 55%, var(--border));
                     color: var(--err-text); }
.pg-msgs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
}
.pg-empty { margin: auto; color: var(--text-dim); text-align: center; }
.pg-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-m);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pg-user { align-self: flex-end; background: var(--accent-fill); color: #fff; }
.pg-bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.pg-tool {
  align-self: flex-start;
  padding: 2px 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}
.pg-sys { align-self: center; color: var(--text-dim); font-size: 13px; }
.pg-inputbar { display: flex; gap: var(--space-2); align-items: flex-end; }
.pg-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

/* Live voice pipeline status — superadmin playground only. */
.pg-runtime {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--surface);
}
.pg-runtime-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 9px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: .65;
}
.pg-runtime[data-stage="connecting"] .pg-runtime-dot,
.pg-runtime[data-stage="preparing"] .pg-runtime-dot,
.pg-runtime[data-stage="searching"] .pg-runtime-dot,
.pg-runtime[data-stage="generating"] .pg-runtime-dot,
.pg-runtime[data-stage="synthesizing"] .pg-runtime-dot {
  background: var(--accent);
  opacity: 1;
  animation: pg-runtime-pulse 1s ease-in-out infinite;
}
.pg-runtime[data-stage="listening"] .pg-runtime-dot { background: var(--ok); opacity: 1; }
.pg-runtime[data-stage="speaking"] .pg-runtime-dot { background: #8b5cf6; opacity: 1; }
.pg-runtime[data-stage="error"] .pg-runtime-dot { background: var(--err); opacity: 1; }
@keyframes pg-runtime-pulse {
  0%, 100% { transform: scale(.75); box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 35%, transparent); }
  50% { transform: scale(1); box-shadow: 0 0 0 5px transparent; }
}
.pg-runtime-copy { min-width: 0; flex: 1; }
.pg-runtime-label { color: var(--text-dim); font-size: 11px; line-height: 1.2; }
.pg-runtime-phase { color: var(--text); font-size: 13px; font-weight: 600; line-height: 1.35; }
.pg-runtime-model {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  background: var(--surface-2);
  font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.pg-runtime-elapsed {
  min-width: 42px;
  text-align: right;
  color: var(--text-dim);
  font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-reduced-motion: reduce) {
  .pg-runtime-dot { animation: none !important; }
}

/* ---- playground: two panes + developer log (SA test bench) ---- */
.pg-cols { display: flex; gap: 16px; min-height: 0; flex: 1; align-items: stretch; }
.pg-main { flex: 1 1 58%; min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.pg-log { flex: 1 1 42%; min-width: 260px; display: flex; flex-direction: column;
          border: 1px solid var(--border); border-radius: var(--radius-m);
          background: var(--surface); }
.pg-log.collapsed { flex: 0 0 auto; min-width: 0; }
.pg-log.collapsed .pg-log-body, .pg-log.collapsed .pg-log-chips { display: none; }
/* Narrow/mobile: stack the two panes so neither collapses to a sliver. */
@media (max-width: 860px) {
  .pg-cols { flex-direction: column; }
  .pg-log { min-width: 0; }
  .pg-runtime-model { max-width: 140px; }
}
.pg-log-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px;
               border-bottom: 1px solid var(--border); }
.pg-log-title { font-weight: 600; font-size: 13px; flex: 1; color: var(--text); }
.pg-log-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px;
                border-bottom: 1px solid var(--border); }
.pg-chip { font: 11px ui-monospace, Menlo, Consolas, monospace; padding: 2px 8px;
           border-radius: 10px; border: 1px solid var(--border); color: var(--text);
           cursor: pointer; user-select: none; opacity: .95; }
.pg-chip.off { opacity: .35; text-decoration: line-through; }
.pg-log-body { flex: 1; overflow-y: auto; padding: 6px 8px; color: var(--text);
               font: 11px/1.5 ui-monospace, Menlo, Consolas, monospace; }
.pg-ll { white-space: pre-wrap; word-break: break-word; padding: 1px 0; }
.pg-ll-t { color: var(--text-dim); margin-right: 6px; }
.pg-ll-c { display: inline-block; min-width: 52px; margin-right: 6px;
           font-weight: 700; }
/* Category badge colors — dark theme (default). Overridden below for light. */
.pg-ll[data-cat="engine"] .pg-ll-c { color: #7aa2f7; }
.pg-ll[data-cat="kb"]     .pg-ll-c { color: #9ece6a; }
.pg-ll[data-cat="tool"]   .pg-ll-c { color: #e0af68; }
.pg-ll[data-cat="stt"]    .pg-ll-c { color: #2ac3de; }
.pg-ll[data-cat="tts"]    .pg-ll-c { color: #bb9af7; }
.pg-ll[data-cat="timing"] .pg-ll-c { color: #c0caf5; }
.pg-ll[data-cat="error"]  .pg-ll-c { color: #f7768e; }
/* Light theme: darker variants that clear ~4.5:1 on --surface (#ffffff). */
[data-theme=light] .pg-ll[data-cat="engine"] .pg-ll-c { color: #2563eb; }
[data-theme=light] .pg-ll[data-cat="kb"]     .pg-ll-c { color: #166534; }
[data-theme=light] .pg-ll[data-cat="tool"]   .pg-ll-c { color: #b45309; }
[data-theme=light] .pg-ll[data-cat="stt"]    .pg-ll-c { color: #0e7490; }
[data-theme=light] .pg-ll[data-cat="tts"]    .pg-ll-c { color: #7c3aed; }
[data-theme=light] .pg-ll[data-cat="timing"] .pg-ll-c { color: #475569; }
[data-theme=light] .pg-ll[data-cat="error"]  .pg-ll-c { color: #dc2626; }
.pg-log-body.hide-engine .pg-ll[data-cat="engine"], .pg-log-body.hide-kb .pg-ll[data-cat="kb"],
.pg-log-body.hide-tool .pg-ll[data-cat="tool"], .pg-log-body.hide-stt .pg-ll[data-cat="stt"],
.pg-log-body.hide-tts .pg-ll[data-cat="tts"], .pg-log-body.hide-timing .pg-ll[data-cat="timing"],
.pg-log-body.hide-error .pg-ll[data-cat="error"] { display: none; }
.pg-voicebar { display: flex; gap: 8px; align-items: center; }
