/* =========================
   CONFIGURAÇÕES GERAIS
========================= */
#ia-chat-container {
  /* Apenas a Cor Primária é dinâmica (via PHP).
     As demais são fixas para garantir consistência visual e não herdar do tema.
  */
  --primary-color: #2563eb; 
  
  /* Paleta Fixa */
  --chat-bg: #ffffff;
  --chat-bg-sec: #f3f4f6;
  --chat-text-main: #1f2937;
  --chat-text-light: #6b7280;
  --chat-border: #e5e7eb;
  --chat-white: #ffffff;

  font-family: 'Inter', sans-serif;
  z-index: 999999;
  position: fixed;
  bottom: 20px;
  right: 20px;
  line-height: 1.5;
  color: var(--chat-text-main);
}

/* Botão Flutuante (Toggle) */
.ia-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--chat-white);
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 10;
}

/* REGRA: Não alterar cor no hover, apenas efeito "grow" (scale) 
*/
.ia-toggle-btn:hover { 
    transform: scale(1.1); 
    background-color: var(--primary-color); /* Mantém a cor fixa */
}

/* Esconde o widget ou botão quando necessário */
.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

#ia-chat-widget {
  all: unset; /* Reseta estilos herdados do tema WP */
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
  
  /* Posicionamento */
  position: absolute; /* Relativo ao container fixo */
  bottom: 80px; /* Espaço para o botão toggle */
  right: 0;
  width: 380px;
  height: 600px;
  max-height: 80vh;
  
  background: var(--chat-bg);
  border-radius: 16px;
  box-shadow: 0 10px 40px -10px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  
  transform-origin: bottom right;
  animation: ia-pop-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ia-pop-in {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

#ia-chat-widget * { box-sizing: border-box; }

/* =========================
   HEADER
========================= */
.ia-chat-header {
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.98);
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-info { display: flex; align-items: center; gap: 12px; }

.avatar-bot {
  width: 36px; height: 36px;
  background: #eff6ff; 
  color: var(--primary-color);
  border-radius: 50%;
  display: grid; place-items: center;
  overflow: hidden;
}

.header-info h1 {
  margin: 0; font-size: 16px; font-weight: 700; color: var(--chat-text-main);
  line-height: 1.2;
}

.status-dot {
  font-size: 12px; color: #10b981; display: flex; align-items: center; gap: 4px;
}
.status-dot::before {
  content: ''; width: 8px; height: 8px; background: currentColor; border-radius: 50%;
}

.header-actions { display: flex; gap: 8px; }

.ia-action-btn {
  cursor: pointer;
  color: var(--chat-text-light);
  background: none; border: none;
  padding: 6px; border-radius: 50%;
  transition: 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.ia-action-btn:hover { background: var(--chat-bg-sec); color: #ef4444; }

/* =========================
   BODY
========================= */
.ia-chat-body {
  flex: 1;
  background: var(--chat-bg);
  overflow-y: auto;
  padding: 20px;
  position: relative;
  color: var(--chat-text-main);
}

/* TELA DE BOAS VINDAS (Centralizada) */
.ia-empty-state {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: opacity 0.3s ease;
  padding: 20px;
}

.company-logo {
  width: 60px; height: 60px;
  object-fit: contain;
  margin-bottom: 16px;
  border-radius: 12px;
}

.ia-empty-state h2 {
  font-size: 20px; margin: 0 0 8px 0; color: var(--chat-text-main); font-weight: 700;
}
.ia-empty-state p {
  font-size: 14px; color: var(--chat-text-light); margin: 0;
}

/* LISTA DE MENSAGENS */
.ia-message-list {
  display: flex; flex-direction: column; gap: 16px;
  padding-bottom: 10px;
}

.message {
  display: flex; flex-direction: column; max-width: 85%;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; align-items: flex-end; }
.message.bot { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  word-wrap: break-word;
}
.bubble a { color: inherit; text-decoration: underline; }

/* CORES DOS BALÕES */
.message.user .bubble {
  background: var(--primary-color);
  color: var(--chat-white);
  border-bottom-right-radius: 2px;
}
.message.bot .bubble {
  background: var(--chat-bg-sec);
  color: var(--chat-text-main);
  border-bottom-left-radius: 2px;
}

.time { font-size: 10px; color: #9ca3af; margin-top: 4px; margin-left: 2px; }

/* =========================
   FOOTER
========================= */
.ia-chat-footer {
  padding: 16px; 
  background: var(--chat-bg); 
  border-top: 1px solid var(--chat-border);
}

.ia-input-wrapper {
  display: flex; 
  align-items: center; 
  gap: 8px;
  background: var(--chat-bg-sec);
  border-radius: 24px; 
  padding: 6px 12px 6px 16px;
  transition: box-shadow 0.2s;
}

.ia-input-wrapper:focus-within {
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2); 
  background: var(--chat-white);
}

.ia-input-wrapper input {
  flex: 1; 
  background: transparent; 
  border: 0 solid transparent !important; /* Garante que não há borda */
  font-size: 14px; 
  color: var(--chat-text-main); 
  outline: none !important; /* Garante que não há outline */
  box-shadow: none !important; /* Garante que não há sombra que pareça borda */
  padding: 8px 0;
  -webkit-appearance: none; /* Remove estilos nativos do iOS/Safari */
}

.ia-send-btn {
  width: 32px; 
  height: 32px; 
  border-radius: 50%;
  background: transparent;
  color: #9ca3af;
  border: none;
  display: grid; 
  place-items: center; 
  cursor: pointer;
  transition: 0.2s;
  padding: 0;
}

.ia-send-btn:hover {
  background: transparent; 
  color: var(--primary-color); 
  transform: scale(1.1);
}
.ia-send-btn:active { transform: scale(0.95); }

.ia-chat-footer small {
  display: block; 
  text-align: center; 
  font-size: 10px; 
  color: #9ca3af; 
  margin-top: 8px;
}

/* Typing */
.ia-typing { display: flex; gap: 4px; padding: 10px; }
.ia-typing span { width: 5px; height: 5px; background: #999; border-radius: 50%; animation: ia-blink 1.4s infinite both; }
.ia-typing span:nth-child(2) { animation-delay: 0.2s; }
.ia-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ia-blink { 0%, 80%, 100% { opacity: 0; } 40% { opacity: 1; } }

/* Mobile */
@media (max-width: 480px) {
    #ia-chat-widget {
        width: 100vw; height: 100vh; max-height: 100vh;
        bottom: 0; right: 0; border-radius: 0;
        position: fixed;
    }
    #ia-chat-container { bottom: 0; right: 0; }
    .ia-toggle-btn { margin: 20px; }
}