/* Daria-Web Stylesheet
 *
 * Designprinzipien:
 *   - Telegram-nahes UI: weiche Kanten, Akzentblau, klare Trennkanten,
 *     Chat-Bubbles links/rechts, sanfte Schatten.
 *   - Vollständig responsive: Mobile-First, ab 720 px Desktop-Layout.
 *   - Dark Mode automatisch via @media (prefers-color-scheme: dark) +
 *     manueller Toggle, der die Wahl in localStorage persistiert.
 *   - CSS-Variablen für Themes: einmal definiert, überall referenziert.
 *   - Kein externes Font-CDN — Systemfonts halten den Footprint klein und
 *     ersparen einen connect-src für CSP.
 */

/* ---------- Reset & Tokens ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Hellmodus-Defaults (Telegram-Light-Palette) */
:root {
  --bg: #ffffff;
  --bg-alt: #f4f5f7;
  --bg-card: #ffffff;
  --bg-elev: #ffffff;
  --text: #0f1419;
  --text-dim: #707579;
  --border: #e7e9eb;
  --accent: #2aabee;          /* Telegram-Blau */
  --accent-strong: #168acd;
  --accent-soft: #e3f2fd;
  --bubble-out: #effdde;      /* Telegram-Bubble grün (Outgoing) */
  --bubble-in: #ffffff;
  --bubble-in-border: #e7e9eb;
  --danger: #e53935;
  --ok: #1aab36;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-elev: 0 4px 16px rgba(16, 24, 40, .12);
  --radius: 12px;
  --radius-sm: 8px;
}

/* Dark-Mode-Tokens — automatisch via OS, oder explizit per [data-theme="dark"] */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17212b;
    --bg-alt: #0e1621;
    --bg-card: #232e3c;
    --bg-elev: #2b5278;
    --text: #f5f5f5;
    --text-dim: #8e99a4;
    --border: #2c3a48;
    --accent: #5288c1;
    --accent-strong: #6ab2f2;
    --accent-soft: #2b5278;
    --bubble-out: #2b5278;
    --bubble-in: #182533;
    --bubble-in-border: #232e3c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-elev: 0 4px 16px rgba(0, 0, 0, .4);
  }
}
:root[data-theme="dark"] {
  --bg: #17212b;
  --bg-alt: #0e1621;
  --bg-card: #232e3c;
  --bg-elev: #2b5278;
  --text: #f5f5f5;
  --text-dim: #8e99a4;
  --border: #2c3a48;
  --accent: #5288c1;
  --accent-strong: #6ab2f2;
  --accent-soft: #2b5278;
  --bubble-out: #2b5278;
  --bubble-in: #182533;
  --bubble-in-border: #232e3c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-elev: 0 4px 16px rgba(0, 0, 0, .4);
}

/* ---------- Login-Seite ---------- */
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 10%, var(--accent-soft) 0%, transparent 40%),
    radial-gradient(circle at 80% 90%, var(--accent-soft) 0%, transparent 35%),
    var(--bg-alt);
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-elev);
  padding: 28px 24px 20px;
  border: 1px solid var(--border);
}
.brand { text-align: center; margin-bottom: 20px; }
.brand-logo {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 700; font-size: 26px;
  display: grid; place-items: center;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-elev);
}
.brand-logo.small { width: 32px; height: 32px; font-size: 16px; margin: 0; box-shadow: none; }
/* Avatar im Header — wenn ein User-Profilbild vorhanden ist, ersetzt es das
   Default-D-Logo. img + Initiale-Fallback teilen sich denselben Slot. */
.brand-logo.avatar {
  background: var(--bg-alt);
  overflow: hidden;
  padding: 0;
}
.brand-logo.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
/* Header-Avatar als Button: klickbar (öffnet Konto), zeigt beim Hover
   ein User-Icon-Overlay an. Cursor + relativer Container für das Overlay,
   sonst Default-Button-Reset (keine Border, kein Padding, transparent). */
.brand-logo-btn {
  position: relative;
  border: 0; padding: 0; cursor: pointer;
  transition: filter .15s, transform .1s;
}
.brand-logo-btn:hover { filter: brightness(1.05); }
.brand-logo-btn:active { transform: scale(0.96); }
.brand-logo-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand-logo-fallback {
  display: grid; place-items: center;
  width: 100%; height: 100%; color: #fff;
  font-weight: 700; font-size: inherit;
}
.brand-logo-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.45); color: #fff;
  border-radius: 50%;
  opacity: 0; transition: opacity .15s;
  pointer-events: none;
}
.brand-logo-btn:hover .brand-logo-overlay,
.brand-logo-btn:focus-visible .brand-logo-overlay { opacity: 1; }
/* Claude-Verbindung Status-Block im Konto-Tab. */
.claude-auth-status { margin-bottom: 12px; }
.claude-auth-status p { margin: 4px 0; }

/* Admin-Bell im Header: relative Position für die Badge oben rechts. */
.icon-btn-bell { position: relative; }
.bell-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--err, #e74c3c);
  color: white;
  font-size: 10px; line-height: 16px;
  text-align: center; font-weight: 600;
  pointer-events: none;
}

/* Admin-Tab: Header-Row mit "Clear"-Button rechts neben H2. */
.admin-header-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.admin-header-row h2 { margin: 0; }

/* Admin-Messages-Liste: chat-artig, neueste zuerst, severity-Farben links. */
.admin-messages-list { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto; }
.admin-msg {
  border-left: 3px solid var(--border);
  padding: 6px 10px;
  background: var(--bg-alt, rgba(255,255,255,0.02));
  border-radius: 4px;
}
.admin-msg-info    { border-left-color: var(--ok, #2ecc71); }
.admin-msg-warning { border-left-color: #f39c12; }
.admin-msg-error   { border-left-color: var(--err, #e74c3c); }
.admin-msg-text { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-word; }
.admin-msg-meta { font-size: 11px; margin-top: 2px; }

/* Konto-Tab: Profilbild-Vorschau */
.account-row {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
}
.avatar-preview {
  width: 96px; height: 96px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.avatar-preview img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-placeholder {
  width: 100%; height: 100%;
  display: grid; place-items: center;
  font-size: 36px; font-weight: 700;
  color: var(--text-dim);
}
/* Klickbares Avatar im Konto-Tab: bei Hover ein Kamera-Icon über das Bild
   blenden. Das Overlay ist standardmäßig unsichtbar und liegt absolut über
   dem <img>; Opacity-Übergang macht den Effekt sanft. */
.avatar-editable {
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: var(--bg-alt);
  transition: border-color .15s;
}
.avatar-editable:hover { border-color: var(--accent); }
.avatar-overlay {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  display: grid; place-items: center;
  opacity: 0;
  transition: opacity .15s;
}
.avatar-editable:hover .avatar-overlay,
.avatar-editable:focus-visible .avatar-overlay { opacity: 1; }
/* Inline-Button im Fließtext (z. B. "Benutzer: dennis ✏️") — soll wie ein
   normaler klickbarer Name aussehen, nicht wie ein Button. Bei Hover blendet
   ein Edit-Icon dezent ein. */
.link-btn {
  background: transparent; border: 0; padding: 2px 4px;
  color: inherit; font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 4px;
}
.link-btn:hover { background: var(--bg-alt); color: var(--accent); }
.link-btn svg { opacity: .55; }
.link-btn:hover svg { opacity: 1; }

/* ---------- Modal ---------- */
.modal-root {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: rgba(0, 0, 0, .55);
  padding: 16px;
  animation: modal-fade .15s ease-out;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elev);
  max-width: 440px; width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 22px;
  animation: modal-pop .18s ease-out;
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-card-wide { max-width: 720px; }
.modal-card .hint { margin-bottom: 12px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 14px; align-items: center;
}
/* Top-Action-Bar in Modals (z. B. Archiv-Modal): Titel links, Buttons rechts.
   Bei schmalen Viewports brechen die Action-Buttons unter den Titel um. */
.modal-header-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; flex-wrap: wrap; margin-bottom: 4px;
}
.modal-header-row h3 { margin: 0; }
.modal-header-actions {
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
.modal-header-actions .ghost { margin: 0; padding: 6px 12px; font-size: 13px; line-height: 1.25; }
.modal-actions .primary,
.modal-actions .ghost { margin: 0; padding: 8px 14px; font-size: 14px; line-height: 1.25; }
.modal-card label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--text-dim); }
.modal-card input[type="text"],
.modal-card input[type="password"] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font-size: 14px;
  outline: none; box-sizing: border-box;
}
.modal-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Sessions-Tab ---------- */
.sessions-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.inline-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.sessions-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.session-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}
.session-meta { font-size: 12px; color: var(--text-dim); }
.session-meta strong { color: var(--text); }
.session-id {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--text-dim);
  word-break: break-all;
}
.session-badges { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 10px;
  text-transform: uppercase; letter-spacing: .3px;
}
.badge.web      { background: rgba(22, 138, 205, .14); color: var(--accent); }
.badge.bridge   { background: rgba(229, 154, 57, .14); color: #c47a1d; }
.badge.cli      { background: rgba(120, 120, 120, .14); color: var(--text-dim); }
.badge.archived { background: rgba(229, 57, 53, .12); color: var(--danger); }
.badge.active   { background: rgba(31, 111, 58, .18); color: #1f6f3a; }
/* Geräte-Chip in der Sessions-Liste — "📱 Web (Mac)", "iOS", "macOS".
   Bewusst dezent (geringere Sättigung als web/bridge/cli), damit drei
   gleichzeitig verbundene Geräte die Liste nicht visuell dominieren. */
.badge.device   { background: rgba(120, 80, 200, .12); color: #6a4ec4; text-transform: none; letter-spacing: 0; }
.session-devices { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-left: 4px; }
.session-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Info-Bubble fuer "Daria wird gerade neu gestartet". Bewusst gelb/amber
   statt rot — der User soll wissen, dass es kein Fehler ist, sondern ein
   erwarteter Zustand (Container-Restart). Hintergrund-Tint passt zum
   bridge/orange-Badge, sodass das Pattern wiedererkennbar bleibt. */
.bubble.info-restart {
  background: rgba(229, 154, 57, 0.16) !important;
  border-color: rgba(229, 154, 57, 0.40) !important;
  /* Mittig + alle 4 Ecken rund + ohne Tail (Schweif).
     Wunsch Dennis 2026-05-18: System-Bubbles ("Daria wurde neu gestartet",
     greeting) sollen sich klar von Dialog-Bubbles unterscheiden — kein
     Sender-Anschluss, sondern wie ein zentrierter Hinweis-Banner. */
  align-self: center !important;
  border-bottom-left-radius: 14px !important;
}
/* Tail (::before) unterdruecken — der `:not(.greeting)`-Selektor matcht
   info-restart sehr wohl, deshalb expliziter Override hier. */
.bubble.in.info-restart::before { content: none !important; }
.session-actions .ghost { padding: 6px 10px; font-size: 12px; }
.brand h1 { font-size: 22px; margin: 0 0 4px; }
.brand-sub { margin: 0; color: var(--text-dim); font-size: 13px; }

.login-form { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.login-form label { font-size: 13px; color: var(--text-dim); margin-top: 8px; }
.login-form input {
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 15px;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.primary {
  margin-top: 14px;
  background: var(--accent); color: #fff; border: 0;
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.primary:hover { background: var(--accent-strong); }
.primary:disabled { opacity: .5; cursor: not-allowed; }

.error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }
.ok { color: var(--ok); font-size: 13px; margin: 6px 0 0; }
/* Prominente Fehler-Box — wird im Username-Modal verwendet, damit eine
   Fehlermeldung garantiert auffällt (die kleine .error-Variante ging
   in vorherigen Iterationen offenbar an Dennis vorbei). */
.err-box {
  color: var(--danger);
  background: rgba(220, 38, 38, .12);
  border: 1px solid rgba(220, 38, 38, .55);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  margin: 10px 0 0;
}
.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 8px; }
/* Inline-Hint unter einem Row-Label (z. B. unter "Endlos-Feed über /new
   hinweg") — kleiner, dezenter und in eigener Zeile, damit der Switch
   rechts ordentlich daneben sitzt. */
small.hint { display: block; font-size: 11px; margin: 2px 0 0; line-height: 1.35; }

.login-footer { display: flex; justify-content: center; margin-top: 16px; }
.lang-toggle {
  background: transparent; border: 0; color: var(--text-dim);
  cursor: pointer; font-size: 13px; padding: 6px 10px; border-radius: var(--radius-sm);
}
.lang-toggle:hover { background: var(--bg-alt); color: var(--text); }

/* ---------- App-Header & Tabs ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-weight: 600; font-size: 16px; }
.header-right { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: transparent; border: 0; color: var(--text);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-alt); }

.tabs {
  display: flex; gap: 4px; justify-content: center;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: 0; color: var(--text-dim);
  font-size: 14px; padding: 8px 14px; border-radius: 999px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--bg-alt); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

/* Mobile: Tabs ALS BAR OBEN, direkt unter Header (TEST 2026-05-17).
   Vorteil gegenüber bottom-bar: Tabs werden NIE von der iOS-Tastatur
   überdeckt — kein Spalt zwischen Eingabefeld und Tastatur möglich. */
@media (max-width: 720px) {
  .app-header { grid-template-columns: auto auto; }
  .tabs {
    position: fixed; top: 60px; left: 0; right: 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    border-top: 0;
    padding: 6px 8px;
    z-index: 20;
    justify-content: space-around;
  }
  /* main braucht padding-top, damit Content nicht unter den fixed-Tabs steckt */
  main { padding-top: 60px; padding-bottom: 0; }
}

/* ---------- Tab-Panels ---------- */
#app-main { max-width: 880px; margin: 0 auto; padding: 16px; }
.tab-panel { display: block; }
.tab-panel[hidden] { display: none; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; gap: 12px; flex-wrap: wrap;
}
.row + .row { border-top: 1px solid var(--border); }

.ghost {
  background: transparent; color: var(--accent); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 14px; transition: background .15s, border-color .15s;
}
.ghost:hover { background: var(--bg-alt); border-color: var(--accent); }
.ghost.danger { color: var(--danger); }
.ghost.danger:hover { border-color: var(--danger); background: rgba(229, 57, 53, .06); }

/* Switch (Toggle) — reine CSS-Implementation, kein JS-Framework nötig */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 24px;
  transition: background .2s;
}
.slider::before {
  content: ''; position: absolute;
  height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }

select, .login-form input, .env-list input {
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 14px; outline: none;
  font-family: inherit;
}
select:focus, .env-list input:focus { border-color: var(--accent); }

/* Env-Editor */
.env-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.env-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 2fr auto;
  gap: 8px; align-items: center;
}
.env-row .env-key {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; color: var(--text-dim);
}
.env-row input { width: 100%; }
.env-row .env-mask { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.env-actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
/* Im .env-Editor sollen "Neu laden" (.ghost) und "Speichern" (.primary)
   optisch gleich groß sein und exakt auf einer Höhe sitzen. `.primary` hat
   global ein margin-top für Login-Forms — das hier rauswerfen, sonst hängt
   "Speichern" tiefer. Padding/Font-Size matchen wir an die ghost-Variante an,
   damit die Höhe identisch ist; Farbe + Hintergrund (das "Design") bleiben. */
.env-actions .primary,
.env-actions .ghost {
  margin: 0;
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.25;
  height: auto;
}

/* IP-Allowlist (Settings → Sicherheits-Card) */
.ipal-list-label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin: 12px 0 6px;
}
.ipal-list-label code {
  background: var(--bg-elev);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.ipal-list {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ipal-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.ipal-list li code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--text);
  flex: 1;
}
.ipal-list li.ipal-empty {
  color: var(--text-dim);
  font-style: italic;
  justify-content: center;
}
.ipal-tag-you {
  font-size: 11px;
  color: var(--accent);
  background: rgba(0, 132, 255, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ipal-remove {
  font-size: 12px;
  padding: 4px 10px;
}
.ipal-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.ipal-add-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
.ipal-add-row input:focus { border-color: var(--accent); outline: none; }
.ipal-default-note {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 12px;
}
#card-ip-allowlist .env-actions { margin-top: 8px; }
#card-ip-allowlist .env-actions .primary,
#card-ip-allowlist .env-actions .ghost {
  margin: 0; padding: 8px 14px; font-size: 14px; line-height: 1.25; height: auto;
}

/* Status-Grid */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.status-grid > div {
  background: var(--bg-alt); border-radius: var(--radius-sm);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.status-grid span { color: var(--text-dim); font-size: 12px; }
.status-grid strong { font-size: 15px; word-break: break-word; }

.codeblock {
  background: var(--bg-alt); color: var(--text);
  padding: 12px; border-radius: var(--radius-sm);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.45;
  overflow-x: auto; max-height: 320px; overflow-y: auto;
  margin: 0;
}
.codeblock.logs { max-height: 420px; white-space: pre-wrap; word-break: break-word; }

/* QR + Recovery */
.qr-wrap {
  background: #fff; padding: 12px;
  display: inline-block; border-radius: var(--radius-sm);
  margin: 10px 0;
}
.secret-line code { font-family: ui-monospace, monospace; background: var(--bg-alt); padding: 2px 6px; border-radius: 4px; }
.recovery-list {
  list-style: none; padding: 0; margin: 8px 0;
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
.recovery-list li {
  background: var(--bg-alt); padding: 6px 10px; border-radius: 6px; text-align: center;
}

/* ---------- Chat ---------- */
.chat-wrap {
  display: flex; flex-direction: column;
  height: calc(100vh - 140px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  /* Damit der absolut positionierte Datum-Indicator (Telegram-Style)
     relativ zum Chat-Container schwebt, nicht zum Viewport. */
  position: relative;
}

/* Telegram-Style Datums-Indicator: schwebt zentriert am oberen Chat-Rand,
   zeigt für den obersten sichtbaren Bubble „Heute"/„Gestern"/Datum.
   Erscheint kurz beim Scrollen und fadet 1.2s nach Scroll-Ende wieder aus
   — exakt wie in Telegram-Desktop. JS toggelt `data-visible="true"`. */
.date-indicator {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 20;
  white-space: nowrap;
  /* Subtiler Blur dahinter — fühlt sich „schwebend" an wie Telegram-Pill. */
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.date-indicator[data-visible="true"] { opacity: 1; }

/* ===== Usage-Badge oben rechts im Chat =====
   Schwebt absolut in der oberen rechten Ecke der chat-wrap. Zwei kleine
   Donut-Ringe (Kontextfenster, 5-Stunden-Plan-Limit). Hintergrund
   halbtransparent mit Blur, damit es Bubbles dahinter nicht verdeckt. */
.usage-badge {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 5;
  display: inline-flex; gap: 6px; align-items: center;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 18px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  pointer-events: auto;
  user-select: none;
  /* Sanftes Reinrutschen, wenn der Watch-Banner ein-/ausgeblendet wird —
     sonst springen die Donuts hart um ~50px nach unten/oben. */
  transition: top 160ms ease;
}
/* Watch-Mode: der Banner "Du liest die Telegram-Session mit" ist ein
   stehender Block am oberen Rand des Chat-Tabs (kein position:absolute,
   sondern Flow). Die absolut positionierten Donuts liegen ohne weiteres
   Zutun darueber und verdecken den "Zurueck"-Button. Body-Klasse wird
   vom JS gesetzt (setWatchBanner). 56px = Banner-Hoehe (10+10 Padding +
   ~18px Text + 1px Border + Reserve) plus ein bisschen Luft. */
body.watch-mode-active .usage-badge {
  top: 60px;
}
.usage-donut {
  width: 30px; height: 30px;
  /* tooltip-faehig: title-attribute am SVG bzw. dem inneren <title>. */
  cursor: help;
}
.usage-donut-bg {
  fill: none;
  stroke: rgba(0, 0, 0, 0.08);
  stroke-width: 4;
}
.usage-donut-fg {
  fill: none;
  /* Stroke-Dasharray + offset = das Standard-Donut-Trick. r=13 → umfang
     ~81.68. Ein 100%-Wert bedeutet dasharray=81.68 81.68, offset=0. */
  stroke-dasharray: 81.68 81.68;
  stroke-dashoffset: 81.68;
  stroke-width: 4;
  stroke-linecap: round;
  /* Drehung um -90 grad, damit der Ring oben anfaengt zu fuellen (statt
     rechts). transform-origin: SVG-Zentrum (16,16). */
  transform: rotate(-90deg);
  transform-origin: 16px 16px;
  transition: stroke-dashoffset 0.4s ease, stroke 0.3s ease;
}
.usage-donut-text {
  font-size: 9.5px; font-weight: 600;
  fill: var(--text);
  font-family: inherit;
  pointer-events: none;
}
/* Ampel-Farben — von CSS-Klassen auf dem aeusseren <svg> gesteuert. */
.usage-donut.usage-green   .usage-donut-fg { stroke: #2ea44f; }
.usage-donut.usage-yellow  .usage-donut-fg { stroke: #d4a017; }
.usage-donut.usage-orange  .usage-donut-fg { stroke: #e07b00; }
.usage-donut.usage-red     .usage-donut-fg { stroke: #d73a49; }
.usage-donut.usage-unknown .usage-donut-fg { stroke: rgba(0,0,0,0.18); }
/* Donut ist tappable / klickbar — Cursor + Fokus-Ring deutlich machen.
   Wir ueberschreiben damit den frueher gesetzten `cursor: help` auf
   .usage-donut (siehe oben). */
.usage-donut { cursor: pointer; outline: none; }
.usage-donut:focus-visible {
  outline: 2px solid var(--accent, #0d6efd);
  outline-offset: 2px;
  border-radius: 50%;
}
/* Popover unterhalb des Badge. Slide-In von oben, schwebt absolut. */
.usage-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  max-width: 280px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text, #111);
  border: 1px solid rgba(0, 0, 0, 0.10);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  font-size: 12.5px;
  line-height: 1.4;
  z-index: 6;
  pointer-events: auto;
  animation: usagePopoverFadeIn 0.12s ease-out;
}
.usage-popover[hidden] { display: none; }
.usage-popover .usage-popover-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 13px;
}
.usage-popover .usage-popover-line {
  color: var(--text-secondary, #555);
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) {
  .usage-popover {
    background: rgba(28, 36, 46, 0.96);
    color: #f0f3f6;
    border-color: rgba(255, 255, 255, 0.10);
  }
  .usage-popover .usage-popover-line { color: rgba(240, 243, 246, 0.72); }
}
@keyframes usagePopoverFadeIn {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Dark-Mode: dunklerer Hintergrund, hellerer Text. */
@media (prefers-color-scheme: dark) {
  .usage-badge {
    background: rgba(20, 28, 36, 0.65);
    border-color: rgba(255, 255, 255, 0.08);
  }
  .usage-donut-bg { stroke: rgba(255, 255, 255, 0.10); }
  .usage-donut-text { fill: var(--text); }
}
@media (max-width: 720px) {
  /* dvh statt vh: berücksichtigt iOS-Browser-Chrome dynamisch.
     env(safe-area-inset-bottom): Home-Indicator beim iPhone (~34px). */
  .chat-wrap { height: calc(100dvh - 180px - env(safe-area-inset-bottom, 0px));
               border-radius: 0; border-left: 0; border-right: 0; }
}
/* Chat-Tab: keine 880-px-Beschränkung, kein Außenrand. Header bleibt oben,
   darunter füllt das Chat-Fenster den gesamten Viewport — wie bei Telegram
   Web. Nur der Chat-Tab; Settings/Status/Konto bleiben in der Karten-Optik. */
body.tab-chat #app-main { max-width: none; padding: 0; }
body.tab-chat .chat-wrap {
  /* Default Header ≈ 58 px (padding 10+10 + Inhalt). Wir geben uns 60 px
     als Puffer, damit kein Scrollbar entsteht. Mobile hat zusätzlich die
     Bottom-Tabs unten — Höhe dort separat (~120 px Header + Tabs). */
  height: calc(100dvh - 60px);
  border: 0; border-radius: 0; box-shadow: none;
}
/* Chat-Rahmen ZUGESCHALTET — der "alte" Look der ersten Daria-Web-Version:
   Chat ist ein abgesetztes, abgerundetes Rechteck mit Außenabstand, statt
   am Viewport-Rand zu kleben. Wir nehmen sowohl die max-width-Befreiung
   als auch das padding:0 von oben wieder zurück, sonst sieht man von der
   Border praktisch nichts. Zusätzliche Klasse (.chat-bordered) → höhere
   Spezifität als die nackten .tab-chat-Regeln, gewinnt also. */
body.tab-chat.chat-bordered #app-main {
  max-width: 880px;
  padding: 20px;
}
body.tab-chat.chat-bordered .chat-wrap {
  height: calc(100dvh - 100px); /* 60 Header + 2×20 padding */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--bg-card);
}
@media (max-width: 720px) {
  /* Auf Mobile IMMER borderless — der chat-bordered-Style mit 12-20px
     padding raubt zu viel von den 402×874 logical pixels. */
  body.tab-chat.chat-bordered #app-main {
    max-width: none !important;
    padding: 60px 0 0 0 !important;  /* nur padding-top für die top-fixed Tabs */
  }
  body.tab-chat.chat-bordered .chat-wrap {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: var(--bg-card);
  }

  /* Höhen-Berechnung: 100dvh - Header(60) - Tabs(60, oben) - Home-Indicator.
     Mit Tabs jetzt oben gibt es keinen Tastatur-Konflikt mehr — kein
     keyboard-open-Sonderfall nötig. dvh schrumpft bei Tastatur dank
     interactive-widget=resizes-content, chat-input klebt direkt drauf. */
  body.tab-chat .chat-wrap,
  body.tab-chat.chat-bordered .chat-wrap {
    height: calc(100dvh - 60px - 60px - env(safe-area-inset-bottom, 0px));
  }
}
.chat-list {
  flex: 1; overflow-y: auto;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
  background: var(--bg-alt);
  /* Scrollbar visuell ausblenden — Scrollen funktioniert weiterhin per
     Mausrad/Touch/Tastatur. Telegram-Look: aufgeräumte Chat-Fläche. */
  scrollbar-width: none;             /* Firefox */
  -ms-overflow-style: none;          /* alte Edge/IE */
}
.chat-list::-webkit-scrollbar { display: none; } /* Chrome, Safari, neue Edge */
.bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: var(--shadow);
  position: relative;
  /* `flex-shrink: 0` ist kritisch — chat-list ist `display: flex;
     flex-direction: column`. Ohne diese Regel würde der Browser die
     Bubble-Höhe in der Spalte komprimieren, sobald die Summe aller
     Bubbles die chat-list-Höhe überschreitet. Das hatte bei Bild-
     Bubbles zur Folge, dass `.bubble-media { overflow: hidden }` das
     Bild unten beschnitten hat — typischer „Bubble ist zu klein für
     das Bild"-Effekt. Mit shrink:0 behalten Bubbles ihre natürliche
     Höhe und chat-list scrollt regulär. */
  flex-shrink: 0;
}
.bubble.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border: 1px solid var(--bubble-in-border);
  /* Tail-Ecke nicht rund → Telegram-Sprechblasen-Anschluss sitzt bündig. */
  border-bottom-left-radius: 0;
}
.bubble.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 0;
}

/* Comic-/Telegram-Sprechblasen-Tail.
   - .bubble.in (Daria, links)  → Tail unten LINKS, zeigt nach links unten.
   - .bubble.out (Dennis, rechts) → Tail unten RECHTS, zeigt nach rechts unten.
   Form: 1:1 Telegram-Desktop-Tail (originaler SVG-Pfad, 9×17). Vertikale
   Anschlusskante an der Bubble-Seite, gebogene Außenkurve mit kleinem
   Bogen-Tip unten. Wir nutzen `clip-path: path()` mit pixelgenauen
   Koordinaten — die Pseudo-Element-Box ist exakt 9×17 px, der Pfad nutzt
   den vollen Box-Bereich. Color kommt via `background: var(--bubble-…)`,
   passt sich also automatisch an Light/Dark-Mode an.

   Wichtig: bei `.bubble.in` überlappen wir den Bubble-Border um 1 px
   (right: calc(100% - 1px)), damit kein sichtbarer Saum zwischen Tail und
   Bubble entsteht. Greeting-Bubbles bekommen bewusst keinen Tail. */
.bubble.in:not(.greeting)::before,
.bubble.out:not(.greeting)::before {
  content: '';
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 20px;
  pointer-events: none;
}
.bubble.out:not(.greeting)::before {
  /* Tail an der rechten Bubble-Kante, ragt nach rechts heraus.
     Telegram-Originalpfad, hochskaliert auf 12×20 (×1.333 H, ×1.176 V).
     Vertikale Anschlusskante x=0 (y 0→20), Bogen-Tip, zwei Cubic-Beziers
     zurück nach (0,0). Box-Höhe 20px passt noch innerhalb der geraden
     rechten Bubble-Kante (Bubble-Border-Radius 14px lässt min. 16px
     Geraden bei einer einzeiligen Bubble). */
  left: 100%;
  background: var(--bubble-out);
  clip-path: path('M 0 0 C 0.26 3.34, 1.17 6.78, 2.73 10.33 C 3.94 13.06, 5.99 15.60, 8.90 17.95 A 1.25 1.25 0 0 1 8 20 L 0 20 Z');
}
.bubble.in:not(.greeting)::before {
  /* Tail an der linken Bubble-Kante, ragt nach links heraus.
     Manuell gespiegelter Pfad (jedes x → 12-x, Arc-Sweep-Flag von
     1 auf 0 geflippt) — kein `transform: scaleX(-1)`-Trick mehr,
     der in Kombination mit `clip-path` bei manchen Renderern flackerte.
     Form ist 1:1 das horizontale Spiegelbild der .out-Form.

     Border-Kompensation: .bubble.in hat einen 1 px-Border, .out nicht.
     `position: absolute` rechnet relativ zur Padding-Box → ohne
     Korrektur säße der Tail-Boden 1 px ÜBER und 1 px RECHTS vom
     äußeren Bubble-Rand, was zu einer sichtbaren Stufe am Anschluss
     führte. Mit `bottom: -1px` und `right: calc(100% - 1px)`(*) sitzt
     der Tail bündig auf dem äußeren Bubble-Rand, genau wie bei .out.
     (*) Das negative 1px überlappt zusätzlich 1 px in den Bubble-
     Border, damit der Border-Streifen am Anschluss weg ist. */
  bottom: -1px;
  right: calc(100% - 1px);
  background: var(--bubble-in);
  clip-path: path('M 12 0 C 11.74 3.34, 10.83 6.78, 9.27 10.33 C 8.06 13.06, 6.01 15.60, 3.10 17.95 A 1.25 1.25 0 0 0 4 20 L 12 20 Z');
}

/* Telegram-Zeitstempel unten rechts in jeder Konversations-Bubble.
   Realisiert via CSS-`::after`-Pseudo, das den Text aus dem
   `data-time`-Attribut auf der Bubble liest (`content: attr(data-time)`).
   Vorteil: das Attribut überlebt jedes spätere `innerHTML = …`
   (Streaming-Updates, Replay), während ein <span>-Kind beim ersten
   Update weg wäre. Wir reservieren via `padding-right`/`padding-bottom`
   auf der Bubble einen Eck-Platz, damit der Text nicht unter den
   Stempel rutscht. Tool- und Greeting-Bubbles haben kein data-time
   gesetzt — der Selektor matcht dort gar nicht. */
.bubble[data-time]::after {
  content: attr(data-time);
  position: absolute;
  right: 8px;
  bottom: 3px;
  font-size: 11px;
  line-height: 1;
  color: var(--text-dim);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}
.bubble[data-time] {
  /* Eck-Platz für den Stempel — sonst überlappt der Text. 44px rechts
     reicht für "23:59" (~30px) + 8px Stempel-Inset + ~6px Luft. 14px
     unten reicht für die 11px-Schriftgröße + 3px Stempel-Inset. */
  padding-right: 44px;
  padding-bottom: 14px;
}
/* Unsichtbares Hit-Element exakt über dem ::after-Stempel — trägt das
   `title`-Attribut, sodass das volle Datum nur beim Hovern über die
   Uhrzeit erscheint, nicht über die ganze Bubble. JS hängt es an und
   ein MutationObserver re-attached es nach `innerHTML`-Updates. */
.bubble-time-hit {
  position: absolute;
  right: 0;
  bottom: 0;
  /* Deckt grob die Fläche des ::after-Stempels ab (rechts 8px + ~30px
     Text-Breite + ein bisschen Luft, unten 14px Padding-Reserve). */
  width: 46px;
  height: 18px;
  /* Über etwaigem Restcontent rechts-unten, aber unter der ::after-Layer
     (die ist `content`-getrieben und liegt visuell oben — das Hit-Element
     muss nicht sichtbar sein, nur hover-bar). */
  z-index: 1;
}

/* Custom Datum-Tooltip — ersetzt den nativen `title`-Tooltip, der erst
   nach ~500-700 ms erscheint. Wir zeigen unseren in <100 ms via JS.
   `position: fixed` damit er nicht vom Chat-`overflow` geclippt wird. */
.datetime-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.08s ease;
  white-space: nowrap;
  /* Beim Erscheinen genau über der Uhrzeit zentrieren — JS setzt left/top
     auf die Mitte des Hit-Elements, transform pixel-genauen Anker. */
  transform: translate(-50%, -100%);
}
.datetime-tooltip[data-visible="true"] { opacity: 1; }
/* Auf dem dunkelblauen Outgoing-Bubble-BG ist --text-dim zu dunkel —
   wir nehmen ein gedimmtes Weiß analog zu Telegram. */
.bubble.out[data-time]::after {
  color: rgba(255, 255, 255, 0.65);
}
@media (prefers-color-scheme: dark) {
  .bubble.out[data-time]::after { color: rgba(255, 255, 255, 0.55); }
}
.bubble.tool {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  box-shadow: none;
  position: relative;
  overflow: visible;
}
/* Greeting-Bubble (Session-ID-Anzeige am Anfang einer Konversation und bei /new
   im Endlos-Feed) — visuell als Marker abgesetzt, dunkelgrün im Light- wie im
   Dark-Mode. Schriftfarbe ist immer weiß, damit der Kontrast in beiden Themes
   stimmt; sonst sähe der Text im Dark-Mode komplett unleserlich aus. */
.bubble.greeting {
  background: #1f6f3a;
  border: 1px solid #154d28;
  color: #ffffff;
  font-weight: 500;
  /* Mittig + alle 4 Ecken rund, ohne Tail. Greeting markiert eine neue
     Session als Trenner — kein "Sender" → kein Sprechblasen-Schweif.
     Wunsch Dennis 2026-05-18. */
  align-self: center;
  border-bottom-left-radius: 14px;
}
/* Tail des greeting-bubbles unterdruecken (frueher: explizit gezeichnet
   mit eigenem clip-path-Pfad weiter unten). content:none gewinnt gegen
   den ::before-Selektor, weil dort kein !important steht. */
.bubble.greeting::before { content: none !important; }
@media (prefers-color-scheme: dark) {
  .bubble.greeting { background: #245d35; border-color: #173e23; }
}
/* Greeting-Bubble bekommt den gleichen Telegram-Tail wie .bubble.in
   (links unten), nur in den Grün-Tönen. 1:1 dieselbe Geometrie wie
   `.bubble.in:not(.greeting)::before` — gespiegelter Pfad, gleicher
   Border-Versatz (bottom:-1px, right:calc(100%-1px)).
   Hinweis: `.bubble.in:not(.greeting)::before` matcht hier nicht, also
   überschreiben wir nichts, sondern ergänzen einen eigenen Selektor.
   Color via Light/Dark-Media-Query, weil Greeting-Töne hardcoded sind. */
.bubble.greeting::before {
  content: '';
  position: absolute;
  bottom: -1px;
  right: calc(100% - 1px);
  width: 12px;
  height: 20px;
  pointer-events: none;
  background: #1f6f3a;
  clip-path: path('M 12 0 C 11.74 3.34, 10.83 6.78, 9.27 10.33 C 8.06 13.06, 6.01 15.60, 3.10 17.95 A 1.25 1.25 0 0 0 4 20 L 12 20 Z');
  /* Stacked drop-shadows = 1) 1px dunkelgrüne „Border"-Linie unten und
     außen-links (führt den Bubble-Border `#154d28` um den Tail herum,
     damit die durchgängige dunkle Kontur nicht am Tail aufhört), 2)
     ein weicher schwarzer Schatten (analog zum Bubble-`box-shadow`,
     der von außen nicht durch den geclippten Tail durchscheint). */
  filter:
    drop-shadow(0 1px 0 #154d28)
    drop-shadow(-1px 0 0 #154d28)
    drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.18));
}
@media (prefers-color-scheme: dark) {
  .bubble.greeting::before {
    background: #245d35;
    filter:
      drop-shadow(0 1px 0 #173e23)
      drop-shadow(-1px 0 0 #173e23)
      drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35));
  }
}

/* Disintegration: Bubble shrinkt + fadet, Partikel fliegen radial weg.
   Telegram-Style "vanish in particles" wenn der Schritt abgeschlossen ist.
   Wir hängen den Effekt an `.bubble.dissolving` (egal welcher Sub-Kind),
   damit auch typing- und Streaming-Bubbles beim Wegmachen denselben
   weichen Auflöse-Effekt bekommen. */
.bubble.dissolving {
  animation: tool-dissolve 0.6s ease-out forwards;
  pointer-events: none;
  /* Partikel müssen über den Rand der Bubble hinausfliegen können.
     .bubble.tool hat das schon; .bubble.in/.out per Default nicht. */
  overflow: visible;
}
@keyframes tool-dissolve {
  0%   { opacity: 1;   transform: scale(1)    translateY(0); }
  40%  { opacity: 0.5; transform: scale(0.96) translateY(-2px); }
  100% { opacity: 0;   transform: scale(0.85) translateY(-6px); filter: blur(1px); }
}
.tool-dot {
  position: absolute;
  width: 5px; height: 5px;
  background: var(--accent);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  animation: tool-dot-fly 0.55s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes tool-dot-fly {
  0%   { transform: translate(0, 0)                        scale(0.6); opacity: 0; }
  15%  { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty))        scale(0.3); opacity: 0; }
}
.bubble pre {
  background: rgba(0,0,0,.06); padding: 8px; border-radius: 6px;
  overflow-x: auto; font-size: 12px;
}
@media (prefers-color-scheme: dark) {
  .bubble pre { background: rgba(255,255,255,.06); }
}
.bubble code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}
/* Markdown-Renderer (renderMd in app.js) produziert diese Elemente —
   wir geben ihnen kompakte, zur Bubble passende Defaults statt der
   Browser-Defaults (h1 wäre sonst riesig, Listen würden weit einrücken). */
.bubble :first-child { margin-top: 0; }
.bubble :last-child  { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3,
.bubble h4, .bubble h5, .bubble h6 {
  margin: 8px 0 4px; line-height: 1.25; font-weight: 600;
}
.bubble h1 { font-size: 1.25em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1.05em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble blockquote {
  margin: 4px 0; padding: 2px 10px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}
.bubble a {
  color: var(--accent); text-decoration: underline;
  text-underline-offset: 2px;
}
.bubble a:hover { color: var(--accent-strong); }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble del { opacity: .6; }
.bubble table {
  border-collapse: collapse;
  margin: 6px 0;
  font-size: 13px;
  max-width: 100%;
  display: block;
  overflow-x: auto;
  white-space: normal;  /* überschreibt pre-wrap der Bubble, damit Zellen nicht
                           durch jeden Zeilenumbruch sprengt werden */
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
}
.bubble th {
  background: rgba(0, 0, 0, .05);
  font-weight: 600;
}
@media (prefers-color-scheme: dark) {
  .bubble th { background: rgba(255, 255, 255, .06); }
}
.bubble .meta {
  font-size: 11px; color: var(--text-dim); margin-top: 4px;
}
.typing { display: inline-flex; gap: 4px; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); opacity: .3;
  animation: typing 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.chat-input-row {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px; background: var(--bg-card);
  border-top: 1px solid var(--border);
}
#chat-input {
  flex: 1;
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 10px 14px; font-size: 15px;
  resize: none; max-height: 200px; min-height: 40px;
  outline: none; font-family: inherit; line-height: 1.4;
}
#chat-input:focus { border-color: var(--accent); }
.send-btn {
  background: var(--accent); color: #fff; border: 0;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-strong); }
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Forms im Account-Tab */
form label { display: block; font-size: 13px; color: var(--text-dim); margin: 10px 0 4px; }
form input[type="password"], form input[type="text"] {
  width: 100%; max-width: 360px;
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; outline: none;
}
form input:focus { border-color: var(--accent); }

/* ---------- Mikrofon-Button ---------- */
.mic-btn {
  background: transparent; color: var(--text-dim); border: 0;
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  flex-shrink: 0; transition: background .15s, color .15s, transform .1s;
}
.mic-btn:hover { background: var(--bg-alt); color: var(--accent); }
.mic-btn.recording-pending {
  /* Orange während getUserMedia + MediaRecorder.start() noch laufen */
  background: #ff9800; color: #fff;
}
.mic-btn.recording {
  background: var(--danger); color: #fff;
  animation: rec-pulse 1.2s infinite;
}
@keyframes rec-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, .45); }
  70%      { box-shadow: 0 0 0 12px rgba(229, 57, 53, 0); }
}

/* Transkriptions-Bubble während Whisper läuft */
.bubble.transcribing { opacity: .7; font-style: italic; }

/* Audio-Player für TTS-Antworten */
audio.voice-answer {
  display: block;
  margin-top: 8px;
  width: 100%;
  height: 36px;
  border-radius: 18px;
}
/* Custom Web-Audio-Player (Safari-kompatibel) */
.voice-player {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px;
  padding: 6px 12px;
  background: rgba(0,0,0,.08);
  border-radius: 18px;
  user-select: none;
}
@media (prefers-color-scheme: dark) {
  .voice-player { background: rgba(255,255,255,.08); }
}
.voice-play-btn {
  background: var(--accent); color: #fff; border: 0;
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  font-size: 14px; line-height: 1; flex-shrink: 0;
  transition: background .15s, transform .1s;
}
.voice-play-btn:hover { background: var(--accent-strong); }
.voice-play-btn:active { transform: scale(.94); }
.voice-progress {
  flex: 1; height: 6px;
  background: rgba(0,0,0,.15);
  border-radius: 3px;
  cursor: pointer; position: relative;
  min-width: 80px;
}
@media (prefers-color-scheme: dark) {
  .voice-progress { background: rgba(255,255,255,.15); }
}
.voice-progress-bar {
  height: 100%; width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width .05s linear;
}
.voice-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--text-dim);
  min-width: 70px; text-align: right;
}
.voice-speed-btn {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px; font-size: 11px; font-weight: 600;
  cursor: pointer; flex-shrink: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  transition: background .15s, color .15s, border-color .15s;
  min-width: 36px;
}
.voice-speed-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

/* Popover: Schnellauswahl aller Geschwindigkeiten oberhalb des Speed-Buttons */
.voice-player { position: relative; } /* nötig fürs absolut positionierte Popover */
.voice-speed-picker {
  position: absolute;
  display: flex; flex-direction: column; gap: 2px;
  padding: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-elev);
  z-index: 5;
  min-width: 56px;
}
.voice-speed-opt {
  background: transparent; color: var(--text);
  border: 0; border-radius: 6px;
  padding: 6px 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background .12s;
}
.voice-speed-opt:hover { background: var(--bg-alt); }
.voice-speed-opt.selected {
  background: var(--accent); color: #fff;
}
.voice-error {
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(229, 57, 53, .12);
  color: var(--danger);
  font-size: 12px;
  border-radius: 6px;
}

/* ---------- Inline-Keyboard (Telegram-Style Buttons in Bubbles) ---------- */
.inline-kb { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.inline-kb-row { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-kb-btn {
  flex: 1;
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  font-family: inherit; min-width: 80px;
}
.inline-kb-btn:hover:not(:disabled) {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong);
}
.inline-kb-btn:active:not(:disabled) { transform: scale(.97); }
.inline-kb-btn:disabled { opacity: .5; cursor: not-allowed; }
.inline-kb-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Slash-Popover (Telegram-Slash-Menü-Äquivalent) ---------- */
.slash-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elev);
  max-height: 280px;
  overflow-y: auto;
  z-index: 30;
  padding: 4px;
}
.slash-item {
  display: flex; align-items: baseline; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--text);
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  font-family: inherit; font-size: 14px;
}
.slash-item:hover, .slash-item.active { background: var(--bg-alt); }
.slash-item.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.slash-cmd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600; color: var(--accent);
  min-width: 70px;
}
.slash-desc { color: var(--text-dim); font-size: 13px; }

/* Menü-Button links neben dem Chat-Input (Telegram-Style "☰") */
.slash-menu-btn {
  background: transparent; color: var(--text-dim); border: 0;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  flex-shrink: 0; transition: background .15s, color .15s;
}
.slash-menu-btn:hover { background: var(--bg-alt); color: var(--accent); }

/* ===== Gedächtnis-Tab ===== */
.memory-info .memory-rules { margin: 8px 0 4px; padding-left: 20px; }
.memory-info .memory-rules li { margin: 4px 0; line-height: 1.45; }
.memory-info .memory-restart {
  margin-top: 8px; padding: 8px 12px; border-radius: 6px;
  background: var(--bg-alt); color: var(--text-dim);
  border-left: 3px solid var(--accent);
}
.memory-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.memory-row {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px; border-radius: 8px;
  background: var(--bg-alt);
  border: 1px solid var(--border, transparent);
}
.memory-row-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.memory-row-main {
  display: flex; justify-content: space-between; gap: 12px;
  align-items: flex-start; flex-wrap: wrap;
}
.memory-row-name { font-weight: 600; }
.memory-row-path {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--text-dim); margin-top: 2px;
  word-break: break-all;
}
.memory-row-meta {
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap;
}
.memory-row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.memory-field-label {
  display: block; margin: 12px 0 4px;
  font-size: 13px; color: var(--text-dim);
}
.memory-editor {
  width: 100%; min-height: 320px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.45;
  padding: 10px 12px; border-radius: 6px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border, #444);
  resize: vertical;
}
.memory-editor:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
#mem-new-name {
  width: 100%; padding: 8px 10px; border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
}

/* ===== Sessions: Name-Input ===== */
.session-name-input {
  width: 100%; max-width: 360px;
  margin: 2px 0 6px;
  padding: 4px 8px;
  font-size: 14px; font-weight: 600;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 6px;
  color: var(--text);
}
.session-name-input::placeholder { color: var(--text-dim); font-weight: 400; }
.session-name-input:hover { border-color: var(--border); }
.session-name-input:focus {
  outline: none; border-style: solid; border-color: var(--accent);
  background: var(--bg-card);
}

/* ===== Chat: Attach-Chip ===== */
.attach-chip-wrap {
  padding: 6px 14px 0;
  display: flex;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 13px; color: var(--text);
  max-width: 100%;
}
.attach-chip-name {
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 280px;
}
.attach-chip-meta { color: var(--text-dim); font-size: 12px; }
.attach-chip-remove {
  background: transparent; border: 0; cursor: pointer;
  color: var(--text-dim); font-size: 18px; line-height: 1;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 50%;
}
.attach-chip-remove:hover { background: var(--bg); color: var(--text); }

/* ===== Memory: Typen-Badges + Erklärungs-Legende ===== */
.memory-row-text { flex: 1; min-width: 0; }
.memory-row-desc { color: var(--text-dim); font-size: 13px; margin: 2px 0; }
.memory-row-when {
  color: var(--text-dim); font-size: 12px; margin: 2px 0 4px;
  font-style: italic;
}
.memory-type-badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 11px; font-weight: 600;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 4px;
  color: #fff;
  background: var(--text-dim);
}
.memory-type-user { background: #5b8def; }
.memory-type-feedback { background: #e8a04f; }
.memory-type-project { background: #6cba6b; }
.memory-type-reference { background: #b079d1; }
.memory-type-legend {
  list-style: none; padding: 0; margin: 8px 0 12px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-dim);
}
.memory-type-legend li {
  display: flex; gap: 8px; align-items: baseline;
}
.memory-type-legend .memory-type-badge { margin: 0; }

/* ===== Account: Lockout-Selects nebeneinander/wie inputs ===== */
#lockout-form select {
  display: block; margin-bottom: 0;
  padding: 8px 10px; border-radius: 6px;
}

/* Generische Inline-Reihe für Account-Forms (Login-Sperre, Passwort ändern):
   Felder + zugehöriger Submit-Button sitzen alle in einer Zeile, Labels
   stehen über dem jeweiligen Input. `align-items: flex-end` lässt den Button
   bündig zur Input-Unterkante stehen, auch wenn die Labels mehrzeilig sind.
   Auf schmalen Viewports wrappen die Felder; Buttons rutschen dann unter
   die zuletzt sichtbare Spalte. */
.inline-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.inline-field {
  display: flex; flex-direction: column;
  min-width: 160px;
}
.inline-field label {
  margin: 0 0 4px;
}
.inline-row input[type="password"],
.inline-row input[type="text"] {
  /* Override des form input-Defaults, der max-width: 360px setzt — in der
     Inline-Row soll das Input die Spaltenbreite voll ausnutzen. */
  max-width: none;
  margin: 0;
}
.inline-row button[type="submit"] {
  /* Keine Top-Margin, damit der Button bündig zur Input-Unterkante sitzt. */
  margin: 0;
}

/* ===== Chat: Media-Bubble (Telegram-Style Inline-Bild + Caption) ===== */
/* Bubble enthält ein Bild oder eine Dateikarte oben und – optional –
   eine Caption darunter, beides als gemeinsame Sprechblase. Damit der
   Bubble-Rahmen das Bild sauber abschneidet, schalten wir Padding und
   Overflow um (sonst guckt das Bild an den Ecken raus). Zusätzlich eine
   min-width/min-height, damit die Bubble auch während des Bild-Ladens
   bzw. bei sehr kleinen Bildern nie zur „dünnen Linie" zusammenfällt
   und Dennis weiß: hier ist eine Bubble, kein Fehler. */
/* Bild-Bubble: bewusst minimalistisch, kein Layout-Magic.
   - Padding 4px. `overflow: visible`, damit der Telegram-Tail
     (`.bubble.out::before` Pseudo-Element) nicht weggeclippt wird.
     Das Bild bleibt trotzdem innerhalb der Rundung, weil
     `.bubble-media` selbst `overflow: hidden` + `border-radius` hat.
   - JS setzt nach `img.onload` die Bubble-Breite per Inline-Style
     auf die tatsächlich gerenderte Bildbreite (siehe
     `addAttachmentBubble`), damit die Bubble exakt so breit ist wie
     das Bild — unabhängig von Browser-Layout-Quirks. */
.bubble.bubble-with-media {
  padding: 4px;
  overflow: visible;
}
.bubble.bubble-with-media[data-time] {
  padding-right: 4px;
  padding-bottom: 4px;
}
.bubble-media {
  display: block;
  margin: 0;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.06);
}
@media (prefers-color-scheme: dark) {
  .bubble-media { background: rgba(255, 255, 255, 0.05); }
}
/* `font-size: 0` auf dem `<a>` killt die anonyme Inline-Linebox, die sonst
   ~24px Whitespace unter dem Bild erzeugt. Der Lade-Placeholder ist ein
   Sibling vom `<a>` und behält seinen eigenen `font-size`. */
.bubble-media a {
  display: block;
  font-size: 0;
  line-height: 0;
}
.bubble-media img {
  display: block;
  /* Ohne explizite Constraints aus dem CSS: JS misst `naturalWidth/Height`
     im `onload` und setzt die effektive Render-Größe als Inline-Style. */
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  cursor: zoom-in;
}
/* Lade-Placeholder, bis `img.onload` feuert. */
.bubble-media-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  min-height: 72px;
  padding: 12px 16px;
  color: var(--text-dim);
  font-size: 13px;
  font-style: italic;
}
/* Caption hat denselben linksbündigen Lese-Look wie ein Text-Bubble.
   Steht jetzt OBERHALB des Bildes (Telegram-Style), damit der Text auch
   sichtbar bleibt, wenn das Bild auf knappe Chat-Höhe geschrumpft wird. */
.bubble-caption {
  padding: 6px 10px 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
/* Wenn die Caption oberhalb steht, braucht sie unten 6px Luft zum Bild
   und keinen Platz für den Zeitstempel (der sitzt rechts unten im Bubble,
   unter dem Bild). */
.bubble-caption.bubble-caption-top {
  padding: 4px 8px 6px;
}
/* Dateikarte (kein Bild): Telegram-Look mit Datei-Icon, Name, Größe.
   Hover-Highlight + Cursor zeigen Klickbarkeit (Download). */
.bubble-file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background .12s;
}
.bubble-file:hover { background: rgba(0, 0, 0, 0.08); }
@media (prefers-color-scheme: dark) {
  .bubble-file { background: rgba(255, 255, 255, 0.05); }
  .bubble-file:hover { background: rgba(255, 255, 255, 0.09); }
}
.bubble-file-icon {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
}
.bubble-file-meta {
  display: flex; flex-direction: column;
  min-width: 0;
}
.bubble-file-name {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 240px;
}
.bubble-file-sub {
  font-size: 12px; color: var(--text-dim);
}

/* ===== Chat: Audio-Anhang (Custom-Player + Meta-Zeile) =====
   Player nutzt das gleiche Look-and-Feel wie `.voice-player` (TTS-
   Antworten), mit kleiner Anpassung: kein `margin-top`, weil der
   Player in der Bubble direkt oben sitzt, nicht unter einer Caption. */
.bubble-audio-player {
  margin-top: 0 !important;
  min-width: 280px;
}
.bubble-audio-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
  padding: 4px 6px;
  text-decoration: none;
  color: inherit;
  font-size: 12px;
}
.bubble-audio-meta:hover { text-decoration: underline; }
.bubble-audio-name { font-weight: 600; font-size: 13px; }
.bubble-audio-sub { color: var(--text-dim); }

/* ===== Chat: Drag&Drop-Overlay ===== */
.chat-dropzone {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(42, 171, 238, 0.18);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  pointer-events: none;
  animation: dropzone-fade 0.12s ease-out;
}
@keyframes dropzone-fade { from { opacity: 0; } to { opacity: 1; } }
.chat-dropzone-inner {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 24px 28px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: var(--shadow-elev);
}
.chat-dropzone-text { font-size: 14px; }
.chat-wrap.drag-over { /* Hook für zukünftige Effekte am Container selbst. */ }

/* ===== Chat: Anhang-Preview-Modal (Telegram-Style) ===== */
.modal-card.modal-card-attachment { max-width: 520px; }
.att-preview-image {
  display: grid; place-items: center;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: 6px;
  margin-bottom: 12px;
}
.att-preview-image img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  width: auto; height: auto;
  border-radius: 6px;
}
.att-preview-file {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}
.att-preview-file-icon {
  flex-shrink: 0;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
}
.att-preview-file-meta {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.att-preview-file-name {
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.att-preview-file-sub {
  font-size: 12px; color: var(--text-dim);
}
.att-preview-label {
  display: block;
  font-size: 13px; color: var(--text-dim);
  margin: 4px 0;
}
.att-preview-caption {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
}
.att-preview-caption:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ===== Markdown-Image im Chat (Daria postet ein Bild via ![alt](url)) ===== */
.md-image {
  display: block;
  margin: 4px 0;
  line-height: 0;
}
.md-image img {
  /* Gleiche Logik wie `.bubble-media img`: ganzes Bild zeigen, im Zweifel
     verkleinern, Aspekt erhalten. Klick öffnet Lightbox (siehe app.js). */
  max-width: 100%;
  max-height: 70vh;
  width: auto; height: auto;
  object-fit: contain;
  border-radius: 10px;
  cursor: zoom-in;
}

/* ===== Image Lightbox (Click auf Inline-Bild im Chat) ===== */
/* Eigener Layer (NICHT der openModal-Layer), weil wir das Bild bis ans
   Viewport-Limit groß zeigen wollen — der Modal-Card-Container hätte da
   eine fixe max-width im Weg. ESC + Backdrop-Klick + X-Button schließen. */
.lightbox-root {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 16px 16px;
  animation: lightbox-fade .12s ease-out;
}
@keyframes lightbox-fade { from { opacity: 0; } to { opacity: 1; } }
.lightbox-toolbar {
  position: absolute;
  top: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center;
  z-index: 1;
}
.lightbox-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit; font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, 0.22); }
.lightbox-btn svg { display: block; }
/* Schließen-Button ist nur das Icon (kein Label) */
.lightbox-btn#lb-close { padding: 8px; }
.lightbox-stage {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* min-height: 0 — sonst sprengt die intrinsic height der img die
     parent-Größe und der Stage wird größer als der verfügbare Bereich. */
  min-height: 0;
  overflow: hidden;
}
.lightbox-img {
  display: block;
  /* Bild soll bis ans Viewport-Limit groß werden, aber nie clipped. */
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
  cursor: default;
}

/* Utility */
[hidden] { display: none !important; }

/* C7 (2026-05-17): CSS-Klassen statt inline-style, damit die CSP
 * `style-src 'self'` (ohne 'unsafe-inline') greifen kann.
 * Tabellen-Zell-Alignment aus Markdown-Tabellen. */
.md-align-left   { text-align: left; }
.md-align-center { text-align: center; }
.md-align-right  { text-align: right; }

/* Label rechts neben der „...tippt"-Animation in der Chat-Bubble. */
.typing-label {
  color: var(--text-dim);
  font-size: 12px;
}

/* Status-Card: volle Session-UUIDs lesbar darstellen — monospace + sauberer
   Umbruch, damit die 36-Zeichen-UUID nicht den Card-Layout zerschießt. */
#st-web-session,
#st-session {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  word-break: break-all;
  line-height: 1.3;
}

/* ---------- TLS-Cert-Karte im Status-Tab ----------
 * Vorher: inline-styles mit #fafafa-Background + #555-color → im Dark-Mode
 * weiss-auf-weiss unleserlich, weil der globale color: var(--text) (= weiss)
 * den nicht ueberall gesetzten Card-Text uebernimmt. Jetzt: theme-aware
 * via CSS-Variablen, plus dedizierte Status-Klassen fuer den Badge.
 */
.cert-card {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 8px;
  box-shadow: var(--shadow);
}
.cert-card .cert-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.cert-card .cert-info { flex: 1; min-width: 240px; }
.cert-card .cert-info strong { color: var(--text); }
.cert-card .cert-title { font-size: 14px; font-weight: 600; }
.cert-card .cert-detail {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  line-height: 1.5;
}
.cert-card .cert-detail strong { color: var(--text); font-weight: 600; }
.cert-card .cert-detail code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  word-break: break-all;
  color: var(--text);
  background: var(--bg-alt);
  padding: 0 4px;
  border-radius: 3px;
}
.cert-card .cert-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cert-card .cert-badge {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 600;
}
.cert-badge.ok      { color: var(--ok); }
.cert-badge.warn    { color: #d97706; }
.cert-badge.danger  { color: var(--danger); }

/* ---------- .env-Editor ----------
 * Sensible Keys (redacted) brauchen einen klaren Hinweis "leer = unveraendert",
 * sonst ueberschreibt ein arglos geklickter "Speichern" den Token mit dem
 * angezeigten Maskenwert (frueher "null").
 */
.env-row {
  display: grid;
  grid-template-columns: minmax(160px, 22%) 1fr auto;
  align-items: center;
  gap: 8px;
}
.env-row .env-key {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}
.env-row input::placeholder { color: var(--text-dim); font-style: italic; }
.env-row .env-actions { display: flex; gap: 4px; }
.env-row .env-redacted-hint {
  grid-column: 2 / 3;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: -4px;
}
@media (max-width: 600px) {
  .env-row {
    grid-template-columns: 1fr;
  }
  .env-row .env-redacted-hint { grid-column: 1 / 2; }
}

/* ---------- Telegram-Setup-Card ----------
 * Dedizierte UI fuer TELEGRAM_BOT_TOKEN + USER_ID mit Inline-Anleitung
 * (@BotFather/@userinfobot). Schreibt ueber /api/env wie der generische
 * Editor, aber prominenter platziert. Theme-aware via CSS-Variablen.
 */
.tg-setup-howto {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 10px 0 16px;
}
.tg-setup-howto > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  padding: 4px 0;
  list-style: none;
  position: relative;
  padding-left: 20px;
}
.tg-setup-howto > summary::-webkit-details-marker { display: none; }
.tg-setup-howto > summary::before {
  content: '▶';
  position: absolute;
  left: 0;
  font-size: 10px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 120ms ease;
  color: var(--text-dim);
}
.tg-setup-howto[open] > summary::before { transform: translateY(-50%) rotate(90deg); }
.tg-setup-howto > summary:hover { color: var(--accent); }
.tg-setup-steps {
  margin: 12px 0 8px;
  padding-left: 24px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}
.tg-setup-steps li { margin-bottom: 6px; }
.tg-setup-howto a {
  color: var(--accent);
  text-decoration: underline;
}
.tg-setup-howto code,
.tg-setup-row code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg);
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.92em;
}
.tg-setup-row {
  margin: 14px 0;
}
.tg-setup-label {
  display: block;
  margin-bottom: 6px;
}
.tg-setup-label > span {
  display: block;
  font-weight: 600;
  color: var(--text);
}
.tg-setup-label > .hint {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: normal;
}
.tg-setup-input {
  display: flex;
  gap: 6px;
  align-items: center;
}
.tg-setup-input input {
  flex: 1;
  min-width: 0;
}
.tg-setup-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- Modal-Dialog (generisch, derzeit nur Telegram-Setup) ----------
 * Backdrop liegt fixed ueber dem ganzen Viewport, der Dialog zentriert
 * mittig. Body-Klasse `modal-open` sperrt das Background-Scrolling, damit
 * der User nicht versehentlich den Chat hinter dem Modal scrollt.
 */
body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vh 16px;
  overflow-y: auto;
  /* Sanftes Reinflashen — kein Fade, kein Slide, nur das Minimum. */
}
.modal-backdrop[hidden] { display: none; }
.modal-dialog {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-elev);
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 10vh);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.modal-close {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg-alt); color: var(--text); }
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
@media (max-width: 600px) {
  .modal-backdrop { padding: 0; }
  .modal-dialog {
    max-width: 100%;
    min-height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: 0;
  }
}
