/* ==========================================================================
   Header Responsive Design - Mobile First Approach
   Optimized for all device sizes with smooth transitions
   ========================================================================== */

/* ==========================================================================
   Base Mobile Styles (< 768px)
   Mobile First Foundation
   ========================================================================== */
@media (max-width: 900px) {
    /* Header Foundation - Fixed positioning to prevent scroll issues */
    .site-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        padding: 1rem 0;
        background: rgba(255, 255, 255, 1);
        box-shadow: none;
        z-index: 9999;
        transition: background 0.3s ease, box-shadow 0.3s ease;
        /* Remove transform transition to prevent hamburger from moving */
        transform: translateY(0) !important;
        will-change: background, box-shadow;
    }

    /* Header Container - Optimized for mobile with stable layout */
    .header-container {
        max-width: 100%;
        margin: 0;
        padding: 0 1.5rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        min-height: 60px;
        position: relative;
        /* Prevent flexbox from causing shifts */
        flex-wrap: nowrap;
    }

    /* Site Branding - Logo Optimization */
    .site-branding {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        max-width: 60%;
        z-index: 10;
    }

    .custom-logo-link {
        display: inline-flex;
        align-items: center;
        max-width: 100%;
    }

    .custom-logo-link img {
        height: 60px; /* Slightly larger for tablets */
        width: auto;
        max-width: 100%;
        object-fit: contain;
        display: block;
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* Menu Toggle Button - Touch Optimized */
    .menu-toggle {
        display: flex !important;
        position: relative;
        width: 44px;
        height: 44px;
        padding: 0;
        background: transparent;
        border: 2px solid rgba(10, 15, 28, 0.1);
        border-radius: 8px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 3px;
        z-index: 10001;
        transition: background 0.3s ease, border-color 0.3s ease, transform 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
        /* Prevent any movement */
        margin-left: auto;
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    .menu-toggle:hover,
    .menu-toggle:focus {
        background: rgba(10, 15, 28, 0.05);
        border-color: rgba(10, 15, 28, 0.2);
        outline: none;
    }

    .menu-toggle:active {
        transform: scale(0.95);
    }

    /* Hamburger Lines */
    .menu-toggle span {
        display: block;
        width: 22px;
        height: 2px;
        background: var(--blaze-secondary, #0A0F1C);
        border-radius: 2px;
        transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
        pointer-events: none;
    }

    /* Shorter middle line for visual balance */
    .menu-toggle span:nth-child(2) {
        width: 18px;
    }

    /* Active state - X formation */
    .menu-toggle.active span:nth-child(1) {
        transform: translateY(5px) rotate(45deg);
    }

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

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

    /* Hide desktop navigation */
    .main-navigation {
        display: none !important;
    }

    /* Hide glassy-nav on mobile */
    .glassy-nav {
        display: none !important;
    }

    /* Mobile Menu Styles are handled by mobile-menu.css */
    
    /* Body scroll prevention when menu open */
    body.menu-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        touch-action: none;
    }

    /* Ensure header stays on top when scrolled */
    .site-header.scrolled {
        /* Keep transparent background when scrolled */
        background: transparent;
        backdrop-filter: none;
        box-shadow: none;
    }

    /* Hide logo when scrolled on mobile - but keep hamburger stable */
    .site-header.scrolled .custom-logo-link {
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    /* Keep site-branding space to prevent layout shift */
    .site-header.scrolled .site-branding {
        /* Don't change flex properties to prevent hamburger from moving */
        flex: 0 0 auto;
        max-width: 60%;
    }
    
    /* Position hamburger to stay in place */
    .menu-toggle {
        position: relative !important;
        margin-left: auto; /* Always stick to right side */
    }
}

/* ==========================================================================
   Small Mobile Adjustments (< 480px)
   Compact layout for small screens
   ========================================================================== */
@media (max-width: 480px) {
    .site-header {
        padding: 0.5rem 0;
    }

    .header-container {
        padding: 0 0.75rem;
        min-height: 52px;
    }

    .custom-logo-link img {
        height: 50px; /* Slightly larger scaling */
    }

    .menu-toggle {
        width: 40px;
        height: 40px;
    }

    .menu-toggle span {
        width: 20px;
    }

    .menu-toggle span:nth-child(2) {
        width: 16px;
    }
}

/* ==========================================================================
   Extra Small Mobile (< 360px)
   Minimal layout for very small screens
   ========================================================================== */
@media (max-width: 360px) {
    .header-container {
        padding: 0 0.5rem;
        min-height: 48px;
    }

    .custom-logo-link img {
        height: 45px; /* Slightly larger scaling */
    }

    .menu-toggle {
        width: 36px;
        height: 36px;
    }

    .menu-toggle span {
        width: 18px;
        height: 2px;
    }

    .menu-toggle span:nth-child(2) {
        width: 14px;
    }
}

/* ==========================================================================
   Tablet Landscape & Small Desktop (901px - 1024px)
   Desktop navigation with compact spacing
   ========================================================================== */
@media (min-width: 901px) and (max-width: 1024px) {
    .site-header {
        padding: 1rem 0;
    }

    .header-container {
        padding: 0 2rem;
        max-width: 100%;
    }

    .custom-logo-link img {
        height: 70px;
    }

    /* Show desktop navigation but with reduced spacing */
    .menu-toggle {
        display: none !important;
    }

    .main-navigation {
        display: flex !important;
    }

    .glassy-nav {
        display: flex !important;
    }

    .glassy-nav > ul {
        gap: 1.5rem;
    }

    .main-navigation a {
        font-size: 0.85rem;
        padding: 0.4rem 0;
    }

    /* Adjust contact button for tablets */
    .glassy-nav > ul > li:last-child a {
        padding: 0.6rem 1.5rem;
        font-size: 0.8rem;
    }

    /* Dropdown adjustments for tablets */
    .main-navigation ul ul.sub-menu {
        min-width: 200px;
        padding: 0.5rem 0;
    }

    .main-navigation ul ul.sub-menu a {
        padding: 0.5rem 0.875rem;
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   Desktop Optimizations (> 1024px)
   Full desktop experience
   ========================================================================== */
@media (min-width: 1025px) {
    /* Ensure hamburger menu is hidden */
    .menu-toggle {
        display: none !important;
    }

    /* Mobile menu overlay should never show on desktop */
    .mobile-menu-overlay {
        display: none !important;
    }

    /* Ensure desktop navigation is visible */
    .main-navigation {
        display: flex !important;
    }

    .glassy-nav {
        display: flex !important;
    }

    .header-container {
        padding: 0 3rem;
    }

    .custom-logo-link img {
        height: 80px;
    }
}

/* ==========================================================================
   Large Desktop (> 1400px)
   Maximum spacing and sizes
   ========================================================================== */
@media (min-width: 1401px) {
    .header-container {
        max-width: 1400px;
        margin: 0 auto;
    }

    .glassy-nav > ul {
        gap: 3rem;
    }

    .main-navigation a {
        font-size: 0.95rem;
    }
}

/* ==========================================================================
   Touch Device Optimizations
   Better interaction for touch screens
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .menu-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .main-navigation a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Better dropdown interaction on touch */
    .main-navigation ul ul.sub-menu {
        margin-top: 0;
    }

    .main-navigation ul ul.sub-menu a {
        padding: 0.75rem 1rem;
        min-height: 44px;
    }

    /* Prevent accidental hover on touch devices */
    .main-navigation li:hover > ul.sub-menu {
        opacity: 0;
        visibility: hidden;
    }

    /* Use click/tap for dropdowns on touch devices */
    .main-navigation li.menu-item-has-children > a::after {
        content: '▼';
        margin-left: 0.5rem;
        font-size: 0.7em;
        opacity: 0.6;
    }
}

/* ==========================================================================
   iOS-Specific Fixes
   Handle Safari quirks and ensure stable hamburger menu
   ========================================================================== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific */
    .is-ios .site-header {
        position: fixed !important;
        top: 0 !important;
        transform: translateY(0) !important;
        -webkit-transform: translateY(0) !important;
        will-change: auto;
    }
    
    .is-ios .menu-toggle {
        position: relative !important;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
    
    /* Prevent iOS Safari from hiding elements during scroll */
    .is-ios .header-container {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }
}

/* ==========================================================================
   Landscape Orientation Specific
   Optimizations for landscape mode
   ========================================================================== */
@media (max-width: 900px) and (orientation: landscape) {
    .site-header {
        padding: 0.5rem 0;
    }

    .header-container {
        min-height: 48px;
    }

    .custom-logo-link img {
        height: 55px;
    }

    .menu-toggle {
        width: 40px;
        height: 40px;
    }

    /* Adjust mobile menu for landscape */
    .mobile-menu-content {
        padding: 1rem;
    }

    .mobile-menu-items {
        max-height: calc(100vh - 100px);
        overflow-y: auto;
    }

    .mobile-menu-link {
        padding: 0.75rem 0;
        font-size: 1rem;
    }
}

/* ==========================================================================
   High Resolution Displays
   Crisp rendering on retina screens
   ========================================================================== */
@media (-webkit-min-device-pixel-ratio: 2), 
       (min-resolution: 192dpi) {
    .menu-toggle span {
        transform: translateZ(0);
        backface-visibility: hidden;
    }

    .site-header {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* ==========================================================================
   Reduced Motion Preference
   Respect user's motion preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .site-header,
    .menu-toggle,
    .menu-toggle span,
    .main-navigation a,
    .main-navigation ul ul.sub-menu {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ==========================================================================
   Admin Bar Adjustments
   Account for WordPress admin bar
   ========================================================================== */
.admin-bar .site-header {
    top: 32px;
}

@media screen and (max-width: 782px) {
    .admin-bar .site-header {
        top: 46px;
    }
    
    .admin-bar .menu-toggle {
        top: calc(1.25rem + 46px) !important;
    }
}

@media screen and (max-width: 600px) {
    .admin-bar .site-header {
        position: fixed;
        top: 0;
    }
    
    .admin-bar .menu-toggle {
        top: calc(1.25rem) !important;
    }
}

/* ==========================================================================
   Print Styles
   Clean header for printing
   ========================================================================== */
@media print {
    .site-header {
        position: static;
        box-shadow: none;
        background: white;
    }

    .menu-toggle,
    .main-navigation {
        display: none !important;
    }

    .header-container {
        justify-content: center;
    }

    .custom-logo-link img {
        height: 50px;
    }
}
