/* ============================================
   Chat Widget — braitner.com.br
   Respeita o Design System: gradiente roxo,
   Inter, breakpoints 768/1024/1200
   ============================================ */

/* — Backdrop — */
#chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 9400;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#chat-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* — Botão flutuante — */
#chat-toggle {
  position: fixed;
  bottom: 30px; /* scrollToTop removido */
  right: 30px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 9500;
  padding: 0;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.45);
  transition:
    transform 0.3s ease,
    box-shadow 0.3s ease;
  overflow: hidden;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#chat-toggle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}

#chat-toggle:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 28px rgba(102, 126, 234, 0.55);
}

#chat-toggle.active {
  transform: scale(0.9);
}

/* Bolinha de notificação */
#chat-toggle::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #25d366;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: chat-pulse 2s infinite;
}

#chat-toggle.hide-dot::after {
  display: none;
}

@keyframes chat-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.75;
  }
}

/* — Caixa de diálogo — */
#chat-box {
  position: fixed;
  bottom: 100px;
  right: 30px;
  width: 360px;
  max-height: 520px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 9500;
  overflow: hidden;
  /* Estado inicial: oculto */
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

#chat-box.chat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* — Header da caixa — */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  object-fit: cover;
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-info strong {
  display: block;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: "Inter", sans-serif;
}

.chat-header-info span {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
}

.chat-header-info span::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #25d366;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
  flex-shrink: 0;
}
.chat-close-btn:hover {
  color: #fff;
}

/* — Mensagens — */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 4px;
}

.chat-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.5;
  font-family: "Inter", sans-serif;
  word-wrap: break-word;
  animation: bubbleIn 0.2s ease;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Agente (esquerda) */
.chat-bubble.agent {
  background: #f3f4f6;
  color: #333;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

/* Usuário (direita) */
.chat-bubble.user {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* Indicador de digitação */
.chat-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 10px 14px;
  background: #f3f4f6;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: typing-dot 1.2s infinite;
}
.chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-dot {
  0%,
  80%,
  100% {
    transform: scale(1);
    opacity: 0.5;
  }
  40% {
    transform: scale(1.3);
    opacity: 1;
  }
}

/* — Input area — */
.chat-input-area {
  padding: 12px 14px;
  border-top: 1px solid #eee;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 0.875rem;
  font-family: "Inter", sans-serif;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  color: #333;
  background: #fff;
}

#chat-input:focus {
  border-color: #667eea;
}

#chat-input::placeholder {
  color: #aaa;
}

#chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

#chat-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

#chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* — Responsivo Mobile — */
@media (max-width: 480px) {
  #chat-box {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 90px;
    max-height: 60vh;
  }

  #chat-toggle {
    right: 16px;
    bottom: 20px;
  }
}
