/* =====================================================================
   NAVBAR — unified public header
   Applies to:  partials/header.ejs            (.header …)
                partials/storefront-header.ejs (.storefront-header …)

   This file is loaded LAST on every public page so it is the single
   source of truth for the top bar. Guarantees:
     • the bar is ALWAYS a single row (never wraps)
     • nothing is ever clipped off-screen (logo shrinks, secondary
       items move into the mobile drawer on very small phones)
     • identical look & behaviour on every public page

   Breakpoints
     > 1024px  desktop  : logo · links · search · actions
     ≤ 1024px  tablet   : logo · actions · hamburger
     ≤  768px  phone    : compact sizing (56px bar)
     ≤  480px  small    : favourites → drawer
     ≤  400px  x-small  : "Sign Up" → drawer (Sign In stays)
     ≤  340px  tiny     : tightest sizing
   ===================================================================== */

:root {
    --nav-h: 64px;
    --nav-h-mobile: 56px;
    --nav-ctrl-h: 38px;
    --nav-radius: 10px;
}

/* ── Bar surface ──────────────────────────────────────────────────── */
.header,
.storefront-header {
    background: rgba(255, 255, 255, 0.9);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.85);
    transition: box-shadow 0.25s ease, background-color 0.25s ease;
}

.header.is-scrolled,
.storefront-header.is-scrolled {
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 8px 28px -14px rgba(15, 23, 42, 0.22);
}

/* ── Single-row container ─────────────────────────────────────────── */
.header-inner,
.storefront-header-container {
    display: flex;
    align-items: center;
    flex-wrap: nowrap !important;
    height: var(--nav-h) !important;
    min-height: 0 !important;
    gap: 16px !important;
    min-width: 0;
}

.header-left {
    display: flex;
    align-items: center;
    flex: 0 1 auto;
    min-width: 0;
    gap: 24px;
}

.header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 auto;
    min-width: 0;
    gap: 12px;
}

/* ── Logo (shrinks instead of pushing items off-screen) ───────────── */
.logo,
.storefront-logo {
    flex: 0 1 auto;
    min-width: 0;
    line-height: 0;
}

.logo img,
.storefront-logo img {
    display: block;
    width: auto;
    height: auto;
    max-width: 160px !important;
    max-height: 36px !important;
    object-fit: contain;
    object-position: left center;
}

.logo span,
.storefront-logo .logo-text {
    line-height: 1.2;
    white-space: nowrap;
}

/* ── Desktop links ────────────────────────────────────────────────── */
.nav-main,
.storefront-top-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
    margin: 0;
}

.nav-link,
.storefront-top-link {
    position: relative;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-link:hover,
.storefront-top-link:hover {
    color: var(--gray-900);
    background-color: var(--gray-100);
}

.nav-link.active,
.storefront-top-link.active {
    color: var(--primary-700, #1d4ed8);
    background-color: var(--primary-50, #eff6ff);
}

.nav-link.active::after,
.storefront-top-link.active::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -13px;
    height: 2px;
    border-radius: 2px;
    background: var(--primary-600, #2563eb);
}

/* ── Desktop search (flexes into available space) ─────────────────── */
.header-right .header-search {
    flex: 1 1 260px;
    width: auto;
    min-width: 160px;
    max-width: 320px;
}

#storefrontSearchWrapper {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 160px;
    max-width: 480px !important;
}

/* ── Action cluster ───────────────────────────────────────────────── */
.header-actions,
.storefront-header-actions {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    overflow: visible !important;
    min-width: 0;
}

.header-actions > *,
.storefront-header-actions > * {
    flex: 0 0 auto;
    margin: 0 !important;
}

/* Currency selector */
.nav-currency {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0 !important;
}

.nav-currency select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    height: var(--nav-ctrl-h);
    padding: 0 28px 0 12px;
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: var(--nav-radius);
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    color: var(--gray-700, #374151);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.nav-currency select:hover {
    border-color: var(--gray-300, #d1d5db);
}

.nav-currency select:focus-visible {
    border-color: var(--primary-500, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

/* Icon buttons (cart / favourites) */
.header-action-btn,
.storefront-action-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--nav-radius);
}

/* Auth buttons */
.nav-auth-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: var(--nav-ctrl-h);
    padding: 0 16px !important;
    border-radius: var(--nav-radius) !important;
    font-size: 14px !important;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

.nav-auth-signin {
    background: transparent;
    border: 1px solid var(--gray-200, #e5e7eb);
    color: var(--gray-800, #1f2937);
}

.nav-auth-signin:hover {
    border-color: var(--primary-300, #93c5fd);
    color: var(--primary-700, #1d4ed8);
    background: var(--primary-50, #eff6ff);
}

.nav-auth-signup {
    box-shadow: 0 6px 16px -6px rgba(37, 99, 235, 0.6);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background-color 0.15s ease;
}

.nav-auth-signup:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px -8px rgba(37, 99, 235, 0.6);
}

.nav-label-short { display: none; }

/* Hamburger (display is toggled in the media queries below) */
.mobile-menu-toggle,
.storefront-mobile-toggle {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    min-width: 40px;
    margin-right: -6px;
    border-radius: var(--nav-radius);
}

/* Drawer — ensure Pricing / Cart links etc. stay tidy */
.mobile-nav-link {
    white-space: nowrap;
}

/* ── Small desktop: tighten so links + search + actions fit ───────── */
@media (max-width: 1200px) {
    .header-left { gap: 16px; }
    .nav-link,
    .storefront-top-link { padding: 8px 10px; }
    .header-right .header-search { max-width: 240px; }
}

/* ── Tablet & below: logo · actions · hamburger ───────────────────── */
@media (max-width: 1024px) {
    .header-inner,
    .storefront-header-container {
        padding: 0 20px !important;
        gap: 12px !important;
    }

    .nav-main,
    .storefront-top-nav,
    .header-search,
    #storefrontSearchWrapper,
    .storefront-tickets-cta {
        display: none !important;
    }

    .header-left { gap: 0; }

    .mobile-menu-toggle,
    .storefront-mobile-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Push the action cluster to the far right on storefront pages */
    .storefront-header-actions { margin-left: auto !important; }
}

/* ── Phones ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    :root { --nav-ctrl-h: 36px; }

    .header-inner,
    .storefront-header-container {
        height: var(--nav-h-mobile) !important;
        padding: 0 16px !important;
        gap: 8px !important;
    }

    .logo img,
    .storefront-logo img {
        max-width: 128px !important;
        max-height: 30px !important;
    }

    .header-right,
    .header-actions,
    .storefront-header-actions {
        gap: 6px !important;
    }

    .nav-currency select {
        padding: 0 22px 0 9px;
        font-size: 12.5px;
        background-position: right 7px center;
        background-size: 10px;
    }

    .header-action-btn,
    .storefront-action-btn {
        width: 36px !important;
        height: 36px !important;
    }

    .nav-auth-btn {
        padding: 0 12px !important;
        font-size: 13px !important;
    }

    .nav-label-long  { display: none; }
    .nav-label-short { display: inline; }

    /* Avatar only — drop the chevron to save width */
    .storefront-header .user-menu-btn > svg { display: none; }

    .user-menu-dropdown {
        right: 0;
        left: auto;
        max-width: calc(100vw - 16px);
    }
}

/* ── Small phones: favourites move to the drawer ──────────────────── */
@media (max-width: 480px) {
    :root { --nav-ctrl-h: 34px; }

    .header-inner,
    .storefront-header-container {
        padding: 0 12px !important;
        gap: 6px !important;
    }

    .logo img,
    .storefront-logo img {
        max-width: 112px !important;
        max-height: 28px !important;
    }

    .header-right,
    .header-actions,
    .storefront-header-actions {
        gap: 4px !important;
    }

    .nav-optional { display: none !important; }

    .nav-auth-btn {
        padding: 0 10px !important;
        font-size: 12.5px !important;
    }

    .mobile-menu-toggle,
    .storefront-mobile-toggle {
        width: 38px;
        height: 38px;
        min-width: 38px;
        margin-right: -4px;
    }
}

/* ── Extra-small phones: "Sign Up" lives in the drawer ────────────── */
@media (max-width: 400px) {
    .nav-auth-signup { display: none !important; }
}

/* ── Tiny phones (≤ 340px, e.g. iPhone SE 1st gen / Galaxy Fold) ──── */
@media (max-width: 340px) {
    .header-inner,
    .storefront-header-container {
        padding: 0 8px !important;
    }

    .logo img,
    .storefront-logo img {
        max-width: 92px !important;
        max-height: 24px !important;
    }

    .nav-currency select {
        padding: 0 18px 0 7px;
        font-size: 12px;
        background-position: right 5px center;
    }

    .nav-auth-btn {
        padding: 0 8px !important;
        font-size: 12px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .header,
    .storefront-header,
    .nav-auth-signup {
        transition: none;
    }
}
