.page {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ===== 顶栏 ===== */
.header {
  background: var(--surface);
  padding: 1rem 1.1rem .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.header .header-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
}

.header .brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.header .brand-name {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -.02em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header .header-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.header .add-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: none;
  font-size: 1.25rem;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  transition: transform .12s, background .15s;
}

.header .add-btn:active {
  transform: scale(.92);
  background: var(--border);
}

/* ===== 群组搜索框 ===== */
.search-box {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: .6rem 1rem .2rem;
  padding: .45rem .7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-shrink: 0;
}
.search-box > i {
  color: var(--text-3);
  font-size: .9rem;
}
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font-size: .9rem;
  min-width: 0;
}
.search-box input::placeholder {
  color: var(--text-3);
}
.search-box input::-webkit-search-cancel-button,
.search-box input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}
.search-box .search-clear {
  border: none;
  background: none;
  color: var(--text-3);
  padding: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

/* ===== 会话列表 ===== */
.list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: .25rem .6rem;
  background-color: #e9edf6;
  background-image: url('../img/chat-bg-light.svg');
  background-repeat: repeat;
  background-size: 240px 240px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .68rem .5rem;
  border-radius: 16px;
  cursor: pointer;
  transition: background .15s;
  /* ★ 长按期间屏蔽系统文字选择/放大镜，同时防止触摸期间意外选中列表文字 */
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* 已置顶：与背景一致的色调区分，左上角置顶角标 */
.room-item.pinned {
  background: rgba(102, 126, 234, .06);
  position: relative;
}
.room-item.pinned::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-top: 14px solid var(--primary);
  border-right: 14px solid transparent;
  border-top-left-radius: 16px;
  pointer-events: none;
}
.room-item.pinned::after {
  content: '\f4ea';   /* bi-pin-angle-fill */
  position: absolute;
  top: 1px;
  left: 1px;
  font-family: "bootstrap-icons";
  color: #fff;
  font-size: 10px;
  line-height: 1;
  pointer-events: none;
  transform: rotate(-12deg);
}

.room-item:active {
  background: rgba(102, 126, 234, .08);
}

.room-item .avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}

.room-item .avatar.dm {
  border-radius: 50%;
}

.room-item .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-item .avatar .group-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--surface);
}

.room-item .avatar .group-badge i {
  font-size: .68rem;
  color: var(--primary);
}

.room-item .avatar .online-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--online, #22c55e);
  box-shadow: 0 0 0 2px var(--surface);
}

.room-item .info {
  flex: 1;
  min-width: 0;
}

.room-item .info .name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.room-item .info .name {
  font-size: .95rem;
  /*font-weight: 600;*/
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item .info .type-tag {
  flex-shrink: 0;
  font-size: .62rem;
  font-weight: 600;
  color: var(--primary);
  background: rgba(102, 126, 234, .1);
  padding: 2px 7px;
  border-radius: 6px;
  letter-spacing: .02em;
}

.room-item .info .type-tag.dm {
  color: #2bb5d8;
  background: rgba(43, 181, 216, .12);
}

.room-item .info .preview {
  font-size: .8rem;
  color: var(--text-2);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item .info .preview .sensitive-tag {
  color: #f33;
  font-weight: 600;
  margin-right: 4px;
}

.room-item .meta {
  text-align: right;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}

.room-item .meta .time {
  font-size: .68rem;
  color: var(--text-3);
}

.room-item .meta .members {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: .68rem;
  color: var(--text-3);
}

.room-item .meta .members i {
  font-size: .68rem;
}

.room-item .meta .unread {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-3);
  font-size: .9rem;
}

/* ===== 加号菜单浮层 ===== */
.add-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .3);
  z-index: 400;
}

.add-menu-overlay.show {
  display: block;
}

.add-menu {
  position: fixed;
  top: 60px;
  right: 14px;
  width: 200px;
  background: var(--surface);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
  z-index: 401;
  transform: translateY(-8px) scale(.97);
  opacity: 0;
  pointer-events: none;
  transition: transform .18s, opacity .18s;
  transform-origin: top right;
}

.add-menu.show {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.add-menu .am-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: none;
  background: none;
  border-radius: 11px;
  font-size: .92rem;
  font-weight: 550;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.add-menu .am-item:active {
  background: rgba(102, 126, 234, .1);
}

.add-menu .am-item i {
  font-size: 1.1rem;
  color: var(--primary);
}

/* ===== 设置侧拉抽屉（右侧滑出） ===== */
.settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .3);
  z-index: 500;
}

.settings-overlay.show {
  display: block;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 60px;
  width: 280px;
  max-width: 85vw;
  background: var(--surface);
  z-index: 501;
  transform: translateX(100%);
  transition: transform .25s;
  display: flex;
  flex-direction: column;
  box-shadow: -2px 0 16px rgba(0, 0, 0, .12);
}

.settings-drawer.show {
  transform: translateX(0);
}

.settings-drawer .sd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-drawer .sd-header h6 {
  margin: 0;
  font-weight: 700;
  color: var(--text);
}

.settings-drawer .sd-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-3);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.settings-drawer .sd-profile {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}

.settings-drawer .sd-profile:active {
  background: #f5f6f8;
}

.settings-drawer .sd-profile .sd-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.settings-drawer .sd-profile .sd-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.settings-drawer .sd-profile .sd-info {
  flex: 1;
  min-width: 0;
}

.settings-drawer .sd-profile .sd-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-drawer .sd-profile .sd-account {
  font-size: .8rem;
  color: var(--text-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-drawer .sd-profile .sd-arrow {
  color: var(--text-3);
  font-size: 1.1rem;
  flex-shrink: 0;
}

.settings-drawer .sd-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: .5rem 0;
}

.settings-drawer .sd-menu-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .9rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  font-size: .95rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}

.settings-drawer .sd-menu-item:active {
  background: #f5f6f8;
}

.settings-drawer .sd-menu-item i {
  color: var(--primary);
  font-size: 1.15rem;
}

.settings-drawer .sd-footer {
  flex-shrink: 0;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
}

/* ==================== 深色主题 ==================== */
[data-theme="dark"] .list {
  background-color: #0e1621;
  background-image: url('../img/chat-bg-dark.svg');
}
[data-theme="dark"] .room-item:active,
[data-theme="dark"] .settings-drawer .sd-menu-item:active {
  background: #1e2a38;
}
[data-theme="dark"] .room-item.pinned {
  background: rgba(102, 126, 234, .10);
}

/* ==================== 个人信息简介色块 ==================== */
.sig-hidden {
  display: none !important;
}
.profile-signature-block {
  background: rgba(102, 126, 234, .10);
  color: var(--text-2);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .875rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  text-align: left;
}
[data-theme="dark"] .profile-signature-block {
  background: rgba(138, 155, 255, .12);
  color: var(--text-2);
}

/* ==================== 二级弹窗固定提示色块 ==================== */
.profile-field-hint {
  background: var(--bg);
  color: var(--text-2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .8rem;
  line-height: 1.5;
  text-align: left;
  margin-bottom: .5rem;
  white-space: pre-line;
}

/* ==================== 二级弹窗下划线输入框 ==================== */
.input-underline {
  border: none;
  border-bottom: 1px solid #ced4da;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}
.input-underline:focus {
  border-bottom-color: #86b7fe;
  box-shadow: none;
}
[data-theme="dark"] .input-underline {
  border: none;
  border-bottom: 1px solid #2b3a4a;
}
[data-theme="dark"] .input-underline:focus {
  border-bottom-color: #8a9bff;
  box-shadow: none;
}

/* ==================== 邮箱验证码发送按钮 ==================== */
.profile-code-btn {
  flex-shrink: 0;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  font-size: .82rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.profile-code-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  color: var(--text-3);
  border-color: var(--border);
}

/* ==================== 资料字段/输入框图标 ==================== */
.profile-field-icon {
  color: var(--primary);
  font-size: 1rem;
  flex-shrink: 0;
}

/* ==================== 主题开关 ==================== */
.settings-drawer .sd-menu-item .sd-switch {
  margin-left: auto;
  display: flex;
  align-items: center;
  padding-left: 0;
}
.settings-drawer .sd-menu-item .sd-switch .form-check-input {
  cursor: pointer;
  width: 38px;
  height: 18px;
}
.form-switch .form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* 头像透明区域棋盘格背景（有头像时透明区域显示棋盘格，而非容器紫色） */
.settings-drawer .sd-profile .sd-avatar img,
.room-item .avatar img,
#profileAvatarImg {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ==================== 发起私聊左侧抽屉 ==================== */
.dm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .3);
  z-index: 500;
}
.dm-overlay.show {
  display: block;
}
.dm-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 60px;
  width: 280px;
  max-width: 85vw;
  background: var(--surface);
  z-index: 501;
  transform: translateX(-100%);
  transition: transform .25s;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 16px rgba(0, 0, 0, .12);
}
.dm-drawer.show {
  transform: translateX(0);
}
.dm-drawer .sd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.dm-drawer .sd-header h6 {
  margin: 0;
  font-weight: 700;
  color: var(--text);
}
.dm-drawer .sd-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-3);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.dm-search-row {
  display: flex;
  gap: 8px;
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== 首页会话长按菜单（ctx-menu） ===== */
.ctx-mask {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, .28);
  /* 屏蔽穿透：遮罩层自身也不能被长按选择文字 */
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
  -webkit-touch-callout: none;
}
.ctx-mask.show { display: block; }

.ctx-menu {
  position: fixed;
  z-index: 9999;
  min-width: 190px;
  max-width: 72vw;
  background: var(--surface);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18), 0 2px 6px rgba(0, 0, 0, .08);
  padding: 6px;
  font-size: .88rem;
  overflow: hidden;
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
  -webkit-touch-callout: none;
  backdrop-filter: blur(10px);
}
.ctx-menu.show { display: block; animation: ctxIn .14s ease-out; }
@keyframes ctxIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1);    }
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
  color: var(--text);
  line-height: 1.3;
}
.ctx-item:hover,
.ctx-item:active {
  background: rgba(102, 126, 234, .1);
}
.ctx-item::before {
  font-family: "bootstrap-icons";
  font-size: 1rem;
  width: 18px;
  text-align: center;
  color: var(--primary);
  flex-shrink: 0;
}
.ctx-item[data-act="pin"]::before    { content: '\f4ea'; }   /* bi-pin-angle-fill */
.ctx-item[data-act="unpin"]::before  { content: '\f4eb'; }   /* bi-pin-angle      */
.ctx-item[data-act="read"]::before   { content: '\f26f'; }   /* bi-check2-all     */
.ctx-item[data-act="readAll"]::before{ content: '\f26f'; }   /* bi-check2-all     */
.ctx-item[data-act="remark"]::before { content: '\f4cd'; }   /* bi-pencil-square  */

.ctx-item.ctx-danger { color: #e25151; }
.ctx-item.ctx-danger::before { color: #e25151; }

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* 长按已触发时，临时对整个 view-index 进一步阻止系统选择（防触摸漂移选中文字） */
#view-index.long-press-active * {
  -webkit-user-select: none !important;
          user-select: none !important;
  -webkit-touch-callout: none !important;
}
.dm-search-row input {
  flex: 1;
  min-width: 0;
}
.dm-search-btn {
  flex-shrink: 0;
}
.dm-result {
  flex: 1;
  overflow: auto;
  padding: .5rem;
}
.dm-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: .6rem;
  border-radius: 10px;
  cursor: pointer;
}
.dm-result-item:active {
  background: rgba(0, 0, 0, .05);
}
.dm-result-item .avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.dm-result-item .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}
.dm-result-item .info {
  flex: 1;
  min-width: 0;
}
.dm-result-item .info .name {
  font-size: .95rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dm-result-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-3);
}
