:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f6f8fb;
  --card: #ffffff;
  --border: #e8edf4;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
body { font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button { font-family: inherit; }
a { color: var(--primary); text-decoration: none; }
code { background: #eef2f7; border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }

.mark { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; flex: none; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, #e8efff 0%, #f6f8fb 55%, #f3f0ff 100%); padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 18px; padding: 34px 30px; box-shadow: 0 24px 60px rgba(15, 23, 42, .1); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand h1 { font-size: 19px; }
.login-brand p { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.login-card label { display: block; font-size: 13px; color: #475569; margin-bottom: 7px; }
.login-card input { width: 100%; border: 1px solid #dbe3ef; border-radius: 10px; padding: 11px 13px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-err { color: var(--danger); font-size: 12.5px; margin-top: 10px; }
.login-tip { font-size: 12px; color: #94a3b8; margin-top: 16px; line-height: 1.6; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 218px; background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; flex: none; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 14px; }
.side-brand .mark { width: 34px; height: 34px; border-radius: 9px; font-size: 15px; }
.side-brand-txt b { display: block; color: #fff; font-size: 13.5px; }
.side-brand-txt span { font-size: 11px; color: #64748b; }
#nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#nav button { display: flex; align-items: center; justify-content: space-between; background: none; border: none; color: #94a3b8; text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 13.5px; cursor: pointer; }
#nav button:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
#nav button.active { background: rgba(37, 99, 235, .22); color: #fff; }
.pill { background: #ef4444; color: #fff; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 999px; padding: 0 5px; }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.side-foot a { color: #94a3b8; padding: 4px 8px; }
.side-foot a:hover { color: #fff; }
.side-foot button { background: none; border: none; color: #94a3b8; text-align: left; padding: 4px 8px; font-size: 12.5px; cursor: pointer; }
.side-foot button:hover { color: #f87171; }

.main { flex: 1; padding: 30px 34px 60px; max-width: 1180px; min-width: 0; }
.page-head { margin-bottom: 22px; }
.page-head h2 { font-size: 22px; }
.page-head p { color: var(--muted); font-size: 13.5px; margin-top: 5px; }
.page-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---------- 卡片 / 统计 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--text); }
.stat .label { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .sub { font-size: 11.5px; color: #94a3b8; margin-top: 6px; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.panel-head h3 { font-size: 15.5px; }
.panel-desc { font-size: 12.5px; color: var(--muted); line-height: 1.7; margin: 6px 0 14px; }
.code { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 14px 16px; font: 12.5px/1.7 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.7; }

/* ---------- 表格 ---------- */
.table-panel { padding: 6px 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { font-size: 13px; padding: 12px 16px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td .trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #334155; }
.empty { text-align: center; color: #94a3b8; padding: 30px 0 !important; font-size: 13px; }
.right { text-align: right; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 0 2px; }
.link-btn.danger { color: var(--danger); }
.lead-status { border: 1px solid #dbe3ef; border-radius: 8px; padding: 5px 8px; font-size: 12.5px; background: #fff; color: var(--text); outline: none; cursor: pointer; }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; font-size: 11.5px; border-radius: 999px; padding: 3px 9px; background: #eef4ff; color: var(--primary); white-space: nowrap; }
.badge.green { background: #ecfdf3; color: #15803d; }
.badge.amber { background: #fffbeb; color: #b45309; }
.badge.red { background: #fef2f2; color: #b91c1c; }
.badge.gray { background: #f1f5f9; color: #64748b; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin-top: 12px; }
.field.span2 { grid-column: span 2; }
.field label { display: block; font-size: 12.5px; color: #475569; margin-bottom: 6px; }
.field input, .field textarea, .field select, .panel > textarea {
  width: 100%; border: 1px solid #dbe3ef; border-radius: 9px; padding: 9px 12px; font-size: 13.5px; outline: none; background: #fff; color: var(--text);
}
.field input:focus, .field textarea:focus, .panel > textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.field textarea, .panel > textarea { resize: vertical; font-family: inherit; line-height: 1.6; }
.field input[type="color"] { padding: 3px; height: 38px; cursor: pointer; }
.row-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.publish-choice { display: flex; flex-direction: column; gap: 8px; border: 1px solid #dbe3ef; border-radius: 9px; padding: 11px 13px; background: #fbfdff; }
.publish-choice label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #334155; cursor: pointer; }
.publish-choice input { width: 15px; height: 15px; }
.hint { font-size: 12px; color: #94a3b8; }
.test-result { margin-top: 12px; font-size: 12.5px; border-radius: 9px; padding: 10px 13px; line-height: 1.6; }
.test-result.ok { background: #ecfdf3; color: #15803d; }
.test-result.fail { background: #fef2f2; color: #b91c1c; }

/* ---------- 按钮 ---------- */
.btn { border: none; border-radius: 9px; padding: 9px 18px; font-size: 13.5px; cursor: pointer; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: #fff; border: 1px solid #dbe3ef; color: #334155; }
.btn.ghost:hover { border-color: #b9c7dd; }
.btn.danger { background: #fef2f2; color: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn.block { width: 100%; margin-top: 18px; padding: 11px; font-size: 14.5px; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 24px; }
.modal { background: #fff; border-radius: 16px; width: min(680px, 94vw); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(15, 23, 42, .25); }
.modal.wide { width: min(760px, 94vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: #94a3b8; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* 会话详情 */
.cm { display: flex; margin-bottom: 10px; }
.cm.user { justify-content: flex-end; }
.cm .b { max-width: 78%; padding: 8px 12px; border-radius: 10px; font-size: 13.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.cm.ai .b { background: #f1f5f9; border-top-left-radius: 3px; }
.cm.user .b { background: var(--primary); color: #fff; border-top-right-radius: 3px; }
.cm-time { text-align: center; font-size: 11px; color: #b6c0cf; margin: 4px 0 12px; }
.conv-meta { font-size: 12.5px; color: var(--muted); margin-bottom: 16px; line-height: 1.8; }

/* ---------- 搜索 / 批量操作 ---------- */
.table-toolbar { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.table-toolbar input, .table-toolbar select, .notify-add input, .notify-add select { border: 1px solid #dbe3ef; border-radius: 9px; padding: 8px 11px; font-size: 13px; outline: none; background: #fff; color: var(--text); }
.table-toolbar input { flex: 1; min-width: 220px; }
.table-toolbar input:focus, .notify-add input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.bulk-bar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: #eff6ff; border-bottom: 1px solid #dbeafe; font-size: 12.5px; color: #1d4ed8; flex-wrap: wrap; }
.bulk-bar span { margin-right: auto; }
.kb-check { width: 15px; height: 15px; cursor: pointer; }

/* ---------- 大模型供应商 ---------- */
.grow { flex: 1; min-width: 220px; border: 1px solid #dbe3ef; border-radius: 9px; padding: 9px 12px; font-size: 13.5px; background: #fff; color: var(--text); }
.provider-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-top: 12px; background: #fbfdff; }
.provider-card.disabled { opacity: .65; }
.provider-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.provider-head b { font-size: 13.5px; }
.provider-order { width: 22px; height: 22px; border-radius: 50%; background: #dbeafe; color: #1d4ed8; font-size: 11.5px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.provider-head .spacer { flex: 1; }
.provider-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.provider-grid .full { grid-column: span 2; }
.provider-grid label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.provider-grid input { width: 100%; border: 1px solid #dbe3ef; border-radius: 8px; padding: 7px 10px; font-size: 13px; outline: none; background: #fff; color: var(--text); }
.provider-grid input:focus { border-color: var(--primary); }
.provider-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.provider-actions .link-btn { font-size: 12px; }
.provider-result { font-size: 12px; margin-top: 8px; line-height: 1.5; }
.provider-result.ok { color: #15803d; }
.provider-result.fail { color: #b91c1c; }

/* ---------- 图标上传 ---------- */
.mascot-upload { display: flex; align-items: center; gap: 16px; border: 1px dashed #cbd5e1; border-radius: 12px; padding: 14px; background: #f8fafc; }
.mascot-upload img { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; box-shadow: 0 4px 14px rgba(15,23,42,.16); flex: none; background: #e2e8f0; }
.mascot-upload .hint { margin-top: 8px; line-height: 1.6; }

/* ---------- 消息提醒 ---------- */
.sub-head { font-size: 13px; font-weight: 600; color: #334155; margin: 20px 0 10px; padding-top: 16px; border-top: 1px solid #f1f5f9; }
.notify-add { display: flex; gap: 10px; flex-wrap: wrap; }
.notify-add input { flex: 1; min-width: 260px; }
.channel-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 10px; background: #fbfdff; }
.channel-row .channel-name { font-size: 13px; font-weight: 600; min-width: 130px; }
.channel-row .channel-token { flex: 1; min-width: 160px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-row input[type="checkbox"] { width: 15px; height: 15px; }

/* ---------- 二级栏目 / 知识库治理 ---------- */
.subnav { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 16px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.subnav button { background: #fff; border: 1px solid var(--border); color: #475569; border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.subnav button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.subnav .pill { background: #ef4444; }
.side-user { color: #e2e8f0; font-size: 12px; padding: 0 8px 6px; line-height: 1.5; word-break: break-all; }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span:before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: #22c55e; }
.switch input:checked + span:before { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: default; }
.kb-detail { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.kb-detail-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; line-height: 1.7; }
.kb-detail-content { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.75; color: #1e293b; max-height: 320px; overflow-y: auto; }
.permission-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.permission-row { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px; font-size: 13px; }
.permission-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.permission-grid label { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: #334155; }
.permission-grid input { width: 15px; height: 15px; }
.perm-badges { display: flex; flex-wrap: wrap; gap: 5px; max-width: 520px; }
.settings-pane .panel table, .kb-pane .panel table { margin-top: 8px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%); background: #0f172a; color: #fff; font-size: 13px; padding: 10px 20px; border-radius: 10px; z-index: 200; box-shadow: 0 10px 30px rgba(15, 23, 42, .3); max-width: 86vw; }
.toast.err { background: #b91c1c; }

@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .field.span2 { grid-column: span 1; }
  .sidebar { width: 178px; }
  .main { padding: 22px 18px 50px; }
}
@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 12px; gap: 8px; }
  .side-brand { border: none; padding: 0; margin: 0; }
  .side-brand-txt { display: none; }
  #nav { flex-direction: row; overflow-x: auto; }
  #nav button { white-space: nowrap; padding: 7px 10px; }
  .side-foot { border: none; padding: 0; flex-direction: row; }
  .side-foot a { display: none; }
}
