/* ========== 基础打印样式重置 ========== */

#mdbook-sidebar,
#mdbook-menu-bar,
header[role="banner"],
.top-nav,
.sidebar,
.nav-chapters,
.mobile-nav-chapters {
    display: none !important;
}

#mdbook-page-wrapper.page-wrapper {
    transform: none !important;
    margin-inline-start: 0px;
    overflow-y: initial;
}

#mdbook-content {
    max-width: none;
    margin: 0;
    padding: 0;
}

.page {
    overflow-y: initial;
}

code {
    direction: ltr !important;
}

pre > .buttons {
    z-index: 2;
}

a, a:visited, a:active, a:hover {
    color: #4183c4;
    text-decoration: none;
}

h1, h2, h3, h4, h5, h6 {
    page-break-inside: avoid;
    page-break-after: avoid;
}

h2 {
    page-break-before: auto;
}

pre, code {
    page-break-inside: avoid;
    white-space: pre-wrap;
}

.fa {
    display: none !important;
}

/* ========== PDF导出防截断设置 ========== */

* {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
}

/* ========== 确保容器不溢出页面 ========== */

.card-control,
.feature-card-group,
.card-in-row,
.intro-three-col {
    max-width: 100% !important;
    width: 100% !important;
    overflow-x: hidden !important;
}

/* ========== 强制保留 flex 布局 ========== */

.card-in-row,
.intro-three-col {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
}

.card-in-row > .card {
    flex: 1 !important;
}

.intro-three-col .col-img,
.intro-three-col .col-text {
    flex: 1 !important;
}

/* ========== 保留高度设置 ========== */

.intro-three-col .col-img img,
.intro-three-col .col-text {
    height: 180px !important;
}

.intro-three-col .col-img img {
    object-fit: cover !important;
}

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

img {
    page-break-inside: avoid;
    page-break-after: avoid;
    max-width: 100% !important;
    height: auto !important;
}

/* ========== 文本处理 ========== */

p,
h1, h2, h3, h4, h5, h6 {
    orphans: 1;
    widows: 1;
}

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

table {
    page-break-inside: avoid;
    width: 100% !important;
    border-collapse: collapse !important;
}

table th,
table td {
    border: 1px solid #ddd !important;
    padding: 4px 6px !important;
    text-align: left !important;
}

/* ========== 列表处理 ========== */

ul, ol {
    page-break-inside: avoid;
}

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

/* 公司介绍部分在主要芳香植物介绍之前结束，后面添加分页 */
.main-title + * {
    page-break-before: always;
}

/* 每个植物介绍（二级标题）之前添加分页 */
.content h2:not(.main-title) {
    page-break-before: always;
}

/* 确保植物介绍内容不被截断到下一页 */
.feature-card-group {
    page-break-inside: avoid;
}

/* 图表卡片不跨页截断 */
.card-control {
    page-break-inside: avoid;
}

/* 参考内容卡片不跨页截断 */
.ref-card {
    page-break-inside: avoid;
}

/* ========== 页面边距和尺寸 ========== */

@page {
    size: A4;
    margin: 12mm;
}

@media print {
    body {
        font-size: 11px !important;
        line-height: 1.3 !important;
        background: white !important;
        color: black !important;
    }

    html {
        background: white !important;
    }

    ::-webkit-scrollbar {
        display: none;
    }

    /* 减小内容区域内边距 */
    .content {
        padding: 8px !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* 减小标题间距 */
    .content h1,
    .content h2,
    .content h3 {
        margin-top: 8px !important;
        margin-bottom: 6px !important;
        line-height: 1.2 !important;
    }

    .content h1 {
        font-size: 18px !important;
    }

    .content h2 {
        font-size: 15px !important;
        padding-bottom: 4px !important;
    }

    .content h3 {
        font-size: 13px !important;
    }

    /* 减小段落间距 */
    .content p {
        margin-bottom: 6px !important;
        line-height: 1.3 !important;
        font-size: 11px !important;
    }

    /* 减小卡片间距 */
    .feature-card-group {
        margin: 4px 0 !important;
    }

    .feature-card-group .card-top,
    .feature-card-group .card-bottom {
        padding: 4px 0 !important;
    }

    /* 减小三列布局高度 */
    .intro-three-col .col-img,
    .intro-three-col .col-text {
        height: 120px !important;
    }

    .intro-three-col .col-img img {
        height: 120px !important;
    }

    /* 减小图表卡片间距 */
    .card-control {
        margin-bottom: 4px !important;
    }

    .card.chart-card {
        padding: 4px !important;
    }

    .chart-title {
        font-size: 12px !important;
        margin-top: 2px !important;
        margin-bottom: 2px !important;
    }

    /* 减小参考内容卡片内边距 */
    .ref-card {
        padding: 8px !important;
        font-size: 10px !important;
    }

    .ref-card p {
        font-size: 10px !important;
        margin-bottom: 4px !important;
    }

    /* 减小图片间距 */
    img {
        margin: 2px 0 !important;
    }

    /* 鼠尾草和香根鸢尾的特殊打印样式 */
    .content .card-control .card.chart-card.small-print {
        width: 38% !important;
        max-width: 38% !important;
        min-width: 0 !important;
        flex-basis: 25% !important;
        -webkit-flex-basis: 25% !important;
    }

    .content .card-control .card.chart-card.small-print img {
        max-width: 100% !important;
        height: auto !important;
    }
}