/* ============================================================
   PDF Export Print Styles
   Purpose: Optimize book rendering for PDF export via Puppeteer
   Principles:
   - Maintain A4 standard (210mm × 297mm)
   - Preserve ReaderProse aesthetics
   - Hide navigation & interactive elements
   ============================================================ */

@media print {
    /* ====================================
       1. Hide Non-Content Elements
       ==================================== */
    
    nav,
    .navbar,
    .sidebar,
    .toc-sidebar,
    .ai-butler,
    .ai-butler-toggle,
    .table-of-contents-toggle,
    .chapter-navigation,
    .back-to-top,
    footer,
    .share-buttons,
    .comment-section,
    .sticky-header,
    button:not(.print-keep) {
        display: none !important;
    }
    
    /* ====================================
       2. Page Setup (A4 Standard)
       ==================================== */
    
    @page {
        size: A4 portrait;
        margin: 2cm 1.5cm 2cm 1.5cm;
    }
    
    /* First page (cover) - no margin */
    @page :first {
        margin: 0;
    }
    
    /* ====================================
       3. Cover Page Optimization
       ==================================== */
    
    .book-cover,
    .cover-page {
        page-break-after: always;
        width: 21cm;
        height: 29.7cm;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: white;
    }
    
    .book-cover img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }
    
    /* ====================================
       4. Chapter Pagination
       ==================================== */
    
    .chapter,
    article[data-chapter] {
        page-break-before: always;
        page-break-after: always;
    }
    
    /* Chapter title - prevent orphan */
    .chapter h1,
    .chapter-title {
        page-break-after: avoid;
        margin-top: 0;
    }
    
    /* ====================================
       5. Typography Optimization
       ==================================== */
    
    /* Prevent widows & orphans */
    p,
    li {
        orphans: 3;
        widows: 3;
    }
    
    /* Avoid breaking inside elements */
    pre,
    blockquote,
    table,
    figure,
    .code-block,
    .callout {
        page-break-inside: avoid;
    }
    
    /* Headings - keep with following content */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
        page-break-inside: avoid;
    }
    
    /* ====================================
       6. ReaderProse Print Adjustments
       ==================================== */
    
    .reader-prose {
        font-size: 11pt;
        line-height: 1.7;
        color: #000;
        background: white;
    }
    
    .reader-prose h1 {
        font-size: 20pt;
        font-weight: 700;
        margin-top: 1.5em;
        margin-bottom: 0.75em;
    }
    
    .reader-prose h2 {
        font-size: 16pt;
        font-weight: 600;
        margin-top: 1.25em;
        margin-bottom: 0.5em;
    }
    
    .reader-prose h3 {
        font-size: 13pt;
        font-weight: 600;
    }
    
    .reader-prose p {
        margin-bottom: 0.75em;
    }
    
    .reader-prose a {
        color: #000;
        text-decoration: underline;
    }
    
    /* Show link URLs in footnote style */
    .reader-prose a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666;
    }
    
    /* ====================================
       7. Code Blocks
       ==================================== */
    
    .reader-prose pre {
        background: #f5f5f5;
        border: 1px solid #ddd;
        padding: 0.75em;
        border-radius: 4px;
        font-size: 9pt;
        line-height: 1.4;
        overflow-x: visible;
        word-wrap: break-word;
    }
    
    .reader-prose code {
        background: #f5f5f5;
        padding: 0.2em 0.4em;
        border-radius: 3px;
        font-size: 10pt;
    }
    
    /* ====================================
       8. Lists
       ==================================== */
    
    .reader-prose ul,
    .reader-prose ol {
        margin-left: 1.5em;
        margin-bottom: 0.75em;
    }
    
    .reader-prose li {
        margin-bottom: 0.25em;
    }
    
    /* ====================================
       9. Blockquotes
       ==================================== */
    
    .reader-prose blockquote {
        border-left: 3px solid #333;
        padding-left: 1em;
        margin-left: 0;
        margin-right: 0;
        font-style: italic;
        color: #333;
    }
    
    /* ====================================
       10. Tables
       ==================================== */
    
    .reader-prose table {
        border-collapse: collapse;
        width: 100%;
        font-size: 10pt;
    }
    
    .reader-prose th,
    .reader-prose td {
        border: 1px solid #ddd;
        padding: 0.5em;
        text-align: left;
    }
    
    .reader-prose th {
        background: #f5f5f5;
        font-weight: 600;
    }
    
    /* ====================================
       11. Images
       ==================================== */
    
    .reader-prose img {
        max-width: 100%;
        height: auto;
        page-break-inside: avoid;
    }
    
    .reader-prose figure {
        margin: 1em 0;
        text-align: center;
    }
    
    .reader-prose figcaption {
        font-size: 9pt;
        color: #666;
        margin-top: 0.5em;
    }
    
    /* ====================================
       12. Page Numbers (Optional)
       ==================================== */
    
    @page {
        @bottom-center {
            content: counter(page);
            font-size: 9pt;
            color: #666;
        }
    }
    
    /* ====================================
       13. Print-Specific Utilities
       ==================================== */
    
    .print-only {
        display: block !important;
    }
    
    .screen-only {
        display: none !important;
    }
    
    /* Force color printing for essential elements */
    .book-cover,
    .chapter-cover {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================================
   End of Print Styles
   ============================================================ */
