/* ============ 打印层：高清 PDF 导出 ============
   导出路径是 window.print() → 「另存为 PDF」。
   浏览器在此路径下会把文字写成带嵌入字体的文本对象，
   因此 PDF 天然可选中/可复制，可被 ATS 完整解析。
   本文件只负责把「屏幕上的缩放外壳」剥掉，让浏览器按真实 A4 尺寸分页。
============================================== */

@page {
  size: A4;
  margin: 0;
}

@media print {
  /* base.css 把 html/body 设成了 height:100%（屏幕上是撑满视口用的）。
     打印时这会变成「只有一页高」，多页简历溢出的部分会被直接丢掉 ——
     实测 4 页内容只输出 1 页，且看不出任何异常。必须改回 auto。 */
  html, body {
    background: #fff !important;
    width: 210mm;
    height: auto !important;
    min-height: 0 !important;
  }
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* 隐藏一切非简历内容 */
  .appbar, .bottombar, .tpl-bar, .side-panel, .autosave, .toasts,
  .modal-mask, .preview-head, .no-print, .auth-page > footer {
    display: none !important;
  }

  .page, .preview-shell, .wrap, .editor-shell { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .preview-canvas {
    border: 0 !important; padding: 0 !important; max-height: none !important;
    overflow: visible !important; display: block !important; background: #fff !important;
    border-radius: 0 !important;
  }
  .preview-stage { display: block !important; }

  /* 真分页：屏幕上的画布让位，改打「分页器产出的每一页」。
     每页都是独立容器（自带 210×297 与模板 padding），所以上下留白天然成立，
     不再依赖 @page 边距 + 位移模拟。 */
  .preview-stage[data-paged="1"] .preview-canvas { display: none !important; }
  .preview-stage[data-paged="1"] .print-stage { display: block !important; }
  /* 高度必须比 A4 少 1px。297mm 换算成 px 是 1122.52，Chromium 布局取整到 1123，
     于是每张纸都比页框高 0.5px —— 浏览器会给每页后面再吐一张空白页，
     PDF 的页数正好翻倍，而屏幕预览完全正常（这就是「PDF 和屏幕对不上」的来源）。 */
  .print-page {
    width: 210mm !important; height: calc(297mm - 1px) !important;
    /* min-height 也要压掉：.cv-page 上的 min-height:297mm 会盖过 height */
    min-height: 0 !important;
    overflow: hidden !important;
    box-shadow: none !important;
    break-after: page; page-break-after: always;
  }
  .print-page:last-child { break-after: auto; page-break-after: auto; }

  /* .cv-root 必须保持 static：一旦成为定位上下文，侧栏底色条
     （position:absolute; top:0; bottom:0）就锚到「内容高度」而不是「纸张高度」，
     续页灰栏只剩一截。下面的 .print-page 才是定位上下文。 */
  .paper-frame { overflow: visible !important; height: auto !important; }
  .page-tabs { display: none !important; }

  /* 剥掉屏幕上为了自适应而做的容器缩放，按真实 A4 尺寸输出。
     box-shadow 必须清掉：屏幕上的纸张投影挂 .paper-frame，打印会变成一圈灰边 */
  .paper-frame {
    position: static !important;
    width: auto !important;
    height: auto !important;
    transform: none !important;
    box-shadow: none !important;
  }
  .cv-page {
    position: static !important;
    width: 210mm !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: 0 !important;
    transform: none !important;
  }
  /* 同上：少 1px，避免「一页内容 → 两页 PDF（第 2 页空白）」
     min-height 必须一起压掉：.cv-page 的 min-height:297mm 会把高度撑回 1122.52。
     position: relative 让绝对定位的装饰底色条锚在纸上（铺满整页）。 */
  .cv-page.is-singlepage {
    height: calc(297mm - 1px) !important;
    min-height: 0 !important;
    position: relative !important;
  }
  /* 屏幕层给单页底板设了 min-height:297mm（1122.52px），比这张纸高 1px。
     按同一口径压到 calc(297mm - 1px)，避免多出的 1px 触发空白页。
     绝对定位不占文档流，本来也不会撑高纸，这里只是把数值对齐。 */
  .cv-page.is-singlepage .dual-bg,
  .cv-page.is-singlepage .tk-bg,
  .cv-page.is-singlepage .fo-bg,
  .cv-page.is-singlepage .gr-bg { min-height: calc(297mm - 1px) !important; }
  .cv-page.is-multipage { min-height: 0 !important; }

  /* 分页器产出的每一页都要自成一张纸的定位上下文。
     侧栏底色（.dual-bg / .tk-bg / .gr-bg）是 position:absolute; top:0; bottom:0，
     没有定位祖先时它会去挂到页面根上，于是第 2 页的灰栏只有一截短条。
     选择器带 .print-stage 是为了压过上面 .cv-page { position: static }。 */
  .print-stage .print-page {
    position: relative !important;
    min-height: 0 !important;
  }
  /* 但装饰条真正的定位祖先是 .cv-root（app.css 里它带 position:relative），
     而 .cv-root 的高度只等于内容高度 —— 内容短的那一页，底色还是到不了纸底。
     让分页后的 .cv-root 撑满整张纸，屏幕上与打印出来的效果才对得上。 */
  .print-stage .print-page > .cv-root { height: 100%; }

  a { text-decoration: none !important; }
  .folio-link { border-color: #ddd7f3 !important; }
}
