/**
 * Busca IA - Estilos para campo de busca com inteligencia artificial
 */

/* Container principal da busca IA */
.busca-ia-container {
    position: relative;
    margin-bottom: 0;
    overflow: visible;
}

/* Garantir que o card pai permite overflow para o dropdown */
.busca-ia-container .card-body,
.card:has(.busca-ia-container) {
    overflow: visible !important;
}

/* Criar contexto de empilhamento para o card de busca */
.card:has(.busca-ia-container) {
    position: relative;
    z-index: 10;
}

/* Quando as sugestoes estao abertas, elevar o card inteiro */
.card:has(.busca-ia-sugestoes.show),
.card.sugestoes-abertas {
    z-index: 1000 !important;
    position: relative;
}

/* Header da busca IA */
.busca-ia-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.busca-ia-header .icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--nga-primary, #0077b6) 0%, #023e8a 100%);
    border-radius: 10px;
    color: white;
    font-size: 1.1rem;
}

.busca-ia-header .title-wrapper {
    flex: 1;
}

.busca-ia-header h5 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
}

.busca-ia-header small {
    color: #64748b;
    font-size: 0.85rem;
}

/* Wrapper do campo de busca (contem input + sugestoes) */
.busca-ia-input-wrapper {
    position: relative;
    margin-bottom: 0.5rem;
    z-index: 100;
}

/* Campo de busca IA */
.busca-ia-input-group {
    position: relative;
    display: flex;
    align-items: stretch;
}

.busca-ia-input {
    border-radius: 50px 0 0 50px;
    padding-left: 3rem;
    border-right: none;
    font-size: 1rem;
    height: 50px;
    background-color: #fff;
    transition: all 0.3s ease;
}

.busca-ia-input:focus {
    box-shadow: 0 0 0 3px rgba(0, 119, 182, 0.15);
    border-color: var(--nga-primary, #0077b6);
}

.busca-ia-input::placeholder {
    color: #999;
    font-style: italic;
}

/* Icone de IA no campo */
.busca-ia-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--nga-primary, #0077b6);
    font-size: 1.2rem;
    z-index: 10;
}

/* Botao de buscar */
.busca-ia-btn {
    border-radius: 0 50px 50px 0;
    padding: 0 1.5rem;
    font-weight: 600;
    height: 50px;
    min-width: 120px;
    background-color: var(--nga-primary, #0077b6);
    border-color: var(--nga-primary, #0077b6);
    transition: all 0.3s ease;
    border-left: none;
}

.busca-ia-btn:hover {
    background-color: var(--nga-dark, #023e8a);
    border-color: var(--nga-dark, #023e8a);
    transform: translateX(2px);
}

.busca-ia-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* Spinner de loading */
.busca-ia-spinner {
    display: none;
    width: 1.2rem;
    height: 1.2rem;
}

.busca-ia-btn.loading .busca-ia-spinner {
    display: inline-block;
}

.busca-ia-btn.loading .busca-ia-btn-text {
    display: none;
}

/* Botao de sugestoes (lampada) */
.btn-sugestoes {
    border-radius: 0;
    padding: 0 0.75rem;
    height: 50px;
    border-color: #ffc107;
    color: #ffc107;
    background-color: transparent;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-sugestoes:hover {
    background-color: #ffc107;
    border-color: #ffc107;
    color: #212529;
}

.btn-sugestoes:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.25);
}

.btn-sugestoes i {
    font-size: 1.1rem;
}

/* Badge de IA */
.busca-ia-badge {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
    margin-left: auto;
}

/* Feedback da IA */
.busca-ia-feedback {
    margin-top: 0.75rem;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    font-size: 0.9rem;
    display: none;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.busca-ia-feedback.show {
    display: block;
}

/* Feedback de sucesso */
.busca-ia-feedback.success {
    background-color: #d1fae5;
    border: 1px solid #a7f3d0;
    color: #065f46;
}

.busca-ia-feedback.success .feedback-icon {
    color: #059669;
}

/* Feedback de erro */
.busca-ia-feedback.error {
    background-color: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.busca-ia-feedback.error .feedback-icon {
    color: #dc2626;
}

/* Feedback de fallback */
.busca-ia-feedback.fallback {
    background-color: #fef3c7;
    border: 1px solid #fde68a;
    color: #92400e;
}

.busca-ia-feedback.fallback .feedback-icon {
    color: #d97706;
}

/* Lista de filtros aplicados */
.filtros-aplicados {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filtro-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background-color: rgba(0, 119, 182, 0.1);
    color: var(--nga-primary, #0077b6);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.filtro-tag i {
    font-size: 0.7rem;
}

.filtro-tag:hover {
    background-color: rgba(0, 119, 182, 0.2);
}

/* Confianca da IA */
.ia-confianca {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #6b7280;
}

.ia-confianca .confianca-bar {
    display: inline-block;
    width: 80px;
    height: 4px;
    background-color: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.ia-confianca .confianca-fill {
    height: 100%;
    background: linear-gradient(90deg, #059669 0%, #10b981 100%);
    transition: width 0.5s ease;
}

/* Sugestoes de busca */
.busca-ia-sugestoes {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 99999;
    display: none;
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    backdrop-filter: blur(10px);
}

.busca-ia-sugestoes.show {
    display: block;
    position: absolute;
    z-index: 99999 !important;
}

/* Garantir que o wrapper mantenha z-index quando sugestoes visiveis */
.busca-ia-input-wrapper:has(.busca-ia-sugestoes.show),
.busca-ia-input-wrapper:hover {
    z-index: 9999;
}

/* Sugestoes mantem visibilidade no hover */
.busca-ia-sugestoes:hover {
    display: block !important;
    z-index: 99999 !important;
}

.sugestao-item {
    padding: 0.85rem 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.15s ease;
    border-bottom: 1px solid #f0f0f0;
    background-color: #ffffff;
}

.sugestao-item:first-child {
    border-radius: 16px 16px 0 0;
}

.sugestao-item:last-child {
    border-bottom: none;
    border-radius: 0 0 16px 16px;
}

.sugestao-item:only-child {
    border-radius: 16px;
}

.sugestao-item:hover {
    background-color: #f0f7ff;
}

.sugestao-item.active {
    background-color: #e0f2fe;
    border-left: 3px solid var(--nga-primary, #0077b6);
}

.sugestao-item i {
    color: #f59e0b;
    font-size: 1rem;
    flex-shrink: 0;
}

.sugestao-item .sugestao-texto {
    flex: 1;
    font-size: 0.9rem;
    color: #374151;
    line-height: 1.4;
}

.sugestao-item .sugestao-tipo {
    font-size: 0.7rem;
    color: #6b7280;
    background-color: #f3f4f6;
    padding: 3px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

/* Footer da busca IA (status + dica) */
.busca-ia-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Status da IA */
.ia-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: #64748b;
    white-space: nowrap;
}

.ia-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #9ca3af;
    flex-shrink: 0;
}

.ia-status-dot.online {
    background-color: #10b981;
    animation: pulse 2s infinite;
}

.ia-status-dot.offline {
    background-color: #ef4444;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Dica de uso */
.busca-ia-dica {
    font-size: 0.8rem;
    color: #64748b;
    white-space: nowrap;
}

.busca-ia-dica i {
    color: #f59e0b;
    margin-right: 0.35rem;
}

/* Secao alternativa de filtros */
.busca-ia-alternativo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
}

.busca-ia-alternativo .text-muted {
    font-size: 0.85rem;
    color: #64748b;
}

.busca-ia-alternativo .btn {
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    padding: 0.4rem 0.85rem;
    transition: all 0.2s ease;
}

.busca-ia-alternativo .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 119, 182, 0.2);
}

.busca-ia-alternativo .btn .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.45rem;
    border-radius: 10px;
    font-weight: 600;
}

/* Responsividade */
@media (max-width: 768px) {
    .busca-ia-header {
        gap: 0.5rem;
    }

    .busca-ia-header .icon-wrapper {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .busca-ia-header h5 {
        font-size: 1rem;
    }

    .busca-ia-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .busca-ia-dica {
        font-size: 0.75rem;
    }

    .busca-ia-alternativo {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (max-width: 576px) {
    .busca-ia-input {
        font-size: 0.9rem;
        height: 45px;
        padding-left: 2.5rem;
    }

    .busca-ia-btn {
        min-width: auto;
        padding: 0 1rem;
        height: 45px;
    }

    .busca-ia-btn-text {
        display: none;
    }

    .busca-ia-btn i {
        margin: 0;
    }

    .btn-sugestoes {
        height: 45px;
        padding: 0 0.5rem;
    }

    .btn-sugestoes i {
        font-size: 1rem;
    }

    .busca-ia-icon {
        font-size: 1rem;
        left: 0.75rem;
    }

    .busca-ia-badge {
        font-size: 0.6rem;
        padding: 2px 6px;
    }

    .filtro-tag {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .busca-ia-alternativo {
        flex-direction: column;
        text-align: center;
    }

    .busca-ia-alternativo .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Modo escuro (se suportado) */
@media (prefers-color-scheme: dark) {
    .busca-ia-input {
        background-color: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }

    .busca-ia-input::placeholder {
        color: #9ca3af;
    }

    .busca-ia-sugestoes {
        background: #1f2937;
        border-color: #374151;
    }

    .sugestao-item {
        border-bottom-color: #374151;
    }

    .sugestao-item:hover {
        background-color: #374151;
    }
}
