/* ==========================================================================
   Site header: shop badge, account button, search
   Pinned at the top; eases into a compact version after scrolling (js/storefront/sticky-header.js):
   the area line and the order lines fold away, logo, name and search get smaller, over 0.25 s
   ========================================================================== */

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    /* Nothing inside ever makes the page wider than the phone (the sideways category row scrolls on its own) */
    overflow-x: clip;
    background: var(--header-gradient);
    color: var(--header-text);
    transition: box-shadow 0.25s ease;
}

/*
 * The header is pinned (fixed), so shrinking it never moves the page (that caused the flicker).
 * This space keeps its full height in the page; js/storefront/sticky-header.js sets --header-space.
 */
.site-header-space {
    height: var(--header-space, 0px);
}

.site-header__inner {
    min-width: 0;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 14px var(--page-gutter) 6px;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    transition: padding 0.25s ease, gap 0.25s ease;
}

.site-header__top {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

/* Shop name and logo */
.shop-badge {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.shop-badge__logo,
.shop-badge__initials {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    transition: width 0.25s ease, height 0.25s ease, border-radius 0.25s ease, font-size 0.25s ease;
}

.shop-badge__logo {
    object-fit: cover;
    background: var(--color-surface);
}

.shop-badge__initials {
    background: linear-gradient(135deg, #D91E5B, #7B2CBF);
    color: #FFFFFF;
    font-weight: 800;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shop-badge__text {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.shop-badge__name {
    font-family: var(--font-display);
    font-size: 21px;
    transition: font-size 0.25s ease;
    font-weight: 800;
    line-height: 1.15;
    overflow-wrap: break-word;
}

.shop-badge__name--long {
    font-size: 18px;
}

/* The narrowest phones (320 px): a smaller shop name, so a word is never split in two */
@media (max-width: 340px) {
    .shop-badge__name {
        font-size: 18px;
    }

    .shop-badge__name--long {
        font-size: 16px;
    }
}

.shop-badge__place {
    max-height: 40px;
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
    margin-top: 3px;
    font-size: 13px;
    font-weight: 500;
    color: #4B3E66;
}

/* Search */
.search-box {
    height: 48px;
    padding: 0 14px;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: height 0.25s ease;
}

.search-box__icon {
    width: 20px;
    height: 20px;
    color: var(--color-ink);
}

.search-box__input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    background: transparent;
    font-size: 15px;
    outline: none;
}

.search-box:focus-within {
    border-color: var(--color-primary);
}

/* Compact header after scrolling */
.site-header.is-compact {
    background: #F4EDFF;
    box-shadow: 0 4px 14px rgba(42, 16, 82, 0.10);
}

.site-header.is-compact .site-header__inner {
    padding-top: 8px;
    padding-bottom: 8px;
    gap: var(--space-2);
}

.site-header.is-compact .shop-badge {
    align-items: center;
}

.site-header.is-compact .shop-badge__logo,
.site-header.is-compact .shop-badge__initials {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* Compact: smaller, still the full name */
.site-header.is-compact .shop-badge__name {
    font-size: 15px;
}

.site-header.is-compact .site-header__top {
    align-items: center;
}

.site-header.is-compact .shop-badge__place {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
}

.site-header.is-compact .icon-button {
    width: 36px;
    height: 36px;
}

.site-header.is-compact .search-box {
    height: 42px;
}

@media (prefers-reduced-motion: reduce) {
    .site-header,
    .site-header__inner,
    .shop-badge__logo,
    .shop-badge__initials,
    .search-box {
        transition: none;
    }
}

@media (min-width: 768px) {
    .site-header__inner {
        flex-direction: row;
        align-items: center;
        padding-top: 16px;
        padding-bottom: 16px;
    }

    .site-header__top {
        flex: 0 0 auto;
        gap: var(--space-6);
    }

    .search-box {
        flex: 1 1 auto;
        max-width: 640px;
        margin-left: auto;
    }

    .site-header.is-compact .site-header__inner {
        padding-top: 10px;
        padding-bottom: 10px;
    }
}

/* Delivery notice line (components/delivery-notice.css): hidden while the header is compact */
.site-header.is-compact .delivery-notice {
    display: none;
}

/* ---------- Cart pills (partials/cart-switcher; look: components/cart-switcher.css) ---------- */

.cart-switcher--header {
    margin: 0 calc(var(--page-gutter) * -1);
    padding: 0 var(--page-gutter) 6px;
}

/* Home page: only once the big type cards (partials/shop-ways) have scrolled away */
.store--home:not(.ways-out-of-view) .cart-switcher--header {
    display: none;
}

@media (min-width: 768px) {
    .site-header__inner {
        flex-wrap: wrap;
    }

    .cart-switcher--header {
        flex-basis: 100%;
        order: 10;
        margin: 0;
        padding: 0;
    }
}

/* ---------- Dark mode button (moon in light mode, sun in dark mode; js/admin/theme-switch.js) ---------- */
.theme-button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 0;
    border-radius: var(--radius-pill);
    background: #FFFFFF;
    box-shadow: 0 2px 8px rgba(42, 16, 82, 0.12);
    color: #5B21B6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.theme-button .icon {
    width: 22px;
    height: 22px;
}

.theme-button__sun,
html[data-theme="dark"] .theme-button__moon {
    display: none;
}

html[data-theme="dark"] .theme-button__sun {
    display: block;
}

html[data-theme="dark"] .theme-button {
    background: #2A2140;
    color: #F5C451;
}

.site-header.is-compact .theme-button {
    width: 40px;
    height: 40px;
}

/* ---------- Main links in the header (partials/nav-links): large screens only, the bottom menu is hidden there ---------- */
.header-nav {
    display: none;
}

/*
 * Tablets and computers: two tidy rows, everything centred on its line (the links from 1024 px)
 *   [logo  name · place · WHOLESALE]   [ search ............................ ]   [WhatsApp]
 *   [Home] [Brands] [Cart] [Account]                                  [● Taking orders now ›]
 */
@media (min-width: 768px) {
    .site-header__inner {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "back   back   back"
            "badge  search whats"
            "nav    nav    status"
            "carts  carts  carts";
        align-items: center;
        column-gap: var(--space-6);
        row-gap: 10px;
    }

    .wholesalers-back { grid-area: back; justify-self: start; }
    .site-header__top { display: contents; }
    .shop-badge { grid-area: badge; align-items: center; }
    .search-box { grid-area: search; width: 100%; max-width: none; margin: 0; }
    .site-header__whatsapp { grid-area: whats; justify-self: end; }
    .header-nav { grid-area: nav; align-self: start; }
    .shop-status { grid-area: status; justify-self: end; align-self: start; }
    .shop-status__inner { align-items: flex-end; }
    .cart-switcher--header { grid-area: carts; }
}

/* The main links in the header from 1024 px (below that the bottom menu stays) */
@media (min-width: 1024px) {
    .header-nav {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .header-nav__item {
        min-height: 40px;
        padding: 0 14px;
        border-radius: var(--radius-pill);
        color: var(--header-text);
        font-size: 15px;
        font-weight: 700;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        opacity: 0.88;
    }

    .header-nav__icon {
        width: 20px;
        height: 20px;
    }

    .header-nav__item:hover,
    .header-nav__item:focus-visible {
        opacity: 1;
        background: rgba(255, 255, 255, 0.12);
    }

    .header-nav__item.is-active {
        opacity: 1;
        background: var(--color-surface);
        color: var(--color-ink);
    }
}
