/* ========================================
   SEARCH MODAL - Accessible Product Search
   ======================================== */

/* Search Toggle Button */
.search-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.search-toggle-btn:focus {
    outline: 2px solid var(--color-primary, #007bff);
    outline-offset: 2px;
}

.search-toggle-btn img {
    width: 20px;
    height: 20px;
}

/* Search Modal Container */
.search-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.search-modal.search-modal--open {
    pointer-events: auto;
    opacity: 1;
}

/* Search Modal Overlay */
.search-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

/* Search Modal Content */
.search-modal__content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 95%;
    max-width: 1100px;
    max-height: 90vh;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
        0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
}

.search-modal--open .search-modal__content {
    transform: translate(-50%, -50%) scale(1);
}

/* Search Header */
.search-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2.4rem;
    border-bottom: 1px solid #e1e1e1;
    flex-shrink: 0;
}

.search-modal__title {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-text-primary, #333);
}

.search-modal__close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    color: var(--color-text-secondary, #666);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-modal__close:hover {
    background-color: #f5f5f5;
    color: var(--color-text-primary, #333);
}

.search-modal__close:focus {
    outline: 2px solid var(--color-primary, #007bff);
    outline-offset: 2px;
}

/* Search Input Section */
.search-modal__input-wrapper {
    padding: 1.5rem;
    border-bottom: 1px solid #e1e1e1;
    flex-shrink: 0;
}

.search-input-container {
    position: relative;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 1.2rem 1.6rem;
    padding-right: 4.8rem;
    border: 2px solid #e1e1e1;
    border-radius: 8px;
    font-size: 1.6rem;
    transition: border-color 0.2s ease;
    background-color: #ffffff;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-primary, #007bff);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.search-input-clear {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    color: var(--color-text-secondary, #666);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-input-clear:hover {
    background-color: #f5f5f5;
    color: var(--color-text-primary, #333);
}

.search-hint {
    margin-top: 0.8rem;
    font-size: 1.4rem;
    color: var(--color-text-secondary, #666);
}

/* Search Results Section */
.search-modal__results {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem 1.5rem;
}

/* Search Results List */
.search-results-list {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    padding: 1rem;
}

.search-results-list.search-visible-grid {
    display: grid;
}

/* Individual Search Result Item */
.search-result-item {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    background: white;
}

.search-result-item:hover {
    border-color: var(--color-primary, #007bff);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.search-result-item:focus {
    outline: 2px solid var(--color-primary, #007bff);
    outline-offset: 2px;
}

.search-result__image {
    width: 100%;
    height: 180px;
    border-radius: 6px;
    overflow: hidden;
    background-color: #f5f5f5;
    margin-bottom: 0.75rem;
}

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

.search-result__details {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.search-result__title {
    margin: 0 0 0.25rem 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--color-text-primary, #333);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-result__type {
    margin: 0 0 0.25rem 0;
    font-size: 0.875rem;
    color: var(--color-text-secondary, #666);
}

.search-result__price {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary, #007bff);
}

.search-result__compare-price {
    text-decoration: line-through;
    color: #999;
    margin-left: 0.5rem;
    font-weight: 400;
}

/* Loading State */
.search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--color-text-secondary, #666);
}

.search-loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--color-primary, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.search-loading p {
    margin: 0;
    font-size: 1rem;
}

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

.search-no-results__icon {
    margin-bottom: 1rem;
    color: var(--color-text-secondary, #666);
}

.search-no-results__title {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-primary, #333);
}

.search-no-results__text {
    margin: 0;
    color: var(--color-text-secondary, #666);
}

/* Popular Products Section */
.search-popular {
    margin-top: 1rem;
}

.search-popular__title {
    margin: 0 0 1rem 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-primary, #333);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e1e1e1;
}

.popular-products-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
}

.popular-product-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1rem;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.popular-product-item:hover {
    border-color: var(--color-primary, #007bff);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.popular-product__image {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background-color: #f5f5f5;
    margin-bottom: 0.75rem;
}

.popular-product__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.popular-product__title {
    margin: 0 0 0.25rem 0;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary, #333);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.popular-product__price {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-primary, #007bff);
}

/* Search Suggestions */
.search-suggestions {
    margin-top: 1rem;
}

.search-suggestions__title {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.search-suggestion-item {
    padding: 0.5rem 0.75rem;
    background-color: #f8f9fa;
    border: 1px solid #e1e1e1;
    border-radius: 20px;
    font-size: 0.875rem;
    color: var(--color-text-primary, #333);
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.search-suggestion-item:hover {
    background-color: var(--color-primary, #007bff);
    color: white;
    border-color: var(--color-primary, #007bff);
}

/* Responsive Design */
@media (max-width: 768px) {
    .search-modal__content {
        width: 95%;
        max-height: 90vh;
        border-radius: 8px;
    }

    .search-modal__header,
    .search-modal__input-wrapper {
        padding: 1rem;
    }

    .search-modal__results {
        padding: 0.75rem 1rem 1rem;
    }

    .search-result-item {
        gap: 0.75rem;
        padding: 0.5rem;
    }

    .search-result__image {
        width: 50px;
        height: 50px;
    }

    .search-result__title {
        font-size: 0.9rem;
    }

    .popular-products-list {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }

    .popular-product__image {
        width: 60px;
        height: 60px;
    }

    .popular-product-item {
        padding: 0.75rem;
    }
}

@media (max-width: 480px) {
    .search-modal__content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
    }

    .search-modal--open .search-modal__content {
        transform: none;
    }

    .popular-products-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .search-modal__content {
        border: 2px solid #000;
    }

    .search-result-item,
    .popular-product-item {
        border-width: 2px;
    }

    .search-input {
        border-width: 3px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .search-modal,
    .search-modal__content,
    .search-result-item,
    .popular-product-item,
    .search-loading__spinner {
        transition: none;
        animation: none;
    }
}

/* Focus Visible Support */
.search-toggle-btn:focus-visible,
.search-modal__close:focus-visible,
.search-input-clear:focus-visible,
.search-result-item:focus-visible,
.popular-product-item:focus-visible,
.search-suggestion-item:focus-visible {
    outline: 2px solid var(--color-primary, #007bff);
    outline-offset: 2px;
}

/* Keyboard Navigation Enhancements */
.search-result-item:focus,
.popular-product-item:focus {
    background-color: rgba(0, 123, 255, 0.05);
}

/* Search Input Focus Enhancement */
.search-input:focus + .search-input-clear {
    opacity: 1;
}

/* Empty State for Search Results */
.search-results-list:empty::after {
    content: "";
    display: block;
    min-height: 200px;
}

/* Utility Classes for Show/Hide */
.search-hidden {
    display: none !important;
}

.search-visible-grid {
    display: grid !important;
}

.search-visible-flex {
    display: flex !important;
}

/* Infinite Scroll Loading Indicator */
.search-loading-more {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    color: #666;
    font-size: 0.9rem;
}

.search-loading-more__spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e1e1e1;
    border-top: 2px solid var(--color-primary, #007bff);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

/* Responsive Grid Adjustments */

/* Ultra-wide Desktop (1600px+): 5 columns */
@media (min-width: 1600px) {
    .search-results-list {
        grid-template-columns: repeat(5, 1fr);
        gap: 1.125rem;
    }
}

/* Large Desktop (1200px - 1599px): 4 columns (default) */

/* Medium Desktop/Laptop (1024px - 1199px): 3 columns */
@media (max-width: 1199px) {
    .search-results-list {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.875rem;
    }
}

/* Tablet (768px - 1023px): 2 columns */
@media (max-width: 1023px) {
    .search-results-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .search-result__image {
        height: 160px;
    }

    .search-result-item {
        padding: 0.875rem;
    }
}

/* Mobile Large (480px - 767px): 2 columns with smaller gaps */
@media (max-width: 767px) {
    .search-results-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .search-result__image {
        height: 140px;
    }

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

    .search-result__title {
        font-size: 0.9rem;
        line-height: 1.2;
    }

    .search-result__type {
        font-size: 0.8rem;
    }

    .search-result__price {
        font-size: 0.9rem;
    }
}

/* Mobile Small (up to 479px): 1 column */
@media (max-width: 479px) {
    .search-results-list {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0.5rem;
    }

    .search-result__image {
        height: 180px;
    }

    .search-result-item {
        padding: 1rem;
    }

    .search-result__title {
        font-size: 1rem;
    }

    .search-result__type {
        font-size: 0.875rem;
    }

    .search-result__price {
        font-size: 1rem;
    }
}
