:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2b6cff;
  --accent-soft: #eaf0ff;
  --gold: #b8860b;
  --green: #1a7f4b;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
#app { display: flex; flex-direction: column; height: 100vh; }

/* topbar */
.topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.logo { background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 7px; font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }
.topbar-actions button, .center-tools button, .compose button, .quick button {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.topbar-actions button:hover, .center-tools button:hover { background: var(--accent-soft); border-color: var(--accent); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 248px 1fr 300px; min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.new-chat { width: 100%; background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px; cursor: pointer; font-size: 13px; }
.new-chat:hover { filter: brightness(1.05); }
.nav-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.tree { display: flex; flex-direction: column; gap: 2px; }
.tree-item { padding: 7px 9px; border-radius: 7px; cursor: pointer; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.tree-item:hover { background: var(--bg); }
.tree-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-item .sub { font-size: 11px; color: var(--muted); }
.tree-item.branch { margin-left: 10px; border-left: 2px solid var(--line); }
.tree-item .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; }
.dot.active { background: var(--gold); } .dot.merged { background: var(--green); } .dot.abandoned { background: #9ca3af; }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); }

/* center */
.center { display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.center-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 6px; }
.center-head h1 { font-size: 16px; margin: 0; }
.center-tools { display: flex; gap: 8px; }
.thread { flex: 1; overflow-y: auto; padding: 8px 20px 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.ai, .msg.report { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.report { border-left: 3px solid var(--green); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; border-radius: 5px; padding: 1px 6px; background: var(--accent-soft); color: var(--accent); }
.msg-actions { margin-top: 8px; display: flex; gap: 8px; }
.msg-actions button { font-size: 12px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 3px 8px; cursor: pointer; }
.msg-actions button:hover { border-color: var(--accent); color: var(--accent); }
.compose { display: flex; gap: 10px; padding: 10px 20px; align-items: flex-end; }
.compose textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font: inherit; outline: none; }
.compose textarea:focus { border-color: var(--accent); }
.compose button { background: var(--accent); color: #fff; border: none; padding: 10px 18px; }
.quick { display: flex; gap: 8px; padding: 0 20px 14px; flex-wrap: wrap; }
.quick button { font-size: 12px; color: var(--muted); }

/* right */
.rightpanel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: none; background: transparent; padding: 11px 4px; cursor: pointer; color: var(--muted); font-size: 12px; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabpane { padding: 14px; overflow-y: auto; flex: 1; }
.ev-card { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; }
.ev-card h4 { margin: 0 0 6px; font-size: 13px; }
.ev-card .lvl { font-weight: 700; color: var(--gold); margin-right: 6px; }
.ev-card p { margin: 4px 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.ev-group { margin-bottom: 14px; }
.ev-group > h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 24px 0; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden, .hidden { display: none !important; }
.modal-card { background: var(--panel); width: min(760px, 92vw); max-height: 82vh; border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.modal-card header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-card header button { border: none; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
#modalBody { padding: 16px; overflow-y: auto; }
.kb-row { border-bottom: 1px solid var(--line); padding: 10px 0; }
.kb-row h4 { margin: 0 0 4px; font-size: 13px; }
.kb-row p { margin: 0; color: var(--muted); font-size: 12px; }

/* toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2430; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 13px; z-index: 60; }

.input-inline { display: flex; gap: 8px; margin-bottom: 12px; }
.input-inline input { flex: 1; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

/* 分叉源头横幅 */
.fork-banner { border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 12px; color: #33415c; }
.fork-banner b { color: var(--accent); }
.fork-banner .snap { color: var(--muted); margin-top: 4px; display: block; }

/* junction 卡（这条回复长出的研究分叉） */
.junction { margin-top: 8px; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 10px; background: #fafbff; }
.junction .jtitle { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.junction .jitem { display: flex; align-items: center; justify-content: space-between; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.junction .jitem:hover { background: var(--accent-soft); }
.junction .jitem .name { font-size: 12px; }
.junction .jitem .arrow { color: var(--accent); }
.junction .jline { font-size: 11px; color: var(--muted); margin-right: 6px; }
.junction .addflag { font-size: 11px; color: var(--accent); cursor: pointer; margin-top: 4px; display: inline-block; }

/* 汇报卡 */
.msg.report { border-left: 3px solid var(--green); background: #f6fffa; }
.msg.report .rpt-head { font-weight: 600; color: var(--green); margin-bottom: 4px; }
.msg.report .rpt-meta { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.msg.report .rpt-badge { float: right; font-size: 11px; background: var(--green); color: #fff; border-radius: 5px; padding: 1px 6px; }

/* 研究线索抽屉分组 */
.clue-group { margin-bottom: 14px; }
.clue-group h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.clue-item { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; cursor: pointer; }
.clue-item:hover { border-color: var(--accent); }
.clue-item .st { font-size: 11px; color: var(--muted); }

/* 会话树图标 */
.tree-item .tico { margin-right: 6px; color: var(--accent); font-size: 11px; }
.tree-item.branch .tico { color: var(--gold); }
