/* =============================================================
   deenja — Chat, Anmeldung, Vorschau
   Farben/Abstaende/Bausteine kommen aus theme.css.
   ============================================================= */

/* Feste Hoehe + display:flex ist Absicht: der Anmeldebildschirm ist ein
   Flex-Kind mit min-height:100dvh und overflow-y:auto. Nur so schrumpft er auf
   Schirmhoehe und rollt INNEN -- als Block-Element waere er einfach hoeher als
   der Body geworden und der untere Teil unerreichbar. */
body {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* =============================================================
   1. Anmelden & Registrieren
   ============================================================= */

/* Der Verlauf im Hintergrund ist zweifarbig und sitzt fest —
   er soll die Karte anheben, nicht mitscrollen. */
.auth-screen {
  position: relative;
  display: flex;
  align-items: center;
  align-items: safe center;   /* sonst waechst ein zu hoher Kasten oben aus
                                 dem Scrollbereich und ist nicht erreichbar */
  justify-content: center;
  flex-wrap: wrap;
  align-content: safe center;
  gap: var(--sp-7);
  min-height: 100dvh;
  padding: var(--sp-6) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom));
  overflow-y: auto;
  isolation: isolate;
}
.auth-screen::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(58rem 34rem at 18% -10%, var(--accent-soft), transparent 62%),
    radial-gradient(46rem 30rem at 92% 8%, rgba(124, 92, 255, 0.10), transparent 60%),
    radial-gradient(40rem 40rem at 50% 118%, var(--accent-soft), transparent 62%);
  pointer-events: none;
}

@media (min-width: 64rem) {
  .auth-screen { flex-wrap: nowrap; gap: 4rem; align-items: center; }
  .auth-screen .login-box { flex: 0 0 27rem; }
  .auth-screen .demo      { flex: 0 1 26rem; }
}

.login-box {
  position: relative;
  width: 100%;
  max-width: 27rem;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: clamp(1.5rem, 1rem + 2vw, 2.25rem);
  box-shadow: var(--shadow-3);
}
/* Haarfeiner heller Saum an der Oberkante — laesst die Karte auf
   dem dunklen Grund plastisch wirken statt aufgeklebt. */
.login-box::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(180deg, var(--hairline), transparent 45%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}

/* ---- Markenkopf ---- */
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
}
.brand-mark {
  width: 3.5rem; height: 3.5rem;
  filter: drop-shadow(0 6px 16px rgba(79, 142, 247, 0.35));
}
.brand h1 {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(100deg, var(--text) 20%, var(--accent-text));
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}
.brand .subtitle {
  color: var(--muted);
  font-size: var(--fs-sm);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
}
.brand .tagline {
  color: var(--text-2);
  font-size: var(--fs-base);
  max-width: 22rem;
  text-wrap: balance;
}

/* ---- Formularteile ---- */
.form-row { display: flex; flex-direction: column; gap: 0.35rem; }
.form-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.form-label .hint { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.85; }

.login-box .btn-primary { width: 100%; min-height: 3rem; font-size: var(--fs-md); }

/* Trenner mit Beschriftung zwischen Anmeldung und Registrierung */
.divider {
  display: flex; align-items: center; gap: var(--sp-3);
  color: var(--muted); font-size: var(--fs-xs);
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.auth-switch {
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.link-btn {
  background: none; border: none; padding: 0;
  margin-left: 0.35rem;
  font: inherit; font-weight: 600;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
@media (hover: hover) { .link-btn:hover { color: var(--accent-hover); } }

/* Meldungen im Kasten statt als fluechtiger Toast: wer sich
   vertippt hat, soll den Grund noch lesen koennen. */
.auth-error {
  display: flex; gap: var(--sp-2);
  padding: 0.6rem 0.75rem;
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
/* "Konto angelegt, wartet auf Freigabe" ist eine Erfolgsmeldung —
   sie lief frueher durch die rote Optik und sah aus wie ein Fehler. */
.auth-error.auth-pending {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.field-hint {
  font-size: var(--fs-xs);
  line-height: 1.45;
  color: var(--muted);
  white-space: pre-line;   /* der Hinweis steht dreisprachig auf drei Zeilen */
}

/* ---- Sprachwahl ----
   Umbrechen ist Pflicht, nicht Kosmetik: die Sprachliste kommt aus
   der Konfiguration und kann zwoelf Eintraege haben. In einer
   starren Reihe schoben sich die Knoepfe auf dem Handy aus dem Bild. */
.lang-buttons { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.lang-btn {
  flex: 1 1 7.5rem;
  min-width: 0;
  min-height: 2.75rem;
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
  text-align: left;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--dur-1), background var(--dur-1),
              box-shadow var(--dur-1), transform var(--dur-1);
}
.lang-btn .flag { width: 1.4rem; height: 0.94rem; }
.lang-btn-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Der Haken sitzt immer da, nur unsichtbar — sonst springt die
   Beschriftung beim Auswaehlen um seine Breite zur Seite. */
.lang-btn-check {
  margin-left: auto;
  width: 1.05rem; height: 1.05rem;
  border-radius: var(--r-full);
  border: 1px solid var(--border-strong);
  display: grid; place-items: center;
  font-size: 0.6rem; line-height: 1;
  color: transparent;
  transition: background var(--dur-1), border-color var(--dur-1), color var(--dur-1);
}
@media (hover: hover) {
  .lang-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
}
.lang-btn:active { transform: scale(0.98); }
.lang-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent-line) inset;
}
.lang-btn.active .lang-btn-check {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}

@media (max-width: 26rem) {
  .lang-btn { flex-basis: 100%; }
}

/* =============================================================
   2. Vorschau neben der Anmeldung
   Benutzt dieselben Klassen wie echte Nachrichten, damit sie
   zeigt, wie der Chat wirklich aussieht. Texte sind fest
   verdrahtet — hier wird nichts uebersetzt, keine API angefasst.
   ============================================================= */
.demo {
  width: 100%;
  max-width: 27rem;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.demo-head h2 {
  font-size: var(--fs-md);
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-2);
  text-wrap: balance;
}

.demo-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
/* Angedeutete Fensterleiste — macht aus dem Kasten ein Geraet,
   ohne dass ein Bild geladen werden muesste. */
.demo-bar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-size: var(--fs-2xs);
  color: var(--muted);
}
.demo-dots { display: flex; gap: 4px; }
.demo-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }

.demo-msgs {
  padding: var(--sp-4);
  /* feste Hoehe, von unten gefuellt wie ein echter Chat — so
     springt beim Aufklappen der Uebersetzung nichts */
  height: clamp(17rem, 44dvh, 21rem);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--sp-3);
  overflow: hidden;
  transition: opacity var(--dur-3) ease;
}
.demo-msgs.resetting { opacity: 0; }

.demo-msgs .msg { max-width: 100%; }
.demo-msgs .msg-bubble { padding: 0.5rem 0.7rem; }
.demo-msgs .msg-translation { font-size: var(--fs-sm); }
.demo-msgs .msg-time { display: none; }

.demo-msg {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-3) var(--ease), transform var(--dur-3) var(--ease);
}
/* .msg bringt eine eigene Einblend-Animation mit; eine laufende
   Animation schlaegt in der Kaskade jede normale Regel. */
.demo-msgs .demo-msg { animation: none; }
.demo-msg.in { opacity: 1; transform: none; }

/* Die uebersetzte Zeile klappt nach dem Original auf — das ist
   der Moment, um den es in der App geht. */
.demo-msgs .msg-translation.demo-trans {
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  padding-top: 0;
  border-top-color: transparent;
  overflow: hidden;
  transition: opacity var(--dur-3) ease, max-height var(--dur-3) ease,
              padding-top var(--dur-3) ease, margin-top var(--dur-3) ease;
}
.demo-msgs .msg-translation.demo-trans.on {
  opacity: 1;
  max-height: 6rem;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top-color: var(--hairline);
}

.demo-typing {
  display: none;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  margin-left: 2.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--other-bg);
  border: 1px solid var(--other-border);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) var(--r-xs);
}
.demo-typing.on { display: flex; }
.demo-typing.right {
  align-self: flex-end;
  margin-left: 0; margin-right: 0;
  background: var(--surface-2);
  border-radius: var(--r-lg) var(--r-lg) var(--r-xs) var(--r-lg);
}
.demo-typing span, .typing-bubble span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot-bounce 1.1s infinite;
}
.demo-typing span:nth-child(2), .typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.demo-typing span:nth-child(3), .typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.45; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* Drei Punkte, die Vertrauen schaffen sollen, ohne zu ueberreden */
.demo-points {
  display: flex; flex-direction: column; gap: 0.45rem;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.demo-points li { display: flex; align-items: flex-start; gap: var(--sp-2); list-style: none; }
.demo-points b { color: var(--text-2); font-weight: 600; }
.demo-points .dot {
  margin-top: 0.45em;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}

@media (prefers-reduced-motion: reduce) {
  .demo-msg { opacity: 1; transform: none; }
  .demo-msgs .msg-translation.demo-trans {
    opacity: 1; max-height: none; margin-top: 0.4rem; padding-top: 0.4rem;
    border-top-color: var(--hairline);
  }
  .demo-typing.on { display: none; }
}

/* =============================================================
   3. Chat — Geruest, Kopfzeile, Seitenleiste
   ============================================================= */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---- Kopfzeile ---- */
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0.55rem var(--sp-4);
  padding-top: calc(0.55rem + env(safe-area-inset-top));
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 82%, transparent);  /* Rueckfall darueber */
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}
/* Glas nur, wo es der Browser wirklich kann — sonst bliebe eine
   halbdurchsichtige Flaeche ohne Unschaerfe stehen. */
@supports (backdrop-filter: blur(12px)) {
  .chat-header { backdrop-filter: blur(14px) saturate(140%); }
}

.icon-btn {
  display: inline-grid; place-items: center;
  width: 2.4rem; height: 2.4rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1);
}
.icon-btn svg { width: 1.15rem; height: 1.15rem; }
@media (hover: hover) {
  .icon-btn:hover { background: var(--hover-wash); color: var(--text); border-color: var(--border); }
}
.icon-btn:active { background: var(--surface-3); }

.room-title { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; flex: 1; }
.room-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
#room-label {
  font-weight: 650;
  font-size: var(--fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-kind { color: var(--muted); font-weight: 500; }
.room-sub {
  font-size: var(--fs-2xs);
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.header-right { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }

.lang-toggles {
  display: flex; align-items: center; gap: 0.25rem;
  padding: 0.2rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  min-width: 0;
}
.lang-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.25rem; min-height: 1.9rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: transparent;
  cursor: pointer;
  opacity: 0.55;
  filter: grayscale(0.7);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity var(--dur-1), filter var(--dur-1), background var(--dur-1), box-shadow var(--dur-1);
}
.lang-toggle .flag { width: 1.3rem; height: 0.87rem; }
@media (hover: hover) {
  .lang-toggle:hover { opacity: 0.85; filter: grayscale(0.25); }
}
.lang-toggle.active {
  opacity: 1;
  filter: none;
  background: var(--surface);
  box-shadow: var(--shadow-1), 0 0 0 1px var(--accent-line);
}

.pill {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: var(--fs-2xs);
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 0.15rem 0.55rem;
  white-space: nowrap;
}

/* ---- Verbindungsstreifen ----
   Ohne ihn sieht eine tote Leitung aus wie ein stiller Chat. */
.net-banner {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 0.35rem var(--sp-4);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--warn);
  flex-shrink: 0;
}
.net-banner .spinner {
  width: 0.8rem; height: 0.8rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Seitenleiste ---- */
.chat-layout { display: flex; flex: 1; min-height: 0; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
}

.sidebar-scroll { flex: 1; overflow-y: auto; padding: var(--sp-2) 0; min-height: 0; }

.sidebar-section { padding: var(--sp-2) 0; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); margin-top: var(--sp-1); }

.sidebar-label {
  font-size: var(--fs-2xs);
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 var(--sp-3) 0.4rem;
}

.sidebar-search { padding: 0 var(--sp-3) var(--sp-2); }
.field-sm { padding: 0.4rem 0.65rem; font-size: var(--fs-sm); border-radius: var(--r-xs); }

.room-btn, .dm-btn {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: calc(100% - var(--sp-3));
  margin: 1px var(--sp-2);
  padding: 0.4rem 0.5rem;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-2);
  cursor: pointer;
  font-size: var(--fs-base);
  text-align: left;
  transition: background var(--dur-1), color var(--dur-1);
  position: relative;
  touch-action: manipulation;
}
.room-btn .room-name, .dm-btn .dm-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1;
}
@media (hover: hover) {
  .room-btn:hover, .dm-btn:hover { background: var(--hover-wash); color: var(--text); }
}
.room-btn.active, .dm-btn.active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--accent-line) inset;
}
.dm-btn.unread { color: var(--text); font-weight: 600; }
/* Ungelesenes bekommt einen Punkt statt nur Fettschrift — Gewicht
   allein ist bei kurzen Namen kaum zu erkennen. */
.dm-btn.unread::after {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.room-icon {
  display: grid; place-items: center;
  width: 1.9rem; height: 1.9rem;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--muted);
  font-size: var(--fs-md);
  font-weight: 700;
  flex-shrink: 0;
}
.room-btn.active .room-icon { background: var(--accent); color: var(--accent-ink); }

.presence {
  position: relative;
  flex-shrink: 0;
}
.presence::after {
  content: '';
  position: absolute;
  right: -1px; bottom: -1px;
  width: 0.62rem; height: 0.62rem;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 2px var(--surface);
  transition: background var(--dur-2);
}
.presence.is-online::after { background: var(--success); }

.sidebar-empty {
  font-size: var(--fs-sm);
  color: var(--muted);
  padding: 0.4rem var(--sp-3);
}

/* margin-top:auto haelt den Fuss unten, auch wenn nur zwei Leute
   online sind — sonst muesste man zum Abmelden erst durch alle
   Kontakte scrollen. */
.sidebar-footer {
  margin-top: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.sidebar-me {
  display: flex; align-items: center; gap: var(--sp-2);
  min-width: 0; flex: 1;
}
.sidebar-me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.sidebar-me-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-me-sub { font-size: var(--fs-2xs); color: var(--muted); }
.logout-btn { width: 2.4rem; height: 2.4rem; }
@media (hover: hover) {
  .logout-btn:hover { color: var(--danger); background: var(--danger-soft); border-color: var(--danger); }
}

/* Avatare: Farbe kommt aus dem Namen (12 feste Klassen statt
   berechneter style-Attribute — so bleibt die CSP ohne
   'unsafe-inline' fuer Styles). */
.avatar {
  display: grid; place-items: center;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  flex-shrink: 0;
  user-select: none;
  overflow: hidden;
}
.avatar-sm { width: 1.75rem; height: 1.75rem; font-size: var(--fs-xs); }
.avatar-lg { width: 2.5rem; height: 2.5rem; font-size: var(--fs-md); }
.av-0  { background: linear-gradient(145deg, #6ea8fe, #3b6fd4); }
.av-1  { background: linear-gradient(145deg, #f97583, #d6336c); }
.av-2  { background: linear-gradient(145deg, #4dd4ac, #17916f); }
.av-3  { background: linear-gradient(145deg, #f0a44a, #d1741a); }
.av-4  { background: linear-gradient(145deg, #a78bfa, #6d4bd6); }
.av-5  { background: linear-gradient(145deg, #4cc9e8, #1a8fb0); }
.av-6  { background: linear-gradient(145deg, #f4739e, #c02b6b); }
.av-7  { background: linear-gradient(145deg, #86c94a, #4f9421); }
.av-8  { background: linear-gradient(145deg, #ffb45c, #e07f1f); }
.av-9  { background: linear-gradient(145deg, #7f9cf5, #4658c9); }
.av-10 { background: linear-gradient(145deg, #f28b82, #c5372c); }
.av-11 { background: linear-gradient(145deg, #55c2a2, #2b8f74); }

/* =============================================================
   4. Nachrichten
   ============================================================= */
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  position: relative;
  background:
    radial-gradient(42rem 26rem at 82% -6%, var(--accent-soft), transparent 60%),
    var(--bg);
}

#messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

/* Der Strang bleibt lesbar breit und mittig — auf einem breiten
   Schirm reissen sonst Absender links und Text rechts auseinander. */
.msg, .day-sep, .msg-empty {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.msg {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
  margin-top: 2px;
  animation: msg-in var(--dur-3) var(--ease);
}
/* Erste Nachricht einer Folge bekommt Luft nach oben, die
   Folgenachrichten ruecken zusammen — so entstehen Bloecke pro
   Person statt einer gleichfoermigen Kette. */
.msg.is-start { margin-top: var(--sp-4); }
.msg.own { flex-direction: row-reverse; }

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

.msg-avatar { align-self: flex-end; }
.msg:not(.is-end) .msg-avatar { visibility: hidden; }   /* Platz bleibt stehen */
.msg.own .msg-avatar { display: none; }

.msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(38rem, 78%);
}
.msg.own .msg-body { align-items: flex-end; }

/* Name und Sprachmarke stehen nur ueber der ersten Blase einer Folge */
.msg:not(.is-start) .msg-header { display: none; }

.msg-header {
  display: flex; align-items: baseline; gap: var(--sp-2);
  margin: 0 0.35rem 0.2rem;
  font-size: var(--fs-xs);
  min-width: 0;
}
.msg-username {
  font-weight: 650;
  color: var(--accent-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-lang-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: var(--muted);
  font-size: var(--fs-2xs);
  letter-spacing: 0.04em;
}
.msg-lang-badge .flag { width: 1.05rem; height: 0.7rem; }

.msg-bubble {
  position: relative;
  padding: 0.6rem 0.85rem;
  border: 1px solid;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  min-width: 0;
}
.msg.other .msg-bubble {
  background: var(--other-bg);
  border-color: var(--other-border);
  --fg: var(--text);
  --fg-2: var(--text-2);
  --rule: var(--hairline);
}
.msg.own .msg-bubble {
  background: var(--own-bg);
  border-color: var(--own-border);
  color: var(--own-text);
  --fg: var(--own-text);
  --fg-2: rgba(255, 255, 255, 0.80);
  --rule: rgba(255, 255, 255, 0.18);
}
/* Die letzte Blase einer Folge bekommt die eingezogene Ecke —
   sie zeigt zur sprechenden Person. */
.msg.other.is-end .msg-bubble { border-bottom-left-radius: var(--r-xs); }
.msg.own.is-end  .msg-bubble { border-bottom-right-radius: var(--r-xs); }

.msg-translations { display: flex; flex-direction: column; }
.msg-translation {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  overflow-wrap: anywhere;
}
.msg-translation + .msg-translation {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--rule);
}
.msg-translation-flag { flex-shrink: 0; line-height: 1; }
.msg-translation-flag .flag { width: 1.1rem; height: 0.74rem; }
/* Original in voller Staerke, Uebersetzung eine Spur zurueck —
   der Unterschied muss sofort lesbar sein, ohne zu trennen. */
.msg-translation.is-source .msg-translation-text { color: var(--fg); }
.msg-translation:not(.is-source) .msg-translation-text {
  color: var(--fg-2);
  font-size: var(--fs-sm);
}

.msg-foot {
  display: flex; align-items: center; gap: var(--sp-2);
  margin: 0.2rem 0.35rem 0;
  font-size: var(--fs-2xs);
  color: var(--muted);
}
.msg.own .msg-foot { flex-direction: row-reverse; }
.msg-cache { color: var(--success); }

/* Zeitstempel nur an der letzten Nachricht einer Folge —
   an jeder einzelnen wird die Spalte zum Flimmern. */
.msg:not(.is-end) .msg-foot { display: none; }

/* ---- Tagestrenner ---- */
.day-sep {
  display: flex; align-items: center; gap: var(--sp-3);
  margin: var(--sp-5) auto var(--sp-2);
  color: var(--muted);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.day-sep::before, .day-sep::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ---- Leerer Raum ---- */
.msg-empty {
  margin-block: auto;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  text-align: center;
  color: var(--muted);
  padding: var(--sp-6) var(--sp-4);
}
.msg-empty .avatar, .msg-empty .room-icon { width: 3rem; height: 3rem; font-size: var(--fs-lg); }
.msg-empty strong { color: var(--text-2); font-size: var(--fs-md); }
.msg-empty p { font-size: var(--fs-sm); max-width: 24rem; text-wrap: balance; }

/* ---- Reaktionen ----
   Leere Knoepfe sind nur da, wo man sie gerade braucht: sonst
   haengen unter jeder Nachricht drei graue Kreise.  */
.msg-reactions { display: flex; gap: 4px; margin: 0.3rem 0.35rem 0; flex-wrap: wrap; }
.msg.own .msg-reactions { justify-content: flex-end; }

.react-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px;
  min-height: 1.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  cursor: pointer;
  font-size: var(--fs-sm);
  line-height: 1.4;
  touch-action: manipulation;
  transition: background var(--dur-1), border-color var(--dur-1), transform var(--dur-1);
}
.react-btn span { font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; }
@media (hover: hover) {
  .react-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
}
.react-btn:active { transform: scale(0.94); }
.react-btn.reacted { background: var(--accent-soft); border-color: var(--accent-line); }
.react-btn.reacted span { color: var(--accent-text); }

.react-btn.zero { display: none; }
.react-add { opacity: 0.55; padding: 1px 7px; }
/* Auf dem Handy gibt es kein Hover — dort klappt der Plus-Knopf
   die Auswahl auf. */
.msg.show-reacts .react-btn.zero { display: inline-flex; }
.msg.show-reacts .react-add { opacity: 1; }
@media (hover: hover) {
  /* Mit Zeiger genuegt Hovern; der Plus-Knopf waere doppelt. */
  .react-add { display: none; }
  .msg:hover .react-btn.zero,
  .msg:focus-within .react-btn.zero { display: inline-flex; }
}

/* ---- Tipp-Anzeige ---- */
#typing-indicator {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0 var(--sp-4) var(--sp-2);
  width: 100%; max-width: var(--content-max); margin-inline: auto;
  font-size: var(--fs-sm);
  color: var(--muted);
  flex-shrink: 0;
}
.typing-bubble {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.5rem 0.7rem;
  background: var(--other-bg);
  border: 1px solid var(--other-border);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) var(--r-xs);
}

/* ---- Sprung ans Ende ---- */
.jump-btn {
  position: absolute;
  right: var(--sp-4);
  bottom: 5.5rem;
  z-index: 15;
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-full);
  color: var(--text);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}
.jump-btn.show { opacity: 1; transform: none; pointer-events: auto; }
.jump-btn .count {
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--r-full); padding: 0 0.4rem;
  font-size: var(--fs-2xs); font-weight: 700;
}

/* =============================================================
   5. Eingabezeile
   ============================================================= */
#message-form {
  flex-shrink: 0;
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 0.3rem 0.35rem 0.3rem 0.5rem;
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
}
/* Der Rahmen wandert auf die Huelle, weil das Feld selbst keinen
   mehr hat — sonst saehe man beim Tippen zwei Rahmen. */
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#message-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  padding: 0.55rem 0.25rem;
  font-size: var(--fs-md);
  color: var(--text);
}
#message-input::placeholder { color: var(--muted); }

/* Schreibsprache: war eine reine Anzeige, ist jetzt der Schalter.
   Wer mitten im Gespraech die Sprache wechselt, musste sich vorher
   ab- und wieder anmelden. */
.lang-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  background: var(--surface-2);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: background var(--dur-1), border-color var(--dur-1);
}
.lang-chip .flag { width: 1.35rem; height: 0.9rem; }
.lang-chip svg { width: 0.7rem; height: 0.7rem; color: var(--muted); }
@media (hover: hover) {
  .lang-chip:hover { background: var(--surface-3); border-color: var(--border); }
}
.lang-chip[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent-line); }

.lang-menu {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  z-index: 40;
  min-width: 12rem;
  padding: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.lang-menu-wrap { position: relative; flex-shrink: 0; }
.lang-menu-title {
  font-size: var(--fs-2xs); color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.07em;
  padding: 0.35rem 0.5rem 0.2rem;
}
.lang-menu-item {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0.45rem 0.5rem;
  min-height: 2.4rem;
  border: none; border-radius: var(--r-xs);
  background: none;
  color: var(--text);
  font-size: var(--fs-base);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-1);
}
.lang-menu-item .flag { width: 1.35rem; height: 0.9rem; }
@media (hover: hover) { .lang-menu-item:hover { background: var(--hover-wash); } }
.lang-menu-item[aria-checked="true"] { background: var(--accent-soft); font-weight: 600; }
.lang-menu-item .check { margin-left: auto; color: var(--accent-text); opacity: 0; }
.lang-menu-item[aria-checked="true"] .check { opacity: 1; }

.send-btn {
  display: grid; place-items: center;
  width: 2.6rem; height: 2.6rem;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  touch-action: manipulation;
  transition: background var(--dur-1), transform var(--dur-1), opacity var(--dur-1);
}
.send-btn svg { width: 1.1rem; height: 1.1rem; }
@media (hover: hover) { .send-btn:hover { background: var(--accent-hover); } }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* =============================================================
   6. Toast
   ============================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(6rem + env(safe-area-inset-bottom));
  z-index: 999;
  transform: translateX(-50%) translateY(1rem);
  max-width: min(90vw, 30rem);
  padding: 0.65rem 1rem;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  text-align: center;
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease);
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--surface); border: 1px solid var(--danger); color: var(--danger); }
.toast-warn  { background: var(--surface); border: 1px solid var(--warn);   color: var(--warn); }
.toast-info  { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); }

/* =============================================================
   7. Handy
   ============================================================= */
.sidebar-scrim {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--scrim);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-2) var(--ease);
}

@media (max-width: 46rem) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    width: min(20rem, 86vw);
    transform: translateX(-100%);
    transition: transform var(--dur-2) var(--ease);
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
  }
  #sidebar.open { transform: none; box-shadow: var(--shadow-3); }
  body.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }

  .msg-body { max-width: 86%; }
  #messages { padding-inline: var(--sp-3); }
  #message-form { padding-inline: var(--sp-3); }

  /* Zwoelf Sprachen passen neben dem Raumnamen nicht in eine
     Handy-Kopfzeile. Sie bekommen eine eigene Zeile und werden
     dort gewischt — das haelt die Kopfzeile flach und trotzdem
     jede Sprache erreichbar. */
  .chat-header { flex-wrap: wrap; row-gap: var(--sp-2); padding-inline: var(--sp-3); }
  .room-title { flex: 1 1 auto; }
  .header-right { width: 100%; order: 3; }
  .lang-toggles {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
  }
  .lang-toggles::-webkit-scrollbar { display: none; }
  .lang-toggle { flex: 0 0 auto; }
  .jump-btn { bottom: 5rem; }
}

/* Sehr schmal: die Kopfzeile darf keine Zeile mehr verlieren */
@media (max-width: 24rem) {
  .room-sub { display: none; }
}

/* Grosse Schirme: die Leiste darf etwas mehr Platz haben */
@media (min-width: 100rem) {
  :root { --sidebar-w: 300px; }
}

/* =============================================================
   8. Ersteinrichtung (/setup)
   Liegt hier statt in einem <style>-Block der Seite — sonst
   braeuchte die CSP 'unsafe-inline' fuer style-src.
   ============================================================= */
.setup-status { font-size: var(--fs-sm); min-height: 1.4em; }
.setup-status.ok    { color: var(--success); }
.setup-status.error { color: var(--danger); }
.setup-status.info  { color: var(--muted); }

.setup-note {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  padding: 0.6rem 0.75rem;
  border-radius: var(--r-sm);
  background: var(--success-soft);
  border: 1px solid var(--success);
  color: var(--success);
  font-size: var(--fs-sm);
}
.setup-link {
  display: block; text-align: center;
  color: var(--accent-text); font-size: var(--fs-sm);
  text-decoration: none; padding: var(--sp-2);
}
.setup-link:hover { text-decoration: underline; }
.reconfigure-toggle {
  font-size: var(--fs-sm); color: var(--accent-text);
  cursor: pointer; text-align: center; background: none; border: none; width: 100%;
}
.reconfigure-toggle:hover { text-decoration: underline; }
.setup-inline-link { color: var(--accent-text); }
code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 0.05em 0.35em;
}

/* =============================================================
   9. Umschalter hell/dunkel
   Welches Symbol zu sehen ist, entscheidet CSS — nicht JS. Sonst
   zeigte der Knopf bis zum ersten Skriptlauf das falsche Zeichen.
   ============================================================= */
.theme-toggle .i-moon { display: none; }
.theme-toggle .i-sun  { display: block; }

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .theme-toggle .i-sun  { display: none; }
  :root:not([data-theme="dark"]) .theme-toggle .i-moon { display: block; }
}
:root[data-theme="light"] .theme-toggle .i-sun  { display: none; }
:root[data-theme="light"] .theme-toggle .i-moon { display: block; }
:root[data-theme="dark"]  .theme-toggle .i-sun  { display: block; }
:root[data-theme="dark"]  .theme-toggle .i-moon { display: none; }

/* Das Setup-Formular ist eine Spalte wie der Anmeldekasten */
#setup-form { display: flex; flex-direction: column; gap: var(--sp-4); }
