/* ========================================
   查手机-讯息页面样式
   角色视角下的聊天APP界面
   ======================================== */

/* ---- 全屏容器 ---- */
.pm-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  max-width: 100%;
  background: var(--color-shell-bg);
  z-index: calc(var(--z-chat) + 2);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: translateX(100%);
  /* 关闭后彻底隐藏，避免在某些视口下从右侧露出、撑宽文档 */
  visibility: hidden;
  transition: transform 0.3s ease, opacity 0.2s ease, visibility 0s linear 0.3s;
  overflow: hidden;
  overflow-x: hidden;
  box-sizing: border-box;
}

.pm-screen.is-active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.3s ease, opacity 0.2s ease, visibility 0s;
}

/* ================================================
   1. 列表视图
   ================================================ */
.pm-list-view {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  transition: transform 0.3s ease;
}

.pm-list-view.is-hidden {
  transform: translateX(-30%);
  pointer-events: none;
}

/* ---- 顶部导航 ---- */
.pm-nav {
  display: flex;
  align-items: center;
  padding: 12px var(--spacing-page);
  gap: 10px;
  flex-shrink: 0;
}

.pm-nav__back {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.pm-nav__back:active { background: var(--color-accent-active); }
.pm-nav__back svg { width: 22px; height: 22px; }

.pm-nav__title {
  flex: 1;
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.pm-nav__right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pm-nav__action {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  color: var(--color-text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.pm-nav__action:active { background: var(--color-accent-active); }
.pm-nav__action svg { width: 20px; height: 20px; }

/* ---- 角色身份栏 ---- */
.pm-owner-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px var(--spacing-page) 12px;
  flex-shrink: 0;
}

.pm-owner-bar__avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--color-card-muted);
  border: 1.5px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  overflow: hidden;
  flex-shrink: 0;
}

.pm-owner-bar__avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

.pm-owner-bar__info {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.pm-owner-bar__name {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

.pm-owner-bar__hint {
  font-size: var(--font-size-sm);
  color: var(--color-text-hint);
}

/* ---- 聊天列表区域 ---- */
.pm-list-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--spacing-page) 24px;
}

/* ---- 聊天列表 ---- */
.pm-chat-list {
  display: flex;
  flex-direction: column;
}

/* 单条聊天项 */
.pm-chat-item {
  display: flex;
  align-items: center;
  padding: 14px 0;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  position: relative;
}

.pm-chat-item:last-child {
  border-bottom: none;
}

.pm-chat-item:active {
  background: rgba(0, 0, 0, 0.02);
}

/* 聊天项头像 */
.pm-chat-item__avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  font-weight: var(--font-weight-semibold);
  color: #fff;
  overflow: hidden;
  position: relative;
}

.pm-chat-item__avatar img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 50%;
}

/* 头像颜色渐变 */
.pm-avatar--grad1 { background: linear-gradient(135deg, #667eea, #764ba2); }
.pm-avatar--grad2 { background: linear-gradient(135deg, #f093fb, #f5576c); }
.pm-avatar--grad3 { background: linear-gradient(135deg, #4facfe, #00f2fe); }
.pm-avatar--grad4 { background: linear-gradient(135deg, #43e97b, #38f9d7); }
.pm-avatar--grad5 { background: linear-gradient(135deg, #fa709a, #fee140); }
.pm-avatar--grad6 { background: linear-gradient(135deg, #a18cd1, #fbc2eb); }

/* 聊天项内容 */
.pm-chat-item__body {
  flex: 1;
  margin-left: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.pm-chat-item__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.pm-chat-item__name {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.pm-chat-item__time {
  font-size: var(--font-size-xs);
  color: var(--color-text-hint);
  flex-shrink: 0;
  margin-left: 8px;
}

.pm-chat-item__preview {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

/* 未读红点 */
.pm-chat-item__badge {
  position: absolute;
  top: 14px; left: 36px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ff3b30;
  border: 2px solid var(--color-shell-bg);
}

/* ---- 加载状态 ---- */
.pm-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
}

.pm-loading.is-hidden {
  display: none;
}

.pm-loading__spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--color-text-secondary);
  border-radius: 50%;
  animation: pmSpin 0.8s linear infinite;
}

@keyframes pmSpin {
  to { transform: rotate(360deg); }
}

.pm-loading__text {
  font-size: var(--font-size-sm);
  color: var(--color-text-hint);
}

/* ---- 空状态 ---- */
.pm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 10px;
}

.pm-empty__icon {
  width: 48px; height: 48px;
  color: var(--color-text-hint);
  opacity: 0.4;
  margin-bottom: 6px;
}

.pm-empty__text {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
}

.pm-empty__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-hint);
}

/* ================================================
   2. 对话详情视图
   ================================================ */
.pm-detail-view {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--color-shell-bg);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 2;
}

.pm-detail-view.is-active {
  transform: translateX(0);
}

/* ---- 详情导航栏 ---- */
.pm-detail-nav {
  display: flex;
  align-items: center;
  padding: 12px var(--spacing-page);
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.pm-detail-nav__back {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.pm-detail-nav__back:active { background: var(--color-accent-active); }
.pm-detail-nav__back svg { width: 22px; height: 22px; }

.pm-detail-nav__profile {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.pm-detail-nav__avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-card-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: var(--font-weight-semibold);
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}

.pm-detail-nav__avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

.pm-detail-nav__name {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pm-detail-nav__right {
  width: 32px;
  flex-shrink: 0;
}

/* ---- 消息区域 ---- */
.pm-detail-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px var(--spacing-page);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 时间分隔 */
.pm-msg-time {
  text-align: center;
  font-size: 11px;
  color: var(--color-text-hint);
  padding: 8px 0;
  user-select: none;
}

/* 消息气泡容器 */
.pm-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
}

.pm-msg--left {
  align-self: flex-start;
}

.pm-msg--right {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* 气泡内小头像 */
.pm-msg__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: var(--font-weight-semibold);
  color: #fff;
  overflow: hidden;
}

.pm-msg__avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

/* 气泡 */
.pm-msg__bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--color-text-primary);
  word-break: break-word;
  position: relative;
}

.pm-msg--left .pm-msg__bubble {
  background: #f0f0f0;
  border-bottom-left-radius: 6px;
}

.pm-msg--right .pm-msg__bubble {
  background: #dcf8c6;
  border-bottom-right-radius: 6px;
}

/* 图片消息 */
.pm-msg__bubble--image {
  padding: 4px;
  background: transparent;
}

.pm-msg__bubble--image img {
  max-width: 180px;
  max-height: 200px;
  border-radius: 14px;
  object-fit: cover;
}

/* 气泡 + 转发按钮包裹层 */
.pm-msg__bubble-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
}

/* 转发质问按钮：仅在 NPC（左侧）气泡旁出现 */
.pm-msg__forward {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: var(--color-text-secondary, #888);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.pm-msg__bubble-wrap:hover .pm-msg__forward,
.pm-msg__forward.is-sent {
  opacity: 1;
  transform: scale(1);
}

.pm-msg__forward:active {
  background: rgba(255, 59, 48, 0.12);
  color: #e0392f;
  transform: scale(0.9);
}

.pm-msg__forward svg {
  width: 14px;
  height: 14px;
}

/* 已转发态：标红常显 */
.pm-msg__forward.is-sent {
  background: rgba(255, 59, 48, 0.12);
  color: #e0392f;
  cursor: default;
  pointer-events: none;
}

/* ---- 详情底部提示 ---- */
.pm-detail-footer {
  flex-shrink: 0;
  padding: 12px var(--spacing-page) 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.pm-detail-footer__hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: var(--font-size-xs);
  color: var(--color-text-hint);
}

.pm-detail-footer__hint svg {
  opacity: 0.6;
}

/* ================================================
   3. Toast
   ================================================ */
.pm-toast {
  position: absolute;
  bottom: 80px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: var(--font-size-sm);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 9999;
}

.pm-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}