/* ========== MESSAGES ========== */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.date-divider { text-align: center; padding: 8px 0; }

.date-divider span {
  background: var(--bg-paper);
  color: var(--text-disabled);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 20px;
  box-shadow: var(--shadow-z1);
}

.message-wrapper {
  display: flex;
  gap: 12px;
  max-width: 70%;
  animation: msgIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message-wrapper.no-animate {
  animation: none !important;
}

.message-wrapper.sent { align-self: flex-end; flex-direction: row-reverse; }
.message-wrapper.received { align-self: flex-start; position: relative; padding-left: 48px; }

.message-wrapper.received .msg-avatar{
  position: absolute;
  top: 0;
  left: 0;
}

.message-wrapper.search-match .message {
  box-shadow: 0 0 0 1px rgba(0,167,111,0.34), var(--shadow-card);
}

.message-wrapper.sent.search-match .message {
  box-shadow: 0 0 0 1px rgba(255,255,255,0.42), var(--shadow-primary);
}

.message-wrapper.search-active .message {
  box-shadow: 0 0 0 2px var(--warning), var(--shadow-z8);
}

@keyframes msgIn { from { opacity: 0; transform: translateY(16px); } }

.msg-avatar { width: 36px; height: 36px; border-radius: var(--radius); flex-shrink: 0;}
.msg-avatar img { width: 100%; height: 100%; border-radius: var(--radius); object-fit: cover; }

.message {
  padding: 14px 16px;
  border-radius: calc(var(--radius) * 2);
  font-size: 0.875rem;
  line-height: 1.6;
  position: relative;
}

.message-wrapper.sent .message {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-bottom-right-radius: var(--radius);
  box-shadow: var(--shadow-primary);
}

.message-wrapper.received .message {
  background: var(--bg-paper);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.msg-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}

.msg-text { word-break: break-word; }

.msg-text .mention {
  background: rgba(0,167,111,0.16);
  color: var(--primary-dark);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}

.message-wrapper.sent .msg-text .mention {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* Media Messages */
.msg-media {
  border-radius: var(--radius);
  max-width: 260px;
  margin-bottom: 8px;
  cursor: pointer;
  overflow: hidden;
}

.msg-media img, .msg-media video { width: 100%; display: block; border-radius: var(--radius); }

/* Voice Messages */
.msg-voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
}

.voice-play {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  transition: var(--transition);
}

.voice-play:hover { background: rgba(255,255,255,0.3); transform: scale(1.1); }
.message-wrapper.received .voice-play { background: var(--primary); color: white; }

.voice-waves { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; }
.voice-bar { width: 3px; background: currentColor; opacity: 0.6; border-radius: 2px; }
.voice-time { font-size: 0.6875rem; opacity: 0.8; }

/* Reactions */
.msg-reactions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.msg-reaction {
  background: rgba(145, 158, 171, 0.16);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: var(--transition);
}

.msg-reaction:hover { background: rgba(145, 158, 171, 0.24); }
.message-wrapper.sent .msg-reaction { background: rgba(255,255,255,0.2); }

/* Message Footer */
.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.6875rem;
  opacity: 0.7;
}

.message-wrapper.sent .msg-footer { justify-content: flex-end; }
.msg-footer .views { display: flex; align-items: center; gap: 4px; }

/* Message Actions */
.msg-actions {
  position: absolute;
  top: -12px;
  right: 12px;
  display: none;
  background: var(--bg-paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow-dropdown);
  padding: 4px;
  gap: 2px;
}

.message-wrapper.received .msg-actions { right: auto; left: 12px; }
.message:hover .msg-actions { display: flex; }

.msg-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  transition: var(--transition);
}

.msg-action-btn:hover { background: var(--bg-neutral); color: var(--primary); }
.msg-action-btn.active { color: var(--warning); }

/* Pinned Message */
.pinned-msg {
  background: rgba(255,171,0,0.08);
  border-left: 3px solid var(--warning);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 0 24px 8px;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pinned-msg i { color: var(--warning); }

/* Reply Quote */
.msg-reply-quote {
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border-left: 3px solid var(--primary);
  background: rgba(145, 158, 171, 0.08);
  cursor: pointer;
  transition: var(--transition);
}

.msg-reply-quote:hover { background: rgba(145, 158, 171, 0.16); }

.message-wrapper.sent .msg-reply-quote {
  background: rgba(255, 255, 255, 0.12);
  border-left-color: rgba(255, 255, 255, 0.5);
}

.message-wrapper.sent .msg-reply-quote:hover { background: rgba(255, 255, 255, 0.2); }

.msg-reply-quote-name {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}

.message-wrapper.sent .msg-reply-quote-name { color: rgba(255, 255, 255, 0.8); }

.msg-reply-quote-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.message-wrapper.sent .msg-reply-quote-text { color: rgba(255, 255, 255, 0.6); }

.msg-starred-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--warning);
}

.msg-edited {
  font-style: italic;
  opacity: 0.85;
}

.msg-inline-edit {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-inline-edit-input {
  width: 100%;
  resize: vertical;
  min-height: 64px;
  max-height: 160px;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--bg-paper);
  color: var(--text-primary);
  font: inherit;
  line-height: 1.5;
}

.msg-inline-edit-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0,167,111,0.16);
}

.message-wrapper.sent .msg-inline-edit-input {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  color: white;
}

.message-wrapper.sent .msg-inline-edit-input::placeholder {
  color: rgba(255,255,255,0.8);
}

.msg-inline-edit-media {
  max-width: 260px;
  border-radius: var(--radius);
  overflow: hidden;
}

.msg-inline-edit-media img,
.msg-inline-edit-media video {
  width: 100%;
  display: block;
}

.msg-inline-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.msg-inline-edit-spacer { flex: 1; }

.msg-inline-edit-btn {
  border: none;
  background: var(--bg-neutral);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  transition: var(--transition);
}

.msg-inline-edit-btn:hover { background: rgba(145, 158, 171, 0.2); }
.msg-inline-edit-btn.primary { background: var(--primary); color: white; }
.msg-inline-edit-btn.primary:hover { background: var(--primary-dark); }
.msg-inline-edit-btn.danger { background: rgba(255,86,48,0.14); color: var(--error); }
.msg-inline-edit-btn.danger:hover { background: rgba(255,86,48,0.24); }

.message-wrapper.sent .msg-inline-edit-btn {
  background: rgba(255,255,255,0.2);
  color: white;
}

.message-wrapper.sent .msg-inline-edit-btn:hover {
  background: rgba(255,255,255,0.3);
}

.message-wrapper.sent .msg-inline-edit-btn.primary {
  background: white;
  color: var(--primary-dark);
}

.message-wrapper.sent .msg-inline-edit-btn.primary:hover {
  background: rgba(255,255,255,0.88);
}

/* Message Highlight (when scrolling to replied message) */
.message-wrapper.highlight .message {
  box-shadow: 0 0 0 2px var(--primary), var(--shadow-z8);
  transition: box-shadow 0.3s;
}

@keyframes highlightFade {
  from { box-shadow: 0 0 0 2px var(--primary), var(--shadow-z8); }
  to { box-shadow: none; }
}

/* ========== EMOJI PICKER ========== */
.emoji-picker {
  position: fixed;
  width: 320px;
  max-height: 380px;
  background: var(--bg-paper);
  border-radius: calc(var(--radius) * 2);
  box-shadow: var(--shadow-dropdown);
  z-index: 1500;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.emoji-picker.active { display: flex; }

.emoji-picker-header {
  padding: 10px 12px 8px;
  border-bottom: 1px dashed var(--divider);
}

.emoji-picker-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
}

.emoji-tab {
  flex: 1;
  padding: 6px;
  border: none;
  background: none;
  font-size: 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
  opacity: 0.5;
}

.emoji-tab:hover { background: var(--bg-neutral); opacity: 0.8; }
.emoji-tab.active { background: var(--bg-neutral); opacity: 1; }

.emoji-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  background: var(--bg-neutral);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-family: inherit;
}

.emoji-search:focus { outline: none; border-color: var(--primary); }
.emoji-search::placeholder { color: var(--text-disabled); }

.emoji-picker-body {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.emoji-category-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-disabled);
  padding: 6px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-item {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
}

.emoji-item:hover { background: var(--bg-neutral); transform: scale(1.2); }

/* Reaction Quick Picker (compact bar) */
.reaction-picker {
  position: fixed;
  background: var(--bg-paper);
  border-radius: 24px;
  box-shadow: var(--shadow-dropdown);
  padding: 6px 8px;
  display: none;
  align-items: center;
  gap: 2px;
  z-index: 1500;
}

.reaction-picker.active { display: flex; }

.reaction-option {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  transition: var(--transition);
}

.reaction-option:hover { background: var(--bg-neutral); transform: scale(1.3); }

.reaction-more {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  border: none;
  background: var(--bg-neutral);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 50%;
  transition: var(--transition);
}

.reaction-more:hover { background: var(--grey-300); color: var(--text-primary); }

/* ========== VIRTUAL ROOM ========== */
.virtual-readonly-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 24px;
  background: rgba(156, 39, 176, 0.06);
  border-top: 1px solid rgba(156, 39, 176, 0.15);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.virtual-readonly-banner i {
  font-size: 0.875rem;
  opacity: 0.7;
}

.msg-room-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  margin-bottom: 6px;
  border-radius: 12px;
  background: rgba(156, 39, 176, 0.08);
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  width: fit-content;
}

.msg-room-source:hover {
  background: rgba(156, 39, 176, 0.16);
  color: var(--primary);
}

.msg-room-source i {
  font-size: 0.6rem;
}

.message-wrapper.sent .msg-room-source {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

.message-wrapper.sent .msg-room-source:hover {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}
