/* =================================================================
   WhatsApp dos clientes — widget retrátil no canto da tela, com as
   conversas do Oxide. Substituiu o chat interno e herdou o lugar e as
   camadas dele: z-index 300, acima do modal de orçamento (100) e da página
   de relatórios (200); sai do caminho só no visualizador de foto.
   ================================================================= */

#wa-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  font-family: var(--fonte-display);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* O contêiner é transparente: só o botão e o painel recebem clique. */
  pointer-events: none;
}
#wa-widget > * { pointer-events: auto; }
body:has(#visualizador-foto:not(.oculta)) #wa-widget { display: none; }

/* ----- Botão flutuante ----- */
.wa-bolha {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-elevado);
  border: 1px solid var(--linha-forte);
  box-shadow: var(--sombra);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--verde);
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.wa-bolha:hover { background: var(--bg-input); border-color: var(--acento-escuro); transform: translateY(-2px); }
.wa-bolha svg { width: 25px; height: 25px; }

.wa-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--vermelho);
  color: #fff;
  font-family: var(--fonte-mono);
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid var(--bg-base);
}
@keyframes wa-pulso {
  0%   { box-shadow: var(--sombra), 0 0 0 0 rgba(74, 222, 128, 0.55); }
  70%  { box-shadow: var(--sombra), 0 0 0 12px rgba(74, 222, 128, 0); }
  100% { box-shadow: var(--sombra), 0 0 0 0 rgba(74, 222, 128, 0); }
}
.wa-bolha.pulsando { animation: wa-pulso 1.2s ease-out 2; }

/* ----- Painel ----- */
.wa-painel {
  width: 380px;
  height: min(600px, calc(100vh - 120px));
  background: var(--bg-superficie);
  border: 1px solid var(--linha-forte);
  border-radius: 8px;
  box-shadow: var(--sombra);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: wa-abrir 0.14s ease-out;
}
@keyframes wa-abrir {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.wa-cabecalho {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elevado);
  border-bottom: 1px solid var(--linha);
  flex-shrink: 0;
}
.wa-titulo {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-subtitulo {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--texto-fraco);
  font-family: var(--fonte-mono);
}
.wa-btn-icone {
  width: 30px;
  height: 30px;
  border-radius: var(--raio);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--texto-medio);
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}
.wa-btn-icone:hover { background: var(--bg-input); color: var(--texto); }

.wa-busca {
  padding: 8px 10px;
  border-bottom: 1px solid var(--linha);
  flex-shrink: 0;
}
.wa-busca input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--linha);
  border-radius: var(--raio);
  color: var(--texto);
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
}

.wa-corpo {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.wa-vazio {
  padding: 32px 18px;
  text-align: center;
  color: var(--texto-fraco);
  font-size: 13px;
  line-height: 1.5;
}
.wa-erro { color: var(--vermelho); }

/* ----- Lista ----- */
.wa-item {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-bottom: 1px solid var(--linha);
  text-align: left;
  cursor: pointer;
}
.wa-item:hover { background: var(--bg-elevado); }
.wa-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-input);
  border: 1px solid var(--linha-forte);
  color: var(--texto-medio);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wa-item-texto { flex: 1; min-width: 0; }
.wa-item-linha { display: flex; align-items: baseline; gap: 8px; }
.wa-item-nome {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-item.nao-lida .wa-item-nome { color: var(--acento-claro); }
.wa-item-hora { font-family: var(--fonte-mono); font-size: 10.5px; color: var(--texto-fraco); }
.wa-item.nao-lida .wa-item-hora { color: var(--verde); }
.wa-item-previa {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--texto-fraco);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-contador {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--verde);
  color: var(--bg-base);
  font-family: var(--fonte-mono);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* Etapa do funil e etiquetas do Oxide */
.wa-etiquetas { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.wa-etiqueta {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  line-height: 16px;
  padding: 0 7px;
  border-radius: 99px;
  border: 1px solid var(--cor, var(--linha-forte));
  color: var(--cor, var(--texto-medio));
  background: color-mix(in srgb, var(--cor, transparent) 12%, transparent);
  white-space: nowrap;
}

/* ----- Conversa ----- */
.wa-mensagens { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.wa-dia {
  align-self: center;
  margin: 6px 0;
  font-size: 10.5px;
  font-family: var(--fonte-mono);
  color: var(--texto-fraco);
  background: var(--bg-elevado);
  border-radius: 99px;
  padding: 1px 9px;
}
.wa-balao {
  max-width: 82%;
  padding: 6px 9px 4px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg-elevado);
  border: 1px solid var(--linha);
  align-self: flex-start;
}
.wa-balao.out {
  align-self: flex-end;
  background: color-mix(in srgb, var(--verde) 12%, var(--bg-elevado));
  border-color: color-mix(in srgb, var(--verde) 30%, var(--linha));
}
.wa-balao.falhou { border-color: var(--vermelho); }
.wa-origem {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--texto-fraco);
  margin-bottom: 2px;
}
.wa-origem.ia, .wa-origem.assistente { color: var(--roxo); }
.wa-origem.orcamentos { color: var(--azul); }
.wa-rodape {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-family: var(--fonte-mono);
  font-size: 10px;
  color: var(--texto-fraco);
}
.wa-rodape .lida { color: var(--azul); }
.wa-rodape .falha { color: var(--vermelho); }
.wa-midia-img {
  display: block;
  max-width: 100%;
  max-height: 240px;
  border-radius: 5px;
  margin-bottom: 4px;
  cursor: zoom-in;
}
.wa-balao audio { width: 230px; max-width: 100%; margin-bottom: 2px; }
.wa-anexo { color: var(--azul); text-decoration: underline; }

.wa-aviso {
  padding: 5px 12px;
  font-size: 11px;
  color: var(--amarelo);
  background: color-mix(in srgb, var(--amarelo) 8%, transparent);
  border-top: 1px solid var(--linha);
  flex-shrink: 0;
}
.wa-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 10px;
  border-top: 1px solid var(--linha);
  background: var(--bg-elevado);
  flex-shrink: 0;
}
.wa-form textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--bg-input);
  border: 1px solid var(--linha);
  border-radius: var(--raio);
  color: var(--texto);
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
}
.wa-enviar {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--raio);
  background: var(--verde);
  color: var(--bg-base);
  font-weight: 700;
  font-size: 13px;
}
.wa-enviar:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 520px) {
  #wa-widget { right: 12px; bottom: 12px; left: 12px; align-items: flex-end; }
  .wa-painel { width: 100%; height: calc(100vh - 96px); height: calc(100dvh - 96px); }
}
