:root {
  /* 品牌主色：瑶光绿 */
  --primary: #7EB8A2;
  --primary-dark: #68A08C;
  --primary-light: #DCEFE5;
  /* 点缀色：淬炼金 */
  --accent: #C8956C;
  --accent-dark: #B07D4E;
  /* 背景色 */
  --bg: #F7F8F6;
  --card: #ffffff;
  /* 文字色 */
  --text: #2E3B35;
  --text-secondary: #8B9A91;
  /* 线条 */
  --border: #E0EBE6;
  /* 气泡 */
  --user-bubble: #7EB8A2;
  --user-text: #fff;
  --bot-bubble: #fff;
  --bot-text: #2E3B35;
  --system-bg: #DCEFE5;
  --danger: #ff6b6b;
  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(126, 184, 162, 0.08);
  --shadow-md: 0 4px 16px rgba(126, 184, 162, 0.10);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* 深色模式 */
:root.dark {
  --bg: #1a1f1c;
  --card: #252b28;
  --text: #E8EDEA;
  --text-secondary: #8B9A91;
  --border: #3A4540;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --primary: #5A8F7A;
  --primary-light: #3D5A4E;
  --bot-bubble: #252b28;
  --bot-text: #E8EDEA;
  --system-bg: #2A3A32;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 页面视图切换 */
.page {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.page.active {
  display: flex;
}

/* ==================== 登录页面 ==================== */
.login-page {
  justify-content: center;
  align-items: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  background: var(--card);
  border-radius: 24px;
  padding: 40px 28px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.login-logo .logo-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  overflow: hidden;
}
.login-logo .logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.login-logo h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text);
}
.login-logo p {
  color: var(--text-secondary);
  font-size: 14px;
}
.login-logo .slogan {
  color: var(--accent);
  font-size: 13px;
  margin-top: 6px;
  font-style: italic;
  letter-spacing: 0.5px;
}

/* 协议勾选区 */
.consent-section {
  padding: 4px 0 4px;
  margin-bottom: 18px;
}
.consent-agreement-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.consent-checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  cursor: pointer;
  position: relative;
}
.consent-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}
.consent-checkmark {
  width: 20px;
  height: 20px;
  border: 1.5px solid #CCD5D0;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  pointer-events: none;
}
.consent-checkbox input:checked + .consent-checkmark {
  background: var(--primary);
  border-color: var(--primary);
}
.consent-checkbox input:checked + .consent-checkmark::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  position: absolute;
  top: 2px;
  left: 6px;
}
.consent-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.consent-text a {
  color: var(--primary-dark);
  text-decoration: none;
  font-weight: 500;
}
.consent-text a:active {
  opacity: 0.6;
}

/* 登录页 AI 免责声明 — 放在 logo 下方 */
.login-disclaimer {
  color: var(--text-secondary);
  font-size: 12px;
  margin-top: 8px;
  line-height: 1.5;
}

.login-footer {
  text-align: center;
  margin-top: 28px;
}
.login-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  transition: color 0.2s;
}
.login-footer a:hover {
  color: var(--primary-dark);
}

.wechat-login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 24px 0 16px;
  color: var(--text-secondary);
  font-size: 13px;
}
.wechat-login-divider::before,
.wechat-login-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.wechat-login-divider span {
  padding: 0 12px;
}

.btn-wechat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #07C160;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 13px 20px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn-wechat:hover:not(:disabled) {
  background: #06AD56;
}
.btn-wechat:disabled {
  background: #a0a0a0;
  cursor: not-allowed;
  opacity: 0.6;
}
.btn-wechat .wechat-icon {
  font-size: 20px;
}

.form-group {
  margin-bottom: 22px;
}
.form-group label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

#phoneStep .btn,
#codeStep .btn {
  margin-top: 4px;
}
.phone-input-group {
  display: flex;
  gap: 12px;
}
.phone-input-group input {
  flex: 1;
}
input[type="text"],
input[type="tel"] {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(126, 184, 162, 0.12);
}
.btn {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(126, 184, 162, 0.3);
}
.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}
.btn-secondary {
  background: var(--primary-light);
  color: var(--primary-dark);
}
.btn-secondary:hover:not(:disabled) {
  background: #CDE4D8;
}
.btn-sm {
  padding: 10px 16px;
  font-size: 14px;
  width: auto;
  white-space: nowrap;
  border-radius: 10px;
}

/* ==================== 设置页面 ==================== */
.settings-item:hover {
  background: var(--primary-light);
}

/* Toggle开关 */
.toggle-switch input:checked + span {
  background-color: var(--primary);
}
.toggle-switch input:focus + span {
  box-shadow: 0 0 1px var(--primary);
}
.toggle-switch input:checked + span:before {
  transform: translateX(24px);
}
.toggle-switch span:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

/* ==================== 消息引用 ==================== */
.message-content-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message-reply {
  background-color: rgba(126, 184, 162, 0.08);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.2s;
  max-width: 280px;
}
.message-reply:hover {
  background-color: rgba(126, 184, 162, 0.15);
}
.reply-role {
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}
.reply-content {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 回复预览条 */
.reply-preview {
  background-color: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.reply-info {
  flex: 1;
  overflow: hidden;
}
.reply-title {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 2px;
}
.reply-content-preview {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-cancel-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
}
.reply-cancel-btn:hover {
  background-color: var(--primary-light);
}

/* 上下文菜单 */
.context-menu {
  position: fixed;
  background-color: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 120px;
  overflow: hidden;
}
.context-menu-item {
  padding: 10px 16px;
  cursor: pointer;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text);
}
.context-menu-item:hover {
  background-color: var(--primary-light);
}

.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-top: 8px;
  display: none;
}
.error-message.show {
  display: block;
}

/* ==================== Header ==================== */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.header-avatar {
  width: 36px; height: 36px;
  overflow: hidden;
}
.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.header-info {
  flex: 1;
}
.header-info h1 { font-size: 16px; font-weight: 600; color: var(--text); }
.header-info p { font-size: 12px; color: var(--text-secondary); }
.header-menu {
  position: relative;
}
.menu-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: background 0.2s;
}
.menu-btn:hover {
  background: var(--primary-light);
}
.menu-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  display: none;
  z-index: 1000;
  overflow: hidden;
}
.menu-dropdown.show {
  display: block;
}
.menu-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.2s;
}
.menu-item:hover {
  background: var(--primary-light);
}
.menu-item.danger {
  color: var(--danger);
}

/* ==================== 会话列表页面 ==================== */
.sessions-page {
  background: var(--bg);
}
.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

/* 新会话按钮 — 悬浮卡片风格 */
.new-session-btn {
  margin: 12px 16px;
  margin-bottom: 0;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}

/* 会话卡片 */
.session-item {
  position: relative;
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}
.session-item:hover {
  box-shadow: var(--shadow-md);
  background: #FBFCFA;
}
.session-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.session-item-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 8px;
  padding-right: 30px;
}
.session-item-date {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  padding-top: 2px;
}
.session-item-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.session-item-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

/* 置顶会话 — 金色角标代替绿色竖线 */
.session-item.pinned {
  border-left: none;
  background: var(--card);
}
.session-item.pinned::before {
  content: "📌";
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 12px;
  opacity: 0.7;
}
.session-item.pinned .session-item-title {
  padding-left: 18px;
}

/* 选中状态 */
.session-item.selected {
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
}

/* 会话菜单按钮 */
.session-item-menu {
  position: relative;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.2s, color 0.2s;
}
.session-item-menu:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* 会话列表直接删除按钮 */
.session-item-delete-btn {
  background: transparent;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 2px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: #999;
  flex-shrink: 0;
}
.session-item-delete-btn:hover {
  background: #fde8e8;
  color: #e53e3e;
}

/* 下拉菜单 */
.session-dropdown {
  position: absolute;
  top: 40px;
  right: 0;
  background: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  min-width: 120px;
  z-index: 1000;
  display: none;
  overflow: hidden;
}
.session-dropdown.show {
  display: block;
}
.session-dropdown-item {
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s;
}
.session-dropdown-item:hover {
  background: var(--primary-light);
}
.session-dropdown-item.danger {
  color: var(--danger);
}

/* ==================== 消息区域 ==================== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}
.message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.bot { align-self: flex-start; }

.message-avatar {
  width: 32px; height: 32px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  overflow: hidden;
}
.message.user .message-avatar { border-radius: 50%; background: #e8e8ed; color: #666; }
.message.bot .message-avatar {
  overflow: hidden;
}
.message.bot .message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* AI 气泡 — 白色卡片 + 阴影，浮在背景上 */
.message.bot .message-bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-top-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  white-space: normal; /* Markdown 渲染后由 HTML 元素控制换行 */
}
/* 用户气泡 — 主色，更大圆角 */
.message.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-top-right-radius: 4px;
}
.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Markdown 渲染内容样式（bot 气泡内） ── */

/* 气泡内首尾元素去掉多余外边距，保持气泡 padding 均匀 */
.message.bot .message-bubble > :first-child { margin-top: 0; }
.message.bot .message-bubble > :last-child  { margin-bottom: 0; }

/* 段落 */
.message.bot .message-bubble p {
  margin: 0 0 6px 0;
  line-height: 1.6;
}
.message.bot .message-bubble p:last-child {
  margin-bottom: 0;
}

/* 列表 — 行间距松散舒适 */
.message.bot .message-bubble ul,
.message.bot .message-bubble ol {
  margin: 4px 0 8px 0;
  padding-left: 20px;
}
.message.bot .message-bubble li {
  margin-bottom: 4px;
  line-height: 1.6;
}
.message.bot .message-bubble li:last-child {
  margin-bottom: 0;
}

/* 标题 */
.message.bot .message-bubble h1,
.message.bot .message-bubble h2,
.message.bot .message-bubble h3,
.message.bot .message-bubble h4 {
  margin: 10px 0 4px 0;
  font-weight: 700;
  line-height: 1.3;
}
.message.bot .message-bubble h1 { font-size: 1.25em; }
.message.bot .message-bubble h2 { font-size: 1.12em; }
.message.bot .message-bubble h3 { font-size: 1.05em; }
.message.bot .message-bubble h4 { font-size: 1em; }

/* 行内代码 */
.message.bot .message-bubble code {
  background: rgba(126, 184, 162, 0.14);
  color: var(--primary-dark);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

/* 代码块 */
.message.bot .message-bubble pre {
  background: #f0f4f2;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}
.message.bot .message-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* 引用块 — 给一点背景色和圆角，融入气泡 */
.message.bot .message-bubble blockquote {
  background: rgba(126, 184, 162, 0.06);
  border-left: 3px solid var(--primary);
  border-radius: 6px;
  margin: 8px 0;
  padding: 8px 12px;
  color: var(--text-secondary);
  font-size: 0.95em;
  line-height: 1.55;
}
.message.bot .message-bubble blockquote p:last-child {
  margin-bottom: 0;
}

/* 链接 */
.message.bot .message-bubble a {
  color: var(--primary-dark);
  text-decoration: underline;
}

/* 分割线 */
.message.bot .message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}

/* 表格 */
.message.bot .message-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}
.message.bot .message-bubble th,
.message.bot .message-bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.message.bot .message-bubble th {
  background: var(--primary-light);
  font-weight: 600;
}

/* 系统消息 */
.message.system {
  align-self: center;
  max-width: 90%;
}
.message.system .message-bubble {
  background: var(--system-bg);
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
  border-radius: 12px;
}

/* 打字指示器 */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: blink 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.3; } 40% { opacity: 1; } }

/* ==================== 输入区域 ==================== */
.input-area {
  position: relative;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
}
.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s, box-shadow 0.2s;
}
.input-row textarea:focus {
  background: var(--card);
  box-shadow: 0 0 0 2px rgba(126, 184, 162, 0.25);
}
.send-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(126, 184, 162, 0.25);
}
.send-btn:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(126, 184, 162, 0.35);
}
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled {
  background: #ccc;
  box-shadow: none;
  cursor: not-allowed;
}

/* ==================== 图片上传 ==================== */
.image-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1.5px dashed var(--border);
  background: var(--card);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.2s, background 0.2s;
}
.image-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.image-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  position: relative;
}
.image-preview img {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.image-preview-remove {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.image-preview-remove:hover { background: rgba(0,0,0,0.7); }

/* ==================== 快捷回复 ==================== */
.quick-replies {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
.quick-reply {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}
.quick-reply:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* 推荐 query 加载骨架屏 */
.quick-replies.loading .quick-reply {
  animation: qr-pulse 1.5s ease-in-out infinite;
  pointer-events: none;
}
.quick-replies.loading .quick-reply:nth-child(1) { animation-delay: 0s; }
.quick-replies.loading .quick-reply:nth-child(2) { animation-delay: 0.1s; }
.quick-replies.loading .quick-reply:nth-child(3) { animation-delay: 0.2s; }
.quick-replies.loading .quick-reply:nth-child(4) { animation-delay: 0.3s; }
@keyframes qr-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ==================== 返回按钮 ==================== */
.back-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}
.back-btn:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ── 深色模式下 Markdown 渲染内容适配 ── */
:root.dark .message.bot .message-bubble code {
  background: rgba(126, 184, 162, 0.15);
  color: var(--primary);
}
:root.dark .message.bot .message-bubble pre {
  background: #1e2522;
  border-color: var(--border);
}
:root.dark .message.bot .message-bubble pre code {
  color: var(--bot-text);
}
:root.dark .message.bot .message-bubble th {
  background: #2a3a32;
}
:root.dark .message.bot .message-bubble blockquote {
  background: rgba(126, 184, 162, 0.08);
  color: #9BAAA1;
}

/* ── Header 操作按钮 ──────────────────────────────────── */
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}
.header-action-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.header-action-btn:hover {
  background: var(--bg);
}
.header-action-btn:active {
  transform: scale(0.92);
}

/* ── 消息反馈按钮 ──────────────────────────────────── */
.message-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  margin-left: 44px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message:hover .message-feedback,
.message-feedback:has(.feedback-btn.active) {
  opacity: 1;
}
.feedback-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 50%;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.feedback-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.1);
}
.feedback-btn:active {
  transform: scale(0.9);
}
.feedback-btn.active {
  background: var(--primary-light);
  transform: scale(1.1);
}

/* ── 反馈弹窗 ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
}
.modal-close-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-body {
  padding: 16px 20px;
}
.modal-footer {
  padding: 0 20px 20px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ── 反馈类型选择 ──────────────────────────────────── */
.feedback-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.feedback-type-btn {
  padding: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.feedback-type-btn:hover {
  border-color: var(--primary);
}
.feedback-type-btn.selected {
  border-color: var(--primary);
  background: rgba(126, 184, 162, 0.1);
  color: var(--primary);
}

#feedbackDescription {
  width: 100%;
  box-sizing: border-box;
}
.feedback-success {
  padding: 12px;
  background: rgba(126, 184, 162, 0.1);
  border-radius: 8px;
  text-align: center;
  margin-top: 12px;
}

.star-rating {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.star-rating .star {
  font-size: 28px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.15s, transform 0.15s;
  user-select: none;
  display: inline-block;
}
.star-rating .star:hover {
  transform: scale(1.2);
  opacity: 0.7;
}

/* ── 语音按钮 ──────────────────────────────────── */
.voice-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.voice-btn:hover { background: var(--bg); transform: scale(1.05); }
.voice-btn:active { transform: scale(0.95); }

/* ── AI 免责声明 ─────────────────────────────── */
.ai-disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  padding-top: 8px;
  user-select: none;
}

.voice-btn.recording {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: pulse-rec 1.5s ease-in-out infinite;
}
@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
/* 激活中：按下立刻反馈，告诉用户"正在初始化麦克风" */
.voice-btn.activating {
  border-color: #f59e0b;
  animation: pulse-activating 0.6s ease-in-out infinite;
}
@keyframes pulse-activating {
  0%, 100% { background: var(--card); }
  50% { background: #fef3c7; }
}

/* ── 语音状态条 ───────────────────────────────── */
.voice-status {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  animation: fadeIn 0.2s;
  z-index: 10;
}
.voice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

/* ── TTS 播放按钮 ─────────────────────────────── */
.tts-play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 50%;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  margin-left: 8px;
  flex-shrink: 0;
}
.message:hover .tts-play-btn,
.tts-play-btn.playing {
  opacity: 1;
  pointer-events: auto;
}
.tts-play-btn:hover { background: var(--bg); }

/* ══════════════════════════════════════════════════════════════
   V2 布局：侧栏 + 主内容区 (Doubao-style)
   ══════════════════════════════════════════════════════════════ */

:root {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 60px;
  --chat-header-height: 52px;
}

/* ── App Shell ────────────────────────────────── */
#appShell {
  display: none;
  height: 100dvh;
  overflow: hidden;
}
#appShell.active {
  display: flex;
}

/* ── 侧栏遮罩 (mobile) ────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 499;
}
.sidebar-overlay.active {
  display: block;
}

/* ── 侧栏 ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100dvh;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease;
  overflow: hidden;
  z-index: 100;
}

/* PC 折叠态 */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .sidebar-logo-sub,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .sidebar-sessions,
.sidebar.collapsed .sidebar-batch-bar {
  display: none;
}
.sidebar.collapsed .sidebar-new-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  margin: 0 auto;
}
.sidebar.collapsed .sidebar-top {
  align-items: center;
  padding: 12px 8px;
}
.sidebar.collapsed .sidebar-logo img {
  margin: 0 auto;
}
.sidebar.collapsed .sidebar-bottom {
  align-items: center;
  padding: 8px 4px;
}
.sidebar.collapsed .sidebar-bottom-btn {
  justify-content: center;
  padding: 8px;
}

/* ── 侧栏顶部 ─────────────────────────────────── */
.sidebar-top {
  padding: 16px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  display: block;
  line-height: 1.3;
}
.sidebar-logo-sub {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  display: block;
}
.sidebar-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  width: 100%;
}
.sidebar-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}
.sidebar-label {
  white-space: nowrap;
  overflow: hidden;
}

/* ── 侧栏搜索 ─────────────────────────────────── */
.sidebar-search {
  padding: 0 16px 8px;
  position: relative;
  flex-shrink: 0;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.sidebar-search input:focus {
  border-color: var(--primary);
}
.sidebar-search button {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 2px 6px;
}

/* ── 批量操作栏 ───────────────────────────────── */
.sidebar-batch-bar {
  display: none;
  padding: 8px 12px;
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.batch-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  flex-wrap: wrap;
}
.batch-bar-row .btn-sm {
  font-size: 11px;
  padding: 3px 8px;
}

/* ── 侧栏会话列表 ─────────────────────────────── */
.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
  -webkit-overflow-scrolling: touch;
}

/* 侧栏中的会话项更紧凑 */
.sidebar .session-item {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: none;
  background: transparent;
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar .session-item:hover {
  background: var(--primary-light);
}
.sidebar .session-item.active-session {
  background: var(--primary-light);
  border: 1px solid var(--primary);
}
.sidebar .session-item-title {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  margin-bottom: 4px;
}
.sidebar .session-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
}
.sidebar .session-item-date {
  font-size: 11px;
  color: var(--text-secondary);
}
.sidebar .session-item-delete-btn {
  font-size: 13px;
  width: 24px;
  height: 24px;
  padding: 2px 0;
}
.sidebar .session-item-menu {
  /* ⋮ 菜单按钮 — 点击弹出重命名/置顶/删除 */
}

/* ── 侧栏底部 ─────────────────────────────────── */
.sidebar-bottom {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-bottom-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
  height: 48px;
}
.sidebar-bottom-btn:hover {
  background: var(--primary-light);
  color: var(--text);
}

/* ── 主内容区 ─────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  background: var(--bg);
}
.main-content .page {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.main-content .page.active {
  display: flex;
}

/* ── Chat Header ──────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  height: var(--chat-header-height);
  padding: 0 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
.chat-header-left,
.chat-header-right {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.chat-header-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  overflow: hidden;
}
.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.chat-disclaimer {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.chat-header-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s;
  flex-shrink: 0;
}
.chat-header-btn:hover {
  background: var(--bg);
}

/* ── Menu Dropdown ────────────────────────────── */
.menu-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: 300;
  overflow: hidden;
}
.menu-dropdown.show {
  display: block;
}
.menu-item {
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
  white-space: nowrap;
}
.menu-item:hover {
  background: var(--bg);
}
.menu-item.danger {
  color: var(--danger);
}
.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
  pointer-events: none;
}

.chat-header-right {
  position: relative;
}

/* ── 全局 page 调整（不再作为 body 直子） ──────── */
body { overflow: hidden; }
.page { display: none; }  /* 旧选择器保持兼容 */
.page.active { display: flex; }

/* ── Login page 不受影响 ──────────────────────── */
#loginPage {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
#loginPage.active {
  display: flex;
}

.login-beian {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}
.login-beian a {
  color: var(--text-secondary);
  text-decoration: none;
}
.login-beian a:hover {
  color: var(--primary-dark);
}

/* ══════════════════════════════════════════════════════════════
   Responsive
   ══════════════════════════════════════════════════════════════ */

/* Mobile: 侧栏变抽屉 */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  /* 手机上不折叠为图标模式，只做抽屉 */
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  #mainContent {
    margin-left: 0;
  }

  .chat-header-left {
    gap: 0;
  }
}

/* PC: 侧栏始终可见 */
@media (min-width: 769px) {
  .sidebar-overlay {
    display: none !important;
  }
  .sidebar {
    position: relative;
    transform: translateX(0) !important;
  }
  #mainContent {
    min-width: 0;
  }
}

