:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #ecfdf5;
  --danger: #b91c1c;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
}
.demo-banner {
  background: #fffbeb; color: #92400e; border-bottom: 1px solid #fde68a;
  font-size: 13px; text-align: center; padding: 7px 14px; line-height: 1.5;
}
.wrap { flex: 1; min-width: 0; max-width: 960px; margin: 0 auto; padding: 28px 20px 80px; }
.layout { display: flex; gap: 24px; max-width: 1260px; margin: 0 auto; padding: 0 20px; align-items: flex-start; }

/* 左侧历史会话 */
.sidebar {
  width: 250px; flex: 0 0 250px; position: sticky; top: 0;
  max-height: 100vh; overflow-y: auto; padding: 28px 0 24px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.side-title { font-size: 14px; font-weight: 650; }
button.small { font-size: 12px; padding: 5px 10px; }
.session-list { display: flex; flex-direction: column; gap: 6px; }
.session-item {
  text-align: left; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px;
  cursor: pointer; font-weight: 500; line-height: 1.4;
}
.session-item:hover { border-color: #cbd5e1; }
.session-item.active { border-color: var(--accent); background: var(--accent-soft); }
.session-item .s-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-item .s-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.sidebar .empty.small { font-size: 12px; }
@media (max-width: 860px) {
  .layout { flex-direction: column; padding: 0 14px; gap: 0; }
  .sidebar { width: 100%; flex: none; position: static; max-height: 210px; padding: 16px 0 0; }
  .wrap { width: 100%; padding: 16px 6px 60px; }
}
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.badge {
  font-size: 12px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}
.badge.warn { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; margin: 14px 0 26px; }
.stat { font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 20px; color: var(--text); font-weight: 650; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; margin-bottom: 22px;
}
h2 { font-size: 16px; margin: 0 0 4px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.drop {
  border: 1.5px dashed #cbd5e1; border-radius: 12px; padding: 26px 20px;
  text-align: center; cursor: pointer; transition: 0.15s;
  background: #fbfcfd;
}
.drop:hover, .drop.drag { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--accent); }
.drop input { display: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
button {
  font: inherit; border: 0; border-radius: 10px; padding: 9px 16px;
  background: var(--accent); color: white; cursor: pointer; font-weight: 600;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.status { font-size: 13px; color: var(--muted); }
.status.error { color: var(--danger); }
.status.ok { color: var(--accent); }

/* 模型设置弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 50; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 23, 42, 0.45);
}
.modal[hidden] { display: none; }
.modal-card {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border-radius: 16px; padding: 22px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close {
  background: transparent; color: var(--muted); font-size: 22px;
  line-height: 1; padding: 2px 8px; border-radius: 8px;
}
.modal-close:hover { background: #f1f5f9; }
.field { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select {
  font: inherit; font-size: 14px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text);
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.field .note { font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* chat */
.chat {
  display: flex; flex-direction: column; gap: 14px;
  max-height: 520px; overflow-y: auto; padding: 6px 4px 12px;
}
.msg { display: flex; flex-direction: column; align-items: flex-start; }
.msg.user { align-items: flex-end; }
.bubble {
  max-width: 86%; padding: 10px 14px; border-radius: 12px;
  font-size: 14px; white-space: pre-wrap; word-break: break-word;
  background: #f1f5f9; border: 1px solid var(--line); border-bottom-left-radius: 4px;
}
.msg.user .bubble {
  background: var(--accent); color: #fff; border-color: var(--accent);
  border-radius: 12px; border-bottom-right-radius: 4px;
}
.msg.pending .bubble { color: var(--muted); font-style: italic; }
.cache-badge {
  margin-top: 6px; font-size: 12px; color: var(--accent);
  background: var(--accent-soft); border: 1px solid #d1fae5;
  border-radius: 999px; padding: 2px 10px;
}
.cache-badge.weak { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.history-question {
  max-width: 86%; margin-top: 6px; font-size: 12px; color: var(--muted);
  padding: 6px 10px; border-left: 2px solid #fde68a; background: #fffdf5;
  border-radius: 0 8px 8px 0; white-space: pre-wrap; word-break: break-word;
}
.history-question b { color: var(--text); font-weight: 600; }
.feedback { display: flex; gap: 8px; margin-top: 6px; }
.feedback button { font-size: 12px; padding: 4px 10px; }
.sources { max-width: 86%; margin-top: 6px; font-size: 12px; color: var(--muted); }
.sources summary { cursor: pointer; user-select: none; }
.src-item {
  margin-top: 6px; padding-left: 9px; border-left: 2px solid var(--line);
  white-space: pre-wrap;
}
.src-item b { color: var(--text); font-weight: 600; }
.chatbar { display: flex; gap: 10px; align-items: flex-end; margin-top: 8px; }
.chatbar textarea {
  flex: 1; font: inherit; font-size: 14px; padding: 10px 14px;
  border-radius: 10px; border: 1px solid var(--line); background: #fbfcfd;
  outline: none; resize: vertical; min-height: 44px; max-height: 140px;
}
.chatbar textarea:focus { border-color: var(--accent); }

/* search */
.searchbar { display: flex; gap: 10px; }
.searchbar input {
  flex: 1; font: inherit; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fbfcfd; outline: none;
}
.searchbar input:focus { border-color: var(--accent); }
.results { margin-top: 18px; display: grid; gap: 12px; }
.hit {
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  background: #fcfdfe;
}
.hit .meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.hit .title { font-weight: 650; color: var(--text); }
.hit .text { white-space: pre-wrap; font-size: 14px; color: #333b45; }
.empty { color: var(--muted); font-size: 14px; padding: 12px 0; }

/* 富文本回答 */
.bubble.rich { white-space: normal; }
.bubble.rich > :first-child { margin-top: 0; }
.bubble.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 9px; }
.rich h1, .rich h2, .rich h3, .rich h4, .rich h5, .rich h6 {
  margin: 14px 0 8px; line-height: 1.35; font-weight: 650;
}
.rich h1 { font-size: 20px; }
.rich h2 { font-size: 17px; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.rich h3 { font-size: 15px; }
.rich h4, .rich h5, .rich h6 { font-size: 14px; }
.rich ul, .rich ol { margin: 6px 0 10px; padding-left: 22px; }
.rich li { margin: 3px 0; }
.rich a { color: var(--accent); text-decoration: none; }
.rich a:hover { text-decoration: underline; }
.rich code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 12.5px; background: #eef2f7; border-radius: 5px; padding: 1px 5px;
}
.rich pre.code {
  background: #0f172a; color: #e2e8f0; border-radius: 9px;
  padding: 11px 13px; overflow-x: auto; margin: 8px 0 10px; line-height: 1.5;
}
.rich pre.code code { background: none; padding: 0; color: inherit; font-size: 12.5px; }
.rich blockquote {
  margin: 8px 0; padding: 7px 12px; color: var(--muted);
  background: #f8fafc; border-left: 3px solid #cbd5e1; border-radius: 0 8px 8px 0;
}
.rich hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.rich .table-wrap { overflow-x: auto; margin: 8px 0 10px; }
.rich table { border-collapse: collapse; width: 100%; font-size: 13px; }
.rich th, .rich td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.rich th { background: #f8fafc; font-weight: 600; }
.rich .rich-box {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin: 8px 0; background: #fcfdfe;
}
.rich .rich-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rich .rich-row > * { margin: 0; }
.rich .rich-badge {
  display: inline-block; font-size: 12px; line-height: 1.7; white-space: nowrap;
  border-radius: 999px; padding: 1px 9px; border: 1px solid var(--line);
  background: #f1f5f9; color: var(--muted); vertical-align: middle;
}
.rich .rich-badge.success { color: #047857; background: #ecfdf5; border-color: #a7f3d0; }
.rich .rich-badge.warn { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.rich .rich-badge.danger { color: var(--danger); background: #fef2f2; border-color: #fecaca; }
.rich .rich-badge.primary { color: var(--accent); background: var(--accent-soft); border-color: #d1fae5; }
.rich .rich-caption { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.rich .rich-text { vertical-align: middle; }
.rich .rich-text.xs { font-size: 12px; }
.rich .rich-text.sm { font-size: 13px; }
.rich .rich-text.lg { font-size: 15px; }
.rich .rich-text.muted { color: var(--muted); }
.rich .rich-text.success { color: #047857; }
.rich .rich-text.danger { color: var(--danger); }
.rich .rich-text.primary { color: var(--accent); }
.rich .rich-icon { display: inline-block; line-height: 1; vertical-align: middle; }
.rich .rich-icon.muted { color: var(--muted); }
.rich .rich-icon.success { color: #059669; }
.rich .rich-icon.danger { color: var(--danger); }
.rich .rich-icon.warn { color: #d97706; }
.rich .rich-icon.primary { color: var(--accent); }
.rich .rich-image {
  display: inline-flex; align-items: center; font-size: 12px; color: var(--muted);
  background: #f1f5f9; border: 1px dashed #cbd5e1; border-radius: 8px; padding: 2px 8px;
}
.rich .rich-link { font-size: 12px; }
.hit .text.rich { white-space: normal; }
footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 40px; }
/* ---------------- 顶部导航 ---------------- */
.topnav {
  display: flex; align-items: center; gap: 18px;
  max-width: 1260px; margin: 0 auto; padding: 14px 20px;
}
.brand {
  font-size: 21px; font-weight: 700; color: var(--text);
  text-decoration: none; letter-spacing: -0.02em; white-space: nowrap;
}
.brand span { color: var(--accent); }
.navlinks { display: flex; gap: 4px; flex-wrap: wrap; }
.navlinks a {
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 6px 12px; border-radius: 9px;
}
.navlinks a:hover { background: #eef2f7; color: var(--text); }
.navlinks a.active { background: var(--accent-soft); color: var(--accent); }
.nav-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 导入页 */
.wrap-narrow { max-width: 860px; }
.page-head h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.02em; }
.page-head h1 span { color: var(--accent); }
.page-head .hint { margin-bottom: 10px; }
.jobs { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.jobs .job {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  font-size: 13px; color: var(--muted); background: #f8fafc;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
}
.jobs .job .ok { color: var(--accent); font-weight: 600; }
.jobs .job .fail { color: var(--danger); font-weight: 600; }
.jobs .empty { font-size: 13px; color: var(--muted); }

@media (max-width: 860px) {
  .topnav { flex-wrap: wrap; padding: 12px 14px; gap: 10px; }
  .nav-actions { margin-left: 0; width: 100%; }
}
