/* ==========================================================================
   Hero Search Widget — [wtpi_hero_search] shortcode
   Standalone search box for the home page hero banner, with a live
   search-as-you-type dropdown via jQuery UI Autocomplete (bundled with
   WordPress core — no external CDN dependency). Fully custom-styled;
   jQuery UI's default theme CSS is never loaded.
   ========================================================================== */

.wtpi-hero-search-widget {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    padding: 8px 8px 8px 20px;
    max-width: 700px;
    font-family: 'Montserrat', sans-serif;
}

.wtpi-hero-search-widget__field {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 auto;
    min-width: 0;
}

.wtpi-hero-search-widget__icon-wrap {
    position: relative;
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
}

.wtpi-hero-search-widget__icon,
.wtpi-hero-search-widget__loader {
    position: absolute;
    inset: 0;
    margin: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
}

.wtpi-hero-search-widget__icon {
    width: 20px;
    height: 20px;
    color: #000000;
    display: inline-flex;
    opacity: 1;
    visibility: visible;
}

.wtpi-hero-search-widget__icon svg {
    width: 100%;
    height: 100%;
}

.wtpi-hero-search-widget__loader {
    width: 18px;
    height: 18px;
    border: 2px solid #E5E5E2;
    border-top-color: #F78F22;
    border-radius: 50%;
    /* Animation runs continuously at all times (never display:none, only
       opacity toggles), so it never restarts/resets rotation — a restart
       on every debounced keystroke is what caused the visible "jump". */
    animation: wtpi-hero-search-spin 0.7s linear infinite;
}

/* While a request is in flight: crossfade from the search icon to the
   spinner instead of toggling display. */
.wtpi-hero-search-widget--loading .wtpi-hero-search-widget__icon {
    opacity: 0;
    visibility: hidden;
}

.wtpi-hero-search-widget--loading .wtpi-hero-search-widget__loader {
    opacity: 1;
    visibility: visible;
}

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

.wtpi-hero-search-widget__input {
    flex: 1 1 auto;
    min-width: 0;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: none !important;
    font-family: 'Montserrat', sans-serif !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    color: #000000 !important;
    padding: 8px 0 !important;
}

.wtpi-hero-search-widget__input::placeholder {
    color: #6E6E67;
    font-weight: 400;
}

.wtpi-hero-search-widget__btn {
    flex: 0 0 auto;
    background-color: #F78F22 !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 6px !important;
    padding: 12px 24px;
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s ease;
}

.wtpi-hero-search-widget__btn:hover,
.wtpi-hero-search-widget__btn:focus {
    background-color: #EB8E24 !important;
    outline: none;
}

/* ---- jQuery UI Autocomplete dropdown panel ----
   .ui-autocomplete is the menu jQuery UI creates and appends to <body>
   (not nested inside .wtpi-hero-search-widget), so these rules are NOT
   scoped under that parent class.

   IMPORTANT: .ui-autocomplete / .ui-menu-item / .ui-state-active are
   generic jQuery UI class names — if any OTHER plugin or theme CSS on
   this site loads a jQuery UI theme (very common, e.g. for datepickers),
   it targets these exact same classes. Every property below is
   !important specifically to guarantee this custom styling wins
   regardless of what else might be loaded, rather than relying on
   load-order alone. */

.ui-autocomplete {
    background: #ffffff !important;
    background-image: none !important;
    border: 1px solid #CACAC7 !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15) !important;
    font-family: 'Montserrat', sans-serif !important;
    list-style: none !important;
    list-style-image: none !important;
    margin: 4px 0 0 !important;
    padding: 0 !important;
    max-height: 400px !important;
    overflow-y: auto !important;
    z-index: 2147483647 !important;
}

.ui-autocomplete .ui-menu-item,
.ui-autocomplete .wtpi-hero-search-item {
    list-style: none !important;
    list-style-image: none !important;
    background: none !important;
    background-image: none !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: inherit !important;
}

.ui-autocomplete .ui-menu-item-wrapper {
    background: none !important;
    background-image: none !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
    color: inherit !important;
}

/* ---- "PRODUCTS (N)" section header ---- */

.ui-autocomplete .wtpi-hero-search-header {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px !important;
    padding: 12px 14px 8px !important;
    background: none !important;
    list-style: none !important;
    margin: 0 !important;
    border-bottom: 1px solid #EFEFED !important;
}

.wtpi-hero-search-header__title {
    font-size: 12px !important;
    font-weight: 700 !important;
    letter-spacing: 0.03em !important;
    text-transform: uppercase !important;
    color: #000000 !important;
}

.wtpi-hero-search-header__link {
    font-size: 12px !important;
    font-weight: 700 !important;
    color: #F78F22 !important;
    text-decoration: none !important;
    white-space: nowrap !important;
}

.wtpi-hero-search-header__link:hover {
    text-decoration: underline !important;
}

/* Safety net: the header title/link must never show the product-row
   active/hover state, even if jQuery UI re-adds ui-state-active to them. */
.ui-autocomplete .wtpi-hero-search-header .ui-state-active,
.ui-autocomplete .wtpi-hero-search-header.ui-state-active {
    background: none !important;
    background-color: transparent !important;
    color: inherit !important;
}

/* ---- Each result row: thumbnail + title + tagline ----
   flex-direction/flex-wrap/flex-shrink are set explicitly (not just
   `display: flex`) because a generic theme rule targeting `img` inside
   list items (a common WP content-image reset) was overriding the
   thumbnail's sizing and forcing it onto its own line below the text. */

.ui-autocomplete .ui-menu-item-wrapper.wtpi-hero-search-result {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    box-sizing: border-box !important;
    gap: 12px !important;
    padding: 10px 14px !important;
    cursor: pointer !important;
}

.ui-autocomplete .wtpi-hero-search-result__thumb {
    display: block !important;
    flex: 0 0 40px !important;
    width: 40px !important;
    height: 40px !important;
    max-width: 40px !important;
    object-fit: contain !important;
    background: #F2F2F2 !important;
    border-radius: 4px !important;
}

.ui-autocomplete .wtpi-hero-search-result__thumb--empty {
    display: block !important;
}

.ui-autocomplete .wtpi-hero-search-result__text {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    min-width: 0 !important;
}

.wtpi-hero-search-result__title {
    font-size: 14px !important;
    font-weight: 700 !important;
    color: #000000 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3 !important;
}

.wtpi-hero-search-result__tagline {
    font-size: 12px !important;
    font-weight: 400 !important;
    color: #6E6E67 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3 !important;
}

/* Keyboard/mouse-highlighted item — jQuery UI adds "ui-state-active" to
   the SAME element as .wtpi-hero-search-result / .ui-menu-item-wrapper
   (the row div), and since that compound selector is more specific than
   .wtpi-hero-search-result, its !important properties win the cascade.
   So this rule re-declares the FULL box model (not just background),
   otherwise the row's padding/flex/sizing silently reset on hover and
   the row balloons in height from the ancestor's inherited font-size. */
.ui-autocomplete .ui-state-active,
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    box-sizing: border-box !important;
    gap: 12px !important;
    padding: 10px 14px !important;
    margin: 0 !important;
    border: none !important;
    background-color: #F78F22 !important;
    background-image: none !important;
    font-size: 14px !important;
    line-height: 1.3 !important;
}

.ui-autocomplete .ui-state-active .wtpi-hero-search-result__title,
.ui-autocomplete .ui-state-active .wtpi-hero-search-result__tagline,
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active .wtpi-hero-search-result__title,
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active .wtpi-hero-search-result__tagline {
    color: #ffffff !important;
}

@media (max-width: 782px) {
    .wtpi-hero-search-widget {
        flex-wrap: wrap;
        padding: 12px;
        position: relative;
    }
    .wtpi-hero-search-widget__field {
        position: relative;
        order: 1;
        flex: 1 1 100%;
        width: 100%;
    }
    .wtpi-hero-search-widget__icon-wrap {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1;
        pointer-events: none;
    }
    .wtpi-hero-search-widget__input {
        flex: 1 1 100%;
        width: 100%;
        padding-left: 40px !important;
    }
    .wtpi-hero-search-widget__btn {
        order: 2;
        flex: 1 1 100%;
        width: 100%;
        margin-top: 4px;
    }
}

/* ---- Site-wide grouped dropdown (v3) ---- */

/* Group headers after the first get a separator. */
.ui-autocomplete .wtpi-hero-search-item + .wtpi-hero-search-header {
    border-top: 1px solid #EFEFED !important;
    margin-top: 4px !important;
}

/* "Showing results for ..." typo note + "No results" row. */
.ui-autocomplete .wtpi-hero-search-header--note,
.ui-autocomplete .wtpi-hero-search-header--empty {
    display: block !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    color: #4A4A47 !important;
    padding: 10px 14px !important;
}

/* Footer "View all N results" row. */
.ui-autocomplete .wtpi-hero-search-header--footer {
    justify-content: center !important;
    border-top: 1px solid #EFEFED !important;
    border-bottom: none !important;
    padding: 12px 14px !important;
}

/* Type icon instead of a photo (pages, collections, files). */
.ui-autocomplete .wtpi-hero-search-result__thumb--icon {
    display: block !important;
    background-color: #FFF4E8 !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 20px 20px !important;
}

.ui-autocomplete .wtpi-hero-search-result__thumb--page {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F78F22' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpolyline points='14 2 14 8 20 8'/%3E%3C/svg%3E") !important;
}

.ui-autocomplete .wtpi-hero-search-result__thumb--collection {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F78F22' stroke-width='2'%3E%3Crect x='3' y='3' width='7' height='7' rx='1'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1'/%3E%3Crect x='14' y='14' width='7' height='7' rx='1'/%3E%3C/svg%3E") !important;
}

.ui-autocomplete .wtpi-hero-search-result__thumb--file {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23F78F22' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E") !important;
}

/* Taglines/excerpts: one line, ellipsis. */
.ui-autocomplete .wtpi-hero-search-result__tagline {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}
