/* Smart Product Search Pro v2.1 */
:root {
    --sps-primary: #c0392b;
    --sps-text: #333;
    --sps-light: #666;
    --sps-border: #ddd;
    --sps-bg: #fff;
    --sps-hover: #f5f5f5;
    --sps-radius: 0;
}

/* ============================================
   CONTENEDOR PRINCIPAL
   ============================================ */
.sps-search-box {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
}

.sps-search-box *,
.sps-search-box *::before,
.sps-search-box *::after {
    box-sizing: border-box !important;
}

.sps-form {
    position: relative !important;
    width: 100% !important;
}

/* ============================================
   INPUT WRAPPER - FLEXBOX HORIZONTAL
   ============================================ */
.sps-search-box .sps-input-wrap {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    width: 100% !important;
    background: var(--sps-bg) !important;
    border: 2px solid var(--sps-border) !important;
    border-radius: var(--sps-radius) !important;
    overflow: hidden !important;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* FIX: Elementor/WordPress widgets añaden <code> que rompe el flex */
.sps-search-box .sps-input-wrap > code,
.sps-search-box .sps-input-wrap code {
    display: contents !important;
}

.sps-search-box .sps-input-wrap:focus-within {
    border-color: var(--sps-primary) !important;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1) !important;
}

/* ============================================
   INPUT FIELD
   ============================================ */
.sps-search-box .sps-input {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    width: 100% !important;
    padding: 12px 15px !important;
    border: none !important;
    outline: none !important;
    font-size: 14px !important;
    background: transparent !important;
    color: var(--sps-text) !important;
    height: auto !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.sps-search-box .sps-input::placeholder {
    color: #999;
}

/* ============================================
   CLEAR Y LOADER - OCULTOS POR DEFECTO
   ============================================ */
.sps-search-box .sps-clear,
.sps-search-box .sps-loader {
    display: none !important;
    flex: 0 0 32px !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    color: #999;
    padding: 0 !important;
    margin: 0 !important;
}

/* VISIBLE cuando tiene la clase */
.sps-search-box .sps-clear.sps-visible,
.sps-search-box .sps-loader.sps-visible {
    display: flex !important;
}

.sps-search-box .sps-clear:hover {
    color: var(--sps-text);
}

.sps-search-box .sps-loader svg {
    animation: sps-rotate 1s linear infinite;
}

@keyframes sps-rotate {
    100% { transform: rotate(360deg); }
}

/* ============================================
   BOTÓN DE BÚSQUEDA
   ============================================ */
.sps-search-box .sps-btn {
    flex: 0 0 48px !important;
    width: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    height: auto !important;
    min-height: 46px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--sps-primary) !important;
    border: none !important;
    cursor: pointer !important;
    color: #fff !important;
    transition: background 0.2s;
    padding: 0 !important;
    margin: 0 !important;
    -webkit-appearance: none !important;
    appearance: none !important;
}

.sps-search-box .sps-btn:hover {
    background: #a93226 !important;
}

.sps-search-box .sps-btn svg {
    width: 20px !important;
    height: 20px !important;
    flex-shrink: 0 !important;
}

/* ============================================
   DROPDOWN - OCULTO POR DEFECTO
   ============================================ */
.sps-search-box .sps-dropdown {
    display: none !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    margin-top: 8px !important;
    background: var(--sps-bg) !important;
    border-radius: var(--sps-radius) !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    z-index: 99999 !important;
    overflow: hidden !important;
    min-width: 280px !important;
}

.sps-search-box .sps-dropdown.sps-visible {
    display: block !important;
    animation: sps-fade 0.2s ease;
}

@keyframes sps-fade {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   RESULTADOS
   ============================================ */
.sps-results {
    max-height: 400px;
    overflow-y: auto;
}

.sps-item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    transition: background 0.15s;
    animation: sps-slide 0.2s ease forwards;
    opacity: 0;
}

.sps-item:hover,
.sps-item.sps-active {
    background: var(--sps-hover);
}

.sps-item-link {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 12px 15px;
    text-decoration: none;
    color: var(--sps-text);
}

.sps-item-img {
    position: relative;
    width: 50px;
    height: 50px;
    margin-right: 12px;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
    flex-shrink: 0;
}

.sps-item-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sps-sale {
    position: absolute;
    top: 2px;
    left: 2px;
    padding: 2px 4px;
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    background: var(--sps-primary);
    border-radius: 2px;
    text-transform: uppercase;
}

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

.sps-item-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--sps-text);
    margin-bottom: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sps-item-name mark {
    background: rgba(192, 57, 43, 0.15);
    color: var(--sps-primary);
    padding: 0 2px;
    border-radius: 2px;
}

.sps-item-sku {
    font-size: 10px;
    color: #999;
}

.sps-item-cat {
    font-size: 11px;
    color: var(--sps-light);
}

.sps-item-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--sps-primary);
    margin-top: 2px;
}

.sps-item-price del {
    color: #999;
    font-weight: 400;
    margin-right: 5px;
}

.sps-item-price ins {
    text-decoration: none;
}

.sps-out {
    font-size: 10px;
    color: #999;
    background: #f0f0f0;
    padding: 2px 5px;
    border-radius: 3px;
}

/* ============================================
   BOTÓN AGREGAR AL CARRITO
   ============================================ */
.sps-add-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-right: 8px;
    background: var(--sps-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s, background 0.15s;
    flex-shrink: 0;
}

.sps-add-cart:hover {
    transform: scale(1.05);
    background: #a93226;
}

.sps-add-cart.loading {
    background: #999;
    pointer-events: none;
}

.sps-add-cart.added {
    background: #27ae60;
}

.sps-spin {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sps-rotate 0.6s linear infinite;
}

.sps-select {
    padding: 6px 10px;
    margin-right: 8px;
    font-size: 11px;
    color: var(--sps-primary);
    background: transparent;
    border: 1px solid var(--sps-primary);
    border-radius: 4px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.sps-select:hover {
    background: var(--sps-primary);
    color: #fff;
}

.sps-no-results {
    padding: 25px;
    text-align: center;
    color: var(--sps-light);
}

/* ============================================
   VER TODOS LOS RESULTADOS
   ============================================ */
.sps-view-all {
    display: none;
    padding: 12px 15px;
    text-align: center;
    background: #f9f9f9;
    color: var(--sps-primary);
    font-weight: 600;
    text-decoration: none;
    border-top: 1px solid #eee;
    transition: background 0.15s;
}

.sps-view-all.sps-visible {
    display: block;
}

.sps-view-all:hover {
    background: #f0f0f0;
}

/* ============================================
   HISTORIAL
   ============================================ */
.sps-history-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    font-size: 11px;
    color: var(--sps-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sps-clear-history {
    background: none;
    border: none;
    color: var(--sps-primary);
    cursor: pointer;
    font-size: 11px;
}

.sps-clear-history:hover {
    text-decoration: underline;
}

.sps-history-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    cursor: pointer;
    color: var(--sps-text);
    transition: background 0.15s;
}

.sps-history-item:hover,
.sps-history-item.sps-active {
    background: var(--sps-hover);
}

.sps-history-item svg {
    margin-right: 10px;
    color: var(--sps-light);
}

/* ============================================
   MOBILE
   ============================================ */
@media (max-width: 600px) {
    .sps-search-box .sps-dropdown.sps-visible {
        position: fixed !important;
        left: 10px !important;
        right: 10px !important;
        top: auto !important;
        bottom: 0 !important;
        margin: 0 !important;
        border-radius: 8px 8px 0 0 !important;
        max-height: 60vh !important;
    }
    
    .sps-results {
        max-height: calc(60vh - 50px);
    }
    
    .sps-item-img {
        width: 40px;
        height: 40px;
    }
}

/* ============================================
   ANIMACIONES
   ============================================ */
.sps-item:nth-child(1) { animation-delay: 0ms; }
.sps-item:nth-child(2) { animation-delay: 30ms; }
.sps-item:nth-child(3) { animation-delay: 60ms; }
.sps-item:nth-child(4) { animation-delay: 90ms; }
.sps-item:nth-child(5) { animation-delay: 120ms; }
.sps-item:nth-child(6) { animation-delay: 150ms; }
.sps-item:nth-child(7) { animation-delay: 180ms; }
.sps-item:nth-child(8) { animation-delay: 210ms; }

@keyframes sps-slide {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}
