/* =====================================================
   YOUKUT — Chat widget (botão flutuante + painel)
===================================================== */

/* ---------- Botão flutuante ---------- */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(255,184,77,0.35);
  z-index: 150;
  transition: transform .15s ease, box-shadow .15s ease;
}
.chat-fab svg { width: 24px; height: 24px; }
.chat-fab:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 10px 26px rgba(255,184,77,0.42); }
.chat-fab:active { transform: translateY(0) scale(0.98); }
.chat-fab.is-open { background: var(--surface-2); color: var(--text); box-shadow: var(--shadow); }

.chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--bg);
}

/* ---------- Painel ---------- */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 360px;
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 150;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatPanelIn .18s ease;
  transform-origin: bottom right;
}
@keyframes chatPanelIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-panel-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.chat-panel-title > div { display: flex; flex-direction: column; min-width: 0; }
#chat-panel-title-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-thread-status { font-size: 11.5px; color: var(--success); }

.chat-icon-btn {
  background: none; border: none; color: var(--text-muted); padding: 6px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s ease, color .15s ease;
}
.chat-icon-btn svg { width: 18px; height: 18px; }
.chat-icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Lista de amigos ---------- */
.chat-list-view { flex: 1; overflow-y: auto; }
.chat-list-label {
  padding: 12px 16px 4px;
  margin: 0;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
.chat-empty { padding: 30px 20px; font-size: 13.5px; line-height: 1.5; }

.chat-friend-search {
  display: block; width: calc(100% - 24px); margin: 4px 12px 8px;
  font-size: 13.5px; padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text);
}
.chat-friend-search::placeholder { color: var(--text-muted); }

.chat-friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background .12s ease;
  border-bottom: 1px solid var(--border);
}
.chat-friend-row:hover { background: var(--surface-2); }
.chat-friend-row .avatar { flex-shrink: 0; }
.chat-friend-info { flex: 1; min-width: 0; }
.chat-friend-name-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-friend-name { font-weight: 700; font-size: 13.5px; }
.chat-friend-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.chat-friend-preview {
  font-size: 12.5px; color: var(--text-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-friend-preview.unread { color: var(--text); font-weight: 600; }
.chat-unread-dot {
  background: var(--accent); color: var(--accent-ink); font-size: 10.5px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 999px; display: flex; align-items: center;
  justify-content: center; padding: 0 4px; flex-shrink: 0;
}

/* ---------- Thread de conversa ---------- */
.chat-thread-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px;
}
.chat-msg-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-msg-row.mine { justify-content: flex-end; }
.chat-bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg-row.theirs .chat-bubble { background: var(--surface-2); color: var(--text); border-bottom-left-radius: 4px; }
.chat-msg-row.mine .chat-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }

.chat-msg-meta {
  display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 10.5px; color: var(--text-muted);
}
.chat-msg-row.mine .chat-msg-meta { justify-content: flex-end; }
.chat-msg-row.mine .group-msg-actions { justify-content: flex-end; }
.chat-msg-group {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  min-width: 0;
}
.chat-msg-avatar {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.chat-seen-check { color: var(--accent-2); }

.chat-day-divider {
  text-align: center; font-size: 11px; color: var(--text-muted); margin: 10px 0 4px;
}

.chat-send-form {
  display: flex; align-items: center; gap: 8px; padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-send-form input { flex: 1; min-width: 0; border-radius: 999px; }
.chat-attach-btn {
  background: none; border: none; color: var(--text-muted); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; padding: 6px; cursor: pointer;
}
.chat-attach-btn:hover { color: var(--text); }
.chat-send-btn {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 50%;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: filter .12s ease, transform .12s ease;
}
.chat-send-btn svg { width: 17px; height: 17px; }
.chat-send-btn:hover { filter: brightness(1.08); }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }

.chat-image-preview-wrap {
  position: relative; margin: 0 12px 10px; border-radius: var(--radius-sm); overflow: hidden;
  max-width: 180px; flex-shrink: 0; background: #000;
}
/* Áudio precisa de mais largura que a thumbnail de imagem/vídeo pros
   controles nativos do player caberem direito — a classe é ligada via
   JS junto com a inserção do preview de áudio */
.chat-image-preview-wrap.has-audio-preview {
  max-width: 280px; background: none; overflow: visible;
}
.chat-image-preview { width: 100%; max-height: 140px; object-fit: cover; display: block; }
#chat-video-preview { width: 100%; max-height: 160px; display: block; }

.chat-msg-image {
  max-width: min(220px, 100%); max-height: 260px; width: auto; border-radius: 14px; object-fit: cover;
  display: block; margin-bottom: 4px; cursor: pointer;
}
.chat-msg-video {
  max-width: min(240px, 100%); max-height: 280px; width: auto; border-radius: 14px;
  display: block; margin-bottom: 4px; background: #000;
}

/* ---------- Mensagem de voz: gravação e player ---------- */
.chat-mic-btn { flex-shrink: 0; }

/* Enquanto grava, essa linha substitui o resto do formulário
   (input + botões de anexo + enviar, escondidos via JS) */
.chat-audio-recording {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
}
.chat-audio-rec-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--danger);
  flex-shrink: 0; animation: chatAudioRecPulse 1.2s ease-in-out infinite;
}
@keyframes chatAudioRecPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .45; transform: scale(0.8); }
}
.chat-audio-rec-timer {
  font-variant-numeric: tabular-nums; font-size: 13.5px; color: var(--text-muted); flex-shrink: 0;
}
.chat-audio-rec-btn {
  background: none; border: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; margin-left: auto;
}
.chat-audio-rec-cancel { color: var(--text-muted); }
.chat-audio-rec-cancel:hover { color: var(--danger); background: rgba(255,255,255,0.06); }
.chat-audio-rec-confirm { color: var(--accent-ink); background: var(--accent); margin-left: 6px; }
.chat-audio-rec-confirm:hover { filter: brightness(1.08); }

/* Player customizado — o <audio controls> nativo praticamente não
   sobra nada visível numa bolha estreita, então esse player próprio
   garante que o play/pause, a barra de progresso e a duração fiquem
   sempre visíveis e fáceis de usar, tanto no mouse quanto no toque. */
.audio-player {
  display: flex; align-items: center; gap: 10px;
  max-width: min(260px, 100%); width: 100%;
  background: var(--surface-2); border-radius: 999px;
  padding: 6px 14px 6px 6px; margin-bottom: 4px;
}
.chat-audio-preview-bubble .audio-player { background: none; padding-left: 0; padding-right: 0; }

.audio-player-btn {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: filter .12s ease, transform .1s ease;
}
.audio-player-btn:hover { filter: brightness(1.08); }
.audio-player-btn:active { transform: scale(0.94); }
.audio-player-btn svg.hidden { display: none; }
/* O ícone de play não é perfeitamente centralizado visualmente (é um
   triângulo) — desloca 1px pra direita pra compensar */
.audio-player-btn .icon-play { margin-left: 1px; }

/* A barra visual é fina (4px), mas a área clicável/arrastável é bem
   maior (padding vertical) — importante pro toque no celular, onde
   acertar uma linha de 4px de altura é frustrante */
.audio-player-progress-bg {
  flex: 1; min-width: 50px; padding: 12px 0; cursor: pointer; touch-action: none;
}
.audio-player-progress-track {
  height: 4px; border-radius: 999px; background: var(--border); position: relative; overflow: hidden;
}
.audio-player-progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: var(--accent); border-radius: 999px;
}
.audio-player-time {
  flex-shrink: 0; font-size: 11.5px; color: var(--text-muted);
  font-variant-numeric: tabular-nums; min-width: 32px; text-align: right;
}
.audio-player-el { display: none; } /* só usado como motor de áudio — a UI é toda customizada acima */

/* Mobile: alvo de toque maior no botão (recomendação de ~44px) e
   mais espaço na barra de progresso pra facilitar o arrasto com o dedo */
@media (max-width: 640px) {
  .audio-player { gap: 12px; padding: 6px 14px 6px 6px; }
  .audio-player-btn { width: 44px; height: 44px; }
  .audio-player-progress-bg { padding: 14px 0; }
}

.chat-audio-preview-bubble {
  padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border); /* tracejado = deixa claro que é só um rascunho, ainda não foi enviado */
}
.chat-audio-preview-label {
  font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600;
}

.chat-typing-hint { font-size: 11.5px; color: var(--text-muted); padding: 0 16px 8px; font-style: italic; }

/* ---------- Responsivo: painel ocupa a tela toda no mobile ---------- */
@media (max-width: 480px) {
  .chat-panel {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100%; height: 100%; max-height: 100%;
    border-radius: 0;
  }
  .chat-fab { bottom: 18px; right: 18px; }

  /* Mesmo ajuste feito na página dedicada de chat — o painel ocupa a
     tela toda por baixo do notch/barra de status aqui também, então
     precisa reservar esse espaço manualmente */
  .chat-panel-header { padding-top: calc(14px + var(--safe-top-forced, env(safe-area-inset-top))); }
  .chat-send-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) and (max-width: 480px) {
  .chat-panel-header { padding-top: 56px !important; }
  .chat-send-form { padding-bottom: 24px !important; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel { animation: none; }
}
