/* =========================================================
   CHAT — assistente do consultório
   Usa os mesmos tokens de css/base.css para parecer parte
   do site. Nenhuma regra de layout do site é alterada aqui.
   ========================================================= */

/* acima do header do site (z-index 100) e do menu mobile (99),
   abaixo do lightbox das fotos (300) */
.chat-fab {
  position: fixed;
  right: clamp(1rem, 3vw, 1.75rem);
  /* soma a area segura: o botao nao pode cair em cima da barra de gesto */
  bottom: calc(clamp(1rem, 3vw, 1.75rem) + env(safe-area-inset-bottom, 0px));
  z-index: 250;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.8rem 1.15rem 0.8rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--teal-500), var(--blue-500));
  color: var(--navy-950);
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease), opacity 0.25s var(--ease);
}

.chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.chat-fab:focus-visible {
  outline: 2px solid var(--teal-500);
  outline-offset: 3px;
}

.chat-fab svg {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
}

.chat-fab[hidden] {
  display: none;
}

/* ---------------- painel ---------------- */
.chat-panel {
  position: fixed;
  right: clamp(1rem, 3vw, 1.75rem);
  bottom: calc(clamp(1rem, 3vw, 1.75rem) + 60px);
  z-index: 251;
  width: min(384px, calc(100vw - 2rem));
  height: min(540px, calc(100vh - 8rem));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: bottom right;
  transition: opacity 0.24s var(--ease), transform 0.24s var(--ease);
}

.chat-panel[hidden] {
  display: none;
}

.chat-panel.is-closing {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
}

/* ---------------- topo ---------------- */
.chat-topo {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.95rem 1.05rem;
  background: var(--navy-900);
  color: var(--on-dark);
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: rgba(20, 214, 196, 0.18);
  border: 1px solid rgba(20, 214, 196, 0.42);
  color: var(--teal-300);
}

.chat-avatar svg {
  width: 19px;
  height: 19px;
}

.chat-topo-texto {
  min-width: 0;
  flex: 1 1 auto;
}

.chat-topo-texto strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.93rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chat-topo-texto span {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.73rem;
  color: var(--on-dark-mute);
}

.chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal-400);
  flex: 0 0 auto;
}

.chat-fechar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--on-dark-soft);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.2s var(--ease);
}

.chat-fechar:hover {
  background: rgba(255, 255, 255, 0.16);
  color: var(--on-dark);
}

.chat-fechar svg {
  width: 16px;
  height: 16px;
}

/* ---------------- mensagens ---------------- */
.chat-mensagens {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 1.05rem;
  background: var(--surface-alt);
}

.chat-msg {
  max-width: 86%;
  padding: 0.7rem 0.9rem;
  border-radius: 16px;
  font-size: 0.89rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: chatEntra 0.28s var(--ease);
}

@keyframes chatEntra {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.chat-msg--agente {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
  color: var(--ink-800);
}

.chat-msg--visitante {
  align-self: flex-end;
  background: linear-gradient(120deg, var(--teal-500), var(--blue-500));
  border-bottom-right-radius: 5px;
  color: var(--navy-950);
  font-weight: 500;
}

.chat-msg--erro {
  align-self: stretch;
  max-width: 100%;
  background: #fdeeee;
  border: 1px solid rgba(199, 62, 62, 0.24);
  color: #8f2a2a;
}

/* três pontinhos */
.chat-digitando {
  display: inline-flex;
  gap: 4px;
  padding: 0.85rem 0.95rem;
  align-items: center;
}

.chat-digitando span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--teal-600);
  animation: chatPula 1.1s infinite ease-in-out;
}

.chat-digitando span:nth-child(2) { animation-delay: 0.15s; }
.chat-digitando span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatPula {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* atalho para o WhatsApp */
.chat-atalho {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-radius: 11px;
  background: #fff;
  border: 1px solid rgba(15, 187, 169, 0.4);
  color: #0a7a6e;
  font-size: 0.83rem;
  font-weight: 600;
  text-decoration: none;
}

.chat-atalho:hover {
  background: var(--surface-soft);
}

/* opções de abertura — só na primeira mensagem da conversa */
.chat-opcoes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.6rem;
}

.chat-opcao {
  padding: 0.5rem 0.85rem;
  border-radius: 11px;
  background: #fff;
  border: 1px solid rgba(15, 187, 169, 0.55);
  color: #0a7a6e;
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.chat-opcao:hover {
  background: var(--surface-soft);
}

.chat-opcao:focus-visible {
  outline: 2px solid rgba(15, 187, 169, 0.7);
  outline-offset: 2px;
}

/* ---------------- campo ---------------- */
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.chat-campo {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 96px;
  padding: 0.62rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink-900);
  background: var(--surface-alt);
  resize: none;
  overflow-y: auto;
}

.chat-campo:focus {
  outline: none;
  border-color: var(--teal-500);
  background: var(--surface);
}

.chat-campo:disabled {
  opacity: 0.6;
}

.chat-enviar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--teal-500), var(--blue-500));
  color: var(--navy-950);
  cursor: pointer;
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}

.chat-enviar:hover:not(:disabled) {
  transform: scale(1.06);
}

.chat-enviar:disabled {
  opacity: 0.45;
  cursor: default;
}

.chat-enviar svg {
  width: 19px;
  height: 19px;
}

.chat-aviso {
  padding: 0 0.85rem 0.7rem;
  font-size: 0.74rem;
  color: var(--ink-400);
  background: var(--surface);
}

/* ---------------- responsivo ---------------- */
@media (max-width: 560px) {
  .chat-fab {
    right: 0.85rem;
    bottom: 0.85rem;
    padding: 0.7rem;
  }

  .chat-fab span {
    display: none;
  }

  .chat-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }

  .chat-msg {
    max-width: 90%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-msg,
  .chat-digitando span {
    animation: none;
  }
}