/*
 * Agent Chatbot Widget — Stylesheet
 * --------------------------------------------------
 * Styles for the floating action button and chat window.
 * Mobile: opens fullscreen (≤480px), locks scroll, prevents zoom.
 * Desktop: fixed bottom-right panel, floats above all site elements.
 */

/* ─── Floating Action Button ─────────────────────────────────────────────── */
.agent-chatbot-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 0 18px;
  height: 48px;
  border-radius: 24px;
  background: #000000;
  color: #fff;
  border: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.agent-chatbot-btn-text {
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.5px;
  white-space: nowrap;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* Animated gradient text — loops through brand colors */
  background: linear-gradient(270deg, #2563eb, #4f46e5, #7c3aed, #4f46e5, #2563eb);
  background-size: 500% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: chatbotTextGradient 6s linear infinite;
}

@keyframes chatbotTextGradient {
  0% { background-position: 0% 50%; }
  100% { background-position: 125% 50%; }
}

.agent-chatbot-btn:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.agent-chatbot-btn:active {
  transform: translateY(0) scale(0.95);
}

.agent-chatbot-btn i {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.agent-chatbot-btn.is-open {
  width: 48px;
  padding: 0;
  border-radius: 50%;
}

.agent-chatbot-btn.is-open .agent-chatbot-btn-text {
  display: none;
}

.agent-chatbot-btn.is-open .bi-x-lg {
  opacity: 1;
  transform: scale(1) rotate(0);
}

.agent-chatbot-btn:not(.is-open) .bi-x-lg {
  opacity: 0;
  transform: scale(0.5) rotate(45deg);
  position: absolute;
}

/* ─── Chat Window ────────────────────────────────────────────────────────── */
.agent-chatbot-window {
  position: fixed;
  bottom: 110px;
  right: 30px;
  width: 360px;
  height: auto;
  min-height: 250px;
  max-height: calc(100vh - 120px);
  background: rgba(255, 255, 255, 0.65); /* semi-transparent glass background */
  backdrop-filter: blur(24px); /* strong blur for glassmorphism effect */
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.4); /* subtle glass border */
  border-radius: 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.5); /* outer shadow + inner highlight */
  display: flex;
  flex-direction: column;
  z-index: 2147483647;
  overflow: hidden;
  
  /* Initial hidden state — revealed by adding .is-open via JS */
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.agent-chatbot-window.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ─── Chat Header (avatars + status) ────────────────────────────────────── */
.agent-chatbot-header {
  padding: 16px 20px;
  background: transparent;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chatbot-team-avatars {
  display: flex;
  align-items: center;
}

.chatbot-avatar-img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  object-fit: cover;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.chatbot-avatar-img:nth-child(2) {
  margin-left: -16px;
  z-index: 1;
}

.agent-chatbot-title-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-left: 4px;
}

.agent-chatbot-status-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.agent-chatbot-status-row h4 {
  margin: 0;
  color: #1e293b;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.agent-chatbot-subtitle {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 2px;
  line-height: 1.2;
}

/* ─── Chat Body (message feed) ──────────────────────────────────────────── */
.agent-chatbot-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.agent-chatbot-body::-webkit-scrollbar {
  width: 6px;
}
.agent-chatbot-body::-webkit-scrollbar-thumb {
  background-color: rgba(0,0,0,0.15);
  border-radius: 10px;
}

.agent-message-wrapper {
  display: flex;
  width: 100%;
  gap: 8px;
}

.agent-message-wrapper.bot {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.agent-message-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-bot-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: #1e293b;
}

.agent-bot-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px; /* Quadrado arredondado como na imagem */
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  animation: agentMsgFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.agent-bot-avatar .avatar-letter {
  font-weight: 900;
  font-size: 1rem;
  background: linear-gradient(270deg, #2563eb, #4f46e5, #7c3aed, #4f46e5, #2563eb);
  background-size: 500% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: chatbotTextGradient 6s linear infinite;
}

.agent-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.85rem;
  line-height: 1.4;
  animation: agentMsgFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  opacity: 0;
  transform: translateY(10px);
}

@keyframes agentMsgFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.agent-message.bot {
  background: transparent;
  color: #334155;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  max-width: 100%;
}

.agent-message-wrapper.user {
  justify-content: flex-end;
  margin-top: 8px; /* extra top gap so user replies don't merge with bot rows */
}

.agent-message.user {
  background: #f1f5f9;
  color: #334155;
  border-bottom-right-radius: 4px;
  box-shadow: none;
}

/* ─── Chat Footer (text input + disclaimer) ─────────────────────────────── */
.agent-chatbot-footer {
  padding: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: transparent;
}

.chatbot-disclaimer {
  text-align: center;
  font-size: 0.7rem;
  color: #94a3b8;
  margin-top: 8px;
  font-weight: 500;
}

.agent-chatbot-input-wrap {
  display: flex;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 24px;
  padding: 4px 16px;
  transition: border-color 0.3s ease, background 0.3s ease;
}

.agent-chatbot-input-wrap:focus-within {
  border-color: #cbd5e1;
  background: #ffffff;
  outline: none !important;
  box-shadow: none !important;
}

.agent-chatbot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #1e293b;
  font-size: 0.95rem;
  font-family: inherit;
  padding: 8px 0;
  box-shadow: none !important;
}

.agent-chatbot-input:focus,
.agent-chatbot-input:active {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

.agent-chatbot-input::placeholder {
  color: #94a3b8;
}

.agent-chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #7c3aed;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.agent-chatbot-send:hover {
  background: #6d28d9;
  transform: scale(1.05);
}

/* ─── Mobile Overrides (≤480px) & Mobile Landscape ──────────────────────── */
@media (max-width: 480px), (max-height: 550px) and (max-width: 960px) and (orientation: landscape) {
  /* Esconde o botão flutuante quando o chat está aberto no mobile */
  .agent-chatbot-btn.is-open {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.8) !important;
  }

  /* Fullscreen no mobile (cobrindo tudo) */
  .agent-chatbot-window {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100dvh !important; /* Usa dynamic viewport para acompanhar o teclado */
    max-height: 100dvh !important;
    border-radius: 0 !important;
    transform-origin: bottom center !important;
    z-index: 999999 !important; /* Força ficar acima do header do site */
  }

  /* Impede o zoom forçado do iOS ao focar em inputs (iOS dá zoom se fonte < 16px) */
  .chatbot-field input,
  .agent-chatbot-input {
    font-size: 16px !important;
  }

  /* Animação de entrada mobile: sobe de baixo */
  .agent-chatbot-window.is-open {
    transform: translateY(0) scale(1) !important;
  }
}

/* Body scroll-lock — class added/removed by JS when chat opens/closes on mobile */
body.agent-chatbot-mobile-open {
  overflow: hidden !important;
  height: 100dvh; /* Acompanha o teclado */
  overscroll-behavior-y: none; /* Evita o bounce effect no iOS */
  touch-action: none; /* Bloqueia scroll da pagina principal */
}

/* ─── Minimize Button (mobile only — top-right chevron) ─────────────────── */
.agent-chatbot-minimize-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  color: #475569;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.agent-chatbot-minimize-btn:hover {
  background: rgba(0, 0, 0, 0.12);
  transform: scale(1.08);
}

.agent-chatbot-minimize-btn i {
  font-size: 1rem;
}

@media (max-width: 480px), (max-height: 550px) and (max-width: 960px) and (orientation: landscape) {
  .agent-chatbot-minimize-btn {
    display: flex !important;
  }
}



/* Onboarding Card (Start Chat) */
.chatbot-start-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  border: 1px solid #e2e8f0;
  margin-top: auto;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  animation: agentMsgFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  overflow: hidden;
}

.chatbot-start-card-body {
  padding: 16px 20px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chatbot-start-card-footer {
  padding: 14px 20px;
  border-top: 1px solid #f1f5f9;
  background: #f8fafc;
}

.chatbot-intro-typing {
  margin-bottom: 2px;
  padding: 0 4px;
}

.chatbot-typing-container {
  color: #1e293b;
  font-size: 1.1rem;
  font-weight: 400;
  line-height: 1.3;
  margin: 0;
}

.chatbot-start-card h3 {
  color: #1e293b;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.chatbot-typing-container {
  color: #1e293b;
  font-size: 1.1rem;
  font-weight: 400;
  line-height: 1.3;
  margin: 0;
}

/* Chatbot Lead Form */
.chatbot-form-card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  border: 1px solid #e2e8f0;
  margin-top: auto;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: agentMsgFadeIn 0.3s ease forwards;
}

.chatbot-lead-form {
  display: flex;
  flex-direction: column;
}

.chatbot-field {
  display: flex;
  flex-direction: column;
  padding: 0 20px 10px 20px;
}

.chatbot-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 2px;
}

.chatbot-field input {
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #1e293b;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  font-family: inherit;
}

.chatbot-field input:focus {
  border-color: #cbd5e1;
  box-shadow: none;
}

.chatbot-start-card p {
  color: #64748b;
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 0;
}

.chatbot-start-btn {
  width: 100%;
  background: transparent;
  border: none;
  color: #0f172a;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-start-btn:hover {
  opacity: 0.8;
  transform: translateX(4px);
}

.chatbot-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
  opacity: 0.35;
  animation: chatbotTypingDot 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatbotTypingDot {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Mobile Landscape Optimization (e.g. iPhone rotated sideways) */
@media (max-height: 550px) and (orientation: landscape) {
  /* Smaller floating button */
  .agent-chatbot-btn {
    bottom: 16px !important;
    right: 16px !important;
    height: 40px !important;
    padding: 0 14px !important;
    border-radius: 20px !important;
  }
  
  .agent-chatbot-btn.is-open {
    width: 40px !important;
    padding: 0 !important;
  }

  /* Centered container layout for readability on wide rotated landscape screens */
  .agent-chatbot-header,
  .agent-chatbot-body,
  .agent-chatbot-footer {
    max-width: 600px !important;
    margin-left: auto !important;
    margin-right: auto !important;
    width: 100% !important;
  }

  /* Reduce padding on header to save vertical height */
  .agent-chatbot-header {
    padding: 10px 14px !important;
    gap: 8px !important;
  }
  
  .chatbot-avatar-img {
    width: 32px !important;
    height: 32px !important;
  }

  .agent-chatbot-status-row h4 {
    font-size: 0.85rem !important;
  }

  .agent-chatbot-subtitle {
    font-size: 0.72rem !important;
  }

  /* Snug body container for messages */
  .agent-chatbot-body {
    padding: 12px 14px !important;
    gap: 10px !important;
  }

  /* Style adjustment for fields and onboarding start card inside chat */
  .chatbot-form-card,
  .chatbot-start-card {
    border-radius: 10px !important;
  }

  .chatbot-start-card-body {
    padding: 8px 12px 4px 12px !important;
  }

  .chatbot-start-card-body p {
    font-size: 0.8rem !important;
    line-height: 1.2 !important;
  }

  .chatbot-lead-form {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0 10px !important;
    padding: 0 12px 6px 12px !important;
  }

  .chatbot-field {
    padding: 0 !important;
    margin-bottom: 6px !important;
  }

  .chatbot-field:nth-child(1) {
    grid-column: 1 / 2 !important;
  }

  .chatbot-field:nth-child(2) {
    grid-column: 2 / 3 !important;
  }

  .chatbot-field:nth-child(3) {
    grid-column: 1 / 3 !important;
  }

  .chatbot-field label {
    font-size: 0.75rem !important;
    margin-bottom: 1px !important;
  }

  .chatbot-field input {
    padding: 6px 10px !important;
    font-size: 16px !important; /* Mantenha 16px para evitar zoom forçado no iOS Safari deitado */
    border-radius: 6px !important;
    height: 34px !important;
  }

  .chatbot-lead-form .chatbot-start-card-footer {
    grid-column: 1 / 3 !important;
    padding: 8px 0 0 0 !important;
    background: transparent !important;
    border-top: none !important;
  }

  .chatbot-lead-form .chatbot-start-btn {
    height: 36px !important;
    font-size: 0.9rem !important;
  }

  .chatbot-start-card {
    padding: 10px !important;
  }

  /* Style adjustment for the chat footer input bar */
  .agent-chatbot-footer {
    padding: 8px 14px !important;
  }

  .agent-chatbot-input {
    font-size: 16px !important; /* Mantenha 16px para evitar zoom no iOS Safari */
    padding: 6px 10px !important;
  }

  .agent-chatbot-send {
    width: 32px !important;
    height: 32px !important;
  }
}
