/* ── Chat Area ──────────────────────────────── */
#chat {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

/* ── Welcome Screen ─────────────────────────── */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  min-height: 100%;
  padding: 40px 16px 20px;
  animation: fadeUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) both;
}

#welcome-screen.hidden {
  display: none;
}

.welcome-orb {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: white;
  margin-bottom: 22px;
  box-shadow: 0 12px 35px var(--primary-glow);
  animation: floatOrb 5s ease-in-out infinite;
}

#welcome-screen h2 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--text) 30%, var(--primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

#welcome-screen p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 500px;
  margin-bottom: 36px;
}

.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 780px;
}

.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 120px;
  -webkit-tap-highlight-color: transparent;
}

.suggestion-card:hover {
  border-color: var(--primary-glow);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  background: var(--surface2);
}

.suggestion-card.hero-card {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.1), rgba(99, 102, 241, 0.1));
  border: 1px solid var(--space-cyan-glow);
}

.suggestion-card.hero-card:hover {
  box-shadow: 0 0 25px var(--space-cyan-glow), var(--shadow-lg);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.18), rgba(99, 102, 241, 0.18));
}

.sug-icon {
  font-size: 1.6rem;
  margin-bottom: 12px;
  display: block;
}

.sug-title {
  font-weight: 600;
  font-size: 0.94rem;
  margin-bottom: 4px;
  color: var(--text);
  line-height: 1.3;
}

.sug-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Messages ───────────────────────────────── */
.message {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  animation: fadeUp 0.25s cubic-bezier(0.4, 0, 0.2, 1) both;
  max-width: 100%;
}

.message.user {
  justify-content: flex-end;
}

.message.assistant {
  justify-content: flex-start;
}

.bot-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.85rem;
  flex-shrink: 0;
  align-self: flex-start;
  box-shadow: 0 4px 12px var(--primary-glow);
  margin-top: 2px;
}

.message-bubble-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(85%, 620px);
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.6;
  word-break: break-word;
  box-shadow: var(--shadow);
}

.message.user .message-bubble {
  background: var(--msg-user-bg);
  color: var(--msg-user-text);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
  background: var(--msg-bot-bg);
  color: var(--msg-bot-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Rich widget container inside assistant bubble */
.message.assistant .message-bubble-wrapper:has(.rich-widget) {
  max-width: min(96%, 680px);
  width: 100%;
}

.message.assistant .message-bubble:has(.rich-widget) {
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Response Action Toolbar */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.msg-actions:hover {
  opacity: 1;
}

.msg-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.76rem;
  padding: 4px 9px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.msg-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ── Scroll to bottom ───────────────────────── */
#scroll-btn {
  position: absolute;
  bottom: 90px;
  right: 24px;
  width: 42px;
  height: 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  font-size: 1rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
  pointer-events: none;
  z-index: 30;
}

#scroll-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#scroll-btn:hover {
  background: var(--surface2);
  border-color: var(--primary);
}

/* ── Typing Indicator ───────────────────────── */
.typing-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 8px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: boing 1.3s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.3s; }
.typing-dot:nth-child(2) { animation-delay: -0.15s; }

@keyframes boing {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ── Input Area ─────────────────────────────── */
.input-zone {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  position: relative;
  z-index: 20;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 28px;
  padding: 7px 10px 7px 18px;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 25px var(--primary-glow), 0 0 0 1px var(--primary);
}

#input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.98rem;
  color: var(--text);
  outline: none;
  line-height: 1.4;
  min-height: 40px;
}

#input::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}

#mic-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

#mic-btn:hover {
  color: var(--text);
  background: var(--surface2);
}

#mic-btn.listening {
  background: var(--error);
  color: white;
  animation: micRipple 1.4s infinite;
}

#send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  box-shadow: 0 4px 14px var(--primary-glow);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

#send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px var(--primary-glow);
}

#send-btn:active {
  transform: scale(0.92);
}

.footer-note {
  text-align: center;
  font-size: 0.73rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.footer-note a {
  color: var(--primary);
  text-decoration: none;
}

/* Responsive Grid Adjustments */
@media (max-width: 800px) {
  .suggestions-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  #chat {
    padding: 16px 12px 24px;
  }
  .suggestions-grid {
    grid-template-columns: 1fr;
  }
  .input-zone {
    padding: 8px 12px 12px;
  }
  .message-bubble-wrapper {
    max-width: 90%;
  }
  #welcome-screen h2 {
    font-size: 1.4rem;
  }
}

/* ── OCR Trigger Button ─────────────────────── */
#ocr-trigger-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  border-radius: 50%;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#ocr-trigger-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  transform: scale(1.08);
}

/* ── Slash Command Palette Autocomplete ──────── */
.slash-palette {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 20px;
  right: 20px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 100;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slash-palette.hidden {
  display: none !important;
}
.slash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}
.slash-item:hover {
  background: rgba(99, 102, 241, 0.15);
}
.slash-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}
.slash-details {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.slash-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.slash-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
}
.slash-cmd {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── Global Drag & Drop Overlay ───────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}
.drop-overlay.hidden {
  display: none !important;
}
.drop-card {
  background: var(--surface);
  border: 2px dashed var(--primary);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 20px 50px var(--primary-glow);
}
.drop-card i {
  color: var(--primary);
  margin-bottom: 16px;
}
.drop-card h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.drop-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Disambiguation Cards & Tool Chips ───────── */
.disambiguation-widget {
  border-left: 3px solid var(--primary);
}
.dis-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.dis-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.dis-chip:hover {
  background: var(--primary);
  color: white;
  transform: translateY(-1px);
}