/* =========================================================
   设计语言：纸墨 (Ink & Paper)
   - 无渐变、无发光、无重阴影
   - 细线分隔 + 排版层级 + 单一暖色强调
   - 明（纸）/ 暗（墨）两套，由 html[data-theme] 控制
   ========================================================= */

:root {
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Source Han Serif SC", "Songti SC",
    "Noto Serif CJK SC", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 12px;

  --sidebar-w: 252px;
  /* 安卓壳注入的安全区（刘海/手势条）；浏览器里恒为 0 */
  --safe-top: 0px;
  --safe-bottom: 0px;
  --safe-left: 0px;
  --safe-right: 0px;
  --reading: 764px;
}

/* ---------- 明：纸 ---------- */
html[data-theme="light"] {
  --bg: #f7f5f0;
  --bg-side: #f0ede6;
  --surface: #fffdf9;
  --surface-2: #f2efe8;
  --line: #dfd9cd;
  --line-soft: #eae5da;
  --text: #201e19;
  --text-dim: #6a6358;
  --text-faint: #736b5d;
  --accent: #9e5330;
  --accent-hover: #86431f;
  --accent-soft: rgba(158, 83, 48, .085);
  --code-bg: #f3efe6;
  --ok: #4a7657;
  --err: #ac4033;
  --shadow: 0 12px 40px -12px rgba(50, 42, 30, .28);
  --caret: #9e5330;
  --table-bd: var(--line);
  --table-line: var(--line-soft);
  --table-head: var(--surface-2);
  color-scheme: light;
}

/* ---------- 暗：墨 ---------- */
html[data-theme="dark"] {
  --bg: #17150f;
  --bg-side: #131109;
  --surface: #1e1c15;
  --surface-2: #24211a;
  --line: #322e25;
  --line-soft: #292519;
  --text: #ece7dc;
  --text-dim: #a29a8b;
  --text-faint: #877f70;
  --accent: #cd8055;
  --accent-hover: #e0946a;
  --accent-soft: rgba(205, 128, 85, .11);
  --code-bg: #1a180f;
  --ok: #7aa88a;
  --err: #d4705f;
  --shadow: 0 16px 50px -14px rgba(0, 0, 0, .8);
  --caret: #cd8055;
  --table-bd: #4a443a;
  --table-line: #3d382e;
  --table-head: #26231b;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
.chat-scroll, .sidebar, .session-list { overscroll-behavior: contain; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  font-feature-settings: "kern" 1;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ================= 布局 ================= */
.app { display: flex; height: 100dvh; width: 100%; padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-side);
  display: flex;
  flex-direction: column;
  transition: margin-left .24s cubic-bezier(.4, 0, .2, 1), transform .24s cubic-bezier(.4, 0, .2, 1);
  z-index: 30;
}
.app.collapsed .sidebar { margin-left: calc(var(--sidebar-w) * -1); }

/* 收起状态：汉堡按钮换成"展开"图标，并在主区左上角保留一个可点区域 */
.app.collapsed .menu-btn svg { transform: scaleX(-1); }
.app.collapsed .menu-btn { color: var(--accent); }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 14px 12px 18px;
}
.brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--accent);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.brand-text span {
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* 通用幽灵按钮：只在 hover 时出现底色 */
.btn-ghost {
  color: var(--text-faint);
  border-radius: var(--r-sm);
  padding: 6px 8px;
  transition: color .14s, background .14s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.icon-btn { padding: 6px; line-height: 0; }

.new-chat {
  margin: 2px 10px 14px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--r-sm);
  color: var(--text-dim);
  font-size: 13px;
  transition: background .14s, color .14s;
}
.new-chat:hover { background: var(--surface-2); color: var(--text); }
.new-chat svg { flex: 0 0 auto; opacity: .8; }

.session-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.session-empty {
  color: var(--text-faint);
  font-size: 12px;
  padding: 22px 12px;
  text-align: center;
  line-height: 1.8;
  white-space: pre-line;
}
.session-group-label {
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 10px 6px;
  font-family: var(--mono);
}

.session-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  transition: background .13s, color .13s;
  position: relative;
}
.session-item:hover { background: var(--surface-2); color: var(--text); }
.session-item.active { background: var(--accent-soft); color: var(--text); }
.session-item.active .s-title { font-weight: 500; }
.session-item .s-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item .s-badge {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .06em;
  color: var(--text-faint);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 3px;
  line-height: 1.5;
  flex: 0 0 auto;
}
.session-item .s-del {
  opacity: 0;
  flex: 0 0 auto;
  color: var(--text-faint);
  padding: 2px;
  border-radius: 4px;
  line-height: 0;
  transition: opacity .14s, color .14s;
}
.session-item:hover .s-del { opacity: 1; }
.session-item .s-del:hover { color: var(--err); }

.sidebar-foot {
  border-top: 1px solid var(--line-soft);
  padding: 8px;
  margin: 0 10px;
}
.foot-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-faint);
  padding: 7px 8px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  transition: background .14s, color .14s;
}
.foot-btn:hover { background: var(--surface-2); color: var(--text); }
.key-dot {
  margin-left: auto;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--err);
}
/* 仅表示「是否已填 Key」，不代表连通性，所以不用绿色 */
.key-dot.ok { background: var(--accent); }

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
  z-index: 10;
}
.menu-btn { display: inline-flex; }
/* 宽屏下侧栏默认展开，汉堡按钮用于收起/展开；收起后依然常驻可见 */

.model-pick { position: relative; display: inline-flex; align-items: center; }
.model-pick select {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 5px 24px 5px 8px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  transition: .14s;
  max-width: 100%;
  text-overflow: ellipsis;
}
.model-pick select:hover { border-color: var(--line); color: var(--text); }
.model-pick select:focus-visible {
  outline: none;
  border-color: var(--accent);
}
.model-pick .chev {
  position: absolute;
  right: 7px;
  pointer-events: none;
  color: var(--text-faint);
}

/* 联网/深度思考入口在输入区 .tool-pill（见输入区样式） */

.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 10px;
}
.topbar-right { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

/* ---------- 聊天流 ---------- */
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-inner {
  max-width: var(--reading);
  margin: 0 auto;
  padding: 34px 14px 200px;
}

/* 欢迎页 */
.welcome { padding: 11vh 0 0; max-width: 560px; margin: 0 auto; }
.welcome-mark {
  color: var(--accent);
  margin-bottom: 18px;
  display: flex;
  justify-content: center;
}
.welcome h1 {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  letter-spacing: -.015em;
  line-height: 1.35;
  margin: 0 0 12px;
  text-align: center;
}
.welcome .welcome-sub {
  color: var(--text-faint);
  margin: 0 0 34px;
  font-size: 13.5px;
  text-align: center;
  line-height: 1.8;
}
.suggests {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.suggest {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 13px 14px;
  transition: border-color .16s, background .16s, transform .16s;
  position: relative;
}
.suggest:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.suggest .s-ico {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
}
.suggest .s-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.suggest b { color: var(--text); font-weight: 500; font-size: 13.5px; }
.suggest .s-main span {
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
}
.suggest .s-go {
  position: absolute;
  right: 12px;
  top: 12px;
  color: var(--accent);
  font-size: 13px;
  opacity: 0;
  transition: opacity .16s;
}
.suggest:hover .s-go { opacity: 1; }
@media (max-width: 620px) {
  .suggests { grid-template-columns: 1fr; }
  .welcome { padding-top: 6vh; }
  .welcome h1 { font-size: 25px; }
}

/* ---------- 消息 ---------- */
.msg {
  display: block;
  margin-bottom: 30px;
}
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.msg { animation: rise .26s ease; }

/* 消息骨架：助手带品牌头像，用户气泡靠右 */
.msg.assistant { display: flex; gap: 12px; }
.msg-avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.msg-body { flex: 1; min-width: 0; }
.msg-role {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.msg-role .model-tag {
  font-size: 10px;
  font-weight: 400;
  border-radius: 99px;
  padding: 0 6px;
  line-height: 1.7;
  background: var(--surface-2);
  color: var(--text-faint);
}

/* 用户消息：右侧浅色气泡 */
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .msg-body { flex: 0 1 auto; max-width: min(78%, 560px); display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  font-size: 14.7px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.72;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 15px;
}
.msg.user .msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 6px; }

/* 助手正文 */
.prose { word-wrap: break-word; overflow-wrap: break-word; font-size: 14.7px; line-height: 1.75; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 14px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -.01em;
  margin: 26px 0 10px;
  line-height: 1.35;
}
.prose h1 { font-size: 22px; }
.prose h2 { font-size: 19px; }
.prose h3 { font-size: 16.5px; }
.prose h4 { font-size: 14.5px; font-family: var(--sans); font-weight: 600; color: var(--text-dim); }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 20px; }
.prose li { margin: 5px 0; padding-left: 2px; }
.prose li > ul, .prose li > ol { margin: 5px 0; }
.prose li::marker { color: var(--text-faint); }
.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 32%, transparent);
  transition: border-color .14s;
}
.prose a:hover { border-bottom-color: var(--accent); }
.prose strong { font-weight: 600; color: var(--text); }
.prose em { font-style: italic; }
.prose del { color: var(--text-faint); }
.prose hr { border: 0; border-top: 1px solid var(--line-soft); margin: 26px 0; }
.prose blockquote {
  margin: 0 0 14px;
  padding: 1px 0 1px 15px;
  border-left: 1px solid var(--line);
  color: var(--text-dim);
  font-style: italic;
}
.prose code {
  font-family: var(--mono);
  font-size: .86em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1.5px 4.5px;
  color: var(--accent-hover);
}
.prose pre {
  margin: 0 0 16px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  overflow: hidden;
}
.prose pre .code-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.prose pre .copy-code {
  margin-left: auto;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
  padding: 2px 6px;
  border-radius: 4px;
  transition: .14s;
}
.prose pre .copy-code:hover { background: var(--surface-2); color: var(--text); }
.prose pre code {
  display: block;
  padding: 13px 15px;
  overflow-x: auto;
  background: transparent;
  color: var(--text);
  font-size: 12.6px;
  line-height: 1.68;
  white-space: pre;
  border-radius: 0;
}

/* 语法高亮：低饱和，与纸墨调性一致 */
html[data-theme="light"] .tok-k { color: #8a4f7d; }
html[data-theme="light"] .tok-s { color: #4f7a52; }
html[data-theme="light"] .tok-c { color: #a29a8b; font-style: italic; }
html[data-theme="light"] .tok-n { color: #9a6320; }
html[data-theme="light"] .tok-f { color: #3f6a8a; }
html[data-theme="dark"] .tok-k { color: #c79ac0; }
html[data-theme="dark"] .tok-s { color: #9cbc8e; }
html[data-theme="dark"] .tok-c { color: #6a6255; font-style: italic; }
html[data-theme="dark"] .tok-n { color: #d3a06a; }
html[data-theme="dark"] .tok-f { color: #8fb0c8; }

.prose .table-wrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--table-bd); border-radius: var(--r-md); }
.prose .math-block { margin: 10px 0 18px; padding: 4px 0; overflow-x: auto; }
.prose math { font-size: 1.08em; }
.prose .math { padding: 0 1px; }
.prose pre.math-raw { white-space: pre-wrap; color: var(--text-dim); }
.prose code.math-raw { font-style: italic; }
.prose table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.2px;
  width: 100%;
  table-layout: auto;
}
.prose th, .prose td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.prose th + th, .prose td + td { border-left: 1px solid var(--table-line); }
.prose thead th {
  border-bottom: 1px solid var(--table-bd);
  background: var(--table-head);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--text-dim);
  white-space: nowrap;
}
.prose tbody tr + tr td { border-top: 1px solid var(--table-line); }

/* 思考过程：左侧细线 + 等宽元信息，不用色块 */
/* 思考 + 执行过程总面板 */
.process-box {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}
.process-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 13px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: left;
  transition: background .14s, color .14s;
}
.process-head:hover { background: var(--surface-2); color: var(--text); }
.process-head .p-title { font-weight: 500; letter-spacing: .01em; }
.process-head .p-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.process-head .caret {
  margin-left: auto;
  transition: transform .2s;
  opacity: .6;
}
.process-box.open .process-head .caret { transform: rotate(90deg); }
.process-head .p-more {
  font-size: 11.5px;
  color: var(--text-faint);
}
.process-body {
  display: none;
  padding: 6px 13px 10px;
  border-top: 1px solid var(--line-soft);
}
.process-box.open .process-body { display: block; }

.reasoning {
  margin: 4px 0 8px;
  border-left: 1px solid var(--line);
  padding-left: 12px;
}
.reasoning-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: left;
  transition: color .14s;
  width: 100%;
  padding: 4px 0;
}
.reasoning-head:hover { color: var(--text-dim); }
.reasoning-head .r-title { letter-spacing: .02em; }
.reasoning-head .r-more {
  font-size: 11px;
  color: var(--text-faint);
}
.reasoning-head .caret {
  margin-left: auto;
  transition: transform .2s;
  opacity: .6;
}
.reasoning.open .reasoning-head .caret { transform: rotate(90deg); }
.reasoning-body {
  display: none;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
  line-height: 1.7;
}
.reasoning.open .reasoning-body { display: block; }

.spinner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .75s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 工具调用：细线列表 */
.tool-stack { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.tool-card { border: 0; }
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 0;
  font-size: 12.4px;
  color: var(--text-faint);
  text-align: left;
  transition: color .13s;
}
.tool-head:hover { color: var(--text); }
.tool-ico {
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  flex: 0 0 auto;
}
.tool-card.ok .tool-ico { color: var(--ok); }
.tool-card.fail .tool-ico { color: var(--err); }
.tool-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--text-faint);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}
.tool-body {
  display: none;
  margin: 2px 0 8px;
  border-left: 1px solid var(--line);
  padding-left: 1px;
}
.tool-card.open .tool-body { display: block; }
.tool-result {
  display: block;
  padding: 6px 0 6px 12px;
  text-decoration: none;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line-soft);
  transition: color .13s;
}
.tool-result:last-child { border-bottom: 0; }
.tool-result:hover { color: var(--text); }
.tool-result:hover .r-title { color: var(--accent); }
.tool-result .r-title { color: var(--text); font-size: 12.8px; display: block; transition: color .13s; }
.tool-result .r-url {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.tool-result .r-snip {
  font-size: 12px;
  color: var(--text-faint);
  display: block;
  margin-top: 3px;
  line-height: 1.55;
}
.tool-err {
  color: var(--err);
  font-size: 12px;
  padding: 6px 0 6px 12px;
}

/* 消息操作 */
.msg-actions { display: flex; gap: 2px; margin-top: 9px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
/* 触屏没有 hover：编辑按钮常显，否则手指根本点不到 */
@media (hover: none) { .msg-actions { opacity: 1; } .msg-actions button { opacity: .72; } .session-item .s-del { opacity: .55; } }

/* 分支切换器：贴在角色行末尾，1px 边框，无填色 */
.branch-switch {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-left: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}
.branch-switch button {
  padding: 1px 6px;
  line-height: 1.4;
  color: var(--text-faint);
  transition: color .13s, background .13s;
}
.branch-switch button:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.branch-switch button:disabled { opacity: .3; cursor: default; }
.branch-switch .b-count { padding: 0 3px; }

/* 编辑态：输入框左侧留一道强调线 */
.composer.editing { border-color: var(--accent); }
.edit-cancel {
  font-size: 12px;
  color: var(--text-dim);
  padding: 5px 9px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  transition: background .13s, color .13s;
}
.edit-cancel:hover { background: var(--surface-2); color: var(--text); }
.msg-actions button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-faint);
  padding: 4px 7px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
  transition: .13s;
}
.msg-actions button svg { flex: 0 0 auto; }
.msg-actions button:hover { background: var(--surface-2); color: var(--text); }
.msg-actions button.done { color: var(--ok); }
.msg.user .msg-actions { margin-top: 4px; }

/* 错误 */
.err-box {
  border-left: 2px solid var(--err);
  padding: 2px 0 2px 12px;
  color: var(--err);
  font-size: 13px;
  white-space: pre-wrap;
  margin-bottom: 12px;
  line-height: 1.65;
}

.caret-blink {
  display: inline-block;
  width: 2px;
  height: 15px;
  background: var(--caret);
  vertical-align: -2px;
  animation: blink 1.1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .15; } }

/* ---------- 输入区 ---------- */
.composer-wrap {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0 26px calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
  pointer-events: none;
}
.composer {
  pointer-events: auto;
  max-width: var(--reading);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color .16s, box-shadow .16s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  padding: 4px 2px;
  max-height: 200px;
  line-height: 1.7;
  font-size: 14.5px;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer-tools { display: flex; align-items: center; gap: 6px; }
.composer-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.attach-btn { color: var(--text-faint); }
.attach-btn:hover { color: var(--text); background: var(--surface-2); }
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid transparent;
  font-size: 12px;
  color: var(--text-faint);
  transition: .15s;
}
.tool-pill:hover { background: var(--surface-2); color: var(--text); }
.tool-pill[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
}
.send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background .14s, opacity .14s, transform .14s;
  flex: 0 0 auto;
}
html[data-theme="dark"] .send-btn { color: #1a1710; }
.send-btn:disabled { opacity: .22; cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: var(--accent-hover); transform: translateY(-1px); }
.send-btn .ico-stop { display: none; }
.send-btn.stop .ico-send { display: none; }
.send-btn.stop .ico-stop { display: block; }
.send-btn.stop { background: var(--surface-2); color: var(--text-dim); }

.jump-latest {
  position: absolute;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text-dim);
  font-size: 12px;
  z-index: 12;
  animation: rise .18s ease;
}
.jump-latest:hover { color: var(--accent); border-color: var(--accent); }

.composer-hint {
  max-width: var(--reading);
  margin: 8px auto 0;
  padding: 0 4px;
  display: flex;
  gap: 10px;
  font-size: 10.5px;
  letter-spacing: .02em;
  color: var(--text-faint);
  pointer-events: none;
}
.composer-hint .spacer { flex: 1; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 12, .38);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 90;
  animation: fade .15s ease;
  backdrop-filter: blur(2px);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(540px, 100%);
  max-height: min(86dvh, 720px);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  padding: 16px 14px 13px 20px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  flex: 1;
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 19px;
}
.modal-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-top: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.modal-foot .spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 500; }
.field-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.6;
}
.field-hint code {
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10.5px;
}
.field input[type="text"],
.field input[type="password"],
.field textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  font-size: 13px;
  outline: 0;
  transition: border-color .15s;
  width: 100%;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea {
  resize: vertical;
  line-height: 1.62;
  font-family: var(--mono);
  font-size: 12px;
  min-height: 210px;
  max-height: 340px;
}
.input-row { display: flex; gap: 7px; }
.input-row input { flex: 1; }
.btn-ghost.small {
  border: 1px solid var(--line);
  padding: 5px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-dim);
}
.switch-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.switch-row > span:first-child { display: flex; flex-direction: column; gap: 3px; }
input[type="checkbox"] {
  appearance: none;
  width: 34px;
  height: 19px;
  border-radius: 99px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background .18s;
  flex: 0 0 auto;
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--bg);
  transition: .18s;
}
input[type="checkbox"]:checked { background: var(--accent); }
input[type="checkbox"]:checked::after { left: 17px; }

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-sm);
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 500;
  transition: opacity .14s;
}
.btn-primary:hover { opacity: .82; }
.search-status {
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.8;
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}
.search-status b { color: var(--text-dim); font-weight: 500; }
.search-status .off { opacity: .45; text-decoration: line-through; }
.search-status code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--surface-2);
  padding: 1px 4px;
  border-radius: 3px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 99px;
  font-size: 12.5px;
  z-index: 120;
  opacity: 0;
  transition: .22s;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); color: #fff; }

.scrim { display: none; }

/* ================= 响应式 ================= */
@media (max-width: 820px) {
  :root { --sidebar-w: 276px; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    border-right: 1px solid var(--line-soft);
  }
  .app.mobile-open .sidebar { transform: none; }
  .app.collapsed .sidebar { margin-left: 0; }
  .app.mobile-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 17, 12, .35);
    z-index: 25;
  }
  .topbar { gap: 5px; padding: 0 9px; }
  .topbar-title { display: none; }
  .model-pick { flex: 1 1 auto; min-width: 0; }
  .model-pick select { width: 100%; }
  .chat-inner { padding: 20px 14px 190px; }
  .composer-wrap { padding: 0 12px calc(10px + var(--safe-bottom)); }
  .welcome { padding-top: 6vh; }
  .welcome h1 { font-size: 26px; }
  .msg { gap: 11px; margin-bottom: 26px; }
  .msg.assistant { gap: 9px; }
  .msg-avatar { width: 26px; height: 26px; }
  .msg-avatar svg { width: 16px; height: 16px; }
  .msg.user .msg-body { max-width: 88%; }
  .tool-pill { padding: 5px 8px; font-size: 11.5px; }
  .jump-latest { bottom: calc(140px + var(--safe-bottom)); }
  .reasoning-body { max-height: 220px; }
  .prose { font-size: 14.2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* 主题切换按钮：只显示目标主题的图标 */
.theme-btn { margin-left: 0; }
html[data-theme="light"] .theme-btn .ico-sun { display: none; }
html[data-theme="dark"] .theme-btn .ico-moon { display: none; }

/* 所有内联图标固定尺寸，避免被 flex 压缩导致笔画变形 */
.topbar svg, .sidebar svg, .composer svg { flex: 0 0 auto; }

/* ============ 附件（官方 Files API） ============ */
.attach-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px 8px;
}
.attach-strip[hidden] { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 4px 5px 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}
.chip .c-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip .c-size {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}
.chip.uploading { opacity: .72; }
.chip.is-error { border-color: var(--err); }
.chip.is-error .c-size { color: var(--err); }
.chip .c-x {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}
.chip .c-x:hover { background: rgba(127, 127, 127, .16); color: var(--text); }

/* 用户气泡下的附件清单（历史消息回看） */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 6px;
}
.msg-files .chip { background: transparent; }

.composer.dragging {
  outline: 1.5px dashed var(--accent);
  outline-offset: 2px;
}

/* ============ 引用角标 ============ */
sup.cite {
  display: inline-block;
  min-width: 14px;
  margin: 0 1px;
  padding: 0 3px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 15px;
  text-align: center;
  vertical-align: 3px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}
sup.cite:hover { background: color-mix(in srgb, var(--accent) 24%, transparent); }

/* ============ 来源入口与右侧抽屉 ============ */
.sources-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  transition: border-color .15s, color .15s, background .15s;
}
.sources-trigger:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--surface));
}

.sources-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .28);
  z-index: 48;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.sources-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

.sources-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 80vw);
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 28px rgba(0, 0, 0, .14);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.sources-drawer.open { transform: translateX(0); }

.sources-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sources-head-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sources-head-title strong { font-size: 14.5px; font-weight: 600; }
.sources-count {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.sources-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.source-card {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, background .15s;
}
.source-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}
.source-card.hit {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}
.source-idx {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
  margin-top: 1px;
}
.source-main { min-width: 0; flex: 1; }
.source-title {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 4px;
}
.source-url {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 附件按钮：尺寸与 pill 行对齐 */
.attach-btn {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  color: var(--text-faint);
}
.attach-btn:hover { color: var(--text); background: var(--surface-2); }

/* 中止提示：附在已生成内容末尾，不覆盖正文 */
.stop-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-faint);
}
.stop-note::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 1px;
  margin-right: 6px;
  vertical-align: 4px;
  background: currentColor;
}

/* ================= 原地编辑提问 ================= */
/* 气泡本体变成编辑框：输入区透明贴在气泡里，视觉就是「原来那个框框」 */
.msg.user.editing .msg-body { flex: 0 1 auto; width: min(78%, 560px); align-items: stretch; }
.msg.user.editing .bubble { padding-bottom: 8px; white-space: normal; }
.edit-input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  padding: 0;
  display: block;
}
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.edit-actions button {
  font-size: 12.5px;
  padding: 5px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.edit-actions button:hover { background: var(--surface); }
.edit-actions .edit-send {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.edit-actions .edit-send:hover { filter: brightness(1.06); }
/* 编辑中隐藏「编辑」铅笔按钮，下游消息变暗且不可点——发送后它们将被新版本取代 */
.msg.user.editing .user-actions { display: none; }
.dim-edit { opacity: .42; pointer-events: none; transition: opacity .15s; }

/* 访问令牌输入层 */
.auth-gate {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(400px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 28px 24px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.auth-title { color: var(--text); }
html[data-theme="dark"] .auth-input { background: var(--surface-2); }
.auth-title { font-size: 17px; font-weight: 600; }
.auth-desc { font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.auth-input {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--mono, ui-monospace, monospace);
  background: var(--bg);
  color: var(--text);
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-btn { padding: 11px; border-radius: 10px; font-size: 14.5px; }

/* ===== 移动端交互层 ===== */
body.typing .chat-scroll { overflow: hidden; }
/* 移动窄屏：fixed 侧栏不吃 .app 的安全区 padding，自己补刘海 */
@media (max-width: 820px) {
  .sidebar { padding-top: var(--safe-top); padding-left: var(--safe-left); }
  .sidebar-foot { padding-bottom: calc(6px + var(--safe-bottom)); }
  /* 编辑中：品牌色描边明确"激活的编辑场" */
  .msg.editing .bubble, .msg.editing .msg-body { border-color: var(--accent) !important; }
}

/* content-visibility：屏外消息跳过渲染，contain-intrinsic-size 由 JS 实测写入 */
.msg.cv { content-visibility: auto; }

/* 顶栏新建按钮：只在移动端出现——桌面侧栏常驻大按钮，顶栏不需要重复 */
.newchat-top { display: none; }
@media (max-width: 820px) {
  .newchat-top { display: inline-flex; }
}

/* ---------- 深度任务模式 ---------- */
/* 锁定的深度线程: pill 常亮但不可点,提示"已是深度线程" */
.mode-pill.locked {
  opacity: .85;
  cursor: default;
  border-style: dashed;
}
/* 深度线程是线性的: 编辑/重生成/分支入口全部隐藏 */
.deep-linear .act-edit,
.deep-linear .act-regen {
  display: none;
}
/* 会话列表里的深度徽章 */
.session-item .s-badge.deep {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 34%, transparent);
  background: var(--accent-soft);
}

/* 回退按钮: 默认隐藏,仅深度会话的用户消息上出现(由 JS 控制) */
.act-rewind { display: inline-flex; align-items: center; gap: 3px; }
.act-rewind[hidden] { display: none; }
/* deep-linear 隐藏编辑/重生成,但回退必须保持可见 */
.deep-linear .act-rewind { display: inline-flex; }
