/* Custom Responsive Header Styles */
.crh-header-wrapper {
    width: 100%;
    max-width: 100%;
    overflow: visible;
    z-index: 9999 !important;
    transition: background-color 0.3s ease;
    display: block;
    visibility: visible;
    opacity: 1;
    position: relative;
    box-sizing: border-box;
}

/* Ensure all header elements respect viewport width */
.crh-header-wrapper,
.crh-header-wrapper * {
    box-sizing: border-box;
}

/* Allow mobile menu to escape parent containers */
.crh-header-wrapper.crh-menu-open,
.crh-header-wrapper.crh-menu-open .crh-container {
    overflow: visible !important;
}

/* Sticky Header - Works with Elementor absolute positioning */
.crh-sticky {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    z-index: 9999 !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
                box-shadow 0.3s ease, 
                background-color 0.3s ease;
    display: block;
    visibility: visible;
    opacity: 1;
    box-sizing: border-box;
    /* NO transform here - it breaks fixed positioning of child elements (nav) */
}

/* Hide header when scrolling down */
.crh-sticky.crh-hidden {
    transform: translateY(-100%);
    will-change: transform;
}

.crh-sticky.crh-scrolled {
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Fix for WordPress Admin Bar - Admin bar has z-index 99999, so stay below it */
body.admin-bar .crh-header-wrapper,
body.admin-bar .crh-sticky {
    z-index: 9999 !important;
}

body.admin-bar .crh-sticky {
    top: 32px !important;
}

@media screen and (max-width: 782px) {
    body.admin-bar .crh-sticky {
        top: 46px !important;
    }
}

/* When admin bar is hidden by extensions/toggles, reset header position */
body.admin-bar .crh-header-wrapper.crh-admin-bar-hidden.crh-sticky {
    top: 0 !important;
}

.crh-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 20px 50px; /* 20px top/bottom padding */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    box-sizing: border-box;
}

/* Default Layout with CTA: Push menu to right */
.crh-container.crh-has-cta .crh-nav {
    margin-left: auto;
    margin-right: 30px;
}

/* Centered Layout: Reset margins */
.crh-layout-center.crh-has-cta .crh-nav {
    margin-left: 0;
    margin-right: 0;
}

/* Left Layout */
.crh-layout-left {
    justify-content: flex-start;
}

.crh-layout-left .crh-nav {
    margin-left: 40px; /* Space from logo */
}

.crh-layout-left .crh-cta {
    margin-left: auto; /* Push CTA to far right */
}

/* Left Layout Override for CTA logic */
.crh-layout-left.crh-has-cta .crh-nav {
    margin-left: 40px;
    margin-right: 0;
}

/* Left All Layout - Everything aligned left */
.crh-layout-left-all {
    justify-content: flex-start;
}

.crh-layout-left-all .crh-nav {
    margin-left: 40px; /* Space from logo */
}

.crh-layout-left-all .crh-cta {
    margin-left: 30px; /* Space from menu */
}

.crh-layout-left-all.crh-has-cta .crh-nav {
    margin-left: 40px;
    margin-right: 0;
}

/* Centered Layout */
.crh-layout-center {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}

.crh-layout-center .crh-logo {
    justify-self: start;
}

.crh-layout-center .crh-nav {
    justify-self: center;
}

.crh-layout-center .crh-cta {
    justify-self: end;
}

.crh-layout-center .crh-mobile-toggle {
    justify-self: end; /* Ensure toggle is on the right in mobile if grid is used */
}

/* CTA Button */
.crh-cta {
    display: block;
}

.crh-mobile-cta {
    display: none; /* Hidden on desktop */
}

/* Logo */
.crh-logo {
    position: relative;
    z-index: 2;
}

.crh-logo a {
    font-size: 24px;
    font-weight: bold;
    text-decoration: none;
    color: #333;
    text-transform: uppercase;
    display: flex;
    align-items: center;
}

.crh-custom-logo {
    height: 100px;
    width: auto;
    display: block;
    object-fit: contain;
}

/* Desktop Menu */
.crh-nav {
    display: flex;
    align-items: center;
}

.crh-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 30px;
}

.crh-menu li {
    position: relative;
}

.crh-menu a {
    text-decoration: none !important;
    color: #333;
    font-weight: 500;
    font-size: 16px;
    transition: color 0.3s ease;
    position: relative;
}

/* Hover effect: Underline Slide - Only for items WITHOUT submenus */
.crh-hover-underline-slide .crh-menu > li:not(.menu-item-has-children) > a::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    width: 0;
    height: 2px;
    background-color: currentColor;
    transition: width 0.3s ease, left 0.3s ease;
}

.crh-hover-underline-slide .crh-menu > li:not(.menu-item-has-children) > a:hover::after {
    width: 100%;
    left: 0;
}

/* Only show underline effects when enabled via class */
.crh-hover-underline .crh-menu > li > a:hover {
    text-decoration: underline !important;
}

.crh-hover-background .crh-menu > li > a {
    padding: 8px 12px;
    border-radius: 4px;
    transition: color 0.3s ease, background-color 0.3s ease;
}

.crh-hover-background .crh-menu > li > a:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.crh-menu a:hover {
    color: #0073aa;
}

/* Dropdown (Submenus) - Desktop Only */
@media (min-width: 769px) {
    .crh-menu .sub-menu {
        position: absolute;
        top: 100%;
        left: 0;
        background: #fff;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        min-width: 180px;
        opacity: 0;
        visibility: hidden;
        transform: translateY(8px);
        transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
        list-style: none;
        padding: 8px 0;
        border-radius: 4px;
        z-index: 10000;
        margin: 0;
    }

    .crh-menu li:hover > .sub-menu {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
}

.crh-menu .sub-menu li {
    padding: 0;
    display: block;
    width: 100%;
}

.crh-menu .sub-menu a {
    display: block;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.crh-menu .sub-menu a:hover {
    background-color: #f5f5f5;
}

/* Ensure parent menu items with submenus are visible */
.crh-menu > li.menu-item-has-children {
    position: relative;
}

/* Add dropdown indicator (arrow) to parent items */
.crh-menu > li.menu-item-has-children > a::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 8px;
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    transition: transform 0.3s ease;
}

/* Rotate arrow when hovering - Desktop only */
@media (min-width: 769px) {
    .crh-menu > li.menu-item-has-children:hover > a::after {
        transform: rotate(180deg);
    }
}

/* Mobile Toggle */
.crh-mobile-toggle {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 6px;
    background: transparent;
    border: none;
    padding: 10px;
    margin: -10px;
}

.crh-mobile-toggle:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.crh-mobile-toggle:focus:not(:focus-visible) {
    outline: none;
}

.crh-mobile-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Screen reader text */
.screen-reader-text {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal !important;
}

.crh-bar {
    width: 25px;
    height: 3px;
    background-color: #333;
    transition: transform 0.3s ease;
}

/* Stop animations during resize */
.crh-resize-stopper * {
    transition: none !important;
    animation: none !important;
}

/* Mobile Styles */
@media (max-width: 1024px) {
    /* Reset Grid/Flex Layouts for Mobile */
    .crh-layout-center,
    .crh-layout-left {
        display: flex;
        justify-content: space-between;
    }
    
    /* Hide CTA on mobile for now to avoid clutter */
    .crh-cta {
        display: none;
    }

    .crh-mobile-cta {
        display: block;
        margin-top: 30px;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .crh-mobile-toggle {
        display: flex;
        position: relative;
        z-index: 10001; /* Keep toggle above the full screen menu */
    }
    
    /* When menu is active, fix the toggle position - keep it in the same visual spot */
    .crh-mobile-toggle.active {
        position: fixed !important;
        top: var(--crh-toggle-top, 20px);
        right: var(--crh-toggle-right, 20px);
        z-index: 1000000 !important;
        visibility: visible !important;
        opacity: 1 !important;
        /* Keep margin to maintain exact visual position */
    }

    .crh-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        background-color: #ffffff;
        display: none;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        z-index: 999999;
        margin: 0 !important;
        border-top: none;
        max-height: none;
        box-shadow: none;
        padding: 20px;
        box-sizing: border-box;
        overflow-y: auto;
        /* No transitions - GSAP handles all animations */
    }

    /* Base styles for active nav - NO opacity/visibility overrides, let GSAP control */
    .crh-nav.active {
        /* Display is set by GSAP, these are structural styles only */
    }
    
    /* Force menu to be visible when nav is active */
    .crh-nav .crh-menu {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 25px !important;
        list-style: none !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 400px !important;
    }
    
    .crh-nav .crh-menu li {
        display: block !important;
        list-style: none !important;
        width: 100% !important;
        text-align: center !important;
    }
    
    .crh-nav .crh-menu a {
        display: block !important;
        color: #333333 !important;
        font-size: 24px !important;
        font-weight: 600 !important;
        padding: 10px !important;
        text-decoration: none !important;
    }

    /* Initial state - hidden. GSAP will control display via inline styles */
    .crh-nav {
        display: none;
    }
    
    /* Ensure menu items are ready for GSAP animations */
    .crh-nav .crh-menu > li,
    .crh-nav .crh-mobile-cta {
        will-change: transform, opacity;
    }
    
    /* Hamburger bars - ready for GSAP animation */
    .crh-bar {
        transform-origin: center center;
        will-change: transform, opacity, background-color;
    }

    .crh-menu {
        display: flex !important;
        flex-direction: column;
        width: 100%;
        gap: 25px;
        text-align: center;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .crh-menu li {
        width: auto;
        border-bottom: none;
        list-style: none;
    }

    .crh-menu a {
        display: block;
        padding: 5px;
        font-size: 24px !important; /* Larger font for full screen */
        font-weight: 600;
        color: #333333 !important;
    }

    /* Mobile Submenu */
    .crh-menu .sub-menu {
        position: static;
        box-shadow: none;
        opacity: 1;
        visibility: visible;
        transform: none;
        background-color: transparent;
        padding: 0;
        text-align: inherit;
        overflow: hidden;
        list-style: none;
        margin: 0;
        height: 0; /* Start collapsed, GSAP will animate */
        /* NO CSS transitions - GSAP handles animation */
    }
    
    .crh-menu .sub-menu.open {
        padding: 10px 0;
        /* Height is set by GSAP */
    }
    
    .crh-menu .sub-menu a {
        font-size: 18px !important;
        padding: 8px 5px !important;
    }
    
    /* Add arrow indicator for parent items on mobile */
    .crh-menu > li.menu-item-has-children > a::after {
        transform: rotate(0deg);
        transition: transform 0.3s ease;
    }
    
    .crh-menu > li.menu-item-has-children.submenu-open > a::after {
        transform: rotate(180deg);
    }

    /* Hamburger Animation */
    .crh-mobile-toggle.active .crh-bar {
        background-color: var(--crh-mobile-close-color, #333) !important;
        transition: transform 0.3s ease, opacity 0.3s ease !important;
    }
    .crh-mobile-toggle.active .crh-bar:nth-child(1) {
        transform: translateY(9px) rotate(45deg);
    }
    .crh-mobile-toggle.active .crh-bar:nth-child(2) {
        opacity: 0;
    }
    .crh-mobile-toggle.active .crh-bar:nth-child(3) {
        transform: translateY(-9px) rotate(-45deg);
    }
}
