/* =============================================================
   Signal Web Client — UI
   ----------------------------------------------------------------
   Hybrid Graphite. Apple-Räume + Porsche-Disziplin.
   Eine Schrift (Inter) für UI, JetBrains Mono nur für Zeit/Code.
   Light & Dark via prefers-color-scheme (Auto-Switch).
   Strikte CSP: kein inline-style, kein hx-on, alles hier zentral.
   ============================================================= */

/* --- Page-Transitions ------------------------------------- */

/* Wenn der User in der Sidebar einen anderen Chat anklickt, ist das eine
   normale Navigation zu /chats/{id}. Ohne Hilfe bricht der Browser den
   alten Frame hart ab und rendert den neuen — sichtbarer Flicker. Mit
   `@view-transition: navigation: auto` blendet der Browser stattdessen
   weich zwischen alter und neuer Seite über. Chrome 126+ unterstützt das,
   Safari/Firefox no-op (kein Schaden, fällt graceful zurück). */
@view-transition {
  navigation: auto;
}

/* Default-Cross-Fade abschalten für alles, was sich gar nicht geändert
   haben sollte (Sidebar bleibt identisch beim Chat-Wechsel) — sonst
   flackert die Sidebar mit, obwohl sie inhaltlich gleich ist. Wir setzen
   stattdessen einen named view-transition auf die Chat-Pane allein. */
.sidebar { view-transition-name: messenger-sidebar; }
.chat-pane { view-transition-name: messenger-chat-pane; }

::view-transition-old(messenger-sidebar),
::view-transition-new(messenger-sidebar) {
  /* Sidebar nicht animieren — sie bleibt sichtbar gleich. */
  animation: none;
}
::view-transition-old(messenger-chat-pane),
::view-transition-new(messenger-chat-pane) {
  animation-duration: 180ms;
  animation-timing-function: cubic-bezier(0.2, 0, 0.2, 1);
}

/* --- Animierbare Custom Properties ------------------------ */

/* Ohne @property sind CSS-Variablen nicht interpolierbar — Übergänge
   würden hart snappen. Mit Registrierung als <length> klappt der
   transition-Pfad sauber für die Scroll-Fade-Masken. Browser ohne
   @property-Support fallen graceful auf Snap zurück. */
@property --fade-top {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --fade-bottom {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

/* --- Fonts ------------------------------------------------- */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/InterVariable.woff2") format("woff2-variations"),
       url("/static/fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --- Tokens — Light (Default) ----------------------------- */

:root {
  color-scheme: light dark;

  /* Surfaces */
  --bg-canvas:      #f6f5f2;   /* Hintergrund hinter allem (warm white) */
  --bg-surface:     #ecebe6;   /* Sidebar, Header */
  --bg-elevated:    #ffffff;   /* Karten, Bubbles eingehend */
  --bg-input:       #ffffff;
  --bg-hover:       rgba(0, 0, 0, 0.035);
  --bg-active:      rgba(0, 0, 0, 0.06);
  --bg-bubble-out:  #1c1d20;   /* Eigene Nachrichten — dunkel auf hell */
  --bg-bubble-in:   #ffffff;

  /* Foreground */
  --fg-primary:     #15161a;
  --fg-secondary:   #5a5e67;
  --fg-tertiary:    #8e929b;
  --fg-on-bubble-out: #f3f2ee;
  --fg-on-accent:   #ffffff;

  /* Borders */
  --border-hairline: rgba(0, 0, 0, 0.08);
  --border-soft:     rgba(0, 0, 0, 0.12);
  --border-strong:   rgba(0, 0, 0, 0.20);

  /* Akzent — gedämpftes Brass; einziger Akzent im UI */
  --accent:        #a37d2c;
  --accent-hover:  #876724;
  --accent-soft:   rgba(163, 125, 44, 0.12);

  /* Status */
  --danger:        #b3261e;
  --danger-soft:   rgba(179, 38, 30, 0.10);

  /* Schatten — sehr zurückhaltend */
  --shadow-sm:  0 1px 2px rgba(20, 20, 25, 0.04);
  --shadow-md:  0 6px 24px -8px rgba(20, 20, 25, 0.10),
                0 2px 6px -2px rgba(20, 20, 25, 0.06);
  --shadow-lg:  0 24px 56px -16px rgba(20, 20, 25, 0.18),
                0 4px 12px -4px rgba(20, 20, 25, 0.08);

  /* Geometrie */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 28px;
  --radius-pill: 999px;

  /* Typo */
  --font-ui:   "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas,
               monospace;

  /* Sizing */
  --sidebar-w: 320px;
  --header-h:  64px;
  --composer-max: 880px;

  /* Bewegung */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast:   140ms;
  --t-base:   220ms;
  --t-slow:   420ms;
}

/* --- Tokens — Dark ---------------------------------------
   Greift in zwei Fällen:
   1) System-Präferenz ist dunkel UND der User hat NICHT manuell auf
      Light gestellt (`data-theme="light"`-Override) — Auto-Modus.
   2) Der User hat explizit Dark gewählt (`data-theme="dark"`),
      unabhängig von der System-Präferenz.
   Light ist Default und braucht keinen extra Block — `:root` ohne
   data-theme greift dann automatisch. */
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}

:root[data-theme="dark"] {
  --bg-canvas:      #0c0d10;
  --bg-surface:     #131418;
  --bg-elevated:    #181a1f;
  --bg-input:       #0a0b0d;
  --bg-hover:       rgba(255, 255, 255, 0.04);
  --bg-active:      rgba(255, 255, 255, 0.07);
  --bg-bubble-out:  #f3f2ee;
  --bg-bubble-in:   #1c1e23;
  --fg-primary:     #ededee;
  --fg-secondary:   #a4a8b1;
  --fg-tertiary:    #70747d;
  --fg-on-bubble-out: #15161a;
  --border-hairline: rgba(255, 255, 255, 0.06);
  --border-soft:     rgba(255, 255, 255, 0.10);
  --border-strong:   rgba(255, 255, 255, 0.18);
  --accent:        #d4b072;
  --accent-hover:  #e6c388;
  --accent-soft:   rgba(212, 176, 114, 0.14);
  --danger:        #ef6b66;
  --danger-soft:   rgba(239, 107, 102, 0.14);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-md:  0 6px 24px -8px rgba(0, 0, 0, 0.55),
                0 2px 6px -2px rgba(0, 0, 0, 0.40);
  --shadow-lg:  0 24px 56px -16px rgba(0, 0, 0, 0.70),
                0 4px 12px -4px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg-canvas:      #0c0d10;
    --bg-surface:     #131418;
    --bg-elevated:    #181a1f;
    --bg-input:       #0a0b0d;
    --bg-hover:       rgba(255, 255, 255, 0.04);
    --bg-active:      rgba(255, 255, 255, 0.07);
    --bg-bubble-out:  #f3f2ee;
    --bg-bubble-in:   #1c1e23;
    --fg-primary:     #ededee;
    --fg-secondary:   #a4a8b1;
    --fg-tertiary:    #70747d;
    --fg-on-bubble-out: #15161a;
    --border-hairline: rgba(255, 255, 255, 0.06);
    --border-soft:     rgba(255, 255, 255, 0.10);
    --border-strong:   rgba(255, 255, 255, 0.18);
    --accent:        #d4b072;
    --accent-hover:  #e6c388;
    --accent-soft:   rgba(212, 176, 114, 0.14);
    --danger:        #ef6b66;
    --danger-soft:   rgba(239, 107, 102, 0.14);
    --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.40);
    --shadow-md:  0 6px 24px -8px rgba(0, 0, 0, 0.55),
                  0 2px 6px -2px rgba(0, 0, 0, 0.40);
    --shadow-lg:  0 24px 56px -16px rgba(0, 0, 0, 0.70),
                  0 4px 12px -4px rgba(0, 0, 0, 0.45);
  }
}

/* --- Reset / Basis --------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* Das HTML-`[hidden]`-Attribut wird von vielen unserer komponenten-spezifischen
   Regeln überschrieben (z.B. .msg-menu-item hat display: flex), was dazu
   führte, dass mit JS auf hidden=true gesetzte Items trotzdem sichtbar
   blieben — siehe Composer-Reply-Bug und Edit-bei-fremden-Bubbles-Bug.
   Globale !important-Regel löst das ein für alle Mal. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--fg-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv05", "cv11";
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* Document selbst NIEMALS scrollen lassen — sonst rutscht auf Mobile-
     Browsern beim URL-Bar-Hide/Show das ganze Layout, und Header + Composer
     "verschwinden" obwohl sie sticky aussehen sollten. Scrollen passiert
     ausschließlich innerhalb der .messages-container. */
  overflow: hidden;
  overscroll-behavior: none;
}

/* Auth-/Setup-Seiten haben kein App-Shell-Layout, sondern eine zentrierte
   Karte — die DARF im Document scrollen, falls die Karte mal länger wird
   (z.B. Setup mit Anleitung). overflow: hidden auf body würde das blocken. */
body:has(> .auth-shell) { overflow: auto; }

/* Text-Selection — solid Brass-Hintergrund mit kontraststarkem Text.
   Die alte rgba(brass, 0.12)-Variante war auf dunklen Out-Bubbles
   nahezu unsichtbar. Jetzt: Light Mode = Brass + Weiß (ratio ≈ 4.7),
   Dark Mode = helleres Brass + Tiefschwarz (ratio ≈ 10) — funktioniert
   auf jedem Hintergrund (Page, Out-Bubble, In-Bubble, Composer). */
::selection {
  background: var(--accent);
  color: #ffffff;
}
@media (prefers-color-scheme: dark) {
  ::selection {
    /* Dark mode hat ein helleres Brass — auf dem ist schwarzer Text
       deutlich kontrastreicher als weißer. */
    background: var(--accent);
    color: #0c0d10;
  }
}

a { color: inherit; text-decoration: none; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* Fokus — sichtbar, aber nicht laut */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible,
.conv-item:focus-visible {
  outline-offset: 3px;
}

/* Scrollbars — dezent */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-soft);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* --- Typografie ------------------------------------------ */

h1, h2, h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--fg-primary);
}
h1 { font-size: 1.75rem; letter-spacing: -0.022em; line-height: 1.15; }
h2 { font-size: 1.0625rem; letter-spacing: -0.012em; }
h3 { font-size: 0.9375rem; }

.muted { color: var(--fg-secondary); font-size: 0.875rem; }

.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xs);
  padding: 0.1em 0.4em;
}

/* --- Buttons --------------------------------------------- */

.btn,
button.primary,
button.secondary,
.composer button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-weight: 500;
  font-size: 0.9375rem;
  letter-spacing: -0.005em;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
  white-space: nowrap;
}

/* Primary — kräftig, dominant. */
.btn,
button.primary,
.composer button[type="submit"] {
  background: var(--fg-primary);
  color: var(--bg-canvas);
  box-shadow: var(--shadow-sm);
}
.btn:hover,
button.primary:hover,
.composer button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.btn:active,
button.primary:active,
.composer button[type="submit"]:active { transform: translateY(0); }

/* Secondary — tonale Brass-Variante. Subtiler Brass-Soft-Hintergrund mit
   Brass-Text und brass-getöntem Hairline-Border. Hover füllt zur vollen
   Akzentfarbe um — fühlt sich wie eine zweite, leise Hierarchie unter
   dem Primary an, ohne ins Generische abzufallen. */
.btn.secondary,
button.secondary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(163, 125, 44, 0.22);
  box-shadow: none;
}
.btn.secondary:hover,
button.secondary:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:active,
button.secondary:active { transform: translateY(0); }
.btn.secondary .icon,
button.secondary .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
}
@media (prefers-color-scheme: dark) {
  .btn.secondary,
  button.secondary {
    border-color: rgba(212, 176, 114, 0.28);
  }
  .btn.secondary:hover,
  button.secondary:hover {
    /* Helleres Brass im Dark Mode → schwarzer Text gibt mehr Kontrast. */
    color: var(--bg-canvas);
  }
}

.btn.ghost,
button.ghost {
  background: transparent;
  color: var(--fg-secondary);
  box-shadow: none;
  padding: 0.5rem 0.75rem;
}
.btn.ghost:hover,
button.ghost:hover {
  color: var(--fg-primary);
  background: var(--bg-hover);
}

/* Icon-Button — quadratisch, dezent */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  background: transparent;
  transition: color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.icon-btn:hover { color: var(--fg-primary); background: var(--bg-hover); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn svg { width: 18px; height: 18px; }

/* SVG-Icons — Strich folgt currentColor */
svg.icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Theme-Toggle: progressive Kreis-States in einem SVG.
   `.theme-toggle-ring`  = Outline-Kreis, immer sichtbar
   `.theme-toggle-half`  = halber Fill (Auto-Mode)
   `.theme-toggle-full`  = voller Fill (Dark-Mode)
   Sichtbarkeit wird per data-theme auf <html> gesteuert. */
.theme-toggle-ring {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
}
.theme-toggle-half {
  fill: currentColor;
  stroke: none;
}
.theme-toggle-full {
  fill: currentColor;
  stroke: none;
}

/* Default (kein data-theme = Auto): Half sichtbar, Full versteckt. */
.theme-toggle-half { display: inline; }
.theme-toggle-full { display: none; }

/* Light = expliziter Override: Half UND Full versteckt → nur Outline. */
:root[data-theme="light"] .theme-toggle-half,
:root[data-theme="light"] .theme-toggle-full { display: none; }

/* Dark = expliziter Override: Full sichtbar, Half versteckt. */
:root[data-theme="dark"] .theme-toggle-half { display: none; }
:root[data-theme="dark"] .theme-toggle-full { display: inline; }

/* SVGs dürfen NICHT vom Flex-Shrink zerquetscht werden — sonst landen wir
   bei 3×18-Bugs (gesehen am Send-Button) oder zerrutschtem Play-Icon im
   Video-Overlay. Universell, damit auch SVGs in <span>-Containern (z.B.
   Avatar-Wrapper, Play-Button-Overlays) ihre intrinsic Größe behalten. */
svg { flex-shrink: 0; }

/* --- Forms ---------------------------------------------- */

.field {
  display: block;
  margin-top: 1.1rem;
}
.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-secondary);
  margin-bottom: 0.4rem;
  letter-spacing: 0.005em;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--bg-input);
  color: var(--fg-primary);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  line-height: 1.45;
  resize: vertical;
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
input[type="text"]:hover,
input[type="password"]:hover,
textarea:hover {
  border-color: var(--border-strong);
}
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type="text"].mono,
input.mono {
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}

/* --- Auth / Setup — zentrierte Karte ---------------------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background:
    radial-gradient(1200px 700px at 50% -10%, var(--accent-soft), transparent 60%),
    var(--bg-canvas);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2.25rem 2rem;
  box-shadow: var(--shadow-lg);
  animation: card-in var(--t-slow) var(--ease-out) both;
}
.auth-card .brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
  color: var(--fg-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.auth-card .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--fg-primary);
  color: var(--bg-canvas);
  display: grid;
  place-items: center;
}
.auth-card .brand-mark svg { width: 16px; height: 16px; }

.auth-card h1 {
  font-size: 1.625rem;
  margin-bottom: 0.4rem;
}
.auth-card .lede {
  margin: 0 0 1.25rem;
  color: var(--fg-secondary);
  font-size: 0.9375rem;
}

.auth-card form button[type="submit"] {
  width: 100%;
  margin-top: 1.5rem;
}

.error {
  margin-top: 1rem;
  padding: 0.65rem 0.85rem;
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.875rem;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Setup / QR ------------------------------------------ */

.steps {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.steps li {
  counter-increment: step;
  position: relative;
  padding: 0.65rem 0.75rem 0.65rem 2.5rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--fg-secondary);
  line-height: 1.4;
}
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fg-primary);
  color: var(--bg-canvas);
  font-size: 0.75rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}
.steps em {
  font-style: normal;
  font-weight: 500;
  color: var(--fg-primary);
}

.qr {
  display: grid;
  place-items: center;
  margin: 1.25rem 0 1rem;
}
.qr-frame {
  position: relative;
  padding: 14px;
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.qr-frame img {
  display: block;
  width: 232px;
  height: 232px;
  border-radius: 6px;
}
.qr-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--accent);
  border-radius: 3px;
}
.qr-corner.tl { top: -4px; left: -4px; border-right: 0; border-bottom: 0; }
.qr-corner.tr { top: -4px; right: -4px; border-left: 0; border-bottom: 0; }
.qr-corner.bl { bottom: -4px; left: -4px; border-right: 0; border-top: 0; }
.qr-corner.br { bottom: -4px; right: -4px; border-left: 0; border-top: 0; }

.poll-hint-wrap {
  display: flex;
  justify-content: center;
}
.poll-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem 0.4rem 0.5rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  color: var(--fg-secondary);
}
.poll-hint .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent);
  animation: poll-pulse 1.6s var(--ease-out) infinite;
}
@keyframes poll-pulse {
  0%   { box-shadow: 0 0 0 0 var(--accent-soft); }
  70%  { box-shadow: 0 0 0 8px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* --- App-Shell (Chat) ------------------------------------ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  /* dvh (dynamic viewport height) ist auf Mobile die EINZIG verlässliche
     Maßangabe — sie reflektiert die echte sichtbare Fläche, inkl. dem
     Hide/Show der URL-Bar. vh als Fallback für ältere Browser. */
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: var(--bg-canvas);
  overflow: hidden;     /* doppelte Sicherung gegen Layout-Sprünge */
}

/* --- Sidebar --------------------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  min-height: 0;            /* damit overflow im inner-scroller greift */
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  height: var(--header-h);
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: 1;
  min-width: 0;
}
.sidebar-brand .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--fg-primary);
  color: var(--bg-canvas);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.sidebar-brand .brand-mark svg { width: 16px; height: 16px; }
.sidebar-brand .brand-text {
  display: flex;
  flex-direction: column;
  /* line-height: 1.1 ließ die Sub-Caps direkt am „g"-Descender von „Signal"
     kleben — wir geben den zwei Zeilen Luft mit einer großzügigeren
     Leading. */
  line-height: 1.25;
  min-width: 0;
}
.sidebar-brand .brand-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.sidebar-brand .brand-sub {
  font-size: 0.6875rem;
  color: var(--fg-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  /* Vertikaler Atem zur Zeile darüber, sonst klebt das „E" am Descender
     des „g" von „Signal". */
  margin-top: 3px;
  line-height: 1;
}

.sidebar-section {
  padding: 1rem 1rem 0.4rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  /* Wie der Chat-Pane: Fade nur dort, wo wirklich Inhalt verborgen liegt.
     JS setzt --fade-top / --fade-bottom basierend auf Scroll-Position. */
  --fade-top: 0px;
  --fade-bottom: 0px;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 var(--fade-top),
    #000 calc(100% - var(--fade-bottom)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    #000 var(--fade-top),
    #000 calc(100% - var(--fade-bottom)),
    transparent 100%
  );
}

.conv-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.conv-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--fg-primary);
  text-decoration: none;
  position: relative;
  transition: background var(--t-fast) var(--ease-out);
  cursor: pointer;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active {
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border-hairline);
}
/* Active-Indicator-Bar steckt im Polish-Layer am Ende des Files —
   dort mit smoothem Slide-In bei .active-Toggle. */

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  display: grid;
  place-items: center;
  color: var(--fg-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: -0.01em;
  overflow: hidden;
}
.avatar svg { width: 16px; height: 16px; }
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}
.avatar.avatar-self {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.avatar.avatar-group {
  background: var(--bg-elevated);
  color: var(--fg-secondary);
  border-color: var(--border-soft);
}
/* Initialen-Avatare deutlicher: bisschen mehr Kontrast zur Bubble. */
.avatar:not(.avatar-self):not(.avatar-group) {
  background: var(--bg-elevated);
  color: var(--fg-primary);
  border-color: var(--border-soft);
}
.avatar.avatar-large {
  width: 44px;
  height: 44px;
  font-size: 0.9375rem;
}
.avatar.avatar-xl {
  width: 56px;
  height: 56px;
  font-size: 1.1rem;
}

.conv-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.conv-name {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: 0.8125rem;
  color: var(--fg-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.conv-item.active .conv-name { color: var(--fg-primary); }
.conv-item.active .conv-preview { color: var(--fg-secondary); }

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.conv-unread {
  background: var(--accent);
  color: var(--fg-on-accent);
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 1px 7px;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.sidebar-empty {
  padding: 1.25rem 1rem;
  color: var(--fg-secondary);
  font-size: 0.875rem;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
.sidebar-footer .user-chip {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  min-width: 0;
}
.sidebar-footer .avatar-user {
  width: 28px;
  height: 28px;
  font-size: 0.75rem;
  position: relative;
  overflow: visible;          /* Dot darf außerhalb sitzen */
}
/* Grüner Live-Indikator analog zu Apple Mail / Slack — ein 8px-Dot mit
   Canvas-Ring, der eine kleine optische Trennung zur Avatar-Kante schafft. */
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #4cae5c;
  box-shadow: 0 0 0 2px var(--bg-surface);
}
.sidebar-footer .user-name {
  flex: 1;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.005em;
}
.sidebar-footer form { margin: 0; }

/* --- Chat-Pane ------------------------------------------- */

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-canvas);
  position: relative;
  /* Filter + Opacity sind GPU-accelerated, will-change-Hint signalisiert
     dem Compositor, eine eigene Layer aufzuziehen. Kein Layout-Reflow. */
  will-change: filter, opacity;
}

/* Cross-fade-Trick: alt und neu treffen sich am Swap-Punkt im IDENTISCHEN
   Zwischenstadium (blur(6px) + opacity 0.4). Der eigentliche DOM-Tausch
   passiert genau dort — visuell ein Übergang ohne Bruchstelle, weil das
   Bild davor und danach denselben „weichen Schleier" zeigt. */
.chat-pane.htmx-swapping {
  animation: chat-pane-fade-out 160ms cubic-bezier(0.4, 0, 1, 0.7) forwards;
}
.chat-pane.htmx-added {
  animation: chat-pane-fade-in 260ms cubic-bezier(0.2, 0.6, 0.2, 1) forwards;
}
@keyframes chat-pane-fade-out {
  from { filter: blur(0); opacity: 1; }
  to   { filter: blur(6px); opacity: 0.4; }
}
@keyframes chat-pane-fade-in {
  from { filter: blur(6px); opacity: 0.4; }
  to   { filter: blur(0); opacity: 1; }
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 1.25rem;
  height: var(--header-h);
  /* Frosted-Glass-Layer über dem Messages-Container.
     Bubbles scrollen sichtbar darunter durch — das ist der Premium-Move.
     Damit das überhaupt funktioniert, MUSS der Header `absolute` sitzen
     (nicht flex-Geschwister), und der Messages-Container kompensiert mit
     padding-top. */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  /* 72%/66% Opazität = Text-Kontrast bleibt erhalten, aber Farben
     darunter scheinen subtil durch. saturate(180%) gleicht den
     Sättigungsverlust aus, den blur() sonst verursacht.
     `color-mix` referenziert das Canvas-Token — passt sich dadurch
     automatisch dem aktiven Theme an, egal ob System-Auto oder
     manueller Override. */
  background: color-mix(in oklab, var(--bg-canvas) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
:root[data-theme="dark"] .chat-header,
:root:not([data-theme="light"]) .chat-header {
  /* Im Dark Mode geringere Opazität für mehr Tiefenwirkung. */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chat-header {
    background: color-mix(in oklab, var(--bg-canvas) 66%, transparent);
  }
}
:root[data-theme="dark"] .chat-header {
  background: color-mix(in oklab, var(--bg-canvas) 66%, transparent);
}
/* Sicherheitsnetz: Browser ohne backdrop-filter (sehr alt) bekommen
   einen soliden Hintergrund, damit der Text nie auf transparentem
   Untergrund landet. */
@supports not (backdrop-filter: blur(1px)) {
  .chat-header { background: var(--bg-canvas); }
}
.chat-header .back-btn {
  display: none;
}
.chat-header-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.chat-header-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header-sub {
  font-size: 0.75rem;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 2px;
}
.chat-header-sub .dot-sep {
  width: 3px; height: 3px; border-radius: 50%;
  background: var(--fg-tertiary);
  display: inline-block;
}

/* --- Messages -------------------------------------------- */

.messages-container {
  flex: 1;
  min-height: 0;                       /* Flex-Item darf schrumpfen */
  overflow-y: auto;
  /* Top-Padding kompensiert den absolut positionierten Frost-Header.
     Die erste Bubble startet damit unter ihm; beim Hochscrollen taucht
     sie wieder unter den Frost und verschwimmt elegant. */
  padding: calc(var(--header-h) + 0.75rem) 1.25rem 1rem;
  scrollbar-gutter: stable;
  /* `overflow-anchor: auto` ist Default, hier aber bewusst gesetzt: sorgt
     dafür, dass beim Nachladen eines Bildes oberhalb des Viewports der
     Browser den sichtbaren Anker hält → kein Jitter. */
  overflow-anchor: auto;
  /* KEIN `scroll-behavior: smooth` auf dem Container — programmatische
     Snap-Restores müssen instant sein, sonst überlagern sich Animation
     und nachfolgende Höhen-Korrekturen sichtbar. Smoothes Scroll bleibt
     beim User-Input via Browser-Default erhalten. */
  /* Mobile: kein Scroll-Chaining auf Body (das würde URL-Bar triggern und
     Header/Composer wegspülen). iOS smooth scroll für Touch-Bewegung. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Fade NUR am unteren Rand (am Composer-Übergang). Oben kein Fade —
     der Chat-Header sitzt direkt drüber, da gibt's nichts zu kaschieren.
     `--fade-bottom` wird vom JS dynamisch gesetzt (24px wenn Inhalt
     unten verborgen ist, 0px wenn am Boden angekommen). */
  --fade-bottom: 0px;
  -webkit-mask-image: linear-gradient(
    to bottom,
    #000 0,
    #000 calc(100% - var(--fade-bottom)),
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    #000 0,
    #000 calc(100% - var(--fade-bottom)),
    transparent 100%
  );
}

.empty-msgs {
  text-align: center;
  margin: 5rem auto 0;
  max-width: 360px;
  color: var(--fg-tertiary);
  font-size: 0.9375rem;
}

.msg-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: var(--composer-max);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg {
  display: flex;
  flex-direction: column;
  /* align-items steuert links/rechts; Bubble + Preview-Cards stehen
     untereinander auf derselben Seite. */
  /* KEINE globale Entrance-Animation mehr — wir animieren GEZIELT nur
     frisch eingefügte Bubbles via `.msg-fresh`. Sonst feuert das
     Animation jedes Mal wenn eine Bubble ins DOM kommt (Chat-Wechsel,
     Page-Load), was redundant zum Chat-Pane-Fade ist. */
}
.msg-out { align-items: flex-end; }
.msg-in  { align-items: flex-start; }
.msg-bubble { min-width: 0; }

/* Visuelle Trennung beim Sender-Wechsel */
.msg + .msg-out:not(.msg-out + .msg-out),
.msg + .msg-in:not(.msg-in + .msg-in) { margin-top: 8px; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  /* Block-Element im Flex-Row schrumpft von selbst auf Inhaltsbreite —
     kein width:fit-content, das würde zusammen mit overflow-wrap:anywhere
     den Text in eine 1-Buchstaben-Säule pressen.
     KEIN pre-wrap hier — sonst rendern Jinja-Whitespaces als Leerzeilen. */
  max-width: min(560px, 72%);
  padding: 5px 11px 6px;
  border-radius: 16px;
  line-height: 1.35;
  overflow-wrap: break-word;
  font-size: 0.9rem;
  position: relative;
}

.msg-out .msg-bubble {
  background: var(--bg-bubble-out);
  color: var(--fg-on-bubble-out);
  border-bottom-right-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg-in .msg-bubble {
  background: var(--bg-bubble-in);
  color: var(--fg-primary);
  border: 1px solid var(--border-hairline);
  border-bottom-left-radius: 5px;
}

.msg-sender {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 1px;
  letter-spacing: -0.005em;
}

.msg-text {
  display: inline;
  /* pre-wrap erhält explizite Newlines (Shift+Enter) im echten Text-Inhalt,
     ohne dass Whitespace zwischen Spans gerendert wird. */
  white-space: pre-wrap;
}

/* Zeit klebt iMessage-mäßig hinter dem letzten Wort. nowrap verhindert,
   dass nur die Uhrzeit umbricht; bricht stattdessen sauber als Block um. */
.msg-ts {
  display: inline;
  margin-left: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.02em;
  color: var(--fg-tertiary);
  opacity: 0.75;
  white-space: nowrap;
  vertical-align: baseline;
}
.msg-out .msg-ts {
  color: var(--fg-on-bubble-out);
  opacity: 0.5;
}

/* Wenn die Bubble nur Anhänge ohne Text hat, soll die Zeit eine eigene
   schmale Zeile unterm Anhang bekommen — sonst sitzt sie an der falschen
   Stelle. */
.msg-attachments + .msg-ts {
  display: block;
  margin-left: 0;
  margin-top: 2px;
  text-align: right;
}

/* --- Anhänge --------------------------------------------- */

.msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}
.msg-attachments:last-child { margin-bottom: 0; }

.att-image {
  display: block;
  max-width: 320px;
  max-height: 320px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
}

/* Video-Anhang — wird wie ein Bild dargestellt, autoplay+loop+muted in der
   Bubble (das GIF-Feeling, das Signal-User von der Mobile-App kennen). */
.att-video-link {
  position: relative;
  display: block;
  max-width: 320px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  text-decoration: none;
  color: inherit;
}
.att-video {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 320px;
  object-fit: cover;
  background: var(--bg-canvas);
}
.att-video-play {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.95);
  display: grid;
  place-items: center;
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: transform var(--t-fast) var(--ease-out);
}
.att-video-play svg { width: 14px; height: 14px; transform: translateX(1px); }
.att-video-link:hover .att-video-play { transform: scale(1.06); }

/* Echtes Video — zentraler, größerer Play-Knopf macht klar: das ist ein Video,
   das du anklicken sollst. Kein Autoplay in der Bubble. */
.att-video-play-center {
  right: auto;
  bottom: auto;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  background: rgba(0, 0, 0, 0.62);
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
.att-video-play-center svg { width: 24px; height: 24px; }
.att-video-link:hover .att-video-play-center {
  transform: translate(-50%, -50%) scale(1.06);
}
/* Statisches Video in der Bubble — wir wollen kein "Pause"-Frame der wie ein
   Standbild aussieht. Subtle dunkler Tint zeigt die Inaktivität. */
.att-video-link.is-video .att-video {
  filter: brightness(0.92);
}

.att-file {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.75rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  max-width: 360px;
  transition: background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
}
.msg-out .att-file {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--fg-on-bubble-out);
}
@media (prefers-color-scheme: dark) {
  .msg-out .att-file {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.10);
  }
}
.att-file:hover { border-color: var(--border-strong); }

.att-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--bg-elevated);
  display: grid; place-items: center;
  color: var(--fg-secondary);
}
.msg-out .att-icon {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg-on-bubble-out);
}
.att-icon svg { width: 16px; height: 16px; }

.att-body { min-width: 0; }
.att-name {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-size {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
}
.msg-out .att-size { color: var(--fg-on-bubble-out); opacity: 0.55; }

/* --- Linkify im Bubble-Text ------------------------------ */

.msg-text a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: var(--accent);
  /* Lange URLs dürfen IM Wort brechen — sonst ragen sie über die Bubble
     hinaus. Nur auf Links, nicht auf den ganzen Text-Span. */
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-text a:hover {
  text-decoration-color: currentColor;
  text-decoration-thickness: 1.5px;
}
/* In den dunklen out-Bubbles ist der Brass-Akzent zu schwach — wir nehmen
   dort den Inhalt-Foreground als Underline-Farbe. */
.msg-out .msg-text a { text-decoration-color: rgba(255, 255, 255, 0.5); }
@media (prefers-color-scheme: dark) {
  .msg-out .msg-text a { text-decoration-color: rgba(0, 0, 0, 0.45); }
}

/* --- Link-Preview-Cards ---------------------------------- */

.msg-link-previews {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(560px, 72%);
  margin-top: 4px;
}
.msg-out + .msg-link-previews,
.msg-out .msg-link-previews { align-self: flex-end; }

/* Bubble-Geschwister: positioniere die Preview unterhalb auf gleicher Seite */
.msg-out > .msg-link-previews { margin-left: auto; }

.link-preview {
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
  text-decoration: none;
  color: var(--fg-primary);
  transition: border-color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.link-preview:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.lp-image {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-hairline);
}

.lp-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0.6rem 0.75rem 0.7rem;
  min-width: 0;
}
.lp-site {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lp-title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--fg-primary);
  line-height: 1.3;
  /* Max 2 Zeilen */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lp-desc {
  font-size: 0.8125rem;
  color: var(--fg-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Minimalistischer Fallback — nur Domain, dezenter Pill-Style */
.link-preview-min {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  color: var(--fg-secondary);
  font-size: 0.8125rem;
  width: fit-content;
  box-shadow: none;
}
.link-preview-min .lp-fav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  color: var(--fg-tertiary);
}
.link-preview-min .lp-fav svg { width: 14px; height: 14px; fill: none; }
.link-preview-min .lp-domain {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.01em;
}

/* Pending-Skeleton — sehr dezent. Wird per WebSocket-Refresh ersetzt, sobald
   der Fetcher fertig ist. */
.link-preview-pending {
  display: block;
  height: 56px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}
.link-preview-pending .lp-skel {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    var(--bg-hover),
    transparent
  );
  animation: skel-shimmer 1.6s var(--ease-out) infinite;
}
/* --- Pagination-Sentinel für ältere Nachrichten ---------- */

/* Schmaler Bereich oben in der Liste, der vom IntersectionObserver
   beobachtet wird. Default unsichtbar (nur 1 px hoch); im Lade-Zustand
   leicht aufgedickt mit einem dezenten Spinner. */
.msg-pagination-sentinel {
  position: relative;
  height: 1px;
  margin: 0;
  pointer-events: none;
  transition: height 200ms var(--ease-out);
}
.msg-pagination-sentinel.is-loading {
  height: 28px;
}
.msg-pagination-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  margin-left: -7px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
  animation: msg-pagination-spin 800ms linear infinite;
}
.msg-pagination-sentinel.is-loading .msg-pagination-spinner {
  opacity: 1;
}
@keyframes msg-pagination-spin {
  to { transform: rotate(360deg); }
}

@keyframes skel-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* --- Composer -------------------------------------------- */

.composer-wrap {
  padding: 0.5rem 1rem 1rem;
  background: linear-gradient(to top, var(--bg-canvas) 60%, transparent);
  flex-shrink: 0;
}

.composer {
  margin: 0 auto;
  max-width: var(--composer-max);
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-xl);
  /* Symmetrisch — sonst sind grid-column:1/-1-Children (Reply, Link-
     Preview) sichtbar nach rechts versetzt. Die Textarea kompensiert
     das eigene Atemraum-Padding selbst (siehe `.composer textarea`). */
  padding: 0.4rem;
  display: grid;
  grid-template-columns: 1fr auto;
  /* center: Knopf sitzt vertikal mittig zur Textzeile (statt am Boden).
     Bei mehrzeiliger Eingabe wandert er trotzdem mit, bleibt aber zur
     Mitte ausgerichtet — iMessage-Stil. */
  align-items: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
.composer:focus-within {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.composer textarea {
  margin: 0;
  /* Links 0.45rem mehr Atemraum für den Cursor — kompensiert das
     symmetrische Composer-Padding, sodass die Schreibposition optisch
     bei der gewohnten Stelle landet. */
  padding: 0.65rem 0.25rem 0.65rem 0.7rem;
  background: transparent;
  border: 0;
  resize: none;
  min-height: 2.6rem;
  max-height: 10rem;
  line-height: 1.45;
  font-size: 0.9375rem;
}
.composer textarea:hover,
.composer textarea:focus {
  border: 0;
  box-shadow: none;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--fg-secondary);
  cursor: pointer;
  background: transparent;
  transition: color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.attach-btn:hover { color: var(--fg-primary); background: var(--bg-hover); }
.attach-btn input[type="file"] { display: none; }
.attach-btn svg { width: 18px; height: 18px; }

.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  /* iMessage-Stil: einziger farbiger Akzent im UI sitzt auf dem Send-Button.
     Brass-Gradient verleiht ein bisschen Tiefe ohne laut zu werden. */
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.18), transparent 60%),
    var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 6px var(--accent-soft),
              inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
.send-btn:hover {
  transform: scale(1.06);
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.22), transparent 60%),
    var(--accent-hover);
  box-shadow: 0 4px 14px var(--accent-soft),
              inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.send-btn:active { transform: scale(0.96); }
.send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;            /* deutlicher Strich gegen den Brass-Hintergrund */
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  /* Kein Translate — der viewBox-Mittelpunkt des Pfeils sitzt schon nahe
     an der optischen Mitte, +1px hat ihn unnötig nach unten verschoben. */
}

.attach-list {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.25rem 0.4rem 0.4rem 0.5rem;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.55rem 0.2rem 0.45rem;
  font-size: 0.75rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  color: var(--fg-secondary);
}
.attach-chip svg { width: 12px; height: 12px; }

/* --- Empty State (kein Chat ausgewählt) ------------------- */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem;
  gap: 1rem;
}
.empty-state .empty-mark {
  width: 64px; height: 64px;
  border-radius: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-hairline);
  display: grid; place-items: center;
  color: var(--fg-secondary);
  margin-bottom: 0.5rem;
}
.empty-state .empty-mark svg { width: 28px; height: 28px; }
.empty-state h2 { font-size: 1.25rem; }
.empty-state p { max-width: 360px; }
.empty-state .empty-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.empty-state form { margin: 0; }
.empty-state form button { margin: 0; }

/* --- Type-Badge (klein, neutral) ------------------------- */

.chat-type-badge {
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-tertiary);
  font-weight: 600;
}

/* --- Responsive ------------------------------------------ */

/* Mobile: Single-Pane. Wenn ein Chat aktiv ist (.app-shell hat dann eine
   .chat-header im Chat-Pane), wird die Sidebar versteckt. Sonst zeigen wir
   die Sidebar voll und der leere Chat-Pane (Empty-State) tritt zurück. */
@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  .sidebar,
  .chat-pane {
    grid-column: 1;
    grid-row: 1;
    border-right: 0;
  }
  /* Default: Sidebar oben, Chat-Pane darunter unsichtbar */
  .sidebar { display: flex; }
  .chat-pane { display: none; }

  /* Sobald ein Chat aktiv ist (Chat-Header existiert), Chat-Pane sichtbar
     und Sidebar verstecken. */
  .app-shell:has(.chat-header) .sidebar { display: none; }
  .app-shell:has(.chat-header) .chat-pane { display: flex; }

  .chat-header .back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--fg-secondary);
    text-decoration: none;
    flex-shrink: 0;
  }
  .chat-header .back-btn:hover {
    color: var(--fg-primary);
    background: var(--bg-hover);
  }

  /* Composer + Messages auf voller Breite */
  .messages-container { padding-inline: 0.85rem; }
  .composer-wrap { padding-inline: 0.85rem; }
  .msg-bubble { max-width: 85%; }

  /* Defensive Sicherung: kein horizontaler Scroll auf der Chat-Pane
     selbst — falls eine Komponente überhängt, fällt der Effekt nicht
     direkt auf den Viewport durch. */
  .chat-pane,
  .messages-container {
    overflow-x: clip;
  }
}

/* --- Bubble-Aktionen (Quick-Reactions + Optionen) ------- */

/* Container schwebt auf Hover über/neben der Bubble. Enthält
   Quick-Reaction-Bar (👍 ❤️ usw.) plus optional ⋯-Menü für eigene Nachrichten. */
.msg-actions {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
  z-index: 5;
  white-space: nowrap;
}
.msg-out .msg-actions { right: calc(100% + 8px); }
.msg-in  .msg-actions { left:  calc(100% + 8px); }
.msg:hover .msg-actions,
.msg-actions:focus-within,
.msg-actions:has(.msg-menu-btn[aria-expanded="true"]) {
  opacity: 1;
  pointer-events: auto;
}

.msg-react-quick {
  display: flex;
  align-items: center;
  gap: 0;
}
/* Visueller Separator zwischen Quick-Picker und ⋯-Menü — als pseudo-element
   AM ENDE der Quick-Bar, damit der Menü-Button selbst sauber zentriert ist
   (kein border-left + padding-Trick, der das SVG verschiebt). */
.msg-react-quick::after {
  content: "";
  width: 1px;
  align-self: stretch;
  background: var(--border-hairline);
  margin-left: 4px;
}
/* Wenn keine ⋯-Optionen vorhanden sind (z.B. fremde Bubble), Separator weg. */
.msg-actions:not(:has(.msg-menu-btn)) .msg-react-quick::after {
  display: none;
}
.msg-react-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.msg-react-emoji:hover {
  background: var(--bg-hover);
  transform: scale(1.15);
}
.msg-react-emoji:active { transform: scale(0.96); }

/* Drei-Punkte-Trigger nur für eigene Bubbles, nun innerhalb der Bar.
   Trennstrich macht die Quick-Bar via ::after, der Button bleibt clean
   und perfekt symmetrisch — sonst wandert das ⋯-SVG asymmetrisch. */
.msg-actions .msg-menu-btn {
  position: static;
  transform: none;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: 0;
  box-shadow: none;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
  opacity: 1;
  pointer-events: auto;
}
.msg-actions .msg-menu-btn svg { width: 14px; height: 14px; }
.msg-actions .msg-menu-btn:hover {
  color: var(--fg-primary);
  background: var(--bg-hover);
}

/* Bubble braucht position:relative damit der Container daneben sitzt. */
.msg-bubble { position: relative; }

/* Mobile-Override für die Aktions-Leiste — MUSS nach den Desktop-Regeln
   stehen, weil bei gleicher Spezifität die spätere Regel gewinnt. Die
   Bar wird auf schmalen Screens als Overlay direkt über der Bubble-
   Oberkante platziert, statt seitlich daneben (das schob den Container
   über den Viewport raus → horizontaler Scroll). */
@media (max-width: 820px) {
  .msg-actions {
    top: auto;
    bottom: calc(100% - 14px);
    transform: none;
    /* Damit die Bar selber nicht aus dem Viewport rutscht, wenn die
       Bubble extrem schmal ist (z.B. „Ok"). */
    max-width: calc(100vw - 1.7rem);
  }
  .msg-out .msg-actions {
    right: 0;
    left: auto;
  }
  .msg-in .msg-actions {
    left: 0;
    right: auto;
  }
}

/* --- Reaktions-Anzeige unter der Bubble ----------------- */

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  /* gleiche Seite wie Bubble (Flex-direction column im Eltern .msg) */
}
.msg-reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px 3px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  color: var(--fg-secondary);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
}
.msg-reaction:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.msg-reaction.is-self {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--fg-primary);
}
.msg-reaction-emoji {
  font-size: 0.95rem;
  line-height: 1;
}
.msg-reaction-count {
  font-variant-numeric: tabular-nums;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--fg-tertiary);
}
.msg-reaction.is-self .msg-reaction-count { color: var(--accent); }

/* Floating Menu — wird per JS positioniert (top/left). */
.msg-menu {
  position: fixed;
  z-index: 50;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  animation: menu-in 140ms var(--ease-out);
}
.msg-menu[hidden] { display: none; }
@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.msg-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--fg-primary);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
}
.msg-menu-item svg { width: 15px; height: 15px; color: var(--fg-secondary); }
.msg-menu-item:hover {
  background: var(--bg-hover);
}
.msg-menu-item:hover svg { color: var(--fg-primary); }
.msg-menu-danger { color: var(--danger); }
.msg-menu-danger svg { color: var(--danger); }
.msg-menu-danger:hover { background: var(--danger-soft); }

/* Edit-Disabled (außerhalb 24h-Fenster) — visuell gemuted, click no-op. */
.msg-menu-item[aria-disabled="true"] {
  opacity: 0.42;
  cursor: not-allowed;
}
.msg-menu-item[aria-disabled="true"]:hover { background: transparent; }

/* --- Soft-Delete-Anzeige --------------------------------- */

.msg-deleted .msg-bubble {
  background: transparent !important;
  border: 1px dashed var(--border-soft) !important;
  box-shadow: none !important;
  color: var(--fg-tertiary) !important;
  border-radius: 14px !important;
}
.msg-deleted-text {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-style: italic;
  font-size: 0.85rem;
}
.msg-deleted-text svg { width: 13px; height: 13px; opacity: 0.7; }
/* Wichtig: Die globale .msg-out .msg-ts-Regel setzt eine dunkle Farbe für den
   Kontrast auf der hellen Out-Bubble. Bei der gelöschten Bubble ist die
   Bubble aber transparent → dunkler Text auf dunklem Canvas wäre unsichtbar.
   Also explizit auf die neutrale fg-tertiary-Farbe zurückzwingen. */
.msg-deleted-text .msg-ts,
.msg-out.msg-deleted .msg-ts,
.msg-deleted .msg-ts {
  color: var(--fg-tertiary) !important;
  opacity: 0.85 !important;
  margin-left: 0.45rem;
}

/* --- Peek-Toggle für gelöschte Nachrichten ---------------- */

/* Auge-Button als dezenter Affordance-Hint. Sitzt direkt nach dem Label,
   vor dem Timestamp. Im normalen Zustand fast unsichtbar, wird beim
   Hover deutlich. Im aktiven (Peek-)Zustand brassgetönt. */
.msg-deleted-peek {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin: 0 0.05rem;
  border: 0;
  background: transparent;
  color: var(--fg-tertiary);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
}
.msg-deleted-peek:hover {
  opacity: 1;
  background: var(--bg-hover);
  color: var(--fg-secondary);
}
.msg-deleted-peek:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  opacity: 1;
}
.msg-deleted-peek .icon { width: 14px; height: 14px; opacity: 1; }
.msg-deleted-peek[aria-pressed="true"] {
  color: var(--accent);
  opacity: 1;
}

/* Peek-Zustand der Bubble: Original wird sichtbar, aber visuell klar als
   „gerade enthülltes Geheimnis" markiert — gepunkteter Rand, leicht
   brassgetönte Tinte, italic. Vermeidet die Verwechslung mit einer
   regulären Nachricht. */
.msg-deleted-revealed {
  font-style: italic;
  font-size: 0.875rem;
  color: var(--fg-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.4;
}
.msg-deleted .msg-bubble:has(.is-peeking),
.msg-deleted-text.is-peeking {
  /* Wenn :has() nicht greift, hängt die Klasse direkt am text-Span. */
}
.msg-deleted-text.is-peeking {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.5rem;
}
.msg-deleted.msg-out .msg-bubble:has(.msg-deleted-text.is-peeking),
.msg-deleted .msg-bubble:has(.msg-deleted-text.is-peeking) {
  /* Brass-getönter Rand statt grauem Strich, damit der Peek-Zustand
     visuell „aktiv" wirkt. */
  border-color: rgba(163, 125, 44, 0.45) !important;
  background: var(--accent-soft) !important;
}
@media (prefers-color-scheme: dark) {
  .msg-deleted .msg-bubble:has(.msg-deleted-text.is-peeking) {
    border-color: rgba(212, 176, 114, 0.40) !important;
  }
}

/* --- Sticker-Platzhalter --------------------------------- */
/* Wenn signal-cli das Pack-Image nicht auflösen kann, zeigen wir nur
   einen dezenten Marker — analog zum Soft-Delete-Stil, damit die
   Konversation visuell nicht durch große leere Bubbles unterbrochen wird. */
.msg-sticker .msg-bubble {
  background: transparent !important;
  border: 1px dashed var(--border-soft) !important;
  box-shadow: none !important;
  color: var(--fg-tertiary) !important;
  border-radius: 14px !important;
  padding: 4px 11px 5px !important;
}
.msg-sticker-text {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  font-size: 0.85rem;
}
.msg-sticker-emoji {
  font-size: 1.05rem;
  line-height: 1;
  filter: saturate(0.9);
}
.msg-sticker-label {
  font-style: italic;
  letter-spacing: 0.01em;
}
/* Out-Bubble-Farbe-Override greift sonst auf den Sticker-Text durch — wir
   ziehen ihn explizit auf den neutralen tertiary-Ton. */
.msg-out.msg-sticker .msg-sticker-text,
.msg-sticker .msg-sticker-text .msg-ts {
  color: var(--fg-tertiary) !important;
  opacity: 0.85 !important;
}

/* --- Edit-Marker ----------------------------------------- */

.msg-edited {
  font-size: 0.65rem;
  font-style: italic;
  color: var(--fg-tertiary);
  opacity: 0.85;
  margin-left: 0.3rem;
  white-space: nowrap;
  cursor: help;
  letter-spacing: 0.01em;
}
.msg-out .msg-edited {
  color: var(--fg-on-bubble-out);
  opacity: 0.55;
}

/* --- Read-Receipt-Indikator (eigene Bubbles) ------------- */

/* Häkchen rechts neben msg-ts in der eigenen Bubble.
   - sent     = ein leeres Häkchen, dezent
   - delivered= zwei leere Häkchen, dezent
   - read     = zwei gefüllte Häkchen in akzentfarbe (lesbar) */
.msg-receipt {
  display: inline-flex;
  align-items: center;
  margin-left: 0.25rem;
  vertical-align: middle;
  line-height: 0;
  color: var(--fg-on-bubble-out);
  opacity: 0.55;
  cursor: help;
}
.msg-receipt .icon {
  width: 14px;
  height: 14px;
  display: block;
}
.msg-receipt-read {
  /* Signal nutzt Blau für „gelesen" — wir greifen auf den Akzent zurück,
     der je nach Theme passt (dunkel = hell, hell = dunkel). */
  color: var(--accent, #4ea1ff);
  opacity: 1;
}
.msg-receipt-pending {
  /* Sand-Uhr/Clock — sanft pulsierend, damit der User merkt: wird grad
     gesendet. Animation ist subtil, kein Spinner-Karussell. */
  opacity: 0.75;
  animation: msg-pending-pulse 1.4s ease-in-out infinite;
}
.msg-receipt-failed {
  /* Roter Warn-Indikator. Steht für sich, damit es deutlich heraussticht. */
  color: var(--color-danger, #d4435c);
  opacity: 1;
}
@keyframes msg-pending-pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.85; }
}

/* --- Pending / Failed Bubble-States ----------------------- */

/* Optimistische Bubble — leicht ausgegraut, signalisiert „on the wire". */
.msg-pending .msg-bubble {
  opacity: 0.75;
}
/* Fehlgeschlagene Bubble — rötlicher Hintergrund + Border, bleibt
   stehen damit der User die Nachricht abschreiben oder retryn kann. */
.msg-failed .msg-bubble {
  background: rgba(212, 67, 92, 0.16) !important;
  border: 1px solid rgba(212, 67, 92, 0.45);
  color: var(--fg-primary);
}
.msg-failed.msg-out .msg-bubble {
  /* Out-Bubbles haben dunklen Hintergrund — Override mit rötlichem Tint. */
  background: rgba(212, 67, 92, 0.22) !important;
}
.msg-pending-attachments {
  font-style: italic;
  color: var(--fg-on-bubble-out);
  opacity: 0.7;
  font-size: 0.85em;
}

/* --- Inline-Edit-Mode ------------------------------------ */

/* Edit-Bubble bricht aus der In/Out-Optik aus — sie verhält sich wie ein
   modaler Composer und braucht ihre eigene neutrale Oberfläche, damit der
   „Abbrechen"-Button nicht hellgrau auf weißem Out-Bubble-BG verschwindet. */
.msg-bubble.is-editing {
  min-width: min(420px, 80vw);
  background: var(--bg-elevated) !important;
  color: var(--fg-primary) !important;
  border: 1px solid var(--border-soft) !important;
  box-shadow: var(--shadow-sm) !important;
  border-radius: 14px !important;
  padding: 8px 10px 10px;
}
.msg-edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  width: 100%;
}
.msg-edit-textarea {
  width: 100%;
  min-height: 2.4rem;
  max-height: 12rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-input);
  color: var(--fg-primary);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.4;
  resize: none;
}
.msg-edit-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}
.msg-edit-actions button {
  margin: 0;
  padding: 0.35rem 0.7rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.msg-edit-cancel {
  background: transparent;
  color: var(--fg-secondary);
  border: 1px solid var(--border-soft);
}
.msg-edit-cancel:hover {
  color: var(--fg-primary);
  background: var(--bg-hover);
}
.msg-edit-save {
  background: var(--accent);
  color: var(--fg-on-accent);
  font-weight: 500;
}
.msg-edit-save:hover { background: var(--accent-hover); }
.msg-edit-hint {
  font-size: 0.65rem;
  color: var(--fg-tertiary);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  align-self: flex-start;
  margin-right: auto;
}

/* --- Confirm-Dialog für Delete --------------------------- */

.confirm-dialog {
  width: min(380px, 90vw);
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.confirm-dialog::backdrop {
  background: rgba(8, 9, 12, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.confirm-body {
  padding: 1.2rem 1.25rem 1rem;
}
.confirm-body h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}
.confirm-body p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--fg-secondary);
  line-height: 1.45;
}
.confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
}
.confirm-actions button {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  border-radius: var(--radius-pill);
}
.confirm-cancel {
  background: transparent;
  color: var(--fg-primary);
  border: 1px solid var(--border-soft);
}
.confirm-cancel:hover { background: var(--bg-hover); }
.confirm-confirm {
  background: var(--danger);
  color: #ffffff;
}
.confirm-confirm:hover { filter: brightness(1.06); }

/* --- Lightbox -------------------------------------------- */

.lightbox {
  /* Reset des Default-<dialog> — wir nehmen volle Viewport-Größe und
     positionieren selbst. */
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-primary);
  overflow: hidden;
}
.lightbox::backdrop {
  background: rgba(8, 9, 12, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.lightbox[open] { animation: lightbox-in 220ms var(--ease-out); }
@keyframes lightbox-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.lightbox-frame {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.lightbox-toolbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  color: rgba(255, 255, 255, 0.92);
  z-index: 2;
}
.lightbox-meta {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  min-width: 0;
}
.lightbox-name {
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
.lightbox-size {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.02em;
}
.lightbox-actions {
  display: flex;
  gap: 4px;
}
.lightbox-actions .icon-btn {
  color: rgba(255, 255, 255, 0.85);
}
.lightbox-actions .icon-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.10);
}

.lightbox-image,
.lightbox-video {
  grid-row: 2;
  align-self: center;
  justify-self: center;
  max-width: min(96vw, calc(100vw - 2rem));
  max-height: calc(100vh - 5rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: lightbox-image-in 280ms var(--ease-out) both;
}
.lightbox-video {
  background: #000;
}
.lightbox-image[hidden],
.lightbox-video[hidden] { display: none; }
@keyframes lightbox-image-in {
  from { opacity: 0; transform: scale(0.985); }
  to   { opacity: 1; transform: scale(1); }
}

/* --- Page-Layout (Settings/Groups/Search) ---------------- */

.page-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 1.25rem;
  height: var(--header-h);
  /* Konsistent zur .chat-header: gleicher Frosted-Glass-Layer in
     Einstellungen, Suche und Gruppen-Verwaltung. */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: color-mix(in oklab, var(--bg-canvas) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .page-header {
    background: color-mix(in oklab, var(--bg-canvas) 66%, transparent);
  }
}
:root[data-theme="dark"] .page-header {
  background: color-mix(in oklab, var(--bg-canvas) 66%, transparent);
}
@supports not (backdrop-filter: blur(1px)) {
  .page-header { background: var(--bg-canvas); }
}
.page-header-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}
.page-header-name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-header-sub {
  font-size: 0.75rem;
  color: var(--fg-tertiary);
  margin-top: 2px;
}

.page-scroll {
  flex: 1;
  overflow-y: auto;
  /* Top-Padding kompensiert den absoluten Frost-Header — analog zur
     .messages-container im Chat. */
  padding: calc(var(--header-h) + 1rem) 1.25rem 2rem;
  scrollbar-gutter: stable;
}

.settings-card {
  max-width: 640px;
  margin: 0 auto 1.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.settings-card h3 {
  margin: 0 0 0.4rem;
  font-size: 1rem;
}
.settings-card .muted { margin: 0 0 1rem; }
.settings-card.settings-card-danger {
  border-color: var(--danger-soft);
}
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.settings-form .field { margin-top: 0.4rem; }
.settings-form button[type="submit"] {
  align-self: flex-start;
  margin-top: 1rem;
}

/* --- Geräte-/Mitglieder-Listen --------------------------- */

.device-list, .member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.device-item, .member-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
}
.device-meta, .member-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.device-name, .member-name {
  font-size: 0.9rem;
  font-weight: 500;
}
.device-detail, .member-detail {
  font-size: 0.7rem;
  color: var(--fg-tertiary);
  letter-spacing: 0.01em;
}
.member-avatar { width: 32px; height: 32px; font-size: 0.85rem; }
.device-primary {
  font-size: 0.7rem;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}
.device-unlink, .member-remove {
  color: var(--danger);
  font-size: 0.8125rem;
}
.device-unlink:hover, .member-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger-soft);
}
button.danger:hover {
  background: var(--danger-soft);
}

/* --- Page-Such-Form (Header) ----------------------------- */

.page-search-form {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-pill);
  padding: 0.4rem 0.85rem;
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
.page-search-form:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.page-search-icon { color: var(--fg-tertiary); }
.page-search-form input {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 0;
  font-size: 0.9375rem;
  color: var(--fg-primary);
}
.page-search-form input:focus {
  outline: none;
  box-shadow: none;
  border: 0;
}
.page-search-clear {
  width: 26px;
  height: 26px;
}

/* --- Such-Ergebnisse ------------------------------------- */

.search-empty {
  max-width: 480px;
  margin: 4rem auto 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.search-summary {
  max-width: 720px;
  margin: 0 auto 1rem;
  font-size: 0.875rem;
}
.search-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.search-hit {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--t-fast) var(--ease-out),
              transform var(--t-fast) var(--ease-out);
}
.search-hit:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.search-hit-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.search-hit-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.search-hit-conv {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-hit-ts {
  font-size: 0.7rem;
  color: var(--fg-tertiary);
  flex-shrink: 0;
}
.search-hit-sender {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}
.search-hit-snippet {
  font-size: 0.875rem;
  color: var(--fg-secondary);
  line-height: 1.4;
}
.search-hit-snippet mark {
  background: var(--accent-soft);
  color: var(--fg-primary);
  border-radius: 2px;
  padding: 0 1px;
}

/* --- Sidebar-Header-Actions ------------------------------ */

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.sidebar-header-actions form { margin: 0; }

/* --- Bubble: Quote / Pin / Mentions ---------------------- */

.msg-quote {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin-bottom: 4px;
  padding: 4px 0;
  cursor: default;
  max-width: 320px;
}
.msg-quote-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}
.msg-out .msg-quote-bar {
  background: rgba(255, 255, 255, 0.6);
}
@media (prefers-color-scheme: dark) {
  .msg-out .msg-quote-bar { background: rgba(0, 0, 0, 0.45); }
}
.msg-quote-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.msg-quote-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.005em;
}
.msg-out .msg-quote-author { opacity: 0.85; }
.msg-quote-text {
  font-size: 0.8125rem;
  color: var(--fg-secondary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.msg-out .msg-quote-text {
  color: var(--fg-on-bubble-out);
  opacity: 0.7;
}

.msg-pin-marker {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}
.msg-pin-marker svg { width: 11px; height: 11px; }
.msg-out .msg-pin-marker { color: var(--fg-on-bubble-out); opacity: 0.7; }

.msg-mentions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 3px;
}
.msg-mention {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 6px;
  border-radius: 999px;
}
.msg-out .msg-mention {
  background: rgba(255, 255, 255, 0.2);
  color: var(--fg-on-bubble-out);
}
@media (prefers-color-scheme: dark) {
  .msg-out .msg-mention { background: rgba(0, 0, 0, 0.15); }
}

/* --- Composer-Reply-State -------------------------------- */

.composer-reply {
  grid-column: 1 / -1;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem 0.4rem 0.4rem;
  margin: 0 0.25rem 0.4rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
}
/* Globaler Override: das [hidden]-Attribut darf nicht durch display:flex
   weiter oben aufgehoben werden — sonst bleibt die Reply-Box ständig
   sichtbar und blockiert visuell den Composer-Eingaberaum. */
.composer-reply[hidden] { display: none !important; }
.composer-reply-bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}
.composer-reply-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.composer-reply-author {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
}
.composer-reply-text {
  font-size: 0.8125rem;
  color: var(--fg-secondary);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.composer-reply-cancel {
  width: 28px;
  height: 28px;
  align-self: center;
}

/* --- Live-Linkvorschau im Composer ----------------------- */

/* Liegt wie das Reply-Element auf einer eigenen Grid-Row über der
   Textarea — wandert mit nach oben, wenn das Textfeld wächst. */
/* --- Drag-and-Drop-Overlay für Dateien ------------------ */

/* Wenn ein File-Drag über dem Fenster läuft, kriegt die aktive Chat-Pane
   diese Klasse. Das ::after pseudo-element legt ein dezentes Overlay
   mit gestrichelter Brass-Border und zentrierter Beschriftung über die
   gesamte Pane. */
.chat-pane.is-drag-over::after {
  content: "Datei hier ablegen zum Anhängen";
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--accent-soft) 100%, var(--bg-canvas) 50%);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  border: 2px dashed var(--accent);
  border-radius: 0;
  color: var(--accent);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  pointer-events: none;
  animation: drop-overlay-in 180ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes drop-overlay-in {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1); }
}

/* --- Anhang-Chips im Composer --------------------------- */

.composer-attachments {
  grid-column: 1 / -1;
  margin: 0 0.25rem 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.composer-attachments[hidden] { display: none !important; }

.composer-att-chip {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.4rem 0.5rem 0.4rem 0.4rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  max-width: 280px;
  /* Wenn nur eine Datei: nimm gerne mehr Breite, sonst Liste eng. */
  flex: 0 0 auto;
}
.composer-att-icon {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--fg-secondary);
}
.composer-att-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.composer-att-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.composer-att-svg svg {
  width: 22px;
  height: 22px;
}
.composer-att-ext {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  line-height: 1;
}
:root[data-theme="dark"] .composer-att-ext {
  color: var(--bg-canvas);
}
.composer-att-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.composer-att-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer-att-size {
  font-size: 0.7rem;
  color: var(--fg-tertiary);
  letter-spacing: 0.02em;
}
.composer-att-remove {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-tertiary);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast) var(--ease-out),
              color var(--t-fast) var(--ease-out);
}
.composer-att-remove:hover {
  background: var(--bg-hover);
  color: var(--fg-primary);
}
.composer-att-remove svg {
  width: 14px;
  height: 14px;
}

.composer-link-preview {
  grid-column: 1 / -1;
  margin: 0 0.25rem 0.4rem;
}
.composer-link-preview[hidden] { display: none !important; }

.composer-link-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 0.65rem;
  padding: 0.5rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--t-fast) var(--ease-out),
              opacity var(--t-fast) var(--ease-out);
}
.composer-link-card:hover {
  border-color: var(--border-strong);
}
.composer-link-card.is-loading {
  opacity: 0.65;
}
/* Wenn kein Bild da ist: Card kollabiert auf eine Spalte. */
.composer-link-card:has(.composer-link-image-wrap[hidden]) {
  grid-template-columns: 1fr;
}
.composer-link-image-wrap {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-elevated);
}
.composer-link-image-wrap[hidden] { display: none; }
.composer-link-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.composer-link-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  align-self: center;
}
.composer-link-site {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer-link-site:empty { display: none; }
.composer-link-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--fg-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.composer-link-title:empty { display: none; }
.composer-link-desc {
  font-size: 0.8125rem;
  color: var(--fg-secondary);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}
.composer-link-desc:empty { display: none; }
.composer-link-state {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--fg-tertiary);
  font-style: italic;
}
.composer-link-state[hidden] { display: none !important; }

/* --- Typing-Indicator ------------------------------------ */

.chat-header-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--fg-tertiary);
  font-style: italic;
}
.chat-header-typing[hidden] { display: none; }
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.typing-dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--fg-tertiary);
  animation: typing-pulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-pulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-2px); }
}

/* --- Typing-Indicator in der Sidebar --------------------- */

/* Default: versteckt — wird von JS via `.conv-item.is-typing` aktiviert.
   Wenn aktiv, ersetzt es die preview-Zeile durch die animierten Dots —
   identisch zur Header-Animation, ohne zusätzlichen Text. iMessage-
   Stil: klares „da tippt jemand", ohne Layout-Sprung. */
.conv-typing { display: none; }
.conv-item.is-typing .conv-preview { display: none; }
.conv-item.is-typing .conv-typing {
  display: inline-flex;
  align-items: center;
  /* Farb-Akzent — Brass passt zur Stilistik des Active-Indicators. */
  color: var(--accent);
}
.conv-item.is-typing .typing-dots span {
  background: var(--accent);
}

/* --- Toast-Stack (unten rechts) -------------------------- */

.toast-stack {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-left: 3px solid var(--fg-secondary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  color: var(--fg-primary);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  animation: toast-in 220ms var(--ease-out) both;
}
.toast.toast-leaving {
  animation: toast-out 200ms var(--ease-out) both;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}
.toast-error { border-left-color: var(--danger); }
.toast-message { border-left-color: var(--accent); }
.toast-title {
  grid-column: 1;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.toast-msg {
  grid-column: 1;
  color: var(--fg-secondary);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  word-wrap: break-word;
  /* So viel Text wie elegant in den Toast passt (3 Zeilen), darüber
     hinaus sauber mit „…" abgeschnitten. `-webkit-box`/`line-clamp`
     wird inzwischen von allen Zielbrowsern verstanden. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast-title + .toast-msg { margin-top: 2px; }
.toast-close {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-tertiary);
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast-close:hover { color: var(--fg-primary); background: var(--bg-hover); }
.toast-close svg { width: 12px; height: 12px; }
a.toast {
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out);
}
a.toast:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  border-left-color: var(--accent);
}

/* --- Popover-Modal (Confirm + Prompt) -------------------- */

.popover {
  width: min(420px, 92vw);
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--fg-primary);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.popover::backdrop {
  background: rgba(8, 9, 12, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.popover[open] { animation: card-in 180ms var(--ease-out); }
.popover-body { padding: 1.25rem 1.4rem 1rem; }
.popover-title {
  margin: 0 0 0.4rem;
  font-size: 1rem;
  letter-spacing: -0.005em;
}
.popover-message {
  margin: 0;
  font-size: 0.875rem;
  color: var(--fg-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.popover-message:empty { display: none; }
.popover-input {
  width: 100%;
  margin-top: 0.85rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  color: var(--fg-primary);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.popover-input[hidden] { display: none; }
.popover-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.85rem 1.4rem 1rem;
  border-top: 1px solid var(--border-hairline);
  background: var(--bg-canvas);
}
.popover-actions button {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  border-radius: var(--radius-pill);
}
.popover-cancel {
  background: transparent;
  color: var(--fg-primary);
  border: 1px solid var(--border-soft);
}
.popover-cancel:hover { background: var(--bg-hover); }
.popover-confirm {
  background: var(--fg-primary);
  color: var(--bg-canvas);
}
.popover-confirm:hover { filter: brightness(1.06); }
.popover-confirm.danger { background: var(--danger); color: #fff; }

/* =============================================================
   POLISH-LAYER — Apple-grade Micro-Animationen.
   Subtil, kausal, GPU-accelerated. Nichts in dieser Sektion ist
   essentiell für Funktion — alles ist „Charakter".
   ============================================================= */

/* --- Bubble-Entrance: causality matters --------------------
   Outbound (eigene Sendung): Bubble „launcht" leicht aus Boden-
   Richtung mit minimalem Scale-Overshoot — wie iMessage's Ballon-
   Inflate. Spürbar, aber sub-300ms.
   Inbound (vom Gegenüber): sanfter Slide+Settle, kein Overshoot,
   weil's nicht „dein" Event ist.
   `backwards`-Fill = Element startet im from-Keyframe, vermeidet
   den 1-Frame-Flash vor Animationsstart.
   ----------------------------------------------------------- */
@keyframes bubble-arrive-out {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.88);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes bubble-arrive-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.msg-fresh.msg-out {
  animation: bubble-arrive-out 320ms cubic-bezier(0.32, 1.4, 0.4, 1) backwards;
  /* Transform-origin auf rechts-unten = Bubble „wächst" aus Composer-
     Richtung hoch. Causality: das Ding kommt da raus, wo der User
     gerade getippt hat. */
  transform-origin: right bottom;
}
.msg-fresh.msg-in {
  animation: bubble-arrive-in 280ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
  transform-origin: left bottom;
}

/* --- Send-Button: tactile press ----------------------------
   Press shrinkt schnell + linear (anticipation), Release federt
   mit leichtem Overshoot zurück zur Ruhe. Spring-Charakter.
   ----------------------------------------------------------- */
.send-btn {
  transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
              background-color var(--t-fast) var(--ease-out),
              box-shadow var(--t-fast) var(--ease-out);
}
.send-btn:active {
  transform: scale(0.92);
  transition-duration: 80ms;
  transition-timing-function: cubic-bezier(0.4, 0, 0.6, 1);
}

/* --- Composer: subtile Elevation bei Focus -----------------
   Beim Aktivieren der Textarea hebt sich die ganze Composer-Bar
   1 px an + bekommt einen weicheren Schatten. Mikrofeedback,
   das dem User sagt: „du bist jetzt im Schreib-Modus".
   ----------------------------------------------------------- */
.composer {
  transition: border-color var(--t-fast) var(--ease-out),
              box-shadow 220ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}
.composer:focus-within {
  transform: translateY(-1px);
}

/* --- Sidebar: Avatar reagiert auf Hover --------------------
   Statt das ganze List-Item zu shiften (was unruhig wirkt),
   skaliert nur der Avatar minimal. Apple Music in der Mediathek-
   Liste verwendet den gleichen Trick.
   ----------------------------------------------------------- */
.conv-item .avatar {
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
}
.conv-item:hover .avatar {
  transform: scale(1.06);
}
.conv-item:active .avatar {
  transform: scale(1.02);
  transition-duration: 80ms;
}

/* --- Sidebar: Active-Indicator ----------------------------
   Linker, brassfarbener Stab am aktiven Item — bekommt eine
   sanfte Slide-In-Animation, sobald die `.active`-Klasse gesetzt
   wird. Nutzt ::before, damit das Item-Layout selbst stabil
   bleibt. */
.conv-item {
  position: relative;
}
.conv-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18%;
  bottom: 18%;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: center;
  opacity: 0;
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
              opacity 200ms ease-out;
  pointer-events: none;
}
.conv-item.active::before {
  transform: scaleY(1);
  opacity: 1;
}

/* --- Reaction-Badge: Pop-In bei Erscheinen -----------------
   Wann immer eine .msg-reaction frisch ins DOM kommt, ein kurzer
   Scale-Bounce. Greift sowohl beim eigenen Toggle als auch beim
   Sync von remote-Reactions. Animationen werden nicht ge-replay-t,
   wenn die Bubble nur gemorpht wird (Klasse bleibt).
   ----------------------------------------------------------- */
@keyframes reaction-pop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.18); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.msg-reaction {
  animation: reaction-pop 280ms cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  transform-origin: center;
}

/* --- Quick-Reaction-Bar: sanftes Settle bei Hover ---------
   Wenn die ⋯-Bar erscheint (Bubble-Hover), kommt sie sanft
   gefaded + kleine Translate-Bewegung „aus der Bubble heraus".
   ----------------------------------------------------------- */
.msg-actions {
  /* base bereits durch andere Regeln gesetzt — hier nur smoothere
     Curve und subtile Translate-Komponente. */
  transform: translateY(2px);
}
.msg-actions:has(.msg-menu-btn[aria-expanded="true"]),
.msg:hover .msg-actions,
.msg-actions:focus-within {
  transform: translateY(0);
}

/* --- Toast: leichter Overshoot beim Erscheinen -------------
   Aktuelle toast-in-Animation kriegt eine weichere Curve mit
   minimalem Settle. Keine neue Animation, nur Curve-Polish über
   den bestehenden Keyframe-Override. */
.toast {
  animation-timing-function: cubic-bezier(0.32, 1.4, 0.4, 1) !important;
}

/* --- Avatar im Chat-Header: subtle pulse on typing --------
   Wenn der typing-Indicator aktiv ist, bekommt der Header-Avatar
   einen ganz feinen Atem-Effekt. Ohne hektische Veränderung. */
@keyframes header-avatar-breath {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}
.chat-header:has(.chat-header-typing:not([hidden])) .avatar {
  animation: header-avatar-breath 2.4s ease-in-out infinite;
}

/* --- Reduced motion -------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   Kondensator-Feed — kanal-/kartenspezifische Styles.
   Nutzt die bestehenden Design-Tokens; das Chrome (app-shell, sidebar,
   conv-item, ...) kommt unverändert von oben.
   ═══════════════════════════════════════════════════════════════════════ */

/* Sidebar: Kanal-Punkt statt Avatar, gelesene Kanäle gedämpft. */
.channel-item { gap: 0.7rem; }
.channel-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  flex-shrink: 0;
}
.channel-item.is-read .conv-name { color: var(--fg-secondary); font-weight: 500; }

/* Kanal-Pane */
.feed-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.feed-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 1.1rem;
  min-height: var(--header-h);
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.feed-header .back-btn { display: none; }
.feed-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  flex: 1;
}
.feed-title h1 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.feed-category { font-size: 0.8rem; flex-shrink: 0; }
.feed-actions { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

.feed-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: clip;
  padding: 1.1rem;
}
.feed-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 820px;
  margin: 0 auto;
}
.feed-empty { padding: 2rem 1rem; text-align: center; }

/* Karte = eine bot_notices-Zeile */
.feed-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 0.95rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--t-fast) var(--ease-out),
              background var(--t-fast) var(--ease-out);
}
.feed-card.is-unread {
  border-left: 3px solid var(--accent);
  padding-left: calc(1.1rem - 2px);
}
.feed-card .unread-dot { display: none; }
.feed-card.is-unread .unread-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.embed { position: relative; }
.embed + .embed { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid var(--border-hairline); }
.embed-author { font-size: 0.82rem; color: var(--fg-secondary); margin-bottom: 0.2rem; }
.embed-author a { color: inherit; }
.embed-title {
  font-size: 1rem;
  font-weight: 640;
  line-height: 1.35;
  margin: 0 0 0.35rem;
}
.embed-title a { color: var(--fg-primary); text-decoration: none; }
.embed-title a:hover { color: var(--accent); text-decoration: underline; }
.embed-desc {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--fg-primary);
  overflow-wrap: anywhere;
}
.embed-desc a { color: var(--accent); }
.embed-desc a:hover { color: var(--accent-hover); }
.embed-fields {
  margin: 0.6rem 0 0;
  display: grid;
  grid-template-columns: minmax(6rem, auto) 1fr;
  gap: 0.2rem 0.9rem;
  font-size: 0.88rem;
}
.embed-fields dt { color: var(--fg-secondary); font-weight: 600; }
.embed-fields dd { margin: 0; overflow-wrap: anywhere; }
.embed-footer { font-size: 0.78rem; margin-top: 0.55rem; }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.7rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border-hairline);
}
.feed-ts { font-family: var(--font-mono); font-size: 0.74rem; color: var(--fg-tertiary); }

.feed-more { display: flex; justify-content: center; padding: 1rem; }
.feed-more-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: var(--radius-pill);
  animation: feed-spin 0.7s linear infinite;
}
@keyframes feed-spin { to { transform: rotate(360deg); } }

/* Mobile: Master-Detail wie beim Messenger, aber an .feed-header gekoppelt. */
@media (max-width: 820px) {
  .app-shell:has(.feed-header) .sidebar { display: none; }
  .app-shell:has(.feed-header) .chat-pane { display: flex; }
  .feed-header .back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    color: var(--fg-secondary);
    text-decoration: none;
    flex-shrink: 0;
  }
  .feed-header .back-btn:hover { color: var(--fg-primary); background: var(--bg-hover); }
  .feed-scroll { padding: 0.85rem; }
}
