#header {
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 0;
    width: 100%;
    max-width: 100%;
    height: 44px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transform: none;
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0;
    box-shadow: none;
    animation: headerFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    will-change: auto;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#header.scrolled {
    background: rgba(0, 0, 0, 0.82);
    border-bottom-color: rgba(255, 255, 255, 0.09);
}

#header.hidden {
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

@keyframes headerFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.header-container {
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 140px 1fr 140px;
    align-items: center;
    height: 44px;
    box-sizing: border-box;
}

.header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    justify-self: start;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s;
}
.header-logo:hover { opacity: 0.7; }

.header-logo img {
    height: 20px;
    width: auto;
    object-fit: contain;
    border-radius: 3px;
}

.header-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.header-nav__link {
    font-size: 0.72rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.78);
    text-decoration: none;
    letter-spacing: 0;
    transition: color 0.15s;
    font-family: var(--font-display);
    padding: 0 0.75rem;
    height: 44px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    background: transparent;
    border: none;
    cursor: pointer;
    outline: none;
}
.header-nav__link:hover,
.header-nav__link.is-active { color: #fff; }

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0;
    position: relative;
}

.header-icon-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.78);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    position: relative;
    flex-shrink: 0;
    border-radius: 0;
    font-size: 0.92rem;
}
.header-icon-btn:hover { color: #fff; }

.cart-button {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
    color: rgba(255, 255, 255, 0.78) !important;
    gap: 0 !important;
    box-shadow: none !important;
    font-size: 0.92rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    overflow: visible !important;
    transition: color 0.2s !important;
    cursor: pointer;
}
.cart-button:hover {
    color: #fff !important;
    background: transparent !important;
    transform: none !important;
    box-shadow: none !important;
}
.cart-button .cart-text { display: none !important; }
.cart-button::before { display: none !important; }

.cart-count {
    position: absolute;
    top: 5px;
    right: 3px;
    min-width: 14px;
    height: 14px;
    font-size: 0.5rem;
    font-weight: 700;
    background: var(--store-primary);
    color: #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    pointer-events: none;
}
.cart-count.empty { display: none; }
.cart-count.has-items { animation: cartBounce 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes cartBounce {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.user-profile {
    position: relative;
    display: flex;
    align-items: center;
}

#loginButton {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    touch-action: manipulation;
    transition: color 0.2s, opacity 0.2s !important;
    font-family: var(--font-display);
    white-space: nowrap;
    overflow: visible !important;
    position: relative;
}

#loginButton:not(.authenticated) {
    padding: 0 0.5rem !important;
    font-size: 0.72rem !important;
    font-weight: 400 !important;
    letter-spacing: 0 !important;
    color: rgba(255, 255, 255, 0.78) !important;
}
#loginButton:not(.authenticated):hover {
    color: #fff !important;
}

#loginButton.authenticated {
    padding: 4px !important;
    border-radius: 50% !important;
    width: 44px !important;
    height: 44px !important;
    color: rgba(255, 255, 255, 0.78) !important;
}
#loginButton.authenticated:hover {
    color: #fff !important;
    opacity: 0.85;
}

#loginButton.authenticated img {
    width: 26px;
    height: 26px;
    object-fit: cover;
    border-radius: 50%;
    border: 1.5px solid rgba(104, 190, 124, 0.4);
    display: block;
}

#loginButton.user-button {
    padding: 0 0.75rem !important;
    gap: 0.4rem;
    font-size: 0.72rem !important;
    font-weight: 400 !important;
    color: rgba(255, 255, 255, 0.78) !important;
    border-radius: 0 !important;
    width: auto !important;
    height: 44px !important;
}
#loginButton.user-button:hover {
    color: #fff !important;
}

#loginButton .user-info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#loginButton .user-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(104, 190, 124, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    color: var(--store-primary);
    flex-shrink: 0;
}

#loginButton .user-name {
    font-size: 0.72rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.78);
    letter-spacing: 0;
}

#loginButton .dropdown-arrow {
    font-size: 0.52rem;
    color: rgba(255, 255, 255, 0.3);
    transition: transform 0.2s;
}

#loginButton[aria-expanded="true"] .dropdown-arrow {
    transform: rotate(180deg);
}

#loginButton::before,
#loginButton::after { display: none !important; }

.search-toggle {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    border-radius: 0;
    color: rgba(255, 255, 255, 0.78);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    flex-shrink: 0;
}
.search-toggle:hover { color: #fff; }

.search-container { display: none !important; }

.search-flyout-overlay {
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.94);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.22s;
    padding: 1.25rem 0;
}
.search-flyout-overlay.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.search-flyout-inner {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 1.5rem;
    position: relative;
}
.search-flyout-inner .search-input-wrapper { position: relative; }
.search-flyout-inner .search-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: #fff;
    font-size: 0.95rem;
    padding: 0.75rem 3rem 0.75rem 1.25rem;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
    font-family: var(--font-display);
}
.search-flyout-inner .search-input:focus {
    border-color: rgba(104, 190, 124, 0.45);
    background: rgba(255, 255, 255, 0.08);
}
.search-flyout-inner .search-button {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
.search-flyout-inner .search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: rgba(12, 12, 12, 0.98);
    backdrop-filter: blur(40px);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    overflow: hidden;
    z-index: 1001;
    max-height: 380px;
    overflow-y: auto;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 400px;
    overflow-y: auto;
    background: rgba(12, 12, 12, 0.98);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    margin-top: 5px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
}
.search-results.active { display: block; opacity: 1; transform: translateY(0); }

.search-results-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 1;
    backdrop-filter: blur(20px);
}
.search-results-count {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    outline: none;
    min-height: 56px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item:focus { background: rgba(255, 255, 255, 0.04); }

.search-result-image {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 0.875rem;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.04);
}
.search-result-image img { width: 100%; height: 100%; object-fit: cover; }
.search-result-content { flex: 1; min-width: 0; }
.search-result-name {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    margin-bottom: 0.1rem;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-result-name mark {
    background: var(--store-primary);
    color: #000;
    padding: 0 0.15rem;
    border-radius: 2px;
    font-weight: 600;
}
.search-result-category { color: rgba(255, 255, 255, 0.3); font-size: 0.72rem; }
.search-result-price { color: var(--store-primary); font-weight: 600; font-size: 0.875rem; margin-top: 0.1rem; }
.search-result-stock { font-size: 0.68rem; font-weight: 500; margin-top: 0.1rem; }
.search-result-stock.in-stock { color: var(--store-success); }
.search-result-stock.low-stock { color: var(--store-warning); }
.search-result-stock.out-of-stock { color: var(--store-error); }
.search-result-actions { margin-left: 0.75rem; flex-shrink: 0; }

.search-add-to-cart {
    background: var(--store-primary);
    color: #000;
    border: none;
    border-radius: 7px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}
.search-add-to-cart:hover { background: var(--store-primary-hover); transform: scale(1.06); }
.search-add-to-cart:disabled { background: rgba(255, 255, 255, 0.08); cursor: not-allowed; transform: none; }

.search-results-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    bottom: 0;
    backdrop-filter: blur(20px);
}
.search-view-all {
    width: 100%;
    background: transparent;
    color: rgba(255, 255, 255, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 8px;
    padding: 0.6rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 400;
    font-family: var(--font-display);
    font-size: 0.78rem;
    min-height: 38px;
}
.search-view-all:hover { background: rgba(255, 255, 255, 0.04); color: #fff; border-color: rgba(255, 255, 255, 0.12); }

.search-loading, .search-no-results, .search-error {
    padding: 2rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.875rem;
}
.search-loading-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--store-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 0.75rem;
}
.no-results-icon, .search-error-icon { font-size: 1.5rem; margin-bottom: 0.75rem; opacity: 0.25; }
.no-results-suggestions { text-align: left; margin-top: 0.75rem; max-width: 220px; margin-left: auto; margin-right: auto; }
.no-results-suggestions ul { margin: 0.4rem 0; padding-left: 1.25rem; list-style-type: disc; }
.no-results-suggestions li { margin-bottom: 0.25rem; font-size: 0.8rem; color: rgba(255, 255, 255, 0.3); }

.search-results::-webkit-scrollbar { width: 4px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }
.search-results::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ─── Mega Menu ──────────────────────────────────────────────── */

.mega-menu-overlay {
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition:
        opacity 0.2s ease,
        transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
        visibility 0.2s;
    pointer-events: none;
}

.mega-menu-overlay.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.mega-menu__inner {
    max-width: 1024px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 1.5rem;
}

.mega-menu__content {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.mega-menu__title {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.25);
    margin-bottom: 0.75rem;
    font-family: var(--font-display);
}

.mega-menu__list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.mega-menu__item {
    display: block;
    padding: 0.38rem 0;
    font-size: 0.8rem;
    font-family: var(--font-display);
    font-weight: 400;
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
    letter-spacing: -0.01em;
    transition: color 0.13s;
    line-height: 1.4;
    white-space: nowrap;
}
.mega-menu__item:hover { color: #fff; }

.mega-menu__view-all {
    display: inline-block;
    margin-top: 0.875rem;
    font-size: 0.7rem;
    font-family: var(--font-display);
    font-weight: 500;
    color: rgba(104, 190, 124, 0.7);
    text-decoration: none;
    letter-spacing: -0.005em;
    transition: color 0.13s;
}
.mega-menu__view-all:hover { color: var(--store-primary); }

.mega-menu__empty {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.25);
    font-family: var(--font-body);
    padding: 0.25rem 0;
}

.mega-menu__loading {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0;
    align-items: center;
}
.mega-menu__loading span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    animation: megaDot 1.2s ease-in-out infinite;
}
.mega-menu__loading span:nth-child(2) { animation-delay: 0.18s; }
.mega-menu__loading span:nth-child(3) { animation-delay: 0.36s; }

@keyframes megaDot {
    0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* ─── Light mode ─────────────────────────────────────────────── */

body.light-mode #header { background: rgba(252, 252, 252, 0.72); border-bottom-color: rgba(0, 0, 0, 0.07); }
body.light-mode #header.scrolled { background: rgba(252, 252, 252, 0.88); }
body.light-mode .header-nav__link { color: rgba(0, 0, 0, 0.72) !important; }
body.light-mode .header-nav__link:hover,
body.light-mode .header-nav__link.is-active { color: #000 !important; }
body.light-mode .header-icon-btn { color: rgba(0, 0, 0, 0.72); }
body.light-mode .header-icon-btn:hover { color: #000; }
body.light-mode .cart-button { color: rgba(0, 0, 0, 0.72) !important; }
body.light-mode .cart-button:hover { color: #000 !important; }
body.light-mode #loginButton:not(.authenticated) { color: rgba(0, 0, 0, 0.72) !important; }
body.light-mode #loginButton:not(.authenticated):hover { color: #000 !important; }
body.light-mode #loginButton.user-button { color: rgba(0, 0, 0, 0.72) !important; }
body.light-mode .search-toggle { color: rgba(0, 0, 0, 0.72); }
body.light-mode .search-toggle:hover { color: #000; }
body.light-mode .search-flyout-overlay { background: rgba(252, 252, 252, 0.96); border-bottom-color: rgba(0, 0, 0, 0.07); }
body.light-mode .search-flyout-inner .search-input { background: rgba(0, 0, 0, 0.04); border-color: rgba(0, 0, 0, 0.1); color: #000; }
body.light-mode .search-flyout-inner .search-input::placeholder { color: rgba(0, 0, 0, 0.35); }
body.light-mode .mega-menu-overlay { background: rgba(252, 252, 252, 0.96); border-bottom-color: rgba(0, 0, 0, 0.07); }
body.light-mode .mega-menu__title { color: rgba(0, 0, 0, 0.3); }
body.light-mode .mega-menu__item { color: rgba(0, 0, 0, 0.55); }
body.light-mode .mega-menu__item:hover { color: #000; }

@media (max-width: 1024px) { .header-container { max-width: 100%; } }
@media (max-width: 860px) {
    .header-nav { display: none; }
    .mega-menu-overlay { display: none; }
    .header-container { grid-template-columns: auto 1fr auto; padding: 0 1rem; }
}
@media (max-width: 480px) { .header-container { padding: 0 0.5rem; } }

@media (prefers-reduced-motion: reduce) {
    #header { animation: none; }
    .cart-count.has-items { animation: none; }
    .mega-menu-overlay { transition: none; }
}