/* ═══════════════════════════════════════════
   Mini-Code Pro — Web UI
   Refined dark chat interface
   ═══════════════════════════════════════════ */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #0d0f13;
  --bg-raised:     #15181e;
  --bg-surface:    #1a1d24;
  --bg-hover:      #1f222a;
  --bg-muted:      #111420;
  --fg:            #e2e4e9;
  --fg-secondary:  #9ca0ac;
  --fg-muted:      #636878;
  --border:        #242832;
  --border-light:  #2e3340;

  --accent:        #6c8cff;
  --accent-dim:    rgba(108,140,255,0.12);
  --accent-glow:   rgba(108,140,255,0.25);

  --user-bg:       #2e3a5c;
  --user-text:     #e8ecf4;
  --assistant-bg:  #14171d;
  --assistant-border: #22262f;
  --tool-bg:       #14161c;
  --tool-border:   #8b7e4a;

  --red:           #f25a5a;
  --amber:         #d4a843;
  --green:         #3fb980;
  --orange:        #f0a53c;

  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --radius-xl:     20px;

  --font-sans:     "Inter", -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  --font-mono:     "JetBrains Mono", "Cascadia Code", "Fira Code", "SF Mono", ui-monospace, Menlo, monospace;

  /* 运行中扫光（双主题各自覆盖：夜间用亮色、日间用深色） */
  --sweep-glow:         rgba(255, 255, 255, 0.22);
  --sweep-glow-soft:    rgba(255, 255, 255, 0.12);

  /* 语义色（双主题各自覆盖） */
  --code-fg:            #d7dce6;
  --accent-hover:       #7a99ff;
  --red-hover:          #f57070;
  --toast-bg:           #2c3e50;
  --toast-fg:           #ffffff;
  --toast-error-bg:     #c0392b;
  --toast-error-fg:     #ffffff;
  --badge-anthropic:    #f0a6a6;
  --badge-openai:       #9ecbff;
  --overlay:            rgba(0, 0, 0, 0.55);
  --shadow-modal:       0 24px 64px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(108, 140, 255, 0.04);
  --choice-bg:          #171a21;
  --choice-option-bg:   #12151b;
  --choice-shadow:      0 14px 34px rgba(0, 0, 0, .24);
}

/* ── 日间主题（light）────────────────────────── */
[data-theme="light"] {
  --bg:            #f5f6f9;
  --bg-raised:     #ffffff;
  --bg-surface:    #edeff4;
  --bg-hover:      #e5e8ef;
  --bg-muted:      #dde0e8;
  --fg:            #1d2432;
  --fg-secondary:  #4c5568;
  --fg-muted:      #8b94a5;
  --border:        #e2e5ec;
  --border-light:  #d3d8e2;

  --accent:        #4d6bf0;
  --accent-dim:    rgba(77, 107, 240, 0.10);
  --accent-glow:   rgba(77, 107, 240, 0.22);

  --user-bg:       #e4eafc;
  --user-text:     #1d2432;
  --assistant-bg:  #ffffff;
  --assistant-border: #e3e7ef;
  --tool-bg:       #f2f4f8;
  --tool-border:   #b09a45;

  --red:           #d04545;
  --amber:         #a87816;
  --green:         #178a56;
  --orange:        #c07f1d;

  --code-fg:            #34415e;
  --accent-hover:       #3c5ae6;
  --red-hover:          #e05555;
  --toast-bg:           #eef1f7;
  --toast-fg:           #1d2432;
  --toast-error-bg:     #fbe7e7;
  --toast-error-fg:     #a83232;
  --badge-anthropic:    #c0534f;
  --badge-openai:       #2f6fb4;
  --overlay:            rgba(30, 36, 50, 0.4);

  /* 日间浅色背景：扫光改用深色，保证对比度与夜间一致 */
  --sweep-glow:         rgba(29, 36, 50, 0.20);
  --sweep-glow-soft:    rgba(29, 36, 50, 0.11);
  --shadow-modal:       0 24px 64px rgba(30, 36, 50, 0.18), 0 0 0 1px rgba(77, 107, 240, 0.06);
  --choice-bg:          #ffffff;
  --choice-option-bg:   #f8f9fc;
  --choice-shadow:      0 12px 30px rgba(36, 46, 72, .12);

  color-scheme: light;
}

:root { color-scheme: dark; }

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── Sidebar ────────────────────────────── */

#sidebar {
  width: 244px;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-weight: 650;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

#new-session-btn {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-secondary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#new-session-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
  border-color: var(--border-light);
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-icon-btn {
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.header-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--fg);
  border-color: var(--border-light);
}

/* 历史文件夹列表：目录名一行、完整路径小字换行 */
#history-dirs-list .dir-item {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  white-space: normal;
}
#history-dirs-list .dir-item-meta {
  margin-left: 0;
  opacity: 0.8;
  white-space: normal;
  word-break: break-all;
  font-size: 11px;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.session-group { margin-bottom: 5px; }
.session-group-head {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 7px 4px;
  cursor: pointer;
  font-size: 11px;
  text-align: left;
}
.session-group-head:hover { color: var(--fg-secondary); }
.session-group-head > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.session-group-head small { font-size: 10px; opacity: 0.7; }
.session-group-arrow { width: 10px; flex: 0 0 10px; }
.session-group.collapsed .session-group-body { display: none; }

.session-item {
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--fg-secondary);
  margin-bottom: 2px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  transition: background 0.12s;
  line-height: 1.35;
}

.session-item:hover { background: var(--bg-hover); color: var(--fg); }
.session-item.active {
  background: var(--accent-dim);
  color: var(--fg);
  border-left: 3px solid var(--accent);
  padding-left: 7px;
}

.session-item-main {
  overflow: hidden;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.session-item-main > span,
.session-item-main > small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item-main > small {
  color: var(--fg-muted);
  font-size: 10px;
  line-height: 1.3;
}

.session-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 7px;
  background: transparent;
}
.session-status.running {
  background: var(--accent);
  box-shadow: 0 0 7px var(--accent-glow);
  animation: sessionPulse 1.4s ease-in-out infinite;
}
.session-status.waiting_permission { background: var(--amber); box-shadow: 0 0 6px rgba(231,166,58,.35); }
@keyframes sessionPulse { 50% { opacity: .45; transform: scale(.82); } }

.session-item .del-btn {
  visibility: hidden;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

.session-item:hover .del-btn { visibility: visible; }
.session-item .del-btn:hover { color: var(--red); }

.session-actions-menu {
  position: fixed;
  z-index: 1200;
  width: 140px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lg);
}
.session-actions-menu button {
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--fg-secondary);
  text-align: left;
  padding: 7px 9px;
  cursor: pointer;
  font-size: 12px;
}
.session-actions-menu button:hover { background: var(--bg-hover); color: var(--fg); }
.session-actions-menu button.danger { color: var(--red); }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.work-dir {
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 10.5px;
  flex: 1;
  min-width: 0;
}

/* 左下角设置按钮（顶栏瘦身后移到这里） */
.sidebar-settings-btn {
  background: transparent;
  border: none;
  padding: 5px;
  border-radius: 6px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.sidebar-settings-btn:hover {
  color: var(--fg);
  background: var(--bg-hover);
}

/* ── Main Area ──────────────────────────── */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Topbar ─────────────────────────────── */

#topbar {
  height: 46px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
}

.topbar-left {
  font-size: 13px;
  font-weight: 550;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* ☰ 仅手机需要（桌面侧边栏常驻，无需菜单按钮） */
#menu-btn { display: none; }

#session-title {
  font-weight: 600;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
}

/* 顶栏分组：控制 / 视图 / 系统，组间细分隔线 */
.topbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-divider {
  width: 1px;
  height: 18px;
  background: var(--border-light);
  margin: 0 10px;
  flex-shrink: 0;
}

/* 模型选择已移到发送框 chip：下拉仅作隐藏的数据持有者 */
#topbar #provider-select { display: none; }

/* 下拉：无边框幽灵式，hover 才显底色 */
#topbar select {
  background: transparent;
  color: var(--fg-secondary);
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  height: 30px;
  max-width: 150px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#topbar select:hover, #topbar select:focus {
  background: var(--bg-hover);
  border-color: var(--border-light);
  color: var(--fg);
}

/* 图标按钮：统一 30px 幽灵按钮，hover 圆角底色 */
#topbar button {
  background: transparent;
  color: var(--fg-secondary);
  border: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

#topbar button:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

#topbar button:active {
  background: var(--accent-dim);
  color: var(--accent);
}

#topbar button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Status dot */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  margin-left: 8px;
}

.status-dot.idle  { background: var(--green); }
.status-dot.busy  { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); animation: pulse 1.4s ease-in-out infinite; }
.status-dot.error { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ── Messages ───────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  /* 只允许纵向滚动：横向固定，手机端左右滑不再把内容带出界面 */
  overflow-x: hidden;
  /* 移动端触屏：惯性平滑滚动 + 阻止滚动链穿透到 body + 只认纵向手势 */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message {
  /* min-width: 0 允许 flex 子项收缩，超长内容（URL/连续字符）不再把消息撑出容器 */
  min-width: 0;
  max-width: 100%;
  padding: 6px 20px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* User message — compact right-aligned bubble */
.message.user {
  align-self: flex-end;
  max-width: 68%;
  margin-right: 16px;
  padding: 7px 14px;
  border-radius: 14px;
  background: var(--user-bg);
  color: var(--user-text);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

/* Assistant message — left-aligned bubble */
.message.assistant {
  align-self: flex-start;
  width: min(820px, calc(100% - 56px));
  max-width: 82%;
  margin: 3px 0 3px 20px;
  padding: 12px 16px 13px;
  border-radius: 15px;
  background: var(--assistant-bg);
  border: 1px solid var(--assistant-border);
  font-size: 13.5px;
  color: var(--fg);
  box-shadow: 0 1px 0 rgba(255,255,255,.018);
}

.message.assistant .text {
  line-height: 1.72;
  letter-spacing: .002em;
  overflow-wrap: anywhere;
}

.message.assistant > .text + .text { margin-top: 9px; }

/* 缓存命中率小字（DeepSeek usage 透传，CLI 实时打印的 web 版） */
/* 统计条可挂在 assistant 消息内或消息容器末尾（最终回复底部），共用同一样式 */
.cache-stats {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(128, 128, 128, 0.3);
  font-size: 11px;
  color: var(--fg-muted);
  opacity: 0.85;
  user-select: none;
}

.message.assistant .text p { margin: 0 0 0.72em; }
.message.assistant .text p:last-child { margin-bottom: 0; }

.message.assistant .text h1,
.message.assistant .text h2,
.message.assistant .text h3 {
  margin: 1.15em 0 0.5em;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -.012em;
}

.message.assistant .text h1 { font-size: 1.22em; }
.message.assistant .text h2 { font-size: 1.12em; }
.message.assistant .text h3 { font-size: 1.02em; }

.message.assistant .text ul,
.message.assistant .text ol {
  padding-left: 1.45em;
  margin: 0.55em 0 0.75em;
}

.message.assistant .text li { margin-bottom: 0.3em; padding-left: .1em; }

.message.assistant .text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.message.assistant .text blockquote {
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 12px;
  margin: 0.5em 0;
  color: var(--fg-secondary);
}

.message.assistant .text a {
  color: var(--accent);
  text-decoration: none;
}

.message.assistant .text a:hover { text-decoration: underline; }

/* Inline & block code */
.message code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(255,255,255,0.06);
  padding: 1.5px 5px;
  border-radius: 4px;
  color: var(--code-fg);
}

.message pre {
  background: var(--tool-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tool-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  overflow-x: auto;
  max-width: 100%;
  margin: 0.5em 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-secondary);
}

.message pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: inherit;
}

/* Thinking block */
.thinking {
  color: var(--fg-muted);
  font-style: italic;
  font-size: 12px;
  border-left: 2px solid var(--border-light);
  padding: 2px 0 2px 10px;
  margin-bottom: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(255,255,255,0.02);
  border-radius: 0 4px 4px 0;
}

/* 思考、正文、工具直接按真实时间线交错；每个过程项独立折叠。 */
.thinking-step {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.018);
  overflow: hidden;
}

.thinking-step > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 3px 9px;
  cursor: pointer;
  color: var(--fg-secondary);
  font-size: 12px;
  user-select: none;
  list-style: none;
}

.thinking-step > summary::-webkit-details-marker,
.tool-details > summary::-webkit-details-marker { display: none; }
.timeline-state { width: 14px; color: var(--accent); text-align: center; flex: 0 0 auto; }
.timeline-label { color: var(--fg-secondary); font-weight: 600; flex: 0 0 auto; }
.thinking-preview-wrap,
.tool-group-ticker-wrap {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  white-space: nowrap;
  mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 18px), transparent 100%);
}
.thinking-preview,
.tool-group-ticker {
  display: inline-block;
  max-width: none;
  color: var(--fg-muted);
  white-space: nowrap;
  padding: 0 20px 0 8px;
}
.timeline-expand { margin-left: auto; color: var(--fg-muted); font-size: 10px; flex: 0 0 auto; }
.thinking-step > .thinking { margin: 0; padding: 8px 10px 9px 30px; max-height: 220px; overflow: auto; border: 0; border-top: 1px solid var(--border); }
.thinking-step.running .thinking-preview { animation: activityTicker 22s linear infinite; }

.tool-group {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.014);
  overflow: hidden;
}
.tool-group > summary {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 3px 9px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  overflow: hidden;
}
.tool-group > summary::-webkit-details-marker { display: none; }
.tool-group-state { width: 14px; flex: 0 0 auto; text-align: center; color: var(--green); }
.tool-group-label { flex: 0 0 auto; color: var(--fg-secondary); font-weight: 600; }
.tool-group-meta { margin-left: auto; flex: 0 0 auto; color: var(--fg-muted); font-size: 10px; }
.tool-group-items { padding: 4px 7px 6px 22px; border-top: 1px solid var(--border); }
.tool-group.error { border-color: color-mix(in srgb, var(--red) 42%, var(--border)); }
.tool-group.error .tool-group-state,
.tool-group.error .tool-group-meta { color: var(--red); }
.tool-group.running.is-latest-running > summary::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 46%;
  transform: translateX(-150%) skewX(-18deg);
  background: linear-gradient(90deg, transparent, var(--sweep-glow), transparent);
  animation: toolSweep 1.35s ease-in-out infinite;
  pointer-events: none;
}
.tool-group.running.is-latest-running .tool-group-ticker { color: var(--fg); animation: activityTicker 18s linear infinite; }

.tool-row { margin: 1px 0; font-family: var(--font-mono); font-size: 11.5px; }
.tool-details > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 2px 5px;
  cursor: pointer;
  list-style: none;
  border-radius: 4px;
}
.tool-details > summary:hover { background: rgba(255,255,255,.035); }
.tool-state { width: 14px; text-align: center; color: var(--green); }
.tool-row:not([data-result-attached="true"]) .tool-state { color: var(--fg-muted); }
.tool-row.error .tool-state { color: var(--red); }
.tool-summary { color: var(--fg-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-expand { margin-left: auto; color: var(--fg-muted); font-size: 10px; }
.tool-row .tool-section { margin: 3px 5px 6px 26px; color: var(--fg-muted); }
.tool-row .tool-detail-label { margin: 5px 0 2px; font-size: 10px; text-transform: uppercase; color: var(--fg-muted); }
.tool-row .tool-section pre { max-height: 260px; overflow: auto; margin: 2px 0; white-space: pre-wrap; }
.tool-row.is-latest-running .tool-summary { color: var(--fg); }
/* 运行中的工具行：从左到右的扫光（toolSweep）动画。
   0d59e8f 重构时误删了 tool-row 级扫光，只留下 tool-group 头部极淡的一条，
   导致"每个工具运行时闪一下"的效果消失，这里按 a501e36 原版恢复。 */
.tool-row.running > .tool-details > summary {
  position: relative;
  overflow: hidden;
}
.tool-row.running > .tool-details > summary::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 38%;
  transform: translateX(-140%) skewX(-18deg);
  background: linear-gradient(90deg, transparent, var(--sweep-glow-soft), transparent);
  animation: toolSweep 1.35s ease-in-out infinite;
  pointer-events: none;
}
.delegate-body { padding: 4px 8px 8px 25px; border-top: 1px solid var(--border); }

@keyframes toolSweep {
  0% { transform: translateX(-140%) skewX(-18deg); }
  65%, 100% { transform: translateX(360%) skewX(-18deg); }
}
@keyframes timelineTextPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}
@keyframes activityTicker {
  0%, 12% { transform: translateX(0); }
  88%, 100% { transform: translateX(-38%); }
}

.change-summary {
  margin: 9px 0 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.018);
  font-size: 12px;
}
.change-summary > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  padding: 7px 10px;
  color: var(--fg-secondary);
  font-weight: 600;
}
.change-summary > summary::-webkit-details-marker { display: none; }
.change-total { font-family: var(--font-mono); color: var(--fg-muted); font-weight: 400; }
.change-files { border-top: 1px solid var(--border); padding: 4px 8px; }
.change-file { display: grid; grid-template-columns: 24px minmax(0,1fr) auto; gap: 7px; padding: 5px 4px; font-family: var(--font-mono); cursor: pointer; border-radius: 4px; }
.change-file:hover, .change-file.active { background: rgba(255,255,255,.045); }
.change-file:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.change-status { color: var(--fg-muted); }
.change-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-secondary); }
.change-lines { white-space: nowrap; }
.change-undo {
  margin: 6px 2px 3px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--fg-muted);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}
.change-undo:hover { color: var(--fg); border-color: var(--border-light); }
.change-diff { grid-column: 1 / -1; margin: 2px 2px 7px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: rgba(0,0,0,.14); }
.change-diff.hidden { display: none; }
.change-diff-loading, .change-diff-error { padding: 10px; color: var(--fg-muted); }
.change-diff-loading { display: flex; align-items: center; gap: 8px; }
.change-diff-error { color: var(--red); }
.change-diff-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--fg-secondary); }
.change-diff-toolbar button { border: 1px solid var(--border); border-radius: 4px; background: transparent; color: var(--fg-secondary); padding: 3px 7px; font-size: 10px; cursor: pointer; }
.change-diff-toolbar button:hover { color: var(--fg); border-color: var(--border-light); }
.diff-code { max-height: 420px; overflow: auto; padding: 5px 0; font-family: var(--font-mono); font-size: 11px; line-height: 1.45; }
.diff-line { min-width: max-content; padding: 0 9px; white-space: pre; color: var(--fg-muted); }
.diff-line.add-line { color: var(--green); background: rgba(48,180,100,.08); }
.diff-line.del-line { color: var(--red); background: rgba(220,70,70,.08); }
.diff-line.hunk-line { color: var(--accent); background: rgba(90,130,255,.07); }
.diff-omitted { padding: 8px 9px; color: var(--fg-muted); border-top: 1px solid var(--border); }

@media (prefers-reduced-motion: reduce) {
  .tool-row.running > .tool-details > summary::after,
  .tool-group.running.is-latest-running > summary::after,
  .tool-group.running.is-latest-running .tool-group-ticker,
  .thinking-step.running .thinking-preview { animation: none; }
}

#send-btn.queue {
  background: var(--accent);
  color: white;
}
.add { color: var(--green); }
.del { color: var(--red); }

/* System message */
.message.system {
  background: transparent;
  color: var(--fg-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 6px 0;
  max-width: 100%;
}

.message.assistant { position: relative; }
.message-copy {
  display: block;
  margin: 5px 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
}
.message.assistant:hover > .message-copy,
.message-copy:focus { opacity: 1; }

/* Tool message */
.message.tool {
  background: var(--tool-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--tool-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 12px;
  margin: 6px 0;
  color: var(--fg-secondary);

}

.message.tool .tool-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--fg);
  font-size: 12.5px;
  margin-bottom: 4px;
}

.message.tool .tool-head .tool-icon { color: var(--tool-border); }
.message.tool .tool-head .tool-id   { color: var(--fg-muted); font-weight: 400; font-size: 11px; }

.message.tool .tool-section {
  margin-top: 4px;
  color: var(--fg-muted);
  font-size: 11.5px;
}

.message.tool .tool-result {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--fg-secondary);
}

.message.tool.error { border-left-color: var(--red); }

.message pre {
  background: rgba(0,0,0,0.3);
  padding: 8px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 6px 0;
}

/* ── Permission Banner ──────────────────── */

.permission-banner {
  margin: 0 18px 10px;
  padding: 12px 16px;
  background: rgba(212,168,67,0.08);
  border: 1px solid rgba(212,168,67,0.25);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.permission-banner.hidden { display: none; }

.permission-banner .perm-tool {
  font-weight: 600;
  font-size: 13px;
  color: var(--amber);
}

.permission-banner .perm-prompt {
  font-size: 13px;
  color: var(--fg);
  white-space: pre-wrap; /* 危险警告等多行文案按换行渲染 */
}

.permission-banner .perm-input {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px 10px;
  max-height: 100px;
  overflow: auto;
  white-space: pre-wrap;
}

.permission-banner .perm-actions {
  display: flex;
  gap: 8px;
}

.permission-banner button {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  transition: filter 0.15s;
}

.permission-banner button:hover { filter: brightness(1.1); }

.perm-allow        { background: var(--green); color: white; }
.perm-allow-always { background: var(--accent); color: white; }
.perm-deny         { background: var(--red); color: white; }

/* ── Composer ───────────────────────────── */

#composer {
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding: 10px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

/* 模型 chip 行 + 弹出列表 */
.composer-model-row {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  max-width: 260px;
}
.model-chip:hover {
  border-color: var(--accent);
  color: var(--fg);
  background: var(--bg-hover);
}
#model-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-chip-arrow { font-size: 9px; color: var(--fg-muted); }
.model-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px); /* 向上弹出，避免遮挡输入框 */
  z-index: 300;
  min-width: 200px;
  max-width: 280px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.model-menu.hidden { display: none; }

.composer-input-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.composer-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.img-btn {
  flex: none;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--fg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.img-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--fg);
  background: var(--bg-hover);
}

.img-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* 待发送图片预览条 */
.img-preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 2px 0;
}

.img-preview-row.hidden { display: none; }

.img-preview-item {
  position: relative;
  display: inline-block;
}

.img-preview-thumb {
  display: block;
  max-width: 96px;
  max-height: 96px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border);
  object-fit: cover;
}

.img-preview-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: #e5484d;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

/* 已发送/历史消息里的图片 */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.msg-image {
  max-width: 260px;
  max-height: 260px;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border);
  object-fit: contain;
}

#input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 180px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#input::placeholder { color: var(--fg-muted); }

#send-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0 22px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 550;
  cursor: pointer;
  height: 42px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

#send-btn:hover  { background: var(--accent-hover); }
#send-btn:active { transform: scale(0.97); }

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Stop button — red, shown when model is executing */
#send-btn.stop {
  background: var(--red);
  color: white;
  animation: stopPulse 1.8s ease-in-out infinite;
}

#send-btn.stop:hover {
  background: var(--red-hover);
}

@keyframes stopPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(242,90,90,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(242,90,90,0); }
}

/* ── Thinking indicator ──────────────────── */

.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg-muted);
  font-size: 12.5px;
  padding: 4px 0;
}

.thinking-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  flex-shrink: 0;
  animation: thinkBounce 1.2s ease-in-out infinite;
}

@keyframes thinkBounce {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50%      { transform: translateY(-4px); opacity: 1; }
}

/* ── Scrollbar ──────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }

::-webkit-scrollbar-track { background: transparent; }

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* ── Empty state ────────────────────────── */

.empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: auto;
  gap: 8px;
  opacity: 0.4;
  user-select: none;
  pointer-events: none;
}

.empty-icon {
  font-size: 36px;
  color: var(--accent);
  opacity: 0.5;
  margin-bottom: 4px;
}

.empty-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.02em;
}

.empty-sub {
  font-size: 13px;
  color: var(--fg-secondary);
}

/* ── Login Overlay ──────────────────────── */

#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

#login-overlay.hidden { display: none; }

.login-card {
  text-align: center;
  width: 320px;
}

.login-logo {
  font-size: 40px;
  color: var(--accent);
  opacity: 0.6;
  margin-bottom: 12px;
}

.login-title {
  font-size: 22px;
  font-weight: 650;
  color: var(--fg);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13px;
  color: var(--fg-muted);
  margin-bottom: 20px;
}

#login-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  outline: none;
  letter-spacing: 4px;
  transition: border-color 0.2s;
}

#login-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#login-input::placeholder {
  letter-spacing: 0;
  color: var(--fg-muted);
}

.login-error {
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

.login-error.hidden { display: none; }

#login-btn {
  width: 100%;
  margin-top: 14px;
  padding: 10px 0;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: inherit;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s;
}

#login-btn:hover { background: var(--accent-hover); }

/* ── Hamburger menu button ──────────────── */

#menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--fg-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  margin-right: 8px;
  border-radius: 4px;
  line-height: 1;
}

#menu-btn:hover { color: var(--fg); background: var(--bg-hover); }

/* ── Sidebar overlay (mobile) ──────────── */

#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: rgba(0,0,0,0.5);
}

/* ═══════════════════════════════════════════
   Mobile: max-width 768px
   ═══════════════════════════════════════════ */

@media (max-width: 768px) {

  #menu-btn {
    display: block;
    font-size: 24px;
    padding: 4px 8px;
  }

  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  #sidebar.open { transform: translateX(0); }

  .session-group-head { padding-top: 9px; font-size: 12px; }
  .session-item { min-height: 38px; font-size: 13px; }

  #main { width: 100%; }

  #topbar {
    height: 50px;
    padding: 0 8px;
    gap: 4px;
  }

  .topbar-left { flex: 0 0 auto; }

  /* 窄屏显示 ☰（会话列表抽屉入口） */
  #menu-btn { display: inline-flex; }

  .topbar-right {
    min-width: 0;
    flex: 1;
    justify-content: flex-end;
    gap: 4px;
  }

  #topbar select {
    font-size: 12px;
    padding: 4px 6px;
    max-width: 84px;
  }

  #topbar button {
    font-size: 12px;
    padding: 0;
  }

  /* 窄屏空间紧张：隐藏分组分隔线 */
  .topbar-divider { display: none; }
  .topbar-group { gap: 2px; }

  .status-dot { width: 8px; height: 8px; margin-left: 0; }

  .messages {
    padding: 8px 0;
    gap: 2px;
  }

  /* 流式输出期间新消息不断插入，fadeIn 动画（translateY）会在滑动时造成视觉晃动，移动端关闭 */
  .message { padding: 6px 12px; animation: none; }

  .message.user {
    max-width: 85%;
    margin-right: 8px;
    padding: 6px 12px;
    font-size: 13px;
  }

  .message.assistant {
    width: calc(100% - 8px);
    max-width: 100%;
    margin-left: 4px;
    padding: 9px 12px;
    font-size: 13px;
  }

  .message pre {
    font-size: 11px;
    padding: 8px 10px;
  }

  .message code { font-size: 0.85em; }

  #composer {
    padding: 8px 10px;
    gap: 6px;
  }

  #input {
    font-size: 16px; /* 16px 防止 iOS Safari 聚焦时自动缩放 */
    padding: 8px 10px;
    min-height: 40px;
    max-height: 120px;
  }

  #send-btn {
    font-size: 12px;
    padding: 0 14px;
    height: 36px;
  }

  .permission-banner {
    margin: 0 8px 6px;
    padding: 10px 12px;
  }

  .permission-banner button { font-size: 11px; padding: 4px 10px; }

  /* 阶段1.2: 窄屏强制隐藏（手机用浮层 #dir-picker / #file-editor） */
  .force-hidden-on-narrow { display: none !important; }

  /* 顶部栏 select 折叠（窄屏由 ⋯ 菜单代理） */
  .topbar-hidden-on-narrow { display: none !important; }

  /* 阶段1.5: 状态坞在窄屏避让 composer（自动收起到输入框上方） */
  .status-dock { pointer-events: none; }
  .status-dock > * { pointer-events: auto; }
  #usage-bar { bottom: 70px; }

  /* 阶段1.6: 设置面板窄屏底部抽屉化 */
  .settings-panel.mobile-view .settings-card {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 8vh;
    max-width: none;
    width: 100%;
    border-radius: 16px 16px 0 0;
    animation: slideUp 0.2s ease;
  }
  .settings-panel.mobile-view .settings-layout {
    flex-direction: column;
  }
  .settings-panel.mobile-view .settings-nav {
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 6px;
    gap: 4px;
    flex-shrink: 0;
  }
  .settings-panel.mobile-view .settings-nav-group { display: none; }
  .settings-panel.mobile-view .settings-nav-item {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
    white-space: nowrap;
  }
  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .empty-hint { padding: 20px; }
  .empty-icon { font-size: 28px; }
  .empty-title { font-size: 17px; }
  .empty-sub { font-size: 12px; }
}

/* 阶段1.4: 顶部栏 ⋯ 溢出菜单（全局——JS 在任何屏宽都会创建菜单，
   此前误写在 768px 媒体查询内，宽屏下菜单无样式且 .hidden 不生效，
   四个按钮（模型/思考/权限/主题）会裸显示在页面上） */
#topbar-overflow-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 16px;
  line-height: 1;
}
#topbar-overflow-btn.hidden { display: none; }
.overflow-menu {
  position: fixed;
  z-index: 200;
  min-width: 200px;
  max-width: 88vw;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  padding: 4px;
  display: flex;
  flex-direction: column;
}
.overflow-menu.hidden { display: none; }
/* 主视图 / 子菜单视图：各占一列，互斥显示 */
.overflow-menu .ov-view {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.overflow-menu .ov-view.hidden { display: none; }
.overflow-menu button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  min-height: 40px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.overflow-menu button:hover { background: var(--bg-hover); }
.overflow-menu button:active { background: var(--bg-hover); }
/* 子菜单返回行 */
.overflow-menu .ov-back {
  color: var(--fg-secondary);
  font-weight: 600;
}
.overflow-menu .ov-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
/* 选项行（⋯ 子菜单 / 发送框模型菜单共用）：✓ 标记当前值 */
.overflow-menu .ov-option,
.model-menu .ov-option {
  display: flex;
  align-items: center;
  gap: 8px;
}
.overflow-menu .ov-option .ov-opt-check,
.model-menu .ov-option .ov-opt-check {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
  color: var(--accent);
  font-weight: 700;
}
.overflow-menu .ov-option.checked .ov-opt-label,
.model-menu .ov-option.checked .ov-opt-label {
  color: var(--accent);
  font-weight: 550;
}
.overflow-menu .ov-option:disabled,
.model-menu .ov-option:disabled {
  opacity: 0.45;
  cursor: default;
}
.overflow-menu .ov-option:disabled:active,
.model-menu .ov-option:disabled:active { background: transparent; }
/* 发送框模型菜单：按钮基础样式（与 ⋯ 菜单按钮一致） */
.model-menu button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  min-height: 40px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
}
.model-menu button:hover { background: var(--bg-hover); }
.model-menu button:active { background: var(--bg-hover); }

/* ===== 任务计划面板 ===== */
.todo-panel {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.todo-panel.hidden { display: none; }
.todo-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.todo-arrow {
  display: inline-block;
  font-size: 10px;
  transition: transform 0.15s;
}
.todo-panel:not(.collapsed) .todo-arrow {
  transform: rotate(90deg);
}
.todo-panel.collapsed .todo-list {
  display: none;
}
.todo-count {
  font-weight: 400;
  font-size: 11px;
  opacity: 0.8;
}
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 2px 0;
  font-size: 13px;
  line-height: 1.4;
}
.todo-item.active .todo-text { color: var(--accent, #4f8cff); font-weight: 600; }
.todo-item.done .todo-text { text-decoration: line-through; opacity: 0.55; }
.todo-mark { flex-shrink: 0; }

/* ===== 子代理块 ===== */
.tool-delegate {
  border: 1px solid var(--accent, #4f8cff);
  border-radius: 6px;
}
.subagent-task {
  font-size: 13px;
  margin: 4px 0;
  color: var(--text);
}
.subagent-status {
  font-size: 12px;
  color: var(--muted);
  margin: 4px 0;
}
.subagent-result {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.subagent-result-head {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}
.subagent-result-head.error {
  color: #e74c3c;
}
.subagent-result-body {
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.5;
}
.subagent-more {
  font-size: 12px;
  color: var(--accent, #4f8cff);
  cursor: pointer;
  margin-top: 4px;
}

/* ===== 子代理实时事件 ===== */
.subagent-tools {
  margin: 6px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.subagent-tool {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(128, 128, 128, 0.07);
  flex-wrap: wrap;
}
.subagent-tool-icon { flex-shrink: 0; line-height: 1.6; }
.subagent-tool-name {
  font-weight: 600;
  flex-shrink: 0;
  min-width: 44px;
  color: var(--text);
}
.subagent-tool-input {
  flex: 1 1 120px;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.6;
}
.subagent-tool-state {
  flex-shrink: 0;
  font-size: 11px;
  line-height: 1.6;
}
.subagent-tool-state.running { color: var(--muted); }
.subagent-tool-state.ok { color: #2ecc71; }
.subagent-tool-state.error { color: #e74c3c; }
.subagent-tool-result {
  flex-basis: 100%;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  padding-left: 22px;
  white-space: pre-wrap;
  word-break: break-all;
}
.subagent-tool-result .subagent-more { font-size: 11px; }

/* 顶栏子代理运行中 pill（淡色胶囊，运行时才出现） */
.subagent-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
  color: var(--accent);
  white-space: nowrap;
  animation: subagent-pulse 1.6s ease-in-out infinite;
}
.subagent-pill.hidden { display: none; }
@keyframes subagent-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* 子代理完成 toast（右下角浮出） */
.subagent-toast {
  position: fixed;
  right: 16px;
  bottom: 84px;
  z-index: 300;
  max-width: 80vw;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.subagent-toast.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.subagent-toast.error {
  background: var(--toast-error-bg);
  color: var(--toast-error-fg);
}
.subagent-toast.hidden { display: none; }

/* ===== 工作目录选择浮层 ===== */
.dir-picker {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dir-picker.hidden { display: none; }

.dir-picker-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 500px;
  max-width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dir-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-picker-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg);
}
.dir-picker-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.dir-picker-close:hover { color: var(--fg); }

.dir-picker-path {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-up {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-secondary);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.dir-up:hover { border-color: var(--accent); color: var(--fg); }
.dir-current {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-secondary);
  word-break: break-all;
  flex: 1;
}

.dir-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 180px;
  max-height: 52vh;
  padding: 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.dir-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dir-item:hover { background: var(--bg-hover); }
.dir-item-dir { color: var(--fg); }
.dir-item-file { color: var(--fg-muted); cursor: default; }
.dir-item-file:hover { background: none; }
.dir-item-hidden { opacity: 0.45; }
.dir-item-up { color: var(--accent); font-weight: 500; }
.dir-item-empty { color: var(--fg-muted); cursor: default; justify-content: center; }
.dir-item-download {
  margin-left: auto;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.dir-item-download:hover { color: var(--accent); background: var(--bg-hover); }

/* 行尾 meta：文件大小 + 修改时间（靠右，弱化显示，不换行） */
.dir-item-meta {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--fg-muted);
  opacity: 0.7;
  white-space: nowrap;
  pointer-events: none;
}

.dir-picker-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-error { flex: 1; font-size: 12px; color: var(--red); }
.dir-error.hidden { display: none; }
.dir-btn {
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: filter 0.15s;
}
.dir-btn:hover { filter: brightness(1.1); }
.dir-btn-ghost {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-secondary);
}
.dir-btn-primary { background: var(--accent); color: white; font-weight: 550; }

@media (max-width: 768px) {
  .dir-picker { padding: 0; align-items: stretch; }
  .dir-picker-card { width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: none; }
  .dir-list { max-height: none; min-height: 0; }
}

/* ===== 文件编辑器浮层 ===== */
.file-editor {
  position: fixed;
  inset: 0;
  z-index: 210;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.file-editor.hidden { display: none; }

.file-editor-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 720px;
  max-width: 100%;
  height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.file-editor-path {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-secondary);
  word-break: break-all;
  flex: 1;
}

.file-editor-text {
  flex: 1;
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  tab-size: 2;
}
.file-editor-text:focus { box-shadow: inset 0 0 0 1px var(--accent); }

.file-editor-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.file-editor-status {
  flex: 1;
  font-size: 12px;
  color: var(--fg-muted);
}
.file-editor-status.ok { color: var(--green); }
.file-editor-status.err { color: var(--red); }

@media (max-width: 768px) {
  .file-editor { padding: 0; align-items: stretch; }
  .file-editor-card { width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: none; }
}

/* ===== 目录选择器：操作栏 / 多选 / 上传 / 删除 ===== */
.dir-picker-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.dir-picker-actions .dir-btn {
  padding: 5px 10px;
  font-size: 12px;
}
.dir-sel-count {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.dir-sel-count.hidden { display: none; }

.dir-btn-danger {
  background: var(--red);
  color: white;
  font-weight: 550;
}
.dir-btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }

/* 多选模式：圆形选择框 + 选中高亮 */
.dir-item-check {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--fg-muted);
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  transition: all 0.12s;
  margin-right: 2px;
}
.dir-item.sel {
  background: var(--accent-dim);
  color: var(--fg);
}
.dir-item.sel .dir-item-check {
  background: var(--accent);
  border-color: var(--accent);
}
.dir-item.sel .dir-item-check::after { content: '✓'; color: #fff; }

/* 上传按钮进行中 */
.dir-btn-uploading { opacity: 0.6; pointer-events: none; }

@media (max-width: 768px) {
  .dir-picker-actions { gap: 4px; }
  .dir-picker-actions .dir-btn { padding: 5px 8px; font-size: 11.5px; }
  .dir-picker-title { font-size: 12.5px; }
}

/* ===== 桌面版：文件树侧边栏（≥769px 显示） ===== */
#dir-sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: width 0.15s ease;
}
/* 折叠：收成 34px 细条，只留 📂 展开按钮 */
#dir-sidebar.collapsed { width: 34px; }
#dir-sidebar.collapsed .dir-sidebar-head,
#dir-sidebar.collapsed .dir-sidebar-path,
#dir-sidebar.collapsed .dir-sidebar-list,
#dir-sidebar.collapsed .dir-sidebar-foot { display: none; }
#dir-sidebar.collapsed .dir-collapsed-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 10px 0;
  cursor: pointer;
  font-size: 15px;
  color: var(--fg-secondary);
  transition: color 0.15s, background 0.15s;
}
#dir-sidebar.collapsed .dir-collapsed-strip:hover {
  color: var(--fg);
  background: var(--bg-hover);
}
.dir-collapsed-strip { display: none; }
.dir-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-sidebar-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 2px 6px;
  margin-left: -6px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}
.dir-sidebar-title:hover { background: var(--bg-hover); }
.dir-sidebar-actions { display: flex; align-items: center; gap: 4px; }
.dir-sidebar-actions .dir-btn { padding: 4px 8px; font-size: 11.5px; }
.dir-sidebar-path {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-sidebar-path .dir-up { width: 24px; height: 24px; font-size: 12px; }
.dir-sidebar-path .dir-current { font-size: 11px; }
.dir-sidebar-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.dir-sidebar-list .dir-item { padding: 5px 8px; font-size: 12px; }
.dir-sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.dir-sidebar-foot .dir-btn { padding: 4px 10px; font-size: 11.5px; }
#dir-sidebar-error { flex: 1; }

/* ===== 桌面版：多文件编辑面板（聊天区上方，可收起） ===== */
#editor-panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 55vh;
  min-height: 15vh;
  max-height: 85vh;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
#editor-panel.hidden { display: none; }
.editor-tabs {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  overflow-x: auto;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
}
.editor-tabs::-webkit-scrollbar { height: 3px; }
.file-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  font-size: 12px;
  color: var(--fg-secondary);
  cursor: pointer;
  white-space: nowrap;
  background: transparent;
  user-select: none;
  flex-shrink: 0;
  max-width: 220px;
}
.file-tab:hover { color: var(--fg); background: var(--bg-hover); }
.file-tab.active {
  background: var(--bg-raised);
  color: var(--fg);
  border-color: var(--accent);
}
.file-tab-name { overflow: hidden; text-overflow: ellipsis; }
.file-tab.dirty .file-tab-name { color: var(--amber); }
.file-tab-close {
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
}
.file-tab-close:hover { color: var(--red); background: var(--bg-hover); }
.editor-text {
  flex: 1;
  min-height: 120px;
  background: var(--bg);
  color: var(--fg);
  border: none;
  outline: none;
  resize: none;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  overflow: auto;
  overscroll-behavior: contain;
  tab-size: 2;
}
.editor-text:focus { box-shadow: inset 0 0 0 1px var(--accent); }
.editor-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.editor-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-muted);
  word-break: break-all;
  flex: 1;
}
.editor-foot .file-editor-status { flex: 0 0 auto; }

@media (max-width: 768px) {
  #dir-sidebar { display: none; }
  #editor-panel { display: none !important; }
}

/* ===== 编辑器面板：拖拽手柄（自由调高） ===== */
.editor-resize-handle {
  height: 6px;
  flex-shrink: 0;
  cursor: ns-resize;
  background: transparent;
  transition: background 0.15s;
  position: relative;
}
.editor-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: var(--border-light);
}
.editor-resize-handle:hover { background: var(--accent-dim); }
.editor-resize-handle:hover::after { background: var(--accent); }

/* topbar 图标按钮：统一由 #topbar button 幽灵式规则控制 */

/* 拖拽过程中禁止文本选择，避免误选 */
body.resizing { cursor: ns-resize; user-select: none; }

/* ── 状态坞（composer 上方固定区：记忆卡片 / 压缩提示 / 轮次明细 / 费用栏） ──
   容器本身透明无背景：没有内容时完全不可见，只有出现元素时才占用空间 */

.status-dock {
  flex-shrink: 0;
  width: 100%;
  padding: 0 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 常驻费用栏：本轮 + 累计 + 高峰徽标（纯文字行，无背景块） */
.usage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 8px;
  font-size: 12px;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  user-select: none;
  border-bottom: 1px solid transparent;
}

.usage-bar.warn { color: var(--amber); }

.usage-main { flex: 1; }

.usage-detail-btn {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.usage-detail-btn:hover { opacity: 1; }

/* 轮次明细面板 */
.usage-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.usage-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-secondary);
  border-bottom: 1px solid var(--border);
}

.usage-detail-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
}

.usage-detail-body {
  max-height: 220px;
  overflow-y: auto;
  padding: 4px 12px 8px;
}

.usage-row {
  display: grid;
  grid-template-columns: 3em 1fr 1fr 1fr auto;
  gap: 8px;
  padding: 2px 0;
  font-size: 12px;
  color: var(--fg-secondary);
  font-variant-numeric: tabular-nums;
}

.usage-row .u-i { color: var(--fg-muted); }
.usage-row .u-r { text-align: right; }
.usage-row .u-c { text-align: right; color: var(--fg-muted); }
.usage-row .u-mark { color: var(--red); font-size: 11px; }

.usage-row.bad { color: var(--red); }
.usage-row.bad .u-c { color: var(--red); }

.usage-row.total {
  border-top: 1px dashed var(--border);
  margin-top: 4px;
  padding-top: 5px;
  color: var(--fg);
  font-weight: 600;
}

/* 压缩提示条 */
.compress-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--fg-secondary);
}

.compress-toast.active {
  border-color: var(--accent-dim);
  background: var(--accent-dim);
  color: var(--accent);
  animation: compressPulse 1.2s ease-in-out infinite;
}

.compress-toast.done {
  border-color: rgba(63,185,128,0.4);
  background: rgba(63,185,128,0.1);
  color: var(--green);
}

/* 前缀断链提醒条：缓存前缀变化提示（警示色，区别于压缩提示） */
.prefix-toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 12.5px;
  border: 1px solid rgba(240,165,60,0.45);
  background: rgba(240,165,60,0.12);
  color: var(--orange, #f0a53c);
}

/* 状态坞元素 hidden 时真正隐藏（此前只有个别元素定义了 .hidden 规则，
   usage-detail / compress-toast / usage-bar / memory-card 加了 hidden 类
   仍显示 → 明细面板收不起、压缩提示背景残留） */
.status-dock > .hidden,
.usage-bar.hidden,
.usage-detail.hidden,
.compress-toast.hidden,
.prefix-toast.hidden,
.memory-card.hidden {
  display: none;
}

@keyframes compressPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* 记忆确认卡片 */
.memory-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.memory-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-secondary);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.memory-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
}

.memory-item:last-of-type { border-bottom: none; }

.memory-text {
  flex: 1;
  font-size: 12.5px;
  color: var(--fg);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}

.memory-edit-input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 5px 9px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}

.memory-btn {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--fg-secondary);
  font-size: 12px;
  padding: 3px 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.memory-btn:hover { border-color: var(--accent); color: var(--accent); }

.memory-btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.memory-btn.primary:hover {
  background: rgba(108,140,255,0.22);
  border-color: var(--accent);
}

.memory-card-foot {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

/* 子代理工具行：整行可点击展开详情（输入 + 返回） */
.subagent-tool {
  cursor: pointer;
  transition: background 0.15s;
}
.subagent-tool:hover { background: rgba(128, 128, 128, 0.14); }

.subagent-tool-detail {
  flex-basis: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  max-height: 260px;
  overflow: auto;
}
/* 收起状态（toggleSubAgentToolDetail 依赖此规则，缺失则收起失效） */
.subagent-tool-detail.hidden { display: none; }
.subagent-tool-detail pre {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--fg-secondary);
}
.subagent-tool-detail pre + pre {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

/* ===============================================
   设置面板（模型 / 记忆 / 经验 / 扩展）
   =============================================== */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: settings-fade 0.18s ease;
}
@keyframes settings-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
/* 🔴 全屏遮罩必须能真正隐藏——此前漏写本规则，hidden class 不生效，
   面板一加载就全屏盖住应用且关不掉（设置/聊天全部"卡死"，刷新也没用） */
.settings-panel.hidden { display: none; }
.settings-panel.hidden > .settings-card { display: none; }
.settings-card {
  background:
    radial-gradient(900px 320px at 50% -100px, var(--accent-glow, rgba(108, 140, 255, 0.09)), transparent 60%),
    var(--bg-raised, #15181e);
  border: 1px solid var(--border-light, #2e3340);
  border-radius: var(--radius-lg, 16px);
  width: min(960px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal, 0 24px 64px rgba(0, 0, 0, 0.55));
  animation: settings-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
  overflow: hidden;
}
@keyframes settings-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border, #242832);
  flex-shrink: 0;
}
.settings-head-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.settings-title-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  border: 1px solid var(--accent-glow, rgba(108, 140, 255, 0.25));
  font-size: 17px;
  color: var(--accent, #6c8cff);
  flex-shrink: 0;
}
.settings-title-text { display: flex; flex-direction: column; gap: 2px; }
.settings-title { font-size: 15px; font-weight: 650; letter-spacing: 0.2px; }
.settings-title-sub { font-size: 11.5px; color: var(--fg-muted, #636878); }
.settings-close {
  background: none;
  border: none;
  color: var(--fg-muted, #636878);
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.settings-close:hover {
  background: var(--bg-hover, #1f222a);
  color: var(--fg, #e2e4e9);
}

/* 左导航 + 内容区 */
.settings-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}
.settings-nav {
  width: 178px;
  flex-shrink: 0;
  border-right: 1px solid var(--border, #242832);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-surface, #1a1d24);
  overflow-y: auto;
}
.settings-nav-group {
  font-size: 10.5px;
  color: var(--fg-muted, #636878);
  padding: 10px 12px 4px;
  letter-spacing: 0.05em;
}
.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--fg-secondary, #9ca0ac);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}
.settings-nav-item:hover { background: var(--bg-hover, #1f222a); color: var(--fg, #e2e4e9); }
.settings-nav-item.active {
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  color: var(--accent, #6c8cff);
  font-weight: 600;
}
.settings-nav-item.disabled { opacity: 0.45; cursor: not-allowed; }
.settings-nav-item.disabled:hover { background: transparent; color: var(--fg-secondary, #9ca0ac); }
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent, #6c8cff);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.settings-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 22px 22px;
}
.settings-tab { display: none; }
.settings-tab.active { display: block; animation: settings-fade 0.15s ease; }
.settings-tab-title {
  font-size: 14.5px;
  font-weight: 650;
  color: var(--fg, #e2e4e9);
  margin-bottom: 4px;
}
.settings-tab-desc {
  font-size: 12px;
  color: var(--fg-muted, #636878);
  margin-bottom: 14px;
  line-height: 1.55;
}

/* 通用设置（主题等） */
.general-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--border, #242832);
}
.general-row:last-child { border-bottom: none; }
.general-label { font-size: 13px; font-weight: 550; color: var(--fg, #e2e4e9); }
.general-desc { font-size: 11.5px; color: var(--fg-muted, #636878); margin-top: 2px; }
.theme-toggle-group {
  display: flex;
  gap: 2px;
  background: var(--bg-surface, #1a1d24);
  border: 1px solid var(--border, #242832);
  border-radius: 9px;
  padding: 3px;
  flex-shrink: 0;
}
.theme-btn {
  border: none;
  background: transparent;
  color: var(--fg-secondary, #9ca0ac);
  padding: 5px 14px;
  border-radius: 7px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 550;
  transition: all 0.15s;
}
.theme-btn.active {
  background: var(--bg-raised, #15181e);
  color: var(--accent, #6c8cff);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

/* 记忆面板 */
.memory-editor-wrap { display: flex; flex-direction: column; gap: 10px; }
.memory-editor {
  width: 100%;
  min-height: 280px;
  background: var(--bg, #0d0f13);
  border: 1px solid var(--border, #242832);
  border-radius: var(--radius-sm, 8px);
  color: var(--fg, #e2e4e9);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  padding: 10px 12px;
  resize: vertical;
}
.memory-editor:focus { outline: none; border-color: var(--accent, #6c8cff); }
.memory-stats {
  display: flex;
  gap: 14px;
  font-size: 11.5px;
  color: var(--fg-muted, #636878);
  flex-wrap: wrap;
}
.memory-stats b { color: var(--fg-secondary, #9ca0ac); font-weight: 600; }
.memory-scenarios { margin-top: 16px; }
.memory-scenario-row {
  display: flex;
  gap: 12px;
  padding: 6px 2px;
  font-size: 12px;
  border-bottom: 1px dashed var(--border, #242832);
  color: var(--fg-secondary, #9ca0ac);
}
.memory-scenario-row .date {
  color: var(--fg-muted, #636878);
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  padding-top: 1px;
}
.memory-scenario-row .preview { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memory-scenario-row { transition: background 0.15s; }
.memory-scenario-row:hover { background: var(--bg-hover, rgba(108,140,255,0.06)); }
.memory-scenario-row.expanded { background: var(--bg-active, rgba(108,140,255,0.1)); border-bottom-color: transparent; }
.scenario-inline-viewer {
  border: 1px solid var(--border, #242832);
  border-radius: 8px;
  padding: 12px;
  margin: 4px 0 8px;
  background: var(--bg-surface, #1a1d24);
}

/* 经验面板 */
.exp-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.exp-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-surface, #1a1d24);
  border: 1px solid var(--border, #242832);
  border-radius: 9px;
  padding: 3px;
}
.exp-tab-btn {
  border: none;
  background: transparent;
  color: var(--fg-secondary, #9ca0ac);
  font-size: 12px;
  font-weight: 550;
  padding: 5px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.exp-tab-btn.active {
  background: var(--bg-raised, #15181e);
  color: var(--accent, #6c8cff);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.exp-search {
  flex: 1;
  min-width: 140px;
  background: var(--bg, #0d0f13);
  border: 1px solid var(--border, #242832);
  border-radius: 8px;
  color: var(--fg, #e2e4e9);
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
}
.exp-search:focus { outline: none; border-color: var(--accent, #6c8cff); }
.exp-list { display: flex; flex-direction: column; gap: 8px; }
.exp-card {
  background: var(--bg-surface, #1a1d24);
  border: 1px solid var(--border, #242832);
  border-radius: var(--radius-md, 12px);
  padding: 12px 14px;
  transition: border-color 0.15s;
}
.exp-card:hover { border-color: var(--border-light, #2e3340); }
.exp-card-top { display: flex; align-items: center; gap: 10px; }
.exp-score {
  min-width: 44px;
  height: 26px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  color: var(--accent, #6c8cff);
  font-weight: 700;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.exp-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg, #e2e4e9);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.exp-scope-pill {
  font-size: 10.5px;
  border: 1px solid var(--border-light, #2e3340);
  border-radius: 999px;
  padding: 1px 8px;
  color: var(--fg-muted, #636878);
  flex-shrink: 0;
}
.exp-tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.exp-tag {
  font-size: 10.5px;
  color: var(--fg-secondary, #9ca0ac);
  background: var(--bg, #0d0f13);
  border: 1px solid var(--border-light, #2e3340);
  border-radius: 999px;
  padding: 1px 8px;
}
.exp-body { margin-top: 8px; font-size: 12px; color: var(--fg-secondary, #9ca0ac); line-height: 1.65; }
.exp-body .lbl { color: var(--fg-muted, #636878); font-size: 10.5px; font-weight: 600; margin-right: 4px; }
.exp-actions { display: flex; gap: 6px; margin-top: 10px; }
.exp-action-btn {
  border: 1px solid var(--border, #242832);
  background: transparent;
  color: var(--fg-secondary, #9ca0ac);
  border-radius: 7px;
  padding: 3px 10px;
  font-size: 11.5px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.exp-action-btn:hover { background: var(--bg-hover, #1f222a); color: var(--fg, #e2e4e9); }
.exp-action-btn.like:hover { color: var(--green, #3fb980); border-color: var(--green, #3fb980); }
.exp-action-btn.dislike:hover { color: var(--red, #f25a5a); border-color: var(--red, #f25a5a); }
.exp-empty { text-align: center; color: var(--fg-muted, #636878); font-size: 12.5px; padding: 36px 0; }

/* 待确认经验卡片 */
.pending-card {
  border: 1px solid var(--accent-glow, rgba(108, 140, 255, 0.25));
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  border-radius: var(--radius-md, 12px);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.pending-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent, #6c8cff);
  margin-bottom: 6px;
}
.pending-fields { font-size: 12px; color: var(--fg-secondary, #9ca0ac); line-height: 1.7; }
.pending-fields b { color: var(--fg, #e2e4e9); font-weight: 600; }
.pending-actions { display: flex; gap: 8px; margin-top: 10px; }

@media (max-width: 720px) {
  .settings-layout { flex-direction: column; }
  .settings-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border, #242832);
    padding: 8px;
  }
  .settings-nav-item { white-space: nowrap; }
  .settings-nav-group { display: none; }
}
.settings-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--fg-secondary, #9ca0ac);
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  border: 1px solid var(--accent-glow, rgba(108, 140, 255, 0.25));
  border-radius: var(--radius-sm, 8px);
  padding: 9px 12px;
  margin-bottom: 14px;
  line-height: 1.55;
}
.settings-hint-icon { font-size: 13px; line-height: 1.5; }
.settings-provider-list { display: flex; flex-direction: column; gap: 8px; }
.settings-provider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 1px solid var(--border, #242832);
  border-radius: var(--radius-sm, 8px);
  background: var(--bg-surface, #1a1d24);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.settings-provider-row:hover {
  border-color: var(--border-light, #2e3340);
  background: var(--bg-hover, #1f222a);
}
.settings-provider-row.active {
  border-color: var(--accent, #6c8cff);
  background: linear-gradient(90deg, var(--accent-dim, rgba(108, 140, 255, 0.12)), var(--bg-surface, #1a1d24) 60%);
  box-shadow: inset 3px 0 0 var(--accent, #6c8cff);
}
.sp-name { flex: 2; font-weight: 600; display: flex; align-items: center; gap: 6px; min-width: 0; }
.sp-fmt { flex: 1; font-size: 12px; }
.sp-model { flex: 1.5; font-size: 12px; color: var(--fg-secondary, #9ca0ac); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-key { flex: 1; font-size: 12px; }
.sp-actions { display: flex; gap: 6px; }
.settings-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-light, #2e3340);
  color: var(--fg-secondary, #9ca0ac);
  background: rgba(255, 255, 255, 0.03);
  letter-spacing: 0.3px;
}
.settings-tag.preset {
  color: var(--accent, #6c8cff);
  border-color: var(--accent-glow, rgba(108, 140, 255, 0.25));
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
}
.settings-add { margin-top: 12px; text-align: right; }
.settings-form-wrap { margin-top: 16px; }
/* 注意：该元素 class 只有 "hidden"（无 settings-form-wrap 类），必须用 id 选择器 */
#settings-form-wrap.hidden { display: none; }
.settings-form-title {
  font-weight: 650;
  font-size: 14px;
  margin-bottom: 14px;
  padding-left: 10px;
  border-left: 3px solid var(--accent, #6c8cff);
  line-height: 1.3;
}
.settings-section-title {
  font-size: 11px;
  font-weight: 650;
  color: var(--fg-muted, #636878);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 14px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border, #242832);
}
.settings-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.settings-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--fg-secondary, #9ca0ac);
}
.settings-form-grid input,
.settings-form-grid select,
.settings-form-json textarea,
.settings-form-price-grid input {
  background: var(--bg, #0d0f13);
  border: 1px solid var(--border, #242832);
  border-radius: 7px;
  color: var(--fg, #e2e4e9);
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.settings-form-grid input::placeholder,
.settings-form-json textarea::placeholder { color: var(--fg-muted, #636878); }
.settings-form-grid input:hover:not(:disabled),
.settings-form-grid select:hover,
.settings-form-json textarea:hover,
.settings-form-price-grid input:hover { border-color: var(--border-light, #2e3340); }
.settings-form-grid input:focus,
.settings-form-grid select:focus,
.settings-form-json textarea:focus,
.settings-form-price-grid input:focus {
  outline: none;
  border-color: var(--accent, #6c8cff);
  box-shadow: 0 0 0 3px var(--accent-dim, rgba(108, 140, 255, 0.12));
  background: var(--bg-surface, #1a1d24);
}
.settings-form-grid input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.settings-form-price {
  margin-top: 4px;
  background: var(--bg-surface, #1a1d24);
  border: 1px solid var(--border, #242832);
  border-radius: var(--radius-sm, 8px);
  padding: 12px 14px;
}
.settings-form-price-title { font-size: 11.5px; color: var(--fg-muted, #636878); margin-bottom: 10px; }
.settings-form-price-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px 12px;
}
.settings-form-price-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--fg-secondary, #9ca0ac);
}
.settings-form-json { margin-top: 4px; }
.settings-form-json label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
  color: var(--fg-secondary, #9ca0ac);
}
.settings-form-json textarea {
  font-family: var(--font-mono, ui-monospace, Consolas, monospace);
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}
.settings-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
  padding-top: 14px;
  border-top: 1px solid var(--border, #242832);
}
.settings-form-msg {
  margin-right: auto;
  font-size: 12px;
  color: var(--fg-secondary, #9ca0ac);
}
.settings-form-msg.ok { color: var(--green, #3fb980); }
.settings-form-msg.warn { color: var(--amber, #d4a843); }
.pf-vision-hint {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--fg-muted, #888);
  line-height: 1.5;
}
/* Provider 行内徽章：Key 状态 / 格式 */
.sp-key-badge,
.sp-fmt-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.sp-key-badge {
  color: var(--fg-muted, #636878);
  border: 1px solid var(--border-light, #2e3340);
  background: rgba(255, 255, 255, 0.03);
}
.sp-key-badge.ok {
  color: var(--green, #3fb980);
  border-color: rgba(63, 185, 128, 0.3);
  background: rgba(63, 185, 128, 0.08);
}
.sp-fmt-badge.anthropic {
  color: var(--badge-anthropic);
  border-color: rgba(240, 166, 166, 0.25);
  background: rgba(240, 166, 166, 0.07);
}
.sp-fmt-badge.openai {
  color: var(--badge-openai);
  border-color: rgba(158, 203, 255, 0.25);
  background: rgba(158, 203, 255, 0.07);
}
@media (max-width: 640px) {
  .settings-form-grid { grid-template-columns: 1fr; }
  .settings-form-price-grid { grid-template-columns: 1fr 1fr; }
  .settings-provider-row { flex-wrap: wrap; }
  .sp-name { flex: 1 1 60%; }
}

/* ===== 通用确认弹窗（替代原生 confirm） ===== */
.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: confirm-fade 0.15s ease;
}
.confirm-modal.hidden { display: none; }

.confirm-card {
  width: 430px;
  max-width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 24px 26px 20px;
  text-align: center;
  animation: confirm-pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.confirm-card:focus { outline: none; }

.confirm-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--amber);
  background: rgba(212, 168, 67, 0.12);
  border: 1px solid rgba(212, 168, 67, 0.25);
}
.confirm-icon.warn {
  color: var(--red);
  background: rgba(242, 90, 90, 0.12);
  border-color: rgba(242, 90, 90, 0.28);
  box-shadow: 0 0 18px rgba(242, 90, 90, 0.15);
}
.confirm-icon.info {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: rgba(108, 140, 255, 0.3);
}

.confirm-title {
  margin-top: 14px;
  font-size: 15.5px;
  font-weight: 650;
  color: var(--fg);
  letter-spacing: -0.01em;
  line-height: 1.4;
}
.confirm-desc {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg-secondary);
  word-break: break-all;
}

.confirm-list {
  margin-top: 14px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  max-height: 140px;
  overflow-y: auto;
}
.confirm-list.hidden { display: none; }
.confirm-list-item {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-secondary);
  line-height: 1.8;
  padding: 2px 6px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 经验编辑弹窗表单 */
.exp-form-label {
  font-size: 12px;
  color: var(--fg-secondary, #9ca0ac);
  font-weight: 550;
}
.exp-input {
  width: 100%;
  background: var(--bg, #0d0f13);
  border: 1px solid var(--border, #242832);
  border-radius: 8px;
  color: var(--fg, #e2e4e9);
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
  resize: vertical;
}
.exp-input:focus { outline: none; border-color: var(--accent, #6c8cff); }

/* ===== 通用选项选择提示条（choice-modal，内嵌于输入框上方，不再居中弹窗） ===== */
.choice-modal {
  position: relative;
  margin: 0 20px 12px;
  padding: 14px 15px 12px;
  background: var(--choice-bg);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  animation: confirm-fade 0.16s ease;
  box-shadow: var(--choice-shadow);
  overflow: hidden;
}
.choice-modal::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 45%, transparent));
}
.choice-modal.hidden { display: none; }

.choice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.choice-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--fg);
  letter-spacing: -0.01em;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.choice-close {
  flex: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--fg-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.choice-close:hover { background: var(--bg-hover); color: var(--fg); }

.choice-prompt {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--fg-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 90px;
  overflow-y: auto;
}
.choice-prompt:empty { display: none; }

.choice-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 7px;
  overflow-y: auto;
  max-height: 240px;
  padding: 1px;
}
.choice-option {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 18px;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--choice-option-bg);
  color: var(--fg);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform .14s, box-shadow .14s;
  position: relative;
  outline: none;
}
.choice-option:hover { background: var(--bg-hover); border-color: var(--border-light); transform: translateY(-1px); }
.choice-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 5px 16px var(--accent-dim);
}
.choice-option.danger {
  border-color: rgba(242, 90, 90, 0.45);
}
.choice-option.danger.selected {
  border-color: var(--red);
  background: rgba(242, 90, 90, 0.12);
  box-shadow: 0 0 0 1px var(--red) inset;
}
.choice-option .co-index {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--fg-muted);
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  transition: all 0.14s;
}
.choice-option.selected .co-index {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.choice-option.danger.selected .co-index {
  background: var(--red);
  border-color: var(--red);
}
.choice-option .co-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.choice-option .co-label { line-height: 1.4; overflow-wrap: anywhere; font-weight: 560; }
.choice-option .co-hint {
  font-size: 11px;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.choice-option .co-check {
  flex: none;
  font-size: 14px;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.16s, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.choice-option.selected .co-check {
  opacity: 1;
  transform: scale(1);
}

.choice-custom {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.choice-custom-label {
  font-size: 11px;
  color: var(--fg-muted);
  margin-bottom: 5px;
  font-weight: 550;
}
.choice-custom-row {
  display: flex;
  gap: 8px;
}
#choice-custom-input {
  flex: 1;
  min-width: 0;
  background: var(--choice-option-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--fg);
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
}
#choice-custom-input:focus { outline: none; border-color: var(--accent); }
#choice-custom-send {
  flex: none;
  min-width: 68px;
}

.choice-hint {
  font-size: 10.5px;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}

/* ===== 向导多步选择（wizard mode） ===== */

.wizard-steps {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px 0 8px;
  overflow-x: auto;
}
.wizard-steps.hidden { display: none; }
.wizard-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--fg-muted);
  white-space: nowrap;
  transition: color 0.2s;
}
.wizard-step.done { color: var(--green); }
.wizard-step.active { color: var(--accent); font-weight: 600; }
.wizard-step-circle {
  flex: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  border: 1.5px solid var(--border-light);
  color: var(--fg-muted);
  background: transparent;
  transition: all 0.2s;
}
.wizard-step.done .wizard-step-circle {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}
.wizard-step.active .wizard-step-circle {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}
.wizard-step-connector {
  flex: 1;
  min-width: 16px;
  height: 1.5px;
  background: var(--border);
  margin: 0 4px;
  transition: background 0.2s;
}
.wizard-step-connector.done { background: var(--green); }

.wizard-step-prompt {
  font-size: 12px;
  line-height: 1.6;
  color: var(--fg-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 60px;
  overflow-y: auto;
  padding-bottom: 6px;
}
.wizard-step-prompt.hidden { display: none; }

.wizard-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 7px;
  overflow-y: auto;
  max-height: 180px;
}
.wizard-options.hidden { display: none; }
.wizard-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--choice-option-bg);
  color: var(--fg);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
  position: relative;
  outline: none;
  user-select: none;
}
.wizard-option:hover { background: var(--bg-hover); border-color: var(--border-light); }
/* 键盘高亮（↑↓ 移动的当前项） */
.wizard-option.cursor {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
  background: var(--bg-hover);
}
.wizard-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
/* 多选：方形勾选框 */
.wizard-option .wo-checkbox {
  flex: none;
  width: 16px; height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: transparent;
  transition: all 0.14s;
}
.wizard-option.selected .wo-checkbox {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
/* 单选：圆形指示器 */
.wizard-option .wo-radio {
  flex: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.14s;
}
.wizard-option .wo-radio::after {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: transparent;
  transition: background 0.14s;
}
.wizard-option.selected .wo-radio {
  border-color: var(--accent);
}
.wizard-option.selected .wo-radio::after {
  background: var(--accent);
}
.wizard-option .wo-copy { min-width: 0; display: flex; flex: 1; flex-direction: column; gap: 2px; }
.wizard-option .wo-label { line-height: 1.4; overflow-wrap: anywhere; font-weight: 560; }
.wizard-option .wo-hint { color: var(--fg-muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wizard-custom {
  padding-top: 6px;
}
.wizard-custom.hidden { display: none; }
.wizard-custom input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  padding: 6px 10px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}
.wizard-custom input:focus { border-color: var(--accent); }

.wizard-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.wizard-nav.hidden { display: none; }
.wizard-step-count {
  font-size: 11.5px;
  color: var(--fg-muted);
}
.wizard-nav-btn {
  padding: 5px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--fg-secondary);
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.wizard-nav-btn:hover { border-color: var(--accent); color: var(--fg); }
.wizard-nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.wizard-next-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.wizard-next-btn:hover { background: var(--accent-hover); }
.wizard-next-btn:disabled { opacity: 0.5; }
.wizard-next-btn.confirm-btn {
  background: var(--green);
  border-color: var(--green);
}
.wizard-next-btn.confirm-btn:hover { filter: brightness(1.1); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
.wizard-next-btn.shake { animation: shake 0.35s ease; }

/* MCP 服务状态点 */
.mcp-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--fg-muted, #636878);
}
.mcp-status-dot.connected { background: var(--green, #3fb980); box-shadow: 0 0 6px var(--green, #3fb980); }
.mcp-status-dot.error { background: var(--red, #f25a5a); box-shadow: 0 0 6px var(--red, #f25a5a); }
.mcp-status-dot.connecting { background: var(--amber, #d4a843); animation: sessionPulse 1.4s ease-in-out infinite; }
.exp-scope-pill.ok { color: var(--green, #3fb980); border-color: rgba(63, 185, 128, 0.35); }
.exp-scope-pill.bad { color: var(--red, #f25a5a); border-color: rgba(242, 90, 90, 0.35); }

/* 技能 / MCP 编辑弹窗更宽 */
.skill-modal-card, .mcp-modal-card { width: 520px; }

/* 转圈（按钮内进度指示） */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--fg-muted, #636878);
  border-top-color: var(--accent, #6c8cff);
  border-radius: 50%;
  animation: mini-spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes mini-spin { to { transform: rotate(360deg); } }
.confirm-card button:disabled { opacity: 0.6; cursor: not-allowed; }

/* 轻量 toast（右下角） */
.mini-toast {
  position: fixed;
  right: 18px;
  bottom: 92px;
  z-index: 500;
  background: var(--toast-bg, #2c3e50);
  color: var(--toast-fg, #ffffff);
  font-size: 12.5px;
  padding: 9px 14px;
  border-radius: 9px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  max-width: 70vw;
}
.mini-toast.active { opacity: 1; transform: translateY(0); }
.mini-toast.warn { background: var(--toast-error-bg, #c0392b); color: var(--toast-error-fg, #ffffff); }
.mini-toast.ok { border: 1px solid var(--border-light, #2e3340); }
.confirm-list-item:hover { background: var(--bg-hover); color: var(--fg); }
.confirm-list-item.dirty { color: var(--amber); }
.confirm-list-more {
  font-size: 11px;
  color: var(--fg-muted);
  padding: 3px 6px 1px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.confirm-actions .dir-btn { min-width: 92px; padding: 8px 18px; font-size: 12.5px; }
.confirm-actions .dir-btn-danger {
  background: var(--red);
  box-shadow: 0 4px 14px rgba(242, 90, 90, 0.25);
}
.confirm-actions .dir-btn:focus-visible,
.dir-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@keyframes confirm-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes confirm-pop {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 480px) {
  .confirm-card { padding: 20px 18px 16px; }
  .confirm-actions { justify-content: stretch; }
  .confirm-actions .dir-btn { flex: 1; }
}

.local-command-result {
  position: relative;
  margin: 4px 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(127, 127, 127, .06);
  overflow: hidden;
}
.local-command-result.error { border-color: var(--red, #ef6464); }
.local-command-result summary {
  cursor: pointer;
  padding: 9px 64px 9px 12px;
  font-size: 13px;
  user-select: none;
}
.local-command-result pre {
  max-height: 520px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}
.local-command-copy {
  position: absolute;
  top: 5px;
  right: 7px;
  z-index: 1;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-card, #222);
  color: var(--text-muted);
  cursor: pointer;
}

/* ═══════════════════════════════════════════
   局域网扫码配对：QR 浮层（电脑端）
   ═══════════════════════════════════════════ */
.qr-panel {
  position: fixed;
  inset: 0;
  z-index: 130;
  background: var(--overlay, rgba(0, 0, 0, 0.55));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: settings-fade 0.18s ease;
}
/* 🔴 浮层隐藏规则必须存在——此前漏写，QR 面板一加载就裸显示盖住页面 */
.qr-panel.hidden { display: none; }

.qr-card {
  background:
    radial-gradient(900px 320px at 50% -100px, var(--accent-glow, rgba(108, 140, 255, 0.09)), transparent 60%),
    var(--bg-raised, #15181e);
  border: 1px solid var(--border-light, #2e3340);
  border-radius: var(--radius-lg, 16px);
  width: min(460px, 94vw);
  box-shadow: var(--shadow-modal, 0 24px 64px rgba(0, 0, 0, 0.55));
  animation: qr-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
  overflow: hidden;
}
@keyframes qr-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.qr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border, #242832);
}
.qr-head-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.qr-title-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  border: 1px solid var(--accent-glow, rgba(108, 140, 255, 0.25));
  font-size: 17px;
  color: var(--accent, #6c8cff);
}
.qr-title-text { display: flex; flex-direction: column; gap: 2px; }
.qr-title { font-size: 15px; font-weight: 650; color: var(--fg, #e2e4e9); }
.qr-title-sub { font-size: 12px; color: var(--fg-muted, #636878); }

.qr-body {
  display: flex;
  gap: 20px;
  padding: 20px;
  align-items: center;
}
.qr-canvas-wrap {
  position: relative;
  flex-shrink: 0;
  background: #ffffff;
  border: 1px solid #d8dbe3;
  border-radius: var(--radius-md, 12px);
  padding: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}
#qr-canvas { display: block; }
.qr-error {
  position: absolute;
  inset: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--red, #f25a5a);
  background: rgba(255, 255, 255, 0.94);
  border-radius: calc(var(--radius-md, 12px) - 6px);
}
.qr-error.hidden { display: none; }

.qr-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.qr-info-row { display: flex; flex-direction: column; gap: 4px; }
.qr-label { font-size: 11.5px; color: var(--fg-muted, #636878); }
.qr-url {
  font-family: var(--font-mono, ui-monospace, Menlo, monospace);
  font-size: 12px;
  color: var(--accent, #6c8cff);
  background: var(--bg-muted, #111420);
  border: 1px solid var(--border, #242832);
  border-radius: 8px;
  padding: 6px 10px;
  word-break: break-all;
  line-height: 1.5;
}
.qr-pin {
  font-family: var(--font-mono, ui-monospace, Menlo, monospace);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 10px;
  text-indent: 10px; /* 平衡 letter-spacing 尾距 */
  color: var(--fg, #e2e4e9);
  background: var(--accent-dim, rgba(108, 140, 255, 0.12));
  border: 1px solid var(--accent-glow, rgba(108, 140, 255, 0.25));
  border-radius: 10px;
  padding: 6px 4px;
  text-align: center;
}
.qr-info-row-tiny { margin-top: -6px; }
.qr-expires { font-size: 12px; color: var(--fg-muted, #636878); }
.qr-lan-warn {
  font-size: 12px;
  line-height: 1.5;
  color: var(--amber, #d4a843);
  background: color-mix(in srgb, var(--amber, #d4a843) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber, #d4a843) 35%, transparent);
  border-radius: 8px;
  padding: 8px 10px;
}
.qr-lan-warn.hidden { display: none; }
.qr-info-hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-muted, #636878);
  background: var(--bg-muted, #111420);
  border-radius: 8px;
  padding: 8px 10px;
}
.qr-refresh-btn { align-self: flex-start; margin-top: 2px; }

/* ═══════════════════════════════════════════
   局域网扫码配对：PIN 输入页（手机端）
   ═══════════════════════════════════════════ */
.pair-page {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg, #0d0f13);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 🔴 同上：隐藏规则必须存在，否则 PIN 页常驻显示 */
.pair-page.hidden { display: none; }
body.pair-mode { overflow: hidden; }

.pair-card { width: min(340px, 90vw); text-align: center; }
.pair-logo {
  font-size: 44px;
  color: var(--accent, #6c8cff);
  opacity: 0.6;
  margin-bottom: 12px;
}
.pair-title {
  font-size: 22px;
  font-weight: 650;
  color: var(--fg, #e2e4e9);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.pair-sub {
  font-size: 13px;
  color: var(--fg-muted, #636878);
  margin-bottom: 22px;
  line-height: 1.6;
}
.pair-input-row { margin-bottom: 14px; }
#pair-pin-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-raised, #15181e);
  border: 1px solid var(--border, #242832);
  border-radius: var(--radius-md, 12px);
  color: var(--fg, #e2e4e9);
  font-family: var(--font-mono, ui-monospace, Menlo, monospace);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 12px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
#pair-pin-input:focus {
  border-color: var(--accent, #6c8cff);
  box-shadow: 0 0 0 3px var(--accent-dim, rgba(108, 140, 255, 0.12));
}
#pair-pin-input::placeholder {
  letter-spacing: 0;
  color: var(--fg-muted, #636878);
  font-weight: 400;
}
.pair-submit {
  width: 100%;
  padding: 12px 0;
  font-size: 15px;
  border-radius: var(--radius-md, 12px);
}
.pair-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.pair-error {
  margin-top: 12px;
  color: var(--red, #f25a5a);
  font-size: 13px;
}
.pair-error.hidden { display: none; }
.pair-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--fg-muted, #636878);
  line-height: 1.6;
}

/* 窄屏：QR 卡片纵向排布 */
@media (max-width: 768px) {
  .qr-body { flex-direction: column; align-items: center; }
  .qr-info { width: 100%; }
  .qr-refresh-btn { align-self: stretch; }
}
