/* Google Fonts - Hind Siliguri, Tiro Bangla, Inter, IBM Plex Mono */
@import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=Tiro+Bangla:ital@0;1&family=Fira+Code:wght@400;500&family=IBM+Plex+Mono:wght@400;600&display=swap');

/* CSS Variables - High-Contrast Professional Vintage / Old Beige Theme */
:root {
    /* Rich Warm Parchment Background */
    --bg-primary: #EDE5D8;
    --bg-gradient: linear-gradient(135deg, #F5EFE6 0%, #E6DCCD 100%);
    --card-bg: #FAF7F2;
    --card-hover: #FFFFFF;
    
    /* Text - High Contrast Razor-Sharp Carbon Typewriter Ink */
    --text-primary: #120F0D;
    --text-secondary: #2C231C;
    --text-muted: #57483B;
    
    /* Warm Vintage Accents */
    --accent: #8A5A2B;
    --accent-hover: #70461E;
    
    --success: #1B6636;
    --success-light: #EAF4EE;
    --error: #B52B1E;
    --error-light: #FCECEB;
    --warning: #B37D14;
    --warning-light: #FDF6E7;
    
    /* Crisp High-Contrast Structural Borders */
    --border: #BAA68B;
    --border-light: #DFD2C0;
    --border-dark: #786044;
    
    --primary: #8A5A2B;
    --primary-hover: #70461E;
    --bg-main: #EDE5D8;
    --paper-bg: #ffffff;
    --border-color: #BAA68B;
    
    /* Professional Elevation Shadows */
    --shadow-sm: 0 1px 3px rgba(35, 25, 15, 0.08), 0 1px 2px rgba(35, 25, 15, 0.05);
    --shadow-md: 0 4px 12px rgba(35, 25, 15, 0.09), 0 2px 4px rgba(35, 25, 15, 0.05);
    --shadow-lg: 0 12px 28px rgba(35, 25, 15, 0.12), 0 4px 8px rgba(35, 25, 15, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Hind Siliguri', 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Authentic Exam Paper Typography */
.font-serif {
    font-family: 'Tiro Bangla', 'Times New Roman', Georgia, serif;
}

.font-mono {
    font-family: 'Fira Code', monospace;
}

/* Exam Sheet Wrapper: Centers discrete A4 pages */
.exam-sheet-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.25rem;
    width: 100%;
    padding: 1.5rem 0.5rem 3rem 0.5rem;
}

/* Authentic A4 Page Dimensions (ISO 216: 210mm x 297mm) */
.a4-page {
    width: 210mm;
    max-width: 100%;
    min-height: 297mm;
    height: auto;
    margin: 0 auto;
    background: #ffffff;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 10px 25px -3px rgba(0, 0, 0, 0.1);
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 12mm 14mm 10mm 14mm;
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    line-height: 1.55;
    transition: all 0.2s ease-in-out;
}

.a4-page-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Typography Scale Classes (ফন্ট সাইজ অ্যাডজাস্টমেন্ট) */
.font-scale-compact {
    font-size: 11.5px;
    line-height: 1.45;
}
.font-scale-compact .institution-name {
    font-size: 1.25rem !important;
}
.font-scale-compact .exam-title {
    font-size: 0.95rem !important;
}
.font-scale-compact .exam-header {
    padding-bottom: 0.5rem !important;
    margin-bottom: 0.65rem !important;
}
.font-scale-compact .header-meta {
    font-size: 0.75rem !important;
    padding-top: 0.25rem !important;
    margin-top: 0.25rem !important;
}
.font-scale-compact .instructions {
    font-size: 0.7rem !important;
    margin-top: 0.2rem !important;
}
.font-scale-compact .question-item {
    margin-bottom: 0.55rem !important;
    padding: 0.25rem 0.35rem !important;
}
.font-scale-compact .stimulus-box {
    padding: 0.25rem 0.5rem !important;
    margin-bottom: 0.35rem !important;
    font-size: 0.775rem !important;
    line-height: 1.4 !important;
}
.font-scale-compact .q-number {
    font-size: 0.825rem !important;
}
.font-scale-compact .q-text {
    font-size: 0.8rem !important;
    line-height: 1.35 !important;
}
.font-scale-compact .q-marks {
    font-size: 0.7rem !important;
}
.font-scale-compact .cq-subquestions {
    margin-top: 0.25rem !important;
    margin-left: 0.65rem !important;
    font-size: 0.775rem !important;
    line-height: 1.35 !important;
}
.font-scale-compact .options-grid {
    margin-top: 0.25rem !important;
    gap: 0.2rem !important;
    font-size: 0.775rem !important;
}
.font-scale-compact .katex {
    font-size: 0.92em !important;
}

/* Normal Scale (Default) */
.font-scale-normal {
    font-size: 13.5px;
    line-height: 1.6;
}

/* Large Scale */
.font-scale-large {
    font-size: 15.5px;
    line-height: 1.7;
}
.font-scale-large .institution-name {
    font-size: 1.75rem !important;
}
.font-scale-large .exam-title {
    font-size: 1.25rem !important;
}
.font-scale-large .question-item {
    margin-bottom: 1.25rem !important;
}
.font-scale-large .q-number,
.font-scale-large .q-text {
    font-size: 1.05rem !important;
}
.font-scale-large .katex {
    font-size: 1.12em !important;
}

/* Fit to 1 Page Compact Padding */
.fit-to-one-page {
    padding: 10mm 12mm 8mm 12mm !important;
    justify-content: flex-start !important;
}
.fit-to-one-page .exam-header {
    padding-bottom: 0.35rem !important;
    margin-bottom: 0.5rem !important;
}
.fit-to-one-page .questions-container {
    gap: 0.35rem !important;
}
.fit-to-one-page .exam-footer {
    margin-top: auto !important;
    padding-top: 0.35rem !important;
}

/* Two Column Layout (Authentic Board Exam Style) */
.two-column-layout .questions-container {
    column-count: 2;
    column-gap: 1.5rem;
    column-rule: 1px dashed #cbd5e1;
}

.two-column-layout .question-item {
    break-inside: avoid;
    page-break-inside: avoid;
    overflow: hidden; /* Never allow children to paint outside column */
    width: 100%;
}

/* Three Column Layout (For dense MCQs >= 18) */
.three-column-layout .questions-container {
    column-count: 3;
    column-gap: 1.15rem;
    column-rule: 1px dashed #cbd5e1;
}

.three-column-layout .question-item {
    break-inside: avoid;
    page-break-inside: avoid;
    overflow: hidden;
    width: 100%;
    font-size: 0.92em;
}

/* Single Column Layout */
.single-column-layout .question-item {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Question Item Type-Specific Compact Spacing (Prevents exceeding A4 boundary) */
.q-item-mcq {
    margin-bottom: 0.45rem !important;
    padding: 0.2rem 0.35rem 0.35rem 0.35rem !important;
}

.q-item-mcq .options-grid {
    margin-top: 0.2rem !important;
    gap: 0.25rem !important;
}

.q-item-mcq .option-item {
    padding: 0.15rem 0.35rem !important;
    font-size: 0.875rem !important;
    line-height: 1.35 !important;
}

.two-column-layout .q-item-mcq {
    margin-bottom: 0.45rem !important;
}

.three-column-layout .q-item-mcq {
    margin-bottom: 0.35rem !important;
    font-size: 0.875rem !important;
}

.q-item-short {
    margin-bottom: 0.55rem !important;
    padding: 0.25rem 0.35rem 0.35rem 0.35rem !important;
}

.two-column-layout .q-item-short {
    margin-bottom: 0.5rem !important;
}

.q-item-cq {
    margin-bottom: 0.85rem !important;
    padding: 0.35rem 0.45rem 0.45rem 0.45rem !important;
}

/* Section Banners span across all columns */
.section-banner {
    column-span: all;
    break-after: avoid;
    page-break-after: avoid;
}

/* Responsive Option Grid inside columns */
.two-column-layout .options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.35rem !important;
}

.three-column-layout .options-grid {
    grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    gap: 0.25rem !important;
}

.single-column-layout .options-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

@media screen and (min-width: 640px) {
    .single-column-layout .options-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
}

/* Editable Focus Glow */
[contenteditable="true"]:focus {
    outline: 2px dashed #6366f1;
    background-color: #f8fafc;
    border-radius: 4px;
}

[contenteditable="true"]:hover {
    background-color: #f1f5f9;
    border-radius: 4px;
    cursor: text;
}

/* Image Upload Dropzone */
.dropzone {
    border: 2px dashed #cbd5e1;
    transition: all 0.2s ease-in-out;
}

.dropzone.dragover {
    border-color: #6366f1;
    background-color: #eef2ff;
}

/* Quality Indicator Badges */
.badge-good {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.badge-medium {
    background-color: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.badge-poor {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* KaTeX soft-wrap and overflow prevention (CRITICAL: prevents formula overlapping) */
.katex {
    white-space: normal !important;
    overflow-wrap: anywhere !important;
    word-break: normal !important;
    font-size: 1.05em;
}

.katex .katex-html {
    white-space: normal !important;
    overflow-wrap: anywhere !important;
}

.katex .base {
    white-space: normal !important;
    display: inline !important;
}

.katex .mspace {
    white-space: normal !important;
}

.katex-display {
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    margin: 0.5rem 0 !important;
}

/* Stimulus Box Styling & Word Wrapping */
.stimulus-box {
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
}

.inline-number {
    display: inline-block;
    letter-spacing: 0.02em;
}

/* Ensure all question text and containers strictly respect column boundaries */
.question-item, .stimulus-box, .q-text, .options-grid, .cq-subquestions, .solution-card {
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
}

/* Mobile & Tablet Responsive View */
@media screen and (max-width: 860px) {
    .exam-sheet-wrapper {
        padding: 0.5rem 0;
        gap: 1.25rem;
    }
    
    .a4-page {
        width: 100% !important;
        min-height: auto !important;
        padding: 1.25rem !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    }

    .two-column-layout .questions-container,
    .three-column-layout .questions-container {
        column-count: 1 !important; /* Stack vertically on small mobile for touch readability */
    }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Print Specific Rules */
@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    body {
        background: #ffffff !important;
        color: #000000 !important;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    nav, aside, header.app-header, .no-print, #uploadSidebar, #topActionsBar, .modal, .toast-container, #editableNotice {
        display: none !important;
    }

    #previewArea {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        background: transparent !important;
        border: none !important;
        overflow: visible !important;
    }

    .exam-sheet-wrapper {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
    }

    .a4-page {
        width: 210mm !important;
        height: 297mm !important;
        min-height: 297mm !important;
        max-height: 297mm !important;
        padding: 12mm 14mm 10mm 14mm !important;
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        page-break-after: always !important;
        break-after: page !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .a4-page:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    [contenteditable="true"]:focus {
        outline: none !important;
        background: transparent !important;
    }

    .two-column-layout .questions-container {
        column-count: 2 !important;
        column-gap: 12mm !important;
        column-rule: 1px solid #94a3b8 !important;
    }

    .three-column-layout .questions-container {
        column-count: 3 !important;
        column-gap: 8mm !important;
        column-rule: 1px solid #94a3b8 !important;
    }

    .section-banner {
        column-span: all !important;
    }

    .question-item {
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
}

/* ========================================================
   Old Beige Vintage Theme - Component Overrides
   ======================================================== */
.app-header {
    background-color: #FAF7F2 !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: var(--shadow-sm) !important;
}

/* Sidebar & General Cards */
.sidebar-card,
aside .bg-white,
#topActionsBar {
    background-color: #FAF7F2 !important;
    border: 1px solid var(--border) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-sm) !important;
}

/* Buttons Styling in Old Beige Theme */
.preset-btn {
    border: 1px solid transparent;
}
.preset-btn.active,
.preset-btn[data-active="true"] {
    background-color: #FFFFFF !important;
    color: var(--accent) !important;
    border-color: var(--border) !important;
    box-shadow: var(--shadow-sm) !important;
}

.action-btn-primary,
button.bg-brand-600 {
    background-color: var(--accent) !important;
    color: #FFFFFF !important;
    border: 1px solid var(--border-dark) !important;
    transition: all 0.15s ease !important;
}
.action-btn-primary:hover,
button.bg-brand-600:hover {
    background-color: var(--accent-hover) !important;
}

.action-btn-secondary,
button.bg-slate-100 {
    background-color: #FFFFFF !important;
    border: 1px solid var(--border) !important;
    color: var(--text-secondary) !important;
}
.action-btn-secondary:hover,
button.bg-slate-100:hover {
    background-color: #F5EFE6 !important;
    color: var(--text-primary) !important;
}

/* Form Controls & Inputs */
input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
    border-color: var(--border) !important;
    background-color: #FFFFFF !important;
    color: var(--text-primary) !important;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent) !important;
    outline: none !important;
    box-shadow: 0 0 0 2px rgba(138, 90, 43, 0.15) !important;
}

/* FV Labs Brand Credit */
.fv-brand-footer {
    padding: 24px 16px;
    text-align: center;
    background: transparent;
    margin-top: auto;
}

.fv-credit-container {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(250, 247, 242, 0.88);
    border: 1px solid rgba(186, 166, 139, 0.7);
    border-radius: 9999px;
    font-size: 0.8rem;
    box-shadow: var(--shadow-sm);
}

.fv-credit-lead {
    color: var(--text-muted);
    font-weight: 500;
}

.fv-credit-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 12px;
    border-radius: 9999px;
    background: #FFFFFF;
    border: 1px solid var(--border);
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
    font-size: 0.8rem;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(35, 25, 15, 0.04);
}

.fv-credit-badge:hover {
    background: #F5EFE6;
    border-color: var(--accent);
    color: var(--accent-hover);
}

.fv-credit-dot {
    color: var(--border);
}

.fv-credit-tagline {
    color: var(--text-muted);
    font-weight: 500;
}

/* User Profile & Quota Badges */
.user-profile-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    background: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.quota-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 9999px;
    background: #FAF7F2;
    border: 1px solid var(--border-light);
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.quota-bar-fill {
    height: 5px;
    border-radius: 9999px;
    background: var(--accent);
    transition: width 0.3s ease;
}

/* Modals in Old Beige Theme */
.vintage-modal-card {
    background-color: #FAF7F2 !important;
    border: 1px solid var(--border) !important;
    box-shadow: var(--shadow-lg) !important;
    color: var(--text-primary) !important;
}

/* Question History Drawer / Modal */
.history-item-card {
    background: #FFFFFF;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 12px 14px;
    transition: all 0.15s ease;
}
.history-item-card:hover {
    border-color: var(--border);
    background: #FAF7F2;
    box-shadow: var(--shadow-sm);
}

/* Chat Messages in Feedback Modal */
.chat-bubble-user {
    align-self: flex-end;
    background: var(--accent);
    color: #FFFFFF;
    border-radius: 12px 12px 2px 12px;
    padding: 10px 14px;
    max-width: 80%;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
}

.chat-bubble-admin {
    align-self: flex-start;
    background: #FFFFFF;
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 12px 12px 12px 2px;
    padding: 10px 14px;
    max-width: 80%;
    font-size: 0.85rem;
    box-shadow: var(--shadow-sm);
}

/* Auth Loading Overlay & Mandatory Login Modal */
.auth-loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-primary);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    color: var(--text-primary);
    font-family: inherit;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.spinner.large {
    width: 48px;
    height: 48px;
    border-width: 4px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.login-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-gradient);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.login-card {
    background: #FAF7F2;
    padding: 40px 32px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 420px;
    width: 100%;
    border: 1px solid var(--border);
}

.google-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    background: #FFFFFF;
    color: #120F0D;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.google-btn:hover {
    background: #F5EFE6;
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

#toastContainer {
    z-index: 100000 !important;
}


