/* Chat View */
.chat-container { display: flex; flex: 1; overflow: hidden; }

.chat-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

/* Fundo do chat — logo com overlay 80% (imagem ~20% visível) */
.chat-bg {
  position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.chat-bg-image {
  position: absolute; inset: 0;
  background: url('/icons/logo-source.jpg') center center / cover no-repeat;
  transform: scale(1.05);
}
.chat-bg-overlay {
  position: absolute; inset: 0;
  background: var(--bg);
  opacity: 0.8;
}
.messages-area,
.chat-input-area,
.chat-closed-banner {
  position: relative; z-index: 1;
}

.chat-header {
  height: var(--header-h); background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px; flex-shrink: 0;
}
.chat-header-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.chat-header-status { font-size: 0.78rem; color: var(--text-sec); }
.chat-closed-banner {
  background: rgba(239, 68, 68, 0.1); border-bottom: 1px solid var(--danger);
  padding: 10px 16px; text-align: center; font-size: 0.85rem; color: var(--danger);
  font-weight: 500;
}

/* Messages area */
.messages-area {
  flex: 1; overflow-y: auto; padding: 12px 8px; display: flex !important; flex-direction: column !important; gap: 4px;
}
.messages-load-more {
  text-align: center; padding: 8px;
}

/* Divisor mensagens não lidas (estilo WhatsApp) */
.unread-divider {
  display: flex; align-items: center; justify-content: center;
  margin: 16px 8px; position: relative; z-index: 1;
}
.unread-divider::before,
.unread-divider::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,92,26,0.5), transparent);
}
.unread-divider span {
  padding: 6px 14px; margin: 0 12px;
  background: rgba(255, 92, 26, 0.15);
  border: 1px solid rgba(255, 92, 26, 0.35);
  border-radius: 99px;
  font-size: 0.72rem; font-weight: 600;
  color: var(--primary); text-transform: uppercase;
  letter-spacing: 0.06em; white-space: nowrap;
}

/* Citação / resposta */
.msg-reply {
  border-left: 3px solid var(--primary);
  background: rgba(0,0,0,0.2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 6px 10px; margin-bottom: 6px;
  cursor: pointer; transition: background 0.15s;
}
.msg.own .msg-reply {
  border-left-color: var(--gold);
  background: rgba(255,255,255,0.06);
}
.msg-reply:hover { background: rgba(255,92,26,0.12); }
.msg-reply-nick {
  display: block; font-size: 0.75rem; font-weight: 700;
  color: var(--primary); margin-bottom: 2px;
}
.msg.own .msg-reply-nick { color: var(--gold); }
.msg-reply-text {
  display: block; font-size: 0.8rem; color: var(--text-sec);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px;
}

.msg-highlight .msg-bubble {
  animation: msgHighlight 1.5s ease;
}
@keyframes msgHighlight {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: 0 0 0 3px var(--primary-glow); }
}

/* Preview de resposta (input) */
.reply-preview {
  display: flex; align-items: stretch; gap: 10px;
  width: 100%; margin-bottom: 10px;
  background: var(--bg2); border-radius: var(--radius-sm);
  padding: 8px 10px; border: 1px solid var(--border);
}
.reply-preview.hidden { display: none; }
.reply-preview-bar {
  width: 3px; border-radius: 99px;
  background: linear-gradient(180deg, var(--primary), var(--gold));
  flex-shrink: 0;
}
.reply-preview-content {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
}
.reply-preview-nick {
  font-size: 0.78rem; font-weight: 700; color: var(--primary);
}
.reply-preview-text {
  font-size: 0.82rem; color: var(--text-sec);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reply-preview-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 0 4px;
  align-self: center; flex-shrink: 0;
}
.reply-preview-close:hover { color: var(--danger); }

.action-btn.reply-btn svg { color: var(--info); }

/* Message Base */
.msg {
  display: flex; gap: 6px; padding: 2px 4px; animation: msgIn 0.2s ease;
  width: 100%; margin-bottom: 6px;
}
.msg.own { flex-direction: row-reverse; }

@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.msg-avatar-col { flex-shrink: 0; align-self: flex-end; }
.msg-avatar-col .avatar { width: 30px; height: 30px; font-size: 0.8rem; }

.msg-bubble {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px 12px 12px 0; padding: 6px 10px;
  max-width: 85%; position: relative; box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  display: flex; flex-direction: column;
}
.msg.own .msg-bubble {
  background: var(--primary-glow);
  border-color: rgba(255, 92, 26, 0.2);
  border-radius: 12px 12px 0 12px;
}

.msg-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px; overflow: hidden;
}
.msg-nick { 
  font-weight: 600; font-size: 0.82rem; color: var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
}

.msg-body { display: flex; flex-direction: column; gap: 4px; }
.msg-text { font-size: 0.95rem; line-height: 1.4; color: rgba(255,255,255,0.9); word-break: break-word; white-space: pre-wrap; }
.msg-text .mention { color: var(--info); font-weight: 600; cursor: pointer; background: rgba(59, 130, 246, 0.15); padding: 0 4px; border-radius: 4px; }

.msg-footer {
  display: flex; justify-content: flex-end; align-items: center; gap: 6px;
  margin-top: -2px; margin-bottom: -2px;
}
.msg-time { font-family: var(--font-body); font-size: 0.65rem; color: rgba(255,255,255,0.4); white-space: nowrap; flex-shrink: 0; }

.msg-delete-btn {
  background: none; border: none; cursor: pointer; color: var(--text-dim); 
  font-size: 0.75rem; padding: 0; opacity: 0; transition: opacity var(--transition);
}
.msg-bubble:hover .msg-delete-btn { opacity: 1; }
.msg-delete-btn:hover { color: var(--danger); }

/* Media messages */
.msg-img { border-radius: var(--radius-sm); max-width: 280px; max-height: 260px; object-fit: cover; cursor: pointer; margin-top: 4px; }
.msg-video { border-radius: var(--radius-sm); max-width: 280px; max-height: 200px; margin-top: 4px; }
.msg-expired { color: var(--text-dim); font-style: italic; font-size: 0.82rem; }

/* Custom audio player (WhatsApp-style) */
.msg-audio-player {
  display: flex; align-items: center; gap: 10px;
  min-width: 220px; max-width: 280px; padding: 2px 0;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.msg-audio-el { display: none; }
.msg-audio-play {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex-shrink: 0;
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.95);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}
.msg-audio-play:active { transform: scale(0.94); }
.msg-audio-play svg { width: 20px; height: 20px; display: block; }
.msg-audio-play .icon-play { margin-left: 2px; }
.msg-audio-play.playing { background: var(--primary); color: #fff; }
.msg.own .msg-audio-play { background: var(--primary); color: #fff; }
.msg.own .msg-audio-play:not(.playing) { background: rgba(255,92,26,0.85); }
.msg-audio-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-top: 2px; }
.msg-audio-wave-wrap {
  position: relative; height: 30px; cursor: pointer;
  display: flex; align-items: center; touch-action: none;
}
.msg-audio-wave {
  display: flex; align-items: center; gap: 2px; height: 30px; width: 100%;
}
.msg-audio-wave--bg { opacity: 0.35; color: rgba(255,255,255,0.85); }
.msg-audio-wave--fg {
  position: absolute; left: 0; top: 0; width: 100%; height: 30px;
  color: rgba(255,255,255,0.95); pointer-events: none;
  clip-path: polygon(0 0, var(--progress, 0%) 0, var(--progress, 0%) 100%, 0 100%);
}
.msg.own .msg-audio-wave--fg { color: #fff; }
.msg-audio-bar {
  flex: 1; min-width: 2px; max-width: 3px; border-radius: 99px;
  background: currentColor; align-self: center;
}
.msg-audio-scrubber {
  position: absolute; top: 50%; width: 11px; height: 11px; border-radius: 50%;
  background: #fff; transform: translate(-50%, -50%); left: var(--progress, 0%);
  pointer-events: none; box-shadow: 0 1px 4px rgba(0,0,0,0.35);
  transition: left 0.05s linear;
}
.msg.own .msg-audio-scrubber { background: #fff; }
.msg-audio-time {
  font-size: 0.68rem; color: rgba(255,255,255,0.55);
  font-variant-numeric: tabular-nums; line-height: 1;
}
:root[data-theme="light"] .msg-audio-play:not(.playing) {
  background: rgba(0,0,0,0.08); color: var(--text);
}
:root[data-theme="light"] .msg.own .msg-audio-play:not(.playing) {
  background: var(--primary); color: #fff;
}
:root[data-theme="light"] .msg-audio-wave--bg { color: var(--text-sec); }
:root[data-theme="light"] .msg-audio-wave--fg { color: var(--primary); }
:root[data-theme="light"] .msg.own .msg-audio-wave--fg { color: var(--primary-hover); }
:root[data-theme="light"] .msg-audio-scrubber { background: var(--primary); }
:root[data-theme="light"] .msg.own .msg-audio-scrubber { background: #fff; }
:root[data-theme="light"] .msg-audio-time { color: var(--text-dim); }

/* System message */
.msg-system {
  text-align: center; font-size: 0.78rem; color: var(--text-dim);
  padding: 4px 0; font-style: italic;
}

/* Input area */
.chat-input-area {
  background: var(--card); border-top: 1px solid var(--border);
  padding: 12px 16px; display: flex; align-items: flex-end; gap: 10px;
  flex-shrink: 0; flex-wrap: wrap;
}
.chat-input-wrap { flex: 1; min-width: 120px; position: relative; }
.chat-input {
  width: 100%; background: var(--bg2); border: 1px solid var(--border);
  color: var(--text); padding: 11px 44px 11px 14px;
  border-radius: 22px; font-size: 0.95rem; resize: none; max-height: 120px;
  line-height: 1.4; transition: all var(--transition);
  font-family: var(--font-body);
}
.chat-input:focus { outline: none; border-color: var(--primary); }
.chat-emoji-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--text-sec);
  transition: transform var(--transition);
}
.chat-emoji-btn:hover { transform: translateY(-50%) scale(1.2); }
.chat-actions { display: flex; gap: 8px; align-items: center; }
.chat-send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--primary);
  border: none; color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); flex-shrink: 0;
}
.chat-send-btn:hover { background: var(--primary-hover); transform: scale(1.05); box-shadow: 0 0 16px var(--primary-glow); }
.chat-media-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--bg3);
  border: 1px solid var(--border); color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all var(--transition);
}
.chat-media-btn:hover { border-color: var(--primary); color: var(--primary); }
.chat-mic-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--bg3);
  border: 1px solid var(--border); color: var(--text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all var(--transition);
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.chat-mic-btn.recording {
  background: var(--danger); border-color: var(--danger); color: #fff;
  animation: recordPulse 1s ease-in-out infinite;
}
@keyframes recordPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); } 50% { box-shadow: 0 0 0 12px rgba(239,68,68,0); } }

/* Recording Mode Adjustments */
.chat-input-area.recording-active .chat-input-wrap,
.chat-input-area.recording-active .chat-media-btn,
.chat-input-area.recording-active .chat-mic-btn {
  display: none !important;
}

.chat-input-area.recording-active .recording-indicator {
  flex: 1;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid var(--danger);
  border-radius: 22px;
  padding: 8px 16px;
}

/* Recording indicator */
.recording-indicator {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: rgba(239,68,68,0.1); border: 1px solid var(--danger);
  border-radius: 22px; color: var(--danger); font-size: 0.85rem; font-weight: 500;
}
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s ease infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.2; } }

/* Mention suggestion */
.mention-box {
  position: absolute; bottom: 100%; left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; z-index: 50; max-height: 180px; overflow-y: auto;
}
.mention-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  cursor: pointer; transition: background var(--transition); font-size: 0.88rem;
}
.mention-item:hover, .mention-item.selected { background: var(--primary-glow); }
.mention-item.selected { border-left: 3px solid var(--primary); }
.mention-box:empty { display: none; }

/* Members sidebar */
.members-panel {
  width: 220px; background: var(--card); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 16px;
}
.members-panel-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-dim); font-weight: 600; margin-bottom: 12px; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.85rem; }
.member-item-nick { font-weight: 500; }
.member-item-role { font-size: 0.7rem; color: var(--gold); font-family: var(--font-mono); }

/* Image lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.9);
  z-index: 9000; display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: var(--radius); }

/* User card modal — FF ID copiável */
.user-card-ff-id {
  font-weight: 600; font-family: var(--font-mono);
  cursor: pointer; border-radius: 4px; padding: 2px 4px; margin: 0 -4px;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.user-card-ff-id:hover, .user-card-ff-id:focus-visible {
  color: var(--primary); background: var(--primary-glow); outline: none;
}
.user-card-ff-id:active { opacity: 0.75; }

@media (max-width: 768px) {
  .members-panel { display: none; }
  .msg-bubble { max-width: 85%; }
}

/* Action Sheet (Edit/Delete options) */
.action-sheet {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.action-sheet.desktop {
  border-radius: var(--radius-sm);
  min-width: 180px;
}

.action-sheet.mobile {
  bottom: 0; left: 0; right: 0;
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.1, 0.9, 0.2, 1);
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.action-sheet.mobile.open {
  transform: translateY(0);
}

.action-btn {
  background: none;
  border: none;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
}

.action-sheet.desktop .action-btn {
  padding: 10px 16px;
  font-size: 0.88rem;
}

.action-btn:hover {
  background: var(--bg2);
}

.action-btn svg {
  width: 20px;
  height: 20px;
}

.action-btn.delete-btn {
  color: var(--danger);
}

.action-btn.edit-btn {
  color: var(--info);
}

/* Editing state */
.chat-send-btn.editing {
  background: var(--info);
}
.chat-send-btn.editing:hover {
  background: #2563eb; /* darker blue */
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.4);
}

.msg-edited {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-style: italic;
  margin-left: 4px;
}

.msg-link {
  color: var(--info);
  text-decoration: underline;
  word-break: break-all;
}
.msg-link:hover { opacity: 0.8; }
