/* =========================================================
   Compositor de chat flutuante
   ========================================================= */

.chat {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  z-index: 95;
  width: min(620px, calc(100vw - 1.6rem));
  transform: translateX(-50%);
  display: grid;
  gap: 0.6rem;
  pointer-events: none;
}

.chat > * {
  pointer-events: auto;
}

/* --- painel do histórico: sobe de trás do compositor --- */

.chat__panel {
  display: flex;
  flex-direction: column;
  max-height: min(56vh, 460px);
  border-radius: var(--r-lg);
  background: rgba(10, 17, 30, 0.72);
  opacity: 0;
  transform: translateY(28px) scale(0.97);
  transform-origin: bottom center;
  pointer-events: none;
  visibility: hidden;
  transition:
    opacity 0.45s var(--ease-out),
    transform 0.55s var(--ease-out),
    visibility 0s linear 0.55s;
}

.chat.is-open .chat__panel {
  opacity: 1;
  transform: none;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.chat__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.82rem;
  color: var(--paper-dim);
}

.chat__head strong {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--paper);
}

.chat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-2);
  box-shadow: 0 0 12px 2px var(--gold-glow);
  animation: pulseGlow 2.4s ease-in-out infinite;
}

.chat__close {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-faint);
  transition: color 0.3s var(--ease-out);
}

.chat__close:hover {
  color: var(--gold-2);
}

.chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overscroll-behavior: contain;
}

.bubble {
  max-width: 84%;
  padding: 0.72rem 0.95rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  animation: rise 0.45s var(--ease-out) both;
}

.bubble--book {
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--paper-dim);
}

.bubble--me {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  background: linear-gradient(180deg, rgba(227, 181, 121, 0.9), rgba(192, 133, 68, 0.9));
  color: #1a1206;
  font-weight: 500;
}

.bubble--typing {
  display: flex;
  gap: 5px;
  padding: 0.85rem 1rem;
}

.bubble--typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--paper-faint);
  animation: blink3 1.2s ease-in-out infinite;
}

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

@keyframes blink3 {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* --- compositor --- */

.chat__composer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.5rem 0.5rem 0.9rem;
  border-radius: 999px;
  background: rgba(10, 17, 30, 0.72);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 20px 50px -22px rgba(0, 0, 0, 0.9);
}

.chat__spark {
  flex: none;
  width: 20px;
  height: 20px;
  color: var(--gold-2);
  opacity: 0.85;
  animation: pulseGlow 3.2s ease-in-out infinite;
}

.chat__spark svg {
  width: 100%;
  height: 100%;
}

.chat__composer input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--paper);
  font-size: 0.95rem;
  padding: 0.6rem 0;
}

.chat__composer input:focus {
  outline: none;
}

.chat__composer input::placeholder {
  color: rgba(244, 241, 234, 0.42);
}

.chat__send {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #1a1206;
  background: linear-gradient(180deg, #fbe0b4, var(--gold-2) 46%, #c08544);
  box-shadow: 0 10px 26px -12px var(--gold-glow);
  transition: transform 0.3s var(--ease-spring);
}

.chat__send svg {
  width: 18px;
  height: 18px;
}

.chat__send:hover {
  transform: scale(1.06);
}

.chat__send:active {
  transform: scale(0.94);
}

@media (max-width: 520px) {
  .bubble {
    max-width: 90%;
    font-size: 0.86rem;
  }
  .chat__panel {
    max-height: 50vh;
  }
}

/* O compositor é fixo e fica sempre por cima. Estas folgas evitam que ele
   tape o CTA do hero e o rodapé — sem isto o botão principal fica debaixo
   da barra de chat em ecrãs baixos. */
body {
  padding-bottom: 88px;
}

.hero {
  padding-bottom: clamp(9rem, 20vw, 12rem) !important;
}

.hero__scroll {
  bottom: 5.4rem;
}

@media (max-width: 620px) {
  body { padding-bottom: 80px; }
  .hero__scroll { display: none; }
}
