/* @critical header-bar */
.casablanca-header {
    --header-bg: var(--casablanca-bg-primary);
    /* Site Identity → Appearance → Header Borders / Header Icons. The theme's
       border token is re-pointed here so every border inside the header (the
       bottom rule, the search box, the results dropdown) follows the one
       colour; unset, it is the token's own brand-tinted value. */
    --casablanca-border: var(--casablanca-c-header-border, rgba(var(--casablanca-brand-rgb), 0.15));
    --header-border: var(--casablanca-border);
    --search-border: var(--casablanca-c-header-icons, var(--casablanca-brand));
    --accent-color: var(--casablanca-brand);
    background: var(--header-bg);
    position: sticky;
    /* Sticks below #wpadminbar when logged in, at 0 otherwise.
     * See --casablanca-admin-bar in assets/css/base.css. */
    top: var(--casablanca-admin-bar, 0px);
    z-index: 1000;
    width: 100%;
    border-bottom: 1px solid var(--casablanca-border);
}
/* @critical branding */
.header-container-full {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}
.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    gap: 12px;
}
/* @critical mobile-toggle */
/*
 * The WRAPPER is what appears and disappears, not the button inside it.
 *
 * main-header.php prints `<span class="header-icon-wrap"><button
 * class="mobile-menu-toggle">`. Hiding only the button left the span as a
 * zero-width flex item of .header-main-row, and .header-main-row is
 * `justify-content: space-between` — which spreads the free space between
 * EVERY item, including an invisible one. The logo was therefore pushed a
 * full gap away from the container's start edge on desktop (three visible
 * items, but four gaps' worth of distribution), and no amount of branding CSS
 * could pull it back, because nothing was wrong with the branding.
 *
 * Hiding the wrapper removes the item, so `space-between` sees only what is
 * actually on screen and the logo sits where the container starts.
 */
.header-icon-wrap {
    display: none;
}

.mobile-menu-toggle .action-icon {
    width: 32px;
    height: 32px;
}
.mobile-menu-toggle .action-icon svg {
    width: var(--casablanca-icon-size-7xl);
    height: var(--casablanca-icon-size-7xl);
    color: var(--casablanca-c-header-icons, var(--casablanca-brand));
}
.site-branding {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding-inline-end: 16px;
    position: relative;
}
.site-branding::after {
    content: '';
    position: absolute;
    inset-inline-end: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 18px;
    background: var(--casablanca-c-header-border, rgba(var(--casablanca-brand-rgb), 0.2));
}
/* The brand wrapper is an <h1> on the home page: it must look like the <div> it is elsewhere. */
.site-branding .site-title {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
    font: inherit;
    line-height: 1;
    color: inherit;
}
.casablanca-logo-text { color: inherit; text-decoration: none; }
.casablanca-logo-placeholder {
    width: 40px;
    height: 40px;
    background: var(--accent-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 800;
    font-size: 0.7rem;
}
.casablanca-logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}
.logo-top { font-family: var(--casablanca-font-primary); font-size: 0.65rem; }
.logo-main { font-weight: 900; font-size: 0.95rem; letter-spacing: -0.5px; }
.logo-bottom { font-family: var(--casablanca-font-primary); font-size: 0.6rem; align-self: flex-end; }

/* @critical desktop-nav */
.header-desktop-nav {
    flex-shrink: 1;
    min-width: 0;
    overflow: visible;
    margin-inline-start: 6px;
}
.header-desktop-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    white-space: nowrap;
}
.header-desktop-nav li {
    position: relative;
    padding: 8px 0;
}
.header-desktop-nav a {
    text-decoration: none;
    color: #111827;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 5px;
}
.header-desktop-nav li.menu-item-has-children > a::after {
    content: '';
    width: 11px;
    height: 11px;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M19 9L12 15L5 9' stroke='%23111827' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: contain;
    display: inline-block;
}
.header-desktop-nav a:focus-visible {
    color: var(--casablanca-brand);
}

.header-desktop-nav ul ul,
.header-desktop-nav .sub-menu {
    display: none;
    position: absolute;
    top: 100%;
    inset-inline-start: 0;
    min-width: 210px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: var(--casablanca-radius, 5px);
    padding: 6px 0;
    z-index: 10000;
    list-style: none;
    margin: 0;
    flex-direction: column;
    gap: 0;
}

.header-desktop-nav ul ul::before,
.header-desktop-nav .sub-menu::before {
    content: '';
    position: absolute;
    top: -10px;
    inset-inline: 0;
    height: 10px;
    background: transparent;
}

.header-desktop-nav li:hover > ul,
.header-desktop-nav li:focus-within > ul,
.header-desktop-nav li.menu-item-has-children:hover > .sub-menu {
    display: flex !important;
}

.header-desktop-nav ul ul li,
.header-desktop-nav .sub-menu li {
    padding: 0;
    margin: 0;
    width: 100%;
}

.header-desktop-nav ul ul a,
.header-desktop-nav .sub-menu a {
    display: block;
    padding: 9px 18px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #374151;
    text-transform: capitalize;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.header-desktop-nav li:hover > a {
    transform: none !important;
}

/* @critical search-form */
.header-search-container {
    flex-shrink: 1;
    max-width: 340px;
    width: 100%;
    position: relative;
    margin-inline-start: auto;
}
.header-search-form {
    position: relative;
    display: flex;
    align-items: center;
}
.search-field {
    width: 100%;
    /* Logical: the magnifier sits at the start edge, the close button at the
       end, and the desktop header is RTL (see the end of this file). */
    padding-block: 10px;
    padding-inline: 44px 40px;
    border: 1px solid var(--casablanca-border);
    border-radius: var(--casablanca-radius);
    font-size: 0.85rem;
    height: 40px;
    background: transparent;
}
.search-field:focus {
    outline: none;
    border-color: var(--search-border);
}
/*
 * type="search" gets a browser-drawn clear button (the blue × in WebKit/Blink)
 * and, in WebKit, extra decoration padding. The theme already has its own
 * .search-close, so the native one was a second, differently styled ×.
 */
.search-field {
    -webkit-appearance: none;
    appearance: none;
}
.search-field::-webkit-search-cancel-button,
.search-field::-webkit-search-decoration,
.search-field::-webkit-search-results-button,
.search-field::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}
.search-field::-ms-clear {
    display: none;
}
/* iOS/iPadOS zooms the page into any field under 16px on focus. */
@media (pointer: coarse) {
    .search-field {
        font-size: 16px;
    }
}
.search-submit {
    position: absolute;
    /* 24px hit target (WCAG 2.5.8), centred where the 20px box was centred. */
    inset-inline-start: 10px;
    background: none;
    border: none;
    color: var(--casablanca-c-header-icons, var(--casablanca-brand));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 24px;
    height: 24px;
}
.search-submit svg {
    width: var(--casablanca-icon-size-md);
    height: var(--casablanca-icon-size-md);
    display: block;
}
.search-close {
    position: absolute;
    inset-inline-end: 10px;
    background: rgba(0, 0, 0, 0.06);
    border: none;
    color: var(--casablanca-c-header-icons, var(--casablanca-brand));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: var(--casablanca-radius);
    opacity: 0.6;
}
.search-close svg {
    width: var(--casablanca-icon-size-md);
    height: var(--casablanca-icon-size-md);
    display: block;
}

/* @critical actions */
/* ── Header actions (account, categories, cart) ─────────────────── */
.header-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}
.header-action-item {
    background: none;
    border: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: #374151;
    text-decoration: none;
}
.action-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}
.action-icon svg { 
    width: var(--casablanca-icon-size-7xl);
    height: var(--casablanca-icon-size-7xl);
    color: var(--casablanca-c-header-icons, var(--casablanca-brand));
}

/* ── Action label (shared) ──────────────────────────────────────── */
.action-label {
    display: none;
}
.cart-count {
    position: absolute;
    top: -2px;
    inset-inline-end: -6px;
    background: var(--casablanca-c-cart-badge, var(--casablanca-brand));
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    /* Cart count dot — intentionally exempt from --casablanca-radius. */
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 1.5px solid white;
}

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    inset-inline: 0;
    background: #fff;
    border: 1px solid var(--casablanca-border);
    border-radius: var(--casablanca-radius);
    z-index: 1000;
    display: none;
    max-height: 500px;
    overflow-y: auto;
}
.search-results-dropdown::before {
    content: '';
    position: absolute;
    top: -6px;
    inset-inline-start: 40px;
    width: 12px;
    height: 12px;
    background: #fff;
    border-top: 1px solid var(--casablanca-border);
    border-inline-start: 1px solid var(--casablanca-border);
}
.search-results-dropdown.is-active {
    display: block;
}
.search-results-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    z-index: 1;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    text-decoration: none;
    border-radius: var(--casablanca-radius);
    border: 1px solid transparent;
}
.result-image {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    border-radius: var(--casablanca-radius);
    overflow: hidden;
    background: #f3f4f6;
    border: 1px solid #f0f0f0;
}
.result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.result-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.result-title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}
.result-price {
    display: flex;
    align-items: center;
    gap: 8px;
}
.result-price del {
    font-size: 0.65rem;
    color: #687079;
    text-decoration: line-through;
    font-weight: 300;
    opacity: 0.6;
    margin-inline-end: 4px;
}
.result-price ins, 
.result-price > .amount,
.result-price ins .amount {
    font-size: 0.85rem;
    color: #111827 !important;
    font-weight: 700;
    text-decoration: none !important;
}
.search-results-footer {
    padding: 12px;
    border-top: 1px solid var(--casablanca-border);
    text-align: center;
    background: #fcfcfc;
    border-radius: 0 0 var(--casablanca-radius) var(--casablanca-radius);
}
.view-all-results {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--casablanca-brand);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.no-results {
    padding: 30px 20px;
    text-align: center;
    font-size: 0.85rem;
    color: #6b7280;
}
.search-results-dropdown.is-loading .search-results-content {
    opacity: 0.5;
}

@media (max-width: 1023px) {
    .header-desktop-nav,
    .header-search-container {
        display: none;
    }
    .action-account {
        display: none;
    }
    .header-icon-wrap {
        display: flex;
        align-items: center;
    }
    /*
     * The toggle button (1 icon) and the actions block (2 icons) never have
     * equal widths, so centering the logo with justify-content:space-between
     * on 3 flex siblings always drifts it toward whichever side is narrower.
     * A 1fr/auto/1fr grid keeps the two side columns equal by definition, so
     * the logo column is always dead-center regardless of icon count.
     */
    .header-main-row {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        padding: 4px 0;
        /* No border-bottom here. .header-main-row is the only child of
         * .header-container-full, which is the only child of .casablanca-header, so
         * a border here lands on the exact same line as .casablanca-header's own
         * border-bottom and renders as a doubled 2px rule. The header keeps
         * the single border for every breakpoint. */
    }
    /*
     * Each item names its own column instead of being auto-placed.
     *
     * Auto-placement fills columns in DOM order, so the moment the menu icon
     * is absent — Customizer > "Header Icons" > menu off, which makes
     * main-header.php print no .header-icon-wrap at all — the branding fell
     * into column 1 and the actions into column 2, leaving an empty 1fr on
     * the end: the logo hard left, the icons stranded mid-row. Pinned
     * columns keep the logo in the centre column whatever is or is not
     * rendered beside it.
     *
     * This also used to name `.mobile-menu-toggle`, which is the BUTTON and
     * never a child of .header-main-row — the span wrapping it is. The rule
     * matched nothing.
     */
    .header-main-row > .header-icon-wrap {
        grid-column: 1;
        justify-self: start;
    }
    .header-main-row > .site-branding {
        grid-column: 2;
        justify-self: center;
        padding-inline-end: 0;
    }
    .header-main-row > .site-branding::after {
        display: none;
    }
    .header-main-row > .header-actions {
        grid-column: 3;
        justify-self: end;
    }
    .action-label { display: none; }
    .action-icon {
        width: 32px;
        height: 32px;
    }
    .action-icon svg { 
        width: var(--casablanca-icon-size-7xl);
        height: var(--casablanca-icon-size-7xl);
    }
    .search-results-dropdown {
        position: fixed;
        top: calc(60px + var(--casablanca-admin-bar, 0px));
        inset-inline: 10px;
        width: auto;
        border-radius: var(--casablanca-radius);
        border: 1px solid var(--casablanca-border);
    }
}
@media (max-width: 767px) {
    .header-container-full { padding: 0 10px; }
    .header-main-row { 
        gap: 6px;
        padding: 2px 0;
    }
    .site-branding { gap: 4px; padding-inline-end: 0; }
    .site-branding::after { display: none; }
    .casablanca-logo-placeholder { 
        width: 28px;
        height: 28px; 
        font-size: 0.55rem;
    }
    .logo-main { font-size: 0.8rem; }
    .header-actions { gap: 10px; }
    .action-icon {
        width: 28px;
        height: 28px;
    }
    .action-icon svg { 
        width: var(--casablanca-icon-size-6xl);
        height: var(--casablanca-icon-size-6xl);
    }
    .cart-count { min-width: 14px; height: 14px; font-size: 8px; inset-inline-end: -4px; top: -1px; }
    .hide-header-menu-icon .header-icon-wrap {
        display: none;
    }
}

/* Per-breakpoint header icon visibility (Customizer → Header Icon Visibility).
 * 1023px is the header's own mobile boundary (the search bar hides there). */
@media (min-width: 1024px) {
    .header-action-item.is-hidden-desktop {
        display: none;
    }
}
@media (max-width: 1023px) {
    .header-action-item.is-hidden-mobile {
        display: none;
    }
}

/* Desktop header reads RTL: logo on the right with the menu beside it, the
 * search and the icons on the left. Scoped to .casablanca-header only — the
 * menu, categories and cart drawers are siblings of <header>, so they keep
 * their LTR side and slide direction. Desktop only (1024px, the header's own
 * boundary): the mobile bar keeps its LTR order. A `direction` in a media
 * query rather than a dir attribute, because an attribute cannot be scoped to
 * a breakpoint. Every header rule is a logical property, so this is enough. */
@media (min-width: 1024px) {
    .casablanca-header {
        direction: rtl;
    }
}
