/* Math Worksheet Generator Styles */

.math-tool-container {
    display: flex;
    min-height: calc(100vh - 200px);
    background-color: #f8f9fa;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

/* Sidebar Controls */
.controls-sidebar {
    width: 350px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 10;
    background: #fff;
}

.controls-body {
    flex: 1;
    overflow-y: auto;
}

/* Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #e9ecef;
    position: relative;
    overflow: visible;
}

.preview-toolbar {
    height: 60px;
    background: white;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    z-index: 5;
}

.preview-canvas-wrapper {
    flex: 1;
    overflow: auto;
    padding: 2rem;
    background-color: #e9ecef;
}

/* Pages Container - holds all worksheet pages */
.pages-container,
#worksheet-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    padding-bottom: 3rem;
    min-height: min-content;
}

/* Page Wrapper - maintains space for scaled pages */
.page-wrapper {
    position: relative;
    flex-shrink: 0;
}

/* Worksheet Page */
.worksheet-page {
    background: white;
    color: #000; /* Ensure text is black */
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    position: absolute;
    top: 0;
    left: 0;
    /* Dimensions set by JS */
    padding: 20mm;
    box-sizing: border-box;
    transform-origin: top left;
    transition: transform 0.2s ease;
    flex-shrink: 0; /* Prevent shrinking in flex container */
    overflow: visible; /* Allow content to be visible */
    display: flex;
    flex-direction: column;
}

.worksheet-page.landscape {
    width: 297mm;
    min-height: 210mm;
}

/* Worksheet Content */
.worksheet-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid #000;
    padding-bottom: 1rem;
    width: 100%;
}

.worksheet-title-row {
    width: 100%;
    text-align: center;
    margin-bottom: 1.5rem;
}

.worksheet-title-row h2 {
    margin: 0;
    font-size: 28pt;
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    text-align: center;
}

.worksheet-meta-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    gap: 1rem;
}

.field {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-family: 'Comic Neue', cursive;
    font-size: 14pt;
}

.field-line {
    border-bottom: 1px solid #000;
    width: 150px;
    display: inline-block;
}

.problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 2rem;
    font-family: 'Comic Neue', cursive;
    flex: 1;
    align-content: start;
    overflow: hidden;
}

.problem-item {
    font-size: 20pt;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    min-height: 80px;
}

.problem-vertical {
    display: inline-block;
    text-align: right;
}

.problem-top {
    display: block;
}

.problem-bottom {
    display: flex;
    justify-content: space-between;
    width: 100%;
    border-bottom: 2px solid #000;
    padding-bottom: 0.2rem;
    margin-bottom: 0.5rem;
}

.operator {
    margin-right: 0.5rem;
}

.answer-line {
    height: 30px;
}

/* Watermark */
.worksheet-watermark {
    position: absolute;
    top: 10mm;
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    opacity: 0.85;
    pointer-events: none;
    z-index: 50;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.5rem;
    border-radius: 8px;
}

.worksheet-watermark img {
    height: 48px;
    width: auto;
}

.worksheet-watermark span {
    font-family: 'Quicksand', sans-serif;
    font-size: 18pt;
    color: #374151;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Print Styles */
@media print {
    /* Hide everything except print area */
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        height: auto !important;
        overflow: visible !important;
        background: white !important;
    }
    
    /* Hide ALL elements on the page */
    body > * {
        display: none !important;
        visibility: hidden !important;
    }
    
    /* Show only the print area */
    body > #print-area {
        display: block !important;
        visibility: visible !important;
    }
    
    /* Also hide common page elements that might bleed through */
    header, footer, nav, .navbar, .sidebar, .modal, .toast,
    .controls-sidebar, .preview-area, .math-tool-container,
    .navbar-brand, .nav-link, .breadcrumb {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }

    #print-area {
        display: block !important;
        visibility: visible !important;
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .worksheet-page {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        margin: 0 !important;
        padding: 15mm !important;
        box-shadow: none !important;
        border: none !important;
        transform: none !important;
        page-break-after: always !important;
        page-break-inside: avoid !important;
        overflow: visible !important;
        visibility: visible !important;
        background: white !important;
        box-sizing: border-box !important;
    }

    .worksheet-page:last-child {
        page-break-after: auto !important;
    }
    
    .problems-grid {
        flex: 1 !important;
        overflow: visible !important;
    }
    
    .problem-item {
        page-break-inside: avoid !important;
    }

    .worksheet-header,
    .worksheet-watermark {
        visibility: visible !important;
    }

    .worksheet-watermark {
        opacity: 1 !important;
        position: absolute !important;
        top: 5mm !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        background: white !important;
        z-index: 9999 !important;
        box-shadow: 0 0 0 15px white !important;
    }
    
    .worksheet-watermark img {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .worksheet-watermark span {
        color: #111 !important;
    }
    
    /* White header overlay to cover any stray content */
    .worksheet-page::before {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 25mm !important;
        background: white !important;
        z-index: 9998 !important;
    }
}

/* Responsive */
@media (max-width: 991px) {
    .math-tool-container {
        flex-direction: column;
        height: auto;
    }
    
    .controls-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }
    
    .preview-area {
        height: 600px;
    }
}
