/* ============ 主题变量（浅色默认 + 深色 OLED 覆盖） ============ */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f2f3f5;
  --surface-3: #e8eaef;
  --text: #1f2329;
  --text-2: #4e5969;
  --text-3: #8f959e;
  --border: #e5e6eb;
  --border-soft: #ececec;
  --primary: #1e6eff;
  --primary-hover: #0062e6;
  --primary-soft: #e8f0fe;
  --primary-soft-hover: #f5f9ff;
  --bubble-user: #eef1f4;        /* 用户气泡：低饱和灰蓝（区别于品牌蓝系） */
  --bubble-user-text: var(--text);
  --primary-text: #1a4ec9;
  --primary-disabled: #c5d3f5;
  --primary-shadow: rgba(30, 110, 255, 0.10);
  --brand: #1e3a8a;
  --ok: #2ba471;
  --err: #e53e3e;
  --mask: rgba(0, 0, 0, 0.40);
  --shadow-brand: 0 2px 8px rgba(37, 99, 235, 0.28);
  --shadow-brand-lg: 0 8px 24px rgba(37, 99, 235, 0.30);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05), 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --toast-bg: #1f2329;
  --toast-text: #ffffff;
  --thumb-remove-bg: #333333;
  --watermark: #1f2329;
  --sidebar-bg: #f9fafb;         /* 侧栏底色（DeepSeek #F9FAFB） */
  --sb-pill: #ffffff;            /* 新对话胶囊/悬浮胶囊底色 */
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #1a1a1a;
  --surface-3: #2a2a2a;
  --text: #ffffff;
  --text-2: #a8a8a8;
  --text-3: #6e6e6e;
  --border: #2a2a2a;
  --border-soft: #1f1f1f;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: #0e1e3a;
  --primary-soft-hover: #14254a;
  --bubble-user: #23272d;        /* 深色用户气泡：低饱和暗灰 */
  --bubble-user-text: var(--text);
  --primary-text: #93c5fd;
  --primary-disabled: #1e3a5f;
  --primary-shadow: rgba(59, 130, 246, 0.20);
  --brand: #93c5fd;
  --ok: #4ade80;
  --err: #f87171;
  --mask: rgba(0, 0, 0, 0.65);
  --shadow-brand: 0 2px 8px rgba(59, 130, 246, 0.35);
  --shadow-brand-lg: 0 8px 24px rgba(59, 130, 246, 0.35);
  --shadow-modal: 0 16px 48px rgba(0, 0, 0, 0.60);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.55);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.4);
  --toast-bg: #ffffff;
  --toast-text: #000000;
  --thumb-remove-bg: #a8a8a8;
  --watermark: #ffffff;
  --sidebar-bg: #101010;
  --sb-pill: #1c1c1e;
}

/* ============ 基础 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ============ 斜向水印 ============ */
.watermark {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.watermark-inner {
  position: absolute;
  inset: -50%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 80px 40px;
  transform: rotate(-22deg);
  opacity: 0.07;
}
.watermark-inner span {
  font-size: 18px;
  color: var(--watermark);
  white-space: nowrap;
  text-align: center;
  user-select: none;
}

/* ============ 品牌（logo 常驻侧栏顶部，折叠态在悬浮胶囊；主区无顶栏） ============ */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
  user-select: none;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-brand);
  flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name {
  font-size: 1.1em;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--brand);
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Source Han Sans SC', 'Noto Sans SC', sans-serif;
  line-height: 1;
  white-space: nowrap;
}

/* ============ 主区域 ============ */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: row;   /* 左会话栏 + 右工作区 */
  height: 100vh;
  height: 100dvh;   /* 动态视口：手机键盘弹起时自动缩小，输入框始终在可见区，避免整个页面被推上去；老浏览器回落 100vh */
}

/* ============ 左侧会话栏（照抄 chat.deepseek.com 实测规格） ============ */
/* 实测：宽261 背景#F9FAFB 内边距6/12 无右边框；条目高40 圆角12 hover#F1F3F5；
   分组标签12px/#81858C；新对话=白底胶囊(radius100,高40,微阴影)；主区无顶栏 */
.sidebar {
  flex-shrink: 0;
  width: 261px;
  display: flex;
  flex-direction: column;
  padding: 0 12px;
  background: var(--sidebar-bg);
  overflow: hidden;
  transition: margin-left .25s ease, opacity .2s ease;
}
/* 顶部行：返回（有上一页才显示，JS 控制）+ 收起按钮（恒靠右） */
.sb-top {
  display: flex; align-items: center; justify-content: flex-start; gap: 8px;
  padding: 14px 0 10px 4px;
  flex-shrink: 0;
}
.sb-back {
  flex-shrink: 0; width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-2); cursor: pointer; transition: background .15s, color .15s;
}
.sb-back:hover { background: var(--surface-2); color: var(--text); }
.sb-collapse {
  flex-shrink: 0; width: 34px; height: 34px; margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-2); cursor: pointer; transition: background .15s, color .15s;
}
.sb-collapse:hover { background: var(--surface-2); color: var(--text); }
/* 新对话：DeepSeek 白底胶囊（高40/radius100/无边框/微投影） */
.sb-new {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 40px; padding: 0 16px;
  background: var(--sb-pill); border: none; border-radius: 100px;
  font-size: 0.875em; font-weight: 500; color: var(--text); cursor: pointer; font-family: inherit;
  box-shadow: 0 -2px 2px rgba(72,104,178,0.04), 0 2px 2px rgba(106,111,117,0.09), 0 1px 2px rgba(72,104,178,0.08);
  transition: background .15s;
}
:root[data-theme="dark"] .sb-new { box-shadow: none; }
.sb-new:hover { background: var(--surface-2); }
.sb-new svg { flex-shrink: 0; }
/* 滚动条独立成列：负右边距把滚动条推到侧栏最右缘，
   内容再留 20px 右空隙 → 条目文字与滚动条之间隔出一条专属空隙列 */
/* 滚动条平时隐藏（thumb 透明），滚动中由 JS 挂 .scrolling 显形，停止 800ms 后隐去 */
.sb-list {
  flex: 1;
  overflow-y: auto;
  margin-right: -12px;
  padding: 10px 20px 0 0;
  scrollbar-width: thin;                                   /* Firefox */
  scrollbar-color: transparent transparent;
}
.sb-list.scrolling {
  scrollbar-color: var(--surface-3) transparent;
}
.sb-list::-webkit-scrollbar { width: 6px; }
.sb-list::-webkit-scrollbar-track { background: transparent; }
.sb-list::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
.sb-list.scrolling::-webkit-scrollbar-thumb { background: var(--surface-3); }
.sb-list.scrolling::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
.sb-group { font-size: 0.75em; font-weight: 500; color: var(--text-3); padding: 2px 10px; margin: 18px 0 4px; line-height: 18px; }
.sb-item {
  height: 42px; display: flex; align-items: center;
  margin-bottom: 2px;
  padding: 0 6px 0 10px; border-radius: 12px; font-size: 0.875em; color: var(--text);
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .12s;
}
.sb-item:hover { background: var(--surface-2); }
.sb-item.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.sb-empty { font-size: 0.8em; color: var(--text-3); text-align: center; padding: 24px 0; }
.sb-mask { display: none; }

/* ===== 栏底设置入口（DeepSeek 用户行式）+ 向上弹出菜单 ===== */
.sb-footer { flex-shrink: 0; position: relative; padding: 6px 0 10px; }
.sb-set {
  width: 100%; height: 40px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px; border: none; border-radius: 12px;
  background: transparent; color: var(--text-2);
  font-size: 0.875em; font-family: inherit; cursor: pointer;
  transition: background .12s, color .12s;
}
.sb-set:hover { background: var(--surface-2); color: var(--text); }
.sb-set-icon { flex-shrink: 0; }
/* 弹出菜单（DeepSeek 菜单皮：白底/圆角12/内边距4/三层投影，item 高40 圆角8） */
.sb-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 0 1px rgba(0,0,0,0.2), 0 0 4px rgba(0,0,0,0.02), 0 12px 32px rgba(0,0,0,0.08);
  z-index: 1001;
}
.sb-menu.show { display: block; }

/* ===== 折叠态/窄屏：左上角悬浮胶囊（返回/新建/設置/展开 四钮） ===== */
.sb-float {
  position: fixed;
  top: 12px; left: 16px;
  z-index: 70;
  height: 40px;
  display: none;
  align-items: center; gap: 2px;
  padding: 0 6px 0 4px;
  background: var(--sb-pill);
  border: 1px solid var(--border-soft);
  border-radius: 100px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.04);
  font-family: inherit;
}
.sf-btn {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); cursor: pointer;
  transition: background .12s, color .12s;
  user-select: none;
}
.sf-btn:hover { background: var(--surface-2); color: var(--text); }
.sf-btn svg { flex-shrink: 0; }
/* 折叠态的设置菜单：挂在胶囊正下方 */
.sb-float .sb-menu {
  position: absolute;
  bottom: auto;
  top: calc(100% + 6px);
  left: 0;
}

/* 工作区（顶栏+主区+输入区的纵向容器） */
.workspace {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* 窄屏/折叠入口：悬浮胶囊常显逻辑
   桌面(≥1024)：默认隐藏，.app.sb-collapsed 时显示；侧栏用负 margin 滑出
   窄屏(<1024)：常显（侧栏默认抽屉态隐藏），抽屉打开时由 JS 加 .hide 隐藏 */
.sb-float { display: none; }
.sb-float.hide { display: none !important; }

/* 桌面：可折叠（侧栏内收起钮 + 悬浮胶囊展开钮） */
@media (min-width: 1024px) {
  .app.sb-collapsed .sidebar { margin-left: -261px; opacity: 0; pointer-events: none; }
  .app.sb-collapsed .sb-float { display: inline-flex; }
}

@media (max-width: 1023px) {
  .sb-float { display: inline-flex; }
  .sb-float.hide { display: none; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 80;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 24px rgba(0,0,0,0.18);
  }
  .sidebar.open { transform: none; }
  .sb-mask {
    display: block; position: fixed; inset: 0; z-index: 75;
    background: rgba(0,0,0,0.4);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .sb-mask.show { opacity: 1; pointer-events: auto; }
}
.main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ============ Hero（启动态） ============ */
.hero {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  overflow-y: auto;
  opacity: 0;            /* 默认未就绪隐藏，等 bootstrap 拿到完整内容后加 .ready 显示，避免启动三段跳变 */
  transition: opacity 0.25s;
}
.hero.ready { opacity: 1; }
.hero.hidden { opacity: 0; pointer-events: none; }

.hero-avatar {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
  box-shadow: var(--shadow-brand-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}
.hero-avatar svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hero-name {
  font-size: 1.4em;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.hero-greeting {
  max-width: 560px;
  text-align: center;
  color: var(--text-2);
  font-size: 1em;
  line-height: 1.7;
  margin-bottom: 28px;
  white-space: pre-wrap;
}

.examples {
  list-style: none;
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.example-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  user-select: none;
}
.example-item:hover {
  background: var(--surface-3);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.example-item:active {
  transform: scale(0.99);
}
.example-icon {
  width: 22px; height: 22px;
  flex-shrink: 0;
  border-radius: 4px;
  background: linear-gradient(135deg, #b8c5ff 0%, #8b9eff 100%);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.example-text {
  flex: 1;
  color: var(--text);
  font-size: 1em;
  line-height: 1.5;
}
.example-arrow {
  color: var(--text-3);
  font-size: 1em;
  flex-shrink: 0;
}

/* ============ Chat（对话态） ============ */
.chat {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.chat.active { display: flex; }

.chat-header {
  display: none; /* 顶栏已有「泰帮帮」图标+名称，对话态不再重复显示标题栏 */
}
.chat-header .mini-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E") center/16px no-repeat, linear-gradient(135deg, #2563eb 0%, #0ea5e9 100%);
  flex-shrink: 0;
}
.chat-header .mini-name {
  font-size: 1em;
  font-weight: 500;
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;   /* 兜底：禁止横向滚动条，内容在 .content 内自适应换行 */
  padding: 24px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }

.msg {
  margin-bottom: 22px;
  animation: fadein 0.3s ease;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user {
  display: flex;
  justify-content: flex-end;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  padding: 10px 14px;
  border-radius: 14px 14px 2px 14px;
  max-width: 78%;
  word-wrap: break-word;
  overflow-wrap: anywhere; /* 同 AI 回复，防止用户粘贴长串/表格撑宽 */
  font-size: 1em;
}
.msg.user .bubble .q-text { display: block; }
.msg.user .bubble .thumb {
  margin-top: 8px;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  display: block;
  cursor: pointer;
}

.msg.ai {
  display: flex;
  align-items: flex-start;
}
.msg.ai .content {
  flex: 1;
  min-width: 0;            /* 解除 flex 子项 min-width:auto 限制，允许收缩到 flex:1 宽度 */
  color: var(--text);
  font-size: 1em;
  padding: 2px 0;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere; /* 能在任意不可断串（表格分隔行 |---|、===== 等）处换行，避免撑宽溢出 */
}
.msg.ai .content .cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--primary);
  vertical-align: middle;
  animation: blink 1s infinite;
  margin-left: 2px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

.status-line {
  font-size: 0.75em;
  color: var(--text-3);
  padding: 2px 0 6px 40px;
  font-family: "Consolas", monospace;
}
.status-line.err { color: var(--err); }

/* 状态块：回答过程逐步展示进度（已建立连接/调用知识库…），完成后折叠，点击标题展开 */
.status-block { padding-left: 40px; margin: 2px 0 8px; font-family: "Consolas", monospace; font-size: 0.75em; }
.status-head { color: var(--text); cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 5px; font-weight: 500; }
.status-head::before { content: "▸"; color: var(--text-3); font-size: 14px; transition: transform .2s; }
.status-block:not(.collapsed) .status-head::before { transform: rotate(90deg); }
.status-list { margin-top: 3px; }
.status-list .status-line { padding: 1px 0; }
.status-list .status-line.ok { color: var(--ok); }
.status-block.collapsed .status-list { display: none; }
.status-line.ok { color: var(--ok); }

/* ============ 参考来源（AI 回答引用的知识库文档）============ */
.refs-box { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.refs-title { font-size: 0.75em; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.refs-list { display: flex; flex-direction: column; gap: 3px; }

/* ===== 文件卡片（参考来源：微信文件消息式，类型图标+文件名+来源+下载键） ===== */
.file-list { gap: 6px; }
.file-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, transform .12s;
}
.file-card:hover { background: var(--surface-2); border-color: var(--primary); transform: translateY(-1px); }
.file-card .fc-icon {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.62em; font-weight: 800; letter-spacing: 0.5px; color: #fff;
}
.fc-pdf  { background: linear-gradient(135deg, #ff7a70, #f04438); }
.fc-doc  { background: linear-gradient(135deg, #5b9dff, #2f6bd8); }
.fc-xls  { background: linear-gradient(135deg, #34c77b, #1f9d55); }
.fc-ppt  { background: linear-gradient(135deg, #ffb057, #f07f1f); }
.fc-txt  { background: linear-gradient(135deg, #8f9bb3, #5f6b82); }
.fc-etc  { background: linear-gradient(135deg, #a78bfa, #7c5cd6); }
.file-card .fc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-card .fc-name { font-size: 0.8em; font-weight: 600; color: var(--text); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-meta { font-size: 0.7em; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-dl {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: rgba(0, 102, 255, 0.1); color: var(--primary);
  display: inline-flex; align-items: center; justify-content: center;
}
.file-card .fc-dl svg { width: 14px; height: 14px; }
/* 内嵌句中的文件卡片（正文链接非独占段落时） */
.file-card.inline { display: inline-flex; max-width: 100%; vertical-align: middle; margin: 2px 0; }

/* ===== 设置菜单里的调试日志按钮 ===== */
.log-open-btn {
  display: block; width: 100%; padding: 8px 10px; margin-top: 2px;
  background: transparent; border: none; border-radius: 8px;
  font-size: 0.82em; color: var(--text); text-align: left; cursor: pointer;
  font-family: inherit; transition: background .15s;
}
.log-open-btn:hover { background: var(--surface-2); }

/* ============ 推荐问题（💡 猜你想问）============ */
.recm-box { margin-top: 14px; padding-top: 10px; }
.recm-title { font-size: 0.75em; color: var(--text-2); font-weight: 600; margin-bottom: 8px; }
.recm-list { display: flex; flex-wrap: wrap; gap: 8px; }
.recm-item { font-family: inherit; font-size: 0.8em; color: var(--primary); background: var(--primary-soft, rgba(59,130,246,.08)); border: 1px solid var(--primary); border-radius: 16px; padding: 6px 14px; cursor: pointer; line-height: 1.4; transition: background .15s, color .15s; }
.recm-item:hover { background: var(--primary); color: #fff; }

/* ============ AI 回答 markdown 渲染（表格/列表/标题/粗体）============ */
.msg.ai .content { overflow-x: auto; }
/* marked 渲染后切 normal：marked 输出的 HTML 标签间含字面 \n，pre-wrap 下会变成可见空行
   （finishAiMessage 完成渲染时加 .rendered）；流式纯文本阶段仍用默认 pre-wrap 显示 \n 换行 */
.msg.ai .content.rendered { white-space: normal; }
.msg.ai .content table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 0.8em; }
.msg.ai .content th, .msg.ai .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg.ai .content th { background: var(--surface-2, rgba(0,0,0,.04)); font-weight: 600; }
.msg.ai .content h1, .msg.ai .content h2, .msg.ai .content h3, .msg.ai .content h4 { font-size: 0.95em; font-weight: 700; margin: 12px 0 6px; line-height: 1.4; }
.msg.ai .content ul, .msg.ai .content ol { padding-left: 22px; margin: 6px 0; }
.msg.ai .content li { margin: 3px 0; line-height: 1.6; }
.msg.ai .content strong { font-weight: 700; }
.msg.ai .content code { background: var(--surface-2, rgba(0,0,0,.05)); padding: 1px 5px; border-radius: 3px; font-family: "Consolas", monospace; font-size: 0.75em; }
.msg.ai .content pre { background: var(--surface-2, rgba(0,0,0,.05)); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
.msg.ai .content pre code { background: transparent; padding: 0; }
.msg.ai .content p { margin: 6px 0; line-height: 1.7; }
.msg.ai .content blockquote { border-left: 3px solid var(--border); padding-left: 12px; margin: 8px 0; color: var(--text-2); }

/* ===== 表格卡片 + 工具条（照抄 DeepSeek 安卓 app：顶部条 左"表格"标签 + 右 复制/下载） ===== */
.tbl-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;       /* 圆角裁掉表格直角 */
  margin: 10px 0;
  background: var(--surface);
}
.tbl-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.tbl-label {
  font-size: 12px;
  color: var(--text-3);
  margin-right: auto;
  user-select: none;
}
.tbl-btn {
  display: inline-flex; align-items: center; gap: 4px;
  border: none; background: transparent;
  color: var(--text-2); font-size: 12px;
  padding: 4px 8px; border-radius: 8px;
  cursor: pointer; font-family: inherit;
  transition: background .12s, color .12s;
}
.tbl-btn:hover { background: var(--surface-3); color: var(--text); }
.tbl-btn svg { flex-shrink: 0; }
/* 卡片内的表格：去掉自身外边距，行线保留、外框由卡片负责（选择器加权盖过 .msg.ai .content table） */
.msg.ai .content .tbl-card table { border: none; margin: 0; width: 100%; }
.msg.ai .content .tbl-card table th,
.msg.ai .content .tbl-card table td { border: none; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
.msg.ai .content .tbl-card table th:last-child,
.msg.ai .content .tbl-card table td:last-child { border-right: none; }
.msg.ai .content .tbl-card table tr:last-child td { border-bottom: none; }
.msg.ai .content .tbl-card table th { background: transparent; }

/* ============ 底部 composer ============ */

/* ===== 模式下拉/知识库胶囊（已下线）=====
   .mode-menu/.mode-option 样式保留：分享菜单(share.js)复用这两组类 */
.mode-menu { position: absolute; bottom: calc(100% + 6px); left: 0; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); padding: 6px; z-index: 30; }
.mode-option { display: flex; flex-direction: column; padding: 8px 12px; border-radius: 10px; cursor: pointer; transition: background .12s; }
.mode-option:hover { background: var(--surface-2); }
.mode-option b { font-size: 0.9em; font-weight: 600; color: var(--text); }
.mode-option span { font-size: 0.78em; color: var(--text-3); margin-top: 2px; }

/* 分享/导出菜单：挂 body，fixed 定位由 JS 计算
   ⚠️ 必须置 bottom:auto：复用的 .mode-menu 带 bottom:calc(100%+6px)，fixed 下会同时满足
   top(JS 内联)+bottom(CSS) 把面板拉伸到整个视口高，边界跑到屏幕外（表现为"没底色看不到边界"） */
.share-menu { position: fixed; bottom: auto; }
.share-menu .mode-option b { font-size: 0.85em; font-weight: 600; }

/* ===== 思考状态指示器 + 思考面板 ===== */
.thought-wrapper {
  max-width: 820px;
  margin: 12px auto 4px;
  padding: 0 24px;
}
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
}
.thinking-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  flex-shrink: 0;
}
.thinking-wave span {
  display: block;
  width: 3px;
  height: 6px;
  border-radius: 3px;
  background: var(--primary, #3b82f6);
  animation: thinking-wave 2s ease-in-out infinite;
}
.thinking-wave span:nth-child(1) { animation-delay: 0s; }
.thinking-wave span:nth-child(2) { animation-delay: 0.25s; }
.thinking-wave span:nth-child(3) { animation-delay: 0.5s; }
@keyframes thinking-wave {
  0%, 100% { height: 8px; opacity: 0.3; }
  50% { height: 28px; opacity: 1; }
}
.thinking-body { display: flex; align-items: center; }
.thinking-text {
  font-size: 0.9em;
  color: var(--text-2);
  transition: opacity .3s;
}

/* 工具分段步骤条（每步一行，进行中呼吸点→完成灰点+耗时） */
.thought-steps {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 6px 0 2px;
}
.tool-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82em;
  color: var(--text-3);
}
.tool-step .step-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.tool-step.running .step-dot { background: var(--primary); animation: stepPulse 1.2s ease-in-out infinite; }
.tool-step.running .step-label { color: var(--primary); }
.tool-step.done .step-dot { background: var(--text-3); }
.tool-step .step-time { opacity: 0.75; font-variant-numeric: tabular-nums; }
@keyframes stepPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* 思考面板（折叠展开） */
.thought-panel {
  margin-top: 8px;
  border-radius: 12px;
  background: var(--surface-2);
  overflow: hidden;
}
.thought-panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.82em;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.thought-panel-head:hover { background: var(--surface-3); }
.thought-panel-icon { font-size: 14px; }
.thought-panel-title { font-weight: 500; }
.thought-panel-toggle {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-3);
  opacity: 0.6;
}
.thought-panel-body {
  padding: 6px 14px 12px;
  font-size: 0.82em;
  line-height: 1.7;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid var(--border-soft);
}
.thought-agent-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary, #3b82f6);
  margin: 8px 0 4px;
}
/* AI 消息底部操作行（复制等；常显小字，手机无 hover 也可用） */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-3);
  background: transparent;
  border: none;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.msg-action-btn:hover { background: var(--surface-2); color: var(--text); }
.msg-action-btn.active { color: var(--primary); background: var(--primary-soft); }

.composer-area {
  flex-shrink: 0;
  padding: 12px 24px 12px;
  background: transparent;
}
.composer-box {
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-shadow);
}

.composer-thumb {
  position: relative;
  margin-right: 4px;
}
.composer-thumb img {
  width: 44px; height: 44px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.composer-thumb .remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--thumb-remove-bg);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.upload-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.upload-btn:hover { background: var(--surface-2); color: var(--text); }
.upload-btn svg { width: 20px; height: 20px; }

textarea#input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 1em;
  line-height: 1.6;
  max-height: 120px;
  padding: 7px 4px;
  background: transparent;
  color: var(--text);
}
textarea#input::placeholder { color: var(--text-3); }

.send-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.send-btn:disabled { background: var(--primary-disabled); cursor: not-allowed; }
.send-btn:active:not(:disabled) { transform: scale(0.94); }
.send-btn svg { width: 18px; height: 18px; }
/* 发送↔停止双态图标切换（流式中变 ■ 停止键） */
.send-btn .icon-stop { display: none; }
.send-btn.stopping { background: var(--text); color: var(--bg); }
.send-btn.stopping .icon-send { display: none; }
.send-btn.stopping .icon-stop { display: block; width: 14px; height: 14px; }
:root[data-theme="dark"] .send-btn.stopping { background: #fff; color: #111; }

.composer-footer {
  max-width: 820px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}
.composer-footer a {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
.composer-footer a:hover { text-decoration: underline; }

/* ============ 响应式适配 ============ */
/* 平板 (768-1024px)：紧凑间距 */
@media (max-width: 1024px) {
  .composer-area { padding: 10px 16px 10px; }
  .messages { padding: 20px 18px; }
}

/* 手机 (≤767px)：单列紧凑布局 */
@media (max-width: 767px) {
  body { font-size: var(--fs); }
  .sb-float { top: calc(10px + env(safe-area-inset-top, 0px)); left: 10px; }
  .brand-name { font-size: 1em; letter-spacing: 1.5px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; }
  .brand-mark svg { width: 16px; height: 16px; }

  /* hero：紧凑 */
  .hero { padding: 16px; }
  .hero-avatar { width: 60px; height: 60px; margin-bottom: 14px; }
  .hero-avatar svg { width: 32px; height: 32px; }
  .hero-name { font-size: 1.25em; margin-bottom: 8px; }
  .hero-greeting { font-size: 1em; line-height: 1.65; margin-bottom: 20px; }
  .examples { gap: 8px; }
  .example-item { padding: 10px 12px; gap: 10px; }
  .example-text { font-size: 1em; line-height: 1.45; }
  .example-icon { width: 20px; height: 20px; font-size: 11px; }

  /* chat 态：紧凑 */
  .chat-header { padding: 10px 14px; }
  .chat-header .mini-avatar { width: 26px; height: 26px; }
  .chat-header .mini-name { font-size: 1em; }
  .messages { padding: 14px 12px; }
  .msg.user .bubble { font-size: 1em; padding: 8px 12px; max-width: 85%; }
  .msg.ai .content { font-size: 1em; }
  .status-line { padding-left: 36px; font-size: 0.7em; }

  /* composer：紧凑 */
  .composer-area { padding: 8px 10px 8px; }
  .composer-box { border-radius: 14px; padding: 6px 6px 6px 10px; }
  textarea#input { font-size: 1em; max-height: 100px; }
  .composer-footer { font-size: 0.7em; margin-top: 6px; padding: 0 4px; }

  /* 水印：字号小一点，密度稀一点，避免在小屏太挤 */
  .watermark-inner { gap: 60px 24px; }
  .watermark-inner span { font-size: 1em; }
}

/* 极窄屏 (≤360px)：进一步压缩 */
@media (max-width: 360px) {
  .hero-name { font-size: 1em; }
  .example-text { font-size: 12px; }
  .messages { padding: 10px 8px; }
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 999;
}
.toast.show { opacity: 1; }

/* ============ 设置菜单内容（主题/字号分段控件；外壳 .sb-menu 见侧栏段） ============ */
.set-section { padding: 6px 8px; margin-bottom: 8px; }
.set-section:last-child { margin-bottom: 0; }
.set-label {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 6px;
  font-weight: 500;
}
.theme-segments {
  display: flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.theme-seg {
  flex: 1;
  padding: 7px 6px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  white-space: nowrap;
  font-family: inherit;
}
.theme-seg:hover { color: var(--text); }
.theme-seg.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
/* ============ 字号（只调文字大小，布局/输入框位置不变，三档） ============ */
:root { --fs: 16px; }
:root[data-fontsize="small"] { --fs: 13px; }
:root[data-fontsize="large"] { --fs: 22px; }

/* 角色选择弹层（已下线） */

/* 调试日志面板（🪵 按钮触发）*/
.log-panel { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(.96);
  width: min(92vw, 640px); max-height: 80vh; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25); z-index: 1000; font-size: 0.82em; }
.log-panel.show { display: flex; transform: translate(-50%, -50%) scale(1); }
.log-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border-soft); color: var(--text-2); }
.log-head-btns button { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px; cursor: pointer; color: var(--text-2); font-size: .95em; margin-left: 4px; }
.log-head-btns button:hover { border-color: var(--primary); color: var(--primary); }
.log-body { overflow-y: auto; padding: 8px 14px; }
.log-row { padding: 6px 0; border-bottom: 1px dashed var(--border-soft); white-space: pre-wrap; word-break: break-word; color: var(--text-2); line-height: 1.6; }
.log-row.warn { color: #DC2626; background: rgba(220,38,38,.05); padding: 8px; border-radius: 6px; }
.log-empty { padding: 24px; text-align: center; color: var(--text-3); }
