:root {
  --paper: #f6f3ec;
  --paper-deep: #f0ece2;
  --card: #fffdf8;
  --ink: #211d17;
  --muted: #877f72;
  --line: #e4ddd0;
  --line-strong: #d6cdba;
  --accent: #6f5a3e;
  --accent-soft: #efe7d9;
  --ok: #4f7a58;
  --ok-soft: #e7efe6;
  --warn: #9a6a33;
  --warn-soft: #f6ecdd;
  --err: #a0413f;
  --err-soft: #f5e3e2;
  --radius: 6px;
  --serif: "Noto Serif SC", "Songti SC", "Source Han Serif SC", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.brand .sub { color: var(--muted); font-size: 12px; }
.userbar { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.wrap {
  width: 100%;
  max-width: var(--content-max, 1800px);
  margin: 0 auto;
  padding: 22px clamp(16px, 2.2vw, 48px) 60px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fffdf8; }
.btn.primary:hover { background: #5c4a32; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.ok { color: var(--ok); border-color: var(--ok); }
.btn.err { color: var(--err); border-color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input[type="text"], input[type="number"], input[type="date"], textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
}
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }

.login-card {
  max-width: 420px;
  margin: 8vh auto 0;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card h2 { margin: 0 0 6px; font-family: var(--serif); font-size: 22px; }
.login-card p.hint { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.warn-banner {
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.6;
}

.split {
  display: grid;
  grid-template-columns: clamp(210px, 17vw, 320px) minmax(0, 1fr);
  gap: clamp(16px, 1.8vw, 30px);
  align-items: start;
}
.split > * { min-width: 0; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.panel h3 { margin: 0 0 12px; font-family: var(--serif); font-size: 16px; font-weight: 600; }

.doc-item {
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.doc-item:hover { background: var(--accent-soft); }
.doc-item.active { background: var(--accent-soft); border-color: var(--line-strong); }
.doc-item .t { font-weight: 600; }
.doc-item .m { color: var(--muted); font-size: 12px; }

.doc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.doc-head h2 { margin: 0; font-family: var(--serif); font-size: 22px; min-width: 0; overflow-wrap: anywhere; }
.doc-head .meta { color: var(--muted); font-size: 12px; }

.block {
  position: relative;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.block:hover { border-color: var(--line-strong); }
.block .block-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.block .type-badge {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.block .block-text { white-space: pre-wrap; }
.block h1, .block h2, .block h3, .block h4 { margin: 0; font-family: var(--serif); }
.block.is-highrisk { border-left: 3px solid var(--warn); }
.region-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
}
.block-actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.block:hover .block-actions { opacity: 1; }
.block-actions .btn { padding: 2px 8px; font-size: 12px; }

.placeholder-note {
  padding: 10px;
  background: var(--warn-soft);
  border-radius: var(--radius);
  color: var(--warn);
  font-size: 13px;
}
.table-preview { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-preview th, .table-preview td { border: 1px solid var(--line-strong); padding: 5px 8px; text-align: left; }

.wall { margin-top: 18px; }
.request-card {
  padding: 14px;
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.request-card .req-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.request-card .req-author { font-weight: 600; }
.request-card .req-reason { color: var(--muted); font-size: 13px; margin: 4px 0; }
.request-card .req-proposed {
  padding: 8px 10px;
  background: var(--paper-deep);
  border-radius: var(--radius);
  font-size: 13px;
  white-space: pre-wrap;
}
.status { font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.status.pending { background: var(--accent-soft); color: var(--accent); }
.status.approved, .status.merged { background: var(--ok-soft); color: var(--ok); }
.status.rejected, .status.conflict { background: var(--err-soft); color: var(--err); }
.status.warn { background: var(--warn-soft); color: var(--warn); }

.votes { display: flex; align-items: center; gap: 10px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.vote-actions { display: flex; gap: 6px; margin-top: 8px; }
.vote-actions .btn { padding: 3px 10px; font-size: 12px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(33, 29, 23, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow: auto;
  background: var(--card);
  border-radius: 10px;
  padding: 22px;
  border: 1px solid var(--line-strong);
}
.modal h3 { margin: 0 0 14px; font-family: var(--serif); font-size: 18px; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 80;
}

.empty { color: var(--muted); font-size: 13px; padding: 16px 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs .tab { padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs .tab.active { background: var(--accent-soft); color: var(--accent); }

/* ---------- 管理后台 ---------- */
.admin-section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
}
.admin-section h2 {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }
.row-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row-inline > * { flex: 0 0 auto; }
.row-inline .grow { flex: 1 1 220px; }
.code-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 20px;
  letter-spacing: 0.18em;
  text-align: center;
}
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th, table.list td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; }
table.list th { color: var(--muted); font-weight: 500; font-size: 12px; }
.token-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 26px;
  background: var(--paper-deep);
  border-bottom: 1px solid var(--line);
}
.token-bar input { max-width: 340px; }
.admin-doc-grid { grid-template-columns: minmax(300px, .85fr) minmax(0, 1.15fr); }
.admin-doc-card {
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.admin-doc-card .field { margin-bottom: 12px; }
.admin-doc-card .field-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}
.pin-choices {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--card);
}
.pin-choice { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pin-choice input { width: auto; margin: 0; }
.pin-choices .empty { padding: 2px 0; }
.admin-doc-actions { display: flex; gap: 7px; flex-wrap: wrap; }
@media (max-width: 900px) { .admin-doc-grid { grid-template-columns: 1fr; } }

/* ---------- 批注式两侧布局 ---------- */
.block-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 18vw, 340px);
  gap: 20px;
  align-items: start;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 8px;
  transition: background .15s;
}
.block-row:hover { background: rgba(111, 90, 62, 0.05); }
.block-row .block { margin-bottom: 0; }
.block-row .block-actions { opacity: 1; }
.margin-cell { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
@media (max-width: 1000px) {
  .block-row { grid-template-columns: 1fr; gap: 8px; }
  .margin-cell { padding-left: 14px; border-left: 2px solid var(--line); }
}

.type-label { font-weight: 600; font-size: 12px; color: var(--ink); letter-spacing: .04em; }
.cat-badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--paper-deep); color: var(--muted); }

.annotation {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--card);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.6;
}
.annotation.pending { border-left-color: var(--accent); }
.annotation.merged, .annotation.approved { border-left-color: var(--ok); }
.annotation.rejected { border-left-color: var(--err); opacity: .72; }
.annotation.conflict { border-left-color: var(--err); }
.annotation .ann-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.annotation .ann-author { font-weight: 600; }
.annotation .ann-reason { color: var(--muted); margin: 6px 0 4px; }
.annotation .ann-stats { color: var(--muted); font-size: 12px; }
.annotation .ann-note { margin-top: 4px; font-size: 12px; color: var(--warn); }
.annotation .ann-actions { display: flex; gap: 6px; margin-top: 8px; }
.annotation .ann-actions .btn { padding: 3px 10px; font-size: 12px; }
.retype-line { font-size: 13px; padding: 6px 8px; background: var(--accent-soft); border-radius: 5px; }

/* 差异对比 */
.diff { margin: 6px 0; }
.diff-label { color: var(--muted); font-size: 11.5px; margin: 6px 0 3px; }
.diff-old, .diff-new {
  padding: 6px 8px;
  border-radius: 5px;
  white-space: pre-wrap;
  word-break: break-word;
  border-left: 2px solid transparent;
}
.diff-old { background: #fbf6f5; border-left-color: var(--err); }
.diff-new { background: #f4f9f3; border-left-color: var(--ok); }
.diff-old del { background: #f3d9d7; color: var(--err); text-decoration: line-through; }
.diff-new ins { background: #d9ebd6; color: var(--ok); text-decoration: none; border-radius: 2px; }
.diff-old.struck { text-decoration: line-through; color: var(--err); }

/* 汇总条 / 引导 */
.summary-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  padding: 9px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.summary-bar .count { color: var(--muted); }
.summary-bar .count b { color: var(--ink); margin-left: 2px; }
.summary-bar .spacer { flex: 1; }
.summary-bar label { display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
.summary-bar input[type="checkbox"] { width: auto; }

.hint-banner {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.6;
}

.orphan-section { margin-top: 26px; }
.orphan-section h3 { font-family: var(--serif); font-size: 15px; margin: 0 0 10px; }
.orphan-section .annotation { margin-bottom: 8px; max-width: 420px; }

/* ---------- 左侧目录 / 多选 / 合并 ---------- */
.sidebar { position: sticky; top: 14px; }
.doc-switch { margin-bottom: 14px; }
.doc-switch select { width: 100%; }
.toc { border-top: 1px solid var(--line); padding-top: 12px; }
.toc h3 { margin: 0 0 8px; font-family: var(--serif); font-size: 15px; font-weight: 600; }
.toc-item {
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-item:hover { background: var(--accent-soft); }
.toc-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.block-check { width: auto !important; margin: 0; cursor: pointer; flex: 0 0 auto; }
.block-index {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  background: var(--paper-deep);
  border-radius: 4px;
  padding: 1px 6px;
}

.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(33, 29, 23, 0.25);
  z-index: 60;
  font-size: 13px;
}
.selection-bar .btn { background: transparent; color: var(--paper); border-color: rgba(246, 243, 236, 0.4); }
.selection-bar .btn.primary { background: var(--accent); border-color: var(--accent); color: #fffdf8; }
.selection-bar .sel-count { letter-spacing: 0.04em; }

.block-row.flash { animation: flash-bg 1.4s ease-out; }
@keyframes flash-bg {
  0% { background: rgba(111, 90, 62, 0.18); }
  100% { background: transparent; }
}

.merge-sources { margin: 10px 0; display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow: auto; }
.merge-source {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  padding: 4px 6px;
  background: var(--paper-deep);
  border-radius: 5px;
}
.merged-preview { white-space: pre-wrap; word-break: break-word; }
.ref-line { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ---------- 分节标签页 ---------- */
.tabs-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  min-width: 0;
}
.tab-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 260px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn .tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tab-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.tab-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tab-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
.tab-level {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}
.tab-level select { width: auto; padding: 5px 8px; font-size: 12px; }

/* 标签很多时标签栏内部横向滚动，给出可见的细滚动条 */
.tab-bar { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.tab-bar::-webkit-scrollbar { height: 8px; }
.tab-bar::-webkit-scrollbar-track { background: transparent; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

/* 宽度档位（摘要栏内） */
.summary-bar select { width: auto; padding: 4px 8px; font-size: 12px; }

/* 按正文列实际宽度自适应：正文列偏窄时批注移到段落下方，避免挤压正文 */
.doc-pane { container-type: inline-size; }
@container (max-width: 820px) {
  .block-row { grid-template-columns: 1fr; gap: 8px; }
  .margin-cell { padding-left: 14px; border-left: 2px solid var(--line); }
}
