/* =====================================================================
   ENHANCED AI CHAT UI
   Original panel/bubble/branding/modal system, extended with:
   - Typing indicator
   - Streaming cursor (kept + refined)
   - Message reactions (thumbs up/down)
   - Regenerate / retry response
   - Edit user message
   - Scroll-to-bottom button
   - Code block styling + copy button
   - Markdown elements (lists, tables, blockquote, inline code)
   - File/image attachment chips + drag & drop overlay
   - Suggested follow-up prompt chips
   - Error / retry banner
   - Avatar online-status dot
   - Message timestamp
   - Theme toggle (dark/light)
   - Voice input button
   - Loading skeleton
   - Accessibility: focus-visible + reduced motion
   ===================================================================== */

/* ===== DESIGN TOKENS ===== */
:root {
  --chat-accent: #8ab4f8;
  --chat-accent-soft: rgba(138,180,248,.14);
  --chat-mint: #80ffe1;
  --chat-success: #00cd93;
  --chat-danger: #ff6b6b;
  --chat-warn: #ffd54f;
  --chat-bg: #0b0b0c;
  --chat-surface: rgba(255,255,255,.04);
  --chat-surface-hover: rgba(255,255,255,.08);
  --chat-border: rgba(255,255,255,.08);
  --chat-text: rgba(255,255,255,.92);
  --chat-text-dim: rgba(255,255,255,.5);
  --chat-text-faint: rgba(255,255,255,.3);
  --chat-radius: 14px;
  --chat-font: 'DM Sans', system-ui, sans-serif;
  --chat-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

/* Light theme override, toggled via .theme-light on a wrapping element */
.theme-light {
  --chat-bg: #f7f7f5;
  --chat-surface: rgba(0,0,0,.03);
  --chat-surface-hover: rgba(0,0,0,.06);
  --chat-border: rgba(0,0,0,.08);
  --chat-text: rgba(20,20,20,.92);
  --chat-text-dim: rgba(20,20,20,.55);
  --chat-text-faint: rgba(20,20,20,.35);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Consistent visible focus ring across all interactive elements */
.ai-response-panel button:focus-visible,
.ai-response-panel a:focus-visible,
.ai-response-panel [tabindex]:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ===== RESPONSE PANEL ===== */
.ai-response-panel {
  display: none;
  max-width: 550px;
  margin: 0 auto 18px;
  text-align: left;
  position: relative;
}
.ai-response-panel.visible { display: block; }

@media (min-width: 760px) {
  .ai-response-panel.visible {
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    width: 780px;
    max-width: 88vw;
  }
}

.ai-response-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 4px 4px 0;
  -ms-overflow-style: none;
  scrollbar-width: none;
  scroll-behavior: smooth;
}
.ai-response-inner > *:first-child { margin-top: auto; }
.ai-response-inner::-webkit-scrollbar { display: none; }

/* ===== CHAT TURNS ===== */
.chat-turn {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeUp .35s ease both;
}

/* User bubble */
.chat-user-row { display: flex; justify-content: flex-end; align-items: flex-start; gap: 10px; }
.chat-user-avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  overflow: hidden;
  margin-top: 2px;
  background: rgba(255,255,255,.1);
}
.chat-user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.chat-user-bubble {
  max-width: 78%;
  background: rgba(138,180,248,.1);
  border: 1px solid rgba(138,180,248,.14);
  color: rgba(255,255,255,.92);
  font-family: var(--chat-font);
  font-size: .9rem;
  line-height: 1.6;
  padding: 10px 16px;
  border-radius: 18px 18px 4px 18px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* User bubble editing state */
.chat-user-bubble.editing {
  padding: 8px;
  border-color: var(--chat-accent);
}
.chat-user-edit-textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
  background: transparent;
  border: none;
  outline: none;
  color: inherit;
  font: inherit;
  line-height: 1.6;
}
.chat-user-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.chat-user-edit-actions button {
  font-family: var(--chat-font);
  font-size: 11.5px;
  padding: 5px 12px;
  border-radius: 100px;
  cursor: pointer;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-dim);
  transition: background .2s, color .2s;
}
.chat-user-edit-actions button:hover { background: var(--chat-surface-hover); color: var(--chat-text); }
.chat-user-edit-actions .save-btn { background: var(--chat-accent-soft); border-color: rgba(138,180,248,.3); color: var(--chat-accent); }

/* Message-level hover actions (edit / copy) for user turns */
.chat-user-row { position: relative; }
.chat-user-hover-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s;
  margin-top: 4px;
}
.chat-user-row:hover .chat-user-hover-actions,
.chat-user-row:focus-within .chat-user-hover-actions { opacity: 1; }
.chat-user-hover-actions button {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-dim);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.chat-user-hover-actions button:hover { background: var(--chat-surface-hover); color: var(--chat-text); }
.chat-user-hover-actions svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }

/* Message timestamp */
.chat-timestamp {
  font-size: 10px;
  color: var(--chat-text-faint);
  margin-top: 2px;
  font-family: var(--chat-font);
  letter-spacing: .2px;
}
.chat-user-row .chat-timestamp { text-align: right; }

/* Assistant row */
.chat-assistant-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.chat-avatar {
  flex-shrink: 0;
  width: 56px; height: 56px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-top: 2px;
  position: relative;
}
.chat-avatar img {
  width: 48px; height: 48px;
  object-fit: contain;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid rgba(255,255,255,.07);
}
/* Online/active status dot on the avatar */
.chat-avatar-status {
  position: absolute;
  bottom: 0; left: 34px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--chat-success);
  border: 2px solid var(--chat-bg);
}
.chat-avatar-status.thinking {
  background: var(--chat-warn);
  animation: pulseDot 1.4s ease-in-out infinite;
}

.chat-assistant-body { flex: 1; min-width: 0; }

/* ===== RESPONSE LABEL ROW ===== */
.ai-response-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.ai-response-label {
  font-size: 10.5px;
  color: #80ffe1;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  margin: 0;
  font-family: var(--chat-font);
  font-weight: 500;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
}
.typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--chat-accent);
  opacity: .5;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }

/* ===== LOADING SKELETON (before first token arrives) ===== */
.response-skeleton { display: flex; flex-direction: column; gap: 8px; }
.response-skeleton-line {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--chat-surface) 25%, var(--chat-surface-hover) 37%, var(--chat-surface) 63%);
  background-size: 400% 100%;
  animation: skeletonShimmer 1.4s ease infinite;
}
.response-skeleton-line.w-80 { width: 80%; }
.response-skeleton-line.w-60 { width: 60%; }
.response-skeleton-line.w-95 { width: 95%; }

/* ===== RESPONSE ACTIONS (copy + speak + regenerate + reactions) ===== */
.response-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Shared small icon-button base */
.copy-btn,
.speak-btn,
.regen-btn,
.reaction-btn,
.mic-btn,
.theme-toggle-btn {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .15s, color .2s;
  color: var(--chat-text-dim);
  position: relative;
}
.copy-btn:hover, .speak-btn:hover, .regen-btn:hover, .reaction-btn:hover, .mic-btn:hover, .theme-toggle-btn:hover {
  background: var(--chat-accent-soft);
  border-color: rgba(138,180,248,.25);
  color: var(--chat-text);
}
.copy-btn:active, .speak-btn:active, .regen-btn:active, .reaction-btn:active, .mic-btn:active { transform: scale(.88); }
.copy-btn svg, .speak-btn svg, .regen-btn svg, .reaction-btn svg, .mic-btn svg, .theme-toggle-btn svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: opacity .15s;
}

/* copy button states */
.copy-icon-check { display: none; }
.copy-btn.copied {
  background: rgba(0,205,147,.12);
  border-color: rgba(0,205,147,.25);
  color: var(--chat-success);
  animation: popIn .25s ease both;
}
.copy-btn.copied .copy-icon-copy { display: none; }
.copy-btn.copied .copy-icon-check { display: block; }

/* tooltip, reused by several action buttons */
.copy-btn::after,
.regen-btn::after,
.reaction-btn::after,
.mic-btn::after,
.theme-toggle-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  background: rgba(20,20,20,.92);
  color: #fff;
  font-size: 10px;
  letter-spacing: .3px;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s;
  font-family: var(--chat-font);
  z-index: 3;
}
.copy-btn:hover::after, .regen-btn:hover::after, .reaction-btn:hover::after, .mic-btn:hover::after, .theme-toggle-btn:hover::after { opacity: 1; }

/* speak state */
.speak-btn.speaking {
  background: rgba(138,180,248,.18);
  border-color: rgba(138,180,248,.3);
  color: var(--chat-accent);
}

/* regenerate spin while working */
.regen-btn.loading svg { animation: spin .8s linear infinite; }

/* reactions */
.reaction-group { display: flex; gap: 4px; }
.reaction-btn.active.up { background: rgba(0,205,147,.14); border-color: rgba(0,205,147,.3); color: var(--chat-success); }
.reaction-btn.active.down { background: rgba(255,107,107,.14); border-color: rgba(255,107,107,.3); color: var(--chat-danger); }

/* mic / voice input */
.mic-btn.recording {
  background: rgba(255,107,107,.14);
  border-color: rgba(255,107,107,.3);
  color: var(--chat-danger);
  animation: pulseRing 1.4s ease-out infinite;
}

/* theme toggle */
.theme-toggle-btn .icon-sun { display: none; }
.theme-light .theme-toggle-btn .icon-moon { display: none; }
.theme-light .theme-toggle-btn .icon-sun { display: block; }

/* ===== RESPONSE TEXT ===== */
.ai-response-text {
  font-size: .92rem;
  line-height: 1.8;
  color: var(--chat-text-dim);
  font-family: var(--chat-font);
  white-space: pre-wrap;
}
.ai-response-text.typing::after {
  content: '▋';
  display: inline-block;
  animation: blink .7s step-end infinite;
  color: var(--chat-accent);
  margin-left: 2px;
}
.ai-response-text a {
  color: var(--chat-warn);
  text-decoration: underline;
  font-weight: 500;
  word-break: break-word;
}
.ai-response-text a:hover { opacity: .85; }

/* Markdown elements inside a response */
.ai-response-text h1, .ai-response-text h2, .ai-response-text h3 {
  color: var(--chat-text);
  font-weight: 600;
  margin: 14px 0 6px;
  line-height: 1.3;
}
.ai-response-text h1 { font-size: 1.15rem; }
.ai-response-text h2 { font-size: 1.05rem; }
.ai-response-text h3 { font-size: .98rem; }
.ai-response-text ul, .ai-response-text ol {
  margin: 6px 0 10px;
  padding-left: 22px;
}
.ai-response-text li { margin-bottom: 4px; }
.ai-response-text blockquote {
  margin: 10px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--chat-accent);
  color: var(--chat-text-dim);
  background: var(--chat-surface);
  border-radius: 0 8px 8px 0;
}
.ai-response-text code:not(pre code) {
  font-family: var(--chat-mono);
  font-size: .85em;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  padding: 1px 6px;
  border-radius: 5px;
  color: var(--chat-mint);
}
.ai-response-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: .85rem;
}
.ai-response-text th, .ai-response-text td {
  border: 1px solid var(--chat-border);
  padding: 6px 10px;
  text-align: left;
}
.ai-response-text th { background: var(--chat-surface); color: var(--chat-text); font-weight: 600; }

/* Code block with header + copy button */
.code-block-wrap {
  margin: 10px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  background: rgba(0,0,0,.35);
}
.theme-light .code-block-wrap { background: rgba(0,0,0,.04); }
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--chat-surface);
  border-bottom: 1px solid var(--chat-border);
  font-family: var(--chat-mono);
  font-size: 10.5px;
  color: var(--chat-text-dim);
  letter-spacing: .3px;
}
.code-block-copy {
  border: none;
  background: transparent;
  color: var(--chat-text-dim);
  cursor: pointer;
  font-family: var(--chat-font);
  font-size: 10.5px;
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  border-radius: 5px;
  transition: background .2s, color .2s;
}
.code-block-copy:hover { background: var(--chat-surface-hover); color: var(--chat-text); }
.code-block-copy svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }
.code-block-wrap pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--chat-mono);
  font-size: .82rem;
  line-height: 1.6;
  color: rgba(255,255,255,.85);
}
.theme-light .code-block-wrap pre { color: rgba(20,20,20,.85); }

/* ===== SUGGESTED FOLLOW-UP CHIPS ===== */
.suggested-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.suggested-prompt-chip {
  font-family: var(--chat-font);
  font-size: 12px;
  padding: 7px 14px;
  border-radius: 100px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-dim);
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s, transform .15s;
}
.suggested-prompt-chip:hover {
  background: var(--chat-accent-soft);
  border-color: rgba(138,180,248,.3);
  color: var(--chat-text);
  transform: translateY(-1px);
}

/* ===== FILE / IMAGE ATTACHMENT CHIPS ===== */
.attachment-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 6px;
  border-radius: 10px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  font-family: var(--chat-font);
  font-size: 11.5px;
  color: var(--chat-text-dim);
  max-width: 220px;
}
.attachment-chip-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--chat-accent-soft);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--chat-accent);
}
.attachment-chip-icon svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }
.attachment-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip-remove {
  border: none; background: transparent; color: var(--chat-text-faint);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; flex-shrink: 0;
}
.attachment-chip-remove:hover { color: var(--chat-danger); }

/* Drag & drop overlay for the whole panel */
.chat-dropzone-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(138,180,248,.08);
  border: 2px dashed var(--chat-accent);
  border-radius: var(--chat-radius);
  z-index: 6;
  font-family: var(--chat-font);
  color: var(--chat-accent);
  font-size: 13px;
  backdrop-filter: blur(2px);
}
.chat-dropzone-overlay.active { display: flex; }

/* ===== ERROR / RETRY BANNER ===== */
.chat-error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255,107,107,.08);
  border: 1px solid rgba(255,107,107,.2);
  color: var(--chat-danger);
  font-family: var(--chat-font);
  font-size: 12.5px;
}
.chat-error-banner svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.chat-error-banner .retry-link {
  margin-left: auto;
  background: none;
  border: 1px solid rgba(255,107,107,.35);
  color: var(--chat-danger);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: var(--chat-font);
  flex-shrink: 0;
  transition: background .2s;
}
.chat-error-banner .retry-link:hover { background: rgba(255,107,107,.12); }

/* ===== SCROLL-TO-BOTTOM BUTTON ===== */
.scroll-to-bottom-btn {
  position: absolute;
  bottom: 78px;
  right: 12px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(20,20,20,.92);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  z-index: 5;
  transition: background .2s, transform .15s;
}
.theme-light .scroll-to-bottom-btn { background: rgba(255,255,255,.95); }
.scroll-to-bottom-btn.visible { display: flex; animation: fadeUp .25s ease both; }
.scroll-to-bottom-btn:hover { transform: translateY(-2px); }
.scroll-to-bottom-btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }
.scroll-to-bottom-btn .unread-dot {
  position: absolute;
  top: -2px; right: -2px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--chat-danger);
  border: 2px solid var(--chat-bg);
}

/* ===== DISCLAIMER ===== */
.disclaimer-text {
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--chat-text-faint);
  letter-spacing: .2px;
  font-family: var(--chat-font);
  animation: fadeUp .4s ease .3s both;
}

.disclaimer-mobile {
  display: none;
}

.chat-branding .disclaimer-text {
  margin-top: 0;
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10.5px;
  padding: 0 14px;
  animation: none;
}

/* ===== AI IMAGE ===== */
.ai-response-image-wrap {
  position: relative;
  display: inline-block;
  max-width: 320px;
  margin: 10px 0 4px;
}
.ai-response-image {
  display: block;
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--chat-border);
}
.ai-response-image-download {
  position: absolute;
  bottom: 8px; right: 8px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background .15s;
}
.ai-response-image-download:hover { background: rgba(0,0,0,.85); }
.ai-response-image-download svg {
  width: 14px; height: 14px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ===== CHAT BRANDING ===== */
.chat-branding {
  display: none;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--chat-border);
  font-family: var(--chat-font);
  position: sticky;
  bottom: 0;
  background: transparent;
  z-index: 4;
}
.chat-branding.visible { display: grid; }

.chat-branding-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  justify-self: start;
}
.chat-branding-logo {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--chat-border);
}
.chat-branding-logo img { width: 100%; height: 100%; object-fit: contain; }
.chat-branding-text { font-size: 11px; color: var(--chat-text-faint); letter-spacing: .3px; }
.chat-branding-text b { color: var(--chat-text-dim); font-weight: 500; }

/* ===== NEW CHAT BUTTON ===== */
.new-chat-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: 100px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-text-dim);
  font-family: var(--chat-font);
  font-size: 11px;
  letter-spacing: .3px;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s, transform .15s;
}
.new-chat-btn:hover {
  background: var(--chat-accent-soft);
  border-color: rgba(138,180,248,.2);
  color: var(--chat-text);
}
.new-chat-btn:active { transform: scale(.94); }
.new-chat-btn svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor;
  stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}
.new-chat-btn { position: relative; }
.new-chat-btn::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: rgba(20,20,20,.95);
  color: #fff;
  font-size: 11px;
  letter-spacing: .2px;
  line-height: 1.35;
  white-space: normal;
  width: 170px;
  text-align: left;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.08);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .18s, transform .18s;
  font-family: var(--chat-font);
  z-index: 5;
}
.new-chat-btn:hover::after { opacity: 1; transform: translateY(0); }

.chat-branding-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}

/* ===== SIGN-IN MODAL ===== */
.modern-signin-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  font-family: var(--chat-font);
  backdrop-filter: blur(12px);
  animation: fadeInModal .4s ease;
}

.signin-modal-content {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: rgba(16,16,16,.95);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 24px;
  padding: 40px 28px 32px;
  box-shadow: 0 32px 80px rgba(0,0,0,.7), 0 0 0 1px rgba(255,255,255,.04) inset;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}
.signin-modal-content::-webkit-scrollbar { width: 6px; }
.signin-modal-content::-webkit-scrollbar-track { background: transparent; }
.signin-modal-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }

.signin-logo-container {
  text-align: center;
  margin-bottom: 24px;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1) .1s backwards;
}
.signin-logo-container img {
  height: 56px;
  width: auto;
  margin-bottom: 0;
  object-fit: contain;
}

.signin-heading {
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: -.3px;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1) .15s backwards;
}
.signin-subtitle {
  font-size: 13.5px;
  color: rgba(255,255,255,.5);
  text-align: center;
  margin-bottom: 28px;
  line-height: 1.6;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1) .2s backwards;
}
.signin-button-container {
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1) .25s backwards;
}
.signin-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0;
  animation: slideUp .5s cubic-bezier(0.34, 1.56, 0.64, 1) .3s backwards;
}
.signin-divider-line { flex: 1; height: 1px; background: rgba(255,255,255,.1); }
.signin-divider-text {
  color: rgba(255,255,255,.4);
  font-size: 11px;
  letter-spacing: .5px;
  font-weight: 500;
  white-space: nowrap;
  text-transform: uppercase;
}
.signin-continue-btn {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.85);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--chat-font);
  cursor: pointer;
  transition: all .25s ease;
  letter-spacing: .2px;
  min-height: 48px;
  touch-action: manipulation;
  outline: none;
}
.signin-continue-btn:hover {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.18);
  color: #fff;
}
.signin-continue-btn:active { transform: scale(.98); }
.signin-continue-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.signin-error {
  display: none;
  color: var(--chat-danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(255,107,107,.1);
  border-radius: 8px;
  border: 1px solid rgba(255,107,107,.2);
}
.signin-error.visible { display: block; animation: slideDown .2s ease; }

.signin-fallback {
  display: none;
  max-width: 100%;
  text-align: center;
  color: rgba(255,255,255,.4);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 12px;
}
.signin-fallback.visible { display: block; }

/* ===== MOBILE RESPONSIVE (chat) ===== */
@media (max-width: 759px) {
  .ai-response-panel.visible {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 0 1 auto;
  }

@media (max-width: 768px) {
  .disclaimer-desktop {
    display: none;
    }
  .disclaimer-mobile {
    display: inline;
    }
  }
  .ai-response-inner {
    flex: 0 1 auto;
    min-height: 0;
    max-height: none;
  }
  .chat-avatar { display: none; }
  .chat-user-avatar { width: 26px; height: 26px; }
  .chat-user-bubble { font-size: .79rem; }
  .ai-response-text { font-size: .81rem; }
  .ai-response-label { font-size: 9.5px; }
  .ai-response-panel { margin: 0 auto 0; }
  .disclaimer-text { font-size: 9.75px; margin-top: 8px; }
  .chat-branding .disclaimer-text { font-size: 8.5px; padding: 0 8px; margin-top: 0; }
  .chat-branding-text { display: none; }
  .new-chat-btn { font-size: 10px; padding: 6px 11px; min-height: 32px; }
  .chat-branding { flex: 0 0 auto; }
  .new-chat-btn::after, .copy-btn::after, .regen-btn::after, .reaction-btn::after, .mic-btn::after, .theme-toggle-btn::after { display: none; }
  .chat-branding { padding-bottom: env(safe-area-inset-bottom); }
  .scroll-to-bottom-btn { bottom: 66px; }
  .suggested-prompt-chip { font-size: 11.5px; padding: 6px 12px; }
}

@media (max-width: 420px) { .chat-user-bubble { max-width: 90%; } }

@media (min-width: 760px) {
  body.keyboard-open .ai-response-inner { max-height: 38vh; }
  body.chat-active .ai-response-panel.visible {
    display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
  }
  body.chat-active .ai-response-inner {
    flex: 1 1 auto; min-height: 0; max-height: none; overflow-y: auto;
  }
  body.chat-active .chat-branding { flex: 0 0 auto; }
}

/* Chat-image styles shared with main input (kept here for chat-context grouping) */
.chat-user-image {
  display: block;
  width: 200px;
  max-width: 100%;
  border-radius: 12px;
  margin-bottom: 6px;
  object-fit: cover;
}

/* ===== KEYFRAMES ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes popIn {
  0% { transform: scale(.7); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes fadeInModal { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes skeletonShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,213,79,.5); }
  50% { box-shadow: 0 0 0 4px rgba(255,213,79,0); }
}
@keyframes pulseRing {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,107,107,.4); }
  50% { box-shadow: 0 0 0 5px rgba(255,107,107,0); }
}