/**
 * Site search — global icon trigger + overlay + autosuggest dropdown.
 *
 * Plain CSS (no SCSS / Tailwind dependency) so it works without a
 * build step. OKLCH values come from the `primary` brand color
 * (#134093 → oklch(39.6% 0.145 261.4)) for visual consistency.
 */

/* ---------- Trigger button (sits inside the header actions) ---------- */
.site-search-trigger {
    color: currentColor;
}

/* ---------- Overlay ---------- */
.site-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 1rem 1rem;
    background: oklch(20% 0.10 261.4 / 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.18s ease-out;
}

.site-search-overlay.is-open {
    opacity: 1;
}

.site-search-overlay__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: oklch(100% 0 0 / 0.92);
    color: oklch(15% 0.030 261.4);
    cursor: pointer;
    transition: background 0.15s ease;
}

.site-search-overlay__close svg {
    width: 16px;
    height: 16px;
}

.site-search-overlay__close:hover {
    background: oklch(100% 0 0);
}

@media (width >= 768px) {
    .site-search-overlay__close {
        width: 44px;
        height: 44px;
    }
    .site-search-overlay__close svg {
        width: 24px;
        height: 24px;
    }
}

.site-search-overlay__panel {
    width: 100%;
    max-width: 720px;
    transform: translateY(-12px);
    transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.site-search-overlay.is-open .site-search-overlay__panel {
    transform: translateY(0);
}

/* Lock body and html scroll while the overlay is open (class added
   via JS). Force-overrides any Tailwind utility on body that might
   leave overflow:auto. */
html:has(body.site-search-open),
body.site-search-open {
    overflow: hidden !important;
}

/* ---------- Autosuggest dropdown (shared with the inline block) ---------- */
.product-search {
    /* Input is short enough that 999px renders as a true pill; the
     * dropdown is hundreds of pixels tall, so a separate, fixed corner
     * radius keeps it from bending into a banana shape. */
    --bps-radius:          999px;
    --bps-radius-dropdown: 20px;
    --bps-border:          oklch(85% 0.005 261.4);
    --bps-fg:     oklch(0.1865 0.055 259.52);
    --bps-muted:  oklch(0.55 0.06 269.8);
    --bps-accent: oklch(0.4262 0.1283 269.8);
    --bps-bg:     #fff;
    --bps-shadow: 0 12px 32px -12px oklch(20% 0.10 261.4 / 0.18);
    position: relative;
    width: 100%;
    max-width: 720px;
    margin-inline: auto;
}

.product-search__form {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.product-search__field {
    position: relative;
    display: flex;
    align-items: stretch;
    background: var(--bps-bg);
    border: 1px solid var(--bps-border);
    border-radius: var(--bps-radius);
    /* No border-radius transition — clearing/repopulating the results
       list flips `:has(.results:not([hidden]))` rapidly, which would
       restart the morph and produce a flicker. Snapping is instant
       and reads as solid. */
    transition: border-color 0.15s ease;
}

/* Soft neutral focus state — no shadow, just a subtle border tint. */
.product-search__field:focus-within {
    border-color: color-mix(in oklch, var(--bps-fg) 25%, transparent);
}

/* When the dropdown is visible, the field merges with it. We swap the
   pill radius for the dropdown's softer corner radius on the top so
   the combined shape reads as one rounded panel; bottom corners go
   flat to seal against the dropdown above. */
.product-search:has(.product-search__results:not([hidden])) .product-search__field {
    border-radius: var(--bps-radius-dropdown) var(--bps-radius-dropdown) 0 0;
}

.product-search__input {
    flex: 1;
    min-width: 0;
    padding: 0.875rem 1.5rem;
    border: 0;
    border-radius: 0 var(--bps-radius) var(--bps-radius) 0;
    font: inherit;
    color: var(--bps-fg);
    background: transparent;
    outline: none;
}

.product-search__input::placeholder {
    color: var(--bps-muted);
}

/* Shortcut hint; JS fills it with ⌘K / Ctrl+K on devices with a keyboard. */
.product-search__kbd {
    flex: none;
    align-self: center;
    margin-right: 1.25rem;
    font-family: inherit;
    font-size: 0.75rem;
    line-height: 1;
    color: var(--bps-muted);
    pointer-events: none;
}

.product-search__kbd[hidden] {
    display: none;
}

.product-search__submit {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 1.25rem;
    border: 0;
    background: transparent;
    color: var(--bps-muted);
    cursor: pointer;
    transition: color 0.15s ease;
}

.product-search__submit:hover,
.product-search__submit:focus-visible {
    color: var(--bps-accent);
    outline: none;
}

/* Vertical divider between the icon button and the input. The
   element is a plain <span>; we draw it as a 1px tall column inset
   from top and bottom so it doesn't reach the rounded edges of the
   pill. */
.product-search__divider {
    flex: none;
    width: 1px;
    align-self: stretch;
    margin: 12px 0;
    background: oklch(75% 0.010 261.4);
    pointer-events: none;
}

.product-search__results {
    position: absolute;
    /* No gap — results sit flush against the input. The 1px overlap
       hides the input's bottom border so the seam is invisible. */
    top: calc(100% - 1px);
    left: 0;
    right: 0;
    z-index: 50;
    margin: 0;
    /* Extra right padding makes room for the slim scrollbar so it
       sits visually inset from the panel edge instead of pinned to
       the very edge. */
    padding: 0.5rem 0.6rem 0.6rem;
    list-style: none;
    background: var(--bps-bg);
    border: 1px solid var(--bps-border);
    border-top: 0;
    border-bottom-left-radius: var(--bps-radius-dropdown);
    border-bottom-right-radius: var(--bps-radius-dropdown);
    box-shadow: var(--bps-shadow);
    max-height: 60vh;
    overflow-y: auto;
    /* Firefox custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: oklch(80% 0.005 261.4) transparent;
}

/* WebKit / Chromium / Edge custom scrollbar — slim, rounded, gray, inset. */
.product-search__results::-webkit-scrollbar {
    width: 18px;
}
.product-search__results::-webkit-scrollbar-track {
    background: transparent;
    margin: 12px 0;
}
.product-search__results::-webkit-scrollbar-thumb {
    background: oklch(82% 0.005 261.4);
    border-radius: 999px;
    /* Asymmetric transparent border — wider on the right side pushes
       the visible thumb further from the panel edge. */
    border: 5px solid transparent;
    border-right-width: 9px;
    background-clip: padding-box;
    min-height: 40px;
}
.product-search__results::-webkit-scrollbar-thumb:hover {
    background: oklch(70% 0.010 261.4);
    background-clip: padding-box;
}

.product-search__result {
    margin: 0;
    padding: 0;
    list-style: none;
    position: relative;
}

/* Dashed separator between siblings — none on the last child. */
.product-search__result + .product-search__result::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0.75rem;
    right: 0.75rem;
    border-top: 1px dashed oklch(88% 0.005 261.4);
    pointer-events: none;
}

/* Hide the separator on the row that's currently active/hovered (and
   the one right after) so the highlight stays visually clean. */
.product-search__result.is-active::before,
.product-search__result.is-active + .product-search__result::before,
.product-search__result:hover::before,
.product-search__result:hover + .product-search__result::before {
    border-color: transparent;
}

.product-search__result.is-active,
.product-search__result:hover {
    background: color-mix(in oklch, var(--bps-accent) 8%, transparent);
    border-radius: 0.6rem;
}

.product-search__link {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 0.75rem;
    align-items: center;
    padding: 0.6rem 0.75rem;
    color: var(--bps-fg);
    text-decoration: none;
    border-radius: 0.6rem;
}

.product-search__link:hover {
    color: var(--bps-fg);
}

.product-search__thumb {
    display: block;
    width: 56px;
    height: 56px;
    object-fit: contain;
    background: oklch(97% 0.006 261.4);
    border-radius: 0.5rem;
}

.product-search__thumb--placeholder {
    background:
        repeating-linear-gradient(
            45deg,
            oklch(95% 0.006 261.4),
            oklch(95% 0.006 261.4) 6px,
            oklch(92% 0.006 261.4) 6px,
            oklch(92% 0.006 261.4) 12px
        );
}

.product-search__body {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.product-search__title {
    font-weight: 500;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.product-search__title mark {
    background: color-mix(in oklch, var(--bps-accent) 18%, transparent);
    color: var(--bps-accent);
    font-weight: 600;
    padding: 0 3px;
    border-radius: 3px;
}

/* The search overlay is rendered inside the site header, so when the
   page header has the `--transparent` modifier (hero pages), its
   global `a { color: #fff }` rule cascades into the dropdown and
   makes result titles invisible on the white panel. Pin the overlay
   text colours explicitly so they win regardless of the header's
   transparent state. */
.site-search-overlay .product-search__link,
.site-search-overlay .product-search__link:hover,
.site-search-overlay .product-search__title {
    color: var(--bps-fg) !important;
}

.site-search-overlay .product-search__meta,
.site-search-overlay .product-search__sku {
    color: var(--bps-muted) !important;
}

.site-search-overlay .product-search__title mark {
    color: var(--bps-accent) !important;
}

.product-search__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.75rem;
    font-size: 0.8rem;
    color: var(--bps-muted);
}

.product-search__sku {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.product-search__sku::before {
    content: '#';
    opacity: 0.6;
}

.product-search__category::before {
    content: '·';
    margin-right: 0.4rem;
    opacity: 0.5;
}
