/* =====================================================================
   Direct Messages: Chat Inbox & Directory Search
   ===================================================================== */

/* =====================================================================
   Scroll Containers & Layout Rigor
   ===================================================================== */

dm-chat-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
}

dm-chat-list {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  width: 100%;
  padding: 12px;
  flex: 0 0 auto;
  margin-top: auto;
}

#dm-chats-component.dm-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}

panel-header {
  flex: 0 0 52px;
}

direct-message-section {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: auto;
}

.scroll-sentinel {
  height: 1px;
  width: 100%;
  clear: both;
  pointer-events: none;
  visibility: hidden;
}

/* Toggle States */
direct-message-section.chats direct-message-directory { display: none; }
direct-message-section.chats direct-message-chats { display: block; height: 100%; }

direct-message-section.search direct-message-directory { display: block; height: 100%; }
direct-message-section.search direct-message-chats { display: none; }

direct-message-section.accountMode { display: none; }

/* =====================================================================
   Search Bar
   ===================================================================== */

direct-message-search-section {
  padding: 12px 16px;
  background: transparent;
  border-bottom: 1px solid var(--border-subtle, #edebe6);
}

direct-message-search form {
  display: flex;
  gap: 8px;
  align-items: center;
}

direct-message-search span {
  flex: 1;
  position: relative;
  border: 1px solid var(--border-subtle, #edebe6);
  border-radius: 12px;                          /* Modern search pill */
  background: #f7f6f2;
  padding: 6px 14px;
  transition: all 0.15s ease;
}

direct-message-search span.active,
direct-message-search span:focus-within {
  background: #ffffff;
  border-color: var(--accent, #4f46e5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

#searchValue {
  width: 100%;
  border: none;
  outline: none;
  font: inherit;
  font-size: 0.95rem;
  background: transparent;
  color: var(--text-main, #16181b);
}

div#tagsControls.inactive {
  display: none;
}

/* =====================================================================
   Chat List & Conversation Rows
   ===================================================================== */

direct-message-chats {
  flex: 1;
}

/* Chat Item Row */
dm-chat-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 12px;                          /* Card-like touch item */
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

dm-chat-item:hover {
  background-color: var(--surface-hover, #f7f6f2);
}

dm-chat-item.menu-active {
  background-color: rgba(79, 70, 229, 0.08);    /* Refined indigo active state */
}

/* Unread Notification Indicator Dot */
dm-chat-item.isUnread::after {
  content: '';
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  background-color: var(--accent, #4f46e5);
  border-radius: 50%;
  box-shadow: 0 0 0 2px #ffffff;
}

dm-chat-content.unread-summary {
  display: none;
  color: var(--accent, #4f46e5);
  font-weight: 600;
}

dm-chat-item.isUnread .preview-text {
  display: none;
}

dm-chat-item.isUnread .unread-summary {
  display: block;
}

dm-chat-item.isUnread dm-chat-title,
dm-chat-item.isUnread dm-chat-content {
  font-weight: 700;
  color: var(--text-main, #16181b);
}

/* =====================================================================
   Avatars & Online Presence Indicators
   ===================================================================== */

dm-chat-avatar {
  display: inline-block;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  margin-right: 14px;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle, #edebe6);
  position: relative;
  background-color: #ffffff;
}

panel-header dm-chat-avatar {
  display: inline-block;
  width: 36px;
  height: 36px;
}

panel-header dm-chat-avatar.is-group { display: none; }

/* One-to-one chat: avatar and name open the other person's profile
   (data-action="openProfile", DmMessagesModule.js). */
dm-messages-module.has-profile panel-header dm-chat-avatar,
dm-messages-module.has-profile panel-header panel-label {
  cursor: pointer;
}

/* The Online Indicator Dot */
dm-chat-avatar.is-online::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background-color: #10b981;                    /* Fresh emerald */
  border-radius: 50%;
  border: 2.5px solid #ffffff;
  box-sizing: content-box;
  animation: presencePulse 2.2s infinite;
}

panel-header dm-chat-avatar.is-online::after {
  width: 9px;
  height: 9px;
}

@keyframes presencePulse {
  0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45); }
  70%  { box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Group Avatar Stacking */
dm-chat-avatar.is-group {
  background-size: 0;
  border: none;
  background-color: transparent;
}

dm-chat-avatar.is-group::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-color: #edebe6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23656f77'%3E%3Ccircle cx='9' cy='8' r='3.5'/%3E%3Cpath d='M2 19.5c0-3.3 3.1-5.5 7-5.5s7 2.2 7 5.5V20H2z'/%3E%3Ccircle cx='16.5' cy='7.5' r='2.75' opacity='.7'/%3E%3Cpath opacity='.7' d='M15.6 12.6c3.3.1 6.4 1.9 6.4 4.9V20h-4.6v-.5c0-2.7-.7-5-1.8-6.9z'/%3E%3C/svg%3E");
  background-size: 18px;
  background-position: center;
  background-repeat: no-repeat;
  border: 1px solid var(--border-subtle, #edebe6);
  box-sizing: border-box;
}

dm-chat-avatar.is-group::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background-image: inherit;
  background-size: cover;
  background-position: center;
  border: 2px solid #ffffff;
  box-sizing: border-box;
  box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.06);
}

/* Details & Typography */
dm-chat-details {
  flex: 1;
  overflow: hidden;
}

dm-chat-title {
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-main, #16181b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

dm-chat-content {
  font-size: 0.88rem;
  color: var(--text-muted, #656f77);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  margin-top: 3px;
}

chat-indicator {
  display: inline-block;
  margin-right: 14px;
  font-size: 0.8rem;
}

/* =====================================================================
   Directory & Member Search Results
   ===================================================================== */

direct-message-directory {
  overflow-y: auto;
  padding: 16px;
}

#toggleChats {
  padding: 0;
  margin-right: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  border: 0;
  background: transparent;
  color: var(--accent, #4f46e5);
  font-weight: 600;
  visibility: hidden;
}

#toggleChats::before {
  content: "\276E";
  margin-right: 5px;
}

direct-message-section.search #toggleChats {
  visibility: visible;
}

/* Search Result Member Row */
dm-member {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  cursor: pointer;
  padding-right: 2rem;
  position: relative;
  transition: background-color 0.12s ease;
}

dm-member:hover {
  background-color: var(--surface-hover, #f7f6f2);
}

dm-member-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-image: url("/images/message_tag_icon.png");
  margin-right: 12px;
  border: 1px solid var(--border-subtle, #edebe6);
}

dm-member-nickname {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main, #16181b);
}

/* Nickname with the location under it (DmMember.js) */
dm-member-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

dm-member-location {
  margin-top: 2px;
  font-size: 0.8rem;
  color: var(--text-muted, #656f77);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Member selection indicators */
dm-member::after {
  content: '';
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%) scale(0);
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  opacity: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

dm-search-list.group-mode dm-member::after {
  content: '+';
  font-size: 1.2rem;
  font-weight: 400;
  color: var(--text-muted, #656f77);
  transform: translateY(-50%) scale(1);
  opacity: 1;
}

dm-search-list.group-mode dm-member.selected::after {
  content: '';
  background-color: var(--accent, #4f46e5);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-size: 70%;
  background-repeat: no-repeat;
  background-position: center;
  transform: translateY(-50%) scale(1);
  opacity: 1;
}

dm-search-list.group-mode dm-member.selected {
  background-color: rgba(79, 70, 229, 0.08);
}

/* Group Mode Pill Switcher */
.search-mode-toggle {
  display: flex;
  align-items: flex-end;
  background: var(--border-subtle, #edebe6);
  border-radius: 2rem;
  padding: 3px;
  gap: 4px;
  width: fit-content;
  margin-left: auto;
  margin-bottom: 10px;
}

.search-mode-toggle button {
  border: none;
  background: transparent;
  border-radius: 2rem;
  padding: 0.35rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted, #656f77);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.search-mode-toggle button.active {
  background: #ffffff;
  color: var(--text-main, #16181b);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Group Selection Dock */
.group-selection-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle, #edebe6);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 8px;
}

.group-selection-bar.active {
  opacity: 1;
  pointer-events: all;
}

.group-selection-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.group-selection-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(79, 70, 229, 0.08);
  border: 1px solid rgba(79, 70, 229, 0.2);
  color: var(--accent, #4f46e5);
  border-radius: 8px;
  padding: 0.2rem 0.5rem 0.2rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.group-selection-chip button {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
  color: inherit;
  line-height: 1;
}

.group-create-btn {
  border: none;
  background: var(--accent, #4f46e5);
  color: #ffffff;
  border-radius: 10px;
  padding: 0.45rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  transition: filter 0.15s ease;
}

.group-create-btn:hover {
  filter: brightness(1.06);
}

/* =====================================================================
   Row Menu (⋯) & Action Bottom Sheet
   ===================================================================== */

dm-chat-item {
  position: relative;
}

.thread-menu,
.chat-row-menu {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-muted, #656f77);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease;
}

dm-chat-item:hover .chat-row-menu {
  opacity: 1;
}

.chat-row-menu:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-main, #16181b);
}

.thread-menu {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(0, 0, 0, 0.85);
  opacity: 1;
}

.thread-menu:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* Action Sheet Modal */
dm-chat-actions {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

dm-chat-actions.active {
  pointer-events: all;
  opacity: 1;
}

dm-chat-actions .overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 16, 0.4);
  backdrop-filter: blur(4px);
}

dm-chat-actions .panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-radius: 20px 20px 0 0;
  padding: 0.5rem 0 2rem;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

dm-chat-actions.active .panel {
  transform: translateY(0);
}

/* Grab handle */
dm-chat-actions .panel::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--border-subtle, #edebe6);
  border-radius: 2px;
  margin: 0.75rem auto 1rem;
}

dm-chat-actions .controls {
  list-style: none;
  margin: 0;
  padding: 0;
}

dm-chat-actions .controls li {
  padding: 0.85rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-main, #16181b);
  cursor: pointer;
  transition: background-color 0.12s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

dm-chat-actions .controls li:hover {
  background: rgba(22, 24, 27, 0.04);
}

dm-chat-actions .controls li.danger {
  color: #ef4444;
  border-top: 1px solid var(--border-subtle, #edebe6);
  margin-top: 0.5rem;
  padding-top: 1rem;
}

dm-chat-actions .controls li.hidden {
  display: none;
}

dm-chat-actions .panel-title {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted, #656f77);
  padding: 0 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle, #edebe6);
  margin-bottom: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =====================================================================
   Mobile Tweaks
   ===================================================================== */

@media (max-width: 480px) {
  direct-message-section {
    width: 100%;
    margin: 0;
  }
  
  dm-chat-item {
    padding: 12px 14px;
  }
}