/* Assistente de IA do catálogo (Fase 2). Carregado só quando chatbot_enabled = 1,
   injetado por server/routes/catalogPage.js.
   Usa os tokens estruturais do tema do catálogo (--radius, --shadow, --gray*) para
   herdar forma/espaçamento de cada tenant, mas a COR é fixa (--chat-primary abaixo,
   igual ao avatar em chat.js): o assistente é uma marca própria do produto, não deve
   mudar de cor conforme o tema de cada catálogo. */

:root {
  --chat-primary: #102552;
  --chat-primary-dark: #0B1A39;
}

/* O widget inteiro (pilha e painel) fica ancorado ACIMA do .whatsapp-float. Esse botão
   mora em style.css com bottom/right 2rem, 56px de lado, e tamanhos próprios em dois
   breakpoints — os tokens abaixo são o único lugar que reproduz esses números, e é o que
   precisa mudar se o WhatsApp mudar de posição.
   O z-index tem que passar de 999 (o do .whatsapp-float): sem isso o botão verde fica por
   cima do painel aberto e cobre o campo de digitação. */
:root {
  --chat-lado: 2rem;
  --chat-base: calc(2rem + 56px + .75rem);
}

.chat-dock {
  position: fixed; right: var(--chat-lado); bottom: var(--chat-base); z-index: 1000;
  display: flex; flex-direction: column; align-items: flex-end; gap: .6rem;
  pointer-events: none;   /* a pilha em si não bloqueia clique no que está atrás */
}
.chat-dock > * { pointer-events: auto; }

.chat-fab {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem 1.1rem .45rem .45rem; border: 0; border-radius: 50px;
  background: var(--chat-primary); color: #fff;
  font-family: inherit; font-size: .95rem; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); cursor: pointer;
  transition: transform .15s, background .15s;
}
.chat-fab:hover { background: var(--chat-primary-dark); transform: translateY(-2px); }
.chat-fab[hidden] { display: none; }
.chat-fab__avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  background: #fff; display: block;
}

/* Balão proativo: aparece sozinho depois de um tempo na página, à esquerda do botão. */
.chat-convite {
  position: relative;
  max-width: min(280px, calc(100vw - 3rem));
  padding: .75rem 2rem .75rem .9rem;
  background: #fff; color: #1f2937; border-radius: var(--radius);
  font-size: .85rem; line-height: 1.4;
  box-shadow: 0 8px 28px rgba(0,0,0,.16);
  animation: chat-convite-entra .35s ease-out;
}
.chat-convite[hidden] { display: none; }
.chat-convite::after {
  content: ''; position: absolute; right: 26px; bottom: -7px;
  border: 7px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.chat-convite__fechar {
  position: absolute; top: .3rem; right: .4rem;
  background: transparent; border: 0; color: var(--gray);
  font-size: 1.1rem; line-height: 1; cursor: pointer; padding: .15rem .3rem;
}
@keyframes chat-convite-entra { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.chat-panel {
  position: fixed; right: var(--chat-lado); bottom: var(--chat-base); z-index: 1001;
  display: flex; flex-direction: column;
  width: 380px; max-width: calc(100vw - 2 * var(--chat-lado));
  height: 560px; max-height: calc(100dvh - var(--chat-base) - 1rem);
  background: #fff; border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(0,0,0,.24); overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem 1rem; background: var(--chat-primary); color: #fff; flex: 0 0 auto;
}
.chat-head strong { font-size: 1rem; font-weight: 600; }
.chat-head small { font-size: .75rem; opacity: .85; display: block; }
.chat-close {
  margin-left: auto; background: transparent; border: 0; color: #fff;
  font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 .25rem;
}

.chat-body {
  flex: 1 1 auto; overflow-y: auto; padding: 1rem;
  background: var(--bg-light); display: flex; flex-direction: column; gap: .75rem;
}

.chat-msg { max-width: 85%; padding: .65rem .85rem; border-radius: var(--radius); font-size: .9rem; line-height: 1.45; }
.chat-msg--bot  { background: #fff; color: #1f2937; align-self: flex-start; box-shadow: var(--shadow); }
.chat-msg--user { background: var(--chat-primary); color: #fff; align-self: flex-end; }
.chat-msg--erro { background: #FEF2F2; color: #991B1B; align-self: flex-start; }

.chat-cards { display: flex; flex-direction: column; gap: .5rem; align-self: stretch; }
.chat-card {
  display: flex; align-items: center; gap: .7rem; width: 100%;
  padding: .6rem; border: 1px solid var(--gray-light); border-radius: var(--radius);
  background: #fff; text-align: left; font-family: inherit; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.chat-card:hover { border-color: var(--chat-primary); transform: translateY(-1px); }
.chat-card img {
  width: 52px; height: 52px; flex: 0 0 auto;
  object-fit: cover; border-radius: 8px; background: var(--gray-light);
}
.chat-card__txt { min-width: 0; }
.chat-card__nome {
  font-size: .85rem; font-weight: 600; color: #1f2937; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chat-card__preco { font-size: .8rem; color: var(--chat-primary); font-weight: 600; margin-top: .15rem; }

.chat-digitando { display: flex; gap: .25rem; align-self: flex-start; padding: .75rem .85rem; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); }
.chat-digitando span { width: 7px; height: 7px; border-radius: 50%; background: var(--gray); animation: chat-pulso 1.2s infinite; }
.chat-digitando span:nth-child(2) { animation-delay: .2s; }
.chat-digitando span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-pulso { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.chat-foot { flex: 0 0 auto; border-top: 1px solid var(--gray-light); background: #fff; }
.chat-form { display: flex; gap: .5rem; padding: .75rem; }
.chat-form input {
  flex: 1 1 auto; min-width: 0; padding: .65rem .85rem;
  border: 1px solid var(--gray-light); border-radius: 50px;
  font-family: inherit; font-size: 16px; /* 16px evita o zoom automático do iOS ao focar */
  color: #1f2937;
}
.chat-form input:focus { outline: 2px solid var(--chat-primary); outline-offset: -1px; }
.chat-form button {
  flex: 0 0 auto; width: 42px; height: 42px; border: 0; border-radius: 50%;
  background: var(--chat-primary); color: #fff; font-size: 1.1rem; cursor: pointer;
}
.chat-form button:disabled { opacity: .5; cursor: default; }
.chat-aviso { padding: 0 .75rem .6rem; font-size: .7rem; color: var(--gray); text-align: center; }

/* Acompanha os breakpoints do .whatsapp-float (50px @768, 48px @480). */
@media (max-width: 768px) {
  :root { --chat-lado: 1rem; --chat-base: calc(1rem + 50px + .625rem); }
}

/* No celular o painel ocupa a tela inteira: 380px numa tela de 360 não cabe. */
@media (max-width: 480px) {
  :root { --chat-lado: .75rem; --chat-base: calc(.75rem + 48px + .5rem); }
  /* Em tela cheia o painel cobre o botão do WhatsApp — por isso o z-index acima de 999. */
  .chat-panel {
    right: 0; bottom: 0; width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh; border-radius: 0;
  }
  .chat-fab { padding: .4rem .9rem .4rem .4rem; font-size: .875rem; }
  .chat-fab__avatar { width: 34px; height: 34px; }
}
