:root {
  color-scheme: dark;
  --bg: #030405;
  --panel: #162532;
  --panel2: #10151f;
  --line: #536171;
  --muted: #8b96a6;
  --text: #eef4fb;
  --green: #56c56c;
  --orange: #f49a32;
  --user: #c89509;
  --bot: #172b39;
  font-family: "Noto Sans SC", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-light {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel2: #edf2f7;
  --line: #cbd5e1;
  --muted: #667085;
  --text: #111827;
  --green: #138a4f;
  --orange: #c97915;
  --user: #d98a13;
  --bot: #ffffff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 18%, transparent 0 44px, rgba(130,140,150,.22) 46px 50px, transparent 52px),
    radial-gradient(circle at 92% 29%, transparent 0 34px, rgba(130,140,150,.2) 36px 40px, transparent 42px),
    linear-gradient(32deg, transparent 0 46%, rgba(120,130,142,.24) 46.2% 46.6%, transparent 46.8%),
    #030405;
  overflow: hidden;
}

body.theme-light {
  background:
    radial-gradient(circle at 18% 18%, transparent 0 44px, rgba(148,163,184,.22) 46px 50px, transparent 52px),
    radial-gradient(circle at 92% 29%, transparent 0 34px, rgba(148,163,184,.2) 36px 40px, transparent 42px),
    linear-gradient(32deg, transparent 0 46%, rgba(148,163,184,.2) 46.2% 46.6%, transparent 46.8%),
    #f5f7fb;
}

button, textarea, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.appHead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px 10px;
  border-bottom: 1px solid rgba(160,170,182,.18);
  background: rgba(3,4,5,.88);
  backdrop-filter: blur(10px);
}
body.theme-light .appHead {
  border-bottom-color: rgba(148,163,184,.35);
  background: rgba(255,255,255,.9);
}

.tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
.tabs::-webkit-scrollbar { display: none; }

.session {
  position: relative;
  flex: 0 0 auto;
  height: 50px;
  min-width: 104px;
  max-width: 190px;
  padding: 6px 18px;
  border: 1px solid #253244;
  border-radius: 25px;
  background: #111a26;
  color: #dce6f0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
body.theme-light .session {
  border-color: #d4dce8;
  background: #ffffff;
  color: #1f2937;
}
.session.active {
  border-color: var(--orange);
  background: rgba(98,62,22,.55);
  box-shadow: inset 0 0 0 1px rgba(244,154,50,.35);
}
.session.processing {
  border-color: rgba(86,197,108,.65);
  box-shadow: inset 0 0 0 1px rgba(86,197,108,.22);
}
body.theme-light .session.active {
  border-color: var(--orange);
  background: #fff4e4;
  box-shadow: inset 0 0 0 1px rgba(201,121,21,.32);
}
.session-main {
  min-width: 0;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.session .name {
  font-size: 18px;
  line-height: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.session .sub { display: none; }
.session-busy {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--green);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}
.session-busy span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(86,197,108,.12);
  animation: statusPulse 1s ease-in-out infinite alternate;
}
.brandSvg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: currentColor;
}
.brand-openai { color: #10a37f; }
.brand-anthropic { color: #d97757; }
.brand-zhipu { color: #6f5af6; }
.brand-deepseek { color: #4d6bfe; }
.brand-hermes { color: #e0b96b; }

.iconBtn, .iconLink {
  width: 42px;
  height: 42px;
  border: 0;
  background: transparent;
  color: #9aa8b8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 21px;
  font-size: 25px;
  cursor: pointer;
}
#newSessionBtn { color: var(--orange); }
.iconBtn svg, .iconLink svg {
  width: 25px;
  height: 25px;
  fill: currentColor;
}
.iconBtn:hover, .iconLink:hover { color: #d6dee8; }
body.theme-light .iconBtn,
body.theme-light .iconLink { color: #526170; }
body.theme-light .iconBtn:hover,
body.theme-light .iconLink:hover { color: #111827; background: rgba(15,23,42,.06); }
.headActions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.statusRail {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--green);
  border-bottom: 1px solid rgba(160,170,182,.45);
  background: rgba(0,0,0,.6);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
body.theme-light .statusRail {
  color: var(--green);
  border-bottom-color: rgba(148,163,184,.45);
  background: rgba(255,255,255,.82);
}
.statusRail::-webkit-scrollbar { display: none; }
.statusRail .title {
  color: #f4f4f4;
  font-size: 16px;
  font-weight: 500;
}
body.theme-light .statusRail .title { color: #111827; }
.statusRail .meta { display: none; }
.statusIcon, .themeBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--green);
}
.statusIcon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.statusIcon.status-dim { color: #8ba0b6; }
.statusIcon.status-green { color: var(--green); }
.statusIcon.status-yellow { color: var(--orange); }
.statusIcon.status-red { color: #f05d5e; }
.statusIcon.status-pulse {
  animation: statusPulse 1s ease-in-out infinite alternate;
}
@keyframes statusPulse {
  from { opacity: .28; }
  to { opacity: 1; }
}
.themeBtn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: #ffb43a;
  cursor: pointer;
  font-size: 21px;
  line-height: 1;
}
.themeBtn:hover {
  background: rgba(255,180,58,.12);
}
body.theme-light .themeBtn {
  color: #475569;
}

.usage {
  display: flex;
  gap: 8px;
  align-items: center;
}
.pill {
  color: var(--green);
  font-size: 15px;
  border-left: 1px solid rgba(86,197,108,.32);
  padding-left: 8px;
}
.pill strong {
  display: inline;
  color: var(--green);
  font-size: 15px;
  font-weight: 500;
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px 9vw 18px;
}
.empty {
  margin: 22vh auto 0;
  color: #8f9aaa;
  text-align: center;
}
body.theme-light .empty { color: #6b7280; }

.msg {
  position: relative;
  width: fit-content;
  max-width: min(84vw, 920px);
  margin: 0 0 18px 52px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--bot);
  color: #f2f6fb;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 18px;
  box-shadow: 0 0 0 1px rgba(120,140,160,.12);
}
body.theme-light .msg {
  background: var(--bot);
  color: #111827;
  box-shadow: 0 1px 3px rgba(15,23,42,.08), 0 0 0 1px rgba(148,163,184,.24);
}
.msg .avatar {
  position: absolute;
  left: -48px;
  bottom: 4px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  background: #102d52;
  border: 2px solid #71a4d4;
}
.msg.user {
  margin-left: auto;
  margin-right: 52px;
  background: var(--user);
  color: #fff8e8;
  border-radius: 8px 8px 2px 8px;
}
body.theme-light .msg.user {
  background: var(--user);
  color: #fffaf0;
}
.msg.user .avatar {
  left: auto;
  right: -50px;
  background: #f1ae38;
  border-color: #ffd384;
}
.msg .head {
  margin-bottom: 8px;
  color: rgba(235,242,248,.68);
  font-size: 14px;
}
body.theme-light .msg .head { color: rgba(31,41,55,.58); }
.msg.user .head { color: rgba(255,248,232,.72); }
.msg a { color: #bceaff; }
body.theme-light .msg a { color: #0b66c3; }
body.theme-light .msg.user a { color: #fff4c7; }

/* ── Markdown 富文本渲染 ─────────────────────────────────────────────────────
   .msg 默认 white-space: pre-wrap 适合纯文本；md 渲染后块级元素自带排版，
   .body 改回 normal，由各 md 元素自己控制间距。代码块/行内代码仍保留空白。 */
.msg .body { white-space: normal; }
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }

.msg .body p { margin: 0 0 .7em; }
.msg .body h1, .msg .body h2, .msg .body h3,
.msg .body h4, .msg .body h5, .msg .body h6 {
  margin: 1em 0 .5em;
  line-height: 1.3;
  font-weight: 700;
}
.msg .body h1 { font-size: 1.5em; border-bottom: 1px solid rgba(160,170,182,.28); padding-bottom: .25em; }
.msg .body h2 { font-size: 1.32em; border-bottom: 1px solid rgba(160,170,182,.2); padding-bottom: .2em; }
.msg .body h3 { font-size: 1.18em; }
.msg .body h4 { font-size: 1.06em; }
.msg .body h5, .msg .body h6 { font-size: 1em; color: var(--muted); }

.msg .body ul, .msg .body ol { margin: 0 0 .7em; padding-left: 1.6em; }
.msg .body li { margin: .2em 0; }
.msg .body li > ul, .msg .body li > ol { margin: .2em 0; }

.msg .body blockquote {
  margin: 0 0 .7em;
  padding: .2em .9em;
  border-left: 3px solid var(--orange);
  background: rgba(120,140,160,.1);
  color: #d4dde7;
  border-radius: 0 4px 4px 0;
}
body.theme-light .msg .body blockquote {
  background: #f1f5f9;
  color: #334155;
}
.msg .body blockquote p:last-child { margin-bottom: 0; }

.msg .body hr {
  border: 0;
  border-top: 1px solid rgba(160,170,182,.28);
  margin: 1em 0;
}

.stream-status {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(160,170,182,.16);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(225,235,244,.66);
  font-size: 12px;
  line-height: 1.2;
}
body.theme-light .stream-status {
  border-top-color: rgba(148,163,184,.28);
  color: rgba(51,65,85,.7);
}
.stream-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(86,197,108,.14);
}
.thinking-local .stream-dot {
  animation: none;
}

/* 行内代码 */
.msg .body code {
  background: rgba(2,6,13,.55);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
  white-space: pre-wrap;
  word-break: break-word;
}
body.theme-light .msg .body code {
  background: #eef2f7;
  color: #111827;
}
/* 代码块 */
.msg .body pre {
  margin: 0 0 .8em;
  padding: 0;
  border-radius: 8px;
  background: #0b1016;
  border: 1px solid rgba(120,140,160,.22);
  overflow: hidden;
}
body.theme-light .msg .body pre {
  background: #f8fafc;
  border-color: rgba(148,163,184,.45);
}
.msg .body pre code {
  display: block;
  padding: 12px 14px;
  background: transparent;
  border-radius: 0;
  overflow-x: auto;
  white-space: pre;
  font-size: .9em;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
}

/* 表格 */
.msg .body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 .8em;
  font-size: .94em;
  display: block;
  overflow-x: auto;
}
.msg .body th, .msg .body td {
  border: 1px solid rgba(140,155,170,.35);
  padding: 7px 11px;
  text-align: left;
  vertical-align: top;
}
.msg .body th {
  background: rgba(120,140,160,.18);
  font-weight: 600;
}
body.theme-light .msg .body th { background: #eef2f7; }
body.theme-light .msg .body tbody tr:nth-child(even) { background: #f8fafc; }
.msg .body tbody tr:nth-child(even) { background: rgba(120,140,160,.07); }

.msg .body img { max-width: 100%; border-radius: 6px; }
.msg .body strong { font-weight: 700; }

/* KaTeX 块级公式横向可滚，避免长公式撑破气泡 */
.msg .body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; margin: .6em 0; }

/* 用户消息（橙底）里的代码/引用对比度微调 */
.msg.user .body code { background: rgba(0,0,0,.28); }
.msg.user .body pre { background: rgba(0,0,0,.32); border-color: rgba(0,0,0,.25); }
.msg.user .body blockquote { background: rgba(0,0,0,.16); color: #fff5e3; }

/* ── 富内容：附件 / 引用 / chip / lightbox（v20260617c）────────────────────── */

/* 消息内附件区 */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.att-img {
  max-width: min(320px, 100%);
  max-height: 360px;
  border-radius: 8px;
  cursor: zoom-in;
  display: block;
  object-fit: contain;
  background: rgba(0,0,0,.25);
  box-shadow: 0 0 0 1px rgba(120,140,160,.18);
}
.att-video {
  max-width: min(420px, 100%);
  border-radius: 8px;
  background: #000;
}
.att-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 9px 13px;
  border-radius: 8px;
  background: rgba(2,6,13,.4);
  border: 1px solid rgba(120,140,160,.28);
  color: #dce6f0;
  text-decoration: none;
}
.att-file:hover { background: rgba(2,6,13,.6); border-color: var(--orange); }
.att-file-icon { display: inline-flex; flex: 0 0 auto; }
.att-file-icon svg { width: 26px; height: 26px; fill: #9fc3ec; }
.att-file-meta { display: flex; flex-direction: column; min-width: 0; }
.att-file-name {
  font-size: 15px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 240px;
}
.att-file-size { font-size: 12px; color: var(--muted); }
.msg.user .att-file { background: rgba(0,0,0,.22); color: #fff6e6; }

/* 引用块（消息内，正文上方） */
.reply-previews { display: flex; flex-direction: column; gap: 5px; margin-bottom: 9px; }
.reply-quote {
  border-left: 3px solid #6fb0ff;
  background: rgba(60,90,130,.22);
  border-radius: 0 6px 6px 0;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
  display: flex;
  gap: 6px;
  align-items: baseline;
  overflow: hidden;
}
.reply-quote:hover { background: rgba(60,90,130,.4); }
.reply-quote-role { color: #8fc0ff; font-weight: 600; flex: 0 0 auto; }
.reply-quote-text {
  color: #c6d3e2;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.msg.user .reply-quote { border-left-color: #ffd27a; background: rgba(0,0,0,.18); }
.msg.user .reply-quote-role { color: #ffe0a0; }
.msg.user .reply-quote-text { color: #fff2da; }

/* 消息操作按钮（hover 时显示） */
.msg-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,.35);
  border-radius: 7px;
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  opacity: 0;
  transition: opacity .12s;
}
.msg-actions button {
  width: 25px;
  height: 25px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #b9c6d6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button:hover { background: var(--orange); color: #fff; }
.msg.user .msg-actions { right: auto; left: 6px; }

/* 跳转高亮 */
.msg-flash { animation: msgFlash 1.6s ease; }
@keyframes msgFlash {
  0%, 100% { box-shadow: 0 0 0 1px rgba(120,140,160,.12); }
  20% { box-shadow: 0 0 0 2px var(--orange), 0 0 18px rgba(244,154,50,.6); }
}

/* lightbox 放大遮罩 */
.lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.92);
  z-index: 40;
  cursor: zoom-out;
  padding: 24px;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 96vw; max-height: 92vh; border-radius: 6px; }

/* 待发送 chip 托盘 */
.pendingTray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right));
  background: rgba(3,4,5,.9);
}
body.theme-light .pendingTray { background: rgba(255,255,255,.92); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 5px 8px;
  border-radius: 16px;
  background: #1b2a39;
  border: 1px solid #36485c;
  font-size: 14px;
  color: #dce6f0;
}
body.theme-light .chip {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #1f2937;
}
.chip-quote { border-left: 3px solid #6fb0ff; border-radius: 4px 16px 16px 4px; }
.chip-label { color: #8fc0ff; flex: 0 0 auto; }
.chip-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip-thumb { width: 24px; height: 24px; border-radius: 4px; object-fit: cover; flex: 0 0 auto; }
.chip-x {
  border: 0;
  background: transparent;
  color: #98a6b6;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  flex: 0 0 auto;
}
.chip-x:hover { color: #ff8b8b; }

.composer {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 56px 48px minmax(0, 1fr) 42px 58px;
  gap: 8px;
  align-items: center;
  padding: 10px max(14px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  background: rgba(3,4,5,.9);
}
body.theme-light .composer {
  background: rgba(255,255,255,.92);
  border-top: 1px solid rgba(148,163,184,.25);
}
.composer textarea {
  height: 60px;
  max-height: 150px;
  min-height: 60px;
  resize: none;
  border: 1px solid #78879a;
  border-radius: 30px;
  outline: none;
  padding: 16px 18px;
  color: #e9f2fb;
  background: #162532;
  line-height: 1.35;
}
body.theme-light .composer textarea {
  border-color: #cbd5e1;
  color: #111827;
  background: #ffffff;
}
.composer textarea::placeholder { color: #667487; }
.attachBtn {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: #f59c2e;
  color: white;
}
.voiceBtn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(70,82,96,.85);
  color: #dce6f0;
}
body.theme-light .voiceBtn {
  background: #e5e7eb;
  color: #334155;
}
.voiceBtn.listening {
  background: #c4452f;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(196,69,47,.18);
}
.voiceBtn.transcribing {
  background: #2563eb;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(37,99,235,.18);
}
.voiceBtn.unsupported,
.voiceBtn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.attachBtn svg,
.voiceBtn svg {
  width: 23px;
  height: 23px;
  fill: currentColor;
}
.smallStop {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(70,82,96,.85);
  color: #ffc36d;
}
body.theme-light .smallStop {
  background: #e5e7eb;
  color: #a35c08;
}
.smallStop svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}
.sendBtn {
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: #314253;
  color: #fff;
  padding-left: 4px;
}
body.theme-light .sendBtn {
  background: #475569;
}
.sendBtn svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.login {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.985);
  backdrop-filter: blur(8px);
  padding: 20px;
  z-index: 20;
}
body.theme-light .login {
  background: rgba(245,247,251,.96);
}
.login.show { display: flex; }
.loginBox {
  width: min(390px, 100%);
  border: 1px solid #38485a;
  border-radius: 10px;
  background: #142331;
  padding: 22px;
}
body.theme-light .loginBox {
  border-color: #cbd5e1;
  background: #ffffff;
}
.loginBox h1 { margin: 0 0 8px; font-size: 26px; }
.loginBox p { margin: 0 0 16px; color: var(--muted); }
.loginBox input {
  width: 100%;
  border: 1px solid #4a5d71;
  border-radius: 6px;
  padding: 12px;
  color: var(--text);
  background: #0c1119;
  margin-bottom: 12px;
}
body.theme-light .loginBox input {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #111827;
}
.loginBox button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 12px;
  background: #d58f22;
  color: white;
}
.error { margin-top: 10px; color: #ff8b8b; font-size: 13px; min-height: 18px; }

/* ── 第二批：会话管理 / 搜索 / 工具时间线 / 加载更多（v20260617d）─────────── */

/* statusRail 上的会话操作按钮（重命名/模型/删除） */
.railBtn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: #8ba0b6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
}
.railBtn svg { width: 18px; height: 18px; fill: currentColor; }
.railBtn:hover { color: #d6dee8; background: rgba(120,140,160,.16); }
.railBtn-danger:hover { color: #ff8b8b; background: rgba(255,90,90,.14); }

/* 通用遮罩 */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 30;
  background: rgba(0,0,0,.78);
  backdrop-filter: blur(6px);
}
body.theme-light .overlay {
  background: rgba(241,245,249,.72);
}
.overlay.show { display: flex; }

/* 通用对话框 */
.modal { align-items: center; justify-content: center; padding: 20px; }
.modalBox {
  width: min(420px, 100%);
  border: 1px solid #38485a;
  border-radius: 12px;
  background: #142331;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
body.theme-light .modalBox {
  border-color: #cbd5e1;
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
.modalTitle { margin: 0 0 16px; font-size: 20px; }
.modalBody { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.modalBody label { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.modalBody input[type=text], .modalBody select {
  width: 100%;
  border: 1px solid #4a5d71;
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--text);
  background: #0c1119;
  font-size: 15px;
}
body.theme-light .modalBody input[type=text],
body.theme-light .modalBody select {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #111827;
}
.modalBody .hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.modalBody .warn { color: #ffb37a; }
.modalActions { display: flex; justify-content: flex-end; gap: 10px; }
.btnGhost, .btnPrimary {
  border: 0;
  border-radius: 7px;
  padding: 10px 18px;
  font-size: 15px;
  cursor: pointer;
}
.btnGhost { background: #243341; color: #c6d3e2; }
.btnGhost:hover { background: #2e404f; }
body.theme-light .btnGhost { background: #e5e7eb; color: #334155; }
body.theme-light .btnGhost:hover { background: #dbe3ee; }
.btnPrimary { background: #d58f22; color: #fff; }
.btnPrimary:hover { background: #e6a134; }
.btnPrimary.danger { background: #c4452f; }
.btnPrimary.danger:hover { background: #d8513a; }
.modalX {
  border: 0; background: transparent; color: #98a6b6;
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modalX:hover { color: #ff8b8b; }

/* 搜索面板 */
.searchPanel { align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; }
.searchBox {
  width: min(640px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid #38485a;
  border-radius: 12px;
  background: #142331;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
body.theme-light .searchBox,
body.theme-light .panelShell,
body.theme-light .historyBox {
  border-color: #cbd5e1;
  background: #ffffff;
  box-shadow: 0 20px 60px rgba(15,23,42,.18);
}
.searchHead {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(160,170,182,.2);
}
.searchHead input[type=search] {
  flex: 1 1 auto;
  border: 1px solid #4a5d71;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: #0c1119;
  font-size: 16px;
}
body.theme-light .searchHead input[type=search] {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: #111827;
}
.searchScope { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.searchResults { overflow-y: auto; padding: 6px 0; }
.searchResults .empty { margin: 24px auto; }
.search-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #dce6f0;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(160,170,182,.08);
}
body.theme-light .search-item {
  color: #1f2937;
  border-bottom-color: rgba(148,163,184,.24);
}
body.theme-light .search-item:hover { background: #f1f5f9; }
.search-item:hover { background: rgba(120,140,160,.12); }
.search-item .si-meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.search-item .si-text { font-size: 14px; line-height: 1.45; max-height: 3.2em; overflow: hidden; }
.search-item .si-hit { color: var(--orange); font-weight: 600; }

.wikiPanel, .historyPanel { align-items: center; justify-content: center; padding: 16px; }
.panelShell, .historyBox {
  width: min(1040px, 100%);
  height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  border: 1px solid #38485a;
  border-radius: 12px;
  background: #142331;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.panelHead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(160,170,182,.2);
}
.panelTitle { font-size: 16px; font-weight: 600; color: #eef4fb; }
body.theme-light .panelTitle { color: #111827; }
#wikiFrame {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  background: #fff;
}
.historyBox { width: min(720px, 100%); }
.historyList { overflow-y: auto; padding: 6px 0; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid rgba(160,170,182,.08);
  background: transparent;
  color: #dce6f0;
  padding: 8px 10px 8px 16px;
}
body.theme-light .history-item {
  color: #1f2937;
  border-bottom-color: rgba(148,163,184,.24);
}
body.theme-light .history-item:hover,
body.theme-light .history-item.active { background: #f1f5f9; }
.history-item:hover, .history-item.active { background: rgba(120,140,160,.14); }
.hi-open {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 4px 0;
  cursor: pointer;
}
.hi-main {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.hi-name { min-width: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-meta { flex: 0 0 auto; color: var(--muted); font-size: 12px; }
.hi-last { color: var(--muted); font-size: 13px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hi-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.hi-actions button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: #9aa8b8;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.hi-actions button:hover { color: #fff; background: rgba(120,140,160,.18); }
body.theme-light .hi-actions button { color: #526170; }
body.theme-light .hi-actions button:hover { color: #111827; background: rgba(15,23,42,.08); }
.hi-actions [data-act="delete"]:hover { color: #ff8b8b; background: rgba(255,90,90,.14); }

/* 加载更多历史 */
.loadMore {
  display: block;
  margin: 4px auto 16px;
  border: 1px solid #36485c;
  background: #1b2a39;
  color: #c6d3e2;
  padding: 7px 18px;
  border-radius: 16px;
  font-size: 14px;
  cursor: pointer;
}
body.theme-light .loadMore {
  border-color: #cbd5e1;
  background: #ffffff;
  color: #334155;
}
.loadMore:hover { border-color: var(--orange); color: #fff; }
.loadMore:disabled { opacity: .55; cursor: default; }

/* 工具调用时间线 segments（低调折叠区） */
.segments { margin-top: 10px; border-top: 1px dashed rgba(140,155,170,.28); padding-top: 8px; }
.seg-tools-toggle {
  border: 0;
  background: transparent;
  color: #8fa6bd;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.seg-tools-toggle:hover { color: #b9cbdd; }
.seg-tools-toggle .caret { transition: transform .15s; display: inline-block; }
.seg-tools-toggle.open .caret { transform: rotate(90deg); }
.seg-tool-list { margin-top: 7px; display: none; flex-direction: column; gap: 6px; }
.seg-tool-list.open { display: flex; }
.seg-tool {
  border-left: 2px solid rgba(111,176,255,.5);
  background: rgba(60,90,130,.12);
  border-radius: 0 6px 6px 0;
  padding: 6px 9px;
  font-size: 13px;
}
.seg-tool.err { border-left-color: #ff8b8b; background: rgba(150,60,60,.14); }
.seg-tool-head { display: flex; align-items: center; gap: 7px; color: #cdd9e6; }
.seg-tool-name { font-weight: 600; color: #9fc3ec; }
.seg-tool-name.err { color: #ff9d9d; }
.seg-tool-status { font-size: 11px; color: var(--muted); }
.seg-tool-io {
  margin-top: 4px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #aab9c9;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
}
.seg-tool-io .io-label { color: #7f93a8; }
.seg-tool-children { margin: 6px 0 0 10px; display: flex; flex-direction: column; gap: 5px; }

@media (max-width: 680px) {
  .appHead {
    grid-template-columns: minmax(0, 1fr) 34px auto;
    gap: 6px;
    padding: 9px 10px 8px;
  }
  .headActions { gap: 2px; }
  .iconBtn, .iconLink { width: 34px; height: 34px; font-size: 21px; }
  .session {
    height: 46px;
    min-width: 88px;
    padding: 0 14px;
  }
  .session .name { font-size: 16px; }
  .statusRail {
    justify-content: flex-start;
    min-height: 46px;
    font-size: 14px;
  }
  .pill, .pill strong { font-size: 14px; }
  .messages { padding: 14px 64px 12px 42px; }
  .msg {
    max-width: 78vw;
    margin-left: 26px;
    font-size: 16px;
  }
  .msg.user { margin-right: 26px; }
  .msg .avatar { left: -38px; width: 30px; height: 30px; }
  .msg.user .avatar { right: -39px; }
}
