/* ==========================================================
   Chat estilo WhatsApp — layout e componentes
   ========================================================== */
*, *::before, *::after { box-sizing: border-box; }
:root {
  --wa-header: #008069;
  --wa-header-dark: #005e54;
  --wa-bg: #efeae2;
  --wa-in: #ffffff;
  --wa-out: #d9fdd3;
  --wa-text: #111b21;
  --wa-meta: #667781;
  --wa-tick-read: #53bdeb;
  --wa-green: #00a884;
  --wa-chip: #ffffff;
  --wa-notice: #ffeecd;
  --wa-shadow: 0 1px .5px rgba(11, 20, 26, .13);
}
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #d1d7db;
  color: var(--wa-text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.icon-library { display: none; }
svg { fill: currentColor; }

.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background-color: var(--wa-bg);
  background-image:
    radial-gradient(rgba(0,0,0,.035) 1.2px, transparent 1.4px),
    radial-gradient(rgba(0,0,0,.025) 1.2px, transparent 1.4px);
  background-size: 22px 22px, 22px 22px;
  background-position: 0 0, 11px 11px;
  overflow: hidden;
}

/* ---------- Cabeçalho ---------- */
.user-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px 4px;
  background: var(--wa-header);
  color: #fff;
  z-index: 5;
}
.bar-action {
  border: 0; background: none; color: inherit; padding: 6px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.bar-action svg { width: 24px; height: 24px; }
.profile-button {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  border: 0; background: none; color: inherit; text-align: left; padding: 2px; cursor: pointer;
}
.profile-copy { display: flex; flex-direction: column; min-width: 0; }
.profile-identity { display: flex; align-items: center; gap: 4px; }
.profile-name { font-size: 16.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verified-badge { width: 17px; height: 17px; flex: none; }
.profile-status { font-size: 13px; opacity: .85; }
.profile-status.is-typing { opacity: 1; font-style: normal; }
.bar-icons { display: flex; gap: 18px; padding: 0 6px; }
.bar-icons svg { width: 22px; height: 22px; }

/* ---------- Avatar ---------- */
.avatar {
  flex: none; display: grid; place-items: center; overflow: hidden;
  border-radius: 50%; background: #dfe5e7; color: #54656f; font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.header-avatar { width: 40px; height: 40px; font-size: 15px; }
.mini-avatar { width: 28px; height: 28px; font-size: 11px; align-self: flex-start; }
.dialog-avatar { width: 96px; height: 96px; font-size: 32px; margin: 4px auto 10px; }

/* ---------- Conversa ---------- */
.conversation {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 10px 16px;
  scroll-behavior: auto;
}
#message-list { display: flex; flex-direction: column; gap: 2px; }
.date-chip, .info-chip {
  align-self: center; margin: 6px auto; padding: 5px 12px;
  border-radius: 8px; font-size: 12.5px; box-shadow: var(--wa-shadow);
}
.date-chip { background: var(--wa-chip); color: var(--wa-meta); text-transform: uppercase; }
.info-chip {
  display: flex; gap: 6px; align-items: flex-start; max-width: 88%;
  background: var(--wa-notice); color: #54656f; text-align: center; line-height: 1.35; margin-bottom: 10px;
}
.info-chip svg { width: 15px; height: 15px; flex: none; margin-top: 1px; }

.message-row { display: flex; gap: 6px; align-items: flex-end; animation: pop .22s ease-out; }
.message-row.group-start { margin-top: 8px; }
.message-row.received { justify-content: flex-start; }
.message-row.sent { justify-content: flex-end; }
.message-row.received:not(.group-start) .mini-avatar { visibility: hidden; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

.bubble {
  position: relative; max-width: min(82%, 400px);
  padding: 6px 8px 8px 9px; border-radius: 8px;
  font-size: 15px; line-height: 1.38; box-shadow: var(--wa-shadow);
  overflow-wrap: anywhere;
}
.received .bubble { background: var(--wa-in); }
.sent .bubble { background: var(--wa-out); }
.group-start.received .bubble { border-top-left-radius: 0; }
.group-start.sent .bubble { border-top-right-radius: 0; }
.group-start.received .bubble::before,
.group-start.sent .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.group-start.received .bubble::before { left: -8px; background: var(--wa-in); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.group-start.sent .bubble::before { right: -8px; background: var(--wa-out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.bubble-body { white-space: pre-wrap; }
.bubble-body strong { font-weight: 700; }
.meta-spacer { display: inline-block; width: 66px; height: 1px; }
.meta {
  position: absolute; right: 7px; bottom: 4px;
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--wa-meta);
}
.tick { width: 16px; height: 11px; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }
.tick-bot { color: var(--wa-tick-read); }
.tick-read { color: var(--wa-meta); transition: color .3s; }
.meta.read .tick-read { color: var(--wa-tick-read); }

/* foto */
.photo-message { padding: 3px; }
.photo-message .bubble-body button {
  display: block; border: 0; padding: 0; background: none; cursor: zoom-in; width: 100%;
}
.photo-message img { display: block; width: 100%; height: auto; max-width: 300px; border-radius: 6px; }
.photo-message .meta-spacer { display: none; }
.photo-message .meta {
  color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.6); right: 10px; bottom: 8px;
}
.photo-message .meta .tick-bot { color: #fff; }

/* depoimento */
.testimonial-card { min-width: 220px; }
.testimonial-label { font-size: 12px; color: var(--wa-green); font-weight: 600; margin-bottom: 6px; }
.testimonial-box { background: #f0f2f5; border-left: 4px solid var(--wa-green); border-radius: 6px; padding: 6px 8px; }
.testimonial-name { font-size: 13px; font-weight: 700; color: var(--wa-green); }
.testimonial-text { font-size: 14px; margin-top: 2px; }
.testimonial-time { font-size: 11px; color: var(--wa-meta); text-align: right; margin-top: 2px; }

/* carregando */
.loading-msg { min-width: 230px; }
.loading-text { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.loading-bar { height: 8px; border-radius: 99px; background: #e9edef; overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 0; background: var(--wa-green); border-radius: inherit; transition: width .15s linear; }
.loading-pct { font-size: 12px; color: var(--wa-meta); margin-top: 5px; }
.loading-msg.done .loading-pct { color: var(--wa-green); font-weight: 600; }

/* digitando */
.typing-row { display: flex; gap: 6px; align-items: flex-end; margin-top: 2px; }
.typing-row.group-start { margin-top: 8px; }
.typing-row:not(.group-start) .mini-avatar { visibility: hidden; }
.typing-row[hidden] { display: none; }
.typing-bubble {
  background: var(--wa-in); border-radius: 8px; padding: 12px 14px; box-shadow: var(--wa-shadow);
  display: flex; gap: 4px;
}
.typing-row.group-start .typing-bubble { border-top-left-radius: 0; }
.typing-bubble span {
  width: 7px; height: 7px; border-radius: 50%; background: #8696a0;
  animation: blink 1.2s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Opções ---------- */
.choices { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 4px 0 40px; }
.choices:empty { padding: 0; }
.choice {
  font: inherit; font-size: 15px; font-weight: 600;
  border: 0; border-radius: 22px; padding: 12px 16px; cursor: pointer;
  text-align: center; text-decoration: none;
  animation: pop .25s ease-out both;
  transition: transform .12s ease, filter .2s;
}
.choice:active { transform: scale(.97); }
.choice.primary { background: #fff; color: var(--wa-header); box-shadow: 0 1px 2px rgba(0,0,0,.15); border: 1.5px solid var(--wa-green); }
.choice.primary:hover { filter: brightness(.97); }
.choice.cta-final { background: var(--wa-green); color: #fff; border: 0; animation: pop .25s ease-out both, pulse 1.6s 0.4s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(0,168,132,.5); } 50% { box-shadow: 0 0 0 10px rgba(0,168,132,0); } }

.choices.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-label { grid-column: 1 / -1; margin: 0; text-align: center; font-size: 13px; color: var(--wa-meta); font-weight: 600; }
.choice.img-option {
  background: #fff; padding: 6px 6px 8px; border-radius: 12px;
  border: 2px solid transparent; box-shadow: 0 1px 3px rgba(0,0,0,.15);
  display: flex; flex-direction: column; gap: 6px; color: var(--wa-text);
}
.choice.img-option:hover { border-color: var(--wa-green); }
.choice.img-option img { width: 100%; height: auto; border-radius: 8px; display: block; aspect-ratio: 552 / 592; object-fit: cover; background: #f0f2f5; }
.choice.img-option span { font-size: 13.5px; }

/* ---------- Botão "ir para o fim" ---------- */
.scroll-bottom {
  position: absolute; right: 14px; bottom: 76px; z-index: 4;
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: #fff; color: #54656f; box-shadow: 0 2px 6px rgba(0,0,0,.2);
  display: grid; place-items: center; cursor: pointer;
}
.scroll-bottom[hidden] { display: none; }
.scroll-bottom svg { width: 26px; height: 26px; }

/* ---------- Rodapé (composer decorativo) ---------- */
.chat-footer {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.composer {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: #fff; border-radius: 24px; padding: 10px 14px; color: #8696a0;
  box-shadow: var(--wa-shadow);
}
.composer svg { width: 24px; height: 24px; flex: none; }
.composer-placeholder { flex: 1; font-size: 16px; }
.composer-icons { display: flex; gap: 16px; }
.composer-icons .clip { transform: rotate(-45deg); }
.mic-button {
  width: 48px; height: 48px; border-radius: 50%; background: var(--wa-green); color: #fff;
  display: grid; place-items: center; flex: none;
}
.mic-button svg { width: 24px; height: 24px; }

/* ---------- Diálogos ---------- */
dialog { border: 0; padding: 0; }
dialog::backdrop { background: rgba(11, 20, 26, .55); }
.chat-dialog {
  width: min(92vw, 360px); border-radius: 14px; padding: 22px 20px 16px; text-align: center;
  color: var(--wa-text);
}
.chat-dialog h1, .chat-dialog h2 { margin: 4px 0 8px; font-size: 19px; }
.chat-dialog p { margin: 0 0 16px; color: var(--wa-meta); font-size: 14.5px; line-height: 1.45; }
.dialog-close {
  position: absolute; top: 8px; right: 8px; border: 0; background: none; color: #54656f;
  width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; border-radius: 50%;
}
.dialog-close svg { width: 22px; height: 22px; }
.dialog-primary, .dialog-secondary {
  display: block; width: 100%; font: inherit; font-weight: 600; font-size: 15px;
  border: 0; border-radius: 22px; padding: 11px; cursor: pointer; margin-top: 8px;
}
.dialog-primary { background: var(--wa-green); color: #fff; }
.dialog-secondary { background: none; color: var(--wa-header); }
.photo-dialog { background: transparent; max-width: 96vw; max-height: 92vh; }
.photo-dialog img { display: block; max-width: 96vw; max-height: 88vh; border-radius: 8px; }
.photo-dialog .dialog-close { background: rgba(0,0,0,.5); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
