/* /chat — conversa em tela cheia no estilo de app de mensagens. */
:root {
  color-scheme: light;
  --top: #008069;
  --top-text: #fff;
  --page: #d1d7db;
  --band: #00a884;
  --wall: #efeae2;
  --wall-dot: rgba(0, 0, 0, .05);
  --in: #fff;
  --out: #d9fdd3;
  --text: #111b21;
  --meta: #667781;
  --pill: #fff;
  --notice: #ffeecd;
  --notice-text: #54656f;
  --bar: #f0f2f5;
  --field: #fff;
  --icon: #54656f;
  --accent: #00a884;
  --link: #027eb5;
  --tick: #53bdeb;
  --danger: #ea0038;
  --shadow: 0 1px .5px rgba(11, 20, 26, .13);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --top: #202c33;
    --top-text: #e9edef;
    --page: #0c1317;
    --band: #0c1317;
    --wall: #0b141a;
    --wall-dot: rgba(255, 255, 255, .035);
    --in: #202c33;
    --out: #005c4b;
    --text: #e9edef;
    --meta: #8696a0;
    --pill: #182229;
    --notice: #182229;
    --notice-text: #ffd279;
    --bar: #202c33;
    --field: #2a3942;
    --icon: #8696a0;
    --link: #53bdeb;
    --shadow: 0 1px .5px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
/* O fundo da página tem a cor da barra de digitação: é o que o navegador
   mostra atrás das barras nativas e na área segura (notch / barra de gestos). */
html, body { height: 100%; background: var(--bar); }
body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow: hidden;
}
button, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--tick); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

.chat-app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--wall);
}

/* ---------- Cabeçalho ---------- */
.chat-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-height: 60px;
  padding: 8px 12px 8px 6px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--top);
  color: var(--top-text);
}
.chat-top__back {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: inherit;
}
.chat-top__back:hover { background: rgba(255, 255, 255, .1); }
.chat-top__back svg { width: 24px; height: 24px; fill: currentColor; }
.chat-top__avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff; object-fit: cover; }
.chat-top__info { flex: 1; min-width: 0; }
.chat-top__info h1 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.3; }
.chat-top__info p { margin: 0; font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-top__end {
  flex: none;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 18px;
  background: transparent;
  font-size: 13px;
  cursor: pointer;
}
.chat-top__end:hover { background: rgba(255, 255, 255, .12); }
.chat-top__end:disabled { opacity: .5; cursor: default; }

/* ---------- Conversa ---------- */
.chat-main { position: relative; flex: 1; min-height: 0; }
.chat-log {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 5% 10px;
  background-color: var(--wall);
  background-image: radial-gradient(var(--wall-dot) 1.2px, transparent 1.3px);
  background-size: 18px 18px;
}
@media (max-width: 600px) { .chat-log { padding: 10px 10px 8px; } }

.chat-pill {
  display: table;
  max-width: 90%;
  margin: 10px auto;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--pill);
  color: var(--meta);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow);
}
.chat-pill--day { text-transform: uppercase; font-size: 12px; }
.chat-pill--notice { max-width: 440px; background: var(--notice); color: var(--notice-text); }
.chat-pill--notice svg { width: 11px; height: 11px; margin-right: 3px; fill: currentColor; vertical-align: -1px; }

.msg { display: flex; flex-direction: column; margin-top: 2px; }
.msg--first { margin-top: 10px; }
.msg--mine { align-items: flex-end; }
.msg--theirs { align-items: flex-start; }

.bubble {
  position: relative;
  max-width: min(78%, 560px);
  min-width: 70px;
  padding: 6px 7px 8px 9px;
  border-radius: 8px;
  background: var(--in);
  color: var(--text);
  font-size: 14.2px;
  line-height: 19px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
@media (max-width: 600px) { .bubble { max-width: 85%; } }
.msg--mine .bubble { background: var(--out); }
/* "Rabinho" do primeiro balão de cada sequência */
.msg--first .bubble::before {
  content: "";
  position: absolute;
  top: 0;
  width: 8px;
  height: 13px;
  background: inherit;
}
.msg--theirs.msg--first .bubble { border-top-left-radius: 0; }
.msg--theirs.msg--first .bubble::before { left: -8px; clip-path: polygon(100% 0, 0 0, 100% 100%); }
.msg--mine.msg--first .bubble { border-top-right-radius: 0; }
.msg--mine.msg--first .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }

.bubble__name { margin-bottom: 2px; color: #1f7aec; font-size: 12.8px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .bubble__name { color: #53bdeb; } }
.bubble__text { display: inline; white-space: pre-wrap; }
.bubble__text a { color: var(--link); }
.bubble__meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 6px 0 -5px 10px;
  color: var(--meta);
  font-size: 11px;
  line-height: 15px;
}
.bubble__tick { display: inline-flex; }
.bubble__tick svg { width: 16px; height: 15px; fill: var(--meta); }
.msg--failed .bubble__tick svg { fill: var(--danger); }

.bubble--media { padding: 3px 3px 6px; }
.bubble--media .bubble__text { display: block; padding: 4px 4px 0 6px; }
.bubble--media .bubble__meta { margin-right: 4px; }
.bubble__media { position: relative; display: block; line-height: 0; }
.bubble__media img, video.bubble__media {
  display: block;
  width: auto;
  height: auto;
  min-width: 140px;
  /* Sem % aqui: max-width em % é ignorado no cálculo da largura do balão,
     que acabava esticando até o máximo com a largura original da imagem. */
  max-width: 330px;
  max-height: 330px;
  border-radius: 6px;
  object-fit: cover;
  background: rgba(0, 0, 0, .06);
}
@media (max-width: 600px) { .bubble__media img, video.bubble__media { max-width: min(260px, 68vw); max-height: 300px; } }
/* Balão com foto/vídeo fica exatamente da largura da mídia; a legenda quebra dentro dela. */
.bubble--visual { width: min-content; min-width: 0; }

/* Foto sem legenda: hora sobre a imagem, com sombra embaixo. */
.bubble--bare { min-width: 0; padding: 3px; }
.bubble--bare .bubble__name { padding: 3px 4px 1px 6px; }
.bubble--bare .bubble__media::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 28px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .45));
  pointer-events: none;
}
.bubble--bare .bubble__meta {
  position: absolute;
  right: 9px;
  bottom: 6px;
  margin: 0;
  float: none;
  color: rgba(255, 255, 255, .92);
}
.bubble--bare .bubble__tick svg { fill: rgba(255, 255, 255, .92); }
.bubble__audio { display: block; width: 260px; max-width: 100%; margin: 4px; }
.bubble__file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .05);
  color: inherit;
  text-decoration: none;
}
.bubble__file-icon {
  display: grid; place-items: center;
  flex: none;
  width: 34px; height: 40px;
  border-radius: 4px;
  background: #e04646;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.bubble__file-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bubble__options {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 2px;
}
.bubble__option {
  padding: 8px 12px;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 6px;
  background: rgba(0, 0, 0, .03);
  color: var(--link);
  font-size: 14px;
  text-align: center;
  cursor: pointer;
}
.bubble__option:hover:not(:disabled) { background: rgba(0, 0, 0, .07); }
.bubble__option:disabled { color: var(--meta); cursor: default; }
.bubble__option--chosen:disabled { color: var(--link); font-weight: 600; }

/* Carrossel de cards: rola na horizontal, com encaixe por card. */
.msg--carousel { align-self: stretch; }
.carousel {
  display: flex;
  gap: 8px;
  max-width: 100%;
  margin-top: 6px;
  padding: 2px 2px 6px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.carousel__card {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  width: min(280px, 72vw);
  border-radius: 8px;
  background: var(--in);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
  scroll-snap-align: start;
}
.carousel__media { display: block; line-height: 0; }
.carousel__media img, video.carousel__media {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: auto;
  max-height: none;
  aspect-ratio: 1 / 1;
  border-radius: 0;
  object-fit: cover;
}
.carousel__card .bubble__file { margin: 6px; min-width: 0; }
.carousel__text {
  flex: 1;
  padding: 8px 10px 6px;
  font-size: 14.2px;
  line-height: 19px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.carousel__options { display: flex; flex-direction: column; border-top: 1px solid rgba(0, 0, 0, .08); }
.carousel__options .bubble__option {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 10px 12px;
}
.carousel__options .bubble__option + .bubble__option { border-top: 1px solid rgba(0, 0, 0, .08); }
.carousel__options .bubble__option:hover:not(:disabled) { background: rgba(0, 0, 0, .05); }
@media (prefers-color-scheme: dark) {
  .carousel__options, .carousel__options .bubble__option + .bubble__option { border-color: rgba(255, 255, 255, .1); }
}

.msg__retry {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
}

.chat-jump {
  position: absolute;
  right: 16px;
  bottom: 14px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--pill);
  color: var(--icon);
  box-shadow: 0 1px 3px rgba(11, 20, 26, .3);
  cursor: pointer;
}
.chat-jump[hidden] { display: none; }
.chat-jump svg { width: 26px; height: 26px; fill: currentColor; }
.chat-jump__count {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
}

/* ---------- Barra de digitação ---------- */
.chat-composer {
  flex: none;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--bar);
}
.chat-form { display: flex; align-items: flex-end; gap: 6px; }
.chat-attach {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  color: var(--icon);
  cursor: pointer;
}
.chat-attach:hover { background: rgba(0, 0, 0, .06); }
.chat-attach svg { width: 24px; height: 24px; fill: currentColor; transform: rotate(45deg); }
.chat-attach input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.chat-attach:focus-within { outline: 2px solid var(--tick); outline-offset: 2px; }
.chat-field {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  border-radius: 22px;
  background: var(--field);
}
.chat-field textarea {
  display: block;
  width: 100%;
  max-height: 140px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
  line-height: 22px;
  resize: none;
}
.chat-field textarea::placeholder { color: var(--meta); }
.chat-send {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity .15s ease, transform .15s ease;
}
.chat-send svg { width: 22px; height: 22px; fill: currentColor; margin-left: 2px; }
.chat-send:disabled { opacity: .55; cursor: default; }
.chat-send:not(:disabled):active { transform: scale(.94); }
.chat-send[hidden] { display: none; }
.chat-send--mic svg { margin-left: 0; }

/* Gravação de áudio */
.chat-rec { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.chat-rec[hidden], .chat-form[hidden] { display: none; }
.chat-rec__cancel {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--icon);
  cursor: pointer;
}
.chat-rec__cancel:hover { background: rgba(0, 0, 0, .06); color: var(--danger); }
.chat-rec__cancel svg { width: 24px; height: 24px; fill: currentColor; }
.chat-rec__dot {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: chat-rec-blink 1s ease-in-out infinite;
}
.chat-rec__time { min-width: 42px; color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.chat-rec__hint { flex: 1; color: var(--meta); font-size: 14px; }
@keyframes chat-rec-blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .chat-rec__dot { animation: none; } }

/* iOS: 16px evita o zoom automático ao focar o campo */
@media (max-width: 600px) { .chat-field textarea { font-size: 16px; } }

/* ---------- Confirmação ---------- */
.chat-dialog {
  width: min(360px, calc(100% - 32px));
  padding: 22px 22px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--in);
  color: var(--text);
  box-shadow: 0 17px 50px rgba(11, 20, 26, .19);
}
.chat-dialog::backdrop { background: rgba(11, 20, 26, .45); }
.chat-dialog p { margin: 0 0 8px; color: var(--meta); font-size: 14px; }
.chat-dialog .chat-dialog__title { color: var(--text); font-size: 17px; }
.chat-dialog__actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 18px; }
.chat-dialog__actions button {
  padding: 9px 16px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.chat-dialog__actions button:hover { background: rgba(0, 168, 132, .1); }
.chat-dialog__actions .is-danger { background: var(--danger); color: #fff; }
.chat-dialog__actions .is-danger:hover { background: #c4002f; }
