/* chat-style.css - VERSÃO FINAL AJUSTADA (Input e Posição Corrigidos) */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    /* SUAS VARIÁVEIS ORIGINAIS */
    --primary-color: #333333; 
    --primary-gradient: linear-gradient(135deg, #333333, #000000);
    --secondary-color: #f3f4f6;
    
    --text-dark: #1f2937;
    --text-light: #ffffff;
    --text-muted: #9ca3af;

    --radius-window: 16px;
    --radius-bubble: 18px;
    --shadow-soft: 0 12px 48px rgba(0, 0, 0, 0.12);
    --shadow-button: 0 8px 24px rgba(99, 102, 241, 0.3);
}

/* 1. ISOLAMENTO DE CSS (Para não quebrar o site do cliente) */
.chat-widget, .chat-widget * { box-sizing: border-box; }

.chat-widget {
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    
    position: fixed;
    bottom: 10px; 
    right: 10px;  
    z-index: 2147483647;
    
    display: flex;
    flex-direction: column-reverse; 
    align-items: flex-end; 
    gap: 16px; 
}

/* Garante os ícones (Correção FontAwesome) */
.chat-widget .fa-solid, .chat-widget .fas, .chat-widget i {
    font-family: "Font Awesome 6 Free", "FontAwesome", sans-serif !important;
    font-weight: 900 !important;
}

/* --- BOTÃO FLUTUANTE --- */
.chat-widget .chat-toggle-btn {
    width: 60px; height: 60px;
    
    /* 1. Formato Redondo Obrigatório */
    border-radius: 50% !important; 
    
    /* 2. Sem Fundo e Sem Borda */
    background: transparent !important;
    border: none !important;
    
    /* 3. Sombra suave para o botão flutuar (opcional, pode tirar se quiser chapado) */
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    position: relative; padding: 0; margin: 0;
    overflow: hidden; /* Garante que a imagem não vaze do círculo */
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-widget .chat-toggle-btn:hover { transform: scale(1.1); }

/* Estilo da Imagem */
.chat-widget .avatar-img {
    width: 100%; height: 100%;
    
    /* 4. Preenche o círculo perfeitamente */
    object-fit: cover; 
    
    /* Garante arredondamento na imagem também */
    border-radius: 50% !important; 
}

/* Ícones e Estados (Mantém igual) */
.chat-widget .icon-open, .chat-widget .icon-close { position: absolute; transition: 0.3s; }
.chat-widget .icon-close { font-size: 24px; color: white; opacity: 0; transform: rotate(-90deg) scale(0.5); }

/* Quando abre, ganha cor de fundo para o X aparecer */
.chat-widget.open .chat-toggle-btn {
    background: var(--primary-gradient) !important;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3) !important;
    transform: rotate(0);
}
.chat-widget.open .icon-open { opacity: 0; transform: scale(0.5); }
.chat-widget.open .icon-close { opacity: 1; transform: rotate(0) scale(1); }


/* --- JANELA DO CHAT --- */
/* --- .chat-widget .chat-window {
    width: 340px; height: 520px; max-height: 70vh;
    background: #ffffff;
    border-radius: var(--radius-window);
    box-shadow: var(--shadow-soft);
    display: flex; flex-direction: column; overflow: hidden;
    position: relative; 
    opacity: 0; transform: translateY(20px) scale(0.95);
    display: none; transition: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
} --- */
.chat-widget .chat-window {
    width: 330px;
    height: 500px;
    max-height: 75vh;
    background: var(--kai-bg-window);
    border-radius: var(--kai-radius);
    box-shadow: var(--kai-shadow);
    border-radius: var(--radius-window);
    
    display: flex;
    flex-direction: column;
    overflow: hidden;

    position: relative; 
    bottom: auto;
    right: auto;
    
    /* Estado Fechado */
    display: none; 
    opacity: 0;
    
    /* Garante que a animação comece do canto inferior direito */
    transform-origin: bottom right; 
    border: 1px solid rgba(0,0,0,0.05);
}



/* AQUI ESTAVA O ERRO DA JANELA SUBIR: Removi o margin-bottom extra 
.chat-widget.open .chat-window { display: flex; opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }*/

.chat-widget.open .chat-window {
    display: flex; 
    opacity: 1;
    
    /* 
       0.7s = Tempo da animação (bem perceptível)
       cubic-bezier = O "freio" suave no final
    */
    animation: chatSlideUp 0.7s cubic-bezier(0.23, 1, 0.32, 1) forwards;
    
    pointer-events: all;
}

/* --- CABEÇALHO --- */
.chat-widget .chat-header {
    background: var(--primary-gradient);
    padding: 9px 20px; color: white;
    display: flex; justify-content: space-between; align-items: center;
}
.chat-widget .chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-widget .avatar-wrapper img { width: 46px; height: 46px; border-radius: 50%; background: transparent !important;}
.chat-widget .status-dot { display: none !important; }
.chat-widget .agent-details h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: white;
  text-align: left; /* força alinhamento à esquerda */
}

.chat-widget .agent-details p { font-size: 12px; opacity: 0.9; margin: 0; color: white; }
.chat-widget .chat-close-mini { background: none; border: none; color: white; opacity: 0.7; cursor: pointer; font-size: 18px; }


/* --- CORPO --- */
.chat-widget .chat-body {
    flex: 1; padding: 20px; overflow-y: auto; background-color: #f8fafc;
    display: flex; flex-direction: column; gap: 16px;
}
.chat-widget .message { max-width: 85%; display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; border: none; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.chat-widget .message-content {
    padding: 14px 18px; font-size: 14px; line-height: 1.5;
    word-wrap: break-word; text-align: left; width: fit-content;
}
.chat-widget .bot-message .message-content {
    background: white; color: var(--text-dark);
    border-radius: var(--radius-bubble); border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.chat-widget .user-message .message-content {
    background: var(--primary-gradient); color: white;
    border-radius: var(--radius-bubble); border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}
.chat-widget .message-time { font-size: 10px; color: var(--text-muted); margin: 0 4px; }


/* --- RODAPÉ (AQUI ESTÁ A CORREÇÃO DO INPUT/MIC) --- */
.chat-widget .chat-footer {
    padding: 15px; 
    background: white; 
    border-top: 1px solid rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    gap: 10px; /* Isso cria o espaço físico entre o input e o botão */
    flex-wrap: wrap;
}

/* 1. A Pílula Cinza (Input + Mic) */
.chat-widget .input-container {
    /* Mude de width fixo para flex: 1 */
    flex: 1; /* Faz ele ocupar todo o espaço DISPONÍVEL (menos os 10px e o botão) */
    position: relative; 
    background: var(--secondary-color);
    border-radius: 25px;
    display: flex;
    align-items: center;
    padding: 6px; /* Padding menor para não engordar */
    height: 42px;
}

/* 2. O Input (Texto) */
.chat-widget #chat-input {
    width: 100%;
    height: 100%;
    background: transparent; 
    border: none; 
    outline: none;
    
    /* 35px na direita para dar espaço ao microfone */
    padding: 0 35px 0 15px; 
    
    color: var(--text-dark); 
    margin: 0;
    font-family: 'Inter', sans-serif;
}

/* 3. O Microfone (Flutuante na direita da pílula) */
.chat-widget #chat-mic-btn {
    display: flex !important; /* Força aparecer (caso o JS esteja escondendo errado) */
    position: absolute;       /* Flutua */
    right: 10px;              /* Cola no canto direito da pílula */
    top: 50%;                 /* Centraliza na altura */
    transform: translateY(-50%);
    
    background: none; 
    border: none; 
    color: #999;              /* Cor cinza visível */
    
    cursor: pointer; 
    padding: 5px; 
    z-index: 10;              /* Garante que fique na frente do input */
    font-size: 16px;
}

/* 4. O Botão Enviar (O Ícone Colorido) */
.chat-widget #chat-send-btn {
    width: 42px; height: 42px;
    border: none; background: transparent !important; box-shadow: none !important;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; transition: transform 0.2s;
    
    /* IMPEDE QUE ELE SEJA ESMAGADO PELO INPUT */
    flex-shrink: 0; 
    padding: 0;
}

/* Gradiente no Ícone */
.chat-widget #chat-send-btn i {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent; 
    display: inline-block;
}

.chat-widget #chat-send-btn:hover { transform: scale(1.15); filter: brightness(1.2); }
.chat-widget .branding { width: 100%; text-align: center; font-size: 10px; color: #ccc; margin-top: 5px; }
.chat-widget .branding a { color: #94a3b8; text-decoration: none; }


/* --- MOBILE --- */
@media (max-width: 480px) {
    .chat-widget { bottom: 10px; right: 10px; }
    .chat-widget .chat-window {
        width: calc(100vw - 40px);
        height: 80vh; max-height: 600px;
        position: relative; bottom: auto; right: auto;
    }
}

/* --- DARK MODE --- */
.chat-widget.dark-mode {
    --bg-window: #1f2937; --bg-body: #111827; --bg-input: #374151;
    --text-dark: #f9fafb; --text-muted: #94a3b8; --bot-bubble: #374151;
}

.chat-widget.dark-mode .chat-window { background-color: #1f2937 !important; border: 1px solid #374151; }
.chat-widget.dark-mode .chat-header { border-bottom: 1px solid rgba(255,255,255,0.1); }
.chat-widget.dark-mode .chat-body { background-color: #111827 !important; }
.chat-widget.dark-mode .bot-message .message-content { background: #374151 !important; color: #f3f4f6 !important; border: 1px solid #4b5563; }
.chat-widget.dark-mode .user-message .message-content { color: #ffffff !important; }
.chat-widget.dark-mode .chat-footer { background-color: #1f2937 !important; border-top: 1px solid #374151; }
.chat-widget.dark-mode .input-container { background-color: #374151 !important; border: 1px solid #4b5563; }
.chat-widget.dark-mode #chat-input { color: #ffffff !important; }
.chat-widget.dark-mode #chat-input::placeholder { color: #9ca3af !important; }
.chat-widget.dark-mode .agent-details h3, .chat-widget.dark-mode .agent-details p { color: white !important; }

/* Ícone Branco no Dark */
.chat-widget.dark-mode #chat-send-btn i {
    background: none !important;
    -webkit-text-fill-color: #ffffff !important;
    color: #ffffff !important;
}
.chat-widget.dark-mode #chat-send-btn:hover { transform: scale(1.1); }

/* Esconde botão flutuante ao abrir */
.chat-widget.open #chat-toggle-btn {
    transform: scale(0) !important; 
    opacity: 0 !important;          
    pointer-events: none;           
    height: 0; margin: 0; padding: 0;
}

/* --- NOVA ANIMAÇÃO DE ENTRADA (SLIDE UP) --- */
@keyframes chatSlideUp {
    0% {
        opacity: 0;
        /* Começa 100px abaixo e um pouco menor (efeito de profundidade) */
        transform: translateY(100px) scale(0.9); 
    }
    100% {
        opacity: 1;
        /* Termina na posição original e tamanho real */
        transform: translateY(0) scale(1); 
    }
}