/* ============================================================
   可达搜素（deepseekv4.1） · 聊天界面样式（对标 DeepSeek 官网视觉语言）
   ============================================================ */
:root {
  --brand: #4d6bfe;
  --brand-hover: #3d5ce8;
  --radius: 12px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
          system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, "Courier New", monospace;
}

/* ---------------- 深色主题（默认） ---------------- */
html[data-theme="dark"] {
  --bg: #1b1c1f;
  --bg-elev: #212327;
  --sidebar-bg: #17181b;
  --sidebar-hover: #232529;
  --sidebar-active: #2a2d33;
  --text: #e8e9ec;
  --text-soft: #b4b7bf;
  --text-dim: #85888f;
  --line: #2c2f35;
  --line-soft: #24272c;
  --bubble-user: #2f3238;
  --code-bg: #16171a;
  --code-head: #1e2024;
  --inline-code-bg: #2a2d33;
  --tool-bg: #1f2226;
  --shadow: 0 8px 32px rgba(0, 0, 0, .45);
  --scrollbar: #3a3d44;
}

/* ---------------- 浅色主题 ---------------- */
html[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #ffffff;
  --sidebar-bg: #f7f8fa;
  --sidebar-hover: #eceef2;
  --sidebar-active: #e2e5eb;
  --text: #1f2329;
  --text-soft: #4e5969;
  --text-dim: #86909c;
  --line: #e5e6eb;
  --line-soft: #f0f1f4;
  --bubble-user: #eef0f4;
  --code-bg: #f6f7f9;
  --code-head: #eceef2;
  --inline-code-bg: #f2f3f5;
  --tool-bg: #f7f8fa;
  --shadow: 0 8px 32px rgba(31, 35, 41, .14);
  --scrollbar: #c9cdd4;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand); }

/* ============================ 布局 ============================ */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------- 侧边栏 ---------------------------- */
.sidebar {
  width: 268px;
  flex: 0 0 268px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease, opacity .22s ease;
}
.app.sb-collapsed .sidebar {
  margin-left: -268px;
  opacity: 0;
  pointer-events: none;
}

.sb-head { padding: 14px 12px 8px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c8ffd);
  color: #fff; font-weight: 700; font-size: 16px;
  display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(77, 107, 254, .35);
}
.brand-name { font-weight: 600; font-size: 14.5px; letter-spacing: .2px; }
.brand-sub { font-size: 10.5px; color: var(--text-dim); letter-spacing: 1.2px; text-transform: uppercase; }

.btn-new {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s ease, transform .12s ease;
}
.btn-new:hover { background: var(--brand-hover); }
.btn-new:active { transform: scale(.985); }

.conv-scroll { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
.conv-group-title {
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 12px 8px 6px;
  letter-spacing: .3px;
}

.conv-list { display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-soft);
  cursor: pointer;
  position: relative;
  transition: background .13s ease, color .13s ease;
}
.conv-item:hover { background: var(--sidebar-hover); color: var(--text); }
.conv-item.active { background: var(--sidebar-active); color: var(--text); font-weight: 500; }
.conv-item .ci-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item .ci-del {
  opacity: 0;
  flex: 0 0 auto;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 5px;
  color: var(--text-dim);
  font-size: 13px;
  transition: opacity .12s ease, background .12s ease;
}
.conv-item:hover .ci-del { opacity: 1; }
.conv-item .ci-del:hover { background: rgba(255, 90, 90, .16); color: #ff6b6b; }

.conv-empty {
  padding: 18px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

.sb-foot {
  border-top: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.foot-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-soft);
  transition: background .13s ease, color .13s ease;
}
.foot-item:hover { background: var(--sidebar-hover); color: var(--text); }

/* ---------------------------- 主区 ---------------------------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  height: 52px;
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line-soft);
}
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--text-soft);
  transition: background .13s ease, color .13s ease;
}
.icon-btn:hover { background: var(--sidebar-hover); color: var(--text); }
.topbar-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 11.5px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  padding: 3px 8px;
  border-radius: 20px;
  font-family: var(--mono);
  white-space: nowrap;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: #9aa0a8; }
.dot.ok { background: #3ac569; box-shadow: 0 0 6px rgba(58, 197, 105, .6); }
.dot.bad { background: #ff6b6b; }

/* ---------------------------- 滚动区 ---------------------------- */
.scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
}

/* 欢迎屏 */
.welcome {
  max-width: 760px;
  margin: 0 auto;
  padding: 12vh 24px 40px;
  text-align: center;
  animation: fadeUp .5s ease both;
}
.welcome.hidden { display: none; }
.welcome-mark {
  width: 52px; height: 52px;
  margin: 0 auto 20px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--brand), #8a9bff);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 6px 22px rgba(77, 107, 254, .38);
}
.welcome-title {
  font-size: 27px;
  font-weight: 600;
  margin: 0 0 10px;
  letter-spacing: -.2px;
}
.welcome-sub { color: var(--text-dim); font-size: 14.5px; margin: 0 0 30px; }

.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  text-align: left;
}
.chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  font-size: 13.5px;
  color: var(--text-soft);
  background: var(--bg-elev);
  transition: border-color .15s ease, background .15s ease, transform .12s ease, color .15s ease;
}
.chip:hover {
  border-color: var(--brand);
  color: var(--text);
  background: var(--sidebar-hover);
  transform: translateY(-1px);
}
.chip-ico { font-size: 15px; }

/* ---------------------------- 消息 ---------------------------- */
.messages {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.msg { display: flex; flex-direction: column; animation: fadeUp .32s ease both; }

/* 用户消息 */
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  max-width: 82%;
  background: var(--bubble-user);
  border-radius: 16px 16px 4px 16px;
  padding: 11px 15px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
}

/* 助手消息 */
.msg.assistant .ai-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.ai-avatar {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--brand), #8a9bff);
  color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}
.ai-name { font-size: 13px; font-weight: 600; color: var(--text-soft); }

/* 本轮耗时标签：生成中跳动，结束后定格 */
.ai-timer {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: 2px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: var(--tool-bg);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  white-space: nowrap;
  transition: color .2s, border-color .2s;
}
.ai-timer-ico { font-size: 11px; line-height: 1; }
.ai-timer.live { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.ai-timer.live .ai-timer-ico { animation: timerPulse 1s ease-in-out infinite; }
@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-timer.live .ai-timer-ico { animation: none; }
}

.ai-body { padding-left: 32px; }

/* 思考过程 */
.reasoning {
  margin-bottom: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--tool-bg);
  overflow: hidden;
}
.reasoning-head {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  user-select: none;
  cursor: pointer;
}
.reasoning-head:hover { color: var(--text-soft); }
.reasoning-head .arrow { transition: transform .18s ease; display: inline-block; }
.reasoning.open .reasoning-head .arrow { transform: rotate(90deg); }
.reasoning-body {
  display: none;
  padding: 0 12px 10px;
  font-size: 13px;
  color: var(--text-dim);
  white-space: pre-wrap;
  border-top: 1px solid var(--line-soft);
  line-height: 1.75;
  max-height: 340px;
  overflow-y: auto;
}
.reasoning.open .reasoning-body { display: block; }

/* 工具调用卡片 */
.tools { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.tool {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 9px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--tool-bg);
  font-size: 12.8px;
  color: var(--text-soft);
  animation: fadeUp .25s ease both;
}
.tool .t-ico { flex: 0 0 auto; font-size: 14px; line-height: 1.4; }
.tool .t-main { flex: 1; min-width: 0; }
.tool .t-name { font-weight: 600; color: var(--text); font-family: var(--mono); font-size: 12px; }
.tool .t-sum { color: var(--text-dim); margin-top: 2px; word-break: break-word; }
.tool.running .t-sum::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: pulse 1s infinite ease-in-out;
}
.tool.err { border-color: rgba(255, 107, 107, .4); }
.tool.err .t-sum { color: #ff8f8f; }
.tool .t-src { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.tool .t-src a {
  color: var(--brand);
  font-size: 12px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool .t-src a:hover { text-decoration: underline; }

/* 文件卡片 */
.files { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-card {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-elev);
  transition: border-color .15s ease, transform .12s ease;
}
.file-card:hover { border-color: var(--brand); transform: translateY(-1px); }
.file-ico {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 17px;
  background: var(--sidebar-hover);
}
.file-info { flex: 1; min-width: 0; }
.file-name {
  font-size: 13.5px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }
.file-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.file-btn {
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--text-soft);
  transition: background .13s ease, color .13s ease, border-color .13s ease;
}
.file-btn:hover { background: var(--brand); border-color: var(--brand); color: #fff; }

/* 图片预览 */
.img-preview {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  background: var(--tool-bg);
}
.img-preview img { display: block; width: 100%; height: auto; }
.img-preview .ip-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--line-soft);
}

/* Markdown 排版 */
.md { font-size: 15px; line-height: 1.78; word-break: break-word; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-weight: 600; line-height: 1.4; margin: 22px 0 10px; }
.md h1 { font-size: 22px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 16.5px; }
.md h4 { font-size: 15px; }
.md p { margin: 10px 0; }
.md ul, .md ol { margin: 10px 0; padding-left: 24px; }
.md li { margin: 4px 0; }
.md li > p { margin: 4px 0; }
.md a { color: var(--brand); text-decoration: none; border-bottom: 1px solid transparent; }
.md a:hover { border-bottom-color: var(--brand); }
.md strong { font-weight: 600; }
.md em { font-style: italic; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }
.md blockquote {
  margin: 12px 0;
  padding: 6px 14px;
  border-left: 3px solid var(--brand);
  background: var(--tool-bg);
  color: var(--text-soft);
  border-radius: 0 8px 8px 0;
}
.md code.inline {
  background: var(--inline-code-bg);
  padding: 2px 5px;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 13px;
}
.md .table-wrap { overflow-x: auto; margin: 14px 0; }
.md table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 8px 11px; text-align: left; vertical-align: top; }
.md th { background: var(--sidebar-hover); font-weight: 600; }

/* 代码块 */
.codeblock {
  margin: 14px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--code-bg);
}
.codeblock-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px;
  background: var(--code-head);
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.copy-btn {
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 5px;
  transition: background .13s, color .13s;
}
.copy-btn:hover { background: var(--sidebar-hover); color: var(--text); }
.codeblock pre {
  margin: 0;
  padding: 13px 15px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 2;
}
.codeblock pre code { font-family: inherit; }

/* 数学公式（零依赖 LaTeX 子集渲染） */
.math {
  font-family: "Cambria Math", "Latin Modern Math", "STIX Two Math", Georgia, "Times New Roman", serif;
  font-size: 1.02em;
}
.math-display {
  margin: 14px 0;
  padding: 12px 16px;
  background: var(--tool-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  text-align: center;
  line-height: 2.2;
}
.math sup, .math sub { font-size: .72em; }
.math .frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  margin: 0 .2em;
}
.math .frac .fnum { border-bottom: 1px solid currentColor; padding: 0 .34em .06em; }
.math .frac .fden { padding: .06em .34em 0; }
.math .sqrt { white-space: nowrap; }
.math .sqrt > sup { font-size: .62em; margin-right: -.1em; }
.math .sqrt .rad { border-top: 1px solid currentColor; padding: 0 .2em; margin-left: .08em; }
/* \boxed{x} / \overline{x} / \hat{x} 等装饰命令 */
.math .mbox {
  display: inline-block;
  border: 1px solid currentColor;
  border-radius: 5px;
  padding: 0 .34em;
  margin: 0 .12em;
  line-height: 1.5;
}
.math .ovl { border-top: 1px solid currentColor; padding-top: .04em; }
.math .unl { border-bottom: 1px solid currentColor; padding-bottom: .04em; }
.math .acc { position: relative; display: inline-block; padding-top: .34em; }
.math .acc::before {
  position: absolute;
  top: -.16em;
  left: 50%;
  transform: translateX(-50%);
  font-size: .74em;
  line-height: 1;
}
.math .acc-hat::before { content: "^"; }
.math .acc-bar::before { content: "‾"; }
.math .acc-tilde::before { content: "~"; }
.math .acc-vec::before { content: "→"; }
.md li > ul, .md li > ol { margin: 4px 0; padding-left: 22px; }
.md blockquote > *:first-child { margin-top: 0; }
.md blockquote > *:last-child { margin-bottom: 0; }

/* 光标 */
.caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  background: var(--brand);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: blink .95s step-end infinite;
}

/* 错误提示 */
.err-note {
  margin-top: 10px;
  padding: 10px 13px;
  border-radius: 9px;
  background: rgba(255, 107, 107, .1);
  border: 1px solid rgba(255, 107, 107, .35);
  color: #ff9b9b;
  font-size: 13px;
}

/* 消息操作 */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  padding-left: 32px;
  opacity: 0;
  transition: opacity .15s ease;
}
.msg.assistant:hover .msg-actions { opacity: 1; }
.act-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
  transition: background .13s, color .13s;
}
.act-btn:hover { background: var(--sidebar-hover); color: var(--text); }

/* ---------------------------- 输入区 ---------------------------- */
.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 24px 16px;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.composer {
  max-width: 780px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg-elev);
  padding: 10px 12px 8px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(77, 107, 254, .13);
}
#input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  max-height: 200px;
  padding: 2px 2px 6px;
}
#input::placeholder { color: var(--text-dim); }

.composer-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 4px;
}
.capabilities { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }
.cap {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
}
.send-btn {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  transition: background .15s ease, transform .12s ease, opacity .15s ease;
}
.send-btn:hover { background: var(--brand-hover); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .38; cursor: not-allowed; }
.send-btn.stop { background: #ff6b6b; }
.send-btn.stop:hover { background: #e85a5a; }

.disclaimer {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ---------------------------- 弹窗 ---------------------------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .18s ease both;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 640px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 22px 18px;
  animation: popIn .22s ease both;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0 0 5px; font-size: 17px; font-weight: 600; }
.modal-sub { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }

.mem-input {
  width: 100%;
  height: 240px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--tool-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.7;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s ease;
}
.mem-input:focus { border-color: var(--brand); }
.mem-input::placeholder { color: var(--text-dim); }

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.save-status { font-size: 12px; color: var(--text-dim); }
.save-status.saving { color: var(--brand); }
.save-status.saved { color: #3ac569; }
.save-status.error { color: #ff6b6b; }
.modal-actions { display: flex; gap: 8px; }
.btn-ghost, .btn-primary {
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  transition: background .15s ease, border-color .15s ease;
}
.btn-ghost { border: 1px solid var(--line); color: var(--text-soft); }
.btn-ghost:hover { background: var(--sidebar-hover); }
.btn-primary { background: var(--brand); color: #fff; font-weight: 500; }
.btn-primary:hover { background: var(--brand-hover); }

/* ---------------------------- Toast ---------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%) translateY(12px);
  background: var(--sidebar-active);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------------------- 动画 ---------------------------- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse {
  0%, 100% { opacity: .25; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
  .scroll { scroll-behavior: auto; }
}

/* ---------------------------- 移动端 ---------------------------- */
/* 抽屉遮罩：只在窄屏且抽屉打开时出现 */
.sb-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, .5);
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 820px) {
  /* 手机/窄屏：侧栏改为「离屏抽屉」，默认完全收起，绝不遮挡主区 */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(272px, 84vw);
    flex: 0 0 auto;
    margin-left: 0;
    opacity: 1;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: none;
    pointer-events: auto;
    will-change: transform;
  }
  /* 桌面端的 sb-collapsed 在窄屏不应残留 margin/opacity 干扰抽屉动画 */
  .app.sb-collapsed .sidebar {
    margin-left: 0;
    opacity: 1;
    pointer-events: auto;
  }
  .app.sb-mobile-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 10px 44px rgba(0, 0, 0, .5);
  }
  .app.sb-mobile-open .sb-backdrop { display: block; }

  /* 主区始终占满整屏宽度，不受侧栏影响 */
  .main { width: 100%; }

  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-right { gap: 6px; }
  .ctx-meter { padding: 5px 8px; gap: 5px; }
  .ctx-bar { width: 34px; }

  .messages, .composer, .disclaimer { padding-left: 14px; padding-right: 14px; }
  .composer-wrap { padding: 8px 14px 12px; }
  .welcome { padding-top: 8vh; }
  .chips { grid-template-columns: 1fr; }
  .welcome-title { font-size: 22px; }
  .badge { display: none; }
  .ai-body, .msg-actions { padding-left: 0; }
  /* 窄屏下名字 + 耗时标签可能挤在一行，允许换行 */
  .msg.assistant .ai-head { flex-wrap: wrap; row-gap: 4px; }
}

@media (max-width: 480px) {
  .ctx-meter .ctx-num { font-size: 10.5px; }
  .capabilities { display: none; }
  .welcome-title { font-size: 20px; }
}

/* 刘海屏安全区：抽屉与输入区不被系统栏压住 */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 820px) {
    .sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    .composer-wrap { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .disclaimer { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  }
}

/* ============================================================
   附件上传（图片 / PDF）
   ============================================================ */
.attach-btn {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 9px;
  border: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text-soft);
  display: grid; place-items: center;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.attach-btn:hover { color: var(--brand); border-color: var(--brand); background: rgba(77, 107, 254, .08); }

.composer.drag {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(77, 107, 254, .2);
}

.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 2px 8px;
  border-bottom: 1px dashed var(--line-soft);
  margin-bottom: 6px;
}
.att-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--tool-bg);
  padding: 5px 6px 5px 5px;
}
.att-chip-img {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.att-chip-ico {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 6px;
  background: var(--bg-elev);
}
.att-chip-info { min-width: 0; flex: 1 1 auto; }
.att-chip-name {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-chip-sub { font-size: 11px; color: var(--text-dim); }
.att-chip-x {
  flex: 0 0 auto;
  width: 20px; height: 20px;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 11px;
  display: grid; place-items: center;
}
.att-chip-x:hover { background: rgba(255, 107, 107, .16); color: #ff6b6b; }

/* 已发送消息里的附件 */
.msg.user .bubble { white-space: normal; }
.msg.user .bubble-text { white-space: pre-wrap; }
.att-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.att-box:first-child { margin-top: 0; }
.att-item {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 320px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: rgba(0, 0, 0, .16);
  padding: 6px;
}
.att-img {
  width: 84px; height: 84px;
  flex: 0 0 84px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}
.att-ico {
  width: 84px; height: 84px;
  flex: 0 0 84px;
  display: grid; place-items: center;
  font-size: 34px;
  border-radius: 8px;
  background: var(--bg-elev);
}
.att-meta { min-width: 0; flex: 1 1 auto; }
.att-name {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.att-dl {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 7px;
  color: var(--text-soft);
  display: grid; place-items: center;
  text-decoration: none;
  font-size: 13px;
}
.att-dl:hover { background: rgba(77, 107, 254, .16); color: var(--brand); }

@media (max-width: 640px) {
  .att-img, .att-ico { width: 64px; height: 64px; flex-basis: 64px; }
  .att-item { max-width: 100%; }
}

/* ============================================================
   上下文用量 / 压缩 / 设置
   ============================================================ */
/* ---- 顶栏上下文计量 ---- */
.ctx-meter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-soft);
  font-size: 11.5px;
  line-height: 1;
  transition: border-color .15s ease, background .15s ease;
}
.ctx-meter:hover { background: var(--sidebar-hover); border-color: var(--brand); }
.ctx-label { color: var(--text-dim); }
.ctx-num { font-family: var(--mono); font-size: 11px; color: var(--text-soft); }
.ctx-bar {
  display: block;
  width: 46px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.ctx-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width .3s ease, background .2s ease;
}
.ctx-meter.warn { border-color: #d9a441; }
.ctx-meter.warn .ctx-bar > i { background: #d9a441; }
.ctx-meter.warn .ctx-num { color: #e0b25a; }
.ctx-meter.over { border-color: #ff6b6b; }
.ctx-meter.over .ctx-bar > i { background: #ff6b6b; }
.ctx-meter.over .ctx-num { color: #ff8a8a; }

/* ---- 压缩提示条 ---- */
.compress-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 18px;
  font-size: 12px;
  color: var(--text-soft);
  background: var(--tool-bg);
  border-bottom: 1px solid var(--line-soft);
}
.compress-banner[hidden] { display: none; }
.cb-ico { font-size: 13px; }
.cb-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-btn {
  flex: none;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 11.5px;
  color: var(--text-soft);
}
.cb-btn:hover { background: var(--sidebar-hover); color: var(--text); }

/* ---- 消息内的压缩过程提示 ---- */
.compress-note {
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 9px;
  background: var(--tool-bg);
  color: var(--text-soft);
  font-size: 12.5px;
  line-height: 1.6;
}
.compress-note.done { border-left-color: #3ac569; color: var(--text-soft); }

/* ---- 上游排队等待提示（临时状态条，收到内容就撤掉）---- */
.wait-note {
  margin: 0 0 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid #d9a441;
  border-radius: 9px;
  background: var(--tool-bg);
  color: var(--text-soft);
  font-size: 12.5px;
  line-height: 1.6;
}

/* ---- 上下文面板 ---- */
.modal-narrow { max-width: 520px; }
.modal-wide { max-width: 640px; max-height: 86vh; display: flex; flex-direction: column; }

.ctx-hero { margin-bottom: 14px; }
.ctx-hero-num { font-size: 22px; font-weight: 600; font-family: var(--mono); letter-spacing: -.3px; }
.ctx-hero-sub { margin-top: 3px; font-size: 12px; color: var(--text-dim); }
.ctx-hero-bar {
  margin-top: 9px;
  height: 7px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.ctx-hero-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width .3s ease, background .2s ease;
}
.ctx-hero-bar > i.warn { background: #d9a441; }
.ctx-hero-bar > i.over { background: #ff6b6b; }

.ctx-rows { display: flex; flex-direction: column; gap: 8px; }
.ctx-row {
  display: grid;
  grid-template-columns: 74px 1fr 54px;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
.ctx-row-label { color: var(--text-soft); }
.ctx-row-bar {
  display: block;
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.ctx-row-bar > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  opacity: .75;
}
.ctx-row-num { text-align: right; font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }
.ctx-extra { margin-top: 4px; font-size: 11.5px; color: var(--text-dim); line-height: 1.7; }
.ctx-empty { font-size: 12.5px; color: var(--text-dim); line-height: 1.7; }

.ctx-summary-box {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--tool-bg);
  overflow: hidden;
}
.ctx-summary-box[hidden] { display: none; }
.csb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--text-soft);
  font-weight: 500;
}
.csb-meta { font-size: 11px; font-weight: 400; color: var(--text-dim); font-family: var(--mono); }
.csb-text {
  max-height: 190px;
  overflow-y: auto;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--text-soft);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- 设置表单 ---- */
.set-body {
  overflow-y: auto;
  padding-right: 4px;
  margin-right: -4px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.set-group { display: flex; flex-direction: column; gap: 10px; }
.set-group-title {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.set-field { display: flex; flex-direction: column; gap: 5px; }
.set-label { font-size: 12px; color: var(--text-soft); }
.set-field input[type="text"],
.set-field input[type="url"],
.set-field input[type="password"],
.set-field input[type="number"] {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--tool-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s ease;
}
.set-field input:focus { border-color: var(--brand); }
.set-field input::placeholder { color: var(--text-dim); font-family: var(--font); }
.set-field input.is-override { border-color: #4a7d5a; }
.set-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.set-check { flex-direction: row; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-soft); }
.set-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.set-hint { font-size: 11.5px; color: var(--text-dim); line-height: 1.6; }
.set-hint.error { color: #ff8a8a; }

@media (max-width: 640px) {
  .ctx-meter .ctx-label { display: none; }
  .set-row2 { grid-template-columns: 1fr; }
  .modal-wide { max-height: 92vh; }
}

.btn-ghost:disabled,
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

/* ============================================================
   账号：侧栏用户行 + 登录/注册门
   ============================================================ */
.sb-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .13s ease;
}
.sb-user:hover { background: var(--sidebar-hover); }
.sb-user-avatar {
  width: 28px; height: 28px; flex: none;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c8ffd);
  color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(77, 107, 254, .3);
}
.sb-user-meta { flex: 1; min-width: 0; }
.sb-user-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-user-sub {
  font-size: 11px; color: var(--text-dim); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-logout {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-dim);
  cursor: pointer;
  transition: background .13s ease, color .13s ease;
}
.sb-logout:hover { background: var(--sidebar-active); color: #ff6b6b; }

/* ---- 登录/注册门（整屏遮罩，未登录时不可绕过） ---- */
.auth-mask {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
}
.auth-mask[hidden] { display: none; }
body.auth-locked { overflow: hidden; }

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px 24px 20px;
  animation: popIn .24s ease both;
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.auth-title { font-size: 17px; font-weight: 600; color: var(--text); }
.auth-sub { font-size: 11.5px; color: var(--text-dim); line-height: 1.55; margin-top: 3px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: var(--tool-bg);
  border: 1px solid var(--line-soft);
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  padding: 7px 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .13s ease, color .13s ease;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.18); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field[hidden] { display: none; }
.auth-label { font-size: 12px; color: var(--text-soft); }
.auth-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--tool-bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease;
}
.auth-field input:focus { border-color: var(--brand); }
.auth-field input::placeholder { color: var(--text-dim); font-size: 12.5px; }

.auth-error {
  font-size: 12.5px;
  color: #ff8a8a;
  background: rgba(255, 107, 107, .1);
  border: 1px solid rgba(255, 107, 107, .28);
  border-radius: 9px;
  padding: 8px 11px;
  line-height: 1.5;
}
.auth-error[hidden] { display: none; }

.auth-submit {
  margin-top: 2px;
  padding: 10px 0;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.auth-submit:hover { background: var(--brand-hover); }
.auth-submit:disabled { opacity: .55; cursor: not-allowed; }

.auth-foot {
  margin-top: 14px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
  text-align: center;
}

@media (max-width: 480px) {
  .auth-card { padding: 20px 18px 16px; }
  .auth-mask { padding: 14px; align-items: center; }
}
