/* RAG 知识库控制台 —— 企业级管理后台风格 */
:root {
  --primary: #1677ff;
  --primary-hover: #4096ff;
  --primary-bg: #e8f1ff;
  --danger: #ff4d4f;
  --ok: #52c41a;
  --warn: #faad14;

  --sidebar-bg: #1d2433;
  --sidebar-text: #9aa4b8;
  --sidebar-active: #ffffff;

  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d5d9e0;
  --text: #1f2329;
  --muted: #646a73;
  --faint: #8f959e;

  --mono: "SF Mono", "Cascadia Code", Consolas, "Courier New", monospace;
  --radius: 6px;
}

* { box-sizing: border-box; }
[v-cloak] { display: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--mono); font-size: 0.92em; }
.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 56px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 30px; height: 30px; border-radius: 6px; background: var(--primary);
  color: #fff; font-weight: 700; font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.02em; }
.top-status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.v-sep { width: 1px; height: 14px; background: var(--line-strong); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(82, 196, 26, 0.15); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(250, 173, 20, 0.15); }

/* ---------- 布局:侧导航 + 内容 ---------- */
.shell { display: flex; min-height: calc(100vh - 56px); }
.sidenav {
  width: 200px; flex-shrink: 0; background: var(--sidebar-bg);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 16px 0;
  /* 钉在视口左侧:内容再长也只滚内容区,侧栏不随页面滚走 */
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
}
.sidenav nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidenav a {
  color: var(--sidebar-text); padding: 9px 12px; border-radius: 6px;
  font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  user-select: none; transition: background .12s, color .12s;
}
.sidenav a:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.sidenav a.active { color: var(--sidebar-active); background: var(--primary); }
.nav-marker { width: 3px; height: 14px; border-radius: 2px; background: transparent; flex-shrink: 0; }
.sidenav a.active .nav-marker { background: rgba(255, 255, 255, 0.85); }
.sidenav-footer { padding: 14px 22px; color: var(--sidebar-text); font-size: 11px; line-height: 1.8; }
.sidenav-footer .dim { color: #5b6478; }

.content { flex: 1; padding: 24px 28px 48px; min-width: 0; max-width: 1080px; }

/* ---------- 页头 / 面板 ---------- */
.page-head { margin-bottom: 20px; }
.page-head h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.page-desc { color: var(--muted); margin: 0; font-size: 13px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.panel-title { font-size: 15px; font-weight: 600; }
.panel-title .count { color: var(--muted); font-weight: 400; font-size: 13px; }
.panel-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }

.banner {
  background: #fff2f0; border: 1px solid #ffccc7; color: #cf1322;
  border-radius: var(--radius); padding: 9px 14px; margin-bottom: 16px; font-size: 13px;
}

/* ---------- 统计卡片 ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px;
}
@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.3; }
.stat-value.sm { font-size: 16px; word-break: break-all; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat-sub { color: var(--faint); font-size: 12px; margin-top: 2px; }

/* ---------- 快捷入口 ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 1000px) { .quick-grid { grid-template-columns: repeat(2, 1fr); } }
.quick-item {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; font-size: 13px; color: var(--text); cursor: pointer; text-align: left;
  transition: border-color .12s, color .12s;
}
.quick-item:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- 按钮 ---------- */
.btn {
  border: none; border-radius: var(--radius); padding: 7px 16px;
  font-size: 13px; cursor: pointer; white-space: nowrap; background: transparent;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.ghost { border: 1px solid var(--line-strong); color: var(--muted); background: #fff; }
.btn.ghost:hover:not(:disabled) { color: var(--primary); border-color: var(--primary); }
.btn.text-danger { color: var(--danger); padding: 2px 6px; }
.btn.text-danger:hover:not(:disabled) { background: #fff2f0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 上传 ---------- */
.dropzone {
  border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: 26px 20px; text-align: center; color: var(--muted);
  transition: border-color .12s, background .12s;
}
.dropzone.over { border-color: var(--primary); background: var(--primary-bg); }
.dropzone-icon { font-size: 22px; color: var(--faint); margin-bottom: 4px; }
.dropzone-main { font-size: 14px; }
.link { color: var(--primary); cursor: pointer; }
.dropzone-hint { margin-top: 6px; font-size: 12px; color: var(--faint); }

.uploads { list-style: none; padding: 0; margin: 14px 0 0; }
.uploads li { padding: 5px 0; }
.u-line { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.u-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-msg { color: var(--muted); white-space: nowrap; font-size: 12px; }
li.error .u-msg { color: var(--danger); }
li.done .u-msg { color: var(--ok); }
.bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); transition: width .15s; }
.bar-fill.done { background: var(--ok); }
.bar-fill.error { background: var(--danger); }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 9px 10px; background: #fafbfc; border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 10px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
.table tbody tr:hover { background: #f7f9fc; }
th.num, td.num { text-align: right; }
.cell-strong { font-weight: 600; }
.preview { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-op { text-align: right; white-space: nowrap; }
.kv-table td { border-bottom: 1px solid var(--line); }
.kv-key { color: var(--muted); width: 170px; }

/* 状态标签 */
.state-chip {
  display: inline-block; padding: 1px 9px; border-radius: 10px; font-size: 12px;
  white-space: nowrap;
}
.state-chip.processing { background: #fffbe6; color: #d48806; }
.state-chip.done { background: #f6ffed; color: var(--ok); }
.state-chip.error { background: #fff2f0; color: var(--danger); }

/* 上传进度(任务表内) */
.t-progress-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px; font-size: 12px; }
.t-bar { height: 3px; background: var(--line); border-radius: 2px; }
.t-bar-fill { height: 100%; background: var(--warn); transition: width .3s; }

/* 折叠 / 分页 */
.fold-toggle {
  display: block; width: 100%; margin-top: 8px;
  background: none; color: var(--muted); border: none; border-top: 1px solid var(--line);
  padding: 9px 0; font-size: 12px; cursor: pointer;
}
.fold-toggle:hover { color: var(--primary); }
.pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
}
.pager-collapse { margin-left: auto; }

/* 文档过滤 / 批量选择 */
.docs-toolbar { display: flex; gap: 8px; align-items: center; }
.doc-filter {
  width: 190px; padding: 6px 10px; font-size: 13px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.doc-filter:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12); }
.select-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--primary-bg); border: 1px solid #bcd9ff;
  border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; font-size: 13px;
}
.flex-sp { flex: 1; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #ff7875; }
.table input[type="checkbox"] { accent-color: var(--primary); cursor: pointer; }
.row-selected { background: #f0f7ff !important; }

/* ---------- 空状态 ---------- */
.empty { text-align: center; padding: 32px 0; color: var(--faint); }
.empty.flat { padding: 18px 0; font-size: 13px; }
.empty-title { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.empty-desc { font-size: 12px; margin-bottom: 14px; }

/* ---------- 检索 / 问答 ---------- */
.search-bar { display: flex; gap: 8px; }
.search-bar input {
  flex: 1; padding: 9px 12px; font-size: 14px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); outline: none; transition: border-color .12s, box-shadow .12s;
}
.search-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12);
}
.search-bar select {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; padding: 0 8px; color: var(--muted);
}
.results { margin-top: 16px; }
.chunk { padding: 12px 0; border-bottom: 1px solid var(--line); }
.chunk-src { color: var(--primary); font-size: 11px; margin-bottom: 6px; }
.chunk-text { font-size: 13px; line-height: 1.7; }

.answer {
  margin-top: 16px; padding: 4px 0 4px 16px;
  border-left: 3px solid var(--primary); background: #fafbfc;
  border-radius: 0 var(--radius) var(--radius) 0;
  white-space: pre-wrap; line-height: 1.8; font-size: 14px;
}
.cursor { color: var(--faint); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.sources { margin-top: 12px; color: var(--muted); font-size: 11px; line-height: 1.9; }

/* ---------- LLM 配置 ---------- */
.llm-profile { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.llm-profile.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.08); }
.llm-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.llm-row:hover { background: #f7f9fc; }
.llm-name { font-weight: 600; white-space: nowrap; }
.llm-meta { color: var(--muted); font-size: 12px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proto-tag {
  font-size: 10px; padding: 1px 7px; border: 1px solid var(--line-strong);
  border-radius: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.proto-tag.anthropic { color: #ad6800; border-color: #ffe58f; background: #fffbe6; }
.llm-active-tag { font-size: 12px; color: var(--primary); white-space: nowrap; }
.llm-form { padding: 4px 14px 14px; border-top: 1px solid var(--line); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-field.wide { grid-column: 1 / -1; }
.form-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-field input, .form-field select {
  display: block; width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; outline: none; color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.form-field input:focus, .form-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12);
}
.llm-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.llm-status { font-size: 11px; color: var(--muted); }
.llm-status.ok-text { color: var(--ok); }
.llm-status.err-text { color: var(--danger); word-break: break-all; }

/* 部门切换 / 弹窗 */
.dept-switch {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; padding: 4px 8px; font-size: 12px; color: var(--text); outline: none;
}
.assign-bar { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.assign-bar select { border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 5px 8px; }
.dept-cell { border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; font-size: 12px; background: #fff; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 20, 30, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
  width: 380px; max-width: calc(100vw - 40px); background: #fff;
  border-radius: 10px; padding: 24px 26px 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.modal-title { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- 登录 / 初始化 ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1d2433 0%, #2b3a55 100%); padding: 24px;
}
.auth-card {
  width: 400px; max-width: 100%; background: #fff; border-radius: 10px;
  padding: 32px 32px 28px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.auth-brand { margin-bottom: 22px; }
.auth-title { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.auth-desc { color: var(--muted); font-size: 12px; margin: 0 0 18px; }
.auth-field { display: block; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.auth-field input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px; font-size: 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.auth-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.12); }
.auth-btn { width: 100%; padding: 10px; margin-top: 4px; font-size: 14px; }
.auth-err { color: var(--danger); font-size: 12px; margin-bottom: 10px; }
.auth-key { margin-top: 16px; background: #f6ffed; border: 1px solid #b7eb8f; border-radius: var(--radius); padding: 10px 12px; }
.auth-key-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.auth-key-value { font-size: 12px; word-break: break-all; color: var(--text); }

/* 角色标签 */
.role-tag {
  display: inline-block; font-size: 10px; padding: 1px 7px; border-radius: 9px;
  text-transform: uppercase; letter-spacing: .05em; margin-right: 6px;
  background: #f4f5f7; color: var(--muted); border: 1px solid var(--line-strong);
}
.role-tag.admin { background: #e8f1ff; color: var(--primary); border-color: #bcd9ff; }
.role-tag.viewer { background: #f6ffed; color: var(--ok); border-color: #b7eb8f; }
.user-chip { font-size: 13px; color: var(--text); }

/* 质量评估 */
.eval-score { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.eval-score-value { font-size: 34px; font-weight: 600; color: var(--primary); }
.eval-score-label { color: var(--muted); font-size: 13px; }
.eval-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.eval-form input, .eval-form select {
  padding: 7px 10px; font-size: 13px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); outline: none; min-width: 140px; flex: 1;
}
.eval-form input:focus { border-color: var(--primary); }
.key-value { font-size: 11px; word-break: break-all; }
.audit-detail { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-text { color: var(--ok); }
.err-text { color: var(--danger); }

/* ---------- markdown / mermaid 渲染 ---------- */
.md { font-size: 13px; line-height: 1.7; word-break: break-word; }
.md h1, .md h2, .md h3, .md h4 { margin: 0.8em 0 0.3em; font-weight: 600; line-height: 1.4; }
.md h1 { font-size: 16px; } .md h2 { font-size: 15px; } .md h3 { font-size: 14px; } .md h4 { font-size: 13px; }
.md p { margin: 0.4em 0; }
.md ul, .md ol { margin: 0.4em 0; padding-left: 1.5em; }
.md li { margin: 0.15em 0; }
.md strong { font-weight: 600; }
.md table {
  border-collapse: collapse; margin: 8px 0; font-size: 12.5px;
  display: block; max-width: 100%; overflow-x: auto;
}
.md th, .md td { border: 1px solid var(--line-strong); padding: 4px 10px; text-align: left; }
.md th { background: #fafbfc; font-weight: 600; }
.md code { font-family: var(--mono); font-size: 0.9em; background: #f4f5f7; padding: 1px 5px; border-radius: 3px; }
.md pre { background: #f4f5f7; padding: 10px 12px; border-radius: var(--radius); overflow-x: auto; margin: 8px 0; }
.md pre code { background: none; padding: 0; font-size: 12px; }
.md blockquote { border-left: 2px solid var(--line-strong); margin: 8px 0; padding: 2px 12px; color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.md a { color: var(--primary); }

.mermaid { margin: 12px 0; text-align: center; }
.mermaid svg { max-width: 100%; height: auto; }
.mermaid-fallback {
  font-family: var(--mono); font-size: 12px; text-align: left;
  white-space: pre-wrap; color: var(--muted);
}
