/**
 * Product Search Styles
 * Maison de l'Énergie
 */

/* ============================================
   SEARCH ICON IN HEADER (next to language buttons)
   ============================================ */

.search-icon-header {
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 50%;
    transition: all 0.3s ease;
    color: #fff;
    background: var(--primary);
    border: 2px solid var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
}

.search-icon-header svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.search-icon-header:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: scale(1.1);
}

.search-icon-header:active {
    transform: scale(0.95);
}

/* Legacy support for old navigation icon (if still present) */
.search-icon-wrapper {
    display: inline-flex;
    align-items: center;
}

#search-icon:not(.search-icon-header) {
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.3s ease;
    color: var(--text-dark);
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#search-icon:not(.search-icon-header) svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

#search-icon:not(.search-icon-header):hover {
    background-color: var(--primary);
    color: var(--white);
    transform: scale(1.1);
}

#search-icon:not(.search-icon-header):active {
    transform: scale(0.95);
}

/* ============================================
   SEARCH OVERLAY (BACKDROP)
   ============================================ */

#search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 100px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#search-overlay.active {
    display: flex;
    opacity: 1;
}

/* ============================================
   SEARCH MODAL
   ============================================ */

.search-modal {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: slideDown 0.3s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   SEARCH HEADER
   ============================================ */

.search-header {
    padding: 20px 24px;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.search-header-icon {
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-header-icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

.search-input-wrapper {
    flex: 1;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: all 0.3s ease;
}

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

#search-input::placeholder {
    color: #999;
}

#search-close {
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
    transition: all 0.2s ease;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#search-close svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

#search-close:hover {
    background: #f5f5f5;
    color: #333;
    transform: rotate(90deg);
}

/* ============================================
   SEARCH RESULTS CONTAINER
   ============================================ */

#search-results {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 200px;
}

/* Custom scrollbar */
#search-results::-webkit-scrollbar {
    width: 8px;
}

#search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#search-results::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

#search-results::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* ============================================
   SEARCH MESSAGES
   ============================================ */

.search-message {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    font-size: 1rem;
}

.search-results-count {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e0e0e0;
}

/* ============================================
   SEARCH RESULT ITEMS
   ============================================ */

.search-results-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: white;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
}

.search-result-item:hover {
    background: #f8f9fa;
    border-color: var(--primary);
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.1);
}

.search-result-image {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: white;
    border: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-result-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-dark);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search-result-category {
    font-size: 0.85rem;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

/* Highlight matched text */
.search-result-name mark {
    background-color: #fff3cd;
    color: inherit;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */

@media (max-width: 768px) {
    #search-overlay {
        padding-top: 20px;
        align-items: stretch;
    }

    .search-modal {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        margin: 0;
    }

    .search-header {
        padding: 16px;
    }

    #search-input {
        font-size: 16px;
        /* Prevent zoom on iOS */
    }

    #search-results {
        padding: 16px;
    }

    .search-result-item {
        gap: 12px;
        padding: 10px;
    }

    .search-result-image {
        width: 60px;
        height: 60px;
    }

    .search-result-name {
        font-size: 0.95rem;
    }

    .search-result-category {
        font-size: 0.8rem;
    }

    /* Search icon in header on mobile */
    .search-icon-header {
        padding: 6px 10px;
        margin-left: 5px;
    }

    .search-icon-header svg {
        width: 18px;
        height: 18px;
    }

    /* Make search icon more prominent on mobile */
    #search-icon {
        padding: 10px;
    }

    #search-icon svg {
        width: 22px;
        height: 22px;
    }
}

/* ============================================
   RTL SUPPORT (ARABIC)
   ============================================ */

body.lang-ar .search-header {
    flex-direction: row-reverse;
}

body.lang-ar .search-result-item {
    flex-direction: row-reverse;
}

body.lang-ar .search-result-item:hover {
    transform: translateX(-4px);
}

body.lang-ar #search-input {
    text-align: right;
}

body.lang-ar .search-result-info {
    text-align: right;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

#search-input:focus-visible,
#search-close:focus-visible,
.search-result-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Ensure keyboard navigation is visible */
.search-result-item:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
}

/* Loading state (optional, for future enhancement) */
.search-loading {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.search-loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60%,
    100% {
        content: '...';
    }
}