/**
 * ==============================================================================
 * PROJETO: Progressiva Vegetal Havana
 * FASE 3: Widget de Chatbot de Atendimento e Conversão (Somente Local)
 * ARQUIVO: public/assets/css/chatbot.css
 * DESCRIÇÃO: Estilos encapsulados para o Shadow DOM e host do widget.
 * ==============================================================================
 */

/* ------------------------------------------------------------------------------
   1. HOST DO WIDGET (No documento principal)
   ------------------------------------------------------------------------------ */
#havana-chat-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  pointer-events: none; /* Deixa cliques passarem em áreas vazias */
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------------------
   2. RECIPIENTE ENCAPSULADO NO SHADOW DOM
   ------------------------------------------------------------------------------ */
:host {
  display: block;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #222222;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ------------------------------------------------------------------------------
   3. BOTÃO FLUTUANTE DE ABERTURA (LAUNCHER)
   ------------------------------------------------------------------------------ */
.chat-launcher {
  pointer-events: auto;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #EC538E 0%, #D83E7A 100%);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(236, 83, 142, 0.45), 0 2px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
  z-index: 10000;
  outline: none;
}

.chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 22px rgba(236, 83, 142, 0.55), 0 3px 8px rgba(0, 0, 0, 0.15);
}

.chat-launcher:focus-visible {
  outline: 3px solid #61CE70;
  outline-offset: 3px;
}

.chat-launcher:active {
  transform: scale(0.95);
}

.chat-launcher-icon {
  width: 28px;
  height: 28px;
  fill: currentColor;
  transition: transform 0.2s ease;
}

.chat-launcher[aria-expanded="true"] .chat-launcher-icon-chat {
  display: none;
}

.chat-launcher[aria-expanded="false"] .chat-launcher-icon-close {
  display: none;
}

/* Badge de notificação sutil */
.chat-launcher-badge {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 14px;
  height: 14px;
  background-color: #61CE70;
  border: 2px solid #FFFFFF;
  border-radius: 50%;
}

/* ------------------------------------------------------------------------------
   4. PAINEL PRINCIPAL DO CHAT
   ------------------------------------------------------------------------------ */
.chat-panel {
  pointer-events: auto;
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 110px);
  background-color: #FFFFFF;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 2px 10px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
  z-index: 9999;
}

.chat-panel.aberto {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ------------------------------------------------------------------------------
   5. CABEÇALHO DO CHAT
   ------------------------------------------------------------------------------ */
.chat-header {
  background: linear-gradient(135deg, #EC538E 0%, #D83E7A 100%);
  color: #FFFFFF;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-color: #FFFFFF;
  color: #EC538E;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.chat-title-group {
  display: flex;
  flex-direction: column;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: #FFFFFF;
  line-height: 1.2;
}

.chat-subtitle {
  font-size: 12px;
  color: #FFE1EE;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background-color: #61CE70;
  border-radius: 50%;
  display: inline-block;
}

.chat-btn-fechar {
  background: transparent;
  border: none;
  color: #FFFFFF;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  outline: none;
}

.chat-btn-fechar:hover {
  background-color: rgba(255, 255, 255, 0.18);
}

.chat-btn-fechar:focus-visible {
  outline: 2px solid #FFFFFF;
}

/* ------------------------------------------------------------------------------
   6. ÁREA DE MENSAGENS E CONTEÚDO
   ------------------------------------------------------------------------------ */
.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #FAFAFB;
  scroll-behavior: smooth;
}

/* Scrollbar estilizada */
.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #E0E0E0;
  border-radius: 4px;
}

.chat-bubble {
  max-width: 88%;
  padding: 11px 14px;
  font-size: 13.5px;
  line-height: 1.45;
  border-radius: 14px;
  word-break: break-word;
  animation: fadeInBubble 0.22s ease-out;
}

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

.chat-bubble-bot {
  align-self: flex-start;
  background-color: #FFFFFF;
  color: #222222;
  border: 1px solid #ECECEC;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.chat-bubble-user {
  align-self: flex-end;
  background-color: #EC538E;
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(236, 83, 142, 0.25);
}

.chat-bubble p + p {
  margin-top: 8px;
}

/* Efeito sutil de digitação */
.chat-typing {
  align-self: flex-start;
  background-color: #FFFFFF;
  border: 1px solid #ECECEC;
  padding: 10px 14px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: #EC538E;
  border-radius: 50%;
  opacity: 0.6;
  animation: typingPulse 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 typingPulse {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-4px); opacity: 1; }
}

/* ------------------------------------------------------------------------------
   7. CHIPS DE PERGUNTAS RÁPIDAS
   ------------------------------------------------------------------------------ */
.chat-quick-questions {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
  animation: fadeInBubble 0.25s ease-out;
}

.quick-question-btn {
  background-color: #FFFFFF;
  border: 1px solid #FFC1D9;
  color: #D83E7A;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(236, 83, 142, 0.06);
  outline: none;
}

.quick-question-btn:hover {
  background-color: #FFE1EE;
  border-color: #EC538E;
  color: #B52B62;
  transform: translateY(-1px);
}

.quick-question-btn:focus-visible {
  outline: 2px solid #EC538E;
  outline-offset: 1px;
}

.quick-question-btn::after {
  content: "→";
  font-size: 14px;
  opacity: 0.7;
}

/* ------------------------------------------------------------------------------
   8. AÇÕES EMBUTIDAS NAS RESPOSTAS (CHECKOUT E OPÇÕES CONTEXTUAIS)
   ------------------------------------------------------------------------------ */
.chat-actions-container {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
}

.chat-btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
  text-align: center;
}

.chat-btn-action:hover {
  transform: translateY(-1px);
}

.chat-btn-action:focus-visible {
  outline: 2px solid #222222;
  outline-offset: 2px;
}

.chat-btn-checkout {
  background-color: #61CE70;
  color: #FFFFFF;
  box-shadow: 0 3px 8px rgba(97, 206, 112, 0.35);
}

.chat-btn-checkout:hover {
  background-color: #4EB85D;
}

.chat-btn-opcao {
  background-color: #FFFFFF;
  border: 1px solid #FFC1D9;
  color: #D83E7A;
}

.chat-btn-opcao:hover {
  background-color: #FFE1EE;
  border-color: #EC538E;
  color: #B52B62;
}

.chat-btn-voltar {
  background-color: #EFEFEF;
  color: #555555;
}

.chat-btn-voltar:hover {
  background-color: #E2E2E2;
  color: #222222;
}

/* ------------------------------------------------------------------------------
   9. RODAPÉ DO CHAT
   ------------------------------------------------------------------------------ */
.chat-footer {
  padding: 10px 14px;
  background-color: #FFFFFF;
  border-top: 1px solid #ECECEC;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-disclaimer {
  font-size: 11px;
  color: #888888;
  line-height: 1.25;
}

.chat-btn-reset {
  background: transparent;
  border: 1px solid #E0E0E0;
  color: #666666;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  outline: none;
}

.chat-btn-reset:hover {
  background-color: #F5F5F5;
  color: #222222;
  border-color: #CCCCCC;
}

.chat-btn-reset:focus-visible {
  outline: 2px solid #EC538E;
}

/* ------------------------------------------------------------------------------
   10. RESPONSIVIDADE E ACESSIBILIDADE MOBILE
   ------------------------------------------------------------------------------ */
@media (max-width: 480px) {
  #havana-chat-root {
    bottom: 12px;
    right: 12px;
  }

  .chat-launcher {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    right: 14px;
    width: 54px;
    height: 54px;
  }

  .chat-panel {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: 72vh;
    max-height: calc(100vh - 100px - env(safe-area-inset-bottom, 0px));
    border-radius: 16px;
  }

  .chat-bubble {
    max-width: 92%;
    font-size: 13px;
  }

  .quick-question-btn {
    font-size: 12.5px;
    padding: 8px 10px;
  }
}

@media (max-width: 360px) {
  .chat-panel {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    height: 75vh;
  }

  .chat-launcher {
    width: 50px;
    height: 50px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    right: 10px;
  }
}

/* Respeito a usuários com preferência por redução de movimento */
@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-panel,
  .chat-bubble,
  .quick-question-btn,
  .chat-btn-action,
  .typing-dot {
    animation: none !important;
    transition: none !important;
  }
}
