:root {
  --blue: #3370ff;
  --blue-hover: #245bdb;
  --blue-soft: #e1eaff;
  --bg: #ffffff;
  --sidebar: #f5f6f7;
  --panel: #ffffff;
  --border: #e5e6eb;
  --border-strong: #d0d3d9;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --danger: #f54a45;
  --green: #2ea121;
  /* surfaces and soft fills (dark theme overrides these, not the literals) */
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #f7f8fa;
  --hover: #f2f3f5;
  --hover-2: #eef0f3;
  --line-soft: #f2f3f5;
  --blue-wash: #f5f8ff;
  --blue-line: #bbd0ff;
  --blue-ink: #1e40af;
  --danger-soft: #fff2f0;
  --danger-line: #ffccc7;
  --danger-text: #a8071a;
  --warn-soft: #fff4e5;
  --warn-line: #ffd8a8;
  --warn-text: #ad6800;
  --green-soft: #e8f7e8;
  --dot: #c9cdd4;
  --icon: #8a919c;
  --avatar: #dfe3e8;
  --item-hover: rgba(255, 255, 255, .9);
  --head-bg: rgba(255, 255, 255, .92);
  --card-bg: rgba(255, 255, 255, .97);
  color-scheme: light;
  --radius: 12px;
  --sidebar-w: 286px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ================= Sidebar ================= */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px 10px;
  gap: 12px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4d7cff, #2b4ef1);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .5px;
  box-shadow: 0 2px 6px rgba(51, 112, 255, .3);
}

.brand-name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.icon-btn.sidebar-close { display: none; margin-left: auto; }

.session-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -6px;
  padding: 0 6px;
}
.list-hint { color: var(--text-3); font-size: 12px; padding: 16px 8px; text-align: center; }

.session-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
  position: relative;
  transition: background .12s;
}
.session-item:hover { background: var(--item-hover); }
.session-item.active { background: var(--blue-soft); }
.session-item.active .session-title { color: var(--blue-hover); font-weight: 600; }

.session-avatar {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--avatar); color: #5a6472;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600; flex: none;
}
.session-item.active .session-avatar { background: var(--blue-soft); color: var(--blue-hover); }

.session-main { min-width: 0; flex: 1; }
.session-title-row { display: flex; align-items: baseline; gap: 6px; }
.session-title {
  font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.session-time { font-size: 10.5px; color: var(--text-3); flex: none; }
.session-preview {
  font-size: 11.5px; color: var(--text-3); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-preview.preview-running { color: var(--blue); }
.session-run {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  border: 2px solid var(--blue-line); border-top-color: var(--blue);
  animation: spin .8s linear infinite;
}
.session-unread {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--blue); box-shadow: 0 0 0 3px rgba(51, 112, 255, .15);
}
.session-item.running .session-title { color: var(--blue-hover); }

.session-actions {
  display: none;
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: linear-gradient(90deg, transparent, var(--sidebar) 18%);
  padding-left: 14px;
  border-radius: 6px;
}
.session-item:hover .session-actions { display: flex; }
.session-item.active .session-actions { background: linear-gradient(90deg, transparent, var(--blue-soft) 18%); }
.session-actions .icon-btn { font-size: 12px; padding: 4px; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.foot-btn {
  border: none; background: none; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-2); padding: 4px 4px;
  border-radius: 6px;
}
.foot-btn:hover { background: var(--hover-2); }
.foot-right { display: flex; align-items: center; gap: 5px; min-width: 0; }
.foot-icon {
  width: 24px; height: 24px; flex: none; display: grid; place-items: center;
  border: none; background: none; color: var(--text-3); border-radius: 6px; cursor: pointer;
}
.foot-icon:hover { color: var(--text); background: var(--hover); }
.foot-icon svg { display: block; }
.conn-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex: none;
}
.conn-dot.ok { background: var(--green); }
.conn-dot.error { background: var(--danger); }
.conn-dot.checking { background: #ff8800; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
.foot-meta { font-size: 10.5px; color: var(--text-3); }

/* ================= Main ================= */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

.chat-head {
  height: 58px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--head-bg);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.icon-btn.mobile-menu { display: none; }
.chat-title-wrap { min-width: 0; }
.chat-title {
  font-size: 15px; font-weight: 600; line-height: 1.25;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.caret {
  width: 4.5px; height: 4.5px; flex: none;
  margin: -2px 0 0 4px;
  border-right: 1.4px solid currentColor;
  border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg);
  opacity: .45;
}
.head-actions { margin-left: auto; display: flex; gap: 2px; flex: none; }

.icon-btn {
  border: none; background: none; cursor: pointer;
  color: var(--text-2); border-radius: 7px;
  width: 30px; height: 30px; flex: none;
  display: inline-grid; place-items: center;
  font-size: 15px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.active { background: var(--blue-wash); color: var(--blue); }
.icon-btn.active:hover { background: var(--blue-wash); color: var(--blue); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.error-banner {
  background: var(--danger-soft);
  color: var(--danger-text);
  border-bottom: 1px solid var(--danger-line);
  padding: 9px 20px;
  font-size: 12.5px;
  display: flex; align-items: center; gap: 8px;
}
.error-banner code { background: var(--surface); padding: 1px 5px; border-radius: 4px; }
.queue-banner {
  background: var(--blue-wash);
  color: var(--blue-ink);
  border-bottom: 1px solid var(--blue-line);
  padding: 9px 20px;
  font-size: 12.5px;
  display: flex; align-items: center; gap: 8px;
}
.queue-banner-note { color: var(--warn-text); }
.queue-banner-spacer { flex: 1; }
.link-btn { border: none; background: none; color: var(--blue); cursor: pointer; font-size: 12.5px; }

/* ================= Messages ================= */
.chat-body { flex: 1; min-height: 0; display: flex; }
.messages {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 26px 20px 18px;
}
/* 空状态在标题栏与输入框之间垂直居中，避免内容全挤在上半屏。 */
.messages.is-empty {
  display: flex;
  flex-direction: column;
}
.messages.is-empty .empty-state { margin: auto; }
.msg-list { max-width: 860px; margin: 0 auto; }

.side-rail {
  width: 258px;
  flex: none;
  padding: 14px 14px 14px 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.outline {
  width: 100%;
  flex: 0 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 8px 28px rgba(31, 35, 41, .07);
  backdrop-filter: blur(6px);
}
.outline-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  border-radius: 7px;
  padding: 9px 8px;
  cursor: pointer;
  text-align: right;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-3);
}
.outline-item:hover { background: var(--surface-3); color: var(--text); }
.outline-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.outline-item.active { color: var(--blue); font-weight: 500; }

@media (max-width: 1180px) {
  .side-rail { display: none; }
}

@media (min-width: 1181px) {
  .composer-wrap.with-rail { padding-right: 278px; }
  .jump-bottom.with-rail { left: calc(50% - 129px); }
}

.empty-state {
  max-width: 560px; margin: auto; text-align: center; padding: 0 16px;
}
.empty-logo {
  width: 62px; height: 62px; border-radius: 18px; margin: 0 auto 24px;
  background: linear-gradient(135deg, #4d7cff, #2b4ef1);
  color: #fff; display: grid; place-items: center;
  font-size: 28px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(51, 112, 255, .25);
}
.empty-proj {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; margin: 0 0 18px;
}
.empty-proj-chips {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; min-width: 0;
}
.empty-proj-label { font-size: 11px; color: var(--text-3); margin-right: 1px; }
.proj-chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 200px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 14px; padding: 6px 11px; font-size: 11.5px; cursor: pointer;
  transition: all .15s;
}
.proj-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-chip:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-wash); }
.proj-chip.active { border-color: var(--blue); color: var(--blue); background: var(--blue-wash); font-weight: 600; }
.empty-resume {
  display: none; margin: 18px auto 0; max-width: 100%;
  border: none; background: none; color: var(--text-3);
  font: inherit; font-size: 12px; cursor: pointer;
  padding: 5px 9px; border-radius: 7px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.empty-resume:hover { color: var(--blue); background: var(--blue-wash); }
.empty-resume-title {
  display: inline-block; max-width: min(58vw, 360px); vertical-align: bottom;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--text-2);
}
.empty-resume:hover .empty-resume-title { color: var(--blue); }

.turn {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
  align-items: flex-start;
}
.user-turn { justify-content: flex-end; }
.assistant-turn { justify-content: flex-start; }

.avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  margin-top: 2px;
}
.ai-avatar {
  background: linear-gradient(135deg, #4d7cff, #2b4ef1);
  color: #fff;
  box-shadow: 0 2px 6px rgba(51, 112, 255, .25);
}
.user-avatar { background: var(--hover); color: var(--text-2); order: 2; }

.bubble-col {
  display: flex; flex-direction: column; align-items: flex-end; min-width: 0; max-width: 78%;
}
.user-bubble {
  background: var(--blue);
  color: #fff;
  border-radius: 12px 12px 3px 12px;
  padding: 10px 13px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(31, 35, 41, .06);
}
.bubble-text { white-space: pre-wrap; }
.bubble-images { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.bubble-images img {
  max-width: 420px; max-height: 320px; border-radius: 8px; display: block;
  cursor: zoom-in;
}
.bubble-files { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  color: #fff; border-radius: 7px; padding: 4px 8px;
  font-size: 12px; text-decoration: none; width: fit-content; max-width: 100%;
}
.file-chip:hover { background: rgba(255, 255, 255, .24); }
.file-chip-ico { flex: none; }
.file-chip-name {
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-chip-size { opacity: .75; font-size: 10.5px; flex: none; }

.assistant-col { min-width: 0; flex: 1; max-width: calc(100% - 42px); }
.reply-images { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin: 8px 0; }
.reply-image-button { display: block; max-width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.reply-image-button img { display: block; max-width: min(100%, 560px); max-height: 420px; object-fit: contain; border-radius: 8px; }
.reply-image-unavailable { color: var(--text-3); font-size: 12px; }
.assistant-name {
  font-size: 12px; color: var(--text-3); margin: 2px 0 6px;
  display: flex; align-items: center; gap: 8px; min-width: 0;
}
.typing {
  color: var(--blue); font-size: 11px; min-width: 0; flex: 0 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.turn-time { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }
.user-turn .turn-time { text-align: right; }

.markdown {
  font-size: 14.5px;
  line-height: 1.72;
  color: var(--text);
  word-break: break-word;
}
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 10px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  margin: 18px 0 8px; line-height: 1.4; font-weight: 600;
}
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 18px; }
.markdown h3 { font-size: 16px; }
.markdown h4 { font-size: 14.5px; }
.markdown ul, .markdown ol { padding-left: 22px; margin: 8px 0 12px; }
.markdown li { margin: 3px 0; }
.markdown li > p { margin: 0; }
.markdown blockquote {
  margin: 10px 0; padding: 6px 12px; border-left: 3px solid var(--border-strong);
  color: var(--text-2); background: var(--surface-2); border-radius: 0 6px 6px 0;
}
.markdown a { color: var(--blue); text-decoration: none; }
.markdown a:hover { text-decoration: underline; }
.markdown code {
  background: var(--hover);
  border-radius: 4px;
  padding: 1.5px 5px;
  font-size: 12.8px;
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.markdown pre {
  position: relative;
  background: #0d1117;
  color: #e6edf3;
  border-radius: 9px;
  padding: 14px 14px 14px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 12.8px;
  line-height: 1.6;
  border: 1px solid #21262d;
}
.markdown pre code {
  background: none; padding: 0; border-radius: 0; font-size: inherit; color: inherit;
}
.markdown table {
  border-collapse: collapse; margin: 10px 0; font-size: 13px; width: auto; max-width: 100%;
  display: block; overflow-x: auto;
}
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; }
.markdown th { background: var(--surface-3); font-weight: 600; }
.markdown img { max-width: 100%; border-radius: 8px; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.code-copy {
  position: absolute; top: 7px; right: 8px;
  background: rgba(255, 255, 255, .08); color: #b6c2cf;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 5px; padding: 2px 7px; font-size: 11px; cursor: pointer;
  opacity: 0; transition: opacity .15s;
}
pre:hover .code-copy { opacity: 1; }
.code-copy:hover { background: rgba(255, 255, 255, .16); color: #fff; }

.turn-foot { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.turn-foot .turn-time { margin-top: 0; }
.text-btn {
  border: none; background: none; color: var(--text-3); font-size: 11px; cursor: pointer;
  padding: 1px 4px; border-radius: 4px;
}
.text-btn:hover { color: var(--blue); background: var(--blue-wash); }

.commentary {
  font-size: 12.5px; color: var(--text-3);
  border-left: 2px solid var(--border);
  padding: 2px 0 2px 10px;
  margin: 6px 0 10px;
  white-space: pre-wrap;
}

.thinking { display: flex; gap: 4px; padding: 8px 0 4px; }
.thinking .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--dot);
  animation: blink 1.2s infinite both;
}
.thinking .dot:nth-child(2) { animation-delay: .18s; }
.thinking .dot:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.msg-error {
  margin-top: 8px; background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger-text);
  padding: 8px 10px; border-radius: 8px; font-size: 12.5px; white-space: pre-wrap;
}
.msg-error.stopped {
  background: var(--surface-3); border-color: var(--border); color: var(--text-3);
}

/* ================= Tool cards ================= */
.tool-stack { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.tool-turn { margin-bottom: 12px; }

.tool-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  overflow: hidden;
  max-width: 760px;
  transition: border-color .15s;
}
.tool-card:hover { border-color: var(--border-strong); }
.tool-card.error { border-color: var(--danger-line); background: var(--danger-soft); }
.tool-card summary {
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
}
.tool-card summary::-webkit-details-marker { display: none; }
.tool-card summary::after {
  content: "›"; margin-left: 2px; color: var(--text-3); font-size: 14px;
  transition: transform .15s; flex: none;
}
.tool-card[open] summary::after { transform: rotate(90deg); }
.tool-ico { font-size: 12px; opacity: .8; flex: none; }
.tool-name {
  font-weight: 600; color: var(--text); font-size: 12.5px;
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  flex: none;
}
.tool-preview {
  color: var(--text-3);
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 11.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.tool-badge {
  flex: none; font-size: 10.5px; color: var(--text-3);
  background: var(--hover); border-radius: 10px; padding: 1px 7px;
}
.tool-badge.err { color: var(--danger); background: var(--danger-soft); }
.tool-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--blue-line); border-top-color: var(--blue);
  animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.tool-body { border-top: 1px solid var(--border); padding: 10px 12px 12px; background: var(--surface); }
.tool-label {
  font-size: 10.5px; color: var(--text-3); text-transform: uppercase;
  letter-spacing: .04em; margin: 2px 0 5px;
}
.tool-args, .tool-output {
  margin: 0 0 10px;
  background: var(--surface-3); border: 1px solid var(--line-soft); border-radius: 7px;
  padding: 8px 10px; font-size: 11.8px; line-height: 1.55;
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
  max-height: 320px; overflow: auto;
  color: var(--text-2);
}
.tool-args:last-child, .tool-output:last-child { margin-bottom: 0; }
.tool-wait { font-size: 11.5px; color: var(--text-3); padding: 2px 0 4px; }

/* Process: one collapsed container for all tool steps of a turn */
.process-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  overflow: hidden;
  max-width: 760px;
  margin: 2px 0 10px;
}
.process-summary {
  list-style: none;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 11px;
  cursor: pointer; user-select: none;
  font-size: 12px; color: var(--text-2);
}
.process-summary::-webkit-details-marker { display: none; }
.process-summary::after {
  content: "›";
  margin-left: auto;
  color: var(--text-3);
  font-size: 14px;
  transition: transform .15s;
}
.process-card[open] > .process-summary::after { transform: rotate(90deg); }
.process-ico { font-size: 12px; opacity: .7; flex: none; }
.process-title { font-weight: 600; color: var(--text); flex: none; }
.process-body {
  border-top: 1px solid var(--border);
  padding: 8px 10px;
  background: var(--surface);
  display: flex; flex-direction: column; gap: 6px;
}
.process-step { display: block; }
.process-think { font-size: 10.5px; color: var(--text-3); padding: 2px 4px; }
.process-body .tool-card { max-width: none; }
.process-body .tool-card summary { padding: 6px 9px; }
.slow-badge { color: var(--warn-text); background: var(--warn-soft); }
.slow-rank {
  flex: none; font-size: 10px; font-weight: 700;
  color: var(--warn-text); background: var(--warn-soft);
  border: 1px solid var(--warn-line); border-radius: 9px; padding: 0 5px;
}
.tool-card.slow { border-color: var(--warn-line); }
.tool-card.slow-1 { border-color: var(--warn-line); }

/* ================= Composer ================= */
.jump-bottom {
  position: absolute; bottom: 108px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 16px; padding: 5px 12px; font-size: 12px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(31, 35, 41, .08); z-index: 4;
}
.jump-bottom:hover { color: var(--blue); border-color: var(--blue-line); }

.composer-wrap {
  flex: none;
  padding: 8px 20px 12px;
  background: linear-gradient(to top, var(--bg) 75%, rgba(0,0,0,0));
}
.composer {
  max-width: 860px; margin: 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface);
  padding: 10px 10px 8px;
  transition: border-color .15s, box-shadow .15s, background .15s;
  position: relative;
}
.composer.dragging { border-color: var(--blue); background: var(--blue-wash); }
.drop-hint {
  text-align: center; color: var(--blue); font-size: 12.5px;
  border: 1px dashed var(--blue-line); border-radius: 8px;
  padding: 7px; margin: 2px 2px 8px; background: var(--surface);
}
/* queue dock: the queued turns, docked above the composer so they stay in view */
.queue-dock {
  max-width: 860px; margin: 0 auto 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 3px 4px 3px;
  box-shadow: 0 8px 22px rgba(23, 31, 46, .07);
  animation: queue-in .16s ease-out;
}
@keyframes queue-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.queue-head { display: flex; align-items: center; gap: 7px; padding: 6px 8px 5px; font-size: 12px; }
.queue-ico { display: inline-flex; flex-direction: column; gap: 2px; width: 12px; flex: none; }
.queue-ico i { display: block; height: 1.5px; border-radius: 1px; background: var(--icon); }
.queue-ico i:nth-child(1) { width: 12px; }
.queue-ico i:nth-child(2) { width: 9px; }
.queue-ico i:nth-child(3) { width: 6px; }
.queue-title { font-weight: 600; color: var(--text); }
.queue-count {
  color: var(--blue); background: var(--blue-soft);
  border-radius: 999px; padding: 1px 7px; font-size: 10.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.queue-hint { color: var(--text-3); font-size: 11px; margin-left: auto; white-space: nowrap; }
.queue-clear {
  border: none; background: none; color: var(--text-2); font-size: 11.5px;
  cursor: pointer; padding: 2px 5px; border-radius: 6px; flex: none;
  margin-left: 4px; padding-left: 9px; border-left: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
}
.queue-clear:hover { color: var(--danger); background: var(--danger-soft); }
.queue-list { list-style: none; margin: 0; padding: 0 2px 2px; max-height: 38vh; overflow-y: auto; }
.queue-row {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 6px 7px 3px; border-radius: 9px; position: relative;
}
.queue-row + .queue-row { border-top: 1px solid var(--line-soft); }
.queue-row:hover { background: var(--surface-3); }
.queue-row.next::before {
  content: ''; position: absolute; left: -1px; top: 10px; bottom: 10px;
  width: 2px; border-radius: 2px; background: var(--blue);
}
.queue-row.dragging { background: var(--blue-soft); box-shadow: 0 3px 10px rgba(43, 78, 241, .13); }
.queue-grip {
  flex: none; width: 12px; height: 22px; margin-top: 1px; cursor: grab;
  background-image: radial-gradient(#b6bdc8 1.1px, transparent 1.2px);
  background-size: 5px 5px; border-radius: 3px; opacity: .5; touch-action: none;
}
.queue-grip:hover { opacity: .95; }
.queue-row.dragging .queue-grip { cursor: grabbing; opacity: .95; }
.queue-no {
  flex: none; width: 16px; text-align: right; font-size: 11px; color: var(--text-3);
  font-variant-numeric: tabular-nums; margin-top: 2px;
}
.queue-row.next .queue-no {
  width: 16px; height: 16px; margin-top: 1px; border-radius: 50%;
  background: var(--blue); color: #fff; font-size: 9.5px; font-weight: 600;
  display: grid; place-items: center; text-align: center;
}
.queue-main { flex: 1; min-width: 0; }
.queue-text {
  font-size: 12.5px; color: var(--text); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  white-space: pre-wrap; word-break: break-word;
}
.queue-meta { display: flex; align-items: center; gap: 7px; margin-top: 3px; font-size: 10.5px; color: var(--text-3); }
.queue-warn { color: var(--warn-text); }
.queue-ops { display: flex; align-items: center; gap: 3px; flex: none; opacity: .7; transition: opacity .12s; margin-top: -1px; }
.queue-row:hover .queue-ops, .queue-row.next .queue-ops { opacity: 1; }
.queue-op {
  width: 26px; height: 26px; display: grid; place-items: center;
  border: none; background: none; border-radius: 7px; color: var(--text-2);
  font-size: 12.5px; cursor: pointer;
}
.queue-op svg { display: block; }
.queue-op:hover { background: var(--hover-2); color: var(--text); }
.queue-op.danger:hover { background: var(--danger-soft); color: var(--danger); }
.queue-input {
  width: 100%; resize: vertical; min-height: 44px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 6px 8px; font: inherit; font-size: 12.5px; line-height: 1.45;
  color: var(--text); background: var(--surface); outline: none;
}
.queue-input:focus { border-color: var(--blue-line); box-shadow: 0 0 0 3px rgba(51, 112, 255, .09); }
.queue-edit-row { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.queue-edit-hint { color: var(--text-3); font-size: 10.5px; margin-right: auto; }
@media (hover: none) { .queue-ops { opacity: 1; } }
@media (max-width: 640px) {
  .queue-hint { display: none; }
  .queue-dock { margin-bottom: 6px; border-radius: 12px; }
}

.composer.focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(51, 112, 255, .1);
}
.composer textarea {
  display: block;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.6;
  padding: 2px 4px 6px;
  max-height: 180px;
  min-height: 26px;
  color: var(--text);
  background: transparent;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.composer-left { display: flex; align-items: center; gap: 4px; min-width: 0; flex: 1; }
.attach-btn { font-size: 15px; }

/* ===== 推理强度 ===== */
.chat-sub-line { display: flex; align-items: center; margin-top: 3px; min-width: 0; }
.meta-bar {
  display: inline-flex; align-items: center;
  height: 24px; min-width: 0; max-width: 100%;
  padding: 0 2px; border-radius: 7px;
  background: var(--surface-3); border: 1px solid var(--line-soft);
}
.meta-item {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 6px; min-width: 0;
  border: none; border-radius: 5px; background: none;
  font-family: inherit; font-size: 11.5px; line-height: 1;
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.meta-item:hover, .meta-item.active {
  background: var(--surface); box-shadow: 0 1px 2px rgba(31,35,41,.09);
}
.meta-item.active .meta-v { color: var(--blue); }
.meta-k { font-size: 10.5px; color: var(--text-3); flex: none; }
.meta-v {
  min-width: 0; max-width: 220px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.meta-tag {
  flex: none; padding: 0 4px; border-radius: 4px;
  font-size: 9.5px; line-height: 14px; font-weight: 500;
  background: var(--hover-2); color: var(--text-3);
}
.meta-dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  display: inline-block; margin-right: -1px;
}
.meta-div { width: 1px; height: 12px; flex: none; background: var(--hover-2); margin: 0 3px; }
.model-pick { flex: 0 1 auto; }
.proj-btn .meta-v { max-width: 150px; }
.reason-wrap, .proj-wrap { position: relative; display: inline-flex; min-width: 0; }
.reason-wrap { flex: none; }
.proj-wrap { flex: 0 1 auto; }
.proj-btn { min-width: 0; }
.reason-menu {
  position: absolute; top: calc(100% + 9px); left: 0; z-index: 60; width: 170px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 10px 26px rgba(31,35,41,.14); padding: 4px;
}
.reason-item {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  border: none; background: none; font-family: inherit; font-size: 12px;
  color: var(--text-2); padding: 6px 8px; border-radius: 6px; cursor: pointer; text-align: left;
}
.reason-item:hover { background: var(--blue-wash); }
.reason-item.active { color: var(--blue); font-weight: 600; }
.reason-check { font-size: 11px; }
.reason-note {
  padding: 5px 8px 4px; margin-top: 2px; border-top: 1px solid var(--line-soft);
  font-size: 10px; line-height: 1.4; color: var(--text-3);
}
.reason-chip {
  margin-left: 0; padding: 0 6px; border-radius: 6px;
  background: var(--hover); color: var(--text-2); font-size: 10.5px; line-height: 17px;
  display: inline-block; vertical-align: 1px;
}
.skill-last { font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
/* ===== 项目分组 ===== */
.group-head {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 10px 4px; cursor: pointer; user-select: none;
  font-size: 11px; color: var(--text-3);
}
.group-head:hover { color: var(--text-2); }
.group-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block; }
.group-name {
  flex: 1; min-width: 0; font-weight: 600; letter-spacing: .2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.group-count { font-size: 10px; }
.group-add {
  width: 16px; height: 16px; flex: none; padding: 0; display: inline-grid; place-items: center;
  border: none; border-radius: 5px; background: transparent; color: var(--text-2);
  font-size: 13px; line-height: 1; cursor: pointer; opacity: .85; margin-left: 2px;
  position: relative; transition: opacity .15s, background .15s, color .15s;
}
.group-add::after { content: ''; position: absolute; inset: -4px -2px; }
.group-head:hover .group-add { opacity: 1; }
.group-add:hover { background: var(--blue-wash); color: var(--blue); }
@media (hover: none) { .group-add { opacity: 1; } }
.group-caret { font-size: 9px; opacity: .7; }
.proj-menu { width: 210px; left: auto; right: 0; }
.proj-menu-name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.proj-manage-link { border: none; background: none; color: var(--blue); font: inherit; font-size: 10.5px; cursor: pointer; padding: 0; }
.project-modal { width: min(520px, 100%); }
.proj-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.proj-main { flex: 1; min-width: 0; }
.proj-name { font-size: 12.5px; font-weight: 600; }
.proj-path { font-size: 10.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-editor {
  margin-top: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.proj-editor-title { font-size: 12px; font-weight: 600; color: var(--text-2); }
.proj-editor input {
  border: 1px solid var(--border-strong); border-radius: 7px;
  padding: 7px 8px; font: inherit; font-size: 12.5px; outline: none; background: var(--surface);
}
.proj-editor input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.proj-colors { display: flex; gap: 6px; }
.proj-color { width: 16px; height: 16px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.proj-color.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--text); }
.proj-editor-actions { display: flex; justify-content: flex-end; gap: 8px; }
.proj-editor-actions .primary:disabled { background: var(--dot); cursor: not-allowed; }
.proj-editor-actions .ghost {
  border: 1px solid var(--border); background: var(--surface); border-radius: 7px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.proj-editor-actions .primary {
  border: none; background: var(--blue); color: #fff; border-radius: 7px;
  padding: 5px 12px; font-size: 12px; cursor: pointer;
}
.send-btn {
  width: 32px; height: 32px; border-radius: 9px;
  border: none; background: var(--blue); color: #fff;
  font-size: 17px; font-weight: 600; cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, opacity .15s;
  flex: none;
}
.send-btn:hover { background: var(--blue-hover); }
.send-btn:disabled { background: var(--dot); cursor: not-allowed; }
.send-btn.stop { background: #3b414b; font-size: 12px; }
.send-btn.stop:hover { background: #1f2329; }

.attach-strip { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 4px 8px; }
.attach-item { position: relative; }
.attach-item img {
  width: 54px; height: 54px; object-fit: cover; border-radius: 8px; display: block;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.attach-item.file { width: auto; max-width: 260px; }
.attach-file {
  display: flex; align-items: center; gap: 6px; height: 54px;
  padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); font-size: 12px; max-width: 100%;
}
.attach-file-ico { font-size: 16px; flex: none; }
.attach-file-name {
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-file-size { color: var(--text-3); font-size: 10.5px; flex: none; }
.attach-del {
  position: absolute; top: -5px; right: -5px;
  width: 17px; height: 17px; border-radius: 50%;
  border: none; background: #1f2329; color: #fff; font-size: 9px; cursor: pointer;
  display: grid; place-items: center;
}

/* ================= Modal / toast ================= */
.modal-mask {
  position: fixed; inset: 0; background: rgba(31, 35, 41, .42);
  display: grid; place-items: center; z-index: 100; padding: 20px;
}
.modal {
  width: min(440px, 100%);
  background: var(--surface); border-radius: 14px;
  box-shadow: 0 16px 48px rgba(31, 35, 41, .22);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 10px;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 4px 18px 14px; }
.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.field input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; outline: none;
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.theme-seg {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px;
}
.theme-seg button {
  flex: 1; border: none; background: none; color: var(--text-2);
  font-size: 12px; padding: 5px 8px; border-radius: 6px; cursor: pointer;
}
.theme-seg button:hover { color: var(--text); }
.theme-seg button.active {
  background: var(--surface); color: var(--text); font-weight: 500;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}
[data-theme="dark"] .theme-seg button.active { background: var(--hover); color: var(--text); }
.modal-note { font-size: 11.5px; color: var(--text-3); line-height: 1.6; margin-bottom: 12px; }
.modal-note code, .error-banner code { font-family: Menlo, monospace; }
.test-row { display: flex; align-items: center; gap: 10px; }
.test-result { font-size: 12px; }
.test-result.ok { color: var(--green); }
.test-result.error { color: var(--danger); }
.test-result.checking { color: #ff8800; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px 16px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* models */
.model-modal { width: min(560px, 100%); }
.model-filter { display: flex; gap: 8px; margin-bottom: 10px; }
.provider-select {
  flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 8px; font-size: 13px; background: var(--surface); color: var(--text); outline: none;
}
.provider-select:focus { border-color: var(--blue); }
.model-filter input {
  flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 9px; font-size: 13px; outline: none;
}
.model-filter input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.model-presets {
  border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
  margin-bottom: 8px; background: var(--surface);
}
.model-presets-head {
  font-size: 10.5px; color: var(--text-3); letter-spacing: .02em;
  padding: 5px 11px 4px; background: var(--surface-2); border-bottom: 1px solid var(--line-soft);
}
.model-presets .preset-item { border-bottom: 1px solid var(--line-soft); }
.model-presets .preset-item:last-child { border-bottom: none; }
.preset-item .model-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.preset-ico { color: #f5a623; flex: none; font-size: 12px; }
.preset-meta {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px; color: var(--text-3); flex: none;
}
.model-list {
  max-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 9px;
}
.model-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; border: none; border-bottom: 1px solid var(--line-soft);
  background: var(--surface); padding: 9px 11px; cursor: pointer; text-align: left;
  font-size: 13px;
}
.model-item:last-child { border-bottom: none; }
.model-item:hover { background: var(--blue-wash); }
.model-item.current { background: var(--blue-soft); color: var(--blue-hover); }
.model-item.isDefault { box-shadow: inset 3px 0 0 var(--green); }
.model-badges { display: flex; align-items: center; gap: 4px; flex: none; }
.model-badge {
  font-size: 10px; color: #fff; background: var(--green);
  border-radius: 8px; padding: 1px 6px;
}
.model-name {
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-current {
  flex: none; font-size: 10.5px; color: var(--blue);
  background: var(--surface); border-radius: 8px; padding: 1px 6px;
}

/* context meter: persistent at the top of the side rail */
.ctx-card {
  flex: none;
  padding: 9px 12px 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(31, 35, 41, .07);
  backdrop-filter: blur(6px);
  cursor: default;
}
.ctx-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--text-3);
}
.ctx-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 1px;
}
.ctx-line b {
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text);
  white-space: nowrap;
}
.ctx-line em {
  flex: none;
  font-style: normal;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
}
.usage-bar { height: 5px; margin-top: 6px; border-radius: 3px; overflow: hidden; background: var(--hover-2); }
.usage-bar i { display: block; height: 100%; border-radius: inherit; background: var(--blue); transition: width .25s; }
.usage-bar i.warn { background: #f5a623; }

/* help */
.help-modal { width: min(430px, 100%); }
.help-row {
  display: flex; gap: 12px; padding: 7px 0;
  border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.help-row:last-of-type { border-bottom: none; }
.help-row code {
  color: var(--blue); font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px; min-width: 64px;
}
.help-row span { color: var(--text-2); }
.primary-btn, .ghost-btn {
  border-radius: 8px; padding: 8px 16px; font-size: 13px; cursor: pointer;
}
.primary-btn { border: none; background: var(--blue); color: #fff; }
.primary-btn:hover { background: var(--blue-hover); }
.ghost-btn { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.ghost-btn:hover { border-color: var(--blue); color: var(--blue); }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: rgba(31, 35, 41, .92); color: #fff;
  padding: 9px 16px; border-radius: 9px; font-size: 12.5px;
  z-index: 200; max-width: 80vw;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.image-lightbox {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15, 18, 24, .78);
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.image-lightbox img {
  max-width: 92vw; max-height: 88vh;
  border-radius: 8px; background: var(--surface);
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  object-fit: contain;
}
.image-lightbox-close {
  position: fixed; top: 18px; right: 22px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.35); color: #fff; font-size: 16px;
  cursor: pointer;
}
.image-lightbox-close:hover { background: rgba(0,0,0,.55); }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(31,35,41,.16); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(31,35,41,.28); }
::-webkit-scrollbar-track { background: transparent; }

/* ================= Workspace nav ================= */
.ws-nav { display: flex; flex-direction: column; gap: 2px; padding: 2px; }
.ws-item {
  display: flex; align-items: center; gap: 9px;
  border: none; background: none; border-radius: 8px;
  padding: 8px 10px; cursor: pointer; text-align: left;
  font-size: 13px; color: var(--text-2);
}
.ws-item:hover { background: var(--hover); }
.ws-item.active { background: var(--blue-soft); color: var(--blue-hover); font-weight: 600; }
.ws-new .ws-ico { font-size: 16px; font-weight: 500; line-height: 1; }
.ws-ico { width: 16px; text-align: center; font-size: 13px; flex: none; }
.ws-label { flex: 1; }
.ws-count {
  font-size: 10.5px; color: var(--text-3); background: var(--hover-2);
  border-radius: 8px; padding: 0 6px; flex: none;
}
.ws-item.active .ws-count { background: var(--surface); color: var(--blue); }

.mem-rail { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.rail-row { display: flex; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--text-3); }
.rail-row b { color: var(--text); font-weight: 600; }
.rail-mem .bar { margin-top: 4px; }
.rail-root { font-size: 10.5px; color: var(--text-3); margin-top: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-refresh { width: 100%; font-size: 11px; padding: 5px 8px; }

/* ================= Memory & skills ================= */
.mem-main { flex: 1; min-height: 0; overflow-y: auto; padding: 22px 26px 48px; position: relative; }
.mem-page { max-width: 1080px; margin: 0 auto; }
.mem-stamp { text-align: right; font-size: 11px; color: var(--text-3); margin-bottom: 10px; }
.mem-empty { text-align: center; color: var(--text-3); font-size: 12.5px; padding: 40px 0; }
.mem-view { display: flex; flex-direction: column; gap: 16px; }

.cards-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.mem-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; min-width: 0; }
.mem-card h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.mem-card .hint { font-size: 11.5px; color: var(--text-3); line-height: 1.55; }
.mem-card .big { font-size: 30px; font-weight: 600; letter-spacing: -.02em; margin: 10px 0 8px; }
.mem-card .big small { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 6px; }

.bar { height: 6px; background: var(--hover-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--blue); border-radius: 3px; transition: width .2s; }
.bar.warn > i { background: #ff8800; }

.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: 16px; padding: 5px 10px; font-size: 11.5px; cursor: pointer;
}
.cat-chip b { color: var(--text-3); font-weight: 500; font-size: 10.5px; }
.cat-chip:hover { border-color: var(--blue-line); color: var(--blue); }
.cat-chip.active { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue-hover); }
.cat-chip.active b { color: var(--blue); }

.rank { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.rank-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 12px; color: var(--text-2); }
.rank-row b { font-weight: 500; color: var(--text-3); font-size: 11px; }
.rank-bar { grid-column: 1 / -1; height: 5px; background: var(--hover-2); border-radius: 3px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }

.kv { display: grid; grid-template-columns: 80px 1fr; gap: 8px 12px; margin: 14px 0 0; font-size: 12px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); word-break: break-word; }

.mem-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.mem-card-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.mem-name { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; }
.add-btn { font-size: 11px; padding: 2px 8px; }
.mem-bar-wrap { width: 180px; flex: none; margin-top: 8px; }

.entries { display: flex; flex-direction: column; margin-top: 6px; }
.entry { border-bottom: 1px solid var(--line-soft); }
.entry:last-child { border-bottom: none; }
.entry-head { display: flex; align-items: baseline; gap: 10px; padding: 10px 2px; cursor: pointer; }
.entry-idx { width: 20px; flex: none; color: var(--text-3); font-size: 11px; font-family: "SF Mono", Menlo, Monaco, Consolas, monospace; }
.entry-title { flex: 1; min-width: 0; font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry.open .entry-title { color: var(--text); }
.entry-chars { flex: none; font-size: 10.5px; color: var(--text-3); }
.entry-body { padding: 0 2px 12px 30px; }
.entry-text { font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; margin-bottom: 8px; }
.entry-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.entry textarea, .entry-editor textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.6;
  resize: vertical; outline: none; margin-bottom: 8px; font-family: inherit;
}
.entry textarea:focus, .entry-editor textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.entry-editor { border: 1px solid var(--blue-line); background: var(--blue-wash); border-radius: 10px; padding: 10px; margin: 10px 0; }

.skills-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.skill-scope { display: inline-flex; flex: none; gap: 2px; padding: 2px; background: var(--hover); border-radius: 999px; }
.scope-btn {
  border: 0; background: transparent; border-radius: 999px; padding: 5px 11px;
  font-family: inherit; font-size: 11.5px; color: var(--text-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.scope-btn b { margin-left: 2px; font-weight: 600; color: var(--text-3); }
.scope-btn:hover { color: var(--text); }
.scope-btn.active { background: var(--surface); color: var(--blue); box-shadow: 0 1px 2px rgba(15,23,42,.12); }
.scope-btn.active b { color: var(--blue); }
.skill-search {
  flex: 1; min-width: 220px; border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none;
}
.skill-search:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.skill-list { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface); }
.skill-row { display: flex; align-items: center; gap: 16px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.skill-row:last-child { border-bottom: none; }
.skill-row:hover { background: var(--surface-3); }
.skill-row.is-off { opacity: .55; }
.skill-main { flex: 1; min-width: 0; }
.skill-name { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.skill-name .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--blue); flex: none; }
.skill-row.is-off .skill-name .dot { background: var(--dot); }
.skill-desc { margin-top: 3px; font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.skill-side { display: flex; align-items: center; gap: 8px; flex: none; }
.skill-files { font-size: 10.5px; color: var(--text-3); }

.tag { font-size: 10px; border-radius: 9px; padding: 1px 7px; background: var(--hover-2); color: var(--text-2); white-space: nowrap; }
.tag.hot { background: var(--green-soft); color: var(--green); }
.tag.bundled { background: var(--blue-wash); color: #3370ff; }
.tag.off { background: var(--danger-soft); color: var(--danger-text); }
.tag.warn { background: var(--warn-soft); color: var(--warn-text); }
.tag.on { background: var(--green-soft); color: #2ea121; }

.switch-wrap { display: inline-flex; align-items: center; cursor: pointer; }
.switch-input { display: none; }
.switch { width: 30px; height: 17px; border-radius: 9px; background: var(--border-strong); position: relative; transition: background .15s; }
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
  border-radius: 50%; background: var(--surface); transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch-input:checked + .switch { background: var(--blue); }
.switch-input:checked + .switch::after { transform: translateX(13px); }

.ghost-btn.small, .primary-btn.small { padding: 4px 10px; font-size: 11.5px; border-radius: 7px; }
.ghost-btn.small.danger { color: var(--danger); }
.ghost-btn.small.danger:hover { border-color: var(--danger); }

/* drawer */
.skill-drawer {
  position: fixed; top: 58px; right: 0; bottom: 0; width: min(620px, 92%);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px rgba(31, 35, 41, .12);
  z-index: 40; display: flex; flex-direction: column;
}
.drawer-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 28px; height: 28px; border-radius: 7px; border: none;
  background: var(--hover); color: var(--text-2); cursor: pointer; font-size: 12px;
}
.drawer-close:hover { background: var(--hover-2); }
.drawer-head { padding: 18px 22px 10px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0 0 8px; font-size: 17px; padding-right: 34px; }
.drawer-meta { display: flex; flex-wrap: wrap; gap: 5px; }
.drawer-tabs { display: flex; gap: 4px; padding: 8px 18px 0; border-bottom: 1px solid var(--border); }
.drawer-tab {
  border: none; background: none; padding: 8px 10px; font-size: 12.5px;
  color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent;
}
.drawer-tab:hover { color: var(--text); }
.drawer-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px 32px; }
.file-list { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.file-row {
  width: 100%; display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border: none; border-bottom: 1px solid var(--line-soft);
  background: var(--surface); font-size: 12px; color: var(--text-2); text-align: left; cursor: pointer;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--surface-3); }
.file-row.static { cursor: default; }
.file-row.static:hover { background: var(--surface); }
.raw {
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; font-size: 12px; line-height: 1.6; margin-top: 12px;
  max-height: 420px; overflow: auto;
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace;
}
.drawer-events { margin-top: 16px; }
.drawer-events h3 { font-size: 12px; margin: 0 0 6px; color: var(--text-2); }

/* ---------- 定时任务 ---------- */
.cron-view { gap: 14px; }
.cron-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cron-summary { flex: 1; min-width: 0; font-size: 12px; color: var(--text-3); }
.cron-summary-bad { color: var(--danger-text); }
.cron-stamp { color: var(--text-3); }
.cron-tools { display: flex; gap: 6px; flex: none; }
.cron-form {
  border: 1px solid var(--blue-line); background: var(--blue-wash);
  border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.cron-form-grid { display: grid; grid-template-columns: 1.2fr 1.1fr .9fr; gap: 10px; }
.cron-field { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--text-3); }
.cron-input, .cron-textarea {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font-size: 12.5px; font-family: inherit; outline: none;
}
.cron-input:focus, .cron-textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(51,112,255,.1); }
.cron-textarea { resize: vertical; line-height: 1.6; }
.cron-form-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.cron-form-foot .hint { font-size: 11px; color: var(--text-3); line-height: 1.5; }
.cron-form-actions { display: flex; gap: 6px; flex: none; }
.cron-list { display: flex; flex-direction: column; gap: 10px; }
.cron-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
}
.cron-card.paused { background: var(--surface-2); }
.cron-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cron-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--dot); }
.cron-dot.on { background: var(--green); }
.cron-dot.bad { background: var(--danger); }
.cron-dot.run { background: var(--blue); }
.cron-name { margin: 0; font-size: 13.5px; font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cron-when { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cron-sched {
  font-family: "SF Mono", Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--text);
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px;
}
.cron-next { font-size: 11.5px; color: var(--text-3); }
.cron-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.cron-chip {
  font-size: 10.5px; color: var(--text-2); background: var(--hover-2); border-radius: 9px;
  padding: 1px 8px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cron-last { font-size: 11.5px; color: var(--text-3); }
.cron-last.bad { color: var(--danger-text); }
.cron-err {
  margin-top: 5px; font-size: 11px; color: var(--danger-text); background: var(--danger-soft);
  border: 1px solid var(--danger-line); border-radius: 7px; padding: 6px 8px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.cron-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding-top: 2px; }
.cron-actions-hint { font-size: 10.5px; color: var(--text-3); }
.rail-bad { color: var(--danger-text); }

@media (max-width: 1180px) {
  .cards-3 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .mem-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .cards-3 { grid-template-columns: 1fr; }
  .mem-main { padding: 16px 12px 32px; }
  .cron-form-grid { grid-template-columns: 1fr; }
  .cron-form-foot { flex-direction: column; align-items: stretch; }
  .cron-actions-hint { display: none; }
  .skill-drawer { width: 100%; }
  .skill-row { flex-wrap: wrap; }
  .skill-side { width: 100%; justify-content: flex-end; }
}

/* ================= Responsive ================= */
/* 768–900px 侧栏仍占 286px，meta 条空间最紧：收紧内边距，别压模型名 */
@media (max-width: 900px) and (min-width: 641px) {
  .meta-item { padding: 0 4px; font-size: 11px; }
  .meta-k { font-size: 10px; }
  .proj-btn .meta-v { max-width: 140px; }
}
@media (max-width: 640px) {
  /* 窄屏：模型名与标签让位给完整值，“默认”状态交给选择器表达 */
  .model-pick .meta-k, .model-pick .meta-tag { display: none; }
  .meta-item { padding: 0 4px; font-size: 11px; }
  .meta-k { font-size: 10px; }
  .meta-div { margin: 0 2px; }
  /* 项目名先让位，模型名必须能读全；项目靠色点和 tooltip 识别 */
  .model-pick { flex: 0 0 auto; }
  .proj-btn .meta-k { display: none; }
  .proj-btn .meta-v { max-width: 90px; }
}
@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 30px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .icon-btn.sidebar-close { display: inline-grid; }
  .icon-btn.mobile-menu { display: inline-grid; width: 38px; height: 38px; }
  .messages { padding: 18px 12px 12px; }
  .composer-wrap { padding: 6px 12px 10px; }
  .jump-bottom { bottom: 142px; }
  .bubble-col { max-width: 86%; }
  .user-avatar { display: none; }
  .chat-head { padding: 0 12px; }
  .proj-chip { min-height: 34px; }
  .empty-proj { flex-direction: column; gap: 7px; }
  .empty-resume { display: block; min-height: 34px; }
}

/* ================= Theme: dark ================= */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181d;
  --sidebar: #131519;
  --panel: #1e2127;
  --surface: #1e2127;
  --surface-2: #1a1d22;
  --surface-3: #20242b;
  --hover: #272b33;
  --hover-2: #2c313a;
  --line-soft: #262a31;
  --border: #2f343d;
  --border-strong: #3c424c;
  --text: #e6e9ef;
  --text-2: #b3bac6;
  --text-3: #8f98a6;
  --blue: #4d7cff;
  --blue-hover: #7d9dff;
  --blue-soft: #22304f;
  --blue-wash: #1b2434;
  --blue-line: #31486f;
  --blue-ink: #a8c0ff;
  --danger: #ff6b66;
  --danger-soft: #38201f;
  --danger-line: #5a2f2d;
  --danger-text: #ff9e9a;
  --warn-soft: #342711;
  --warn-line: #5c4620;
  --warn-text: #ffc46b;
  --green: #46c93a;
  --green-soft: #17301a;
  --dot: #4a5160;
  --icon: #79818d;
  --avatar: #2b3038;
  --item-hover: #1c1f25;
  --head-bg: rgba(22, 24, 29, .92);
  --card-bg: rgba(30, 33, 39, .97);
}

/* dark fixes for literals that stay light on purpose or need more contrast */
[data-theme="dark"] .session-avatar { color: #c6ccd6; }
[data-theme="dark"] .session-item.active .session-avatar { background: var(--blue-soft); color: var(--blue-ink); }
[data-theme="dark"] .session-item.active .session-actions { background: linear-gradient(90deg, transparent, var(--blue-soft) 18%); }
[data-theme="dark"] .meta-bar { background: #1a1d22; }
[data-theme="dark"] .meta-item:hover,
[data-theme="dark"] .meta-item.active { background: var(--hover); }
[data-theme="dark"] .toast { background: rgba(58, 64, 74, .96); }
[data-theme="dark"] .switch { background: var(--border-strong); }
[data-theme="dark"] .switch::after { background: #e6e9ef; }
[data-theme="dark"] .image-lightbox img { background: #101217; }
[data-theme="dark"] .msg-list .markdown pre { border-color: #2a2f37; }
[data-theme="dark"] .scope-btn.active,
[data-theme="dark"] .ws-item.active .ws-count { background: var(--surface-3); }
[data-theme="dark"] .scope-btn.active { color: var(--blue-ink); }
[data-theme="dark"] .model-current { background: var(--blue-soft); color: var(--blue-ink); font-weight: 500; }
[data-theme="dark"] .tag.hot { color: var(--green); }
[data-theme="dark"] .tag.bundled { color: var(--blue-ink); }
[data-theme="dark"] .code-copy { background: rgba(255,255,255,.1); }
[data-theme="dark"] .session-item.active .session-title { color: var(--blue-ink); }
[data-theme="dark"] .file-chip { background: rgba(255,255,255,.1); }
[data-theme="dark"] .attach-del { background: #3c424c; }
[data-theme="dark"] .foot-btn:hover { background: var(--hover); }
[data-theme="dark"] .icon-btn { background: var(--hover-2); }
[data-theme="dark"] .icon-btn:hover { background: var(--hover); }
[data-theme="dark"] .icon-btn.danger:hover { background: var(--danger-soft); }
[data-theme="dark"] .queue-clear:hover { background: var(--danger-soft); }
[data-theme="dark"] .markdown pre { background: #0d1117; }
[data-theme="dark"] .markdown th { background: var(--surface-3); color: var(--text-2); }
