/* =====================================================
   ENLAÇA — 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(--text-muted); }

.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-empty { padding: 30px 20px; font-size: 13.5px; line-height: 1.5; }

.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; }
.chat-msg-row.mine { justify-content: flex-end; }
.chat-bubble {
  max-width: 75%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.4;
  word-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-group { display: flex; flex-direction: column; max-width: 100%; }
.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; border-radius: 999px; }
.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-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; }
}

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