/* ========================================
   小扒虫 AI 助手 - 白色主题样式系统
   ======================================== */

:root {
  --brand: #A78BFA;
  --brand-light: #F5F3FF;
  --brand-hover: #8B5CF6;

  --bg: #FFFFFF;
  --bg-sidebar: #F9FAFB;
  --bg-chat: #FFFFFF;
  --bg-input: #F4F6F8;
  --bg-user-msg: #A78BFA;
  --bg-ai-msg: #F4F6F8;

  --text-primary: #111827;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
  --text-on-brand: #FFFFFF;

  --border: #E5E7EB;
  --border-input: #D1D5DB;
  --border-focus: #A78BFA;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.14);

  --sidebar-w: 256px;
  --topbar-h: 56px;
  --input-area-h: 100px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size: 15px;

  --transition: 0.2s ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: var(--font-size); }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  overflow: hidden;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
textarea { font-family: inherit; resize: none; outline: none; }
a { color: var(--brand); text-decoration: none; }

/* ========================================
   侧边栏
   ======================================== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), min-width var(--transition);
  overflow: hidden;
  z-index: 100;
}
.sidebar.collapsed {
  width: 0;
  min-width: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.logo-icon svg { width: 100%; height: 100%; }
.logo-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 12px;
  transition: background var(--transition), color var(--transition);
}
.sidebar-toggle:hover { background: var(--border); color: var(--text-primary); }

/* 新建对话按钮 */
.new-chat-btn {
  margin: 12px 10px 8px;
  padding: 9px 14px;
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition), transform var(--transition);
  box-shadow: 0 2px 8px rgba(167,139,250,0.20);
}
.new-chat-btn:hover { background: var(--brand-hover); transform: translateY(-1px); }
.new-chat-btn i { font-size: 13px; }

/* 历史对话 */
.chat-history { flex: 1; overflow-y: auto; padding: 4px 0; }
.history-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 14px 6px;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  margin: 1px 6px;
  font-size: 13.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--border); color: var(--text-primary); }
.history-item.active {
  background: var(--brand-light);
  color: var(--brand);
  font-weight: 500;
}
.history-item i { font-size: 12px; flex-shrink: 0; }

/* 侧边栏底部 */
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sf-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.sf-btn:hover { background: var(--border); color: var(--text-primary); }
.sf-btn i { font-size: 13px; width: 16px; text-align: center; }

/* ========================================
   主内容区
   ======================================== */
.main-area {
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
}

/* 顶部导航栏 */
.topbar {
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  z-index: 50;
  flex-shrink: 0;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.menu-btn:hover { background: var(--bg-input); }

/* 模型选择器 */
/* 顶部导航模型选择器 — 永久隐藏（模型选择统一在底部输入栏）*/
#modelSelectorWrap { display: none !important; }

.model-selector { position: relative; }
.model-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: #fff;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.model-btn:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10A37F;
  transition: background var(--transition);
}
.model-btn i { font-size: 11px; color: var(--text-muted); }

/* 模型下拉 */
.model-dropdown {
  position: fixed;        /* 脱离所有父级，避免父级display:none或overflow影响 */
  width: 300px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-height: 420px;
  overflow-y: auto;
  display: none;
  z-index: 9999;          /* 最高层，不被任何元素遮挡 */
  padding: 6px;
  /* 防止iOS Safari滚动穿透 */
  -webkit-overflow-scrolling: touch;
}
.model-dropdown.open { display: block; }

.dropdown-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 10px 4px;
}
.model-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}
.model-option:hover { background: var(--bg-input); }
.model-option.selected { background: var(--brand-light); }
.model-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
}
.model-icon-emoji { font-size: 18px; width: 22px; text-align: center; }
.mo-name { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }
.mo-desc { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.mo-badge {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: #FEF3C7;
  color: #D97706;
}
.mo-badge.new { background: #DCFCE7; color: #16A34A; }

/* 顶部右侧 */
.topbar-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.topbar-icon-btn:hover { background: var(--bg-input); color: var(--text-primary); }

/* 更多菜单 */
.more-menu-wrap {
  position: relative;
}
.more-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 160px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.10);
  padding: 6px 0;
  opacity: 0;
  transform: translateY(-6px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 300;
}
.more-dropdown.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}
.more-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: none;
  border: none;
  font-size: 13.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.more-item:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}
.more-item i {
  width: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.more-item:hover i { color: var(--brand); }
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

/* ========================================
   聊天区域
   ======================================== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}
/* 欢迎页时禁用滚动 */
.chat-container.welcome-mode {
  overflow-y: hidden;
}
.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }

/* 欢迎屏 */
.welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 28px 20px 8px;
  animation: fadeUp 0.5s ease;
  /* 防止内容超出时出现空白滚动区 */
  min-height: 0;
  overflow: hidden;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
.welcome-logo svg {
  width: 80px;
  height: 80px;
  margin-bottom: 18px;
}
.welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 5px;
  letter-spacing: -0.5px;
}
.brand-text { color: var(--brand); }
.welcome-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  text-align: center;
}

/* 模型展示横条 */
.model-showcase {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}
.ms-item {
  padding: 4px 12px;
  border-radius: 20px;
  background: #fff;
  border: 1.5px solid var(--c, #E5E7EB);
  font-size: 11px;
  font-weight: 600;
  color: var(--c, #6B7280);
  transition: transform var(--transition), box-shadow var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
}
.ms-item .ms-logo {
  width: 14px;
  height: 14px;
  object-fit: contain;
  flex-shrink: 0;
}
.ms-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.10); }

.welcome-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  margin-bottom: 12px;
}

/* ---- 功能卡片区（2×2 布局） ---- */
.feature-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
  width: 100%;
  max-width: 400px;
  padding: 0 2px 4px;
}
.feat-card {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.feat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--fb, #F5F3FF) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.18s;
}
.feat-card:hover {
  border-color: var(--fc, #A78BFA);
  box-shadow: 0 3px 12px rgba(0,0,0,0.07);
  transform: translateY(-1px);
}
.feat-card:hover::before { opacity: 1; }
.feat-card:active { transform: translateY(0); }

.feat-icon {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--fb, #F5F3FF);
  color: var(--fc, #A78BFA);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  transition: transform 0.18s;
}
.feat-card:hover .feat-icon { transform: scale(1.1); }

.feat-body {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}
.feat-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  line-height: 1.3;
}
.feat-desc {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  margin-top: 1px;
}

.feat-arrow {
  font-size: 9px;
  color: var(--text-muted);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  transition: transform 0.18s, color 0.18s;
}
.feat-card:hover .feat-arrow {
  transform: translateX(2px);
  color: var(--fc, #A78BFA);
}

/* 移动端：保持双列 */
@media (max-width: 480px) {
  .feature-cards { max-width: 320px; gap: 6px; }
  .feat-card { padding: 6px 9px; }
}

/* 消息列表 */
.messages-list {
  padding: 20px 0 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 单条消息 */
.message-row {
  display: flex;
  gap: 12px;
  padding: 6px 24px;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message-row.user { justify-content: flex-end; }
.message-row.ai   { justify-content: flex-start; }

/* 头像 */
.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}
.msg-avatar.ai-avatar {
  background: #F5F3FF;
  color: #7C3AED;
}
.msg-avatar.user-avatar-msg {
  background: linear-gradient(135deg, #A78BFA 0%, #C4B5FD 100%);
  color: #fff;
}

/* 消息内容 */
.msg-content-wrap { max-width: 72%; display: flex; flex-direction: column; gap: 4px; }
.message-row.user .msg-content-wrap { align-items: flex-end; }

.msg-bubble {
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
}
.message-row.user .msg-bubble {
  background: linear-gradient(135deg, #A78BFA 0%, #C4B5FD 100%);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.message-row.ai .msg-bubble {
  background: var(--bg-ai-msg);
  color: var(--text-primary);
  border-bottom-left-radius: 5px;
}

/* Markdown 渲染 */
.msg-bubble pre {
  background: #1E293B;
  color: #E2E8F0;
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}
.msg-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
}
.msg-bubble p:not(:last-child) { margin-bottom: 6px; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 4px 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 { font-weight: 600; margin: 8px 0 4px; }
.message-row.user .msg-bubble a { color: #DDD6FE; }

/* 消息底部工具栏 */
.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.message-row:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: #fff;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.msg-action-btn:hover { background: var(--bg-input); color: var(--text-primary); }

/* 时间戳 */
.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 2px;
}

/* 打字中动画 */
.typing-dot {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}
.typing-dot span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.4;
  animation: typingBounce 1.2s infinite;
}
.typing-dot span:nth-child(2) { animation-delay: 0.2s; }
.typing-dot span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%,80%,100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* 建议问题 */
.suggestions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 4px 70px;
}
.suggestion-chip {
  padding: 5px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
  background: #fff;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background var(--transition);
}
.suggestion-chip:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

/* ========================================
   输入区（重构为卡片式布局）
   ======================================== */
.input-area {
  padding: 8px 14px 10px;
  background: #fff;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
}

/* 快捷功能按钮（已移入欢迎屏，此处隐藏旧入口） */
.quick-tools { display: none; }
.qt-btn { display: none; }

/* 输入框包裹 */
.input-box-wrap { display: flex; flex-direction: column; }

/* ---- 大输入卡片 ---- */
.input-card {
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 20px;
  padding: 12px 12px 8px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.input-card:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.12);
  background: #fff;
}

/* textarea */
.chat-input {
  width: 100%;
  background: transparent;
  border: none;
  font-size: 14.5px;
  color: var(--text-primary);
  line-height: 1.6;
  max-height: 160px;
  overflow-y: auto;
  resize: none;
  outline: none;
}
.chat-input::placeholder { color: var(--text-muted); }

/* ---- 卡片底部工具栏 ---- */
.input-card-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.input-card-bar-left {
  display: flex;
  align-items: center;
  gap: 4px;
}
.input-card-bar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* + 新建按钮 */
.icb-plus-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.icb-plus-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-light);
}

/* 模型选择器 */
.icb-model-wrap { position: relative; }
.icb-model-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: #fff;
  font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  white-space: nowrap;
}
.icb-model-btn:hover { border-color: var(--brand); color: var(--brand); }
.icb-model-btn .model-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #10A37F;
  flex-shrink: 0;
}
.icb-model-btn .fa-chevron-down { font-size: 9px; color: var(--text-muted); }

/* 附件按钮 */
.attach-btn, .icb-attach-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.attach-btn:hover, .icb-attach-btn:hover { background: var(--border); }

/* 发送按钮 */
.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #A78BFA 0%, #C4B5FD 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background var(--transition), transform var(--transition);
  box-shadow: 0 2px 8px rgba(167,139,250,0.25);
}
.send-btn:hover { background: var(--brand-hover); transform: scale(1.05); }
.send-btn:disabled { background: var(--border); color: var(--text-muted); box-shadow: none; transform: none; cursor: not-allowed; }
.send-btn.stop-mode { background: #EF4444; }
.send-btn.stop-mode:hover { background: #DC2626; }

.input-footer-tip {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
}

/* ========================================
   Modal 通用
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(3px);
}
.modal-overlay.open, .modal-overlay.show { display: flex; }

.modal-box {
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.22s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.api-modal { width: 720px; max-width: 95vw; }
.settings-modal { width: 420px; max-width: 95vw; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.modal-header h2 i { color: var(--brand); }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.modal-close:hover { background: var(--bg-input); color: var(--text-primary); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* API 面板 */
.api-intro {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 18px;
  line-height: 1.6;
}
.api-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.api-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.api-card:hover { border-color: var(--c, var(--brand)); box-shadow: 0 2px 12px rgba(0,0,0,0.08); }
.api-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.api-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.api-logo-img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}
.logo-invert {
  filter: brightness(0) invert(1);
}
.api-logo-fallback {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.api-card-name { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.api-card-company { font-size: 11.5px; color: var(--text-muted); }
.api-card-models { display: flex; flex-wrap: wrap; gap: 4px; }
.api-model-tag {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
/* 获取 Key 链接按钮 */
.api-get-key-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1.5px solid;
  font-size: 11.5px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--transition), opacity var(--transition);
  opacity: 0.85;
}
.api-get-key-link:hover { opacity: 1; background: rgba(0,0,0,0.04); }
.api-get-key-link i { font-size: 10px; }

/* 输入行 */
.api-input-row {
  display: flex;
  gap: 7px;
  align-items: center;
}
.api-input-row .api-card-input {
  flex: 1;
  width: auto;
}
.api-card-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  font-size: 12px;
  color: var(--text-primary);
  background: #fff;
  outline: none;
  transition: border-color var(--transition);
}
.api-card-input:focus { border-color: var(--c, var(--brand)); }
.api-card-input::placeholder { color: var(--text-muted); }
.api-card-save {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 7px;
  background: var(--c, var(--brand));
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  transition: opacity var(--transition);
  white-space: nowrap;
}
.api-card-save:hover { opacity: 0.88; }

/* 设置面板 */
.settings-section { margin-bottom: 24px; }
.settings-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 13.5px;
  color: var(--text-primary);
}
.settings-row select {
  padding: 5px 10px;
  border: 1px solid var(--border-input);
  border-radius: 7px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  background: #fff;
}
.toggle-row { cursor: default; }
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-input);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ========================================
   用户认证 & 权限系统
   ======================================== */

/* 顶栏登录按钮 */
.login-trigger-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.login-trigger-btn:hover { background: var(--brand-hover); transform: translateY(-1px); }
.login-trigger-btn i { font-size: 14px; }

/* 用户头像区域 */
.user-avatar-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.user-avatar:hover { transform: scale(1.08); box-shadow: 0 2px 10px rgba(167,139,250,0.4); }

/* 用户下拉菜单 */
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 200px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  padding: 12px 0;
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}
.user-menu.show { opacity: 1; transform: translateY(0); pointer-events: all; }
.user-menu-info { padding: 4px 16px 10px; }
.um-name { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.um-email { font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; word-break: break-all; }
.um-level { display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
  background: var(--brand-light); color: var(--brand); }
.um-level.pro { background: #FEF9C3; color: #B45309; }
.um-divider { margin: 0; border: none; border-top: 1px solid var(--border); }
.um-btn {
  width: 100%; text-align: left; padding: 10px 16px;
  font-size: 13px; color: var(--text-secondary);
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  transition: background 0.15s, color 0.15s;
}
.um-btn:hover { background: #FEF2F2; color: #EF4444; }

/* ---- Auth Modal ---- */
.auth-modal {
  width: 400px;
  max-width: calc(100vw - 40px);
  border-radius: 20px;
  padding: 0;
  overflow: hidden;
}
.auth-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px 0;
  gap: 0;
}
.auth-tab {
  flex: 1;
  background: none; border: none;
  font-size: 15px; font-weight: 500;
  color: var(--text-muted);
  padding: 8px 0 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.auth-tabs .modal-close {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none; background: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin-left: auto;
  transition: background 0.15s;
}
.auth-tabs .modal-close:hover { background: var(--border); }

.auth-form {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 24px;
  gap: 14px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
.auth-logo span {
  font-size: 18px; font-weight: 700;
  color: var(--text-primary);
}
.auth-field {
  display: flex; flex-direction: column; gap: 5px;
}
.auth-field label {
  font-size: 12.5px; font-weight: 500;
  color: var(--text-secondary);
}
.auth-field input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-input);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}
.auth-field input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(167,139,250,0.15);
  background: #fff;
}
.auth-pw-wrap { position: relative; }
.auth-pw-wrap input { padding-right: 40px; }
.auth-pw-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 13px;
  padding: 4px;
}
.auth-pw-eye:hover { color: var(--brand); }

.auth-error {
  font-size: 12.5px; color: #EF4444;
  min-height: 16px;
  margin-top: -6px;
}

/* Google 登录按钮 */
.google-login-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  background: #fff;
  border: 1.5px solid #E5E7EB;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.google-login-btn:hover:not(:disabled) {
  background: #F9FAFB;
  border-color: #D1D5DB;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}
.google-login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* 分割线 */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-submit-btn {
  width: 100%;
  padding: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.auth-submit-btn:hover:not(:disabled) { background: var(--brand-hover); transform: translateY(-1px); }
.auth-submit-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}
.auth-switch a { color: var(--brand); text-decoration: none; font-weight: 500; }
.auth-switch a:hover { text-decoration: underline; }

/* ---- Gate Modal (权限拦截) ---- */
.gate-modal {
  width: 340px;
  max-width: calc(100vw - 40px);
  border-radius: 20px;
  padding: 32px 28px 24px;
  text-align: center;
}
.gate-icon {
  width: 60px; height: 60px;
  background: var(--brand-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--brand);
  margin: 0 auto 16px;
}
.gate-title {
  font-size: 17px; font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.gate-desc {
  font-size: 13.5px; color: var(--text-muted);
  margin: 0 0 20px;
  line-height: 1.6;
}
.gate-btns {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 12px;
}
.gate-login-btn {
  width: 100%; padding: 11px;
  background: none;
  border: 1.5px solid var(--brand);
  color: var(--brand);
  border-radius: 12px;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.gate-login-btn:hover { background: var(--brand-light); }
.gate-skip {
  background: none; border: none;
  color: var(--text-muted); font-size: 12px;
  cursor: pointer; text-decoration: underline;
  padding: 4px;
}
.gate-skip:hover { color: var(--text-secondary); }

/* Toast 颜色扩展 */
.toast.success { background: #10B981; }
.toast.error { background: #EF4444; }
.toast.info { background: #6B7280; }

/* ========================================
   Toast
   ======================================== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1E293B;
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========================================
   滚动条美化
   ======================================== */
.model-dropdown::-webkit-scrollbar { width: 4px; }
.model-dropdown::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 2px; }

/* ========================================
   响应式
   ======================================== */
/* 侧边栏遮罩层 */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 99;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s ease;
}
.sidebar-overlay.active {
  display: block;
  opacity: 1;
}

@media (max-width: 768px) {
  :root { --sidebar-w: 80vw; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  /* 手势滑动时跟手动画（JS设置inline style时关闭transition） */
  .sidebar.is-dragging {
    transition: none !important;
  }
  .sidebar-overlay.is-dragging {
    transition: none !important;
  }
  .main-area { width: 100%; }
  .message-row { padding: 6px 12px; }
  .msg-content-wrap { max-width: 88%; }
  .quick-tools { gap: 4px; }
  .qt-btn { width: 40px; height: 40px; font-size: 9px; }
  .qt-btn i { font-size: 12px; }
  .suggestions-row { padding: 4px 12px; }
}

/* ========================================
   系统消息
   ======================================== */
.system-msg {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 0;
}

/* 分隔线 */
.chat-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 24px;
  color: var(--text-muted);
  font-size: 11.5px;
}
.chat-divider::before, .chat-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ========================================
   PWA 安装横幅
   ======================================== */
.install-banner {
  position: fixed;
  bottom: -100px;
  left: 12px;
  right: 12px;
  background: #fff;
  border: 1.5px solid #EDE9FE;
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(139,92,246,0.18);
  z-index: 999;
  transition: bottom 0.4s cubic-bezier(0.34,1.56,0.64,1);
}
.install-banner.show { bottom: 16px; }

.install-banner-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}
.install-banner-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.install-banner-text strong {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.install-banner-text span {
  font-size: 11.5px;
  color: var(--text-muted);
}
.install-banner-btn {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #8B5CF6, #A78BFA);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  box-shadow: 0 3px 10px rgba(139,92,246,0.3);
  transition: opacity 0.15s, transform 0.15s;
}
.install-banner-btn:hover { opacity: 0.9; transform: scale(1.03); }
.install-banner-close {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: background var(--transition);
}
.install-banner-close:hover { background: var(--border); }

/* 顶栏安装按钮 */
.install-btn { color: #8B5CF6 !important; }
.install-btn:hover { background: #F5F3FF !important; }
