/**
 * Enhanced Algolia Search Styles
 * Modern, clean, and responsive design
 */

/* Enhanced search container */
.search-container {
    position: relative;
    margin: 20px 0;
}

.search-container .search-loader {
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.2s;
    color: #3369E7;
    z-index: 10;
}

.search-container .search-loader.active {
    opacity: 1;
}

/* Modern search input */
.search-input,
input[type="search"] {
    width: 100%;
    padding: 14px 50px 14px 20px;
    font-size: 16px;
    border: 2px solid #E5E7EB;
    border-radius: 10px;
    background: white;
    transition: all 0.3s ease;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.search-input:focus,
input[type="search"]:focus {
    outline: none;
    border-color: #3369E7;
    box-shadow: 0 0 0 4px rgba(51, 105, 231, 0.1), 0 2px 8px rgba(51, 105, 231, 0.08);
    background: #FAFBFF;
}

.search-input::placeholder,
input[type="search"]::placeholder {
    color: #6C757D;
    opacity: 0.7;
}

/* Enhanced dropdown - Improved design */
.algolia-dropdown-enhanced {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
    max-height: 520px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    animation: slideDown 0.2s ease-out;
}

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

/* Custom scrollbar - Thinner and more subtle */
.algolia-dropdown-enhanced::-webkit-scrollbar {
    width: 6px;
}

.algolia-dropdown-enhanced::-webkit-scrollbar-track {
    background: transparent;
    margin: 10px 0;
}

.algolia-dropdown-enhanced::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

.algolia-dropdown-enhanced::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* Search categories - More spacious */
.algolia-dropdown-enhanced .search-category {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 8px 0;
}

.algolia-dropdown-enhanced .search-category:first-child {
    padding-top: 0;
}

.algolia-dropdown-enhanced .search-category:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.algolia-dropdown-enhanced .search-category h4 {
    padding: 12px 20px 8px;
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: #8B92A5;
    background: transparent;
    letter-spacing: 1px;
    position: relative;
}

/* Add icon before category headers */
.algolia-dropdown-enhanced .search-category h4:before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 4px;
    background: #3369E7;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

.algolia-dropdown-enhanced .search-category ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.algolia-dropdown-enhanced .search-category li {
    border: none;
    margin: 0 8px;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.algolia-dropdown-enhanced .search-category li:hover {
    background: linear-gradient(90deg, #F0F4FF 0%, #F8FAFF 100%);
}

.algolia-dropdown-enhanced .search-category li a {
    display: block;
    padding: 14px 16px;
    color: #2C3E50;
    text-decoration: none;
    transition: all 0.15s ease;
    position: relative;
    border-radius: 8px;
}

.algolia-dropdown-enhanced .search-category li a:hover {
    background: transparent;
    padding-left: 20px;
}

.algolia-dropdown-enhanced .search-category li a:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: #3369E7;
    border-radius: 2px;
    transition: height 0.2s ease;
}

.algolia-dropdown-enhanced .search-category li a:hover:before {
    height: 20px;
}

.algolia-dropdown-enhanced .result-title {
    display: block;
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 6px;
    transition: color 0.2s;
    line-height: 1.4;
    color: #1A202C;
}

.algolia-dropdown-enhanced .search-category li a:hover .result-title {
    color: #3369E7;
}

.algolia-dropdown-enhanced .result-title mark {
    background: linear-gradient(90deg, rgba(51, 105, 231, 0.15) 0%, rgba(0, 174, 255, 0.15) 100%);
    color: inherit;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 700;
}

.algolia-dropdown-enhanced .result-snippet {
    display: block;
    font-size: 13px;
    color: #6B7280;
    line-height: 1.5;
    margin-top: 4px;
}

.algolia-dropdown-enhanced .result-snippet mark {
    background: linear-gradient(90deg, rgba(51, 105, 231, 0.2) 0%, rgba(0, 174, 255, 0.2) 100%);
    font-weight: 600;
    padding: 1px 3px;
    border-radius: 3px;
}

.algolia-dropdown-enhanced .cas-number,
.algolia-dropdown-enhanced .supplier-location {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    color: #4B5563;
    background: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
    padding: 4px 10px;
    border-radius: 12px;
    margin-top: 8px;
    margin-right: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.algolia-dropdown-enhanced .cas-number {
    background: linear-gradient(135deg, #EBF5FF 0%, #DBEAFE 100%);
    color: #1E40AF;
    border-color: rgba(59, 130, 246, 0.2);
}

/* Dropdown header with result count */
.algolia-dropdown-enhanced .dropdown-header {
    padding: 12px 20px;
    background: linear-gradient(180deg, #FFFFFF 0%, #FAFBFC 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
}

.algolia-dropdown-enhanced .dropdown-header .result-count {
    font-size: 13px;
    font-weight: 600;
    color: #1A202C;
}

.algolia-dropdown-enhanced .dropdown-header .search-time {
    font-size: 12px;
    color: #8B92A5;
}

/* Category icons */
.algolia-dropdown-enhanced .category-icon {
    margin-right: 4px;
    font-size: 14px;
}

/* Fade in animation for results */
.algolia-dropdown-enhanced .fade-in {
    animation: fadeInUp 0.3s ease-out forwards;
    opacity: 0;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Keyboard navigation focus state */
.algolia-dropdown-enhanced a.focused {
    background: linear-gradient(90deg, #EEF2FF 0%, #F5F8FF 100%) !important;
    outline: 2px solid #3369E7;
    outline-offset: -2px;
}

/* Chemical formula badge */
.algolia-dropdown-enhanced .chemical-formula {
    display: inline-block;
    font-size: 11px;
    font-family: 'Courier New', monospace;
    color: #059669;
    background: linear-gradient(135deg, #D1FAE5 0%, #A7F3D0 100%);
    padding: 3px 8px;
    border-radius: 10px;
    margin-left: 6px;
    border: 1px solid rgba(5, 150, 105, 0.2);
}

/* Supplier rating */
.algolia-dropdown-enhanced .supplier-rating {
    display: inline-block;
    font-size: 12px;
    color: #F59E0B;
    margin-left: 8px;
}

/* No results - More friendly */
.algolia-dropdown-enhanced .no-results {
    padding: 60px 20px;
    text-align: center;
    color: #6B7280;
}

.algolia-dropdown-enhanced .no-results:before {
    content: '🔍';
    display: block;
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
    filter: grayscale(100%);
}

.algolia-dropdown-enhanced .no-results p {
    margin: 0 0 8px;
    font-size: 16px;
    color: #4B5563;
}

.algolia-dropdown-enhanced .no-results strong {
    color: #1F2937;
    font-weight: 600;
}

.algolia-dropdown-enhanced .no-results-hint {
    font-size: 13px;
    color: #9CA3AF;
}

/* Search footer - Enhanced design */
.algolia-dropdown-enhanced .search-footer {
    padding: 16px 20px;
    background: linear-gradient(180deg, #FAFBFC 0%, #F3F4F6 100%);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 0 0 12px 12px;
    margin-top: 8px;
}

.algolia-dropdown-enhanced .search-footer .view-all {
    color: #3369E7;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 8px 16px;
    border-radius: 8px;
    background: white;
    border: 1px solid rgba(51, 105, 231, 0.2);
}

.algolia-dropdown-enhanced .search-footer .view-all:hover {
    background: #3369E7;
    color: white;
    border-color: #3369E7;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(51, 105, 231, 0.25);
}

.algolia-dropdown-enhanced .search-footer .view-all:hover i {
    transform: translateX(4px);
}

.algolia-dropdown-enhanced .search-footer .view-all i {
    margin-left: 8px;
    transition: transform 0.2s;
    font-size: 12px;
}

/* Enhanced search box widget */
.search-box-root {
    position: relative;
    margin-bottom: 30px;
}

.search-box-root .search-box-form {
    position: relative;
}

.search-box-root .search-box-input {
    width: 100%;
    padding: 15px 120px 15px 50px;
    font-size: 18px;
    border: 2px solid #DEE2E6;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.search-box-root .search-box-input:focus {
    outline: none;
    border-color: #3369E7;
    box-shadow: 0 0 0 3px rgba(51, 105, 231, 0.1);
}

.search-box-root .search-box-submit,
.search-box-root .search-box-reset {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.search-box-root .search-box-submit:hover,
.search-box-root .search-box-reset:hover {
    opacity: 0.7;
}

.search-box-root .search-box-submit {
    right: 10px;
    background: #3369E7;
    color: white;
    border-radius: 5px;
    padding: 10px 20px;
}

.search-box-root .search-box-submit:hover {
    background: #2952b3;
    opacity: 1;
}

.search-box-root .search-box-reset {
    right: 100px;
    color: #6C757D;
}

.search-box-root .search-box-reset[hidden] {
    display: none;
}

/* Search results */
#algolia-hits .search-hit {
    background: white;
    border: 1px solid #DEE2E6;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    transition: all 0.3s ease;
}

#algolia-hits .search-hit:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

#algolia-hits .search-hit h3 {
    margin: 0 0 10px;
    font-size: 20px;
}

#algolia-hits .search-hit h3 a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s;
}

#algolia-hits .search-hit h3 a:hover {
    color: #3369E7;
}

#algolia-hits .search-hit h3 a mark {
    background: rgba(0, 174, 255, 0.2);
    color: inherit;
    padding: 0 3px;
    border-radius: 3px;
}

#algolia-hits .search-hit .hit-description {
    color: #6C757D;
    line-height: 1.6;
    margin-bottom: 10px;
}

#algolia-hits .search-hit .hit-description mark {
    background: rgba(0, 174, 255, 0.3);
    font-weight: 500;
}

#algolia-hits .search-hit .hit-meta {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

#algolia-hits .search-hit .hit-meta span {
    display: inline-block;
    font-size: 13px;
    padding: 4px 10px;
    background: #F8F9FA;
    border-radius: 4px;
    color: #6C757D;
}

#algolia-hits .search-hit .hit-meta .hit-type {
    background: rgba(51, 105, 231, 0.1);
    color: #3369E7;
    font-weight: 500;
}

/* No results message */
#algolia-hits .no-results-message {
    text-align: center;
    padding: 40px 20px;
    background: #F8F9FA;
    border-radius: 8px;
}

#algolia-hits .no-results-message h3 {
    color: #333;
    margin-bottom: 10px;
}

#algolia-hits .no-results-message p {
    color: #6C757D;
    margin-bottom: 20px;
}

#algolia-hits .no-results-message .btn-clear-filters {
    background: #3369E7;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
}

#algolia-hits .no-results-message .btn-clear-filters:hover {
    background: #2952b3;
}

/* Load more button */
#algolia-hits .ais-InfiniteHits-loadMore {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background: white;
    border: 2px solid #3369E7;
    color: #3369E7;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

#algolia-hits .ais-InfiniteHits-loadMore:hover {
    background: #3369E7;
    color: white;
}

#algolia-hits .ais-InfiniteHits-loadMore[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Stats widget */
#algolia-stats {
    margin-bottom: 20px;
    color: #6C757D;
    font-size: 14px;
}

#algolia-stats span {
    background: #F8F9FA;
    padding: 5px 12px;
    border-radius: 20px;
    display: inline-block;
}

/* Facets/Filters */
#ais-facets {
    background: white;
    border-radius: 8px;
    padding: 20px;
}

#ais-facets .ais-facets {
    margin-bottom: 25px;
}

#ais-facets .ais-facets h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #333;
    font-weight: 600;
}

/* Custom checkbox styles */
#ais-facets .custom-checkbox {
    position: absolute;
    opacity: 0;
}

#ais-facets .custom-checkbox + .custom-label {
    position: relative;
    padding-left: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    transition: color 0.2s;
}

#ais-facets .custom-checkbox + .custom-label:hover {
    color: #3369E7;
}

#ais-facets .custom-checkbox + .custom-label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    border: 2px solid #DEE2E6;
    border-radius: 4px;
    background: white;
    transition: all 0.3s ease;
}

#ais-facets .custom-checkbox + .custom-label:after {
    content: '\f00c';
    font-family: 'FontAwesome';
    position: absolute;
    left: 3px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: white;
    opacity: 0;
    transition: opacity 0.2s;
}

#ais-facets .custom-checkbox:checked + .custom-label {
    color: #3369E7;
    font-weight: 500;
}

#ais-facets .custom-checkbox:checked + .custom-label:before {
    background: #3369E7;
    border-color: #3369E7;
}

#ais-facets .custom-checkbox:checked + .custom-label:after {
    opacity: 1;
}

#ais-facets .custom-count {
    background: #F8F9FA;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    color: #6C757D;
    margin-left: 8px;
}

/* Filter toggle button */
.toggle-filters {
    display: none;
    background: white;
    border: 2px solid #DEE2E6;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
}

.toggle-filters:hover,
.toggle-filters.active {
    background: #3369E7;
    color: white;
    border-color: #3369E7;
}

.toggle-filters i {
    margin-right: 8px;
}

/* Filter badges */
.filter-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.filter-badges .filter-badge {
    background: rgba(51, 105, 231, 0.1);
    color: #3369E7;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.filter-badges .filter-badge i {
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.filter-badges .filter-badge i:hover {
    opacity: 1;
}

/* Clear refinements */
#clear-refinements {
    margin-top: 20px;
}

#clear-refinements button {
    width: 100%;
    padding: 10px;
    background: white;
    border: 1px solid #DEE2E6;
    border-radius: 5px;
    color: #6C757D;
    cursor: pointer;
    transition: all 0.3s ease;
}

#clear-refinements button:hover {
    background: #F8F9FA;
    color: #333;
}

/* Loading animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fa-spinner.fa-spin {
    animation: spin 1s linear infinite;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    #ais-facets {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2000;
        overflow-y: auto;
    }
    
    #ais-facets.active {
        display: block;
    }
    
    .toggle-filters {
        display: inline-block;
    }
    
    body.search-active .search-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 3000;
        background: white;
        padding: 20px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }
    
    body.search-active .algolia-dropdown-enhanced {
        position: fixed;
        top: 80px;
        left: 10px;
        right: 10px;
        max-height: calc(100vh - 100px);
    }
    
    .search-input,
    input[type="search"] {
        font-size: 16px;
    }
    
    .search-box-input {
        padding: 12px 100px 12px 15px;
        font-size: 16px;
    }
    
    #algolia-hits .search-hit {
        padding: 15px;
    }
    
    #algolia-hits .search-hit h3 {
        font-size: 18px;
    }
}

/* Responsive adjustments */
@media (min-width: 768px) {
    #ais-facets {
        padding-top: 0 !important;
        width: 350px !important;
        padding-left: 15px !important;
    }
}