/* Enhanced Product Search Styles */

/* Remove loading state from search input (no spinner above search bar) */
.woocommerce-product-search.loading {
    position: relative;
}

/* Typing indicator during debounce period */
.ajax-search-result.typing {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    border-top: none !important;
    border-radius: 0 0 8px 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    min-height: 60px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 1000 !important;
    opacity: 0.8 !important;
}

.ajax-search-result.typing::before {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--e-global-color-primary, #007cba);
    border-radius: 50%;
    animation: bokifa-typing-pulse 1.5s ease-in-out infinite;
    margin-bottom: 6px;
}

.ajax-search-result.typing::after {
    content: "Typing...";
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    text-align: center;
}

@keyframes bokifa-typing-pulse {
    0%, 100% { 
        opacity: 0.3;
        transform: scale(0.8);
    }
    50% { 
        opacity: 1;
        transform: scale(1);
    }
}

/* Loading state for actual search (after debounce) */
.ajax-search-result.loading {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    background: #fff !important;
    border: 1px solid #e0e0e0 !important;
    border-top: none !important;
    border-radius: 0 0 8px 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    min-height: 80px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 1000 !important;
    opacity: 1 !important;
}

.ajax-search-result.loading::before {
    content: "";
    width: 28px;
    height: 28px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--e-global-color-primary, #007cba);
    border-radius: 50%;
    animation: bokifa-search-spin 1s linear infinite;
    margin-bottom: 8px;
}

.ajax-search-result.loading::after {
    content: "Searching for products...";
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    text-align: center;
}

@keyframes bokifa-search-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Mobile responsiveness for loading and typing states */
@media (max-width: 768px) {
    .ajax-search-result.typing {
        min-height: 50px;
    }
    
    .ajax-search-result.typing::before {
        width: 16px;
        height: 16px;
        border-width: 2px;
        margin-bottom: 4px;
    }
    
    .ajax-search-result.typing::after {
        font-size: 11px;
    }
    
    .ajax-search-result.loading {
        min-height: 70px;
    }
    
    .ajax-search-result.loading::before {
        width: 24px;
        height: 24px;
        border-width: 2px;
        margin-bottom: 6px;
    }
    
    .ajax-search-result.loading::after {
        font-size: 12px;
    }
}

/* Search Results Container */
.ajax-search-result {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 500px; /* Increased from 400px to handle more results */
    overflow-y: auto;
    z-index: 1000;
    transition: opacity 0.2s ease;
    scrollbar-width: thin;
    scrollbar-color: #ccc #f1f1f1;
    display: block; /* Ensure it's always displayed when shown */
    visibility: visible;
    padding: 0;
}

/* Force visibility when loading or typing states are active */
.ajax-search-result.loading,
.ajax-search-result.typing {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Webkit scrollbar styling for better UX with more results */
.ajax-search-result::-webkit-scrollbar {
    width: 6px;
}

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

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

.ajax-search-result::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.ajax-search-result.loading {
    opacity: 0.9;
}

/* Results counter for multiple results */
.search-results-header {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    padding: 8px 15px;
    font-size: 12px;
    color: #666;
    z-index: 10;
}

.search-results-header.many-results {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    font-weight: 500;
}

/* Loading pulse effect for search input */
.woocommerce-product-search.loading .search-field {
    background-color: #f8f9fa;
    transition: background-color 0.3s ease;
}

/* Individual Search Result Items */
.product-item-search {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
}

.product-item-search:last-child {
    border-bottom: none;
}

.product-item-search:hover,
.product-item-search.keyboard-selected {
    background-color: #f8f9fa;
}

.product-item-search .product-link {
    display: flex;
    align-items: center;
    width: 100%;
    text-decoration: none;
    color: inherit;
}

/* Product Image */
.product-item-search .product-image {
    position: relative;
    width: 50px;
    height: 50px;
    margin-right: 12px;
    flex-shrink: 0;
    overflow: hidden;
    border-radius: 4px;
    background-color: #f5f5f5;
}

.product-item-search .product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.product-item-search:hover .product-image img {
    transform: scale(1.05);
}

/* Featured Badge */
.product-item-search .featured-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--e-global-color-primary, #007cba);
    color: white;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Product Content */
.product-item-search .product-content {
    flex: 1;
    min-width: 0;
}

.product-item-search .product-title {
    font-size: 14px;
    font-weight: 500;
    margin: 0 0 4px 0;
    line-height: 1.3;
    color: #333;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-item-search .product-subtitle {
    font-size: 12px;
    color: #666;
    margin: 2px 0 4px 0;
    line-height: 1.2;
    font-style: italic;
}

.product-item-search .product-price {
    font-size: 13px;
    font-weight: 600;
    color: var(--e-global-color-primary, #007cba);
    margin: 2px 0;
}

.product-item-search .product-price del {
    color: #999;
    font-weight: normal;
    margin-right: 5px;
}

/* Suggestion Notes */
.product-item-search .suggestion-note {
    font-size: 11px;
    color: #666;
    font-style: italic;
}

/* Featured Products Styling */
.product-item-search.featured-product {
    background: linear-gradient(90deg, #fff9e6 0%, #ffffff 100%);
    border-left: 3px solid var(--e-global-color-primary, #007cba);
}

.product-item-search.featured-product .product-title {
    color: #1a1a1a;
}

/* No Results Styling */
.product-item-search.suggestion-no_results {
    justify-content: center;
    padding: 20px;
    color: #666;
    font-style: italic;
    background: #f9f9f9;
}

.no-search-results,
.search-error {
    padding: 20px;
    text-align: center;
    color: #666;
    font-style: italic;
    background: #f9f9f9;
}

.search-error {
    color: #d63384;
    background: #fff5f5;
}

/* Keyboard Navigation Indicator */
.product-item-search.keyboard-selected {
    background-color: #e3f2fd;
    border-left: 3px solid var(--e-global-color-primary, #007cba);
}

/* Responsive Design */
@media (max-width: 768px) {
    .ajax-search-result {
        max-height: 300px;
    }
    
    .product-item-search {
        padding: 10px 12px;
    }
    
    .product-item-search .product-image {
        width: 40px;
        height: 40px;
        margin-right: 10px;
    }
    
    .product-item-search .product-title {
        font-size: 13px;
    }
    
    .product-item-search .product-subtitle {
        font-size: 11px;
    }
    
    .product-item-search .product-price {
        font-size: 12px;
    }
}

/* Search Input Focus State */
.woocommerce-product-search .search-field:focus {
    border-color: var(--e-global-color-primary, #007cba);
    box-shadow: 0 0 0 2px rgba(0, 124, 186, 0.1);
    outline: none;
}

/* Search Container Positioning */
.ajax-search {
    position: relative;
}

/* Smooth transitions */
.ajax-search-result,
.product-item-search,
.product-image img {
    transition: all 0.2s ease;
}

/* Scrollbar Styling for Search Results */
.ajax-search-result::-webkit-scrollbar {
    width: 6px;
}

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

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

.ajax-search-result::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* High contrast for accessibility */
@media (prefers-contrast: high) {
    .product-item-search {
        border-bottom-color: #000;
    }
    
    .ajax-search-result {
        border-color: #000;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    
    .product-item-search.keyboard-selected {
        background-color: #ffff00;
        color: #000;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    .product-item-search,
    .product-image img,
    .ajax-search-result {
        transition: none;
    }
    
    .woocommerce-product-search.loading::after {
        animation: none;
    }
}

.ajax-search-result.d-none {
    border: none !important;
}

.ajax-search-result.typing {
    display: none !important; /* Hide by default, shown when typing */
}

/* Layout 3 - Uses Layout 2 trigger button, Layout 1 search form in popup */
/* No additional button styles needed since it uses the same trigger as Layout 2 */
/* The popup content styling is handled by existing Layout 1 search form styles */