/**
 * Fleet CRM Apex v3 — Mobile & Tablet Responsive Architecture
 * Prevents UI horizontal jamming, enables Table-to-Card views and bottom navigation.
 */

/* Desktop only components */
.desktop-only {
    display: flex;
}
.mobile-only {
    display: none;
}

/* ----------------------------------------------------
   RESPONSIVE BREAKPOINTS (Tablets & Mobile: <992px)
---------------------------------------------------- */
@media screen and (max-width: 992px) {
    .desktop-only {
        display: none !important;
    }
    .mobile-only {
        display: flex !important;
    }

    /* Collapse Desktop Sidebar entirely to off-canvas on mobile */
    aside.apex-sidebar {
        position: fixed;
        top: 0;
        left: -270px;
        height: 100vh;
        z-index: 150;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.7);
        transition: left var(--transition-smooth);
    }
    aside.apex-sidebar.mobile-open {
        left: 0;
    }

    /* Sidebar Mobile Backdrop */
    .apex-sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 140;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-fast);
    }
    .apex-sidebar-backdrop.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Main Workspace on Mobile */
    main.apex-main {
        padding-bottom: 68px; /* Safe space for Bottom Navigation */
    }

    header.apex-header {
        padding: 0 16px;
        height: 58px;
    }

    .apex-header-search {
        width: 200px;
    }

    #apex-content {
        padding: 16px;
        gap: 16px;
    }

    /* ----------------------------------------------------
       TABLE-TO-CARD SWITCHER (Mobile Card Mode)
    ---------------------------------------------------- */
    .apex-table-cards,
    .apex-table,
    .apex-table-cards tbody,
    .apex-table tbody,
    .apex-table-cards tr,
    .apex-table tr,
    .apex-table-cards td,
    .apex-table td {
        display: block;
        width: 100%;
        min-width: 0 !important;
        white-space: normal !important;
    }

    .balance-grid,
    .dashboard-split-grid {
        grid-template-columns: 1fr !important;
    }



    .apex-table-cards thead,
    .apex-table thead {
        display: none; /* Hide multi-column headers on mobile */
    }

    .apex-table-cards tr,
    .apex-table tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        margin-bottom: 12px;
        padding: 14px;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .apex-table-cards td,
    .apex-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 4px 0;
        border: none;
        font-size: 13px;
    }

    .apex-table-cards td::before,
    .apex-table td::before {
        content: attr(data-label);
        font-size: 11.5px;
        font-weight: 700;
        color: var(--text-sub);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .apex-table-cards td.card-primary-row {
        justify-content: flex-start;
        font-size: 15px;
        font-weight: 800;
        color: #fff;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        padding-bottom: 8px;
        margin-bottom: 4px;
    }
    .apex-table-cards td.card-primary-row::before {
        display: none;
    }

    .apex-table-cards td.card-actions-row {
        border-top: 1px solid rgba(255, 255, 255, 0.06);
        padding-top: 10px;
        margin-top: 6px;
        justify-content: flex-end;
        gap: 8px;
    }
    .apex-table-cards td.card-actions-row::before {
        display: none;
    }
}

/* ----------------------------------------------------
   MOBILE BOTTOM NAVIGATION BAR
---------------------------------------------------- */
nav.apex-mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(9, 14, 26, 0.94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    z-index: 120;
    padding: 0 10px;
    align-items: center;
    justify-content: space-around;
}

@media screen and (max-width: 992px) {
    nav.apex-mobile-bottom-nav {
        display: flex;
    }
}

.apex-bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
    flex: 1;
    height: 100%;
    position: relative;
    transition: color var(--transition-fast);
}

.apex-bottom-item i {
    font-size: 18px;
    transition: transform var(--transition-fast);
}

.apex-bottom-item.active {
    color: #38bdf8;
}
.apex-bottom-item.active i {
    transform: translateY(-2px);
}

.apex-bottom-badge {
    position: absolute;
    top: 6px;
    right: 22%;
    background: #ef4444;
    color: #fff;
    font-size: 9.5px;
    font-weight: 900;
    padding: 1px 5px;
    border-radius: 10px;
    line-height: 1.2;
}

/* ----------------------------------------------------
   BOTTOM SHEET DRAWER FOR MOBILE (<768px)
---------------------------------------------------- */
@media screen and (max-width: 768px) {
    .apex-drawer {
        width: 100vw;
        height: 88vh;
        top: auto;
        bottom: -95vh;
        right: 0;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-top: 1px solid var(--border-highlight);
        transition: bottom var(--transition-smooth);
    }
    .apex-drawer.active {
        bottom: 0;
        right: 0;
    }

    .apex-drawer-header {
        position: relative;
        padding-top: 26px;
    }

    /* Swipe pull handle indicator */
    .apex-drawer-header::before {
        content: '';
        position: absolute;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: 44px;
        height: 4px;
        border-radius: 4px;
        background: rgba(255, 255, 255, 0.25);
    }

    /* Modal Mobile Bottom Sheet */
    .apex-modal-card {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-top: auto;
        border-radius: 18px 18px 0 0 !important;
        max-height: 85vh !important;
    }
}

