/* ============================================
   responsive.css — Mobile & Tablet Responsive
   Only @media rules. Desktop stays untouched.
   ============================================ */

/* ──────────────────────────────────────────────
   MOBILE  (max-width: 767.98px)
   ────────────────────────────────────────────── */
@media (max-width: 767.98px) {

    /* --- Content padding for bottom nav --- */
    .main_content_wrapper {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }
    
    /* --- Status bar responsive --- */
    .sb-status-bar {
        left: 0;
        width: 100%;
        bottom: calc(56px + env(safe-area-inset-bottom, 0px)); /* Above mobile bottom nav */
    }

    /* --- Hide secondary navbar icon buttons on mobile, but keep popover elements accessible --- */
    .navbar-secondary-actions {
        display: contents !important;
    }

    .navbar-secondary-actions>.navbar-popover-wrap>.navbar-icon-btn,
    .navbar-secondary-actions>.navbar-icon-btn,
    .navbar-secondary-actions>a.navbar-icon-btn,
    .navbar-secondary-actions>a[class="navbar-icon-btn"],
    .navbar-secondary-actions>button.navbar-icon-btn,
    .navbar-secondary-actions>#fullscreenBtn,
    .navbar-secondary-actions>.theme-toggle-btn {
        display: none !important;
    }

    /* --- Streamlined navbar --- */
    .navbar_container {
        height: 48px;
        min-height: 48px;
        padding: 0 12px;
        padding-top: env(safe-area-inset-top, 0px);
        overflow: visible;
    }

    /* Hide profile name on mobile, show only avatar */
    .navbar-profile-name {
        display: none;
    }

    .navbar-chevron {
        display: none;
    }

    .navbar-profile-btn {
        padding: 4px;
        gap: 0;
    }

    /* Compact icon buttons on mobile */
    .navbar-icon-btn {
        width: 34px;
        height: 34px;
        font-size: 1.05rem;
    }

    .navbar-right {
        gap: 2px;
    }

    .list-detail-wrapper {
        flex-direction: column;
        flex: none;
        gap: 16px;
        min-height: 0;
        overflow: visible !important;
    }

    .main_list_container,
    .element_details_container {
        flex: none;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
    }

    .element_details_container {
        margin-right: 0;
    }

    /* --- Sticky dash cards on mobile --- */
    .students-stats-grid,
    .vehicles-stats-grid,
    .drivers-stats-grid,
    .attendants-stats-grid,
    .stats-grid {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 48px !important;
        z-index: 99 !important;
        background: var(--sb-bg, #f5f6f8);
        padding-top: 4px;
        padding-bottom: 4px;
    }

    /* --- Page title / heading --- */
    .list_page_title {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        font-size: 22px;
        padding: 14px 12px 8px;
    }

    .section-title {
        font-size: 22px !important;
    }

    .search-btn-wrapper {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .student-search-container {
        max-width: 100%;
        left: 0;
        flex: 1 1 100%;
    }

    .student-search-container .search_input {
        width: 100%;
        max-width: 100%;
        font-size: 16px;
    }

    /* --- Tables to Cards (Mobile Native Look) --- */
    .list_wrapper,
    .driver_list_wrapper {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0;
    }

    .scroll-container {
        /* Remove fixed height and inner scroll for single-scroll mobile experience */
        max-height: none;
        overflow-x: hidden;
        overflow-y: visible;
    }

    table,
    .data-table {
        min-width: 100% !important;
    }

    /* Convert tables into compact cards */
    table.data-table {
        display: block;
        background: transparent !important;
        border: none !important;
    }

    table.data-table thead {
        display: none;
        /* Hide table headers */
    }

    table.data-table tbody {
        display: block;
        width: 100%;
    }

    table.data-table tr {
        display: flex;
        flex-direction: column;
        background: var(--sb-surface);
        border: 1px solid var(--sb-border);
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    }

    table.data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border: none !important;
        border-bottom: 1px solid var(--sb-border-light) !important;
        text-align: right;
        min-height: 44px;
        /* Touch target size */
    }

    table.data-table td:last-child {
        border-bottom: none !important;
    }

    /* Use data-label attribute for the key */
    table.data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--sb-text-muted);
        font-size: 13px;
        margin-right: 12px;
        text-align: left;
        flex-shrink: 0;
    }

    /* Ensure flex layouts inside td align correctly on mobile */
    table.data-table td>div {
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    table.data-table td>div.d-flex {
        justify-content: flex-end !important;
    }

    table.data-table td>div.table-actions {
        width: 100%;
        justify-content: space-between !important;
        margin-top: 8px;
    }

    /* Utility to hide secondary columns on mobile to keep cards compact */
    .d-none-mobile {
        display: none !important;
    }

    .list-user-name {
        width: auto;
        max-width: none;
    }

    /* --- Detail panels --- */
    .detail-cont {
        padding: 10px;
    }

    .bus-info {
        max-height: none;
        overflow-y: visible;
        padding: 12px;
    }

    .bus-id {
        width: auto;
        max-width: 100%;
    }

    .grid-container {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .grid-item .label {
        font-size: 14px;
    }

    .grid-item .value {
        font-size: 15px;
    }

    /* --- Forms: full-width inputs --- */
    .form_wrapper {
        max-height: none;
        overflow-y: visible;
    }

    .form-div input,
    .form-div select,
    .form-div textarea,
    .form-control {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px !important;
        /* Prevent iOS auto-zoom */
        min-height: 48px;
        /* Better touch targets */
    }

    /* --- Dashboard (school_top_bar cards) --- */
    .dashboard-title-wrap .d-flex {
        flex-wrap: wrap;
    }

    /* --- Graphs --- */
    .graph-container {
        width: 100%;
        margin: 12px 0;
        padding: 12px;
        border-radius: 12px;
    }

    .graph-wrapper {
        padding: 8px;
    }

    .graph-box {
        height: 250px;
        min-height: 250px;
    }

    .collapse-left {
        font-size: 18px;
    }

    .graph-grid {
        grid-template-columns: 1fr !important;
        padding: 0px;
    }

    /* --- Report dashboard filters --- */
    .report-form-inline,
    #reportForm {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    #reportForm .form-group {
        flex: 1 1 calc(50% - 8px);
        min-width: 120px;
    }

    #reportForm .form-group select,
    #reportForm .form-group input {
        width: 100% !important;
        font-size: 14px;
    }

    .report_container {
        padding: 8px;
    }

    /* --- Filter dropdown (bottom-sheet on mobile) --- */
    .filter-dropdown,
    .toolbar-filter .filter-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 70vh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
        z-index: 1065;
        padding: 16px;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }

    /* Backdrop behind the filter bottom-sheet */
    .filter-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 8;
    }

    .filter-backdrop.show {
        display: block;
    }

    /* --- Navbar popovers: bottom sheet style on mobile --- */
    .navbar-popover {
        position: fixed !important;
        top: auto !important;
        bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 80dvh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0 !important;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15) !important;
        z-index: 1065 !important;
        transform: translateY(0) !important;
    }

    .navbar-popover::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--sb-border-light, #dee2e6);
        border-radius: 100px;
        margin: 10px auto 4px;
    }

    .navbar-support-popover,
    .navbar-broadcast-popover,
    .navbar-profile-popover {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* --- Vehicle details --- */
    .vehicle-doc {
        width: 140px;
        height: 140px;
    }

    /* --- Misc fixed widths --- */
    .view-all-btn {
        width: 180px;
    }

    .elem_card {
        max-height: none;
    }

    /* --- Routes page: search bar on own row, buttons below --- */
    .list_page_title>.d-flex {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .route-search-cont {
        flex: 1 1 100% !important;
        max-width: 100% !important;
        left: 0 !important;
    }

    #search-input {
        width: 100% !important;
        max-width: 100% !important;
        font-size: 16px;
    }

    #search-results {
        width: 100% !important;
    }

    #search-results li {
        width: 100% !important;
    }

    /* Routes & Vehicles: card text wrapping */
    .card-div1,
    .card-div2 {
        flex-wrap: wrap;
        gap: 4px;
    }

    .vehicle-title {
        font-size: 18px;
        margin-left: 10px;
    }

    .card-link {
        font-size: 14px;
    }

    /* --- Vehicle list cards --- */
    .list_wrapper {
        max-height: none;
    }

    /* --- Report form: wrap inputs into rows, keep all visible --- */
    .dashboard-title-wrap.d-flex,
    .dashboard-title-wrap .d-flex {
        flex-wrap: wrap !important;
    }

    #reportForm {
        flex-wrap: wrap !important;
        gap: 8px;
        width: 100%;
    }

    #reportForm .form-group {
        flex: 1 1 calc(50% - 8px);
        min-width: calc(50% - 8px);
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    #reportForm .form-group select,
    #reportForm .form-group input[type="date"] {
        width: 100% !important;
    }

    #reportForm button[type="submit"] {
        flex: 0 0 auto;
    }

    /* --- Report content tables --- */
    .report_container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .report_container table {
        min-width: 600px;
    }

    .export-top-section {
        flex-direction: column;
        gap: 8px;
    }

    .export-buttons {
        display: flex;
        gap: 8px;
    }

    /* --- Track Vehicle: map --- */
    .map-section {
        min-height: 300px;
        max-height: none;
        height: 50vh;
    }

    .content-grid {
        min-height: auto;
    }

    .track-screen-header-wrapper {
        flex-direction: column;
    }

    /* --- Maintenance stat cards --- */
    .m-header {
        flex-direction: column;
        align-items: flex-start;
    }

    /* --- Map container (dashboard) --- */
    #dash_map {
        width: 100% !important;
    }

    .checkbox-group {
        height: auto;
        max-height: 100px;
    }

    /* --- Route details: buttons wrap on mobile --- */
    .bus-info .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 8px;
    }

    .bus-info .d-flex.justify-content-between>div {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .bus-info .btn {
        flex: 1 1 auto;
        white-space: nowrap;
        font-size: 13px;
        padding: 6px 12px;
        text-align: center;
    }

    .detail-btn-wrap {
        margin-top: 4px;
    }

    /* --- Edit path / route action buttons --- */
    .route-action-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .toolbar-btn {
        font-size: 12px;
        padding: 6px 10px;
    }

    /* --- Dashboard stats horizontal scroll on mobile --- */
    .dashboard-stats-grid {
        display: flex !important;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 10px;
        padding-bottom: 6px;
        scrollbar-width: none;
    }

    .dashboard-stats-grid::-webkit-scrollbar {
        display: none;
    }

    .dashboard-stats-item {
        flex: 0 0 auto;
        min-width: 140px;
        scroll-snap-align: start;
    }

    /* --- Toast positioning for bottom nav --- */
    .sb-toast-container {
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        top: auto;
        right: 12px;
        left: 12px;
    }

    /* --- Modals as Bottom Sheets --- */
    .modal-dialog {
        display: flex;
        align-items: flex-end;
        min-height: 100%;
        margin: 0;
    }

    /* --- Fare Calculator & Fare Zones --- */
    .fc-split,
    .fz-split {
        display: flex !important;
        flex-direction: column-reverse;
        min-height: auto !important;
    }

    .fc-left,
    .fz-left {
        border-right: none !important;
        border-top: 1px solid var(--sb-border-light);
        padding: 16px 12px !important;
        overflow-y: visible !important;
    }

    .fc-right,
    .fz-right {
        min-height: 350px;
        height: auto !important;
    }

    #fareMap,
    #zoneMap {
        min-height: 350px !important;
        height: 350px !important;
    }

    .fc-loc-grid,
    .fz-form-grid {
        grid-template-columns: 1fr !important;
    }

    .fc-passenger-row {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .fz-form-col-full {
        grid-column: span 1 !important;
    }

    .modal-content {
        border-radius: 20px 20px 0 0;
        border: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }


    /* --- Keep logout/delete modals centered (don't make them bottom sheets) --- */
    .logout-modal-dialog {
        align-items: center !important;
        margin: 1.75rem auto !important;
        min-height: calc(100% - 3.5rem) !important;
    }

    .logout-modal-content {
        border-radius: 16px !important;
        padding-bottom: 24px !important;
    }
}


/* ──────────────────────────────────────────────
   TABLET  (768px – 1024px)
   ────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1024px) {

    /* --- List + Detail: stack vertically --- */
    .list-detail-wrapper {
        flex-direction: column;
        gap: 16px;
    }

    .main_list_container,
    .element_details_container {
        flex: none;
        width: 100% !important;
        max-width: 100% !important;
    }

    .element_details_container {
        margin-right: 0;
    }

    /* --- Page title --- */
    .list_page_title {
        flex-wrap: wrap;
        gap: 10px;
        font-size: 26px;
    }

    .search-btn-wrapper {
        flex-wrap: wrap;
        gap: 8px;
    }

    /* --- Tables --- */
    .list_wrapper,
    .driver_list_wrapper {
        width: 100% !important;
        max-width: 100% !important;
    }

    .scroll-container {
        overflow-x: auto;
    }

    /* --- Detail panels --- */
    .bus-info {
        max-height: none;
    }

    .grid-container {
        grid-template-columns: 1fr 1fr;
    }

    /* --- Forms --- */
    .form_wrapper {
        max-height: none;
    }

    /* --- Graphs --- */
    .graph-container {
        width: 100%;
        margin: 12px 0;
    }

    /* --- Filter dropdown --- */
    .filter-dropdown,
    .toolbar-filter .filter-dropdown {
        width: 380px;
    }



    /* --- Routes page --- */
    .route-search-cont {
        max-width: 100%;
        left: 0;
    }

    #search-input {
        width: 100%;
        max-width: 100%;
    }

    .elem_card {
        max-height: none;
    }

    .vehicle-title {
        font-size: 20px;
    }


    /* --- Report form --- */
    #reportForm {
        flex-wrap: wrap !important;
        gap: 8px;
    }

    #reportForm .form-group {
        flex: 1 1 calc(50% - 8px);
        min-width: 140px;
    }

    .report_container {
        overflow-x: auto;
    }

    .report_container table {
        min-width: 600px;
    }

    /* --- Track Vehicle map --- */
    .map-section {
        max-height: none;
        height: 50vh;
    }

    /* --- Sticky Pagination on Mobile --- */
    nav:has(> .pagination),
    .pagination-wrapper,
    nav:has(> ul.pagination),
    nav[aria-label*="pagination" i] {
        position: sticky;
        bottom: 0;
        background: var(--sb-surface, #ffffff);
        padding: 12px 0;
        z-index: 99;
        border-top: 1px solid var(--sb-border-light, #eee);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
        margin-top: auto !important;
        margin-bottom: 0 !important;
        width: 100%;
        left: 0;
    }
    
    .pagination {
        margin-bottom: 0 !important;
    }

}