/**
 * Maxi Ajax Search — Frontend Styles
 * Compatível com Flatsome. Expansível desktop + mobile abaixo do header.
 * @package MaxiAjaxSearch
 */

/* ── Reset & Base ──────────────────────────────────────────────────────── */
.maxi-search-wrap *,
.maxi-search-wrap *::before,
.maxi-search-wrap *::after {
    box-sizing: border-box;
}

/* ── Contêiner principal ─────────────────────────────────────────────── */
.maxi-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

/* ── Botão disparador (lupa / close) ───────────────────────────────────── */
.maxi-search-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    padding: 6px;
    margin: 0;
    cursor: pointer;
    color: inherit;
    border-radius: 4px;
    transition: opacity 0.2s;
    z-index: 2;
    flex-shrink: 0;
}

.maxi-search-trigger:hover {
    opacity: 0.75;
}

.maxi-search-trigger:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Ícones dentro do trigger — alterna entre lupa e X */
.maxi-trigger-icon-search,
.maxi-trigger-icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s, transform 0.15s;
}

/* Estado fechado: mostra lupa, esconde X */
.maxi-trigger-icon-close {
    display: none;
}

/* Estado aberto: esconde lupa, mostra X */
.maxi-search-wrap.is-open .maxi-trigger-icon-search {
    display: none;
}

.maxi-search-wrap.is-open .maxi-trigger-icon-close {
    display: flex;
}

/* ── Wrapper do input (âncora para o submit absoluto) ──────────────────── */
.maxi-search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

input.maxi-search-input {
    border-radius: 5px !important;
}

.maxi-search-input:focus {
    border-color: #0073aa !important;
    box-shadow: 0 0 0 2px rgb(0 115 170 / 10%) !important;
}

/* ─────────────────────────────────────────────────────────────────────── */
/*  DESKTOP (≥850px)                                                       */
/* ─────────────────────────────────────────────────────────────────────── */

@media (min-width: 850px) {

    /* No desktop o trigger some ao abrir (campo sobrepõe) */
    .maxi-search-wrap.is-open .maxi-search-trigger {
        opacity: 0;
        pointer-events: none;
    }

    /* Campo: position absolute, expande da esquerda para a direita */
    .maxi-search-field-wrap {
        display: flex;
        align-items: center;
        position: absolute;
        top: 50%;
        left: 0;
        transform: translateY(-50%);
        width: 0;
        opacity: 0;
        pointer-events: none;
        z-index: 100;
        background: #ffffff;
        transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.25s ease;
    }

    .maxi-search-wrap.is-open .maxi-search-field-wrap {
        width: 357px;
        opacity: 1;
        pointer-events: auto;
        padding: 10px 0;
    }

    .maxi-search-input {
        flex: 1;
        width: 100%;
        height: 34px !important;
        padding: 4px 36px 4px 14px !important;
        border: 1px solid #ddd;
        font-size: 14px;
        background: #fff;
        outline: none;
        color: #333;
        box-sizing: border-box;
        transition: border-color 0.2s, box-shadow 0.2s;
        -webkit-appearance: none;
        appearance: none;
    }

    .maxi-search-submit {
        position: absolute;
        top: 50%;
        right: 6px;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        padding: 0;
        margin: 0;
        width: 26px;
        height: 26px;
        cursor: pointer;
        color: #aaa;
        transition: color 0.15s;
        z-index: 1;
    }

    .maxi-search-submit:hover { color: #333; }

    .maxi-search-submit .maxi-search-icon {
        width: 15px;
        height: 15px;
    }

    .maxi-search-submit:hover .maxi-search-icon { opacity: 0.8; }

    /* Close dentro do field-wrap — visível no desktop */
    .maxi-search-close {
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        padding: 0 0 0 8px;
        width: 26px;
        height: 26px;
        cursor: pointer;
        color: #aaa;
        flex-shrink: 0;
        transition: color 0.15s;
    }

    .maxi-search-close:hover { color: #333; }

    .maxi-search-close .maxi-close-icon {
        width: 13px;
        height: 13px;
    }

    /* Dropdown de resultados */
    .maxi-search-results {
        display: none;
        position: absolute;
        top: calc(100% + 8px);
        left: 0;
        width: 317px;
        max-height: 420px;
        overflow-y: auto;
        background: #fff;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        z-index: 9999;
        animation: maxiDropIn 0.2s ease;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }

    .maxi-search-wrap.results-visible .maxi-search-results {
        display: block;
    }
}

/* ─────────────────────────────────────────────────────────────────────── */
/*  MOBILE (<850px) — campo e resultados abaixo do header                 */
/* ─────────────────────────────────────────────────────────────────────── */

@media (max-width: 849px) {

    /* Trigger: sempre visível no mobile, não some ao abrir */
    .maxi-search-wrap.is-open .maxi-search-trigger {
        opacity: 1;
        pointer-events: auto;
    }

    /* Close dentro do field-wrap: oculto no mobile (função assumida pelo trigger) */
    .maxi-search-close {
        display: none;
    }

    /* Campo: fixed abaixo do header */
    .maxi-search-field-wrap {
        display: flex;
        align-items: center;
        position: fixed;
        top: var(--maxi-header-height, 107px);
        left: 0;
        right: 0;
        width: 100%;
        transform: translateY(-6px);
        opacity: 0;
        pointer-events: none;
        z-index: 9998;
        background: #ffffff;
        border-bottom: 1px solid #e8e8e8;
        box-shadow: 0 9px 12px rgb(0 0 0 / 5%);
        padding: 10px 16px;
        gap: 8px;
        transition: opacity 0.25s ease,
                    transform 0.25s ease;
    }

    .maxi-search-wrap.is-open .maxi-search-field-wrap {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }

    .maxi-search-input {
        flex: 1;
        min-width: 0;
        height: 2.7em !important;
        padding: 4px 36px 4px 14px;
        border: 1px solid #ddd;
        border-radius: 20px;
        font-size: 16px !important;
        background: #f7f7f7;
        outline: none;
        color: #333;
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
        transition: border-color 0.2s, background 0.2s;
    }

    .maxi-search-submit {
        position: absolute;
        top: 50%;
        right: 6px;
        transform: translateY(-50%);
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        padding: 0;
        width: 26px;
        height: 26px;
        cursor: pointer;
        color: #aaa;
        transition: color 0.15s;
        z-index: 1;
    }

    .maxi-search-submit:hover { color: #333; }

    .maxi-search-submit .maxi-search-icon {
        width: 15px;
        height: 15px;
        opacity: 0.45;
    }

    .maxi-search-submit:hover .maxi-search-icon { opacity: 0.8; }

    /* Resultados mobile — fixed, abaixo do campo */
    .maxi-search-results {
        display: none;
        position: fixed;
        top: calc(var(--maxi-header-height, 109px) + 58px);
        left: 0;
        right: 0;
        width: 100%;
        max-height: calc(100vh - var(--maxi-header-height, 109px) - 58px - 16px);
        overflow-y: auto;
        background: #fff;
        border-top: 1px solid #e8e8e8;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
        z-index: 9997;
        animation: maxiDropIn 0.2s ease;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }

    .maxi-search-wrap.results-visible .maxi-search-results {
        display: block;
    }
}

/* ── Animações ─────────────────────────────────────────────────────────── */

@keyframes maxiDropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes maxiFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Grupos de resultados / sugestões ──────────────────────────────────── */

.maxi-search-group {
    padding: 12px 23px 8px;
}

.maxi-search-group + .maxi-search-group {
    border-top: 1px solid #f0f0f0;
}

.maxi-search-group-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.06em;
    color: #000000;
    margin-bottom: 12px !important;
}

/* ── Ícone de lupa nas sugestões ────────────────────────────────────── */

.maxi-suggestion-icon {
    flex-shrink: 0;
    opacity: 0.35;
    color: currentColor;
}

/* ── Listas de sugestões ─────────────────────────────────────────────── */

.maxi-search-suggestion-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.maxi-search-suggestion-list li + li {
    margin-top: 2px;
}

.maxi-search-suggestion-cat,
.maxi-search-suggestion-product {
    display: flex;
    align-items: center;
    gap: 9px;
    border-radius: 6px;
    text-decoration: none;
    color: #333;
    font-size: 14px;
    transition: background 0.15s;
}

.maxi-search-suggestion-cat:hover,
.maxi-search-suggestion-product:hover {
    color: #007b3f;
}

.maxi-search-suggestion-cat img,
.maxi-search-suggestion-product img {
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

/* ── Resultados dinâmicos (AJAX) ─────────────────────────────────────── */

.maxi-result-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 16px;
    text-decoration: none;
    color: #333;
    border-radius: 6px;
    transition: background 0.15s;
    margin: 2px 4px;
}

.maxi-result-item:hover {
    background: #f5f5f5;
    color: #000;
}

.maxi-result-item img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 2px;
}

.maxi-result-item-info {
    flex: 1;
    min-width: 0;
}

.maxi-result-item-name {
    font-size: 14px;
    font-weight: 500;
    display: block;
    white-space: normal;
    overflow: visible;
    word-break: break-word;
    line-height: 1.4;
}

/* ── Ver todos os resultados ─────────────────────────────────────────── */

.maxi-search-view-all {
    padding: 8px 12px 12px;
    border-top: 1px solid #f0f0f0;
    margin-top: 4px;
}

.maxi-search-view-all-link {
    display: block;
    text-align: center;
    padding: 8px 16px;
    background: #f7f7f7;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.maxi-search-view-all-link:hover {
    background: #eef4fb;
    border-color: #0073aa;
    color: #0073aa;
}

/* ── Estados: loader / vazio / erro ─────────────────────────────────── */

.maxi-search-status {
    padding: 20px 16px !important;
    text-align: center;
    font-size: 14px;
    color: #888;
}

/* Loader spinner */
.maxi-loader {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid #ddd;
    border-top-color: #0073aa;
    border-radius: 50%;
    animation: maxiSpin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes maxiSpin {
    to { transform: rotate(360deg); }
}

/* ── Scrollbar discreta no dropdown ────────────────────────────────── */

.maxi-search-results::-webkit-scrollbar {
    width: 4px;
}

.maxi-search-results::-webkit-scrollbar-track {
    background: transparent;
}

.maxi-search-results::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 4px;
}

.maxi-search-results::-webkit-scrollbar-thumb:hover {
    background: #bbb;
}

/* ── Match highlighting ────────────────────────────────────────────── */

mark.maxi-highlight {
    background: transparent;
    color: inherit;
    font-weight: 600;
}

/* ── Separador entre sugestões e dinâmico ──────────────────────────── */

.maxi-search-suggestions + .maxi-search-dynamic:not(:empty) {
    border-top: 1px solid #f0f0f0;
}