/* ===========================================================
   NDN Messenger (Hòm thư) — modern UI
   Scoped, high-specificity styles that override the base modal.
   =========================================================== */

.ndn-msg-modal {
  --msg-accent: #6366f1;
  --msg-accent-2: #8b5cf6;
  --msg-accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --msg-ink: #0f172a;
  --msg-muted: #64748b;
  --msg-line: #eceef3;
  --msg-line-2: #f1f3f7;
  --msg-bg: #ffffff;
  --msg-bg-soft: #f7f8fc;
  --msg-them: #f0f2f7;
  --msg-unread: #eef2ff;
  --msg-danger: #ef4444;
}

/* --- Inbox trigger button (next to the notification bell) --- */
.ndn-inbox-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none;
  width: 40px; height: 40px;
  font-size: 20px; line-height: 1; cursor: pointer;
  border-radius: 50%;
  transition: background .18s ease, transform .12s ease;
}
.ndn-inbox-btn:hover { background: rgba(99,102,241,.12); }
.ndn-inbox-btn:active { transform: scale(.92); }
.ndn-inbox-badge {
  position: absolute; top: 0; right: 0;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--msg-danger); color: #fff;
  font-size: 10px; font-weight: 800; line-height: 18px;
  text-align: center; border-radius: 10px;
  box-shadow: 0 0 0 2px #fff;
}

/* --- Modal shell (override base .ndn-modal-box constraints) --- */
.ndn-modal.ndn-msg-modal { padding: 16px; }
.ndn-modal.ndn-msg-modal .ndn-modal-box.ndn-msg-box {
  width: 960px;
  max-width: 96vw;
  height: 84vh;
  max-height: 760px;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  background: var(--msg-bg);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
  animation: ndnMsgPop .22s cubic-bezier(.22, 1, .36, 1);
}
@keyframes ndnMsgPop {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ndn-msg-modal .ndn-modal-close-btn {
  z-index: 6; top: 14px; right: 16px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(4px);
}

.ndn-msg-layout { display: flex; flex: 1; min-height: 0; }

/* --- Sidebar --- */
.ndn-msg-sidebar {
  width: 340px; flex-shrink: 0;
  border-right: 1px solid var(--msg-line);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--msg-bg-soft);
}
.ndn-msg-sidebar-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 10px;
}
.ndn-msg-title {
  font-size: 22px; font-weight: 800; letter-spacing: -.02em;
  color: var(--msg-ink);
}
.ndn-msg-compose-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--msg-accent-grad); color: #fff; border: none;
  font-size: 16px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(99,102,241,.35);
  transition: transform .12s ease, box-shadow .18s ease;
}
.ndn-msg-compose-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(99,102,241,.45); }
.ndn-msg-compose-btn:active { transform: scale(.94); }

/* Segmented folder tabs */
.ndn-msg-tabs {
  display: flex; gap: 4px; margin: 0 16px 10px;
  padding: 4px; background: #eceef4; border-radius: 12px;
}
.ndn-msg-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px; border: none; background: transparent;
  font-size: 13px; font-weight: 700; color: var(--msg-muted);
  border-radius: 9px; cursor: pointer; transition: .15s;
}
.ndn-msg-tab:hover { color: var(--msg-ink); }
.ndn-msg-tab.active {
  background: #fff; color: var(--msg-accent);
  box-shadow: 0 2px 6px rgba(15,23,42,.08);
}
.ndn-msg-tab-count { font-size: 11px; font-weight: 800; color: var(--msg-danger); }
.ndn-msg-tab.active .ndn-msg-tab-count { color: var(--msg-danger); }

/* Compose search */
.ndn-msg-compose { padding: 0 16px 10px; position: relative; }
.ndn-msg-compose input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--msg-line);
  border-radius: 12px; font-size: 13px; box-sizing: border-box;
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.ndn-msg-compose input:focus {
  outline: none; border-color: var(--msg-accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.ndn-msg-search-results {
  max-height: 240px; overflow-y: auto; margin-top: 6px;
  background: #fff; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15,23,42,.12); border: 1px solid var(--msg-line);
}
.ndn-msg-search-results:empty { display: none; }
.ndn-msg-search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--msg-ink);
}
.ndn-msg-search-item:hover { background: var(--msg-unread); }
.ndn-msg-search-item img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }

/* Conversation list */
.ndn-msg-conv-list { flex: 1; overflow-y: auto; min-height: 0; padding: 4px 8px 8px; }
.ndn-msg-empty { padding: 28px 16px; text-align: center; color: #94a3b8; font-size: 13px; }

.ndn-msg-conv {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; cursor: pointer; position: relative;
  border-radius: 14px; transition: background .14s;
}
.ndn-msg-conv + .ndn-msg-conv { margin-top: 2px; }
.ndn-msg-conv:hover { background: #eef0f6; }
.ndn-msg-conv.is-active { background: #e6e9fb; }
.ndn-msg-conv.is-unread { background: var(--msg-unread); }
.ndn-msg-conv-avatar {
  width: 50px; height: 50px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(15,23,42,.06);
}
.ndn-msg-conv-main { flex: 1; min-width: 0; }
.ndn-msg-conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ndn-msg-conv-name {
  font-weight: 700; font-size: 14.5px; color: var(--msg-ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ndn-msg-conv-time { font-size: 11px; color: #94a3b8; flex-shrink: 0; }
.ndn-msg-conv-preview {
  font-size: 13px; color: var(--msg-muted); margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ndn-msg-conv.is-unread .ndn-msg-conv-name,
.ndn-msg-conv.is-unread .ndn-msg-conv-preview { color: var(--msg-ink); font-weight: 700; }
.ndn-msg-conv-unread {
  flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--msg-accent-grad); color: #fff; border-radius: 10px;
  font-size: 11px; font-weight: 800; line-height: 20px; text-align: center;
}

/* --- Thread --- */
.ndn-msg-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--msg-bg); }
.ndn-msg-thread-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #94a3b8; gap: 14px; padding: 24px;
  text-align: center;
}
.ndn-msg-thread-empty-icon {
  display: flex; align-items: center; justify-content: center;
  width: 88px; height: 88px; border-radius: 50%;
  background: var(--msg-unread); font-size: 40px;
}
.ndn-msg-thread-empty p { margin: 0; font-size: 14px; max-width: 240px; }
.ndn-msg-thread-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.ndn-msg-thread-hd {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 56px 12px 16px;
  border-bottom: 1px solid var(--msg-line);
  background: rgba(255,255,255,.92); backdrop-filter: blur(6px);
}
.ndn-msg-back {
  display: none; background: none; border: none; font-size: 28px;
  cursor: pointer; color: var(--msg-accent); line-height: 1; padding: 0 2px;
}
.ndn-msg-thread-avatar {
  width: 42px; height: 42px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 1px rgba(15,23,42,.06);
}
.ndn-msg-thread-name {
  font-weight: 800; font-size: 15.5px; color: var(--msg-ink);
  text-decoration: none; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ndn-msg-thread-name:hover { color: var(--msg-accent); }
.ndn-msg-thread-tools { display: flex; gap: 6px; }
.ndn-msg-tool {
  display: inline-flex; align-items: center; gap: 5px;
  background: #f1f3f7; border: none; border-radius: 10px;
  padding: 7px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; color: #475569; white-space: nowrap; transition: .15s;
}
.ndn-msg-tool:hover { background: #e6e9f1; color: var(--msg-ink); }
.ndn-msg-tool.is-active { background: #fde7e7; color: var(--msg-danger); }

/* Messages area */
.ndn-msg-messages {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 3px;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(99,102,241,.05), transparent 70%),
    var(--msg-bg);
}
.ndn-msg-bubble-row { display: flex; margin-top: 2px; }
.ndn-msg-bubble-row.ndn-msg-me { justify-content: flex-end; }
/* group spacing: a little more air when switching speaker */
.ndn-msg-bubble-row.ndn-msg-me + .ndn-msg-bubble-row.ndn-msg-them,
.ndn-msg-bubble-row.ndn-msg-them + .ndn-msg-bubble-row.ndn-msg-me { margin-top: 10px; }
.ndn-msg-bubble {
  position: relative; max-width: 74%;
  padding: 9px 13px; border-radius: 18px;
  font-size: 14px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(15,23,42,.05);
}
.ndn-msg-them .ndn-msg-bubble {
  background: var(--msg-them); color: var(--msg-ink);
  border-bottom-left-radius: 6px;
}
.ndn-msg-me .ndn-msg-bubble {
  background: var(--msg-accent-grad); color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 12px rgba(99,102,241,.3);
}
.ndn-msg-time { display: block; font-size: 10.5px; opacity: .7; margin-top: 4px; }
.ndn-msg-me .ndn-msg-time { color: rgba(255,255,255,.85); }
.ndn-msg-spam-tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: #fde7e7; color: #c62828; font-size: 10px;
  font-weight: 800; border-radius: 6px; vertical-align: middle; text-transform: uppercase;
}
.ndn-msg-del-one {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: #fff; border: 1px solid var(--msg-line); color: #94a3b8;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  font-size: 13px; line-height: 1; display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(15,23,42,.12);
}
.ndn-msg-me .ndn-msg-del-one { left: -28px; }
.ndn-msg-them .ndn-msg-del-one { right: -28px; }
.ndn-msg-bubble-row:hover .ndn-msg-del-one { display: inline-flex; }
.ndn-msg-del-one:hover { color: var(--msg-danger); border-color: #fecaca; }

.ndn-msg-blocked-note {
  margin: 0 16px 6px; padding: 10px 14px; text-align: center; color: #b91c1c;
  font-size: 13px; background: #fef2f2; border: 1px solid #fee2e2; border-radius: 12px;
}

/* Composer */
.ndn-msg-composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 16px 16px; border-top: 1px solid var(--msg-line); background: #fff;
}
.ndn-msg-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--msg-line); border-radius: 22px;
  padding: 11px 16px; font-size: 14px; line-height: 1.4;
  max-height: 140px; font-family: inherit; box-sizing: border-box;
  background: var(--msg-bg-soft); transition: border-color .15s, box-shadow .15s, background .15s;
}
.ndn-msg-composer textarea:focus {
  outline: none; border-color: var(--msg-accent); background: #fff;
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.ndn-msg-send {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 50%;
  border: none; background: var(--msg-accent-grad); color: #fff;
  font-size: 16px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(99,102,241,.4);
  transition: transform .12s ease, box-shadow .18s ease, opacity .15s;
}
.ndn-msg-send:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99,102,241,.5); }
.ndn-msg-send:active { transform: scale(.92); }

/* Slim scrollbars inside the messenger */
.ndn-msg-modal .ndn-msg-conv-list::-webkit-scrollbar,
.ndn-msg-modal .ndn-msg-messages::-webkit-scrollbar,
.ndn-msg-modal .ndn-msg-search-results::-webkit-scrollbar { width: 8px; }
.ndn-msg-modal .ndn-msg-conv-list::-webkit-scrollbar-thumb,
.ndn-msg-modal .ndn-msg-messages::-webkit-scrollbar-thumb,
.ndn-msg-modal .ndn-msg-search-results::-webkit-scrollbar-thumb {
  background: #d4d8e2; border-radius: 8px;
}
.ndn-msg-modal .ndn-msg-conv-list:hover::-webkit-scrollbar-thumb,
.ndn-msg-modal .ndn-msg-messages:hover::-webkit-scrollbar-thumb { background: #c2c7d4; }

/* --- Mobile --- */
@media (max-width: 680px) {
  .ndn-modal.ndn-msg-modal { padding: 0; }
  .ndn-modal.ndn-msg-modal .ndn-modal-box.ndn-msg-box {
    width: 100vw; max-width: 100vw; height: 100vh; max-height: none;
    border-radius: 0; animation: none;
  }
  .ndn-msg-sidebar { width: 100%; }
  .ndn-msg-sidebar.ndn-msg-mobile-hidden { display: none; }
  .ndn-msg-back { display: block; }
  .ndn-msg-thread { width: 100%; }
  .ndn-msg-thread-hd { padding-right: 16px; }
  .ndn-msg-thread-tools .ndn-msg-tool {
    padding: 8px; font-size: 0; gap: 0;
  }
  .ndn-msg-thread-tools .ndn-msg-tool::first-letter { font-size: 15px; }
  .ndn-msg-bubble { max-width: 82%; }
}
