/**
 * Typesense Search Styling for NopCommerce
 * Extracted and adapted from showcase-ecommerce-store-master/src/app.scss
 * 
 * Note: Button styling is handled by the Emporium theme CSS.
 * This file only contains search-specific styling.
 */

/* ============ Search Results Container ============ */
#typesense-results-container {
    min-height: 400px;
    padding: 20px 0;
    background-color: #ffffff;
}

.typesense-search-active .master-column-wrapper {
    display: none !important;
}

.typesense-search-active #typesense-results-container {
    display: block !important;
}

/* ============ Search Result Cards ============ */
.search-result-card {
    min-height: 100px;
    font-size: 14px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px;
    background-color: #fff;
    transition: box-shadow 0.2s ease-in-out;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.search-result-card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-color: #007bff;
}

@media (min-width: 768px) {
    .search-result-card {
        min-height: 350px;
        font-size: 13px;
    }
}

.search-result-card .image-container {
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.search-result-card .image-container img {
    max-width: 100%;
    max-height: 150px;
    object-fit: contain;
    border-radius: 4px;
}

.search-result-card .product-name {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.3;
}

.search-result-card .product-description {
    color: #666;
    font-size: 13px;
    line-height: 1.4;
    margin-bottom: 10px;
    flex-grow: 1;
}

.search-result-card .hit-price {
    font-size: 18px;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 5px;
}

.search-result-card .hit-rating {
    font-size: 12px;
    color: #666;
    margin-bottom: 8px;
}

.search-result-card .free-shipping-badge {
    background-color: #28a745;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
    margin-bottom: 10px;
}

/* ============ Search Results Grid ============ */
.search-results-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 20px;
    margin-top: 20px;
}

@media (min-width: 768px) {
    .search-results-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        column-gap: 20px;
        row-gap: 25px;
    }
}

@media (min-width: 1200px) {
    .search-results-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ============ Search Stats ============ */
.search-stats {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
}

/* ============ No Results ============ */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.no-results h3 {
    margin-bottom: 15px;
    color: #333;
}

.no-results p {
    font-size: 16px;
    margin-bottom: 0;
}

/* ============ Search Highlighting ============ */
mark {
    background-color: #fff3cd;
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 600;
}

/* ============ Buttons ============ */
.add-to-cart-btn {
    background-color: #007bff;
    border-color: #007bff;
    color: white;
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 4px;
    transition: all 0.2s ease-in-out;
}

.add-to-cart-btn:hover {
    background-color: #0056b3;
    border-color: #0056b3;
    transform: translateY(-1px);
}

/* ============ Typesense Search Box ============ */
#typesense-search-form {
    position: relative;
}

#typesense-search-form .search-box-button {
    display: none !important; /* Hide search button for real-time search */
}

#typesense-searchbox {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: border-color 0.2s ease-in-out;
}

#typesense-searchbox:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.search-reset-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #666;
    font-size: 16px;
}

.search-reset-icon:hover {
    color: #333;
}

/* ============ InstantSearch Widget Overrides ============ */

/* Hierarchical Menu */
.ais-HierarchicalMenu-item--selected a,
.ais-HierarchicalMenu-item--selected a:hover {
    color: #007bff !important;
    font-weight: 600;
}

/* Pagination */
.ais-Pagination-item--selected a,
.ais-Pagination-item--selected a:hover {
    color: #007bff !important;
    font-weight: 600;
}

/* Rating Menu */
.ais-RatingMenu-item--selected a,
.ais-RatingMenu-item--selected a:hover {
    color: #007bff !important;
    font-weight: 600;
}

/* ============ Range Slider Styling ============ */
.ais-RangeSlider .rheostat {
    overflow: visible;
    margin-top: 40px;
    margin-bottom: 40px;
}

.ais-RangeSlider .rheostat-background {
    height: 6px;
    top: 0;
    width: 100%;
    position: relative;
    background-color: #fff;
    border: 1px solid #aaa;
}

.ais-RangeSlider .rheostat-progress {
    position: absolute;
    top: 1px;
    height: 4px;
    background-color: #007bff;
}

.ais-RangeSlider .rheostat-handle {
    margin-left: -12px;
    top: -7px;
    position: relative;
    z-index: 1;
    width: 17px;
    height: 17px;
    background-color: #fff;
    border: 1px solid #333;
    border-radius: 50%;
    cursor: grab;
}

.ais-RangeSlider .rheostat-handle:active {
    cursor: grabbing;
}

.rheostat-marker {
    margin-left: -1px;
    position: absolute;
    width: 1px;
    height: 5px;
    background-color: #aaa;
}

.rheostat-marker--large {
    height: 9px;
}

.rheostat-value {
    padding-top: 15px;
    margin-left: 50%;
    position: absolute;
    text-align: center;
    transform: translateX(-50%);
}

.rheostat-tooltip {
    top: -22px;
    margin-left: 50%;
    position: absolute;
    text-align: center;
    transform: translateX(-50%);
}

/* ============ Rating Stars ============ */
.ais-RatingMenu-starIcon {
    position: relative;
    top: -1px;
    width: 15px;
    fill: #ffc107;
}

/* ============ Form Controls ============ */
.ais-HitsPerPage-select:focus,
.ais-SortBy-select:focus {
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
    border-color: #007bff;
}

/* ============ Refinement Lists ============ */
.ais-RefinementList-item {
    margin-bottom: 5px;
}

.ais-RefinementList-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
}

.ais-RefinementList-checkbox {
    margin-right: 8px;
}

.ais-RefinementList-count {
    background-color: #e9ecef;
    color: #495057;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    margin-left: auto;
}

.ais-RefinementList-showMore {
    background-color: #6c757d;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    font-size: 12px;
    margin-top: 10px;
    cursor: pointer;
}

.ais-RefinementList-showMore:hover {
    background-color: #5a6268;
}

/* ============ Clear Refinements ============ */
.ais-ClearRefinements-button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}

.ais-ClearRefinements-button:hover {
    background-color: #0056b3;
}

.ais-ClearRefinements-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

/* ============ Loading States ============ */
.ais-SearchBox-loadingIcon {
    stroke: #007bff;
}

/* ============ Mobile Responsiveness ============ */
@media (max-width: 767px) {
    #typesense-results-container {
        padding: 15px 0;
    }
    
    .search-result-card {
        margin-bottom: 15px;
    }
    
    .search-result-card .product-name {
        font-size: 15px;
    }
    
    .search-result-card .hit-price {
        font-size: 16px;
    }
}

/* ============ Real Typesense Data Styling ============ */
.hit-manufacturer {
    color: #6c757d;
    font-size: 0.9em;
    margin-bottom: 2px;
}

.hit-part-number {
    color: #6c757d;
    font-size: 0.85em;
    margin-bottom: 5px;
}

.hit-stock.in-stock {
    color: #28a745;
    font-weight: bold;
    font-size: 0.9em;
}

.hit-stock.out-of-stock {
    color: #dc3545;
    font-weight: bold;
    font-size: 0.9em;
}

/* ============ Loading States ============ */
.search-loading {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
    font-style: italic;
}

.search-error {
    text-align: center;
    padding: 2rem;
    color: #dc3545;
}

.search-error h3 {
    color: #dc3545;
    margin-bottom: 10px;
}

/* ============ Enhanced Search Stats ============ */
.search-stats {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
    font-weight: 500;
}

/* ============ Animation and Transitions ============ */
#typesense-results-container {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-result-card {
    animation: slideInUp 0.3s ease-out;
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============ Enhanced Button Styling ============ */
.btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn:not([disabled]):hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ============ Debug Information ============ */
.hit-debug {
    margin-top: 5px;
    padding: 2px 0;
    font-size: 0.75em;
    border-top: 1px solid #e9ecef;
}

.hit-debug small {
    color: #6c757d !important;
    font-family: monospace;
}

/* ============ Facets Sidebar ============ */
.facets-sidebar {
    background: #fff;
    padding: 1rem;
    border: 1px solid #e6e6e6;
    border-radius: 3px;
    margin-bottom: 1rem;
}

.facet-group {
    margin-bottom: 1.5rem;
}

.facet-group:last-child {
    margin-bottom: 0;
}

.facet-title {
    font-size: 0.9rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    border-bottom: 1px solid #e6e6e6;
    padding-bottom: 0.25rem;
}

.facet-items {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.facet-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.6rem;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: #f8f9fa;
    border: 1px solid transparent;
}

.facet-item:hover {
    background-color: #e9ecef;
    border-color: #dee2e6;
}

.facet-item.selected {
    background-color: #ff9600;
    color: #fff;
    border-color: #b36900;
}

.facet-item.selected:hover {
    background-color: #b36900;
}

.facet-label {
    font-size: 0.85rem;
    flex-grow: 1;
}

.facet-count {
    font-size: 0.75rem;
    color: #6c757d;
    font-weight: normal;
}

.facet-item.selected .facet-count {
    color: rgba(255, 255, 255, 0.8);
}

/* ============================================
   MOBILE-FRIENDLY CONTENT HIDING
   ============================================ */
.typesense-hidden {
    visibility: hidden !important;
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
    z-index: -1 !important;
    pointer-events: none !important;
}

/* Responsive behavior for search active state */
body.typesense-search-active #typesense-results-container {
    position: relative;
    z-index: 10;
    background: #fff;
    min-height: 100vh;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .typesense-hidden {
        display: none !important; /* On mobile, completely hide to save memory */
    }
    
    body.typesense-search-active #typesense-results-container {
        min-height: calc(100vh - 60px); /* Account for mobile header */
    }
    
    /* Mobile search overlay results */
    .store-search-box #typesense-results-container {
        position: relative !important;
        display: block !important;
        background: #fff !important;
        padding: 10px !important;
        max-height: calc(100vh - 120px) !important;
        overflow-y: auto !important;
    }
    
    /* Mobile facets - collapsible layout */
    .store-search-box #typesense-results-container .side-2 {
        width: 100% !important;
        order: -1 !important; /* Show facets above results */
        margin-bottom: 15px !important;
    }
    
    .store-search-box #typesense-results-container .center-2 {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Mobile facets toggle button */
    .mobile-facets-toggle {
        display: block !important;
        width: 100% !important;
        background: #007bff !important;
        color: white !important;
        border: none !important;
        padding: 12px 16px !important;
        border-radius: 4px !important;
        font-size: 14px !important;
        font-weight: bold !important;
        cursor: pointer !important;
        margin-bottom: 10px !important;
        text-align: center !important;
        position: relative !important;
    }
    
    .mobile-facets-toggle:after {
        content: "▼" !important;
        position: absolute !important;
        right: 16px !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        transition: transform 0.3s ease !important;
    }
    
    .mobile-facets-toggle.expanded:after {
        transform: translateY(-50%) rotate(180deg) !important;
    }
    
    /* Mobile facets container - hidden by default */
    .store-search-box .facets-sidebar {
        display: none !important;
        margin-top: 0 !important;
        padding: 15px !important;
        background: #f8f9fa !important;
        border-radius: 4px !important;
        border: 1px solid #dee2e6 !important;
    }
    
    .store-search-box .facets-sidebar.expanded {
        display: block !important;
    }
    
    /* Hide toggle button on desktop */
    @media (min-width: 769px) {
        .mobile-facets-toggle {
            display: none !important;
        }
    }
    
    /* Mobile product grid adjustments */
    .store-search-box .search-results-grid {
        grid-template-columns: 1fr !important; /* Single column on mobile */
        gap: 10px !important;
    }
    
    .store-search-box .search-result-card {
        min-height: auto !important;
        padding: 10px !important;
    }
    
    /* Mobile facets toggle button - Emporium theme styling */
    .mobile-facets-toggle-inline:hover {
        background-color: #303030 !important;
    }
    
    .mobile-facets-toggle-inline:active {
        transform: translateY(1px) !important;
    }
}