/* =========================================================
   学校简报发布系统 · 样式
   ========================================================= */

/* ============ 简报字体（Web Font 内置，全设备显示一致，与导出 PDF 同源） ============ */
/* 注意：故意不声明 bold 字面的 @font-face —— 让浏览器对加粗做合成加粗，
   否则 bold 会映射到同一常规字重文件，加粗完全不可见（三级标题仿宋加粗等） */
@font-face { font-family: "仿宋"; src: url("fonts/fangsong.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
@font-face { font-family: "仿宋_GB2312"; src: url("fonts/fangsong.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
@font-face { font-family: "楷体"; src: url("fonts/kaiti.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
@font-face { font-family: "黑体"; src: url("fonts/hei.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
@font-face { font-family: "宋体"; src: url("fonts/song.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
/* 页码专用：仅含 0-9 与「—」等页码字符的子集（2.5KB），避免为画页码拉取整包 4.5MB 宋体 */
@font-face { font-family: "宋体页码"; src: url("fonts/song-pagenum.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }
@font-face { font-family: "方正小标宋简体"; src: url("fonts/xiaobiaosong.woff2") format("woff2"); font-weight: normal; font-style: normal; font-display: swap; }

/* ========== 基础 ========== */
:root {
  --red: #a61b29; --red-deep: #8a1420; --red-soft: #fdf3f1;
  --ink: #2b2b2b; --muted: #8a8a8a; --line: #eadfd8;
  --bg: #f6f2ec; --card: #ffffff; --gold: #c9a86a;
  --blue: #2b7de9;
  --shadow: 0 2px 12px rgba(90, 40, 30, .08);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: auto; }
body { min-height: 100vh; font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "微软雅黑", sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.boot-mask { position: fixed; inset: 0; z-index: 9998; background: #f6f2ec; display: flex; align-items: center; justify-content: center; }
.boot-box { display: flex; align-items: center; gap: 10px; color: #8a6f63; font-size: 14px; }
.pv-spin.dark { border-color: rgba(166,27,41,.25); border-top-color: var(--red); }

/* ============ 顶栏 ============ */
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: linear-gradient(120deg, var(--red-deep), var(--red) 55%, #c0392b); color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 10px rgba(120, 20, 20, .25); }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.logo { width: 42px; height: 42px; border-radius: 50%; background: #fff; padding: 2px; object-fit: contain; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 11px; opacity: .85; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.user-chip { background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.35); padding: 6px 14px; border-radius: 20px; cursor: default; user-select: none; font-size: 13px; }

/* ============ 固定工具条 ============ */
.actionbar { position: sticky; top: 60px; z-index: 45; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 8px 18px; background: #fffdf9; border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(120, 40, 30, .06); }
.ab-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.ab-tab { border: none; background: transparent; color: #6d5a52; font-size: 14px; padding: 8px 13px; border-radius: 9px; display: inline-flex; align-items: center; gap: 6px; transition: all .15s; }
.ab-tab:hover { background: var(--red-soft); color: var(--red); }
.ab-tab.active { background: linear-gradient(120deg, var(--red), #c0392b); color: #fff; font-weight: 600; box-shadow: 0 2px 7px rgba(166,27,41,.28); }
.ab-tab.active .nav-badge { background: rgba(255,255,255,.32); }
.nav-icon { font-size: 15px; }
.nav-badge { background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: none; align-items: center; justify-content: center; padding: 0 5px; }
.ab-ops { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.ab-sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }
.sel { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff; outline: none; max-width: 220px; }

/* 格式 / 图片工具条 */
.fmtbar { position: sticky; top: 116px; z-index: 44; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 18px; background: #fff8f4; border-bottom: 1px dashed #e0b4a8; box-shadow: 0 2px 8px rgba(120, 40, 30, .05); }
.fmtbar-label { font-size: 12.5px; color: var(--red); font-weight: 700; margin-right: 4px; }
.fmtbar select { border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; font-size: 12.5px; background: #fff; outline: none; }
.fmtbar select:focus { border-color: var(--red); }
#fmtColor, #imgBorder { width: 32px; height: 28px; border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 2px; cursor: pointer; }
.imgbar { background: #f2f6ff; border-bottom-color: #b9cdf3; }
.imgbar .fmtbar-label { color: #2456a8; }
.ib-num { display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; color: #5a6b88; }
.ib-num input[type="number"] { width: 54px; border: 1px solid var(--line); border-radius: 7px; padding: 4px 5px; font-size: 12.5px; }
.ib-num input[type="range"] { width: 76px; }
.ib-cap { border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; font-size: 12.5px; width: 180px; outline: none; }

/* ============ 底部固定操作条 ============ */
.dockbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; background: #fffdf9; border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(120, 40, 30, .10); padding-bottom: env(safe-area-inset-bottom, 0); }
.dockbar.hidden { display: none; }
.db-inner { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 9px 16px; max-width: 1200px; margin: 0 auto; }
.db-label { font-size: 12.5px; color: var(--red); font-weight: 700; flex: none; }
.db-spacer { flex: 1 1 12px; }
.dockbar select { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; font-size: 13px; background: #fff; outline: none; max-width: 38vw; }
body.with-dock .paper-stage { padding-bottom: 92px; }

/* ============ 移动端底部工具栏 ============ */
.mobile-dock { display: none; }
.mobile-dock.hidden { display: none; }
@media (max-width: 980px) { .mobile-dock:not(.hidden) { display: block; } }
.mobile-dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 96; background: #fffdf9; border-top: 1px solid var(--line); box-shadow: 0 -3px 14px rgba(120, 40, 30, .12); max-height: 62vh; overflow-y: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom, 0); }
.mobile-dock #composeOps, .mobile-dock #fmtbar, .mobile-dock #imgbar { position: static !important; top: auto !important; width: auto; }
.mobile-dock #composeOps { margin: 0; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.mobile-dock #fmtbar, .mobile-dock #imgbar { border-bottom: none; border-top: none; box-shadow: none; }
@media (max-width: 980px) { #dockbar { display: none !important; } body.with-dock .paper-stage { padding-bottom: calc(var(--dock-h, 150px)); } }

/* ============ 布局 ============ */
.layout { min-height: calc(100vh - 120px); }
.main { padding: 0; overflow-x: hidden; }
.view { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; } }
.main > .view:not(#view-compose) { padding: 18px 22px; }
.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.view-head h2 { font-size: 20px; color: var(--red-deep); letter-spacing: 1px; }
.view-head-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.search { padding: 9px 14px; border: 1px solid var(--line); border-radius: 20px; outline: none; width: 230px; background: #fff; }
.search:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(166,27,41,.08); }

/* ============ 按钮 ============ */
.btn { border: none; border-radius: 9px; padding: 9px 16px; font-size: 14px; transition: all .15s; display: inline-flex; align-items: center; gap: 5px; }
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(120deg, var(--red), #c0392b); color: #fff; box-shadow: 0 3px 8px rgba(166,27,41,.3); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-accent { background: linear-gradient(120deg, #b8860b, #d4a017); color: #fff; box-shadow: 0 3px 8px rgba(180,140,20,.25); }
.btn-accent:hover { filter: brightness(1.08); }
.btn-outline { background: #fff; border: 1px solid var(--red); color: var(--red); }
.btn-outline:hover { background: var(--red-soft); }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: #6d5a52; }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-danger { background: #fff; border: 1px solid #d4a0a0; color: #b23b2e; }
.btn-danger:hover { background: #fdf0ee; }
.btn-success { background: linear-gradient(120deg, #1e7e34, #2e9e50); color: #fff; box-shadow: 0 3px 8px rgba(30,126,52,.25); }
.btn-success:hover { filter: brightness(1.08); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.mini-btn { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; font-size: 12.5px; color: #6d5a52; }
.mini-btn:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.mini-btn.danger { color: #b23b2e; }
.mini-btn.on { background: var(--red); border-color: var(--red); color: #fff; }

/* ============ 卡片与表单 ============ */
.card { background: var(--card); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid #f1e7e0; }
.f-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.f-field > span { font-size: 12.5px; color: var(--muted); }
.f-field input, .f-field textarea, .f-field select { border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; outline: none; background: #fffdfb; transition: border .15s; width: 100%; resize: vertical; }
.f-field input:focus, .f-field textarea:focus, .f-field select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(166,27,41,.07); }

/* ============ 编写（所见即所得纸张） ============ */
.compose-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 10px 20px 6px; color: #6d5a52; font-size: 12.5px; }
.cm-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cm-hint { color: #9c8c82; }
.pv-zoom { display: inline-flex; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.pv-zoom button { border: none; background: transparent; font-size: 12px; padding: 4px 10px; border-radius: 7px; color: #7a6a60; }
.pv-zoom button:hover { color: var(--red); background: var(--red-soft); }
.pv-zoom button.on { background: var(--red); color: #fff; font-weight: 600; }
.doc-state { font-style: normal; font-size: 11.5px; background: #eee; color: #888; border-radius: 9px; padding: 3px 10px; font-weight: 600; }
.doc-state.saved { background: #e5f5e9; color: #1e7e34; }
.doc-state.dirty { background: #fdf0e0; color: #b8860b; }
.paper-stage { overflow: auto; padding: 14px 16px 50px; background: #ece5da; min-height: calc(100vh - 210px); }
.paper-scale { transform-origin: top center; margin: 0 auto; }
.paper-tip { text-align: center; font-size: 12.5px; color: #a89a90; padding: 10px 0 20px; }

/* ============ Word 式分页视图（编写区） ============
   编辑器下推内容的是每页首个块的 margin-top（见 app.js renderPageGuides），
   这里只负责把「多张 A4 纸」画到内容之下：底板层用 z-index:-1 沉到所有正文之下，
   纸张本身的底色/投影交给底板，.paper 自身改为透明。 */
.paper.editable.paged { background: transparent; box-shadow: none; }
.paper.editable .page-guides { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.page-guides .pg-sheet { position: absolute; left: 0; right: 0; background: #fff; border-radius: 2px; box-shadow: 0 3px 12px rgba(80, 40, 30, .16); }
.page-guides .pg-no { position: absolute; bottom: 12px; font-family: "宋体页码", "SimSun", serif; font-size: 14pt; line-height: 1; color: #cfc7c0; letter-spacing: 1px; }
.page-guides .pg-no.odd { right: 30px; }
.page-guides .pg-no.even { left: 30px; }
.page-guides .pg-gap { position: absolute; left: 0; right: 0; top: 100%; margin-top: 2px; text-align: center; font-size: 11.5px; color: #9c8f88; letter-spacing: .5px; }
.pg-count { font-style: normal; font-size: 11.5px; background: #fff; color: #7a6a60; border: 1px solid var(--line); border-radius: 9px; padding: 3px 10px; font-weight: 600; }
.pg-count:empty { display: none; }

/* ============ 纸张（A4，GB/T 9704 页边距） ============ */
.paper { position: relative; display: flex; flex-direction: column; width: 210mm; min-height: 297mm; box-sizing: border-box; padding: 37mm 26mm 35mm 28mm; margin: 0 auto; background: #fff; box-shadow: 0 6px 26px rgba(80, 40, 30, .18); font-family: "仿宋_GB2312", "仿宋", "仿宋_GB2312", FangSong, STFangsong, "Noto Serif CJK SC", serif; }

/* ---- 简报元素（编辑预览与打印共用） ---- */
.doc-org { font-family: "方正小标宋简体", "方正小标宋_GBK", "华文中宋", STZhongsong, "Noto Serif CJK SC", SimSun, serif; color: #d0342c; text-align: center; font-size: 30pt; line-height: 1.25; letter-spacing: 1px; font-weight: 700; white-space: nowrap; margin-bottom: 41.4pt; }
.doc-org-file { margin-left: .25em; letter-spacing: 2px; }
.doc-number { display: flex; align-items: baseline; font-size: 16pt; color: #000; line-height: 1.2; margin-bottom: 8.1pt; }
.doc-number .num-left, .doc-number .num-date { flex: 1 1 0; min-width: 0; font-size: 14pt; white-space: nowrap; overflow: hidden; }
.doc-number .num-left { text-align: left; }
.doc-number .num-center { flex: 0 0 auto; text-align: center; white-space: nowrap; }
.doc-number .num-date { text-align: right; }
.doc-number.num-edit { white-space: nowrap; }
.doc-number .num-seq { display: inline-block; background: #f3efec; color: #6d5a52; border-radius: 4px; padding: 0 3px; }
.paper.editable .doc-number .eb.num-prefix { display: inline-block; min-width: 2em; }
.doc-redline { border: none; border-bottom: 2.4pt solid #d0342c; margin: 0 0 50.8pt; }
.doc-title { font-family: "方正小标宋简体", "方正小标宋_GBK", "华文中宋", STZhongsong, "Noto Serif CJK SC", SimSun, serif; text-align: center; font-size: 22pt; line-height: 1.45; margin-bottom: 18pt; color: #000; font-weight: 400; }
.doc-to { font-size: 16pt; margin-bottom: 4pt; }
.doc-block { font-size: 16pt; text-indent: 2em; margin: 0; }
/* 标题规格：一级=三号黑体、二级=三号楷体、三级=三号仿宋加粗、正文=三号仿宋_GB2312 */
.doc-block.t-h1 { font-family: "黑体", SimHei, sans-serif; }
.doc-block.t-h2 { font-family: "楷体", "楷体_GB2312", KaiTi, STKaiti, serif; }
.doc-block.t-h3 { font-family: "仿宋_GB2312", "仿宋", FangSong, STFangsong, serif; font-weight: bold; }
.doc-attach-wrap { display: flow-root; }
.doc-attach { font-size: 16pt; text-indent: 2em; margin-top: 14pt; }
/* 落款区高度必须容得下印章：印章默认 42mm 且向上溢出约 10mm，
   故落款区最小高度取 56mm（约 159pt），避免印章压到版记或跑到页外 */
.doc-sign-area { position: relative; margin-top: 26pt; min-height: 56mm; margin-bottom: 18mm; clear: both; }
.doc-sign { position: relative; z-index: 3; text-align: right; font-size: 16pt; padding-right: 3em; }
.doc-date { position: relative; z-index: 3; text-align: right; font-size: 16pt; padding-right: 4em; margin-top: 4pt; }
/* 印章：规范做法是下压落款单位与日期，横向居中于发文机关署名右端 */
.doc-seal { position: absolute; width: 42mm; height: 42mm; opacity: .9; left: 58%; top: -10mm; pointer-events: none; z-index: 1; }

.doc-seal img { width: 100%; height: 100%; }
/* 版记：随内容流动 —— 内容少时贴纸底，内容多时跟随内容向下移动 */
.doc-version { position: relative; margin-top: auto; padding-top: 22pt; }
.doc-body { outline: none; }
.doc-body > p { max-width: 100%; }
.paper.editable #docBody:focus, .paper.editable #docBody:focus-visible { outline: none; }
.doc-version .cc-line { font-size: 14pt; border-top: 1pt solid #000; border-bottom: 1pt solid #000; padding: 3pt 0; text-align: left; }
.doc-version .review-line { font-size: 14pt; border-bottom: 1pt solid #000; padding: 3pt 0; text-align: center; white-space: nowrap; }
.doc-version .date-line { font-size: 14pt; border-bottom: 1pt solid #000; padding: 3pt 0; text-align: right; white-space: nowrap; }
.paper.editable .review-line .eb { display: inline; border-bottom: none !important; background: none; }
.paper.editable .review-line .eb:hover { background: rgba(255, 240, 225, .55); }
.paper.editable .review-line .eb:focus { background: #fff7ec; border-bottom: none !important; }
.paper.editable .date-line .eb { display: inline-block; max-width: 100%; }
.doc-blank { text-align: center; color: #c9beb4; font-size: 12pt; padding: 40pt 0; letter-spacing: 2px; }

/* ---- 可编辑纸张（WYSIWYG） ---- */
/* Word 式编辑：无下划线、无分隔框，仅悬停/聚焦轻提示 */
.paper.editable .eb { outline: none; border-radius: 3px; cursor: text; display: block; max-width: 100%; border-bottom: none; background: transparent; }
.paper.editable .doc-org .eb, .paper.editable .cc-line .eb, .paper.editable .date-line .eb,
.paper.editable .doc-number .num-left .eb, .paper.editable .doc-number .num-date .eb,
.paper.editable .review-line .eb { display: inline; border-bottom: none; background: none; }
.paper.editable .doc-number .num-left .eb, .paper.editable .doc-number .num-date .eb { display: inline-block; max-width: 100%; }
/* 发文字号「前缀+期号+后缀」是同一行的一段文字，基线上的 .eb 默认 display:block 会让「第 __ 期」
   竖排折成三行。这里必须保持行内，且整体 nowrap。 */
.paper.editable .doc-number .num-center .eb { display: inline-block; min-width: .6em; vertical-align: baseline; }
.paper.editable .doc-number .num-center { white-space: nowrap; }
.paper.editable .eb:hover { background: rgba(255, 240, 225, .4); }
.paper.editable .eb:focus { background: #fff7ec; border-bottom: none; }
.paper.editable p.doc-block { min-height: 1.75em; }
.paper.editable .doc-block .eb { display: inline; }
.paper.editable .eb.empty-hint:empty::before, .paper.editable .eb[data-ph]:empty::before { content: attr(data-ph); color: #c4b6ab; font-style: italic; font-size: .82em; }
.paper.editable .doc-block { position: relative; }
.paper.editable .doc-block .blk-del { position: absolute; right: -22px; top: 2px; width: 18px; height: 18px; line-height: 16px; border: none; border-radius: 50%; background: #e8dcd3; color: #9b8377; font-size: 13px; cursor: pointer; opacity: 0; transition: opacity .15s; padding: 0; }
.paper.editable .doc-block:hover .blk-del { opacity: 1; }
.paper.editable .doc-block .blk-del:hover { background: var(--red); color: #fff; }
.paper.editable .empty-hint { color: #bdb0a6; }
.paper.editable .doc-img-cap[contenteditable]:empty::before { content: attr(data-ph); color: #c4b6ab; font-style: italic; font-size: .82em; }
.paper.editable .doc-img-cap[contenteditable]:hover { background: rgba(255, 240, 225, .55); }
.paper.editable .doc-img-cap[contenteditable]:focus { background: #fff7ec; outline: none; }
@media (max-width: 980px) { .paper.editable .blk-del { right: 0; } }

/* =========================================================
   图片与图文混排（Word 式环绕）
   ========================================================= */
.doc-img-line { margin: 0; }
.img-inner { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
.img-inner img { -webkit-user-drag: none; user-select: none; }
.doc-img img { display: block; width: 100%; height: auto; }
.doc-img-cap { display: block; text-align: center; font-family: "楷体", "楷体_GB2312", KaiTi, serif; font-size: 10.5pt; line-height: 1.5; color: #333; margin-top: 2pt; text-indent: 0; }
.doc-img-cap:empty { display: none; }

/* 四周型 / 紧密型：浮动，文字环绕 */
.img-float { margin: 0; }
.img-float.float-left { float: left; }
.img-float.float-right { float: right; }
.img-float.tight { shape-margin: 4px; }
.img-float.clear-end { clear: none; }

/* 上下型：图文互不侵入 */
.doc-img-block { display: block; clear: both; margin: 8pt 0; text-align: center; }

/* 嵌入型图片行：连续嵌入型图片归入同一行容器，可并排（对齐由容器 text-align 控制） */
.doc-img-row { margin: 8pt 0; }
.doc-img-row .doc-img-block { display: inline-block; clear: none; margin: 0 3pt; vertical-align: top; }

/* 浮于文字上方 / 衬于文字下方：绝对定位 */
.doc-img-abs { position: absolute; margin: 0; }
.doc-img-abs.layer-front { z-index: 6; }
.doc-img-abs.layer-behind { z-index: 0; }

/* --- 编辑态：选中框 + 八个控制点 --- */
.paper.editable .img-inner { cursor: move; }
.paper.editable .img-inner:hover { outline: 1px dashed rgba(43, 125, 233, .55); outline-offset: 1px; }
.paper.editable .img-inner.sel { outline: 2px solid var(--blue); outline-offset: 2px; }
.img-handle { display: none; position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--blue); border-radius: 2px; z-index: 30; box-sizing: border-box; }
.paper.editable .img-inner.sel .img-handle { display: block; }
.img-handle[data-h="nw"] { left: -6px; top: -6px; cursor: nwse-resize; }
.img-handle[data-h="ne"] { right: -6px; top: -6px; cursor: nesw-resize; }
.img-handle[data-h="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.img-handle[data-h="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.img-handle[data-h="w"] { left: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.img-handle[data-h="e"] { right: -6px; top: 50%; margin-top: -5px; cursor: ew-resize; }
.img-handle[data-h="n"] { left: 50%; top: -6px; margin-left: -5px; cursor: ns-resize; }
.img-handle[data-h="s"] { left: 50%; bottom: -6px; margin-left: -5px; cursor: ns-resize; }
.img-badge { position: absolute; left: 0; top: -20px; background: var(--blue); color: #fff; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 4px 4px 0 0; white-space: nowrap; display: none; z-index: 30; }
.paper.editable .img-inner.sel .img-badge { display: block; }
/* 注意：不可给 .doc-img-line 一律加 position:relative —— 会覆盖 front/behind 的绝对定位，
   导致「浮于文字上方/衬于文字下方」的图片无法自由拖动定位（浮动/块状的 relative 由内联样式保证） */

/* 编辑态：段落因 .doc-block { position:relative } 画在浮动图片之上，导致失焦后点不到图片。
   把四周型/紧密型浮动框与嵌入/上下型图块提升到段落之上（仅编辑态；front=z6/behind=z0 不受影响）。
   严禁改成 .doc-img-line 通配，否则覆盖 .doc-img-abs 的 absolute。 */
.paper.editable .doc-img-line.img-float,
.paper.editable .doc-img-block { position: relative; z-index: 5; }

/* 图片占位（打印态不显示） */
.img-ph { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; min-height: 40pt; background: #f4f0ec; color: #b5a89e; font-size: 11pt; }

/* ============ 列表 ============ */
.doc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.doc-card { background: #fff; border-radius: 14px; padding: 16px; box-shadow: var(--shadow); border: 1px solid #f1e7e0; display: flex; flex-direction: column; gap: 9px; }
.doc-card .dc-title { font-size: 15.5px; font-weight: 700; color: var(--ink); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card .dc-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); }
.doc-card .dc-no { color: var(--red); font-weight: 600; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 8px; font-size: 11.5px; background: var(--red-soft); color: #9c5a50; }
.tag.pub { background: #e5f5e9; color: #1e7e34; }
.tag.draft { background: #f0ede9; color: #8a8175; }
.dc-ops { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; border-top: 1px dashed #f0e6de; }

/* ============ 表格 ============ */
.table-wrap { background: #fff; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid #f1e7e0; padding: 6px; overflow-x: auto; }
.rec-table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 900px; }
.rec-table th { background: linear-gradient(120deg, var(--red-deep), var(--red)); color: #fff; padding: 11px 10px; text-align: left; font-weight: 600; white-space: nowrap; }
.rec-table th:first-child { border-radius: 10px 0 0 0; }
.rec-table th:last-child { border-radius: 0 10px 0 0; }
.rec-table td { padding: 10px; border-bottom: 1px solid #f5ece6; vertical-align: middle; }
.rec-table tr:nth-child(even) td { background: #fdf8f5; }
.rec-table tr:hover td { background: var(--red-soft); }
.rec-no { color: var(--red); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.logs-panel { margin-top: 14px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); border: 1px solid #f1e7e0; padding: 4px 16px; }
.logs-panel summary { cursor: pointer; padding: 12px 0; font-weight: 700; color: var(--red-deep); font-size: 14px; }
.logs { max-height: 320px; overflow: auto; font-size: 12.8px; }
.log-item { display: flex; gap: 10px; padding: 7px 2px; border-bottom: 1px dashed #f0e6de; color: #6d5a52; }
.log-item .lg-t { color: #b0a49c; white-space: nowrap; }
.log-item .lg-act { color: var(--red); font-weight: 600; white-space: nowrap; }

/* ============ 模板库 ============ */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tpl-card { background: #fff; border-radius: 14px; padding: 18px; box-shadow: var(--shadow); border: 1px solid #f1e7e0; transition: all .18s; cursor: pointer; position: relative; overflow: hidden; }
.tpl-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, var(--red), #d4a017); }
.tpl-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(120, 40, 30, .16); }
.tpl-icon { font-size: 30px; margin-bottom: 8px; }
.tpl-name { font-size: 16px; font-weight: 700; color: var(--red-deep); margin-bottom: 5px; }
.tpl-desc { font-size: 12.5px; color: var(--muted); line-height: 1.55; margin-bottom: 10px; min-height: 38px; }
.tpl-ops { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tpl-card:hover .tpl-ops { opacity: 1; }
.tpl-op { border: none; background: #f7f1ec; border-radius: 8px; width: 28px; height: 28px; cursor: pointer; font-size: 13px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; transition: all .15s; }
.tpl-op:hover { background: var(--red-soft); transform: translateY(-1px); }
.tpl-form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; text-align: left; }
.tpl-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #6d5a52; font-weight: 600; }
.tpl-form input, .tpl-form textarea { border: 1px solid #e5d8cf; border-radius: 9px; padding: 9px 12px; font-size: 14px; font-family: inherit; background: #fff; color: #333; }
.tpl-form input:focus, .tpl-form textarea:focus { outline: 2px solid var(--red-soft); border-color: var(--red); }
.tpl-form textarea { line-height: 1.7; resize: vertical; font-family: "仿宋", fangsong, serif; }
.tpl-form-row { display: flex; gap: 10px; }
.tpl-form-row label { flex: 1; }

/* ============ 弹窗 ============ */
.modal-mask { position: fixed; inset: 0; background: rgba(60, 20, 15, .45); z-index: 100; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 16px; padding: 22px 24px; width: min(560px, 92vw); max-height: 86vh; overflow: auto; box-shadow: 0 16px 50px rgba(60,20,15,.35); animation: pop .18s ease; }
@keyframes pop { from { transform: scale(.94); opacity: 0;} to { transform: scale(1); opacity: 1;} }
.modal h3 { color: var(--red-deep); margin-bottom: 14px; font-size: 17px; }
.modal .modal-ops { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ============ 全屏预览 ============ */
.preview-mask { position: fixed; inset: 0; background: #5c4c44; z-index: 120; overflow-y: auto; overflow-x: hidden; }
.pv-topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; background: rgba(52, 36, 30, .95); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.3); }
.pv-title { font-size: 15px; font-weight: 600; }
.pv-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pv-count { font-size: 12.5px; color: #e6d5cb; background: rgba(255,255,255,.12); border-radius: 20px; padding: 3px 10px; }
.pv-body { padding: 18px 10px 70px; }
.pv-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pv-page-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 100%; }
.pv-page { background: #fff; box-shadow: 0 6px 22px rgba(0,0,0,.35); overflow: hidden; border-radius: 2px; line-height: 0; }
.pv-page img { display: block; width: 100%; height: 100%; }
.pv-pageno { font-size: 12px; color: #cdbab0; letter-spacing: .5px; }
.pv-loading, .pv-error { color: #f0e2da; font-size: 14px; padding: 46px 20px; text-align: center; line-height: 2; display: flex; align-items: center; justify-content: center; gap: 10px; }
.pv-spin { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; animation: pvspin .8s linear infinite; }
@keyframes pvspin { to { transform: rotate(360deg); } }

/* ============ toast ============ */
.toast { position: fixed; top: 74px; left: 50%; transform: translateX(-50%) translateY(-12px); background: rgba(43, 43, 43, .92); color: #fff; padding: 10px 22px; border-radius: 24px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 200; max-width: 80vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { background: rgba(30, 126, 52, .95); }
.toast.err { background: rgba(178, 59, 46, .95); }

/* ============ 登录页 ============ */
.login-mask { position: fixed; inset: 0; z-index: 9999; background: linear-gradient(160deg, #8f1d15 0%, #c0392b 55%, #a83228 100%); display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fff; border-radius: 18px; padding: 34px 36px 26px; width: 380px; max-width: 100%; box-shadow: 0 24px 60px rgba(60,10,5,.45); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-logo { width: 62px; height: 62px; margin: 0 auto 2px; display: block; }
.login-title { font-size: 20px; font-weight: 800; color: var(--red-deep); letter-spacing: 1px; }
.login-sub { font-size: 12.5px; color: #9a867c; margin-bottom: 12px; }
.login-input { border: 1px solid #e5d8cf; border-radius: 10px; padding: 12px 14px; font-size: 15px; font-family: inherit; background: #faf6f2; }
.login-input:focus { outline: 2px solid var(--red-soft); border-color: var(--red); background: #fff; }
.login-err { background: #fdecea; color: #b02a22; font-size: 13px; border-radius: 8px; padding: 8px 10px; }
.login-btn { border: none; border-radius: 10px; background: var(--red); color: #fff; font-size: 16px; font-weight: 700; letter-spacing: 6px; padding: 12px; cursor: pointer; transition: all .15s; margin-top: 4px; }
.login-btn:hover { background: var(--red-deep); }
.login-tip { font-size: 12px; color: #b3a099; }

.role-badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 20px; background: #eef2ee; color: #3c7a3c; margin-left: 6px; vertical-align: 1px; }
.role-badge.admin { background: #fdecea; color: #b02a22; }
.role-badge.super { background: linear-gradient(120deg, #8a1420, #c0392b); color: #fff; }
.user-ops { white-space: nowrap; }
.user-ops .btn { margin-right: 4px; }
.st-badge { display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 8px; }
.st-badge.on { background: #e5f5e9; color: #1e7e34; }
.st-badge.off { background: #f4e9e7; color: #a8453a; }
tr.row-off > td { opacity: .6; }
tr.row-off > td:last-child { opacity: 1; }
.btn-warn { background: #fff; border: 1px solid #e0b98a; color: #a2621a; }
.btn-warn:hover { background: #fdf6ec; }
.tag.own-none { background: #f3efe9; color: #8a7767; border: 1px dashed #d9cbbd; }

/* ============ 移动端 ============ */
@media (max-width: 980px) {
  .topbar { padding: 0 12px; }
  .brand-name { font-size: 13.5px; }
  .brand-sub { display: none; }
  .logo { width: 34px; height: 34px; }
  .user-chip { padding: 5px 9px; font-size: 12px; max-width: 104px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .actionbar { top: 56px; padding: 7px 10px; gap: 8px; }
  .ab-tab { padding: 7px 10px; font-size: 13px; }
  .ab-ops { width: 100%; margin-left: 0; gap: 6px; }
  .ab-ops .btn { padding: 8px 11px; font-size: 13px; flex: 1 1 auto; justify-content: center; }
  .ab-ops .sel { flex: 1 1 100%; max-width: none; }
  .fmtbar { top: 148px; padding: 7px 10px; gap: 5px; }
  .fmtbar-label { width: 100%; margin: 0 0 2px; }
  .ib-cap { width: 100%; }
  .db-inner { padding: 8px 10px; gap: 6px; }
  .db-label { display: none; }
  .dockbar select { flex: 1 1 30%; min-width: 0; max-width: none; }
  .dockbar .btn { flex: 1 1 auto; justify-content: center; }
  .paper-stage { padding: 8px 6px 40px; min-height: auto; background: #ece5da; }
  .paper-scale { width: 100%; transform: none !important; height: auto !important; }
  .paper { width: 100%; min-height: auto; padding: 34px 18px 30px; }
  .paper.editable .blk-del { right: 0; }
  .doc-version { position: static; margin-top: 14px; }
  .main > .view:not(#view-compose) { padding: 14px 12px; }
  .search { width: 100%; }
  .modal { width: 96vw; padding: 14px 10px; max-height: 94vh; }
  .modal h3 { font-size: 15.5px; }
  .pv-body { padding: 12px 4px 60px; }
  .tpl-form-row { flex-direction: column; }
}

/* ============ 桌面端固定悬浮三条 ============ */
@media (min-width: 981px) {
  .topbar { position: fixed; top: 0; left: 0; right: 0; }
  .actionbar { position: fixed; top: 60px; left: 0; right: 0; }
  .fmtbar { position: fixed; top: var(--head-h, 116px); left: 0; right: 0; }
  body { padding-top: var(--head-h, 116px); }
  body.with-dock .layout { padding-top: var(--fmtbar-h, 42px); }
}

/* ============ 打印 ============ */
#printHolder { display: none; }
@media print {
  body { background: #fff; padding: 0 !important; }
  .topbar, .actionbar, .fmtbar, .dockbar, .mobile-dock, .compose-meta, .paper-tip, .toast, .modal-mask, .boot-mask, .preview-mask { display: none !important; }
  .paper-stage { padding: 0 !important; background: #fff !important; overflow: visible !important; }
  .paper-scale { transform: none !important; height: auto !important; }
  .paper { box-shadow: none !important; margin: 0 !important; }
  .paper.editable .eb { border-bottom: none !important; background: none !important; }
  .paper.editable .eb.empty-hint::before, .paper.editable .eb[data-ph]:empty::before { content: "" !important; }
  .paper.editable .doc-img-cap[contenteditable]:empty::before { content: "" !important; }
  .blk-del, .img-handle, .img-badge { display: none !important; }
  .page-guides { display: none !important; }
  .paper.editable.paged { background: #fff !important; box-shadow: none !important; }
  .paper.editable .img-inner { outline: none !important; }
  @page { size: A4 portrait; margin: 0; }
  /* 通过 #printHolder 打印时：只输出该副本 */
  body.printing > *:not(#printHolder) { display: none !important; }
  body.printing #printHolder { display: block !important; padding: 0 !important; }
  body.printing #printHolder .paper { box-shadow: none !important; margin: 0 !important; }
}

/* =========================================================
   新公文编辑器 · 补充样式
   （命名与旧版界面不同但视觉沿用同一套设计变量）
   ========================================================= */

/* ---- 弹窗结构 ---- */
.modal-title { color: var(--red-deep); margin-bottom: 14px; font-size: 17px; font-weight: 700; }
.modal-body { font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* 表单字段：与旧 .f-field 等价 */
.fld { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.fld > span { font-size: 12.5px; color: var(--muted); }
.fld input, .fld textarea, .fld select {
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px;
  outline: none; background: #fffdfb; transition: border .15s; width: 100%; resize: vertical;
}
.fld input:focus, .fld textarea:focus, .fld select:focus {
  border-color: var(--red); box-shadow: 0 0 0 3px rgba(166,27,41,.07);
}

/* ---- 简报卡片 ---- */
.doc-card .dc-main { min-width: 0; flex: 1; }
.doc-card .dc-ops { display: flex; gap: 6px; align-items: flex-start; flex-shrink: 0; }

/* ---- 操作日志 ---- */
.log-item .log-time { color: #b0a49c; white-space: nowrap; }
.log-item .log-act { color: var(--red); font-weight: 600; white-space: nowrap; }
.log-item .log-title { color: var(--ink); font-weight: 600; }
.log-item .log-detail { color: #6d5a52; flex: 1; min-width: 0; }
.log-item .log-user { color: #b0a49c; white-space: nowrap; margin-left: auto; }

/* ---- 模板卡片 ---- */
.tpl-cat {
  display: inline-block; font-size: 11.5px; color: var(--red); background: var(--red-soft);
  border-radius: 20px; padding: 2px 9px; margin-bottom: 7px;
}
.tpl-descr {
  font-size: 12.5px; color: var(--muted); line-height: 1.55; margin-bottom: 10px; min-height: 38px;
}

/* ---- 编辑器内部细节 ---- */
.doc-org-name { display: inline; }
.img-ph-box { display: block; }

/* ---- 离屏渲染容器：与编辑纸张完全同宽同底色，保证测量与像素一致 ---- */
.offscreen-paper { position: fixed; left: -100000px; top: 0; width: 210mm; background: #fff; z-index: -1; }
.offscreen-paper .paper { margin: 0; box-shadow: none; }
/* 离屏容器内不显示任何仅编辑态存在的交互标记 */
.offscreen-paper .img-handle, .offscreen-paper .img-badge,
.offscreen-paper .blk-del, .offscreen-paper .page-guides { display: none !important; }

/* ---- PDF 预览层 ---- */
.pdf-preview-layer { position: fixed; inset: 0; z-index: 120; }

/* ---- 页面边界标记（导出时的真实分页位置） ---- */
.page-guides .pg-bound { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(43,125,233,.5); }

/* 并排行内单图：间距由行容器统一提供，单图不再自带外边距 */
.doc-img-row-single .doc-img-block { margin: 0 !important; }

/* 分页视图：每页一张真实 A4 底衬，页码位置与 PDF stampPageNo 规则一致 */
.paper.editable.paged .page-guides .pg-sheet { position: absolute; left: 0; right: 0; background: #fff; border-radius: 2px; box-shadow: 0 3px 12px rgba(80,40,30,.16); }
.paper.editable.paged .page-guides .pg-no {
  position: absolute; bottom: 4mm; font-family: "宋体页码", "SimSun", serif;
  font-size: 14pt; line-height: 1; color: #000; letter-spacing: 0; white-space: nowrap;
}
.paper.editable.paged .page-guides .pg-no.odd { right: 5mm; }
.paper.editable.paged .page-guides .pg-no.even { left: 5mm; }
.paper.editable.paged .page-guides .pg-bound { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(43,125,233,.55); z-index: 1; }
