/* ==========================================================================
   MAKO — ASSISTENTE VIRTUAL DO GRUPO MAKRO CHUÍ
   Widget flutuante (canto inferior direito) com o logo da marca como avatar.
   100% funcional em regras (sem backend externo).
   ========================================================================== */

.chuibot-widget {
  /* Alias hacia los tokens de marca reales del sitio (src/app/globals.css)
     — este archivo se mantiene tal cual fue provisto, así que en vez de
     reescribir cada regla de abajo, se mapean acá los nombres que espera. */
  --color-primary-green: var(--color-primary);
  --color-dark-banner: var(--color-primary-dark);
  --color-primary-red: var(--color-secondary);
  --color-border-green: #bfe8cd;
  --color-section-bg: var(--color-surface);
  --color-text-dark: var(--color-text);
  --color-text-muted: var(--color-muted);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius-pill: 999px;

  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9997;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: 'Sanuk Pro', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --------------------------------------------------------------------------
   BOTÃO FLUTUANTE (FAB) — formato "blob" orgânico, nada de círculo clássico
   -------------------------------------------------------------------------- */
.chuibot-fab {
  position: relative;
  width: 52px;
  height: 52px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--color-primary-green) 0%, #087a34 100%);
  border-radius: 62% 38% 55% 45% / 45% 55% 45% 55%;
  box-shadow: 0 8px 20px rgba(13, 177, 75, 0.4), 0 2px 5px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chuibotBlobMorph 7s ease-in-out infinite, chuibotBob 3.4s ease-in-out infinite;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  flex-shrink: 0;
}

.chuibot-fab::before {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  border: 2px solid rgba(13, 177, 75, 0.55);
  animation: chuibotPulseRing 2.6s ease-out infinite;
  pointer-events: none;
}

.chuibot-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 14px 32px rgba(13, 177, 75, 0.55), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.chuibot-fab:active {
  transform: translateY(0) scale(0.97);
}

.chuibot-fab-face,
.chuibot-fab-x {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.25s ease;
}

/* Moedinha branca com o logo — garante contraste sobre o blob verde e é
   onde mora o efeito dinâmico ("estou aqui!"): um leve balanço contínuo
   mais um brilho que varre o ícone de tempos em tempos. */
.chuibot-fab-icon-coin {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.chuibot-fab-icon-coin img {
  width: 26px;
  height: auto;
  display: block;
  animation: chuibotIconWiggle 3.2s ease-in-out infinite;
}

.chuibot-fab-icon-coin::after {
  content: '';
  position: absolute;
  top: -60%;
  left: -70%;
  width: 35%;
  height: 220%;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.95), transparent);
  transform: rotate(20deg);
  animation: chuibotShine 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes chuibotIconWiggle {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-9deg); }
  60% { transform: rotate(7deg); }
}

@keyframes chuibotShine {
  0% { left: -70%; }
  40% { left: 130%; }
  100% { left: 130%; }
}

.chuibot-fab-x {
  opacity: 0;
  transform: scale(0.5) rotate(-90deg);
  color: #ffffff;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.chuibot-widget.is-open .chuibot-fab-face {
  opacity: 0;
  transform: scale(0.5) rotate(90deg);
}

.chuibot-widget.is-open .chuibot-fab-x {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.chuibot-widget.is-open .chuibot-fab {
  animation: none;
}

.chuibot-fab-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--color-primary-red);
  color: #ffffff;
  font-size: 9.5px;
  font-weight: 900;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #ffffff;
  box-shadow: 0 2px 6px rgba(215, 30, 32, 0.5);
  animation: chuibotBadgePop 0.35s ease;
}

@keyframes chuibotBlobMorph {
  0%, 100% { border-radius: 62% 38% 55% 45% / 45% 55% 45% 55%; }
  33% { border-radius: 45% 55% 40% 60% / 55% 45% 55% 45%; }
  66% { border-radius: 55% 45% 60% 40% / 40% 60% 40% 60%; }
}

@keyframes chuibotBob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -4px; }
}

@keyframes chuibotPulseRing {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.35); opacity: 0; }
}

@keyframes chuibotBadgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   BALÃO TEASER — o Makro AI puxa assunto sozinho
   -------------------------------------------------------------------------- */
.chuibot-teaser {
  position: relative;
  max-width: 210px;
  margin-bottom: 10px;
  background: #ffffff;
  color: var(--color-text-dark);
  border: 1.5px solid var(--color-border-green);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 26px 10px 14px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  animation: chuibotTeaserIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chuibotTeaserIn {
  0% { opacity: 0; transform: translateY(10px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.chuibot-teaser-close {
  position: absolute;
  top: 6px;
  right: 8px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 2px;
}

.chuibot-teaser-close:hover {
  color: var(--color-text-dark);
}

/* --------------------------------------------------------------------------
   PAINEL DO CHAT
   -------------------------------------------------------------------------- */
.chuibot-panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: 320px;
  max-width: calc(100vw - 24px);
  height: 460px;
  max-height: calc(100vh - 110px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22), 0 4px 14px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: scale(0.85) translateY(16px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid rgba(0, 0, 0, 0.06);
}

.chuibot-widget.is-open .chuibot-panel {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* Header */
.chuibot-header {
  position: relative;
  background: linear-gradient(120deg, var(--color-dark-banner) 0%, var(--color-primary-green) 100%);
  padding: 14px 14px 20px 14px;
  flex-shrink: 0;
}

.chuibot-header-content {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.chuibot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}

.chuibot-avatar img {
  width: 27px;
  height: auto;
  display: block;
}

.chuibot-header-text {
  flex: 1;
  min-width: 0;
}

.chuibot-name {
  font-size: 14px;
  font-weight: 900;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chuibot-status-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
  animation: statusPulse 1.6s ease-in-out infinite;
}

.chuibot-status {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.85);
  font-weight: 600;
  margin-top: 1px;
}

.chuibot-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.chuibot-close-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.chuibot-header-wave {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 18px;
  background: #ffffff;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  transform: scaleX(1.2);
}

/* Messages */
.chuibot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-section-bg);
}

.chuibot-messages::-webkit-scrollbar {
  width: 6px;
}

.chuibot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}

.chuibot-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: chuibotMsgIn 0.3s ease;
}

@keyframes chuibotMsgIn {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

.chuibot-msg-row.is-user {
  flex-direction: row-reverse;
}

.chuibot-msg-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 1.5px solid var(--color-border-green);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chuibot-msg-avatar img {
  width: 15px;
  height: auto;
  display: block;
}

.chuibot-bubble {
  max-width: 78%;
  padding: 8px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  font-weight: 600;
  word-wrap: break-word;
}

.chuibot-msg-row.is-bot .chuibot-bubble {
  background: #ffffff;
  color: var(--color-text-dark);
  border: 1.5px solid var(--color-border-green);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow-sm);
}

.chuibot-msg-row.is-user .chuibot-bubble {
  /* Verde oscuro oficial de la paleta de marca (Pantone 7735 C, #003f0b)
     en vez de un verde intermedio inventado. */
  background: linear-gradient(120deg, var(--color-primary-green), var(--color-dark-banner));
  color: #ffffff;
  border-radius: 16px 4px 16px 16px;
  font-weight: 700;
}

.chuibot-bubble a {
  color: inherit;
  text-decoration: underline;
}

.chuibot-bubble .chuibot-mini-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  background: var(--color-primary-red);
  color: #ffffff !important;
  font-weight: 800;
  font-size: 11px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  text-decoration: none !important;
}

/* --------------------------------------------------------------------------
   ESTADOS DE PROCESAMIENTO — regla del cliente (2026-09-18): en vez de un
   "Escribiendo..." fijo, la burbuja de espera muestra qué está haciendo el
   bot en cada momento (buscando productos, consultando stock/precio,
   preparando la respuesta...), actualizado en vivo desde
   chuibotSetProcessingState (ver chatbot.js) — nunca un texto inventado sin
   relación con el trabajo real en curso.
   -------------------------------------------------------------------------- */
.chuibot-typing-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px;
}

.chuibot-typing-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  white-space: nowrap;
  transition: opacity 0.16s ease, transform 0.16s ease;
  opacity: 1;
  transform: translateY(0);
}

.chuibot-typing-label.is-swapping {
  opacity: 0;
  transform: translateY(3px);
}

/* Respiración sutil del avatar mientras el bot "piensa" — solo en la fila
   del indicador (chuibot-typing-row), nunca en los avatares de mensajes ya
   enviados. */
.chuibot-msg-avatar.is-thinking {
  animation: chuibotAvatarBreathe 1.8s ease-in-out infinite;
}

@keyframes chuibotAvatarBreathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.09); }
}

.chuibot-typing-dots {
  display: flex;
  gap: 4px;
  padding: 4px 2px;
  flex-shrink: 0;
}

.chuibot-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-primary-green);
  opacity: 0.5;
  animation: chuibotTypingBounce 1.1s ease-in-out infinite;
}

.chuibot-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chuibot-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chuibotTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick replies */
.chuibot-quickreplies {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 12px 8px 12px;
  background: var(--color-section-bg);
  flex-shrink: 0;
}

.chuibot-chip {
  background: #ffffff;
  border: 1.5px solid var(--color-border-green);
  color: var(--color-text-dark);
  font-size: 10.5px;
  font-weight: 800;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chuibot-chip:hover {
  background: var(--color-primary-green);
  border-color: var(--color-primary-green);
  color: #ffffff;
  transform: translateY(-1px);
}

/* Input row */
.chuibot-input-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
  background: #ffffff;
  flex-shrink: 0;
}

.chuibot-input-row input {
  flex: 1;
  border: 1.5px solid #cbd5e1;
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  outline: none;
  color: var(--color-text-dark);
  min-width: 0;
}

.chuibot-input-row input:focus {
  border-color: var(--color-primary-green);
}

.chuibot-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary-green);
  color: #ffffff;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.chuibot-send-btn:hover {
  background: var(--color-dark-banner);
  transform: scale(1.06);
}

.chuibot-send-btn:active {
  transform: scale(0.94);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .chuibot-fab,
  .chuibot-fab::before,
  .chuibot-status-live-dot,
  .chuibot-fab-icon-coin img,
  .chuibot-fab-icon-coin::after,
  .chuibot-msg-avatar.is-thinking {
    animation: none !important;
  }
}

/* Mobile: bottom-sheet
   OBS: em telas ≤600px a .floating-app-bar (botão "Baixar App") vira uma
   barra de largura total ancorada no mesmo canto inferior direito — por
   isso o widget do chat sobe (bottom: 80px) para nunca se sobrepor a ela. */
@media (max-width: 600px) {
  .chuibot-widget {
    right: 12px;
    bottom: 80px;
  }

  .chuibot-panel {
    position: fixed;
    right: 8px;
    left: 8px;
    bottom: 80px;
    width: auto;
    max-width: none;
    height: min(58vh, 460px);
  }

  .chuibot-teaser {
    max-width: 190px;
  }
}
