:root {
  --bg: #f5f6f8;
  --pane: #ffffff;
  --hover: #eef1f6;
  --primary: #2d5cf6;
  --primary-hover: #1e47d4;
  --text: #1a2233;
  --muted: #6b7280;
  --border: #e2e5ea;
  --danger: #d33;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select { font: inherit; }

/* ── 登录 ── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  background: var(--pane); padding: 2.5rem 2rem; border-radius: var(--radius);
  box-shadow: 0 6px 30px rgba(20,30,60,.08); width: 100%; max-width: 360px; text-align: center;
}
.auth-card h1 { font-size: 1.6rem; margin-bottom: .25rem; }
.auth-card .subtitle { color: var(--muted); margin-bottom: 1.5rem; font-size: .9rem; }
.auth-card form { display: grid; gap: .75rem; }
.auth-card input, .modal-card input, .auth-card select {
  padding: .7rem .85rem; border: 1px solid var(--border); border-radius: 8px; outline: none; width: 100%;
}
.auth-card input:focus, .modal-card input:focus { border-color: var(--primary); }
.auth-card button {
  padding: .75rem; background: var(--primary); color: #fff; border: none; border-radius: 8px;
  cursor: pointer; font-weight: 600;
}
.auth-card button:hover { background: var(--primary-hover); }

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; background: var(--pane); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 700; font-size: 1rem; }
.topbar .spacer { flex: 1; }
.topbar .me { font-size: .85rem; color: var(--muted); }
.search-wrap { position: relative; flex: 0 1 360px; }
.search-input {
  width: 100%; padding: .5rem .8rem; border: 1px solid var(--border);
  border-radius: 8px; outline: none; background: var(--bg);
}
.search-input:focus { border-color: var(--primary); background: #fff; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-height: 420px; overflow-y: auto;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 40;
}
.search-results.hidden { display: none; }
.sr-item { padding: .6rem .8rem; cursor: pointer; border-bottom: 1px solid var(--hover); }
.sr-item:hover { background: var(--hover); }
.sr-title { font-weight: 600; }
.sr-snippet { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.sr-snippet mark { background: #fff3a0; }
.sr-empty { padding: 1rem; color: var(--muted); text-align: center; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: .25rem .5rem; }
.link:hover { text-decoration: underline; }

/* ── 三栏布局（可拖拽 + 响应式）── */
.layout {
  display: grid;
  grid-template-columns: var(--col-left, 260px) 6px var(--col-mid, 240px) 6px 1fr;
  height: calc(100vh - 49px);
}
.pane { border-right: 1px solid var(--border); overflow-y: auto; background: var(--pane); min-width: 0; }
.pane.right { border-right: none; }

/* 拖拽分隔条 */
.splitter {
  background: var(--border);
  cursor: col-resize;
  user-select: none;
  position: relative;
  transition: background .12s;
  z-index: 5;
}
.splitter::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -3px; right: -3px;
}
.splitter:hover, .splitter.active { background: var(--primary); }
body.kb-dragging { cursor: col-resize; }
body.kb-dragging iframe, body.kb-dragging .ql-editor { pointer-events: none; }

/* 窄屏：纵向堆叠，隐藏 splitter */
@media (max-width: 899px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
    min-height: calc(100vh - 49px);
  }
  .splitter { display: none; }
  .pane { border-right: none; border-bottom: 1px solid var(--border); }
  .pane.left, .pane.middle { max-height: 38vh; }
}

/* ── v5：侧栏隐藏（折叠左栏/中栏，对应轨道与分隔条一并收为 0）── */
.layout.hide-left { grid-template-columns: 0 0 var(--col-mid, 240px) 6px 1fr; }
.layout.hide-left > #left-pane, .layout.hide-left > .splitter[data-target="left"] { display: none; }
.layout.hide-mid { grid-template-columns: var(--col-left, 260px) 6px 0 6px 1fr; }
.layout.hide-mid > #middle-pane, .layout.hide-mid > .splitter[data-target="mid"] { display: none; }
.layout.hide-left.hide-mid { grid-template-columns: 0 0 0 0 1fr; }

/* 折叠后左边缘的「展开」浮条（保留一条边，点击还原） */
#kb-reveal-bar {
  position: fixed; left: 0; top: 49px; bottom: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 10px 0; pointer-events: none; /* 容器不挡点击，仅按钮可点 */
}
.kb-reveal-btn {
  pointer-events: auto;
  display: none; /* applyHide 会显式设 'flex' 来显示 */
  background: var(--pane); border: 1px solid var(--border); border-left: none;
  border-radius: 0 10px 10px 0;
  padding: 16px 6px; cursor: pointer; font-size: .74rem; color: var(--muted);
  writing-mode: vertical-rl; line-height: 1.2; letter-spacing: .5px;
  box-shadow: 2px 1px 8px rgba(0,0,0,.14);
  transition: background .12s, color .12s, transform .12s;
}
.kb-reveal-btn:hover { background: var(--primary); color: #fff; transform: translateX(2px); }

/* ── v5：附件分页控件 ── */
.att-loading { padding: 1rem; color: var(--muted); font-size: .85rem; }
.att-pager {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem .2rem; border-top: 1px solid var(--border); font-size: .82rem; color: var(--muted);
}
.att-pager .pg-info { margin-right: auto; }
.att-pager .pg-size { padding: .2rem .3rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; outline: none; font-size: .8rem; }
.att-pager .pg-size:focus { border-color: var(--primary); }
.att-pager .link:disabled { opacity: .4; cursor: default; }

/* 左栏 */
.tree { padding: .5rem; }
.tree-header { display: flex; gap: .4rem; margin-bottom: .5rem; }
.tree-header select {
  flex: 1; padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; outline: none;
}
.icon-btn {
  background: var(--hover); border: none; border-radius: 6px; cursor: pointer;
  width: 30px; height: 30px; font-size: 1rem; color: var(--text);
}
.icon-btn:hover { background: #dde2eb; }
.sections { display: flex; flex-direction: column; gap: 2px; }
.section-item {
  padding: .45rem .6rem; border-radius: 6px; cursor: pointer; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between; gap: .4rem;
}
.section-item .sec-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-item:hover { background: var(--hover); }
.section-item.active { background: #e3ebff; color: var(--primary); font-weight: 600; }
.add-btn { margin-top: .4rem; align-self: flex-start; color: var(--muted); font-size: .8rem; }

/* 中栏 */
.page-list { padding: .5rem; }
.page-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .25rem .4rem .5rem; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em;
}
.pages { display: flex; flex-direction: column; gap: 2px; }
.page-item { padding: .5rem .6rem; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: .4rem; }
.page-item:hover { background: var(--hover); }
.page-item.active { background: #e3ebff; }
.page-item .pi-main { min-width: 0; flex: 1; }
.pi-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pi-meta { font-size: .72rem; color: var(--muted); margin-top: .15rem; }
/* 树/页面项的删除按钮（hover 显隐） */
.tree-del {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .85rem; padding: 0 .25rem; line-height: 1;
}
.section-item:hover .tree-del,
.page-item:hover .tree-del { display: inline-block; }
.tree-del:hover { color: var(--danger); }

/* 右栏编辑器 */
.editor-wrap { padding: 1.5rem clamp(1rem, 3vw, 2.5rem); max-width: 1100px; margin: 0 auto; }
.page-title-input {
  border: none; outline: none; font-size: 1.7rem; font-weight: 700; width: 100%;
  padding: .25rem 0; margin-bottom: .5rem; background: transparent;
}
#kb-quill { min-height: 360px; font-size: 15px; }
.ql-toolbar.ql-snow { border: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.ql-container.ql-snow { border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; min-height: 360px; }
.save-status { color: var(--muted); font-size: .78rem; margin-top: .5rem; min-height: 1em; }

.empty { color: var(--muted); padding: 1rem; font-size: .85rem; }

/* ── 通用 ── */
.error { color: var(--danger); font-size: .85rem; min-height: 1.1em; }
#toast-root { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast {
  background: #1a2233; color: #fff; padding: .65rem 1rem; border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .85rem;
  transition: opacity .3s;
}
.toast-error { background: #b3261e; }
.toast.fade-out { opacity: 0; }

/* ── 聊天浮窗 ── */
.chat-host {
  position: fixed; right: 1.25rem; bottom: 1.25rem; width: 420px; max-width: calc(100vw - 2rem);
  z-index: 60; box-shadow: 0 10px 40px rgba(0,0,0,.18); border-radius: 12px; overflow: hidden;
  background: var(--pane); border: 1px solid var(--border);
}
.chat-host.collapsed .chat-body { display: none; }
.chat-panel { display: flex; flex-direction: column; }
.chat-header {
  display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem;
  background: var(--primary); color: #fff;
}
.chat-header span { font-weight: 600; }
.chat-scope {
  margin-left: auto; padding: .25rem .4rem; border: none; border-radius: 6px;
  font-size: .8rem; background: rgba(255,255,255,.2); color: #fff; outline: none;
}
.chat-scope option { color: #1a2233; }
.chat-header .icon-btn { background: rgba(255,255,255,.2); color: #fff; width: 26px; height: 26px; }
.chat-body { display: flex; flex-direction: column; height: 420px; }
.chat-messages { flex: 1; overflow-y: auto; padding: .8rem; background: var(--bg); }
.chat-hint { color: var(--muted); font-size: .8rem; text-align: center; padding: 1rem; }
.msg { margin-bottom: .6rem; display: flex; }
.msg-user { justify-content: flex-end; }
.msg-user .msg-bubble {
  background: var(--primary); color: #fff; padding: .5rem .8rem; border-radius: 12px 12px 2px 12px;
  max-width: 85%; white-space: pre-wrap; word-break: break-word;
}
.msg-assistant .msg-bubble {
  background: #fff; border: 1px solid var(--border); padding: .6rem .8rem; border-radius: 12px 12px 12px 2px;
  max-width: 90%;
}
.msg-assistant .md { white-space: pre-wrap; word-break: break-word; }
.typing { color: var(--muted); font-style: italic; }
.citations { margin-top: .5rem; padding-top: .4rem; border-top: 1px dashed var(--border); font-size: .75rem; color: var(--muted); }
.cite-badge {
  display: inline-block; background: #e3ebff; color: var(--primary); padding: 0 .35rem;
  border-radius: 4px; cursor: pointer; margin: 0 2px; font-weight: 600;
}
.cite-badge:hover { background: var(--primary); color: #fff; }
.chat-input-wrap { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--border); background: var(--pane); }
.chat-input-wrap textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; outline: none; font-size: .85rem;
}
.chat-input-wrap textarea:focus { border-color: var(--primary); }
.chat-input-wrap button {
  padding: 0 1rem; background: var(--primary); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-weight: 600;
}

/* ── 参考范围按钮（聊天头部）── */
.chat-ref-btn {
  margin-left: auto; padding: .25rem .55rem; border: none; border-radius: 6px;
  font-size: .78rem; background: rgba(255,255,255,.2); color: #fff; cursor: pointer;
  white-space: nowrap; max-width: 60%; overflow: hidden; text-overflow: ellipsis;
}
.chat-ref-btn:hover { background: rgba(255,255,255,.32); }

/* ── 参考范围选择器弹层 ── */
.ref-overlay {
  position: fixed; inset: 0; z-index: 180; background: rgba(20,30,60,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.ref-modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 16px 50px rgba(0,0,0,.25);
}
.ref-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.ref-quick { display: flex; flex-wrap: wrap; gap: .4rem; padding: .6rem 1rem; }
.chip {
  background: var(--hover); border: 1px solid var(--border); border-radius: 14px;
  padding: .25rem .7rem; font-size: .78rem; cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.ref-filter {
  margin: 0 1rem; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.ref-filter:focus { border-color: var(--primary); }
.ref-tree { flex: 1; overflow-y: auto; padding: .5rem 1rem; font-size: .85rem; }
.ref-repo { margin-bottom: .3rem; }
.ref-repo-row { display: flex; align-items: center; gap: .3rem; padding: .25rem 0; }
.ref-twist { cursor: pointer; width: 16px; color: var(--muted); user-select: none; }
.ref-repo-label, .ref-branch, .ref-leaf { display: flex; align-items: center; gap: .35rem; cursor: pointer; padding: .15rem 0; }
.ref-repo-label span, .ref-branch span, .ref-leaf span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-branch { font-weight: 500; }
.ref-children { margin-left: 20px; border-left: 1px dashed var(--border); padding-left: .5rem; }
.ref-sub { margin-left: 18px; }
.ref-empty { color: var(--muted); font-size: .8rem; padding: .3rem 0; }
.ref-foot { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; border-top: 1px solid var(--border); }
.ref-count { color: var(--muted); font-size: .8rem; }
.ref-ok { background: var(--primary); color: #fff; border: none; border-radius: 8px; padding: .5rem 1.4rem; cursor: pointer; font-weight: 600; }
.ref-ok:hover { background: var(--primary-hover); }

/* ── 用户管理面板（admin）── */
.admin-overlay {
  position: fixed; inset: 0; z-index: 190; background: rgba(20,30,60,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.admin-modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 920px; max-height: 86vh;
  display: flex; flex-direction: column; box-shadow: 0 16px 50px rgba(0,0,0,.25);
}
.admin-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.admin-toolbar { display: flex; align-items: center; gap: .8rem; padding: .6rem 1rem; }
.admin-hint { color: var(--muted); font-size: .76rem; }
.admin-scroll { overflow: auto; padding: 0 1rem 1rem; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th, .admin-table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
.admin-table td.muted { color: var(--muted); font-size: .78rem; }
.admin-acts { white-space: nowrap; }
.admin-acts .danger { color: var(--danger); }
.role-badge { display: inline-block; padding: .05rem .4rem; border-radius: 4px; font-size: .72rem; margin-right: 2px; }
.role-admin { background: #fde2e2; color: #b3261e; }
.role-editor { background: #e3ebff; color: var(--primary); }
.role-viewer { background: #e2e3e5; color: #555; }

/* 用户编辑/新建子卡片 */
.admin-submodal {
  position: absolute; inset: 0; background: rgba(20,30,60,.35);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  border-radius: 12px;
}
.admin-card { background: #fff; border-radius: 10px; width: 100%; max-width: 420px; box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.admin-card-head { display: flex; align-items: center; justify-content: space-between; padding: .7rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.admin-form { display: flex; flex-direction: column; gap: .6rem; padding: 1rem; }
.admin-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .82rem; color: var(--muted); }
.admin-form label.inline { flex-direction: row; align-items: center; gap: .4rem; }
.admin-form input { padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 6px; outline: none; font-size: .85rem; color: var(--text); }
.admin-form input:focus { border-color: var(--primary); }
.uf-roles { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.uf-roles-label { color: var(--muted); font-size: .82rem; }
.chip-role { display: inline-flex; align-items: center; gap: .25rem; padding: .2rem .6rem; border: 1px solid var(--border); border-radius: 14px; font-size: .78rem; cursor: pointer; }
.admin-form-acts { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .2rem; }

#admin-btn { font-size: .82rem; }

/* ── 附件区 ── */
.attachments { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.att-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem; }
.att-title { font-weight: 600; font-size: .9rem; color: var(--muted); }
.att-upload-btn {
  background: var(--hover); padding: .35rem .7rem; border-radius: 6px; cursor: pointer; font-size: .8rem;
}
.att-upload-btn:hover { background: #dde2eb; }
.att-url-input {
  flex: 1; min-width: 180px; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 6px; outline: none; font-size: .8rem;
}
.att-url-input:focus { border-color: var(--primary); }
.att-list { display: flex; flex-direction: column; gap: 4px; }
.att-item {
  display: flex; align-items: center; gap: .4rem; padding: .4rem .6rem; background: var(--bg);
  border-radius: 6px; font-size: .82rem; flex-wrap: wrap;
}
.att-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-status { font-size: .72rem; padding: .1rem .4rem; border-radius: 4px; }
.st-done { background: #d4edda; color: #155724; }
.st-processing { background: #fff3cd; color: #856404; }
.st-pending { background: #e2e3e5; color: #6c757d; }
.st-failed { background: #f8d7da; color: #721c24; }
.att-empty { color: var(--muted); font-size: .8rem; padding: .5rem 0; }

/* 拖放区（附件区内） */
.att-dropzone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 1rem;
  text-align: center; color: var(--muted); font-size: .82rem; margin-bottom: .6rem;
  transition: border-color .15s, background .15s, color .15s; cursor: default;
}
.att-dropzone .att-drop-hint b { color: var(--primary); }
.att-dropzone.drag {
  border-color: var(--primary); background: #eef3ff; color: var(--text);
}

/* 全局拖放遮罩（窗口任意位置拖入文件） */
.kb-drop-overlay {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(45, 92, 246, .12); backdrop-filter: blur(1px);
  align-items: center; justify-content: center; pointer-events: none;
}
.kb-drop-overlay.show { display: flex; }
.kb-drop-box {
  background: #fff; border: 2px dashed var(--primary); border-radius: 14px;
  padding: 2rem 3rem; color: var(--primary); font-size: 1.05rem; font-weight: 600;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}

/* ════════════════════════════════════════════════════════════════
   v3：通用模态 / 版本标签 / 附件预览 / 贡献度 / 回收站 / 更新日志 / 多语言
   ════════════════════════════════════════════════════════════════ */

/* 通用模态层（贡献/回收站/更新日志/预览/语言询问共用） */
.kb-overlay {
  position: fixed; inset: 0; z-index: 210; background: rgba(20,30,60,.5);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.kb-overlay-sub { z-index: 220; background: rgba(20,30,60,.35); }
.kb-modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 760px; max-height: 86vh;
  display: flex; flex-direction: column; box-shadow: 0 16px 50px rgba(0,0,0,.25);
}
.kb-modal-wide { max-width: 940px; }
.kb-modal-narrow { max-width: 480px; }
.kb-modal-head {
  display: flex; align-items: center; gap: .8rem; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.kb-modal-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-modal-scroll { overflow: auto; padding: 1rem; }
.muted { color: var(--muted); }
.muted.sm, .sm { font-size: .76rem; }
.danger { color: var(--danger); }
.empty-pad { padding: 2rem; text-align: center; color: var(--muted); }

/* 版本标签 */
.version-tag {
  font-size: .72rem; color: var(--muted); background: var(--hover);
  padding: .15rem .5rem; border-radius: 20px; white-space: nowrap;
}

/* 共享表格 */
.kb-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.kb-table th, .kb-table td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--border); }
.kb-table th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }

/* ── 附件预览 ── */
.kb-modal-wide .preview-body { overflow: auto; max-height: 78vh; background: #525659; }
.preview-frame { width: 100%; height: 78vh; border: 0; background: #fff; display: block; }
.preview-img-wrap { display: flex; align-items: center; justify-content: center; padding: 1rem; min-height: 50vh; }
.preview-img { max-width: 100%; max-height: 76vh; border-radius: 4px; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.preview-unsupp { padding: 3rem; text-align: center; color: #fff; background: #525659; }
.preview-unsupp a { color: #fff; }

/* ── 贡献度面板 ── */
.cb-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 760px) { .cb-grid { grid-template-columns: 1fr; } }
.cb-card { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.cb-card:last-child { margin-bottom: 0; }
.cb-card-title { font-weight: 600; margin-bottom: .6rem; }
.cb-score-big { font-size: 2rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.score-breakdown { margin-top: .6rem; }
.score-row { display: flex; justify-content: space-between; padding: .2rem 0; font-size: .82rem; border-bottom: 1px dashed var(--border); }
.score-row:last-child { border-bottom: 0; }
.score-pts { font-weight: 600; color: var(--primary); }
.score-pts em { color: var(--muted); font-style: normal; font-weight: 400; font-size: .74rem; }
.rules-row { margin-top: .6rem; }
.rule-chip { display: inline-block; background: #eef3ff; color: var(--primary); padding: .15rem .5rem; border-radius: 20px; font-size: .74rem; margin: .15rem .15rem 0 0; }
.rule-chip.sm { font-size: .7rem; }
.rule-chip b { font-weight: 700; }
.rank { text-align: center; font-weight: 700; color: var(--muted); }
.rank-1 { color: #d4a017; } .rank-2 { color: #8a8a8a; } .rank-3 { color: #b87333; }

/* ── 回收站面板 ── */
.trash-group { font-weight: 600; color: var(--muted); font-size: .8rem; margin: .8rem 0 .3rem; text-transform: uppercase; letter-spacing: .03em; }
.trash-group:first-child { margin-top: 0; }
.trash-item { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem .6rem; background: var(--bg); border-radius: 8px; margin-bottom: 4px; }
.trash-main { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; min-width: 0; }
.trash-name { font-weight: 500; }
.trash-due { font-size: .72rem; color: var(--muted); background: #fff; padding: .1rem .45rem; border-radius: 20px; border: 1px solid var(--border); }
.trash-due.due-soon { color: var(--danger); border-color: #f5c2c7; background: #fff5f5; }
.trash-acts { white-space: nowrap; }
.trash-acts .danger { color: var(--danger); }

/* ── 更新日志面板 ── */
.cl-item { border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; margin-bottom: .8rem; background: var(--bg); }
.cl-item-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.cl-ver { font-weight: 700; color: var(--primary); background: #eef3ff; padding: .1rem .5rem; border-radius: 6px; }
.cl-date { color: var(--muted); font-size: .78rem; }
.cl-title { font-weight: 600; flex: 1; min-width: 120px; }
.cl-item-head .trash-acts { margin-left: auto; }
.cl-content { font-size: .85rem; line-height: 1.6; }
.cl-content h3 { font-size: .95rem; margin: .5rem 0 .3rem; }
.cl-content h4 { font-size: .88rem; margin: .4rem 0 .2rem; }
.cl-content p { margin: .25rem 0; }
.cl-content ul { margin: .25rem 0 .25rem 1.2rem; }
.cl-content li { margin: .15rem 0; }
.cl-content code { background: #eef1f6; padding: .05rem .35rem; border-radius: 4px; font-size: .8rem; }
.cl-form { display: grid; gap: .6rem; padding: 1rem; }
.cl-form label { display: grid; gap: .25rem; font-size: .8rem; color: var(--muted); }
.cl-form input, .cl-form textarea { padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; outline: none; font: inherit; resize: vertical; }
.cl-form input:focus, .cl-form textarea:focus { border-color: var(--primary); }
.admin-form-acts { display: flex; justify-content: flex-end; gap: .5rem; align-items: center; }

/* ── 编辑器：语言栏 / 只读译文预览 ── */
.editor-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  margin: .6rem 0; padding-bottom: .4rem; border-bottom: 1px solid var(--border);
}
.lang-label { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--muted); }
.lang-label select { padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 6px; outline: none; background: #fff; }
.lang-label select:focus { border-color: var(--primary); }
.lang-preview { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin: .4rem 0; background: #fff; }
.lang-preview-bar { display: flex; align-items: center; justify-content: space-between; padding: .5rem .7rem; background: var(--hover); border-bottom: 1px solid var(--border); }
.lang-preview-tag { font-size: .8rem; color: var(--primary); font-weight: 600; }
.lang-preview-body { padding: 1rem 1.1rem; font-size: .9rem; line-height: 1.65; max-height: 60vh; overflow: auto; }
.lang-preview-body h1,.lang-preview-body h2,.lang-preview-body h3 { margin: .6rem 0 .3rem; }
.lang-preview-body p { margin: .35rem 0; }
.lang-preview-body ul { margin: .35rem 0 .35rem 1.2rem; }
/* 预览态隐藏可编辑 Quill 工具栏与正文 */
.editor-wrap.previewing .ql-toolbar, .editor-wrap.previewing #kb-quill { display: none; }

/* 语言作用域询问 */
.lang-scope-body { padding: 1.2rem 1rem; display: grid; gap: .8rem; }
.lang-scope-q { font-size: .9rem; }
.lang-scope-acts { display: flex; gap: .6rem; }
.lang-scope-acts .ref-ok { flex: 1; text-align: center; }

/* ════════════════════════════════════════════════════════════════
   v4：问答窗 4 状态 / 富文本工具与表格 / 设置 / 搜索结果 / 拖拽
   ════════════════════════════════════════════════════════════════ */

/* ── 聊天浮窗：四档大小 ── */
.chat-host { width: auto; max-width: calc(100vw - 2rem); }
.chat-panel { background: var(--pane); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0,0,0,.18); }
.chat-icon-face, .chat-bar-face, .chat-full { display: none; }

/* state-icon：单个圆形图标 */
.chat-panel.state-icon { width: 52px; height: 52px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.chat-panel.state-icon .chat-icon-face { display: flex; }

/* state-bar：底部一条 */
.chat-panel.state-bar { width: 320px; max-width: calc(100vw - 2rem); }
.chat-panel.state-bar .chat-bar-face { display: flex; align-items: center; gap: .5rem; padding: .55rem .8rem; background: var(--primary); color: #fff; font-weight: 600; }
.chat-panel.state-bar .chat-bar-face .icon-btn { background: rgba(255,255,255,.2); color: #fff; width: 24px; height: 24px; margin-left: auto; }

/* state-small / state-large：完整面板 */
.chat-panel.state-small { width: 400px; max-width: calc(100vw - 2rem); }
.chat-panel.state-large { width: 680px; max-width: calc(100vw - 2rem); }
.chat-panel.state-small .chat-full,
.chat-panel.state-large .chat-full { display: flex; flex-direction: column; }
.chat-panel.state-small .chat-body { height: 440px; }
.chat-panel.state-large .chat-body { height: 66vh; min-height: 440px; }
.cite-label { color: var(--muted); }
.cite-badge { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* v5：引用属性标签 chip */
.cite-tag {
  display: inline-block; font-size: .68rem; padding: 0 .32rem; margin-left: .15rem;
  background: #eef1ff; color: var(--primary); border-radius: 4px; white-space: nowrap;
}

/* v5：拖拽改大小手柄（仅 small/large 显示） */
.chat-resize {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize;
  z-index: 6; opacity: .5;
}
.chat-resize::after {
  content: ''; position: absolute; right: 3px; bottom: 3px; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
}
.chat-panel.state-small, .chat-panel.state-large { position: relative; }
body.kb-dragging .chat-resize, body.kb-dragging .chat-header { user-select: none; }

/* v5：问答回答富文本排版（豆包/Claude Code 风格） */
.msg-assistant .md { white-space: normal; word-break: break-word; line-height: 1.65; font-size: .9rem; }
.msg-assistant .md > *:first-child { margin-top: 0; }
.msg-assistant .md > *:last-child { margin-bottom: 0; }
.msg-assistant .md p { margin: .4rem 0; }
.msg-assistant .md h1, .msg-assistant .md h2, .msg-assistant .md h3, .msg-assistant .md h4 {
  margin: .8rem 0 .4rem; line-height: 1.3; font-weight: 600;
}
.msg-assistant .md h1 { font-size: 1.2rem; }
.msg-assistant .md h2 { font-size: 1.08rem; }
.msg-assistant .md h3 { font-size: 1rem; }
.msg-assistant .md ul, .msg-assistant .md ol { margin: .4rem 0 .4rem 1.3rem; padding: 0; }
.msg-assistant .md li { margin: .2rem 0; }
.msg-assistant .md a { color: var(--primary); text-decoration: underline; }
.msg-assistant .md blockquote {
  margin: .5rem 0; padding: .3rem .8rem; border-left: 3px solid var(--primary);
  background: var(--hover); color: var(--text); border-radius: 0 6px 6px 0;
}
.msg-assistant .md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em;
  background: var(--hover); padding: .1em .35em; border-radius: 4px;
}
.msg-assistant .md pre {
  margin: .5rem 0; padding: .7rem .8rem; background: #1e2430; border-radius: 8px; overflow-x: auto;
}
.msg-assistant .md pre code { background: transparent; color: #e6e6e6; padding: 0; font-size: .82em; }
.msg-assistant .md table { border-collapse: collapse; margin: .5rem 0; width: 100%; font-size: .85rem; }
.msg-assistant .md th, .msg-assistant .md td { border: 1px solid var(--border); padding: .35rem .5rem; text-align: left; }
.msg-assistant .md th { background: var(--hover); font-weight: 600; }
.msg-assistant .md hr { border: none; border-top: 1px solid var(--border); margin: .7rem 0; }

/* v5：管理员可见性矩阵 */
.vis-body { padding: 1rem; display: flex; flex-direction: column; gap: .8rem; max-height: 70vh; overflow-y: auto; }
.vis-repo { border: 1px solid var(--border); border-radius: 8px; padding: .6rem; }
.vis-repo-head { display: flex; align-items: center; gap: .6rem; }
.vis-lvl { padding: .25rem .4rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; font-size: .8rem; }
.vis-lvl:disabled { opacity: .5; }
.vis-secs { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0 0 1.4rem; }

/* v5：RAG 配置面板 */
.rc-body { padding: 1rem; display: flex; flex-direction: column; gap: .9rem; }
.rc-field { display: flex; flex-direction: column; gap: .3rem; }
.rc-label { font-size: .85rem; font-weight: 600; color: var(--text); }
.rc-textarea { width: 100%; padding: .5rem; border: 1px solid var(--border); border-radius: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; resize: vertical; box-sizing: border-box; }
.rc-input { padding: .4rem .5rem; border: 1px solid var(--border); border-radius: 6px; font-size: .9rem; width: 100%; box-sizing: border-box; }
.rc-row { display: flex; gap: 1rem; }
.rc-row .rc-field { flex: 1; }
.rc-inline { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; }
.rc-hint { font-size: .78rem; line-height: 1.5; }
.rc-hint code { background: var(--hover); padding: 0 .3rem; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.rc-acts { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .3rem; }

/* ── 编辑器：富文本工具按钮 + 表格 ── */
.editor-bar { flex-wrap: wrap; }
.editor-bar-acts { display: inline-flex; gap: .35rem; }
.tool-btn {
  background: var(--hover); border: 1px solid var(--border); border-radius: 6px;
  padding: .25rem .55rem; cursor: pointer; font-size: .78rem; color: var(--text);
}
.tool-btn:hover { background: #dde2eb; }
/* Quill 内表格可编辑样式 */
.ql-editor table.kb-table-edit, .lang-preview-body table { border-collapse: collapse; width: 100%; margin: .4rem 0; }
.ql-editor table.kb-table-edit th, .ql-editor table.kb-table-edit td,
.lang-preview-body table th, .lang-preview-body table td { border: 1px solid #bbb; padding: .3rem .45rem; min-width: 40px; }
.ql-editor table.kb-table-edit th, .lang-preview-body table th { background: var(--hover); }
.ql-editor table.kb-table-edit td { background: #fff; }

/* ── 设置面板表单 ── */
.settings-form { display: grid; gap: .7rem; padding: 1.1rem 1rem; }
.settings-form label { display: grid; gap: .25rem; font-size: .82rem; color: var(--muted); }
.settings-form input, .settings-form select { padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; outline: none; font: inherit; background: #fff; }
.settings-form input:focus, .settings-form select:focus { border-color: var(--primary); }

/* ── 搜索结果：面包屑 + 类型标签 ── */
.sr-crumb { font-size: .72rem; color: var(--muted); margin-top: .1rem; }
.sr-tag { display: inline-block; font-size: .64rem; font-weight: 700; padding: .02rem .35rem; border-radius: 4px; background: #eef3ff; color: var(--primary); vertical-align: middle; margin-left: .25rem; }

/* ── 附件：勾选框 + 合并按钮 ── */
.att-check { margin: 0 .2rem 0 0; cursor: pointer; }
.att-merge { padding: .35rem .7rem; font-size: .76rem; }
.att-merge:disabled { opacity: .5; cursor: not-allowed; }

/* ── 拖拽排序指示 ── */
.section-item.dragging, .page-item.dragging { opacity: .4; }
.section-item[draggable="true"], .page-item[draggable="true"] { cursor: grab; }
