/**
 * Popup de Resultados de Busca - Design Moderno e Minimalista
 * Sobreposição elegante sobre toda a página
 */

/* ==================== ESCONDER DROPDOWNS ANTIGOS ==================== */
#desktop-search-results,
#mobile-search-results,
#main-search-results {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ==================== GARANTIR QUE POPUP ESTEJA ACIMA DE TUDO ==================== */
/* Força o popup a estar acima de qualquer elemento, incluindo header e menu de categorias */
#search-popup-overlay,
.search-popup-overlay {
    z-index: 9999999 !important; /* Z-index máximo */
    position: fixed !important;
}

#search-popup-container,
.search-popup-container {
    z-index: 10000000 !important; /* Z-index máximo absoluto */
    position: fixed !important;
}

/* Garantir que menu de categorias fique abaixo do popup */
.category-nav,
#site-header .category-nav,
header .category-nav,
nav.category-nav {
    z-index: 998 !important;
    position: relative !important;
    isolation: isolate !important; /* Criar novo contexto de empilhamento */
}

/* Garantir que header não interfira e não crie contexto que capture o popup */
#site-header {
    z-index: 1000 !important;
    position: relative !important;
    isolation: isolate !important; /* Criar contexto isolado */
}

/* EXCEÇÃO CRÍTICA: Popup deve estar FORA de qualquer contexto de empilhamento */
#search-popup-overlay,
.search-popup-overlay {
    isolation: auto !important;
    z-index: 9999999 !important;
}

#search-popup-container,
.search-popup-container {
    isolation: auto !important;
    z-index: 10000000 !important;
}

/* ==================== OVERLAY ==================== */
.search-popup-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(4px) !important;
    z-index: 9999999 !important; /* Z-index MÁXIMO - acima de TUDO */
    opacity: 0;
    visibility: hidden;
    pointer-events: none !important; /* Não bloquear cliques quando oculto */
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.search-popup-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto !important; /* Bloquear cliques apenas quando visível */
}

/* ==================== POPUP CONTAINER ==================== */
.search-popup-container {
    position: fixed !important;
    top: 45% !important; /* Ajustado para começar um pouco mais abaixo */
    left: 50% !important;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 650px; /* Reduzido um pouco */
    max-height: 75vh; /* Reduzido para evitar conflito */
    background: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0 !important; /* Design flat */
    box-shadow: none !important; /* Design flat */
    z-index: 10000000 !important; /* Z-index MÁXIMO ABSOLUTO - acima do overlay e TUDO */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.3s ease;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    margin-top: 80px !important; /* Espaçamento adicional do topo */
}

/* Container do popup - não bloquear quando oculto */
.search-popup-container:not(.show) {
    pointer-events: none !important;
}

.search-popup-container.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto !important; /* Permitir cliques quando visível */
}

/* Garantir que elementos dentro do popup sejam clicáveis quando visível */
.search-popup-container.show * {
    pointer-events: auto !important;
}

/* Header do Popup */
.search-popup-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f9fafb;
    flex-shrink: 0;
}

.search-popup-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-popup-title svg {
    width: 1.25rem;
    height: 1.25rem;
    color: #2563eb;
}

.search-popup-close {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
    padding: 0;
}

.search-popup-close:hover {
    background: #e5e7eb;
    color: #111827;
}

.search-popup-close svg {
    width: 20px;
    height: 20px;
}

/* Corpo do Popup */
.search-popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    max-height: calc(85vh - 140px);
}

.search-popup-body::-webkit-scrollbar {
    width: 8px;
}

.search-popup-body::-webkit-scrollbar-track {
    background: #f3f4f6;
}

.search-popup-body::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.search-popup-body::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Loading */
.search-popup-loading {
    padding: 3rem 2rem;
    text-align: center;
    color: #6b7280;
}

.search-popup-loading svg {
    width: 2rem;
    height: 2rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Lista de Resultados */
.search-popup-results {
    list-style: none;
    margin: 0;
    padding: 0;
}

.search-popup-item {
    border-bottom: 1px solid #f3f4f6;
    transition: background-color 0.15s ease;
}

.search-popup-item:last-child {
    border-bottom: none;
}

.search-popup-item:hover {
    background-color: #f9fafb;
}

.search-popup-item-link {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: inherit;
}

.search-popup-item-image {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    border: 1px solid #e5e7eb;
}

.search-popup-item-content {
    flex: 1;
    min-width: 0;
}

.search-popup-item-title {
    font-size: 0.9375rem;
    font-weight: 500;
    color: #111827;
    margin: 0 0 0.25rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-popup-item-title mark {
    background: #fef3c7;
    color: #92400e;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 600;
}

.search-popup-item-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #fef3c7;
    color: #92400e;
}

.search-popup-item-price {
    font-size: 1rem;
    font-weight: 700;
    color: #2563eb;
    margin: 0.25rem 0 0 0;
}

/* Estado vazio */
.search-popup-empty {
    padding: 3rem 2rem;
    text-align: center;
    color: #6b7280;
}

.search-popup-empty svg {
    width: 3rem;
    height: 3rem;
    margin: 0 auto 1rem;
    color: #d1d5db;
}

.search-popup-empty-title {
    font-size: 1rem;
    font-weight: 500;
    color: #111827;
    margin: 0 0 0.5rem 0;
}

.search-popup-empty-text {
    font-size: 0.875rem;
    color: #6b7280;
    margin: 0;
}

/* Footer do Popup */
.search-popup-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}

.search-popup-footer-link {
    display: block;
    text-align: center;
    padding: 0.75rem 1rem;
    background: #2563eb;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color 0.2s ease;
}

.search-popup-footer-link:hover {
    background: #1d4ed8;
}

/* Badge de sugestão */
.search-popup-suggestion-badge {
    padding: 0.75rem 1.5rem;
    background: #dbeafe;
    border-bottom: 1px solid #bfdbfe;
    font-size: 0.875rem;
    color: #1e40af;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Dica de busca */
.search-popup-tip {
    padding: 0.75rem 1.5rem;
    background: #fef3c7;
    border-top: 1px solid #fde68a;
    font-size: 0.8125rem;
    color: #92400e;
}

.search-popup-tip strong {
    font-weight: 600;
}

/* ==================== RESPONSIVIDADE ==================== */
@media (max-width: 768px) {
    .search-popup-container {
        width: 95%;
        max-height: 90vh;
        border-radius: 12px;
    }
    
    .search-popup-header {
        padding: 1rem 1.25rem;
    }
    
    .search-popup-title {
        font-size: 1rem;
    }
    
    .search-popup-item-link {
        padding: 0.875rem 1.25rem;
    }
    
    .search-popup-item-image {
        width: 56px;
        height: 56px;
    }
    
    .search-popup-footer {
        padding: 0.875rem 1.25rem;
    }
}

@media (max-width: 480px) {
    .search-popup-container {
        width: 100%;
        max-height: 100vh;
        border-radius: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: translate(0, 0) scale(1);
    }
    
    .search-popup-container.show {
        transform: translate(0, 0) scale(1);
    }
    
    .search-popup-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}

/* ==================== ANIMAÇÕES ==================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate(-50%, -40%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Indicador de qualidade */
.search-quality-indicator {
    display: inline-block;
    font-size: 0.875rem;
    margin-left: 0.25rem;
}

