:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #1f2328;
  --text-2: #5b6470;
  --text-3: #8b939e;
  --accent: #1f6feb;
  --accent-weak: #eaf1fe;
  --ok: #1a7f4b;
  --ok-weak: #e8f5ee;
  --warn: #a2620a;
  --warn-weak: #fdf4e3;
  --danger: #b3261e;
  --danger-weak: #fdecea;
  --purple: #6b46c1;
  --purple-weak: #f1ecfb;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: var(--font);
  font-size: 14px; line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-2); }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.spacer { flex: 1; }

/* ---------------- boot ---------------- */
.boot { display: flex; height: 100vh; align-items: center; justify-content: center; }
.boot-inner { color: var(--text-2); }

/* ---------------- layout ---------------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 216px; flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 14px; border-bottom: 1px solid var(--border); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; letter-spacing: .4px;
}
.brand-title { font-size: 14px; font-weight: 600; }
.brand-sub { font-size: 11.5px; color: var(--text-3); }

.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--text-2); cursor: pointer; border: none; background: none;
  font-family: inherit; font-size: 13.5px; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; font-size: 13px; }
.nav-item .count {
  margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 9px; padding: 0 6px; font-size: 11px; line-height: 17px; min-width: 17px;
  text-align: center;
}
.nav-item .count.gray { background: var(--border-strong); color: #fff; }
.sidebar-foot { padding: 10px 14px; border-top: 1px solid var(--border); }
.usage { font-size: 11.5px; color: var(--text-3); line-height: 1.7; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 12px 20px; display: flex; align-items: center; gap: 12px;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; }
.page-sub { font-size: 12.5px; color: var(--text-3); margin-left: 10px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 38px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); min-width: 140px; padding: 4px; display: none; z-index: 60;
}
.dropdown.open { display: block; }
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 8px 10px;
  border: none; background: none; font-family: inherit; font-size: 13px;
  border-radius: 6px; cursor: pointer; color: var(--text);
}
.dropdown button:hover { background: var(--panel-2); }
.avatar {
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent-weak);
  color: var(--accent); display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
}
.content { flex: 1; overflow: auto; padding: 20px; }

/* ---------------- components ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 16px;
}
.card.tight { padding: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin: -2px 0 12px; }
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-head .hint { font-size: 12px; color: var(--text-3); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.stat .label { font-size: 12.5px; color: var(--text-2); }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -.4px; }
.stat .sub { font-size: 11.5px; color: var(--text-3); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  font-family: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #1a5fd0; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: #15683d; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #982117; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-lg { padding: 9px 16px; font-size: 14px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; border-radius: 20px; font-size: 11.5px; line-height: 18px;
  background: var(--panel-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge-role { background: var(--purple-weak); color: var(--purple); border-color: #ddd2f5; }
.badge-blue { background: var(--accent-weak); color: var(--accent); border-color: #cfe0fd; }
.badge-ok { background: var(--ok-weak); color: var(--ok); border-color: #cdeada; }
.badge-warn { background: var(--warn-weak); color: var(--warn); border-color: #f3e0ba; }
.badge-danger { background: var(--danger-weak); color: var(--danger); border-color: #f6d3d0; }
.badge-plain { background: var(--panel-2); color: var(--text-2); }

input[type=text], input[type=password], input[type=number], input[type=search],
select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); font-family: inherit; font-size: 13px;
  color: var(--text); background: var(--panel); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
textarea { resize: vertical; line-height: 1.65; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
.checkline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.checkline input { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--panel-2); white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
td .title-link { color: var(--text); font-weight: 500; cursor: pointer; text-decoration: none; border-bottom: 1px dashed var(--border-strong); }
td .title-link:hover { color: var(--accent); border-color: var(--accent); }
.table-wrap { overflow-x: auto; }

/* ---------------- 批量选择 ---------------- */
/* 表格里的勾选框：与首行文字对齐，别贴到单元格顶部 */
td > input[type=checkbox], th > input[type=checkbox] { margin: 2px 0 0; cursor: pointer; }
/* 选中的行给点底色，方便核对"即将删掉哪几条"（旧浏览器不支持 :has 就只是不高亮，不影响功能） */
tr:has(> td > input[type=checkbox]:checked) { background: var(--accent-weak); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  padding: 7px 12px; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 13.5px; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab:disabled { opacity: .45; cursor: not-allowed; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters > * { flex: 0 0 auto; }
.filters input[type=search], .filters input[type=text] { width: 220px; }
.filters select { width: auto; min-width: 110px; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-3); font-size: 13px; }
.empty .big { font-size: 15px; color: var(--text-2); margin-bottom: 6px; }

.progress-line { display: flex; align-items: center; gap: 0; margin: 4px 0 16px; flex-wrap: wrap; }
.step { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-3); }
.step .dot {
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 11px; background: var(--panel);
}
.step.done { color: var(--ok); }
.step.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.current { color: var(--accent); font-weight: 600; }
.step.current .dot { border-color: var(--accent); color: var(--accent); }
.step.pending { color: var(--warn); font-weight: 600; }
.step.pending .dot { border-color: var(--warn); background: var(--warn-weak); color: var(--warn); }
.step-line { width: 26px; height: 1px; background: var(--border-strong); margin: 0 8px; }

/* ---------------- modal ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .35);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; z-index: 100; overflow: auto;
}
.modal {
  background: var(--panel); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 620px; padding: 20px;
}
.modal.wide { max-width: 1000px; }
.modal-head { display: flex; align-items: center; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------------- toast ---------------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: #26292e; color: #fff; padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; max-width: 420px; box-shadow: var(--shadow-lg); line-height: 1.55;
  animation: slidein .18s ease;
}
.toast.ok { background: #14683c; }
.toast.err { background: #9f231b; }
.toast.warn { background: #8a5410; }
@keyframes slidein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- 长任务状态条（AI 出词 / 联网搜索 / 写文章） ----------------
   后端是一次性返回，前端不知道真实进度，所以只显示「在做什么 + 已等多久」，
   不做假百分比。条子吸在顶部，不遮挡页面操作。*/
.busy-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 300;
  display: none; align-items: center; gap: 10px;
  padding: 9px 16px; font-size: 13px; line-height: 1.5;
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px rgba(16, 24, 40, .22);
}
.busy-bar.on { display: flex; animation: slidein .18s ease; }
.busy-bar .busy-text { flex: 1; }
.busy-bar .busy-time { flex: 0 0 auto; font-variant-numeric: tabular-nums; opacity: .88; }
.busy-spin {
  flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: busy-spin .7s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* ---------------- article workspace ---------------- */
.ws { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
@media (max-width: 1180px) { .ws { grid-template-columns: 1fr; } }

/* 内容框（选题 / 大纲 / 正文）。注意：高度由 JS（autoGrow）按内容自动适应，
   这里的 min-height 只是「脚本没跑到」时的下限兜底 —— 早先这条规则挂在
   .editor-area 上，而全项目没有任何元素用过这个类，等于没生效，
   结果内容框一直是最小的两行高，用户每次都得手动拖。*/
#ws-text {
  min-height: 420px; font-family: var(--mono); font-size: 13px; line-height: 1.7;
}
/* 「给 AI 的额外要求」：单行 input 改成可长高的 textarea（最多约 5 行，超出框内滚动） */
#ws-instr { resize: vertical; }
.editor-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.preview {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px;
  background: var(--panel); min-height: 420px; overflow-wrap: break-word;
}
.preview h1 { font-size: 22px; margin: 0 0 14px; }
.preview h2 { font-size: 17px; margin: 22px 0 8px; }
.preview h3 { font-size: 15px; margin: 18px 0 6px; }
.preview p { margin: 10px 0; }
.preview table { margin: 12px 0; }
.preview ul, .preview ol { padding-left: 22px; }
.preview code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.preview blockquote { border-left: 3px solid var(--border-strong); margin: 12px 0; padding: 4px 14px; color: var(--text-2); }

.side-panel .card { padding: 14px; }
.kv { display: flex; gap: 8px; font-size: 12.5px; padding: 4px 0; }
.kv .k { color: var(--text-3); flex: 0 0 68px; }
.kv .v { color: var(--text); word-break: break-word; }

.ver-item, .hist-item, .mat-item, .ai-item {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 6px; font-size: 12.5px; cursor: pointer; background: var(--panel);
}
.ver-item:hover, .mat-item:hover { border-color: var(--accent); }
.ver-item .top, .hist-item .top, .mat-item .top, .ai-item .top {
  display: flex; align-items: center; gap: 6px; margin-bottom: 2px;
}
.hist-item.reject { background: var(--danger-weak); border-color: #f6d3d0; }
.hist-item.approve { background: var(--ok-weak); border-color: #cdeada; }
.hist-item.unlock { background: var(--warn-weak); border-color: #f3e0ba; }

.score-ring {
  display: inline-flex; align-items: center; justify-content: center;
  width: 54px; height: 54px; border-radius: 50%; font-size: 19px; font-weight: 600;
}

.diff { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; max-height: 460px; overflow-y: auto; }
.diff .dl { padding: 1px 10px; white-space: pre-wrap; word-break: break-word; }
.diff .dl.add { background: #e7f6ec; color: #14683c; }
.diff .dl.del { background: #fdecea; color: #9f231b; }
.diff .dl.same { color: var(--text-2); }

.warn-banner {
  background: var(--warn-weak); border: 1px solid #f3e0ba; color: #7a4d0a;
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}
.info-banner {
  background: var(--accent-weak); border: 1px solid #cfe0fd; color: #14528f;
  border-radius: var(--radius); padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px;
}
.danger-banner {
  background: var(--danger-weak); border: 1px solid #f6d3d0; color: #8f1f18;
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}

/* ---------------- login ---------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow); }
.login-box h1 { margin: 0 0 4px; font-size: 19px; }
.login-box .sub { color: var(--text-3); font-size: 12.5px; margin-bottom: 22px; }
.login-box .btn { width: 100%; justify-content: center; }

.alert { padding: 9px 12px; border-radius: var(--radius); font-size: 12.5px; margin-bottom: 12px; }
.alert-err { background: var(--danger-weak); color: var(--danger); border: 1px solid #f6d3d0; }
.alert-ok { background: var(--ok-weak); color: var(--ok); border: 1px solid #cdeada; }

.tag-chip {
  display: inline-block; padding: 0 7px; margin: 2px 3px 2px 0;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 4px; font-size: 11.5px; color: var(--text-2);
}
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px; font-size: 12.5px; color: var(--text-2); }
.drop-zone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--text-2); font-size: 13px;
  background: var(--panel-2); cursor: pointer;
}
.drop-zone.over { border-color: var(--accent); background: var(--accent-weak); color: var(--accent); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.list-plain li:last-child { border-bottom: none; }

details.inline > summary { cursor: pointer; font-size: 12.5px; color: var(--accent); }
details.inline > div { margin-top: 8px; }

.rule-basis { font-size: 11px; padding: 0 5px; border-radius: 3px; }
.basis-empirical { background: var(--warn-weak); color: var(--warn); }
.basis-official { background: var(--ok-weak); color: var(--ok); }
.basis-pending { background: var(--danger-weak); color: var(--danger); }

/* ---------------- 配图（配图环节） ---------------- */
.img-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.img-item {
  display: flex; gap: 14px; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--panel);
}
.img-item.ready { background: var(--panel-2); }
.img-thumb {
  flex: 0 0 160px; height: 116px; border-radius: var(--radius); overflow: hidden;
  background: var(--bg); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.img-thumb[data-img] { cursor: zoom-in; }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-body { flex: 1; min-width: 0; }
.prompt-box {
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; word-break: break-word;
}
/* 图表 / 示意图的规格摘要：把要画的数据摊开，方便渲染前核对数字 */
.spec-table {
  width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.spec-table th, .spec-table td {
  padding: 3px 8px; text-align: left; border-bottom: 1px solid var(--border);
}
.spec-table th { color: var(--text-2); font-weight: 600; }
.spec-table tbody tr:last-child td { border-bottom: none; }
.spec-table td.num { text-align: right; font-family: var(--mono); }
.spec-list { margin: 4px 0 0; padding-left: 18px; font-size: 12px; }
.spec-list li { margin-bottom: 2px; }
.spec-cols { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.spec-cols > div { flex: 1 1 160px; min-width: 0; }
.warn-banner {
  margin-top: 6px; font-size: 12px; padding: 5px 8px; border-radius: var(--radius);
  background: var(--warn-weak); color: var(--warn); border: 1px solid var(--warn);
}
@media (max-width: 720px) {
  .img-item { flex-direction: column; }
  .img-thumb { flex: none; width: 100%; height: 180px; }
}
