/* ===================== ELENA WEBCHAT — VISUAL ===================== */
:root {
  --verde-topo: #008069;
  --verde-botao: #00a884;
  --balao-cliente: #d9fdd3;
  --balao-agente: #ffffff;
  --fundo: #efeae2;
  --texto: #111b21;
  --texto-sec: #667781;
  --azul-check: #53bdeb;
  --link: #027eb5;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0b141a; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--texto);
  overflow: hidden;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background-color: var(--fundo);
  background-image: url("../imagens/background.jpg");
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

/* ---------- topo ---------- */
.topo {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 8px 4px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--verde-topo);
  color: #fff;
  z-index: 2;
}
.icone-topo { background: none; border: 0; color: #fff; padding: 4px; display: flex; }
.avatar {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #dfe5e7;
  overflow: hidden;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.avatar img.falhou { display: none; }
.avatar .inicial { color: #fff; font-weight: 600; font-size: 18px; background: #6b7c85; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.contato { flex: 1; min-width: 0; margin-left: 4px; }
.contato .nome { font-size: 16.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contato .status { font-size: 13px; opacity: .85; white-space: nowrap; }
.acoes-topo { display: flex; gap: 20px; padding-right: 6px; opacity: .95; }

/* ---------- mensagens ---------- */
.mensagens {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 6% 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}
.chip-data {
  align-self: center;
  background: #ffffffe6;
  color: #54656f;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 8px;
  margin: 8px 0;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  text-transform: uppercase;
}

.linha { display: flex; width: 100%; }
.linha.cliente { justify-content: flex-end; }
.linha.agente { justify-content: flex-start; }
.linha.primeira { margin-top: 8px; }

.balao {
  position: relative;
  max-width: 82%;
  padding: 6px 7px 8px 9px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.35;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  animation: entra .18s ease-out;
}
@keyframes entra { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.cliente .balao { background: var(--balao-cliente); }
.agente .balao { background: var(--balao-agente); }
.primeira.cliente .balao { border-top-right-radius: 0; }
.primeira.agente .balao { border-top-left-radius: 0; }
.primeira.cliente .balao::before,
.primeira.agente .balao::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.primeira.cliente .balao::before { right: -8px; background: linear-gradient(to bottom left, var(--balao-cliente) 50%, transparent 50%); }
.primeira.agente .balao::before { left: -8px; background: linear-gradient(to bottom right, var(--balao-agente) 50%, transparent 50%); }

.texto-msg { white-space: pre-wrap; }
.texto-msg a { color: var(--link); }
.meta {
  float: right;
  margin: 6px 0 -4px 10px;
  font-size: 11px;
  color: var(--texto-sec);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  position: relative;
  top: 4px;
}
.meta .check { width: 16px; height: 11px; color: #8696a0; }
.meta .check.lido { color: var(--azul-check); }
.meta .relogio { width: 12px; height: 12px; color: #8696a0; }
.meta .falha { color: #e53935; font-weight: 700; }

/* mídia */
.balao.midia { padding: 3px 3px 3px 3px; }
.balao.midia .meta { position: absolute; right: 8px; bottom: 6px; margin: 0; float: none; top: auto; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.6); }
.balao.midia .meta .check { color: #fff; }
.balao.midia .meta .check.lido { color: var(--azul-check); }
.img-msg, .video-msg {
  display: block;
  max-width: 100%;
  width: 260px;
  max-height: 340px;
  object-fit: cover;
  border-radius: 6px;
  background: #ddd;
  cursor: pointer;
}
.video-msg { cursor: auto; }

/* áudio */
.balao.audio { padding: 7px 8px 8px 7px; min-width: 250px; }
.player { display: flex; align-items: center; gap: 8px; }
.player .foto-audio { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; position: relative; flex: 0 0 auto; background: #6b7c85; }
.player .foto-audio img { width: 100%; height: 100%; object-fit: cover; }
.player .foto-audio .mic {
  position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; color: #00a884;
  background: transparent;
}
.player button.play { background: none; border: 0; width: 34px; height: 34px; padding: 0; color: #54656f; flex: 0 0 auto; cursor: pointer; }
.player .trilha { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.player input[type=range] { width: 100%; height: 4px; accent-color: #00a884; margin: 8px 0 0; }
.player .tempos { display: flex; justify-content: space-between; font-size: 11px; color: var(--texto-sec); }

/* arquivo */
.arquivo-msg {
  display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.05);
  padding: 10px; border-radius: 6px;
  color: var(--texto); text-decoration: none;
  min-width: 220px;
}
.arquivo-msg .ext { background: #e53935; color: #fff; font-size: 10px; font-weight: 700; padding: 6px 4px; border-radius: 4px; min-width: 32px; text-align: center; }
.arquivo-msg .nome-arq { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* botões de resposta rápida */
.botoes {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 82%;
  margin-top: 4px;
}
.botoes button {
  background: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  color: #008069;
  font-weight: 500;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
  cursor: pointer;
  text-align: center;
  font-family: inherit;
}
.botoes button:active { background: #f0f2f5; }

/* digitando */
.digitando .balao { padding: 12px 14px; }
.pontinhos { display: flex; gap: 4px; }
.pontinhos span, .carregando span {
  width: 7px; height: 7px; border-radius: 50%; background: #90a4ae;
  animation: pula 1.2s infinite ease-in-out;
}
.pontinhos span:nth-child(2), .carregando span:nth-child(2) { animation-delay: .15s; }
.pontinhos span:nth-child(3), .carregando span:nth-child(3) { animation-delay: .3s; }
@keyframes pula { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.carregando { align-self: center; display: flex; gap: 5px; margin-top: 40px; background: #fff; padding: 10px 14px; border-radius: 16px; }

/* ---------- rodapé ---------- */
.rodape {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.campo {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: #fff;
  border-radius: 24px;
  padding: 4px 6px 4px 16px;
  min-height: 48px;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
}
.campo textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 16px;
  line-height: 22px;
  max-height: 120px;
  padding: 9px 0;
  background: transparent;
  color: var(--texto);
}
.icone-campo { background: none; border: 0; color: #54656f; padding: 8px; display: flex; cursor: pointer; }
.btn-acao {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 0;
  background: var(--verde-botao);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.btn-acao .ic-enviar { display: none; margin-left: 3px; }
.btn-acao.enviar .ic-enviar { display: block; }
.btn-acao.enviar .ic-mic { display: none; }

.gravando {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 24px;
  padding: 4px 16px 4px 6px;
  min-height: 48px;
  box-shadow: 0 1px .5px rgba(11,20,26,.13);
}
.gravando[hidden], .campo[hidden] { display: none; }
.lixo { color: #e53935; }
.ponto-rec { width: 10px; height: 10px; border-radius: 50%; background: #e53935; animation: pisca 1s infinite; }
@keyframes pisca { 50% { opacity: .2; } }
.tempo-rec { font-variant-numeric: tabular-nums; font-size: 15px; }
.dica-rec { color: var(--texto-sec); font-size: 14px; }

/* ---------- visualizador e aviso ---------- */
.visualizador {
  position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.visualizador[hidden] { display: none; }
.visualizador img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visualizador .fechar {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px;
  background: none; border: 0; color: #fff; font-size: 26px; cursor: pointer;
}
.aviso {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 14px; z-index: 60; max-width: 90%; text-align: center;
}
.aviso[hidden] { display: none; }

@media (min-width: 521px) {
  .app { box-shadow: 0 0 30px rgba(0,0,0,.4); }
}
