/**
 * Football Analytics Textbook - Print Styles
 * Optimized styling for printing chapters
 */

@media print {
    /* Reset and Basic Layout */
    * {
        background: transparent !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    body {
        font-size: 11pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }

    /* Hide non-printable elements */
    .sidebar,
    .chapter-nav,
    footer,
    .progress-container,
    .progress-controls,
    .chapter-checkbox,
    .interactive-tool,
    .completion-celebration,
    .mobile-header,
    .mobile-nav-bottom,
    .hamburger-menu,
    button,
    input[type="range"],
    .calculator-controls,
    nav,
    .nav-tabs {
        display: none !important;
    }

    /* Main content takes full width */
    .container {
        display: block;
        width: 100%;
    }

    .main-content {
        margin: 0;
        padding: 0;
        max-width: 100%;
        width: 100%;
    }

    /* Page setup */
    @page {
        margin: 2cm 1.5cm;
        size: letter;
    }

    @page :first {
        margin-top: 1cm;
    }

    /* Running header with chapter title */
    @page :left {
        @top-left {
            content: "Football Analytics Textbook";
            font-size: 9pt;
            font-style: italic;
            color: #666;
        }
    }

    @page :right {
        @top-right {
            content: string(chapter-title);
            font-size: 9pt;
            font-style: italic;
            color: #666;
        }
    }

    /* Page numbers in footer */
    @page {
        @bottom-center {
            content: "Page " counter(page);
            font-size: 9pt;
            color: #666;
        }
    }

    /* Chapter title for running header */
    h1 {
        string-set: chapter-title content();
    }

    /* Typography */
    h1 {
        font-size: 24pt;
        font-weight: bold;
        color: #000;
        margin-bottom: 12pt;
        margin-top: 0;
        page-break-after: avoid;
        orphans: 4;
    }

    h2 {
        font-size: 18pt;
        font-weight: bold;
        color: #000;
        margin-top: 18pt;
        margin-bottom: 9pt;
        page-break-after: avoid;
        orphans: 4;
        border-bottom: 1pt solid #000;
        padding-bottom: 3pt;
    }

    h3 {
        font-size: 14pt;
        font-weight: bold;
        color: #000;
        margin-top: 14pt;
        margin-bottom: 7pt;
        page-break-after: avoid;
        orphans: 3;
    }

    h4 {
        font-size: 12pt;
        font-weight: bold;
        color: #000;
        margin-top: 12pt;
        margin-bottom: 6pt;
        page-break-after: avoid;
        orphans: 3;
    }

    h5, h6 {
        font-size: 11pt;
        font-weight: bold;
        color: #000;
        margin-top: 10pt;
        margin-bottom: 5pt;
        page-break-after: avoid;
    }

    /* Paragraphs */
    p {
        margin-bottom: 8pt;
        orphans: 3;
        widows: 3;
        text-align: justify;
        hyphens: auto;
    }

    /* Lists */
    ul, ol {
        margin-bottom: 8pt;
        margin-left: 20pt;
        page-break-inside: avoid;
    }

    li {
        margin-bottom: 4pt;
        orphans: 2;
        widows: 2;
    }

    /* Code blocks - preserve formatting */
    pre {
        background: #f5f5f5 !important;
        border: 1pt solid #ccc !important;
        padding: 8pt;
        font-size: 9pt;
        line-height: 1.4;
        overflow: visible;
        white-space: pre-wrap;
        word-wrap: break-word;
        page-break-inside: avoid;
        margin: 10pt 0;
    }

    code {
        font-family: 'Courier New', Courier, monospace;
        font-size: 9pt;
        background: #f5f5f5 !important;
        padding: 1pt 3pt;
        border: 0.5pt solid #ddd;
        white-space: pre-wrap;
        word-wrap: break-word;
    }

    pre code {
        border: none;
        padding: 0;
        background: transparent !important;
    }

    /* Tables */
    table {
        width: 100%;
        border-collapse: collapse;
        page-break-inside: avoid;
        margin: 10pt 0;
        font-size: 10pt;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    th {
        background: #000 !important;
        color: #fff !important;
        padding: 6pt 8pt;
        text-align: left;
        font-weight: bold;
        border: 1pt solid #000;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    td {
        padding: 5pt 8pt;
        border: 1pt solid #666;
    }

    tr {
        page-break-inside: avoid;
    }

    /* Zebra striping for tables - light gray */
    tr:nth-child(even) td {
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Blockquotes */
    blockquote {
        border-left: 3pt solid #000;
        padding-left: 12pt;
        margin: 10pt 0 10pt 10pt;
        font-style: italic;
        page-break-inside: avoid;
    }

    /* Callout boxes - high contrast for B&W printing */
    .callout {
        border: 2pt solid #000;
        padding: 10pt;
        margin: 10pt 0;
        page-break-inside: avoid;
        background: #fff !important;
    }

    .callout-note {
        border-left: 4pt solid #000;
    }

    .callout-tip {
        border-left: 4pt solid #000;
        border-style: dashed;
    }

    .callout-warning {
        border-left: 4pt solid #000;
        border-style: double;
    }

    .callout-important {
        border: 3pt solid #000;
        font-weight: bold;
    }

    .callout::before {
        font-weight: bold;
        text-transform: uppercase;
        display: block;
        margin-bottom: 5pt;
    }

    .callout-note::before {
        content: "NOTE: ";
    }

    .callout-tip::before {
        content: "TIP: ";
    }

    .callout-warning::before {
        content: "WARNING: ";
    }

    .callout-important::before {
        content: "IMPORTANT: ";
    }

    /* Links - show URL for external links */
    a {
        color: #000;
        text-decoration: underline;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        font-style: italic;
        word-wrap: break-word;
    }

    /* Don't show URLs for internal chapter links */
    a[href^="chapter"]::after,
    a[href^="#"]::after {
        content: "";
    }

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

    figure {
        page-break-inside: avoid;
        margin: 10pt 0;
    }

    figcaption {
        font-size: 10pt;
        font-style: italic;
        text-align: center;
        margin-top: 5pt;
    }

    /* Charts and graphs - placeholder text */
    #teamChart::after,
    #wpChart::after,
    .plotly::after {
        content: "[Interactive chart - view online for full visualization]";
        display: block;
        font-style: italic;
        text-align: center;
        padding: 20pt;
        border: 1pt dashed #666;
        background: #f5f5f5 !important;
    }

    /* Tab content - show all tabs when printing */
    .tab-pane {
        display: block !important;
        page-break-inside: avoid;
        margin-bottom: 15pt;
    }

    .tab-pane::before {
        content: attr(data-tab-title);
        display: block;
        font-weight: bold;
        font-size: 11pt;
        margin-bottom: 8pt;
        padding-bottom: 4pt;
        border-bottom: 1pt solid #666;
    }

    /* Page break helpers */
    .page-break-before {
        page-break-before: always;
    }

    .page-break-after {
        page-break-after: always;
    }

    .no-page-break {
        page-break-inside: avoid;
    }

    /* Section breaks */
    h2 {
        page-break-before: auto;
    }

    h2.major-section {
        page-break-before: always;
        margin-top: 0;
    }

    /* Ensure important content stays together */
    .keep-together {
        page-break-inside: avoid;
    }

    /* Mathematical equations */
    .MathJax,
    .MathJax_Display {
        page-break-inside: avoid;
        font-size: 11pt !important;
    }

    /* Definition lists */
    dl {
        margin-bottom: 10pt;
    }

    dt {
        font-weight: bold;
        margin-top: 8pt;
    }

    dd {
        margin-left: 20pt;
        margin-bottom: 6pt;
    }

    /* Horizontal rules */
    hr {
        border: none;
        border-top: 1pt solid #000;
        margin: 15pt 0;
        page-break-after: avoid;
    }

    /* Abbreviations and acronyms */
    abbr[title]::after {
        content: " (" attr(title) ")";
        font-size: 9pt;
    }

    /* Citation and references */
    cite {
        font-style: italic;
    }

    /* Superscript and subscript */
    sup, sub {
        font-size: 8pt;
        line-height: 0;
    }

    /* Print quality adjustments */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Optimize text rendering */
    body {
        text-rendering: optimizeLegibility;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Remove decorative elements */
    .decoration,
    .background-image,
    .gradient {
        display: none !important;
    }

    /* Ensure sufficient contrast */
    .text-light,
    .text-muted {
        color: #333 !important;
    }

    /* Clean up spacing */
    * + h1,
    * + h2,
    * + h3 {
        margin-top: 15pt;
    }

    /* First page special formatting */
    h1:first-of-type {
        margin-top: 0;
        padding-top: 0;
    }

    /* Prevent awkward breaks */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }

    img, table, figure, pre {
        page-break-before: avoid;
    }

    /* Summary boxes */
    .summary,
    .key-points {
        border: 2pt solid #000;
        padding: 10pt;
        margin: 15pt 0;
        page-break-inside: avoid;
        background: #f9f9f9 !important;
    }

    .summary::before {
        content: "SUMMARY";
        display: block;
        font-weight: bold;
        font-size: 11pt;
        margin-bottom: 8pt;
    }

    /* Footnotes */
    .footnote {
        font-size: 9pt;
        border-top: 1pt solid #666;
        margin-top: 15pt;
        padding-top: 8pt;
    }

    /* Chapter metadata */
    .chapter-meta {
        font-size: 10pt;
        color: #666;
        margin-bottom: 15pt;
        padding-bottom: 10pt;
        border-bottom: 1pt solid #ccc;
    }

    /* Ensure good print quality for all content */
    @media print and (color) {
        /* For color printers, maintain some color for clarity */
        th {
            background: #333 !important;
        }

        .callout-note {
            border-left-color: #0066cc !important;
        }

        .callout-tip {
            border-left-color: #4caf50 !important;
        }

        .callout-warning {
            border-left-color: #ff9800 !important;
        }

        .callout-important {
            border-color: #f44336 !important;
        }
    }
}
