/* ==========================================================================
   FRS Ask AI — estilos do assistente
   Tudo escopado em .frs-ask-ai para não vazar para o tema/Divi.
   Mobile first; breakpoints alinhados ao Divi:
     ≤ 767px   smartphones
     768–980px tablets
     ≥ 981px   desktop
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Variáveis da marca e rede de segurança
   -------------------------------------------------------------------------- */

.frs-ask-ai {
  --frs-red:        #d32323;
  --frs-red-dark:   #b21d1d;
  --frs-gold:       #f59e0b;
  --frs-gold-soft:  #fff4dc;
  --frs-dark:       #1f2937;
  --frs-gray:       #6b7280;
  --frs-line:       #e5e7eb;
  --frs-bg:         #f3f4f6;
  --frs-white:      #ffffff;
  --frs-radius:     16px;
  --frs-ai-height:  min(70vh, 640px);   /* altura do painel; o shortcode pode sobrescrever */

  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: var(--frs-ai-height);
  min-height: 480px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--frs-line);
  border-radius: var(--frs-radius);
  background: var(--frs-white);
  box-shadow: 0 12px 40px rgba(31, 41, 55, 0.12);
  color: var(--frs-dark);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Nenhum elemento interno pode empurrar a página para o lado. */
.frs-ask-ai *,
.frs-ask-ai *::before,
.frs-ask-ai *::after { box-sizing: border-box; min-width: 0; }

.frs-ask-ai a { color: var(--frs-red); text-decoration: underline; text-underline-offset: 2px; }
.frs-ask-ai a:hover { color: var(--frs-red-dark); }

/* Leitor de tela apenas */
.frs-ai__sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* --------------------------------------------------------------------------
   1. Cabeçalho
   -------------------------------------------------------------------------- */

.frs-ai__head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--frs-dark);
  color: var(--frs-white);
}

.frs-ai__brand {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.frs-ai__avatar {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--frs-red);
  color: var(--frs-white);
}
.frs-ai__avatar svg { width: 24px; height: 24px; }

.frs-ai__title {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 800;
  color: var(--frs-white);
  letter-spacing: -0.01em;
}

.frs-ai__subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.78);
}

.frs-ai__actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* --------------------------------------------------------------------------
   2. Botões (compartilhados por cabeçalho, CTAs e formulário de lead)
   -------------------------------------------------------------------------- */

.frs-ai__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;                 /* alvo de toque confortável */
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none !important;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background-color 0.15s ease;
}
.frs-ai__btn:hover { transform: translateY(-1px); filter: brightness(1.05); }
.frs-ai__btn:focus-visible { outline: 3px solid var(--frs-gold); outline-offset: 2px; }
.frs-ai__btn:disabled { opacity: 0.65; cursor: wait; transform: none; }

.frs-ai__btn--ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.35);
  color: var(--frs-white);
}
.frs-ai__btn--ghost:hover { background: rgba(255, 255, 255, 0.08); }

.frs-ai__btn--accent {
  background: var(--frs-gold);
  color: var(--frs-dark);
}

.frs-ai__btn--primary {
  background: var(--frs-red);
  color: var(--frs-white) !important;
}
.frs-ai__btn--primary:hover { background: var(--frs-red-dark); }

/* Dentro do log (fundo claro) o botão "ghost" precisa de contraste escuro. */
.frs-ai__log .frs-ai__btn--ghost {
  border-color: var(--frs-dark);
  color: var(--frs-dark);
}
.frs-ai__log .frs-ai__btn--ghost:hover { background: rgba(31, 41, 55, 0.06); }

/* --------------------------------------------------------------------------
   3. Log da conversa
   -------------------------------------------------------------------------- */

.frs-ai__log {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--frs-bg);
  scroll-behavior: smooth;
}

.frs-ai__msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: frs-ai-pop 0.22s ease-out both;
}

.frs-ai__msg--user { flex-direction: row-reverse; }

.frs-ai__who {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--frs-red);
  color: var(--frs-white);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.frs-ai__bubble {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.frs-ai__msg--bot .frs-ai__bubble {
  background: var(--frs-white);
  border: 1px solid var(--frs-line);
  border-bottom-left-radius: 4px;
  color: var(--frs-dark);
}

.frs-ai__msg--user .frs-ai__bubble {
  background: var(--frs-red);
  border-bottom-right-radius: 4px;
  color: var(--frs-white);
}

.frs-ai__bubble p { margin: 0 0 8px; }
.frs-ai__bubble p:last-child { margin-bottom: 0; }
.frs-ai__bubble ul { margin: 8px 0 8px 18px; padding: 0; }
.frs-ai__bubble li { margin: 0 0 4px; }
.frs-ai__bubble strong { font-weight: 700; }

/* --------------------------------------------------------------------------
   4. Indicador "digitando"
   -------------------------------------------------------------------------- */

.frs-ai__dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 18px;
}
.frs-ai__dots i {
  display: block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--frs-gray);
  animation: frs-ai-dot 1.1s infinite ease-in-out;
}
.frs-ai__dots i:nth-child(2) { animation-delay: 0.15s; }
.frs-ai__dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes frs-ai-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40%           { transform: translateY(-4px); opacity: 1; }
}

@keyframes frs-ai-pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --------------------------------------------------------------------------
   5. Sugestões rápidas (chips) e perguntas relacionadas
   -------------------------------------------------------------------------- */

.frs-ai__chips {
  display: flex;
  gap: 8px;
  padding: 10px 16px 0;
  overflow-x: auto;                 /* no celular vira um carrossel horizontal */
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  background: var(--frs-white);
  border-top: 1px solid var(--frs-line);
}
.frs-ai__chips::-webkit-scrollbar { display: none; }
.frs-ai__chips:empty { display: none; }

.frs-ai__chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--frs-gold);
  border-radius: 999px;
  background: var(--frs-gold-soft);
  color: var(--frs-dark);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.frs-ai__chip:hover { background: var(--frs-gold); transform: translateY(-1px); }
.frs-ai__chip:focus-visible { outline: 3px solid var(--frs-gold); outline-offset: 2px; }

.frs-ai__followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--frs-line);
}
.frs-ai__chip--inline {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
  white-space: normal;              /* dentro do balão pode quebrar linha */
  text-align: left;
}

/* CTA no fim da resposta */
.frs-ai__cta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.frs-ai__cta .frs-ai__btn { width: 100%; }

/* --------------------------------------------------------------------------
   6. Compositor (caixa de texto + enviar)
   -------------------------------------------------------------------------- */

.frs-ai__composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 10px 12px 12px;
  background: var(--frs-white);
}

.frs-ai__input {
  flex: 1 1 auto;
  width: 100%;
  min-height: 48px;
  max-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--frs-line);
  border-radius: 14px;
  background: var(--frs-bg);
  color: var(--frs-dark);
  font: inherit;
  font-size: 16px;                  /* 16px evita o zoom automático do iOS */
  line-height: 1.4;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}
.frs-ai__input::placeholder {
  color: var(--frs-gray);
  white-space: nowrap;              /* placeholder nunca quebra em 2 linhas */
  overflow: hidden;
  text-overflow: ellipsis;
}
.frs-ai__input:focus {
  outline: none;
  border-color: var(--frs-gold);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
  background: var(--frs-white);
}

.frs-ai__send {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--frs-red);
  color: var(--frs-white);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.frs-ai__send svg { width: 22px; height: 22px; }
.frs-ai__send:hover { background: var(--frs-red-dark); transform: translateY(-1px); }
.frs-ai__send:focus-visible { outline: 3px solid var(--frs-gold); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   7. Formulário de lead dentro do chat
   -------------------------------------------------------------------------- */

.frs-ai__msg--lead .frs-ai__bubble { max-width: 100%; width: 100%; }

.frs-ai__lead { margin: 0; }

.frs-ai__lead-title {
  display: block;
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 800;
}
.frs-ai__lead-intro {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--frs-gray);
}

.frs-ai__lead-grid {
  display: grid;
  grid-template-columns: 1fr;       /* 1 coluna no celular */
  gap: 10px;
  margin-bottom: 12px;
}
.frs-ai__lead-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}
.frs-ai__lead-grid input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--frs-line);
  border-radius: 10px;
  background: var(--frs-white);
  color: var(--frs-dark);
  font: inherit;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.frs-ai__lead-grid input:focus {
  outline: none;
  border-color: var(--frs-gold);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

.frs-ai__lead .frs-ai__btn--primary { width: 100%; }

/* Honeypot: fora da tela, nunca display:none (alguns bots detectam). */
.frs-ai__hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.frs-ai__lead-status {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}
.frs-ai__lead-status.is-ok    { background: #ecfdf5; border: 1px solid #10b981; color: #065f46; }
.frs-ai__lead-status.is-error { background: #fef2f2; border: 1px solid var(--frs-red); color: #991b1b; }

/* --------------------------------------------------------------------------
   8. Sem JavaScript
   -------------------------------------------------------------------------- */

.frs-ai__noscript {
  margin: 0;
  padding: 16px;
  background: var(--frs-gold-soft);
  border-top: 1px solid var(--frs-gold);
  font-size: 15px;
}

/* --------------------------------------------------------------------------
   9. Tablets (768–980px)
   -------------------------------------------------------------------------- */

@media (min-width: 768px) and (max-width: 980px) {
  .frs-ask-ai { --frs-ai-height: min(72vh, 680px); }

  .frs-ai__head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
  }
  .frs-ai__actions { flex-wrap: nowrap; }

  .frs-ai__log { padding: 20px; }
  .frs-ai__bubble { max-width: 80%; }

  .frs-ai__chips { flex-wrap: wrap; overflow: visible; padding: 12px 20px 0; }

  .frs-ai__lead-grid { grid-template-columns: 1fr 1fr; }
  .frs-ai__cta .frs-ai__btn,
  .frs-ai__lead .frs-ai__btn--primary { width: auto; min-width: 220px; }
}

/* --------------------------------------------------------------------------
   10. Desktop (≥ 981px)
   -------------------------------------------------------------------------- */

@media (min-width: 981px) {
  .frs-ask-ai {
    --frs-ai-height: min(75vh, 720px);
    max-width: 900px;
  }

  .frs-ai__head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
  }
  .frs-ai__title { font-size: 20px; }
  .frs-ai__subtitle { font-size: 14px; }
  .frs-ai__actions { flex-wrap: nowrap; }

  .frs-ai__log { padding: 24px; gap: 14px; }
  .frs-ai__bubble { max-width: 72%; font-size: 16px; }

  .frs-ai__chips { flex-wrap: wrap; overflow: visible; padding: 12px 24px 0; }

  .frs-ai__composer { padding: 12px 16px 16px; }

  .frs-ai__lead-grid { grid-template-columns: 1fr 1fr; }
  .frs-ai__cta .frs-ai__btn,
  .frs-ai__lead .frs-ai__btn--primary { width: auto; min-width: 220px; }
}

/* --------------------------------------------------------------------------
   11. Smartphones (≤ 767px): ajustes finos
   -------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .frs-ask-ai {
    --frs-ai-height: min(78vh, 640px);
    border-radius: 12px;
  }
  .frs-ai__actions .frs-ai__btn { flex: 1 1 auto; font-size: 13px; padding: 8px 12px; }
  .frs-ai__bubble { max-width: 92%; }
  .frs-ai__who { display: none; }   /* ganha largura útil para o texto */
}

/* --------------------------------------------------------------------------
   12. Acessibilidade e movimento
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .frs-ask-ai *,
  .frs-ask-ai *::before,
  .frs-ask-ai *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
  .frs-ai__log { scroll-behavior: auto; }
  .frs-ai__dots i { opacity: 0.8; }
}
