:root {
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Outfit', var(--font-primary);
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-2xl: 32px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.14);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.20);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --transition-fast: 120ms var(--ease-out);
  --transition-normal: 220ms var(--ease-out);
  --transition-slow: 380ms var(--ease-out);

  --sidebar-width: 272px;
  --header-height: 60px;
  --chat-max-width: 760px;
}

/* ═══════════════════════════════ DARK THEME ══════════════════════════════════ */
[data-theme="dark"] {
  --bg-base:       #070910;
  --bg-primary:    #0C0E1C;
  --bg-secondary:  #10122A;
  --bg-tertiary:   #151834;
  --bg-elevated:   #1A1D3E;
  --bg-hover:      rgba(112,114,255,0.07);
  --bg-active:     rgba(112,114,255,0.12);

  --surface-glass:        rgba(12,14,28,0.82);
  --surface-glass-strong: rgba(20,22,48,0.92);
  --surface-glass-border: rgba(255,255,255,0.055);

  --text-primary:   #EAECff;
  --text-secondary: #8890C8;
  --text-tertiary:  #4E5490;
  --text-inverse:   #070910;

  --accent-primary:   #7072FF;
  --accent-secondary: #9D6FFF;
  --accent-gradient:  linear-gradient(135deg, #7072FF 0%, #9D6FFF 100%);
  --accent-glow:      0 0 32px rgba(112,114,255,0.22);

  --user-bubble-bg:    rgba(112,114,255,0.14);
  --user-bubble-border:rgba(112,114,255,0.28);

  --border-subtle: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.12);

  --success:  #34D399;
  --warning:  #FBBF24;
  --error:    #F87171;
  --info:     #60A5FA;

  --pubmed-color:    #3B82F6;
  --wiki-color:      #10B981;
  --web-color:       #8B5CF6;
}

/* ═══════════════════════════════ LIGHT THEME ═════════════════════════════════ */
[data-theme="light"] {
  --bg-base:       #F5F6FA;
  --bg-primary:    #FFFFFF;
  --bg-secondary:  #F0F1F8;
  --bg-tertiary:   #E8EAF4;
  --bg-elevated:   #FFFFFF;
  --bg-hover:      rgba(99,102,241,0.06);
  --bg-active:     rgba(99,102,241,0.10);

  --surface-glass:        rgba(255,255,255,0.85);
  --surface-glass-strong: rgba(248,249,255,0.94);
  --surface-glass-border: rgba(0,0,0,0.06);

  --text-primary:   #1A1B3A;
  --text-secondary: #5C5F8A;
  --text-tertiary:  #9295BC;
  --text-inverse:   #FFFFFF;

  --accent-primary:   #5B5EFC;
  --accent-secondary: #8B5CF6;
  --accent-gradient:  linear-gradient(135deg, #5B5EFC 0%, #8B5CF6 100%);
  --accent-glow:      0 0 28px rgba(91,94,252,0.18);

  --user-bubble-bg:    rgba(91,94,252,0.10);
  --user-bubble-border:rgba(91,94,252,0.22);

  --border-subtle: rgba(0,0,0,0.07);
  --border-strong: rgba(0,0,0,0.14);

  --success:  #10B981;
  --warning:  #F59E0B;
  --error:    #EF4444;
  --info:     #3B82F6;

  --pubmed-color:    #2563EB;
  --wiki-color:      #059669;
  --web-color:       #7C3AED;
}

/* ═══════════════════════════════ RESET & BASE ════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-primary);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* Background orbs */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(120px);
  opacity: 0.35;
}
.bg-orb-1 {
  width: 600px; height: 600px;
  top: -200px; left: -200px;
  background: radial-gradient(circle, rgba(112,114,255,0.35) 0%, transparent 70%);
}
.bg-orb-2 {
  width: 500px; height: 500px;
  bottom: -150px; right: -150px;
  background: radial-gradient(circle, rgba(157,111,255,0.28) 0%, transparent 70%);
}
[data-theme="light"] .bg-orb { opacity: 0.18; }

/* ═══════════════════════════════ LAYOUT ══════════════════════════════════════ */
#app {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ═══════════════════════════════ SIDEBAR ═════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-glass);
  border-right: 1px solid var(--border-subtle);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: width var(--transition-normal), transform var(--transition-normal);
  flex-shrink: 0;
  z-index: 20;
  overflow: hidden;
}
.sidebar.collapsed {
  width: 0;
  border-right-color: transparent;
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(0);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.collapsed {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 16px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  box-shadow: var(--accent-glow);
  flex-shrink: 0;
}
.logo-icon svg { color: white; }
.logo-text {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.sidebar-conversations::-webkit-scrollbar { width: 4px; }
.sidebar-conversations::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 10px 8px 6px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: 42px;
}
.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active {
  background: var(--bg-active);
  border: 1px solid rgba(112,114,255,0.18);
}
.conv-title {
  flex: 1;
  font-size: 13.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-item.active .conv-title { color: var(--text-primary); }
.conv-delete {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
}
.conversation-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover {
  background: rgba(248,113,113,0.12);
  color: var(--error);
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}
.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13.5px;
  font-family: var(--font-primary);
  transition: all var(--transition-fast);
  text-align: left;
}
.sidebar-footer-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.crisis-btn:hover { color: var(--error) !important; background: rgba(248,113,113,0.08) !important; }

/* ═══════════════════════════════ MAIN ════════════════════════════════════════ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════ HEADER ══════════════════════════════════════ */
.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface-glass);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 10;
}

.header-left, .header-right { display: flex; align-items: center; gap: 6px; width: 140px; }
.header-right { justify-content: flex-end; }
.header-center { display: flex; align-items: center; justify-content: center; flex: 1; }

.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.header-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px currentColor;
  transition: background var(--transition-normal);
  flex-shrink: 0;
}
.status-dot.thinking {
  background: var(--accent-primary);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
.status-dot.searching {
  background: var(--info);
  animation: pulse-dot 0.9s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.25); }
}

/* ═══════════════════════════════ WELCOME SCREEN ══════════════════════════════ */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  overflow-y: auto;
}
.welcome-content {
  max-width: 600px;
  width: 100%;
  text-align: center;
  animation: welcome-in 0.5s var(--ease-out);
}

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome-logo-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
}
.welcome-logo-core {
  display: flex; align-items: center; justify-content: center;
  width: 80px; height: 80px;
  background: var(--accent-gradient);
  border-radius: 22px;
  box-shadow: var(--accent-glow), 0 8px 40px rgba(112,114,255,0.3);
  position: relative;
  z-index: 2;
}
.welcome-logo-core svg { color: white; }
.welcome-pulse-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--accent-primary);
  opacity: 0.2;
  animation: ping 2.4s cubic-bezier(0, 0, 0.2, 1) infinite;
  width: 100px; height: 100px;
}
.welcome-pulse-ring-2 {
  width: 130px; height: 130px;
  animation-delay: 0.6s;
}
@keyframes ping {
  0% { transform: scale(0.8); opacity: 0.35; }
  100% { transform: scale(1.4); opacity: 0; }
}

.welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 20px;
  letter-spacing: 0.3px;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

.welcome-title {
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  margin-bottom: 14px;
  line-height: 1.2;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto 36px;
  line-height: 1.65;
}

.welcome-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  text-align: left;
}
@media (max-width: 520px) {
  .welcome-prompts { grid-template-columns: 1fr; }
}

.prompt-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-normal);
  text-align: left;
  font-family: var(--font-primary);
  color: inherit;
}
.prompt-card:hover {
  background: var(--bg-elevated);
  border-color: rgba(112,114,255,0.3);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.prompt-icon-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  flex-shrink: 0;
  font-size: 18px;
}
.prompt-text { flex: 1; min-width: 0; }
.prompt-label { display: block; font-size: 13.5px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.prompt-desc { display: block; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prompt-arrow { color: var(--text-tertiary); flex-shrink: 0; opacity: 0; transition: opacity var(--transition-fast); }
.prompt-card:hover .prompt-arrow { opacity: 1; color: var(--accent-primary); }

/* ═══════════════════════════════ CHAT MESSAGES ═══════════════════════════════ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  padding: 0 0 8px;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.messages-container {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ═══════════════════════════════ MESSAGES ════════════════════════════════════ */
.message {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 6px 0;
  animation: msg-in 0.3s var(--ease-out);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
  letter-spacing: 0.5px;
}

.message.user { flex-direction: row-reverse; }
.message.user .message-avatar {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 2px 8px rgba(112,114,255,0.3);
}
.message.assistant .message-avatar {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--accent-primary);
}

.message-body { max-width: calc(100% - 50px); min-width: 0; }
.message.user .message-body { align-items: flex-end; display: flex; flex-direction: column; }

.message-content {
  display: inline-block;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 14.5px;
  max-width: 100%;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--user-bubble-bg);
  border: 1px solid var(--user-bubble-border);
  border-bottom-right-radius: var(--radius-xs);
  color: var(--text-primary);
}
.message.assistant .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-xs);
  color: var(--text-primary);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 0;
}
.message.user .message-meta { justify-content: flex-end; }
.message-time {
  font-size: 11px;
  color: var(--text-tertiary);
}

/* Markdown rendering */
.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { font-weight: 600; color: var(--text-primary); }
.message-content em { font-style: italic; }
.message-content h1,.message-content h2,.message-content h3 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 12px 0 6px;
  color: var(--text-primary);
  line-height: 1.35;
}
.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 14.5px; }
.message-content ul,.message-content ol {
  padding-left: 20px;
  margin: 6px 0;
}
.message-content li { margin-bottom: 4px; }
.message-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-secondary);
}
.message-content pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  overflow-x: auto;
  margin: 10px 0;
}
.message-content pre code { background: none; padding: 0; font-size: 13px; color: var(--text-primary); }
.message-content blockquote {
  border-left: 3px solid var(--accent-primary);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-secondary);
  font-style: italic;
}
.message-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 12px 0;
}

/* ═══════════════════════════════ SEARCH SOURCES ══════════════════════════════ */
.search-sources {
  margin-top: 12px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}
.search-sources-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}
.search-sources-label svg { color: var(--info); flex-shrink: 0; }
.sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.source-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: all var(--transition-fast);
  overflow: hidden;
}
.source-chip:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  transform: translateX(2px);
}
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  flex-shrink: 0;
  text-transform: uppercase;
}
.source-badge.pubmed {
  background: rgba(59,130,246,0.12);
  color: var(--pubmed-color);
  border: 1px solid rgba(59,130,246,0.2);
}
.source-badge.wikipedia {
  background: rgba(16,185,129,0.12);
  color: var(--wiki-color);
  border: 1px solid rgba(16,185,129,0.2);
}
.source-title {
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.source-chip:hover .source-title { color: var(--text-primary); }

/* Search indicator while loading */
.search-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(96,165,250,0.08);
  border: 1px solid rgba(96,165,250,0.18);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--info);
  margin-bottom: 12px;
  animation: msg-in 0.2s var(--ease-out);
}
.search-indicator svg { animation: spin 1.5s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════ FEEDBACK / ACTIONS ══════════════════════════ */
.message-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px 2px;
  flex-wrap: wrap;
}
.feedback-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-primary);
  transition: all var(--transition-fast);
}
.feedback-btn:hover { background: var(--bg-hover); color: var(--text-secondary); border-color: var(--border-strong); }
.feedback-btn.active { background: var(--bg-active); color: var(--accent-primary); border-color: var(--accent-primary); }
.retry-btn { color: var(--text-secondary); }
.retry-btn:hover { color: var(--accent-primary); }

/* ═══════════════════════════════ REQUEST ERROR ═══════════════════════════════ */
.request-error {
  background: rgba(248,113,113,0.08);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: msg-in 0.3s var(--ease-out);
}
.request-error-copy strong { display: block; font-size: 14px; color: var(--error); margin-bottom: 4px; }
.request-error-copy span { font-size: 13px; color: var(--text-secondary); }

/* ═══════════════════════════════ SAFETY BANNER ═══════════════════════════════ */
.safety-banner {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(251,191,36,0.08);
  border: 1px solid rgba(251,191,36,0.2);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--warning);
  line-height: 1.5;
}
.safety-banner a { color: inherit; font-weight: 600; }

/* ═══════════════════════════════ TYPING INDICATOR ════════════════════════════ */
.typing-indicator {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 6px 0;
  animation: msg-in 0.2s var(--ease-out);
}
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-xs);
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ═══════════════════════════════ SESSION DIVIDER ════════════════════════════ */
.session-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  color: var(--text-tertiary);
  font-size: 12px;
}
.session-divider::before, .session-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ═══════════════════════════════ COMPOSER ═══════════════════════════════════ */
.composer-area {
  padding: 12px 20px 16px;
  flex-shrink: 0;
  background: transparent;
}

.composer {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  overflow: hidden;
}
.composer:focus-within {
  border-color: rgba(112,114,255,0.4);
  box-shadow: 0 0 0 3px rgba(112,114,255,0.08), var(--shadow-md);
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px 12px 18px;
}

.message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  scrollbar-width: thin;
}
.message-input::placeholder { color: var(--text-tertiary); }

.send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-gradient);
  color: white;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(112,114,255,0.25);
}
.send-btn:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 4px 14px rgba(112,114,255,0.4);
}
.send-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: default;
  box-shadow: none;
}

.composer-footer {
  padding: 0 18px 10px;
}
.composer-note {
  font-size: 11.5px;
  color: var(--text-tertiary);
  line-height: 1.5;
}
.composer-note a { color: var(--text-tertiary); text-decoration: underline; }
.composer-note a:hover { color: var(--accent-primary); }

/* ═══════════════════════════════ MODALS ══════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7,9,16,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: overlay-in 0.2s var(--ease-out);
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: var(--shadow-xl);
  animation: panel-in 0.28s var(--ease-spring);
}
@keyframes panel-in {
  from { opacity: 0; transform: scale(0.93) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.settings-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  width: 100%;
  max-width: 520px;
  position: relative;
  box-shadow: var(--shadow-xl);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  animation: panel-in 0.28s var(--ease-spring);
}

.modal-close, .crisis-close {
  position: absolute;
  top: 16px; right: 16px;
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
}
.modal-close:hover, .crisis-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.25;
}
.modal-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.55;
}

/* Mood modal */
.mood-options {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.mood-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 12px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-subtle);
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-width: 70px;
  font-family: var(--font-primary);
}
.mood-option:hover, .mood-option.selected {
  border-color: var(--accent-primary);
  background: var(--bg-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.mood-emoji { font-size: 28px; }
.mood-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); }

/* Crisis modal */
.crisis-header-icon { font-size: 36px; margin-bottom: 14px; }
.crisis-resources { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.crisis-resource {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  transition: all var(--transition-fast);
}
.crisis-resource:hover { background: var(--bg-elevated); border-color: var(--border-strong); transform: translateX(3px); }
.crisis-resource.emergency:hover { border-color: rgba(248,113,113,0.4); background: rgba(248,113,113,0.06); }
.resource-icon { font-size: 24px; flex-shrink: 0; }
.resource-info { display: flex; flex-direction: column; }
.resource-info strong { font-size: 14px; color: var(--text-primary); margin-bottom: 2px; }
.resource-info span { font-size: 12.5px; color: var(--text-secondary); }
.crisis-footer-note { font-size: 12.5px; color: var(--text-tertiary); text-align: center; line-height: 1.5; }

/* Settings modal */
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 0;
  flex-shrink: 0;
}
.settings-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
.settings-body {
  padding: 20px 28px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: thin;
}

.settings-section {}
.settings-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}
.settings-section-header svg { color: var(--accent-primary); flex-shrink: 0; }
.settings-section-header h3 { font-size: 14px; font-weight: 600; color: var(--text-primary); }

.settings-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.settings-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 14px;
  line-height: 1.55;
}
.settings-card-desc code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-elevated);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent-secondary);
}

.runtime-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.runtime-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.runtime-label { font-size: 11px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.4px; }
.runtime-value { font-size: 13px; color: var(--text-secondary); }
.runtime-mono { font-family: var(--font-mono); font-size: 12px; }

.api-key-display { margin-bottom: 12px; }
.api-key-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 12px;
}
.api-key-value {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.api-key-copy {
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: var(--radius-xs);
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.api-key-copy:hover { color: var(--accent-primary); background: var(--bg-hover); }

.api-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}
.pref-divider { height: 1px; background: var(--border-subtle); margin: 8px 0; }
.pref-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.pref-name { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }
.pref-desc { font-size: 12px; color: var(--text-secondary); }
.pref-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 13px;
  padding: 5px 8px;
  width: 110px;
  transition: border-color var(--transition-fast);
  outline: none;
  flex-shrink: 0;
}
.pref-input:focus { border-color: var(--accent-primary); }

.memory-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 14px;
  justify-content: center;
}
.memory-stat { text-align: center; }
.memory-stat-value { display: block; font-size: 24px; font-weight: 700; color: var(--accent-primary); line-height: 1; }
.memory-stat-label { font-size: 11.5px; color: var(--text-tertiary); margin-top: 4px; display: block; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-gradient);
  color: white;
  font-size: 13.5px;
  font-weight: 600;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: 0 2px 8px rgba(112,114,255,0.2);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(112,114,255,0.35); }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: rgba(248,113,113,0.12) !important; color: var(--error) !important; border-color: rgba(248,113,113,0.25) !important; }
.btn-danger:hover { background: rgba(248,113,113,0.2) !important; }
.btn-danger-ghost { color: var(--error); border-color: rgba(248,113,113,0.2); }
.btn-danger-ghost:hover { background: rgba(248,113,113,0.08); }

/* ═══════════════════════════════ RESPONSIVE ══════════════════════════════════ */
@media (max-width: 768px) {
  .messages-container { padding: 16px 12px; }
  .chat-header { padding: 0 12px; }
  .composer-area { padding: 8px 12px 14px; }
  .welcome-content { padding: 0 4px; }
  .modal-panel, .settings-panel { border-radius: var(--radius-xl); }
  .settings-body { padding: 16px 20px 24px; }
  .settings-header { padding: 20px 20px 0; }
}
