/**
 * Styles pour SearchOverlay - Mapster
 * Interface de recherche hybride cohérente avec l'architecture mobile existante
 * S'intègre harmonieusement avec mobile-ux.css
 */

/* ========================================
   BARRE DE RECHERCHE MOBILE STICKY
   ======================================== */

.search-mobile-bar-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 950; /* Sous le FAB mais au-dessus de la carte */
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) 16px;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.85) 100%);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Masquer par défaut, visible uniquement sur mobile via media query */
    display: none;
}

.search-mobile-bar-container.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* 📱 Mode expanded : la barre devient plein écran avec résultats */
.search-mobile-bar-container.expanded {
    top: 0;
    bottom: 0;
    padding-top: max(12px, env(safe-area-inset-top));
    background: #ffffff;
    backdrop-filter: none;
    border-top: none;
    display: flex;
    flex-direction: column;
    z-index: 1200;
    overflow: hidden;
}

.search-mobile-bar-container.expanded .search-mobile-bar {
    flex-shrink: 0;
}

.search-mobile-bar-close {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gris-600, #4b5563);
}

.search-mobile-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0;
}

/* Réutiliser les styles de résultats existants dans le conteneur mobile */
.search-mobile-results .search-result-item,
.search-mobile-results .search-placeholder,
.search-mobile-results .search-no-results,
.search-mobile-results .search-error,
.search-mobile-results .search-loading {
    padding: 12px 16px;
}

.search-mobile-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--couleur-blanche, #ffffff);
    border: 2px solid var(--gris-300, #d1d5db);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    /* Zone tactile optimisée */
    min-height: 48px;
}

.search-mobile-bar:focus-within {
    border-color: #8b5cf6;
    box-shadow: 0 4px 25px rgba(139, 92, 246, 0.15);
}

.search-mobile-bar-icon {
    font-size: 18px;
    color: var(--gris-500, #6b7280);
    flex-shrink: 0;
}

.search-mobile-bar-input {
    flex: 1;
    font-size: 16px; /* >= 16px pour éviter le zoom iOS */
    color: var(--gris-900, #111827);
    line-height: 1.4;
    border: none;
    outline: none;
    background: transparent;
    padding: 0;
    min-width: 0;
}

.search-mobile-bar-input::placeholder {
    color: var(--gris-500, #6b7280);
}

/* Animation d'apparition progressive */
.search-mobile-bar-container {
    animation-delay: 0.3s;
}

/* ========================================
   OVERLAY DE RECHERCHE
   ======================================== */

.search-overlay-container {
    /* Même pattern que mobile-place-details-container */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1100; /* Au-dessus des détails de lieu (999) */
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.search-overlay-container.active {
    opacity: 1;
    visibility: visible;
    pointer-events: none; /* L'overlay n'intercepte jamais les événements */
}

/* Seuls le backdrop et le panel peuvent capturer les événements */
.search-overlay-backdrop,
.search-overlay-panel {
    pointer-events: auto;
}

.search-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6); /* Légèrement plus foncé que les détails de lieu */
    backdrop-filter: blur(3px);
    transition: opacity 0.3s ease;
}

/* Sur mobile, backdrop blanc plein écran quand actif */
@media (max-width: 768px) {
    .search-overlay-container.active .search-overlay-backdrop {
        background: var(--couleur-blanche, #ffffff);
        backdrop-filter: none;
    }
}

.search-overlay-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 75vh; /* Plus petit que les détails de lieu pour différencier */
    background: var(--couleur-blanche, #ffffff);
    border-radius: 20px 20px 0 0; /* Légèrement plus arrondi */
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.2);
    /* Optimisations tactiles */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    will-change: transform;
    overscroll-behavior: contain;
}

/* Sur mobile : panneau plein écran avec input en haut */
@media (max-width: 768px) {
    .search-overlay-container.active .search-overlay-panel {
        top: 0;
        bottom: 0;
        max-height: 100vh;
        border-radius: 0;
        box-shadow: none;
        transform: translateY(0);
    }
}

.search-overlay-container.active .search-overlay-panel {
    transform: translateY(0);
}

.search-overlay-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    position: relative;
    overflow: hidden; /* Empêcher tout débordement */
}

/* Indicateur de swipe pour fermer */
.search-overlay-panel::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--gris-400, #9ca3af);
    border-radius: 2px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    z-index: 1;
}

.search-overlay-panel:active::before {
    opacity: 1;
}

/* ========================================
   HEADER DE RECHERCHE
   ======================================== */

.search-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px 16px 16px;
    border-bottom: 1px solid var(--gris-200, #e5e7eb);
    position: relative;
}

/* Sur mobile : header sticky en haut avec safe area */
@media (max-width: 768px) {
    .search-overlay-header {
        padding-top: max(20px, env(safe-area-inset-top) + 12px);
        position: sticky;
        top: 0;
        background: var(--couleur-blanche, #ffffff);
        z-index: 10;
    }
}

.search-overlay-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--gris-900, #111827);
    margin: 0;
}

.search-overlay-close {
    /* Même style que mobile-place-details-close */
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--gris-700, #374151);
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    /* Zone tactile optimisée */
    min-width: 44px;
    min-height: 44px;
}

.search-overlay-close:hover,
.search-overlay-close:focus {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-overlay-close:active {
    transform: scale(0.95);
}

/* ========================================
   INPUT DE RECHERCHE
   ======================================== */

.search-overlay-panel .search-input-container {
    position: relative;
    padding: 0 16px 16px 16px;
    border-bottom: 1px solid var(--gris-200, #e5e7eb);
}

/* Sur mobile : input container sticky en haut */
@media (max-width: 768px) {
    .search-overlay-panel .search-input-container {
        position: sticky;
        top: 0;
        background: var(--couleur-blanche, #ffffff);
        z-index: 10;
        padding-top: 16px;
    }
}

.search-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border: 2px solid var(--gris-300, #d1d5db);
    border-radius: 12px;
    font-size: 16px;
    color: var(--gris-900, #111827);
    background: var(--couleur-blanche, #ffffff);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.search-input:focus {
    outline: none;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.search-input::placeholder {
    color: var(--gris-500, #6b7280);
}

.search-input-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--gris-400, #9ca3af);
    pointer-events: none;
}

/* Sur desktop : centrer par rapport à l'input */
@media (min-width: 769px) {
    .search-input-icon {
        /* Calculer la position en tenant compte du padding-bottom du container */
        top: calc(50% - 8px); /* 16px de padding-bottom / 2 */
    }
}

/* Sur mobile : centrer par rapport à l'input */
@media (max-width: 768px) {
    .search-input-icon {
        top: 50%;
    }
}

/* ========================================
   INDICATEUR DE CHARGEMENT
   ======================================== */

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px 16px;
    font-size: 14px;
    color: var(--gris-600, #4b5563);
    background: rgba(139, 92, 246, 0.05);
    border-bottom: 1px solid var(--gris-200, #e5e7eb);
}

.search-loading.hidden {
    display: none;
}

.search-loading .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ========================================
   RÉSULTATS DE RECHERCHE
   ======================================== */

.search-results {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-height: 200px;
    max-height: 100%; /* S'assurer que les résultats ne dépassent jamais */
}

.search-results.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* Item de résultat */
.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border: 1px solid var(--gris-200, #e5e7eb);
    border-radius: 12px;
    margin-bottom: 8px;
    background: var(--couleur-blanche, #ffffff);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.search-result-item:hover {
    border-color: #8b5cf6;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.15);
    transform: translateY(-1px);
}

.search-result-item:focus {
    outline: 2px solid rgba(139, 92, 246, 0.5);
    outline-offset: 2px;
}

.search-result-item:last-child {
    margin-bottom: 0;
}

.search-result-content {
    flex: 1;
    min-width: 0; /* Pour permettre la truncature */
}

.search-result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.search-result-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--gris-900, #111827);
    line-height: 1.3;
    /* Truncature pour les noms longs */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.search-result-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    flex-shrink: 0;
}

.search-result-badge-user {
    background: rgba(59, 130, 246, 0.1);
    color: #1d4ed8;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.search-result-badge-google {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.search-result-badge-icon {
    font-size: 10px;
}

.search-result-address {
    font-size: 14px;
    color: var(--gris-600, #4b5563);
    line-height: 1.4;
    margin-bottom: 4px;
    /* Truncature sur 2 lignes max */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-result-rating {
    font-size: 12px;
    color: var(--gris-600, #4b5563);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Bouton d'action */
.search-result-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
    flex-shrink: 0;
}

.search-result-btn-view {
    background: rgba(59, 130, 246, 0.1);
    color: #1d4ed8;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.search-result-btn-view:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
}

.search-result-btn-select {
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.search-result-btn-select:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: rgba(139, 92, 246, 0.5);
}

/* ========================================
   ÉTATS SPÉCIAUX
   ======================================== */

/* Placeholder initial */
.search-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--gris-500, #6b7280);
}

.search-placeholder-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.search-placeholder-text {
    font-size: 16px;
    line-height: 1.5;
}

/* Aucun résultat */
.search-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--gris-600, #4b5563);
}

.search-no-results-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.search-no-results-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--gris-700, #374151);
}

.search-no-results-hint {
    font-size: 14px;
    color: var(--gris-500, #6b7280);
}

/* Erreur */
.search-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: #dc2626;
    background: rgba(220, 38, 38, 0.05);
    border-radius: 12px;
    margin: 16px;
}

.search-error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.8;
}

.search-error-text {
    font-size: 16px;
    line-height: 1.5;
}

/* ========================================
   RESPONSIVE - DESKTOP
   ======================================== */

@media (min-width: 769px) {
    /* Sur desktop, centrer l'overlay et limiter sa largeur */
    .search-overlay-panel {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) translateY(100%);
        width: 90vw;
        max-width: 500px;
        max-height: 600px;
        height: auto; /* Hauteur automatique basée sur le contenu */
        border-radius: 16px;
        bottom: auto;
        overflow: hidden; /* Empêcher tout débordement du panel */
    }
    
    /* S'assurer que le contenu respecte la hauteur du panel */
    .search-overlay-content {
        max-height: 600px;
    }
    
    /* Limiter la hauteur des résultats pour éviter le dépassement */
    .search-results {
        max-height: calc(600px - 120px); /* 600px panel - header et input approximatifs */
    }
    
    .search-overlay-container.active .search-overlay-panel {
        transform: translate(-50%, -50%);
    }
    
    .search-overlay-panel::before {
        display: none; /* Pas d'indicateur de swipe sur desktop */
    }
    
    /* Masquer la barre mobile sur desktop */
    .search-mobile-bar-container {
        display: none !important;
    }
}

/* ========================================
   RESPONSIVE - MOBILE (768px et moins)
   ======================================== */

@media (max-width: 768px) {
    /* Afficher la barre mobile */
    .search-mobile-bar-container {
        display: block;
    }
    
    /* En mode expanded, flex pour le layout plein écran */
    .search-mobile-bar-container.expanded {
        display: flex;
    }
}

/* ========================================
   RESPONSIVE - TRÈS PETIT ÉCRAN
   ======================================== */

@media (max-width: 480px) {
    .search-overlay-panel {
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
    }
    
    /* Ajustements pour la barre mobile sur très petits écrans */
    .search-mobile-bar-container {
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom)) 12px;
    }
    
    .search-mobile-bar {
        padding: 12px 14px;
        min-height: 44px;
    }
    
    .search-mobile-bar-icon {
        font-size: 16px;
    }
    
    .search-mobile-bar-placeholder,
    .search-mobile-bar-input {
        font-size: 16px;
    }
    
    .search-result-item {
        padding: 12px;
        gap: 8px;
    }
    
    .search-result-name {
        font-size: 15px;
    }
    
    .search-result-address {
        font-size: 13px;
    }
    
    .search-result-btn {
        padding: 6px 12px;
        font-size: 13px;
        min-width: 70px;
    }
}

/* ========================================
   ACCESSIBILITÉ ET PRÉFÉRENCES UTILISATEUR
   ======================================== */

/* Mode mouvement réduit */
@media (prefers-reduced-motion: reduce) {
    .search-overlay-container,
    .search-overlay-panel,
    .search-overlay-backdrop,
    .search-result-item {
        transition: none;
    }
    
    .search-loading .spinner {
        animation: none;
    }
}

/* Mode contraste élevé */
@media (prefers-contrast: high) {
    .search-overlay-panel {
        border: 2px solid var(--gris-900, #111827);
    }
    
    .search-overlay-close {
        border: 1px solid var(--gris-500, #6b7280);
    }
    
    .search-input {
        border-width: 2px;
    }
    
    .search-result-item {
        border-width: 2px;
    }
}

/* Mode sombre (si implémenté dans le futur) */
@media (prefers-color-scheme: dark) {
    .search-overlay-panel {
        background: var(--gris-900, #111827);
        color: var(--gris-100, #f3f4f6);
    }
    
    .search-overlay-title {
        color: var(--gris-100, #f3f4f6);
    }
    
    .search-input {
        background: var(--gris-800, #1f2937);
        border-color: var(--gris-600, #4b5563);
        color: var(--gris-100, #f3f4f6);
    }
    
    .search-result-item {
        background: var(--gris-800, #1f2937);
        border-color: var(--gris-600, #4b5563);
    }
    
    .search-result-name {
        color: var(--gris-100, #f3f4f6);
    }
}


/* ========================================
   ANIMATIONS D'ENTRÉE ET SORTIE
   ======================================== */
