/* =========================================================
   Shared mobile navigation — drawer layout
   Works with .nav-menu (ePostcode pattern) and .nav-links (eSortcode)
   ========================================================= */

/* Backdrop when menu is open
   MUST sit BELOW the navbar stacking context, otherwise the drawer
   (a child of .navbar) is painted under the overlay, looks blurred,
   and cannot receive clicks. */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(18, 12, 16, 0.48);
    /* no backdrop-filter — blurs the drawer if stacking is wrong */
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

.mobile-nav-overlay.is-visible {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

body.mobile-nav-open {
    overflow: hidden;
}

/* Lift whole navbar above the overlay so the drawer is clickable */
body.mobile-nav-open .navbar,
body.nav-open .navbar {
    z-index: 1100 !important;
    box-shadow: 0 2px 20px rgba(16, 24, 40, 0.08);
}

/* Hamburger affordance */
@media (max-width: 968px) {
    .hamburger {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        padding: 10px;
        border-radius: 12px;
        border: 1px solid rgba(236, 46, 94, 0.2);
        background: rgba(236, 46, 94, 0.06);
        box-sizing: border-box;
        cursor: pointer;
        position: relative;
        z-index: 1102;
        transition: background 0.2s ease, border-color 0.2s ease;
    }

    .hamburger:hover {
        background: rgba(236, 46, 94, 0.12);
        border-color: rgba(236, 46, 94, 0.35);
    }

    .hamburger span {
        display: block;
        width: 100%;
        height: 2.5px;
        background: #EC2E5E;
        border-radius: 2px;
        transition: transform 0.25s ease, opacity 0.2s ease;
        transform-origin: center;
    }

    /*
     * Only ONE close control when the drawer is open: the in-panel button.
     * Hide the external hamburger / toggle so it does not also become an X
     * on top of the drawer (that was showing as two close icons).
     */
    body.mobile-nav-open .hamburger,
    body.nav-open .hamburger,
    body.mobile-nav-open .mobile-menu-toggle,
    body.nav-open .mobile-menu-toggle,
    body.mobile-nav-open #hamburger,
    body.nav-open #hamburger,
    body.mobile-nav-open .mobile-toggle,
    body.nav-open .mobile-toggle,
    body.mobile-nav-open #mobileToggle,
    body.nav-open #mobileToggle,
    body.mobile-nav-open .nav-toggle,
    body.nav-open .nav-toggle,
    body.mobile-nav-open #navToggle,
    body.nav-open #navToggle,
    body.mobile-nav-open #mobileMenuToggle,
    body.nav-open #mobileMenuToggle {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    .mobile-menu-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        border: 1px solid rgba(236, 46, 94, 0.2);
        background: rgba(236, 46, 94, 0.06);
        color: #EC2E5E;
        font-size: 1.15rem;
        cursor: pointer;
        z-index: 1002;
        transition: background 0.2s ease, border-color 0.2s ease;
    }

    .mobile-menu-toggle:hover,
    .mobile-menu-toggle[aria-expanded="true"] {
        background: rgba(236, 46, 94, 0.12);
        border-color: rgba(236, 46, 94, 0.35);
    }

    /* Drawer panel — both menu systems */
    .nav-menu,
    .nav-links {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        left: auto !important;
        width: min(360px, 88vw) !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0 !important;
        background: #ffffff !important;
        box-shadow: -12px 0 40px rgba(16, 24, 40, 0.18) !important;
        border-left: 1px solid #eef0f3 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        z-index: 1101 !important;
        transform: translateX(105%) !important;
        left: auto !important;
        right: 0 !important;
        pointer-events: auto !important;
        visibility: visible !important;
        transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1) !important;
        text-align: left !important;
        list-style: none !important;
    }

    .nav-menu.active,
    .nav-menu.open,
    .nav-links.active,
    .nav-links.open {
        transform: translateX(0) !important;
        left: auto !important;
        right: 0 !important;
        display: flex !important;
        pointer-events: auto !important;
    }

    /* Kill legacy full-width slide-from-left rules that fight the drawer */
    .nav-menu.active {
        left: auto !important;
    }

    /* eAutomate / custom toggle buttons */
    #hamburger,
    .mobile-toggle,
    #mobileToggle,
    .nav-toggle,
    #navToggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        border: 1px solid rgba(236, 46, 94, 0.2);
        background: rgba(236, 46, 94, 0.06);
        color: #EC2E5E;
        cursor: pointer;
        z-index: 1002;
    }

    /* Active state on external toggles is unused while open (toggle is hidden) */

    /* Header strip inside drawer */
    .mobile-nav-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        padding: 1rem 1.15rem;
        border-bottom: 1px solid #eef0f3;
        background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 3;
    }

    .mobile-nav-header .label {
        font-size: 0.78rem;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #8B1538;
    }

    .mobile-nav-close {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        border: 1px solid #e5e7eb;
        background: #fff;
        color: #374151;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 1.1rem;
        transition: background 0.15s ease, color 0.15s ease;
    }

    .mobile-nav-close:hover {
        background: #f3f4f6;
        color: #EC2E5E;
    }

    /* Scrollable link list */
    .mobile-nav-scroll {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0.65rem 0.85rem 1rem;
        list-style: none;
        margin: 0;
    }

    /* When we don't restructure DOM, style direct children */
    .nav-menu > li,
    .nav-links > li {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        order: 0 !important;
        list-style: none !important;
    }

    .nav-menu > li.mobile-nav-header,
    .nav-links > li.mobile-nav-header {
        list-style: none !important;
        display: flex !important;
        flex-shrink: 0;
    }

    .nav-menu > li.mobile-nav-footer,
    .nav-links > li.mobile-nav-footer {
        list-style: none !important;
        margin-top: auto !important;
        flex-shrink: 0;
    }

    .nav-menu .nav-link,
    .nav-menu a.nav-link,
    .nav-links a,
    .nav-links > li > a {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        width: 100% !important;
        min-height: 48px !important;
        padding: 0.75rem 1rem !important;
        margin: 0.15rem 0 !important;
        border-radius: 12px !important;
        color: #1a1a1a !important;
        font-weight: 600 !important;
        font-size: 0.98rem !important;
        text-decoration: none !important;
        line-height: 1.3 !important;
        box-sizing: border-box !important;
        transition: background 0.15s ease, color 0.15s ease !important;
    }

    .nav-menu .nav-link::after,
    .nav-links a::after {
        display: none !important;
    }

    .nav-menu .nav-link:hover,
    .nav-menu .nav-link:focus,
    .nav-links a:hover,
    .nav-links a:focus {
        background: #f8fafc !important;
        color: #EC2E5E !important;
    }

    .nav-menu .mobile-only {
        display: list-item !important;
    }

    .nav-menu .mobile-only,
    .nav-links .mobile-only {
        display: block !important;
    }

    /* CTA buttons in drawer */
    .nav-menu .btn-contact,
    .nav-menu a.btn-contact,
    .nav-links .btn-signup,
    .nav-links a.btn-signup,
    .nav-links a.btn-nav.btn-signup {
        background: linear-gradient(145deg, #EC2E5E 0%, #8B1538 100%) !important;
        color: #fff !important;
        border: none !important;
        border-radius: 999px !important;
        justify-content: center !important;
        margin-top: 0.35rem !important;
        box-shadow: 0 8px 18px rgba(236, 46, 94, 0.22) !important;
        min-height: 48px !important;
        line-height: 1.2 !important;
        padding: 0.85rem 1.25rem !important;
    }

    .nav-menu .btn-portal,
    .nav-menu a.btn-portal,
    .nav-links .btn-portal,
    .nav-links a.btn-portal,
    .nav-links a.btn-nav.btn-portal {
        background: #fff !important;
        color: #EC2E5E !important;
        border: 2px solid rgba(236, 46, 94, 0.45) !important;
        border-radius: 999px !important;
        justify-content: center !important;
        margin-top: 0.35rem !important;
        min-height: 48px !important;
        line-height: 1.2 !important;
        padding: 0.8rem 1.25rem !important;
    }

    .nav-menu .btn-contact:hover,
    .nav-menu .btn-portal:hover,
    .nav-links .btn-signup:hover,
    .nav-links .btn-portal:hover {
        transform: none !important;
    }

    /* Footer with Etellect logo */
    .mobile-nav-footer {
        flex-shrink: 0;
        margin-top: auto;
        padding: 1rem 1.15rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #eef0f3;
        background: #f8fafc;
        text-align: center;
        position: sticky;
        bottom: 0;
        z-index: 3;
    }

    .mobile-nav-footer .mobile-nav-footer-label {
        display: block;
        font-size: 0.68rem;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #9ca3af;
        margin-bottom: 0.55rem;
    }

    .mobile-nav-footer a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.35rem 0.5rem;
        border-radius: 10px;
        transition: background 0.15s ease;
    }

    .mobile-nav-footer a:hover {
        background: #fff;
    }

    .mobile-nav-footer img {
        display: block;
        max-height: 36px;
        width: auto;
        max-width: 160px;
        object-fit: contain;
    }
}

/* Desktop: never show mobile-only chrome */
@media (min-width: 969px) {
    .mobile-nav-overlay,
    .mobile-nav-header,
    .mobile-nav-footer,
    .mobile-nav-close {
        display: none !important;
    }
}
