/**
 * Enhanced Header Structure
 * Fixes header layout, cart icon positioning, and mobile responsiveness
 */

/* Remove any default body/html spacing */
html {
    margin: 0 !important;
    padding: 0 !important;
}

body {
    margin: 0 !important;
    padding-top: 0 !important;
}

/* Remove spacing from main wrapper and header */
#haru-main {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

#haru-header {
    margin-top: 0 !important;
}

/* Header Container - Fixed structure */
.haru-header {
    position: relative;
    z-index: 999;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-top: 0 !important;
}

.header-default,
.haru-header-default {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 30px;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    min-height: 90px; /* Ensure minimum height for header */
}

/* Logo Section */
.haru-header-logo,
.haru-logo,
.haru-logo--left {
    flex-shrink: 0;
    z-index: 10;
    order: 2; /* Center on mobile */
    display: flex !important;
    align-items: center;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
}

.haru-header-logo a,
.haru-logo a {
    display: inline-block;
}

.haru-header-logo img,
.haru-logo img,
.haru-logo__default {
    max-height: 60px !important;
    width: auto !important;
    height: auto !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Hide retina and dark versions */
.haru-logo__retina,
.haru-logo__dark,
.haru-logo__dark-retina {
    display: none !important;
}

/* Hide duplicate or overlapping logo elements */
.haru-header-logo + .haru-header-logo,
.haru-logo + .haru-logo {
    display: none !important;
}

/* Ensure only one logo shows */
.header-default .haru-header-logo:not(:first-of-type),
.haru-header-default .haru-header-logo:not(:first-of-type),
.header-default .haru-logo:not(:first-of-type),
.haru-header-default .haru-logo:not(:first-of-type) {
    display: none !important;
}

/* Hide text if image logo exists */
.haru-header-logo img ~ *:not(img),
.haru-logo img ~ *:not(img) {
    display: none !important;
}

/* Fix for sites with text logo */
.haru-header-logo .site-title,
.haru-logo .site-title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    line-height: 1;
}

.haru-header-logo .site-title a,
.haru-logo .site-title a {
    color: #333;
    text-decoration: none;
}

.haru-header-logo .site-title a:hover,
.haru-logo .site-title a:hover {
    color: #4caf50;
}

/* Header Content - Navigation and Cart */
.haru-header-content {
    display: flex;
    align-items: center;
    gap: clamp(15px, 2vw, 25px);
    margin-left: auto;
    z-index: 10;
    order: 3;
}

/* Navigation Menu */
.haru-menu-default {
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-wrap {
    display: flex;
}

.haru-main-menu,
.haru-nav-menu {
    display: flex;
    align-items: center;
    gap: 25px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.haru-main-menu > li,
.haru-nav-menu > li {
    position: relative;
}

.haru-main-menu > li > a,
.haru-nav-menu > li > a {
    display: inline-block;
    padding: 10px 15px;
    font-size: 15px;
    font-weight: 500;
    color: #333;
    text-decoration: none;
    transition: color 0.3s ease;
}

.haru-main-menu > li > a:hover,
.haru-nav-menu > li > a:hover {
    color: #4caf50;
}

/* Cart Section - Properly structured */
.header-cart-default {
    position: relative;
}

.haru-cart {
    position: relative;
    display: flex;
    align-items: center;
}

.haru-cart-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.haru-cart-opener {
    position: relative;
    cursor: pointer;
}

.haru-cart-opener > a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.3s ease;
    text-decoration: none;
    color: #333;
}

.haru-cart-opener > a:hover {
    background: #f8f9fa;
}

/* Cart Icon with proper positioning */
.haru-cart-icon {
    position: relative;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.haru-cart-icon::before {
    content: '\e905';
    font-family: 'phosphor';
    font-size: 24px;
    line-height: 1;
}

/* Cart Number Badge - Properly positioned */
.haru-cart-number {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #f44336;
    color: #fff;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.haru-cart-number span {
    display: inline-block;
}

/* Cart Subtotal */
.haru-cart-sub-total {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.haru-cart-sub-total .amount {
    color: #4caf50;
}

/* Mobile Menu Toggle - Hidden on desktop */
.haru-toggle-default,
.haru-menu-toggle,
#haru-menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    padding: 0;
    margin: 0;
}

/* Force show toggle on mobile */
@media (max-width: 768px) {
    .haru-toggle-default,
    .haru-menu-toggle,
    #haru-menu-toggle {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Hide duplicate hamburger icons */
.haru-menu-toggle:not(:first-of-type),
#haru-menu-toggle ~ .haru-menu-toggle {
    display: none !important;
}

.haru-toggle-default span,
.haru-menu-toggle span {
    position: relative;
    display: block;
    width: 24px;
    height: 2px;
    background: #333;
    transition: all 0.3s ease;
}

.haru-toggle-default span::before,
.haru-toggle-default span::after,
.haru-menu-toggle span::before,
.haru-menu-toggle span::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    background: #333;
    transition: all 0.3s ease;
}

.haru-toggle-default span::before,
.haru-menu-toggle span::before {
    top: -8px;
}

.haru-toggle-default span::after,
.haru-menu-toggle span::after {
    bottom: -8px;
}

/* Cart Dropdown Panel */
.haru-cart-content {
    position: absolute;
    top: calc(100% + 15px);
    right: 0;
    width: 380px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    z-index: 1000;
    max-height: 600px;
    overflow: hidden;
}

.haru-cart-wrap:hover .haru-cart-content,
.haru-cart-content.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Arrow for cart dropdown */
.haru-cart-content::before {
    content: '';
    position: absolute;
    top: -8px;
    right: 20px;
    width: 16px;
    height: 16px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.08);
}

/* Tablet View */
@media (max-width: 1024px) {
    .header-default,
    .haru-header-default {
        padding: 12px 20px;
    }
    
    .haru-main-menu,
    .haru-nav-menu {
        gap: 15px;
    }
    
    .haru-main-menu > li > a,
    .haru-nav-menu > li > a {
        font-size: 14px;
        padding: 8px 10px;
    }
}

/* Mobile View */
@media (max-width: 768px) {
    /* Header wrapper - fixed at top */
    .haru-header,
    #haru-header {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 9998 !important;
        background: #fff !important;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    }
    
    /* Add padding to body to compensate for fixed header */
    body {
        padding-top: 60px !important;
    }
    
    /* Main header container - single row with flexbox */
    .haru-header-default {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 8px 12px !important;
        min-height: 55px !important;
        flex-wrap: nowrap !important;
        gap: 10px !important;
    }
    
    /* SHOW logo on mobile - center */
    .haru-logo,
    .haru-logo--left,
    .haru-header-logo {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        order: 2 !important;
        position: absolute !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        z-index: 5 !important;
    }
    
    .haru-logo img,
    .haru-logo--left img,
    .haru-header-logo img {
        max-height: 35px !important;
        width: auto !important;
    }
    
    /* Header content - holds menu and cart */
    .haru-header-content {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        width: 100% !important;
        justify-content: space-between !important;
    }
    
    /* Menu container - hamburger on LEFT (RTL = visual right) */
    .haru-menu-default {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        order: 1 !important;
    }
    
    /* Hide the nav menu list */
    .menu-wrap,
    #header-primary-menu,
    .haru-main-menu {
        display: none !important;
    }
    
    /* Hamburger toggle - MUST show */
    .haru-toggle-default {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        align-items: center !important;
        justify-content: center !important;
        width: 36px !important;
        height: 36px !important;
        background: #f5f5f5 !important;
        border: none !important;
        border-radius: 8px !important;
        cursor: pointer !important;
        position: relative !important;
    }
    
    /* Hamburger lines */
    .haru-toggle-default span {
        display: block !important;
        width: 20px !important;
        height: 2px !important;
        background: #333 !important;
        position: relative !important;
    }
    
    .haru-toggle-default span::before,
    .haru-toggle-default span::after {
        content: '' !important;
        position: absolute !important;
        width: 20px !important;
        height: 2px !important;
        background: #333 !important;
        left: 0 !important;
    }
    
    .haru-toggle-default span::before {
        top: -6px !important;
    }
    
    .haru-toggle-default span::after {
        bottom: -6px !important;
    }
    
    /* Cart - on RIGHT (RTL = visual left) */
    .header-cart-default,
    .haru-cart {
        display: flex !important;
        align-items: center !important;
        order: 2 !important;
    }
    
    /* Cart icon styling */
    .haru-cart-icon {
        font-size: 20px !important;
        width: 24px !important;
        height: 24px !important;
    }
    
    .haru-cart-number {
        top: -5px !important;
        right: -5px !important;
        min-width: 16px !important;
        height: 16px !important;
        font-size: 10px !important;
    }
    
    /* Hide subtotal and cart text on mobile */
    .haru-cart-sub-total,
    .haru-cart__title {
        display: none !important;
    }
    
    /* Cart dropdown on mobile */
    .haru-cart-content {
        position: fixed !important;
        top: 60px !important;
        right: 10px !important;
        width: calc(100vw - 20px) !important;
        max-width: 350px !important;
    }
}

/* Extra Small Devices */
@media (max-width: 480px) {
    .header-default,
    .haru-header-default {
        padding: 8px 10px;
    }
    
    .haru-header-logo img,
    .haru-logo img {
        max-height: 40px !important;
    }
    
    .haru-header-content {
        gap: 10px;
    }
    
    .haru-cart-content {
        width: calc(100vw - 20px);
        left: -10px;
    }
}

/* Hide all duplicate menu toggles - keep only one */
.haru-toggle-default + .haru-toggle-default,
.haru-menu-toggle + .haru-menu-toggle,
#haru-menu-toggle + .haru-toggle-default,
#haru-menu-toggle + .haru-menu-toggle,
.haru-nav-custom .haru-menu-toggle {
    display: none !important;
}

/* Ensure only first toggle shows on mobile */
@media (max-width: 768px) {
    .haru-toggle-default:first-of-type,
    .haru-menu-toggle:first-of-type,
    #haru-menu-toggle:first-of-type {
        display: flex !important;
    }
}

/* Ensure proper layout structure */
.haru-header-wrap {
    position: relative;
    width: 100%;
}

/* Fix for overlapping elements */
.haru-header * {
    box-sizing: border-box;
}

/* Fix logo container to prevent overflow */
.haru-header-logo,
.haru-logo {
    overflow: hidden;
    max-width: 300px;
}

/* Ensure clean single logo display */
.haru-header-logo > *:not(a):not(img),
.haru-logo > *:not(a):not(img) {
    display: none !important;
}

/* Clean up any pseudo-elements that might cause duplication */
.haru-header-logo::before,
.haru-header-logo::after,
.haru-logo::before,
.haru-logo::after {
    display: none !important;
}

/* If there's a background image causing overlap */
.haru-header-logo,
.haru-logo {
    background-image: none !important;
}

/* Ensure cart doesn't overflow */
.haru-cart-wrap.no-price .haru-cart-sub-total {
    display: none !important;
}

/* Mobile menu dropdown (if using custom menu) */
@media (max-width: 768px) {
    .haru-nav-menu--dropdown {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: #fff;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transition: left 0.3s ease;
        z-index: 9999;
        overflow-y: auto;
        padding: 20px 0;
    }
    
    .haru-nav-menu--dropdown.active {
        left: 0;
    }
    
    .haru-nav-menu--dropdown .haru-nav-menu {
        flex-direction: column;
        gap: 0;
        width: 100%;
    }
    
    .haru-nav-menu--dropdown .haru-nav-menu > li {
        width: 100%;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .haru-nav-menu--dropdown .haru-nav-menu > li > a {
        display: block;
        padding: 15px 20px;
        width: 100%;
    }
}

/* Mobile menu overlay */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 9998;
}

.mobile-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Sticky header support */
.haru-header.sticky {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Accessibility improvements */
.haru-cart-opener > a:focus,
.haru-toggle-default:focus,
.haru-menu-toggle:focus,
.haru-main-menu a:focus {
    outline: 2px solid #4caf50;
    outline-offset: 2px;
}

/* High contrast support */
@media (prefers-contrast: high) {
    .haru-header {
        border-bottom: 2px solid #000;
    }
    
    .haru-cart-number {
        border: 3px solid #fff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Desktop-specific fixes for header layout */
@media (min-width: 769px) {
    /* Header layout with proper flex positioning */
    .header-default,
    .haru-header-default {
        display: flex;
        align-items: center;
        gap: clamp(20px, 3vw, 40px);
        padding: 1rem clamp(20px, 3vw, 40px);
        padding-left: min(200px, 18vw) !important; /* Space for user controls on the left */
    }
    
    /* Logo */
    .haru-header-logo,
    .haru-logo {
        order: 1;
        flex-shrink: 0;
    }
    
    /* User/Login container - absolutely positioned on far left */
    .custom-user-container,
    .custom-login-button-container {
        position: absolute !important;
        left: clamp(20px, 3vw, 40px) !important;
        right: auto !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        z-index: 100 !important;
        flex-shrink: 0;
        margin: 0 !important;
        max-width: min(180px, 15vw);
    }
    
    /* Header content (nav + cart) on the right */
    .haru-header-content {
        order: 2;
        margin-left: auto;
        margin-right: 0;
        display: flex;
        align-items: center;
        gap: clamp(15px, 2vw, 30px);
        flex-shrink: 0;
    }
    
    /* Navigation proper spacing */
    .haru-main-menu,
    .haru-nav-menu {
        gap: clamp(15px, 1.5vw, 25px);
    }
    
    /* Cart with relative positioning */
    .header-cart-default {
        position: relative;
        flex-shrink: 0;
    }
}

