/* ===== SISTEMA DE BUSCA UNIFICADA - CONECTA ASSAÍ ===== */

/* Regra global para garantir que o dropdown sempre apareça acima de outros elementos, mas não do header */
.search-dropdown {
    position: absolute !important;
    z-index: 150 !important; /* Acima do header (100) mas abaixo de modais e notificações */
    transform: translateZ(0) !important;
    isolation: isolate !important;
}

/* Estilos base para containers de busca */
.search-container,
#search-bar {
    position: relative;
    max-width: 600px;
    width: 100%;
    z-index: 10 !important; /* Z-index baixo para o container não sobrepor navbar */
    /* Forçar novo contexto de empilhamento */
    transform: translateZ(0);
    isolation: isolate;
    will-change: transform;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    z-index: 10 !important; /* Z-index baixo para o search-box não sobrepor navbar */
    transform: translateZ(0);
}

/* Input de busca */
.search-input {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px 0 0 8px;
    font-size: 16px;
    outline: none;
    background: white;
    transition: box-shadow 0.2s ease;
}

.search-input:focus {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Botão de busca */
.search-button {
    padding: 12px 20px;
    background: #007bff;
    border: none;
    border-radius: 0 8px 8px 0;
    color: white;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s ease;
}

.search-button:hover {
    background: #0056b3;
}

/* Loading indicator */
.search-loading {
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    display: none;
}

/* Dropdown de resultados */
.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e1e5e9;
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 150 !important; /* Acima do header (1000) mas abaixo de notificações */
    max-height: 400px;
    overflow-y: auto;
    display: none;
    /* Forçar contexto de empilhamento próprio */
    transform: translateZ(0);
    will-change: transform;
}

.search-dropdown.show {
    display: block !important;
}

/* Resultados */
.search-results {
    padding: 8px 0;
}

.search-group {
    margin-bottom: 12px;
}

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

.search-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
}

.search-group-count {
    background: #dee2e6;
    color: #495057;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 10px;
}

/* Item de resultado */
.search-result-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f1f3f4;
    transition: background-color 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.search-result-item:hover,
.search-result-item.selected {
    background-color: #f8f9fa;
    text-decoration: none;
    color: inherit;
}

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

.search-result-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #e3f2fd;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    font-size: 14px;
    color: #1976d2;
}

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

.search-result-title {
    font-weight: 500;
    color: #212529;
    margin-bottom: 4px;
    line-height: 1.3;
}

.search-result-title mark {
    background: #fff3cd;
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 600;
}

.search-result-description {
    font-size: 13px;
    color: #6c757d;
    line-height: 1.4;
    margin-bottom: 4px;
}

.search-result-description mark {
    background: #fff3cd;
    padding: 1px 2px;
    border-radius: 2px;
}

.search-result-metadata {
    font-size: 11px;
    color: #868e96;
    line-height: 1.3;
}

.search-result-type {
    margin-left: 12px;
    flex-shrink: 0;
}

/* Badges de tipo */
.search-type-badge {
    font-size: 10px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.search-type-servico {
    background: #e3f2fd;
    color: #1976d2;
}

.search-type-categoria {
    background: #f3e5f5;
    color: #7b1fa2;
}

.search-type-grupo {
    background: #e8f5e8;
    color: #388e3c;
}

.search-type-evento {
    background: #fff3e0;
    color: #f57c00;
}

.search-type-perfil {
    background: #fce4ec;
    color: #c2185b;
}

.search-type-formulario {
    background: #e0f2f1;
    color: #00796b;
}

.search-type-edital {
    background: #f1f8e9;
    color: #689f38;
}

/* Estados especiais */
.search-no-results {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.search-no-results i {
    font-size: 24px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.search-no-results p {
    margin-bottom: 4px;
    font-size: 14px;
}

.search-no-results small {
    font-size: 12px;
    opacity: 0.7;
}

.search-error {
    text-align: center;
    padding: 20px;
    color: #dc3545;
}

.search-error i {
    font-size: 20px;
    margin-bottom: 8px;
}

.search-show-more {
    padding: 12px 16px;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    text-align: center;
}

.search-show-more p {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 8px;
}

.search-show-all-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-show-all-btn:hover {
    background: #0056b3;
}

/* Responsividade */
@media (max-width: 768px) {
    .search-input {
        font-size: 16px; /* Previne zoom no iOS */
        padding: 14px 16px;
    }

    .search-button {
        padding: 14px 18px;
        font-size: 16px;
    }

    .search-dropdown {
        max-height: 300px;
    }

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

    .search-result-icon {
        width: 28px;
        height: 28px;
        margin-right: 10px;
    }

    .search-result-title {
        font-size: 14px;
    }

    .search-result-description {
        font-size: 12px;
    }
}

/* Hero section específico */
.hero-section .search-container {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}

.hero-section .search-input {
    flex: 1;
    padding: 16px 20px;
    border: none;
    border-radius: 8px 0 0 8px;
    font-size: 18px;
    outline: none;
    background: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.hero-section .search-button {
    padding: 16px 24px;
    background: #0984e3;
    border: none;
    border-radius: 0 8px 8px 0;
    color: white;
    cursor: pointer;
    font-size: 18px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: background 0.3s ease;
}

.hero-section .search-button:hover {
    background: #0056b3;
}

/* Scrollbar personalizada para dropdown */
.search-dropdown::-webkit-scrollbar {
    width: 6px;
}

.search-dropdown::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.search-dropdown::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.search-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animações */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-dropdown.show {
    animation: fadeIn 0.2s ease-out;
}

/* High contrast mode support - Commented out due to browser compatibility */
/*
@media (prefers-contrast: high) {
    .search-dropdown {
        border: 2px solid #000;
    }

    .search-result-item:hover {
        background-color: #000;
        color: #fff;
    }
}
*/

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .search-dropdown,
    .search-result-item,
    .search-button {
        transition: none;
    }

    .search-dropdown.show {
        animation: none;
    }
}

/* ===== ESTILOS ESPECÍFICOS PARA PÁGINA INICIAL ===== */
.hero-section .search-container {
    max-width: 600px;
    width: 90%;
    margin: 0 auto;
}

.hero-section .search-box {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
}

.hero-section .search-input {
    padding: 15px 20px;
    font-size: 16px;
    border-radius: 8px 0 0 8px;
    width: calc(100% - 60px);
}

.hero-section .search-button {
    padding: 15px 20px;
    font-size: 16px;
    border-radius: 0 8px 8px 0;
    width: 60px;
}

/* Correção para mobile na página inicial */
@media (max-width: 768px) {
    .hero-section .search-container {
        width: 95%;
        max-width: none;
    }

    .hero-section .search-input {
        padding: 14px 18px;
        font-size: 16px;
    }

    .hero-section .search-button {
        padding: 14px 18px;
        font-size: 16px;
    }
}

/* ===== REGRAS DE Z-INDEX CONTROLADAS ===== */
/* Hierarquia: Navbar (1000) > Dropdown de busca (150) > Conteúdo (10) */
.search-container,
#search-bar,
.search-box {
    z-index: 10 !important;
}

/* Dropdown aparece acima do conteúdo mas abaixo da navbar */
.search-dropdown {
    z-index: 150 !important;
}

/* Garantir posicionamento correto do dropdown */
.search-dropdown.show {
    z-index: 150 !important;
    position: absolute !important;
    top: 100% !important;
}

/* Casos específicos mantêm a mesma hierarquia */
body .search-dropdown,
html .search-dropdown,
.modal .search-dropdown,
.overlay .search-dropdown {
    z-index: 150 !important;
    position: absolute !important;
}
