/* ============================================================
   CodeJato - Pagina /chat
   Depende dos tokens de assets/css/styles.css (--orange-500,
   --cream-bg, --shadow-3d-md e afins). Mobile-first: area de
   mensagens rolavel e compositor colado na base.
   ============================================================ */

[hidden] { display: none !important; }

.chat-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* -------------- Estrutura da pagina ----------------------- */

.chat-page {
  /* Cinza-quente proprio para texto secundario: os tokens --black-mute-*
     nao alcancam contraste AA sobre o creme. */
  --chat-muted: #55524A;
  --chat-line: rgba(5, 5, 5, 0.12);
  background: var(--cream-bg);
  padding-top: var(--topbar-h);
}

.chat-shell {
  width: 100%;
  max-width: 72ch;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2rem);
  min-height: calc(100vh - var(--topbar-h));
  min-height: calc(100dvh - var(--topbar-h));
  display: flex;
  flex-direction: column;
}

.chat-intro {
  padding: 1.25rem 0 0.5rem;
}
.chat-intro__title {
  font-size: clamp(1.35rem, 4.2vw, 1.9rem);
  font-weight: 900;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--black);
}
.chat-intro__sub {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--chat-muted);
}

/* -------------- Area rolavel da conversa ------------------ */

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* -------------- Estado vazio ------------------------------ */

.chat-empty__hint {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--chat-muted);
  margin-bottom: 0.7rem;
}
.chat-suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-suggestion {
  text-align: left;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--black);
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: 0.75rem;
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow-3d-md);
  transition: transform 0.15s var(--ease-out-soft), box-shadow 0.15s var(--ease-out-soft);
}
.chat-suggestion:hover {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--black);
}
.chat-suggestion:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--black);
}

/* -------------- Mensagens --------------------------------- */

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.chat-msg__role {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--chat-muted);
}
.chat-msg__body {
  font-size: 0.95rem;
  line-height: 1.7;
  color: #111;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 2px solid var(--black);
  border-radius: 0.9rem;
  padding: 0.8rem 1rem;
  background: var(--white);
}
.chat-msg--user .chat-msg__body {
  background: var(--orange-tint-08);
  border-color: var(--orange-tint-30);
}
.chat-msg--assistant .chat-msg__body {
  box-shadow: var(--shadow-3d-md);
}

/* Selo de modelo e tempo, logo abaixo da resposta. */
.chat-stamp {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--chat-muted);
  padding-left: 0.2rem;
}

/* -------------- Aguardando e transmitindo ----------------- */

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  height: 1.2em;
}
.chat-typing i {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--orange-500);
  animation: chat-dot-pulse 1.1s var(--ease-out-soft) infinite;
}
.chat-typing i:nth-child(2) { animation-delay: 0.16s; }
.chat-typing i:nth-child(3) { animation-delay: 0.32s; }

@keyframes chat-dot-pulse {
  0%, 60%, 100% { opacity: 0.32; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-0.22rem); }
}

.chat-cursor {
  display: inline-block;
  width: 0.5ch;
  height: 1em;
  vertical-align: -0.14em;
  margin-left: 0.1em;
  background: var(--orange-500);
  animation: chat-blink 1s steps(2, start) infinite;
}

@keyframes chat-blink {
  to { visibility: hidden; }
}

/* -------------- Erro -------------------------------------- */

.chat-error {
  border: 2px solid var(--black);
  border-radius: 0.9rem;
  background: var(--cream2-bg);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.7rem;
}
.chat-error__text {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #111;
}
.chat-error__retry {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--white);
  background: var(--orange-500);
  border: 2px solid var(--black);
  border-radius: 0.6rem;
  padding: 0.5rem 1rem;
  box-shadow: var(--shadow-3d-md);
  transition: transform 0.15s var(--ease-out-soft), box-shadow 0.15s var(--ease-out-soft);
}
.chat-error__retry:hover {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--black);
}

/* -------------- Rodape fixo: contador e compositor -------- */

.chat-foot {
  position: sticky;
  bottom: 0;
  background: var(--cream-bg);
  border-top: 2px solid var(--black);
  padding: 0.7rem 0 max(0.9rem, env(safe-area-inset-bottom));
}

.chat-remaining {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--chat-muted);
  margin-bottom: 0.5rem;
  min-height: 1em;
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
}
.chat-composer__input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-stack);
  font-size: 1rem;
  line-height: 1.5;
  color: #111;
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: 0.75rem;
  padding: 0.65rem 0.85rem;
  resize: none;
  max-height: 40vh;
  overflow-y: auto;
}
.chat-composer__input::placeholder { color: var(--chat-muted); }

.chat-composer__send {
  flex: 0 0 auto;
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
}
.chat-composer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-3d-md);
}

.chat-legal {
  margin-top: 0.6rem;
  font-size: 0.72rem;
  color: var(--chat-muted);
}

/* -------------- Muro de captura de e-mail ----------------- */

/* Card que ocupa o lugar do compositor quando o limite e atingido. */
.chat-wall {
  border: 2px solid var(--black);
  border-radius: 0.9rem;
  background: var(--white);
  box-shadow: var(--shadow-3d-md);
  padding: 1rem;
}

.chat-wall__title {
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--black);
}
.chat-wall__sub {
  margin-top: 0.35rem;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--chat-muted);
}

.chat-wall__form {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chat-wall__field {
  font-family: var(--font-stack);
  font-size: 1rem;
  line-height: 1.5;
  color: #111;
  background: var(--cream-bg);
  border: 2px solid var(--black);
  border-radius: 0.75rem;
  padding: 0.65rem 0.85rem;
}
.chat-wall__field::placeholder { color: var(--chat-muted); }

.chat-wall__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-3d-md);
}

/* Estado do envio: mesma cor de erro e de sucesso usada no formulario vivo. */
.chat-wall__status {
  font-size: 0.82rem;
  line-height: 1.5;
  min-height: 1em;
  color: var(--chat-muted);
}
.chat-wall__status[data-tone="error"] { color: #c00; }
.chat-wall__status[data-tone="success"] { color: #0a7; }

/* -------------- Desktop ----------------------------------- */

@media (min-width: 768px) {
  .chat-intro { padding: 2rem 0 0.75rem; }
  .chat-msg__body { font-size: 1rem; }
  .chat-composer__send { padding: 0.75rem 1.75rem; }
}

/* -------------- Movimento reduzido ------------------------ */

@media (prefers-reduced-motion: reduce) {
  .chat-cursor { animation: none; }
  .chat-typing i { animation: none; opacity: 0.7; }
  .chat-suggestion,
  .chat-error__retry { transition: none; }
}
