/* ===================================
   LearningChief - Print Styles
   Matches the official PDF printables
   Clean, minimal, professional design
   =================================== */

@media print {

    /* ===================================
       Hide Interactive UI Elements
       =================================== */
    .header,
    .config-panel,
    .worksheet-toolbar,
    .interactive-panel,
    .tutor-panel,
    .loading-overlay,
    .modal,
    .nav-btn,
    .back-btn,
    .submit-answer-btn,
    .feedback-message {
        display: none !important;
    }

    /* ===================================
       Page Setup - Compact for 5 questions per page
       =================================== */
    @page {
        size: A4;
        margin: 10mm 12mm;
    }

    body {
        background: white !important;
        margin: 0;
        padding: 0;
        font-size: 10pt;
        font-family: 'Nunito', 'Segoe UI', Arial, sans-serif;
        color: #333;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .app-container,
    .main-content,
    .worksheet-section,
    .worksheets-container {
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background: white !important;
        box-shadow: none !important;
        overflow: visible !important;
    }

    /* ===================================
       Worksheet Page - NO forced page breaks
       Let content flow naturally across pages
       =================================== */
    .worksheet-page {
        /* Remove forced page breaks - let content flow naturally */
        page-break-after: auto;
        page-break-before: auto;
        page-break-inside: auto;

        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        margin-bottom: 20px !important;
        overflow: visible !important;
        background: white !important;
    }

    .worksheet-page::before {
        display: none;
    }

    /* ===================================
       Header - LearningChief Style (Compact)
       =================================== */
    .worksheet-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding-bottom: 6px;
        margin-bottom: 12px;
        border-bottom: 2px solid #E6A23C !important;
        background: none !important;
        border-radius: 0 !important;
        border-top: none !important;
        border-left: none !important;
        border-right: none !important;
        page-break-after: avoid;
        break-after: avoid;
    }

    .worksheet-branding {
        display: flex;
        align-items: center;
        gap: 0;
    }

    /* Hide logo in print to match PDF style */
    .worksheet-logo {
        display: none;
    }

    .worksheet-brand-text {
        font-family: 'Quicksand', 'Nunito', Arial, sans-serif;
        font-size: 1.4rem;
        font-weight: 700;
        color: #E6A23C !important;
        text-transform: uppercase;
        letter-spacing: 1px;
    }

    .worksheet-info {
        text-align: right;
    }

    .worksheet-subject {
        font-size: 0.95rem;
        font-weight: 600;
        color: #333;
        display: flex;
        align-items: center;
        gap: 4px;
        justify-content: flex-end;
    }

    /* Hide emoji in print for cleaner look */
    .worksheet-subject span:first-child {
        display: none;
    }

    .worksheet-meta {
        font-size: 0.8rem;
        font-weight: 400;
        color: #666;
        margin-top: 2px;
    }

    /* Header Name Field */
    .header-name-field {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .header-name-field label {
        font-weight: 600;
        color: #333;
        font-size: 0.9rem;
    }

    .header-name-field .line {
        width: 150px;
        border-bottom: 1.5px solid #333;
    }

    /* ===================================
       Worksheet Title Section
       =================================== */
    .worksheet-title-section {
        text-align: center;
        margin-bottom: 12px;
        page-break-after: avoid;
        break-after: avoid;
    }

    .worksheet-title {
        font-family: 'Georgia', 'Times New Roman', serif;
        font-size: 1.6rem;
        font-weight: 400;
        color: #333;
        margin: 0 0 4px 0;
    }

    .worksheet-subtitle {
        font-size: 0.85rem;
        font-style: italic;
        color: #888;
        margin: 0;
    }

    /* ===================================
       Student Info - Name field style
       =================================== */
    .student-info {
        display: flex;
        gap: 24px;
        margin-bottom: 16px;
        padding: 0 !important;
        background: none !important;
        border: none !important;
        border-radius: 0 !important;
        page-break-after: avoid;
        break-after: avoid;
    }

    .student-field {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .student-field label {
        font-weight: 600;
        color: #333;
        font-size: 0.9rem;
    }

    .student-field .line {
        width: 150px;
        border-bottom: 1.5px solid #333;
        height: 1px;
    }

    .student-field .date-line {
        width: 100px;
    }

    /* ===================================
       Worksheet Title Section
       =================================== */
    .worksheet-title {
        text-align: center;
        margin-bottom: 8px;
    }

    .worksheet-title h2 {
        font-family: 'Georgia', 'Times New Roman', serif;
        font-size: 1.8rem;
        font-weight: 400;
        color: #333;
        margin: 0;
    }

    .worksheet-subtitle {
        text-align: center;
        font-size: 0.85rem;
        font-style: italic;
        color: #888;
        margin-bottom: 24px;
    }

    /* ===================================
       Questions Container - Compact spacing
       =================================== */
    .questions-container {
        gap: 0 !important;
        /* Allow questions to flow across pages naturally */
        page-break-inside: auto;
    }

    /* ===================================
       Question Items - Compact box style
       =================================== */
    .question-item {
        display: flex;
        gap: 10px;
        padding: 10px 12px !important;
        margin-bottom: 8px;
        background: white !important;
        border: 1.5px solid #DDD !important;
        border-radius: 4px !important;
        border-left: none !important;

        page-break-inside: avoid !important;
        break-inside: avoid !important;
        orphans: 3;
        widows: 3;
    }

    /* Challenge/Word problem style - dashed orange border */
    .question-item.challenge,
    .question-item.word-problem {
        border: 2px dashed #E6A23C !important;
        border-radius: 8px !important;
        padding: 16px 18px !important;
        margin-top: 20px;
    }

    /* Revision questions - subtle styling */
    .question-item.revision {
        border-color: #E6A23C !important;
        background: #FFFBF5 !important;
    }

    .question-item.revision::after {
        content: 'Revision';
        position: absolute;
        top: -8px;
        right: 12px;
        background: #E6A23C !important;
        color: white !important;
        font-size: 0.6rem;
        font-weight: 700;
        padding: 2px 8px;
        border-radius: 10px;
    }

    /* Question Number - Simple circle */
    .question-number {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 26px;
        height: 26px;
        min-width: 26px;
        background: white !important;
        border: 2px solid #333;
        border-radius: 50%;
        font-family: 'Nunito', Arial, sans-serif;
        font-weight: 700;
        font-size: 0.85rem;
        color: #333;
        flex-shrink: 0;
    }

    /* Question Content */
    .question-content {
        flex: 1;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .question-text {
        font-size: 10pt;
        line-height: 1.5;
        color: #333;
        margin-bottom: 6px;
    }

    .question-text strong {
        font-weight: 700;
        color: #222;
    }

    /* ===================================
       Answer Areas
       =================================== */
    .answer-box {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        margin-top: 8px;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .answer-label {
        font-weight: 600;
        color: #555;
        font-size: 0.9rem;
    }

    .answer-line {
        display: inline-block;
        width: 100px;
        height: 20px;
        min-height: 18px;
        border: none;
        border-bottom: 2px solid #333 !important;
        background: transparent;
        vertical-align: bottom;
    }

    .answer-line.wide {
        width: 120px;
    }

    .answer-line.extra-wide {
        width: 120px;
    }

    .answer-area {
        width: 100%;
        min-height: 60px;
        border: 1.5px solid #CCC;
        border-radius: 4px;
        margin-top: 8px;
    }

    .answer-area.lined {
        background: repeating-linear-gradient(transparent,
                transparent 22px,
                #E5E5E5 22px,
                #E5E5E5 23px) !important;
        min-height: 80px;
    }

    /* ===================================
       Multiple Choice
       =================================== */
    .multiple-choice {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-top: 10px;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .choice-option {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
        background: white !important;
        border: 1.5px solid #DDD !important;
        border-radius: 4px;
    }

    .choice-letter {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        background: white !important;
        border: 1.5px solid #666;
        border-radius: 50%;
        font-weight: 700;
        font-size: 0.8rem;
        color: #333;
    }

    .choice-text {
        color: #333;
        font-size: 10pt;
    }

    /* ===================================
       Visual Elements
       =================================== */
    .question-visual {
        margin: 12px 0;
        padding: 12px;
        background: white !important;
        border: none;
        border-radius: 0;
        text-align: center;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .question-visual svg {
        max-width: 100%;
        height: auto;
    }

    /* Shapes with clean gray borders */
    .shape-item {
        background: white !important;
        border: 1.5px solid #999;
        border-radius: 4px;
        padding: 10px;
    }

    /* Inline blanks within sentences */
    .inline-blank {
        display: inline-block;
        width: 100px;
        min-width: 60px;
        border-bottom: 1.5px solid #333;
        margin: 0 4px;
        vertical-align: bottom;
    }

    /* ===================================
       Writing Boxes (Fix the Sentence style)
       =================================== */
    .writing-box {
        border: 1.5px solid #DDD !important;
        border-radius: 6px;
        padding: 10px 14px;
        margin: 8px 0;
        min-height: 60px;
        background: repeating-linear-gradient(transparent,
                transparent 22px,
                #E5E5E5 22px,
                #E5E5E5 23px) !important;
        page-break-inside: avoid;
    }

    /* ===================================
       Word Chips / Pills (for sorting)
       =================================== */
    .word-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 10px 0;
        justify-content: center;
    }

    .word-chip {
        display: inline-block;
        padding: 5px 12px;
        background: white !important;
        border: 1.5px solid #DDD !important;
        border-radius: 16px;
        font-size: 9pt;
        font-weight: 500;
        color: #333;
    }

    /* ===================================
       Sorting Columns
       =================================== */
    .sorting-columns {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-top: 12px;
        page-break-inside: avoid;
    }

    .sorting-column {
        border: 1.5px solid #DDD !important;
        border-radius: 6px;
        min-height: 120px;
        overflow: hidden;
    }

    .sorting-column-header {
        padding: 8px 14px;
        font-weight: 700;
        color: white !important;
        text-align: center;
        font-size: 9pt;
    }

    .sorting-column-header.blue {
        background: #6ECFEA !important;
    }

    .sorting-column-header.red {
        background: #FF6B6B !important;
    }

    .sorting-column-header.orange {
        background: #E6A23C !important;
    }

    .sorting-column-body {
        padding: 10px;
        min-height: 80px;
    }

    /* ===================================
       Tables with Colored Headers
       =================================== */
    .worksheet-table {
        width: 100%;
        border-collapse: collapse;
        margin: 12px 0;
        page-break-inside: avoid;
    }

    .worksheet-table th {
        background: #E6A23C !important;
        color: white !important;
        padding: 8px 12px;
        font-weight: 700;
        text-align: center;
        border: 1px solid #D4921A !important;
        font-size: 9pt;
    }

    .worksheet-table td {
        padding: 10px 12px;
        border: 1.5px solid #DDD !important;
        text-align: center;
        vertical-align: middle;
        font-size: 10pt;
    }

    .worksheet-table td.blank {
        border-bottom: 1.5px solid #333 !important;
    }

    /* ===================================
       Long Multiplication / Division Boxes
       =================================== */
    .math-operation-box {
        border: 1.5px solid #DDD !important;
        border-radius: 6px;
        padding: 16px;
        display: inline-block;
        min-width: 100px;
        text-align: right;
        page-break-inside: avoid;
    }

    .math-operation-box .operand {
        font-size: 1.2rem;
        font-weight: 500;
    }

    .math-operation-box .operator {
        font-size: 1rem;
        margin-right: 6px;
    }

    .math-operation-box .line {
        border-top: 1.5px solid #333;
        margin-top: 6px;
        padding-top: 6px;
    }

    /* Reading Passage */
    .reading-passage {
        padding: 14px;
        background: #FAFAFA !important;
        border: 1.5px solid #DDD !important;
        border-left: 3px solid #E6A23C !important;
        border-radius: 4px;
        margin-bottom: 12px;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .passage-title {
        font-weight: 700;
        font-style: normal;
        color: #333;
        margin-bottom: 6px;
        font-size: 1rem;
    }

    /* ===================================
       Number Line
       =================================== */
    .number-line {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 0;
        margin: 12px 0;
        border-bottom: 2px solid #333;
        position: relative;
        page-break-inside: avoid;
    }

    .number-line::before,
    .number-line::after {
        content: '';
        position: absolute;
        bottom: -6px;
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
    }

    .number-line::before {
        left: -5px;
        border-top: 6px solid #333;
    }

    .number-line::after {
        right: -5px;
        border-top: 6px solid #333;
    }

    .number-line-mark::before {
        background: #333;
    }

    /* ===================================
       Solutions
       =================================== */
    .solution-container {
        margin-top: 10px;
        padding: 10px 12px;
        background: #F5FFF5 !important;
        border: 1px solid #90C090 !important;
        border-left: 3px solid #5A5 !important;
        border-radius: 4px;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .solution-label {
        font-weight: 700;
        color: #4A4 !important;
        font-size: 0.8rem;
        margin-bottom: 4px;
    }

    .solution-text {
        color: #333;
        font-weight: 600;
        font-size: 10pt;
    }

    .solution-explanation {
        font-size: 9pt;
        color: #666;
        margin-top: 6px;
        padding-top: 6px;
        border-top: 1px dashed #90C090;
    }

    /* ===================================
       Footer - Copyright style
       Prevent footer from appearing alone on new page
       =================================== */
    .worksheet-footer {
        /* Make footer compact to reduce spillover chances */
        margin-top: 8px;
        padding: 4px 0;
        border-top: 1px solid #E0E0E0 !important;
        background: none !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: none !important;
        border-radius: 0 !important;
        display: flex;
        justify-content: center;
        align-items: center;

        /* Shrink footer to reduce space needed */
        flex-shrink: 0;
        min-height: 20px;

        /* Prevent footer from being orphaned on its own page */
        page-break-before: avoid !important;
        break-before: avoid !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;

        /* Keep footer attached to preceding content */
        orphans: 4;
        widows: 4;
    }

    .footer-copyright {
        font-size: 0.75rem;
        color: #888;
        text-align: center;
        font-weight: 400;
    }

    .page-number {
        font-size: 0.75rem;
        color: #888;
        font-weight: 400;
    }

    /* Keep last question and footer together */
    .question-item:last-child {
        page-break-after: avoid !important;
        break-after: avoid !important;
    }

    /* ===================================
       Links
       =================================== */
    a {
        text-decoration: none;
        color: inherit;
    }

    /* ===================================
       Print Color Settings
       =================================== */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .worksheet-section {
        display: block !important;
    }

    .worksheets-container {
        max-height: none !important;
    }
}

/* ===================================
   Print Preview Mode
   =================================== */
.print-preview .worksheet-page {
    margin: 20px auto;
    max-width: 210mm;
    min-height: 297mm;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid #E0E0E0;
}