/* Genie OS – God's Eye UI (Look & Feel · RUN 2)
   -------------------------------------------------------------------
   All appearance comes from semantic tokens. Themes live in
   /static/themes/<id>.css and only override tokens. Presence rules in
   /static/presence.css. Motion respects data-motion + prefers-reduced-motion.
   Density scales spacing via data-density.  Legacy token aliases at the
   bottom keep older selectors working while templates finish migrating.
   ------------------------------------------------------------------- */

/* ===================================================================
   1. Semantic tokens (default = aurora).  Individual themes override
      the same variables via `:root[data-theme="<id>"]`.
   =================================================================== */
:root,
:root[data-theme="aurora"] {
  color-scheme: dark;

  /* Surfaces (LEVEL 0-5 per vision §5) */
  --bg-canvas: #060817;
  --bg-atmosphere: radial-gradient(1200px 700px at 55% 18%, #131A50 0%, transparent 70%),
                   radial-gradient(900px 900px at 88% 92%, rgba(70, 60, 180, 0.35), transparent 70%),
                   #060817;
  --bg-surface: #0D1230;
  --bg-surface-elevated: #141A3E;
  --bg-overlay: #1B2350;
  --bg-sidebar: rgba(13, 18, 48, 0.72);

  /* Text */
  --text-primary: #E9EBF8;
  --text-secondary: #A9B3CE;
  --text-tertiary: #6B7695;
  --text-inverse: #060817;

  /* Borders */
  --border-subtle: rgba(155, 150, 255, 0.10);
  --border-default: rgba(155, 150, 255, 0.18);
  --border-strong: rgba(155, 150, 255, 0.32);

  /* Accents */
  --accent-primary: #7457FF;
  --accent-secondary: #4B4FFF;
  --accent-tertiary: #9C71FF;
  --accent-primary-ink: #FFFFFF;

  /* State */
  --success: #4ADE80;
  --success-ink: #052E10;
  --warning: #F0B455;
  --warning-ink: #2B1A04;
  --danger: #F77474;
  --danger-ink: #2E0B0B;
  --info: #467BFF;
  --info-ink: #051428;

  /* Glow */
  --glow-primary: rgba(116, 87, 255, 0.55);
  --glow-secondary: rgba(70, 123, 255, 0.35);

  /* Shadows */
  --shadow-small: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-medium: 0 8px 24px rgba(0, 0, 0, 0.40);
  --shadow-large: 0 22px 60px rgba(0, 0, 0, 0.55);
  --shadow-floating: 0 40px 90px -20px rgba(70, 60, 180, 0.55);

  /* Radii */
  --radius-small: 8px;
  --radius-medium: 12px;
  --radius-large: 16px;
  --radius-xl: 22px;
  --radius-panel: 18px;

  /* Glass */
  --glass-opacity: 0.85;
  --glass-blur: 18px;
  --panel-opacity: 0.94;

  /* Chart palette */
  --chart-1: #7457FF;
  --chart-2: #467BFF;
  --chart-3: #9C71FF;
  --chart-4: #EEE6D8;
  --chart-5: #4B4FFF;

  /* Focus ring */
  --focus-ring: rgba(155, 150, 255, 0.55);

  /* Layout */
  --sidebar-width: 250px;
  --content-max-width: 1240px;

  /* Fonts */
  --font-ui: "Inter", "Geist", ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Cormorant Garamond", "Playfair Display", Georgia,
    "Iowan Old Style", "Apple Garamond", serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Type scale (documented in DECISIONS_theme_engine.md).
     Sizes for utility work; display sizes are fluid on `.greeting`. */
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-20: 20px;
  --fs-28: 28px;
  --fs-40: 40px;
  --fs-56: 56px;
  --lh-tight: 1.15;
  --lh-snug: 1.35;
  --lh-normal: 1.5;
  --lh-relaxed: 1.65;
}

/* ===================================================================
   2. Motion & density modes.
   =================================================================== */
:root {
  --motion-micro: 180ms;
  --motion-panel: 320ms;
  --motion-cinematic: 12s;
  --motion-scale: 1;

  --density-scale: 1;
  --space-1: calc(4px * var(--density-scale));
  --space-2: calc(8px * var(--density-scale));
  --space-3: calc(12px * var(--density-scale));
  --space-4: calc(16px * var(--density-scale));
  --space-5: calc(20px * var(--density-scale));
  --space-6: calc(24px * var(--density-scale));
  --space-7: calc(32px * var(--density-scale));
  --space-8: calc(42px * var(--density-scale));
}
:root[data-motion="reduced"] {
  --motion-micro: 90ms;
  --motion-panel: 160ms;
  --motion-cinematic: 20s;
  --motion-scale: 0.6;
}
:root[data-motion="off"] {
  --motion-micro: 0ms;
  --motion-panel: 0ms;
  --motion-cinematic: 0s;
  --motion-scale: 0;
}
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-micro: 0ms;
    --motion-panel: 0ms;
    --motion-cinematic: 0s;
    --motion-scale: 0;
  }
}
:root[data-density="compact"] {
  --density-scale: 0.82;
}
:root[data-motion="off"] *,
:root[data-motion="off"] *::before,
:root[data-motion="off"] *::after {
  animation-duration: 0s !important;
  transition-duration: 0s !important;
}

/* ===================================================================
   3. Legacy token aliases (for templates that still use them).
   =================================================================== */
:root {
  --bg: var(--bg-canvas);
  --bg-elev: var(--bg-surface);
  --panel: var(--bg-surface);
  --panel-2: var(--bg-surface-elevated);
  --panel-3: var(--bg-overlay);
  --border: var(--border-default);
  --text: var(--text-primary);
  --text-dim: var(--text-secondary);
  --muted: var(--text-tertiary);
  --accent: var(--accent-primary);
  --accent-2: var(--accent-secondary);
  --accent-ink: var(--accent-primary-ink);
  --violet: var(--accent-tertiary);
  --ok: var(--success);
  --ok-ink: var(--success-ink);
  --warn: var(--warning);
  --warn-ink: var(--warning-ink);
  --err: var(--danger);
  --err-ink: var(--danger-ink);
  --pill-bg: var(--bg-surface-elevated);
  --shadow-1: var(--shadow-small);
  --shadow-2: var(--shadow-medium);
  --radius: var(--radius-medium);
  --radius-lg: var(--radius-large);
  --font: var(--font-ui);
  --mono: var(--font-mono);
  --surface-2: var(--bg-surface-elevated);
}

/* ===================================================================
   4. Reset + base typography.
   =================================================================== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg-canvas); color: var(--text-primary); min-height: 100vh; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-14);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv02", "cv03", "cv04", "ss01", "tnum";
  color: var(--text-primary);
  min-height: 100vh;
  position: relative;
}

/* Atmosphere layer — one per theme, sits behind everything, cheap to
   render (no per-frame blur), reacts to motion mode. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--bg-atmosphere);
  transition: background var(--motion-panel) ease;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(1px 1px at 20% 30%, var(--text-tertiary), transparent),
              radial-gradient(1px 1px at 70% 15%, var(--text-tertiary), transparent),
              radial-gradient(1.5px 1.5px at 85% 60%, var(--accent-primary), transparent),
              radial-gradient(1px 1px at 40% 80%, var(--text-tertiary), transparent),
              radial-gradient(1px 1px at 10% 70%, var(--accent-secondary), transparent),
              radial-gradient(1px 1px at 60% 45%, var(--text-tertiary), transparent);
  opacity: 0.35;
  animation: atmosphere-drift var(--motion-cinematic) ease-in-out infinite alternate;
}
:root[data-theme="minimal-light"] body::after,
:root[data-theme="minimal-dark"] body::after,
:root[data-theme="command-center"] body::after { opacity: 0.10; }
:root[data-theme="celestial-gold"] body::after { opacity: 0.14; }
@keyframes atmosphere-drift {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(0, -8px, 0); }
}

a { color: var(--accent-primary); text-decoration: none; transition: color var(--motion-micro) ease; }
a:hover { color: var(--accent-secondary); }
code, pre { font-family: var(--font-mono); font-size: var(--fs-12); }
pre {
  background: var(--bg-surface-elevated);
  padding: 12px 14px;
  border-radius: var(--radius-small);
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 20px 0; }

/* Visible focus for keyboard users only. */
:where(a, button, [role="button"], input, textarea, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: var(--radius-small);
}

/* ===================================================================
   5. Layout shell (base.html).
   =================================================================== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  gap: 0;
  padding: 14px 14px 14px 14px;
}

/* -- Sidebar ------------------------------------------------------- */
/* Phase 2c · D4: `aside.sidebar` statt `.sidebar`, damit das Presence-
   Variant `presence-slot.sidebar` (Chat-Topbar) NICHT vom Nav-Sidebar-
   Regelsatz eingefangen wird (Klassennamen-Kollision fuehrte zu einem
   zweiten „leeren Kreis" neben dem Genie-Kopf). */
aside.sidebar {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  padding: 18px 14px;
  position: sticky;
  top: 14px;
  height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--shadow-medium);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  font-weight: 700;
  font-size: var(--fs-20);
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.brand small {
  color: var(--text-tertiary);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-left: 4px;
  display: block;
}
.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: color-mix(in oklab, var(--accent-primary) 22%, transparent);
  border: 1px solid color-mix(in oklab, var(--accent-primary) 40%, transparent);
  flex: none;
}
.brand-mark svg { width: 16px; height: 16px; }
.brand-tag {
  color: var(--text-tertiary);
  font-size: 11px;
  padding: 0 6px;
  letter-spacing: 0.02em;
}
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group h6 {
  margin: 8px 10px 4px;
  font-size: 10.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 13.5px;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background-color var(--motion-micro) ease,
              color var(--motion-micro) ease,
              border-color var(--motion-micro) ease;
}
.nav-item .ic { width: 16px; height: 16px; flex: none; opacity: 0.9; }
.nav-item:hover { background: color-mix(in oklab, var(--accent-primary) 8%, transparent); color: var(--text-primary); text-decoration: none; }
.nav-item[aria-current="page"] {
  background: color-mix(in oklab, var(--accent-primary) 16%, transparent);
  color: var(--text-primary);
  border-color: color-mix(in oklab, var(--accent-primary) 35%, transparent);
}
/* Phase 1.1: neuer Haupt-Button "Neuer Chat". */
.nav-primary {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--accent-primary) 22%, transparent);
  border: 1px solid color-mix(in oklab, var(--accent-primary) 45%, transparent);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: background-color var(--motion-micro) ease;
}
.nav-primary:hover { background: color-mix(in oklab, var(--accent-primary) 32%, transparent); text-decoration: none; }
.nav-primary .ic { width: 18px; height: 18px; }

/* Phase 1.3: Badge am Menuepunkt Freigaben statt eines Freigabe-Balkens. */
.nav-item-badged { position: relative; padding-right: 34px; }
.nav-badge {
  position: absolute;
  right: 8px; top: 50%; transform: translateY(-50%);
  min-width: 20px; height: 20px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--warning);
  color: var(--warning-ink);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Phase 1.1: Letzte Chats — scrollbare Liste. */
.nav-recent { display: flex; flex-direction: column; min-height: 0; gap: 4px; flex: 1 1 auto; }
.nav-recent h6 {
  margin: 8px 10px 4px; font-size: 10.5px; letter-spacing: 0.10em;
  text-transform: uppercase; color: var(--text-tertiary); font-weight: 600;
}
.recent-list {
  list-style: none; margin: 0; padding: 0;
  overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 1px;
  scrollbar-gutter: stable;
}
.recent-list li a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 6px 10px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none;
  font-size: 13px;
}
.recent-list li a:hover { background: color-mix(in oklab, var(--accent-primary) 8%, transparent); color: var(--text-primary); }
.recent-list li.is-active a {
  background: color-mix(in oklab, var(--accent-primary) 16%, transparent);
  color: var(--text-primary);
}
.recent-title { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-when  { flex: 0 0 auto; color: var(--text-tertiary); font-size: 11px; font-variant-numeric: tabular-nums; }
.recent-empty { color: var(--text-tertiary); font-size: 12.5px; padding: 4px 10px; margin: 0; }

/* Fusszeile der Seitenleiste: Genie-Karte, Verbindungen, Einstellungen. */
.side-foot { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }

/* Phase 7 · 7.2: Sprach-Umschalter DE | EN. Zwei kleine, gleich
   grosse Knoepfe unter den Fusszeilen-Links. */
.lang-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 8px 2px;
}
.lang-switch-form { display: inline-flex; margin: 0; }
.lang-switch-btn {
  min-width: 34px;
  padding: 4px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background-color var(--motion-micro) ease, color var(--motion-micro) ease, border-color var(--motion-micro) ease;
}
.lang-switch-btn:hover {
  background: color-mix(in oklab, var(--accent-primary) 10%, transparent);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.lang-switch-btn.is-active {
  background: color-mix(in oklab, var(--accent-primary) 22%, transparent);
  border-color: color-mix(in oklab, var(--accent-primary) 55%, transparent);
  color: var(--text-primary);
}
.lang-switch-btn[aria-pressed="true"] { cursor: default; }
body.sidebar-collapsed .lang-switch-btn { min-width: 28px; padding: 4px; }

/* Phase 1b · B1: Attribut [hidden] muss immer durchgreifen (auch wenn
   ein spezifischerer Selektor spaeter display: block setzt). */
[hidden] { display: none !important; }

/* Phase 1.4: Genie-Karte in der Seitenleiste. */
.genie-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--accent-primary) 7%, transparent);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  color: inherit;
  transition: background-color var(--motion-micro) ease, border-color var(--motion-micro) ease;
}
.genie-card:hover { background: color-mix(in oklab, var(--accent-primary) 14%, transparent); border-color: var(--border-strong); text-decoration: none; }
.genie-card-head {
  width: 44px; height: 44px; flex: none;
  position: relative;
  border-radius: 999px;
  /* Ring als inset-shadow, damit der Border keine Content-Flaeche frisst
     und die Kind-Elemente die volle Kreisflaeche belegen (Phase 1b · B3). */
  box-shadow:
    inset 0 0 0 2px color-mix(in oklab, var(--accent-primary) 55%, transparent),
    0 0 0 4px color-mix(in oklab, var(--accent-primary) 12%, transparent);
  overflow: hidden;
  aspect-ratio: 1 / 1;
}
/* Phase 1b · B3: block-Container mit absolut positionierten Kindern,
   damit width/height: 100 % auf Orb/Avatar/Fallback wirklich greifen.
   (`display: grid; place-items: center` liess den Orb auf 6×0 px
   schrumpfen.) */
.genie-card-head .presence-slot { width: 100%; height: 100%; display: block; position: relative; }
.genie-card-head .presence-slot > .presence-orb,
.genie-card-head .presence-slot > .presence-avatar,
.genie-card-head .presence-slot > .presence-fallback {
  position: absolute; inset: 0; width: 100%; height: 100%;
}
.genie-card-head .presence-slot > .presence-symbol {
  position: absolute; inset: 12%; width: 76%; height: 76%;
}
/* Fallback bekommt Innenrand + Diamant-Skalierung, damit das Icon
   groesser ist als 80 % der Kreisflaeche (Phase 1b · B3-Test). */
.genie-card-head .presence-slot > .presence-fallback { padding: 4px; }
.genie-card-text { display: flex; flex-direction: column; min-width: 0; }
.genie-card-text b { display: block; font-size: 13px; color: var(--text-primary); font-weight: 600; }
.genie-state { font-size: 11.5px; color: var(--success); }
.genie-state[data-genie-state="listening"] { color: var(--info); }
.genie-state[data-genie-state="thinking"]  { color: var(--warning); }
.genie-state[data-genie-state="speaking"]  { color: var(--accent-primary); }
/* Bewegung nur, wenn nicht reduziert. */
[data-motion="reduced"] .genie-card-head { box-shadow: none; transition: none; }

/* Alte .side-me — Rueckwaerts-Kompatibilitaet, sichtbar nur, wenn ein Template
   sie noch direkt benutzt. Wird von .genie-card ersetzt und ausgeblendet. */
.side-me { display: none; }

/* Sidebar einklappen (Desktop). */
.sidebar-collapse-btn {
  margin-left: auto;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: transparent; border: 1px solid var(--border-subtle);
  border-radius: 8px; color: var(--text-secondary); cursor: pointer;
}
.sidebar-collapse-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.sidebar-collapse-btn svg { width: 14px; height: 14px; }
body.sidebar-collapsed aside.sidebar { width: 68px; padding-left: 8px; padding-right: 8px; --sidebar-width: 68px; }
body.sidebar-collapsed .layout { grid-template-columns: 68px 1fr; }
body.sidebar-collapsed .nav-primary span,
body.sidebar-collapsed .nav-item:not([aria-hidden]) span:not(.nav-badge),
body.sidebar-collapsed .brand > div,
body.sidebar-collapsed .nav-recent,
body.sidebar-collapsed .genie-card-text { display: none; }
body.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }
.btn-icon {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
}
.btn-icon:hover { color: var(--text-primary); border-color: var(--border-strong); }
.btn-icon svg { width: 16px; height: 16px; }

/* -- Main -------------------------------------------------------- */
.main {
  padding: 8px 20px 24px 20px;
  max-width: var(--content-max-width);
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}
.page-hd {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 4px 0 8px;
}
.page-hd .h1 { margin: 0; }
.page-hd .sub { color: var(--text-tertiary); font-size: 13.5px; }
.page-hd .spacer { flex: 1; }

/* ===================================================================
   6. Typography helpers.
   =================================================================== */
.h1 {
  font-size: var(--fs-28);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  line-height: var(--lh-tight);
  color: var(--text-primary);
}
.h1.display, .hero-display, .greeting {
  font-family: var(--font-display);
  font-weight: 500;
}
.greeting {
  font-size: clamp(34px, 4.2vw, 54px);
  line-height: 1.05;
  margin: 0;
  color: var(--text-primary);
  text-wrap: balance;
}
.greeting em {
  font-style: normal;
  color: var(--text-secondary);
  display: block;
  font-size: 0.55em;
  margin-top: 10px;
  font-family: var(--font-ui);
  font-weight: 400;
  letter-spacing: 0;
}
.h2 {
  font-size: var(--fs-16);
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 20px 0 10px;
  color: var(--text-primary);
}
.muted { color: var(--text-tertiary); }
.text-dim { color: var(--text-secondary); }
.pageintro { color: var(--text-tertiary); font-size: 13.5px; margin: 0 0 6px; max-width: 720px; }

.text-xxs { font-size: 11px; }
.text-xs { font-size: var(--fs-12); }
.text-sm { font-size: 12.5px; }
.text-md { font-size: var(--fs-13); }
.text-md-plus { font-size: 13.5px; }
.text-lg { font-size: 15px; }
.text-metric-sm { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.text-metric-md { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.text-metric-lg { font-size: var(--fs-28); font-weight: 700; letter-spacing: -0.01em; }
.text-metric-xl { font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.metric-warn   { color: var(--warning); }
.metric-danger { color: var(--danger); }
.metric-muted  { color: var(--text-tertiary); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.line-through-muted { color: var(--text-tertiary); text-decoration: line-through; }
.num { font-variant-numeric: tabular-nums; }

/* ===================================================================
   7. Grids.
   =================================================================== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 1180px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  aside.sidebar { position: relative; height: auto; top: 0; }
  .grid-2, .grid-3, .split { grid-template-columns: 1fr; }
  .main { padding: 4px; }
}

/* (Responsive rules for narrow viewports live at the bottom of this
   file so their cascade wins over the base component rules that appear
   later in this source.) */

/* ===================================================================
   8. Cards (glass + solid).
   =================================================================== */
.card {
  background: color-mix(in oklab, var(--bg-surface) calc(var(--panel-opacity) * 100%), transparent);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-panel);
  padding: 16px 18px;
  box-shadow: var(--shadow-small);
  transition: border-color var(--motion-micro) ease,
              box-shadow var(--motion-micro) ease,
              transform 90ms ease;
}
.card.glass {
  background: color-mix(in oklab, var(--bg-surface) calc(var(--glass-opacity) * 100%), transparent);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.card h3 {
  margin: 0 0 10px;
  font-size: var(--fs-13);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h3 .more {
  margin-left: auto;
  font-weight: 500;
  font-size: var(--fs-12);
  color: var(--text-tertiary);
  text-decoration: none;
}
.card h3 .more:hover { color: var(--text-primary); }
.card:hover { border-color: var(--border-default); }
.card.floating { box-shadow: var(--shadow-floating); border-color: var(--border-default); }
.card.hero { padding: 22px 24px; border-radius: var(--radius-xl); box-shadow: var(--shadow-large); }
.card.hero .greeting { margin-bottom: 4px; }

/* ===================================================================
   9. Pills, tags, badges.
   =================================================================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  letter-spacing: 0.005em;
}
.pill.ok { color: var(--success); border-color: color-mix(in oklab, var(--success) 30%, transparent); background: color-mix(in oklab, var(--success) 10%, var(--bg-surface-elevated)); }
.pill.warn { color: var(--warning); border-color: color-mix(in oklab, var(--warning) 30%, transparent); background: color-mix(in oklab, var(--warning) 10%, var(--bg-surface-elevated)); }
.pill.err { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 30%, transparent); background: color-mix(in oklab, var(--danger) 10%, var(--bg-surface-elevated)); }
.pill.info { color: var(--info); border-color: color-mix(in oklab, var(--info) 30%, transparent); background: color-mix(in oklab, var(--info) 10%, var(--bg-surface-elevated)); }
.pill.violet { color: var(--accent-tertiary); border-color: color-mix(in oklab, var(--accent-tertiary) 30%, transparent); background: color-mix(in oklab, var(--accent-tertiary) 10%, var(--bg-surface-elevated)); }
/* Solid info variant (used for high-emphasis notice pills). */
.pill.info.solid { background: var(--info); color: var(--info-ink); border-color: transparent; }
/* Inverted surface for tooltips/toasts on top of the canvas. */
.toast {
  padding: 8px 14px;
  border-radius: var(--radius-small);
  background: var(--text-primary);
  color: var(--text-inverse);
  box-shadow: var(--shadow-medium);
  font-size: var(--fs-13);
}

.badge-risk {
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.risk-R0 { background: color-mix(in oklab, var(--success) 12%, transparent); color: var(--success); border-color: color-mix(in oklab, var(--success) 30%, transparent); }
.risk-R1 { background: color-mix(in oklab, var(--accent-primary) 12%, transparent); color: var(--accent-primary); border-color: color-mix(in oklab, var(--accent-primary) 30%, transparent); }
.risk-R2 { background: color-mix(in oklab, var(--accent-tertiary) 15%, transparent); color: var(--accent-tertiary); border-color: color-mix(in oklab, var(--accent-tertiary) 30%, transparent); }
.risk-R3 { background: color-mix(in oklab, var(--warning) 15%, transparent); color: var(--warning); border-color: color-mix(in oklab, var(--warning) 35%, transparent); }
.risk-R4 { background: color-mix(in oklab, var(--danger) 15%, transparent); color: var(--danger); border-color: color-mix(in oklab, var(--danger) 35%, transparent); }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 5px;
  background: var(--bg-surface-elevated);
  font-size: 11px;
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
  word-break: break-all;
  max-width: 100%;
}

/* ===================================================================
   10. Tables.
   =================================================================== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
th {
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: transparent;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 100ms ease; }
tbody tr:hover { background: color-mix(in oklab, var(--accent-primary) 5%, transparent); }
table code { font-size: 12px; padding: 1px 5px; border-radius: 4px; background: var(--bg-surface-elevated); }

/* ===================================================================
   11. Inputs & buttons.
   =================================================================== */
input, textarea, select, button { font-family: var(--font-ui); font-size: var(--fs-14); }
input, textarea, select {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-small);
  padding: 9px 12px;
  color: var(--text-primary);
  width: 100%;
  transition: border-color var(--motion-micro) ease, box-shadow var(--motion-micro) ease;
}
input:hover, textarea:hover, select:hover { border-color: var(--border-default); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
textarea { resize: vertical; min-height: 84px; }
.form-row { margin-bottom: 12px; }
.form-row label {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-small);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color var(--motion-micro) ease,
              background-color var(--motion-micro) ease,
              color var(--motion-micro) ease,
              transform 60ms ease;
  text-decoration: none;
}
.btn:hover { border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
  border: 1px solid transparent;
  color: var(--accent-primary-ink);
  box-shadow: 0 8px 24px -8px var(--glow-primary);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.warn { background: var(--warning); color: var(--warning-ink); border-color: transparent; }
.btn.err  { background: var(--danger);  color: var(--danger-ink);  border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn.quiet:hover { color: var(--text-primary); background: color-mix(in oklab, var(--accent-primary) 8%, transparent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ===================================================================
   12. States (empty, spinner, callout).
   =================================================================== */
.empty {
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-large);
  padding: 26px 22px;
  text-align: center;
  color: var(--text-tertiary);
  background: color-mix(in oklab, var(--bg-surface-elevated) 30%, transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.empty strong { color: var(--text-secondary); font-weight: 600; }
.empty .btn { margin-top: 6px; }
.empty.small { padding: 12px; font-size: 13px; }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  animation: spin 700ms linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.callout {
  border-left: 3px solid var(--accent-primary);
  padding: 12px 14px;
  background: color-mix(in oklab, var(--accent-primary) 8%, var(--bg-surface));
  border-radius: var(--radius-small);
  margin: 16px 0;
  font-size: 13.5px;
  color: var(--text-primary);
}
.callout.warn { border-color: var(--warning); background: color-mix(in oklab, var(--warning) 10%, var(--bg-surface)); }
.callout.err  { border-color: var(--danger);  background: color-mix(in oklab, var(--danger) 10%, var(--bg-surface)); }

/* ===================================================================
   13. Timelines & streamlog.
   =================================================================== */
.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.timeline li {
  padding: 10px 12px;
  border-radius: var(--radius-small);
  background: transparent;
  border: 1px solid var(--border-subtle);
  font-size: 13.5px;
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  align-items: baseline;
}
.timeline li:hover { background: color-mix(in oklab, var(--accent-primary) 5%, transparent); }
.timeline li time {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
}
/* N3 · Projekt-Seite: Zeitangaben in normaler Schrift, nicht wie Code. */
.timeline-plain-time li time {
  font-family: inherit;
  font-size: 12px;
}

.streamlog {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  padding: 12px;
  max-height: 380px;
  overflow-y: auto;
  color: var(--text-secondary);
}
.streamlog .line { padding: 3px 0; }
.streamlog .kind {
  color: var(--accent-primary);
  font-weight: 700;
  margin-right: 8px;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.06em;
}

.progress {
  height: 6px;
  background: var(--bg-overlay);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress > div { height: 100%; transition: width var(--motion-panel) ease; }
.progress-bar { height: 100%; transition: width var(--motion-panel) ease; }
.progress-bar.ok  { background: var(--accent-primary); }
.progress-bar.warn { background: var(--warning); }
.progress-bar.err  { background: var(--danger); }

/* ===================================================================
   14. Notify bar.
   =================================================================== */
/* Phase 1.3: .notifybar entfaellt. Regel bleibt als Fallback, damit
   Vorlagen, die noch nicht migriert sind, keine kaputten Kanten zeigen. */
.notifybar { display: none; }
.notifybar--legacy { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.notify {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: 13.5px;
  color: var(--text-primary);
}
.notify.warn { border-color: color-mix(in oklab, var(--warning) 40%, transparent); background: color-mix(in oklab, var(--warning) 10%, var(--bg-surface)); color: var(--warning); }
.notify.err  { border-color: color-mix(in oklab, var(--danger)  40%, transparent); background: color-mix(in oklab, var(--danger)  10%, var(--bg-surface)); color: var(--danger); }
.notify .btn { padding: 4px 12px; font-size: var(--fs-12); }

/* ===================================================================
   15. Ask / command field (hero + chat composer).
   =================================================================== */
.ask {
  display: flex;
  align-items: center;
  gap: 6px;
  background: color-mix(in oklab, var(--bg-surface) calc(var(--glass-opacity) * 100%), transparent);
  border: 1px solid color-mix(in oklab, var(--accent-primary) 40%, var(--border-default));
  border-radius: 999px;
  padding: 6px 6px 6px 20px;
  box-shadow: 0 12px 40px -12px var(--glow-primary),
              0 4px 24px -8px var(--glow-secondary),
              inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  max-width: 640px;
  transition: border-color var(--motion-micro) ease, box-shadow var(--motion-micro) ease;
}
.ask:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--focus-ring),
              0 12px 40px -12px var(--glow-primary);
}
.ask textarea, .ask input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  min-width: 0;
  padding: 8px 4px;
  resize: none;
  min-height: 24px;
  max-height: 168px;  /* ~6 lines at 28 px line-height (P1 RUN 3b) */
  overflow-y: auto;
  line-height: 1.5;
}
.ask textarea::placeholder, .ask input::placeholder { color: var(--text-tertiary); }
.ask textarea:focus, .ask input:focus { outline: none; box-shadow: none; border: 0; }
.ask .ib {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  flex: none;
}
.ask .ib:hover { color: var(--text-primary); background: color-mix(in oklab, var(--accent-primary) 12%, transparent); }
.ask .ib.go {
  background: var(--accent-primary);
  color: var(--accent-primary-ink);
  box-shadow: 0 0 20px -6px var(--glow-primary);
}
.ask .ib.go:hover { filter: brightness(1.1); }
.ask .ib svg { width: 18px; height: 18px; }
.ask .ib.recording { background: var(--danger); color: var(--danger-ink); animation: pulse-rec 1.4s ease-in-out infinite; }
.ask .ib.transcribing { background: var(--warning); color: var(--warning-ink); }
@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--danger) 45%, transparent); }
  70%      { box-shadow: 0 0 0 10px transparent; }
}
.mic-hint { font-size: var(--fs-12); color: var(--text-tertiary); align-self: center; padding: 0 8px; }

/* Chip row */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border-subtle);
  background: color-mix(in oklab, var(--bg-surface) calc(var(--glass-opacity) * 100%), transparent);
  backdrop-filter: blur(calc(var(--glass-blur) * 0.5));
  -webkit-backdrop-filter: blur(calc(var(--glass-blur) * 0.5));
  border-radius: 999px;
  padding: 7px 14px;
  font-size: var(--fs-13);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  text-decoration: none;
  transition: border-color var(--motion-micro) ease, color var(--motion-micro) ease;
}
.chip:hover { border-color: var(--accent-primary); color: var(--text-primary); }
.chip small { color: var(--text-tertiary); font-size: 11px; }

/* ===================================================================
   16. Start view (home).
   =================================================================== */
.start-shell {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 20px;
}
.start-hero {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
  align-items: center;
  min-height: 380px;
}
.start-copy {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 6px 0 6px 6px;
}
.start-figure {
  position: relative;
  height: 380px;
  display: grid;
  place-items: center;
}
.start-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-content: start;
}
.status-ring {
  --p: 0;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: conic-gradient(var(--accent-primary) calc(var(--p) * 1%),
                              color-mix(in oklab, var(--accent-primary) 15%, transparent) 0);
  display: grid;
  place-items: center;
  flex: none;
}
.status-ring b {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-surface);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.status-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.status-row dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto auto;
  gap: 3px 14px;
  font-size: var(--fs-12);
}
.status-row dt { color: var(--text-tertiary); }
.status-row dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; color: var(--text-primary); }

.feed { display: grid; gap: 2px; }
.feed .item {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 6px;
  border-radius: 10px;
  color: var(--text-primary);
  text-decoration: none;
}
.feed .item:hover { background: color-mix(in oklab, var(--accent-primary) 6%, transparent); }
.feed .ic {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: color-mix(in oklab, var(--accent-primary) 14%, transparent);
  color: var(--accent-primary);
  flex: none;
}
.feed .ic svg { width: 15px; height: 15px; }
.feed b { display: block; font-size: var(--fs-13); font-weight: 600; }
.feed span { font-size: 11.5px; color: var(--text-tertiary); }
.feed .st { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.feed .st.done { color: var(--success); background: color-mix(in oklab, var(--success) 14%, transparent); }
.feed .st.wait { color: var(--warning); background: color-mix(in oklab, var(--warning) 14%, transparent); }
.feed .st.err  { color: var(--danger);  background: color-mix(in oklab, var(--danger)  14%, transparent); }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tool {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--fs-12);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 10px;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
}
.tool i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.tool.off { opacity: 0.55; }
.tool.off i { background: var(--warning); box-shadow: 0 0 6px var(--warning); }

@media (max-width: 1180px) {
  .start-shell { grid-template-columns: 1fr; }
  .start-hero { grid-template-columns: 1fr; }
  .start-figure { order: -1; height: auto; display: flex; justify-content: center; margin-bottom: 20px; }
}

/* ===================================================================
   17. Chat — Grundklassen fuer Bubbles, Markdown und Tool-Karten.
   Container/Sidebar/Threadliste sind mit Phase 2 nach `.chat-v2*`
   umgezogen (siehe unten); die alten Klassen `.chat-shell/.chat-side/
   .thread-list/.chat-main/.chat-hd/.chat-messages` wurden geloescht
   (RUN_ORDER v1 §2.6, 75 Zeilen entfernt).
   =================================================================== */
.chat-msg { display: flex; }
.chat-msg.role-user { justify-content: flex-end; }
.chat-msg.role-assistant, .chat-msg.role-system, .chat-msg.role-tool { justify-content: flex-start; }
.chat-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  color: var(--text-primary);
  line-height: var(--lh-normal);
  display: block;
  width: fit-content;
}
/* User text: preserve whitespace inside the text container only, so
   bubbles keep their original shape without inflating from template
   indentation. */
.chat-bubble.text { white-space: pre-wrap; }
.chat-msg.role-user .chat-bubble {
  background: color-mix(in oklab, var(--accent-primary) 22%, transparent);
  border-color: color-mix(in oklab, var(--accent-primary) 40%, transparent);
  border-bottom-right-radius: 6px;
}
.chat-msg.role-assistant .chat-bubble { border-bottom-left-radius: 6px; }
.chat-meta { color: var(--text-tertiary); font-size: 10.5px; margin-top: 4px; font-family: var(--font-mono); display: block; }

/* Compact in-message markdown scale (fixes D2). */
.chat-md { font-size: var(--fs-14); line-height: var(--lh-normal); }
.chat-md > *:first-child { margin-top: 0; }
.chat-md > *:last-child  { margin-bottom: 0; }
.chat-md h1, .chat-md h2, .chat-md h3, .chat-md h4 {
  font-family: var(--font-ui);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text-primary);
  margin: 12px 0 4px;
  line-height: var(--lh-snug);
}
.chat-md h1 { font-size: 17px; }
.chat-md h2 { font-size: 16px; }
.chat-md h3 { font-size: 15px; }
.chat-md h4 { font-size: var(--fs-14); }
.chat-md p, .chat-md ul, .chat-md ol { margin: 4px 0; }
.chat-md ul, .chat-md ol { padding-left: 1.4em; }
.chat-md li { margin: 2px 0; }
.chat-md pre {
  background: var(--bg-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  font-size: 12px;
  margin: 6px 0;
}
.chat-md code {
  background: var(--bg-overlay);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.chat-md blockquote {
  border-left: 2px solid var(--accent-primary);
  padding: 2px 10px;
  margin: 6px 0;
  color: var(--text-secondary);
  background: color-mix(in oklab, var(--accent-primary) 5%, transparent);
  border-radius: 0 6px 6px 0;
}
.chat-md a { color: var(--accent-primary); }
.chat-md a:hover { color: var(--accent-secondary); }

/* Tool card family (research/image/error/plan/memory-note). */
.tc {
  max-width: 78%;
  border: 1px solid color-mix(in oklab, var(--accent-primary) 40%, var(--border-subtle));
  background: color-mix(in oklab, var(--bg-surface) calc(var(--panel-opacity) * 100%), transparent);
  border-radius: 16px;
  padding: 12px 14px;
  display: grid;
  gap: 6px;
  color: var(--text-primary);
}
.tc-lab {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--accent-primary);
  display: flex;
  gap: 8px;
  align-items: center;
}
.tc-lab i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.tc-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-primary); }
a.tc-title:hover { color: var(--accent-primary); text-decoration: none; }
.tc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: var(--fs-12);
  color: var(--text-tertiary);
}
.tc-meta b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.tc-link {
  color: var(--accent-primary);
  font-weight: 600;
  text-decoration: none;
  font-size: var(--fs-13);
  margin-top: 2px;
  display: inline-block;
}
.tc.err {
  border-color: color-mix(in oklab, var(--danger) 45%, var(--border-subtle));
  background: color-mix(in oklab, var(--danger) 6%, var(--bg-surface));
}
.tc.err .tc-lab { color: var(--danger); }
.tc.err .tc-lab i { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.tc.planned {
  border-color: color-mix(in oklab, var(--accent-tertiary) 30%, var(--border-subtle));
  background: color-mix(in oklab, var(--accent-tertiary) 5%, var(--bg-surface));
  opacity: 0.94;
}
.tc.planned .tc-lab { color: var(--accent-tertiary); }
.tc.planned .tc-lab i { background: var(--accent-tertiary); box-shadow: 0 0 6px var(--accent-tertiary); }
.tc-plan { margin: 4px 0 0 18px; padding: 0; }
.tc-plan li { margin: 2px 0; }
.tc-caps { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.tc-caps .pill { font-size: 10.5px; padding: 1px 8px; }

.chat-image-preview {
  max-width: 100%;
  margin-top: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

/* ===================================================================
   18. Activity timeline, research CTA.
   =================================================================== */
.activity-timeline {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  padding: 8px 6px;
  max-height: 460px;
  overflow-y: auto;
}
.act-line {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px dashed var(--border-subtle);
}
.act-line:last-child { border-bottom: none; }
.act-line time {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.7;
}
.act-title { display: inline-block; margin-left: 8px; font-weight: 500; }
.act-meta { font-size: 12.5px; margin-top: 4px; }
.act-raw { margin-top: 4px; }
.act-raw > summary { color: var(--text-tertiary); font-size: 11.5px; }
.act-raw pre { margin-top: 4px; font-size: 11px; max-height: 180px; overflow: auto; }

.cta-research {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px 20px;
  border-radius: var(--radius-large);
  background: linear-gradient(135deg,
    color-mix(in oklab, var(--accent-primary) 18%, var(--bg-surface)),
    color-mix(in oklab, var(--accent-tertiary) 18%, var(--bg-surface)));
  border: 1px solid color-mix(in oklab, var(--accent-primary) 30%, var(--border-default));
  color: var(--text-primary);
  margin-bottom: 16px;
}
.cta-research strong { font-size: 15px; }
.cta-research .muted { font-size: 12.5px; }
.cta-research .btn.primary { margin-left: auto; }

/* ===================================================================
   19. Appearance page (theme gallery with rendered mini previews).
   =================================================================== */
.appearance-hero { display: grid; gap: 6px; margin-bottom: 16px; }
.theme-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.theme-card {
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  display: block;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  background: var(--bg-surface);
  transition: border-color var(--motion-micro) ease,
              box-shadow var(--motion-micro) ease,
              transform 90ms ease;
  position: relative;
}
/* Visually-hidden radio (a11y-friendly, does NOT stretch to 100 % width). */
.theme-card input,
.control-scope input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.theme-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-medium); border-color: var(--border-default); }
.theme-card.selected {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--focus-ring), var(--shadow-medium);
}
/* Rendered mini preview (sidebar + panel + command field, in that theme). */
.theme-mini {
  height: 160px;
  padding: 10px;
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 8px;
  overflow: hidden;
  background: var(--mini-bg, var(--bg-canvas));
  position: relative;
}
.theme-mini::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--mini-atmo);
  opacity: 0.9;
  pointer-events: none;
}
.theme-mini > * { position: relative; z-index: 1; }
.mini-side {
  background: var(--mini-panel);
  border: 1px solid var(--mini-line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
}
.mini-side i {
  height: 6px;
  border-radius: 3px;
  background: var(--mini-line);
}
.mini-side i.on { background: var(--mini-accent); }
.mini-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: space-between;
}
.mini-panel {
  flex: 1;
  background: var(--mini-panel);
  border: 1px solid var(--mini-line);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-hd {
  height: 8px;
  width: 62%;
  border-radius: 3px;
  background: color-mix(in oklab, var(--mini-ink) 40%, transparent);
}
.mini-row { height: 5px; border-radius: 2px; background: color-mix(in oklab, var(--mini-ink) 22%, transparent); width: 88%; }
.mini-row.short { width: 62%; }
.mini-orb {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff 0, var(--mini-accent) 55%, transparent 100%);
  box-shadow: 0 0 12px var(--mini-accent);
}
.mini-avatar {
  position: absolute;
  right: 8px;
  bottom: 6px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 12%;
  border: 2px solid color-mix(in oklab, var(--mini-accent) 55%, transparent);
  box-shadow: 0 0 12px color-mix(in oklab, var(--mini-accent) 45%, transparent);
  background: color-mix(in oklab, var(--mini-panel) 90%, transparent);
}
.mini-ask {
  height: 14px;
  border-radius: 999px;
  background: var(--mini-panel);
  border: 1px solid var(--mini-accent);
  box-shadow: 0 0 10px color-mix(in oklab, var(--mini-accent) 50%, transparent);
}
.theme-card-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-subtle);
}
.theme-card-body strong { display: block; font-size: var(--fs-14); color: var(--text-primary); }
.theme-card-body small { color: var(--text-tertiary); font-size: var(--fs-12); }

.appearance-controls {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.control-group {
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  background: var(--bg-surface);
}
.control-group h3 { margin: 0 0 10px; font-size: var(--fs-13); color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.control-group .options { display: flex; gap: 6px; flex-wrap: wrap; }
.control-group label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--bg-surface-elevated);
  transition: border-color var(--motion-micro) ease, color var(--motion-micro) ease, background-color var(--motion-micro) ease;
}
.control-group label:hover { border-color: var(--border-default); }
.control-group label input { /* visually hidden — see .control-scope input above */ }
.control-group label.selected {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: color-mix(in oklab, var(--accent-primary) 12%, var(--bg-surface-elevated));
}
.presence-preview {
  height: 220px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-large);
  background: color-mix(in oklab, var(--bg-surface-elevated) 60%, transparent);
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
}
.presence-preview .presence-slot {
  /* Constrain the hero-sized preview so it never exceeds the card. */
  --presence-size: 160px;
}

/* ===================================================================
   20. Utility (layout-only).
   =================================================================== */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }
.mt-6 { margin-top: 24px; }
.mt-7 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.ml-auto { margin-left: auto; }
.ml-1 { margin-left: 6px; }
.p-narrow { padding: 6px 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.form-two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list-plain { list-style: none; padding-left: 16px; margin: 0; }
.wrap-pre { white-space: pre-wrap; }
.chart-svg { width: 100%; height: 200px; }
.source-preview { max-height: 180px; overflow: auto; }
.memory-inline-form { margin-top: 8px; min-width: 280px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 4px; }
.hidden-init { display: none; }
.plan-list { margin: 6px 0 0 18px; }
.conn-hd { display: flex; align-items: baseline; gap: 8px; }
.diff-line-file { color: var(--accent-primary); }
.diff-line-add  { color: var(--success); }
.diff-line-del  { color: var(--danger); }
.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
}
.diff-old { text-decoration: line-through; color: var(--text-tertiary); }
.link-icon::after { content: " \2197"; color: var(--text-tertiary); font-size: 12px; }
details > summary { cursor: pointer; user-select: none; }
details > summary:hover { color: var(--accent-primary); }
.roadmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.roadmap .card small { color: var(--text-tertiary); font-size: var(--fs-12); line-height: 1.45; }
.tests-scroll { max-height: 400px; overflow-y: auto; }

/* Scrollbars (webkit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in oklab, var(--text-secondary) 22%, transparent);
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: color-mix(in oklab, var(--text-secondary) 40%, transparent); }

/* Hint-Absatz mit Befehlszeile: verhindert, dass lange <code>-Blöcke
   den Container sprengen. Der Label-Span wird schmal gehalten, der
   Code-Block umbricht in eigenen Zeilen. */
.hint-detail {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 6px 0;
}
.hint-detail .hint-label {
  color: var(--text-secondary);
  font-size: var(--fs-13);
  flex: 0 0 auto;
}
.hint-code {
  display: inline-block;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12.5px;
  color: var(--text-primary);
}

/* =====================================================================
   21. Responsive breakpoints (placed at the file end so their cascade
       reliably wins over the base component rules above).
       Order: 820 px (tablet/phone), 480 px (small phone), 960 px
       (already present higher up for the shell but kept minimal here).
   ===================================================================== */
@media (max-width: 820px) {
  /* Phase 2 (RUN_ORDER v1 §2.6): alte Chat- und Start-Container-Regeln
     entfielen mit dem Neubau. `.chat-bubble` und `.tc` behalten ihren
     Overflow-Schutz weiter unten (siehe .chat-md, .chat-bubble.text). */
  .chat-bubble, .tc { max-width: 100%; }

  .theme-gallery { grid-template-columns: 1fr; }
  .appearance-controls { grid-template-columns: 1fr; }

  /* Any table becomes horizontally scrollable inside its own box (Phase 1.2 Fix). */
  .card, .tests-scroll, .split > *, .grid > *, main.main {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Zusaetzlich: Tabellen bekommen einen eigenen Scroll-Rahmen, damit
     die Zellen nicht auf ein Zeichen pro Zeile zusammengedrueckt werden
     (siehe Wissen/Freigaben-Mobile-Shots vor dem Fix). */
  main.main > table,
  main.main > table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  main.main > table > thead,
  main.main > table > tbody {
    display: table;
    width: max-content;
    min-width: 100%;
  }

  .side-me { display: none; }
  .tag, .tool { word-break: break-word; overflow-wrap: anywhere; }

  /* Inside chat-md and long user text bubbles, wrap unbreakable words. */
  .chat-md, .chat-bubble.text { overflow-wrap: anywhere; word-break: break-word; }
}

@media (max-width: 480px) {
  .main { padding: 4px 2px; }
}

/* Tabs (fuer Wissen und andere Ansichten mit Unter-Tabs). */
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  background: color-mix(in oklab, var(--bg-surface) 60%, transparent);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin: 8px 0 16px 0;
}
.tabs .tab {
  padding: 6px 12px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; font-size: 13px;
  transition: background-color var(--motion-micro) ease, color var(--motion-micro) ease;
}
.tabs .tab:hover { color: var(--text-primary); text-decoration: none; }
.tabs .tab.is-active {
  background: color-mix(in oklab, var(--accent-primary) 16%, transparent);
  color: var(--text-primary);
}

/* ===================================================================
   Phase 2.1 — Start = neuer Chat
   Zentriert: Figur, Begruessung, Composer, 4 Chips, "Heute"-Zeile.
   =================================================================== */
.start-v2 {
  max-width: 760px;
  margin: 0 auto;
  padding: 32px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-height: 60vh;
}
.start-figure-v2 {
  display: grid;
  place-items: center;
  width: 100%;
  /* A1 (04.10. spät): kein ``max-height`` mehr – die Figurenhöhe wird
     in ``presence.css`` jetzt per ``min(clamp(…), 42vh)`` begrenzt,
     damit der Flex-Fluss darunter (Begrüßung, Composer) wirklich
     Platz behält.  Vorher stand der Container auf 42vh, der Avatar
     war aber bis zu 520 px hoch und lief sichtbar in die Begrüßung
     hinein. */
  margin-bottom: 4px;
}
.start-greeting-v2 {
  margin: 8px 0 0;
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text-primary);
  text-align: center;
}
.start-subgreet-v2 {
  margin: 0;
  color: var(--text-secondary);
  font-size: 15px;
  text-align: center;
}
.start-composer {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 680px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  /* R1 (04.10.): die Hero-Figur (`.presence-slot.hero`) steht mit
     `position: relative` im Normalfluss und zeichnet deshalb über
     spätere statische Geschwister. Auf Desktops ist sie `clamp(340, 40vw,
     520)` hoch, der Rahmen `.start-figure-v2` begrenzt aber nur per
     `max-height: 42vh` (~378 px) – der Avatar läuft also sichtbar in den
     Composer-Bereich. Ohne eigenes Stacking fängt die Hero-Hülle Klicks
     auf dem oberen Composer-Rand ab. Positionierter Composer + z-index
     holen die Klickfläche wieder nach oben, ohne pointer-events anfassen
     zu müssen. */
  position: relative;
  z-index: 1;
}
.start-composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  padding: 6px 4px;
  max-height: 168px;
}
.start-composer .ib {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--text-secondary);
  cursor: pointer;
}
.start-composer .ib:hover { background: color-mix(in oklab, var(--accent-primary) 10%, transparent); color: var(--text-primary); }
.start-composer .ib.go {
  background: var(--accent-primary);
  color: var(--accent-ink, #fff);
}
.start-composer .ib.go:hover { background: var(--accent-secondary); }
.start-composer svg { width: 18px; height: 18px; }

.start-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 680px;
  margin-top: 4px;
}
.start-chips .chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: color-mix(in oklab, var(--accent-primary) 8%, transparent);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
}
.start-chips .chip:hover {
  background: color-mix(in oklab, var(--accent-primary) 16%, transparent);
  text-decoration: none;
}

.start-today {
  margin-top: 12px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px;
  color: var(--text-tertiary);
  font-size: 12.5px;
}
.start-today .today-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 4px;
}
.start-today .today-item { color: var(--text-secondary); text-decoration: none; }
.start-today .today-item:hover { color: var(--text-primary); text-decoration: underline; }
.start-today .today-sep { color: var(--text-tertiary); }

/* ===================================================================
   Phase 2.2 — Chat-Layout
   100dvh Shell, nur Nachrichten scrollen; Kopf + Composer fest.
   Phase 2b · C4: `.body-chat` liefert dem Chat exakt die verfuegbare
   Hoehe ohne .main-Padding, damit der Composer bei 900 px Fensterhoehe
   nicht mehr unter den Bildschirmrand rutscht.
   =================================================================== */
body.body-chat { overflow: hidden; }
body.body-chat main.main {
  padding: 0;
  height: calc(100vh - 28px);
  min-height: 0;
  overflow: hidden;
  gap: 0;
}
.chat-v2 {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  position: relative;
}
.chat-v2-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: color-mix(in oklab, var(--bg-canvas) 92%, transparent);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  min-height: 52px;
}
.chat-v2-hd-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.chat-v2-ghead {
  width: 36px; height: 36px; flex: none;
  position: relative; overflow: hidden;
  border-radius: 999px;
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent-primary) 55%, transparent),
              0 0 0 3px color-mix(in oklab, var(--accent-primary) 12%, transparent);
}
.chat-v2-ghead .presence-slot { width: 100%; height: 100%; display: block; position: relative; }
.chat-v2-ghead .presence-slot > .presence-orb,
.chat-v2-ghead .presence-slot > .presence-avatar { position: absolute; inset: 0; width: 100%; height: 100%; }
.chat-v2-ghead.is-thinking { animation: chat-ghead-pulse 1.4s ease-in-out infinite; }
@keyframes chat-ghead-pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.2); } }
.chat-v2-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-v2-hd-right { display: flex; align-items: center; gap: 8px; flex: none; }
.chat-v2-projform { margin: 0; }
.chat-v2-projchip {
  background: color-mix(in oklab, var(--accent-primary) 8%, transparent);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  outline: none;
}
.chat-v2-menu { position: relative; }
.chat-v2-menu summary {
  list-style: none;
  cursor: pointer;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
}
.chat-v2-menu summary::-webkit-details-marker { display: none; }
.chat-v2-menu summary:hover { background: color-mix(in oklab, var(--accent-primary) 10%, transparent); color: var(--text-primary); }
.chat-v2-menu-body {
  position: absolute; right: 0; top: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 6px;
  display: flex; flex-direction: column; min-width: 180px;
  box-shadow: var(--shadow-large);
  z-index: 10;
}
.chat-v2-menu-body button {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent; border: 0; color: var(--text-primary);
  font: inherit; font-size: 13px; cursor: pointer;
}
.chat-v2-menu-body button:hover { background: color-mix(in oklab, var(--accent-primary) 12%, transparent); }

.chat-v2-body {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 20px;
  min-height: 0;
}
.chat-v2-col {
  max-width: 760px;
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-v2-col .chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.chat-v2-col .chat-msg.role-user { align-items: flex-end; }
.chat-v2-col .chat-msg.role-assistant,
.chat-v2-col .chat-msg.role-system,
.chat-v2-col .chat-msg.role-tool { align-items: flex-start; }
.chat-v2-col .chat-msg.role-user .chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* Genie: keine Blase, Text direkt auf Hintergrund. */
.chat-v2-col .chat-msg.role-assistant .chat-bubble,
.chat-v2-col .chat-msg.role-assistant .chat-md {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text-primary);
  max-width: 100%;
  width: 100%;
  overflow-wrap: anywhere;
}
.chat-v2-col .chat-md.is-thinking {
  color: var(--text-tertiary);
  font-style: italic;
  animation: chat-thinking 1.4s ease-in-out infinite;
}
@keyframes chat-thinking { 0%,100% { opacity: 0.7; } 50% { opacity: 1; } }

/* Aktionszeile unter Genie-Antwort. */
.chat-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity var(--motion-micro) ease;
}
.chat-v2-col .chat-msg.role-assistant:hover .chat-actions,
.chat-v2-col .chat-msg.role-assistant:focus-within .chat-actions { opacity: 1; }
.chat-actions button {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--text-secondary);
  font: inherit; font-size: 12px; cursor: pointer;
}
.chat-actions button:hover { color: var(--text-primary); border-color: var(--border-strong); background: color-mix(in oklab, var(--accent-primary) 8%, transparent); }

/* Ergebnis-Karten (tc) im Chat. */
.chat-v2-col .tc { max-width: 560px; }

/* Fix3 · M2: strukturierte Chat-Fehlerkarte (Nachricht + Link). */
.chat-error-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md, 10px);
  border: 1px solid color-mix(in oklab, var(--danger) 35%, transparent);
  background: color-mix(in oklab, var(--danger) 10%, var(--bg-surface-elevated));
  color: var(--text-primary);
  max-width: 560px;
}
.chat-error-card .chat-error-msg { margin: 0; line-height: 1.4; }
.chat-error-card .chat-error-link { align-self: flex-start; }

/* Scroll-nach-unten-Knopf. */
.chat-v2-scrollbtn {
  position: absolute; right: 20px; bottom: 96px;
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow-large);
  z-index: 5;
}

/* Composer fest unten. */
.chat-v2-composer {
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in oklab, var(--bg-canvas) 92%, transparent);
  border-top: 1px solid var(--border-subtle);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.chat-v2-composer-row {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
}
.chat-v2-composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  border: 0; outline: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  padding: 6px 2px;
  max-height: 168px;
}
.chat-v2-composer .cbtn {
  flex: none;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: transparent;
  border: 0; border-radius: 999px;
  color: var(--text-secondary);
  cursor: pointer;
}
.chat-v2-composer .cbtn:hover { color: var(--text-primary); background: color-mix(in oklab, var(--accent-primary) 10%, transparent); }
.chat-v2-composer .cbtn.send,
.chat-v2-composer .cbtn.stop {
  background: var(--accent-primary);
  color: var(--accent-ink, #fff);
}
.chat-v2-composer .cbtn.send:hover,
.chat-v2-composer .cbtn.stop:hover { background: var(--accent-secondary); }
.chat-v2-composer .cbtn.stop { background: var(--warning); }

.mic-hint { display: block; text-align: center; margin-top: 6px; font-size: 11.5px; color: var(--text-tertiary); }
.mic-hint.hidden-init { display: none; }

/* -------------------------------------------------------------------
   Phase 2b · C5 — leerer Chat = Startseiten-Feeling.
   ------------------------------------------------------------------- */
.chat-v2-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; padding: 36px 12px 12px;
  text-align: center;
}
/* Phase 3 · 3.0.2: der leere Chat zeigt die Figur wie auf der Startseite
   (`.start-figure-v2`) — kein `overflow: hidden`, damit der weiche
   Halo/Schatten frei ins Umfeld verläuft und kein sichtbares Rechteck
   hinter der Figur entsteht. */
.chat-v2-empty-figure {
  display: grid;
  place-items: center;
  width: 100%;
  max-height: 46vh;
  margin-bottom: 4px;
}
.chat-v2-empty-figure .presence-slot.hero { max-height: 44vh; }
.chat-v2-empty-title {
  margin: 4px 0 0; font-size: 22px; color: var(--text-primary);
  font-weight: 500;
}
.chat-v2-empty-chips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  max-width: 560px;
}
.chat-v2-empty-chips .chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: color-mix(in oklab, var(--accent-primary) 8%, transparent);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  color: var(--text-primary);
  text-decoration: none;
  font: inherit; font-size: 13px; cursor: pointer;
}
.chat-v2-empty-chips .chip:hover {
  background: color-mix(in oklab, var(--accent-primary) 16%, transparent);
}

/* -------------------------------------------------------------------
   Phase 2b · C5 — kleiner Genie-Kopf (24 px, von vorne) an der ersten
   Antwort einer Gruppe. Er benutzt den bestehenden `_presence.html` im
   Compact-Modus, verkleinert per --presence-size.
   ------------------------------------------------------------------- */
.chat-v2-msg-avatar {
  width: 100%; max-width: 760px;
  margin: 6px auto -4px;
  display: flex; align-items: center;
  padding-left: 2px;
}
.chat-v2-msg-avatar .presence-slot {
  --presence-size: 24px;
  width: 24px; height: 24px;
  border-radius: 999px; overflow: hidden;
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent-primary) 55%, transparent);
}
.chat-v2-msg-avatar .presence-slot > .presence-orb,
.chat-v2-msg-avatar .presence-slot > .presence-avatar {
  position: absolute; inset: 0; width: 100%; height: 100%;
}

/* -------------------------------------------------------------------
   Phase 2b · C8 — Werkzeug-/Intent-Karten mit gleichem turn_id fallen
   in einen zusammenklappbaren Block. Wird per JS umschlossen.
   ------------------------------------------------------------------- */
.chat-v2-col .chat-v2-toolgroup {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 4px 10px;
  background: color-mix(in oklab, var(--bg-surface) 55%, transparent);
  max-width: 760px;
}
.chat-v2-col .chat-v2-toolgroup > summary {
  list-style: none;
  cursor: pointer;
  padding: 6px 4px;
  color: var(--text-secondary);
  font-size: 12.5px;
}
.chat-v2-col .chat-v2-toolgroup > summary::-webkit-details-marker { display: none; }
.chat-v2-col .chat-v2-toolgroup > summary::after {
  content: " ▸";
  color: var(--text-tertiary);
}
.chat-v2-col .chat-v2-toolgroup[open] > summary::after { content: " ▾"; }
.chat-v2-col .chat-v2-toolgroup > .chat-msg { padding: 4px 0; }

/* -------------------------------------------------------------------
   Phase 2b · C8 — Uhrzeiten (.chat-meta) sind standardmaessig unsichtbar
   und tauchen nur beim Hovern / Fokus auf.
   ------------------------------------------------------------------- */
.chat-v2-col .chat-msg .chat-meta {
  opacity: 0;
  transition: opacity 120ms ease;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 2px 4px;
}
.chat-v2-col .chat-msg:hover .chat-meta,
.chat-v2-col .chat-msg:focus-within .chat-meta { opacity: 1; }
@media (hover: none) {
  /* Auf Beruehrgeraeten: pro Gruppe die letzte Karte zeigen. */
  .chat-v2-col .chat-msg + .chat-msg:not(.role-user) .chat-meta { opacity: 0; }
  .chat-v2-col .chat-msg:last-child .chat-meta { opacity: 0.75; }
}

/* -------------------------------------------------------------------
   Phase 2b · C7 — +-Menue Popover + Drop-Zone.
   ------------------------------------------------------------------- */
.chat-v2-plus-wrap { position: relative; flex: none; }
.chat-v2-plus-menu {
  position: absolute;
  left: 0; bottom: calc(100% + 8px);
  min-width: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 6px;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-large);
  z-index: 20;
}
.chat-v2-plus-menu button {
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  background: transparent; border: 0; color: var(--text-primary);
  font: inherit; font-size: 13px; cursor: pointer;
}
.chat-v2-plus-menu button:hover {
  background: color-mix(in oklab, var(--accent-primary) 12%, transparent);
}
.chat-v2-dropzone {
  margin: 8px auto 0;
  max-width: 760px;
  padding: 8px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  color: var(--text-secondary);
  text-align: center;
  font-size: 12.5px;
  background: color-mix(in oklab, var(--accent-primary) 6%, transparent);
}

/* -------------------------------------------------------------------
   Phase 2b · C3 — laufende Antwort sichtbar markieren und abgebrochene
   ehrlich taggen (kein visueller Blocker).
   ------------------------------------------------------------------- */
.chat-msg.is-live .chat-md { }  /* Marker; Pulsieren macht .is-thinking. */
.chat-msg.is-stopped .chat-md::after {
  content: "";
}

/* -------------------------------------------------------------------
   Phase 2b · C9 — minimal-light "Neuer Chat" so leicht wie die Nutzer-
   Blase: heller Hintergrund + feiner Rand statt schwerem Grau.
   ------------------------------------------------------------------- */
:root[data-theme="minimal-light"] .nav-primary {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-weight: 500;
}
:root[data-theme="minimal-light"] .nav-primary:hover {
  background: color-mix(in oklab, var(--accent-primary) 10%, var(--bg-surface));
  border-color: var(--border-strong);
}

/* -------------------------------------------------------------------
   Phase 2b · C9 — Sidebar-Orb wirklich mittig, ohne Beschnitt.
   Der Halo (`.presence-orb::after` inset:-18%) wurde von
   `.genie-card-head { overflow:hidden }` verschluckt; jetzt bleibt der
   Halo drinnen, der Orb fuellt den Kreis komplett.
   ------------------------------------------------------------------- */
.genie-card-head .presence-slot > .presence-orb {
  inset: 0; margin: 0;
  left: 0; top: 0;
  width: 100%; height: 100%;
  border-radius: 999px;
}
.genie-card-head .presence-slot > .presence-orb::after {
  inset: -4%;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* -------------------------------------------------------------------
   Phase 3 (RUN_ORDER v1) — Gesprächsmodus (Voice Overlay).
   Vollflächige, themabezogene Bühne.  Die Figur reagiert auf
   `--voice-level` (0–1) aus dem WebAudio-Analyser.  Bei
   `data-motion="reduced"` gibt es nur einen Farbwechsel, keine
   Bewegung.  Alle Responsive-Regeln stehen am Ende der Datei.
   ------------------------------------------------------------------- */
.voice-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  /* Phase 3b · E4: mind. 96 % deckend, damit die Genie-Figur der
     dahinterliegenden Seite nicht als "Geister-Genie" durchscheint.
     ``--bg-canvas`` ist die tatsächlich definierte Seitenfarbe
     (``--bg-page`` existiert nicht → color-mix wäre sonst transparent). */
  background: color-mix(in oklab, var(--bg-canvas) 96%, transparent);
  backdrop-filter: blur(18px) saturate(1.05);
  -webkit-backdrop-filter: blur(18px) saturate(1.05);
  animation: voice-overlay-in 220ms ease-out;
}
/* Browser ohne color-mix bekommen einen soliden Fallback: nichts
   scheint durch. */
@supports not (background: color-mix(in oklab, red, blue)) {
  .voice-overlay { background: var(--bg-canvas); }
}
body.body-voice-open { overflow: hidden; }
@keyframes voice-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.voice-overlay-inner {
  width: 100%; max-width: 720px;
  padding: clamp(20px, 4vw, 40px);
  display: flex; flex-direction: column; align-items: center;
  gap: 14px; text-align: center;
  /* Phase 3b · E4: klare Spalten-Anordnung ohne Überlappung. */
  justify-content: flex-start;
}
.voice-close {
  position: absolute; top: 16px; right: 16px;
  width: 42px; height: 42px; border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: color-mix(in oklab, var(--bg-surface) 70%, transparent);
  color: var(--text-primary);
  display: grid; place-items: center;
  cursor: pointer;
}
.voice-close:hover { background: color-mix(in oklab, var(--accent-primary) 12%, var(--bg-surface)); }
/* Phase 3c · F1 + F7: Genie-Figur mittig, ohne overflow:hidden.
   Größe wird an Viewport gekoppelt, damit Halo + Steine + Schweben nie
   hart abgeschnitten werden. Der frühere Orb ist im Overlay entfernt. */
.voice-figure {
  position: relative;
  --voice-level: 0;
  --voice-tint: color-mix(in oklab, var(--accent-primary) 55%, transparent);
  --voice-halo: 12px;   /* Sicherheitsrand für Glow/Ring rundherum */
  display: grid; place-items: center;
  width: 100%;
  margin-bottom: 8px;
  /* KEIN overflow:hidden — der Ring/Glow soll ganz sichtbar sein.
     Der frühere overflow:hidden hat den Halo zu einem Rechteck
     geschnitten (Cowork-Befund F1). */
}
.voice-genie {
  position: relative;
  aspect-ratio: 2 / 3;
  /* Höhe an Viewport-Höhe koppeln; Breite = (2/3) * Höhe. Zusätzlich
     kappt die Formel die Breite an ``100vw - 2×Halo``, damit die Figur
     inkl. Glow immer in den Viewport passt.  --voice-figure-height wird
     vom Media-Query am Dateiende gesetzt (Master §8: Media-Queries am
     Ende). */
  height: min(var(--voice-figure-height, 40vh),
              (100vw - 2 * var(--voice-halo)) * 3 / 2);
  width: auto;
  max-width: calc(100vw - 2 * var(--voice-halo));
  display: block;
}
.voice-genie-img {
  display: block;
  width: 100%; height: 100%;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 12px 32px var(--voice-tint));
  transition: filter 200ms ease;
}
/* Phase 6.3: minimal-light hat sehr helle Bg + dunkle Silhouette.
   Ein staerkerer, bunterer Halo (aus --info) macht die Figur besser
   lesbar, ohne dass die Silhouette absauft.  Nur fuer dieses Theme. */
:root[data-theme="minimal-light"] .voice-genie-img {
  filter:
    drop-shadow(0 0 18px color-mix(in oklab, var(--info) 55%, transparent))
    drop-shadow(0 14px 40px color-mix(in oklab, var(--info) 40%, transparent));
}

/* Phase 3c · F7: sanftes Schweben (±4 px, ca. 3 s), nur wenn Genie
   spricht. Bei prefers-reduced-motion abschaltbar. */
@keyframes voice-figure-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}
.voice-figure[data-voice-state="speaking"] .voice-genie {
  animation: voice-figure-float 3s ease-in-out infinite;
}

/* Steine (Turban + Amulett). Position wird per --gem-*-x/y/r im
   Voice-Overlay-JS aus registry.json gesetzt (Prozentwerte relativ zur
   Bild-Box). Radius r ist der halbe Durchmesser in % der Bildbreite;
   der Glow ist gut 3× so breit wie der Stein.
   Blend-Modus je Theme: dunkle Themes = "screen" (heller Glanz), helle
   Themes = "plus-lighter" bzw. "normal" (kein grauer Schmierfleck, Farbe
   kommt aus dem gefärbten Box-Shadow). Phase 3e · D3. */
.voice-gem {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  left: calc(var(--gem-x, 50%) - var(--gem-r, 4%));
  top:  calc(var(--gem-y, 50%) - var(--gem-r, 4%));
  width:  calc(var(--gem-r, 4%) * 2);
  height: calc(var(--gem-r, 4%) * 2);
  background: radial-gradient(circle,
      color-mix(in oklab, var(--accent-tertiary) 90%, white) 0%,
      var(--voice-tint) 45%,
      transparent 72%);
  box-shadow:
    0 0 12px color-mix(in oklab, var(--accent-tertiary) 60%, transparent),
    0 0 34px color-mix(in oklab, var(--accent-primary)  40%, transparent);
  opacity: 0;
  transform: scale(1);
  transition: opacity 120ms ease, transform 120ms ease;
  mix-blend-mode: screen;
}
/* Helle Themes: "screen" auf hellem Grund ergibt einen grauen Schmierfleck.
   plus-lighter addiert die Farbkanäle sauber und behält die Sättigung.
   Gradient wird mit weniger Weiß gemixt und stärker mit dem Akzent, damit
   der Stein farbig bleibt statt auszubleichen. */
:root[data-theme="minimal-light"] .voice-gem,
:root[data-theme="celestial-gold"] .voice-gem {
  mix-blend-mode: plus-lighter;
  background: radial-gradient(circle,
      color-mix(in oklab, var(--accent-tertiary) 70%, white 30%) 0%,
      color-mix(in oklab, var(--accent-primary) 70%, transparent) 45%,
      transparent 72%);
  box-shadow:
    0 0 14px color-mix(in oklab, var(--accent-tertiary) 70%, transparent),
    0 0 36px color-mix(in oklab, var(--accent-primary)  55%, transparent);
}
/* Minimal-Light: accent-primary ist beinahe schwarz (#171717), das ergibt
   den grauen Ring aus der Cowork-Prüfung 3e.  Der Glow läuft stattdessen
   auf --info (Blau, Theme-Akzent für Fokus). Phase 4 · Schritt 0.1. */
:root[data-theme="minimal-light"] .voice-gem {
  background: radial-gradient(circle,
      color-mix(in oklab, var(--info) 60%, white 40%) 0%,
      color-mix(in oklab, var(--info) 55%, transparent) 45%,
      transparent 72%);
  box-shadow:
    0 0 14px color-mix(in oklab, var(--info) 55%, transparent),
    0 0 36px color-mix(in oklab, var(--info) 35%, transparent);
}
.voice-gem-turban {
  --gem-x: var(--gem-turban-x, 50%);
  --gem-y: var(--gem-turban-y, 15%);
  --gem-r: var(--gem-turban-r, 4.5%);
}
.voice-gem-amulet {
  --gem-x: var(--gem-amulet-x, 50%);
  --gem-y: var(--gem-amulet-y, 40%);
  --gem-r: var(--gem-amulet-r, 4%);
}
/* Zustandsabhängige Sichtbarkeit + Puls. */
.voice-figure[data-voice-state="listening"] .voice-gem {
  opacity: 0.18;
}
.voice-figure[data-voice-state="thinking"] .voice-gem {
  opacity: 0.55;
  animation: voice-gem-pulse 1.6s ease-in-out infinite;
}
.voice-figure[data-voice-state="speaking"] .voice-gem {
  /* Helligkeit folgt dem TTS-Pegel (--voice-level 0..1). */
  opacity: calc(0.55 + var(--voice-level) * 0.45);
  transform: scale(calc(1 + var(--voice-level) * 0.12));
}
@keyframes voice-gem-pulse {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 0.75; transform: scale(1.10); }
}

/* Reduzierte Bewegung: kein Schweben, kein Pulsieren — nur Glanz. */
.voice-overlay[data-motion="reduced"] .voice-figure .voice-genie,
.voice-overlay[data-motion="reduced"] .voice-figure .voice-gem {
  animation: none !important;
  transform: none !important;
}

.voice-state {
  font-size: clamp(20px, 2.6vw, 28px);
  color: var(--text-primary);
  margin: 0;
}
.voice-transcript { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.voice-said, .voice-reply {
  margin: 0; line-height: 1.5;
  font-size: clamp(15px, 1.8vw, 18px);
}
.voice-said {
  color: var(--text-secondary);
  min-height: 0;
}
.voice-said:empty { display: none; }
.voice-reply {
  color: var(--text-primary);
  font-weight: 500;
  min-height: 0;
}
.voice-reply:empty { display: none; }

.voice-cards {
  width: 100%;
  display: flex; flex-direction: column; gap: 8px;
}
.voice-cards:empty { display: none; }
.voice-card {
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: color-mix(in oklab, var(--bg-surface) 80%, transparent);
  text-align: left;
}
.voice-card-lab {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-tertiary); margin-bottom: 4px;
}
.voice-card-title {
  margin: 0; font-size: 15px; font-weight: 500; color: var(--text-primary);
}
.voice-card-tool_error { border-color: color-mix(in oklab, var(--accent-danger, #b23) 40%, var(--border-subtle)); }

.voice-hint {
  min-height: 0; margin: 0;
  color: var(--text-tertiary); font-size: 12.5px;
}
.voice-hint:empty { display: none; }

.voice-actions {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
}
.voice-btn {
  padding: 8px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  background: color-mix(in oklab, var(--bg-surface) 85%, transparent);
  color: var(--text-primary);
  font: inherit; font-size: 13px;
  cursor: pointer;
}
.voice-btn:hover { background: color-mix(in oklab, var(--accent-primary) 12%, var(--bg-surface)); }
.voice-btn[aria-pressed="true"] {
  background: color-mix(in oklab, var(--accent-primary) 26%, var(--bg-surface));
  border-color: color-mix(in oklab, var(--accent-primary) 40%, var(--border-subtle));
}
.voice-shortcut {
  margin: 4px 0 0; font-size: 11px; color: var(--text-tertiary);
}

/* Öffner in Chat-Kopf: der Button darf nicht wie ein Button aussehen. */
.chat-v2-ghead {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: inline-flex; align-items: center;
  color: inherit;
}

/* E5 · Experten-Seite und Chat-Karte. */
.experten-search { display: flex; gap: 8px; margin-bottom: 12px; }
.experten-search input[type="text"] {
  flex: 1; min-width: 0; padding: 8px 12px;
  border: 1px solid var(--border, #ccc); border-radius: 8px;
  background: var(--bg-surface, #fff); color: inherit;
}
.tabs { display: flex; gap: 6px; margin: 8px 0 16px; border-bottom: 1px solid var(--border, #ccc); }
.tabs .tab {
  padding: 6px 12px; border-radius: 8px 8px 0 0; text-decoration: none;
  color: var(--text-secondary, #666);
}
.tabs .tab.is-active {
  color: inherit; background: var(--bg-surface, #fff);
  border: 1px solid var(--border, #ccc); border-bottom-color: var(--bg-surface, #fff);
  position: relative; top: 1px;
}
.experten-group { margin-top: 12px; }
.experten-list { list-style: none; padding: 0; margin: 8px 0 0; }
/* Sammel B1 · S2: Zeile als 2-Spalten-Grid (Name links, Pille rechts
   so breit wie Text).  Zweite Zeile (Beschreibung) spannt beide Spalten.
   Pille zusätzlich mit ``width: fit-content`` + ``justify-self: start``
   abgesichert, damit sie sich nicht in die 1fr-Spalte streckt. */
.experten-row {
  display: grid; grid-template-columns: 1fr auto;
  grid-template-rows: auto auto; gap: 4px 10px; align-items: center;
  padding: 8px 0; border-top: 1px dashed var(--border-faint, #e5e5e5);
}
.experten-row:first-child { border-top: 0; }
.experten-row-link { color: inherit; }
.experten-row > .pill { justify-self: start; width: fit-content; }
.experten-row p { grid-column: 1 / span 2; margin: 0; }
/* Detail-Kopf: Pille „kuratiert" neben der Abteilung — nicht breiter als Text. */
.experten-detail-head .pill { width: fit-content; }
.experten-detail { padding: 16px; margin-bottom: 16px; }
.experten-detail-head { display: flex; align-items: center; gap: 12px; }
.experten-detail-head h2 { margin: 0; }
.experten-detail-head .btn { margin-left: auto; }
.experten-detail-desc { margin: 8px 0; }
.experten-body pre { white-space: pre-wrap; overflow-x: auto; max-height: 60vh; }

/* G2 — Division-Icons: feste Groesse, damit die inline-SVG nicht die
   volle Containerbreite einnimmt. */
.experten-div-icon {
  width: 20px; height: 20px; flex: none; vertical-align: -3px;
  color: var(--muted, #8e8e8e); opacity: 0.9;
}
.experten-detail-icon { width: 28px; height: 28px; vertical-align: -4px; }
.experten-group .h3 { display: flex; align-items: center; gap: 8px; }

/* Experten-Karte im Chat */
.tc.expert-card {
  border-left: 3px solid var(--expert-color, var(--accent, #4a90e2));
}
.tc.expert-card .expert-emoji { margin-right: 6px; }
/* Sammel B1 · S3 — SVG-Icon im Kartenkopf: dieselbe Größe wie auf /experten. */
.tc.expert-card .experten-div-icon { margin-right: 6px; vertical-align: -4px; }
.tc.expert-card .expert-details { margin-top: 8px; }
.tc.expert-card .expert-details summary { cursor: pointer; }
.tc.expert-card .expert-auftrag,
.tc.expert-card .expert-answer { margin-top: 6px; }
.tc.expert-card .expert-auftrag p,
.tc.expert-card .expert-answer p { margin: 2px 0 0; white-space: pre-wrap; }

/* Handy: kleinere Figur auf der Startseite, Composer 16 px Schrift. */
@media (max-width: 820px) {
  .start-figure-v2 { max-height: 36vh; }
  .start-greeting-v2 { font-size: 26px; }
  .chat-v2-body { padding: 12px 8px 16px; }
  .chat-v2-hd { padding: 8px 12px; }
  .chat-v2-composer { padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .chat-v2-composer-row { padding: 6px 8px; }
  .chat-v2-composer textarea { font-size: 16px; }
  .start-composer textarea { font-size: 16px; }
  .chat-v2 { height: calc(100dvh - 56px); }
  /* Topbar bleibt aus base.html (56 px + safe-area). */

  /* Phase 2b · C6: keine Dopplung. Die mobile Topbar traegt bereits
     Titel + Genie-Kopf; die linke Seite des Chat-Kopfs (Genie + Titel)
     entfaellt. Rechts bleiben Projekt-Chip und Menue erreichbar. */
  .chat-v2-hd-left { display: none; }
  .chat-v2-hd { justify-content: flex-end; padding: 6px 12px; min-height: 44px; }
  body.body-chat main.main { height: 100dvh; }
}

/* ===================================================================
   Phase 1.2 — Handy (<=820 px)
   Feste Topbar (Menue + Titel + Genie), Navigations-Schublade von links,
   Overlay-Klick + Esc + Focus-Trap in mobile-nav.js.  Sicherstellen, dass
   Inhalt oberhalb 120 px sichtbar startet (Test-Kriterium 1.2).
   =================================================================== */
.mobile-topbar { display: none; }
.mobile-drawer-overlay { display: none; }

@media (max-width: 820px) {
  html, body { overscroll-behavior-y: contain; }
  body { padding-top: 56px; }

  .mobile-topbar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 40;
    height: calc(56px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0 12px;
    background: color-mix(in oklab, var(--bg-canvas) 90%, transparent);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--border-subtle);
  }
  .mobile-topbar-title {
    flex: 1 1 auto; text-align: center;
    font-weight: 600; font-size: 14px; letter-spacing: 0.01em;
    color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mobile-menu-btn,
  .mobile-topbar-genie {
    width: 40px; height: 40px; flex: none;
    display: grid; place-items: center;
    border-radius: 999px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    text-decoration: none;
  }
  .mobile-menu-btn svg { width: 20px; height: 20px; }
  .mobile-topbar-genie .presence-slot { width: 100%; height: 100%; display: block; position: relative; }
  .mobile-topbar-genie .presence-slot > .presence-orb,
  .mobile-topbar-genie .presence-slot > .presence-avatar {
    position: absolute; inset: 0; width: 100%; height: 100%;
  }
  .mobile-topbar-genie .presence-slot > .presence-symbol,
  .mobile-topbar-genie .presence-slot > .presence-fallback {
    position: absolute; inset: 20%; width: 60%; height: 60%;
  }
  /* Phase 1b · B3: presence=hidden darf die Topbar nie leer lassen. */
  :root[data-genie-presence="hidden"] .mobile-topbar-genie .presence-slot {
    display: block;
  }
  :root[data-genie-presence="hidden"] .mobile-topbar-genie .presence-fallback {
    display: block;
    color: color-mix(in oklab, var(--accent-primary) 90%, var(--text-primary));
  }

  /* Layout ohne Sidebar-Spalte. */
  .layout { display: block; padding: 0; }
  .main { padding: 12px 12px 24px 12px; }

  /* Sidebar wird zur Schublade. */
  aside.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(320px, 88vw);
    max-width: 88vw;
    height: 100vh; height: 100dvh;
    padding: calc(env(safe-area-inset-top, 0px) + 16px) 14px 14px 14px;
    transform: translateX(-102%);
    transition: transform var(--motion-panel) cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 50;
    border-radius: 0 var(--radius-large) var(--radius-large) 0;
    box-shadow: var(--shadow-large);
  }
  body.mobile-drawer-open aside.sidebar { transform: translateX(0); }
  body.mobile-drawer-open { overflow: hidden; }
  /* Phase 1b · B1: overlay ist standardmaessig unsichtbar; das
     [hidden]-Attribut vom Server bleibt erhalten und wird durch die
     CSS-Regel nicht mehr ueberschrieben. Nur geoeffnete Schublade
     schaltet den Overlay sichtbar. */
  .mobile-drawer-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 45;
    display: none;
  }
  body.mobile-drawer-open .mobile-drawer-overlay { display: block; }
  [hidden] { display: none !important; }
  .sidebar-collapse-btn { display: none; }

  /* Formularfelder mindestens 16 px, um iOS-Zoom zu vermeiden. */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="search"], textarea, select {
    font-size: 16px;
  }

  /* Phase 1b · B4: Tabellen werden zu Karten. Reihenfolge per data-order,
     Spaltenname per data-label. Der Kopf verschwindet.
     Wir muessen die Selektor-Spezifitaet gegen die generischen
     `main.main > table > thead/tbody`-Regeln (Zeile ~1710) anheben,
     sonst blitzt der table-header wieder auf. */
  main.main > table.cards-on-mobile { display: block; width: 100%; border-collapse: separate; overflow: visible; }
  main.main > table.cards-on-mobile > thead { display: none; }
  main.main > table.cards-on-mobile > tbody { display: block; width: 100%; min-width: 0; }
  table.cards-on-mobile tbody tr {
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 12px;
    margin: 0 0 10px 0;
  }
  table.cards-on-mobile tbody td {
    display: block;
    padding: 0;
    border: 0;
    order: 9;
    font-size: 13.5px;
    color: var(--text-secondary);
  }
  table.cards-on-mobile tbody td[data-order="1"] { order: 1; }
  table.cards-on-mobile tbody td[data-order="2"] { order: 2; }
  table.cards-on-mobile tbody td[data-order="3"] { order: 3; }
  table.cards-on-mobile tbody td[data-order="4"] { order: 4; }
  table.cards-on-mobile tbody td[data-order="5"] { order: 5; }
  table.cards-on-mobile tbody td[data-order="6"] { order: 6; }
  table.cards-on-mobile tbody td.cell-primary {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
  }
  table.cards-on-mobile tbody td.cell-primary a { text-decoration: none; color: inherit; }
  table.cards-on-mobile tbody td[data-label]:not(.cell-primary)::before {
    content: attr(data-label) ": ";
    color: var(--text-tertiary);
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    display: inline;
    margin-right: 6px;
  }
  table.cards-on-mobile tbody td[data-label=""]:not(.cell-primary)::before { content: ""; }
}

/* Abschluss-Lauf · 6.1 — Karten fuer Projekte, Wissen, Verlauf, Freigaben.
   Grid-Layout auf Desktop, einspaltig unter 820 px. */
.project-grid, .memory-grid, .runs-grid, .approvals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.project-card, .memory-card, .run-card, .approval-card {
  display: block;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-large);
  background: var(--bg-surface);
  padding: 14px 16px;
  color: inherit;
  text-decoration: none;
  transition: border-color 120ms ease, transform 120ms ease;
}
.project-card:hover, .memory-card:hover, .run-card:hover, .approval-card:hover {
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}
.pc-head, .mc-head, .rc-head, .ac-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.pc-name, .mc-title, .rc-title, .ac-title {
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.pc-goal, .mc-body, .rc-body, .ac-body {
  color: var(--text-secondary);
  font-size: 13.5px;
  margin: 4px 0 6px;
  line-height: 1.4;
}
.pc-meta, .mc-meta, .rc-meta, .ac-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--text-tertiary);
  font-size: 12px;
}
/* Feinschliff §1.5: Badge und Empfaenger in eigenen Zeilen, damit
   der Text im Freigaben-Karten-Body bei 390 px nicht ueberlappt. */
.ac-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ac-body .ac-risk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ac-body .ac-receiver {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: 12.5px;
}
.ac-body .ac-receiver-label {
  color: var(--text-tertiary);
}
.ac-body .ac-receiver-value {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}
/* Feinschliff §1.2/§1.3: technische Details unter dem Karten-Meta
   zusammengeschlossen. */
.rc-tech {
  margin-top: 6px;
}

/* Filter-Zeile fuer /wissen und /verlauf */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 14px;
  align-items: center;
}
.filter-row .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 12.5px;
  background: var(--bg-surface);
  cursor: pointer;
  text-decoration: none;
}
.filter-row .chip.active {
  background: color-mix(in oklab, var(--accent-primary) 12%, transparent);
  border-color: var(--accent-primary);
  color: var(--text-primary);
}
.filter-row .chip:hover { border-color: var(--accent-primary); }
.filter-row .filter-label {
  color: var(--text-tertiary);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}

/* Phase 3: Voice-Overlay Grundhöhe pro Breite.
   Phase 3c · F1: --voice-figure-height ist die Höhe des Genie-Bildes; die
   Breite wird über aspect-ratio 2:3 abgeleitet und zusätzlich an
   ``100vw - 2×Halo`` gekappt, damit auch bei 390 px nichts abgeschnitten
   wird (siehe .voice-genie oben). Master §8: Media-Queries am Ende. */
.voice-figure { --voice-figure-height: 42vh; }
@media (max-width: 820px) {
  .voice-figure { --voice-figure-height: 40vh; --voice-halo: 10px; }
}
@media (max-width: 480px) {
  .voice-overlay-inner { padding: 20px 14px 24px; gap: 12px; }
  .voice-close { top: 12px; right: 12px; width: 36px; height: 36px; }
  .voice-figure { --voice-figure-height: 34vh; --voice-halo: 8px; }
  .voice-state { font-size: 20px; }
  .voice-shortcut { display: none; }
}

/* ---------------------------------------------------------------------
   Phase 3a · Nachbesserung 2 · B5.1/B5.5 — Freigabe-Karte + Modus-Tabelle.
   -------------------------------------------------------------------- */
.tc-approval-values {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 10px;
  margin: 6px 0 8px;
  padding: 8px 10px;
  background: var(--bg-surface-elevated, rgba(255,255,255,0.03));
  border-radius: 8px;
  border: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
  font-size: 13px;
}
.tc-approval-values dt {
  margin: 0; padding: 2px 0;
  color: var(--text-secondary, #999);
  white-space: nowrap;
}
.tc-approval-values dd {
  margin: 0; padding: 2px 0;
  overflow-wrap: anywhere;
  color: var(--text-primary, inherit);
}

/* Phase 3a · Nachbesserung 2 · B5.5 — Modus-Einstellungen bei 390 px.
   - Radio-Knopf und Beschriftung stehen nebeneinander, nicht gestapelt.
   - Die Matrix-Tabelle wird in Karten pro Klasse umgebaut (eine Karte je
     Risiko-Klasse mit drei Zeilen „Vorsichtig/Ausgewogen/Autonom").  So
     entfaellt horizontales Scrollen; der Hinweis bleibt sichtbar.
   Master §8 Regel: Media-Queries am Ende der Datei. */
.mode-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}
.mode-row input[type="radio"] {
  margin-top: 4px;
  flex: 0 0 auto;
  /* ``input {width:100%}`` greift sonst global — hier eine runde
     Radio-Pille statt eine volle Zeile. */
  width: auto;
  min-width: 0;
}
.mode-row .mode-label {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}
.mode-row .mode-label .hint {
  color: var(--text-secondary, #999);
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.mode-matrix-cards { display: none; }
@media (max-width: 480px) {
  table.data[data-testid="mode-matrix"] { display: none; }
  .mode-matrix-cards { display: grid; gap: 8px; margin-top: 10px; }
  .mode-matrix-cards .mmc {
    border: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--bg-surface, transparent);
  }
  .mode-matrix-cards .mmc h3 {
    margin: 0 0 6px 0;
    font-size: 14px;
    font-weight: 600;
  }
  .mode-matrix-cards .mmc dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 2px 10px;
    margin: 0;
    font-size: 13px;
  }
  .mode-matrix-cards .mmc dt { color: var(--text-secondary, #999); }
  .mode-matrix-cards .mmc dd { margin: 0; }
}

