/* ==========================================================================
   Mobile / tablet usability (loaded after site.css, see Sections/_Styles.cshtml)
   Everything is inside max-width media queries, so the desktop layout is untouched.
   Breakpoints follow Bootstrap: < 768px = phones, < 1200px = tablets / where the sidebar becomes off-canvas.
   ========================================================================== */

/* ---- Tablets and below: off-canvas sidebar ------------------------------ */
@media (max-width: 1199.98px) {
    /* The sidebar slides over the page; keep it above sticky navbars and the dimming overlay below it. */
    #layout-menu { z-index: 1100; }
    .layout-overlay { z-index: 1090; }

    /* Navbar: tighter so everything fits on one row */
    .layout-navbar { padding-left: .75rem; padding-right: .75rem; }
    .layout-navbar .navbar-nav-right { flex: 1 1 auto; min-width: 0; }
}

/* ---- Phones ------------------------------------------------------------- */
@media (max-width: 767.98px) {

    /* Page gutters: pages use .container-xxl.px-4 / .container-fluid.py-4 which is far too much on a phone */
    .content-wrapper .container-xxl,
    .content-wrapper .container-fluid,
    .content-wrapper .container-xxl.px-4 {
        padding-left: .75rem !important;
        padding-right: .75rem !important;
    }
    .content-wrapper .container-xxl.mt-4,
    .content-wrapper .container-fluid.py-4,
    .content-wrapper .container-xxl.py-4 { margin-top: .75rem !important; padding-top: .5rem !important; padding-bottom: .5rem !important; }

    /* ---- Navbar ---- */
    .layout-navbar { height: auto; min-height: 3.5rem; }
    .layout-navbar .navbar-nav-right ul.navbar-nav { gap: 0; }
    .layout-navbar .nav-link { padding-left: .4rem; padding-right: .4rem; }
    #navAttendanceTimer { font-size: .85rem; }
    /* Notification / user dropdowns must never be wider than the screen */
    .layout-navbar .dropdown-menu { max-width: calc(100vw - 1rem); }
    .dropdown-notifications .dropdown-menu { width: calc(100vw - 1rem); max-width: 24rem; }

    /* Announcement ticker */
    #announcementMarquee { font-size: .8rem; }

    /* ---- Typography / spacing ---- */
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.3rem; }
    h3, .h3 { font-size: 1.2rem; }
    h4, .h4 { font-size: 1.1rem; }
    .card-body { padding: .85rem; }
    .card-header { padding: .75rem .85rem; }

    /* Card / section headers that hold a title + buttons: let them wrap instead of overflowing */
    .card-header.d-flex,
    .card-header .d-flex,
    .d-flex.justify-content-between.align-items-center { flex-wrap: wrap; gap: .5rem; }

    /* Toolbars and button rows wrap and the buttons stay tappable */
    .btn { white-space: normal; }
    .btn-sm { padding: .4rem .65rem; }
    .btn-toolbar, .btn-group { flex-wrap: wrap; }

    /* ---- Forms ---- */
    /* 16px stops iOS Safari zooming in on focus */
    .form-control, .form-select, .select2-selection { font-size: 16px; }
    .form-control, .form-select { min-height: 2.6rem; }
    .select2-container { width: 100% !important; }
    .input-group { flex-wrap: wrap; }
    label.form-label { margin-bottom: .25rem; }

    /* ---- Tables ---- */
    .table-responsive,
    .dataTables_wrapper { max-width: 100%; }
    .table-responsive { -webkit-overflow-scrolling: touch; }
    .table > :not(caption) > * > * { padding: .55rem .6rem; }
    table.dataTable { width: 100% !important; }
    /* DataTables tables that are not in .table-responsive scroll sideways instead of squashing the columns */
    .dataTables_wrapper > table.dataTable { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .dataTables_wrapper > table.dataTable th,
    .dataTables_wrapper > table.dataTable td { white-space: nowrap; }
    /* ... but long free-text columns may wrap */
    .dataTables_wrapper > table.dataTable td.annotation-cell,
    .dataTables_wrapper > table.dataTable td.text-wrap { white-space: normal; min-width: 14rem; }
    /* tables inside modals / ajax-loaded panels */
    .modal-body table:not(.dataTable),
    .offcanvas-body table:not(.dataTable) { display: block; overflow-x: auto; white-space: nowrap; }

    /* DataTables controls: stack, full width, centred paging */
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dt-buttons,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        width: 100%;
        text-align: left !important;
        margin: 0 0 .5rem 0;
    }
    .dataTables_wrapper .dataTables_filter label { width: 100%; display: flex; align-items: center; gap: .5rem; margin: 0; }
    .dataTables_wrapper .dataTables_filter input { flex: 1 1 auto; width: 100% !important; margin-left: 0 !important; }
    .dataTables_wrapper .dataTables_length select { min-width: 4.5rem; }
    .dataTables_wrapper .dataTables_info { text-align: center !important; }
    .dataTables_wrapper .dataTables_paginate { text-align: center !important; white-space: normal; }
    .dataTables_wrapper .dataTables_paginate .paginate_button { padding: .35rem .6rem; }
    /* The Card list moves the search / length controls into #tableControls */
    #tableControls { flex-wrap: wrap; width: 100%; }
    #tableControls > * { flex: 1 1 100%; }

    /* ---- Modals: nearly full-screen, scrollable ---- */
    .modal-dialog { margin: .5rem; max-width: calc(100vw - 1rem); }
    .modal-dialog.modal-xl, .modal-dialog.modal-lg { max-width: calc(100vw - 1rem); }
    .modal-body { overflow-x: auto; }
    .modal-footer { flex-wrap: wrap; gap: .5rem; }
    .modal-footer > * { flex: 1 1 auto; }

    /* ---- Tabs / steps / pills scroll sideways rather than wrapping into a tall block ---- */
    .nav-tabs, .nav-pills { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
    .nav-tabs .nav-link, .nav-pills .nav-link { white-space: nowrap; }
    .bs-stepper .bs-stepper-header { flex-direction: row; overflow-x: auto; }

    /* ---- Media / misc ---- */
    img, video, canvas, svg { max-width: 100%; }
    pre, code { white-space: pre-wrap; word-break: break-word; }
    .apexcharts-canvas, .apexcharts-canvas svg { max-width: 100%; }
    .swal2-popup { width: calc(100vw - 2rem) !important; max-width: 32rem; }

    /* Follow-up ticket "Annotations" table has 8 columns: scroll it (inside its .table-responsive) at a readable width */
    .annotation-table { min-width: 960px; }

    /* Footer */
    .content-footer .container-fluid, .content-footer .container-xxl { text-align: center; }
    .content-footer .d-flex { flex-direction: column; gap: .25rem; }
}

/* ---- Small phones ------------------------------------------------------- */
@media (max-width: 479.98px) {
    .layout-navbar .navbar-nav-right ul.navbar-nav.flex-row { flex-wrap: nowrap; }
    #navAttendanceLabel { display: none !important; }
    .dropdown-style-switcher { display: none; } /* theme switcher is available from tablet/desktop; saves navbar room */
}
