/* chat：对话页（OpenWebUI 式对话流 × 机房控制台色板）。
 * 结构：用户消息=右侧圆角气泡；agent 回合=左侧品牌头像 + 内容列（.turn，
 * 由 chat.js 分组）；工具调用/状态为无框细行，不打断阅读流。 */

/* 对话流与输入区共用一条居中栏（内容宽度封顶 800px）。
 * position:relative 必须保留：KaTeX 的无障碍 MathML 节点是 position:absolute
 * 的隐藏元素，若最近的定位祖先在滚动容器之外（.pane），长对话里深处的公式
 * 会以内容坐标锚出去，把整页撑出一条看不见的滚动区（双滚动条）。 */
.chat-log {
  position: relative;
  flex: 1; overflow-y: auto;
  padding: 24px max(20px, calc((100% - 800px) / 2)) 8px;
  display: flex; flex-direction: column; gap: 14px;
  /* 上下边界虚化：对话内容在贴近「对话切换栏」和「输入卡」时渐隐，
   * 与上下两栏之间留出一道柔和的分界，视觉上把中间的对话流单独划出来。
   * 顶部渐隐更长（旧内容滚上去时溶入切换栏），底部只轻描一笔，
   * 避免流式输出时最新一行被压暗影响阅读。 */
  --fade-top: 30px;
  --fade-bottom: 14px;
  -webkit-mask-image: linear-gradient(to bottom,
    transparent 0, #000 var(--fade-top),
    #000 calc(100% - var(--fade-bottom)), transparent 100%);
  mask-image: linear-gradient(to bottom,
    transparent 0, #000 var(--fade-top),
    #000 calc(100% - var(--fade-bottom)), transparent 100%);
}
/* 滚动 flex 容器的子项禁止收缩，否则内容超高时消息会被垂直压扁 */
.chat-log > * { flex-shrink: 0; }

/* 新消息淡入（历史加载在隐藏态完成，呈现时整体淡入一次） */
.msg, .turn { animation: msg-in 0.2s ease-out; }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px); }
}

/* ---- 用户消息：右对齐圆角气泡，无边框 ---- */
.msg { font-size: 15px; line-height: 1.75; }
.msg.user {
  align-self: flex-end;
  max-width: 78%;
  background: var(--panel-2);
  border-radius: 18px 18px 6px 18px;
  padding: 10px 16px;
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- Agent 回合：品牌头像 + 内容列 ---- */
.turn { display: flex; gap: 12px; align-items: flex-start; }
/* 回合头像用原始品牌 logo（不套圆圈瓦片），略放大，色随品牌 */
.turn-avatar { flex: none; margin-top: 2px; }
.turn-avatar .agent-ico { width: 24px; height: 24px; }
.turn-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding-top: 2px;
}
.turn-body > * { min-width: 0; }

.msg.agent { word-break: break-word; }
.msg.agent > :first-child { margin-top: 0; }
.msg.agent > :last-child { margin-bottom: 0; }

/* Answer actions and provenance: one quiet footer, always reachable on touch. */
.answer-footer {
  display: flex; align-items: flex-start; flex-wrap: wrap; gap: 0 8px;
  margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.6;
}
.answer-footer[hidden] { display: none; }
.answer-actions { display: flex; flex: none; }
.answer-copy {
  flex: none; width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted);
  cursor: pointer; transition: background 140ms, color 140ms;
}
.answer-copy:hover { background: var(--panel-2); color: var(--text); }
.answer-copy:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.answer-copy.copied { color: var(--green); }
.answer-context {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px 12px;
  flex: 1; min-width: 0; padding: 6px 0;
}
.answer-context > * { min-width: 0; overflow-wrap: anywhere; }
.answer-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.answer-model { color: var(--text); opacity: .72; }
.answer-effort { white-space: nowrap; }
.answer-cost { white-space: nowrap; font-variant-numeric: tabular-nums; }
.answer-cost.priced { color: var(--green); }
.answer-details {
  flex-basis: 100%; margin: 6px 0 4px 8px; padding: 2px 0 2px 12px;
  border-left: 2px solid var(--line); overflow-wrap: anywhere;
}
.answer-details[hidden] { display: none; }
.answer-details > div + div { margin-top: 4px; }
.answer-details .chip.result { font-size: inherit; padding: 0; opacity: 1; }
@media (max-width: 760px) {
  .answer-copy { width: 40px; height: 40px; }
  .answer-context { padding: 9px 0; gap: 3px 10px; }
  .answer-time { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .answer-copy { transition: none; }
}

/* ---- 轻量 Markdown ---- */
.md-p { white-space: pre-wrap; margin: 0 0 10px; }
.md-h { font-weight: 650; line-height: 1.45; margin: 16px 0 6px; }
.md-h1 { font-size: 19px; }
.md-h2 { font-size: 17px; }
.md-h3 { font-size: 15.5px; }
.md-h4 { font-size: 15px; color: var(--muted); }
.md-hr { height: 1px; background: var(--line); margin: 14px 0; }

/* 数学公式（KaTeX）：字号与正文协调，颜色随文本；块级居中，过宽时自身横向滚动 */
.katex { font-size: 1.05em; }
.math-inline { white-space: normal; }
.math-display {
  margin: 12px 0; padding: 2px 0;
  overflow-x: auto; overflow-y: hidden;
}
.math-display .katex-display { margin: 0; }
.md-list { margin: 0 0 10px; padding-left: 22px; }
.md-list li { margin: 3px 0; white-space: pre-wrap; }
.md-list li::marker { color: var(--muted); }
.md-quote {
  margin: 0 0 10px;
  padding: 2px 2px 2px 13px;
  border-left: 3px solid var(--amber-dim);
  color: var(--muted);
  white-space: pre-wrap;
}
.md-link { color: var(--amber); text-decoration: none; border-bottom: 1px solid var(--amber-dim); }
.md-link:hover { border-bottom-color: var(--amber); }
/* 文档里的图片：没写尺寸时不许撑破正文；透明 PNG/SVG 铺棋盘格才看得清边界 */
.md-img {
  max-width: 100%; height: auto;
  vertical-align: middle; border-radius: 6px;
  background: repeating-conic-gradient(var(--panel-2) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}
.md-tablewrap {
  max-width: 100%; overflow-x: auto;
  margin: 2px 0 10px;
  border: 1px solid var(--line); border-radius: 10px;
}
.md-table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.md-table th, .md-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top;
  white-space: nowrap;
}
.md-table th { background: var(--panel); font-weight: 600; }
.md-table tr:last-child td { border-bottom: none; }

/* 行内代码：暗底暖字的磷光小片 */
.msg code {
  font-family: var(--mono); font-size: 12.5px;
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: 5px;
  padding: 1.5px 6px;
}

/* ---- 代码块：语言头 + 复制按钮 ---- */
.codeblock {
  margin: 2px 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  overflow: hidden;
}
.cb-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 7px 4px 8px;
  background: var(--code-head);
  border-bottom: 1px solid var(--code-line);
}
/* 折叠开关：箭头 + 语言 + 行数，整块可点 */
.cb-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  min-width: 0;
  background: none; border: none; border-radius: 6px;
  color: var(--muted);
  padding: 3px 8px 3px 5px;
}
.cb-toggle:hover { color: var(--text); background: var(--panel-2); }
.cb-caret {
  display: inline-flex; flex: none;
  transform: rotate(90deg);
  transition: transform 0.15s ease;
}
.codeblock.folded .cb-caret { transform: none; }
.cb-lang { font-size: 11px; letter-spacing: 0.07em; }
.cb-count { font-size: 11px; opacity: 0.65; }
.cb-copy {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none; border-radius: 6px;
  color: var(--muted);
  font-family: var(--sans); font-size: 12px;
  padding: 3px 8px;
}
.cb-copy:hover { color: var(--text); background: var(--panel-2); }
.cb-copy:disabled { color: var(--green); cursor: default; background: none; }
/* 主体：行号列固定，代码区横向滚动；折叠时整体隐藏 */
.cb-body { display: flex; align-items: stretch; }
.codeblock.folded .cb-body { display: none; }
.codeblock.folded .cb-head { border-bottom: none; }
.cb-gutter {
  flex: none;
  padding: 12px 0 12px 14px;
  text-align: right;
  color: color-mix(in srgb, var(--muted) 55%, transparent);
  font-size: 12.5px; line-height: 1.65;
  white-space: pre;
  user-select: none;
}
.codeblock pre {
  flex: 1; min-width: 0;
  margin: 0; padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  white-space: pre;
}
.codeblock code {
  background: none; border: none; padding: 0;
  color: var(--text); font-size: inherit;
}

/* ---- 事件行：无框细行（工具调用 / 状态），错误保留醒目面板 ---- */
.chip {
  max-width: 100%;
  font-family: var(--mono); font-size: 12px;
  color: var(--muted);
  padding: 1px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip .name { color: var(--amber); margin-right: 9px; }
.chip .name svg { vertical-align: -1.5px; margin-right: 5px; }
.chip .sum { color: var(--muted); }
.chip.result { font-size: 11.5px; color: var(--green); opacity: 0.75; padding-top: 3px; }
/* 「预览」入口：Agent 刚写出的 HTML 直接在这里点开渲染 */
.chip.has-open { display: flex; align-items: center; }
.chip.has-open .name { flex: none; }
.chip.has-open .sum { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.chip.has-open .chip-open { flex: none; }
.chip-open {
  margin-left: 9px; padding: 0 8px; height: 18px;
  border: 1px solid color-mix(in srgb, var(--amber) 40%, transparent);
  border-radius: 9px; background: transparent;
  color: var(--amber); font: inherit; font-size: 11px; line-height: 16px;
  vertical-align: 1px; cursor: pointer;
}
.chip-open:hover, .chip-open:focus-visible {
  background: color-mix(in srgb, var(--amber) 12%, transparent); outline: none;
}
.chip.err, .chip.warn {
  border-radius: 10px;
  padding: 8px 13px;
  white-space: pre-wrap; overflow: visible; text-overflow: clip;
  word-break: break-word;
}
.chip.err {
  color: var(--red);
  background: color-mix(in srgb, var(--red) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--red) 28%, transparent);
}
.chip.warn {
  color: var(--amber);
  background: color-mix(in srgb, var(--amber) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 25%, transparent);
}

details.raw { font-family: var(--mono); font-size: 12px; color: var(--muted); }
details.raw summary { cursor: pointer; }
details.raw pre { max-height: 240px; overflow: auto; margin: 6px 0 0; }

/* 思考过程：折叠细行，展开为左侧竖线的引文 */
details.think { max-width: 100%; font-size: 13px; color: var(--muted); }
details.think summary {
  cursor: pointer; list-style: none;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12px;
  border-radius: 6px;
}
details.think summary::-webkit-details-marker { display: none; }
details.think summary::before {
  content: "›";
  transition: transform 0.15s ease;
  color: var(--muted);
}
details.think[open] summary::before { transform: rotate(90deg); }
details.think summary:hover { color: var(--text); }
details.think .think-body {
  white-space: pre-wrap;
  border-left: 2px solid var(--line);
  padding: 4px 0 4px 14px;
  margin: 8px 0 2px 4px;
  opacity: 0.8;
  line-height: 1.7;
}

/* ---- 流式生成中：打字机增量节点（完整事件到达后被正式渲染替换）。
 * text 块内容是 Markdown 渲染产物（块级），光标挂在最后一个块的末尾；
 * 首个字符到达前节点为空，光标退回容器本身 ---- */
.msg.live-text.streaming:empty::after,
.msg.live-text.streaming > :last-child::after,
details.think.streaming .think-body::after {
  content: "▍";
  margin-left: 2px;
  color: var(--amber);
  animation: cursor-blink 1s steps(2) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

/* ---- 附件条：composer 内输入框上方的缩略图 / 文件条 ---- */
.chat-attach {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  padding: 2px 4px 4px;
}
.attach-file {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2);
  padding: 6px 10px;
  font-size: 12px; color: var(--text);
  max-width: 240px;
}
.attach-file .fn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-file .spin { width: 10px; height: 10px; }
.file-link {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 3px 4px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--code-bg);
  padding: 5px 10px;
  font-size: 12px; color: var(--amber);
  text-decoration: none;
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-link:hover { border-color: var(--amber); }
.attach-thumb {
  position: relative;
  width: 64px; height: 64px;
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
  display: flex; align-items: center; justify-content: center;
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.attach-thumb .badge {
  position: absolute; left: 3px; top: 3px; z-index: 1;
  background: var(--overlay-chip);
  color: var(--amber);
  font-family: var(--mono); font-size: 10px;
  padding: 1px 5px; border-radius: 4px;
}
.attach-thumb .up {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--muted); font-size: 11px;
}

/* 消息气泡里的图片缩略图 */
.msg.user .chat-thumb {
  display: inline-block; vertical-align: middle;
  max-width: 200px; max-height: 110px;
  border: 1px solid var(--line); border-radius: 10px;
  margin: 3px 4px;
  cursor: zoom-in;
}
.msg.user .chat-thumb:hover { border-color: var(--amber); }
.img-gone { color: var(--muted); font-size: 12px; font-family: var(--mono); }

/* ---- 对话切换栏：当前对话标题（历史面板入口）+ 新对话（chat-threads.js） ---- */
.thread-bar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 8px max(20px, calc((100% - 800px) / 2)) 0;
}

/* 对话通道连接状态：仅断开/重连时出现（连上即隐藏），让长回合期间的掉线
 * 可见，而不是等到用户按发送才发现发不出去。 */
.chat-conn {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  margin: 8px max(20px, calc((100% - 800px) / 2)) 0;
  padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-2);
  font-size: 12.5px; color: var(--muted);
}
.chat-conn .btn { margin-left: auto; }

@media (max-width: 760px) {
  .chat-conn { margin: 6px 8px 0; }
}
.thread-cur {
  display: inline-flex; align-items: center; gap: 7px;
  min-width: 0;
  background: none; border: none; border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 12px;
}
.thread-cur:hover { color: var(--text); background: var(--panel); }
.thread-cur .t {
  min-width: 0; max-width: 52vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.thread-cur svg { flex: none; display: block; }
/* 内网是对话的辅助状态入口，与历史标题同级，避免做成主操作按钮。 */
.chat-network {
  position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 32px; margin-left: 4px; padding: 5px 8px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font: 400 12px/1.5 var(--sans);
  white-space: nowrap; transition: background 140ms ease, color 140ms ease;
}
.chat-network::before {
  content: ""; position: absolute; left: -7px; top: 10px; bottom: 10px;
  width: 1px; background: var(--line);
}
.chat-network:hover, .chat-network:focus-visible { background: var(--panel); color: var(--text); }
.chat-network-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.chat-network-status { color: var(--muted); }
.chat-network[data-state="ready"] .chat-network-dot { background: var(--green); }
.chat-network[data-state="ready"] .chat-network-status { color: var(--green); }
.chat-network[data-state="pending"] .chat-network-dot { background: var(--amber); }
.chat-network[data-state="pending"] .chat-network-status { color: var(--amber); }
.chat-network[data-state="proxy"] .chat-network-dot { background: var(--green); }
.chat-network-arrow { flex: none; opacity: .5; transition: opacity 140ms ease, transform 140ms ease; }
.chat-network:hover .chat-network-arrow, .chat-network:focus-visible .chat-network-arrow { opacity: 1; transform: translateX(2px); }
@media (prefers-reduced-motion: reduce) {
  .chat-network, .chat-network-arrow { transition: none; }
}
.thread-new {
  flex: none; margin-left: auto;
  background: none;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--text);
  font-size: 12px; font-weight: 500;
  min-height: 32px; padding: 4px 10px;
}
.thread-new:hover { color: var(--text); border-color: var(--amber-dim); background: var(--panel); }

/* ---- 历史对话面板：右侧滑出，列表可切换 / 新建 / 删除 ---- */
.tp-scrim {
  position: fixed; inset: 0; z-index: 79;
  background: var(--scrim);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.tp-scrim.show { opacity: 1; pointer-events: auto; }
.thread-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 80;
  width: min(360px, 92vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(102%);
  transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
.thread-panel.open { transform: none; }
.tp-head {
  flex: none;
  display: flex; align-items: center; gap: 9px;
  padding: 16px 14px 12px 18px;
}
.tp-head b { font-size: 15px; }
.tp-count { flex: 1; color: var(--muted); font-size: 11.5px; }
.tp-new { flex: none; margin: 0 16px 10px 18px; }
/* 搜索：对话攒多了靠标题快速定位；只有一条时由 JS 隐藏 */
.tp-search {
  flex: none; margin: 0 16px 10px 18px;
  padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--text);
  font-size: 13px;
}
.tp-search:focus-visible { outline: none; border-color: var(--amber); }
.tp-search::placeholder { color: var(--muted); }
.tp-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  padding: 2px 10px 12px;
}
.tp-item {
  display: flex; align-items: stretch;
  border-radius: 10px;
}
.tp-item:hover { background: var(--panel-2); }
.tp-item.on { background: color-mix(in srgb, var(--amber) 9%, transparent); }
.tp-open {
  flex: 1; min-width: 0; text-align: left;
  display: grid; grid-template-columns: 15px minmax(0, 1fr); gap: 3px 7px;
  background: none; border: none; border-radius: 10px 0 0 10px;
  padding: 9px 4px 9px 10px;
}
.tp-open > .ui-icon { grid-row: 1 / 3; align-self: center; color: var(--muted); }
.tp-open > .tp-meta { grid-column: 2; }
.tp-title {
  color: var(--text); font-size: 13.5px; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tp-item.on .tp-title { color: var(--amber); }
.tp-meta { color: var(--muted); font-size: 11px; }
.tp-del {
  flex: none; align-self: center;
  width: 30px; height: 30px; margin: 0 6px 0 2px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 8px;
  color: var(--muted);
}
.tp-del:hover { color: var(--red); background: var(--panel); }
/* 桌面端删除钮悬停行才浮现；触屏无悬停，常驻可见 */
@media (hover: hover) {
  .tp-item .tp-del { opacity: 0; }
  .tp-item:hover .tp-del, .tp-item .tp-del:focus-visible { opacity: 1; }
}
.tp-empty {
  color: var(--muted); font-size: 13px; line-height: 1.7;
  text-align: center;
  padding: 34px 18px;
}
.tp-empty .spin { margin-right: 8px; }
.tp-hint {
  flex: none;
  color: var(--muted); font-size: 11.5px; line-height: 1.6;
  border-top: 1px solid var(--line);
  margin: 0; padding: 10px 18px 12px;
}

/* ---- 上下文分割线：新对话起点 ---- */
.chat-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0 8px;
  color: var(--muted); font-size: 11px; letter-spacing: 0.08em;
}
.chat-divider::before,
.chat-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.chat-divider span { white-space: nowrap; }

/* ---- 执行指示：对话流末尾一枚会动的品牌头像 + 阶段文案（仿桌面端 Contemplating）。
 * 沿用 .turn 布局（左头像 + 右内容列），头像按品牌做不同动画，文案在头像右侧。 ---- */
.turn.working .turn-body { justify-content: center; }
.work-label {
  font-family: var(--mono); font-size: 13px;
  color: var(--muted);
  animation: work-breathe 1.6s ease-in-out infinite;
}
@keyframes work-breathe { 50% { opacity: 0.45; } }

/* Claude：星芒脉动（触手伸缩跳动） */
.turn.working .agent-ico.agent-claude {
  transform-origin: center;
  animation: claude-throb 1.15s ease-in-out infinite;
}
@keyframes claude-throb {
  0%, 100% { transform: scale(0.82); }
  50% { transform: scale(1.08); }
}
/* Codex：图标转圈 */
.turn.working .agent-ico.agent-codex {
  transform-origin: center;
  animation: codex-spin 1.4s linear infinite;
}
@keyframes codex-spin { to { transform: rotate(360deg); } }

/* ---- 输入卡：大圆角悬浮卡，聚焦时琥珀微光 ---- */
.composer-wrap {
  flex: none;
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  padding: 6px max(20px, calc((100% - 800px) / 2)) 18px;
}
.chat-scroll-bottom {
  position: absolute; left: 50%; top: 2px; z-index: 5;
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  backdrop-filter: blur(10px) saturate(120%);
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translate(-50%, 1px) scale(0.88);
  transition: opacity 0.16s ease, visibility 0.16s ease,
    transform 0.2s cubic-bezier(0.2, 0.75, 0.25, 1),
    color 0.12s ease, background 0.12s ease;
}
.chat-scroll-bottom.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: translate(-50%, -100%) scale(1);
}
.chat-scroll-bottom:hover {
  color: var(--amber);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}
.chat-scroll-bottom:active {
  transform: translate(-50%, -100%) scale(0.92);
}
.chat-scroll-bottom:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 2px;
}
.composer {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 12px 12px 10px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer:focus-within {
  border-color: var(--amber-dim);
  box-shadow: var(--shadow-md),
    0 0 0 3px color-mix(in srgb, var(--amber) 12%, transparent);
}
.composer textarea {
  background: transparent; border: none; outline: none;
  resize: none;
  padding: 4px 6px 8px 2px;
  min-height: 36px; max-height: 220px;
  color: var(--text);
  font-size: 15px; line-height: 1.6;
}
.composer textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.composer textarea:focus-visible { outline: none; }
.composer-bar { display: flex; align-items: center; gap: 2px; min-width: 0; }

/* 圆形幽灵图标钮 */
.icon-btn {
  width: 34px; height: 34px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: none; border-radius: 50%;
  color: var(--muted);
  line-height: 1;
}
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn.rec {
  color: var(--on-red); background: var(--red);
  animation: voice-pulse 1.4s ease-out infinite;
}
@keyframes voice-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 45%, transparent); }
  100% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--red) 0%, transparent); }
}

/* 发送：琥珀实心圆纸飞机，执行中变红色中断钮（两个 SVG 靠 .stop 切换） */
.send-btn {
  width: 34px; height: 34px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent);
  border: none; border-radius: 50%;
  color: var(--on-accent);
  line-height: 1;
  margin-left: 6px;
  transition: background 0.12s ease, transform 0.12s ease;
}
.send-btn:hover { background: var(--accent-hi); }
.send-btn:active { transform: scale(0.92); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn .ic-send { display: block; transform: translate(-1px, 1px); } /* 机头朝右上，视觉重心回正 */
.send-btn .ic-stop { display: none; }
.send-btn.stop { background: var(--red); color: var(--on-red); }
.send-btn.stop:hover { background: var(--red-hi); }
.send-btn.stop .ic-send { display: none; }
.send-btn.stop .ic-stop { display: block; }

/* ---- 模型 / 思考强度选择胶囊 + 上弹菜单 ---- */
.picker { margin-left: auto; position: relative; min-width: 0; }
.pick-pill {
  max-width: 100%;
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: none; border-radius: 999px;
  color: var(--muted);
  font-size: 12.5px;
  padding: 8px 12px;
}
.pick-pill .t {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Agent 图标与折叠箭头：不参与压缩，由 align-items 垂直居中 */
.pick-pill svg { flex: none; display: block; }
.pick-pill:hover { color: var(--text); background: var(--panel-2); }
.pick-menu {
  position: absolute; right: 0; bottom: calc(100% + 10px); z-index: 40;
  width: 268px; max-height: 60vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
}
/* 悬停浮层：贴在面板左侧，展示某个属性的全部选项 */
.pick-fly {
  position: absolute; z-index: 41;
  width: 210px; max-height: 60vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
}
.pick-fly-h {
  color: var(--muted);
  font-size: 11px;
  padding: 5px 11px 6px;
}
.pick-sep { border-top: 1px solid var(--line); margin: 5px 0; }

/* 主面板行：模型 / 推理强度 → 悬停浮层 */
.pick-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: 9px;
  color: var(--text);
  font-size: 13px;
  padding: 9px 11px;
}
.pick-row:hover, .pick-row.open { background: var(--panel-2); }
.pick-row .val { color: var(--muted); font-size: 12px; }
.pick-back {
  display: flex; justify-content: flex-start; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 11px 8px; margin-bottom: 4px;
  border-radius: 0;
}
.pick-back:hover { color: var(--text); }
.pick-opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left;
  background: none; border: none; border-radius: 9px;
  color: var(--text);
  font-size: 13px;
  padding: 7px 11px;
}
.pick-opt:hover { background: var(--panel-2); }
.pick-opt .lbl { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pick-opt .sub { color: var(--muted); font-size: 11px; }
.pick-opt .check { color: var(--amber); visibility: hidden; flex: none; }
.pick-opt.on .check { visibility: visible; }

/* 历史对话失败时留在同一状态位，停止转圈并给出唯一恢复动作。 */
#chat-loading.history-error { gap: 10px; }
#chat-loading.history-error #chat-loading-text { color: var(--text); }

/* ---- 空会话引导：品牌头像 + 问候 + 建议 pills ---- */
.chat-hero {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 18px;
  padding: 20px;
  overflow-y: auto;
}
.hero-avatar .agent-avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  box-shadow: 0 0 44px color-mix(in srgb, var(--brand) 22%, transparent);
}
.chat-hero h2 {
  display: flex; align-items: center; justify-content: center;
  margin: 0;
  font-size: 26px; font-weight: 600; letter-spacing: 0.01em;
}
.hero-cursor {
  display: block; flex: none; overflow: hidden;
  width: 0.55em; height: 1.02em;
  margin-left: 8px;
  background: var(--accent); color: transparent;
  animation: blink 1.1s steps(1) infinite;
}
.hero-pills {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 10px;
  max-width: 620px;
  margin-top: 4px;
}
.hero-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: transparent;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--muted);
  font-size: 13.5px;
  padding: 9px 18px;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.hero-pill:hover { color: var(--text); border-color: var(--amber-dim); background: var(--panel); }
.hero-pill .hp-ico { font-size: 15px; }

/* ---- 窄屏：收窄留白、放宽气泡、防 iOS 聚焦缩放、引导 pills 改单列 ---- */
@media (max-width: 760px) {
  .chat-log { padding: 14px 12px 4px; gap: 12px; --fade-top: 20px; --fade-bottom: 10px; }
  .msg.user { max-width: 88%; }
  .thread-bar { padding: 6px 8px 0; }
  .thread-cur { padding: 6px 10px; }
  .chat-network { min-height: 36px; padding-inline: 6px; gap: 5px; }
  .chat-network::before { top: 12px; bottom: 12px; }
  /* 窄屏历史面板与左侧菜单抽屉同宽 */
  .thread-panel { width: min(300px, 84vw); }
  .turn { gap: 9px; }
  .turn-avatar .agent-ico { width: 22px; height: 22px; }
  .chip { max-width: 100%; }
  .composer-wrap { padding: 4px 10px 12px; }
  .composer { border-radius: 20px; padding: 10px 10px 8px 12px; }
  /* iOS 聚焦时字号 <16px 会强制放大整页 */
  .composer textarea { font-size: 16px; min-height: 32px; }
  .chat-hero { justify-content: flex-start; padding-top: 13vh; gap: 15px; }
  .chat-hero h2 { font-size: 21px; }
  .hero-avatar .agent-avatar { width: 52px; height: 52px; }
  .hero-pills { flex-direction: column; align-items: stretch; width: 100%; max-width: 420px; gap: 8px; }
  .hero-pill { justify-content: flex-start; padding: 10px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .msg, .turn { animation: none; }
  .work-label, .turn.working .agent-ico { animation: none; }
  .icon-btn.rec { animation: none; }
  .hero-cursor { animation: none; }
  .msg.live-text.streaming:empty::after,
  .msg.live-text.streaming > :last-child::after,
  details.think.streaming .think-body::after { animation: none; }
  .send-btn, .composer, .hero-pill, .cb-caret, .chat-scroll-bottom { transition: none; }
  .thread-panel, .tp-scrim { transition: none; }
}
