/**
 * 打印样式优化。
 *
 * 针对文章页面的打印输出进行优化：
 * - 隐藏导航、侧栏、评论等非内容元素
 * - 优化正文排版以适应纸张
 * - 显示链接地址便于离线查阅
 * - 移除背景色和装饰性元素节省墨水
 */
@media print {
    /* ========================================================================
     * 全局打印设置
     * ======================================================================== */

    /* 基础页面设置：A4 纸张，合适的边距 */
    @page {
        size: A4;
        margin: 2cm 1.5cm;
    }

    /* 重置背景和颜色，节省墨水 */
    *,
    *::before,
    *::after {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* 基础字体设置 */
    body {
        font-family: "Songti SC", "SimSun", "Times New Roman", serif;
        font-size: 12pt;
        line-height: 1.6;
    }

    /* ========================================================================
     * 隐藏非打印元素
     * ======================================================================== */

    /* 导航和头部 */
    .portal-header,
    .portal-nav-toggle,
    .portal-nav,
    .portal-back-link {
        display: none !important;
    }

    /* 侧边栏 */
    .portal-sidebar,
    .portal-sidebar-card {
        display: none !important;
    }

    /* 页脚 */
    .portal-footer {
        display: none !important;
    }

    /* Banner 区域（保留标题，隐藏装饰） */
    .portal-banner {
        background: none !important;
        padding: 0 !important;
        margin-bottom: 1cm !important;
        min-height: auto !important;
    }
    .portal-banner__eyebrow {
        display: none !important;
    }
    .portal-banner p {
        display: none !important;
    }

    /* 交互元素 */
    .portal-share,
    .portal-share-float,
    .portal-article-nav,
    .portal-comments-section,
    .portal-btn,
    button,
    .portal-search {
        display: none !important;
    }

    /* 浮动元素和固定定位 */
    .portal-reading-progress,
    .portal-page-progress,
    [style*="position: fixed"],
    [style*="position:fixed"] {
        display: none !important;
    }

    /* 懒加载占位符 */
    .lazy-placeholder,
    .skeleton {
        display: none !important;
    }

    /* ========================================================================
     * 内容区域优化
     * ======================================================================== */

    /* 主内容区全宽显示 */
    .portal-main,
    .portal-section,
    .portal-container,
    .portal-layout,
    .portal-content,
    .portal-article {
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
    }

    /* 文章标题 */
    .portal-article-header h1,
    .portal-banner h1 {
        font-size: 18pt !important;
        font-weight: bold !important;
        margin-bottom: 0.5cm !important;
        page-break-after: avoid;
    }

    /* 文章元信息 */
    .portal-article-meta {
        font-size: 10pt !important;
        color: #666 !important;
        margin-bottom: 0.5cm !important;
        border-bottom: 1px solid #ccc !important;
        padding-bottom: 0.3cm !important;
    }

    /* 文章正文 */
    .portal-article-content {
        font-size: 12pt !important;
        line-height: 1.8 !important;
    }

    /* 段落间距 */
    .portal-article-content p {
        margin-bottom: 0.5cm !important;
        orphans: 3;
        widows: 3;
    }

    /* 标题样式 */
    .portal-article-content h1,
    .portal-article-content h2,
    .portal-article-content h3,
    .portal-article-content h4,
    .portal-article-content h5,
    .portal-article-content h6 {
        page-break-after: avoid;
        page-break-inside: avoid;
        margin-top: 0.8cm !important;
        margin-bottom: 0.3cm !important;
    }

    .portal-article-content h2 {
        font-size: 16pt !important;
        border-bottom: 1px solid #ccc !important;
        padding-bottom: 0.2cm !important;
    }

    .portal-article-content h3 {
        font-size: 14pt !important;
    }

    .portal-article-content h4 {
        font-size: 12pt !important;
    }

    /* ========================================================================
     * 链接处理
     * ======================================================================== */

    /* 链接样式 */
    a {
        color: #000 !important;
        text-decoration: underline !important;
    }

    /* 在链接后显示 URL（仅外部链接） */
    .portal-article-content a[href^="http"]:not([href*="javascript"])::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666 !important;
        word-break: break-all;
    }

    /* 内部锚点链接不显示 URL */
    .portal-article-content a[href^="#"]::after {
        content: none;
    }

    /* ========================================================================
     * 图片处理
     * ======================================================================== */

    /* 图片基础设置 */
    img {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
    }

    /* 文章封面 */
    .portal-article-cover {
        margin-bottom: 0.5cm !important;
        text-align: center;
    }

    .portal-article-cover img {
        max-height: 8cm !important;
        width: auto !important;
    }

    /* 内容图片 */
    .portal-article-content img {
        display: block;
        margin: 0.5cm auto !important;
        max-height: 12cm !important;
    }

    /* 图片说明 */
    figure {
        margin: 0.5cm 0 !important;
        page-break-inside: avoid;
    }

    figcaption {
        font-size: 10pt !important;
        font-style: italic;
        text-align: center;
        margin-top: 0.2cm !important;
    }

    /* ========================================================================
     * 代码块处理
     * ======================================================================== */

    /* 代码块：保留边框便于识别 */
    pre,
    code {
        font-family: "Courier New", Courier, monospace !important;
        font-size: 10pt !important;
    }

    pre {
        border: 1px solid #ccc !important;
        padding: 0.3cm !important;
        margin: 0.5cm 0 !important;
        overflow-x: visible !important;
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        page-break-inside: avoid;
    }

    code {
        background: #f5f5f5 !important;
        padding: 0 0.1cm !important;
    }

    /* ========================================================================
     * 引用和列表
     * ======================================================================== */

    /* 引用块 */
    blockquote {
        border-left: 3px solid #666 !important;
        margin: 0.5cm 0 !important;
        padding-left: 0.5cm !important;
        font-style: italic;
        page-break-inside: avoid;
    }

    /* 列表 */
    ul, ol {
        margin: 0.3cm 0 !important;
        padding-left: 1cm !important;
    }

    li {
        margin-bottom: 0.2cm !important;
    }

    /* ========================================================================
     * 表格处理
     * ======================================================================== */

    table {
        border-collapse: collapse !important;
        width: 100% !important;
        margin: 0.5cm 0 !important;
        font-size: 10pt !important;
        page-break-inside: avoid;
    }

    th, td {
        border: 1px solid #666 !important;
        padding: 0.2cm !important;
        text-align: left;
    }

    th {
        font-weight: bold !important;
    }

    thead {
        display: table-header-group;
    }

    tr {
        page-break-inside: avoid;
    }

    /* ========================================================================
     * 分页控制
     * ======================================================================== */

    /* 避免在这些元素内分页 */
    .portal-article-header,
    .portal-article-cover,
    .portal-article-footer {
        page-break-inside: avoid;
    }

    /* 文章标签（打印时显示为文本） */
    .portal-article-tags {
        font-size: 10pt !important;
        margin-top: 0.5cm !important;
        padding-top: 0.3cm !important;
        border-top: 1px solid #ccc !important;
    }

    .portal-article-tags a {
        text-decoration: none !important;
    }

    .portal-article-tags a::after {
        content: none !important;
    }

    /* ========================================================================
     * 打印页脚信息
     * ======================================================================== */

    /* 在文章末尾添加来源信息 */
    .portal-article-content::after {
        content: "本文打印自：" attr(data-print-url);
        display: block;
        margin-top: 1cm;
        padding-top: 0.3cm;
        border-top: 1px solid #ccc;
        font-size: 9pt;
        color: #666 !important;
    }
}
