/* CHAT.CSS — Chat panel, messages, conversations, emoji, profiles */

/* ================================================================
   CHAT PANEL
   ================================================================ */

/* FAB badge (mensagens não lidas) */
.qa-chat-wrap { position: relative; }
.chat-fab-badge {
  position: absolute;
  top: -5px; right: -5px;
  min-width: 18px; height: 18px;
  background: #EF233C;
  color: #fff;
  border-radius: 99px;
  font-size: 0.6875rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-card);
  line-height: 1;
  pointer-events: none;
}

/* Dot badge no FAB principal */
.chat-fab-dot {
  position: absolute;
  top: 6px; right: 6px;
  width: 11px; height: 11px;
  background: #EF233C;
  border-radius: 50%;
  border: 2px solid #fff;
  animation: fabDotPulse 2s ease-in-out infinite;
}
@keyframes fabDotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,35,60,0.5); }
  50%       { box-shadow: 0 0 0 5px rgba(239,35,60,0); }
}

/* ── Painel principal ── */
.chat-panel {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 380ms cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}
.chat-panel.active { transform: translateY(0); }

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--primary, #3D6A8E);
  color: #fff;
  flex-shrink: 0;
  min-height: 64px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
}
.chat-back-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-back-btn:hover { background: rgba(255,255,255,0.28); }

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
  margin: -4px -6px;
  transition: background 0.15s;
}
.chat-header-info:hover { background: rgba(255,255,255,0.1); }
.chat-header-avatars {
  position: relative;
  width: 42px; height: 42px;
  flex-shrink: 0;
}
.chat-hdr-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.7);
  position: absolute;
  left: 0; top: 0;
}
.chat-hdr-avatar:first-child { z-index: 2; }
.chat-hdr-avatar-2           { left: 14px; z-index: 1; }

.chat-header-text { flex: 1; min-width: 0; }
.chat-title {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.chat-subtitle {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.75);
}

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.chat-status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #06D6A0;
  box-shadow: 0 0 0 2px rgba(6,214,160,0.3);
  animation: pulse-green 2s infinite;
}
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 2px rgba(6,214,160,0.3); }
  50%       { box-shadow: 0 0 0 5px rgba(6,214,160,0.1); }
}
.chat-status-label {
  font-size: 0.6875rem;
  color: rgba(255,255,255,0.8);
}

/* ── Lista de mensagens ── */
.chat-messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 8px; /* 18px para as caudas (-7px) não serem cortadas */
  display: flex;
  flex-direction: column;
  gap: 0; /* controlado por margin em cada .chat-msg */
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background-color: #eae6df;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c9c4bc' fill-opacity='0.18'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
[data-theme="dark"] .chat-messages-list {
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

/* Estado vazio */
.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  padding: 40px 24px;
  text-align: center;
}
.chat-empty-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(var(--primary-rgb, 61,106,142), 0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  color: var(--primary);
}
.chat-empty-title { font-weight: 700; font-size: 1rem; color: var(--text-primary); margin: 0; }
.chat-empty-sub   { font-size: 0.875rem; color: var(--text-muted); margin: 0; }

/* Placeholder desktop (só visível em tela larga via responsive.css) */
.chat-desktop-placeholder {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-left: 1px solid var(--border);
}

/* Separador de data */
.chat-date-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 8px; /* margin-top garante espaço acima do separador de dia */
  color: var(--text-muted);
  font-size: 0.6875rem;
}
.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.chat-date-sep span {
  background: var(--bg-body);
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* ── Mensagem ── */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  margin-top: 8px; /* espaço entre grupos de remetentes diferentes */
  animation: msgSlide 0.2s ease;
}
@keyframes msgSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-mine   { align-self: flex-end;   flex-direction: row-reverse; margin-right: 8px; }
.msg-theirs { align-self: flex-start; margin-left: 8px; }

.chat-msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 18px; /* alinha com a base da bolha */
}
.chat-avatar-mine { margin-bottom: 18px; }
.chat-avatar-bubble {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.chat-initial {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--grad-primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.chat-bubble-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 100%;
}
.msg-mine   .chat-bubble-col { align-items: flex-end; }
.msg-theirs .chat-bubble-col { align-items: flex-start; }

.chat-sender-name {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--primary);
  margin-left: 4px;
}

.chat-bubble {
  padding: 7px 12px 8px;
  border-radius: 8px;
  word-break: break-word;
  hyphens: auto;
  line-height: 1.45;
  max-width: 100%;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.msg-mine .chat-bubble {
  background: var(--primary, #3D6A8E);
  color: #fff;
  border-top-right-radius: 0;
}
.msg-theirs .chat-bubble {
  background: #fff;
  color: var(--text-primary);
  border: none;
  border-top-left-radius: 0;
}
[data-theme="dark"] .msg-theirs .chat-bubble {
  background: var(--bg-card-alt);
}

.chat-bubble-text {
  margin: 0;
  font-size: 0.9375rem;
  color: inherit;
}

/* Bolha de imagem */
.chat-bubble--img {
  padding: 4px;
  background: transparent !important;
  box-shadow: none;
  border: none;
}
.chat-img-link { display: block; line-height: 0; border-radius: 10px; overflow: hidden; }
.chat-bubble-img {
  max-width: 220px;
  max-height: 300px;
  width: 100%;
  border-radius: 10px;
  display: block;
  object-fit: cover;
  cursor: zoom-in;
  transition: opacity 0.2s;
}
.chat-bubble-img:hover { opacity: 0.92; }

.chat-link {
  color: inherit;
  text-decoration: underline;
  opacity: 0.85;
}

.chat-time-label {
  font-size: 0.625rem;
  color: var(--text-muted);
  margin: 0 4px;
}

/* ── Reaction Bar (popup) ── */
.chat-bubble-wrap {
  display: flex;
  align-items: center;
  gap: 0;
  position: relative;
}
.msg-mine .chat-bubble-wrap { flex-direction: row-reverse; }
.chat-react-trigger {
  width: 26px; height: 26px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin: 0 2px;
}
.chat-msg:hover .chat-react-trigger,
.chat-msg:active .chat-react-trigger { opacity: 1; }
@media (pointer: coarse) { .chat-react-trigger { opacity: 0.5; } }
.chat-react-trigger:hover { background: rgba(var(--primary-rgb), 0.1); color: var(--primary); }

.chat-reaction-bar {
  position: absolute;
  display: flex;
  gap: 2px;
  padding: 5px 8px;
  background: var(--bg-card);
  border-radius: 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
  z-index: 30;
  animation: reactionPop 0.18s ease;
}
[data-theme="dark"] .chat-reaction-bar { background: var(--bg-card-alt); }
@keyframes reactionPop {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1); }
}
.chat-reaction-bar button {
  width: 36px; height: 36px;
  border: none;
  background: transparent;
  font-size: 1.3rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.12s;
}
.chat-reaction-bar button:hover { background: rgba(var(--primary-rgb), 0.1); transform: scale(1.2); }
.chat-reaction-bar button:active { transform: scale(0.9); }
.reaction-more-btn {
  color: var(--text-muted) !important;
  font-size: 0.85rem !important;
  border-left: 1px solid var(--border) !important;
  margin-left: 2px;
  padding-left: 4px;
}
.reaction-more-btn:hover { color: var(--primary) !important; }

/* Expanded emoji grid inside reaction bar */
.reaction-expanded-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px 4px;
  border-top: 1px solid var(--border);
  max-height: 180px;
  overflow-y: auto;
  width: 100%;
  scrollbar-width: thin;
}
.chat-reaction-bar:has(.reaction-expanded-grid) {
  flex-wrap: wrap;
  border-radius: 16px;
  width: 280px;
}
.reaction-expanded-grid button {
  width: 100% !important; aspect-ratio: 1;
  font-size: 1.2rem !important;
  border-radius: 8px !important;
}

/* ── Reaction Badges (below bubble) ── */
.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.chat-reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 12px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}
.chat-reaction-badge:hover { border-color: var(--primary); }
.chat-reaction-badge.mine { border-color: var(--primary); background: rgba(var(--primary-rgb), 0.1); }
.chat-reaction-badge .react-emoji { font-size: 0.95rem; }
.chat-reaction-badge .react-count { font-size: 0.6875rem; color: var(--text-muted); font-weight: 600; }
[data-theme="dark"] .chat-reaction-badge { background: rgba(255,255,255,0.06); }

/* ── Input bar ── */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Emoji Toggle Button */
.emoji-toggle-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}
.emoji-toggle-btn:hover { color: var(--primary); background: rgba(var(--primary-rgb), 0.08); }
.emoji-toggle-btn.active { color: var(--primary); }

/* Emoji Picker Panel */
.emoji-picker {
  position: relative;
  width: 100%;
  background: var(--bg-card);
  border-radius: 0;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
  border-top: 1px solid var(--border);
  z-index: 20;
  overflow: hidden;
  flex-shrink: 0;
  animation: emojiSlideUp 0.2s ease;
}
@keyframes emojiSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.emoji-picker-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 4px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.emoji-picker-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.emoji-tab:hover { background: rgba(var(--primary-rgb), 0.08); }
.emoji-tab.active { background: rgba(var(--primary-rgb), 0.14); }
.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.emoji-picker-grid button {
  width: 100%; aspect-ratio: 1;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.12s;
}
.emoji-picker-grid button:hover { background: rgba(var(--primary-rgb), 0.1); transform: scale(1.15); }
.emoji-picker-grid button:active { transform: scale(0.95); }

/* Dark mode */
[data-theme="dark"] .emoji-picker { background: var(--bg-card); border-top-color: var(--border); box-shadow: 0 -4px 16px rgba(0,0,0,0.3); }

.chat-input {
  flex: 1;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 0.9375rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input:focus { border-color: var(--primary); }

.chat-send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--grad-primary);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 14px rgba(61,106,142,0.4);
}
.chat-send-btn:hover  { transform: scale(1.08); box-shadow: 0 6px 20px rgba(61,106,142,0.5); }
.chat-send-btn:active { transform: scale(0.94); }
.chat-send-btn:disabled { opacity: 0.5; pointer-events: none; }

/* Dark mode tweaks */
[data-theme="dark"] .chat-panel          { background: var(--bg); }
[data-theme="dark"] .chat-view           { background: var(--bg); }
[data-theme="dark"] .conv-list           { background: var(--bg); }
[data-theme="dark"] .conv-item           { border-bottom-color: var(--border); }
[data-theme="dark"] .conv-item:hover     { background: var(--bg-card-alt); }
[data-theme="dark"] .conv-unread         { background: rgba(61,106,142,0.12); }
[data-theme="dark"] .search-contact-body { background: var(--bg); }
[data-theme="dark"] .search-phone-wrap   { background: var(--bg-card-alt); border-color: var(--border); }
[data-theme="dark"] .search-result-card  { background: var(--bg-card); border-color: var(--border); }
[data-theme="dark"] .srm                 { background: var(--bg-card); }
[data-theme="dark"] .chat-input-bar      { background: var(--bg-card); border-top-color: var(--border); }
[data-theme="dark"] .chat-input          { background: rgba(255,255,255,0.07); color: var(--text-primary); }
[data-theme="dark"] .chat-input::placeholder { color: var(--text-muted); }
[data-theme="dark"] .msg-theirs .chat-bubble { background: var(--bg-card-alt); }
[data-theme="dark"] .phone-modal-overlay { background: rgba(0,0,0,0.6); }
[data-theme="dark"] .phone-modal         { background: var(--bg-card); }
[data-theme="dark"] .phone-modal-close   { background: var(--bg-card-alt); }

/* ── Painel de Perfil do Contato (estilo WhatsApp) ── */
.chat-profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 1600;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: flex-end;
  animation: fadeIn 0.2s ease;
}
.chat-profile-panel {
  width: 100%;
  max-width: 420px;
  height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  animation: profileSlideIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}
@keyframes profileSlideIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.chat-profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--primary, #3D6A8E);
  color: #fff;
  flex-shrink: 0;
  min-height: 56px;
}
.chat-profile-header .chat-back-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}
.chat-profile-header .chat-back-btn:hover { background: rgba(255,255,255,0.28); }
.chat-profile-header-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: #fff;
}
.chat-profile-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px 20px;
  background: var(--bg-card);
}
.chat-profile-avatar-wrap {
  width: 160px; height: 160px;
  border-radius: 50%;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  background: var(--bg-card-alt);
}
.chat-profile-avatar {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.chat-profile-avatar-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-size: 4rem;
}
.chat-profile-name {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
  text-align: center;
}
.chat-profile-phone {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}
.chat-profile-actions {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 20px 24px;
  background: var(--bg-card);
  border-bottom: 8px solid var(--bg);
}
.chat-profile-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 500;
  transition: opacity 0.15s;
}
.chat-profile-action-btn:hover { opacity: 0.75; }
.chat-profile-action-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(var(--primary-rgb), 0.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  color: var(--primary);
}
.chat-profile-section {
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 8px solid var(--bg);
}
.chat-profile-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.chat-profile-bio {
  font-size: 0.9375rem;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.5;
}
.chat-profile-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  background: none;
  border: none;
  padding: 14px 0;
  font-size: 0.9375rem;
  color: var(--text-primary);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.chat-profile-option:last-child { border-bottom: none; }
.chat-profile-option:hover { background: rgba(var(--primary-rgb), 0.04); }
.chat-profile-option i { width: 20px; text-align: center; font-size: 1rem; }
.chat-profile-option--danger { color: #EF233C; }
.chat-profile-option--danger i { color: #EF233C; }

[data-theme="dark"] .chat-profile-panel { background: var(--bg); }
[data-theme="dark"] .chat-profile-body { background: var(--bg-card); }
[data-theme="dark"] .chat-profile-actions { background: var(--bg-card); border-bottom-color: var(--bg); }
[data-theme="dark"] .chat-profile-section { background: var(--bg-card); border-bottom-color: var(--bg); }
[data-theme="dark"] .chat-profile-overlay { background: rgba(0,0,0,0.6); }

/* ================================================================
   CHAT — VIEWS (lista / busca / mensagens)
   ================================================================ */

/* Cada view ocupa o espaço total do painel e fica oculta por padrão */
.chat-view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
.chat-view.active { display: flex; }

/* ── Lista de conversas ── */
.conv-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.conv-item {
  display: flex;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  position: relative;
}
.conv-item:hover  { background: var(--bg-card-alt); }
.conv-item:active { background: rgba(var(--primary-rgb,61,106,142), 0.08); }
.conv-unread { background: rgba(var(--primary-rgb,61,106,142), 0.04); }

.conv-avatar-wrap {
  width: 46px; height: 46px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
.conv-avatar-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.conv-avatar-initial {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: var(--grad-primary);
  color: #fff;
  font-size: 1.125rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.conv-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.conv-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.conv-name {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 0.6875rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.conv-preview {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview-unread {
  color: var(--text-primary);
  font-weight: 500;
}
.conv-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

/* ── View de busca por telefone ── */
.search-contact-body {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

/* ── Phone Gate ── */
.phone-gate-body {
  flex: 1;
  padding: 40px 24px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  overflow-y: auto;
}
.phone-gate-icon {
  width: 76px; height: 76px;
  border-radius: 50%;
  background: rgba(var(--primary-rgb,61,106,142), 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--primary);
  margin-bottom: 4px;
}
.phone-gate-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}
.phone-gate-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
  max-width: 320px;
}
.phone-gate-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}
.phone-gate-error {
  font-size: 0.8375rem;
  color: var(--danger, #EF233C);
  background: rgba(239,35,60,0.08);
  border-radius: var(--r-md, 8px);
  padding: 10px 14px;
  text-align: center;
}
.search-phone-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.search-contact-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
  background: rgba(var(--primary-rgb,61,106,142), 0.07);
  padding: 12px 14px;
  border-radius: var(--r-lg, 12px);
}
.search-contact-hint i { color: var(--primary); margin-top: 2px; flex-shrink: 0; }

.search-phone-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  padding: 12px 18px;
  transition: border-color 0.2s;
}
.search-phone-wrap:focus-within { border-color: var(--primary); }
.search-phone-icon { color: var(--text-muted); font-size: 1rem; }
.search-phone-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1.0625rem;
  color: var(--text-primary);
  outline: none;
  letter-spacing: 0.5px;
}
.search-phone-input::placeholder { color: var(--text-muted); }

.search-phone-submit {
  width: 100%;
  padding: 13px;
  border-radius: 50px;
  background: var(--grad-primary);
  color: #fff;
  border: none;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 4px 14px rgba(61,106,142,0.35);
}
.search-phone-submit:hover  { opacity: 0.9; }
.search-phone-submit:active { transform: scale(0.97); }

.search-result-area { display: flex; flex-direction: column; gap: 12px; }

/* Mensagens de estado (loading / erro) */
.srm {
  text-align: center;
  padding: 20px 16px;
  border-radius: var(--r-lg,12px);
  font-size: 0.875rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.srm-warn { color: var(--danger,#EF233C); border-color: var(--danger-bg,rgba(239,35,60,0.15)); background: var(--danger-bg,rgba(239,35,60,0.06)); }

/* Card do contato encontrado */
.search-result-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg,12px);
  box-shadow: var(--shadow-sm);
}
.search-result-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.search-result-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}
.search-result-phone {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.btn-start-chat {
  padding: 9px 16px;
  border-radius: 50px;
  background: var(--grad-primary);
  color: #fff;
  border: none;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-start-chat:hover { opacity: 0.88; }

/* ================================================================
   MODAL — editar telefone
   ================================================================ */
.phone-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: fadeIn 0.2s ease;
}
.phone-modal {
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp 0.28s cubic-bezier(0.32,0.72,0,1);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.phone-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.phone-modal-header h3 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}
.phone-modal-close {
  background: var(--bg-card-alt);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s;
}
.phone-modal-close:hover { background: var(--border); }
.phone-modal-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}
.phone-modal-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card-alt);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  padding: 12px 18px;
  transition: border-color 0.2s;
}
.phone-modal-input-wrap:focus-within { border-color: var(--primary); }
.phone-modal-input-wrap i { color: var(--text-muted); }
.phone-modal-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--text-primary);
  outline: none;
  letter-spacing: 0.5px;
}
.phone-modal-input-wrap input::placeholder { color: var(--text-muted); }
.phone-modal-error {
  font-size: 0.8125rem;
  color: var(--danger,#EF233C);
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--danger-bg,rgba(239,35,60,0.08));
}
.phone-modal-save {
  width: 100%;
  padding: 13px;
  border-radius: 50px;
  background: var(--grad-primary);
  color: #fff;
  border: none;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(61,106,142,0.35);
  transition: opacity 0.2s, transform 0.15s;
}
.phone-modal-save:hover  { opacity: 0.9; }
.phone-modal-save:active { transform: scale(0.97); }

/* ================================================================
   CHAT — OPÇÕES DA CONVERSA (bottom sheet)
   ================================================================ */
.chat-options-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
}
.chat-options-panel {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 8px 0 max(env(safe-area-inset-bottom, 0px), 16px);
  display: flex;
  flex-direction: column;
}
.chat-options-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px auto 14px;
}
.chat-options-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  font-size: 0.97rem;
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background var(--ease);
}
.chat-options-btn:hover { background: var(--bg-card-alt); }
.chat-options-btn i     { width: 22px; text-align: center; color: var(--text-secondary); flex-shrink: 0; }
.chat-options-btn--danger       { color: var(--danger); }
.chat-options-btn--danger i     { color: var(--danger); }
.chat-options-btn--cancel {
  justify-content: center;
  color: var(--text-secondary);
  font-weight: var(--fw-semi);
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 14px;
}

/* ================================================================
   CHAT — BOTÃO ARQUIVADAS no rodapé da lista
   ================================================================ */
.conv-archived-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: var(--fw-medium);
  cursor: pointer;
  width: 100%;
  transition: background var(--ease);
  flex-shrink: 0;
}
.conv-archived-btn:hover { background: var(--bg-card-alt); }
.conv-archived-btn i     { color: var(--text-muted); }
.archived-count {
  margin-left: auto;
  background: var(--bg-card-alt);
  color: var(--text-secondary);
  border-radius: var(--r-full);
  padding: 2px 9px;
  font-size: 0.78rem;
  font-weight: var(--fw-semi);
}

/* ── Barra inferior: avatar do próprio usuário ── */
.chat-list-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: none;
  border: none;
  border-top: 1px solid var(--border);
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: background var(--ease);
  flex-shrink: 0;
}
.chat-list-footer:hover { background: var(--bg-card-alt); }

.clf-avatar-wrap {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-card-alt);
}
.clf-avatar {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.clf-avatar-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(var(--primary-rgb), 0.12);
  color: var(--primary);
  font-size: 1.1rem;
}
.clf-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.clf-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clf-recado {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.clf-arrow {
  color: var(--text-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* ── Meu perfil: overlay de câmera no avatar ── */
.my-profile-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #fff;
  font-size: 0.6875rem;
  opacity: 0;
  transition: opacity 0.2s;
}
.chat-profile-avatar-wrap:hover .my-profile-avatar-overlay { opacity: 1; }
.my-profile-avatar-overlay i { font-size: 1.4rem; }

/* ── Meu perfil: linha editável ── */
.my-profile-editable-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.my-profile-editable-row .chat-profile-bio { flex: 1; }
.my-profile-edit-btn {
  background: rgba(var(--primary-rgb), 0.10);
  border: none;
  color: var(--primary);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}
.my-profile-edit-btn:hover { background: rgba(var(--primary-rgb), 0.22); }

/* ── Botão restaurar conversa arquivada ── */
.conv-unarchive-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  transition: background var(--ease), color var(--ease);
  flex-shrink: 0;
}
.conv-unarchive-btn:hover { background: var(--bg-card-alt); color: var(--primary); }

/* ================================================================
   CHAT — EDITAR MENSAGEM (modal)
   ================================================================ */
.chat-edit-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.chat-edit-modal {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card);
  border-radius: var(--r-xl);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-xl);
}
.chat-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-edit-header h4 {
  font-size: 1rem;
  font-weight: var(--fw-semi);
  color: var(--text-primary);
  margin: 0;
}
.chat-edit-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  background: var(--bg-card-alt);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font);
  resize: vertical;
  min-height: 80px;
  transition: border-color var(--ease);
  box-sizing: border-box;
}
.chat-edit-input:focus { border-color: var(--primary); outline: none; }
.chat-edit-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.chat-edit-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.chat-edit-btn {
  padding: 10px 20px;
  border-radius: var(--r-md);
  font-size: 0.9rem;
  font-weight: var(--fw-medium);
  cursor: pointer;
  border: none;
  transition: opacity var(--ease);
}
.chat-edit-btn--cancel { background: var(--bg-card-alt); color: var(--text-secondary); }
.chat-edit-btn--save   { background: var(--primary); color: #fff; display: flex; align-items: center; gap: 6px; }
.chat-edit-btn:hover   { opacity: 0.85; }

/* ── Label "(editado)" na mensagem ── */
.chat-edited {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ================================================================
   DARK MODE — novas classes de opções / editar / arquivadas
   ================================================================ */
[data-theme="dark"] .chat-options-panel          { background: var(--bg-card); }
[data-theme="dark"] .chat-options-btn:hover      { background: var(--bg-card-alt); }
[data-theme="dark"] .chat-options-btn--cancel    { border-top-color: var(--border); }
[data-theme="dark"] .conv-archived-btn           { border-top-color: var(--border); }
[data-theme="dark"] .conv-unarchive-btn:hover    { background: var(--bg-card-alt); }
[data-theme="dark"] .chat-edit-modal             { background: var(--bg-card); }
[data-theme="dark"] .chat-edit-input             { background: var(--bg-card-alt); border-color: var(--border); color: var(--text-primary); }
[data-theme="dark"] .chat-edit-btn--cancel       { background: var(--bg-card-alt); }

/* ================================================================
   WHATSAPP-STYLE UPGRADES
   ================================================================ */

/* ── Bolha como flex-column para conter footer ── */
.chat-bubble {
  display: flex;
  flex-direction: column;
  position: relative; /* âncora para as pseudo-caudas */
}

/* ── Caudas (triangulos) nas bolhas ── */
/* Mina: canto superior direito */
.msg-mine .chat-bubble::before {
  content: '';
  position: absolute;
  top: 0; right: -7px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 0 0 8px;
  border-color: transparent transparent transparent var(--primary, #3D6A8E);
}
/* Dele/dela: canto superior esquerdo */
.msg-theirs .chat-bubble::before {
  content: '';
  position: absolute;
  top: 0; left: -7px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 8px 0 0;
  border-color: transparent #fff transparent transparent;
}
[data-theme="dark"] .msg-theirs .chat-bubble::before {
  border-right-color: var(--bg-card-alt);
}

/* ── Footer da bolha (hora + ticks) dentro da bolha ── */
.chat-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  margin-left: 14px; /* empurra o footer p/ direita em msgs curtas */
  line-height: 1;
  align-self: flex-end; /* cola no lado direito do flex-column */
  float: none;
}
.chat-bubble-time {
  font-size: 0.6563rem;
  white-space: nowrap;
  line-height: 1;
}
.msg-mine   .chat-bubble-time { color: rgba(255,255,255,0.65); }
.msg-theirs .chat-bubble-time { color: var(--text-muted); }

/* Ticks de status */
.msg-ticks {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  line-height: 1;
}
.msg-ticks i         { color: rgba(255,255,255,0.55); }
.msg-ticks.tick-read i { color: #53bdeb; }

/* ── Label editado ── */
.chat-edited {
  font-size: 0.65rem;
  font-style: italic;
  opacity: 0.7;
}
.msg-mine   .chat-edited { color: rgba(255,255,255,0.65); }
.msg-theirs .chat-edited { color: var(--text-muted); }

/* ── Botões send / mic ── */
.chat-send-btn--active {
  background: var(--grad-primary);
  box-shadow: 0 4px 14px rgba(61,106,142,0.4);
  animation: sendPop 0.18s cubic-bezier(0.34,1.56,0.64,1);
}
.chat-send-btn--mic {
  background: var(--grad-primary);
  box-shadow: 0 4px 14px rgba(61,106,142,0.35);
}
@keyframes sendPop {
  from { transform: scale(0.7) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}
@keyframes micPop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Indicador de digitação ── */
.chat-typing-row {
  padding: 4px 16px 8px;
  flex-shrink: 0;
}
.chat-typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border-radius: 0 18px 18px 18px;
  padding: 10px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  position: relative;
}
.chat-typing-bubble::before {
  content: '';
  position: absolute;
  top: 0; left: -7px;
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 8px 0 0;
  border-color: transparent #fff transparent transparent;
}
[data-theme="dark"] .chat-typing-bubble         { background: var(--bg-card-alt); }
[data-theme="dark"] .chat-typing-bubble::before { border-right-color: var(--bg-card-alt); }
.chat-typing-bubble span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.2s ease-in-out infinite;
}
.chat-typing-bubble span:nth-child(1) { animation-delay: 0s; }
.chat-typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-bubble span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}
.chat-typing-label {
  font-size: 0.75rem;
  color: var(--primary);
  font-style: italic;
  animation: typingFade 1.4s ease infinite;
}
@keyframes typingFade {
  0%, 100% { opacity: 0.6; }
  50%       { opacity: 1;   }
}

/* ── FAB scroll-to-bottom ── */
.chat-scroll-down {
  position: absolute;
  bottom: 76px; right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: none;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  color: var(--text-secondary);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 10;
}
.chat-scroll-down:hover { transform: scale(1.1); box-shadow: 0 4px 18px rgba(0,0,0,0.25); }
.chat-scroll-badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 18px; height: 18px;
  background: #25D366;
  color: #fff;
  border-radius: 99px;
  font-size: 0.6563rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  border: 1.5px solid var(--bg-card);
}

/* ── Barra de resposta acima do input ── */
.chat-reply-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  animation: replyBarIn 0.18s ease;
}
@keyframes replyBarIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-reply-bar-accent {
  width: 3px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}
.chat-reply-bar-content { flex: 1; min-width: 0; }
.chat-reply-bar-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-reply-bar-text {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-reply-cancel-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.chat-reply-cancel-btn:hover { background: var(--bg-card-alt); color: var(--text-primary); }

/* ── Citação de resposta DENTRO da bolha ── */
.chat-reply-quote {
  display: flex;
  gap: 8px;
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 5px;
  cursor: pointer;
  overflow: hidden;
  transition: opacity 0.15s;
}
.chat-reply-quote:hover { opacity: 0.85; }
.msg-mine .chat-reply-quote {
  background: rgba(0,0,0,0.12);
}
.msg-theirs .chat-reply-quote {
  background: rgba(0,0,0,0.05);
}
[data-theme="dark"] .msg-theirs .chat-reply-quote {
  background: rgba(255,255,255,0.07);
}
.chat-reply-quote-bar {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}
.msg-mine   .chat-reply-quote-bar { background: rgba(255,255,255,0.8); }
.msg-theirs .chat-reply-quote-bar { background: var(--primary); }
.chat-reply-quote-body   { flex: 1; min-width: 0; }
.chat-reply-quote-name {
  font-size: 0.72rem;
  font-weight: 700;
  margin: 0 0 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-mine   .chat-reply-quote-name { color: rgba(255,255,255,0.9); }
.msg-theirs .chat-reply-quote-name { color: var(--primary); }
.chat-reply-quote-text {
  font-size: 0.78rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-mine   .chat-reply-quote-text { color: rgba(255,255,255,0.7); }
.msg-theirs .chat-reply-quote-text { color: var(--text-muted); }

/* ── Menu de contexto (long press) ── */
.chat-ctx-menu {
  position: absolute;
  z-index: 50;
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 6px 28px rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  overflow: hidden;
  min-width: 170px;
  animation: ctxPop 0.15s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes ctxPop {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
.chat-ctx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.chat-ctx-item:last-child { border-bottom: none; }
.chat-ctx-item:hover { background: var(--bg-card-alt); }
.chat-ctx-item i { width: 18px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.chat-ctx-item--danger       { color: #EF233C; }
.chat-ctx-item--danger i     { color: #EF233C; }
[data-theme="dark"] .chat-ctx-menu { background: var(--bg-card); border-color: var(--border); }

/* ── Badge verde de não lidas na lista (número) ── */
.conv-unread-badge {
  min-width: 20px; height: 20px;
  border-radius: 10px;
  background: #25D366;
  color: #fff;
  font-size: 0.6563rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  line-height: 1;
}

/* ── Tick do último enviado na lista ── */
.conv-last-tick {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  margin-right: 3px;
  flex-shrink: 0;
}
.conv-last-tick i              { color: var(--text-muted); }
.conv-last-tick.tick-read i   { color: #53bdeb; }

/* ── Avatar inicial no header da conversa ── */
.chat-hdr-initial {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Ajuste: tempo fora da bolha → removido (agora fica dentro) ── */
.chat-time-label { display: none; }

/* ── Destaque de mensagem ao clicar em citação ── */
.chat-msg.msg-highlight .chat-bubble {
  animation: msgHighlight 1.2s ease;
}
@keyframes msgHighlight {
  0%, 100% { filter: brightness(1); }
  30%       { filter: brightness(1.25); }
}

/* ── Linha inferior da lista de conversas (preview + badge) ── */
.conv-bottom-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.conv-bottom-row .conv-preview {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Hora verde quando há não lidas ── */
.conv-time--unread {
  color: #25D366;
  font-weight: 700;
}

/* ── Agrupamento de mensagens consecutivas ── */

/* Ghost: espaço vazio onde iria o avatar (mantém alinhamento) */
.chat-avatar-ghost {
  width: 30px; height: 1px;
  flex-shrink: 0;
  background: transparent;
}

/* Mensagens agrupadas: gap menor e sem cauda */
.chat-msg--grouped {
  margin-top: 2px; /* mensagem consecutiva do mesmo remetente: bem próxima */
}

/* Bolha continuada (não primeira da sequência) — sem canto cortado */
.chat-bubble--cont-mine    { border-top-right-radius: 4px !important; }
.chat-bubble--cont-theirs  { border-top-left-radius:  4px !important; }

/* Oculta a cauda (::before) em mensagens agrupadas que não são a primeira */
.msg-mine   .chat-bubble--cont-mine::before,
.msg-theirs .chat-bubble--cont-theirs::before { display: none; }

/* ── Barra de gravação de áudio ── */
.chat-recording-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-rec-cancel {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(239,35,60,0.12);
  color: #EF233C;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-rec-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1;
}
.chat-rec-wave span {
  display: block;
  width: 3px;
  border-radius: 99px;
  background: #EF233C;
  animation: recWave 0.8s ease-in-out infinite;
}
.chat-rec-wave span:nth-child(1) { height: 8px;  animation-delay: 0.0s; }
.chat-rec-wave span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.chat-rec-wave span:nth-child(3) { height: 20px; animation-delay: 0.2s; }
.chat-rec-wave span:nth-child(4) { height: 14px; animation-delay: 0.3s; }
.chat-rec-wave span:nth-child(5) { height: 8px;  animation-delay: 0.4s; }
@keyframes recWave {
  0%, 100% { transform: scaleY(1);   opacity: 0.6; }
  50%       { transform: scaleY(1.6); opacity: 1;   }
}
.chat-rec-timer {
  font-size: 0.875rem;
  font-weight: 600;
  color: #EF233C;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  min-width: 32px;
}
.chat-mic-recording {
  background: #EF233C !important;
  box-shadow: 0 0 0 4px rgba(239,35,60,0.3) !important;
  animation: micPulse 1s ease-in-out infinite !important;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(239,35,60,0.3); }
  50%       { box-shadow: 0 0 0 8px rgba(239,35,60,0.15); }
}

/* ── Player de áudio nas bolhas ── */
.chat-audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
  max-width: 240px;
  padding: 2px 0;
}
.chat-audio-play-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s;
}
.chat-audio-play-btn:active { transform: scale(0.9); }
.msg-mine   .chat-audio-play-btn { background: rgba(255,255,255,0.25); color: #fff; }
.msg-theirs .chat-audio-play-btn { background: var(--primary); color: #fff; }
.chat-audio-track {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.25);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.msg-theirs .chat-audio-track { background: rgba(0,0,0,0.12); }
.chat-audio-progress-bar {
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 99px;
  transition: width 0.1s linear;
}
.msg-theirs .chat-audio-progress-bar { background: var(--primary); }
.chat-audio-time {
  font-size: 0.6563rem;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 26px;
  text-align: right;
}
.msg-mine   .chat-audio-time { color: rgba(255,255,255,0.7); }
.msg-theirs .chat-audio-time { color: var(--text-muted); }

/* ── Dark mode extras ── */
[data-theme="dark"] .chat-scroll-down  { background: var(--bg-card-alt); }
[data-theme="dark"] .chat-reply-bar    { background: var(--bg-card); border-top-color: var(--border); }
[data-theme="dark"] .chat-recording-bar { background: var(--bg-card); border-top-color: var(--border); }
