:root {
  --brand: #2b6cff;
  --brand-d: #1b53d6;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e9f2;
  --bg: #f5f7fb;
  --card: #ffffff;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cfd8e6; border-radius: 8px; }

/* ---------- 登录 ---------- */
#login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 10%, #e8f0ff 0, transparent 60%),
              radial-gradient(900px 500px at 90% 90%, #e6fbf4 0, transparent 55%), #f5f7fb;
  padding: 24px;
}
.login-card {
  width: 400px; background: #fff; border-radius: 20px; padding: 34px 32px;
  box-shadow: 0 20px 60px rgba(23, 43, 99, .12);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.logo-mark {
  width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #2b6cff, #12b5a4);
  display: grid; place-items: center; color: #fff; font-weight: 800; letter-spacing: -.5px;
}
.login-card h1 { font-size: 21px; margin: 0 0 6px; }
.login-card p.sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.login-tabs { display: flex; gap: 6px; background: #f1f5fb; border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.login-tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.login-tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15,23,42,.1); }
.login-card .hint { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.7; }
.trial-tip { margin-top: 16px; font-size: 12px; color: #7b89a1; background: #f7f9fd; border: 1px dashed #dbe4f3; border-radius: 10px; padding: 10px 12px; }

/* ---------- 布局 ---------- */
#app { display: none; min-height: 100vh; }
.shell { display: grid; grid-template-columns: 226px 1fr; min-height: 100vh; }
.side {
  background: #0f172a; color: #cbd5e1; padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; color: #fff; }
.side .brand b { font-size: 15px; }
.side .brand i { display: block; font-style: normal; font-size: 11px; color: #7c8aa3; margin-top: 2px; }
.side .nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #cbd5e1; cursor: pointer; font-size: 13.5px; transition: .15s;
}
.side .nav-item:hover { background: #182338; color: #fff; }
.side .nav-item.on { background: linear-gradient(90deg, #22355c, #1b2740); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.side .nav-item .badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: 11px; }
.side .nav-sep { margin: 12px 10px 4px; font-size: 11px; color: #5f6f8a; letter-spacing: .08em; }
.side .foot { margin-top: auto; padding: 12px 10px 4px; font-size: 11.5px; color: #64748b; line-height: 1.7; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 62px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center;
  padding: 0 22px; gap: 14px; position: sticky; top: 0; z-index: 20;
}
.topbar h2 { font-size: 16px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.lic-chip { font-size: 12px; padding: 5px 10px; border-radius: 20px; background: #eef4ff; color: #2b53a8; }
.lic-chip.warn { background: #fff7e6; color: #a15c00; }
.lic-chip.bad { background: #feeceb; color: #b91c1c; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #e8eeff; color: #2b53a8; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.content { padding: 22px; max-width: 1400px; width: 100%; }

/* ---------- 通用组件 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.card-b { padding: 18px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3, .g2 { grid-template-columns: 1fr; } }
.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 12.5px; }
.stat .v { font-size: 26px; font-weight: 750; margin-top: 6px; letter-spacing: -.5px; }
.stat .d { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.stat .v small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2); padding: 8px 14px;
  border-radius: 9px; font-weight: 600; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #c8d4e6; background: #f8fafd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); border-color: var(--brand-d); }
.btn.danger { color: var(--danger); border-color: #f4c7c7; }
.btn.danger:hover { background: #fff5f5; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--brand); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff;
  color: var(--ink); outline: none; transition: .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: #9db9ff; box-shadow: 0 0 0 3px rgba(43,108,255,.1); }
.textarea { resize: vertical; min-height: 90px; line-height: 1.65; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); font-weight: 600; margin-bottom: 6px; }
.field .tip { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.6; }
.row { display: flex; gap: 10px; align-items: center; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; background: #f8fafd; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 12px; border-bottom: 1px solid #f0f3f9; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fbfcff; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 3px 9px; border-radius: 20px; font-weight: 600; }
.pill.ai { background: #eef4ff; color: #2b53a8; }
.pill.waiting { background: #fff3e0; color: #a15c00; }
.pill.human { background: #e8fbf3; color: #0b7a5b; }
.pill.closed { background: #f1f5f9; color: #64748b; }
.pill.ok { background: #e8fbf3; color: #0b7a5b; }
.pill.bad { background: #feeceb; color: #b91c1c; }
.pill.warn { background: #fff7e6; color: #a15c00; }
.empty { padding: 46px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .big { font-size: 30px; margin-bottom: 10px; opacity: .35; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #f1f5fb; color: #5b6b85; font-size: 11.5px; }
.hr { height: 1px; background: var(--line); margin: 18px 0; }

/* ---------- 会话工作台 ---------- */
.workbench { display: grid; grid-template-columns: 340px 1fr; gap: 16px; height: calc(100vh - 62px - 44px); min-height: 520px; }
.conv-list { display: flex; flex-direction: column; min-height: 0; }
.conv-list .toolbar { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.conv-list .items { overflow: auto; flex: 1; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid #f2f5fa; cursor: pointer; transition: .12s; }
.conv-item:hover { background: #f8faff; }
.conv-item.on { background: #eef4ff; box-shadow: inset 3px 0 0 var(--brand); }
.conv-item .l1 { display: flex; align-items: center; gap: 8px; }
.conv-item .l1 b { font-size: 13px; font-weight: 650; }
.conv-item .l1 .t { margin-left: auto; font-size: 11px; color: var(--muted); }
.conv-item .l2 { font-size: 12px; color: var(--muted); margin-top: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-panel { display: flex; flex-direction: column; min-height: 0; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.chat-head { padding: 13px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.chat-body { flex: 1; overflow: auto; padding: 18px; background: #fafbfe; }
.chat-foot { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 10px; align-items: flex-end; background: #fff; }
.chat-foot .textarea { min-height: 44px; max-height: 140px; }
.msg { display: flex; gap: 10px; margin-bottom: 14px; align-items: flex-start; }
.msg .bubble { max-width: 76%; padding: 10px 13px; border-radius: 12px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; background: #fff; border: 1px solid var(--line); }
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: #eaf1ff; border-color: #dbe7ff; }
.msg.ai .bubble { background: #fff; }
.msg.agent .bubble { background: #e8fbf3; border-color: #d2f4e6; }
.msg.system { justify-content: center; }
.msg.system .bubble { background: #f1f5f9; border: 0; color: #64748b; font-size: 12px; padding: 5px 10px; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .ava { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: #e8eeff; color: #2b53a8; flex: 0 0 30px; }
.msg.agent .ava { background: #e8fbf3; color: #0b7a5b; }
.msg.user .ava { background: #f1f5f9; color: #475569; }

/* ---------- 知识库 ---------- */
.kb-grid { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.kb-item { padding: 12px 14px; border-bottom: 1px solid #f2f5fa; cursor: pointer; }
.kb-item.on { background: #eef4ff; box-shadow: inset 3px 0 0 var(--brand); }
.kb-item b { display: block; font-size: 13px; }
.kb-item span { font-size: 11.5px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 14px; }
.tabs button { border: 0; background: transparent; padding: 12px 12px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.dropzone { border: 1.5px dashed #c9d6ea; border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); background: #fafcff; cursor: pointer; }
.dropzone:hover { border-color: var(--brand); background: #f5f9ff; }
.snippet { background: #0f172a; color: #d6e2f5; border-radius: 10px; padding: 13px 15px; font-size: 12.5px; overflow: auto; white-space: pre-wrap; word-break: break-all; line-height: 1.75; }
.testsrc { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fbfcff; font-size: 12.5px; line-height: 1.7; }
.testsrc b { color: #2b53a8; }

/* ---------- 弹窗 ---------- */
.mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 16px; width: 560px; max-width: 100%; max-height: 90vh; overflow: auto; box-shadow: 0 24px 80px rgba(15,23,42,.25); }
.modal.wide { width: 760px; }
.modal-h { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 15px; }
.modal-h .x { margin-left: auto; border: 0; background: transparent; font-size: 20px; color: var(--muted); line-height: 1; }
.modal-b { padding: 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- toast ---------- */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(15,23,42,.25); animation: in .18s ease; max-width: 340px; }
.toast.ok { background: #0b7a5b; }
.toast.bad { background: #b91c1c; }
@keyframes in { from { transform: translateY(-6px); opacity: 0; } }

/* ---------- 图表 ---------- */
.chart { width: 100%; height: 170px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; height: 100%; }
.bars .b { width: 100%; border-radius: 5px 5px 0 0; background: var(--brand); opacity: .85; min-height: 2px; }
.bars .lbl { font-size: 10px; color: var(--muted); }
.bars .col:hover .b { opacity: 1; }

.banner { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.banner.warn { background: #fff7e6; color: #91560c; border: 1px solid #ffe4b3; }
.banner.bad { background: #feeceb; color: #b91c1c; border: 1px solid #fbd5d3; }
.banner .btn { margin-left: auto; }
.login-err { color: var(--danger); font-size: 12.5px; min-height: 18px; margin-bottom: 8px; }
