/* ==========================================================================
 * print.css —— 通用打印样式兼容模板
 * --------------------------------------------------------------------------
 * 引入方式（放在 <head> 最后，确保覆盖其他样式）：
 *   <link rel="stylesheet" href="print.css" media="print">
 *
 * 忽略（不打印）元素的三种方式，任选：
 *   1. 直接给元素加 class="no-print"
 *   2. 给元素加 data-print="ignore"
 *   3. 自动匹配下方选择器里的常见交互元素（导航/按钮/表单等）
 * ========================================================================== */

/* ---------- 1. 纸张设置 ---------- */

/* ---------- 2. 打印基础修正 ---------- */
@media print {

    /* ① 强制打印背景色/背景图（Chrome、Safari 默认不打印背景，最常见坑） */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    html, body {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        color: #000 !important;
        font-size: 12pt;                 /* 打印建议用 pt，避免 px 缩放异常 */
        line-height: 1.5;
        overflow: visible !important;    /* 防止溢出产生空白第二页 */
    }

    /* ② 关掉动画/过渡/阴影/文字阴影，避免卡在初始帧或打印错乱 */
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* ③ 忽略不打印的元素（核心：导航、按钮、表单、弹窗、广告等） */
    .no-print,
    .noprint,
    .print-hidden,
    [data-print="ignore"],
    header, footer, nav, aside,
    .toolbar, .sidebar, .menu, .breadcrumb, .pagination, .pager,
    button, .btn, input, select, textarea,
    .ad, .ads, .banner, .popup, .modal, .cookie, .toast {
        display: none !important;
    }

    /* ④ fixed/sticky 定位打印时只出现在第一页，改为普通流 */
    .fixed, .sticky, [class*="fixed"], [class*="sticky"] {
        position: static !important;
    }

    /* ⑤ 内容铺满纸张，去掉屏幕布局的宽度/边距限制 */
    .container, .wrapper, .content, main, article {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* ⑥ 链接：打印时展示其地址，便于阅读 */
    a {
        color: #000 !important;
        text-decoration: none !important;
    }
    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #555;
        word-break: break-all;
    }

    /* ⑦ 图片/媒体：不溢出纸张，避免被横向截断 */
    img, svg, video, canvas {
        max-width: 100% !important;
        height: auto !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* ---------- 3. 分页控制 ---------- */
    h1, h2, h3, h4, h5, h6 {
        break-after: avoid;        /* 标题后不换页，避免标题单独留在页尾 */
        page-break-after: avoid;
    }

    p, li, blockquote, figure, pre {
        break-inside: avoid;       /* 段落/列表项内部不被打断 */
        page-break-inside: avoid;
    }

    /* 表格：跨页不割裂，并在每页重复表头 */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }
    tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    thead {
        display: table-header-group;   /* 关键：每页顶部自动重复表头 */
    }
    tfoot {
        display: table-footer-group;
    }
    th, td {
        border: 1px solid #999 !important;
        padding: 4px 6px;
        font-size: 10pt;
    }

    /* 需要强制分页 / 避免断页的辅助类 */
    .page-break {
        break-before: page;
        page-break-before: always;
    }
    .avoid-break {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* ---------- 4. 现代布局兼容（Flex / Grid 打印引擎支持差） ---------- */
    /* 布局异常时整体回退为块级流式布局 */
    .print-block, .print-block * {
        display: block !important;
        float: none !important;
    }
    .row, .grid, [class*="flex"], [class*="grid"] {
        display: block !important;
    }

    /* 多列文本打印错位时回退单列 */
    .multi-column {
        column-count: 1 !important;
    }

    /* 溢出内容展开，避免被裁剪 */
    pre, code, .overflow-auto, .overflow-hidden {
        white-space: pre-wrap !important;
        word-break: break-word !important;
        overflow: visible !important;
    }

    /* ---------- 5. 只打印指定区域（可选） ---------- */
    /* 给要打印的容器加 class="print-area"，其余内容全部忽略 */
    body.print-area-only > *:not(.print-area) {
        display: none !important;
    }
}
