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

#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 {
}

h2 {
    page-break-before: auto;
}

h1 {
    page-break-before: avoid;
}

pre, code {
    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 {
    max-width: 100% !important;
    height: auto !important;
}

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

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

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

table {
    width: 100% !important;
    border-collapse: collapse !important;
}

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

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

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

/* 二级标题前添加分页（每个植物单独一页） */
h2 {
    page-break-before: always;
}

/* h1前不添加分页 */
h1 {
    page-break-before: avoid;
}

/* 首页内容和主标题区域不被分页分割 */
.content > .card-control:first-of-type {
    page-break-inside: avoid;
}
.content > .card-control:nth-of-type(2) {
    page-break-inside: avoid;
    page-break-after: always;
}

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

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

@media print {
    html, body {
        background: white !important;
        color: black !important;
        height: auto !important;
        min-height: auto !important;
    }

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

    /* 重置页面包装器和页头的顶部间距 */
    .page-wrapper,
    .page,
    header {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }

    /* 隐藏顶部导航栏（打印时不需要） */
    .top-nav {
        display: none !important;
    }

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

    /* ====== 植物介绍部分应用紧凑格式 ====== */
    /* 植物介绍区域的字体和行间距 */
    .feature-card-group,
    .feature-card-group ~ * {
        font-size: 11px !important;
        line-height: 1.3 !important;
    }

    /* 植物介绍区域的标题间距 */
    .feature-card-group ~ * h1,
    .feature-card-group ~ * h2,
    .feature-card-group ~ * h3 {
        margin-top: 8px !important;
        margin-bottom: 6px !important;
        line-height: 1.2 !important;
    }

    .feature-card-group ~ * h1 {
        font-size: 18px !important;
    }

    .feature-card-group ~ * h2 {
        font-size: 15px !important;
        padding-bottom: 4px !important;
    }

    .feature-card-group ~ * h3 {
        font-size: 13px !important;
    }

    /* 首页三级标题与段落之间的间距缩小一半 */
    h3 {
        margin-top: 0.5em !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;
    }
    
    /* 确保主标题区域的 flex 布局在打印时生效 */
    .card-control[style*="display: flex"] {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 24px !important;
    }
    
    /* 确保内联宽度样式在打印时生效 */
    .card-control[style*="display: flex"] .card.chart-card[style*="width"] {
        max-width: none !important;
        min-width: 0 !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:last-of-type {
        margin-bottom: 10mm !important;
    }

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

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