/* ============ Messages ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px var(--gutter-main) 56px;
  /* scroll-behavior 必须保持 auto/instant：流式期 scrollTop=scrollHeight 是高频
     "贴底跟随"调用，smooth 会把单次 scroll 拆成 ~60 帧动画，中间帧 gap 可达
     200+ px，远超 isNearBottom 的 40px 阈值，导致 scroll listener 把 autoFollow
     翻成 false、之后流式更新不再跟随。 */
  scroll-behavior: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 22px;
  align-items: stretch;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }

/* Inner width constraint — we wrap messages with CSS instead of a wrapper div */
.messages > * { max-width: 1040px; width: 100%; margin-left: auto; margin-right: auto; }

.msg-row {
  display: flex;
  gap: 12px;
  animation: fadeUp 260ms ease-out;
  position: relative;
}
.msg-row.user {
  justify-content: flex-end;
  animation: bubbleSlideIn 360ms cubic-bezier(0.25, 1, 0.4, 1);
  transform-origin: bottom right;
}

/* ── 消息级分支切换器 ‹ N/M › ──────────────────────────────────────
   嵌入 .msg-actions bar，跟"复制 / 编辑"按钮并排。当 user message
   有兄弟分支时，此切换器**常显**（强制 visibility:visible 打破父规
   则的 hidden 默认），让用户一眼能看到"这里有别的分支可切"，不需
   要 hover 才发现。
   设计：箭头按钮跟其他 chip 一致的圆角 + 间距，中间分页式 N/M label
   用稍亮的描边把"这是一个独立组件"和"复制/编辑"在视觉上区分开。 */
.msg-row.user .msg-actions:has(.msg-branch-switch) {
  visibility: visible;
}
.msg-branch-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  margin-right: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  user-select: none;
}
.msg-branch-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink, #333);
  transition: background 140ms ease, color 140ms ease;
}
.msg-branch-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}
.msg-branch-arrow:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.07);
  color: var(--brand, #1f6feb);
}
.msg-branch-label {
  min-width: 28px;
  text-align: center;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink, #333);
  padding: 0 2px;
}
@keyframes bubbleSlideIn {
  0%   { opacity: 0; transform: translateY(34px) scale(0.94); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.msg-row.user .msg-av {
  display: none;
}
.msg-row.assistant .msg-av {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  position: relative;
  transition: background 200ms;
}
.msg-row.assistant .msg-av svg {
  width: 18px;
  height: 18px;
  display: block;
}
.msg-row.assistant.is-waiting .msg-av {
  background: transparent;
  border-color: transparent;
  color: var(--ink);
}
.msg-row.assistant.is-waiting .msg-av::before,
.msg-row.assistant.is-waiting .msg-av::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.55;
  animation: avHalo 1.8s cubic-bezier(0.25, 1, 0.5, 1) infinite;
}
.msg-row.assistant.is-waiting .msg-av::after {
  animation-delay: 0.6s;
}
.msg-row.assistant.is-waiting .msg-av-core {
  position: relative;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  z-index: 1;
  animation: avCore 1.8s ease-in-out infinite;
}
@keyframes avHalo {
  0%   { transform: scale(0.6); opacity: 0.55; }
  70%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}
@keyframes avCore {
  0%, 100% { transform: scale(0.85); opacity: 0.85; }
  50%      { transform: scale(1.05); opacity: 1; }
}
html[data-theme="dark"] .msg-row.assistant .msg-av { color: #14171a; }
.msg-row.sys {
  justify-content: center;
}

.msg-body {
  min-width: 0;
  flex: 1 1 auto;
  padding-top: 4px;
}
.msg-row.user .msg-body {
  flex: 0 1 auto;
  max-width: 72%;
  padding-top: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-bubble {
  font-size: 14.5px;
  line-height: 1.72;
  color: var(--text);
  word-wrap: break-word;
  max-width: 780px;
}
.msg-row.user .msg-bubble {
  padding: 11px 16px;
  background: var(--user-bubble);
  color: var(--text);
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  max-width: 100%;
}
.msg-row.assistant .msg-bubble {
  background: transparent;
  padding: 0;
  white-space: normal;
}

/* Markdown within assistant bubble */
.msg-row.assistant .msg-bubble p { margin: 0 0 12px; }
.msg-row.assistant .msg-bubble p:last-child { margin-bottom: 0; }
.msg-row.assistant .msg-bubble h1,
.msg-row.assistant .msg-bubble h2,
.msg-row.assistant .msg-bubble h3,
.msg-row.assistant .msg-bubble h4 {
  font-family: inherit;
  line-height: 1.35;
  color: var(--text);
  font-weight: 600;
}
.msg-row.assistant .msg-bubble h2 { font-size: 16px; margin: 18px 0 8px; }
.msg-row.assistant .msg-bubble h3 { font-size: 14.5px; margin: 14px 0 6px; }
.msg-row.assistant .msg-bubble h4 { font-size: 13.5px; margin: 12px 0 5px; }
.msg-row.assistant .msg-bubble h1:first-child,
.msg-row.assistant .msg-bubble h2:first-child,
.msg-row.assistant .msg-bubble h3:first-child { margin-top: 0; }

.msg-row.assistant .msg-bubble ul,
.msg-row.assistant .msg-bubble ol {
  margin: 0 0 12px;
  padding-left: 20px;
}
.msg-row.assistant .msg-bubble li { margin-bottom: 5px; }

.msg-row.assistant .msg-bubble blockquote {
  margin: 10px 0 12px;
  padding: 8px 14px;
  border-left: 3px solid var(--ink);
  background: var(--ink-softer);
  border-radius: 4px;
  color: var(--text-2);
}
.msg-row.assistant .msg-bubble blockquote p { margin-bottom: 6px; }

.msg-row.assistant .msg-bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 1.5px 5px;
  background: var(--code-bg);
  border-radius: 4px;
  color: var(--text);
}
.msg-row.assistant .msg-bubble pre {
  margin: 10px 0 12px;
  padding: 14px 16px;
  background: #1f2327;
  color: #e6e5e0;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  position: relative;
}
html[data-theme="dark"] .msg-row.assistant .msg-bubble pre { background: #0d0f11; border: 1px solid var(--border); }
.msg-row.assistant .msg-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
}
.msg-row.assistant .msg-bubble strong { font-weight: 600; color: var(--text); }
.msg-row.assistant .msg-bubble em { font-style: italic; }
.msg-row.assistant .msg-bubble table {
  border-collapse: collapse;
  margin: 10px 0 14px;
  font-size: 13.5px;
  width: 100%;
  max-width: 100%;
}
.msg-row.assistant .msg-bubble th {
  text-align: left;
  padding: 8px 12px;
  background: var(--ink-softer);
  color: var(--text);
  font-weight: 600;
  border-bottom: 1px solid var(--border-soft);
}
.msg-row.assistant .msg-bubble td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.msg-row.assistant .msg-bubble tr:last-child td { border-bottom: none; }
.msg-row.assistant .msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border-soft);
  margin: 14px 0;
}
.msg-row.assistant .msg-bubble a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: rgba(31, 60, 51, 0.3);
  text-underline-offset: 2px;
}
html[data-theme="dark"] .msg-row.assistant .msg-bubble a {
  text-decoration-color: rgba(127, 195, 158, 0.3);
}
.msg-row.assistant .msg-bubble a:hover { text-decoration-color: var(--ink); }

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #aaa;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  opacity: 0;
  transition: opacity 150ms, background 120ms;
  font-family: var(--font-mono);
  z-index: 1;
}
.msg-row.assistant .msg-bubble pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.code-copy-btn.copied { color: var(--green-accent); }

/* Per-message actions (copy / retry / edit) */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 10px;
}
/* user 消息按钮（复制 / 编辑）只在 hover 时显示，避免视觉污染。
   assistant 消息（复制 / 重试）保持常显，方便阅读时直接操作。

   注意几个坑：
   1) display: none/flex 切换会重排布局，把下方内容上下抖动 ✗
   2) opacity + visibility + transition 在 Safari 上 hover state
      黏住，鼠标离开后按钮仍显示 ✗
   3) 单纯 visibility（不带 transition）：保留布局空间不抖动，
      Safari 也不会卡 hover ✓ — 这是当前方案 */
.msg-row.user .msg-actions {
  justify-content: flex-end;
  margin-top: 4px;
  visibility: hidden;
}
.msg-row.user:hover .msg-actions { visibility: visible; }
.msg-copy-btn,
.msg-retry-btn,
.msg-edit-btn,
.msg-branch-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  font-size: 11.5px;
  color: var(--text-3);
  border-radius: 6px;
  background: transparent;
  border: none;
  font-family: inherit;
  transition: background 120ms, color 120ms;
  cursor: pointer;
}
.msg-copy-btn:hover,
.msg-retry-btn:hover,
.msg-edit-btn:hover,
.msg-branch-btn:hover {
  background: var(--hover);
  color: var(--text-2);
}
.msg-branch-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
/* 侧栏分支会话标记：标题前的小分叉图标 */
.sb-session-title-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.sb-session-branch-icon {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  color: var(--text-3);
  opacity: 0.85;
}
.sb-session-title-row .sb-session-title {
  flex: 1;
  min-width: 0;
}
.sb-session-running-icon {
  flex: 0 0 auto;
  width: 11px;
  height: 11px;
  color: var(--accent, #3b82f6);
  animation: sb-session-running-spin 1.4s linear infinite;
  margin-left: 4px;
}
.sb-session-running-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
@keyframes sb-session-running-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.msg-copy-btn.copied { color: var(--green-accent); }

/* Inline edit — stay at bubble size, don't stretch/shrink the row */
.msg-row.editing .msg-body {
  width: 72%;
  max-width: 72%;
  flex: 0 0 72%;
}
.msg-edit-ta {
  display: block;
  width: 100%;
  box-sizing: border-box;
  background: var(--user-bubble);
  color: var(--text);
  border: 0;
  border-radius: 16px;
  padding: 11px 16px;
  font: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  /* 现在是 contenteditable div（不是 textarea）—— 保留多行换行 + 长文本滚动 */
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.6em;
  max-height: 480px;
  overflow-y: auto;
  outline: none;
  box-shadow: 0 0 0 1.5px var(--ink) inset;
  transition: box-shadow 150ms;
}
.msg-edit-bar {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}
.msg-edit-bar button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms, border-color 120ms;
}
.msg-edit-bar button:hover { background: var(--hover); }
.msg-edit-bar .msg-edit-send {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
html[data-theme="dark"] .msg-edit-bar .msg-edit-send { color: #14171a; }
.msg-edit-bar .msg-edit-send:hover { filter: brightness(1.08); background: var(--ink); }

/* Images / files inside message */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  justify-content: flex-end;
}
.msg-row.assistant .msg-files { justify-content: flex-start; }
.msg-files img {
  max-width: 240px;
  max-height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  transition: filter 0.6s ease, opacity 0.6s ease;
}
/* 渐进 preview 中间帧:轻模糊 + 低 opacity 提示"还在生成"。
   is_final 到达时 composer.js 会去掉 .img-loading 类,过渡到清晰版。
   partial_index 越大模糊越浅,作为渐进强度暗示。 */
.msg-files img.img-loading {
  filter: blur(6px) saturate(0.85);
  opacity: 0.7;
}
.msg-files img.img-loading[data-partial-index="1"] {
  filter: blur(3px) saturate(0.92);
  opacity: 0.85;
}
.msg-files img.img-loading[data-partial-index="2"] {
  filter: blur(1.5px);
  opacity: 0.95;
}

/* ── 图片放大预览 lightbox(generated 图点击触发) ──
   背景复用 main.css 的 .modal-backdrop;此处专属图片居中、按钮位置。 */
.imgmodal-backdrop { padding: 0 !important; }
.imgmodal-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 92vw;
  max-height: 92vh;
}
.imgmodal-img {
  max-width: 92vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  background: var(--card-bg, #fff);
}
.imgmodal-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 1;
}
.imgmodal-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(20, 22, 20, 0.55);
  color: #fff;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
}
.imgmodal-btn:hover { background: rgba(20, 22, 20, 0.78); }
.imgmodal-btn svg { display: block; }

/* 多图翻页:左右两侧圆按钮 + 底部计数 */
.imgmodal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(20, 22, 20, 0.55);
  color: #fff;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.15s ease;
  z-index: 1;
}
.imgmodal-nav:hover { background: rgba(20, 22, 20, 0.78); }
.imgmodal-nav svg { display: block; }
.imgmodal-prev { left: 12px; }
.imgmodal-next { right: 12px; }
.imgmodal-counter {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  background: rgba(20, 22, 20, 0.55);
  color: #fff;
  font-size: 13px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1;
  pointer-events: none;
}
.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-2);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* System chip */
.sys-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  background: var(--ink-softer);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  padding: 6px 14px 6px 12px;
  max-width: 100%;
}
/* Sys-chip 里的内嵌按钮：要让它一眼看出来"这是个可点的按钮"。
   做法对齐 ChatGPT 的 "Regenerate" 控件 —— outlined 胶囊形 +
   重试图标 + 文字。hover 时实心填充给明确反馈。 */
.sys-chip-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  margin-left: 4px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.sys-chip-action:hover {
  background: var(--ink);
  color: #fff;
}
html[data-theme="dark"] .sys-chip-action:hover { color: #14171a; }
.sys-chip-action svg { flex-shrink: 0; }
.sys-chip .sdot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
  flex-shrink: 0;
}
.sys-chip .sdot::before,
.sys-chip .sdot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--ink);
}
.sys-chip .sdot::before { animation: sys-pulse 1.8s cubic-bezier(0.25, 1, 0.5, 1) infinite; }
.sys-chip .sdot::after  { animation: sys-pulse 1.8s cubic-bezier(0.25, 1, 0.5, 1) 0.6s infinite; }
@keyframes sys-pulse {
  0%   { transform: scale(1);   opacity: 0.55; }
  70%  { transform: scale(2.6); opacity: 0; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* Thinking block */
/* ────────────────── 思考过程面板 ──────────────────
   设计骨架：折叠头胶囊 + 展开后时间线（左侧虚线 + 节点）。
   颜色 / 圆角 / 字号继承 theme.css 的 token，节点状态色复用
   --ink / --green-accent / --danger；动画 pulse-dot + think-shine
   保留供运行态用。视觉参考 Notion / Linear，米色背景 + 墨绿强调。
   ──────────────────────────────────────────────── */
.thinking-block {
  margin: 0 0 10px;
  max-width: 100%;
}
/* ask_user_question 卡片 / 已答折叠挂在思考块里(thinkBody 之后):左侧内缩对齐
   时间线,与思考步骤同一视觉层级(用户要求把提问放进「思考过程」)。 */
.thinking-block > .uq-card,
.thinking-block > .answered-qs-fold {
  margin: 6px 0 8px 18px;
}
.thinking-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  padding: 4px 10px 4px 8px;
  background: var(--ink-softer);
  border-radius: 999px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 500;
  transition: background 120ms, color 120ms;
  white-space: nowrap;
  max-width: 100%;
}
.thinking-header:hover { background: var(--ink-soft); color: var(--text-2); }
.thinking-block.running .thinking-header { color: var(--ink); }
.thinking-header .think-dots {
  display: inline-flex;
  gap: 2px;
  flex-shrink: 0;
}
.thinking-header .think-dots i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  opacity: 0.5;
}
.thinking-block.running .thinking-header .think-dots i {
  animation: pulse-dot 1.2s ease-in-out infinite;
  opacity: 1;
}
.thinking-block.running .thinking-header .think-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-block.running .thinking-header .think-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse-dot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
.thinking-header .think-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thinking-header .think-meta {
  font-size: 11.5px;
  color: var(--text-4);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.thinking-header .think-caret {
  width: 11px;
  height: 11px;
  color: var(--text-4);
  flex-shrink: 0;
  transition: transform 180ms var(--ease);
}
.thinking-block.collapsed .thinking-header .think-caret { transform: rotate(-90deg); }

.thinking-body {
  position: relative;
  margin-top: 10px;
  padding: 14px 16px 12px 18px;
  background: var(--ink-softer);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.55;
}
.thinking-block.collapsed .thinking-body { display: none; }

/* 时间线竖向虚线骨架：贴左侧 padding 内 12px，覆盖所有 step 之间 */
.thinking-body::before {
  content: "";
  position: absolute;
  left: 24px;
  top: 18px;
  bottom: 18px;
  width: 1px;
  background-image: linear-gradient(to bottom, var(--border) 50%, transparent 50%);
  background-size: 1px 4px;
  background-repeat: repeat-y;
  pointer-events: none;
}

.think-step {
  position: relative;
  padding: 6px 0 6px 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
/* 节点圆点：覆盖在时间线上 */
.think-step::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 11px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-softer);
  border: 1.5px solid var(--text-5);
  box-sizing: border-box;
  transition: background 180ms, border-color 180ms, transform 180ms;
  z-index: 1;
}
.think-step.done::before    { background: var(--green-accent); border-color: var(--green-accent); }
.think-step.error::before   { background: var(--danger); border-color: var(--danger); }
.think-step.running::before {
  background: var(--ink);
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(31, 60, 51, 0.12);
  animation: think-node-pulse 1.6s ease-in-out infinite;
}
html[data-theme="dark"] .think-step.running::before {
  box-shadow: 0 0 0 4px rgba(127, 195, 158, 0.16);
}
@keyframes think-node-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(31, 60, 51, 0.10); }
  50%      { box-shadow: 0 0 0 6px rgba(31, 60, 51, 0.18); }
}

.think-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  outline: none;
}
.think-step-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.think-step.running .think-step-icon { color: var(--ink); }
.think-step.done .think-step-icon    { color: var(--text-3); }
.think-step.error .think-step-icon   { color: var(--danger); }
.think-step-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.think-step.running .think-step-label {
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text) 45%, var(--text-3) 90%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: think-shine 2.4s linear infinite;
}
@keyframes think-shine {
  0%   { background-position: 220% 0; }
  100% { background-position: -120% 0; }
}
.think-step-count {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  font-size: 10.5px;
  color: var(--text-3);
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.think-step-duration {
  font-size: 11px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.think-step-live { color: var(--ink); opacity: 0.9; }

/* 工具调用步骤的 args 摘要：紧凑 + monospace 风（路径 / 参数指纹这种） */
.think-step:not(.is-narrative) > .think-step-summary {
  margin-left: 22px;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.55;
  padding: 4px 8px;
  background: var(--card-bg);
  border-radius: 6px;
  border: 1px solid var(--border-soft);
  word-break: break-all;
  font-family: var(--font-mono, var(--font));
  max-width: calc(100% - 22px);
}
/* narrative 推理步骤的 summary：模型自述，正文风 + 显眼左饰线，默认展开 */
.think-step.is-narrative {
  padding-top: 8px;
  padding-bottom: 8px;
}
.think-step.is-narrative > .think-step-summary {
  margin-left: 22px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.65;
  padding: 6px 0 6px 10px;
  border-left: 2px solid var(--ink-soft);
  background: transparent;
  border-radius: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: calc(100% - 22px);
}
.think-step.is-narrative::before {
  background: var(--ink);
  border-color: var(--ink);
}
.think-step.is-narrative .think-step-label {
  color: var(--text-3);
  font-style: italic;
  font-size: 12px;
}
.think-step.is-narrative .think-step-icon {
  color: var(--ink);
}
.think-step-child {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 2px 4px;
  font-size: 11.5px;
  color: var(--text-3);
}
.think-step-child-bullet {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-5);
  flex-shrink: 0;
}
.think-step-child-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.think-step-child-duration {
  font-size: 10.5px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* 推理过程（合并自旧 .think-block 灰底块）—— 嵌入 thinking-body 末尾 */
.thinking-body .think-reasoning {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.thinking-body .think-reasoning > summary {
  cursor: pointer;
  user-select: none;
  font-size: 11.5px;
  color: var(--text-4);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  transition: color 120ms;
}
.thinking-body .think-reasoning > summary::-webkit-details-marker { display: none; }
.thinking-body .think-reasoning > summary::before {
  content: "▸";
  color: var(--text-5);
  font-size: 10px;
  transition: transform 180ms var(--ease);
  display: inline-block;
}
.thinking-body .think-reasoning[open] > summary::before { transform: rotate(90deg); }
.thinking-body .think-reasoning > summary:hover { color: var(--text-2); }
.thinking-body .think-reasoning-body {
  margin-top: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-2);
  background: var(--card-bg);
  border-radius: 8px;
  border: 1px solid var(--border-soft);
}
.thinking-body .think-reasoning-body p { margin: 0 0 6px; }
.thinking-body .think-reasoning-body p:last-child { margin-bottom: 0; }

.think-substep {
  margin-left: 22px;
  font-size: 12px;
  color: var(--text-3);
}
.think-substep-query {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-2);
  max-width: 100%;
  overflow: hidden;
}
.think-substep-query-icon {
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  color: var(--text-4);
}
.think-substep-query-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 520px;
}
.think-substep.rejected-query .think-substep-query {
  opacity: 0.55;
  border-color: rgba(193, 67, 67, 0.35);
  background: rgba(193, 67, 67, 0.08);
}
.think-substep.rejected-query .think-substep-query-text {
  text-decoration: line-through;
  text-decoration-color: rgba(193, 67, 67, 0.6);
}
.think-substep-text {
  color: var(--text-3);
  line-height: 1.5;
  font-size: 12.5px;
  padding: 2px 0;
  max-height: 4.6em;
  overflow: hidden;
  position: relative;
}
.think-substep-text::after {
  content: '';
  position: absolute;
  inset: 0 0 0 auto;
  width: 40px;
  background: linear-gradient(90deg, transparent, var(--ink-softer));
  pointer-events: none;
}

.think-spinner {
  width: 13px;
  height: 13px;
  border: 1.6px solid rgba(31, 60, 51, 0.18);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
html[data-theme="dark"] .think-spinner { border-color: rgba(127, 195, 158, 0.18); border-top-color: var(--ink); }

/* Source chips / folds */
.think-sources {
  margin-left: 22px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.meta-sources { margin-left: 0; margin-top: 8px; margin-bottom: 4px; }
.think-source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  max-width: 100%;
  text-decoration: none;
}
.think-source-chip img,
.think-source-chip .source-fav {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--hover);
  object-fit: contain;
}
.think-source-chip a {
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.think-source-chip:hover { color: var(--ink); border-color: rgba(31, 60, 51, 0.3); }

.sources-fold {
  background: var(--ink-softer);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
}
.meta-box .sources-fold { margin-top: 8px; }
.think-step .sources-fold {
  margin-left: 22px;
  max-width: calc(100% - 22px);
}
.sources-fold summary {
  cursor: pointer;
  padding: 7px 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sources-fold summary::-webkit-details-marker { display: none; }
.sources-fold summary::before {
  content: '›';
  font-size: 14px;
  color: var(--text-4);
  transition: transform var(--fast);
  display: inline-block;
  width: 12px;
  text-align: center;
  flex-shrink: 0;
}
.sources-fold[open] summary::before { transform: rotate(90deg); }
.sources-fold summary:hover { color: var(--ink); }
.sources-fold-body { padding: 0 12px 10px; }

/* 图像生成参数折叠（复用 .sources-fold 外壳）—— key:value 成对的小胶囊 */
.image-params-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.image-params-fold .param-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  font-size: 11.5px;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  white-space: nowrap;
}
.image-params-fold .param-key { color: var(--text-4); }
.image-params-fold .param-value { color: var(--ink); font-weight: 500; }
/* 跨厂商 fallback 告知（你选了 A 实际用了 B）—— 警示色，挂在参数胶囊上方 */
.image-params-fold .param-fallback-note {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--warning);
  background: var(--warning-soft);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 8px;
}

/* URL chips */
.msg-bubble a.url-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 9px 1px 6px;
  margin: 0 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-2);
  background: var(--ink-softer);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  text-decoration: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: baseline;
  transition: background 120ms, color 120ms, border-color 120ms;
}
.msg-bubble a.url-chip:hover {
  color: var(--ink);
  border-color: rgba(31, 60, 51, 0.3);
  background: var(--ink-soft);
  text-decoration: none;
}
.msg-bubble a.url-chip .url-chip-fav {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  background: var(--hover);
  object-fit: contain;
}
.msg-bubble a.url-chip-sup {
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  margin: 0 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--ink-softer);
  color: var(--text-2);
  border: 1px solid var(--border-soft);
  text-decoration: none;
  vertical-align: super;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.msg-bubble a.url-chip-sup:hover {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
html[data-theme="dark"] .msg-bubble a.url-chip-sup:hover { color: #14171a; }
.url-preview {
  position: absolute;
  z-index: 1000;
  min-width: 240px;
  max-width: 360px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.04);
  font-size: 12px;
  color: var(--text-2);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 150ms, transform 150ms;
}
.url-preview.visible {
  opacity: 1;
  transform: translateY(0);
}
.url-preview-domain {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 4px;
}
.url-preview-domain img { width: 14px; height: 14px; border-radius: 2px; }
.url-preview-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.url-preview-url {
  font-size: 11.5px;
  color: var(--text-4);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Typing dots */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
}
.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-4);
  animation: bounce 1.4s ease-in-out infinite;
  display: block;
  font-style: normal;
}
.typing i:nth-child(2) { animation-delay: 0.16s; }
.typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30%           { transform: translateY(-4px); opacity: 0.85; }
}

/* Meta box (trace / source fold) */
.meta-box { margin-top: 12px; font-size: 12px; }
.meta-box details {
  background: var(--ink-softer);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 6px;
  transition: background 120ms;
}
.meta-box details:hover { background: var(--ink-soft); }
.meta-box summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-3);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.meta-box summary::-webkit-details-marker { display: none; }
.meta-box summary::before {
  content: '›';
  font-size: 14px;
  color: var(--text-4);
  transition: transform 150ms;
  display: inline-block;
  width: 12px;
  text-align: center;
}
.meta-box details[open] summary::before { transform: rotate(90deg); }
.meta-box summary:hover { color: var(--ink); }
.source-link {
  display: block;
  padding: 8px 12px;
  margin: 4px 8px 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 12px;
  border-radius: 6px;
  transition: background 120ms;
}
.source-link:hover { background: var(--ink-soft); }
.source-snip { display: block; margin-top: 4px; color: var(--text-4); font-size: 11px; }
.trace-pre {
  margin: 4px 8px 8px;
  padding: 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-2);
}

/* Deep thinking (prompt-based) */
.think-block {
  margin: 6px 0 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  background: var(--ink-softer);
}
.think-block summary {
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}
.think-block summary::-webkit-details-marker { display: none; }
.think-block summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.6;
}
.think-block[open] summary { border-bottom: 1px solid var(--border-soft); }
.think-block .think-content {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}
.think-block .think-content p { margin: 0 0 8px; }
.think-block .think-content p:last-child { margin-bottom: 0; }


/* ── Phase C-2：消息时间戳 + per-message 删除按钮 ───────────── */
.msg-row { position: relative; }
.msg-time-stamp {
  font-size: 10.5px;
  color: var(--text-4);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 120ms;
  pointer-events: none;
  white-space: nowrap;
  flex-shrink: 0;
}
/* user：包在 .msg-bubble-wrap（flex row）里，stamp 在气泡左侧，底部对齐 */
.msg-bubble-wrap {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}
.msg-bubble-wrap .msg-time-stamp {
  position: static;
  margin-bottom: 2px; /* 与气泡底部留一点视觉呼吸 */
}
/* assistant：在 msg-actions bar 末尾，随 bar 垂直居中 */
.msg-actions .msg-time-stamp {
  position: static;
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
}
.msg-row:hover .msg-time-stamp { opacity: 1; }

.msg-delete-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  font-size: 11.5px;
  background: transparent;
  border: 0;
  color: var(--text-4);
  cursor: pointer;
  border-radius: 6px;
  transition: background 120ms, color 120ms;
}
.msg-delete-btn:hover {
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
}
html[data-theme="dark"] .msg-delete-btn:hover {
  background: rgba(248, 113, 113, 0.14);
  color: #f87171;
}
.msg-delete-btn:disabled { opacity: 0.5; cursor: default; }

/* session recap 行：挂在最后一条 assistant 消息底部，灰色块
   显示「※ recap: <topic>」，类似 Claude Code 终端里的 recap。
   只是给用户一个"AI 知道我们这次聊了什么"的弱提示，刻意保持低存在感
   ——不抢正文视觉、不打断阅读流，需要详情走 search_sessions 拉。
   长 topic 允许自然折行，不撑宽度也不截断（看不见的部分更糟）。 */
.session-recap-line {
  margin-top: 10px;
  padding-left: 10px;
  border-left: 2px solid var(--border);
  color: var(--text-4);
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.75;
  user-select: text;
  white-space: normal;
  word-break: break-word;
  max-width: 100%;
}

/* ── ask_user_question 作答卡片（分页） ──────────────────────────────── */
.uq-card {
  margin: 12px 0 6px;
  padding: 16px 18px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card-bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.uq-progress {
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-4);
}
/* 分页：当前题淡入，切页天然保留勾选状态 */
.uq-page { display: flex; flex-direction: column; gap: 10px; animation: uqFade 180ms var(--ease); }
.uq-page[hidden] { display: none; }
@keyframes uqFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.uq-header {
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 9px;
  border-radius: 6px;
  background: var(--ink-softer);
  color: var(--ink);
}
.uq-text { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.5; }
.uq-options { display: flex; flex-direction: column; gap: 7px; }
.uq-option {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 10px 12px;
  border: 1.5px solid var(--border-soft);
  border-radius: 10px;
  cursor: pointer;
  transition: background 140ms var(--ease), border-color 140ms var(--ease);
}
.uq-option:hover { background: var(--hover); border-color: var(--border); }
.uq-option.is-checked { border-color: var(--ink); background: var(--ink-softer); }
.uq-input { margin-top: 1px; accent-color: var(--ink); flex: none; width: 16px; height: 16px; }
.uq-option-text { display: flex; flex-direction: column; gap: 2px; }
.uq-option-label { font-size: 14px; font-weight: 500; color: var(--text); }
.uq-option-desc { font-size: 12.5px; color: var(--text-3); line-height: 1.45; }
.uq-other-input {
  margin: 4px 0 0 31px;
  padding: 8px 11px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: var(--card-bg-2);
  border: 1.5px solid var(--border-soft);
  border-radius: 9px;
  outline: none;
  transition: border-color 140ms var(--ease);
}
.uq-other-input:focus { border-color: var(--ink); }
.uq-other-input:disabled { opacity: 0.45; }
.uq-footer { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.uq-back {
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-3);
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.uq-back:hover { background: var(--hover); color: var(--text); }
.uq-submit {
  margin-left: auto;
  padding: 9px 22px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 9px;
  cursor: pointer;
  transition: filter 120ms, opacity 120ms;
}
.uq-submit:hover { filter: brightness(1.08); }
.uq-submit:disabled { opacity: 0.45; cursor: default; }
html[data-theme="dark"] .uq-submit { color: #14171a; }

/* ── 已作答折叠（复用 .sources-fold 外壳，仅定义内部排版） ──────────── */
.answered-qs { display: flex; flex-direction: column; gap: 10px; }
.answered-q { display: flex; flex-direction: column; gap: 3px; }
.answered-q-text { font-size: 13px; color: var(--text-2); line-height: 1.45; }
.answered-q-header {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  background: var(--ink-softer);
  color: var(--ink);
}
.answered-q-pick { font-size: 13.5px; font-weight: 600; color: var(--text); }
.answered-q-pick::before { content: "✓ "; color: var(--ink); }
