:root {
  --verde: #128c7e;
  --verde-claro: #dcf8c6;
  --cinza-fundo: #f0f2f5;
  --cinza-borda: #e2e2e2;
  --texto: #222;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--texto);
  background: var(--cinza-fundo);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.oculto { display: none !important; }

/* --- Login --- */

.tela-login {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--verde), #0a5c52);
}

.caixa-login {
  background: white;
  padding: 32px;
  border-radius: 12px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.caixa-login h1 { margin: 0; font-size: 20px; }
.caixa-login .subtitulo { margin: 0 0 8px; color: #666; font-size: 13px; }

.caixa-login input {
  padding: 10px 12px;
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  font-size: 14px;
}

.caixa-login button {
  padding: 10px;
  background: var(--verde);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.caixa-login button:hover { background: #0a6b5f; }

.erro { color: #c0392b; font-size: 13px; margin: 0; min-height: 16px; }

/* --- App --- */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  border-right: 1px solid var(--cinza-borda);
  background: white;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-topo {
  padding: 14px 16px;
  background: var(--verde);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  position: relative;
}

.sidebar-topo-menu {
  position: relative;
}

.botao-menu-topo {
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.botao-menu-topo:hover,
.botao-menu-topo.ativo {
  background: rgba(255,255,255,0.3);
}

/* Menu suspenso: junta Nova conversa / Notificações / Equipe / Sair num só
   lugar, em vez de vários botões espremidos lado a lado no topo. */
.menu-topo-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: white;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 210px;
  z-index: 50;
}

.menu-topo-dropdown button {
  background: transparent;
  color: var(--texto);
  border: none;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  width: 100%;
  font-weight: 500;
}

.menu-topo-dropdown button:hover { background: var(--cinza-fundo); }

.menu-topo-dropdown button#botao-notificacoes.ativo {
  background: #e6f7f3;
  color: var(--verde);
}

.menu-topo-dropdown button#botao-notificacoes:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.menu-topo-dropdown button#botao-sair { color: #c0392b; }

.menu-topo-divisor {
  border: none;
  border-top: 1px solid var(--cinza-fundo);
  margin: 4px 2px;
}

.lista-conversas { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.item-conversa {
  padding: 12px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-conversa:hover { background: #f7f7f7; }
.item-conversa.ativo { background: #e9f7f4; }

.item-conversa .linha-topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.item-conversa .nome { font-weight: 600; font-size: 14px; }

.item-conversa .previa {
  font-size: 13px;
  color: #777;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.etiqueta-canal {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eee;
  color: #555;
  text-transform: uppercase;
}

.etiqueta-canal.whatsapp { background: #dcf8c6; color: #075e54; }
.etiqueta-canal.sms { background: #dbeafe; color: #1e3a8a; }

/* --- Painel de chat --- */

.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.chat-vazio {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #999;
}

.chat-ativo { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-cabecalho {
  padding: 14px 20px;
  background: white;
  border-bottom: 1px solid var(--cinza-borda);
  display: flex;
  align-items: center;
  gap: 10px;
}

.botao-editar-nome {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.6;
}

.botao-editar-nome:hover {
  opacity: 1;
  background: var(--cinza-fundo);
}

.chat-mensagens {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #e5ddd5;
}

.bolha {
  max-width: 60%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.bolha.cliente {
  align-self: flex-start;
  background: white;
  border-top-left-radius: 2px;
}

.bolha.funcionario {
  align-self: flex-end;
  background: var(--verde-claro);
  border-top-right-radius: 2px;
}

.bolha .nome-quem-respondeu {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--verde);
  margin-bottom: 2px;
}
.bolha .texto-mensagem {
  white-space: pre-wrap;
  word-break: break-word;
}

.bolha img, .bolha video {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  margin-bottom: 4px;
}

.bolha audio {
  display: block;
  margin-bottom: 4px;
  max-width: 100%;
}

.bolha .hora {
  display: block;
  font-size: 10px;
  color: #999;
  margin-top: 4px;
  text-align: right;
}

.chat-enviar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: white;
  border-top: 1px solid var(--cinza-borda);
}

.botao-anexo {
  cursor: pointer;
  font-size: 20px;
  padding: 6px;
}

.botao-audio {
  cursor: pointer;
  font-size: 18px;
  padding: 6px;
  background: transparent;
  border: none;
  border-radius: 6px;
  line-height: 1;
}

.botao-audio:hover { background: var(--cinza-fundo); }

.botao-audio.gravando {
  background: #c0392b;
  color: white;
  animation: pulsar-gravacao 1.2s infinite;
}

@keyframes pulsar-gravacao {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.nome-arquivo {
  font-size: 12px;
  color: #666;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-enviar textarea#input-texto {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--cinza-borda);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

.chat-enviar button {
  padding: 10px 18px;
  background: var(--verde);
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
}

.chat-enviar button:hover { background: #0a6b5f; }

/* --- Modal: editar nome do cliente --- */

.modal-fundo {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-caixa {
  background: white;
  border-radius: 12px;
  padding: 24px;
  width: 320px;
  max-width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.modal-caixa h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

.modal-caixa input[type="text"],
.modal-caixa input[type="tel"],
.modal-caixa textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
  font-family: inherit;
}

.modal-caixa textarea {
  resize: vertical;
  margin-top: 10px;
}

.modal-subtitulo {
  margin: -6px 0 14px;
  font-size: 12px;
  color: #666;
}

.modal-botoes {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-botoes button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  background: var(--verde);
  color: white;
}

.modal-botoes button:hover { background: #0a6b5f; }

.modal-botoes .botao-secundario {
  background: var(--cinza-fundo);
  color: var(--texto);
}

.modal-botoes .botao-secundario:hover { background: var(--cinza-borda); }

/* --- Modal: gerenciar equipe --- */

.modal-caixa-grande {
  width: 420px;
}

.equipe-lista {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.equipe-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--cinza-fundo);
  font-size: 14px;
}

.equipe-item .equipe-item-nome { font-weight: 600; }

.equipe-item .equipe-item-papel {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  margin-left: 6px;
}

.equipe-item button {
  background: transparent;
  border: none;
  color: #c0392b;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
}

.equipe-item button:hover { text-decoration: underline; }

.equipe-divisor {
  border: none;
  border-top: 1px solid var(--cinza-borda);
  margin: 14px 0;
}

.modal-caixa h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.equipe-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.equipe-form input,
.equipe-form select {
  padding: 10px 12px;
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
}

.equipe-form button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  background: var(--verde);
  color: white;
}

.equipe-form button:hover { background: #0a6b5f; }

/* --- Aviso (toast) --- */
/* Usado no lugar de alert()/confirm(): essas caixas nativas do navegador
   não aparecem no PWA instalado no iPhone (modo standalone). */

.aviso-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(90vw, 380px);
  background: #2a2a2a;
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 200;
  text-align: center;
}

.aviso-toast.erro { background: #c0392b; }

/* --- Marcação de funcionário + reabrir conversa (janela de 24h WhatsApp) --- */

.botao-marcar-funcionario {
  background: transparent;
  border: 1px solid var(--cinza-borda);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #666;
}

.botao-marcar-funcionario:hover { background: var(--cinza-fundo); }

.botao-marcar-funcionario.ativo {
  background: #fff3cd;
  border-color: #f0c93b;
  color: #6b5300;
}

.separador-dia {
  align-self: center;
  background: #e1f3fb;
  color: #54656f;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
  margin: 6px 0;
}
.etiqueta-tipo {
  align-self: flex-start;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #fff3cd;
  color: #6b5300;
}

.bolha .etiqueta-modelo {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: #8a6d00;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.aviso-janela {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: #fff3cd;
  border-top: 1px solid #f0c93b;
  font-size: 13px;
  color: #6b5300;
}

.aviso-janela button {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  background: #6b5300;
  color: white;
  white-space: nowrap;
}

.aviso-janela button:hover { background: #4d3c00; }

.lista-modelos {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.modelo-reabrir-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--cinza-borda);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 13px;
}

.modelo-reabrir-item:hover { background: var(--cinza-fundo); }
.modelo-reabrir-item:disabled { opacity: 0.5; cursor: not-allowed; }

.modelo-reabrir-item strong { font-size: 13px; }
.modelo-reabrir-item span { color: #555; font-size: 12px; }

/* --- Status de entrega das mensagens enviadas (estilo WhatsApp) --- */
.bolha .status-entrega {
  display: inline-block;
  margin-left: 4px;
  font-size: 12px;
}
.bolha .status-entrega.enviado { color: #999; }
.bolha .status-entrega.entregue { color: #8696a0; letter-spacing: -2px; }
.bolha .status-entrega.lido { color: #53bdeb; letter-spacing: -2px; }
.bolha .status-entrega.falhou {
  color: #c0392b;
  cursor: help;
}
