@media print {
    /* 最关键：压缩页面物理边距 */
    @page {
        margin: 8mm 12mm 8mm 12mm; /* 上 右 下 左 */
    }

    /* 隐藏侧边栏等 */
    .sidebar-drawer,
    .skip-to-content,
    a.skip-to-content,
    [href="#main-content"],
    .header,
    .mobile-header {
        display: none !important;
    }

    .main-grid {
        display: block !important;
        max-width: 100% !important;
        grid-template-columns: unset !important;
    }

    .content {
        max-width: 100% !important;
        width: 100% !important;
        padding: 0.8rem 1rem !important;
        margin: 0 auto !important;
        min-height: 100vh !important; /* 占满可用高度 */
        box-sizing: border-box !important;
    }

    /* 压紧排版 */
    body {
        font-size: 11pt !important;
        line-height: 1.4 !important;
        color: #000 !important;
    }

    p {
        margin-top: 0.15em !important;
        margin-bottom: 0.3em !important;
    }

    h1, h2, h3, h4, h5, h6 {
        margin-top: 0.4em !important;
        margin-bottom: 0.2em !important;
        line-height: 1.2 !important;
        page-break-after: avoid !important; /* 避免标题后断开 */
    }

    li {
        margin-bottom: 0.05em !important;
    }

    pre, .highlight {
        font-size: 9.5pt !important;
        line-height: 1.2 !important;
        padding: 0.2rem !important;
        margin: 0.3rem 0 !important;
        page-break-inside: avoid !important; /* 防止代码块被截断 */
    }

    table {
        font-size: 10pt !important;
        page-break-inside: avoid !important;
    }

    td, th {
        padding: 0.15rem 0.3rem !important;
    }

    blockquote {
        margin: 0.2rem 1rem !important;
        font-size: 10.5pt !important;
    }

    /* 强制图片不溢出 */
    img {
        max-width: 100% !important;
        page-break-inside: avoid !important;
    }
}
