/* LW Typesense font-size anchor (see instant-search.css for rationale). */
.lw-autocomplete {
    font-size: 16px;
}
/**
 * Living Waters — Custom Autocomplete Styles
 * Uses WordPress theme.json CSS custom properties with fallback values.
 */

/* --- Container -------------------------------------------- */
.lw-autocomplete {
    position: relative;
    width: 100%;
    max-width: 600px;
}

/* --- Input ------------------------------------------------ */
.lw-ac__form {
    margin: 0;
}
.lw-ac__input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.lw-ac__input-icon {
    position: absolute;
    right: 22px;
    color: var(--wp--preset--color--secondary, #545473);
    pointer-events: none;
    flex-shrink: 0;
}
.lw-ac__input,
input[type="search"].lw-ac__input {
    width: 100%;
    padding: 14px 52px 14px 24px;
    border: 1px solid var(--wp--preset--color--border-light, #E3E3F0);
    border-radius: 999px;
    font-size: 1em;
    color: var(--wp--preset--color--main, #1E1E26);
    background: var(--wp--preset--color--base, #fff);
    outline: none;
    box-shadow: 0 4px 14px rgba(17, 24, 39, 0.06), 0 1px 3px rgba(17, 24, 39, 0.04);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    box-sizing: border-box;
}
.lw-ac__input:focus {
    border-color: var(--primary, #163158);
    box-shadow: 0 4px 18px rgba(17, 24, 39, 0.08), 0 0 0 3px rgba(83, 68, 244, 0.12);
}
.lw-ac__input::placeholder {
    color: var(--wp--preset--color--secondary, #545473);
}
.lw-ac__clear {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    font-size: 1.25em;
    color: var(--wp--preset--color--secondary, #545473);
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.lw-ac__clear:hover {
    color: var(--wp--preset--color--main, #1E1E26);
}

/* --- Dropdown --------------------------------------------- */
.lw-ac__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--wp--preset--color--base, #fff);
    border: 1px solid var(--wp--preset--color--border-light, #E3E3F0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 99999;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.lw-ac__dropdown--open {
    display: block;
}

/* --- Sections --------------------------------------------- */
.lw-ac__section {
    padding: 0.5em 0;
}
.lw-ac__section + .lw-ac__section {
    border-top: 1px solid var(--wp--preset--color--border-light, #E3E3F0);
}
.lw-ac__section-header {
    padding: 0.4em 1em 0.3em;
    font-size: 0.7em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--wp--preset--color--secondary, #545473);
}

/* --- Suggestions ------------------------------------------ */
.lw-ac__suggestion-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.lw-ac__suggestion-item {
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding: 0.5em 1em;
    cursor: pointer;
    font-size: 0.875em;
    color: var(--wp--preset--color--main, #1E1E26);
    transition: background 0.15s ease;
}
.lw-ac__suggestion-item:hover,
.lw-ac__suggestion-item.lw-ac__item--active {
    background: var(--wp--preset--color--tertiary, #f8f7fc);
}
.lw-ac__search-icon {
    flex-shrink: 0;
    color: var(--wp--preset--color--secondary, #545473);
}
.lw-ac__suggestion-text mark {
    background: none;
    font-weight: 700;
    color: inherit;
}

/* --- Products --------------------------------------------- */
.lw-ac__product-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.lw-ac__product-item {
    border-bottom: 1px solid var(--wp--preset--color--border-light, #E3E3F0);
}
.lw-ac__product-item:last-child {
    border-bottom: none;
}
.lw-ac__product-link {
    display: flex;
    align-items: center;
    gap: 0.75em;
    padding: 0.6em 1em;
    text-decoration: none;
    color: var(--wp--preset--color--main, #1E1E26);
    transition: background 0.15s ease;
}
.lw-ac__product-link:hover,
.lw-ac__product-link.lw-ac__item--active {
    background: var(--wp--preset--color--tertiary, #f8f7fc);
}
.lw-ac__product-img {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: var(--wp--preset--color--tertiary, #f8f7fc);
}
.lw-ac__product-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.lw-ac__product-info {
    flex: 1;
    min-width: 0;
}
.lw-ac__product-title {
    font-size: 0.85em;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lw-ac__product-title mark {
    background: none;
    font-weight: 700;
    color: inherit;
}
.lw-ac__product-price {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--wp--preset--color--main, #1E1E26);
    margin-top: 0.15em;
}
.lw-ac__product-price del {
    color: var(--wp--preset--color--secondary, #545473);
    font-weight: 400;
}
.lw-ac__product-price ins {
    text-decoration: none;
}
.lw-ac__product-stock--out {
    font-size: 0.75em;
    color: #b00020;
}

/* --- View all --------------------------------------------- */
.lw-ac__view-all {
    padding: 0.6em 1em;
    border-top: 1px solid var(--wp--preset--color--border-light, #E3E3F0);
    text-align: center;
}
.lw-ac__view-all a {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--primary, #163158);
    text-decoration: none;
}
.lw-ac__view-all a:hover {
    text-decoration: underline;
}

/* --- Empty state ------------------------------------------ */
.lw-ac__empty {
    padding: 1.5em 1em;
    text-align: center;
    font-size: 0.85em;
    color: var(--wp--preset--color--secondary, #545473);
}


/* --- Close button (mobile overlay only) ------------------- */
.lw-ac__close {
    display: none;
    background: none;
    border: none;
    padding: 6px;
    margin-left: 4px;
    color: var(--wp--preset--color--main, #1E1E26);
    cursor: pointer;
    flex-shrink: 0;
    line-height: 0;
}
.lw-ac__close:hover {
    color: var(--primary, #163158);
}

/* --- Mobile full-screen overlay --------------------------- */
@media (max-width: 640px) {
    .lw-autocomplete.lw-autocomplete--open {
        position: fixed;
        inset: 0;
        z-index: 999999;
        max-width: none;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        background: var(--wp--preset--color--base, #fff);
        padding: 0.75em;
        display: flex;
        flex-direction: column;
    }

    /* Show the close button, hide the search icon on the left
       (since the input is the entire top row) and the clear ×. */
    .lw-autocomplete.lw-autocomplete--open .lw-ac__close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    .lw-autocomplete.lw-autocomplete--open .lw-ac__clear {
        display: none !important;
    }
    .lw-autocomplete.lw-autocomplete--open .lw-ac__input-icon {
        display: none;
    }

    /* Input fills the row beside the close button. */
    .lw-autocomplete.lw-autocomplete--open .lw-ac__input-wrap {
        gap: 0.25em;
    }
    .lw-autocomplete.lw-autocomplete--open .lw-ac__input {
        padding-right: 14px;
        font-size: 1em;
    }

    /* Dropdown becomes an inline flex panel filling the remaining height. */
    .lw-autocomplete.lw-autocomplete--open .lw-ac__dropdown {
        position: static;
        display: block;
        border: none;
        box-shadow: none;
        border-radius: 0;
        max-height: none;
        flex: 1;
        min-height: 0;
        margin-top: 0.5em;
        overflow-y: auto;
    }
    /* Dropdown renders its content even when the --open class is absent
       (it's managed by .lw-ac__dropdown--open for desktop). */
    .lw-autocomplete.lw-autocomplete--open .lw-ac__dropdown:empty {
        display: none;
    }
}

/* Lock body scroll while overlay is open. */
html.lw-ac-overlay-open,
html.lw-ac-overlay-open body {
    overflow: hidden;
}

/* --- Mobile: header search is tap-only; hide dropdown when overlay is closed --- */
@media (max-width: 640px) {
    .lw-autocomplete:not(.lw-autocomplete--open) .lw-ac__dropdown {
        display: none !important;
    }
}
