/*
 * CFS production search adapter.
 * Loaded by the production boundary after SwiftSearch replaces only the known
 * SearchWP header form. The existing CFS header structure remains authoritative.
 */
:is(.site-header__search, .cfs-production-search-surface), body.cfs-typesense-results-page {
    --cfs-search-accent: #ff1f2a;
    --cfs-search-accent-deep: #e2232c;
    --cfs-search-ink: #111;
    --cfs-search-muted: #565656;
    --cfs-search-line: #d8d8d8;
    --cfs-search-surface: #fff;
    --cfs-search-surface-subtle: #f6f6f6;
}

:is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper) {
    background: var(--cfs-search-surface);
}

/* The theme pointer currently aligns with the account icon at narrow widths. */
:is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper)::before {
    display: none;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-wrapper {
    --ss-primary: var(--cfs-search-accent-deep);
    --ss-primary-rgb: 226, 35, 44;
    --ss-bg: var(--cfs-search-surface);
    --ss-card-bg: var(--cfs-search-surface);
    --ss-text-main: var(--cfs-search-ink);
    --ss-text-muted: var(--cfs-search-muted);
    --ss-border: var(--cfs-search-line);
    width: 100%;
    max-width: none;
    margin: 0;
    font-family: "Outfit", sans-serif;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-search-box {
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-search-box:focus-within {
    box-shadow: none;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-search-input {
    min-height: 52px;
    padding: 12px 16px;
    border: 1px solid var(--cfs-search-ink);
    border-radius: 5px;
    background: var(--cfs-search-surface);
    color: var(--cfs-search-ink);
    font-size: 16px;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-search-input::placeholder {
    color: var(--cfs-search-muted);
    opacity: 1;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-search-input:focus-visible {
    border-color: var(--cfs-search-ink);
    outline: 3px solid var(--cfs-search-surface);
    outline-offset: 2px;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-submit-button {
    min-height: 52px;
    padding-inline: 18px;
    border: 1px solid var(--cfs-search-ink);
    border-radius: 5px;
    background: transparent;
    color: var(--cfs-search-ink);
    font-size: 16px;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-submit-button:hover,
:is(.site-header__search, .cfs-production-search-surface) .ss-submit-button:focus-visible {
    border-color: var(--cfs-search-ink);
    background: var(--cfs-search-ink);
    color: var(--cfs-search-surface);
    filter: none;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-results-container {
    border-radius: 5px;
    background: var(--cfs-search-surface);
    box-shadow: 0 6px 8px rgba(17, 17, 17, .18);
}

:is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-card-image img {
    object-fit: contain;
    padding: 6px;
    box-sizing: border-box;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-card-title {
    color: var(--cfs-search-ink);
    font-weight: 700;
}

:is(.site-header__search, .cfs-production-search-surface) .ss-view-all {
    color: var(--cfs-search-ink);
}

:is(.site-header__search, .cfs-production-search-surface) .ss-view-all:hover,
:is(.site-header__search, .cfs-production-search-surface) .ss-view-all:focus-visible {
    color: var(--cfs-search-accent-deep);
}

:is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-facets {
    background: var(--cfs-search-surface-subtle);
}

body.cfs-typesense-results-page main,
body.cfs-typesense-results-page .site-main {
    width: min(calc(100% - 48px), 1480px);
    max-width: none;
    margin-inline: auto;
}

body.cfs-typesense-results-page .ss-layout-catalog {
    --ss-primary: var(--cfs-search-accent-deep);
    --ss-primary-rgb: 226, 35, 44;
    --ss-bg: var(--cfs-search-surface);
    --ss-card-bg: var(--cfs-search-surface);
    --ss-text-main: var(--cfs-search-ink);
    --ss-text-muted: var(--cfs-search-muted);
    --ss-border: var(--cfs-search-line);
    --ss-radius: 12px;
    --ss-radius-sm: 6px;
    width: 100%;
    max-width: none;
    margin: 32px 0 72px;
    font-family: "Outfit", sans-serif;
}

body.cfs-typesense-results-page .ss-layout-catalog .ss-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
}

body.cfs-typesense-results-page .ss-layout-catalog .ss-card-image img {
    object-fit: contain;
    padding: 12px;
    box-sizing: border-box;
}

body.cfs-typesense-results-page .ss-layout-catalog .ss-card-title {
    font-weight: 700;
}

@media (max-width: 767px) {
    :is(.site-header__search, .cfs-production-search-surface) .ss-search-box {
        align-items: stretch;
        flex-wrap: wrap;
        gap: 8px;
    }

    :is(.site-header__search, .cfs-production-search-surface) .ss-search-input {
        flex-basis: calc(100% - 40px);
    }

    :is(.site-header__search, .cfs-production-search-surface) .ss-submit-button {
        width: 100%;
        background: var(--cfs-search-ink);
        color: var(--cfs-search-surface);
    }

    body.cfs-typesense-results-page main,
    body.cfs-typesense-results-page .site-main {
        width: min(calc(100% - 24px), 1480px);
    }

    body.cfs-typesense-results-page .ss-layout-catalog {
        margin-top: 20px;
    }

    body.cfs-typesense-results-page .ss-layout-catalog .ss-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
}

@media (max-width: 420px) {
    body.cfs-typesense-results-page .ss-layout-catalog .ss-grid {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    :is(.site-header__search, .cfs-production-search-surface) .ss-submit-button {
        transition: none;
    }
}

/* Search-only expanded panel. Native theme navigation remains in place. */
:is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper)[hidden] { display: none !important; }
:is(.site-header__search, .cfs-production-search-surface).cfs-search-open > .sub-menu { display: block !important; visibility: visible !important; opacity: 1 !important; }
:is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper) { color: #111; padding: 18px; margin: 0; list-style: none; box-sizing: border-box; }
.cfs-search-close { display: block; margin: 0 0 12px auto; padding: 10px 16px; min-height: 44px; border: 1px solid #565656; background: #fff; color: #111; border-radius: 5px; cursor: pointer; }
.cfs-search-close:focus-visible { outline: 3px solid #e2232c; outline-offset: 2px; }
:is(.site-header__search, .cfs-production-search-surface) .ss-results-container { position: static; max-height: none; border: 0; box-shadow: none; }
:is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-hits { max-height: min(65vh, 680px); }
:is(.site-header__search, .cfs-production-search-surface) .ss-search-input:focus-visible { outline-color: #e2232c; }
@media (max-width: 767px) {
    body.cfs-search-modal-open { overflow: hidden; }
    :is(.site-header__search, .cfs-production-search-surface).cfs-search-open > .sub-menu { position: fixed !important; inset: 0 !important; transform: none !important; width: 100vw !important; height: 100dvh; max-width: none; max-height: none; overflow: auto; z-index: 100; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
    :is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-hits { max-height: none; overflow: visible; }
    :is(.site-header__search, .cfs-production-search-surface) .ss-results-container { overflow: visible; }
}

/* ValStratis: full-width desktop search surface; mobile retains its full-screen dialog. */
:is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper) { color: #111; }
.cfs-search-close { border-color: #d8d8d8; color: #50575e; background: #fff; }
.cfs-search-close:hover { background: #f6f6f6; color: #111; }
@media (min-width: 768px) {
    :is(.site-header__search, .cfs-production-search-surface) .sub-menu:has(.ss-wrapper) { position: static; width: 100%; max-width: none; transform: none; border-radius: 0; padding: 20px max(24px, calc((100% - 1280px) / 2)) 24px; border-block: 1px solid var(--cfs-search-line); box-shadow: none; }
}

:is(.site-header__search, .cfs-production-search-surface).cfs-search-open > .sub-menu .ss-search-input:focus-visible { outline: 2px solid #111; outline-offset: 2px; border-color: #111; box-shadow: none; }
@media (max-width: 767px) { body.admin-bar :is(.site-header__search, .cfs-production-search-surface).cfs-search-open > .sub-menu { top: 46px !important; height: calc(100dvh - 46px); } }

.cfs-production-search-surface { width: 100%; }
@media (min-width: 768px) { .cfs-production-search-surface .ss-variant-compact .ss-hits { max-height: none; overflow: visible; } }

/* Two-column desktop suggestions; preserve readable single-column mobile results. */
:is(.site-header__search, .cfs-production-search-surface) .ss-search-input { background: #f6f6f6; color: #111; }
:is(.site-header__search, .cfs-production-search-surface) .ss-submit-button { background: #bd1823; border-color: #bd1823; color: #fff; }
:is(.site-header__search, .cfs-production-search-surface) .ss-submit-button:hover { background: #a3151e; border-color: #a3151e; color: #fff; }
@media (min-width: 768px) {
    :is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
    :is(.site-header__search, .cfs-production-search-surface) .ss-variant-compact .ss-card { min-width: 0; }
}

/* Desktop uses the header toggle/Escape; reserve symmetric scrollbar space. */
@media (min-width: 768px) {
    .cfs-production-search-surface .cfs-search-close { display: none; }
    html:has(.cfs-production-search-surface) { scrollbar-gutter: stable both-edges; }
}

/* Preserve header geometry while giving the open search a clear white anchor. */
@media (min-width: 768px) {
    .site-header.cfs-search-header-open { background: #fff; }
    .site-header.cfs-search-header-open .site-header__logo .logo-dark { display: block; }
    .site-header.cfs-search-header-open .site-header__logo .logo-light { display: none; }
    .site-header.cfs-search-header-open .site-header__nav a,
    .site-header.cfs-search-header-open .site-header__search > a,
    .site-header.cfs-search-header-open .site-header__search > a:visited,
    .site-header.cfs-search-header-open .site-header__account-link { color: #111; }
}

/* Theme search: a dropdown over the content, never a new page section. */
@media (min-width: 768px) {
    .cfs-production-search-surface {
        position: fixed;
        inset-inline: 0;
        top: var(--cfs-search-top, 0px);
        z-index: 90; /* Below the theme navigation (100), above page content. */
    }
    .cfs-production-search-surface.cfs-search-open > .sub-menu {
        max-height: calc(100dvh - var(--cfs-search-top, 0px) - 16px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-block: 24px;
        border-top: 1px solid #e2e2e2;
        box-shadow: 0 12px 24px rgb(0 0 0 / 12%);
    }
}
.cfs-production-search-surface .ss-search-input {
    font-weight: 400;
    line-height: 1.5;
    background: #fff;
    border-color: #858585;
}
.cfs-production-search-surface .ss-search-input::placeholder { font-weight: 400; color: #565656; }
.cfs-production-search-surface.cfs-search-open > .sub-menu .ss-search-input:focus,
.cfs-production-search-surface.cfs-search-open > .sub-menu .ss-search-input:focus-visible {
    outline: none;
    border-color: #bd1823;
    box-shadow: 0 0 0 1px #bd1823;
}
.cfs-production-search-surface .ss-submit-button { font-weight: 600; }
@media (prefers-reduced-motion: no-preference) {
    .cfs-production-search-surface.cfs-search-open > .sub-menu { animation: cfs-search-reveal 140ms ease-out; }
    @keyframes cfs-search-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
}

/* A consistent accessible clear control replaces the browser-specific search cancel icon. */
.cfs-production-search-surface .cfs-query-field { position: relative; flex: 1 1 0; min-width: 0; }
.cfs-production-search-surface .cfs-query-field .ss-search-input { width: 100%; box-sizing: border-box; padding-inline-end: 52px; }
.cfs-production-search-surface .ss-search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.cfs-production-search-surface .ss-search-input::-ms-clear { display: none; }
.cfs-query-clear { position: absolute; inset-inline-end: 4px; top: 4px; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 4px; background: transparent; color: #565656; cursor: pointer; font: 400 26px/1 sans-serif; }
.cfs-query-clear[hidden] { display: none; }
.cfs-query-clear:hover { background: #f6f6f6; color: #bd1823; }
.cfs-query-clear:focus-visible { outline: 2px solid #bd1823; outline-offset: -2px; background: #f6f6f6; color: #111; }
@media (max-width: 767px) { .cfs-production-search-surface .cfs-query-field { flex-basis: 100%; } }
