/**
 * Cheetah Product Search
 * Inline / expandable / overlay modes + dropdown results
 */

.cheetah-product-search {
    position: relative;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    /* Dropdown must not be clipped by ancestors */
    overflow: visible;
    z-index: 1;
}

.cheetah-product-search__icon {
    display: block;
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
}

.cheetah-product-search__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 4px;
    background: var(--cheetah-bg, #fff);
    color: var(--cheetah-text, #1e293b);
    cursor: pointer;
}

.cheetah-product-search__trigger:hover,
.cheetah-product-search__trigger:focus {
    border-color: var(--cheetah-primary, #2563eb);
    color: var(--cheetah-primary, #2563eb);
    outline: none;
}

.cheetah-product-search__panel {
    position: relative;
    width: 100%;
    min-width: 16rem;
    overflow: visible;
}

/* Inline: panel always visible */
.cheetah-product-search--inline .cheetah-product-search__trigger {
    display: none;
}

.cheetah-product-search--inline .cheetah-product-search__panel {
    display: block;
}

/* Auto: desktop/tablet inline, mobile overlay. JavaScript updates the mode
 * at runtime; these rules also provide a useful no-JS fallback. */
@media (min-width: 768px) {
    .cheetah-product-search--auto .cheetah-product-search__trigger {
        display: none;
    }

    .cheetah-product-search--auto .cheetah-product-search__panel {
        display: block;
    }

    .cheetah-product-search--auto .cheetah-product-search__panel[hidden] {
        display: block !important;
    }
}

@media (max-width: 767px) {
    .cheetah-product-search--auto .cheetah-product-search__panel[hidden] {
        display: none !important;
    }
}

/* Expandable: panel hidden until open */
.cheetah-product-search--expandable .cheetah-product-search__panel[hidden] {
    display: none !important;
}

.cheetah-product-search--expandable.is-open .cheetah-product-search__panel {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 100;
    min-width: 20rem;
    margin-top: 0.35rem;
    padding: 0.5rem;
    background: var(--cheetah-bg, #fff);
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

/* ==========================================================================
   Overlay mode
   ==========================================================================
   The overlay panel is a full-viewport dialog. BLOCK layout is used (not
   flex) so the form and the results stack with their natural heights —
   this avoids the flex-shrink behaviour that could collapse the results
   list to a near-zero height when the panel was constrained.

   `position: fixed` requires the panel to be outside any transformed
   ancestor. The companion rule in header.css forces `.site-header` to
   `transform: none` while `body.cheetah-search-overlay-open` is set, and
   product-search.js also clears any inline transform on the header as a
   belt-and-braces fallback.
   ========================================================================== */

.cheetah-product-search--overlay .cheetah-product-search__panel[hidden] {
    display: none !important;
}

.cheetah-product-search--overlay .cheetah-product-search__panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 100000;
    display: block;
    padding: 4.5rem 1.25rem 2rem;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/*
 * The form is transparent — the input alone is the visual pill. This
 * removes the duplicate rounded rectangle that appeared when the form had
 * its own white background + 12px radius while the input inside had a
 * 1px border + 999px radius.
 */
.cheetah-product-search--overlay .cheetah-product-search__form {
    width: min(560px, 100%);
    margin: 0 auto;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
}

.cheetah-product-search--overlay .cheetah-product-search__input {
    height: 52px;
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 999px;
    background: #ffffff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
    font-size: 1rem;
}

.cheetah-product-search--overlay .cheetah-product-search__input:focus {
    border-color: var(--cheetah-primary, #2563eb);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18), 0 16px 40px rgba(15, 23, 42, 0.2);
}

/*
 * Results: in overlay mode the panel is a full-screen dialog, so the
 * dropdown should use as much of the available viewport as possible.
 *
 * - `position: static` neutralises the `position: absolute` +
 *   `top: calc(100% + 6px)` from the base rule.
 * - `min-height: 40vh` ensures the list looks substantial even with only
 *   a few matches.
 * - `max-height: calc(100vh - 11rem)` is the panel's remaining vertical
 *   space: panel padding (4.5rem top + 2rem bottom) + form height (52px ≈
 *   3.25rem) + gap between form and list (0.75rem) ≈ 10.5rem, plus a small
 *   buffer.
 */
.cheetah-product-search--overlay .cheetah-product-search__results {
    display: block;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: min(560px, 100%);
    margin: 0.75rem auto 0;
    min-height: 40vh;
    max-height: calc(100vh - 11rem);
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}

/* ==========================================================================
   Close button
   ==========================================================================
   The close button is only meaningful inside the overlay dialog. It is
   hidden by default so it can never flash during the initial HTML render
   — before the component's JavaScript has added the runtime mode class
   (`--inline`, `--overlay`, `--expandable`) to the wrapper element.

   Reveal rules cover the two contexts where the button actually belongs:
     1. Explicit overlay mode:  `.cheetah-product-search--overlay`
     2. Auto mode that resolved to overlay on mobile widths:
        `.cheetah-product-search--auto.cheetah-product-search--overlay`
        (the `--overlay` half of this selector already matches the
        root, so the single `.cheetah-product-search--overlay` rule
        below covers both cases.)

   The inline and expandable contexts are re-asserted as `display: none`
   so the intent is documented in one place, and a belt-and-braces rule
   keeps the button hidden while its parent panel still carries the HTML
   `hidden` attribute.
   ========================================================================== */

/* Hidden by default in every context. */
.cheetah-product-search__close {
    display: none;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    background: transparent;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    color: var(--cheetah-text, #1e293b);
    z-index: 2;
}

/* Never show the button while its parent panel is still hidden. */
.cheetah-product-search__panel[hidden] .cheetah-product-search__close {
    display: none !important;
}

/* Explicitly hide in the inline / expandable contexts (documentation). */
.cheetah-product-search--inline .cheetah-product-search__close,
.cheetah-product-search--expandable .cheetah-product-search__close {
    display: none;
}

/* Reveal only in overlay contexts (explicit overlay, and auto→overlay). */
.cheetah-product-search--overlay .cheetah-product-search__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    color: #ffffff;
    opacity: 0.9;
    transition: opacity 0.15s ease;
}

.cheetah-product-search--overlay .cheetah-product-search__close:hover,
.cheetah-product-search--overlay .cheetah-product-search__close:focus {
    color: #ffffff;
    opacity: 1;
    outline: none;
}

body.cheetah-search-overlay-open {
    overflow: hidden;
}

/* Form */
.cheetah-product-search__form {
    position: relative;
    display: block;
    width: 100%;
}

/*
 * Input padding-right is 6.5rem to reserve room, from the right edge
 * leftward, for three absolutely-positioned / browser-drawn elements
 * that must never overlap:
 *
 *   right: 0.3rem  →  submit button
 *   ~3-4rem        →  native clear "X" (shifted right via margin)
 *   right: 4.4rem  →  loading spinner
 *
 * Text content therefore starts 6.5rem from the right border, keeping it
 * clear of the spinner, the X and the submit button.
 */
.cheetah-product-search__input {
    display: block;
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 6.5rem 0 1.15rem;
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 999px;
    background: #ffffff;
    font-size: 0.9375rem;
    line-height: 1.4;
    color: var(--cheetah-text-color, #1e293b);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cheetah-product-search__input:focus {
    outline: none;
    border-color: var(--cheetah-primary, #2563eb);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/*
 * Shift the native search clear "X" rightward.
 *
 * The browser renders the clear button at the input's content edge, i.e.
 * `padding-right` (6.5rem) from the input's right edge. A negative
 * margin-right pulls it rightward into the padding area so it sits between
 * the spinner and the submit button.
 *
 * Result (from the input's right edge): submit (0.3rem) → X (~3rem) →
 * spinner (4.4rem) → content (6.5rem).
 */
.cheetah-product-search__input::-webkit-search-cancel-button {
    margin-right: -3.5rem;
    cursor: pointer;
}

/*
 * Spinner sits between the shifted X and the text content.
 * Horizontally: right: 4.4rem places it clear of the X (which ends around
 * 4rem from the right) and clear of the content edge (6.5rem from the
 * right).
 * Vertically: top: 50% + translateY(-50%) centres it on the input's
 * midline, matching the browser-centred native X.
 */
.cheetah-product-search__spinner {
    position: absolute;
    right: 4.4rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    pointer-events: none;
    z-index: 2;
}

.cheetah-product-search__spinner[hidden] {
    display: none !important;
}

.cheetah-product-search__spinner-icon {
    display: block;
    width: 1.125rem;
    height: 1.125rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cheetah-product-search-spin 0.7s linear infinite;
}

/* On light form backgrounds (non-header contexts) use primary colour */
.cheetah-product-search__form .cheetah-product-search__spinner-icon {
    border-color: var(--cheetah-border, #e2e8f0);
    border-top-color: var(--cheetah-primary, #2563eb);
}

@keyframes cheetah-product-search-spin {
    to {
        transform: rotate(360deg);
    }
}

.cheetah-product-search__submit {
    position: absolute;
    right: 0.3rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--cheetah-primary, #2563eb);
    color: #ffffff;
    cursor: pointer;
    z-index: 2;
    transition: background-color 0.15s ease;
}

.cheetah-product-search__submit:hover,
.cheetah-product-search__submit:focus {
    background: #1d4ed8;
    outline: none;
    filter: none;
}

.cheetah-product-search__submit:disabled,
.cheetah-product-search__submit.is-loading {
    opacity: 0.7;
    cursor: default;
}

/* Results dropdown
 * Default is absolute under the panel. product-search.js upgrades this to
 * position:fixed with measured coordinates so the fixed header transform
 * cannot clip the list.
 */
.cheetah-product-search__results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 100050;
    max-height: 22rem;
    overflow: auto;
    background: #ffffff;
    border: 1px solid var(--cheetah-border, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}

.cheetah-product-search__results[hidden] {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Status messages
   --------------------------------------------------------------------------
   The status block is the shared container for loading indicators, empty
   results, and errors. Errors can optionally carry a single action
   button (for example the "Refresh page" action shown after a nonce
   expiry has been detected and automatic recovery has failed); when
   present, the container switches to a column layout so the message and
   the button stack cleanly.
   -------------------------------------------------------------------------- */
.cheetah-product-search__status {
    padding: 0.85rem 1rem;
    color: var(--cheetah-secondary, #64748b);
    font-size: 0.9rem;
}

.cheetah-product-search__status--error {
    color: #b91c1c;
}

/*
 * Error messages that carry an action button use a column layout so the
 * message text and the button do not fight for horizontal space. The
 * `:has()` selector scopes the layout change to the specific case where
 * a button is present — a plain error (network failure, server error)
 * keeps the default block layout.
 */
.cheetah-product-search__status--error:has(.cheetah-product-search__refresh) {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
}

.cheetah-product-search__status-message {
    margin: 0;
    line-height: 1.5;
    color: inherit;
}

/*
 * Refresh action button.
 *
 * Styled to match the theme's primary button grammar (solid primary
 * surface, white label, soft elevation) so it reads as the obvious next
 * step rather than as another error surface. Hovering lifts the button
 * slightly; the focus ring reuses the theme's primary accent so it
 * remains visible against the error background.
 */
.cheetah-product-search__refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.95rem;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.4;
    color: #ffffff;
    background: var(--cheetah-primary, #2563eb);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
    transition: background-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.cheetah-product-search__refresh:hover {
    background: var(--cheetah-primary-hover, #1d4ed8);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.cheetah-product-search__refresh:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.cheetah-product-search__refresh:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.28), 0 1px 2px rgba(37, 99, 235, 0.2);
}

.cheetah-product-search__status--error .cheetah-product-search__refresh {
    /* Reset any inherited red error colour; the button has its own palette. */
    color: #ffffff;
}

.cheetah-product-search__list {
    list-style: none;
    margin: 0;
    padding: 0.35rem 0;
}

.cheetah-product-search__item {
    margin: 0;
}

.cheetah-product-search__item.is-active .cheetah-product-search__link,
.cheetah-product-search__link:hover,
.cheetah-product-search__link:focus {
    background: rgba(37, 99, 235, 0.08);
    outline: none;
}

.cheetah-product-search__link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.85rem;
    text-decoration: none;
    color: inherit;
}

.cheetah-product-search__thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    background: #f1f5f9;
}

.cheetah-product-search__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cheetah-product-search__meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.cheetah-product-search__title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--cheetah-heading, #0f172a);
    line-height: 1.3;
}

.cheetah-product-search__title mark {
    background: rgba(37, 99, 235, 0.2);
    color: inherit;
    padding: 0 0.1em;
}

.cheetah-product-search__price {
    font-size: 0.85rem;
    color: var(--cheetah-secondary, #64748b);
}

.cheetah-product-search__view-all {
    display: block;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--cheetah-border, #e2e8f0);
    text-align: center;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--cheetah-primary, #2563eb);
    text-decoration: none;
}

.cheetah-product-search__view-all:hover,
.cheetah-product-search__view-all:focus {
    text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
    .cheetah-product-search * {
        transition: none !important;
    }

    .cheetah-product-search__spinner-icon {
        animation: none;
    }
}

/* ==========================================================================
   Ported results (appended to document.body by product-search.js)
   Must win against header stacking, admin-bar, overlays, etc.
   Explicit height:auto is required – the inset shorthand (or a missing
   height) can collapse the fixed box to a 1-px line in some engines.
   ========================================================================== */

.cheetah-product-search__results--ported,
body > .cheetah-product-search__results {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: fixed !important;
    z-index: 2147483000 !important;
    margin: 0 !important;
    padding: 0.4rem 0 !important;
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.22) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    pointer-events: auto !important;
    color: #0f172a !important;
    -webkit-font-smoothing: antialiased;
    /* Critical: never allow the box to collapse */
    height: auto !important;
    min-height: 0 !important;
    max-height: none; /* JS sets the concrete max-height with !important */
    /* Force a fresh compositing layer so the header's backdrop-filter
       cannot composite over the dropdown. */
    transform: translateZ(0);
    will-change: transform;
}

body > .cheetah-product-search__results[hidden],
.cheetah-product-search__results--ported[hidden] {
    display: none !important;
}

body > .cheetah-product-search__results .cheetah-product-search__list,
.cheetah-product-search__results--ported .cheetah-product-search__list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    height: auto !important;
}

body > .cheetah-product-search__results .cheetah-product-search__item,
.cheetah-product-search__results--ported .cheetah-product-search__item {
    margin: 0 !important;
    display: block !important;
    height: auto !important;
}

body > .cheetah-product-search__results .cheetah-product-search__link,
.cheetah-product-search__results--ported .cheetah-product-search__link {
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    padding: 0.65rem 1rem !important;
    color: #0f172a !important;
    text-decoration: none !important;
    height: auto !important;
    min-height: 48px !important;
}

body > .cheetah-product-search__results .cheetah-product-search__link:hover,
.cheetah-product-search__results--ported .cheetah-product-search__link:hover,
body > .cheetah-product-search__results .cheetah-product-search__item.is-active .cheetah-product-search__link,
.cheetah-product-search__results--ported .cheetah-product-search__item.is-active .cheetah-product-search__link {
    background: #f8fafc !important;
}

body > .cheetah-product-search__results .cheetah-product-search__title,
.cheetah-product-search__results--ported .cheetah-product-search__title {
    display: block !important;
    font-size: 0.9375rem !important;
    font-weight: 600 !important;
    color: #0f172a !important;
    line-height: 1.35 !important;
}

body > .cheetah-product-search__results .cheetah-product-search__title mark,
.cheetah-product-search__results--ported .cheetah-product-search__title mark {
    background: #fef08a !important;
    color: inherit !important;
    padding: 0 0.1em !important;
}

body > .cheetah-product-search__results .cheetah-product-search__price,
.cheetah-product-search__results--ported .cheetah-product-search__price {
    display: block !important;
    font-size: 0.8125rem !important;
    color: #475569 !important;
}

body > .cheetah-product-search__results .cheetah-product-search__thumb img,
.cheetah-product-search__results--ported .cheetah-product-search__thumb img {
    display: block !important;
    width: 48px !important;
    height: 48px !important;
    object-fit: cover !important;
    border-radius: 8px !important;
    background: #f1f5f9 !important;
}

body > .cheetah-product-search__results .cheetah-product-search__status,
.cheetah-product-search__results--ported .cheetah-product-search__status {
    padding: 1rem !important;
    text-align: center !important;
    font-size: 0.875rem !important;
    color: #64748b !important;
}

/*
 * The ported-results block above resets padding/text-align on the status
 * container. That reset would collapse the column layout used by error
 * states that carry an action button, so those properties are reasserted
 * here with a higher-specificity selector.
 */
body > .cheetah-product-search__results .cheetah-product-search__status--error:has(.cheetah-product-search__refresh),
.cheetah-product-search__results--ported .cheetah-product-search__status--error:has(.cheetah-product-search__refresh) {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.75rem !important;
    padding: 1rem 1.15rem !important;
    text-align: left !important;
    color: #b91c1c !important;
}

body > .cheetah-product-search__results .cheetah-product-search__status--error:has(.cheetah-product-search__refresh) .cheetah-product-search__refresh,
.cheetah-product-search__results--ported .cheetah-product-search__status--error:has(.cheetah-product-search__refresh) .cheetah-product-search__refresh {
    align-self: flex-start;
}

body > .cheetah-product-search__results .cheetah-product-search__view-all,
.cheetah-product-search__results--ported .cheetah-product-search__view-all {
    display: block !important;
    padding: 0.85rem 1rem !important;
    text-align: center !important;
    font-size: 0.875rem !important;
    font-weight: 600 !important;
    color: #2563eb !important;
    text-decoration: none !important;
    border-top: 1px solid #e2e8f0 !important;
}