/* Cores usadas no site inteiro, num lugar só */
:root {
  --verde: #00a884;
  --verde-escuro: #008069;
  --fundo: #f0f2f5;
  --fundo-chat: #efeae2;
  --balao-saida: #d9fdd3;
  --borda: #d1d7db;
  --texto-fraco: #667781;
  --erro: #c0392b;

  /* Cores dos status e da distribuição */
  --inicial: #e3f2fd;
  --inicial-texto: #1565c0;
  --atendendo: #fff4e0;
  --atendendo-texto: #b26a00;
  --finalizado: #e8f5e9;
  --finalizado-texto: #2e7d32;
  --sem-atendente: #f57c00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--fundo);
  color: #111b21;
}

a { color: var(--verde-escuro); }

button {
  background: var(--verde);
  color: white;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
}
button:hover { background: var(--verde-escuro); }
button.secundario { background: white; color: var(--verde-escuro); border: 1px solid var(--borda); }

input, select, textarea {
  font: inherit;
  padding: 8px;
  border: 1px solid var(--borda);
  border-radius: 6px;
  width: 100%;
}

/* ---------- Topo ---------- */
.topo {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  height: 52px;
  background: var(--verde-escuro);
  color: white;
}
.topo nav { display: flex; gap: 16px; flex: 1; }
.topo a { color: white; text-decoration: none; }
.topo nav a { white-space: nowrap; }
.topo a:hover { text-decoration: underline; }
.sair { display: flex; align-items: center; gap: 12px; }
.sair button { background: transparent; border: 1px solid white; }

/* ---------- Caixas simples (login, perfis, resumo) ---------- */
.caixa {
  max-width: 560px;
  margin: 32px auto;
  padding: 24px;
  background: white;
  border-radius: 8px;
}
.caixa-login { max-width: 360px; margin-top: 80px; }
.formulario { display: flex; flex-direction: column; gap: 12px; }
.formulario label { display: flex; flex-direction: column; gap: 4px; }
fieldset { border: 1px solid var(--borda); border-radius: 6px; display: flex; flex-direction: column; gap: 8px; }

.erro { color: var(--erro); }
.sucesso { color: var(--verde-escuro); }
.dica, .vazio { color: var(--texto-fraco); font-size: 14px; }
.vazio { padding: 16px; text-align: center; }

table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--borda); }

/* ---------- Tela de conversas: duas colunas ---------- */
.central {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - 52px);
}

.lista {
  background: white;
  border-right: 1px solid var(--borda);
  overflow-y: auto;
}
.filtro { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-bottom: 1px solid var(--borda); }

.item {
  display: block;
  padding: 10px 16px;
  border-bottom: 1px solid var(--fundo);
  color: inherit;
  text-decoration: none;
}
.item:hover { background: var(--fundo); }
.item.ativo { background: #e6f4f1; }
.item.finalizado { opacity: 0.6; }
/* Conversa ainda não distribuída: faixa laranja à esquerda */
.item.sem-atendente { border-left: 4px solid var(--sem-atendente); padding-left: 12px; }
.linha { display: flex; justify-content: space-between; }
.hora { font-size: 12px; color: var(--texto-fraco); }
.previa {
  color: var(--texto-fraco);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.etiqueta {
  display: inline-block;
  margin-top: 4px;
  margin-right: 4px;
  padding: 1px 8px;
  font-size: 12px;
  border-radius: 10px;
  background: var(--fundo);
}
.status-inicial { background: var(--inicial); color: var(--inicial-texto); }
.status-atendendo { background: var(--atendendo); color: var(--atendendo-texto); }
.status-finalizado { background: var(--finalizado); color: var(--finalizado-texto); }
.etiqueta.distribuida { background: var(--fundo); color: var(--texto-fraco); }
.etiqueta.nao-distribuida { background: var(--sem-atendente); color: white; font-weight: 600; }

/* ---------- WhatsApp (admin) ---------- */
.qr { display: block; width: 260px; height: 260px; margin: 16px auto; }
.aviso-risco {
  margin-top: 24px;
  padding: 10px 12px;
  font-size: 14px;
  border-left: 4px solid var(--sem-atendente);
  background: var(--atendendo);
}
.erro-envio { margin: 0; padding: 8px 16px; background: #fdecea; }

/* ---------- Resumo (admin) ---------- */
.caixa-larga { max-width: 820px; }
.cartoes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.cartao {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--fundo);
}
.cartao span { font-size: 14px; }
.cartao strong { font-size: 28px; }
.numero { text-align: right; }
.resumo tfoot th { border-top: 2px solid var(--borda); border-bottom: 0; }
.resumo tr.sem-atendente td:first-child { border-left: 4px solid var(--sem-atendente); }

.chat {
  display: flex;
  flex-direction: column;
  background: var(--fundo-chat);
  min-height: 0;
}
.chat-topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--fundo);
  border-bottom: 1px solid var(--borda);
}
.chat-topo small { color: var(--texto-fraco); margin-right: 6px; }
.acoes { display: flex; align-items: center; gap: 12px; }
.acoes select { width: auto; }

.mensagens {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.balao {
  max-width: 65%;
  padding: 6px 10px;
  border-radius: 8px;
  background: white;
  align-self: flex-start;
}
.balao.saida { background: var(--balao-saida); align-self: flex-end; }
.balao .texto { white-space: pre-wrap; word-wrap: break-word; }
.balao small { display: block; text-align: right; font-size: 11px; color: var(--texto-fraco); }

/* Imagens e documentos dentro do balão */
.balao .foto {
  display: block;
  max-width: 280px;
  max-height: 320px;
  margin-bottom: 4px;
  border-radius: 6px;
}
.balao .documento {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.05);
  color: inherit;
  text-decoration: none;
}
.balao .documento:hover { background: rgba(0, 0, 0, 0.09); }
.doc-icone { font-size: 28px; }
.doc-info { display: flex; flex-direction: column; min-width: 0; }
.doc-info strong { overflow-wrap: anywhere; }
.balao .doc-info small { text-align: left; }

/* Caixa de resposta */
.responder {
  position: relative; /* o painel de emojis se posiciona em relação a ela */
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--fundo);
}
.responder .icone {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 22px;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.responder .icone:hover { background: var(--borda); }
.campo-texto { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.anexo-escolhido {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--verde-escuro);
}
.anexo-escolhido[hidden], .emoji-painel[hidden] { display: none; }
.anexo-escolhido button { padding: 0 6px; background: transparent; color: var(--erro); }
.anexo-escolhido button:hover { background: transparent; text-decoration: underline; }

.emoji-painel {
  position: absolute;
  bottom: 100%;
  left: 16px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
  width: 360px;
  max-width: calc(100% - 32px);
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--borda);
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}
.emoji-painel button {
  padding: 4px 0;
  font-size: 22px;
  line-height: 1;
  background: transparent;
}
.emoji-painel button:hover { background: var(--fundo); }
.aviso { text-align: center; color: var(--texto-fraco); padding: 12px; margin: 0; background: var(--fundo); }

/* ---------- Não lidas, busca, histórico e detalhes da conversa ---------- */
.contador {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--verde);
  color: white;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.contador[hidden] { display: none; }
.topo .contador { background: white; color: var(--verde-escuro); margin-left: 2px; }

.item.nao-lida strong,
.item.nao-lida .previa { font-weight: 700; color: #111b21; }
.item .linha { gap: 8px; align-items: center; }
.item .previa { flex: 1; min-width: 0; }

.limpar-busca { font-size: 13px; }

.topo .conta { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sair form { margin: 0; }
.topo .som { padding: 4px 8px; background: transparent; border: 1px solid transparent; font-size: 18px; }
.topo .som:hover { background: rgba(255, 255, 255, 0.15); }

.contato-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.voltar { display: none; font-size: 24px; text-decoration: none; }
.editar-nome { display: inline-block; vertical-align: middle; }
.editar-nome summary { cursor: pointer; list-style: none; color: var(--texto-fraco); padding: 0 4px; }
.editar-nome summary::-webkit-details-marker { display: none; }
.editar-nome[open] { display: block; }
.editar-nome form { display: flex; gap: 6px; margin: 4px 0; }
.editar-nome input { min-width: 160px; }

.historico { padding: 6px 16px; background: #fffbe6; border-bottom: 1px solid var(--borda); font-size: 14px; }
.historico summary { cursor: pointer; }
.historico ul { margin: 6px 0 2px; padding-left: 20px; }

.balao .video { display: block; max-width: 100%; width: 320px; margin-bottom: 4px; border-radius: 6px; background: black; }
.balao .audio { display: block; width: 260px; max-width: 100%; margin-bottom: 4px; }

/* Os "vistos" das mensagens enviadas */
.visto { margin-left: 4px; letter-spacing: -2px; }
.visto.lida { color: #53bdeb; }

/* ---------- Perfis (admin) ---------- */
.tabela-rolavel { overflow-x: auto; }
tr.desativado { opacity: 0.55; }
button.perigo { background: var(--erro); }
button.perigo:hover { background: #962d22; }
.senha-temporaria { margin: 16px 0; padding: 12px 16px; border: 2px dashed var(--verde); border-radius: 8px; background: #f0fbf8; }
.senha-temporaria p { margin: 4px 0; }
.senha-temporaria code { display: inline-block; margin: 4px 0; padding: 6px 12px; font-size: 20px; letter-spacing: 1px; background: white; border: 1px solid var(--borda); border-radius: 6px; user-select: all; }

/* ---------- Celular ---------- */
/* Em telas estreitas, mostramos só a lista OU só a conversa aberta (com um botão ← para voltar) */
@media (max-width: 700px) {
  .topo { gap: 8px; padding: 0 10px; }
  .topo .marca { display: none; }
  .topo nav { gap: 12px; overflow-x: auto; }
  .topo .conta { max-width: 80px; font-size: 14px; }

  .caixa { margin: 12px 8px; padding: 16px; }
  .caixa-login { margin-top: 32px; }
  .cartoes { grid-template-columns: repeat(2, 1fr); }

  .central { grid-template-columns: 1fr; height: calc(100dvh - 52px); }
  .central.com-conversa .lista { display: none; }
  .central:not(.com-conversa) .chat { display: none; }
  .voltar { display: inline-flex; }

  .chat-topo { flex-wrap: wrap; padding: 8px 10px; }
  .acoes { flex-wrap: wrap; gap: 8px; }
  .acoes label { font-size: 13px; }
  .acoes select { max-width: 150px; padding: 6px; }

  .mensagens { padding: 12px 10px; }
  .balao { max-width: 88%; }
  .balao .foto { max-width: 100%; }
  .historico { padding: 6px 10px; }

  .responder { padding: 8px; gap: 4px; }
  .responder .icone { width: 36px; height: 36px; }
  .emoji-painel { left: 8px; grid-template-columns: repeat(8, 1fr); width: calc(100% - 16px); }
}
