/* ============================================================
 * chat.css — scoped styles for the chat view.
 *
 * All rules are either nested under `#chat-root` or use an
 * explicit `.chat-*` class so we don't leak into other pages.
 * Design tokens live at the top; everything below references
 * them. No `!important` — specificity wins.
 * ============================================================ */

#chat-root {
  /* ── Brand ────────────────────────────────────────────── */
  --chat-brand: #2e7d9e;
  --chat-brand-hover: #256b88;
  --chat-brand-subtle: rgba(46, 125, 158, 0.08);
  --chat-brand-focus: rgba(46, 125, 158, 0.28);

  /* ── Text ─────────────────────────────────────────────── */
  --chat-text: #0f172a;
  --chat-text-muted: #475569;
  --chat-text-dim: #64748b;
  --chat-text-faint: #94a3b8;

  /* ── Surfaces ─────────────────────────────────────────── */
  --chat-surface-page: #faf9f7;
  --chat-surface-elevated: #ffffff;
  --chat-surface-muted: #f1f5f9;

  /* ── Borders ──────────────────────────────────────────── */
  --chat-border: #e2e8f0;
  --chat-border-strong: #cbd5e1;

  /* ── Bubbles ──────────────────────────────────────────── */
  --chat-bubble-user-bg: #e0f2fe;
  --chat-bubble-user-text: #0c4a6e;
  --chat-bubble-user-border: #bae6fd;
  --chat-bubble-user-meta: #475569;

  --chat-bubble-ai-bg: #ffffff;
  --chat-bubble-ai-text: #0f172a;
  --chat-bubble-ai-border: #e2e8f0;

  --chat-bubble-system-bg: var(--chat-brand-subtle);
  --chat-bubble-system-border: var(--chat-brand-focus);
  --chat-bubble-system-text: var(--chat-text);
  --chat-bubble-system-accent: var(--chat-brand);

  /* ── Code ─────────────────────────────────────────────── */
  --chat-code-bg: #f1f5f9;
  --chat-code-text: #2e7d9e;
  --chat-code-pre-text: #334155;

  /* ── Status ───────────────────────────────────────────── */
  --chat-status-sent: #64748b;
  --chat-status-acked: #2e7d9e;
  --chat-status-failed: #dc2626;

  /* ── Radii (8/12/16 + pill) ───────────────────────────── */
  --chat-radius-sm: 8px;
  --chat-radius-md: 12px;
  --chat-radius-lg: 16px;
  --chat-radius-pill: 9999px;

  /* ── Spacing scale (4/8/12/16/24) ─────────────────────── */
  --chat-space-1: 4px;
  --chat-space-2: 8px;
  --chat-space-3: 12px;
  --chat-space-4: 16px;
  --chat-space-6: 24px;

  /* ── Tap target (WCAG) ────────────────────────────────── */
  --chat-tap-min: 44px;
}

/* ============================================================
 * LAYOUT — header, messages container, input area
 * ============================================================ */

#chat-root {
  background: var(--chat-surface-page);
  color: var(--chat-text);
}

.chat-header {
  background: color-mix(in srgb, var(--chat-surface-page) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-color: var(--chat-border);
}

.chat-header-icon {
  color: var(--chat-text-muted);
}
.chat-header-icon:hover {
  color: var(--chat-text);
}

.chat-messages-container {
  background: var(--chat-surface-page);
}
.chat-messages-container::-webkit-scrollbar { width: 6px; }
.chat-messages-container::-webkit-scrollbar-track { background: transparent; }
.chat-messages-container::-webkit-scrollbar-thumb {
  background: var(--chat-border-strong);
  border-radius: 3px;
}

.chat-input-area {
  background: color-mix(in srgb, var(--chat-surface-page) 82%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-color: var(--chat-border);
}

/* ============================================================
 * BUBBLES — user + AI, with inline meta (time + status)
 * ============================================================ */

.chat-msg {
  animation: chat-msg-in 0.2s ease-out;
}
/* Promoted bubbles (optimistic → persisted swap, streaming → persisted swap)
 * are already on screen — suppress the entrance animation so users don't
 * see a second fade-in. */
.chat-msg.chat-msg--promoted {
  animation: none;
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Message grouping — iMessage style.
 * Between different senders: 12px (a clear beat).
 * Consecutive from same sender: 4px (tight run). */
.chat-msg + .chat-msg { margin-top: 12px; }
.chat-msg[data-role="user"] + .chat-msg[data-role="user"],
.chat-msg[data-role="ai"] + .chat-msg[data-role="ai"],
.chat-msg[data-role="voice"] + .chat-msg[data-role="voice"],
.chat-msg[data-role="image"] + .chat-msg[data-role="image"] {
  margin-top: 4px;
}
/* System announcements are loud by nature — give them extra breathing room
 * before and after so they read as a beat in the conversation, not a reply. */
.chat-msg[data-role="system"],
.chat-msg + .chat-msg[data-role="system"],
.chat-msg[data-role="system"] + .chat-msg {
  margin-top: 20px;
}

/* Hide the time + ✓ meta on any bubble that is NOT the last in its
 * same-sender run. Only the final message of a run carries the meta,
 * matching iMessage. Uses :has() — all modern browsers support it. */
.chat-msg[data-role="user"]:has(+ .chat-msg[data-role="user"]) .bubble-meta,
.chat-msg[data-role="ai"]:has(+ .chat-msg[data-role="ai"]) .bubble-meta,
.chat-msg[data-role="voice"]:has(+ .chat-msg[data-role="voice"]) .bubble-meta,
.chat-msg[data-role="image"]:has(+ .chat-msg[data-role="image"]) .bubble-meta {
  display: none;
}

/* Subtly stronger acked checkmark for visibility on light bubble bg */
.bubble-meta.is-acked .status-icon {
  color: var(--chat-status-acked);
  filter: drop-shadow(0 0 0 transparent);
}

.chat-bubble {
  border-radius: var(--chat-radius-lg);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
  border: 1px solid transparent;
}

.chat-bubble-user {
  background: var(--chat-bubble-user-bg);
  color: var(--chat-bubble-user-text);
  border-color: var(--chat-bubble-user-border);
}

/* Scope pre-line to the text body so ERB-template whitespace between
 * content and .bubble-meta doesn't leak into the bubble as blank lines. */
.chat-bubble-body {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.chat-bubble-ai {
  background: var(--chat-bubble-ai-bg);
  color: var(--chat-bubble-ai-text);
  border-color: var(--chat-bubble-ai-border);
}

/* System-role bubble — release notes, gateway restart notices,
 * admin broadcasts. Rendered centered with a brand-tinted fill and
 * left accent strip. No icon — we don't audition a new mark here.
 * Uses the .chat-prose slot for markdown so bullets / bold / links /
 * code spans all render. */
.chat-bubble-system {
  position: relative;
  max-width: 85%;
  padding: 12px 16px 10px;
  background: var(--chat-bubble-system-bg);
  color: var(--chat-bubble-system-text);
  border-color: var(--chat-bubble-system-border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
/* Left accent strip — ties the card back to the brand without
 * the old toy-ish full gradient fill. */
.chat-bubble-system::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 3px;
  background: var(--chat-bubble-system-accent);
}
.chat-bubble-system__body {
  min-width: 0;
}
.chat-bubble-system .bubble-meta {
  justify-content: flex-end;
  color: var(--chat-text-dim);
  margin-top: 2px;
}

/* Inline meta (timestamp + status ✓) in the bottom-right corner.
 * Uses block + text-align: right so it always sits flush inside the
 * bubble's border — floats can escape the bubble on certain layouts. */
.bubble-meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1;
  color: var(--chat-bubble-user-meta);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chat-bubble-ai .bubble-meta {
  color: var(--chat-text-dim);
}

.bubble-meta .status-icon {
  /* Square sizing — paths are drawn centered in a 24×24 viewBox,
   * stretching to non-square distorts the check. */
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke-width: 2.5;
  color: var(--chat-status-sent);
}
.bubble-meta.is-acked .status-icon {
  color: var(--chat-status-acked);
  animation: chat-check-upgrade 0.35s ease-out;
}
.bubble-meta.is-failed {
  color: var(--chat-status-failed);
  cursor: pointer;
}
.bubble-meta.is-sending { opacity: 0.65; }
.bubble-meta.is-sending .status-icon {
  animation: chat-pulse 1.2s ease-in-out infinite;
}

@keyframes chat-check-upgrade {
  0%   { transform: scale(0.7); opacity: 0.5; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes chat-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.9; }
}

/* AI copy action — shown on hover, gives feedback on press */
.chat-bubble-ai-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.group:hover .chat-bubble-ai-actions,
.chat-bubble-ai-actions:focus-within {
  opacity: 1;
}
@media (hover: none) {
  .chat-bubble-ai-actions { opacity: 0.7; }
}
.chat-bubble-ai-actions__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: var(--chat-radius-sm);
  color: var(--chat-text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  min-width: 28px;
  min-height: 28px;
}
.chat-bubble-ai-actions__btn:hover {
  background: var(--chat-surface-muted);
  color: var(--chat-text);
}
.chat-bubble-ai-actions__btn.is-copied {
  color: var(--chat-status-acked);
}

/* ============================================================
 * PROSE — AI markdown rendering
 * ============================================================ */

.chat-prose {
  max-width: none;
  color: var(--chat-bubble-ai-text);
  --tw-prose-body: var(--chat-bubble-ai-text);
  --tw-prose-headings: var(--chat-text);
  --tw-prose-links: var(--chat-brand);
  --tw-prose-bold: var(--chat-text);
  --tw-prose-code: var(--chat-code-text);
  --tw-prose-pre-bg: var(--chat-code-bg);
  --tw-prose-pre-code: var(--chat-code-pre-text);
  --tw-prose-quotes: var(--chat-text-muted);
  --tw-prose-quote-borders: var(--chat-border-strong);
  --tw-prose-counters: var(--chat-text-dim);
  --tw-prose-bullets: var(--chat-text-faint);
  --tw-prose-hr: var(--chat-border);
}
.chat-prose > *:first-child { margin-top: 0; }
.chat-prose > *:last-child { margin-bottom: 0; }
.chat-prose p { margin: 0.75em 0; }
.chat-prose h1, .chat-prose h2, .chat-prose h3, .chat-prose h4 {
  font-weight: 600;
  margin: 1em 0 0.5em;
  color: var(--chat-text);
}
.chat-prose h1 { font-size: 1.15em; }
.chat-prose h2 { font-size: 1.1em; }
.chat-prose h3, .chat-prose h4 { font-size: 1em; }
.chat-prose strong { color: var(--chat-text); font-weight: 600; }
.chat-prose a {
  color: var(--chat-brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-prose ul, .chat-prose ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}
.chat-prose ul { list-style-type: disc; }
.chat-prose ol { list-style-type: decimal; }
.chat-prose li { margin: 0.2em 0; }
.chat-prose blockquote {
  border-left: 3px solid var(--chat-border-strong);
  padding-left: 0.75em;
  margin: 0.6em 0;
  color: var(--chat-text-muted);
}
.chat-prose hr {
  border: none;
  border-top: 1px solid var(--chat-border);
  margin: 0.75em 0;
}
.chat-prose code:not(pre code) {
  color: var(--chat-code-text);
  background: var(--chat-code-bg);
  padding: 0.15em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chat-prose pre {
  background: var(--chat-code-bg);
  color: var(--chat-code-pre-text);
  padding: 12px 14px;
  border-radius: var(--chat-radius-sm);
  margin: 0.75em 0;
  overflow-x: auto;
  font-size: 0.85em;
  line-height: 1.5;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
.chat-prose pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.chat-prose img {
  max-width: 100%;
  max-height: 240px;
  border-radius: var(--chat-radius-sm);
  cursor: zoom-in;
  margin: 0.4em 0;
}
.chat-prose table {
  border-collapse: collapse;
  margin: 0.6em 0;
}
.chat-prose th, .chat-prose td {
  border: 1px solid var(--chat-border);
  padding: 0.35em 0.6em;
  text-align: left;
}
.chat-prose li > input[type="checkbox"] {
  accent-color: var(--chat-brand);
  margin-right: 4px;
}

/* ============================================================
 * FILE CARDS + IMAGE GRID (in-bubble attachments)
 * ============================================================ */

.chat-file-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--chat-radius-sm);
  margin-top: 6px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface-elevated);
  color: inherit;
  text-decoration: none;
  max-width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.chat-file-card:hover {
  background: var(--chat-brand-subtle);
  border-color: var(--chat-brand);
}
.chat-file-card .file-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--chat-brand);
}
.chat-file-card .file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--chat-text);
}

.chat-image-grid {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}
.chat-image-grid.single { grid-template-columns: 1fr; max-width: 280px; }
.chat-image-grid.multi { grid-template-columns: repeat(2, 1fr); max-width: 320px; }
.chat-image-grid img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: var(--chat-radius-sm);
  cursor: zoom-in;
}

/* ============================================================
 * VOICE PLAYER
 * ============================================================ */

.voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}
.voice-play-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--chat-radius-pill);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-brand-subtle);
  color: var(--chat-brand);
  transition: background 0.15s;
  flex-shrink: 0;
}
.voice-play-btn:hover { background: rgba(46, 125, 158, 0.16); }
.voice-play-btn.is-playing { background: rgba(46, 125, 158, 0.22); }
.voice-play-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--chat-brand-focus);
}

.voice-waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 80px;
  height: 24px;
}
.voice-bar {
  width: 3px;
  /* Inline style from the server (real amplitude) can override.
   * Fallback for AI/TTS messages without a stored waveform. */
  height: 10px;
  border-radius: 2px;
  background: var(--chat-brand);
  opacity: 0.35;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.voice-bar.is-active { opacity: 1; }

.voice-time {
  font-size: 12px;
  color: var(--chat-text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 2.5rem;
  text-align: right;
}

.voice-caption {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0.85;
}

/* ============================================================
 * INPUT + ICON BUTTONS
 * ============================================================ */

.chat-input {
  background: var(--chat-surface-elevated);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-radius: var(--chat-radius-lg);
  padding: 10px 16px;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  max-height: 256px;
  width: 100%;
  min-width: 0;
  flex: 1;
}
@media (min-width: 640px) {
  .chat-input { font-size: 14px; }
}
.chat-input:focus {
  outline: none;
  border-color: var(--chat-brand);
  box-shadow: 0 0 0 3px var(--chat-brand-focus);
}
.chat-input::placeholder {
  color: var(--chat-text-faint);
}

/* Unified icon button used for attach, mic, send, cancel, menu */
.chat-icon-btn {
  width: var(--chat-tap-min);
  height: var(--chat-tap-min);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--chat-radius-pill);
  background: var(--chat-surface-muted);
  color: var(--chat-text-muted);
  transition: background 0.15s, color 0.15s, transform 0.1s;
  cursor: pointer;
  border: none;
}
.chat-icon-btn:hover {
  background: var(--chat-border);
  color: var(--chat-text);
}
.chat-icon-btn:active { transform: scale(0.96); }
.chat-icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--chat-brand-focus);
}
.chat-icon-btn-primary {
  background: var(--chat-brand);
  color: #ffffff;
}
.chat-icon-btn-primary:hover {
  background: var(--chat-brand-hover);
  color: #ffffff;
}
.chat-icon-btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--chat-brand);
}

/* ─── Send-slot — mic/send toggle (right of textarea)
 *
 * iMessage / WhatsApp / Telegram / ChatGPT pattern: the right-hand slot
 * holds a mic by default (tap to record a voice message) and swaps to
 * send when the user has something to send (text or attachments).
 *
 * We keep BOTH elements in the DOM and toggle via a class on the form —
 * avoids focus loss on the textarea while typing, and avoids layout
 * shift during the swap. */
.chat-send-slot--send { display: none; }
#chat-form.has-content .chat-send-slot--mic { display: none; }
#chat-form.has-content .chat-send-slot--send { display: inline-flex; }

/* Smooth cross-fade on the swap */
.chat-send-slot { transition: opacity 0.12s, transform 0.12s; }

/* ============================================================
 * ATTACHMENT PREVIEWS (in input bar, pre-send)
 * ============================================================ */

/* `hidden` utility must win — so no `display: flex` here. Use an
 * inner wrapper or the :not(.hidden) guard for layout. */
.attachment-previews:not(.hidden) {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: none;
}
.attachment-previews::-webkit-scrollbar { display: none; }

.attachment-preview {
  position: relative;
  height: 64px;
  border-radius: var(--chat-radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface-elevated);
}
.attachment-preview.is-image { width: 64px; }
.attachment-preview.is-file {
  width: 180px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attachment-preview .attachment-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--chat-brand);
}
.attachment-preview .attachment-name {
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--chat-text);
}
.attachment-preview .attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: var(--chat-radius-pill);
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
}
.attachment-preview:hover .attachment-remove {
  opacity: 1;
  background: rgba(0, 0, 0, 0.75);
}

/* ============================================================
 * TYPING DOTS (header + anywhere we need them)
 * ============================================================ */

.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.typing-dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  background: var(--chat-brand);
  border-radius: 50%;
  animation: chat-blink 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-blink {
  0%, 20% { opacity: 1; }
  50%     { opacity: 0.3; }
  100%    { opacity: 1; }
}

/* ============================================================
 * RECORDING / TRANSCRIBING STATES
 * ============================================================ */

.recording-pulse {
  animation: recording-pulse 1.2s ease-in-out infinite;
}
@keyframes recording-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}
.chat-recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  flex-shrink: 0;
}

/* Recording pill — shape-identical to the textarea so the swap
 * form ↔ recording-state ↔ transcribing-state has no layout jump.
 * Same radius, same height, same border, same background. */
.chat-recording-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 16px;
  background: var(--chat-surface-elevated);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-lg);
}
.chat-recording-pill canvas {
  height: 24px;
  min-width: 0;
  flex: 1;
}

/* ============================================================
 * SCROLL-TO-BOTTOM FAB
 * ============================================================ */

.chat-scroll-fab {
  background: var(--chat-surface-elevated);
  border: 1px solid var(--chat-border);
  color: var(--chat-text-muted);
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.chat-scroll-fab:hover {
  background: var(--chat-brand);
  color: #ffffff;
  border-color: var(--chat-brand);
  transform: translateY(-1px);
}

/* ============================================================
 * CONNECTION BANNER
 * ============================================================ */

/* Banner: use an inner row for flex so the outer element's display
 * stays `block` and Tailwind's `.hidden` utility can toggle it off. */
.chat-connection-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  text-align: center;
}
.chat-connection-banner > * {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  vertical-align: middle;
}
.chat-connection-banner.is-error {
  background: #fee2e2;
  border-bottom-color: #fca5a5;
  color: #7f1d1d;
}
.chat-connection-banner svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  vertical-align: -3px;
}

/* ============================================================
 * HEADER TITLE — instance name ↔ thinking indicator swap
 * ============================================================ */

/* Subtitle and thinking indicator share the same row slot, so the
 * header height is stable whether the AI is working or idle. */
.chat-header-typing { display: none; }
.chat-header-typing.is-visible,
.chat-header-typing:not(.hidden) { display: flex; }
.chat-header-title:has(.chat-header-typing:not(.hidden)) .chat-header-subtitle { display: none; }

/* ============================================================
 * EMPTY STATE
 * ============================================================ */

/* When any message renders in the scroll container, the empty state
 * gets out of the way automatically — no JS needed. */
#chat-messages:has([data-role]) .chat-empty-state { display: none; }

.chat-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 24px 32px;
  gap: 14px;
}
.chat-empty-state__logo {
  font-size: 56px;
  line-height: 1;
  opacity: 0.95;
  filter: drop-shadow(0 4px 14px rgba(46, 125, 158, 0.12));
}
.chat-empty-state__title {
  font-size: 20px;
  font-weight: 600;
  color: var(--chat-text);
  text-align: center;
  margin: 0;
}
.chat-empty-state__subtitle {
  font-size: 14px;
  color: var(--chat-text-muted);
  text-align: center;
  max-width: 340px;
  margin: 0;
}
.chat-empty-state__prompts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  max-width: 380px;
}
.chat-empty-state__prompt {
  padding: 12px 16px;
  border-radius: var(--chat-radius-md);
  background: var(--chat-surface-elevated);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  cursor: pointer;
  width: 100%;
}
.chat-empty-state__prompt:hover {
  background: var(--chat-surface-muted);
  border-color: var(--chat-border-strong);
  transform: translateY(-1px);
}
.chat-empty-state__prompt:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--chat-brand-focus);
}

/* ============================================================
 * MENU DROPDOWN
 * ============================================================ */

.chat-menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  width: 208px;
  background: var(--chat-surface-elevated);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-md);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  padding: 4px;
  overflow: hidden;
  z-index: 50;
}
.chat-menu-divider {
  height: 1px;
  background: var(--chat-border);
  margin: 4px 0;
}
.chat-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  min-height: var(--chat-tap-min);
  font-size: 14px;
  color: var(--chat-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--chat-radius-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}
.chat-menu-item:hover {
  background: var(--chat-surface-muted);
  color: var(--chat-text);
}
.chat-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.chat-menu-item.is-destructive { color: #dc2626; }
.chat-menu-item.is-destructive:hover {
  background: #fef2f2;
  color: #991b1b;
}

/* ============================================================
 * LIGHTBOX
 * ============================================================ */

.chat-lightbox {
  animation: chat-fade-in 0.2s ease-out;
}
@keyframes chat-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ============================================================
 * REDUCED MOTION — respect the user's preference
 * ============================================================ */

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