/* ============================================================
   BENTINHO CHATBOT v2 — Catálise Gestão Integrada
   Componente reutilizável — assets/chatbot.css
   ============================================================ */

/* --- Variáveis --- */
:root {
  --cb-green:      #0e3227;
  --cb-green-mid:  #2e6b4f;
  --cb-accent:     #5db87a;
  --cb-white:      #ffffff;
  --cb-bg:         #f4f7f5;
  --cb-msg-bot:    #ffffff;
  --cb-msg-user:   #0e3227;
  --cb-radius:     16px;
  --cb-shadow:     0 8px 40px rgba(14,50,39,.18);
  --z-float-wa:    890;
  --z-float-ig:    891;
  --z-float-top:   892;
  --z-float-chat:  893;
  --z-chat-panel:  894;
  --z-cookie:      880;
}

/* ===== PILHA DE BOTÕES FLUTUANTES ===== */
#cb-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: var(--z-float-chat);
}

/* Botão genérico flutuante */
.cb-float {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border: none;
  cursor: pointer;
  box-shadow: 0 3px 14px rgba(0,0,0,.22);
  transition: transform .2s ease, box-shadow .2s ease, opacity .3s ease;
  flex-shrink: 0;
  position: relative;
}
.cb-float:hover { transform: scale(1.1); box-shadow: 0 6px 22px rgba(0,0,0,.3); }
.cb-float svg { width: 22px; height: 22px; display: block; }

/* Voltar ao topo — oculto por padrão */
#cb-top {
  background: rgba(14,50,39,.85);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-float-top);
  transition: opacity .3s ease, transform .2s ease;
}
#cb-top.show { opacity: 1; pointer-events: all; }

/* WhatsApp */
#cb-wa {
  background: #25d366;
  z-index: var(--z-float-wa);
}

/* Instagram */
#cb-ig {
  background: linear-gradient(135deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);
  z-index: var(--z-float-ig);
}

/* Botão do chat (FAB) */
#cb-fab {
  width: 56px;
  height: 56px;
  background: var(--cb-green);
  z-index: var(--z-float-chat);
  opacity: 0;
  pointer-events: none;
  overflow: visible;
}
#cb-fab.visible { opacity: 1; pointer-events: all; animation: cb-fab-in .5s cubic-bezier(.34,1.56,.64,1) both; }
#cb-fab img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; display: block; }

/* Badge */
#cb-badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 18px; height: 18px;
  background: #e53e3e;
  border-radius: 50%;
  border: 2px solid #fff;
  font-size: .62rem; font-weight: 700; color: #fff;
  display: none; align-items: center; justify-content: center;
}
#cb-badge.show { display: flex; animation: cb-badge-pop .3s cubic-bezier(.34,1.56,.64,1); }

/* Balão de boas-vindas */
#cb-balloon {
  position: fixed;
  bottom: 90px; right: 24px;
  background: #fff;
  color: #1a2820;
  font-size: .85rem; font-weight: 600;
  padding: 10px 16px;
  border-radius: 12px 12px 4px 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
  z-index: var(--z-float-chat);
  white-space: nowrap;
  opacity: 0; transform: translateY(8px);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
  max-width: calc(100vw - 100px);
  white-space: normal;
}
#cb-balloon.show { opacity: 1; transform: translateY(0); pointer-events: all; cursor: pointer; }
#cb-balloon::after {
  content: '';
  position: absolute;
  bottom: -6px; right: 18px;
  width: 12px; height: 12px;
  background: #fff;
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

/* ===== PAINEL DO CHAT ===== */
#cb-panel {
  position: fixed;
  bottom: 90px; right: 24px;
  width: min(380px, calc(100vw - 48px));
  max-height: min(560px, 80dvh);
  background: #fff;
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  z-index: var(--z-chat-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.97);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s cubic-bezier(.34,1.56,.64,1);
}
#cb-panel.open {
  opacity: 1; transform: none; pointer-events: all;
}

/* Cabeçalho */
#cb-header {
  background: linear-gradient(135deg, var(--cb-green), var(--cb-green-mid));
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#cb-header img {
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255,255,255,.3);
  flex-shrink: 0;
}
#cb-header-info { flex: 1; min-width: 0; }
#cb-header-info strong { display: block; color: #fff; font-size: .92rem; font-weight: 700; line-height: 1.2; }
#cb-header-info small { color: rgba(255,255,255,.75); font-size: .72rem; }
#cb-status { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
#cb-status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cb-accent); flex-shrink: 0; }
#cb-status-text { color: rgba(255,255,255,.75); font-size: .7rem; }
#cb-close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.8); padding: 6px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s; flex-shrink: 0;
  min-width: 44px; min-height: 44px;
}
#cb-close:hover { background: rgba(255,255,255,.15); color: #fff; }
#cb-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Mensagens */
#cb-messages {
  flex: 1; overflow-y: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--cb-bg); scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
#cb-messages::-webkit-scrollbar { width: 4px; }
#cb-messages::-webkit-scrollbar-thumb { background: rgba(14,50,39,.2); border-radius: 2px; }

.cb-msg {
  max-width: 88%; padding: 9px 13px;
  border-radius: 14px; font-size: .88rem; line-height: 1.55;
  word-break: break-word;
}
.cb-msg.bot {
  background: var(--cb-msg-bot); color: #1a2820;
  border-radius: 4px 14px 14px 14px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
  align-self: flex-start;
}
.cb-msg.bot a { color: var(--cb-green-mid); text-decoration: underline; }
.cb-msg.user {
  background: var(--cb-msg-user); color: #fff;
  border-radius: 14px 14px 4px 14px;
  align-self: flex-end;
}

/* Botões rápidos */
.cb-quick-wrap {
  display: flex; flex-direction: column; gap: 6px;
  align-self: flex-start; width: 100%; max-width: 300px;
}
.cb-quick-btn {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1.5px solid rgba(14,50,39,.18);
  color: var(--cb-green); border-radius: 10px;
  padding: 9px 13px; font-size: .83rem; font-weight: 600;
  cursor: pointer; text-align: left;
  transition: background .2s, border-color .2s, transform .15s;
  min-height: 44px; font-family: inherit;
  text-decoration: none; display: flex;
}
.cb-quick-btn:hover { background: #edf5f0; border-color: var(--cb-green-mid); transform: translateX(2px); }
.cb-quick-btn svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Botão WhatsApp */
.cb-wa-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: #25d366; color: #fff; border: none;
  border-radius: 10px; padding: 9px 14px;
  font-size: .83rem; font-weight: 700; cursor: pointer;
  text-decoration: none; min-height: 44px;
  transition: background .2s, transform .15s; font-family: inherit;
}
.cb-wa-btn:hover { background: #1da851; transform: translateY(-1px); }
.cb-wa-btn svg { width: 16px; height: 16px; fill: #fff; }

/* Typing */
.cb-typing {
  display: flex; gap: 4px; padding: 10px 14px;
  background: #fff; border-radius: 4px 14px 14px 14px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
  align-self: flex-start; width: fit-content;
}
.cb-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(14,50,39,.35);
  animation: cb-typing-dot 1.2s infinite;
}
.cb-typing span:nth-child(2) { animation-delay: .2s; }
.cb-typing span:nth-child(3) { animation-delay: .4s; }

/* Captura de contato */
.cb-capture-wrap { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.cb-capture-input {
  width: 100%; padding: 9px 13px; border: 1.5px solid rgba(14,50,39,.18);
  border-radius: 10px; font-size: .88rem; font-family: inherit;
  color: #1a2820; outline: none; box-sizing: border-box;
  transition: border-color .2s; background: #fff;
}
.cb-capture-input:focus { border-color: var(--cb-green-mid); }
.cb-capture-skip { background: none; border: none; color: rgba(14,50,39,.5); font-size: .78rem; cursor: pointer; text-align: left; padding: 2px 0; font-family: inherit; }
.cb-capture-skip:hover { color: var(--cb-green); }

/* Input area */
#cb-input-area {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid rgba(14,50,39,.08);
  background: #fff; flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
#cb-input {
  flex: 1; border: 1.5px solid rgba(14,50,39,.15); border-radius: 10px;
  padding: 9px 13px; font-size: 16px; font-family: inherit;
  color: #1a2820; outline: none; transition: border-color .2s;
  background: var(--cb-bg); min-height: 44px; resize: none;
}
#cb-input:focus { border-color: var(--cb-green-mid); background: #fff; }
#cb-input::placeholder { color: #7a9a8a; font-size: .88rem; }
#cb-char { font-size: .7rem; color: rgba(14,50,39,.4); white-space: nowrap; flex-shrink: 0; }
#cb-char.warn { color: #e53e3e; }
#cb-send {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--cb-green); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .2s, transform .15s;
}
#cb-send:hover:not(:disabled) { background: var(--cb-green-mid); transform: scale(1.05); }
#cb-send:disabled { opacity: .4; cursor: not-allowed; }
#cb-send svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Aviso de privacidade */
#cb-privacy-note { font-size: .7rem; color: rgba(14,50,39,.45); text-align: center; padding: 4px 12px 0; }

/* ===== MOBILE ===== */
@media (max-width: 480px) {
  #cb-panel {
    position: fixed; bottom: 0; left: 0; right: 0;
    width: 100%; max-width: 100%;
    max-height: 80dvh;
    border-radius: var(--cb-radius) var(--cb-radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #cb-stack { bottom: 16px; right: 16px; gap: 8px; }
  #cb-balloon { right: 16px; bottom: 84px; }
  /* Ocultar IG e voltar ao topo quando chat aberto */
  #cb-stack.chat-open #cb-ig,
  #cb-stack.chat-open #cb-top { display: none; }
  /* Travar scroll do fundo */
  body.cb-open { overflow: hidden; }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
  #cb-panel { max-height: 70dvh; }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
  #cb-panel { width: 340px; }
}

/* Desktop — mostrar apenas WA e chat no mobile */
@media (max-width: 480px) {
  #cb-ig { display: none; }
}

/* ===== ANIMAÇÕES ===== */
@keyframes cb-fab-in {
  from { opacity: 0; transform: scale(.6) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes cb-badge-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}
@keyframes cb-typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #cb-fab, #cb-panel, #cb-balloon { transition: none !important; animation: none !important; }
  .cb-typing span { animation: none !important; }
}

/* Acessibilidade — foco visível */
#cb-fab:focus-visible, #cb-close:focus-visible,
.cb-quick-btn:focus-visible, #cb-send:focus-visible,
.cb-wa-btn:focus-visible {
  outline: 3px solid var(--cb-accent);
  outline-offset: 2px;
}

/* Aria-live oculto */
#cb-live { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
