/* ===================================================
   CHAT DE SUPORTE IA — JRSOPENSOFTWARE
   Visual Identity: Tech Navy & Electric Cyan
   =================================================== */

:root {
  --jrs-blue-primary: #0284c7;
  --jrs-blue-dark: #071527;
  --jrs-blue-mid: #0369a1;
  --jrs-cyan: #38bdf8;
  --jrs-glow: rgba(2, 132, 199, 0.35);
  --jrs-glow-strong: rgba(56, 189, 248, 0.5);
}

#chat-suporte-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Botão flutuante (FAB) */
#chat-fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #ffffff;
  color: #fff;
  border: 2.5px solid var(--jrs-blue-primary);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35), 0 0 16px var(--jrs-glow);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
  padding: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
#chat-fab:active,
#chat-fab.is-dragging {
  cursor: grabbing !important;
  transform: scale(1.08);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), 0 0 24px var(--jrs-glow-strong);
}
#chat-fab:hover:not(.is-dragging) {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.38), 0 0 22px var(--jrs-glow-strong);
}
#chat-fab img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: contain;
  padding: 4px;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
#chat-fab.chat-open {
  background: var(--jrs-blue-primary);
  border-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 24px rgba(2, 132, 199, 0.6);
}
#chat-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

/* Janela do chat */
#chat-janela {
  position: fixed;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 40px);
  background: var(--bg-card, #1e293b);
  border: 1px solid rgba(56, 189, 248, 0.2);
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5), 0 0 30px rgba(2, 132, 199, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 99998;
}

@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Cabeçalho Tecnológico JRS */
#chat-header {
  background: linear-gradient(135deg, #071527 0%, #0369a1 60%, #0284c7 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  position: relative;
}
#chat-header::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--jrs-cyan), transparent);
  opacity: 0.6;
}
#chat-header.is-dragging {
  cursor: grabbing !important;
}
#chat-header button {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
#chat-header button:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
}
#chat-avatar {
  width: 38px;
  height: 38px;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), 0 0 10px rgba(56, 189, 248, 0.4);
  flex-shrink: 0;
}
#chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 2px;
}
#chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #38bdf8;
  display: inline-block;
  box-shadow: 0 0 8px #38bdf8;
  animation: pulseDot 2s infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}
#chat-header div { color: #fff; }

/* Área de mensagens */
#chat-mensagens {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.chat-msg p { margin: 0 0 4px; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg code {
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.chat-msg .chat-step {
  background: rgba(2, 132, 199, 0.08);
  border-left: 3px solid var(--jrs-blue-primary);
  padding: 4px 8px;
  margin: 4px 0;
  border-radius: 0 6px 6px 0;
  font-size: 13px;
}
.chat-msg .chat-bullet {
  padding-left: 16px;
  position: relative;
  margin: 2px 0;
  font-size: 13px;
}
.chat-msg .chat-bullet::before {
  content: '•';
  position: absolute;
  left: 4px;
  color: var(--jrs-blue-primary);
  font-weight: bold;
}

/* Botões de Ações e Tópicos Rápidos do Robô */
.chat-options-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.chat-btn-action {
  background: var(--bg-primary, #0f172a);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 8px;
  padding: 8px 11px;
  color: var(--text-primary, #f8fafc);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
}
.chat-btn-action:hover {
  background: rgba(2, 132, 199, 0.12);
  border-color: var(--jrs-blue-primary);
  color: var(--jrs-cyan);
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.2);
  transform: translateX(3px);
}
.chat-btn-action .chip-icon {
  font-size: 14px;
  flex-shrink: 0;
}
.chat-back-btn {
  margin-top: 8px;
  background: transparent;
  border: 1px dashed var(--border, rgba(255, 255, 255, 0.15));
  color: var(--text-muted, #94a3b8);
  font-size: 11.5px;
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}
.chat-back-btn:hover {
  border-color: var(--jrs-blue-primary);
  color: var(--jrs-cyan);
}

.chat-msg-ia {
  background: var(--bg-secondary, #1e293b);
  color: var(--text-primary, #f8fafc);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.chat-msg-usuario {
  background: linear-gradient(135deg, #0284c7 0%, #2563eb 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.3);
}
.chat-msg-sistema {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger, #ef4444);
  border: 1px solid rgba(239, 68, 68, 0.25);
  align-self: center;
  font-size: 12px;
  text-align: center;
}

/* Indicador de digitação */
#chat-typing {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
#chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--jrs-cyan);
  animation: typingBounce 1.2s ease-in-out infinite;
}
#chat-typing span:nth-child(2) { animation-delay: 0.2s; }
#chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Área de input */
#chat-input-area {
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: var(--bg-card, #1e293b);
}
#chat-input {
  flex: 1;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  resize: none;
  background: var(--bg-secondary, #0f172a);
  color: var(--text-primary, #f8fafc);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.4;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: all 0.2s ease;
}
#chat-input:focus {
  border-color: var(--jrs-blue-primary);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.25);
}
#chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}
#chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#chat-send-btn:not(:disabled):hover {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.5);
}

/* Mobile: ocupa tela toda */
@media (max-width: 480px) {
  #chat-janela {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  #chat-suporte-widget { bottom: 16px; right: 16px; }
}
