/* ==========================================================================
   MOBILE RESPONSIVE SYSTEM (GUX CSKH CLOUD - NATIVE APP PWA STANDALONE)
   ========================================================================== */

/* Khung html và body toàn màn hình chống tràn ngang và fix chiều cao dvh */
html, body {
    width: 100%;
    min-height: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

#app-container {
    width: 100%;
    min-height: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* Mặc định trên Desktop: Ẩn bottom-nav và fab-btn */
.bottom-nav {
    display: none;
}
.fab-btn {
    display: none;
}
.mobile-only {
    display: none !important;
}

/* KHI TRÊN ĐIỆN THOẠI & TABLET NHỎ (< 768px) */
@media (max-width: 768px) {
    /* Ẩn các thành phần desktop chỉ dùng cho chuột/màn hình to */
    .desktop-only, .desktop-sidebar, .desktop-nav {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* 1. Header Topbar tinh gọn & Xử lý Safe Area Đỉnh (Dynamic Island / Tai thỏ) */
    .top, .app-header {
        padding-top: calc(env(safe-area-inset-top, 20px) + 6px) !important;
        padding-bottom: 8px !important;
        padding-left: 14px !important;
        padding-right: 14px !important;
        height: auto !important;
        min-height: calc(48px + env(safe-area-inset-top, 20px)) !important;
        box-sizing: border-box !important;
        background: var(--cd) !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        border-bottom: 1px solid var(--ln) !important;
    }
    
    .app-title {
        font-size: 15px !important;
        font-weight: 800 !important;
    }

    /* 2. Main Content & Body co giãn vừa khít màn hình, chừa khoảng trống đáy cho Bottom Nav */
    .body {
        min-height: 0 !important;
        flex: 1 !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }

    .app-main {
        padding: 10px 12px calc(80px + max(env(safe-area-inset-bottom, 0px), 16px)) 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 3. Bảng dữ liệu có container cuộn ngang cảm ứng mượt mà */
    .table-responsive-wrapper {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 10px !important;
        border: 1px solid var(--border-color) !important;
        background: var(--bg-card) !important;
        margin-bottom: 16px !important;
    }

    .table-responsive-wrapper table {
        min-width: 750px !important;
        width: 100% !important;
    }

    /* Thẻ Card trên Mobile */
    .mobile-only-cards {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .desktop-only-table {
        display: table !important;
    }

    /* 4. THANH BOTTOM NAVIGATION CỐ ĐỊNH SÁT VIỀN KÍNH ĐÁY IPHONE (APPLE HIG) */
    .bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: auto !important;
        min-height: 52px !important;
        padding-top: 6px !important;
        padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px) !important;
        background: var(--cd) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-top: 1px solid var(--ln) !important;
        z-index: 9999 !important;
        justify-content: space-around !important;
        align-items: center !important;
        box-sizing: border-box !important;
    }

    .bottom-nav .nav-item {
        flex: 1 !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        background: none !important;
        border: none !important;
        color: var(--mu) !important;
        font-size: 11px !important;
        cursor: pointer !important;
        padding: 2px 0 !important;
        gap: 2px !important;
        transition: all 0.15s ease !important;
    }

    .bottom-nav .nav-item.active {
        color: var(--pr) !important;
        font-weight: 700 !important;
    }

    .bottom-nav .nav-item b {
        font-size: 19px !important;
        line-height: 1 !important;
    }

    /* 5. NÚT NỔI TRÒN FAB TẠO CASE (FLOATING ACTION BUTTON) NỔI TRÊN BOTTOM NAV */
    .fab-btn {
        display: flex !important;
        position: fixed !important;
        right: 18px !important;
        bottom: calc(64px + max(env(safe-area-inset-bottom, 0px), 16px)) !important;
        width: 50px !important;
        height: 50px !important;
        border-radius: 50% !important;
        background: var(--pr) !important;
        color: #fff !important;
        font-size: 26px !important;
        font-weight: 300 !important;
        border: none !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 4px 16px rgba(11, 107, 203, 0.45) !important;
        z-index: 9998 !important;
        cursor: pointer !important;
        transition: transform 0.15s ease !important;
    }

    .fab-btn:active {
        transform: scale(0.92) !important;
    }
}
