/* ============================================================
   DM.CSS — Direct Messages (Mini-Chat Popup & Full Page)
   ============================================================ */

/* ---- HEADER NAV BUTTON & BADGE ---- */
.dm-nav {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.dm-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-primary, #e63946);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(230, 57, 70, 0.45);
  pointer-events: none;
}

/* ---- FLOATING MINI-CHAT POPUP ---- */
.dm-mini-window {
  position: fixed;
  bottom: 24px;
  right: 96px;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 490px;
  max-height: calc(100vh - 100px);
  background: var(--bg-card, #12151f);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 2500;
  backdrop-filter: blur(18px);
}

.dm-mini-window.is-open {
  display: flex;
  animation: dmPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes dmPopIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dm-mini-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-secondary, rgba(255, 255, 255, 0.03));
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}

.dm-mini-header__left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.dm-mini-header__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary, #f3f4f6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-mini-header__sub {
  font-size: 11px;
  color: var(--text-muted, #9ca3af);
}

.dm-mini-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.dm-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #9ca3af);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.dm-icon-btn:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.08));
  color: var(--text-primary, #fff);
}

.dm-mini-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dm-mini-conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.dm-mini-conv-item:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.05));
}

.dm-mini-conv-item.is-active {
  background: var(--accent-subtle, rgba(230, 57, 70, 0.12));
  border-color: rgba(230, 57, 70, 0.25);
}

.dm-conv-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.dm-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--bg-card, #12151f);
}

.dm-conv-meta {
  flex: 1;
  min-width: 0;
}

.dm-conv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.dm-conv-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary, #f3f4f6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-conv-time {
  font-size: 10.5px;
  color: var(--text-muted, #6b7280);
  flex-shrink: 0;
}

.dm-conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 2px;
}

.dm-conv-preview {
  font-size: 12px;
  color: var(--text-muted, #9ca3af);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-conv-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-primary, #e63946);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- MESSAGES BUBBLES ---- */
.dm-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
}

.dm-msg-row.is-me {
  align-self: flex-end;
  align-items: flex-end;
}

.dm-msg-row.is-peer {
  align-self: flex-start;
  align-items: flex-start;
}

.dm-msg-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--bg-secondary, rgba(255, 255, 255, 0.07));
  color: var(--text-primary, #f3f4f6);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.06));
}

.dm-msg-row.is-me .dm-msg-bubble {
  background: var(--accent-primary, #e63946);
  color: #ffffff;
  border-color: transparent;
  border-bottom-right-radius: 4px;
}

.dm-msg-row.is-peer .dm-msg-bubble {
  border-bottom-left-radius: 4px;
}

.dm-msg-time {
  font-size: 10px;
  color: var(--text-muted, #6b7280);
  display: flex;
  align-items: center;
  gap: 4px;
}

.dm-title-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.dm-msg-row.is-peer .dm-title-link {
  background: var(--accent-subtle, rgba(230, 57, 70, 0.14));
  color: var(--accent-primary, #ff6b7a);
}

.dm-mini-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary, rgba(255, 255, 255, 0.02));
}

.dm-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-primary, rgba(0, 0, 0, 0.25));
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-primary, #fff);
  outline: none;
}

.dm-input:focus {
  border-color: var(--accent-primary, #e63946);
}

.dm-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent-primary, #e63946);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, opacity 0.15s;
}

.dm-send-btn:hover { transform: scale(1.04); }
.dm-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.dm-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted, #9ca3af);
  font-size: 13px;
  gap: 8px;
}

.dm-blocked-banner {
  padding: 10px 12px;
  font-size: 12px;
  text-align: center;
  color: #f87171;
  background: rgba(248, 113, 113, 0.08);
  border-top: 1px solid rgba(248, 113, 113, 0.2);
}

/* ---- FULL PAGE /messages ---- */
.dm-page-wrap {
  max-width: 1120px;
  margin: 24px auto 48px;
  padding: 0 16px;
}

.dm-page-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 150px);
  min-height: 520px;
  max-height: 780px;
  background: var(--bg-card, #12151f);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.09));
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

.dm-sidebar {
  border-right: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-secondary, rgba(255, 255, 255, 0.015));
}

.dm-sidebar__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dm-sidebar__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dm-sidebar__title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text-primary, #fff);
}

.dm-privacy-select {
  background: var(--bg-primary, #0b0d14);
  color: var(--text-secondary, #d1d5db);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11.5px;
  outline: none;
  cursor: pointer;
}

.dm-sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dm-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dm-thread__head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dm-thread__peer {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.dm-thread__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dm-thread__back-btn {
  display: none;
}

@media (max-width: 768px) {
  .dm-mini-window {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 76px;
    height: 68vh;
  }

  .dm-page-shell {
    grid-template-columns: 1fr;
    height: calc(100vh - 140px);
  }

  .dm-page-shell.has-active-thread .dm-sidebar {
    display: none;
  }

  .dm-page-shell:not(.has-active-thread) .dm-thread {
    display: none;
  }

  .dm-thread__back-btn {
    display: inline-flex;
  }
}
