:root {
  /* O Verdadeiro Blue Glassmorphism */
  --ima-chat-bg: rgba(14, 30, 64, 0.85); 
  --ima-chat-bg-soft: rgba(59, 130, 246, 0.20); 
  --ima-chat-border: rgba(59, 130, 246, 0.35);
  --ima-chat-text: #f8fafc;
  --ima-chat-muted: #cbd5e1;
  --ima-chat-primary: #3b82f6;
  --ima-chat-primary-2: #2563eb;
  --ima-chat-gold: #f59e0b;
  --ima-chat-success: #10b981;
  --ima-chat-danger: #ef4444; 

}

/* ==========================================================================
   RESET E BASE
   ========================================================================== */
.ima-chat-root { position: fixed; bottom: 24px; right: 24px; z-index: 999999; font-family: 'Inter', Arial, sans-serif; }
.ima-chat-root * { box-sizing: border-box; margin: 0; padding: 0; }
.ima-hidden { display: none !important; }

/* ==========================================================================
   BOTÃO FLUTUANTE (FAB)
   ========================================================================== */
.ima-chat-fab {
  position: absolute; bottom: 0; right: 0; width: 60px; height: 60px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--ima-chat-primary), var(--ima-chat-primary-2));
  color: white; font-size: 28px; cursor: pointer; box-shadow: 0 8px 24px rgba(59, 130, 246, 0.5);
  display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; z-index: 100;
}
.ima-chat-fab:hover { transform: scale(1.08) translateY(-4px); }

/* ==========================================================================
   PAINEL PRINCIPAL (FLEXBOX BLINDADO)
   ========================================================================== */
.ima-chat-panel {
  position: fixed; bottom: 100px; right: 24px; 
  width: 340px; height: 480px; 
  max-width: 90vw; max-height: 80vh;
  background: var(--ima-chat-bg);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--ima-chat-border); border-radius: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4); 
  display: flex; flex-direction: column; overflow: hidden; z-index: 99;
  transform-origin: bottom right; animation: imaPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  
  /* 👇 AS TRÊS LINHAS MÁGICAS DO REDIMENSIONAMENTO 👇 */
  resize: both; 
  min-width: 280px; /* O menor tamanho possível para não quebrar os botões */
  min-height: 350px;
}
@keyframes imaPopIn { 0% { opacity: 0; transform: scale(0.8) translateY(20px); } 100% { opacity: 1; transform: scale(1) translateY(0); } }

/* ==========================================================================
   CABEÇALHO
   ========================================================================== */
.ima-chat-header {
  background: rgba(10, 22, 50, 0.9); padding: 16px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--ima-chat-border); flex-shrink: 0; cursor: grab; z-index: 10;
}
.ima-chat-header:active { cursor: grabbing; }
.ima-chat-header-left { display: flex; align-items: center; gap: 12px; }
.ima-chat-avatar { width: 38px; height: 38px; border-radius: 12px; background: var(--ima-chat-primary); display: flex; align-items: center; justify-content: center; font-size: 18px; box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);}
.ima-chat-header h3 { font-size: 15px; font-weight: 800; color: var(--ima-chat-text); line-height: 1.1;}
.ima-chat-header p { font-size: 12px; color: var(--ima-chat-success); font-weight: 600; margin-top: 4px;}
.ima-chat-header-actions { display: flex; gap: 8px; }
.ima-chat-icon-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--ima-chat-border); background: transparent; color: var(--ima-chat-muted); cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; font-size: 14px;}
.ima-chat-icon-btn:hover { background: var(--ima-chat-bg-soft); color: #fff; }

/* ==========================================================================
   CORPO DAS MENSAGENS (ÁREA ELÁSTICA)
   ========================================================================== */
.ima-chat-body { 
  flex: 1; 
  overflow-y: auto; 
  overflow-x: hidden; /* Evita que o chat inteiro crie barra de rolagem horizontal */
  padding: 16px; 
  display: flex; flex-direction: column; gap: 12px; 
  scroll-behavior: smooth;
}
.ima-chat-body::-webkit-scrollbar { width: 6px; }
.ima-chat-body::-webkit-scrollbar-track { background: transparent; }
.ima-chat-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }
.ima-chat-body::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }

/* ==========================================================================
   BOLHAS DE MENSAGEM
   ========================================================================== */
.ima-msg-row { display: flex; width: 100%; }
.ima-msg-row.bot { justify-content: flex-start; }
.ima-msg-row.user { justify-content: flex-end; }
.ima-msg { 
  max-width: 98%; /* Larga o suficiente para caber a tabela */
  padding: 12px 14px; 
  border-radius: 16px; 
  font-size: 13px; 
  line-height: 1.5; 
  white-space: pre-wrap; 
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  box-sizing: border-box;
  overflow-x: auto; /* Trava de segurança para não estourar a tela */
}
.ima-msg.bot { background: rgba(37, 99, 235, 0.15); color: var(--ima-chat-text); border: 1px solid var(--ima-chat-border); border-bottom-left-radius: 4px; }
.ima-msg.user { background: linear-gradient(135deg, var(--ima-chat-primary), var(--ima-chat-primary-2)); color: #fff; border-bottom-right-radius: 4px; }

/* ==========================================================================
   CARD TABELAS (COMPACTADAS E BLINDADAS)
   ========================================================================== */
.ima-msg-card { 
  background: rgba(10, 22, 50, 0.95); 
  border: 1px solid var(--ima-chat-border); 
  border-radius: 12px; 
  padding: 8px; /* Reduzido para compactar */
  margin-top: 8px; 
  width: 100%; 
  box-sizing: border-box;
  white-space: normal !important; 
  overflow-x: auto; /* Rolagem interna da tabela se for minúscula a tela */
}
.ima-msg-card h4 { margin: 0 0 6px 0; font-size: 12px; font-weight: 800; color: var(--ima-chat-gold); display: flex; justify-content: space-between; align-items: center; }

/* Ajuste fino nas fontes e espaçamentos da Tabela */
.ima-table { width: 100%; border-collapse: collapse; margin-top: 2px; }
.ima-table th, .ima-table td { 
  font-size: 10px; /* Letra menor e elegante */
  padding: 4px; /* Linhas bem baixinhas */
  border-bottom: 1px dashed rgba(255,255,255,0.1); 
  white-space: nowrap; 
}
.ima-table th { color: var(--ima-chat-muted); font-weight: 800; text-transform: uppercase; font-size: 9px; letter-spacing: 0.5px; border-bottom: 1px solid rgba(255,255,255,0.2); padding-bottom: 4px;}
.ima-table th:first-child, .ima-table td:first-child { text-align: left; font-weight: 700; color: var(--ima-chat-muted);}
.ima-table th:last-child, .ima-table td:last-child { text-align: right;}
.ima-table tr:last-child td { border-bottom: none; padding-bottom: 0;}

/* ==========================================================================
   ANIMAÇÕES E BADGES
   ========================================================================== */
.ima-typing { display: inline-flex; align-items: center; gap: 4px; padding: 10px 14px; border-radius: 16px; border-bottom-left-radius: 4px; background: rgba(37, 99, 235, 0.15); border: 1px solid var(--ima-chat-border); }
.ima-dot { width: 6px; height: 6px; background: var(--ima-chat-primary); border-radius: 50%; animation: imaBlink 1.4s infinite; }
.ima-dot:nth-child(2) { animation-delay: .2s; }
.ima-dot:nth-child(3) { animation-delay: .4s; }
@keyframes imaBlink { 0%, 100% { opacity: 0.2; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

.ima-badge-safe { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 11px; color: var(--ima-chat-success); background: rgba(16,185,129,0.15); border-radius: 6px; padding: 6px 8px; width: 100%; font-weight: 600; border: 1px solid rgba(16,185,129,0.3);}

/* ==========================================================================
   ÁREA DE CONTROLES E BOTÕES RÁPIDOS
   ========================================================================== */
.ima-chat-quick { padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px solid var(--ima-chat-border); flex-shrink: 0; background: rgba(10, 22, 50, 0.7);}
.ima-quick-btn { border: 1px solid var(--ima-chat-border); background: var(--ima-chat-bg-soft); color: var(--ima-chat-text); border-radius: 999px; padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s ease; }
.ima-quick-btn:hover { background: var(--ima-chat-primary); color: #fff; border-color: var(--ima-chat-primary); transform: translateY(-2px);}

.ima-chat-input-area { padding: 16px; background: rgba(10, 22, 50, 0.95); border-top: 1px solid var(--ima-chat-border); flex-shrink: 0; z-index: 10;}
.ima-chat-input-area > div { background: transparent !important; padding: 0 !important; border-top: none !important; }

#ima-ai-input {
  background: rgba(14, 30, 64, 0.9) !important; color: var(--ima-chat-text) !important;
  border: 1px solid var(--ima-chat-border) !important; border-radius: 24px !important;
  padding: 14px 20px !important; font-size: 13px !important; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2) !important;
}
#ima-ai-input:focus { outline: none !important; border-color: var(--ima-chat-primary) !important; background: rgba(10, 22, 50, 1) !important;}

#ima-ai-send {
  background: linear-gradient(135deg, var(--ima-chat-primary), var(--ima-chat-primary-2)) !important; color: #fff !important;
  border-radius: 24px !important; padding: 10px 24px !important; font-weight: 800 !important; letter-spacing: 0.5px !important; transition: 0.2s !important;
}
#ima-ai-send:hover { opacity: 0.9 !important; transform: scale(1.05) !important;}

/* ==========================================================================
   SIMULAÇÃO MANUAL
   ========================================================================== */
.ima-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ima-form-field { display: flex; flex-direction: column; gap: 4px; }
.ima-form-field label { font-size: 10px; color: var(--ima-chat-muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;}
.ima-form-field input { width: 100%; border: 1px solid var(--ima-chat-border); background: rgba(14, 30, 64, 0.9); border-radius: 8px; padding: 10px; font-size: 14px; color: var(--ima-chat-gold); outline: none; transition: 0.2s; font-weight: 700; text-align: right;}
.ima-form-field input:focus { border-color: var(--ima-chat-primary); background: rgba(10, 22, 50, 1);}
.ima-form-actions { display: flex; gap: 10px; margin-top: 16px; }
.ima-btn-primary, .ima-btn-secondary { flex: 1; border: none; border-radius: 8px; padding: 12px; cursor: pointer; font-size: 13px; font-weight: 800; transition: 0.2s; text-transform: uppercase; letter-spacing: 0.5px;}
.ima-btn-primary { background: var(--ima-chat-primary); color: #fff; }
.ima-btn-primary:hover { background: var(--ima-chat-primary-2); }
.ima-btn-secondary { background: rgba(255,255,255,0.05); color: var(--ima-chat-text); border: 1px solid rgba(255,255,255,0.15);}
.ima-btn-secondary:hover { background: rgba(255,255,255,0.1); }

/* ==========================================================================
   RESPONSIVIDADE INTELIGENTE
   ========================================================================== */
@media (max-width: 600px) {
  .ima-chat-panel { 
    width: calc(100vw - 24px) !important; 
    height: 60vh !important; 
    bottom: 80px !important; 
    right: 12px !important; 
    left: 12px !important; 
    border-radius: 16px; 
  }
}

@media (min-width: 768px) {
  .ima-chat-panel {
    /* Tiramos o !important para o mouse do usuário ter permissão de alterar o tamanho */
    width: 360px; /* Começa um pouco mais fino por padrão para notebooks */
    height: 70vh; 
    max-width: 60vw; /* Permite ao usuário esticar o chat até o meio da tela se quiser */
    max-height: 85vh; 
    bottom: 110px; 
    right: 32px;
  }
  .ima-msg { font-size: 14px; }
  #ima-ai-input { font-size: 14px !important; }
}

/* ==========================================================================
   ÍCONES PERSONALIZADOS DA IMAUDIT
   ========================================================================== */
.ima-check-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
    margin: 0 4px 2px 2px;
    display: inline-block;
}