/**
 * Antigravity Ajax Search - Styles
 * 
 * Estilos para el dropdown de resultados.
 */

.ag-search-dropdown {
    position: absolute;
    z-index: 9999;
    background: #fff;
    background-color: #ffffff !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    margin-top: 5px;
    border: 1px solid #eee;
    overflow: hidden;
    contain: layout paint style;
    display: none;
    /* Default hidden */
}

.ag-search-results-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    max-height: 400px;
    overflow-y: auto;
    /* Aísla el scroll del listado.
       Prevents the background body from scrolling when the dropdown is scrolled to its limits. */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.ag-search-item {
    /* Reserva espacio de imagen para evitar saltos visuales.
       Subtle entry transition for results. */
    opacity: 0;
    animation: ag-item-fadein 0.2s ease forwards;
}

@keyframes ag-item-fadein {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Selectores directos para no afectar listas anidadas del tema.
   Faster matching for the CSS engine during rendering. */
.ag-search-results-list>.ag-search-item>a {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    text-decoration: none !important;
    color: #333 !important;
    border-bottom: 1px solid #f5f5f5;
    transition: background 0.2s ease;
}

.ag-search-results-list>.ag-search-item:last-child>a {
    border-bottom: none;
}

.ag-search-results-list>.ag-search-item>a:hover {
    background: #f9f9f9;
}

.ag-search-results-list>.ag-search-item.is-active>a,
.ag-search-results-list>.ag-search-item>a:focus-visible {
    background: #f3f3f3;
    outline: 2px solid #d12a14;
    outline-offset: -2px;
}

.ag-item-image {
    flex: 0 0 50px;
    width: 50px;
    height: 50px;
    margin-right: 15px;
    border-radius: 4px;
    overflow: hidden;
    background: #f0f0f0;
}

.ag-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ag-item-content {
    flex: 1;
}

.ag-item-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    line-height: 1.2;
}

.ag-item-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ag-item-price {
    font-weight: 700;
    color: #d12a14;
    font-size: 13px;
}

.ag-item-stock {
    width: fit-content;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

.ag-item-out-of-stock {
    color: #8a1c0d;
    background: #fff0ed;
    border-radius: 10px;
    padding: 4px 8px;
}

.ag-search-item.is-out-of-stock .ag-item-image img {
    opacity: 0.65;
}

.ag-item-attributes {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.ag-attr-tag {
    background: #f0f0f0;
    color: #666;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 600;
}

/* Scrollbar dinámico */
.ag-search-results-list::-webkit-scrollbar {
    width: 6px;
}

.ag-search-results-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.ag-search-results-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.ag-search-results-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.ag-highlight {
    font-weight: 900;
    color: #000;
    background-color: #fff9c4;
    padding: 0 2px;
    border-radius: 2px;
}

.ag-search-view-all {
    background: #fdfdfd;
    padding: 12px;
    text-align: center;
    border-top: 1px solid #eee;
}

.ag-search-view-all a {
    font-weight: 700;
    color: #444;
    text-decoration: none;
    font-size: 13px;
    transition: color 0.2s;
}

.ag-search-view-all a:hover {
    color: #d12a14;
}

.ag-search-status,
.ag-search-loading {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 13px;
    font-style: italic;
}

.ag-search-error {
    color: #8a1c0d;
}

.ag-search-empty {
    font-style: normal;
}

@media (prefers-reduced-motion: reduce) {
    .ag-search-item {
        animation: none;
        opacity: 1;
    }

    .ag-search-results-list>.ag-search-item>a,
    .ag-search-view-all a {
        transition: none;
    }
}

/* Responsive Móvil: Full-width */
@media screen and (max-width: 768px) {
    .ag-search-dropdown {
        position: fixed !important;
        background-color: #ffffff !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        margin: 0;
        border-radius: 0;
        z-index: 9999999;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .ag-search-results-list {
        max-height: none;
        flex: 1;
        overflow-y: auto;
    }

    .ag-search-view-all {
        flex-shrink: 0;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }

    body.ag-search-open {
        overflow: hidden;
        /* Evitar scroll del body al buscar */
    }
}
