/* public/css/style.css — Design inspirado no WhatsApp */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --verde-escuro:   #075e54;
  --verde-medio:    #128c7e;
  --verde-claro:    #25d366;
  --verde-bolha:    #d9fdd3;
  --bg-chat:        #efeae2;
  --bg-sidebar:     #fff;
  --bg-input:       #f0f2f5;
  --texto-primario: #111b21;
  --texto-secundario: #667781;
  --borda:          #e9edef;
  --sombra:         rgba(0,0,0,.08);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-chat);
  color: var(--texto-primario);
}

/* ── Layout principal ─────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  box-shadow: 0 0 40px rgba(0,0,0,.15);
}

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  width: 380px;
  min-width: 300px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--borda);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  background: var(--verde-escuro);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.perfil-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

#sidebar-header .perfil-nome {
  color: #fff;
  font-weight: 600;
  font-size: .95rem;
  flex: 1;
}

.icone-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.85);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: background .15s;
}

.icone-btn:hover { background: rgba(255,255,255,.15); }

#busca-wrapper {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--borda);
}

#busca {
  width: 100%;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: .9rem;
  outline: none;
  color: var(--texto-primario);
}

#lista-conversas {
  flex: 1;
  overflow-y: auto;
}

.conversa-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--borda);
  transition: background .15s;
  position: relative;
}

.conversa-item:hover  { background: #f5f6f6; }
.conversa-item.ativa  { background: #f0f2f5; }

.conversa-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  position: relative;
}

.indicador-online {
  position: absolute;
  bottom: 2px; right: 2px;
  width: 11px; height: 11px;
  background: var(--verde-claro);
  border: 2px solid #fff;
  border-radius: 50%;
}

.conversa-info { flex: 1; min-width: 0; }

.conversa-topo {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.conversa-nome {
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversa-hora { font-size: .78rem; color: var(--texto-secundario); flex-shrink: 0; }

.conversa-preview {
  font-size: .85rem;
  color: var(--texto-secundario);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-nao-lida {
  background: var(--verde-claro);
  color: #fff;
  border-radius: 12px;
  padding: 2px 7px;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Painel do chat ───────────────────────────────────────────── */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-header {
  background: var(--verde-escuro);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#chat-header .conversa-avatar { width: 40px; height: 40px; font-size: 1rem; }

#chat-header-info { flex: 1; }
#chat-header-nome { color: #fff; font-weight: 600; font-size: 1rem; }
#chat-header-status { color: rgba(255,255,255,.7); font-size: .8rem; }

/* ── Área de mensagens ────────────────────────────────────────── */
#mensagens {
  flex: 1;
  overflow-y: auto;
  padding: 12px 5%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-chat)
    url("data:image/svg+xml,%3Csvg width='400' height='400' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h400v400H0z' fill='%23e5ddd5' opacity='.3'/%3E%3C/svg%3E");
}

.separador-data {
  text-align: center;
  margin: 8px 0;
}

.separador-data span {
  background: rgba(225,245,254,.9);
  color: var(--texto-secundario);
  font-size: .78rem;
  padding: 4px 12px;
  border-radius: 8px;
}

/* Bolhas */
.msg {
  max-width: 65%;
  display: flex;
  flex-direction: column;
  margin: 1px 0;
}

.msg.enviada  { align-self: flex-end; }
.msg.recebida { align-self: flex-start; }

.msg-bolha {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .93rem;
  line-height: 1.45;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 2px var(--sombra);
}

.msg.enviada  .msg-bolha { background: var(--verde-bolha); border-bottom-right-radius: 2px; }
.msg.recebida .msg-bolha { background: #fff; border-bottom-left-radius: 2px; }

.msg-remetente {
  font-size: .78rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.msg-hora {
  font-size: .72rem;
  color: var(--texto-secundario);
  text-align: right;
  margin-top: 3px;
  float: right;
  margin-left: 8px;
}

/* Imagem */
.msg-imagem {
  max-width: 280px;
  border-radius: 8px;
  cursor: zoom-in;
  display: block;
}

/* Áudio */
.msg-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
}

.msg-audio audio { flex: 1; height: 36px; }

/* Documento */
.msg-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,.04);
  border-radius: 6px;
  padding: 8px;
  min-width: 200px;
  text-decoration: none;
  color: inherit;
}

.msg-doc svg { flex-shrink: 0; color: var(--verde-escuro); }
.msg-doc-info .nome { font-size: .88rem; font-weight: 600; }
.msg-doc-info .tamanho { font-size: .75rem; color: var(--texto-secundario); }

/* Indicador "digitando" */
#digitando-indicator {
  padding: 4px 16px;
  font-size: .82rem;
  color: var(--texto-secundario);
  min-height: 24px;
}

/* ── Área de input ────────────────────────────────────────────── */
#input-area {
  background: var(--bg-input);
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-top: 1px solid var(--borda);
  flex-shrink: 0;
}

#btn-anexo, #btn-audio, #btn-enviar {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--texto-secundario);
  transition: background .15s, color .15s;
  flex-shrink: 0;
}

#btn-anexo:hover, #btn-audio:hover { background: #ddd; }

#btn-enviar {
  background: var(--verde-escuro);
  color: #fff;
  width: 44px; height: 44px;
}

#btn-enviar:hover { background: var(--verde-medio); }

#btn-audio.gravando { color: #e53935; animation: pulsar 1s infinite; }
@keyframes pulsar { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

#campo-texto {
  flex: 1;
  background: #fff;
  border: none;
  border-radius: 22px;
  padding: 10px 16px;
  font-size: .95rem;
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
}

/* Menu de anexo */
#menu-anexo {
  position: absolute;
  bottom: 70px;
  left: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  overflow: hidden;
  display: none;
  flex-direction: column;
  z-index: 100;
}

#menu-anexo.aberto { display: flex; }

.opcao-anexo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  font-size: .9rem;
  transition: background .15s;
}

.opcao-anexo:hover { background: #f5f5f5; }
.opcao-anexo svg { color: var(--verde-escuro); }

/* Tela vazia */
#tela-inicial {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--texto-secundario);
  gap: 16px;
}

#tela-inicial svg { opacity: .3; }
#tela-inicial h2 { font-size: 1.4rem; color: var(--texto-primario); }
#tela-inicial p  { font-size: .95rem; max-width: 300px; text-align: center; }

/* Modal de imagem */
#modal-img {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}

#modal-img.aberto { display: flex; }
#modal-img img { max-width: 90vw; max-height: 90vh; border-radius: 4px; }

/* ── Responsivo mobile ────────────────────────────────────────── */
@media (max-width: 700px) {
  #sidebar { width: 100%; }
  #chat-panel { display: none; position: fixed; inset: 0; z-index: 10; background: var(--bg-chat); }
  #chat-panel.aberto { display: flex; }
  #btn-voltar { display: flex !important; }
}

#btn-voltar { display: none; }

/* Scroll customizado */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* Tela de carregamento */
#loading {
  position: fixed; inset: 0;
  background: var(--verde-escuro);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 9999;
  color: #fff;
  font-size: 1rem;
}

.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
