/* ========================================
   OPTIMIZED NAVIGATION MENU CSS
   ======================================== */

:root {
    --primary-bg: #762c21;
    --primary-color: #f4eedf;
    --text-color: #fff;
    --black: #020202;
    --transition: 0.4s ease;
    --transition-slow: 0.5s ease;
    --shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    --mobile-padding: 6%;
    --desktop-padding: 12%;
}

/* ========================================
   BASE STYLES
   ======================================== */
.menuMain {
    background: var(--primary-bg);
    font-family: 'Labor Union', sans-serif;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 300;
    padding: 0 var(--desktop-padding);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.menuMain > a {
    display: flex;
    align-items: center;
}

.menuMain > a > img {
    width: 210px;
    margin: 12px;
    transition: transform var(--transition);
    will-change: transform;
}

.menuMain > a > img:hover {
    transform: scale(1.05);
}

/* ========================================
   HAMBURGER MENU
   ======================================== */
.menu-toggle {
    display: none;
    font-family: 'Labor Union', sans-serif;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 350;
    flex-shrink: 0;
}

.menu-toggle span {
    display: block;
    width: 100%;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 2px;
    transition: all var(--transition);
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* ========================================
   UTILITY ICONS
   ======================================== */
.header__utils {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-shrink: 0;
}

.util__icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition);
    text-decoration: none;
    will-change: transform;
}

.util__icon:hover {
    transform: scale(1.1);
}

.util__icon img {
    width: 24px;
    height: 24px;
    display: block;
}

.util__cart {
    position: relative;
}

.util__badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background-color: #f4eedf;
    color: black;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    transition: all 0.3s ease;
}

.util__profile {
    position: relative;
}

.util__tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--black);
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    padding: 10px 15px;
    white-space: nowrap;
    box-shadow: var(--shadow);
    z-index: 400;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

.cart-updated {
    animation: cartPulse 0.6s ease;
}

@keyframes cartPulse {
    0% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.3);
        background-color: #ffff;
    }
    50% {
        transform: scale(1.1);
    }
    75% {
        transform: scale(1.25);
    }
    100% {
        transform: scale(1);
        background-color: #ffff;
    }
}

.util__tooltip p {
    color: var(--text-color);
    margin: 0;
}

.util__profile:hover .util__tooltip,
.util__profile:focus-within .util__tooltip {
    display: block;
    opacity: 1;
}

/* Hide mobile elements by default */
.mobile-menu-parent,
.sidebar-overlay {
    display: none;
}

/* ========================================
   DESKTOP NAVIGATION (769px+)
   ======================================== */
@media (min-width: 769px) {
    .desktop-menu {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        gap: clamp(30px, 4vw, 50px);
    }

    .desktop-menu li {
        position: relative;
        font-size: clamp(16px, 1.2vw, 18px);
    }

    .desktop-menu a {
        text-decoration: none;
        color: var(--text-color);
        transition: color var(--transition-slow);
        padding: 10px 0;
        display: block;
        font-weight: 500;
        position: relative;
    }

    /* Hover underline for regular links */
    .desktop-menu li:not(.dropdown) a::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 0;
        height: 2px;
        background-color: var(--primary-color);
        transition: width var(--transition-slow);
    }

    .desktop-menu li:not(.dropdown) a:hover {
        color: var(--primary-color);
    }

    .desktop-menu li:not(.dropdown) a:hover::after {
        width: 100%;
    }

    /* Shop dropdown link */
    .desktop-menu .shop-link {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        cursor: pointer;
        transition: color var(--transition-slow);
    }
    
    .desktop-menu .shop-link:hover {
        color: var(--primary-color);
    }

    .desktop-menu .shop-link::after {
        content: '▼';
        font-size: 0.6em;
        transition: transform var(--transition-slow);
        margin-left: 5px;
    }

    /* Dropdown menu */
    .desktop-menu .dropdown ul {
        position: absolute;
        top: 100%;
        left: 0;
        background: var(--primary-bg);
        border: 1px solid var(--primary-color);
        border-radius: 6px;
        list-style: none;
        margin: 5px 0 0;
        padding: 8px 0;
        z-index: 1000;
        min-width: 200px;
        box-shadow: var(--shadow);
        
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: opacity var(--transition-slow), 
                    transform var(--transition-slow), 
                    visibility 0s var(--transition-slow);
        will-change: transform, opacity;
    }

    .desktop-menu .dropdown ul li {
        font-size: 14px;
    }

    .desktop-menu .dropdown ul a {
        padding: 10px 20px;
        color: var(--text-color);
        white-space: nowrap;
        font-weight: 400;
        transition: background var(--transition-slow), color var(--transition-slow);
        position: relative;
    }

    .desktop-menu .dropdown ul a::after {
        content: '';
        position: absolute;
        bottom: 8px;
        left: 20px;
        width: 0;
        height: 1px;
        background-color: var(--primary-color);
        transition: width var(--transition-slow);
    }

    .desktop-menu .dropdown ul a:hover {
        background: rgba(118, 44, 33, 0.1);
        color: var(--primary-color);
    }

    .desktop-menu .dropdown ul a:hover::after {
        width: calc(100% - 40px);
    }

    /* Active dropdown */
    .desktop-menu .dropdown.active > ul {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        transition-delay: 0s;
    }

    .desktop-menu .dropdown.active .shop-link::after {
        transform: rotate(180deg);
    }
}

/* ========================================
   MOBILE NAVIGATION (≤768px)
   ======================================== */
@media (max-width: 768px) {
    body.menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    /* Mobile header - FIXED GRID */
    .menuMain {
        padding: 10px var(--mobile-padding);
        display: grid;
        grid-template-columns: auto 1fr auto;
        gap: 10px;
        align-items: center;
        min-height: 60px;
    }

    .menu-toggle {
        display: flex;
        grid-column: 1;
    }

    .menuMain > a {
        grid-column: 2;
        justify-self: center;
        min-width: 0; /* Allow shrinking */
    }

    .menuMain > a > img {
        width: 100%;
        max-width: 140px;
        min-width: 80px;
        height: auto;
        margin: 0;
    }

    .header__utils {
        grid-column: 3;
        justify-self: end;
        gap: 10px;
    }
    
    .util__icon {
        padding: 4px;
    }

    .util__icon img {
        width: 20px;
        height: 20px;
    }

    .util__badge {
        top: -6px;
        right: -6px;
        font-size: 10px;
        min-width: 16px;
        height: 16px;
    }

    .util__tooltip {
        right: -10px;
        font-size: 0.85rem;
        padding: 8px 12px;
    }

    /* Hide desktop menu */
    .desktop-menu {
        display: none;
    }

    /* Mobile menu container - FIXED */
    .mobile-menu-parent {
        display: block;
        position: fixed;
        top: 60px; /* Match min-height of menuMain */
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px); /* Dynamic viewport height for mobile browsers */
        overflow-y: auto;
        overflow-x: hidden;
        background-color: var(--primary-bg);
        list-style: none;
        margin: 0;
        padding: 0;
        border-top: 2px solid var(--primary-color);
        transform: translateX(-100%);
        transition: transform var(--transition-slow);
        z-index: 200;
        will-change: transform;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    .mobile-menu-parent.active {
        transform: translateX(0);
    }

    .mobile-menu-parent > li {
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    }

    .mobile-menu-parent > li > a {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px var(--mobile-padding);
        color: var(--text-color);
        text-decoration: none;
        font-size: clamp(0.9rem, 3vw, 1rem);
        font-weight: 600;
        text-transform: uppercase;
        transition: background var(--transition-slow), color var(--transition-slow);
        -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
    }

    .mobile-menu-parent > li > a:active {
        background: rgba(118, 44, 33, 0.1);
    }

    /* Mobile dropdown */
    .mobile-menu-parent .shop-link-mobile {
        position: relative;
    }

    .mobile-menu-parent .shop-link-mobile::after {
        content: '▼';
        margin-left: 10px;
        font-size: 0.8rem;
        color: var(--primary-color);
        font-weight: 400;
        transition: transform var(--transition-slow);
    }

    .mobile-menu-parent .dropdown.active .shop-link-mobile::after {
        transform: rotate(180deg);
    }

    .mobile-menu-parent .dropdown > ul {
        list-style: none;
        margin: 0;
        padding: 0;
        background: rgba(0, 0, 0, 0.15);
        overflow: hidden;
        max-height: 0;
        transition: max-height var(--transition-slow) ease;
    }

    .mobile-menu-parent .dropdown.active > ul {
        max-height: 1000px; /* Increased for more items */
    }

    .mobile-menu-parent .dropdown > ul > li {
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    }

    .mobile-menu-parent .dropdown > ul > li:last-child {
        border-bottom: none;
    }

    .mobile-menu-parent .dropdown > ul > li > a {
        display: block;
        padding: 14px var(--mobile-padding) 14px calc(var(--mobile-padding) + 4%);
        color: var(--text-color);
        text-decoration: none;
        font-size: clamp(0.85rem, 2.5vw, 0.9rem);
        font-weight: 500;
        text-transform: none;
        transition: background var(--transition-slow), color var(--transition-slow);
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-parent .dropdown > ul > li > a:active {
        background: rgba(118, 44, 33, 0.2);
        color: var(--primary-color);
    }

    /* Overlay - FIXED */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 60px; /* Match menuMain height */
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-slow);
        z-index: 150;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .menuMain {
        padding: 8px 4%;
        gap: 8px;
    }

    .menuMain > a > img {
        max-width: 100px;
    }

    .header__utils {
        gap: 8px;
    }

    .util__icon img {
        width: 18px;
        height: 18px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus states for keyboard navigation */
.desktop-menu a:focus-visible,
.mobile-menu-parent a:focus-visible,
.util__icon:focus-visible,
.menu-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}