/**
 * Image Search Modal - Intégré dans la searchbar
 * Icône appareil photo AI avec modal de recherche visuelle
 */

/* ============================================
   BOUTON APPAREIL PHOTO DANS LA SEARCHBAR
   ============================================ */
.image-search-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    border-left: 1px solid rgba(184, 70, 31, 0.15);
    margin-left: 4px;
}

.image-search-trigger:hover {
    background: rgba(184, 70, 31, 0.08);
}

.image-search-trigger svg {
    width: 20px;
    height: 20px;
    color: #666;
    transition: all 0.3s ease;
}

.image-search-trigger:hover svg {
    color: #B8461F;
    transform: scale(1.1);
}

/* Badge AI */
.image-search-trigger .ai-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 8px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #B8461F 0%, #ff6b3d 100%);
    padding: 2px 4px;
    border-radius: 4px;
    line-height: 1;
    letter-spacing: 0.5px;
}

/* Tooltip */
.image-search-trigger::after {
    content: 'AI Image Search';
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
}

.image-search-trigger:hover::after {
    opacity: 1;
    visibility: visible;
    bottom: -40px;
}


/* ============================================
   MODAL DE RECHERCHE PAR IMAGE
   ============================================ */
.image-search-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-search-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.image-search-modal {
    background: #fff;
    border-radius: 20px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s ease;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
}

.image-search-modal-overlay.active .image-search-modal {
    transform: scale(1) translateY(0);
}

/* Header du modal */
.image-search-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #f0f0f0;
    background: linear-gradient(135deg, rgba(184, 70, 31, 0.05) 0%, rgba(255, 107, 61, 0.05) 100%);
}

.image-search-modal-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.image-search-modal-title svg {
    width: 28px;
    height: 28px;
    color: #B8461F;
}

.image-search-modal-title h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 0;
}

.image-search-modal-title .ai-tag {
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #B8461F 0%, #ff6b3d 100%);
    padding: 3px 8px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.image-search-modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.image-search-modal-close:hover {
    background: rgba(184, 70, 31, 0.1);
    transform: rotate(90deg);
}

.image-search-modal-close svg {
    width: 20px;
    height: 20px;
    color: #666;
}

/* Body du modal */
.image-search-modal-body {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(90vh - 80px);
}

/* Zone d'upload */
.image-search-upload-zone {
    border: 2px dashed rgba(184, 70, 31, 0.3);
    border-radius: 16px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(184, 70, 31, 0.02);
}

.image-search-upload-zone:hover,
.image-search-upload-zone.dragover {
    border-color: #B8461F;
    background: rgba(184, 70, 31, 0.08);
    transform: scale(1.01);
}

.image-search-upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, rgba(184, 70, 31, 0.1) 0%, rgba(255, 107, 61, 0.1) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-search-upload-icon svg {
    width: 32px;
    height: 32px;
    color: #B8461F;
}

.image-search-upload-zone h4 {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0 0 8px;
}

.image-search-upload-zone p {
    font-size: 14px;
    color: #666;
    margin: 0 0 16px;
}

.image-search-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #B8461F 0%, #9b3a1d 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-search-upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(184, 70, 31, 0.4);
}

/* Preview de l'image */
.image-search-preview {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.image-search-preview.active {
    display: flex;
}

.image-search-preview-container {
    position: relative;
    max-width: 280px;
    width: 100%;
}

.image-search-preview-img {
    width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: 12px;
    border: 2px solid rgba(184, 70, 31, 0.2);
}

.image-search-preview-remove {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 32px;
    height: 32px;
    background: #ff4444;
    border: 3px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(255, 68, 68, 0.4);
}

.image-search-preview-remove:hover {
    transform: scale(1.1);
    background: #ff2222;
}

.image-search-preview-remove svg {
    width: 16px;
    height: 16px;
    color: #fff;
}

.image-search-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 32px;
    background: linear-gradient(135deg, #B8461F 0%, #9b3a1d 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-search-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(184, 70, 31, 0.5);
}

.image-search-action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.image-search-action-btn svg {
    width: 20px;
    height: 20px;
}

/* Loading */
.image-search-loading {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px 20px;
}

.image-search-loading.active {
    display: flex;
}

.image-search-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(184, 70, 31, 0.2);
    border-top-color: #B8461F;
    border-radius: 50%;
    animation: imageSearchSpin 1s linear infinite;
}

@keyframes imageSearchSpin {
    to { transform: rotate(360deg); }
}

.image-search-loading p {
    font-size: 14px;
    color: #666;
}

/* Résultats */
.image-search-results {
    display: none;
}

.image-search-results.active {
    display: block;
}

.image-search-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.image-search-results-header h4 {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

.image-search-results-count {
    font-size: 13px;
    color: #666;
    background: rgba(184, 70, 31, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
}

.image-search-results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.image-search-result-card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.image-search-result-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
    border-color: rgba(184, 70, 31, 0.3);
}

.image-search-result-similarity {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    z-index: 2;
}

.image-search-result-similarity.high {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: #fff;
}

.image-search-result-similarity.medium {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: #fff;
}

.image-search-result-img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #f5f5f5;
}

.image-search-result-info {
    padding: 12px;
}

.image-search-result-title {
    font-size: 13px;
    font-weight: 500;
    color: #1a1a1a;
    margin: 0 0 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.image-search-result-price {
    font-size: 15px;
    font-weight: 700;
    color: #B8461F;
}

/* No results */
.image-search-no-results {
    display: none;
    text-align: center;
    padding: 40px 20px;
}

.image-search-no-results.active {
    display: block;
}

.image-search-no-results-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.image-search-no-results h4 {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0 0 8px;
}

.image-search-no-results p {
    font-size: 14px;
    color: #666;
    margin: 0;
}

/* Bouton nouvelle recherche */
.image-search-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    color: #B8461F;
    border: 2px solid #B8461F;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 20px;
}

.image-search-new-btn:hover {
    background: #B8461F;
    color: #fff;
}

/* ============================================
   RESPONSIVE - MOBILE BOTTOM SHEET
   ============================================ */
@media (max-width: 768px) {
    .image-search-modal-overlay {
        align-items: flex-end;
        padding: 0;
    }
    
    .image-search-modal {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 20px 20px 0 0;
        margin-top: auto;
        transform: translateY(100%);
    }
    
    .image-search-modal-overlay.active .image-search-modal {
        transform: translateY(0);
    }
    
    /* Handle bar pour indiquer le swipe */
    .image-search-modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: rgba(0, 0, 0, 0.15);
        border-radius: 4px;
    }
    
    .image-search-modal-header {
        position: relative;
        padding-top: 24px;
    }
    
    .image-search-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .image-search-result-img {
        height: 120px;
    }
    
    .image-search-trigger {
        padding: 6px 10px;
    }
    
    .image-search-trigger svg {
        width: 18px;
        height: 18px;
    }
    
    .image-search-trigger .ai-badge {
        font-size: 7px;
        padding: 1px 3px;
        top: 0;
        right: 2px;
    }
    
    .image-search-trigger::after {
        display: none;
    }
    
    .image-search-upload-zone {
        padding: 30px 15px;
    }
    
    .image-search-upload-icon {
        width: 56px;
        height: 56px;
    }
    
    .image-search-upload-icon svg {
        width: 28px;
        height: 28px;
    }
    
    .image-search-upload-zone h4 {
        font-size: 15px;
    }
    
    .image-search-upload-btn {
        padding: 10px 20px;
        font-size: 13px;
    }
    
    .image-search-action-btn {
        padding: 12px 24px;
        font-size: 14px;
        width: 100%;
        justify-content: center;
    }
    
    .image-search-preview-container {
        max-width: 220px;
    }
    
    .image-search-preview-img {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .image-search-modal-body {
        padding: 16px;
        max-height: calc(90vh - 70px);
    }
    
    .image-search-modal-header {
        padding: 20px 16px 16px;
    }
    
    .image-search-modal-title h3 {
        font-size: 16px;
    }
    
    .image-search-result-info {
        padding: 10px;
    }
    
    .image-search-result-title {
        font-size: 12px;
    }
    
    .image-search-result-price {
        font-size: 14px;
    }
    
    .image-search-result-similarity {
        font-size: 10px;
        padding: 3px 8px;
    }
}
