/**
 * INFINITY E-commerce - AJAX Live Search Styles
 * Woodmart-inspired search experience
 *
 * @package Infinity_Ecommerce
 * @version 3.7.0
 */

/* ==========================================================================
   SEARCH OVERLAY
   ========================================================================== */
.ajax-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--infinity-z-overlay, 1100);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ajax-search-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ==========================================================================
   SEARCH CONTAINER
   ========================================================================== */
.ajax-search-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: 100%;
    max-width: 720px;
    max-height: 85vh;
    background: #FFFFFF;
    border-radius: 20px;
    box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.ajax-search-overlay.active .ajax-search-container {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ==========================================================================
   SEARCH HEADER
   ========================================================================== */
.ajax-search-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    background: #fafbfe;
}

.ajax-search-input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.ajax-search-input-wrapper .search-icon {
    position: absolute;
    left: 1rem;
    color: #94A3B8;
    pointer-events: none;
}

.ajax-search-input {
    width: 100%;
    padding: 0.875rem 3rem;
    font-size: 1rem;
    border: 2px solid #E2E8F0;
    border-radius: 12px;
    background: #FFFFFF;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ajax-search-input:focus {
    border-color: var(--infinity-primary, #6366F1);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08);
}

.ajax-search-input:focus-visible {
    outline: none;
}

.ajax-search-input::placeholder {
    color: #94A3B8;
}

.ajax-search-clear {
    position: absolute;
    right: 0.75rem;
    width: 65px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F1F5F9;
    border: none;
    border-radius: 12px;
    color: #64748B;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.ajax-search-clear.visible {
    opacity: 1;
    visibility: visible;
}

.ajax-search-clear:hover {
    background: #E2E8F0;
    color: #1E293B;
}

.ajax-search-close {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #64748B;
    background: none;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.ajax-search-close:hover {
    color: #6366F1;
}

/* ==========================================================================
   SEARCH RESULTS AREA
   ========================================================================== */
.ajax-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    min-height: 200px;
    max-height: calc(85vh - 80px);
}

/* Custom scrollbar */
.ajax-search-results::-webkit-scrollbar {
    width: 6px;
}

.ajax-search-results::-webkit-scrollbar-track {
    background: #F1F5F9;
    border-radius: 3px;
}

.ajax-search-results::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

.ajax-search-results::-webkit-scrollbar-thumb:hover {
    background: #94A3B8;
}

/* ==========================================================================
   SEARCH SECTIONS
   ========================================================================== */
.search-section {
    margin-bottom: 1.5rem;
}

.search-section:last-child {
    margin-bottom: 0;
}

.search-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94A3B8;
    margin: 0 0 1rem 0;
}

/* ==========================================================================
   POPULAR CATEGORIES GRID
   ========================================================================== */
.search-categories-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.search-category-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    background: #F8FAFC;
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.search-category-item:hover {
    background: #F1F5F9;
    transform: translateY(-2px);
}

.search-category-item img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 0.5rem;
}

.search-category-item span {
    font-size: 0.8rem;
    font-weight: 500;
    color: #1E293B;
    text-align: center;
    line-height: 1.3;
}

/* ==========================================================================
   PRODUCTS LIST
   ========================================================================== */
.search-products-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.search-product-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #FFFFFF;
    border: 1px solid #f1f5f9;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.search-product-item:hover {
    border-color: var(--infinity-primary, #6366F1);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.1);
    background: rgba(99, 102, 241, 0.02);
}

.search-product-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    text-decoration: none;
    min-width: 0;
}

.search-product-link:hover {
    transform: translateX(4px);
}

.search-product-image {
    width: 60px;
    height: 60px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #F8FAFC;
}

.search-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.search-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.search-product-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: #1E293B;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-product-price {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--infinity-primary, #6366F1);
}

.search-product-price del {
    color: #94A3B8;
    font-weight: 400;
    margin-right: 0.5rem;
}

.search-product-price ins {
    text-decoration: none;
    color: var(--infinity-primary, #6366F1);
}

/* Product category badge */
.search-product-category {
    font-size: 0.7rem;
    color: #94A3B8;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ==========================================================================
   SEARCH STATES
   ========================================================================== */

/* Loading state */
.search-loading {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
}

.search-loading.active {
    display: flex;
}

.search-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #E2E8F0;
    border-top-color: #6366F1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.search-loading span {
    font-size: 0.9rem;
    color: #64748B;
}

/* No results state */
.search-no-results {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.search-no-results.active {
    display: flex;
}

.search-no-results svg {
    color: #CBD5E1;
    margin-bottom: 1rem;
}

.search-no-results p {
    font-size: 1.1rem;
    font-weight: 600;
    color: #1E293B;
    margin: 0 0 0.5rem 0;
}

.search-no-results-hint {
    font-size: 0.9rem;
    color: #64748B;
}

/* Initial state */
.search-initial-state {
    display: block;
}

.search-initial-state.hidden {
    display: none;
}

/* Results content */
.search-results-content {
    display: none;
}

.search-results-content.active {
    display: block;
}

/* ==========================================================================
   VIEW ALL RESULTS
   ========================================================================== */
.search-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 14px;
    margin-top: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--infinity-gray, #64748B);
    background: var(--infinity-light, #f8fafc);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease;
    box-shadow: none;
}

.search-view-all:hover {
    color: var(--infinity-primary, #6366F1);
    background: rgba(99, 102, 241, 0.06);
    border-color: rgba(99, 102, 241, 0.15);
}

.search-view-all svg {
    width: 18px;
    height: 18px;
}

/* ==========================================================================
   MATCHED CATEGORIES IN RESULTS
   ========================================================================== */
.search-matched-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-matched-category {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: #1E293B;
    background: #F1F5F9;
    border-radius: 20px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.search-matched-category:hover {
    background: var(--infinity-primary, #6366F1);
    color: #fff;
}

.search-matched-category svg {
    width: 14px;
    height: 14px;
}

/* ==========================================================================
   RECENT SEARCHES
   ========================================================================== */
.search-recent-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.search-recent-item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.85rem;
    color: #64748B;
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 20px;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-recent-item:hover {
    border-color: var(--infinity-primary, #6366F1);
    color: var(--infinity-primary, #6366F1);
    background: rgba(99, 102, 241, 0.04);
}

.search-recent-item svg {
    width: 14px;
    height: 14px;
}

/* ==========================================================================
   SEARCH ADD TO CART BUTTON
   ========================================================================== */
.search-add-to-cart {
    flex-shrink: 0;
    width: 65px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-add-to-cart:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.search-add-to-cart:active {
    transform: scale(0.95);
}

.search-add-to-cart.loading {
    opacity: 0.7;
    pointer-events: none;
}

.search-add-to-cart.added {
    background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
}

.search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Search Notification */
.search-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: #1E293B;
    color: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: var(--infinity-z-notification, 1300);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.search-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.search-notification--success {
    background: linear-gradient(135deg, #22C55E 0%, #16A34A 100%);
}

.search-notification--error {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
}

.search-notification__icon {
    font-size: 1.1rem;
}

/* ==========================================================================
   KEYBOARD NAVIGATION
   ========================================================================== */
.search-product-item.focused,
.search-category-item.focused {
    outline: 2px solid #6366F1;
    outline-offset: 2px;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
    .ajax-search-container {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .ajax-search-header {
        padding: 1rem;
    }

    .ajax-search-results {
        max-height: calc(100vh - 70px);
        padding: 1rem;
    }

    .search-categories-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .search-product-image {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 480px) {
    .search-categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .search-category-item {
        padding: 0.75rem;
    }

    .search-category-item img {
        width: 40px;
        height: 40px;
    }
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-results-content .search-product-item {
    animation: fadeInUp 0.3s ease forwards;
    opacity: 0;
}

.search-results-content .search-product-item:nth-child(1) { animation-delay: 0.05s; }
.search-results-content .search-product-item:nth-child(2) { animation-delay: 0.1s; }
.search-results-content .search-product-item:nth-child(3) { animation-delay: 0.15s; }
.search-results-content .search-product-item:nth-child(4) { animation-delay: 0.2s; }
.search-results-content .search-product-item:nth-child(5) { animation-delay: 0.25s; }
.search-results-content .search-product-item:nth-child(6) { animation-delay: 0.3s; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ajax-search-overlay,
    .ajax-search-container,
    .search-product-item,
    .search-category-item {
        transition: none;
    }

    .search-results-content .search-product-item {
        animation: none;
        opacity: 1;
    }

    .search-loading-spinner {
        animation-duration: 1.5s;
    }
}
