:root {
  --ink: #1c1d21;
  --ink-2: #2a2c31;
  --ink-text: #c9c4ba;
  --desk: #e9e4da;
  --surface: #fbfaf7;
  --surface-2: #f3f0ea;
  --line: #e0dacf;
  --line-strong: #cfc7b9;
  --text: #24262b;
  --muted: #7b766d;
  --red: #b3221e;
  --red-deep: #8f1714;
  --red-soft: #f7e5e1;
  --gold: #9c7a45;
  --ok: #3d6b4f;
  --ok-soft: #e3eee6;
  --radius: 8px;
  --ui: "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", system-ui, -apple-system, sans-serif;
  --fang: "FangSong_GB2312", "仿宋_GB2312", "FangSong", "STFangsong", "仿宋", "Noto Serif CJK SC", serif;
  --kai: "KaiTi_GB2312", "楷体_GB2312", "KaiTi", "STKaiti", "楷体", "Noto Serif CJK SC", serif;
  --hei: "SimHei", "黑体", "STHeiti", "Noto Sans CJK SC", sans-serif;
  --xbs: "方正小标宋简体", "FZXiaoBiaoSong-B05S", "华文中宋", "STZhongsong", "Songti SC", "Noto Serif CJK SC", serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ui);
  font-size: 14px;
  color: var(--text);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 80px 440px minmax(0, 1fr);
  height: 100vh;
}

/* —— 左侧导航 —— */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 16px 0;
  background: var(--ink);
  color: var(--ink-text);
}
.brand { display: flex; justify-content: center; }
.seal {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid var(--red);
  border-radius: 6px;
  color: #e9574f;
  font-family: var(--xbs);
  font-size: 15px;
  line-height: 1.1;
  letter-spacing: 2px;
  writing-mode: vertical-rl;
  box-shadow: inset 0 0 0 2px var(--ink), inset 0 0 0 3px rgba(179, 34, 30, 0.5);
}
.nav { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 0 8px; overflow-y: auto; }
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-text);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.nav-item .glyph {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid #45474e;
  border-radius: 4px;
  font-family: var(--xbs);
  font-size: 16px;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.nav-item .label { font-size: 12px; }
.nav-item:hover { background: var(--ink-2); color: #fff; }
.nav-item.active { color: #fff; }
.nav-item.active .glyph { border-color: var(--red); background: var(--red); color: #fff; }
/* 金句、说明、后台 */
.phrase {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.phrase-text { font-family: var(--fang); font-size: 15px; line-height: 1.8; }
.phrase .issue-actions { align-items: center; }
.phrase-cat { margin-right: auto; font-size: 12px; color: var(--muted); }
.help-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.7; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 8px; border-radius: 6px; background: var(--surface-2); text-align: center; }
.stat-value { font-family: var(--xbs); font-size: 20px; color: var(--red); }
.stat-label { font-size: 12px; color: var(--muted); }

.rail-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-top: auto;
  padding: 0 4px;
  font-size: 11px;
  color: #8d887f;
}
.rail-badge { padding: 4px 8px; border: 1px solid #45474e; border-radius: 4px; }
.rail-user { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #e7e2d8; font-size: 12px; }
.rail-quota { color: #c9a56a; }
.rail-logout { border: 0; background: none; color: #8d887f; font-size: 11px; cursor: pointer; text-decoration: underline; }
.rail-logout:hover { color: #fff; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.btn.busy { opacity: 0.85; cursor: progress; background-image: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }

.login-mask {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(28, 29, 33, 0.72);
  backdrop-filter: blur(4px);
  z-index: 10;
}
.login-box {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 360px;
  padding: 32px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}
.login-box .seal { align-self: center; box-shadow: none; }
.login-box h2 { margin: 0; text-align: center; font-size: 18px; letter-spacing: 4px; }
.login-error { min-height: 20px; margin: 0; color: var(--red); font-size: 12px; }

/* —— 中间面板 —— */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.panel-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 1px; }
.panel-head p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  padding: 16px 24px 32px;
  overflow-y: auto;
  animation: rise 0.28s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.group-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
}
.group-label::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 4px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--red); color: var(--red); }
.chip.active { border-color: var(--red); background: var(--red); color: #fff; }
.chip .count { margin-left: 4px; opacity: 0.7; }

.hint-line {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 8px 12px;
  border-left: 3px solid var(--gold);
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}
.hint-line strong { color: var(--text); font-weight: 600; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  padding: 4px 12px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--ink); color: #fff; }
.opt-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.opt { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }

.card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}
.card-title small { font-weight: 400; color: var(--muted); }
.card.collapsed > :not(.card-title) { display: none; }
.card-title .toggle { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.input, .textarea, .select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.select { width: auto; padding: 4px 8px; background: #fff; font-size: 12px; }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--red);
  background: #fff;
  box-shadow: 0 0 0 3px var(--red-soft);
}
.textarea { resize: vertical; line-height: 1.7; }
.textarea.body-editor { min-height: 320px; font-family: var(--fang); font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--red); background: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-deep); }
.btn.dark { border-color: var(--ink); background: var(--ink); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--line); }
.btn.mini { padding: 4px 8px; font-size: 12px; }
.btn.block { width: 100%; padding: 12px; font-size: 14px; letter-spacing: 2px; }
.btn.danger { color: var(--red); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.note { font-size: 12px; color: var(--muted); line-height: 1.6; }

/* 校对结果 */
.issue {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  border-radius: var(--radius);
  background: #fff;
}
.issue.hint { border-left-color: var(--gold); }
.issue-head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.tag {
  padding: 0 8px;
  border-radius: 4px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 12px;
  line-height: 20px;
}
.issue.hint .tag { background: #f1ead9; color: var(--gold); }
.issue-msg { font-size: 13px; line-height: 1.6; }
.diff { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-family: var(--fang); font-size: 15px; }
.diff del { color: var(--red); text-decoration-thickness: 1px; }
.diff ins { color: var(--ok); text-decoration: none; background: var(--ok-soft); padding: 0 4px; border-radius: 3px; }
.issue-actions { display: flex; gap: 8px; justify-content: flex-end; }
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}
.empty .big { font-family: var(--xbs); font-size: 28px; color: var(--ok); }

/* 格式校正表 */
.role-table { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.role-row {
  display: grid;
  grid-template-columns: 32px 104px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.role-row:last-child { border-bottom: 0; }
.role-row .idx { color: var(--muted); text-align: right; }
.role-row .txt { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--fang); font-size: 14px; }
.role-row.heading .txt { font-family: var(--hei); }
.role-row select { width: 100%; }

/* 模板与历史 */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.list-item:hover { border-color: var(--red); box-shadow: 0 4px 16px rgba(28, 29, 33, 0.06); transform: translateY(-1px); }
.list-item .mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--red-soft);
  color: var(--red);
  font-family: var(--xbs);
  font-size: 13px;
  text-align: center;
  line-height: 1.1;
}
.list-item .mark.alt { background: #ece6da; color: var(--gold); }
.list-item .meta { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.list-item .name { font-size: 14px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.list-item .sub { font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* —— 右侧舞台 —— */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.doc-meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.genre-tag {
  flex: none;
  padding: 2px 8px;
  border: 1px solid var(--red);
  border-radius: 4px;
  color: var(--red);
  font-size: 12px;
}
.doc-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 500; }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }
.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 24px;
  color: var(--muted);
  font-size: 12px;
}
.zoom { display: flex; align-items: center; gap: 8px; }
.zoom span { min-width: 40px; text-align: center; }
.preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 24px 48px;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.55), transparent 50%),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(28, 29, 33, 0.025) 23px 24px),
    var(--desk);
}
.paper-wrap { margin: 0 auto; overflow: hidden; }

/* A4 纸面：按国标版心尺寸 1:1 绘制，缩放用 zoom */
.paper {
  position: relative;
  width: 210mm;
  transform-origin: 0 0;
  min-height: 297mm;
  padding: 37mm 26mm 35mm 28mm;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 12px 40px rgba(28, 29, 33, 0.12);
  font-family: var(--fang);
  font-size: 16pt;
  line-height: 28.95pt;
  color: #111;
  text-align: justify;
  word-break: break-all;
}
.paper-body { position: relative; }
.paper .p { margin: 0; text-indent: 2em; }
.paper .p.flush { text-indent: 0; }
.paper .h1 { font-family: var(--hei); }
.paper .h2 { font-family: var(--kai); font-weight: bold; }
.paper .mark {
  margin: 0 0 57.9pt;
  color: #e60000;
  font-family: var(--xbs);
  text-align: center;
  line-height: 1.25;
  letter-spacing: 1px;
}
.paper .docno { display: flex; justify-content: center; margin: 0 0 57.9pt; padding-bottom: 4mm; border-bottom: 2px solid #e60000; }
.paper .docno.up { justify-content: space-between; padding: 0 1em 4mm; }
.paper .docno .kai { font-family: var(--kai); }
.paper .title { margin: 0 0 28.95pt; font-family: var(--xbs); font-size: 22pt; line-height: 35pt; text-align: center; }
.paper .subtitle { margin: 0; font-family: var(--kai); text-align: center; }
.paper .subtitle.gap { margin-bottom: 28.95pt; }
.paper .recipient { margin: 0; }
.paper .attach { margin-top: 28.95pt; }
.paper .attach .p { padding-left: 5em; text-indent: -3em; }
.paper .attach .p + .p { text-indent: 0; }
.paper .sign { margin-top: 57.9pt; text-align: right; }
.paper .sign p { margin: 0; }
.paper .record { margin-top: 28.95pt; font-size: 14pt; border-top: 1px solid #111; border-bottom: 1px solid #111; }
.paper .record p { margin: 0; padding: 0 1em; }
.paper .record .cc { border-bottom: 0.5px solid #111; }
.paper .record .printer { display: flex; justify-content: space-between; }
.paper .placeholder { color: #b8b2a7; text-align: center; font-family: var(--ui); font-size: 12pt; padding-top: 80mm; text-indent: 0; }
.page-break {
  position: absolute;
  left: -28mm;
  right: -26mm;
  height: 0;
  border-top: 1px dashed #d9b3ad;
  pointer-events: none;
}
.page-break span {
  position: absolute;
  right: 4mm;
  top: -10pt;
  padding: 0 6px;
  background: #fff;
  color: #c98a82;
  font-family: var(--ui);
  font-size: 9pt;
  line-height: 18pt;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.file-input { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 64px 380px minmax(0, 1fr); }
  .actions .ghost { display: none; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: auto; }
  .rail { flex-direction: row; padding: 8px 16px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .rail-foot { display: none; }
  .panel { border-right: 0; }
  .stage { min-height: 80vh; }
}
