/* =============================================================================
   RESPONSIVE CSS — TỐI ƯU SPLIT-SCREEN TỪ MOBILE (360px) ĐẾN MÀN 4K (3840px)
   ============================================================================= */

/* --- Màn hình Full HD lớn (1700px – 2399px) --- */
@media (min-width: 1700px) {
    :root {
        --ed-sidebar-w: 440px;
    }

    .ad-banner-slot {
        width: 180px;
    }
}

/* --- Màn hình 2K QHD & 4K Scale 150%/125% (2400px – 3199px) --- */
@media (min-width: 2400px) {
    :root {
        --ed-sidebar-w: 500px;
        --ed-navbar-h: 72px;
    }

    .edtech-brand {
        font-size: 1.25rem;
    }

    .edtech-sidebar {
        padding: 18px 18px 32px 18px;
    }

    .edtech-sidebar .form-label {
        font-size: 1rem;
    }

    .edtech-sidebar .form-select,
    .edtech-sidebar .form-control,
    .edtech-sidebar .btn {
        min-height: 52px;
        font-size: 1.06rem !important;
    }

    .ad-banner-slot {
        width: 205px;
    }
}

/* --- Màn hình 4K UHD Native 100% (>= 3200px) --- */
@media (min-width: 3200px) {
    :root {
        --ed-sidebar-w: 560px;
        --ed-navbar-h: 82px;
    }

    .edtech-brand {
        font-size: 1.4rem;
    }

    .edtech-sidebar {
        padding: 22px 22px 36px 22px;
    }

    .edtech-sidebar .card-body {
        padding: 18px;
    }

    .edtech-step-head {
        font-size: 0.98rem;
    }

    .edtech-sidebar .form-label {
        font-size: 1.08rem;
    }

    .edtech-sidebar .form-select,
    .edtech-sidebar .form-control,
    .edtech-sidebar .btn {
        min-height: 56px;
        font-size: 1.12rem !important;
    }

    .ad-banner-slot {
        width: 225px;
    }
}

/* --- Tablet & Laptop nhỏ (< 992px): chuyển từ 2 cột sang 1 cột gọn gàng --- */
@media (max-width: 991.98px) {
    .edtech-split-shell {
        grid-template-columns: 1fr;
    }

    .edtech-sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid #cbd5e1;
        padding: 12px;
    }
}

/* --- Điện thoại di động (< 768px): đóng/mở bộ lọc qua Alpine mobileFilterOpen --- */
@media (max-width: 767.98px) {
    .edtech-navbar {
        padding: 6px 10px;
    }

    .edtech-brand-sub {
        display: none !important;
    }

    .edtech-sidebar.is-mobile-hidden {
        display: none;
    }

    .edtech-canvas-area {
        padding: 10px 4px 28px 4px;
    }

    .edtech-print-grid {
        grid-template-columns: 1fr 1fr;
    }

    .edtech-print-grid .btn-main-print {
        grid-column: span 2;
    }

    /* =========================================================================
       CHẾ ĐỘ BỐ TRÍ ĐỀ THI THEO ĐIỆN THOẠI (MOBILE REFLOW MODE — KHÔNG DÙNG KHỔ A4)
       Tự động kích hoạt trên màn hình < 768px giúp học sinh đọc & thao tác chạm dễ dàng
       ========================================================================= */
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) #a4-scale-viewport,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) #a4-sheets-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        transform: none !important;
        margin: 0 !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf).A4 .sheet,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .A4 .sheet {
        width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        padding: 14px 12px !important;
        margin: 0 0 16px 0 !important;
        border-radius: 14px !important;
        box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08) !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .sheet > .a4-body {
        zoom: 1 !important;
        transform: none !important;
        width: 100% !important;
        font-size: 15px !important;
        line-height: 1.55 !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ws-header {
        flex-direction: column;
        gap: 6px;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ws-title {
        font-size: 1.12rem !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ws-section-title {
        font-size: 0.96rem !important;
        padding: 8px 10px !important;
        border-radius: 8px !important;
        background: #eff6ff !important;
        border-left: 4px solid #2563eb !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-trace-grid,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-list,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-options,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-options.cols-4,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-options.cols-2,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-fill-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        font-size: 0.95rem !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-item,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-fill-grid > div,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-scram-item {
        background: #f8fafc;
        border: 1.5px solid #cbd5e1;
        border-radius: 12px;
        padding: 10px 12px;
        margin-bottom: 6px;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-mcq-options > div {
        background: #ffffff;
        border: 1.5px solid #e2e8f0;
        border-radius: 10px;
        padding: 10px 12px;
        min-height: 44px;
        display: flex;
        align-items: center;
        font-weight: 600;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-match-table,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-match-table tbody,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-match-table tr,
    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-match-table td {
        display: block !important;
        width: 100% !important;
        font-size: 0.95rem !important;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .ex-match-table tr {
        background: #f8fafc;
        border: 1.5px solid #cbd5e1;
        border-radius: 10px;
        margin-bottom: 8px;
        padding: 6px;
    }

    body.mobile-reflow-mode:not(.is-printing-now):not(.is-exporting-pdf) .a4-footer-bar {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* --- Khóa in ấn A4 1:1 trên mọi cỡ màn hình --- */
@media print {
    .workspace-with-ads > #a4-scale-viewport,
    #a4-scale-viewport,
    #a4-sheets-wrapper {
        width: auto !important;
        max-width: none !important;
        height: auto !important;
        margin: 0 !important;
        transform: none !important;
    }
}
