/* ==========================================================================
   Smart search UI (additive layer on top of header-apple.modern.css)
   - clear (x) button + loading spinner inside the header inputs
   - "smart bar" (did you mean + intent chips) and rich empty state in the dropdown
   - stock badge / match tag on dropdown cards
   - mobile full-screen sheet
   - search results page summary + quick filter pills
   Colours come from theme variables only (--primary, --card-bg, ...).
   ========================================================================== */

/* ---- Clear button + spinner (desktop and mobile inputs) ------------------ */
.nx-search-clear {
    position: absolute;
    right: 3.1rem;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: color-mix(in srgb, var(--text-secondary, #6e6e73) 16%, transparent);
    color: var(--text-secondary, #6e6e73);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    z-index: 3;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.nx-search-clear[hidden] { display: none; }
.nx-search-clear:hover,
.nx-search-clear:focus-visible {
    background: color-mix(in srgb, var(--primary, #0071e3) 18%, transparent);
    color: var(--primary, #0071e3);
    outline: none;
}

.nx-search-spinner {
    position: absolute;
    right: 3.35rem;
    top: 50%;
    width: 18px;
    height: 18px;
    margin-top: -9px;
    border: 2px solid color-mix(in srgb, var(--primary, #0071e3) 22%, transparent);
    border-top-color: var(--primary, #0071e3);
    border-radius: 50%;
    opacity: 0;
    visibility: hidden;
    z-index: 3;
    pointer-events: none;
}
.is-loading > .nx-search-spinner {
    opacity: 1;
    visibility: visible;
    animation: nx-search-spin 0.7s linear infinite;
}
/* while loading the spinner takes the clear button's place */
.is-loading > .nx-search-clear { visibility: hidden; }

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

/* room for clear + submit buttons so long text never runs underneath */
.nx-search-input-wrapper.has-value .nx-search-input { padding-right: 6rem; }
.nx-mobile-search-wrapper.has-value .nx-mobile-search-input { padding-right: 6.2rem; }
.nx-mobile-search-wrapper .nx-search-clear { right: 3rem; }
.nx-mobile-search-wrapper .nx-search-spinner { right: 3.25rem; }

/* Dropdown arrow follows the search box when JS shifts the panel to stay on screen */
.nx-search-results::before {
    left: var(--nx-search-arrow-left, 50%);
}

/* ---- Smart bar (did you mean + intent chips) ----------------------------- */
.nx-search-smart {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.7rem 1.15rem;
    border-bottom: 1px solid var(--border-color, #eee);
    background: var(--card-bg, #fff);
}
.nx-search-smart.is-visible { display: flex; }

.nx-search-smart__row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem 0.5rem;
    min-width: 0;
}
.nx-search-smart__label {
    flex: 0 0 auto;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-secondary, #6e6e73);
}

.nx-search-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 100%;
    padding: 0.32rem 0.75rem;
    border: 1px solid color-mix(in srgb, var(--primary, #0071e3) 30%, var(--border-color, #e5e5ea));
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary, #0071e3) 7%, var(--card-bg, #fff));
    color: var(--primary, #0071e3);
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}
.nx-search-chip:hover,
.nx-search-chip:focus-visible {
    background: color-mix(in srgb, var(--primary, #0071e3) 14%, var(--card-bg, #fff));
    border-color: var(--primary, #0071e3);
    color: var(--primary, #0071e3);
    text-decoration: none;
    outline: none;
}
.nx-search-chip:active { transform: scale(0.97); }
.nx-search-chip--suggest { font-style: italic; }
.nx-search-chip--plain {
    border-color: var(--border-color, #e5e5ea);
    background: var(--card-bg, #fff);
    color: var(--text-primary, #1d1d1f);
}

/* ---- Cards inside the dropdown: highlight, stock badge, match tag -------- */
.nx-search-card__title mark {
    padding: 0;
    background: color-mix(in srgb, var(--primary, #0071e3) 18%, transparent);
    color: inherit;
    border-radius: 2px;
}
.nx-search-card__meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 0.1rem;
}
.nx-search-card__stock,
.nx-search-card__why {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}
.nx-search-card__stock.is-in {
    background: color-mix(in srgb, #1a9e5c 14%, transparent);
    color: #13774a;
}
.nx-search-card__stock.is-out {
    background: color-mix(in srgb, #8a8a8f 16%, transparent);
    color: #5f5f64;
}
.nx-search-card__why {
    background: color-mix(in srgb, var(--primary, #0071e3) 12%, transparent);
    color: var(--primary, #0071e3);
}

/* ---- Rich empty state ----------------------------------------------------- */
.nx-search-empty-rich {
    grid-column: 1 / -1;
    list-style: none;
    padding: 1.4rem 1rem 1.2rem;
    text-align: center;
    color: var(--text-secondary, #6e6e73);
}
.nx-search-empty-rich__title {
    margin: 0 0 0.25rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary, #1d1d1f);
}
.nx-search-empty-rich__text { margin: 0 0 0.8rem; font-size: 0.82rem; }
.nx-search-empty-rich__chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}

/* ---- Mobile: full-screen sheet while the search is open ------------------- */
.nx-search-sheet-close { display: none; }

@media (max-width: 991.98px) {
    body.nx-search-sheet-open { overflow: hidden; }

    body.nx-search-sheet-open .nx-mobile-search-wrapper .nx-mobile-search-results.search-list-mbl-show,
    body.nx-search-sheet-open .nx-mobile-search-form .nx-mobile-search-results.search-list-mbl.search-list-mbl-show {
        position: fixed !important;
        top: var(--nx-search-sheet-top, 64px) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-height: none !important;
        height: auto !important;
        border-radius: 0 !important;
        border-left: 0;
        border-right: 0;
        transform: none !important;
        display: flex !important;
    }
    body.nx-search-sheet-open .nx-mobile-search-results::before { display: none; }
    body.nx-search-sheet-open .nx-mobile-search-results .nx-mobile-search-list {
        flex: 1 1 auto;
        max-height: none;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    /* Panel, not full screen: it ends just above the bottom nav (56px + safe area) so no card
       hides behind the nav, and uses the lists' soft background so there is no white band */
    body.nx-search-sheet-open .nx-mobile-search-wrapper .nx-mobile-search-results.search-list-mbl-show,
    body.nx-search-sheet-open .nx-mobile-search-form .nx-mobile-search-results.search-list-mbl.search-list-mbl-show {
        bottom: calc(var(--bnav-height, 56px) + env(safe-area-inset-bottom, 0px)) !important;
        background: var(--filter-bg, #f7f7f8);
        border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.08));
        border-radius: 0 0 var(--radius-lg, 14px) var(--radius-lg, 14px) !important;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.12); /* ds-allow-hardcode: matches the existing panel shadow */
    }
    /* "Discover" (suggest) mode: the suggest block is the scroller, so let it take the full
       sheet height instead of its dropdown cap of min(520px, 70vh) - 56px */
    body.nx-search-sheet-open .nx-mobile-search-results .nx-search-suggest:not([hidden]) {
        flex: 1 1 auto;
        max-height: none;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding-bottom: 0.5rem;
    }
    body.nx-search-sheet-open .nx-mobile-search-results .nx-search-suggest .nx-mobile-search-list {
        flex: 0 0 auto;
        overflow: visible;
        padding-bottom: 0.85rem;
    }
    body.nx-search-sheet-open .nx-search-sheet-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 auto;
        width: 32px;
        height: 32px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: color-mix(in srgb, var(--text-secondary, #6e6e73) 14%, transparent);
        color: var(--text-primary, #1d1d1f);
        font-size: 20px;
        line-height: 1;
    }
    .nx-search-smart { padding: 0.6rem 0.85rem; }
    .nx-search-chip { font-size: 0.78rem; padding: 0.38rem 0.8rem; min-height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
    .is-loading > .nx-search-spinner { animation-duration: 1.6s; }
    .nx-search-chip { transition: none; }
}

/* ==========================================================================
   Search results page: summary + quick filter pills
   ========================================================================== */
.nx-search-summary {
    margin: 0.35rem 0 0.9rem;
}
.nx-search-summary__text {
    margin: 0 0 0.6rem;
    font-size: 0.92rem;
    color: var(--text-secondary, #6e6e73);
}
.nx-search-summary__text strong { color: var(--text-primary, #1d1d1f); }

.nx-search-pills {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.nx-search-pills::-webkit-scrollbar { display: none; }

.nx-search-pill {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    min-height: 36px;
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--border-color, #e5e5ea);
    border-radius: 999px;
    background: var(--card-bg, #fff);
    color: var(--text-primary, #1d1d1f);
    font-size: 0.82rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.nx-search-pill:hover,
.nx-search-pill:focus-visible {
    border-color: var(--primary, #0071e3);
    color: var(--primary, #0071e3);
    text-decoration: none;
    outline: none;
}
.nx-search-pill.is-active {
    border-color: var(--primary, #0071e3);
    background: color-mix(in srgb, var(--primary, #0071e3) 10%, var(--card-bg, #fff));
    color: var(--primary, #0071e3);
    font-weight: 600;
}
.nx-search-pill--clear { color: var(--text-secondary, #6e6e73); border-style: dashed; }
.nx-search-pills__sep {
    flex: 0 0 1px;
    align-self: stretch;
    margin: 0.35rem 0.1rem;
    background: var(--border-color, #e5e5ea);
}
