/* File: css/components/header.css */

/*
 * ============================================
 *  HEADER & NAVIGATION STYLES
 * ============================================
 *
 * The header contains our main navigation bar.
 * It sticks to the top of the page as you scroll ("sticky nav").
 *
 * Features:
 * - Transparent on page load, gains background on scroll
 * - Responsive: collapses to hamburger menu on mobile
 * - Glassmorphism effect when scrolled
 * - Smooth transitions for all state changes
 */


/* ---- Header Container ---- */
.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    z-index: 1000;
    transition: all var(--transition-base);
}

/*
 * When the user scrolls down, JavaScript adds the "scrolled" class.
 * This triggers the glassmorphism background effect.
 */
.header.scrolled {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}


/* ---- Nav Layout ---- */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}


/* ---- Logo ---- */
.nav__logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    z-index: calc(var(--z-sticky) + 1);
    /* z-index ensures logo stays above mobile menu overlay */
}

.logo-text {
    font-family: var(--font-mono);
    font-size: var(--fs-xl);
    font-weight: 700;
    color: var(--accent-primary);
    transition: color var(--transition-fast);
    /* The angle brackets < /> give it a "code" feel */
}

.nav__logo:hover .logo-text {
    color: var(--text-heading);
}


/* ---- Desktop Menu ---- */
.nav__menu {
    display: flex;
    align-items: center;
    gap: var(--space-xl);
}

.nav__link {
    position: relative;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--space-xs) 0;
    transition: color var(--transition-fast);
    font-family: var(--font-mono);
}

.nav__link:hover,
.nav__link.active {
    color: var(--accent-primary);
}

/* Animated underline on hover */
.nav__link::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    transition: width var(--transition-base);
}
.nav__link:hover::after,
.nav__link.active::after {
    width: 100%;
}


/* ---- Nav Action Buttons (theme toggle, search, cart) ---- */
.nav__actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.nav__action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    position: relative;
}

.nav__action-btn:hover {
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}


/* ---- Theme Toggle Icon Switching ---- */
/*
 * In dark mode: show sun icon (click to go light)
 * In light mode: show moon icon (click to go dark)
 */
[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

.theme-toggle {
    overflow: hidden;
}

.theme-icon {
    transition: transform var(--transition-bounce);
}

.theme-toggle:hover .theme-icon {
    transform: rotate(15deg);
}


/* ---- Shopping Cart Badge ---- */
.cart-count {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--accent-primary);
    color: var(--text-on-accent);
    font-size: 0.625rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}


/* ---- Hamburger Menu Button (Mobile) ---- */
.nav__toggle {
    display: none;           /* Hidden on desktop */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    gap: 5px;
    z-index: calc(var(--z-sticky) + 1);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.nav__toggle:hover {
    background: var(--bg-tertiary);
}

.hamburger-line {
    display: block;
    width: 22px;
    height: 2px;
    background-color: var(--text-primary);
    border-radius: var(--radius-full);
    transition: all var(--transition-base);
    transform-origin: center;
}

/* Hamburger → X animation when menu is open */
.nav__toggle.active .hamburger-line:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.nav__toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.nav__toggle.active .hamburger-line:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}


/* ==========================================
   RESPONSIVE — MOBILE NAVIGATION
   ========================================== */

@media (max-width: 768px) {
    /* Show hamburger button */
    .nav__toggle {
        display: flex;
    }

    /* Hide search trigger on mobile (we'll use a different UX) */
    .search-trigger {
        display: none;
    }

    /* Mobile menu: full-screen overlay */
    .nav__menu {
        position: fixed;
        top: 0;
        right: -100%;         /* Start off-screen to the right */
        width: 100%;
        height: 100vh;
        height: 100dvh;       /* dvh = dynamic viewport height (accounts for mobile browser chrome) */
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: var(--space-2xl);
        background: var(--bg-primary);
        transition: right var(--transition-slow);
        z-index: var(--z-sticky);
    }

    /* When menu is open */
    .nav__menu.active {
        right: 0;
    }

    .nav__menu .nav__link {
        font-size: var(--fs-xl);
    }

    /* Stagger animation for menu items */
    .nav__menu.active li {
        animation: navItemFadeIn 0.4s ease forwards;
        opacity: 0;
    }
    .nav__menu.active li:nth-child(1) { animation-delay: 0.1s; }
    .nav__menu.active li:nth-child(2) { animation-delay: 0.15s; }
    .nav__menu.active li:nth-child(3) { animation-delay: 0.2s; }
    .nav__menu.active li:nth-child(4) { animation-delay: 0.25s; }
    .nav__menu.active li:nth-child(5) { animation-delay: 0.3s; }
    .nav__menu.active li:nth-child(6) { animation-delay: 0.35s; }
    .nav__menu.active li:nth-child(7) { animation-delay: 0.4s; }

    @keyframes navItemFadeIn {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ==========================================
   NAVIGATION CLICK FIX - Emergency Override
   ========================================== */

/* Ensure nav links are always clickable */
.nav__link,
.nav__menu a,
.nav__item a {
    pointer-events: auto !important;
    cursor: pointer !important;
    position: relative;
    z-index: 1000 !important;
}

/* Ensure the menu container doesn't block */
.nav__menu {
    pointer-events: auto !important;
}

/* Remove any invisible overlays that might block clicks */
.nav__menu::before,
.nav__menu::after {
    pointer-events: none !important;
}

/* Ensure list items don't interfere */
.nav__item {
    pointer-events: auto !important;
    position: relative;
    z-index: 1001 !important;
}

/* Mobile menu specific fixes */
@media (max-width: 768px) {
    .nav__menu {
        pointer-events: auto !important;
        z-index: 999 !important;
    }

    .nav__menu.active {
        pointer-events: auto !important;
    }
}