/* ============================================
   Site header (Layout/_Header)

   Three columns, 1fr auto 1fr: the logo left, the search in the middle (truly centred, not
   just in the leftover space), the menu button right. Every link lives in the drawer
   (Layout/_Drawer, drawer.css).
   Phones: a full-width sticky bar with the logo and the menu button only (the search is the tab
   bar's Search button, which opens the search sheet); it moves as the guest scrolls (see "Phones:
   the bars move" below).
   768px and up: a floating glass pill; the middle is the labelled Where + Who search.
   Pages without a search (hosting, account, booking, the listing page) keep the logo and the
   menu button only.
   ============================================ */

/* The header is sticky inside <body>, so <body> must be as tall as the page, not the viewport
   (style.css sets height: 100% for the old layout). */
body {
    height: auto;
    min-height: 100%;
}

.bl-header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    padding-top: var(--safe-top);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border-light);
}

.bl-header__bar {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2);
    min-height: 60px;
    padding: var(--space-2) var(--gutter);
}

/* Desktop glass layer (see the 768px block). */
.bl-header__surface {
    display: none;
}

/* --- Logo --- */
.bl-header__logo {
    grid-column: 1;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    border-radius: var(--radius-md);
}

.bl-header__logo img {
    display: block;
    width: auto;
    height: 36px;
}

.bl-header__logo .bl-header__logo-mark {
    display: none;
}

/* --- Search: the labelled pill, from 768px only --- */
.bl-header__search {
    display: none;
}

/* --- Menu button: opens the drawer --- */
/* --- Hosting tabs (Listings | Calendar), on /Owner pages from 768px; phones use the tab bar --- */
.bl-header__hosting {
    display: none;
}

@media (min-width: 768px) {
    .bl-header__hosting {
        grid-column: 2;
        justify-self: center;
        display: flex;
        align-items: center;
        gap: var(--space-6);
    }

    .bl-header__hosting-tab {
        position: relative;
        display: inline-flex;
        align-items: center;
        min-height: 44px;
        padding: 0 var(--space-1);
        color: var(--color-text-muted);
        font-size: 15px;
        font-weight: 500;
        text-decoration: none;
        transition: color var(--duration-fast) var(--ease-out);
    }

    .bl-header__hosting-tab::after {
        content: "";
        position: absolute;
        left: var(--space-1);
        right: var(--space-1);
        bottom: 8px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
        transform: scaleX(0);
        transition: transform var(--duration-base) var(--ease-out);
    }

    .bl-header__hosting-tab:hover,
    .bl-header__hosting-tab:focus-visible,
    .bl-header__hosting-tab[aria-current] {
        color: var(--color-ink);
        text-decoration: none;
    }

    .bl-header__hosting-tab[aria-current] {
        font-weight: 600;
    }

    .bl-header__hosting-tab[aria-current]::after {
        transform: scaleX(1);
    }

    .bl-header__hosting-tab:focus-visible {
        outline: 2px solid var(--color-focus);
        outline-offset: 2px;
        border-radius: var(--radius-sm);
    }
}

@media (prefers-reduced-motion: reduce) {
    .bl-header__hosting-tab,
    .bl-header__hosting-tab::after {
        transition: none;
    }
}

.bl-header__actions {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
}

.bl-header__menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    min-width: 44px;
    min-height: 44px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    background: var(--color-surface);
    color: var(--color-ink);
    font-size: 17px;
    line-height: 1;
    text-decoration: none;
    transition: border-color var(--duration-fast) var(--ease-out), scale var(--press-duration) var(--press-ease);
}

.bl-header__menu-btn:hover,
.bl-header__menu-btn:focus {
    color: var(--color-ink);
    text-decoration: none;
}

.bl-header__menu-btn[aria-expanded="true"] {
    border-color: var(--color-ink);
}

.bl-header__menu-btn:active {
    scale: 0.97;
}

/* The avatar shares the menu button from 768px; on phones the button stays a 44px circle.
   The profile picture covers the initial; one that fails to load (alt="") leaves the letter. */
.bl-header__avatar {
    position: relative;
    display: none;
    place-items: center;
    overflow: hidden;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-ink);
    color: var(--color-surface);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
}

.bl-header__avatar-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

@media (hover: hover) and (pointer: fine) {
    .bl-header__menu-btn:hover {
        border-color: var(--color-text-light);
    }
}

/* ============================================
   Phones: the bars move (header.js puts the state on <html>)

   At the top (no class): the full white bar. Scrolling down (html.bl-bars-down) the header slides
   up out of sight; scrolling up mid-page (html.bl-bars-up) only the logo, in a white pill, and the
   round menu button come back, floating with a soft shadow so they read over photos, until the
   top brings the white bar back under them. The bar is its own layer (::before) so it can fade;
   going down, the bar, the pill and the shadow wait until the header has left
   (transition-delay), so the whole white bar slides away. Only translate and opacity move.
   A translate makes the header the containing block of fixed descendants: the phone header has
   none (the search slot isn't shown; the drawer and the search sheet are its siblings).
   ============================================ */
@media (max-width: 767.98px) {
    .bl-header {
        background: none;
        /* The 1px stays, so nothing below moves; the layer draws the line. */
        border-bottom-color: transparent;
        transition: translate var(--duration-base) var(--ease-out);
    }

    .bl-header::before {
        content: "";
        position: absolute;
        inset: 0 0 -1px;
        z-index: -1;
        border-bottom: 1px solid var(--color-border-light);
        background: var(--color-surface);
        pointer-events: none;
        transition: opacity var(--duration-fast) var(--ease-out);
    }

    .bl-header__logo {
        position: relative;
        isolation: isolate;
        transition: translate var(--duration-base) var(--ease-out);
    }

    .bl-header__logo img {
        transition: scale var(--duration-base) var(--ease-out);
    }

    /* The logo's pill while it floats. Part of the link, so it takes the tap too. */
    .bl-header__logo::before {
        content: "";
        position: absolute;
        inset: 0 calc(-1 * var(--space-3));
        z-index: -1;
        border-radius: var(--radius-pill);
        background: var(--color-surface);
        box-shadow: var(--shadow-2);
        opacity: 0;
        transition: opacity var(--duration-fast) var(--ease-out);
    }

    .bl-header__menu-btn {
        position: relative;
    }

    /* The round button is white already: floating, it only gains a shadow. */
    .bl-header__menu-btn::after {
        content: "";
        position: absolute;
        inset: -1px;
        border-radius: inherit;
        box-shadow: var(--shadow-2);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--duration-fast) var(--ease-out);
    }

    html.bl-bars-up .bl-header::before,
    html.bl-bars-down .bl-header::before {
        opacity: 0;
    }

    /* The pill's left edge on the gutter, as the button's right edge is. */
    html.bl-bars-up .bl-header__logo,
    html.bl-bars-down .bl-header__logo {
        translate: var(--space-3) 0;
    }

    /* A little smaller inside its pill, so it has room all round. */
    html.bl-bars-up .bl-header__logo img,
    html.bl-bars-down .bl-header__logo img {
        scale: 0.9;
    }

    html.bl-bars-up .bl-header__logo::before,
    html.bl-bars-down .bl-header__logo::before,
    html.bl-bars-up .bl-header__menu-btn::after,
    html.bl-bars-down .bl-header__menu-btn::after {
        opacity: 1;
    }

    /* Hidden: up and out of sight, the chips' shadow included. */
    html.bl-bars-down .bl-header {
        translate: 0 calc(-100% - var(--space-8));
    }

    html.bl-bars-down .bl-header::before,
    html.bl-bars-down .bl-header__logo,
    html.bl-bars-down .bl-header__logo img,
    html.bl-bars-down .bl-header__logo::before,
    html.bl-bars-down .bl-header__menu-btn::after {
        transition-delay: var(--duration-base);
    }

    /* Floating, the see-through strip between the logo and the button passes taps to the page.
       Hidden, the two keep theirs: they are off screen, out of a finger's reach, and a screen
       reader's activation (VoiceOver's synthesized tap) still reaches them. */
    html.bl-bars-up .bl-header,
    html.bl-bars-down .bl-header {
        pointer-events: none;
    }

    html.bl-bars-up .bl-header__logo,
    html.bl-bars-up .bl-header__menu-btn,
    html.bl-bars-down .bl-header__logo,
    html.bl-bars-down .bl-header__menu-btn {
        pointer-events: auto;
    }
}

/* Reduced motion: the header fades out and back in place instead of sliding. */
@media (max-width: 767.98px) and (prefers-reduced-motion: reduce) {
    .bl-header {
        transition: opacity var(--duration-fast) var(--ease-out);
    }

    html.bl-bars-down .bl-header {
        translate: none;
        opacity: 0;
    }

    /* Faded out in place, they would catch a finger meant for the page under them. */
    html.bl-bars-down .bl-header__logo,
    html.bl-bars-down .bl-header__menu-btn {
        pointer-events: none;
    }

    .bl-header__logo,
    .bl-header__logo img {
        transition: none;
    }
}

/* ============================================
   768px and up: the floating pill
   ============================================ */
@media (min-width: 768px) {
    .bl-header {
        padding: calc(var(--space-3) + var(--safe-top)) var(--space-4) 0;
        background: transparent;
        border-bottom: 0;
        /* The transparent margin around the pill must not swallow clicks on the page beneath. */
        pointer-events: none;
    }

    /* Symmetric padding: the grid's middle column is then centred on the pill itself. */
    .bl-header__bar,
    .bl-header__bar--search {
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        gap: var(--space-4);
        max-width: var(--page-max);
        min-height: 60px;
        margin: 0 auto;
        padding: var(--space-2);
        border-radius: var(--radius-pill);
        isolation: isolate;
        pointer-events: auto;
    }

    /* The glass lives on its own layer: a backdrop-filter on the bar would make it the containing
       block of the fixed Who pop-over and throw off its placement. */
    .bl-header__surface {
        position: absolute;
        inset: 0;
        z-index: -1;
        display: block;
        border: 1px solid color-mix(in srgb, var(--color-ink) 7%, transparent);
        border-radius: inherit;
        background: var(--color-surface);
        background: color-mix(in srgb, var(--color-surface) 96%, transparent);
        box-shadow: var(--shadow-1);
        pointer-events: none;
    }

    /* The glass only once the page has scrolled under the pill (header.js sets .is-scrolled). A
       backdrop-filter is redrawn every frame anything beneath it moves (the hero carousel and the
       New Year fireworks sit right under the pill at the top), which cost weak phones their
       frame rate; at the top there is nothing to blur, so a near-opaque pill looks the same. */
    .bl-header.is-scrolled .bl-header__surface {
        background: color-mix(in srgb, var(--color-surface) 84%, transparent);
        -webkit-backdrop-filter: saturate(1.8) blur(18px);
        backdrop-filter: saturate(1.8) blur(18px);
    }

    /* Carrying the search, the pill sits a little higher (--shadow-2). */
    body.has-header-search .bl-header__surface {
        box-shadow: var(--shadow-2);
    }

    .bl-header__logo {
        margin-left: var(--space-3);
    }

    .bl-header__logo .bl-header__logo-full {
        display: block;
    }

    .bl-header__logo .bl-header__logo-mark {
        display: none;
    }

    /* 768–1023 with the search: the logo mark, so the centred pill keeps its width. */
    .bl-header__bar--search .bl-header__logo .bl-header__logo-full {
        display: none;
    }

    .bl-header__bar--search .bl-header__logo .bl-header__logo-mark {
        display: block;
    }

    /* No transform, translate or scale on the slot: any would make it the containing block of
       the fixed Who pop-over inside the search and throw off its placement. */
    /* Where · Who · What (and the reset beside Search): 520px from 768px, 600px from 1024px,
       640px from 1280px. */
    .bl-header__search {
        grid-column: 2;
        display: block;
        width: 520px;
    }

    .bl-header__search .bl-search--header {
        max-width: none;
    }

    .bl-header__menu-btn {
        padding: 0 var(--space-4);
    }

    /* Signed in: bars + the avatar initial in one pill (Airbnb-style), one control for both. */
    .bl-header__menu-btn:has(.bl-header__avatar) {
        padding: 4px 4px 4px 14px;
    }

    .bl-header__avatar {
        display: grid;
    }
}

@media (min-width: 1024px) {
    .bl-header__bar--search .bl-header__logo .bl-header__logo-full {
        display: block;
    }

    .bl-header__bar--search .bl-header__logo .bl-header__logo-mark {
        display: none;
    }

    .bl-header__search {
        width: 600px;
    }
}

@media (min-width: 1280px) {
    .bl-header__search {
        width: 640px;
    }
}

/* Reduced motion: presses don't shrink. */
@media (prefers-reduced-motion: reduce) {
    .bl-header__menu-btn:active {
        scale: 1;
    }
}
