@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-glass: rgba(22, 22, 40, 0.7);
  --bg-glass-hover: rgba(30, 30, 55, 0.8);
  --border-color: rgba(255, 255, 255, 0.06);
  --border-active: rgba(99, 102, 241, 0.4);
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
  --green: #22c55e;
  --red: #ef4444;
  --user-bubble: rgba(99, 102, 241, 0.12);
  --ai-bubble: rgba(255, 255, 255, 0.03);
  --scrollbar-thumb: rgba(255, 255, 255, 0.08);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-lg: 16px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ===== Auth Page ===== */
#auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-primary);
  position: relative;
  overflow: hidden;
}

#auth-page::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(99,102,241,0.08) 0%, transparent 70%);
  top: 20%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.auth-container {
  width: 400px;
  padding: 48px 40px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-container h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-container .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 36px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group input::placeholder { color: var(--text-muted); }

.btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 20px rgba(99,102,241,0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 30px rgba(99,102,241,0.4);
}

.btn-primary:active { transform: translateY(0); }

.auth-toggle {
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-toggle a {
  color: var(--accent-light);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.auth-toggle a:hover { text-decoration: underline; }

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
  display: none;
}

/* ===== Main Chat Layout ===== */
#chat-page {
  display: none;
  height: 100vh;
}

#chat-page.active { display: flex; }
#auth-page.hidden { display: none; }

/* ===== Sidebar ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: var(--transition);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header .logo {
  font-size: 18px;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 16px;
}

.new-chat-btn {
  width: 100%;
  padding: 11px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.12);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.new-chat-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-light);
}

.new-chat-btn .icon { font-size: 18px; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  transition: var(--transition);
  position: relative;
  group: true;
}

.session-item:hover {
  background: rgba(255,255,255,0.04);
}

.session-item.active {
  background: var(--accent-glow);
  border: 1px solid var(--border-active);
}

.session-item .session-title {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item.active .session-title { color: var(--text-primary); }

.session-item .session-actions {
  display: none;
  gap: 4px;
}

.session-item:hover .session-actions { display: flex; }

.session-action-btn {
  width: 28px; height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: var(--transition);
}

.session-action-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
}

.session-action-btn.delete:hover {
  background: rgba(239,68,68,0.15);
  color: var(--red);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

.user-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-footer-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
  gap: 8px;
  width: 100%;
}

.logout-btn {
  width: 100%;
  height: 36px;
  padding: 0;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  border-radius: 8px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.logout-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.14);
}

#visual-btn:hover,
#settings-btn:hover,
#change-pw-btn:hover,
#admin-btn:hover {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-color: var(--border-active);
}

#logout-btn:hover {
  background: rgba(239,68,68,0.1);
  color: var(--red);
  border-color: rgba(239,68,68,0.22);
}

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-primary);
  position: relative;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(12px);
  min-height: 60px;
}

.chat-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
}

/* ===== Messages ===== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 0;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.message-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: var(--accent-glow);
  color: var(--accent-light);
}

.message.assistant .message-avatar {
  background: rgba(34, 197, 94, 0.12);
  color: var(--green);
}

.message-sender {
  font-size: 13px;
  font-weight: 600;
}

.message.user .message-sender { color: var(--accent-light); }
.message.assistant .message-sender { color: var(--green); }

.message-content {
  padding-left: 40px;
  line-height: 1.75;
  font-size: 14.5px;
  color: var(--text-primary);
}

.message-content p { margin-bottom: 12px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.6;
}

.message-content code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
}

.message-content :not(pre) > code {
  background: var(--bg-tertiary);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 12.5px;
}

.message-content ul, .message-content ol {
  padding-left: 24px;
  margin: 8px 0;
}

.message-content li { margin-bottom: 4px; }

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  color: var(--text-secondary);
  margin: 12px 0;
}

.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

.message-content th, .message-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
}

.message-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* ===== Welcome Screen ===== */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 16px;
}

.welcome-screen .welcome-icon {
  font-size: 64px;
  opacity: 0.3;
}

.welcome-screen h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-secondary);
}

.welcome-screen p {
  font-size: 14px;
  max-width: 400px;
  text-align: center;
  line-height: 1.6;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
  display: none;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 0;
}

.typing-indicator.active { display: block; }

.typing-dots {
  display: flex;
  gap: 5px;
  padding-left: 40px;
}

.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ===== Input Area ===== */
.input-area {
  padding: 16px 24px 24px;
  background: linear-gradient(to top, var(--bg-primary) 60%, transparent);
}

.mode-toolbar {
  max-width: 780px;
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-toolbar-side {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switch {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-color);
  border-radius: 999px;
}

.mode-switch-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.mode-switch-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.05);
}

.mode-switch-btn.active {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 18px rgba(99,102,241,0.22);
}

.mode-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.mode-meta-label {
  color: var(--text-muted);
}

.mode-meta-value {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(99,102,241,0.25);
  background: rgba(99,102,241,0.08);
  color: var(--text-primary);
  font-weight: 600;
}

.chat-reasoning-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.chat-model-mode-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.chat-model-mode-label {
  color: var(--text-muted);
}

.chat-model-mode-select {
  min-width: 96px;
  padding: 7px 28px 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(129, 140, 248, 0.42);
  background: #1a1f3f;
  color: #eef2ff;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.chat-model-mode-select:focus {
  border-color: rgba(129, 140, 248, 0.7);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.chat-reasoning-label {
  color: var(--text-muted);
}

.chat-reasoning-select {
  min-width: 96px;
  padding: 7px 28px 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.42);
  background: #3a2612;
  color: #fff7e6;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.chat-reasoning-select:focus {
  border-color: rgba(251, 191, 36, 0.7);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.chat-model-mode-select option,
.chat-reasoning-select option {
  background: #111521;
  color: #f8fafc;
}

.message-meta-pill {
  display: inline-flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34,197,94,0.22);
  background: rgba(34,197,94,0.08);
  color: #7dd3a7;
  font-size: 12px;
  font-weight: 600;
}

.chat-model-resolved-badge {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(34,197,94,0.22);
  background: rgba(34,197,94,0.08);
  color: #7dd3a7;
  font-size: 12px;
  font-weight: 600;
}

.image-attachment {
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
}

.image-attachment img {
  display: block;
  max-width: min(100%, 360px);
  max-height: 300px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
}

.image-attachment-link {
  color: var(--accent-light);
  text-decoration: none;
  font-size: 12px;
}

.image-attachment-link:hover {
  text-decoration: underline;
}

.input-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 780px;
  margin: 0 auto;
}

.voice-btn {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-glass, rgba(255,255,255,0.03));
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.voice-btn:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: rgba(34,197,94,0.45);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.12);
}

.voice-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.voice-btn.recording {
  color: #fff;
  background: #ef4444;
  border-color: rgba(239,68,68,0.6);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.16);
}

.voice-btn.processing {
  color: #fff;
  background: #0f766e;
  border-color: rgba(20,184,166,0.55);
  box-shadow: 0 0 0 3px rgba(20,184,166,0.14);
}

.voice-status {
  max-width: 780px;
  min-height: 18px;
  margin: 7px auto 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.voice-status.error {
  color: #fca5a5;
}

.voice-status.success {
  color: #86efac;
}

.input-wrapper {
  max-width: 780px;
  margin: 0 auto;
  position: relative;
}

.input-box {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 200px;
  padding: 14px 58px 14px 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: var(--transition);
}

.input-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-box::placeholder { color: var(--text-muted); }

.send-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 38px; height: 38px;
  border: none;
  border-radius: 10px;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: 0 2px 12px rgba(99,102,241,0.3);
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 20px rgba(99,102,241,0.4);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ===== Stop Button (streaming state) ===== */
.send-btn.stop-btn {
  background: linear-gradient(135deg, #ef4444, #f97316);
  box-shadow: 0 2px 14px rgba(239, 68, 68, 0.35);
  opacity: 1;
  cursor: pointer;
  animation: stopPulse 2s ease-in-out infinite;
}

.send-btn.stop-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.5);
}

.send-btn .stop-icon {
  display: none;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 3px;
}

.send-btn.stop-btn .send-icon { display: none; }
.send-btn.stop-btn .stop-icon { display: block; }

@keyframes stopPulse {
  0%, 100% { box-shadow: 0 2px 14px rgba(239, 68, 68, 0.35); }
  50% { box-shadow: 0 2px 20px rgba(239, 68, 68, 0.55); }
}

/* ===== Rename Dialog ===== */
.dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.dialog-overlay.active { display: flex; }

.dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 360px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.2s ease;
}

.dialog h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.dialog input {
  width: 100%;
  padding: 11px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  margin-bottom: 20px;
}

.dialog input:focus {
  border-color: var(--accent);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.dialog-actions button {
  padding: 9px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

.dialog-actions .cancel-btn {
  background: rgba(255,255,255,0.06);
  color: var(--text-secondary);
}

.dialog-actions .cancel-btn:hover {
  background: rgba(255,255,255,0.1);
}

.dialog-actions .confirm-btn {
  background: var(--accent);
  color: #fff;
}

.dialog-actions .confirm-btn:hover {
  background: var(--accent-light);
}

.settings-dialog {
  width: min(840px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 24px 20px;
}

.settings-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.settings-summary {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.settings-section {
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px;
  background: rgba(255,255,255,0.02);
  margin-bottom: 14px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-section-head h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.settings-section-head p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.settings-save-btn {
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-light);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.settings-save-btn:hover {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(99, 102, 241, 0.5);
}

.settings-save-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.settings-note,
.settings-help,
.settings-empty {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}

.settings-note {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
}

.settings-field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.settings-field label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.settings-select,
.settings-input,
.settings-textarea {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.settings-select {
  padding: 11px 12px;
}

.settings-input {
  padding: 11px 12px;
  margin-bottom: 0;
}

.dialog .settings-input {
  margin-bottom: 0;
}

.settings-textarea {
  min-height: 140px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.7;
}

.settings-select:focus,
.settings-input:focus,
.settings-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.department-settings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.department-setting-card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255,255,255,0.02);
}

.department-setting-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.department-setting-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.department-setting-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.department-setting-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
}

.wecom-picker-dialog {
  width: min(680px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
}

.wecom-search-box {
  position: relative;
}

.wecom-search-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary, #0d0d1a);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.wecom-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.wecom-search-results {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.wecom-search-item {
  width: 100%;
  border: 1px solid var(--border-color);
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}

.wecom-search-item:hover,
.wecom-search-item.active {
  border-color: rgba(99, 102, 241, 0.45);
  background: rgba(99, 102, 241, 0.12);
}

.wecom-search-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.wecom-search-item-subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

.wecom-selected-summary {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.2);
  color: #bbf7d0;
  font-size: 12px;
  line-height: 1.7;
}

.wecom-selected-summary strong {
  color: #dcfce7;
}

/* ===== Export UI ===== */
.export-dropdown {
  position: relative;
}

.export-trigger-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.export-trigger-btn:hover {
  background: var(--accent-glow);
  border-color: var(--border-active);
  color: var(--accent-light);
}

.export-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  min-width: 180px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 20;
  animation: fadeUp 0.15s ease;
}

.export-menu.active {
  display: block;
}

.export-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.export-menu-item:hover {
  background: var(--accent-glow);
  color: var(--accent-light);
}

/* Per-message export buttons */
.message-export-actions {
  display: none;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.message:hover .message-export-actions {
  display: flex;
}

.msg-export-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  padding: 0;
}

.msg-export-btn:hover {
  background: var(--accent-glow);
  color: var(--accent-light);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    z-index: 50;
    height: 100vh;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { left: 0; }

  .mobile-menu-btn { display: block; }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
  }

  .sidebar-overlay.active { display: block; }

  .message { padding: 12px 0; }
  .messages-container { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }

  .input-composer-row {
    max-width: 100%;
  }

  .voice-btn {
    width: 46px;
    height: 46px;
    font-size: 18px;
  }

  .voice-status {
    max-width: 100%;
    margin-top: 6px;
  }

  .mode-toolbar {
    align-items: stretch;
  }
  .mode-toolbar-side {
    width: 100%;
    justify-content: space-between;
  }
  .mode-meta {
    width: 100%;
    justify-content: space-between;
  }
  .chat-reasoning-control {
    width: 100%;
    justify-content: space-between;
  }
  .chat-model-mode-control {
    width: 100%;
    justify-content: space-between;
  }
  .chat-model-resolved-badge {
    width: 100%;
    justify-content: center;
  }
  .settings-section-head,
  .department-setting-head {
    flex-direction: column;
    align-items: stretch;
  }
  .settings-save-btn {
    width: 100%;
  }

  /* Export: always show on mobile since hover doesn't work */
  .message-export-actions {
    display: flex;
  }

  .msg-export-btn {
    width: 32px;
    height: 32px;
    font-size: 15px;
    background: rgba(255,255,255,0.06);
  }
}
