@import url('https://fonts.googleapis.com/css2?family=Tinos:ital,wght@0,400;0,700;1,400;1,700&display=swap');

:root {
    --page-margin-x: 15mm;
    --page-margin-y: 15mm;
    --question-spacing: 8px;
}

body {
    font-family: 'Tinos', 'Times New Roman', Times, serif;
}

/* ===== A4 Preview Page ===== */
.a4-page {
    width: 210mm;
    min-height: 297mm;
    padding: var(--page-margin-y) var(--page-margin-x);
    margin: 0 auto;
    background: white;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    color: black;
    font-size: 11pt;
    line-height: 1.3;
    display: flex;
    flex-direction: column;
}

/* ===== Watermark: large centered background logo ===== */
.watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 65%;
    height: auto;
    opacity: 0.12;
    z-index: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.watermark img {
    width: 100%;
    height: auto;
    display: block;
}

/* Content sits above the watermark */
.content-wrapper {
    position: relative;
    z-index: 1;
    flex-grow: 1;
    border: 1px solid black;
    padding: 10px;
    box-sizing: border-box;
}

/* ===== Header Box ===== */
.test-header {
    border: 1.5px solid black;
    padding: 8px 10px;
    position: relative;
    min-height: 65px;
    box-sizing: border-box;
}

.logo-slot {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 55px;
    height: 55px;
}
.logo-slot img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.header-text {
    text-align: center;
    margin-left: 65px;
    margin-right: 10px;
}

.school-name {
    font-weight: bold;
    font-size: 13pt;
    text-transform: uppercase;
}

.exam-title {
    font-weight: bold;
    font-size: 11pt;
    text-decoration: underline;
}

.class-name {
    font-weight: bold;
    font-size: 10pt;
}

/* ===== Info Bar ===== */
.info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 1.5px solid black;
    border-right: 1.5px solid black;
    border-bottom: 1.5px solid black;
    padding: 4px 10px;
    font-weight: bold;
    font-size: 10pt;
    box-sizing: border-box;
}

/* ===== Name / Roll ===== */
.name-roll {
    display: flex;
    justify-content: space-between;
    border-left: 1.5px solid black;
    border-right: 1.5px solid black;
    border-bottom: 1.5px solid black;
    padding: 4px 10px;
    font-size: 10pt;
    font-weight: bold;
    box-sizing: border-box;
}

/* ===== General Instructions ===== */
.instructions {
    border-left: 1.5px solid black;
    border-right: 1.5px solid black;
    border-bottom: 1.5px solid black;
    padding: 4px 10px;
    font-size: 9.5pt;
    box-sizing: border-box;
}

/* ===== Section Headers ===== */
.section-header {
    text-align: center;
    font-weight: bold;
    text-decoration: underline;
    margin: 12px 0 6px 0;
    text-transform: uppercase;
    font-size: 10.5pt;
}

/* ===== Question Rows ===== */
.question-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--question-spacing);
    font-size: inherit;
}

.q-text {
    flex: 1;
}

.q-marks {
    font-weight: bold;
    min-width: 35px;
    text-align: right;
    white-space: nowrap;
    padding-left: 8px;
}

/* ===== MCQ Options Grid (4 columns) ===== */
.options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px 8px;
    margin-left: 18px;
    margin-top: 3px;
    font-size: inherit;
}

/* ===== Sub-points (Case Study) ===== */
.sub-points {
    margin-left: 18px;
    margin-top: 3px;
}
.sub-points div {
    margin-bottom: 2px;
}

/* ===== Overflow Warning ===== */
#overflowWarning {
    font-size: 0.8rem;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%   { opacity: 1; }
    50%  { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ===== Print (Native Client-Side PDF Generation) ===== */
@media print {
    /* Hide the editor, navbar, and modals completely */
    .col-md-5, .navbar, .modal, .no-print {
        display: none !important;
    }
    
    /* Allow the body and containers to expand infinitely */
    html, body, .container-fluid, .row, .col-md-7, .preview-container {
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* Make the preview take up the whole screen natively */
    .col-md-7 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
    
    #pdfPreview {
        position: relative !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
        min-height: 0 !important; /* Let browser paginate */
    }

    /* Prevent questions from being sliced in half across pages */
    .question-item {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .section-header {
        page-break-after: avoid;
        break-after: avoid;
    }
}

#pdfPreview {
    transform-origin: top center;
}

/* ===== Mobile Responsiveness ===== */
.editor-wrapper {
    height: calc(100vh - 56px);
    overflow: hidden;
}

@media (max-width: 767.98px) {
    /* Allow scrolling naturally on small screens */
    .editor-wrapper {
        height: auto !important;
        overflow: visible !important;
    }
    
    .editor-scroll-panel {
        height: auto !important;
        overflow: visible !important;
        margin-bottom: 20px;
    }
    
    /* Put preview on top of the editor so they see changes instantly */
    .mobile-reverse-row {
        flex-direction: column-reverse;
    }
    
    .preview-container {
        min-height: 400px;
        overflow-x: auto;
    }
}