:root {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-2: #666666;
  --text-3: #9aa0a6;
  --border: #f0f0f0;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

/* ===== 顶栏 ===== */
.header {
  background: var(--surface);
  padding: .65rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header .header-user {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-width: 0;
  flex: 1;
}

.header .user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(102, 126, 234, .25);
}

.header .user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header .user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.header .user-name {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header .user-account {
  font-size: .68rem;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.header .add-btn {
  font-size: 1.4rem;
  color: var(--primary);
  background: none;
  border: none;
  padding: 0;
  min-width: 40px;
  cursor: pointer;
  text-align: right;
  transition: transform .15s;
}

.header .add-btn:active {
  transform: scale(.9);
}

/* ===== 聊天室搜索框 ===== */
.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 0;
}

.room-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .8rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}

.room-item:active {
  background: #f5f6f8;
}

.room-item .avatar {
  width: 45px;
  height: 45px;
  border-radius: 14px;
  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 img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.room-item .info {
  flex: 1;
  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 .preview {
  font-size: .8rem;
  color: var(--text-2);
  margin-top: 4px;
  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: 6px;
}

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

.room-item .meta .badge {
  display: none;
  background: var(--primary);
  color: #fff;
  border-radius: 11px;
  min-width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  font-size: .68rem;
  font-weight: 600;
  padding: 0 6px;
  box-shadow: 0 2px 5px rgba(102, 126, 234, .35);
}

.room-item .meta .badge.show {
  display: inline-block;
}

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

/* ===== 底部固定操作栏 ===== */
.footer {
  flex-shrink: 0;
  padding: .8rem 1rem;
  padding-bottom: calc(.8rem + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.footer .join-btn {
  display: block;
  text-align: center;
  color: #fff;
  background: var(--primary);
  text-decoration: none;
  font-weight: 600;
  padding: .68rem 0;
  border-radius: 24px;
  font-size: .92rem;
  box-shadow: 0 4px 12px rgba(102, 126, 234, .3);
  transition: background .15s, transform .1s;
}

.footer .join-btn:active {
  background: var(--primary-dark);
  transform: scale(.98);
}

/* ===== Toast ===== */
.toast-msg {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1.2rem;
  border-radius: 24px;
  color: #fff;
  font-size: .85rem;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  transition: opacity .25s, transform .25s;
}

.toast-msg.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-msg .toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.toast-msg.error {
  background: #dc3545;
}

.toast-msg.info {
  background: var(--primary);
}

.toast-msg.success {
  background: #28a745;
}

/* ===== 设置侧拉抽屉（右侧滑出） ===== */
.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-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"] {
  --primary: #8a9bff;
  --primary-dark: #a5b4ff;
  --bg: #0e1621;
  --surface: #17212b;
  --text: #f5f5f5;
  --text-2: #a8b3bf;
  --text-3: #6c7883;
  --border: #2b3a4a;
}
[data-theme="dark"] .room-item:active,
[data-theme="dark"] .settings-drawer .sd-menu-item:active {
  background: #1e2a38;
}

/* ==================== 按钮颜色统一 ==================== */
.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--primary-dark);
  border-color: var(--primary-dark);
}

/* 次要按钮（取消/关闭）：柔和浅灰 */
.btn-secondary {
  background-color: #eef0f4;
  border-color: #eef0f4;
  color: #4a4f57;
}
.btn-secondary:hover,
.btn-secondary:focus,
.btn-secondary:active {
  background-color: #e2e5ea;
  border-color: #e2e5ea;
  color: #4a4f57;
}
[data-theme="dark"] .btn-secondary {
  background-color: #2b3a4a;
  border-color: #2b3a4a;
  color: #a8b3bf;
}
[data-theme="dark"] .btn-secondary:hover,
[data-theme="dark"] .btn-secondary:focus,
[data-theme="dark"] .btn-secondary:active {
  background-color: #33465a;
  border-color: #33465a;
  color: #f5f5f5;
}

/* 危险按钮：浅色保持 Bootstrap 红，深色提亮 */
[data-theme="dark"] .btn-danger {
  background-color: #ff6b6b;
  border-color: #ff6b6b;
}
[data-theme="dark"] .btn-danger:hover,
[data-theme="dark"] .btn-danger:focus,
[data-theme="dark"] .btn-danger:active {
  background-color: #ff8585;
  border-color: #ff8585;
}

/* 弹窗圆角统一（与气泡/卡片一致） */
.modal-content {
  border-radius: 14px;
  overflow: hidden;
}

/* ==================== 弹窗深色适配 ==================== */
[data-theme="dark"] .modal-content {
  background: #17212b;
  color: #f5f5f5;
  border-color: #2b3a4a;
}
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer {
  border-color: #2b3a4a;
}
[data-theme="dark"] .modal-title {
  color: #f5f5f5;
}
[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}
[data-theme="dark"] .form-control {
  background: #232e3c;
  border-color: #2b3a4a;
  color: #f5f5f5;
}
[data-theme="dark"] .form-control:focus {
  background: #232e3c;
  border-color: #8a9bff;
  color: #f5f5f5;
  box-shadow: 0 0 0 3px rgba(138, 155, 255, .15);
}
[data-theme="dark"] .form-control::placeholder {
  color: #6c7883;
}
[data-theme="dark"] .modal .text-muted {
  color: #a8b3bf !important;
}

/* ==================== 主题开关 ==================== */
.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);
}

/* 头像透明区域棋盘格背景（有头像时透明区域显示棋盘格，而非容器紫色） */
.header .user-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;
}
