/* ===== Design Tokens ===== */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e6e8eb;
  --border-strong: #d6d9de;
  --text: #1f2733;
  --text-muted: #6b7280;
  --text-faint: #9aa1ab;

  --primary: #4f46e5;        /* Slate Blue，纯色使用（P0-2 允许） */
  --primary-hover: #4338ca;
  --primary-soft: #eef0fe;

  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf2e2;
  --danger: #b91c1c;
  --danger-soft: #fdeaea;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);

  --font: "Inter", "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 44px; height: 44px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--text-faint); }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: none; background: none;
  border-radius: var(--radius-sm); color: var(--text-muted); font-size: 14px; cursor: pointer; text-align: left;
  font-family: inherit;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: 12px; padding: 8px 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 26px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-title h1 { font-size: 18px; margin: 0; }
.topbar-title p { margin: 2px 0 0; color: var(--text-faint); font-size: 12.5px; }
.kpis { display: flex; gap: 10px; }
.kpi { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; text-align: center; min-width: 78px; }
.kpi b { display: block; font-size: 18px; color: var(--primary); }
.kpi span { font-size: 11px; color: var(--text-faint); }

/* ===== Views ===== */
.view { display: none; padding: 22px 26px; }
.view.active { display: block; }

/* ===== Workbench ===== */
.workbench { display: grid; grid-template-columns: 380px 1fr; gap: 18px; align-items: start; }
.thread-list-col { display: flex; flex-direction: column; gap: 12px; }
.composer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 8px; }
.input { width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 9px 11px; font-family: inherit; font-size: 13.5px; background: var(--surface); color: var(--text); resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-sm { max-width: 160px; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; color: var(--text-muted); cursor: pointer; font-family: inherit; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.thread-list { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 250px); overflow-y: auto; padding-right: 4px; }
.thread-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .15s; }
.thread-card:hover { border-color: var(--border-strong); }
.thread-card.sel { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.thread-card .tc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.thread-card .tc-author { font-weight: 600; font-size: 13px; }
.thread-card .tc-content { color: var(--text-muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thread-card .tc-time { font-size: 11px; color: var(--text-faint); }

.thread-detail-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-height: 400px; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 420px; color: var(--text-faint); gap: 12px; text-align: center; padding: 20px; }

.detail-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.detail-head .dh-meta { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.badge-pending { background: var(--surface-2); color: var(--text-muted); }
.badge-awaiting_review { background: var(--warning-soft); color: var(--warning); }
.badge-delivered { background: var(--success-soft); color: var(--success); }
.badge-escalated { background: var(--danger-soft); color: var(--danger); }
.badge-rejected { background: var(--surface-2); color: var(--text-muted); }
.badge-risk { background: var(--danger-soft); color: var(--danger); display: inline-flex; align-items: center; gap: 4px; }
.badge-risk .icon { width: 14px; height: 14px; }

.detail-body { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.bubble { border-radius: var(--radius); padding: 12px 14px; max-width: 92%; }
.bubble-q { background: var(--primary-soft); align-self: flex-start; border: 1px solid #dfe2fd; }
.bubble-q .b-label { font-size: 11px; color: var(--primary); font-weight: 600; margin-bottom: 4px; }
.bubble-q .b-text { white-space: pre-wrap; }

.suggest-card { border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.suggest-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px; }
.suggest-head .icon { color: var(--primary); }
.suggest-body { padding: 14px; }
.suggest-body .answer { white-space: pre-wrap; font-size: 13.5px; line-height: 1.7; }
.cite-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.cite { font-size: 12px; color: var(--text-muted); background: var(--surface-2); border-left: 3px solid var(--primary); padding: 6px 10px; border-radius: 0 6px 6px 0; }
.cite b { color: var(--text); }
.suggest-meta { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--text-faint); flex-wrap: wrap; }
.suggest-meta .pill { background: var(--surface-2); padding: 3px 9px; border-radius: 999px; }
.risk-note { margin-top: 12px; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; display: flex; gap: 8px; align-items: flex-start; }
.risk-note .icon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

.verify-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 18px 18px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--radius-sm); padding: 9px 14px; font-size: 13px; cursor: pointer; font-family: inherit; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.94); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

.edit-box { padding: 0 18px 18px; display: none; flex-direction: column; gap: 8px; }
.edit-box.show { display: flex; }
.edit-box textarea { min-height: 120px; }

.review-history { padding: 0 18px 18px; }
.review-history h4 { font-size: 12.5px; color: var(--text-faint); margin: 0 0 8px; }
.review-item { font-size: 12.5px; color: var(--text-muted); border-top: 1px dashed var(--border); padding: 7px 0; }
.review-item b { color: var(--text); }
.delivery-note { background: var(--success-soft); color: var(--success); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12.5px; }

/* ===== Cards / Tables ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; }
.hint { color: var(--text-faint); font-size: 12.5px; margin: 0 0 14px; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.link-btn { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 13px; }
.upload-btn { cursor: pointer; }

.kb-stats { display: flex; gap: 12px; margin-bottom: 14px; }
.kb-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 16px; }
.kb-stat b { font-size: 20px; color: var(--primary); display: block; }
.kb-stat span { font-size: 11.5px; color: var(--text-faint); }
.kb-test { display: flex; gap: 8px; margin-top: 14px; }
.kb-test-result { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.kb-hit { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 12.5px; }
.kb-hit .h-top { display: flex; justify-content: space-between; color: var(--text-muted); margin-bottom: 4px; }
.kb-hit .h-score { color: var(--primary); font-weight: 600; }

/* ===== Metrics ===== */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.metric-card .m-head { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; font-weight: 600; }
.metric-card .m-head .icon { color: var(--primary); }
.metric-card .m-value { font-size: 26px; font-weight: 700; margin: 8px 0 2px; }
.metric-card .m-sub { font-size: 12px; color: var(--text-faint); }
.metric-card .m-bar { height: 6px; background: var(--surface-2); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.metric-card .m-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 3px; }

.status-dist { display: flex; flex-direction: column; gap: 10px; }
.sd-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.sd-row .sd-label { width: 96px; color: var(--text-muted); }
.sd-row .sd-track { flex: 1; height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.sd-row .sd-track > span { display: block; height: 100%; background: var(--primary); }
.sd-row .sd-num { width: 40px; text-align: right; color: var(--text-faint); }

.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-row label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.settings-msg { margin-left: 12px; font-size: 12.5px; color: var(--success); }

/* ===== 知识源（多源异构） ===== */
.source-list { display: flex; flex-direction: column; gap: 10px; }
.source-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface); }
.source-card.has-err { border-color: var(--danger); background: var(--danger-soft); }
.sc-main { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.sc-name { font-size: 14px; }
.sc-stat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sc-stat.stat-err { color: var(--danger); }
.sc-err { width: 100%; font-size: 12px; color: var(--danger); margin-top: 2px; }
.sc-side { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.src-badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; }
.badge-local { background: var(--primary-soft); color: var(--primary); }
.badge-comi { background: #e7f0fd; color: #1d4ed8; }
.badge-other { background: var(--warning-soft); color: var(--warning); }
.src-fixed { font-size: 12px; color: var(--text-faint); }
.src-sub { font-size: 12px; color: var(--text-faint); }
.link-btn { white-space: nowrap; }

.dot-err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* 开关 */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; cursor: pointer; transition: background .15s; }
.switch .slider::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: var(--shadow-sm); }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* 引用与命中源标注 */
.cite-src { color: var(--primary); }
.cite-comi { border-left-color: #1d4ed8; }
.cite-other { border-left-color: var(--warning); }
.pill-hit { background: var(--primary-soft); color: var(--primary); }

.kb-hit-ok { background: var(--success-soft); color: var(--success); border-left: 3px solid var(--success); }

@media (max-width: 880px) {
  .workbench { grid-template-columns: 1fr; }
  .kpis { display: none; }
}

/* ===== 群内审核 ===== */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode-opt { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 12px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  cursor: pointer; font-family: inherit; transition: border-color .15s, background .15s; }
.mode-opt:hover { background: var(--surface-2); }
.mode-opt.is-active { border-color: var(--primary); background: var(--primary-soft); }
.mode-name { font-size: 13.5px; font-weight: 600; color: var(--text); }
.mode-opt.is-active .mode-name { color: var(--primary); }
.mode-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }

.cmd-table { width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-size: 13px; }
.cmd-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-faint);
  padding: 6px 8px; border-bottom: 1px solid var(--border); }
.cmd-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.cmd-table td:first-child { width: 42%; }
.cmd-table code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 2px 6px; font-size: 12.5px; color: var(--text); }

.outbox-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.outbox-item { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); padding: 10px 12px; }
.outbox-meta { font-size: 11.5px; color: var(--text-faint); margin-bottom: 6px; display: flex; gap: 10px; }
.outbox-body { font-size: 13px; color: var(--text); white-space: pre-wrap; line-height: 1.7; }
.outbox-body b { font-weight: 600; }
.gmd-info { color: var(--primary); font-size: 12px; }
.gmd-warning { color: var(--warning); font-size: 12px; }
.gmd-comment { color: var(--text-faint); font-size: 12px; }
.gmd-quote { display: block; border-left: 3px solid var(--border-strong); padding-left: 9px;
  color: var(--text-muted); margin: 2px 0; }
.outbox-empty { font-size: 12.5px; color: var(--text-faint); padding: 12px 0; }

/* 审核渠道标识 */
.rev-channel { font-size: 11.5px; color: var(--text-faint); margin-left: 6px; }

@media (max-width: 640px) {
  .mode-grid { grid-template-columns: 1fr; }
}

.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row .input { flex: 1; }
.inline-row .input-sm { flex: 0 0 130px; max-width: 130px; }
