/* Paleta WhatsApp: header #075E54, acento #25D366, bolha enviada #DCF8C6 */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --verde-escuro: #075E54;
  --verde: #128C7E;
  --verde-claro: #25D366;
  --bolha-eu: #DCF8C6;
  --bolha-ele: #FFFFFF;
  --fundo-chat: #ECE5DD;
  --texto: #111B21;
  --texto-fraco: #667781;
  --borda: #E9EDEF;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--texto); background: #F0F2F5;
  overflow: hidden;
}

/* ---------- login ---------- */
.tela-login { display: grid; place-items: center; background: var(--verde-escuro); padding: 24px; }
.card-login {
  background: #fff; border-radius: 14px; padding: 32px 28px; width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
  box-shadow: 0 12px 32px rgba(0,0,0,.25);
}
.card-login .logo { font-size: 44px; }
.card-login h1 { font-size: 20px; }
.card-login .sub { color: var(--texto-fraco); font-size: 14px; margin-bottom: 6px; }
.card-login input {
  padding: 13px 14px; border: 1px solid #D1D7DB; border-radius: 8px; font-size: 16px;
}
.card-login input:focus { outline: 2px solid var(--verde); border-color: transparent; }
.card-login button {
  padding: 13px; border: 0; border-radius: 8px; background: var(--verde);
  color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.card-login button:active { background: var(--verde-escuro); }
.erro { background: #FDECEA; color: #B3261E; padding: 10px; border-radius: 8px; font-size: 14px; }

/* ---------- layout ---------- */
#app { display: flex; height: 100dvh; }
#painel-lista {
  width: 380px; flex-shrink: 0; display: flex; flex-direction: column;
  background: #fff; border-right: 1px solid var(--borda);
}
#painel-chat { flex: 1; display: flex; flex-direction: column; background: var(--fundo-chat); min-width: 0; }

.topo {
  background: var(--verde-escuro); color: #fff; padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
}
.topo-linha { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.titulo { display: flex; flex-direction: column; line-height: 1.25; }
.titulo strong { font-size: 18px; }
.estado { font-size: 12px; opacity: .85; }
.estado.on::before { content: "● "; color: var(--verde-claro); }
.estado.off::before { content: "● "; color: #F15C6D; }
.icone-btn {
  background: transparent; border: 0; color: #fff; font-size: 20px; cursor: pointer;
  padding: 6px 10px; border-radius: 50%; text-decoration: none; line-height: 1;
}
.icone-btn:active { background: rgba(255,255,255,.15); }
#busca {
  width: 100%; padding: 9px 14px; border: 0; border-radius: 18px; font-size: 15px;
  background: rgba(255,255,255,.14); color: #fff;
}
#busca::placeholder { color: rgba(255,255,255,.65); }
#busca:focus { outline: none; background: #fff; color: var(--texto); }

/* ---------- lista de conversas ---------- */
.lista { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.conversa {
  display: flex; gap: 12px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid #F5F6F6; align-items: center;
}
.conversa:hover { background: #F5F6F6; }
.conversa.ativa { background: #E9EDEF; }
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--verde); color: #fff; display: grid; place-items: center;
  font-size: 18px; font-weight: 600; text-transform: uppercase;
  position: relative; overflow: hidden;
}
/* a inicial fica embaixo; a foto cobre quando (e se) carregar */
.avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%; background: var(--verde);
}
.conversa-corpo { flex: 1; min-width: 0; }
.conversa-linha { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conversa-nome { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversa-hora { font-size: 12px; color: var(--texto-fraco); flex-shrink: 0; }
.conversa-previa {
  font-size: 14px; color: var(--texto-fraco); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; margin-top: 2px;
}
.badge {
  background: var(--verde-claro); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center;
  padding: 0 6px; flex-shrink: 0;
}
.vazio { padding: 30px 16px; text-align: center; color: var(--texto-fraco); font-size: 14px; }

/* ---------- chat ---------- */
#chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.topo-chat { flex-direction: row; align-items: center; gap: 10px; }
.topo-chat .avatar { width: 38px; height: 38px; font-size: 15px; background: var(--verde); }
.chat-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.chat-info strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-info span { font-size: 12px; opacity: .85; }
#voltar { display: none; }

.placeholder {
  flex: 1; display: grid; place-items: center; align-content: center; gap: 12px;
  color: var(--texto-fraco); text-align: center; padding: 24px;
}
.placeholder-icone { font-size: 56px; opacity: .5; }

.mensagens {
  flex: 1; overflow-y: auto; padding: 14px 6%; overscroll-behavior: contain;
  background-color: var(--fundo-chat);
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
  background-size: 22px 22px;
}
.carregar-mais {
  display: block; margin: 0 auto 12px; padding: 7px 16px; border: 0; border-radius: 14px;
  background: rgba(255,255,255,.85); color: var(--texto-fraco); font-size: 13px; cursor: pointer;
}
.dia {
  text-align: center; margin: 14px 0 10px;
}
.dia span {
  background: rgba(225,245,254,.92); color: var(--texto-fraco); font-size: 12px;
  padding: 5px 12px; border-radius: 8px; text-transform: capitalize;
}
.balao {
  max-width: min(78%, 560px); margin-bottom: 8px; padding: 7px 10px 5px;
  border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); position: relative;
  font-size: 15px; line-height: 1.4; word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap; clear: both;
}
.balao.eu { background: var(--bolha-eu); margin-left: auto; border-top-right-radius: 2px; }
.balao.ele { background: var(--bolha-ele); margin-right: auto; border-top-left-radius: 2px; }
.balao.sistema {
  background: rgba(225,245,254,.92); margin: 10px auto; text-align: center;
  font-size: 12.5px; color: var(--texto-fraco); box-shadow: none; max-width: 80%;
}
.balao.apagada { font-style: italic; color: var(--texto-fraco); }
.hora { font-size: 11px; color: var(--texto-fraco); float: right; margin: 6px 0 0 8px; }
.citada {
  border-left: 3px solid var(--verde); background: rgba(0,0,0,.045);
  border-radius: 4px; padding: 5px 8px; margin-bottom: 5px; font-size: 13.5px;
  color: var(--texto-fraco); white-space: pre-wrap;
  max-height: 62px; overflow: hidden;
}
.balao img, .balao video {
  max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; cursor: pointer;
}
.balao audio { width: min(260px, 60vw); margin: 2px 0; }
.anexo-arquivo {
  display: flex; gap: 10px; align-items: center; background: rgba(0,0,0,.05);
  border-radius: 6px; padding: 9px 11px; margin-bottom: 4px; text-decoration: none; color: inherit;
}
.anexo-arquivo .ico { font-size: 24px; }
.anexo-arquivo small { display: block; color: var(--texto-fraco); font-size: 12px; }
.pendente { color: var(--texto-fraco); font-size: 13.5px; font-style: italic; }

.barra-envio {
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: #F0F2F5; flex-shrink: 0;
}
.barra-envio .icone-btn { color: var(--texto-fraco); font-size: 22px; }
#entrada {
  flex: 1; border: 0; border-radius: 20px; padding: 11px 14px; font-size: 16px;
  resize: none; max-height: 120px; font-family: inherit; line-height: 1.35;
}
#entrada:focus { outline: 2px solid var(--verde); }
.enviar {
  width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--verde);
  color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0;
}
.enviar:disabled { opacity: .5; cursor: default; }
.enviando { text-align: center; font-size: 12px; color: var(--texto-fraco); padding: 0 0 6px; }
.falhou { color: #B3261E; }

/* ---------- mobile: uma tela por vez ---------- */
@media (max-width: 820px) {
  #painel-lista { width: 100%; }
  #painel-chat { position: fixed; inset: 0; z-index: 10; transform: translateX(100%);
                 transition: transform .18s ease-out; }
  #app.aberto #painel-chat { transform: translateX(0); }
  #app.aberto #painel-lista { display: none; }
  #voltar { display: block; }
  .placeholder { display: none; }
  .mensagens { padding: 12px 10px; }
  .balao { max-width: 85%; }
}
