/* =============================================================
   MKS Adaptive Header Menu (Menu Chính & Menu Di Động Tự Động)
   matkhau.vn | Design System Synchronization (Inter, #fb3c59)
   ============================================================= */

/* ─── Wrapper chính ──────────────────────────────────────── */
.mks-header-nav-wrapper {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    position: relative;
    box-sizing: border-box;
}

.mks-header-nav-wrapper *,
.mks-header-nav-wrapper *::before,
.mks-header-nav-wrapper *::after {
    box-sizing: inherit;
}

/* ─── 1. MENU CHÍNH DESKTOP (1 HÀNG NGANG) ────────────────── */
.mks-desktop-nav {
    display: flex;
    align-items: center;
    max-width: 100%;
}

.mks-desktop-nav-list {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.mks-d-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative;
}

.mks-d-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 500;
    color: #1e293b !important;
    text-decoration: none !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    line-height: 1.3;
    cursor: pointer;
    user-select: none;
}

.mks-d-link:hover {
    background: #f1f5f9;
    color: #fb3c59 !important;
    transform: translateY(-1px);
}

.mks-d-icon {
    font-size: 14.5px;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: color 0.2s ease;
}

.mks-d-link:hover .mks-d-icon {
    color: #fb3c59;
}

.mks-d-arrow-icon {
    color: #94a3b8;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
    margin-left: 2px;
}

.mks-d-dropdown:hover .mks-d-arrow-icon {
    transform: rotate(180deg);
    color: #fb3c59;
}

/* ─── Dropdown Menu Cấp 2 của Desktop (Công Cụ) ──────────── */
.mks-d-dropdown {
    position: relative;
}

.mks-d-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 195px;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 14px 35px -8px rgba(15, 23, 42, 0.16), 0 0 0 1px rgba(0, 0, 0, 0.04);
    padding: 6px;
    z-index: 999999;
    list-style: none !important;
    margin: 0 !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(6px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

/* Cầu đệm chuột tránh bị mất hover khi rê chuột vào dropdown */
.mks-d-dropdown-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 0;
    width: 100%;
    height: 12px;
}

.mks-d-dropdown:hover .mks-d-dropdown-menu,
.mks-d-dropdown:focus-within .mks-d-dropdown-menu,
.mks-d-dropdown.is-open .mks-d-dropdown-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.mks-d-sub-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mks-d-sub-link {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #334155 !important;
    text-decoration: none !important;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.mks-d-sub-link:hover {
    background: #fff1f2;
    color: #fb3c59 !important;
    transform: translateX(3px);
}

.mks-d-sub-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: #f8fafc;
    color: #64748b;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.mks-d-sub-link:hover .mks-d-sub-icon {
    color: #fb3c59;
    background: #ffffff;
}

/* ─── 2. NÚT MENU DI ĐỘNG (3 GẠCH THUẦN TÚY) ─────────────── */
.mks-mobile-nav-toggle-wrap {
    display: none;
    align-items: center;
    justify-content: center;
    position: relative;
    vertical-align: middle;
}

.mks-mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    cursor: pointer;
    padding: 0;
    position: relative;
    z-index: 999990;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.mks-mobile-menu-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.mks-mobile-menu-btn:active {
    background: #f1f5f9;
    transform: translateY(0);
}

/* 3 gạch hamburger */
.mks-burger-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4.5px;
    width: 22px;
    height: 22px;
}

.mks-burger-bar {
    width: 20px;
    height: 2.2px;
    background: #0f172a;
    border-radius: 2px;
    transition: all 0.2s ease;
}

/* ─── 3. QUY TẮC HIỂN THỊ (ADAPTIVE SWITCHING) ───────────── */
/* Mặc định trên màn hình < 992px: Sử dụng Mobile Menu */
@media (max-width: 991px) {
    .mks-desktop-nav {
        display: none !important;
    }
    .mks-mobile-nav-toggle-wrap {
        display: inline-flex !important;
    }
}

/* Trên màn hình >= 992px: Mặc định hiển thị Desktop Menu 1 hàng */
@media (min-width: 992px) {
    .mks-desktop-nav {
        display: flex;
    }
    .mks-mobile-nav-toggle-wrap {
        display: none;
    }

    /* KHI KHÔNG THỂ HIỂN THỊ 1 HÀNG: Tự động chuyển sang Mobile Menu */
    .mks-header-nav-wrapper.mks-use-mobile-mode .mks-desktop-nav {
        display: none !important;
    }
    .mks-header-nav-wrapper.mks-use-mobile-mode .mks-mobile-nav-toggle-wrap {
        display: inline-flex !important;
    }
}

/* ─── 4. BACKDROP TOÀN MÀN HÌNH ──────────────────────────── */
.mks-mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999980;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.3s ease;
}

.mks-mobile-menu-backdrop.is-active {
    opacity: 1;
    visibility: visible;
}

/* ─── 5. POPUP MENU DỌC (TỪ ĐẦU ĐIỆN THOẠI TRỞ XUỐNG) ───── */
.mks-mobile-menu-popup {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    max-height: 100vh;
    max-height: 100dvh;
    background: #ffffff;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 25px 60px -12px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(0, 0, 0, 0.04);
    padding: 16px 20px 24px;
    z-index: 999995;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-100%);
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease, visibility 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
}

.mks-mobile-menu-popup *,
.mks-mobile-menu-popup *::before,
.mks-mobile-menu-popup *::after {
    box-sizing: inherit;
}

.mks-mobile-menu-popup.is-active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Popup Header */
.mks-mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 14px;
    margin-bottom: 12px;
    border-bottom: 1px solid #f1f5f9;
}

.mks-menu-header-title {
    font-size: 15px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #0f172a;
}

/* Nút hình tròn có chữ X bên trong trên Header Popup để tắt */
.mks-popup-close-circle-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fee2e2;
    border: 1.5px solid #fecaca;
    color: #fb3c59;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(251, 60, 89, 0.15);
    padding: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

.mks-popup-close-circle-btn:hover {
    background: #fb3c59;
    border-color: #fb3c59;
    color: #ffffff;
    transform: rotate(90deg);
}

.mks-popup-close-circle-btn:active {
    transform: scale(0.95) rotate(90deg);
}

/* ─── Danh Sách Menu Dọc Trên Mobile ─────────────────────── */
.mks-mobile-nav-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mks-nav-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mks-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    color: #1e293b !important;
    text-decoration: none !important;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
}

.mks-nav-link:hover {
    background: #f8fafc;
    color: #fb3c59 !important;
    transform: translateX(3px);
}

.mks-nav-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: #f1f5f9;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
    transition: all 0.18s ease;
}

.mks-nav-link:hover .mks-nav-icon {
    background: #fff1f2;
    color: #fb3c59;
}

.mks-nav-text {
    flex: 1;
    line-height: 1.3;
}

/* ─── Menu Cấp 2 Trên Mobile (Công Cụ) - Luôn hiển thị ─── */
.mks-submenu-header {
    display: flex;
    align-items: center;
    border-radius: 10px;
}

.mks-submenu-label {
    flex: 1;
    font-weight: 600 !important;
    cursor: default;
}

.mks-submenu-label:hover {
    background: transparent !important;
    color: #1e293b !important;
    transform: none !important;
}

/* Submenu list luôn hiển thị trên mobile */
.mks-submenu-list {
    display: flex !important;
    list-style: none !important;
    margin: 4px 0 8px 18px !important;
    padding: 6px 8px 8px 12px !important;
    background: #f8fafc;
    border-left: 2.5px solid #fb3c59;
    border-radius: 0 10px 10px 0;
    flex-direction: column;
    gap: 4px;
}

.mks-sub-item {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mks-sub-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 14.5px;
    font-weight: 500;
    color: #475569 !important;
    text-decoration: none !important;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.mks-sub-link:hover {
    background: #ffffff;
    color: #fb3c59 !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transform: translateX(3px);
}

.mks-sub-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: #ffffff;
    color: #64748b;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.mks-sub-link:hover .mks-sub-icon {
    color: #fb3c59;
    background: #fff1f2;
}

.mks-sub-text {
    flex: 1;
}

/* Khóa cuộn trang khi menu mở */
body.mks-mobile-menu-opened {
    overflow: hidden !important;
}
