/* =========================================================
   Pocket Claude — Web-UI v2 Redesign
   Vanilla CSS, ChatGPT-inspirierter Look, Light/Dark.
   ========================================================= */

:root {
  /* Brand */
  --brand-50:  #EAF4FB;
  --brand-100: #C8E3F2;
  --brand-200: #9ECCE5;
  --brand-400: #5BC0DE;
  --brand-500: #4A90C2;
  --brand-600: #2F6A94;
  --brand-700: #1E4D75;

  /* Light theme */
  --bg:          #FFFFFF;
  --bg-elev:     #F7F7F8;
  --bg-elev-2:   #ECECF1;
  --sidebar-bg:  #F9F9F9;
  --surface:     #FFFFFF;
  --surface-2:   #F0F0F2;
  --border:      #E5E5E7;
  --border-soft: #EFEFF1;
  --text:        #2D2D2F;
  --text-soft:   #565869;
  --text-muted:  #8E8EA0;
  --bubble-user: #F0F4F9;
  --bubble-user-fg: #2D2D2F;
  --accent:      var(--brand-500);
  --accent-hover: var(--brand-600);
  --danger:      #DC2626;
  --success:     #10B981;
  --warning:     #F59E0B;
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.04);
  --shadow:      0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.14);
  --radius:      12px;
  --radius-lg:   18px;
  --radius-xl:   24px;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg:          #0F0F10;
  --bg-elev:     #181819;
  --bg-elev-2:   #242427;
  --sidebar-bg:  #161617;
  --surface:     #1B1B1D;
  --surface-2:   #232326;
  --border:      #2A2A2D;
  --border-soft: #222225;
  --text:        #EAEAEC;
  --text-soft:   #B4B4BA;
  --text-muted:  #7D7D86;
  --bubble-user: #2B2C30;
  --bubble-user-fg: #EAEAEC;
  --accent:      var(--brand-400);
  --accent-hover: var(--brand-200);
  --shadow-sm:   0 1px 2px rgba(0,0,0,0.5);
  --shadow:      0 8px 24px rgba(0,0,0,0.4);
  --shadow-lg:   0 24px 60px rgba(0,0,0,0.6);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0F0F10;
    --bg-elev:     #181819;
    --bg-elev-2:   #242427;
    --sidebar-bg:  #161617;
    --surface:     #1B1B1D;
    --surface-2:   #232326;
    --border:      #2A2A2D;
    --border-soft: #222225;
    --text:        #EAEAEC;
    --text-soft:   #B4B4BA;
    --text-muted:  #7D7D86;
    --bubble-user: #2B2C30;
    --bubble-user-fg: #EAEAEC;
    --accent:      var(--brand-400);
    --accent-hover: var(--brand-200);
    --shadow-sm:   0 1px 2px rgba(0,0,0,0.5);
    --shadow:      0 8px 24px rgba(0,0,0,0.4);
    --shadow-lg:   0 24px 60px rgba(0,0,0,0.6);
    color-scheme: dark;
  }
}

/* ----------- Reset ----------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.icon.icon-sm { width: 14px; height: 14px; }

/* ----------- Login ----------- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(800px 600px at 20% 0%, color-mix(in srgb, var(--brand-500) 18%, transparent), transparent 60%),
    radial-gradient(900px 700px at 100% 100%, color-mix(in srgb, var(--brand-400) 10%, transparent), transparent 60%),
    var(--bg);
  z-index: 100;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 56px; height: 56px;
  margin-bottom: 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  box-shadow: 0 8px 24px color-mix(in srgb, var(--brand-500) 35%, transparent);
}
.login-brand h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.login-brand p { margin: 0; color: var(--text-soft); font-size: 14px; }
.field {
  display: block;
  margin-top: 14px;
}
.field > span {
  display: block;
  font-size: 12px;
  color: var(--text-soft);
  margin-bottom: 6px;
  font-weight: 500;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.login .btn-primary { width: 100%; margin-top: 20px; }
.login-status {
  margin-top: 14px; min-height: 1.2em;
  text-align: center; font-size: 13px;
  color: var(--text-soft);
}
.login-status.error { color: var(--danger); }
.login-status.ok { color: var(--success); }

/* ----------- App Layout ----------- */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100dvh;
  background: var(--bg);
  transition: grid-template-columns 0.2s ease;
}
/* Desktop: Sidebar einklappbar — App-Klasse `sidebar-collapsed`
   schaltet die Sidebar-Spalte auf 0 und blendet sie aus. */
.app.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}
.app.sidebar-collapsed .sidebar {
  width: 260px;
  transform: translateX(-100%);
}
.sidebar {
  transition: transform 0.2s ease;
}
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0;
    width: 86%; max-width: 320px;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
}

/* ----------- Sidebar ----------- */
.sidebar {
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-section {
  padding: 10px 10px 0;
}
.sidebar-section + .sidebar-section { padding-top: 6px; }
.search-wrap {
  position: relative;
  display: flex; align-items: center;
}
.search-wrap .search-icon {
  position: absolute; left: 10px;
  color: var(--text-muted);
  width: 16px; height: 16px;
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--bg-elev);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}
.search-wrap input:focus {
  background: var(--surface);
  border-color: var(--border);
}

.chat-nav {
  flex: 1; overflow-y: auto;
  padding: 12px 10px;
}
.chat-nav-group { margin-bottom: 18px; }
.chat-nav-label {
  display: block;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  position: relative;
  transition: background 0.12s;
}
.chat-item:hover { background: var(--bg-elev-2); }
.chat-item.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 500;
}
.chat-item .title {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item .pin-mark {
  color: var(--accent); font-size: 11px;
}
/* Hover-only "…" trigger for the per-chat rename/pin/delete menu */
.chat-item .chat-row-more {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  display: none;
  align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--text-soft);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
}
.chat-item:hover .chat-row-more,
.chat-item.menu-open .chat-row-more { display: inline-flex; }
.chat-item .chat-row-more:hover { background: var(--bg-elev-3, rgba(255,255,255,0.06)); color: var(--text); }
.chat-item .chat-row-more svg { width: 14px; height: 14px; }
/* Floating menu — positioned via JS */
.chat-row-menu {
  position: fixed; z-index: 50;
  min-width: 160px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  font-size: 14px;
}
.chat-row-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.chat-row-menu button:hover { background: var(--bg-elev-3, rgba(255,255,255,0.08)); }
.chat-row-menu button.danger { color: var(--danger, #e96666); }
.chat-row-menu button.danger:hover { background: rgba(233,102,102,0.10); }
.chat-row-menu hr {
  border: none; border-top: 1px solid var(--border, rgba(255,255,255,0.08));
  margin: 4px 2px;
}
.chat-row-menu svg { width: 14px; height: 14px; flex-shrink: 0; }
.chat-item.search-hit {
  padding: 10px;
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
}
.chat-item.search-hit .title { font-weight: 500; }
.chat-item.search-hit .snippet {
  font-size: 13px;
  color: var(--text-soft);
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.chat-item.search-hit .snippet b {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--text);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
}
.empty-chats {
  padding: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 8px 10px 12px;
  border-top: 1px solid var(--border-soft);
}
.footer-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-soft);
}
.footer-user .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
}
.footer-user .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footer-user .badge {
  font-size: 10px; padding: 2px 6px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.footer-row {
  display: flex; gap: 4px;
  margin-top: 4px;
}

/* User-Verwaltung */
.users-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.user-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}
.user-row .name { font-weight: 500; flex: 0 0 auto; }
.user-row .badge {
  font-size: 10px; padding: 2px 5px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  border-radius: 3px;
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.user-row .token {
  flex: 1; min-width: 0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  user-select: all;
}
.user-row .actions { display: flex; gap: 2px; flex-shrink: 0; }
.user-row .actions .icon-btn { width: 28px; height: 28px; }
.user-row .actions .icon-btn .icon { width: 14px; height: 14px; }
.user-row .user-spacer { flex: 1; }
.user-row .badge.warn {
  background: color-mix(in srgb, #ffb84d 22%, transparent);
  color: #d68a17;
}
@media (prefers-color-scheme: dark) {
  .user-row .badge.warn { color: #ffb84d; }
}

/* Password-Change-Modal: gleiche Optik wie prompt-modal aber mit mehreren Feldern */
#pwchange-modal .modal-body { display: flex; flex-direction: column; gap: 10px; }
#pwchange-modal .field { margin: 0; }
#pwchange-modal .login-status { margin-top: 4px; }

/* ----------- Buttons ----------- */
.ghost-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.ghost-btn:hover { background: var(--bg-elev-2); }
.ghost-btn.new-chat {
  background: var(--surface);
  border-color: var(--border);
}
.ghost-btn.new-chat:hover { background: var(--bg-elev-2); border-color: var(--border); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  border-radius: 8px;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.pill-btn:hover { background: var(--bg-elev-2); }

.btn-primary {
  padding: 10px 18px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
}
.btn-secondary:hover { background: var(--bg-elev-2); }
.btn-ghost {
  padding: 8px 14px;
  background: transparent;
  color: var(--text-soft);
  border: 0;
  border-radius: var(--radius);
  font-size: 14px;
}
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); }

/* ----------- Main ----------- */
.main {
  display: flex; flex-direction: column;
  /* WICHTIG: min-width/min-height: 0, sonst dehnt sich die Grid-Zelle (default
     min-content) auf den gesamten Messages-Content aus → ganze Seite scrollt
     statt nur die Messages, Sidebar wandert mit. */
  min-width: 0; min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  flex: 0 0 auto;  /* fix oben im Flex-Container — kein sticky mehr nötig */
  z-index: 10;
}
.topbar-title {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; line-height: 1.2;
}
.topbar-title h1 {
  margin: 0; font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-meta {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-meta.warn { color: var(--warning); }
.topbar-actions {
  display: flex; align-items: center; gap: 4px;
  position: relative;
}

/* Dropdowns */
.effort-wrap { position: relative; }
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 180px;
  z-index: 20;
}
.dropdown.right { right: 0; }
.dropdown button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  transition: background 0.1s;
}
.dropdown button:hover { background: var(--bg-elev-2); }
.dropdown button.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.dropdown button.danger { color: var(--danger); }
.dropdown button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.dropdown hr { border: 0; border-top: 1px solid var(--border-soft); margin: 4px 0; }

/* ----------- Messages ----------- */
.messages {
  flex: 1;
  min-height: 0; /* damit der Flex-Item überhaupt schrumpfen darf */
  overflow-y: auto;
  /* KEIN scroll-behavior: smooth — sonst dauert jeder scrollTop-Set 300ms+
     und unser „pin zum unteren Ende beim Chat-Öffnen" wirkt zerrissen. */
  padding-bottom: 16px;
}
.messages-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 20px 0;
}
.empty-hint {
  margin: 18vh auto;
  max-width: 380px;
  text-align: center;
  color: var(--text-muted);
}
.empty-hint .e-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  border-radius: 20px;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--brand-500) 30%, transparent);
}
.empty-hint h3 { margin: 0 0 6px; font-size: 18px; font-weight: 600; color: var(--text); }
.empty-hint p { margin: 0; font-size: 14px; }

.msg { margin: 18px 0; }
.msg.user {
  display: flex;
  justify-content: flex-end;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-fg);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 14px;
  max-width: 75%;
  word-wrap: break-word;
}

/* Collapsible long user messages (ChatGPT-style).
   JS toggelt .collapsed bei zu langen Bubbles. CSS macht den eigentlichen
   Trick: max-height + Fade-Out-Mask überm letzten sichtbaren Bereich. */
.msg.user .bubble.collapsed {
  max-height: 11em;          /* ≈ 6 Textzeilen bei body line-height */
  overflow: hidden;
  position: relative;
  mask-image: linear-gradient(180deg, #000 0%, #000 80%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 80%, transparent 100%);
}
.msg.user .bubble-toggle {
  display: block;
  margin: 4px 0 0 auto;       /* rechts-bündig zur User-Bubble */
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
}
.msg.user .bubble-toggle:hover {
  text-decoration: underline;
}
.msg.assistant .content {
  width: 100%;
  color: var(--text);
  word-wrap: break-word;
}
.msg.assistant .content :first-child { margin-top: 0; }
.msg.assistant .content :last-child { margin-bottom: 0; }
.msg.assistant .content h1,
.msg.assistant .content h2,
.msg.assistant .content h3 {
  margin: 18px 0 10px;
  font-weight: 600;
}
.msg.assistant .content h1 { font-size: 22px; }
.msg.assistant .content h2 { font-size: 19px; }
.msg.assistant .content h3 { font-size: 16px; }
.msg.assistant .content p { margin: 10px 0; }
.msg.assistant .content ul,
.msg.assistant .content ol { padding-left: 22px; margin: 10px 0; }
.msg.assistant .content li { margin: 4px 0; }
.msg.assistant .content code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg.assistant .content pre {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 0 0 12px 12px;
  padding: 14px 16px;
  margin: 0;
  overflow-x: auto;
  font-size: 13.5px;
  line-height: 1.6;
}
.msg.assistant .content pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}
/* Code-Block-Wrapper (Header mit Sprache + Copy-Button) */
.codeblock {
  margin: 12px 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-soft);
}
.codeblock pre { border: 0; border-radius: 0; }
.codeblock-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border-soft);
  font-size: 12px;
  color: var(--text-muted);
}
.codeblock-lang {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  text-transform: lowercase;
}
.codeblock-copy {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  font-size: 12px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.codeblock-copy:hover { background: var(--bg-elev); color: var(--text); }
.msg.assistant .content a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 50%, transparent);
  text-underline-offset: 2px;
}
.msg.assistant .content a:hover {
  text-decoration-color: var(--accent);
}
.msg.assistant .content blockquote {
  border-left: 3px solid var(--border);
  margin: 12px 0;
  padding: 4px 0 4px 14px;
  color: var(--text-soft);
}
.msg.assistant .content table {
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}
.msg.assistant .content th,
.msg.assistant .content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
}

.msg-tools {
  display: flex; gap: 2px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg.assistant:hover .msg-tools { opacity: 1; }
.msg-tools .icon-btn { width: 30px; height: 30px; }
.msg-tools .icon-btn .icon { width: 15px; height: 15px; }
.msg-tools .icon-btn.active { color: var(--accent); }
.typing-dot {
  display: inline-block;
  width: 8px; height: 8px;
  margin: 0 2px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* Attachments im Verlauf */
.msg .attachments {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 8px;
}
.msg.user .attachments { justify-content: flex-end; margin-top: 0; margin-bottom: 4px; }
.msg .attachments img {
  max-width: 300px; max-height: 240px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
}
.msg .attachments .file-card {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
}
.msg .attachments .file-card:hover { background: var(--bg-elev-2); }

/* ----------- Composer ----------- */
.composer-wrap {
  padding: 12px 20px 18px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}
.pending-attachments {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 4px;
  margin-bottom: 8px;
}
.att-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  max-width: 260px;
}
.att-chip .att-preview {
  width: 36px; height: 36px; border-radius: 6px;
  object-fit: cover; background: var(--surface-2);
}
.att-chip .att-info { display: flex; flex-direction: column; min-width: 0; }
.att-chip .att-info .name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; max-width: 180px;
}
.att-chip .att-info .meta {
  font-size: 11px; color: var(--text-muted);
}
.att-chip .rm {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.att-chip .rm:hover { color: var(--danger); background: var(--bg-elev-2); }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.composer textarea {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
  padding: 10px 8px;
  min-height: 24px;
  max-height: 240px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
}
.composer textarea::placeholder { color: var(--text-muted); }
.composer-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: transparent;
  border: 0;
  color: var(--text-soft);
  border-radius: 50%;
  transition: background 0.12s, color 0.12s;
}
.composer-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.composer-btn.primary {
  background: var(--accent);
  color: white;
}
.composer-btn.primary:hover { background: var(--accent-hover); }
.composer-btn.primary:disabled {
  background: var(--bg-elev-2);
  color: var(--text-muted);
  cursor: not-allowed;
}
.composer-hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* ----------- Mic-Button (Voice-Input via Groq Whisper) ----------- */
/* Drei States:
 *   .mic-btn.idle       — gray icon
 *   .mic-btn.recording  — grünes Filling + zwei konzentrische Pulse-Ringe
 *   .mic-btn.busy       — Spinner während Transcribe
 * Visuell angelehnt an die WhisperTyper-Pulse + die Android-MicButton-Composable. */
.mic-btn { position: relative; overflow: visible; }
.mic-btn .mic-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  background: #22C55E;
  opacity: 0;
  pointer-events: none;
}
.mic-btn.recording {
  background: #22C55E;
  color: #fff;
}
.mic-btn.recording:hover { background: #16A34A; color: #fff; }
.mic-btn.recording .mic-pulse {
  animation: micPulse 1.4s linear infinite;
}
.mic-btn.recording .mic-pulse-2 {
  animation-delay: 0.7s;
}
@keyframes micPulse {
  0%   { transform: scale(1);   opacity: 0.55; }
  100% { transform: scale(1.7); opacity: 0;    }
}
.mic-btn.busy {
  cursor: progress;
}
.mic-btn.busy .icon { opacity: 0.25; }
.mic-btn.mic-disabled,
.mic-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.mic-btn.busy::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  margin: -8px 0 0 -8px;
  width: 16px; height: 16px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: micSpin 0.7s linear infinite;
}
@keyframes micSpin { to { transform: rotate(360deg); } }

/* ----------- Auto-Mode-Pill (sichtbar wenn der Voice-Loop läuft) ----------- */
.auto-mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 6px auto 0;
  padding: 4px 12px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  align-self: center;
}
.auto-mode-pill:hover {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}
.composer-wrap { display: flex; flex-direction: column; align-items: stretch; }

/* ----------- Image Mode ----------- */
/* aktivierter Image-Mode-Knopf bekommt Brand-Akzent — User sieht sofort:
   ah, mein Prompt geht an Gemini, nicht an Claude. */
.composer-btn.image-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}
.composer-btn.image-active:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}
.composer.image-mode {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent), var(--shadow);
}

.image-options {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.image-options-row {
  display: flex; flex-wrap: wrap; gap: 16px 24px;
  align-items: flex-start;
}
.image-options-group {
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.image-options-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.image-options select {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  min-width: 200px;
}
.chip-row {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip:hover { background: var(--bg-elev-2); color: var(--text); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.image-options-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
}
.image-options-status.error { color: var(--danger); }
.image-options-status.busy { color: var(--accent); }

/* Generierte Bilder im Chat-Stream — bisschen größer & polierter als
   normale Datei-Attachments. */
.msg .image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 8px;
  max-width: 720px;
}
.msg .image-grid figure {
  margin: 0;
  position: relative;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 1 / 1;
}
.msg .image-grid figure img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.msg .image-grid figure .img-actions {
  position: absolute; bottom: 6px; right: 6px;
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg .image-grid figure:hover .img-actions { opacity: 1; }
.msg .image-grid figure .img-actions button {
  background: rgba(0,0,0,0.65);
  color: white;
  border: 0;
  border-radius: 999px;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.msg .image-grid figure .img-actions button:hover { background: rgba(0,0,0,0.85); }
.msg .image-grid figure .img-actions .icon { width: 14px; height: 14px; }

/* Lightbox / Zoom — wenn man auf ein Bild klickt */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}
.lightbox .lb-close {
  position: absolute; top: 16px; right: 20px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 0;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255,255,255,0.3); }

/* ----------- Modals ----------- */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-card {
  width: 100%; max-width: 560px;
  max-height: 88vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-card.small { max-width: 400px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-header h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 6px;
  padding: 12px 18px;
  border-top: 1px solid var(--border-soft);
}

.settings-section { margin-bottom: 26px; }
.settings-section:last-child { margin-bottom: 0; }
.settings-section h3 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.settings-section .hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-soft);
}
.settings-section textarea {
  width: 100%;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-family: inherit;
  font-size: 14px;
  min-height: 80px;
  resize: vertical;
}
.settings-section textarea:focus { border-color: var(--accent); background: var(--surface); }
.settings-section .field { margin-top: 12px; }
.settings-section select,
.settings-section input[type="range"] {
  width: 100%;
}
.settings-section .field em {
  font-style: normal;
  font-weight: 500;
  color: var(--accent);
}

.segments {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 6px 0;
}
.segments label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.12s;
}
.segments label:has(input:checked) {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: var(--accent);
  color: var(--text);
}
.segments input[type="radio"] {
  appearance: none;
  width: 14px; height: 14px;
  border: 1.5px solid var(--text-muted);
  border-radius: 50%;
  position: relative;
  margin: 0;
}
.segments input[type="radio"]:checked {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--surface);
}

.row-gap {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 4px;
}
.backup-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-soft);
  min-height: 1em;
}
.backup-status.error { color: var(--danger); }
.backup-status.ok { color: var(--success); }

.prompt-text {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--text);
}
#prompt-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
#prompt-input:focus { border-color: var(--accent); }

/* ----------- Toast ----------- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  z-index: 200;
  animation: toast-in 0.2s ease;
}
.toast.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ----------- Scrollbars (Webkit) ----------- */
.messages::-webkit-scrollbar,
.chat-nav::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb,
.chat-nav::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-thumb:hover,
.chat-nav::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
