/* ============================================================
   消息中心样式（页面 + 弹窗共用）
   - 页面模式：messages.html 直接渲染（薄壳调用 MessagesModule.mountAsPage）
   - 弹窗模式：任意页面通过 MessagesModule.open() 弹出
   - 由 js/messages-module.js 同时驱动两种模式
   ============================================================ */

/* ----- 主题变量（仅 messages 作用域内） ----- */
.msg-scope,
.msg-modal {
  --bg-page:    #fafbfc;
  --bg-card:    #ffffff;
  --bg-soft:    #eff6ff;
  --bg-muted:   #f3f4f6;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #64748b;
  --text-hint:      #94a3b8;
  --border:        #dbeafe;
  --border-soft:   #e5e7eb;
  --border-input:  #cbd5e1;
  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --success: #10b981;
  --danger:  #dc2626;
}

/* ----- 页面模式容器 ----- */
.msg-scope main { padding: 28px 24px 64px; }
.msg-scope .container { max-width: 880px; margin: 0 auto; }
.msg-scope .page-title { font-size: 24px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.msg-scope .page-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

/* ----- 弹窗：遮罩 + 对话框 ----- */
.msg-modal[hidden] { display: none !important; }
.msg-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 64px 24px 24px;
  animation: msg-modal-fade 0.18s ease-out;
  overflow-y: auto;
}
@keyframes msg-modal-fade { from { opacity: 0; } to { opacity: 1; } }

.msg-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.20), 0 4px 12px rgba(15, 23, 42, 0.08);
  width: min(880px, 100%);
  /* 固定高度：四个 tab 切换时弹窗尺寸保持一致（880×620 长方形）；矮屏自动收缩 */
  height: min(620px, calc(100vh - 88px));
  max-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: msg-dialog-up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes msg-dialog-up {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

.msg-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-card);
  position: relative;
  flex-shrink: 0;
}
.msg-dialog-head .msg-dialog-titles { display: flex; flex-direction: column; gap: 4px; }
.msg-dialog-title { font-size: 18px; font-weight: 600; color: var(--text-primary); letter-spacing: 0.02em; }
.msg-dialog-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.msg-dialog-close:hover,
.msg-dialog-close:focus-visible {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-color: var(--border-soft);
  outline: none;
}

.msg-dialog-body {
  padding: 18px 24px 24px;
  /* 滚动下沉到各 tab 的 .list，body 只负责把内容区纵向铺满 */
  overflow: hidden;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ----- 弹窗定高：内容区 flex 占满、列表内部滚动、空状态居中 ----- */
.msg-dialog [data-msg-content] {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.msg-dialog .tab-bar { flex-shrink: 0; }
/* 申请/会话/找好友/通知 列表统一占满剩余高度，滚动固定在列表层（含滚动条占位，避免各 tab 宽度抖动）
   选择器提到 3 个 class/属性，特异性高于后文 .msg-dialog .list 基础规则里的 overflow:hidden */
.msg-dialog [data-msg-content] .list:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}
/* 找好友 / 通知 面板：工具行固定，列表弹性填充 */
.msg-dialog [data-scope="findPane"]:not([hidden]),
.msg-dialog [data-scope="notifPane"]:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.msg-dialog .find-bar,
.msg-dialog .notif-toolbar { flex-shrink: 0; }
/* 空状态在列表框内垂直水平居中 */
.msg-dialog .empty { margin: auto; }

/* ----- Tab ----- */
.msg-scope .tab-bar,
.msg-dialog .tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.msg-scope .tab,
.msg-dialog .tab {
  padding: 12px 18px;
  font-size: 14px;
  color: var(--text-muted);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.msg-scope .tab.active,
.msg-dialog .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}
.msg-scope .tab .badge,
.msg-dialog .tab .badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  height: 18px;
  line-height: 18px;
  background: var(--danger);
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  margin-left: 6px;
  text-align: center;
}
.msg-scope .tab .badge:empty,
.msg-scope .tab .badge.zero,
.msg-dialog .tab .badge:empty,
.msg-dialog .tab .badge.zero { display: none; }

/* ----- List & Item ----- */
.msg-scope .list,
.msg-dialog .list {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  overflow: hidden;
}
.msg-scope .item,
.msg-dialog .item {
  display: flex;
  gap: 14px;
  padding: 16px 20px;
  align-items: center;
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.12s;
  text-decoration: none;
  color: inherit;
}
.msg-scope .item:last-child,
.msg-dialog .item:last-child { border-bottom: 0; }
.msg-scope .item:hover,
.msg-dialog .item:hover { background: var(--bg-soft); }
.msg-scope .item.unread,
.msg-dialog .item.unread { background: #f0f7ff; }
.msg-scope .item.unread:hover,
.msg-dialog .item.unread:hover { background: #e6f1ff; }

/* ----- Avatar ----- */
.msg-scope .avatar,
.msg-dialog .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}
.msg-scope .avatar img,
.msg-dialog .avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ----- Item main ----- */
.msg-scope .item-main,
.msg-dialog .item-main { flex: 1; min-width: 0; }
.msg-scope .item-row1,
.msg-dialog .item-row1 { display: flex; gap: 8px; align-items: baseline; }
.msg-scope .item-name,
.msg-dialog .item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
}
.msg-scope .item-name:hover,
.msg-dialog .item-name:hover { color: var(--accent); }
.msg-scope .item-time,
.msg-dialog .item-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}
.msg-scope .item-row2,
.msg-dialog .item-row2 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-scope .item-actions,
.msg-dialog .item-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ----- Buttons ----- */
.msg-scope .btn,
.msg-dialog .btn {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border-input);
  background: #fff;
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msg-scope .btn:hover,
.msg-dialog .btn:hover { background: var(--bg-muted); }
.msg-scope .btn-primary,
.msg-dialog .btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.msg-scope .btn-primary:hover,
.msg-dialog .btn-primary:hover { background: var(--accent-hover); }
.msg-scope .btn-danger,
.msg-dialog .btn-danger { color: var(--danger); border-color: #fecaca; }
.msg-scope .btn-danger:hover,
.msg-dialog .btn-danger:hover { background: #fef2f2; }

/* ----- Unread dot ----- */
.msg-scope .unread-dot,
.msg-dialog .unread-dot {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  background: var(--danger);
  color: #fff;
  border-radius: 9px;
  font-size: 11px;
  padding: 0 6px;
  text-align: center;
  font-weight: 500;
}

/* ----- Empty ----- */
.msg-scope .empty,
.msg-dialog .empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.msg-scope .empty .icon,
.msg-dialog .empty .icon { font-size: 40px; margin-bottom: 8px; opacity: 0.5; }

/* ----- Notification ----- */
.msg-scope .notif-toolbar,
.msg-dialog .notif-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}
.msg-scope .notif-toolbar .hint,
.msg-dialog .notif-toolbar .hint { color: var(--text-muted); font-size: 12px; }
.msg-scope .notif-type,
.msg-dialog .notif-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}
.msg-scope .notif-type-system,
.msg-dialog .notif-type-system   { background: #dbeafe; color: #1d4ed8; }
.msg-scope .notif-type-activity,
.msg-dialog .notif-type-activity { background: #d1fae5; color: #047857; }
.msg-scope .notif-type-warning,
.msg-dialog .notif-type-warning  { background: #fef3c7; color: #b45309; }
.msg-scope .notif-type-reward,
.msg-dialog .notif-type-reward   { background: #fce7f3; color: #be185d; }
.msg-scope .notif-title,
.msg-dialog .notif-title { font-size: 14px; font-weight: 500; color: var(--text-primary); }
.msg-scope .notif-source,
.msg-dialog .notif-source { font-size: 11px; color: var(--text-hint); margin-left: 6px; }
.msg-scope .notif-content,
.msg-dialog .notif-content {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.5;
  word-break: break-word;
}
.msg-scope .notif-link,
.msg-dialog .notif-link {
  font-size: 12px;
  color: var(--accent);
  margin-top: 6px;
  display: inline-block;
  text-decoration: none;
}
.msg-scope .notif-link:hover,
.msg-dialog .notif-link:hover { text-decoration: underline; }

/* ----- Find friend ----- */
.msg-scope .find-bar,
.msg-dialog .find-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.msg-scope .find-bar input,
.msg-dialog .find-bar input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-input);
  border-radius: 999px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.msg-scope .find-bar input:focus,
.msg-dialog .find-bar input:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
/* Relation tag（找好友/粉丝列表关系标签：关注-回关状态机） */
.msg-scope .relation-tag,
.msg-dialog .relation-tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
}
.msg-scope .relation-tag.friend,
.msg-dialog .relation-tag.friend        { background: #d1fae5; color: #047857; }
.msg-scope .relation-tag.following,
.msg-dialog .relation-tag.following     { background: #dbeafe; color: #1d4ed8; }
.msg-scope .relation-tag.followed_by,
.msg-dialog .relation-tag.followed_by   { background: #fef3c7; color: #b45309; }
.msg-scope .relation-tag.blocked,
.msg-dialog .relation-tag.blocked       { background: #fee2e2; color: #b91c1c; }

/* ----- Toast ----- */
.msg-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.msg-toast.show { opacity: 1; }
.msg-toast.error   { background: var(--danger); }
.msg-toast.success { background: var(--success); }

/* ----- Recalled pill ----- */
.msg-scope .recalled-pill,
.msg-dialog .recalled-pill {
  display: inline-block;
  padding: 1px 8px;
  background: var(--bg-muted);
  color: var(--text-muted);
  border-radius: 4px;
  font-size: 11px;
  margin-left: 6px;
}

/* ----- 响应式 ----- */
@media (max-width: 720px) {
  .msg-modal { padding: 0; align-items: stretch; }
  .msg-dialog {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: 0;
  }
  .msg-dialog-body { padding: 14px 16px 24px; }
  .msg-dialog-head { padding: 16px 16px 12px; }
  .msg-scope .item,
  .msg-dialog .item { padding: 12px 14px; }
  .msg-scope .item-actions,
  .msg-dialog .item-actions { flex-direction: column; gap: 4px; }
}