/* === Universal Box Sizing === */
.my-mbm-container,
.my-mbm-container * {
    box-sizing: border-box;
}

/* === CSS Variables & Cấu hình Vùng An Toàn (Safe Area) === */
:root {
    --my-mbm-height: 60px;
    --my-mbm-safe-area-bottom: 0px;
    --my-mbm-app-height: 100%; 
}

/* Hỗ trợ Vùng An Toàn */
@supports (padding-bottom: constant(safe-area-inset-bottom)) {
    :root { --my-mbm-safe-area-bottom: constant(safe-area-inset-bottom); }
}
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    :root { --my-mbm-safe-area-bottom: env(safe-area-inset-bottom); }
}


/* ================================================================== */
/* === GIẢI PHÁP PHONG TỎA, ỔN ĐỊNH VÀ HẠT NHÂN === */
/* ================================================================== */

@media (max-width: 767px) {
    
    /* 1. ỔN ĐỊNH CHIỀU CAO */
    html.my-mbm-html-active {
       height: var(--my-mbm-app-height);
       transition: height 0.1s ease-out; /* Thêm transition để mượt hơn khi resize/đóng popup */
    }
    
    /* Hack bổ sung riêng cho iOS Safari */
    @supports (-webkit-touch-callout: none) {
        html.my-mbm-html-active {
            min-height: -webkit-fill-available;
        }
    }

    /* 2. PHONG TỎA LAYOUT & GIẢI PHÁP HẠT NHÂN (Chỉ áp dụng khi menu HIỂN THỊ) */
    /* Các quy tắc này sẽ bị vô hiệu hóa khi có class .my-mbm-suppressed (xem phần 4c) */
    html.my-mbm-html-active,
    html.my-mbm-html-active body {
        /* A. Chặn tràn ngang */
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
        
        /* B. Chặn hiệu ứng đàn hồi/Bounce */
        overscroll-behavior: none !important;

        /* C. GIẢI PHÁP HẠT NHÂN (Vô hiệu hóa sự can thiệp của Theme) */
        transform: none !important;
        -webkit-transform: none !important;
        perspective: none !important;
        -webkit-perspective: none !important;
        filter: none !important;
        will-change: auto !important;
        
        /* Đảm bảo position là static */
        position: static !important; 
    }

    /* 3. Điều chỉnh Body Padding */
    body.my-mbm-active {
        padding-bottom: calc(var(--my-mbm-height) + var(--my-mbm-safe-area-bottom));
        transition: padding-bottom 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    }
    
    /* ================================================================== */
    /* 4. GIẢI PHÁP NHƯỜNG CHỖ (Manual Suppression) */
    /* ================================================================== */
    
    /* 4a. Ẩn menu khi có lệnh (Class thêm bởi frontend-fix.js) */
    body.my-mbm-suppressed .my-mbm-container {
        transform: translate3d(0, 100%, 0) !important;
        -webkit-transform: translate3d(0, 100%, 0) !important;
        visibility: hidden;
    }
    
    /* 4b. Loại bỏ padding của body khi menu đã ẩn */
    body.my-mbm-active.my-mbm-suppressed {
        padding-bottom: 0 !important;
    }
    
    /* 4c. VÔ HIỆU HÓA PHONG TỎA KHI MENU BỊ ẨN (QUAN TRỌNG) */
    /* Khi menu ẩn đi, chúng ta phải trả lại quyền kiểm soát layout */
    /* cho thư viện Pop-up để nó hoạt động bình thường (ví dụ: khóa cuộn nền). */
    html.my-mbm-html-active.my-mbm-suppressed,
    body.my-mbm-active.my-mbm-suppressed {
        /* Khôi phục lại khả năng kiểm soát Overflow */
        overflow-x: initial !important;
        overflow-y: initial !important;
        
        /* Khôi phục lại Overscroll Behavior mặc định */
        overscroll-behavior: auto !important;

        /* Khôi phục lại Position mặc định */
        position: initial !important;
        
        /* Khôi phục chiều cao tự động */
        height: auto !important;
        min-height: initial !important;
    }
}


/* === Main Container: Cố định vị trí tuyệt đối === */
.my-mbm-container {
    /* CƯỠNG CHẾ VỊ TRÍ VÀ KÍCH THƯỚC */
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    
    width: 100% !important; 
    max-width: 100vw !important;
    margin: 0 !important;

    /* Giữ Z-index cao nhất để đảm bảo ổn định, vì chúng ta đã có cơ chế ẩn đi khi cần. */
    z-index: 2147483647; 

    /* Kích thước rõ ràng */
    height: calc(var(--my-mbm-height) + var(--my-mbm-safe-area-bottom));
    
    /* Đảm bảo padding chỉ áp dụng cho đáy (Vùng an toàn) */
    padding: 0 0 var(--my-mbm-safe-area-bottom) 0 !important; 

    background-color: #ffffff;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    overflow: hidden;

    /* === KỸ THUẬT ỔN ĐỊNH HÓA NÂNG CAO === */
    /* A. Tăng tốc phần cứng và thiết lập vị trí mặc định */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    
    /* B. Ngăn các thao tác chạm */
    touch-action: none; 

    /* C. Hiệu ứng chuyển tiếp (Cho việc ẩn/hiện mượt mà) */
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), visibility 0.3s;
}

/* === List Items (Phần còn lại giữ nguyên) === */
.my-mbm-list {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    list-style: none;
    margin: 0;
    padding: 0;
    height: var(--my-mbm-height);
}

.my-mbm-item {
    flex-grow: 1;
}

.my-mbm-item a {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    padding: 4px 0;
    text-decoration: none;
    color: #4A4A4A;
    font-size: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease;
}

.my-mbm-item a:hover {
    color: #0073aa;
}

.my-mbm-icon {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
    object-fit: contain;
}

.my-mbm-text {
    line-height: 1.2;
}

/* === Ẩn menu trên thiết bị không phải di động === */
@media (min-width: 768px) {
    .my-mbm-container {
        display: none !important;
    }
}