:root {
  --bg: #101318; --panel: #171b22; --panel2: #1e232c; --line: #2a303b; --text: #e8ebf0; --muted: #8b94a3;
  --accent: #35c48d; --accent-ink: #062a1c; --danger: #f0616d; --bubble: #222833; --bubble-me: #1d6b51; --bubble-me-text: #f2fff9;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f3; --panel: #ffffff; --panel2: #f5f6f8; --line: #e1e4ea; --text: #1c2129; --muted: #6b7483;
    --accent: #12996a; --accent-ink: #ffffff; --danger: #d43d4b; --bubble: #ffffff; --bubble-me: #c8f1db; --bubble-me-text: #0d2b1f;
    --shadow: 0 12px 40px rgba(20, 30, 50, .18);
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app { height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.pad { padding: 10px 16px; }
.icon { display: inline-flex; width: 22px; height: 22px; }
.icon svg { width: 100%; height: 100%; }

/* 按钮与表单 */
.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; background: var(--panel2); white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover:not(:disabled), .btn.icon-btn:hover { background: var(--panel2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.link { background: none; color: var(--accent); padding: 6px; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 10px; }
.btn.icon-btn { background: none; padding: 8px; border-radius: 50%; color: var(--muted); }
.danger-text { color: var(--danger) !important; }
.btn:focus-visible, .input:focus-visible, .item:focus-visible, .rail-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 > div { grid-column: 1 / -1; }

/* 登录页 */
.auth { height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto; }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px 20px; text-align: center; }
.auth-logo { width: 64px; height: 64px; border-radius: 16px; }
.auth-card h1 { font-size: 22px; margin: 12px 0 4px; }
.auth-form { text-align: left; margin-top: 22px; }
.notice { margin: 22px 0 10px; padding: 12px; background: var(--panel2); border-radius: 8px; }

/* 主布局 */
.app { height: 100%; display: grid; grid-template-columns: 68px 320px 1fr; }
.rail { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 0; }
.rail-me { margin-bottom: 10px; }
.rail-btn { position: relative; width: 52px; padding: 8px 0 6px; border: 0; border-radius: 10px; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rail-btn:hover { background: var(--panel2); }
.rail-btn.active { color: var(--accent); background: var(--panel2); }
.rail-label { font-size: 11px; }
.rail-btn .badge { position: absolute; top: 2px; right: 4px; }
.badge { background: var(--danger); color: #fff; font-size: 11px; font-weight: 600; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: inline-grid; place-items: center; flex-shrink: 0; }

.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 16px; }
.list-head h2 { font-size: 18px; }
.offline-bar { background: var(--danger); color: #fff; font-size: 13px; text-align: center; padding: 4px; }
.list-body { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.section { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 16px 6px; }
.section.flat { padding: 0 0 8px; }
.item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 16px; border: 0; background: none; text-align: left; }
button.item:hover { background: var(--panel2); }
.item.active { background: var(--panel2); box-shadow: inset 3px 0 var(--accent); }
.item.static { cursor: default; }
.item.check { cursor: pointer; }
.item.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.item-text { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-top strong, .item-text > strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-top time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.item-sub { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.preview { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.at-flag { color: var(--danger); font-style: normal; }
.empty { padding: 48px 24px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }

.avatar { position: relative; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 17px; flex-shrink: 0; user-select: none; }
.avatar.group { border-radius: 12px; }
.avatar.small { width: 32px; height: 32px; font-size: 14px; }
.avatar.small.group { border-radius: 9px; }
.avatar.all { background: var(--accent); color: var(--accent-ink); }
.dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); border: 2px solid var(--panel); }
.dot.on { background: #3ddc84; }
.tag { font-style: normal; font-size: 11px; font-weight: 500; margin-left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); }
.tag.plain { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.tag.red { background: var(--danger); color: #fff; }

/* 聊天区 */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.placeholder { margin: auto; text-align: center; color: var(--muted); }
.placeholder img { width: 72px; opacity: .5; filter: grayscale(.4); margin-bottom: 10px; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 58px; }
.chat-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.chat-title strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 20px; overscroll-behavior: contain; }
.sys { text-align: center; font-size: 12px; color: var(--muted); margin: 10px auto; max-width: 80%; }
.more { display: block; margin: 0 auto 8px; font-size: 13px; }
.msg { display: flex; gap: 8px; margin: 6px 0; align-items: flex-start; }
.msg.mine { justify-content: flex-end; }
.msg-body { max-width: min(70%, 560px); display: flex; flex-direction: column; align-items: flex-start; }
.msg.mine .msg-body { align-items: flex-end; }
.msg-name { font-size: 12px; color: var(--muted); margin: 0 4px 2px; }
.bubble { background: var(--bubble); border-radius: 4px 14px 14px 14px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); }
.msg.mine .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-radius: 14px 4px 14px 14px; }
.msg.mine .bubble a { color: inherit; }
.bubble.at-me { outline: 2px solid var(--accent); }
.at { font-weight: 600; color: var(--accent); }
.msg.mine .at { color: inherit; text-decoration: underline; }
.bubble.media { padding: 4px; background: var(--bubble) !important; }
.pic { display: block; max-width: min(280px, 58vw); max-height: 320px; width: auto; height: auto; border-radius: 10px; cursor: zoom-in; }
.filecard { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 200px; }
.filecard .icon { width: 30px; height: 30px; flex-shrink: 0; opacity: .8; }
.file-text { display: flex; flex-direction: column; min-width: 0; }
.file-text strong { font-weight: 600; overflow-wrap: anywhere; }
.file-text small { opacity: .7; }
.composer { position: relative; display: flex; align-items: flex-end; gap: 4px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer-input { flex: 1; resize: none; background: var(--bg); border: 1px solid var(--line); border-radius: 18px; padding: 8px 14px; max-height: 140px; margin: 0 4px; }
.composer-input:focus { outline: none; border-color: var(--accent); }
.send { border-radius: 50%; width: 40px; height: 40px; padding: 0; flex-shrink: 0; }
.at-pop { position: absolute; left: 14px; bottom: 100%; margin-bottom: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 200px; max-height: 260px; overflow-y: auto; padding: 4px; z-index: 5; }
.at-pop button { display: flex; width: 100%; align-items: center; gap: 8px; padding: 6px 8px; border: 0; background: none; border-radius: 6px; text-align: left; }
.at-pop button:hover, .at-pop button:first-child { background: var(--panel2); }

/* 页面（管理、我） */
.page { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; max-width: 860px; width: 100%; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { font-size: 15px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; }
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.table { display: flex; flex-direction: column; }
.tr { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tr:first-child { border-top: 0; }
.tr code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; letter-spacing: .5px; background: var(--panel2); padding: 2px 8px; border-radius: 6px; }
.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.profile.big { margin: 4px 0 0; }
.profile strong { font-size: 17px; }

/* 弹层 */
.modal-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: min(440px, 100%); max-height: 86dvh; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
dialog.modal { position: fixed; inset: 0; margin: auto; padding: 0; height: fit-content; max-height: min(86dvh, calc(100dvh - 32px)); color: var(--text); }
dialog.modal::backdrop { background: transparent; }
.modal header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal h3 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body .field:last-of-type { margin-bottom: 4px; }
.pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.pick-list:empty { display: none; }
.pick-list .item { padding: 8px 12px; }
.confirm-text { line-height: 1.7; }
.popmenu { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 110px; }
.popmenu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; border-radius: 6px; }
.popmenu button:hover { background: var(--panel2); }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: grid; place-items: center; z-index: 70; cursor: zoom-out; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 80; pointer-events: none; width: max-content; max-width: 90vw; }
.toast { background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 20px; font-size: 14px; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }

/* 手机 */
@media (max-width: 760px) {
  .app { display: flex; flex-direction: column-reverse; }
  .rail { flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); }
  .rail-me { display: none; }
  .rail-btn { width: 72px; }
  .rail-btn .badge { right: 14px; }
  .list { flex: 1; border-right: 0; }
  .main { display: none; position: fixed; inset: 0; z-index: 10; height: 100dvh; }
  body.main-open .main { display: flex; }
  .back { display: inline-flex; margin-left: -6px; }
  .chat-head { padding-left: 10px; }
  .msgs { padding: 12px; }
  .msg-body { max-width: 78%; }
  .grid2 { grid-template-columns: 1fr; }
  .page { padding: 14px; }
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
  .composer { padding-left: 8px; padding-right: 8px; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: pop .18s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(-6px); } }
}

/* Allow native copy/paste in editors, including the manual-copy fallback. */
.composer-input, .copy-message-text { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }

/* Member picker and a visible group-chat mention entry. */
.mention-trigger { font-size:22px; font-weight:600; }
.mention-list { display:flex; flex-direction:column; gap:6px; max-height:min(48vh,360px); overflow-y:auto; overscroll-behavior:contain; }
.mention-option { display:flex; align-items:center; gap:12px; width:100%; min-height:48px; padding:8px 12px; border:0; border-radius:12px; background:var(--panel2); color:inherit; text-align:left; cursor:pointer; }
.mention-option:hover, .mention-option:focus-visible { outline:2px solid var(--accent); outline-offset:-2px; }
.mention-name { overflow-wrap:anywhere; }
.mention-hint { margin:0; }

/* Personal avatars open chats; names in the member grid still open member details. */
.avatar-chat-button { display:inline-flex; align-items:center; justify-content:center; flex:0 0 auto; align-self:flex-start; padding:0; border:0; border-radius:50%; background:none; color:inherit; cursor:pointer; touch-action:manipulation; }
.avatar-chat-button:focus-visible { outline:2px solid var(--accent); outline-offset:3px; }
.avatar-chat-button:disabled { cursor:progress; }
.member-tile > .avatar-chat-button { align-self:center; }
.member-profile-name { max-width:100%; padding:0; border:0; background:none; color:inherit; font:inherit; font-size:12px; line-height:1.4; cursor:pointer; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.member-profile-name:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
