/* ===================================================
   Yprontu — Diagnóstico Yprontu (formulário conversacional)
   =================================================== */

:root {
  --azul-primario: #2F6FED;
  --azul-gradiente-claro: #5B9BF7;
  --azul-gradiente-escuro: #1E5FE0;
  --azul-escuro: #1F2937;
  --cinza-texto: #4B5563;
  --cinza-claro: #F1F3F6;
  --branco: #FFFFFF;
  --fundo-app: #F6F8FC;
  --borda: #E5E7EB;
  --erro: #EF4444;
  --radius: 18px;
  --radius-sm: 10px;
  --font: 'Sarabun', sans-serif;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--azul-escuro);
  background: var(--fundo-app);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button, input, select {
  font-family: inherit;
}

/* ===================================================
   App shell
   =================================================== */

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--branco);
  box-shadow: 0 0 40px rgba(31, 41, 55, 0.06);
  position: relative;
  overflow: hidden;
}

/* ===================================================
   Header + progress bar
   =================================================== */

.chat-header {
  flex: 0 0 auto;
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--borda);
  background: var(--branco);
  z-index: 5;
}

.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.chat-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-logo-bg {
  display: flex;
  align-items: center;
  background: var(--azul-primario);
  border-radius: 7px;
  padding: 5px 10px;
}

.chat-logo-img {
  height: 18px;
  width: auto;
  display: block;
}

.chat-logo-fallback {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--azul-primario);
  color: var(--branco);
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.chat-header-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--azul-escuro);
}

.chat-step-indicator {
  font-size: 12px;
  font-weight: 600;
  color: var(--cinza-texto);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.chat-progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--cinza-claro);
  overflow: hidden;
}

.chat-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--azul-gradiente-claro), var(--azul-gradiente-escuro));
  transition: width 0.4s ease;
}

/* ===================================================
   Messages area
   =================================================== */

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: msgIn 0.28s ease;
}

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

.msg-row.bot {
  justify-content: flex-start;
  margin: 6px 0;
}

.msg-row.user {
  justify-content: flex-end;
  margin: 6px 0;
}

.msg-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--azul-gradiente-claro), var(--azul-gradiente-escuro));
  color: var(--branco);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  align-self: flex-end;
  overflow: hidden;
}

.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.msg-avatar.spacer {
  visibility: hidden;
}

.msg-bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.45;
  max-width: 78%;
  word-wrap: break-word;
}

.msg-row.bot .msg-bubble {
  background: var(--cinza-claro);
  color: var(--azul-escuro);
  border-bottom-left-radius: 4px;
}

.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, var(--azul-gradiente-claro), var(--azul-gradiente-escuro));
  color: var(--branco);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.msg-row.typing .msg-bubble {
  background: var(--cinza-claro);
  border-bottom-left-radius: 4px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9AA4B2;
  animation: typingBounce 1.1s infinite ease-in-out;
}

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

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

/* Quick-reply chip options rendered inline in the flow */
.msg-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 0 6px 52px;
  max-width: 78%;
}

.msg-option-btn {
  text-align: left;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--borda);
  background: var(--branco);
  color: var(--azul-escuro);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.msg-option-btn:hover {
  border-color: var(--azul-gradiente-claro);
  background: #F3F7FF;
}

.msg-option-btn:active {
  transform: scale(0.98);
}

.msg-option-btn.is-selected {
  border-color: var(--azul-primario);
  background: #EAF1FF;
  color: var(--azul-primario);
  font-weight: 600;
}

/* ===================================================
   Campo de resposta inline (dentro do fluxo do chat)
   =================================================== */

.field-row-wrap {
  margin: 2px 0 6px 52px;
  max-width: 78%;
  animation: msgIn 0.28s ease;
}

.input-field-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--cinza-texto);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
  display: block;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1.5px solid var(--borda);
  border-radius: 999px;
  background: var(--branco);
  padding: 4px 4px 4px 14px;
  transition: border-color 0.15s;
}

.input-row:focus-within {
  border-color: var(--azul-primario);
}

.input-row.is-error {
  border-color: var(--erro);
}

.text-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  padding: 8px 0;
  border: none;
  font-size: 14.5px;
  color: var(--azul-escuro);
  background: transparent;
  outline: none;
}

.send-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--azul-gradiente-claro), var(--azul-gradiente-escuro));
  color: var(--branco);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.send-btn svg {
  width: 16px;
  height: 16px;
}

/* Botão que envia o lead (última pergunta, e-mail) — visualmente distinto
   dos demais "Enviar" do fluxo e com id/classe exclusivos para ferramentas
   de mensuração (ex: Meta Event Setup Tool) apontarem só para ele. */
.send-btn--enviar-lead {
  width: 40px;
  height: 40px;
  background: #25D366;
}

.send-btn--enviar-lead svg {
  width: 18px;
  height: 18px;
}

.field-error {
  font-size: 12px;
  color: var(--erro);
  margin-top: 6px;
  display: none;
}

.field-error.is-visible {
  display: block;
}

/* Aviso de consentimento (etapa 1) — texto informativo, sem interação */
.consent-note {
  margin-top: 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--cinza-texto);
}

.consent-note a {
  color: var(--azul-primario);
  text-decoration: underline;
}

/* Botão "Continuar" (etapas sem campo de texto) */
.continue-btn {
  display: inline-block;
  margin: 4px 0 6px 52px;
  max-width: 78%;
  padding: 11px 20px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--azul-gradiente-claro), var(--azul-gradiente-escuro));
  color: var(--branco);
  font-size: 14.5px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  animation: msgIn 0.28s ease;
}

.continue-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.continue-btn:not(:disabled):active {
  transform: scale(0.98);
}

/* Variante compacta e centralizada — usada no botão-link de encerramento
   do fluxo (ex.: "Seguir Yprontu"), que não fica alinhado sob o avatar
   como o "Continuar →" padrão. */
.continue-btn--compact {
  align-self: center;
  width: auto;
  max-width: fit-content;
  margin: 4px 0 6px;
  padding: 7px 16px;
}

/* Scrollbar tidy-up */
.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #D7DEE8;
  border-radius: 999px;
}

/* ===================================================
   Responsive
   =================================================== */

@media (min-width: 560px) {
  body {
    background: linear-gradient(160deg, #EEF3FE, #F6F8FC);
  }
  .chat-app {
    height: min(760px, 92vh);
    margin: 4vh auto;
    border-radius: 20px;
  }
}
