/* Shared responsive layer: loaded AFTER each page's inline styles. */
html { -webkit-text-size-adjust: 100%; }

img, video, iframe { max-width: 100%; }
input, select, textarea, button { max-width: 100%; }
.main-content, .page-header, .page-container, .content-wrapper,
.toolbar, .form-panel, .form-group, .filter-item,
.profile-grid, .dashboard-grid, .map-grid, .report-controls {
    min-width: 0;
}

/* Mobile navigation stays in document flow instead of covering page content. */
@media (max-width: 991px) {
    .header { position: relative !important; }

    .header .header-inner {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px;
        /* Override the fixed desktop header height so the mobile nav
           stays inside the dark header and pushes content down. */
        height: auto !important;
        min-height: 64px;
        padding: 10px 16px;
    }

    .header .header-brand {
        flex: 1 1 0;
        max-width: none;
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .header .mobile-nav-toggle {
        order: 2;
        flex: 0 0 40px;
        margin-left: auto;
    }

    .header .header-nav {
        position: static !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 10px 12px 12px !important;
        background: #12244f !important;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
        border: 1px solid rgba(255, 255, 255, 0.12) !important;
        border-radius: 11px;
        animation: none !important;
        gap: 6px;
    }

    .header .header-nav:not(.is-open):not(.active) { display: none !important; }
    .header .header-nav.is-open,
    .header .header-nav.active { display: flex !important; }

    .header .header-nav .nav-dropdown { width: 100%; }
    .header .header-nav .nav-btn,
    .header .header-nav .nav-dropbtn {
        min-height: 40px;
        width: 100%;
        text-align: left;
        justify-content: space-between;
        white-space: normal;
        color: #fff !important;
        background: #203363 !important;
    }

    /* Dropdowns open on tapping their header; hover alone won't expand them. */
    .header .header-nav .nav-dropdown-content,
    .header .header-nav .nav-dropdown:hover .nav-dropdown-content {
        display: none !important;
        position: static !important;
        width: 100% !important;
        min-width: 0 !important;
        margin: 4px 0 6px;
        box-shadow: none !important;
        transform: none !important;
        background: #0c1b3f !important;
    }

    .header .header-nav .nav-dropdown.is-open > .nav-dropdown-content {
        display: block !important;
    }

    .header .header-nav .user-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        width: 100%;
    }

    .header .header-nav .user-bar .role-badge {
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .hero, .hero-inner { max-width: 100%; }
    .main-content { width: 100%; padding-left: 18px !important; padding-right: 18px !important; }
    .hero { padding-left: 18px !important; padding-right: 18px !important; }
    .hero-title { overflow-wrap: anywhere; }

    .toolbar, .filter-bar, .report-controls, .form-actions {
        flex-wrap: wrap;
        max-width: 100%;
    }
    .filter-bar .filter-item, .report-controls .rc-group { min-width: 0; }

    .grid-wrapper, .table-responsive, .table-responsive-box,
    .table-container-wrapper, .schedule-grid-wrap {
        max-width: 100%;
        min-width: 0;
    }
    .grid-wrapper, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .form-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
    .profile-grid { grid-template-columns: minmax(0, 1fr); }
    .profile-grid > *, .dashboard-grid > *, .map-grid > * { min-width: 0; }
    .profile-grid .right-col, .profile-grid .section-card {
        min-width: 0;
        max-width: 100%;
    }
    .profile-grid .section-card { overflow-x: auto; }

    /* The teaching-load report is a document: keep its columns intact and
       let the report scroll on screen, without affecting print styles. */
    .tl-doc { max-width: 100%; overflow-x: auto; }
    .tl-table { min-width: 640px; }

    /* Existing fixed-position dialogs should scroll on short screens. */
    #assignSubjectModal, #deleteModal, #scheduleAlertModal,
    [id$='pnlRejectModal'],
    .modal-overlay, .dialog-overlay {
        padding: 14px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    #assignSubjectModal > div, #deleteModal > div,
    [id$='pnlRejectModal'] > div,
    #scheduleAlertModal > div, .modal-content, .modal-dialog {
        max-width: min(100%, 560px) !important;
        max-height: calc(100dvh - 28px);
        overflow-y: auto;
        margin: auto;
    }
}

@media (max-width: 600px) {
    .main-content { padding-left: 12px !important; padding-right: 12px !important; }
    .hero { padding: 28px 14px 34px !important; }
    .hero-title { font-size: clamp(25px, 8vw, 36px) !important; }
    .hero-sub { font-size: 13px !important; line-height: 1.5; }

    .toolbar { align-items: stretch; gap: 12px; }
    .toolbar > div, .toolbar > * { max-width: 100%; }

    .filter-bar, .report-controls { padding: 14px !important; gap: 12px !important; }
    .filter-bar .filter-item, .report-controls .rc-group {
        flex: 1 1 100%;
        width: 100%;
    }
    .filter-bar .filter-item { flex-wrap: wrap; align-items: flex-start; }
    .filter-bar .filter-item label { white-space: normal; }
    .filter-bar select, .filter-bar input,
    .report-controls select, .report-controls input { max-width: 100%; width: 100% !important; min-width: 0 !important; }

    .form-panel { padding: 17px !important; }
    .form-grid, .form-row { grid-template-columns: minmax(0, 1fr) !important; }
    .profile-grid [style*='grid-template-columns: 1fr 1fr'],
    #assignSubjectModal [style*='grid-template-columns:1fr 1fr'] {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions button, .form-actions input[type='submit'] { width: 100%; }

    .dashboard-grid, .map-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 14px; }
    .dashboard-grid .card { min-height: 0; padding: 20px !important; }

    .grid-wrapper table, .table-responsive table { max-width: none; }
    .table-responsive { scrollbar-width: thin; }
    .grid-header-container { flex-wrap: wrap; gap: 10px; }
    .grid-scroll-actions, .floating-arrow-btn { display: none !important; }

    #assignSubjectModal > div, #deleteModal > div,
    [id$='pnlRejectModal'] > div,
    #scheduleAlertModal > div { padding: 18px !important; width: 100% !important; }
    #assignSubjectModal [style*='justify-content:flex-end'],
    #deleteModal [style*='justify-content:flex-end'],
    [id$='pnlRejectModal'] [style*='justify-content: flex-end'] { flex-wrap: wrap; }
    #modalTargetInfo { overflow-wrap: anywhere; }
    input[type='text'], input[type='password'], input[type='email'],
    input[type='number'], input[type='search'], input[type='time'],
    textarea, select { font-size: 16px !important; }

    /* Reports / profile forms: no fixed-width controls beyond the viewport. */
    .rc-group { width: 100%; }
    .rc-group select, .rc-group input { min-width: 0 !important; width: 100% !important; }
    .login-card { max-width: 100% !important; padding: 24px 18px !important; }
    .denied-box { max-width: 100%; padding: 24px 18px !important; }
    .footer { padding-left: 14px !important; padding-right: 14px !important; }
    .footer-inner { grid-template-columns: minmax(0, 1fr) !important; gap: 18px; text-align: center; }
    .footer-right, .footer-brand-row { justify-content: center; }
}

@media (max-width: 360px) {
    .header .header-inner { padding: 8px 10px; gap: 7px; }
    .header .header-logo { width: 35px; height: 35px; }
    .header .header-brand { font-size: 11px; }
    .main-content { padding-left: 10px !important; padding-right: 10px !important; }
    .hero { padding-left: 10px !important; padding-right: 10px !important; }
}
