/* Briod's site header (#24)
   ==========================
   Markup: template-parts/header-briod.php. Behaviour: js/header.js.
   The measures are the design's, from design/header/README.md; where this
   file departs from it, a comment says why.

   Layout by width:
     ≥ 1360   logo on row 1; menu left and search · divider · buttons right on row 2
     993–1359 logo and search · divider · buttons on row 1; the menu on row 2
     993–1279 as above, with smaller buttons
     < 993    phones: 68px bar (logo, search, menu button), buttons under it,
              the menu as a full-screen panel
   Scrolled past (.bh-holder.is-scrolled), the header is a slim fixed bar.

   The bar is as wide as the page's content (Shoptimizer's .col-full: 1170px
   plus 2.617924em each side), not the whole window as in the design's frames,
   so the logo lines up with the content under it on wide screens. */

.bh-holder {
    position: relative;
    z-index: 100;
}

.bh {
    --bh-bg: #202531;
    --bh-red: #e52a1e;
    --bh-red-hover: #c8241a;
    --bh-line: rgba(255, 255, 255, .15);
    position: relative;
    background: var(--bh-bg);
    color: #fff;
    font-family: 'Sofia Pro', Helvetica, Arial, sans-serif;
    font-weight: 700;
    -webkit-font-smoothing: antialiased;
}
.bh a,
.bh a:hover,
.bh a:focus { color: #fff; text-decoration: none; }
.bh ul { margin: 0; padding: 0; list-style: none; }
.bh li { margin: 0; }
/* The theme styles bare buttons (background, padding, min-height); none of
   the header's buttons is one of those. */
.bh button {
    margin: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    min-height: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
}
.bh :focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.bh__bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    grid-template-areas:
        "logo search divider ctas"
        "nav  nav    nav     nav";
    align-items: center;
    column-gap: 22px;
    row-gap: 18px;
    box-sizing: content-box;
    max-width: 1170px;
    margin: 0 auto;
    padding: 20px 2.617924em 16px;
}
@media (min-width: 1360px) {
    .bh__bar {
        grid-template-areas:
            "logo .      .       .   "
            "nav  search divider ctas";
    }
}

.bh__logo {
    grid-area: logo;
    justify-self: start;
    display: block;
    width: 112px;
    line-height: 0;
}
.bh__logo svg { display: block; width: 100%; height: auto; }

.bh__nav { grid-area: nav; min-width: 0; margin-right: 10px; /* 22 + 10: the design's 32px to the right-hand group */ }
.bh__search { grid-area: search; position: relative; display: flex; }
.bh__divider { grid-area: divider; width: 1px; height: 40px; background: rgba(255, 255, 255, .45); }
.bh__ctas { grid-area: ctas; display: flex; gap: 10px; }

.bh .bh__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    color: #fff;
    transition: color .15s ease;
}
.bh .bh__menu-toggle { display: none; }   /* phones only */
/* Only with a real pointer: on a phone a tap would leave the icon red. */
@media (hover: hover) {
    .bh .bh__icon:hover { color: var(--bh-red); }
}

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

.bh-menu {
    display: flex;
    flex-wrap: wrap;
    row-gap: 8px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0;
    white-space: nowrap;
}
.bh-menu > li { position: relative; display: flex; align-items: center; }
.bh-menu > li > a {
    display: flex;
    align-items: center;
    padding: 6px .55em;
    transition: opacity .2s;
}
.bh-menu > li:first-child > a { padding-left: 0; }
.bh-menu > li.menu-item-has-children > a { padding-right: 0; }
.bh-menu__label { position: relative; }

.bh .bh-menu__toggle {
    display: flex;
    align-items: center;
    padding: 6px .55em 6px 6px;
    transition: opacity .2s;
}
.bh-menu__toggle svg { transition: transform .4s; }
.bh-menu > li.is-open > .bh-menu__toggle svg { transform: rotate(180deg); }

@media (min-width: 993px) {
    /* The red line under the item grows from the left, and leaves to the
       right: the transform-origin flips with the state. */
    .bh-menu > li > a .bh-menu__label::after {
        content: "";
        position: absolute;
        left: 0;
        top: calc(100% + 4px);
        width: 100%;
        border-bottom: 2px solid var(--bh-red);
        transform: scale(0, 1);
        transform-origin: right center;
        transition: transform .6s cubic-bezier(.28, .75, .22, .95);
    }
    .bh-menu > li:hover > a .bh-menu__label::after,
    .bh-menu > li.is-open > a .bh-menu__label::after,
    .bh-menu > li > a:focus-visible .bh-menu__label::after {
        transform: scale(1, 1);
        transform-origin: left center;
    }
    /* Pointing at one item dims the others. */
    .bh-menu:hover > li > a,
    .bh-menu:hover > li > .bh-menu__toggle { opacity: .65; }
    .bh-menu > li:hover > a,
    .bh-menu > li:hover > .bh-menu__toggle { opacity: 1; }
    .bh-menu > li:hover > .bh-menu__toggle svg { transform: rotate(180deg); }

    /* Sub-menu: opens on hover, or from the caret button (click, keyboard).
       It hangs 16px under the item, level with the header's bottom edge; the
       ::before bridges that gap so the pointer can cross it. */
    .bh-menu .sub-menu {
        position: absolute;
        top: 100%;
        left: -20px;
        z-index: 6;
        min-width: 280px;
        margin-top: 16px;
        padding: 8px 0 12px;
        background: var(--bh-bg);
        border-top: 1px solid var(--bh-line);
        border-radius: 0 0 6px 6px;
        box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
        visibility: hidden;
        opacity: 0;
        transition: opacity .15s ease, visibility .15s;
    }
    .bh-menu .sub-menu::before {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 100%;
        height: 17px;
    }
    .bh-menu > li:hover > .sub-menu,
    .bh-menu > li.is-open > .sub-menu { visibility: visible; opacity: 1; }
    .bh-menu .sub-menu a {
        display: flex;
        padding: 10px 20px;
        font-size: 15px;
        font-weight: 600;
        transition: color .15s ease;
    }
    .bh .bh-menu .sub-menu a:hover,
    .bh .bh-menu .sub-menu a:focus-visible { color: var(--bh-red); }
}

/* ── Buttons ──────────────────────────────────────────────────────────── */

.bh .bh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 30px;
    border: 1px solid #fff;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0;
    white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.bh .bh-btn--outline { background: transparent; color: #fff; }
.bh .bh-btn--outline:hover { background: #fff; color: var(--bh-bg); }
.bh .bh-btn--solid { border-color: var(--bh-red); background: var(--bh-red); color: #fff; }
.bh .bh-btn--solid:hover { border-color: var(--bh-red-hover); background: var(--bh-red-hover); color: #fff; }

@media (min-width: 993px) and (max-width: 1279px) {
    .bh .bh-btn { min-height: 42px; padding: 0 14px; font-size: 14px; }
}

/* ── Search ───────────────────────────────────────────────────────────── */

.bh__search-panel {
    position: absolute;
    top: calc(100% + 14px);
    right: -10px;
    z-index: 5;
    width: 380px;
    max-width: calc(100vw - 48px);
    box-sizing: border-box;
    background: var(--bh-bg);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 6px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
}
.bh__search-panel[hidden] { display: none; }
/* The arrow pointing up at the search icon. */
.bh__search-panel::before {
    content: "";
    position: absolute;
    top: -7px;
    right: 22px;
    width: 12px;
    height: 12px;
    background: var(--bh-bg);
    border-top: 1px solid rgba(255, 255, 255, .18);
    border-left: 1px solid rgba(255, 255, 255, .18);
    transform: rotate(45deg);
}
.bh__search-form {
    position: relative;   /* above the arrow */
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0;
    padding: 12px 16px;
}
.bh__search-form > svg { flex-shrink: 0; color: #fff; }
.bh .bh__search-input {
    flex: 1;
    min-width: 0;
    height: auto;
    margin: 0;
    padding: 6px 0;
    border: 0;
    border-radius: 0;
    outline: none;
    background: none;
    box-shadow: none;
    color: #fff;
    font: 400 16px 'Sofia Pro', Helvetica, Arial, sans-serif;
}
.bh .bh__search-input::placeholder { color: #c9ccd0; opacity: 1; }
.bh .bh__search-input::-webkit-search-cancel-button { display: none; }
.bh .bh__search-close { display: flex; padding: 4px; color: #fff; }

/* ── Live results (#25) ───────────────────────────────────────────────── */

.bh__search-panel.has-results { width: 440px; }
.bh__results {
    position: relative;   /* above the arrow */
    max-height: min(560px, 70vh);
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 0 0 5px 5px;
    background: #fff;
    color: #202531;
    font-weight: 400;
    text-align: left;
    white-space: normal;
}
.bh__results[hidden] { display: none; }
.bh .bh__results a,
.bh .bh__results a:hover,
.bh .bh__results a:focus { color: #202531; }
.bh__results a {
    display: flex;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid #e6e8eb;
    transition: background .15s ease;
}
.bh .bh__results a:hover,
.bh .bh__results a:focus-visible { background: #f6f7f9; outline: none; }

.bh-r__product { align-items: center; }
.bh-r__thumb {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    overflow: hidden;
    border-radius: 4px;
    background: #eef1f4;
}
.bh-r__thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.bh-r__text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bh-r__name { font-size: 15px; font-weight: 700; line-height: 1.25; }
.bh-r__price { font-size: 14px; font-weight: 600; line-height: 1.2; }

.bh-r__row { align-items: baseline; justify-content: space-between; }
.bh-r__title { font-size: 15px; line-height: 1.35; text-wrap: pretty; }
.bh-r__type,
.bh-r__head {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #8a8f95;
}
.bh-r__type { flex-shrink: 0; white-space: nowrap; }
.bh-r__head { padding: 18px 20px 8px; }

.bh .bh__results .bh-r__all {
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 20px;
    border-bottom: 0;
    background: #f3f4f6;
    font-size: 14px;
    font-weight: 600;
}
.bh .bh__results .bh-r__all:hover,
.bh .bh__results .bh-r__all:focus-visible { background: #e9ebee; }

.bh-r__none { margin: 0; padding: 20px; font-size: 15px; color: #54595F; }

/* ── Scrolled: the slim bar ───────────────────────────────────────────── */

.bh-holder.is-scrolled .bh {
    position: fixed;
    top: var(--wp-admin--admin-bar--height, 0px);
    left: 0;
    right: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
    animation: bh-in .25s ease-out;
}
@keyframes bh-in {
    from { transform: translateY(-100%); }
}
@media (prefers-reduced-motion: reduce) {
    .bh-holder.is-scrolled .bh { animation: none; }
}
/* Below 601px WordPress's admin bar scrolls away with the page. */
@media (max-width: 600px) {
    .bh-holder.is-scrolled .bh { top: 0; }
}

@media (min-width: 993px) {
    .is-scrolled .bh__bar {
        grid-template-columns: auto minmax(0, 1fr) auto auto auto;
        grid-template-areas: "logo nav search divider ctas";
        row-gap: 0;
        column-gap: 16px;
        min-height: 64px;
        padding-top: 0;
        padding-bottom: 0;
    }
    .is-scrolled .bh__logo { width: 70px; margin-right: 16px; /* the design's 32px column gap */ }
    .is-scrolled .bh__nav { margin-right: 16px; }
    .is-scrolled .bh__divider { height: 28px; }
    .is-scrolled .bh .bh-btn { min-height: 32px; padding: 0 16px; font-size: 13px; }
    .is-scrolled .bh-menu .sub-menu { margin-top: 17px; }
}
/* Under 1240px the slim bar cannot hold the menu (624px at 14px) and the two
   buttons (259px) on one row: at 993px the menu gets 467px and wrapped onto a
   second line. The design has no frame this narrow. The menu stays and the
   buttons go; they are back as soon as the full header is. */
@media (min-width: 993px) and (max-width: 1239px) {
    .is-scrolled .bh__divider,
    .is-scrolled .bh__ctas { display: none; }
    .is-scrolled .bh__logo,
    .is-scrolled .bh__nav { margin-right: 4px; }
    .is-scrolled .bh-menu { font-size: 14px; }
    .is-scrolled .bh-menu > li > a { padding: 6px .4em; }
    .is-scrolled .bh-menu > li:first-child > a { padding-left: 0; }
    .is-scrolled .bh-menu > li.menu-item-has-children > a { padding-right: 0; }
    .is-scrolled .bh .bh-menu__toggle { padding-right: .4em; }
}

/* ── Phones ───────────────────────────────────────────────────────────── */

@media (max-width: 992px) {
    .bh__bar {
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "logo search menu"
            "ctas ctas   ctas";
        column-gap: 4px;
        row-gap: 0;
        max-width: none;
        padding: 0 12px 0 20px;
    }
    .bh__logo { display: flex; align-items: center; width: 84px; height: 68px; }
    .bh__nav { margin-right: 0; }
    .bh__divider { display: none; }

    .bh .bh__icon { width: 44px; height: 44px; padding: 0; }
    .bh__search-toggle svg { width: 24px; height: 24px; }
    .bh .bh__menu-toggle { display: flex; grid-area: menu; }
    .bh__menu-close,
    .bh.is-menu-open .bh__menu-open { display: none; }
    .bh.is-menu-open .bh__menu-close { display: block; }

    /* The bar's padding is 20px left and 12px right; the buttons' row is 20px
       in from both edges. */
    .bh__ctas { padding: 0 8px 14px 0; }
    .bh .bh-btn { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0 12px; font-size: 14px; }

    /* Search: a row across the full width, under the header. */
    .bh__search { position: static; }
    .bh__search-panel {
        top: 100%;
        left: 0;
        right: 0;
        width: auto;
        max-width: none;
        border: 0;
        border-top: 1px solid var(--bh-line);
        border-radius: 0;
    }
    .bh__search-panel::before { display: none; }
    .bh__search-form { gap: 12px; padding: 6px 12px 6px 20px; }
    .bh__search-form > svg { width: 20px; height: 20px; }
    .bh .bh__search-input { padding: 10px 0; }
    .bh .bh__search-close { width: 44px; height: 44px; justify-content: center; align-items: center; padding: 0; }
    .bh__search-close svg { width: 16px; height: 16px; }
    .bh__search-panel.has-results { width: auto; }
    .bh__results { max-height: 70vh; border-radius: 0; }

    /* Menu: full screen under the header. js/header.js sets --bh-bottom to
       where the header ends when it opens. */
    .bh__nav {
        display: none;
        position: fixed;
        top: var(--bh-bottom, 122px);
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 5;
        padding: 8px 20px 28px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: var(--bh-bg);
        border-top: 1px solid var(--bh-line);
    }
    .bh.is-menu-open .bh__nav { display: block; }

    .bh-menu { display: block; white-space: normal; }
    .bh-menu > li { flex-wrap: wrap; border-bottom: 1px solid rgba(255, 255, 255, .12); }
    .bh-menu > li > a,
    .bh-menu > li:first-child > a { flex: 1; min-height: 56px; padding: 0; }
    .bh .bh-menu__toggle { justify-content: center; width: 44px; height: 56px; padding: 0; }
    .bh-menu__toggle svg { transition-duration: .3s; }

    .bh-menu .sub-menu { display: none; flex-basis: 100%; padding: 0 0 12px 16px; }
    .bh-menu > li.is-open > .sub-menu { display: block; }
    .bh .bh-menu .sub-menu a {
        display: flex;
        align-items: center;
        min-height: 44px;
        font-size: 15px;
        font-weight: 600;
        color: rgba(255, 255, 255, .82);
    }

    /* Scrolled: only the 68px bar stays. */
    .is-scrolled .bh__ctas { display: none; }
}

/* While the phone menu is open, the page under it does not scroll. */
body.bh-menu-locked { overflow: hidden; }
