/**
 * Chat Widget - Estilos
 * Widget de atendimento inteligente
 */

/* Container principal */
.chat-widget-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Botão flutuante */
.chat-widget-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chat-widget-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.6);
}

.chat-widget-toggle:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

.chat-widget-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Janela do chat */
.chat-widget-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s ease;
}

.chat-widget-window.chat-widget-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.chat-widget-window.chat-widget-minimized {
    height: 60px;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

/* Cabeçalho */
.chat-widget-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-widget-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
}

.chat-widget-header-info i {
    font-size: 20px;
}

.chat-widget-header-actions {
    display: flex;
    gap: 8px;
}

.chat-widget-btn-minimize,
.chat-widget-btn-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.chat-widget-btn-minimize:hover,
.chat-widget-btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Área de mensagens */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden; /* Prevenir scroll horizontal */
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

/* Mensagem do bot - SEMPRE coluna */
.chat-widget-message {
    display: flex;
    flex-direction: column; /* SEMPRE coluna: texto acima, botões abaixo */
    max-width: 80%;
    width: 100%;
    box-sizing: border-box;
    animation: fadeIn 0.3s ease;
    align-items: flex-start; /* Alinhar à esquerda */
}

/* Garantir que mensagens do sistema sejam coluna (não row) */
.chat-widget-message-system {
    flex-direction: column !important;
}

/* Container de mensagem do bot - garantir estrutura coluna */
.chat-widget-message.bot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

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

.chat-widget-message-user {
    align-self: flex-end;
    margin-left: auto;
}

.chat-widget-message-system {
    align-self: flex-start;
}

.chat-widget-message-text {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal !important; /* Forçar normal */
    max-width: 100%;
    word-break: normal !important; /* Não quebrar palavras desnecessariamente */
    display: block; /* Garantir que é block */
    width: 100%;
    box-sizing: border-box;
}

.chat-widget-message-user .chat-widget-message-text {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-widget-message-system .chat-widget-message-text {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Indicador de digitação */
.chat-widget-typing {
    padding: 0 20px 10px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.chat-widget-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.chat-widget-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-widget-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Área de input */
.chat-widget-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.chat-widget-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-widget-input:focus {
    border-color: #667eea;
}

.chat-widget-btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.chat-widget-btn-send:hover {
    transform: scale(1.1);
}

.chat-widget-btn-send:active {
    transform: scale(0.95);
}

/* Botão WhatsApp fallback */
.chat-widget-fallback {
    padding: 12px 20px;
    background: #f0f0f0;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.chat-widget-btn-whatsapp {
    width: 100%;
    padding: 12px;
    background: #25d366;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.2s ease;
}

.chat-widget-btn-whatsapp:hover {
    background: #128c7e;
}

.chat-widget-btn-whatsapp i {
    font-size: 18px;
}

/* Responsividade */
@media (max-width: 768px) {
    .chat-widget-container {
        bottom: 20px;
        right: 20px;
    }
    
    .chat-widget-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        max-height: calc(100vh - 100px);
        bottom: 80px;
        right: 0;
    }
    
    .chat-widget-toggle {
        width: 56px;
        height: 56px;
        font-size: 22px;
    }
}

/* Scrollbar personalizada */
.chat-widget-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-widget-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-widget-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-widget-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Acessibilidade */
@media (prefers-reduced-motion: reduce) {
    .chat-widget-window,
    .chat-widget-toggle,
    .chat-widget-message {
        transition: none;
        animation: none;
    }
}

/* Quick Replies (botões de resposta rápida) - FASE 2: 1 coluna, alinhados abaixo do balão */
.chat-widget-quick-replies {
    display: flex;
    flex-direction: column; /* SEMPRE coluna: 1 botão por linha */
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden; /* Prevenir scroll horizontal */
}

.chat-widget-quick-reply-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    background: white;
    border: 1px solid #667eea;
    color: #667eea;
    border-radius: 999px; /* FASE 2: border-radius arredondado */
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2; /* FASE 2: line-height ajustado */
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: normal; /* Permite quebra de linha */
    word-wrap: break-word;
    width: 100%; /* FASE 2: cada botão ocupa 100% da largura */
    box-sizing: border-box;
    text-align: center;
}

/* Container de ações - garantir que fique abaixo do balão */
.chat-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.chat-action-btn {
    width: 100%;
    white-space: normal;
    line-height: 1.2;
    padding: 10px 12px;
    border-radius: 14px;
}

/* Balão de mensagem - garantir quebra de palavra */
.chat-bubble,
.chat-widget-message-text {
    max-width: 85%;
    word-break: break-word;
}

.chat-widget-quick-reply-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.chat-widget-quick-reply-btn:active {
    transform: translateY(0);
}

/* Botão especial para "Falar com corretor" - mais destacado */
.chat-widget-quick-reply-btn[data-quick-reply-id="intent_contact"],
.chat-widget-quick-reply-btn.contact-btn {
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    border: 2px solid #25D366;
    color: white;
    font-weight: 600;
    box-shadow: 0 3px 10px rgba(37, 211, 102, 0.3);
    position: relative;
}

.chat-widget-quick-reply-btn[data-quick-reply-id="intent_contact"]:before,
.chat-widget-quick-reply-btn.contact-btn:before {
    content: '💬';
    margin-right: 6px;
    font-size: 16px;
}

.chat-widget-quick-reply-btn[data-quick-reply-id="intent_contact"]:hover,
.chat-widget-quick-reply-btn.contact-btn:hover {
    background: linear-gradient(135deg, #128C7E 0%, #075E54 100%);
    border-color: #128C7E;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
    transform: translateY(-2px);
}

/* Botão de contato durante o fluxo também destacado */
.chat-widget-quick-reply-btn[data-quick-reply-id^="contact_"] {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid #667eea;
    color: white;
    font-weight: 600;
}

/* Suggestions (cards de imóveis) */
.chat-widget-suggestions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.chat-widget-suggestion-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease;
}

.chat-widget-suggestion-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.chat-widget-suggestion-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.4;
}

.chat-widget-suggestion-price {
    font-size: 18px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 6px;
}

.chat-widget-suggestion-location {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-widget-suggestion-location::before {
    content: '📍';
    font-size: 12px;
}

.chat-widget-suggestion-btn {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.chat-widget-suggestion-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-widget-suggestion-btn:active {
    transform: translateY(0);
}

/* Ajustar largura máxima da mensagem quando tem quick_replies ou suggestions */
.chat-widget-message-system:has(.chat-widget-quick-replies),
.chat-widget-message-system:has(.chat-widget-suggestions) {
    max-width: 90%;
}

/* Garantir que mensagens do sistema com botões tenham layout correto */
.chat-widget-message-system {
    flex-direction: column;
}

/* Markdown simples (negrito) */
.chat-widget-message-text strong {
    font-weight: 600;
    color: #333;
}

/* Autocomplete de localização */
.chat-widget-autocomplete {
    margin-top: 12px;
    position: relative;
}

.chat-widget-autocomplete-wrapper {
    position: relative;
}

.chat-widget-autocomplete-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.chat-widget-autocomplete-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-widget-autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.chat-widget-autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.chat-widget-autocomplete-item:last-child {
    border-bottom: none;
}

.chat-widget-autocomplete-item:hover {
    background-color: #f5f5f5;
}

.chat-widget-autocomplete-item:active {
    background-color: #e8e8e8;
}


