/* ===========================================================================
   Flixi: Oberflaeche nach dem Flixtake-Designsystem (design/DESIGNSYSTEM.md)
   Farben nur als Tokens (flixi-tokens.css), Abstaende nur 0/S/M/L,
   Hoehen 20/28/36/44/56, Radien 8/12/16/rund, Dauern 120/200/320 ms.
   Kantengesetz: Text auf der Inhaltskante (M in Seitenleiste, Kopfzeilen,
   Karten, Menues; L im Hauptbereich und in Dialogen; Handy ueberall M),
   Flaechen ragen genau S darueber hinaus.
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--highlight-bg); color: var(--highlight-text); }
button { cursor: pointer; border: 0; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--indigo-400); outline-offset: 2px; border-radius: var(--radius-sm); }

/* Scrollbalken: nur im Hauptbereich sichtbar, sonst ausgeblendet */
.sb-chats, .search-results, .settings-content, .dialog-box, .md-preview, .proj-picker, .thinking-block {
  scrollbar-width: none;
}
.sb-chats::-webkit-scrollbar, .search-results::-webkit-scrollbar,
.settings-content::-webkit-scrollbar, .dialog-box::-webkit-scrollbar, .md-preview::-webkit-scrollbar,
.proj-picker::-webkit-scrollbar, .thinking-block::-webkit-scrollbar { display: none; }
.msg-area { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.msg-area::-webkit-scrollbar { width: 8px; }
.msg-area::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
.msg-area::-webkit-scrollbar-track { background: transparent; }

/* Knoepfe, Menues, Listen, Blatt und Dialogfuss kommen aus der gemeinsamen
   Grundschicht (flixtake-tooltip.js): .ft-symbolknopf, .ft-hauptknopf,
   .ft-nav-eintrag, .ft-nav-titel, .ft-menue, .ft-menue-eintrag,
   .ft-menue-trenner, .ft-blatt, .ft-dialog-fuss. Hier steht nur, was Flixi
   dazu braucht. Die Schicht haengt ihr Stylesheet zur Laufzeit ein; wo Flixi
   etwas daran aendert, braucht die Regel deshalb eine hoehere Spezifitaet. */

/* ================================================================ Knoepfe */
/* Hauptknopf, Nebenknopf („Abbrechen“, „Zurück“) und Symbolknopf kommen aus der
   Grundschicht (.ft-hauptknopf, .ft-knopf, .ft-symbolknopf); Flixi hat keine eigenen. */

/* ================================================================ Anmeldeschirm */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: calc(var(--hoehe-kopf) + var(--abstand-l)) var(--abstand-l) var(--abstand-l);
  background: var(--bg-page);
}
.auth-card {
  width: 100%; max-width: 480px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--abstand-l);
  box-shadow: var(--shadow-panel);
  display: flex; flex-direction: column; gap: var(--abstand-m);
  text-align: center;
}
.auth-logo { width: 48px; height: 48px; border-radius: var(--radius-md); overflow: hidden; margin: 0 auto; }
.auth-logo img { width: 100%; height: 100%; display: block; }
.auth-title { font-size: var(--text-h4); font-weight: var(--weight-semibold); }
.auth-subtitle { color: var(--text-muted); }
.auth-card .ft-hauptknopf { width: 100%; }
.auth-switch { color: var(--text-muted); }
.auth-link { color: var(--accent); font-weight: var(--weight-medium); }
.auth-link:hover { text-decoration: underline; }
.auth-error { display: none; text-align: left; padding: var(--abstand-s) var(--abstand-m); border-radius: var(--radius-md); background: var(--danger-quiet); color: var(--danger); }

/* ================================================================ Rahmen */
#app-screen { display: none; height: 100%; }
flixtake-bar { position: fixed; top: 0; left: 0; right: 0; height: var(--hoehe-kopf); z-index: 200; display: block; }
.layout { position: fixed; top: var(--hoehe-kopf); left: 0; right: 0; bottom: 0; display: flex; }

/* ================================================================ Seitenleiste
   Breite 248, Inhaltskante 16. Flaechen (Auswahl, Hover, Symbolknoepfe)
   beginnen 8 vom Rand und 8 unter jeder Linie. */
.sidebar {
  width: 248px; flex: none; height: 100%;
  display: flex; flex-direction: column;
  background: var(--bg-warm);
  border-right: 1px solid var(--border);
}
.sb-top { padding: var(--abstand-m) var(--abstand-m) var(--abstand-s); display: flex; flex-direction: column; gap: var(--abstand-s); }
.sb-new { width: 100%; }
.sb-search { position: relative; }
.sb-search input {
  width: 100%; height: var(--hoehe-steuer);
  padding: 0 var(--abstand-s);
  background: var(--surface-inset); border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-primary); outline: none;
  transition: border-color var(--dur-fast) var(--ease-out);
}
.sb-search input:focus { border-color: var(--accent); }
.sb-search input::placeholder { color: var(--text-dim); }
.sb-search input::-webkit-search-cancel-button { display: none; }

.sb-chats { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--abstand-s) var(--abstand-s); }
.sb-projects { padding: 0 var(--abstand-s); }
.sb-projects:empty { display: none; }

/* Titel ueber Listen: .ft-nav-titel (Text auf 16). Mit Knopf rechts in der Spalte. */
.sb-titel-zeile { display: flex; align-items: flex-end; justify-content: space-between; }
.sb-titel-zeile .ft-nav-titel { flex: 1; min-width: 0; }

/* Zeilen: .ft-nav-eintrag (36, Flaeche 8 vom Rand, Text bei 16). Rechts eine
   36er-Zelle fuer Zaehler, Ungelesen-Punkt oder den Mehr-Knopf; sie schliesst
   buendig mit der Flaeche ab, deshalb rechts kein Innenabstand. */
.sidebar .ft-nav-eintrag { padding-right: 0; min-width: 0; }
.sidebar .ft-nav-eintrag.ungelesen { color: var(--text-primary); font-weight: var(--weight-medium); }
.sidebar .ft-nav-eintrag:focus-visible { outline-offset: -2px; }
.sidebar .proj-item[aria-current="true"] { background: var(--auswahl-bg); color: var(--auswahl-text); font-weight: var(--weight-medium); }
.sidebar .proj-item[aria-current="true"] .proj-icon { color: var(--auswahl-symbol); }
.sb-chat-text, .proj-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-icon, .sb-zeile-symbol { flex: none; display: inline-flex; color: var(--text-dim); }
.proj-item:not([data-proj-id]) { padding-right: var(--abstand-s); }
.sb-zelle { flex: none; width: var(--hoehe-steuer); height: var(--hoehe-steuer); display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-xs); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.sb-ungelesen { width: var(--abstand-s); height: var(--abstand-s); border-radius: var(--radius-full); background: var(--accent); }
.sidebar .sb-mehr { display: none; }
.sidebar .ft-nav-eintrag:hover .sb-mehr, .sidebar .ft-nav-eintrag:focus-within .sb-mehr,
.sidebar .ft-nav-eintrag[aria-current] .sb-mehr, .sidebar .ft-nav-eintrag.menue-offen .sb-mehr { display: inline-flex; }
.sidebar .ft-nav-eintrag:hover .sb-zelle-status, .sidebar .ft-nav-eintrag:focus-within .sb-zelle-status,
.sidebar .ft-nav-eintrag[aria-current] .sb-zelle-status, .sidebar .ft-nav-eintrag.menue-offen .sb-zelle-status { display: none; }
.sidebar .sb-zelle-status:empty { display: none; }
.sidebar .ft-nav-eintrag .sb-chat-text:last-child, .sidebar .ft-nav-eintrag .proj-name:last-child { margin-right: var(--abstand-s); }
.sb-rename-input {
  width: 100%; height: var(--hoehe-klein);
  padding: 0 var(--abstand-s);
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--surface-card); color: var(--text-primary); outline: none;
}
.sb-leer { padding: var(--abstand-s); color: var(--text-dim); }
/* Laden: Skelettzeilen in Zeilenhoehe */
.sb-skelett { display: flex; align-items: center; height: var(--hoehe-steuer); padding: 0 var(--abstand-s); }
.sb-skelett::before { content: ''; width: 70%; height: var(--abstand-s); border-radius: var(--radius-full); background: var(--surface-raised); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.sb-skelett:nth-child(odd)::before { width: 50%; }

.sb-bottom { position: relative; border-top: 1px solid var(--border); padding: var(--abstand-s); }
.sb-user {
  display: flex; align-items: center; gap: var(--abstand-s);
  height: var(--hoehe-kopf); padding: 0 0 0 var(--abstand-s);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.sb-user:hover { background: var(--overlay-hover); }
.sb-user:focus-visible { outline-offset: -2px; }
.sb-avatar, .profile-avatar {
  flex: none; width: var(--hoehe-klein); height: var(--hoehe-klein);
  border-radius: var(--radius-full); background: var(--accent); color: var(--text-on-accent);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
}
.sb-user-info { flex: 1; min-width: 0; }
.sb-user-name { font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-plan { font-size: var(--text-xs); color: var(--text-dim); }

/* ================================================================ Menues
   Form aus der Grundschicht (.ft-menue, .ft-menue-eintrag, .ft-menue-trenner,
   unter 768 px .ft-blatt). Flixi setzt nur die Lage und die Breite. */
.flixi-menue-frei { position: fixed; z-index: 300; min-width: 240px; max-width: 320px; }
.flixi-menue .ctx-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.flixi-menue:focus { outline: none; }
.ft-blatt .flixi-menue { min-width: 0; max-width: none; }

/* ================================================================ Hauptbereich */
.main { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; position: relative; overflow: hidden; background: var(--bg-page); }
.main::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse 46% 42% at 50% 56%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 62%);
  opacity: 0; transition: opacity var(--dur-slow) var(--ease-out);
}
body.welcome-mode .main::before { opacity: 1; }

/* Kopfzeile des Chats: 56 hoch, Titel links auf 24, Symbolknoepfe rechts */
.chat-kopf {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: var(--abstand-s);
  height: var(--hoehe-kopf); flex: none;
  padding: 0 var(--abstand-l);
}
.chat-kopf-titel { flex: 1; min-width: 0; font-weight: var(--weight-medium); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-kopf-knoepfe { display: flex; align-items: center; margin-right: calc(-1 * var(--abstand-s)); }
.chat-kopf .mob-toggle { display: none; margin-left: calc(-1 * var(--abstand-s)); position: relative; }
#mob-toggle.hat-neues::after { content: ''; position: absolute; top: var(--abstand-s); right: var(--abstand-s); width: var(--abstand-s); height: var(--abstand-s); border-radius: var(--radius-full); background: var(--accent); }
body.welcome-mode .chat-kopf-titel, body.welcome-mode .chat-kopf-knoepfe { visibility: hidden; }

.msg-area { flex: 1; min-height: 0; overflow-y: auto; position: relative; z-index: 1; }
.msg-inner { max-width: 768px; margin: 0 auto; padding: var(--abstand-s) var(--abstand-l) var(--abstand-l); display: flex; flex-direction: column; gap: var(--abstand-l); }
/* Leerer Chat: Gruss und Eingabefeld stehen als Paar in der Mitte */
body.welcome-mode .chat-kopf { position: absolute; top: 0; left: 0; right: 0; }
body.welcome-mode .msg-area { flex: none; overflow: visible; margin-top: auto; }
body.welcome-mode .msg-inner { max-width: none; align-items: center; padding-bottom: var(--abstand-l); }
body.welcome-mode .input-area { margin-bottom: auto; }

/* Leerer Chat */
.welcome { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 60vh; }
body.welcome-mode .welcome { min-height: 0; width: min(768px, 100%); }
/* Begruessung wie vor dem 24.09. (Louis): gross und leicht, nicht die App-Titelgroesse. */
.welcome-title { font-family: var(--font-sans); font-size: clamp(30px, 4vw, 44px); font-weight: 400; letter-spacing: 0; line-height: 1.18; color: var(--text-primary); }

/* ================================================================ Nachrichten */
.msg { position: relative; animation: einblenden var(--dur) var(--ease-out); }
@keyframes einblenden { from { opacity: 0; } to { opacity: 1; } }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.assistant { display: flex; }
.msg-icon { display: none !important; }
.msg-sender { display: none; }
.msg-body-wrap { min-width: 0; }
.msg.assistant .msg-body-wrap { flex: 1; }
.msg.user .msg-body-wrap { max-width: 80%; display: flex; flex-direction: column; align-items: flex-end; gap: var(--abstand-s); }
.msg-text { font-size: var(--text-body); line-height: var(--leading-normal); color: var(--text-primary); overflow-wrap: break-word; }
.msg.user .msg-text {
  display: inline-block; white-space: pre-wrap;
  background: var(--surface-raised);
  border-radius: var(--radius-md);
  padding: var(--abstand-s) var(--abstand-m);
}

/* Lesbare Antworten: 16 px, Fliesstext 1.55, klare Abstaende */
.msg-text > :first-child { margin-top: 0 !important; }
.msg-text > :last-child { margin-bottom: 0 !important; }
.msg-text p { margin: 0 0 var(--abstand-m); }
.msg-text h1, .msg-text h2, .msg-text h3, .msg-text h4 { font-weight: var(--weight-semibold); line-height: 1.4; margin: var(--abstand-l) 0 var(--abstand-s); color: var(--text-primary); }
.msg-text h1, .msg-text h2 { font-size: var(--text-h4); }
.msg-text h3, .msg-text h4 { font-size: var(--text-body); }
.msg-text ul, .msg-text ol { padding-left: var(--abstand-l); margin: 0 0 var(--abstand-m); }
.msg-text li { margin: 0 0 var(--abstand-s); }
.msg-text li::marker { color: var(--accent); }
.msg-text ol > li::marker { font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.msg-text li > ul, .msg-text li > ol { margin: var(--abstand-s) 0 0; }
.msg-text strong { font-weight: var(--weight-semibold); color: var(--text-primary); }
.msg-text em { font-style: italic; }
.msg-text del { opacity: .7; }
.msg-text a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.msg-text hr { border: 0; border-top: 1px solid var(--border); margin: var(--abstand-l) 0; }
.msg-text blockquote { border-left: 1px solid var(--accent); padding-left: var(--abstand-m); color: var(--text-muted); margin: 0 0 var(--abstand-m); }
.msg-text blockquote p { margin-bottom: var(--abstand-s); }
.msg-text code { font-family: var(--font-mono); font-size: var(--text-sm); background: var(--inline-code-bg); padding: 0 var(--abstand-s); border-radius: var(--radius-sm); color: var(--text-primary); }
.katex-block { margin: 0 0 var(--abstand-m); overflow-x: auto; }

/* Codeblock: Kopf ohne eigene Flaeche; der Kopieren-Knopf sitzt 8 von Rand und Oberkante */
.code-block { margin: 0 0 var(--abstand-m); border-radius: var(--radius-md); background: var(--code-bg); border: 1px solid var(--border); overflow: hidden; }
.code-hdr { display: flex; align-items: center; justify-content: space-between; padding: var(--abstand-s) var(--abstand-s) 0 var(--abstand-m); font-size: var(--text-xs); color: var(--code-meta); }
.code-hdr .copy-btn { color: var(--code-meta); }
.code-hdr .copy-btn:hover { background: var(--auf-bild-flaeche); color: var(--code-text); }
.code-hdr .copy-btn.kopiert { color: var(--positive); }
.msg-text pre { margin: 0; overflow-x: auto; background: transparent; }
.msg-text pre code, .msg-text pre code.hljs { display: block; padding: var(--abstand-s) var(--abstand-m) var(--abstand-m); background: transparent; color: var(--code-text); font-size: var(--text-sm); line-height: var(--leading-normal); border-radius: 0; }
.mermaid { margin: 0 0 var(--abstand-m); padding: var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--paper-0); overflow-x: auto; }

/* Tabellen */
.tbl-wrap { overflow-x: auto; margin: 0 0 var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); max-width: 100%; -webkit-overflow-scrolling: touch; }
.md-tbl { width: 100%; border-collapse: collapse; font-size: var(--text-sm); line-height: 1.4; }
.md-tbl th, .md-tbl td { padding: var(--abstand-s) var(--abstand-m); text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.md-tbl th { font-weight: var(--weight-semibold); background: var(--surface-raised); }
.md-tbl th + th, .md-tbl td + td { border-left: 1px solid var(--border); }
.md-tbl tbody tr:last-child td { border-bottom: 0; }

/* Aktionsleiste unter der Antwort. Die erste Flaeche ragt 8 links ueber den Text. */
.msg-leiste { display: flex; margin: var(--abstand-s) 0 0 calc(-1 * var(--abstand-s)); opacity: 0; transition: opacity var(--dur-fast) var(--ease-out); }
.msg.assistant:hover .msg-leiste, .msg.assistant:focus-within .msg-leiste, .msg.assistant:last-child .msg-leiste { opacity: 1; }
.msg-actions { display: flex; opacity: 0; margin-right: calc(-1 * var(--abstand-s)); transition: opacity var(--dur-fast) var(--ease-out); }
.msg.user:hover .msg-actions, .msg.user:focus-within .msg-actions { opacity: 1; }
.msg-act, .fb-btn, .copy-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--hoehe-steuer); height: var(--hoehe-steuer);
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.msg-act:hover, .fb-btn:hover { background: var(--overlay-hover); color: var(--text-primary); }
.msg-act:active, .fb-btn:active { background: var(--overlay-press); }
.fb-btn[aria-pressed="true"], .msg-act.vorlese.aktiv { background: var(--accent-quiet); color: var(--accent); }
.msg-act svg, .fb-btn svg, .copy-btn svg { width: 18px; height: 18px; }

/* Begruendung zur Bewertung */
.fb-grund {
  margin-top: var(--abstand-s); max-width: 480px;
  padding: var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-card);
  display: flex; flex-direction: column; gap: var(--abstand-s);
}
.fb-grund-kopf { display: flex; align-items: center; justify-content: space-between; min-height: var(--hoehe-steuer); margin: calc(-1 * var(--abstand-s)) calc(-1 * var(--abstand-s)) 0 0; font-weight: var(--weight-medium); }
.fb-grund textarea { width: 100%; min-height: 72px; resize: vertical; padding: var(--abstand-s); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-page); color: var(--text-primary); outline: none; line-height: 1.4; }
.fb-grund textarea:focus { border-color: var(--accent); }
.fb-grund-fuss { display: flex; justify-content: flex-end; gap: var(--abstand-s); }
.fb-danke { margin-top: var(--abstand-s); font-size: var(--text-xs); color: var(--text-dim); }

/* Bearbeiten der eigenen Nachricht */
.msg-edit-wrap { width: min(640px, 100%); padding: var(--abstand-m); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface-raised); display: flex; flex-direction: column; gap: var(--abstand-s); }
.msg-edit-textarea { width: 100%; min-height: 72px; border: 0; outline: none; background: transparent; resize: none; font-size: var(--text-body); line-height: var(--leading-normal); color: var(--text-primary); }
.msg-edit-actions { display: flex; justify-content: flex-end; gap: var(--abstand-s); }

/* Denk-Blase */
.loading-bubble { display: inline-flex; align-items: center; gap: var(--abstand-s); max-width: 100%; padding: var(--abstand-s) var(--abstand-m); border-radius: var(--radius-full); background: var(--surface-raised); }
.denk-punkt { flex: none; width: var(--abstand-s); height: var(--abstand-s); border-radius: var(--radius-full); background: var(--accent); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
/* Warte-Puls (denkt nach, schreibt, laedt): Deckkraft 0.4 bis 1, --dur-puls, ease-in-out */
@keyframes denk-puls { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }
.denk-text { font-size: var(--text-sm); color: var(--text-muted); transition: opacity var(--dur-fast) var(--ease-out); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.typing-cursor, .streaming-cursor { display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: text-bottom; animation: denk-puls var(--dur-puls) ease-in-out infinite; }

/* Denkprozess und Schritte */
.thinking-block { margin: 0 0 var(--abstand-m); padding: var(--abstand-s) var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); max-height: 180px; overflow-y: auto; color: var(--text-muted); overflow-wrap: anywhere; }
.thinking-block.collapsed { max-height: none; overflow: hidden; }
.thinking-block.collapsed .thinking-text { display: none; }
/* Kopf: Titel auf der Inhaltskante, der Knopf ragt S ueber sie hinaus. Zugeklappt
   zeigt der Pfeil nach rechts (fester Zustand, keine Drehbewegung). */
.thinking-kopf { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-s); min-height: var(--hoehe-steuer); }
.thinking-titel { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-muted); }
.thinking-kopf > .thinking-toggle { margin-right: calc(-1 * var(--abstand-s)); }
.thinking-block.collapsed .thinking-toggle svg { transform: rotate(-90deg); }
.thinking-text { white-space: pre-wrap; font-family: var(--font-mono); font-size: var(--text-xs); line-height: var(--leading-normal); }
.steps-timeline { margin: 0 0 var(--abstand-m); display: flex; flex-direction: column; }
.step-item { display: flex; align-items: center; gap: var(--abstand-s); min-height: var(--hoehe-steuer); }
.step-icon { flex: none; width: var(--hoehe-abzeichen); height: var(--hoehe-abzeichen); border-radius: var(--radius-full); border: 1px solid var(--border-strong); display: inline-flex; align-items: center; justify-content: center; color: var(--text-dim); }
.step-item.active .step-icon { border-color: var(--accent); color: var(--accent); }
.step-item.done .step-icon { border-color: var(--positive); background: var(--positive); color: var(--ink-900); }
.step-item.done .step-icon svg { stroke: currentColor; }
.step-label { color: var(--text-muted); }
.step-item.active .step-label { color: var(--text-primary); font-weight: var(--weight-medium); }
.step-spinner, .attach-spinner, .kreisel { width: 12px; height: 12px; border-radius: var(--radius-full); border: 2px solid var(--accent); border-top-color: transparent; animation: drehen var(--dur-dreh) linear infinite; }
/* Im Hauptknopf ersetzt der Kreisel das Symbol in dessen Groesse und Textfarbe (Klasse laedt). */
.ft-hauptknopf > [data-sym] { display: inline-flex; }
.ft-hauptknopf > [data-sym] > .kreisel { display: none; width: 18px; height: 18px; border-color: currentColor; border-top-color: transparent; }
.ft-hauptknopf.laedt > [data-sym] > svg { display: none; }
.ft-hauptknopf.laedt > [data-sym] > .kreisel { display: block; }
@keyframes drehen { to { transform: rotate(360deg); } }

/* Websuche-Quellen */
.sources-box { margin: 0 0 var(--abstand-m); display: flex; flex-direction: column; gap: var(--abstand-s); }
.sources-head { display: flex; align-items: center; gap: var(--abstand-s); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-muted); }
.sources-dot { width: var(--abstand-s); height: var(--abstand-s); border-radius: var(--radius-full); background: var(--accent); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.sources-list { display: flex; flex-wrap: wrap; gap: var(--abstand-s); }
.source-chip { display: inline-flex; align-items: center; gap: var(--abstand-s); max-width: 240px; height: var(--hoehe-klein); padding: 0 var(--abstand-s); border-radius: var(--radius-full); background: var(--surface-raised); border: 1px solid var(--border); transition: background var(--dur-fast) var(--ease-out); }
.source-chip:hover { background: var(--overlay-press); }
.source-nr { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--accent); font-variant-numeric: tabular-nums; }
.source-host { font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Fehler- und Verbindungskarte */
.verb-hinweis { max-width: 520px; padding: var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-card); display: flex; flex-direction: column; gap: var(--abstand-s); }
.verb-hinweis.fehler { border-color: var(--danger-border); }
.verb-kopf { display: flex; align-items: center; gap: var(--abstand-s); }
.verb-punkt { flex: none; width: var(--abstand-s); height: var(--abstand-s); border-radius: var(--radius-full); background: var(--accent); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.verb-hinweis.fehler .verb-punkt { background: var(--danger); animation: none; }
.verb-titel { font-weight: var(--weight-semibold); color: var(--text-primary); }
.verb-detail { color: var(--text-muted); line-height: 1.4; }
.verb-code { font-size: var(--text-xs); color: var(--text-dim); font-family: var(--font-mono); }
.verb-knoepfe { display: flex; gap: var(--abstand-s); flex-wrap: wrap; }

/* Eigene Anhaenge unter der eigenen Nachricht */
.msg-anhaenge { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--abstand-s); }
.anhang-datei { display: inline-flex; align-items: center; gap: var(--abstand-s); max-width: 240px; height: var(--hoehe-steuer); padding: 0 var(--abstand-m); border-radius: var(--radius-md); background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-muted); }
.anhang-datei svg { flex: none; color: var(--accent); }
.anhang-datei span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Bildkacheln 148 x 148, Klick oeffnet gross */
.img-strip { display: flex; flex-wrap: wrap; gap: var(--abstand-s); margin: 0 0 var(--abstand-m); }
.img-tile { position: relative; display: inline-flex; flex: none; width: 148px; height: 148px; border-radius: var(--radius-md); overflow: hidden; background: var(--surface-raised); border: 1px solid var(--border); vertical-align: top; }
.img-tile img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; opacity: 0; transition: opacity var(--dur) var(--ease-out); }
.img-tile[data-state="da"] img { opacity: 1; }
.img-tile[data-state="laden"]::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: var(--highlight-bg); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.img-fehler { display: none; position: absolute; inset: 0; flex-direction: column; align-items: center; justify-content: center; gap: var(--abstand-s); padding: var(--abstand-m); text-align: center; font-size: var(--text-xs); line-height: 1.4; color: var(--text-muted); }
.img-tile[data-state="fehler"] img { display: none; }
.img-tile[data-state="fehler"] .img-fehler { display: flex; }
.bild-warte { display: flex; flex-wrap: wrap; gap: var(--abstand-s); margin-top: var(--abstand-m); }
.bild-warte:empty { display: none; }
.img-pending { display: inline-flex; flex-direction: column; gap: var(--abstand-s); vertical-align: top; }
.img-pending-karte { position: relative; width: 148px; height: 148px; border-radius: var(--radius-md); overflow: hidden; background: var(--surface-card); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; color: var(--accent-hover); }
.img-pending-karte::before { content: ''; position: absolute; inset: 0; background: var(--highlight-bg); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.img-pending-karte svg { position: relative; }
.img-pending-text { font-size: var(--text-xs); color: var(--text-dim); }
.bild-fehler { display: inline-block; padding: var(--abstand-s) var(--abstand-m); border-radius: var(--radius-md); background: var(--danger-quiet); color: var(--danger); }

/* Grossansicht */
.bild-gross { position: fixed; inset: 0; z-index: 2500; background: var(--bild-schleier); display: flex; flex-direction: column; animation: einblenden var(--dur) var(--ease-out); }
.bild-gross img { flex: 1; min-height: 0; width: 100%; padding: 0 var(--abstand-l) var(--abstand-l); object-fit: contain; }
.bild-gross-leiste { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: var(--abstand-s); height: var(--hoehe-kopf); padding: 0 var(--abstand-m); }
.bild-gross-leiste .ft-symbolknopf { color: var(--auf-bild); background: var(--auf-bild-flaeche); }
.bild-gross-leiste .ft-symbolknopf:hover { background: var(--auf-bild-hover); color: var(--auf-bild); }

/* ================================================================ Eingabefeld
   Karte mit Radius 12. Text bei 16, Symbolknoepfe 8 vom Rand. */
.input-area { position: relative; z-index: 2; flex: none; padding: 0 var(--abstand-l) var(--abstand-m); }
.input-inner { max-width: 720px; margin: 0 auto; position: relative; display: flex; flex-direction: column; gap: var(--abstand-s); }
.input-box {
  display: flex; flex-direction: column;
  padding: var(--abstand-s);
  background: var(--surface-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  transition: border-color var(--dur-fast) var(--ease-out);
}
.input-box:focus-within { border-color: var(--accent); }
.input-textarea {
  display: block; width: 100%;
  padding: var(--abstand-s);
  font-size: var(--text-body); line-height: var(--leading-normal);
  color: var(--text-primary); background: transparent;
  border: 0; outline: none; resize: none;
  max-height: 200px; overflow-y: auto;
}
.input-textarea::placeholder { color: var(--text-dim); }
.input-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-s); }
.input-left { display: flex; align-items: center; gap: 0; min-width: 0; padding-left: var(--abstand-s); }
.model-pill {
  height: var(--hoehe-steuer); max-width: 180px; min-width: 0;
  padding: 0 var(--abstand-l) 0 var(--abstand-s);
  margin-right: var(--abstand-s);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background-color: transparent; color: var(--text-muted);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  appearance: none; -webkit-appearance: none; cursor: pointer; outline: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
  transition: border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.model-pill:hover { border-color: var(--border-strong); color: var(--text-primary); }
.model-pill:focus-visible { outline: 2px solid var(--indigo-400); outline-offset: 2px; }
.model-pill option { background: var(--surface-raised); color: var(--text-primary); }
.tool-btn, .dr-toggle, .send-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--hoehe-steuer); height: var(--hoehe-steuer);
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.tool-btn:hover, .dr-toggle:hover { background: var(--overlay-hover); color: var(--text-primary); }
.tool-btn:active, .dr-toggle:active { background: var(--overlay-press); }
.tool-btn svg, .dr-toggle svg, .send-btn svg { width: 18px; height: 18px; }
.dr-toggle { display: none; }
.dr-toggle.visible { display: inline-flex; }
.dr-toggle.active, .dr-toggle[aria-pressed="true"], #mic-btn[aria-pressed="true"] { background: var(--accent-quiet); color: var(--accent); }
.send-btn { background: var(--accent); color: var(--text-on-accent); border-radius: var(--radius-full); }
.send-btn:not(:disabled):hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--surface-inset); color: var(--text-dim); cursor: default; opacity: 1; }
.send-btn.stopping { background: var(--text-primary); color: var(--bg-page); }
.send-btn.stopping svg { display: none; }
.send-btn.stopping::after { content: ''; width: 12px; height: 12px; border-radius: 2px; background: currentColor; }
.input-hint { text-align: center; font-size: var(--text-xs); color: var(--text-dim); }
body.welcome-mode .input-hint { display: none; }

/* Anhaenge im Eingabefeld: Karten 56 hoch, Vorschau 40, Entfernen in der rechten Spalte */
.attach-bar { display: none; flex-wrap: wrap; gap: var(--abstand-s); padding: 0 0 var(--abstand-s); }
.attach-bar.has-files { display: flex; }
.attach-item {
  display: flex; align-items: center; gap: var(--abstand-s);
  height: var(--hoehe-kopf); max-width: 240px; min-width: 0;
  padding: 0 var(--abstand-s);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-page); color: var(--text-muted);
}
.attach-item img, .attach-item .file-icon { flex: none; width: 40px; height: 40px; border-radius: var(--radius-sm); object-fit: cover; }
.attach-item .file-icon { display: inline-flex; align-items: center; justify-content: center; background: var(--accent-quiet); color: var(--accent); }
.attach-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-item.laedt { opacity: .7; }
.attach-remove { flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--hoehe-steuer); height: var(--hoehe-steuer); border-radius: var(--radius-sm); color: var(--text-muted); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.attach-remove:hover { background: var(--danger-quiet); color: var(--danger); }
.attach-remove svg { width: 16px; height: 16px; }
.drag-overlay { display: none; position: absolute; inset: 0; z-index: 60; align-items: center; justify-content: center; border: 1px dashed var(--accent); border-radius: var(--radius-md); background: var(--accent-quiet); color: var(--accent); font-weight: var(--weight-medium); }
.drag-overlay.active { display: flex; }

/* Meldung ueber dem Eingabefeld, bleibt bis man sie schliesst */
.sende-hinweis { display: flex; align-items: flex-start; gap: var(--abstand-s); padding: var(--abstand-s) var(--abstand-s) var(--abstand-s) var(--abstand-m); border-radius: var(--radius-md); border: 1px solid var(--danger-border); background: var(--danger-quiet); }
.sende-hinweis-punkt { flex: none; width: var(--abstand-s); height: var(--abstand-s); margin-top: var(--abstand-s); border-radius: var(--radius-full); background: var(--danger); }
.sende-hinweis-text { flex: 1; min-width: 0; padding-top: var(--abstand-s); color: var(--text-muted); line-height: 1.4; }
.sende-hinweis-text strong { display: block; color: var(--text-primary); font-weight: var(--weight-semibold); }

/* Diktat: das Eingabefeld wird zur Pegel-Blase */
.diktat { display: flex; align-items: center; gap: var(--abstand-s); height: var(--hoehe-kopf); padding: 0 var(--abstand-s); border-radius: var(--radius-full); background: var(--surface-card); border: 1px solid var(--accent); animation: einblenden var(--dur) var(--ease-out); }
.diktat-knopf { flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--hoehe-steuer); height: var(--hoehe-steuer); border-radius: var(--radius-full); background: var(--surface-inset); color: var(--text-primary); transition: background var(--dur-fast) var(--ease-out); }
.diktat-knopf:hover { background: var(--overlay-press); }
.diktat-ok { background: var(--accent); color: var(--text-on-accent); }
.diktat-ok:hover { background: var(--accent-hover); }
.diktat-ok:disabled { background: var(--surface-inset); color: var(--text-dim); cursor: default; }
.diktat-mitte { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--abstand-m); }
.diktat-pegel { flex: 1; min-width: 0; height: var(--hoehe-klein); display: flex; align-items: center; justify-content: space-between; gap: 0; overflow: hidden; }
.diktat-pegel span { flex: 1; max-width: 4px; min-width: 2px; height: var(--hoehe-klein); border-radius: var(--radius-full); background: var(--accent); transform: scaleY(.1); transition: transform var(--dur-fast) linear; }
.diktat-zeit { flex: none; font-size: var(--text-xs); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.diktat-hinweis { display: none; color: var(--text-muted); }
.diktat-mitte[data-zustand="erkennt"] .diktat-pegel, .diktat-mitte[data-zustand="erkennt"] .diktat-zeit,
.diktat-mitte[data-zustand="fehler"] .diktat-pegel, .diktat-mitte[data-zustand="fehler"] .diktat-zeit { display: none; }
.diktat-mitte[data-zustand="erkennt"] .diktat-hinweis, .diktat-mitte[data-zustand="fehler"] .diktat-hinweis { display: flex; align-items: center; gap: var(--abstand-s); }
.diktat-mitte[data-zustand="erkennt"] .diktat-hinweis::before { content: ''; flex: none; width: 12px; height: 12px; border-radius: var(--radius-full); border: 2px solid var(--accent); border-top-color: transparent; animation: drehen var(--dur-dreh) linear infinite; }
.diktat-mitte[data-zustand="fehler"] .diktat-hinweis { color: var(--danger); }

/* Vorlese-Player ueber dem Eingabefeld: Karte 56 hoch */
.vorleser { display: none; align-items: center; gap: 0; height: var(--hoehe-kopf); padding: 0 var(--abstand-s); background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--radius-md); }
.vorleser.offen { display: flex; }
.vl-btn { flex: none; display: inline-flex; align-items: center; justify-content: center; width: var(--hoehe-steuer); height: var(--hoehe-steuer); border-radius: var(--radius-sm); color: var(--text-muted); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.vl-btn:hover { background: var(--overlay-hover); color: var(--text-primary); }
.vl-play { background: var(--accent); color: var(--text-on-accent); border-radius: var(--radius-full); margin-right: var(--abstand-s); }
.vl-play:hover { background: var(--accent-hover); color: var(--text-on-accent); }
.vl-mitte { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--abstand-s); padding: 0 var(--abstand-s); }
.vl-titel { font-size: var(--text-xs); color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vl-leiste { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: var(--radius-full); background: var(--surface-inset); outline: none; cursor: pointer; }
.vl-leiste::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; border-radius: var(--radius-full); background: var(--accent); cursor: pointer; }
.vl-leiste::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: var(--radius-full); background: var(--accent); cursor: pointer; }
.vl-zeit { flex: none; padding: 0 var(--abstand-s); font-size: var(--text-xs); color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ================================================================ Suche
   Trefferliste unter dem Suchfeld in der Form eines Menues (.ft-menue). */
.search-results { position: absolute; top: calc(100% + var(--abstand-s)); left: 0; right: 0; z-index: 60; max-height: 360px; overflow-y: auto; display: none; }
.search-results.open { display: block; }
.sr-item { display: flex; flex-direction: column; justify-content: center; min-height: var(--hoehe-kopf); padding: 0 var(--abstand-s); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--dur-fast) var(--ease-out); }
.sr-item:hover, .sr-item.aktiv { background: var(--overlay-hover); }
.sr-title { font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-meta { font-size: var(--text-xs); font-weight: var(--weight-regular); color: var(--text-dim); }
.sr-snippet { font-size: var(--text-xs); color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-item mark { background: var(--highlight-bg); color: var(--highlight-text); }
.sr-leer { padding: var(--abstand-s); color: var(--text-dim); }

/* ================================================================ Toast
   Unten rechts, 24 vom Rand, kommt 8 px von unten. Handy: volle Breite minus 16. */
.toast-stapel { position: fixed; right: var(--abstand-l); bottom: var(--abstand-l); z-index: 3000; display: flex; flex-direction: column; align-items: flex-end; gap: var(--abstand-s); pointer-events: none; }
.toast {
  max-width: 360px; padding: var(--abstand-s) var(--abstand-m);
  border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text-primary);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(8px);
  animation: toast-ein var(--dur) var(--ease-out) forwards;
  pointer-events: auto;
}
.toast.weg { animation: toast-aus var(--dur-fast) var(--ease-out) forwards; }
@keyframes toast-ein { to { opacity: 1; transform: none; } }
@keyframes toast-aus { from { opacity: 1; } to { opacity: 0; } }

/* ================================================================ Dialoge
   Radius 16, Breite 480, Kopf 56 mit Titel auf 24, Fuss rechtsbuendig. */
.dialog-overlay, .settings-overlay {
  position: fixed; inset: 0; z-index: 2000;
  display: none; align-items: center; justify-content: center;
  padding: var(--abstand-l);
  background: var(--scrim);
}
.dialog-overlay.open, .settings-overlay.open { display: flex; animation: einblenden var(--dur-slow) var(--ease-out); }
.dialog-box, .settings-panel {
  width: 100%; max-width: 480px; max-height: calc(100vh - 2 * var(--abstand-l));
  display: flex; flex-direction: column;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  overflow: hidden;
}
.dialog-overlay.open .dialog-box, .settings-overlay.open .settings-panel { animation: dialog-ein var(--dur-slow) var(--ease-out); }
@keyframes dialog-ein { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.dialog-kopf { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-s); height: var(--hoehe-kopf); flex: none; padding: 0 var(--abstand-m) 0 var(--abstand-l); }
.dialog-title { font-size: var(--text-body); font-weight: var(--weight-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-inhalt { padding: 0 var(--abstand-l); display: flex; flex-direction: column; gap: var(--abstand-m); overflow-y: auto; min-height: 0; }
.dialog-desc { color: var(--text-muted); line-height: 1.4; }
.dialog-input {
  width: 100%; height: var(--hoehe-steuer); padding: 0 var(--abstand-s);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-page); color: var(--text-primary); outline: none;
  transition: border-color var(--dur-fast) var(--ease-out);
}
.dialog-input:focus { border-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--abstand-s); padding: var(--abstand-l); flex: none; }
/* Dialog ohne Fuss (Tastenkuerzel): der Inhalt haelt unten dieselbe Kante. */
.dialog-inhalt:last-child { padding-bottom: var(--abstand-l); }
.dialog-link { display: flex; gap: var(--abstand-s); }
.dialog-link .dialog-input { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }
/* Teilen beenden rechts neben dem Link: die Flaeche ragt S ueber die Inhaltskante. */
.dialog-link > .ft-symbolknopf { margin-right: calc(-1 * var(--abstand-s)); }
.dialog-hinweis { font-size: var(--text-xs); color: var(--text-dim); line-height: 1.4; }

/* Projektauswahl im Dialog */
.proj-picker { display: flex; flex-direction: column; max-height: 240px; overflow-y: auto; margin: 0 calc(-1 * var(--abstand-s)); }
.proj-picker-item { display: flex; align-items: center; gap: var(--abstand-s); height: var(--hoehe-steuer); padding: 0 var(--abstand-s); border-radius: var(--radius-sm); cursor: pointer; transition: background var(--dur-fast) var(--ease-out); }
.proj-picker-item:hover { background: var(--overlay-hover); }
.proj-picker-item.selected { background: var(--auswahl-bg); color: var(--auswahl-text); font-weight: var(--weight-medium); }
.proj-picker-icon { flex: none; color: var(--text-dim); }
.proj-picker-item.selected .proj-picker-icon { color: var(--auswahl-symbol); }

/* ================================================================ Einstellungen
   Dialog 640 breit. Kopf 56, darunter die Reiter, Inhalt auf 24. */
.settings-panel { max-width: 640px; height: min(720px, calc(100vh - 2 * var(--abstand-l))); }
.settings-nav { flex: none; }
.settings-nav-items { display: flex; gap: var(--abstand-s); padding: 0 var(--abstand-l); border-bottom: 1px solid var(--border); }
.sn-item {
  position: relative; display: inline-flex; align-items: center; gap: var(--abstand-s);
  height: var(--hoehe-steuer); padding: 0 var(--abstand-s); margin-bottom: var(--abstand-s);
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.sn-item:first-child { margin-left: calc(-1 * var(--abstand-s)); }
.sn-item:hover { background: var(--overlay-hover); color: var(--text-primary); }
.sn-item.active { background: var(--auswahl-bg); color: var(--auswahl-text); font-weight: var(--weight-medium); }
.sn-item.active svg, .sn-item.active [data-sym] { color: var(--auswahl-symbol); }
.sn-item svg { flex: none; width: 16px; height: 16px; }
.sn-item span[data-sym] { display: inline-flex; }
.settings-content { flex: 1; min-height: 0; overflow-y: auto; padding: var(--abstand-l); }
.sc-page { display: none; flex-direction: column; gap: var(--abstand-l); }
.sc-page.active { display: flex; }
.sc-group { display: flex; flex-direction: column; }
.sc-group-title { display: flex; align-items: center; height: var(--hoehe-klein); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-dim); }
/* Trennlinien laufen von Flaechenkante zu Flaechenkante: 8 ueber die Inhaltskante hinaus */
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-m); min-height: var(--hoehe-kopf); margin: 0 calc(-1 * var(--abstand-s)); padding: 0 var(--abstand-s); border-bottom: 1px solid var(--border); }
.sc-row:last-child { border-bottom: 0; }
.sc-row-left { flex: 1; min-width: 0; }
.sc-row-title { font-weight: var(--weight-medium); }
.sc-row-desc { font-size: var(--text-xs); color: var(--text-dim); line-height: 1.4; }
.sc-row > .ft-symbolknopf { margin-right: calc(-1 * var(--abstand-s)); }
.sc-text { color: var(--text-muted); line-height: 1.4; }
.sc-knopfreihe { display: flex; justify-content: flex-end; gap: var(--abstand-s); padding-top: var(--abstand-s); }
.m-select {
  height: var(--hoehe-steuer); min-width: 160px; max-width: 220px;
  padding: 0 var(--abstand-l) 0 var(--abstand-s);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background-color: var(--bg-page); color: var(--text-primary); outline: none; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px, 4px 4px; background-repeat: no-repeat;
}
.m-select:focus-visible { outline: 2px solid var(--indigo-400); outline-offset: 2px; }
.m-select option { background: var(--surface-raised); color: var(--text-primary); }

/* Schalter: rund, 36 x 20 */
.toggle { position: relative; flex: none; width: var(--hoehe-steuer); height: var(--hoehe-abzeichen); }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.toggle-track { position: absolute; inset: 0; border-radius: var(--radius-full); background: var(--surface-inset); box-shadow: inset 0 0 0 1px var(--border-strong); transition: background var(--dur-fast) var(--ease-out); }
.toggle-track::before { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: var(--radius-full); background: var(--white); transition: transform var(--dur-fast) var(--ease-out); }
.toggle input:checked + .toggle-track { background: var(--accent); box-shadow: none; }
.toggle input:checked + .toggle-track::before { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--indigo-400); outline-offset: 2px; }

/* Segmente (Denktiefe, Darstellung) */
.seg { display: inline-flex; padding: 0; gap: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { height: var(--hoehe-steuer); padding: 0 var(--abstand-m); color: var(--text-muted); transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button:hover { background: var(--overlay-hover); color: var(--text-primary); }
.seg button.active, .seg button[aria-pressed="true"] { background: var(--auswahl-bg); color: var(--auswahl-text); font-weight: var(--weight-medium); }
.seg button:focus-visible { outline-offset: -2px; }
.sc-row.aus .seg { opacity: .4; }
.seg button:disabled { cursor: default; }
.seg button:disabled:hover { background: transparent; color: var(--text-muted); }

/* Konto */
.profile-card { display: flex; align-items: center; gap: var(--abstand-m); min-height: var(--hoehe-kopf); }
.profile-card .profile-avatar { width: 40px; height: 40px; font-size: var(--text-body); }
.profile-info { min-width: 0; }
.profile-info h3 { font-size: var(--text-body); font-weight: var(--weight-semibold); }
.profile-info p { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }
.plan-card { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-m); padding: var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); }
.plan-label { font-weight: var(--weight-semibold); }
.plan-sub { font-size: var(--text-xs); color: var(--text-muted); }
/* Wie in den Zeilen darunter: die Flaeche des Symbolknopfs ragt S ueber die Inhaltskante. */
.plan-card > .ft-symbolknopf { margin-right: calc(-1 * var(--abstand-s)); }
.usage-card { display: flex; flex-direction: column; gap: var(--abstand-s); padding: var(--abstand-m); border: 1px solid var(--border); border-radius: var(--radius-md); }
.usage-header { display: flex; justify-content: space-between; gap: var(--abstand-s); }
.usage-model { font-weight: var(--weight-medium); }
.usage-count { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.usage-bar-lg { height: var(--abstand-s); border-radius: var(--radius-full); background: var(--surface-inset); overflow: hidden; }
.usage-bar-fill-lg { height: 100%; border-radius: var(--radius-full); background: var(--accent); transform-origin: left; }
.usage-fuss { font-size: var(--text-xs); color: var(--text-dim); }
.usage-fuss:empty { display: none; }
.usage-card [hidden] { display: none; }
.sc-hinweis { padding-top: var(--abstand-s); font-size: var(--text-xs); color: var(--text-dim); }

/* Gedaechtnis und eigene Anweisungen: eine Flaeche, ein Rand */
.md-textarea {
  width: 100%; min-height: 120px; max-height: 320px; resize: vertical;
  padding: var(--abstand-s);
  font-family: var(--font-mono); font-size: var(--text-xs); line-height: var(--leading-normal);
  color: var(--text-primary); background: var(--bg-page);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); outline: none;
  transition: border-color var(--dur-fast) var(--ease-out);
}
.md-textarea.fliesstext { font-family: var(--font-sans); font-size: var(--text-sm); }
.md-textarea:focus { border-color: var(--accent); }
.md-card { display: flex; flex-direction: column; gap: var(--abstand-s); padding-bottom: var(--abstand-m); }
.md-card-hdr { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-s); min-height: var(--hoehe-steuer); }
.md-card-title { font-weight: var(--weight-medium); font-family: var(--font-mono); font-size: var(--text-xs); }
.md-card-meta { font-size: var(--text-xs); color: var(--text-dim); }
.md-preview {
  font-family: var(--font-mono); font-size: var(--text-xs); line-height: var(--leading-normal);
  color: var(--text-muted);
  max-height: 160px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  padding: var(--abstand-s); border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: text; transition: border-color var(--dur-fast) var(--ease-out);
}
.md-preview[role="button"]:hover { border-color: var(--border-strong); }
.md-preview:empty::before { content: 'Noch leer'; color: var(--text-dim); }
.md-editor { display: none; flex-direction: column; gap: var(--abstand-s); }
.md-editor.open { display: flex; }
.md-actions { display: flex; justify-content: flex-end; gap: var(--abstand-s); }
.md-badge { display: inline-flex; align-items: center; height: var(--hoehe-abzeichen); padding: 0 var(--abstand-s); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.md-badge.on { background: color-mix(in srgb, var(--positive) 16%, transparent); color: var(--positive); }
.md-badge.off { background: var(--surface-inset); color: var(--text-dim); }

/* Tastenkuerzel-Liste */
.kuerzel-liste { display: flex; flex-direction: column; }
.kuerzel-zeile { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-m); min-height: var(--hoehe-steuer); margin: 0 calc(-1 * var(--abstand-s)); padding: 0 var(--abstand-s); border-bottom: 1px solid var(--border); }
.kuerzel-zeile:last-child { border-bottom: 0; }
.kuerzel-zeile kbd { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted); }

/* Weiter-Knopf (Antwort fortsetzen) */
.continue-btn { margin-top: var(--abstand-s); }

/* ================================================================ Leseansicht (geteilter Chat) */
body.lese-seite { overflow: auto; display: flex; flex-direction: column; min-height: 100%; }
/* Seiten mit der Flixtake-Leiste (fest oben, 56): Leseansicht, Anmeldeseite fuer Bilder */
body.mit-leiste { padding-top: var(--hoehe-kopf); }
.lese-titelzeile { display: flex; align-items: center; justify-content: space-between; gap: var(--abstand-m); margin-bottom: var(--abstand-l); }
.lese-titelzeile .lese-titel { margin-bottom: 0; min-width: 0; }
.lese-abzeichen { flex: none; display: inline-flex; align-items: center; height: var(--hoehe-klein); padding: 0 var(--abstand-s); border-radius: var(--radius-full); background: var(--surface-inset); color: var(--text-muted); font-size: var(--text-xs); }
.lese-inhalt { flex: 1; width: 100%; max-width: 768px; margin: 0 auto; padding: var(--abstand-l); }
.lese-titel { font-size: var(--text-h4); font-weight: var(--weight-semibold); line-height: 1.4; margin-bottom: var(--abstand-l); }
.lese-inhalt .lese-verlauf { max-width: none; padding: 0; }
.lese-fuss { padding: var(--abstand-l); text-align: center; font-size: var(--text-xs); color: var(--text-dim); }
.lese-fuss a { color: var(--accent); }
.lese-skelett { display: flex; flex-direction: column; gap: var(--abstand-m); }
.skelett-zeile { height: var(--abstand-m); width: 60%; border-radius: var(--radius-sm); background: var(--surface-raised); animation: denk-puls var(--dur-puls) ease-in-out infinite; }
.skelett-zeile.breit { width: 100%; }
.skelett-zeile.kurz { width: 30%; }
.lese-leer { display: flex; flex-direction: column; align-items: center; gap: var(--abstand-m); padding: var(--abstand-l) 0; text-align: center; color: var(--text-muted); }
.lese-leer [data-sym] { color: var(--text-dim); }
.lese-leer h1 { font-size: var(--text-body); font-weight: var(--weight-semibold); color: var(--text-primary); }
.lese-leer p { max-width: 400px; line-height: 1.4; }
@media (max-width: 767px) { .lese-inhalt, .lese-fuss { padding-left: var(--abstand-m); padding-right: var(--abstand-m); } }

/* iOS-Huelle: die App bringt eigene Kopfzeile und eigenes Eingabefeld */
html.flixi-ios-shell .chat-kopf, html.flixi-ios-shell .sb-schleier { display: none; }

/* ================================================================ Schublade (< 900)
   Die Seitenleiste schiebt von links ueber den Inhalt, darunter ein Schleier.
   Breite bleibt 248; unter 768 wird sie breiter (Handy-Regeln unten). */
.sb-schleier { display: none; }
@media (max-width: 899px) {
  .sidebar {
    position: fixed; top: var(--hoehe-kopf); bottom: 0; left: 0; z-index: 110;
    transform: translateX(-100%);
    transition: transform var(--dur-slow) var(--ease-out);
  }
  /* Schatten nur offen: geschlossen fiele er sonst als Streifen an den linken Rand. */
  .sidebar.open { transform: none; box-shadow: var(--shadow-panel); }
  .sb-schleier { display: block; position: fixed; inset: var(--hoehe-kopf) 0 0 0; z-index: 105; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity var(--dur-slow) var(--ease-out); }
  .sidebar.open ~ .sb-schleier { opacity: 1; pointer-events: auto; }
  .chat-kopf .mob-toggle { display: inline-flex; }
}

/* ================================================================ Handy (< 768)
   Inhaltskante ueberall 16, Zeilen und Tippflaechen 44, Menues als Blatt. */
@media (max-width: 767px) {
  html .ft-symbolknopf { --ft-knopf: var(--hoehe-touch); }
  html .ft-hauptknopf, html .ft-knopf { height: var(--hoehe-touch); }
  html .sidebar .ft-nav-eintrag { height: var(--hoehe-touch); font-size: var(--text-body); }
  .sidebar .sb-mehr { display: inline-flex; }
  .sidebar .sb-zelle-status { display: none; }
  .sidebar { width: min(320px, calc(100vw - var(--hoehe-kopf))); }
  .proj-picker-item { height: var(--hoehe-touch); font-size: var(--text-body); }
  .sb-zelle { width: var(--hoehe-touch); height: var(--hoehe-touch); }
  .sb-search input, .dialog-input, .m-select, .model-pill { height: var(--hoehe-touch); font-size: var(--text-body); }
  .seg button, .sn-item { height: var(--hoehe-touch); }
  .msg-act, .fb-btn, .copy-btn, .tool-btn, .dr-toggle, .send-btn, .attach-remove, .vl-btn, .diktat-knopf { width: var(--hoehe-touch); height: var(--hoehe-touch); }
  .msg-leiste, .msg-actions { opacity: 1; }
  .chat-kopf { padding: 0 var(--abstand-m); }
  .msg-inner { padding: var(--abstand-s) var(--abstand-m) var(--abstand-l); width: 100%; min-width: 0; }
  .input-area { padding: 0 var(--abstand-m) var(--abstand-m); }
  .model-pill { max-width: 132px; }
  .msg.user .msg-body-wrap { max-width: 88%; }
  .toast-stapel { left: var(--abstand-m); right: var(--abstand-m); bottom: var(--abstand-m); align-items: stretch; }
  .toast { max-width: none; }
  .dialog-overlay, .settings-overlay { padding: var(--abstand-m); }
  .settings-overlay { padding: 0; align-items: flex-end; }
  .settings-panel { max-width: none; height: calc(100% - var(--hoehe-kopf)); max-height: none; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .dialog-kopf { padding: 0 var(--abstand-s) 0 var(--abstand-m); }
  .dialog-inhalt { padding: 0 var(--abstand-m); }
  .dialog-inhalt:last-child { padding-bottom: var(--abstand-m); }
  .dialog-actions { padding: var(--abstand-m); }
  .settings-nav-items { padding: 0 var(--abstand-m); }
  .settings-content { padding: var(--abstand-m); }
  .sc-row { flex-wrap: wrap; padding: var(--abstand-s) 0; }
  .m-select { min-width: 0; max-width: 100%; }
  .bild-gross img { padding: 0 var(--abstand-m) var(--abstand-m); }
  .bild-gross-leiste { padding: 0 var(--abstand-s); }
  .vl-titel, .vl-tempo { display: none; }
  .welcome-title { font-size: 28px; line-height: 1.18; max-width: 11ch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 120ms !important; animation-iteration-count: 1 !important; transition-duration: 120ms !important; }
  .toast { transform: none !important; }
  .sidebar { transition: opacity 120ms !important; }
  /* Ladekreis und Warte-Puls stehen still */
  .denk-punkt, .sources-dot, .verb-punkt, .typing-cursor, .streaming-cursor, .sb-skelett::before, .skelett-zeile,
  .img-tile[data-state="laden"]::after, .img-pending-karte::before,
  .step-spinner, .attach-spinner, .kreisel, .diktat-mitte[data-zustand="erkennt"] .diktat-hinweis::before { animation: none !important; }
}
