/* =========================================
   1. RESET E VARIÁVEIS
   ========================================= */
:root {
  --azul-unifacig: #004694;
  --vermelho-unifacig: #BF0811;
  --cinza-claro: #f0f2f5;
}

/* Garante que o padding não aumente o tamanho dos elementos */
.unifaciggpt-sig *,
.unifaciggpt-sig *::before,
.unifaciggpt-sig *::after,
.unifaciggpt-chatbox *,
.unifaciggpt-chatbox *::before,
.unifaciggpt-chatbox *::after {
    box-sizing: border-box;
}

/* =========================================
   2. CONTAINER PRINCIPAL (CHATBOX)
   ========================================= */
.unifaciggpt-chatbox {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    position: fixed;
    
    /* Tamanho Desktop */
    width: 380px; 
    height: 600px;
    max-height: 80vh;
    
    bottom: 90px;
    left: 20px;
    right: auto;
    
    border-radius: 20px;
    background: #ffffff;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.2);
    
    /* CORREÇÃO AQUI: Começa escondido, e definimos o flex-direction */
    display: none; 
    flex-direction: column;
    overflow: hidden; 
    z-index: 99999;
}

/* ESSA REGRA É NOVA: Força o modo Flex apenas quando o chat estiver visível */
.unifaciggpt-chatbox[style*="display: block"],
.unifaciggpt-chatbox[style*="display: inline"] {
    display: flex !important;
}
/* O script JS usa .toggle() que coloca display: block. 
   Precisamos forçar display: flex quando estiver visível com !important ou via script.
   Como o JS do jQuery usa inline style, adicione isso para garantir: */
.unifaciggpt-chatbox[style*="display: block"] {
    display: flex !important;
}


/* =========================================
   3. CABEÇALHO (NAVBAR)
   ========================================= */
.unifaciggpt-chat-navbar {
    background-color: var(--azul-unifacig) !important;
    height: 60px; /* Altura fixa para o topo */
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    color: white;
}

.unifaciggpt-sig-closechat {
    background: transparent;
    border: none;
    color: white !important;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.8;
    transition: 0.3s;
}
.unifaciggpt-sig-closechat:hover {
    opacity: 1;
    transform: scale(1.1);
}

.unifaciggpt-chat-image {
    max-width: 50px;
    max-height: 50px;
    background: whitesmoke;
    border-radius: 50%;
}

/* =========================================
   4. AVISO LEGAL (O "ATENÇÃO") - REDESIGN
   ========================================= */
.unifaciggpt-chat-alert {
    position: absolute; /* Flutua sobre as mensagens */
    top: 60px; /* Logo abaixo do header */
    left: 0;
    width: 100%;
    height: calc(100% - 60px); /* Ocupa todo o resto do chat */
    background: rgba(255, 255, 255, 0.95); /* Fundo branco quase sólido */
    backdrop-filter: blur(5px); /* Efeito de vidro */
    z-index: 100;
    padding: 30px;
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.unifaciggpt-chat-alert h5 {
    color: var(--vermelho-unifacig);
    font-size: 1.2rem;
    margin-bottom: 15px;
    font-weight: bold;
    text-transform: uppercase;
}

.unifaciggpt-chat-alert p {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 25px;
    line-height: 1.6;
}

.unifaciggpt-sig-agreebtn {
    background-color: var(--azul-unifacig) !important;
    color: white !important;
    border: none;
    padding: 12px 30px !important;
    border-radius: 50px; /* Botão redondinho moderno */
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 4px 15px rgba(0, 70, 148, 0.3);
}

.unifaciggpt-sig-agreebtn:hover {
    background-color: var(--vermelho-unifacig) !important;
    transform: translateY(-2px);
}

/* =========================================
   5. ÁREA DE MENSAGENS
   ========================================= */
.unifaciggpt-chat-messages {
    flex: 1; /* Ocupa todo o espaço disponível no meio */
    overflow-y: auto;
    padding: 20px;
    background-color: var(--cinza-claro); /* Fundo cinza clarinho tipo WhatsApp */
    scroll-behavior: smooth;
}

/* Mensagens */
.unifaciggpt-chat-message {
    max-width: 85%;
    
    /* A MÁGICA ACONTECE AQUI: */
    width: fit-content; /* Faz o balão encolher para caber o texto */
    
    padding: 12px 16px;
    border-radius: 15px;
    font-size: 0.95em;
    margin-bottom: 15px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Mensagem do Robô (Sig) */
.unifaciggpt-chat-message.assistant {
    background: var(--vermelho-unifacig); /* Balão vermelho */
    color: white;
    border-bottom-left-radius: 2px;
    margin-right: auto; /* Alinha na esquerda */
}

/* Mensagem do Usuário */
.unifaciggpt-chat-message.user {
    background: var(--azul-unifacig); /* Balão Azul */
    color: white;
    border-bottom-right-radius: 2px;
    margin-left: auto; /* Alinha na direita */
}

/* =========================================
   6. ÁREA DE INPUT (DIGITAÇÃO)
   ========================================= */
.unifaciggpt-chat-input-wrapper {
    background: white;
    padding: 10px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px; /* Espaço entre input e botão */
    min-height: 70px;
}

.unifaciggpt-chat-input {
    flex-grow: 1;
    width: auto;
    
    /* FONTE CORRIGIDA */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    font-size: 0.75em;
    line-height: 1.4; /* Importante para o texto não cortar */
    
    border: 1px solid #ddd !important;
    border-radius: 15px 15px 15px 15px !important;
    
    /* Padding ajustado para centralizar o texto verticalmente na altura de 45px */
    padding: 10px 10px 10px 15px !important;
    
    background: #f9f9f9 !important;
    color: #333 !important;
    outline: none !important;
    
    /* TAMANHO */
    height: 45px; /* Altura fixa */
    resize: none; /* Impede o usuário de arrastar */
    
    /* SCROLLBAR MODERNA */
    overflow-y: auto; /* Só aparece se precisar */
    scrollbar-width: thin; /* Firefox: barra fina */
    scrollbar-color: rgba(0,0,0,0.1) transparent; /* Firefox: cor discreta */
}

/* Foco */
.unifaciggpt-chat-input:focus {
    background: #fff !important;
    border-color: var(--azul-unifacig) !important;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05); /* Sutil profundidade */
}

/* Corrigir a cor e fonte do Placeholder (Dica de Ouro) */
.unifaciggpt-chat-input::placeholder {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #aaa; /* Cinza mais suave */
    opacity: 1;
    font-weight: 400;
}

.unifaciggpt-send {
    width: 45px;
    height: 45px;
    border-radius: 50% !important; /* Botão de enviar redondo */
    background-color: var(--azul-unifacig) !important;
    border: none;
    color: white !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    position: static; /* Reset do position absolute antigo */
}

.unifaciggpt-send:hover {
    background-color: var(--vermelho-unifacig) !important;
    transform: scale(1.05);
}

/* ID discreto */
.unifaciggpt-chatid {
    font-size: 10px;
    color: #ccc;
    position: absolute;
    bottom: 0.1px;
    right: 15px;
    pointer-events: none;
}

/* =========================================
   7. ANIMAÇÃO DIGITANDO
   ========================================= */
.typing-animation {
    width: 8px;
    height: 8px;
    background-color: #ccc;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: typing 1s infinite alternate;
}
@keyframes typing {
    0% { transform: translateY(0); opacity: 0.5; }
    100% { transform: translateY(-5px); opacity: 1; background-color: #ccc; }
}

/* =========================================
   8. BOTÃO FLUTUANTE (TOGGLE)
   ========================================= */
.unifaciggpt-toggle {
    padding: 0px;
    bottom: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50% !important;
    background-color: var(--azul-unifacig) !important;
    box-shadow: 0 4px 20px rgba(0, 70, 148, 0.4);
    border: none;
    z-index: 9999;
    position: fixed;
    cursor: pointer;
    transition: transform 0.2s;
}
.unifaciggpt-toggle:hover {
    transform: scale(1.1);
    background-color: var(--vermelho-unifacig) !important;
}

/* =========================================
   BALÃO DE CONVITE (CORRIGIDO)
   ========================================= */
.unifaciggpt-sig-chatbubble {
    display: block;
    position: fixed;
    
    /* Distância do fundo: 20px (botão) + 60px (altura botão) + 15px (seta) */
    bottom: 95px; 
    left: 20px;   /* Alinhado com o início do botão */
    
    /* Tamanho inteligente */
    width: auto;         /* Largura se adapta ao texto */
    max-width: 280px;    /* Mas não deixa ficar gigante */
    min-width: 200px;
    
    background-color: var(--vermelho-unifacig);
    color: white;
    
    /* Padding generoso na direita por causa do botão X */
    padding: 15px 35px 15px 20px; 
    
    border-radius: 15px; /* Bordas redondinhas em tudo */
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25); /* Sombra mais bonita */
    
    font-size: 0.9em;
    line-height: 1.4;
    z-index: 9990;
    
    /* Animação de entrada */
    animation: bounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* A Setinha (Triângulo) apontando para o Sig */
.unifaciggpt-sig-chatbubble::after {
    content: '';
    position: absolute;
    bottom: -10px; /* Joga a seta para fora do balão */
    left: 20px;    /* Alinha o centro da seta com o centro do botão (30px visualmente) */
    
    /* Geometria do triângulo CSS */
    width: 0; 
    height: 0; 
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--vermelho-unifacig); /* A cor da seta */
}

/* Botão de fechar (X) - Ajuste fino de posição */
.unifaciggpt-sig-closebubble {
    position: absolute;
    top: 50%;           /* Centraliza verticalmente */
    transform: translateY(-50%); /* Correção da centralização */
    right: 15px;        /* Distância da direita */
    
    color: rgba(255, 255, 255, 0.7) !important;
    font-size: 16px;
    cursor: pointer;
    background: transparent;
    border: none;
    transition: 0.2s;
    padding: 5px; /* Aumenta área de clique */
}

.unifaciggpt-sig-closebubble:hover {
    color: white !important;
}

/* Efeito "Pulo" ao aparecer (mais amigável) */
@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.8) translateY(10px); }
    70% { transform: scale(1.05) translateY(-5px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Mobile: Ajuste para não cobrir a tela */
@media (max-width: 480px) {
    .unifaciggpt-sig-chatbubble {
        bottom: 85px; /* Um pouco mais baixo no celular */
        left: 15px;
        max-width: 250px; /* Um pouco mais estreito */
        font-size: 0.85em;
    }
}

/* =========================================
   9. MOBILE TOTAL (A MÁGICA ACONTECE AQUI)
   ========================================= */
@media (max-width: 480px) {
    .unifaciggpt-chatbox {
        /* Tamanho mais seguro para mobile */
        width: 90% !important; /* Deixa 5% de margem de cada lado */
        height: 80vh !important; /* Ocupa 80% da altura da tela */
        
        /* Centraliza na tela */
        left: 5% !important;
        bottom: 20px !important;
        right: auto !important;
        top: auto !important;
        
        border-radius: 20px !important; /* Mantém arredondado */
        
        /* Garante que o display none funcione até clicar */
        display: none; 
    }
    
    /* Quando o chat abrir no mobile, forçamos o display flex */
    .unifaciggpt-chatbox[style*="display: block"] {
        display: flex !important;
    }

    .unifaciggpt-chat-navbar {
        height: 60px; /* Altura padrão */
    }
    
    .unifaciggpt-chat-alert {
        top: 60px;
        height: calc(100% - 60px);
    }
}

/* =========================================
   SCROLLBAR PERSONALIZADA (CHROME/EDGE)
   ========================================= */
/* A barra em si */
.unifaciggpt-chat-input::-webkit-scrollbar {
    width: 4px; /* Super fina */
}

/* O fundo da barra (transparente) */
.unifaciggpt-chat-input::-webkit-scrollbar-track {
    background: transparent; 
}

/* O "polegar" que a gente arrasta */
.unifaciggpt-chat-input::-webkit-scrollbar-thumb {
    background-color: #ccc; /* Cinza claro */
    border-radius: 10px;    /* Arredondado */
}

/* Hover na barra */
.unifaciggpt-chat-input::-webkit-scrollbar-thumb:hover {
    background-color: var(--azul-unifacig); /* Fica azul se passar o mouse */
}