/* Hermes Chat —— 深色优先，跟随系统亮暗模式 */

:root {
  --bg: #0f1115;
  --bg-elevated: #161a21;
  --bg-sidebar: #12151b;
  --bg-input: #1b2029;
  --bg-hover: #222836;
  --border: #262c38;
  --border-strong: #333b4a;
  --code-bg: #12151b;
  --code-head-bg: #181c24;
  --code-fg: #d6dbe5;
  --hl-comment: #7c8594;
  --hl-keyword: #c792ea;
  --hl-string: #9ece6a;
  --hl-number: #ff9e64;
  --hl-title: #82aaff;
  --hl-attr: #e0af68;
  --hl-type: #4fd6be;
  --hl-meta: #9aa5ce;
  --text: #e6e9ef;
  --text-dim: #99a1b3;
  --text-faint: #6a7385;
  --accent: #5b8cff;
  --accent-hover: #6f9cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --danger: #f0616d;
  --success: #3ecf8e;
  --warning: #f3ad4e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.38);
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC",
          "Hiragino Sans GB", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

/* 浅色配色。两处定义是有意重复的：
   - 媒体查询这份负责「跟随系统」，但要让位给用户的显式选择，所以排除 data-theme="dark"
   - 属性选择器那份负责用户在界面上手动切到浅色
   纯 CSS 没法把两种条件合成一条规则，只能各写一遍。 */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f7f8fa;
    --bg-elevated: #ffffff;
    --bg-sidebar: #f0f2f5;
    --bg-input: #ffffff;
    --bg-hover: #e8ebf0;
    --border: #e0e4ea;
    --border-strong: #ccd2dc;
  --code-bg: #f6f7f9;
  --code-head-bg: #eef0f4;
  --code-fg: #24292f;
  --hl-comment: #6e7781;
  --hl-keyword: #a626a4;
  --hl-string: #0a7a3c;
  --hl-number: #b35900;
  --hl-title: #0550ae;
  --hl-attr: #8a5a00;
  --hl-type: #0b7285;
  --hl-meta: #57606a;
    --text: #1a1d23;
    --text-dim: #5b6472;
    --text-faint: #8b93a1;
    --accent: #2f6bff;
    --accent-hover: #1f5aef;
    --accent-soft: rgba(47, 107, 255, 0.1);
    --shadow: 0 8px 28px rgba(20, 30, 60, 0.1);
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-sidebar: #f0f2f5;
  --bg-input: #ffffff;
  --bg-hover: #e8ebf0;
  --border: #e0e4ea;
  --border-strong: #ccd2dc;
  --code-bg: #f6f7f9;
  --code-head-bg: #eef0f4;
  --code-fg: #24292f;
  --hl-comment: #6e7781;
  --hl-keyword: #a626a4;
  --hl-string: #0a7a3c;
  --hl-number: #b35900;
  --hl-title: #0550ae;
  --hl-attr: #8a5a00;
  --hl-type: #0b7285;
  --hl-meta: #57606a;
  --text: #1a1d23;
  --text-dim: #5b6472;
  --text-faint: #8b93a1;
  --accent: #2f6bff;
  --accent-hover: #1f5aef;
  --accent-soft: rgba(47, 107, 255, 0.1);
  --shadow: 0 8px 28px rgba(20, 30, 60, 0.1);
  color-scheme: light;
}

* { box-sizing: border-box; }

/* hidden 属性来自 UA 样式表，优先级低于任何类选择器。下面好几处元素用了
   .lightbox / .drop-overlay / .send-btn 这类带 display 的类，会把 hidden 顶掉，
   所以这里显式兜底，否则遮罩层会一直挂在屏幕上。 */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------------- 登录页 ---------------- */

.auth-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 600px at 15% -10%, rgba(91, 140, 255, 0.16), transparent 60%),
    radial-gradient(800px 500px at 95% 110%, rgba(62, 207, 142, 0.1), transparent 55%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.auth-logo, .brand-logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8f6bff);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
}

.auth-brand h1 { margin: 0; font-size: 19px; letter-spacing: -0.2px; }
.auth-sub { margin: 2px 0 0; color: var(--text-dim); font-size: 12.5px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.auth-tab {
  flex: 1;
  padding: 8px 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.is-active {
  background: var(--accent);
  color: #fff;
}

.field { display: block; margin-bottom: 15px; }

.field > span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
}

.field em { font-style: normal; color: var(--text-faint); font-weight: 400; }

/* 项目弹窗里的 connect.json 摘要 */
.connect-block > span em { font-family: var(--mono); font-size: 11px; }

.connect-body {
  margin-top: 5px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.7;
}

.connect-row { display: flex; gap: 10px; }
.connect-k { flex: 0 0 108px; color: var(--text-faint); }
.connect-v { flex: 1; min-width: 0; word-break: break-all; }
.connect-v.is-mono { font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; max-height: 220px; overflow: auto; }

/* connect.json 的填写问题，比如把密码填进了 auth 字段 */
.connect-warn {
  margin-top: 6px;
  padding: 6px 9px;
  border-left: 2px solid var(--warning);
  border-radius: 0 4px 4px 0;
  background: rgba(243, 173, 78, 0.1);
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.6;
}

.connect-actions { display: flex; align-items: center; gap: 10px; margin-top: 7px; }
/* 提示文字很长，别把按钮挤成竖排：按钮不换行，提示自己折行 */
.connect-actions button { flex: 0 0 auto; white-space: nowrap; }
.connect-actions .connect-hint { flex: 1 1 auto; min-width: 0; }
/* 连通性实测结果：紧贴在对应的服务器 / 数据库行下面 */
.connect-probe .connect-v { font-size: 12px; }
.connect-probe.is-ok .connect-v { color: var(--success); }
.connect-probe.is-fail .connect-v { color: var(--danger); }
.connect-hint { color: var(--text-faint); font-size: 11.5px; }

/* 技能来源徽标：公共（PROJECTS_ROOT/_agent）还是项目私有 */
.detail-skill-scope {
  flex: 0 0 auto;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-faint);
  font-size: 10.5px;
  line-height: 16px;
}
.detail-skill-scope.is-shared { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* 输入框下方的实时提示，比如工作目录展开后的完整路径 */
.field-note {
  display: block;
  margin-top: 5px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 11.5px;
  word-break: break-all;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  width: 100%;
  padding: 11px 0;
  margin-top: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.form-error {
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid rgba(240, 97, 109, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(240, 97, 109, 0.1);
  color: var(--danger);
  font-size: 13px;
}

.auth-foot {
  margin: 18px 0 0;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

/* ---------------- 主布局 ---------------- */

.layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: 268px;
  flex: 0 0 268px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  transition: margin-left 0.22s ease;
}

.layout.sidebar-hidden .sidebar { margin-left: -268px; }

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

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 14.5px;
}

.brand-logo { width: 26px; height: 26px; font-size: 13px; border-radius: 8px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.btn-new {
  margin: 0 14px 12px;
  padding: 9px 0;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.btn-new:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.conv-list {
  flex: 1;
  /* flex 项默认 min-height: auto，撑到内容高度就不再收缩，
     overflow-y 便永远轮不到触发——侧栏还有项目面板在抢空间，必须显式放开 */
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.conv-group-label {
  padding: 12px 8px 5px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.conv-item:hover { background: var(--bg-hover); color: var(--text); }
.conv-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }

.conv-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-streaming-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse-stream 1.4s infinite ease-in-out;
  flex: 0 0 auto;
}

.conv-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: 0 0 auto;
}
.conv-item.is-unread .conv-item-title { color: var(--text); font-weight: 600; }

@keyframes pulse-stream {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.15); }
}

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

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
}

.agent-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 4px 9px;
  color: var(--text-faint);
  font-size: 11.5px;
}

.dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
}

.dot.is-ok { background: var(--success); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.16); }
.dot.is-bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(240, 97, 109, 0.16); }

.user-box {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 6px;
  border-radius: var(--radius-sm);
}

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8f6bff);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
}

.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-sub { color: var(--text-faint); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 主区域 ---------------- */

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.conv-title {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-projects {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
  max-width: 65%;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0;
}
.topbar-projects::-webkit-scrollbar { display: none; }

.topbar-proj-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.15s ease;
  user-select: none;
}
.topbar-proj-chip:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.06);
}
.topbar-proj-chip.is-primary {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: var(--accent-soft);
}
.topbar-proj-chip.is-primary:hover {
  border-color: var(--accent);
}
.topbar-proj-icon {
  font-size: 10px;
  color: var(--accent);
  line-height: 1;
}
.topbar-proj-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions { display: flex; gap: 2px; flex-shrink: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 0 8px;
  scroll-behavior: smooth;
}

.empty-state {
  max-width: 460px;
  margin: 8vh auto 0;
  padding: 0 24px;
  text-align: center;
}

.empty-logo { font-size: 42px; margin-bottom: 10px; }
.empty-state h2 { margin: 0 0 10px; font-size: 19px; font-weight: 600; }
.empty-state p { margin: 0 0 8px; color: var(--text-dim); font-size: 13.5px; }
.empty-hint { color: var(--text-faint) !important; font-size: 12.5px !important; }

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-input);
  font-family: var(--mono);
  font-size: 11.5px;
}

/* ---------------- 消息 ---------------- */

.msg {
  display: flex;
  gap: 13px;
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 24px 16px;
}

.msg-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  margin-top: 2px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
}

.msg-user .msg-avatar { background: linear-gradient(135deg, #4a7bff, #8f6bff); }
.msg-assistant .msg-avatar { background: linear-gradient(135deg, #21c08a, #12a3b8); }
.msg-error .msg-avatar { background: linear-gradient(135deg, #f0616d, #d4384a); }

.msg-body { flex: 1; min-width: 0; }

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.msg-name { font-size: 13px; font-weight: 600; }
.msg-time { color: var(--text-faint); font-size: 11px; }

/* 助手消息底部的统计行：时间 · 耗时 · token。淡色小字，不抢正文 */
.msg-foot {
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.msg-copy {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.msg:hover .msg-copy { opacity: 1; }
.msg-copy:hover { background: var(--bg-hover); color: var(--text); }

/* 自己发的消息靠右，套一层气泡；agent 的回答保持左侧平铺，
   长文本和代码块在平铺布局下更好读。 */
.msg-user { flex-direction: row-reverse; }

.msg-user .msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-user .msg-head {
  justify-content: flex-end;
  align-self: stretch;
}

/* 复制按钮挪到最左，name/time 才能贴着右边 */
.msg-user .msg-copy { order: -1; margin-left: 0; margin-right: auto; }

.msg-user .msg-content {
  max-width: min(100%, 620px);
  padding: 9px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 14px 14px 4px 14px;
  background: var(--accent-soft);
}

.msg-user .msg-images { justify-content: flex-end; }

.msg-content { font-size: 14.5px; line-height: 1.7; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-content > :first-child { margin-top: 0; }
.msg-content > :last-child { margin-bottom: 0; }
.msg-content p { margin: 0 0 10px; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 20px 0 8px;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.msg-content h1 { font-size: 20px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.msg-content h2 { font-size: 17.5px; }
.msg-content h3 { font-size: 15.5px; }
.msg-content h4, .msg-content h5, .msg-content h6 { font-size: 14.5px; }
.msg-content ul, .msg-content ol { margin: 0 0 10px; padding-left: 24px; }
.msg-content li { margin-bottom: 4px; }
.msg-content li > p { margin-bottom: 4px; }
.msg-content li > ul, .msg-content li > ol { margin: 4px 0 2px; }
.msg-content ul ul { list-style: circle; }
.msg-content li::marker { color: var(--text-dim); }
.msg-content li input[type="checkbox"] { margin: 0 6px 0 -18px; vertical-align: -1px; accent-color: var(--accent); }
.msg-content li:has(> input[type="checkbox"]) { list-style: none; }
.msg-content a { color: var(--accent); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.msg-content a:hover { border-bottom-color: var(--accent); }
.msg-content strong { font-weight: 650; }
.msg-content blockquote {
  margin: 0 0 10px;
  padding: 6px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--text-dim);
}
.msg-content blockquote > :last-child { margin-bottom: 0; }
.msg-content hr { margin: 18px 0; border: 0; border-top: 1px solid var(--border); }
.msg-content img { max-width: 100%; border-radius: var(--radius-sm); }

.msg-content code {
  padding: 1.5px 5px;
  border-radius: 5px;
  background: var(--bg-hover);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  font-family: var(--mono);
  font-size: 12.8px;
}

/* ---- 过程卡片：agent 调了哪些工具 ----------------------------------------
   放在正文上方。生成中展开、逐条追加，让人看到它在干活；生成完折叠成一行摘要，
   不抢正文的视线，想看细节再点开。 */

.msg-steps {
  margin: 0 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 12px;
  overflow: hidden;
}

.steps-head {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  text-align: left;
}

.steps-head:hover { background: var(--bg-hover); }
.steps-caret { color: var(--text-faint); font-size: 10px; transition: transform 0.15s; }
.msg-steps.is-collapsed .steps-caret { transform: rotate(-90deg); }
.msg-steps.is-collapsed .steps-list { display: none; }
.steps-title { flex: 1; }

.steps-spin {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: steps-spin 0.8s linear infinite;
}

@keyframes steps-spin { to { transform: rotate(360deg); } }

.steps-list {
  padding: 2px 6px 6px;
  border-top: 1px solid var(--border);
}

.step {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 5px;
  border-radius: 5px;
  line-height: 1.5;
}

.step-running { background: var(--accent-soft); }
/* 每步开始的时刻：等宽、灰，放最前面，扫一眼就能看出哪两步之间空了很久 */
.step-time {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 58px;
}
/* 「等待模型回复 · 已 N 秒」：没有工具在跑的那段时间 */
.step-wait { color: var(--text-dim); }
.step-wait .step-wait-text { flex: 1; min-width: 0; }
.step-wait.is-live { background: var(--accent-soft); }
.step-icon { flex: 0 0 18px; text-align: center; font-size: 12px; }
.step-name { flex: 0 0 auto; color: var(--text); font-weight: 500; }

.step-label {
  flex: 1;
  min-width: 0;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.step-tail {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.step-done .step-tail { color: var(--success); }

/* 能点开的行：鼠标是手，hover 有底色，展开后左边亮一条 */
.step.has-detail { cursor: pointer; }
.step.has-detail:hover { background: var(--bg-hover); }
.step.has-detail.is-open { background: var(--bg-hover); border-radius: 5px 5px 0 0; }
.step.has-detail .step-name::after {
  content: "▸";
  margin-left: 5px;
  color: var(--text-faint);
  font-size: 9px;
  transition: transform 0.15s;
  display: inline-block;
}
.step.has-detail.is-open .step-name::after { transform: rotate(90deg); }

.step-detail {
  margin: 0 5px 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background: var(--bg);
}

.step-block + .step-block { margin-top: 8px; }

.step-block-title {
  display: flex;
  align-items: center;
  margin-bottom: 4px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.step-block-copy {
  margin-left: auto;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 10.5px;
  opacity: 0;
  transition: opacity 0.12s;
}
.step-block:hover .step-block-copy { opacity: 1; }
.step-block-copy:hover { color: var(--text); border-color: var(--border-strong); }

.step-pre {
  margin: 0;
  padding: 7px 9px;
  max-height: 320px;
  overflow: auto;
  border-radius: 5px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}
.step-pre.is-args { color: var(--text-dim); }

.step-meta {
  margin-top: 5px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10.5px;
}

/* ---- 来源标注 ----------------------------------------------------------
   正文里的编号角标、行尾的来源署名、文末的来源清单。
   共同点是都要"在但不抢眼"：正文读起来不被打断，想追溯时一眼能找到。 */

.msg-content a.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 15px;
  margin: 0 1px 0 3px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  /* 用 vertical-align 而不是 <sup>，<sup> 会把整行行距撑开 */
  vertical-align: 1.5px;
  transition: background 0.15s, color 0.15s;
}

.msg-content a.cite:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

.msg-content .src-tag {
  margin-left: 6px;
  color: var(--text-faint);
  font-size: 11.5px;
  white-space: nowrap;
}

.msg-content .src-tag::before {
  margin-right: 4px;
  content: "·";
  opacity: 0.6;
}

.msg-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.msg-sources-label {
  margin-right: 2px;
  color: var(--text-faint);
  font-size: 11.5px;
}

.msg-content .msg-sources .src {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 9px 2.5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11.5px;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.msg-content .msg-sources .src:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

.msg-sources .src-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  border-radius: 3px;
  background: var(--bg-hover);
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.msg-sources .src:hover .src-n { color: var(--accent); }

/* 代码块：顶部一条语言/复制栏，下面是高亮的代码 */
.code-block {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 4px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--code-head-bg);
}

.code-lang {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: lowercase;
}

.code-copy {
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.code-copy:hover { color: var(--text); background: var(--bg-hover); border-color: var(--border-strong); }

.msg-content pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  background: transparent;
}

.msg-content pre code {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  font-size: 12.8px;
  line-height: 1.6;
  white-space: pre;
  color: var(--code-fg);
  font-variant-ligatures: none; /* != 别被连字画成 ≠，代码要所见即所得 */
}

/* 没有 .code-block 壳的 pre（预览、老消息里可能有） */
.msg-content > pre, .msg-content blockquote > pre, .msg-content li > pre {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
}

/* highlight.js 配色：跟随明暗主题的变量，不引它自带的主题文件 */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-meta .hljs-keyword, .hljs-template-tag { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--hl-string); }
.hljs-number, .hljs-literal, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--hl-number); }
.hljs-title, .hljs-title.function_, .hljs-title.class_, .hljs-section, .hljs-name { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-variable, .hljs-template-variable, .hljs-property, .hljs-params { color: var(--hl-attr); }
.hljs-built_in, .hljs-type, .hljs-class .hljs-title, .hljs-selector-class, .hljs-selector-id { color: var(--hl-type); }
.hljs-meta, .hljs-tag, .hljs-punctuation, .hljs-operator { color: var(--hl-meta); }
.hljs-deletion { color: var(--danger); }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }
.hljs-subst { color: var(--code-fg); }

.md-table {
  margin: 0 0 12px;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.msg-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.msg-content th, .msg-content td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.msg-content th:last-child, .msg-content td:last-child { border-right: 0; }
.msg-content tbody tr:last-child td { border-bottom: 0; }
.msg-content th { background: var(--bg-hover); font-weight: 600; }
.msg-content tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-hover) 45%, transparent); }
.msg-content th[align="right"], .msg-content td[align="right"] { text-align: right; }
.msg-content th[align="center"], .msg-content td[align="center"] { text-align: center; }
.msg-content td { white-space: normal; min-width: 60px; }

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 9px;
}

.msg-images img {
  max-width: 260px;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: zoom-in;
  transition: border-color 0.15s;
}

.msg-images img:hover { border-color: var(--accent); }

/* agent 导出的文件：正文下面一排下载卡片 */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.file-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 340px;
  padding: 8px 12px 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.file-card:hover { border-color: var(--accent); background: var(--bg); }
div.file-card { cursor: pointer; }
div.file-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.file-icon { font-size: 22px; line-height: 1; flex: none; }

.file-meta { display: flex; flex-direction: column; min-width: 0; }

.file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }

.file-dl {
  flex: none;
  margin-left: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.file-dl:hover { background: var(--accent); color: #fff; }

/* ---------- 文件预览弹窗 ---------- */

body.preview-open { overflow: hidden; }

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  width: min(1400px, 100%);
  height: min(92vh, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.preview-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.preview-meta { flex: 1; font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.preview-dl { padding: 5px 12px; font-size: 13px; text-decoration: none; }

.preview-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

/* Luckysheet 和 PDF 撑满整个内容区 */
.preview-sheet, .preview-pdf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.preview-docx {
  min-height: 100%;
  padding: 24px;
  background: #e9ebef;
}

.preview-docx .docx-wrapper { background: transparent; padding: 0; }
.preview-docx .docx-wrapper > section.docx { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18); margin-bottom: 20px; }

.preview-text { padding: 20px 26px; }

.preview-text pre {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.preview-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 24px;
}

.preview-status.is-error { color: var(--danger); }

.preview-status .spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@media (max-width: 720px) {
  .preview-modal { padding: 0; }
  .preview-panel { width: 100%; height: 100%; border-radius: 0; }
}

.msg-error-box {
  padding: 9px 12px;
  border: 1px solid rgba(240, 97, 109, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(240, 97, 109, 0.08);
  color: var(--danger);
  font-size: 13px;
}

.msg-warning {
  margin-top: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(243, 173, 78, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(243, 173, 78, 0.08);
  color: var(--warning);
  font-size: 12.5px;
}

.typing {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 1px;
  background: var(--accent);
  border-radius: 1px;
  vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { to { visibility: hidden; } }

/* ---------------- 输入区 ---------------- */

.composer-wrap {
  /* 项目选择器绝对定位在它上方，锚点就是这里 */
  position: relative;
  padding: 8px 24px 14px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.composer {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-input);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer.is-dragover { border-color: var(--accent); background: var(--accent-soft); }

.attach-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 4px 9px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 7px;
}

.attach-chip {
  position: relative;
  width: 62px;
  height: 62px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-hover);
}

.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 非图片文件：图标 + 文件名，宽一点 */
.attach-chip.attach-file {
  width: auto;
  max-width: 220px;
  height: auto;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 30px 6px 10px;
}

.attach-file-icon { font-size: 20px; line-height: 1; flex: none; }

.attach-file-name {
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-chip.is-uploading .attach-file-name { opacity: 0.5; }

.attach-chip.is-uploading img { opacity: 0.4; }

.attach-chip .spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.attach-chip .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 11px;
  line-height: 1;
}

.attach-chip .remove:hover { background: var(--danger); }

.attach-chip.is-failed { border-color: var(--danger); }

.composer-row { display: flex; align-items: flex-end; gap: 6px; }

.attach-btn { margin-bottom: 3px; }

#input {
  flex: 1;
  min-height: 24px;
  max-height: 220px;
  padding: 6px 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow-y: auto;
}

#input::placeholder { color: var(--text-faint); }

.send-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.stop-btn { background: var(--danger); }
.stop-btn:hover { background: #d4384a; }

.composer-tip {
  max-width: 820px;
  margin: 7px auto 0;
  color: var(--text-faint);
  font-size: 11.5px;
  text-align: center;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  pointer-events: none;
}

.drop-overlay > div {
  padding: 22px 34px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
}

/* ---------------- 图片灯箱 ---------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 40px;
  background: rgba(0, 0, 0, 0.86);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 15px;
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.26); }

/* ---------------- 提示条 ---------------- */

.toast-host {
  position: fixed;
  bottom: 22px;
  left: 50%;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 0.2s ease;
}

.toast.is-error { border-color: rgba(240, 97, 109, 0.5); color: var(--danger); }
.toast.is-ok { border-color: rgba(62, 207, 142, 0.5); color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 滚动条 ---------------- */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: padding-box; }

/* ---------------- 窄屏 ---------------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    box-shadow: var(--shadow);
  }
  .layout:not(.sidebar-hidden)::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.5);
  }
  .msg { padding: 12px 14px 16px; gap: 10px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .msg-images img { max-width: 160px; max-height: 160px; }
}

/* ================= 管理后台 ================= */

.admin-body { height: auto; min-height: 100%; }

.admin-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.admin-tabs { display: flex; gap: 4px; flex: 1; }

.admin-tab {
  padding: 6px 14px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.admin-tab:hover { background: var(--bg-hover); color: var(--text); }
.admin-tab.is-active { background: var(--accent); color: #fff; }

.admin-top-actions { display: flex; align-items: center; gap: 8px; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  padding: 6px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-inline { width: auto; margin: 0; padding: 7px 15px; font-size: 13.5px; }

.admin-main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }

.admin-panel { display: none; }
.admin-panel.is-active { display: block; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 26px 0 12px;
}

.panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

.panel-hint { margin: 0 0 14px; color: var(--text-faint); font-size: 12.5px; }

/* 统计卡片 */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.stat-value { font-size: 24px; font-weight: 600; line-height: 1.2; }
.stat-label { margin-top: 3px; color: var(--text-faint); font-size: 12px; }

/* 表格 */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.admin-table th {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr.is-disabled { opacity: 0.5; }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-table .dim { color: var(--text-faint); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 11.5px;
  white-space: nowrap;
}

.tag-admin { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tag-executed { border-color: var(--warning); color: var(--warning); background: rgba(243, 173, 78, 0.1); }
.tag-restored { border-color: var(--success); color: var(--success); background: rgba(62, 207, 142, 0.1); }

/* 数据库改动表：SQL 列要能看全，其他列别挤 */
.panel-head-gap { margin-top: 28px; }
.dbops-table td { vertical-align: top; }
.dbops-sql { max-width: 420px; }
.dbops-sql code {
  display: block;
  padding: 4px 7px;
  border-radius: 5px;
  background: var(--bg-hover);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.dbops-label { margin-top: 3px; font-size: 11px; }
.dbops-id { font-size: 11px; white-space: nowrap; cursor: help; }
.dbops-conv { white-space: nowrap; }
.dbops-conv .link-btn { font-size: 12px; text-decoration: none; display: inline-block; }
.tag-ok { border-color: rgba(62, 207, 142, 0.5); color: var(--success); }
.tag-off { border-color: rgba(240, 97, 109, 0.5); color: var(--danger); }

.actions { display: flex; flex-wrap: wrap; gap: 4px; }

.link-btn {
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 12.5px;
  white-space: nowrap;
  transition: background 0.12s;
}

.link-btn:hover:not(:disabled) { background: var(--accent-soft); }
.link-btn:disabled { color: var(--text-faint); cursor: not-allowed; }

/* 三栏浏览 */
.browse {
  display: grid;
  grid-template-columns: 230px 280px 1fr;
  height: calc(100vh - 140px);
  min-height: 460px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
}

/* min-height: 0 是必需的：grid 项和 flex 项默认 min-height: auto，
   撑到内容高度就不再收缩，.browse-list 的 overflow-y 也就永远轮不到触发，
   消息列会直接被 .browse 的 overflow: hidden 裁掉。 */
.browse-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--border);
}
.browse-col:last-child { border-right: 0; }

.browse-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browse-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; }

.browse-item {
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.browse-item:hover { background: var(--bg-hover); }
.browse-item.is-active { background: var(--accent-soft); }
.browse-item-main { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-item-sub { color: var(--text-faint); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.browse-empty { padding: 26px 14px; color: var(--text-faint); font-size: 12.5px; text-align: center; }

/* 只读消息 */
.ro-msg {
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.ro-user { border-left: 3px solid var(--accent); }
.ro-assistant { border-left: 3px solid var(--success); }

.ro-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.ro-name { font-size: 12.5px; font-weight: 600; }
.ro-time { color: var(--text-faint); font-size: 11px; }
.ro-content { font-size: 13.5px; }

.ro-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.ro-images img {
  max-width: 150px;
  max-height: 150px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: cover;
  cursor: zoom-in;
}

/* 搜索 */
.search-bar { display: flex; gap: 8px; margin-bottom: 10px; }

.search-bar input[type="search"] {
  flex: 1;
  padding: 9px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.search-bar input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-bar select {
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

.hit-card {
  padding: 12px 14px;
  margin-bottom: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
}

.hit-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.hit-user { font-size: 13px; font-weight: 600; }
.hit-title { color: var(--text-dim); font-size: 12px; margin-bottom: 6px; }
.hit-body { font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.hit-body mark { padding: 0 2px; border-radius: 3px; background: var(--warning); color: #1a1d23; }

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.modal-card h3 { margin: 0 0 18px; font-size: 16px; font-weight: 600; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 900px) {
  .browse { grid-template-columns: 1fr; height: auto; }
  .browse-col { border-right: 0; border-bottom: 1px solid var(--border); max-height: 300px; }
  .admin-tabs { overflow-x: auto; }
}

.admin-entry {
  display: block;
  padding: 7px 10px;
  margin-bottom: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12.5px;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}

.admin-entry:hover { background: var(--accent-soft); color: var(--accent); }

/* ================= 项目切换器 ================= */

/* ---- 输入框上方的「附加资源」条 -------------------------------------
   这次对话带着哪些项目，发送前一眼能确认，也能当场摘掉。 */

.context-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 2px;
}

.context-add {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 20px;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.context-add:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- 项目选择器 ------------------------------------------------------
   项目可能几十上百个，不做常驻列表：点开、搜索、选中。 */

.proj-picker {
  position: absolute;
  /* 宽度和居中方式跟 .composer 保持一致，弹出来才对得齐 */
  left: 50%;
  transform: translateX(-50%);
  width: min(820px, calc(100% - 48px));
  bottom: calc(100% - 8px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  /* 窗口矮的时候不能把输入框挤没了 */
  max-height: min(340px, 50vh);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.proj-picker-head {
  display: flex;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}

.proj-picker-head input {
  flex: 1;
  min-width: 0;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.proj-picker-head input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.proj-picker-list {
  flex: 1;
  /* flex 项默认不收缩到内容以下，不写这句列表就不会滚 */
  min-height: 0;
  overflow-y: auto;
  padding: 5px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  padding: 6px 30px 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

/* is-cursor 是键盘光标，is-active 是已挂载——两者互相独立，可以同时出现 */
.picker-item.is-cursor { background: var(--bg-hover); }
.picker-item.is-active .picker-name { color: var(--accent); }

.picker-mark {
  flex: 0 0 12px;
  color: var(--accent);
  font-size: 10.5px;
  text-align: center;
}

.picker-body { flex: 1; min-width: 0; }

.picker-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-path {
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 10.5px;
  /* 路径前缀都一样，截左边留尾巴才认得出是哪个项目 */
  direction: rtl;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-edit {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  opacity: 0;
}

.picker-item:hover .picker-edit { opacity: 1; }
.picker-edit:hover { background: var(--bg-input); color: var(--text); }

.picker-hint {
  padding: 18px 10px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.proj-picker-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
  color: var(--text-faint);
  font-size: 11px;
}

.picker-clear {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 11px;
  text-decoration: underline;
}

.picker-clear:hover { color: var(--danger); }

.context-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 260px;
  padding: 3px 5px 3px 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-elevated);
  font-size: 11.5px;
}

.context-chip.is-primary {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.context-chip-icon { color: var(--accent); font-size: 9.5px; }

/* 没挂项目时的一句说明，和 chips 同一行、不可点 */
.context-note {
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 3px 4px;
  cursor: default;
}

.context-chip-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-chip-del {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.context-chip-del:hover { background: var(--bg-hover); color: var(--danger); }

.modal-wide { max-width: 520px; max-height: 88vh; overflow-y: auto; }
.modal-spacer { flex: 1; }

.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
}

/* ---- 项目详情弹窗 ---------------------------------------------------- */

.detail-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.detail-modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.detail-modal-title-wrap h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--text-faint);
  border: 1px solid var(--border);
}

.detail-badge.is-primary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.detail-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.detail-section {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.detail-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.detail-section-title em {
  font-style: normal;
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  font-family: var(--mono);
}

.detail-count-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: 500;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.detail-item:last-child { margin-bottom: 0; }

.detail-k {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-faint);
}

.detail-v {
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
}
.detail-v.is-mono {
  font-family: var(--mono);
  font-size: 12px;
}

.detail-path-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.detail-path {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

.btn-mini {
  flex-shrink: 0;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 5px;
}

.detail-sub {
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
  margin-top: 2px;
}

.detail-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.detail-instructions {
  margin: 0;
  padding: 8px 10px;
  border-radius: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 140px;
  overflow-y: auto;
  color: var(--text-dim);
}

.detail-skills-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-skill-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 9px;
  border-radius: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 12px;
}

.detail-skill-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-skill-name {
  font-weight: 600;
  color: var(--accent);
  font-family: var(--mono);
}

.detail-skill-path {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--text-faint);
  font-family: var(--mono);
}

.detail-skill-desc {
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.4;
}

@media (max-width: 760px) {
  .context-chip { max-width: 150px; }
  .proj-picker { max-height: 60vh; }
  .topbar-proj-name { max-width: 80px; }
  .topbar-projects { max-width: 50%; }
}

/* ---------------- 审批卡片：agent 想执行被拦下的命令，等人决定 ---------------- */

.msg-approval {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(243, 173, 78, 0.45);
  border-radius: var(--radius-sm);
  background: rgba(243, 173, 78, 0.08);
}

.msg-approval.is-resolved {
  border-color: var(--border);
  background: transparent;
  opacity: 0.8;
}

.approval-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--warning);
  margin-bottom: 6px;
}

.msg-approval.is-resolved .approval-title { color: var(--text-muted, inherit); }

.approval-cmd {
  margin: 0 0 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-all;
}

.approval-desc {
  font-size: 12.5px;
  opacity: 0.85;
  margin-bottom: 8px;
}

.approval-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.approval-btns .btn-primary, .approval-btns .btn-ghost { padding: 5px 12px; font-size: 12.5px; }

.btn-danger {
  border-color: rgba(240, 97, 109, 0.5);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) { background: rgba(240, 97, 109, 0.12); }

.approval-result {
  font-size: 12.5px;
  opacity: 0.85;
}

/* ---------------- 用量看板 ---------------- */

.panel-actions { display: flex; gap: 8px; align-items: center; }

.select-inline {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.usage-bar {
  display: inline-block;
  height: 10px;
  min-width: 2px;
  border-radius: 3px;
  background: var(--accent);
  opacity: 0.75;
  vertical-align: middle;
  margin-right: 6px;
}

/* ---------------- 侧栏搜索 / 加载更早 ---------------- */

.conv-search { padding: 0 14px 10px; }

.conv-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.conv-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.conv-item-body { flex: 1; min-width: 0; }
.conv-item-body .conv-item-title { display: block; }

.conv-item .conv-snippet {
  display: block;
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item .conv-snippet mark { background: rgba(243, 173, 78, 0.35); color: inherit; border-radius: 2px; }

.load-earlier {
  display: block;
  margin: 4px auto 14px;
  padding: 6px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
}

.load-earlier:hover { background: var(--bg-hover); color: var(--text); }
.load-earlier:disabled { opacity: 0.6; cursor: wait; }

/* connect.json 编辑器 */
.connect-editor-card { max-width: 720px; }
.connect-editor-card h3 em { font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--text-faint); margin-left: 8px; }
.connect-editor-card textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 360px;
  max-height: 60vh;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  resize: vertical;
  outline: none;
  tab-size: 2;
}
.connect-editor-card textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.connect-editor-tip { margin: 8px 0 12px; color: var(--text-faint); font-size: 11.5px; line-height: 1.6; }

/* 管理后台：安全 */
.security-actions { display: flex; gap: 10px; margin-bottom: 14px; }
.security-result {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}
