/* ===== CSS Variables ===== */
:root {
  --bg: #f0f2f5;
  --bg-2: #ffffff;
  --bg-3: #f5f6f8;
  --bg-hover: #e8eaed;
  --border: #d5d9df;
  --text: #1a1a2e;
  --text-2: #555;
  --text-3: #999;
  --accent: #5b8def;
  --link: #1a6bdb;
  --link-hover: #0f4fae;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 10px;
}
[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-2: #232340;
  --bg-3: #2a2a4a;
  --bg-hover: #32325a;
  --border: #3a3a5c;
  --text: #e8e8f0;
  --text-2: #aab;
  --text-3: #778;
  --link: #7ab0ff;
  --link-hover: #a8cbff;
}

/* ===== Global ===== */
html, body {
  margin:0; padding:0;
  width:100vw; height:100vh;
  overflow: hidden;
  font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  color:var(--text); background:var(--bg);
}
* { box-sizing:border-box; }
button { font-family:inherit; border:none; cursor:pointer; }
input,textarea,select { font-family:inherit; color:var(--text); outline:none; }

/* ===== Login ===== */
.login-view {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.login-card {
  background: var(--bg-2);
  border-radius: 12px;
  padding: 40px 36px;
  width: 380px;
  max-width: 92vw;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.10);
  flex-shrink: 0;
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .brand-logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 22px;
  margin: 0 auto 12px;
}
.login-card h1 { margin:0 0 6px; font-size:22px; line-height:1.3; }
.login-card .brand-sub { color:var(--text-3); margin:0 0 20px; font-size:14px; line-height:1.4; }
.login-card label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.login-card form input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 16px; line-height: 1.3;
  background: var(--bg-3); margin-bottom: 12px;
  -webkit-appearance: none;
  -moz-appearance: none;
}
.login-card form input::placeholder { color: var(--text-3); opacity: 1; }
.login-card button.btn-primary {
  width: 100%; padding: 12px;
  border-radius: 6px; background: var(--accent);
  color: #fff; font-size: 16px; font-weight: 600;
  margin-top: 4px; cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
}
.login-card button:disabled { opacity:.6; cursor:not-allowed; }
.login-error { color:#e35b5b; font-size:13px; margin:12px 0 0; min-height:18px; line-height:1.4; }

/* 移动端适配 */
@media (max-width:480px) {
  .login-card {
    width: 100%;
    max-width: 92vw;
    padding: 28px 20px;
    border-radius: 10px;
  }
  .login-card h1 { font-size: 20px; }
  .login-card input { font-size: 16px; padding: 10px; }
  .login-card button { font-size: 16px; padding: 12px; }
}

/* 平板适配 */
@media (min-width:481px) and (max-width:900px) {
  .login-card {
    width: 400px;
    padding: 36px 32px;
  }
}

/* ===== App Layout ===== */
.app-view {
  display: flex; flex-direction: row;
  width: 100vw; height: 100vh; height: 100dvh;
  overflow: hidden;
}
.app-view > .sidebar { flex: 0 0 280px; }
.app-view > .chat { flex: 1 1 auto; min-width: 0; }
.chat { display:flex; flex-direction:column; min-width:0; min-height:0; background:var(--bg); height:100%; }

/* ===== Sidebar ===== */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex: 0 0 280px; width: 280px;
  height: 100%; min-height: 0;
  overflow: hidden;
  transition: flex 0.25s ease, width 0.25s ease;
}

/* 侧栏收起：仅图标 */
.sidebar.collapsed {
  flex: 0 0 60px; width: 60px;
}

/* 收起时隐藏文字 */
.sidebar.collapsed .brand-title { display: none; }
.sidebar.collapsed .brand-logo.sm { margin: 0 auto; }
.sidebar.collapsed .sidebar-search { display: none; }
.sidebar.collapsed .tab { font-size: 18px; padding: 8px 0; }
.sidebar.collapsed .tab span { display: block; }
.sidebar.collapsed .tab small { display: none; }
.sidebar.collapsed .me-name,
.sidebar.collapsed .me-username { display: none; }
.sidebar.collapsed .sidebar-foot { justify-content: center; padding: 8px; }
.sidebar.collapsed .sidebar-foot .avatar { margin: 0 auto; }
.sidebar.collapsed .user-name,
.sidebar.collapsed .user-last,
.sidebar.collapsed .user-text,
.sidebar.collapsed .user-badge { display: none !important; }
.sidebar.collapsed .user-row { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .sidebar-head { padding: 12px; justify-content: center; }

.sidebar-head { display:flex; align-items:center; padding:12px 14px; border-bottom:1px solid var(--border); flex-shrink:0; }
.brand-row { display:flex; align-items:center; gap:8px; flex:1; }
.brand-logo { width:32px;height:32px;border-radius:8px;background:var(--accent);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;font-size:16px; }
.brand-logo.sm { width:26px;height:26px;font-size:13px; }
.brand-title { font-weight:600; font-size:15px; }
.sidebar-search { padding:10px 12px; border-bottom:1px solid var(--border); flex-shrink:0; }
.sidebar-search input { width:100%; padding:8px 10px; border-radius:6px; border:1px solid var(--border); background:var(--bg-3); font-size:13px; }
.sidebar-tabs { display:flex; padding:0 8px; border-bottom:1px solid var(--border); flex-shrink:0; }
.tab { flex:1; padding:8px; font-size:13px; background:none; color:var(--text-3); border-bottom:2px solid transparent; }
.tab.active { color:var(--accent); border-bottom-color:var(--accent); font-weight:600; }
.user-list, .admin-panel { flex:1 1 0; min-height:0; overflow-y:auto; overflow-x:hidden; padding:4px 0; }
.admin-panel { padding:12px; display:flex; flex-direction:column; gap:10px; }
.user-row { display:flex; align-items:center; gap:10px; padding:8px 14px; cursor:pointer; }
.user-row:hover, .user-row.active { background:var(--bg-hover); }
.user-text { min-width:0; flex:1; }
.user-name { font-size:14px; font-weight:500; }
.user-last { font-size:12px; color:var(--text-3); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.user-badge { font-size:11px; padding:1px 6px; border-radius:3px; margin-left:4px; }
.user-badge.admin { background:rgba(91,141,239,0.10); color:var(--accent); }

/* ===== Avatars ===== */
.avatar { width:36px;height:36px;border-radius:50%;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:600;font-size:14px;flex-shrink:0;background-size:cover;background-position:center; }
.avatar.lg { width:56px;height:56px;font-size:22px; }

/* ===== Sidebar Footer ===== */
.sidebar-foot { padding:8px 12px; border-top:1px solid var(--border); display:flex;align-items:center;gap:8px; flex-shrink:0; }
.sidebar-foot .me-name { font-size:13px; font-weight:600; }
.sidebar-foot .me-username { font-size:11px; color:var(--text-3); }
.icon-btn { width:34px;height:34px;border-radius:8px;background:transparent;display:flex;align-items:center;justify-content:center;color:var(--text-2);font-size:16px; }
.icon-btn:hover { background:var(--bg-hover); }
.ghost-btn { padding:5px 12px;border-radius:6px;background:var(--bg-3);border:1px solid var(--border);color:var(--text-2);font-size:13px; }
.ghost-btn:hover { background:var(--bg-hover); }
.ghost-btn.del { color:#e35b5b; }
.btn-primary { padding:8px 20px;border-radius:6px;background:var(--accent);color:#fff;font-size:14px;font-weight:600; }

/* ===== Chat ===== */
.chat-head { padding:12px 18px; border-bottom:1px solid var(--border); background:var(--bg-2); display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
.chat-peer { display:flex; align-items:center; gap:12px; min-width:0; flex:1; }
.chat-peer .peer-text { min-width:0; flex:1; overflow:hidden; }
.peer-name { font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.peer-meta { font-size:12px; color:var(--text-3); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.messages { flex:1 1 0; min-height:0; overflow-y:auto; -webkit-overflow-scrolling:touch; padding:18px 22px; }
.msg { display:flex; gap:10px; max-width:84%; }
.msg + .msg { margin-top:18px; }
.msg.self { flex-direction:row-reverse; align-self:flex-end; }
.avatar-wrap { flex-shrink:0; }
.msg-body { display:flex; flex-direction:column; gap:4px; min-width:0; }
.msg-meta { font-size:12px; color:var(--text-3); padding:0 2px; }
.bubble { background:var(--bg-2); border-radius:12px; padding:10px 14px; word-break:break-word; white-space:pre-wrap; line-height:1.5; box-shadow:var(--shadow); font-size:14px; }
.msg.self .bubble { background:var(--accent); color:#fff; }

/* ===== Attachments ===== */
.attachment { display:flex; align-items:center; gap:10px; padding:10px 14px; background:var(--bg-3); border-radius:10px; border:1px solid var(--border); margin-top:4px; }
.attachment .att-icon { font-size:20px; }
.attachment .att-meta { display:flex; flex-direction:column; min-width:0; }
.attachment .att-name { font-weight:500; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:13px; }
.attachment .att-size { font-size:11px; color:var(--text-3); }
.attachment a { color:var(--accent); flex-shrink:0; font-size:13px; text-decoration:none; }
.att-image { margin-top:4px; max-width:100%; border-radius:10px; overflow:hidden; background:var(--bg-3); border:1px solid var(--border); }
.att-image img { display:block; max-width:100%;height:auto; max-height:320px; object-fit:contain; cursor:zoom-in; background:var(--bg-3); border-radius:10px 10px 0 0; }
.msg.self .att-image img { max-width:280px; }
.att-image-meta { padding:6px 10px; display:flex;align-items:center;gap:8px; border-top:1px solid var(--border); font-size:12px; }
.att-image-meta .att-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-2); }
.att-image-meta .att-size { color:var(--text-3); font-size:11px; }
.att-image-meta .att-download { color:var(--accent); text-decoration:none; font-size:12px; }

/* ===== MP3/MP4 ===== */
.att-media { margin-top:4px; max-width:100%; border-radius:10px; overflow:hidden; background:var(--bg-3); border:1px solid var(--border); }
.att-media-preview { padding:8px; display:flex; flex-direction:column; align-items:center; gap:8px; }
.att-media-icon { font-size:32px; opacity:0.7; }
.att-media audio,.att-media video { display:block; outline:none; }

/* ===== Image Lightbox ===== */
.img-lightbox { position:fixed; inset:0; z-index:300; background:rgba(0,0,0,0.92); display:flex; flex-direction:column; align-items:center; justify-content:center; padding:24px; animation:lightboxIn .2s ease-out; }
.img-lightbox img { max-width:95vw; max-height:88vh; object-fit:contain; border-radius:8px; box-shadow:0 8px 32px rgba(0,0,0,0.5); }
.img-lightbox-close { position:absolute; top:16px; right:16px; z-index:10; width:44px;height:44px;border-radius:50%; background:rgba(255,255,255,0.18); color:#fff;font-size:22px; display:flex;align-items:center;justify-content:center; cursor:pointer; transition:background .15s; border:1px solid rgba(255,255,255,0.3); }
.img-lightbox-close:hover { background:rgba(255,255,255,0.35); }
.img-lightbox-caption { margin-top:14px; color:rgba(255,255,255,0.85); font-size:13px; text-align:center; max-width:90vw; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@keyframes lightboxIn { from{opacity:0;transform:scale(0.95)} to{opacity:1;transform:scale(1)} }

/* ===== Media Player ===== */
#media-player-inner { display:flex; flex-direction:column; align-items:center; gap:16px; max-width:90vw; }
#media-player-inner video { max-width:85vw; max-height:70vh; border-radius:8px; outline:none; }
#media-player-inner audio { width:360px; max-width:80vw; height:48px; outline:none; }

/* ===== Uploader ===== */
.uploader { padding:10px 18px 6px; border-top:1px solid var(--border); background:var(--bg-2); flex-shrink:0; }
.dropzone { border:2px dashed var(--border); border-radius:10px; padding:12px; text-align:center; cursor:pointer; color:var(--text-3); font-size:13px; }
.dropzone.dragover { border-color:var(--accent); background:rgba(91,141,239,0.05); }
.upload-list { display:flex; flex-wrap:wrap; gap:12px; margin-bottom:6px; min-height:0; }
.upload-item { font-size:12px; padding:3px 8px; background:var(--bg-3); border-radius:6px; display:flex;align-items:center;gap:6px; }
.recipient-row { display:flex; align-items:center; gap:8px; margin-top:6px; font-size:13px; flex-wrap:wrap; }
#recipient-picker { display:inline-flex; align-items:center; gap:8px; }
.recipient-row select { padding:5px 10px; border-radius:6px; border:1px solid var(--border); background:var(--bg-3); font-size:13px; }

/* ==== 紧凑附件预览 ==== */
/* 容器：去掉 overflow:hidden（缩略图自身带圆角），让右上角叉子半悬外完整可见 */
.upload-chip { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; background:var(--bg-3); border-radius:8px; font-size:12px; max-width:160px; position:relative; }
.upload-chip .chip-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
/* 图片附件：缩略图自身圆角裁剪，无需容器裁剪 */
.upload-chip.is-image { padding:4px; }
.chip-thumb { width:52px; height:52px; object-fit:cover; border-radius:6px; display:block; }
/* 关闭按钮：半悬于附件右上角，白边+阴影与任何背景隔离，z-index 置顶 */
.upload-chip .x {
  position:absolute; top:-8px; right:-8px;
  width:20px; height:20px;
  background:#e35b5b; color:#fff;
  border-radius:50%;
  border:1.5px solid #fff;
  box-shadow:0 1px 4px rgba(0,0,0,.35);
  display:flex; align-items:center; justify-content:center;
  font-size:11px; line-height:1;
  padding:0; cursor:pointer; z-index:5;
}
.upload-chip .x:active { transform: scale(.92); }
#attach-actions { display:inline-flex; gap:6px; }
.confirm-btn { color:var(--accent) !important; border-color:var(--accent) !important; font-weight:600; }
.cancel-btn { color:#e35b5b !important; border-color:rgba(227,91,91,.5) !important; }


/* ===== Composer (输入框+发���按钮) ===== */
.composer {
  display: flex; align-items:stretch; gap:8px;
  padding:0 18px 12px; background:var(--bg-2);
  flex-shrink: 0;
  position: relative;   /* 供 @提及选择器定位 */
}
/* ==== @提及成员选择器 ==== */
#mention-pop {
  position: absolute; bottom: calc(100% + 6px); left: 18px;
  width: min(320px, calc(100% - 36px));
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.16);
  max-height: 230px; overflow-y: auto; z-index: 700;
  display: none; padding: 4px;
}
#mention-pop.show { display: block; }
.mention-item { display:flex; align-items:center; gap:10px; padding:7px 10px; border-radius:8px; cursor:pointer; }
.mention-item:hover, .mention-item.active { background: var(--bg-3); }
.mention-item .avatar { width:28px; height:28px; min-width:28px; font-size:11px; color:#fff; }
.mention-item .mi-text { min-width:0; }
.mention-item .mi-name { font-size:13px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.mention-item .mi-user { font-size:11px; color:var(--text-3); }
.mention-empty { padding:12px; color:var(--text-3); font-size:12px; text-align:center; }
/* @提及消息高亮 */
.msg.mentioned .bubble {
  background: rgba(91,141,239,.13);
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
/* 群列表"有人@我"闪烁徽标 */
.mention-badge {
  display:inline-block; margin-left:6px; padding:1px 7px;
  font-size:10px; line-height:1.6; color:#fff;
  background: var(--accent); border-radius:9px;
  vertical-align: 2px; white-space: nowrap;
  animation: blink 1s ease-in-out infinite;
}
/* ==== 消息右键/长按菜单 ==== */
#msg-ctx-menu {
  position: fixed; z-index: 900; display: none;
  min-width: 170px; padding: 5px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.18);
  font-size: 13px; user-select: none; -webkit-user-select: none;
}
#msg-ctx-menu.show { display: block; animation: ctxIn .12s ease-out; }
@keyframes ctxIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text); white-space: nowrap;
}
.ctx-item:hover { background: var(--bg-3); }
.ctx-item .ctx-ico { width: 18px; text-align: center; color: var(--accent); font-weight: 600; }
.ctx-item.ctx-checked { color: var(--accent); }
/* 引用消息格式（以 "> " 开头的行） */
.bubble .quote-line { color: var(--text-2); border-left: 3px solid var(--accent); background: var(--bg-3); border-radius: 4px; padding: 4px 8px; margin: 2px 0; display: block; font-size: 13px; }
/* 可跳转引用块 */
.bubble .quote-jump { cursor: pointer; transition: background .15s; }
.bubble .quote-jump:hover { background: var(--accent); color: #fff; }
/* 跳转目标消息闪烁高亮 */
@keyframes flashBg {
  0%, 100% { background: transparent; }
  30%, 70% { background: rgba(91, 141, 239, .30); }
}
.msg.flash-highlight { border-radius: 10px; animation: flashBg 1.5s ease-in-out 2; }
/* 消息内网址链接（浅/深主题独立色值，与气泡背景高对比） */
.bubble .msg-link {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  word-break: break-all;
  transition: color .15s ease;
}
.bubble .msg-link:hover,
.bubble .msg-link:focus-visible {
  color: var(--link-hover);
}
/* ===== 消息卡片（Bot 互动审批）===== */
.msg-card { background:var(--bg-3); border:1px solid var(--border); border-radius:10px; padding:10px 12px; max-width:320px; box-shadow:var(--shadow); }
.msg-card.done { opacity:.75; }
.mc-title { font-size:13px; font-weight:500; margin-bottom:4px; }
.mc-body { font-size:13px; color:var(--text-2); line-height:1.5; word-break:break-word; white-space:pre-wrap; margin-bottom:8px; }
.mc-actions { display:flex; gap:8px; }
.mc-btn { flex:1; padding:7px 0; border-radius:6px; font-size:13px; font-weight:500; }
.mc-btn.ok { background:var(--accent); color:#fff; }
.mc-btn.ok:hover { filter:brightness(1.1); }
.mc-btn.no { background:transparent; border:1px solid var(--border); color:var(--text-2); }
.mc-btn.no:hover { background:var(--bg-hover); }
.mc-btn:disabled { opacity:.6; cursor:default; }
.mc-status { display:inline-block; padding:4px 12px; border-radius:20px; font-size:12px; background:var(--bg-hover); color:var(--text-2); }
/* 自己发送的气泡为 accent 蓝底白字 → 链接用白色，避免蓝底蓝字看不清 */
.msg.self .bubble .msg-link {
  color: #fff;
  text-decoration-color: rgba(255,255,255,.75);
}
.msg.self .bubble .msg-link:hover,
.msg.self .bubble .msg-link:focus-visible {
  color: #eaf2ff;
  text-decoration-color: #eaf2ff;
}
/* 网址安全确认框 */
#link-confirm { position: fixed; inset: 0; z-index: 950; display: none; align-items: center; justify-content: center; }
#link-confirm.show { display: flex; }
#link-confirm .lc-mask { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
#link-confirm .lc-box {
  position: relative; width: min(320px, calc(100vw - 48px));
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 18px 14px;
  box-shadow: 0 10px 32px rgba(0,0,0,.22);
  animation: ctxIn .15s ease-out;
}
#link-confirm .lc-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
#link-confirm .lc-text { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
#link-confirm .lc-url {
  font-size: 12px; color: var(--accent); word-break: break-all;
  background: var(--bg-3); border-radius: 6px; padding: 6px 8px; margin-bottom: 14px;
  max-height: 64px; overflow-y: auto;
}
#link-confirm .lc-btns { display: flex; gap: 10px; justify-content: flex-end; }
#link-confirm .lc-btn { padding: 8px 16px; border-radius: 8px; font-size: 13px; cursor: pointer; border: none; }
#link-confirm .lc-cancel { background: var(--bg-3); color: var(--text-2); }
#link-confirm .lc-ok { background: var(--accent); color: #fff; }
.composer textarea {
  flex: 1; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-3); font-size: 14px; line-height: 1.5;
  resize: none; min-height: 48px; outline: none;
  font-family: inherit; color: var(--text);
}
.composer textarea::placeholder { color: var(--text-3); }
.composer button {
  padding: 0 24px; background: var(--accent); color: #fff;
  border-radius: 10px; font-weight: 600; font-size: 15px;
  white-space: nowrap; flex-shrink: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-height: 53px;
}
.composer button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Toast & Notifications ===== */
.toast { position:fixed; top:20px; right:20px; z-index:500; padding:12px 20px; border-radius:8px; font-size:14px; color:#fff; animation:toastIn .3s ease-out; pointer-events:none; }
.toast.error { background:#e35b5b; }
@keyframes toastIn { from{opacity:0;transform:translateY(-10px)} to{opacity:1;transform:translateY(0)} }
.notif-stack { position:fixed; top:20px; right:20px; z-index:400; display:flex; flex-direction:column; gap:8px; }
.notif-toast { padding:12px 16px; border-radius:8px; background:var(--bg-2); box-shadow:0 4px 16px rgba(0,0,0,0.12); font-size:13px; max-width:320px; }

/* ===== Modals ===== */
.modal { position:fixed; inset:0; z-index:200; display:flex; align-items:center; justify-content:center; }
.modal-mask { position:absolute; inset:0; background:rgba(0,0,0,0.35); }
.modal-card { position:relative; background:var(--bg-2); border-radius:12px; padding:0; width:520px; max-width:92vw; max-height:90vh; display:flex; flex-direction:column; box-shadow:0 8px 32px rgba(0,0,0,0.12); }
.modal-head { display:flex; align-items:center; justify-content:space-between; padding:16px 20px; border-bottom:1px solid var(--border); flex-shrink:0; }
.modal-title { font-weight:600; font-size:16px; }
.modal-body { padding:20px; overflow-y:auto; flex:1; min-height:0; }
.modal-foot { padding:12px 20px; border-top:1px solid var(--border); display:flex; gap:8px; justify-content:flex-end; flex-shrink:0; }

/* ===== Group Edit ===== */
/* 邀请成员列表 & 附件列表共用同款卡片式勾选列表样式 */
.member-checkbox-list, .att-list-box {
  max-height:200px; overflow-y:auto; margin-bottom:12px;
  border:1px solid var(--border); border-radius:6px;
  padding:8px 12px; background:var(--bg-3);
}
.member-checkbox-list label, .att-list-box label {
  display:flex; align-items:center; gap:8px; padding:4px 0;
  font-size:14px; cursor:pointer; min-width:0;
}
/* 附件行内信息右对齐，文件名超长省略 */
.att-list-box label .att-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; }
.att-list-box label .att-meta { color:var(--text-3); margin-left:auto; flex-shrink:0; font-size:12px; }

/* ===== Profile Modal ===== */
.profile-card { text-align:center; }
.profile-card .avatar { margin:0 auto 12px; }

/* ===== Pinned Zone ===== */
#pinned-zone {
  background:var(--bg-2); border-top:1px solid var(--border);
  border-bottom:1px solid var(--border);
  flex-shrink:0; overflow:hidden;
}
#pinned-zone.visible {
  padding-bottom: 8px;
  margin-bottom: 8px;
}
#pinned-zone .pinned-zone-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:5px 16px; font-size:12px; color:var(--text-2);
  background:var(--bg-3); border-bottom:1px solid var(--border);
}
#pinned-zone .pinned-messages {
  overflow-y:auto; padding:4px 0;
  max-height: 144px;  /* 恰好 3条消息 */
}
#pinned-zone .pinned-item {
  display:flex; align-items:center; gap:8px;
  padding:5px 16px; cursor:pointer; font-size:12px;
  transition:all .15s; border-bottom:1px solid transparent;
}
#pinned-zone .pinned-item:hover { background:var(--bg-hover); }
/* 拖拽中 */
#pinned-zone .pinned-item.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}
#pinned-zone .pinned-item.drag-over {
  border-bottom-color: var(--accent);
  background: rgba(91,141,239,0.08);
}
#pinned-zone .pinned-content { display:flex; flex-direction:column; gap:2px; flex:1; min-width:0; }
#pinned-zone .pinned-sender { font-weight:600; font-size:12px; }
#pinned-zone .pinned-text { font-size:12px; color:var(--text-2); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#pinned-zone .pinned-thumb { width:48px; height:36px; border-radius:4px; object-fit:cover; margin-top:2px; }
#pinned-zone .pinned-att-badge { font-size:11px; color:var(--text-3); background:var(--bg-3); padding:1px 6px; border-radius:3px; margin-top:2px; display:inline-block; }
#pinned-zone .pinned-drag-handle { cursor:grab; padding:0 6px; color:var(--text-3); user-select:none; font-size:14px; }
#pinned-zone .pinned-drag-handle:active { cursor:grabbing; }
#pinned-zone .pinned-unpin { padding:2px 8px; font-size:11px; border-radius:4px; background:var(--bg-3); border:1px solid var(--border); color:var(--text-3); cursor:pointer; flex-shrink:0; }
#pinned-zone .pinned-unpin:hover { color:#e35b5b; border-color:#e35b5b; }
#pinned-zone .pinned-unpin:active { background:rgba(227,91,91,0.1); }

/* 移动端：缩小置顶区 */
@media (max-width: 768px) {
  #pinned-zone .pinned-messages { max-height: 120px; }
  #pinned-zone .pinned-item { padding: 4px 10px; }
  #pinned-zone .pinned-unpin { padding: 4px 10px; font-size: 14px; }  /* 增大点击区域 */
}

/* ===== Pin Button ===== */
.msg-pin-btn {
  display:none; background:none; border:1px solid var(--border);
  border-radius:4px; padding:0 4px;
  font-size:12px; cursor:pointer; color:var(--text-3);
  vertical-align:middle; margin-left:6px;
}
.msg:hover .msg-pin-btn.is-admin { display:inline; }
.msg-pin-btn:hover { color:var(--accent); border-color:var(--accent); }
.msg-pin-btn.pinned { display:inline; color:#f0ad4e; border-color:#f0ad4e; background:rgba(240,173,78,0.1); }

/* ===== Announce Manager ===== */
.ann-item { display:flex; align-items:center; gap:10px; padding:10px 12px; border-bottom:1px solid var(--border); }
.ann-item:hover { background:var(--bg-hover); }
.ann-icon { font-size:18px; flex-shrink:0; }
.ann-content { flex:1; min-width:0; }
.ann-text { font-size:13px; color:var(--text-2); overflow:hidden; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; margin-top:2px; }
.ann-item .ann-delete { flex-shrink:0; }
.ann-thumb-wrap { margin-top:6px; }
.ann-thumb { max-width:100%; max-height:120px; border-radius:6px; cursor:zoom-in; }
.ann-file-badge { display:inline-block; margin-top:4px; padding:3px 8px; border-radius:4px; background:var(--bg-3); font-size:12px; color:var(--text-3); }

/* ===== Sidebar Toggle ===== */
.sidebar-toggle-btn { font-size:18px; margin-right:4px; }
.sidebar-show-btn { position:fixed; top:12px; left:12px; z-index:100; background:var(--bg-2); border-radius:8px; box-shadow:var(--shadow); padding:10px 14px; font-size:18px; }

/* ===== Responsive ===== */
@media (max-width:768px) {
  .app-view { grid-template-columns:1fr; position:relative; }

  /* 侧栏：默认隐藏，汉堡菜单触发展开（覆盖模式） */
  .sidebar {
    display: none;
    position: fixed; top:0; left:0; z-index: 60;
    width: 85%; max-width: 300px; height: 100%;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.show {
    display: flex;
  }

  /* 手机端汉堡菜单按钮 */
  .sidebar-toggle-btn {
    display: block;
  }

  /* 侧栏展开时显示遮罩 */
  .sidebar-backdrop {
    display: none;
    position: fixed; inset:0; z-index: 55;
    background: rgba(0,0,0,0.35);
  }
  .sidebar-backdrop.show { display: block; }

  /* 聊天区：全宽 */
  .chat { width: 100%; }

  /* 消息列表 padding 减小 */
  .messages { padding: 12px 14px; }

  /* 附件上传区缩小 */
  .uploader { padding: 8px 12px 4px; }
  .dropzone { padding: 10px; font-size: 12px; }

  /* 输入框固定在底部 */
  .composer {
    position: sticky;
    bottom: 0;
    padding: 0 12px 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
  .composer textarea { font-size: 16px; min-height: 40px; }
  .composer button { padding: 0 16px; font-size: 14px; display: flex; align-items: center; align-self: stretch; min-height: 45px; }

  /* 消息气泡满宽 */
  .msg { max-width: 92%; }
}

/* ===== Touch ===== */
@media (hover:none) {
  .icon-btn:hover,.user-row:hover,.sidebar-foot:hover { background:inherit; }
  .composer {
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }
}

/* ===== 管理面板布局修复 ===== */

.admin-panel {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  padding: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  box-sizing: border-box;
}

.admin-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.admin-section h3 { margin: 0 0 4px; font-size: 15px; }
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}
.admin-form input,
.admin-form select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
}
.admin-form input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
}

/* 显示名 + 颜色 选择行 */
.nu-display-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  width: 100%;
}
.nu-display-row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
}
.nu-display-row input[type="color"] {
  flex: 0 0 40px;
  width: 40px;
  padding: 2px;
}

/* 附件配额行 */
.nu-quota-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  font-size: 12px;
}
.nu-quota-row .quota-label { color: var(--text-2); }
.nu-quota-row .quota-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.nu-quota-row input[type="number"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text);
}
.nu-quota-row .quota-hint {
  font-size: 11px;
  color: var(--text-3);
  word-break: break-word;
  line-height: 1.4;
}

/* 权限分组复选框 */
.nu-groups-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--bg-3);
  border-radius: 6px;
  border: 1px solid var(--border);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.nu-groups-list label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-2);
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
}
.nu-groups-list label input[type="checkbox"] { margin: 0; }

/* 提交按钮 */
.admin-form button[type="submit"],
.admin-form #nu-cancel-btn {
  width: 100%;
  box-sizing: border-box;
}

/* 用户列表区 */
#admin-users, #perm-group-list, #quota-user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
#admin-users > div, #perm-group-list > div, #quota-user-list > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--bg-3);
  border-radius: 6px;
  border: 1px solid var(--border);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
#admin-users .user-name { font-weight: 600; font-size: 13px; word-break: break-all; }
#admin-users .user-username { color: var(--text-3); font-size: 12px; }
#admin-users .user-actions { display: flex; gap: 6px; margin-top: 4px; }


/* ===== 修复：头部空白 + 头像尺寸 + 置顶区分 ===== */

/* 1. 聊天头部和置顶区固定，防止空白 */
.chat-head {
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
}

/* 置顶区默认不占空间（display:none），仅在 loadPins 设为 flex */
#pinned-zone {
  display: none;
  flex-shrink: 0;
  flex-grow: 0;
}
#pinned-zone.visible {
  display: flex !important;
}

/* 2. 消息头像尺寸锁定（防止被覆盖） */
.msg .avatar {
  width: 36px !important;
  height: 36px !important;
  min-width: 36px !important;
  min-height: 36px !important;
  font-size: 14px !important;
  flex-shrink: 0 !important;
}
.msg .avatar-wrap {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* 3. 置顶条目视觉区分（蓝色左边框 + 浅背景） */
#pinned-zone .pinned-item {
  background: rgba(91,141,239,0.05);
  border-left: 3px solid var(--accent);
  padding: 6px 14px;
  margin: 0 0 2px;
  border-radius: 0 4px 4px 0;
}
#pinned-zone .pinned-item:hover {
  background: rgba(91,141,239,0.10);
}
#pinned-zone .pinned-pin-icon {
  font-size: 14px;
  flex-shrink: 0;
}

/* 4. 头部按钮间距 */
.chat-head-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* 5. 手机端补充：消息气泡宽度约束 */
@media (max-width: 768px) {
  .msg .avatar {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
  }
  .msg .avatar-wrap {
    width: 32px;
    height: 32px;
  }
}
/* ===== Grid 布局 + 收起侧栏 + 置顶区 + 移动端 ===== */

/* 主容器：Grid 双列 */
.app-view {
  display: grid !important;
  grid-template-columns: 280px 1fr !important;
  grid-template-rows: 100vh !important;
  grid-template-rows: 100dvh !important;
  height: 100vh !important;
  height: 100dvh !important;
  overflow: hidden !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Grid 子项约束：拉伸到行高 */
.sidebar {
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}
.chat {
  height: 100% !important;
  max-height: 100% !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

/* 锁死 html/body */
html, body {
  margin: 0 !important;
  padding: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  overflow: hidden !important;
}

/* 侧栏收起 */
.sidebar.collapsed {
  grid-column: 1;
  width: 60px !important;
}
.sidebar.collapsed .brand-title,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .sidebar-search input,
.sidebar.collapsed .user-name,
.sidebar.collapsed .user-last,
.sidebar.collapsed .user-text,
.sidebar.collapsed .user-badge,
.sidebar.collapsed .me-name,
.sidebar.collapsed .me-username { display: none !important; }
.sidebar.collapsed .user-row { justify-content: center; padding: 6px 0; }
.sidebar.collapsed .sidebar-head { justify-content: center; padding: 12px 6px; }
.sidebar.collapsed .sidebar-foot { justify-content: center; padding: 6px; }
.sidebar.collapsed .tab { font-size: 18px; padding: 6px 0; text-align: center; }

/* 聊天头部固定 */
.chat-head {
  flex-shrink: 0;
  flex-grow: 0;
  height: 60px;
  min-height: 60px;
}

/* 置顶区：默认隐藏 */
#pinned-zone { display: none; flex-shrink: 0; }
#pinned-zone.visible { display: flex !important; flex-direction: column; }

/* 消息区：填充剩余 */
.messages {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
}

/* 底部固定 */
#uploader { flex-shrink: 0; }
.composer { flex-shrink: 0; }

/* 移动端：侧栏覆盖模式 + 输入固定 */
@media (max-width: 768px) {
  .app-view {
    grid-template-columns: 0 1fr !important;
  }
  .app-view.show-sidebar {
    grid-template-columns: 280px 1fr !important;
  }
  .sidebar {
    display: none;
    position: fixed;
    z-index: 60;
    width: 280px;
    height: 100%;
  }
  .app-view.show-sidebar .sidebar {
    display: flex;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0,0,0,0.35);
  }
  .sidebar-backdrop.show { display: block; }
  .chat-head {
    height: 56px;
    min-height: 56px;
  }
  .composer {
    position: sticky;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
  .composer textarea { font-size: 16px; }
}

/* 触屏优化 */
@media (hover: none) {
  .composer {
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }
}


/* ===== 移动端修复 ===== */
@media (max-width: 768px) {
  .app-view {
    grid-template-columns: 0 1fr !important;
    position: relative;
  }

  /* 显示侧栏列表 */
  .app-view.mobile-show-list {
    grid-template-columns: 280px 0 !important;
  }
  .app-view.mobile-show-list .sidebar { display: flex !important; }
  .app-view.mobile-show-list .chat { display: none !important; }

  /* 显示聊天（侧栏隐藏） */
  .app-view.mobile-hidden {
    grid-template-columns: 0 1fr !important;
  }
  .app-view.mobile-hidden .sidebar { display: none !important; }
  .app-view.mobile-hidden .chat { display: flex !important; }

  /* 侧栏覆盖模式 */
  .sidebar {
    display: none;
    position: fixed;
    z-index: 60;
    width: 280px;
    height: 100%;
  }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(0,0,0,0.35);
  }
  .sidebar-backdrop.show { display: block; }

  .chat-head {
    height: 56px !important;
    min-height: 56px !important;
  }
  .composer {
    position: sticky;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
  }
  .composer textarea { font-size: 16px; }
}

/* ===== 配色统一 ===== */

/* 1. 权限分组界面 */
.nu-groups-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.nu-groups-list label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.nu-groups-list label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(91,141,239,0.08);
  color: var(--accent);
}
.nu-groups-list label:hover {
  border-color: var(--accent);
}

/* 2. 用户列表按钮统一样式 */
#admin-users .user-actions button,
#perm-group-list button,
#quota-user-list button {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
#admin-users .user-actions button:hover,
#perm-group-list button:hover,
#quota-user-list button:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
#admin-users .user-actions .user-delete-btn,
#perm-group-list .del-btn {
  color: #e35b5b;
}
#admin-users .user-actions .user-delete-btn:hover,
#perm-group-list .del-btn:hover {
  background: rgba(227,91,91,0.08);
  border-color: #e35b5b;
}

/* 3. 滚动条配色 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-3);
}

/* Firefox 滚动条 */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}


/* ===== 1. 侧栏收起优化 ===== */

/* 侧栏收起宽度调大 + 不遮挡按钮 */
.sidebar.collapsed {
  grid-column: 1;
  width: 64px !important;
  min-width: 64px !important;
}

/* 收起时保留底部用户信息区的原始布局 */
.sidebar.collapsed .sidebar-foot {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  padding: 6px 4px !important;
  border-top: 1px solid var(--border);
}
.sidebar.collapsed .sidebar-foot .avatar {
  flex-shrink: 0;
}
/* 收起时不隐藏下半部分的信息 */
.sidebar.collapsed .me-name { display: block !important; font-size: 11px; }
.sidebar.collapsed .me-username { display: block !important; font-size: 10px; }

/* 收起时隐藏文字元素 */
.sidebar.collapsed .brand-title,
.sidebar.collapsed .sidebar-search,
.sidebar.collapsed .sidebar-search input,
.sidebar.collapsed .user-name,
.sidebar.collapsed .user-last,
.sidebar.collapsed .user-text,
.sidebar.collapsed .user-badge { display: none !important; }

/* 用户列表收起只显示头像 */
.sidebar.collapsed .user-row {
  justify-content: center;
  padding: 8px 0;
}

/* 头部收起：Logo居中 + 切换按钮可见 */
.sidebar.collapsed .sidebar-head {
  justify-content: center;
  padding: 10px 0;
  flex-shrink: 0;
}
.sidebar.collapsed .sidebar-head .sidebar-toggle-btn {
  position: static;
  z-index: auto;
}
.sidebar.collapsed .brand-row { display: none; }
.sidebar.collapsed .sidebar-head .icon-btn:last-child { position: absolute; top: 8px; right: 4px; }

/* 标签只显示图标 */
.sidebar.collapsed .tab {
  font-size: 18px;
  padding: 8px 0;
  text-align: center;
}

/* ===== 2. 权限分组纵向排列 ===== */

.nu-groups-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.nu-groups-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
  box-sizing: border-box;
}
.nu-groups-list label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(91,141,239,0.08);
  color: var(--accent);
}
.nu-groups-list label:hover {
  border-color: var(--accent);
}

/* ===== 3. 用户列表行重构 ===== */

#admin-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#admin-users > div {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 6px 8px !important;
  background: var(--bg-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  min-width: 0 !important;
}
#admin-users .user-row-avatar {
  flex: 0 0 32px;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
#admin-users .user-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#admin-users .user-info .admin-user-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#admin-users .user-info .admin-user-meta {
  font-size: 11px;
  color: var(--text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#admin-users .user-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
#admin-users .user-actions button {
  padding: 3px 8px !important;
  border-radius: 5px !important;
  border: 1px solid var(--border) !important;
  background: var(--bg-3) !important;
  color: var(--text-2) !important;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}
#admin-users .user-actions button:hover {
  background: var(--bg-hover) !important;
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}
#admin-users .user-actions .admin-user-delete {
  color: #e35b5b !important;
}
#admin-users .user-actions .admin-user-delete:hover {
  background: rgba(227,91,91,0.08) !important;
  border-color: #e35b5b !important;
}

/* menu 右键菜单保持 */
#admin-users .context-menu {
  position: absolute;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  padding: 4px;
  min-width: 140px;
}
#admin-users .context-menu button {
  display: block;
  width: 100%;
  padding: 6px 12px;
  text-align: left;
  border: none;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
}
#admin-users .context-menu button:hover { background: var(--bg-hover); }


/* === 权限分组布局精修 === */

.nu-groups-list {
  display: flex !important;
  flex-direction: column !important;
  gap: 4px !important;
  padding: 6px !important;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 180px;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
}

.nu-groups-list label {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 6px 10px !important;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 复选框固定不缩放 */
.nu-groups-list label input[type="checkbox"] {
  flex-shrink: 0;
  margin: 0;
}

/* 分组名字可截断 */
.nu-groups-list label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* === 修复分组显示 === */

/* 1. 分配到权限分组：文字可见，不被截断 */
.nu-groups-list label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 8px !important;
  padding: 6px 10px !important;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text) !important;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: visible !important;
}
.nu-groups-list label input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px; height: 16px;
  margin: 0;
  cursor: pointer;
}
.nu-groups-list label > span {
  flex: 1 1 auto;
  min-width: 0;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text) !important;
}
.nu-groups-list label > span small {
  color: var(--text-3) !important;
  font-size: 11px;
  margin-left: 4px;
}
.nu-groups-list label:has(input:checked) {
  border-color: var(--accent) !important;
  background: rgba(91,141,239,0.10) !important;
  color: var(--accent) !important;
}
.nu-groups-list label:has(input:checked) > span {
  color: var(--accent) !important;
}

/* 2. 权限分组卡片：单行不换行 */
.perm-group-card {
  display: block;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 8px;
}
.perm-group-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  min-width: 0;
  flex-wrap: nowrap;
}
.perm-group-icon {
  flex: 0 0 24px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: var(--accent);
}
.perm-group-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.perm-group-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text) !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.perm-group-meta {
  font-size: 11px;
  color: var(--text-3) !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.perm-group-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.perm-action-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.perm-action-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.perm-action-btn.del:hover { color: #e35b5b; border-color: #e35b5b; }


/* === 管理面板用户列表：统一为权限分组同风格 === */

#admin-users {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#admin-users div.admin-user-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  justify-content: flex-start !important;
  gap: 8px !important;
  padding: 8px 10px !important;
  background: var(--bg-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  width: 100% !important;
  box-sizing: border-box !important;
  min-width: 0 !important;
}
#admin-users .user-row-avatar {
  flex: 0 0 28px;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 12px;
  flex-shrink: 0;
}
#admin-users .user-info {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 1px !important;
  overflow: hidden;
}
#admin-users .admin-user-name {
  font-size: 13px !important;
  font-weight: 600 !important;
  color: var(--text) !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#admin-users .admin-user-name small {
  font-weight: 400 !important;
  color: var(--text-3) !important;
  font-size: 11px !important;
}
#admin-users .admin-user-meta {
  font-size: 11px !important;
  color: var(--text-3) !important;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#admin-users .user-actions {
  flex: 0 0 auto !important;
  display: flex !important;
  gap: 4px !important;
  flex-shrink: 0 !important;
}
#admin-users .user-actions button {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-3);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  color: var(--text-2);
}
#admin-users .user-actions button:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
#admin-users .user-actions .edit::before { content: "✏️"; }
#admin-users .user-actions .admin-user-delete::before { content: "🗑"; }
#admin-users .user-actions .admin-user-delete:hover {
  color: #e35b5b;
  border-color: #e35b5b;
}


/* === 用户列表按钮：图标模式 + 放大 === */

#admin-users .user-actions button {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-3);
  font-size: 15px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
#admin-users .user-actions button:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
#admin-users .user-actions button.edit:hover { border-color: var(--accent); }
#admin-users .user-actions button.admin-user-delete:hover {
  border-color: #e35b5b;
}


/* === 按钮：仅图标 + 加大 === */
#admin-users .user-actions button {
  width: 32px; height: 32px;
  display: flex !important; align-items: center !important; justify-content: center !important;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-3);
  font-size: 14px;
  cursor: pointer;
  padding: 0 !important;
  line-height: 1;
  text-align: center;
  /* 关键：禁止 ::before 添加内容 */
  color: var(--text-2);
}
#admin-users .user-actions button::before,
#admin-users .user-actions button::after { content: none !important; }
#admin-users .user-actions button.edit:hover { border-color: var(--accent); }
#admin-users .user-actions button.admin-user-delete:hover { border-color: #e35b5b; }


/* === 移动端修复：侧栏 Drawer + 聊天全屏 === */

@media (max-width: 768px) {
  .app-view {
    grid-template-columns: 1fr !important;
    position: relative;
    overflow: hidden !important;
  }

  /* 侧栏：Drawer 模式，默认隐藏在左侧 */
  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0; left: -290px;
    z-index: 70;
    width: 280px !important;
    height: 100% !important;
    transition: left 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }
  .sidebar.open {
    left: 0;
  }

  /* 遮罩层 */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 65;
    background: rgba(0,0,0,0.4);
  }
  .sidebar-backdrop.show {
    display: block;
  }

  /* 聊天区：始终占满全屏 */
  .chat {
    display: flex !important;
    width: 100% !important;
    grid-column: 1 !important;
  }

  /* 清除旧的 grid 模式 */
  .app-view.mobile-show-list,
  .app-view.mobile-hidden {
    grid-template-columns: 1fr !important;
  }

  .chat-head {
    height: 56px !important;
    min-height: 56px !important;
  }

  .messages { padding: 12px; }
  .msg { max-width: 92%; }

  .composer {
    padding: 0 10px 8px !important;
    padding-bottom: env(safe-area-inset-bottom, 8px) !important;
  }
  .composer textarea { font-size: 16px; }
}

@media (max-width: 1024px) {
  /* 平板：侧栏可收起 */
  .app-view {
    grid-template-columns: 280px 1fr !important;
  }
  .sidebar { width: 280px !important; }
}

/* 触屏安全区 */
@media (hover: none) {
  .composer {
    padding-bottom: env(safe-area-inset-bottom, 12px);
  }
}


/* === 移动端聊天全宽修复 === */

@media (max-width: 768px) {
  .app-view {
    grid-template-columns: 1fr !important;
    position: relative;
    width: 100vw !important;
    overflow: hidden !important;
  }

  /* 侧栏：Drawer 模式，隐藏时不占 grid 空间 */
  .sidebar {
    position: fixed !important;
    top: 0; left: -290px;
    z-index: 70;
    width: 280px !important;
    height: 100% !important;
    transition: left 0.25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  }
  .sidebar.open {
    left: 0;
  }

  /* 遮罩 */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 65;
    background: rgba(0,0,0,0.4);
  }
  .sidebar-backdrop.show { display: block; }

  /* 聊天区：100vw 全宽 */
  .chat {
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    min-width: 0 !important;
    height: 100% !important;
    grid-column: 1 !important;
  }

  .chat-head {
    height: 56px !important;
    min-height: 56px !important;
  }

  .messages {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding: 12px;
  }

  .msg { max-width: 92%; }

  .uploader { padding: 8px 10px 4px !important; }

  .composer {
    flex-shrink: 0 !important;
    padding: 0 10px !important;
    padding-bottom: env(safe-area-inset-bottom, 8px) !important;
    border-top: 1px solid var(--border);
  }
  .composer textarea { font-size: 16px; }
}

@media (max-width: 1024px) {
  .sidebar { width: 280px !important; }
}

@media (hover: none) {
  .composer { padding-bottom: env(safe-area-inset-bottom, 12px) !important; }
}


/* === 未读消息角标 + 闪烁动画 === */
.unread-badge {
  display: inline-block;
  min-width: 18px; height: 18px;
  line-height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e35b5b;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  margin-left: 4px;
  vertical-align: middle;
}
.unread-badge.blink {
  animation: badgeBlink 1s ease-in-out infinite;
}
@keyframes badgeBlink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.15); }
}

/* === Toast 通知堆叠 === */
#notif-stack {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 360px;
}
.notif-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  transform: translateX(40px);
  transition: all 0.25s ease;
}
.notif-toast.show {
  opacity: 1;
  transform: translateX(0);
}
.notif-toast.hide {
  opacity: 0;
  transform: translateX(40px);
}
.notif-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 14px;
  flex-shrink: 0;
}
.notif-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
}
.notif-name {
  font-size: 13px; font-weight: 600;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.notif-close {
  font-size: 16px; color: var(--text-3); cursor: pointer;
  padding: 0 4px; flex-shrink: 0; line-height: 1;
}
.notif-close:hover { color: #e35b5b; }
.notif-text {
  font-size: 12px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 280px;
}

/* === 移动端 Toast 适配 === */
@media (max-width: 768px) {
  #notif-stack {
    top: 8px; right: 8px; left: 8px;
    max-width: none;
    gap: 6px;
  }
  .notif-toast {
    padding: 10px 12px;
    gap: 8px;
  }
  .notif-avatar {
    width: 32px; height: 32px;
    font-size: 13px;
  }
  .notif-name { font-size: 12px; }
  .notif-text {
    font-size: 11px;
    max-width: none;
  }
  .unread-badge {
    min-width: 16px; height: 16px;
    line-height: 16px;
    font-size: 10px;
  }
}


/* === 未读角标：放大 + 移至用户名末尾 === */
.unread-badge {
  display: inline-block;
  min-width: 22px; height: 22px;
  line-height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #e35b5b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  margin-left: 6px;
  vertical-align: middle;
}
.unread-badge.blink {
  animation: badgeBlink 1s ease-in-out infinite;
}

@media (max-width: 768px) {
  .unread-badge {
    min-width: 20px; height: 20px;
    line-height: 20px;
    font-size: 11px;
  }
}


/* === 修复：自己消息靠右 === */

.messages {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;  /* 默认靠左 */
}

.msg {
  display: flex !important;
  width: auto !important;          /* 宽度由内容决定 */
  max-width: 84% !important;
  min-width: 0 !important;
}

.msg.self {
  flex-direction: row-reverse !important;
  align-self: flex-end !important;  /* 靠右 */
  margin-left: auto !important;     /* 推送到右 */
}

.msg-body { min-width: 0 !important; }


/* === 消息气泡：宽度跟随内容 === */

.msg {
  display: flex !important;
  max-width: 84% !important;
  width: auto !important;          /* 由内容决定 */
  min-width: 0 !important;
}

.msg-body {
  flex: 0 1 auto !important;       /* 不拉伸，跟随内容 */
  width: auto !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

.bubble {
  display: inline-block !important;  /* 关键：随文字宽度 */
  width: auto !important;
  max-width: 100% !important;
  word-break: break-word;
}


/* === 角标移至最右 + 靠右对齐 === */
.user-row > .unread-badge {
  align-self: center;
  margin-left: auto;
  flex-shrink: 0;
}
