:root {
  --brand: #0B53D9; --brand-2: #2f6ff0; --brand-soft: #e8f0fe;
  --bg: #f3f5f8; --panel: #ffffff; --panel-2: #f7f8fa; --line: #e5e8ee;
  --text: #1c2230; --muted: #7a8394; --danger: #e5484d; --ok: #1a9e5c;
  --bubble-me: #0B53D9; --bubble-me-text: #fff; --bubble: #ffffff; --bubble-text: #1c2230;
  --chat-bg: #eef1f5; --shadow: 0 8px 30px rgba(20, 30, 60, .12);
  --rail: #0f1a33; --rail-text: #9fb0d0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: #16264a; --bg: #0f131a; --panel: #161b24; --panel-2: #1b212c; --line: #262d3a;
    --text: #e6e9ef; --muted: #8a93a5; --bubble: #222937; --bubble-text: #e6e9ef; --chat-bg: #11161e;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5); --rail: #0b0f16; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #dbe7ff 0, transparent 60%), var(--bg); }
@media (prefers-color-scheme: dark) { .auth { background: var(--bg); } }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.auth-logo img { width: 36px; height: 36px; }
.auth-sub { color: var(--muted); margin: 0 0 22px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs button { flex: 1; padding: 8px; border-radius: 8px; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); font-weight: 500; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); outline: none; transition: border-color .15s; }
.input:focus { border-color: var(--brand); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; padding: 11px; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .6; cursor: default; }
.err { color: var(--danger); min-height: 20px; font-size: 13px; margin: 4px 0 8px; }

/* ---------- 主框架 ---------- */
.app { display: grid; grid-template-columns: 64px 300px 1fr; height: 100vh; height: 100dvh; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 14px 0; gap: 6px; }
.rail .me-av { margin-bottom: 14px; cursor: pointer; }
.rail-btn { position: relative; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; color: var(--rail-text); }
.rail-btn svg { width: 24px; height: 24px; }
.rail-btn:hover { background: rgba(255,255,255,.06); color: #fff; }
.rail-btn.on { background: rgba(255,255,255,.12); color: #fff; }
.rail-btn .badge { position: absolute; top: 3px; right: 2px; }
.rail .spacer { flex: 1; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }

.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.pane-head { height: 60px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.pane-head h2 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); flex-shrink: 0; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.search { margin: 10px 12px 6px; position: relative; }
.search input { width: 100%; padding: 8px 10px 8px 32px; border-radius: 9px; border: 1px solid transparent; background: var(--panel-2); outline: none; }
.search input:focus { border-color: var(--brand); background: var(--panel); }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); }
.list { flex: 1; overflow-y: auto; padding: 4px 0; }
.item { display: flex; align-items: center; gap: 11px; padding: 10px 14px; cursor: pointer; position: relative; }
.item:hover { background: var(--panel-2); }
.item.on { background: var(--brand-soft); }
.item .meta { flex: 1; min-width: 0; }
.item .row { display: flex; align-items: center; gap: 6px; }
.item .name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.item .sub { flex: 1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { font-size: 12px; color: var(--muted); padding: 12px 14px 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.av { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; color: #fff; font-weight: 600; flex-shrink: 0; position: relative; font-size: 15px; user-select: none; }
.av.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 13px; }
.av.lg { width: 64px; height: 64px; border-radius: 16px; font-size: 24px; }
.av .dot { position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: var(--ok); border: 2px solid var(--panel); }
.av svg { width: 22px; height: 22px; }

/* ---------- 聊天区 ---------- */
.chat-pane { display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); position: relative; }
.chat-pane .pane-head { background: var(--panel); }
.chat-pane .pane-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.back-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px 8px; overscroll-behavior: contain; }
.load-more { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0 12px; }
.day { text-align: center; margin: 14px 0 10px; }
.day span, .sys span { font-size: 12px; color: var(--muted); background: rgba(127,140,160,.12); padding: 3px 10px; border-radius: 10px; }
.sys { text-align: center; margin: 10px 0; }
.msg { display: flex; gap: 9px; margin: 10px 0; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.msg .body { max-width: min(70%, 560px); display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.msg.me .body { align-items: flex-end; }
.msg .who { font-size: 12px; color: var(--muted); margin: 0 4px 3px; }
.bubble { background: var(--bubble); color: var(--bubble-text); padding: 9px 12px; border-radius: 4px 14px 14px 14px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.04); }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-radius: 14px 4px 14px 14px; }
.msg.me .bubble a { color: #fff; }
.bubble.media, .msg.me .bubble.media { padding: 0; background: transparent; box-shadow: none; overflow: hidden; border-radius: 12px; }
.bubble.media img { display: block; max-width: min(320px, 62vw); max-height: 320px; border-radius: 12px; cursor: zoom-in; background: var(--panel-2); }
.bubble.media video { display: block; max-width: min(380px, 66vw); max-height: 360px; border-radius: 12px; background: #000; }
.msg .tools { font-size: 11px; color: var(--muted); margin: 3px 4px 0; display: flex; gap: 10px; }
.msg .tools button { color: var(--muted); padding: 0; font-size: 11px; }
.msg .tools button:hover { color: var(--brand); }
.msg .recalled { font-size: 12px; color: var(--muted); font-style: italic; padding: 6px 2px; }
.file-card { display: flex; align-items: center; gap: 10px; background: var(--bubble); color: var(--bubble-text); padding: 10px 12px; border-radius: 12px; min-width: 220px; max-width: 320px; text-decoration: none; border: 1px solid var(--line); }
.file-card .ic { width: 40px; height: 40px; border-radius: 9px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; text-transform: uppercase; }
.file-card .fn { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fs { font-size: 12px; color: var(--muted); }
.file-card .fm { min-width: 0; flex: 1; }
.upload-card { background: var(--bubble); border-radius: 12px; padding: 10px 12px; min-width: 220px; max-width: 320px; border: 1px solid var(--line); }
.upload-card .fn { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.upload-card .row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.upload-card .row button { color: var(--danger); font-size: 12px; padding: 0; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; max-height: 160px; min-height: 40px; outline: none; background: var(--panel-2); line-height: 1.45; }
.composer textarea:focus { border-color: var(--brand); background: var(--panel); }
.composer .icon-btn { width: 40px; height: 40px; }
.composer .send { height: 40px; }
.drop-mask { position: absolute; inset: 0; background: rgba(11,83,217,.08); border: 2px dashed var(--brand); display: grid; place-items: center; color: var(--brand); font-size: 16px; font-weight: 600; z-index: 5; pointer-events: none; }
.welcome { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
.welcome img { width: 72px; opacity: .9; margin-bottom: 10px; }
.disabled-note { text-align: center; font-size: 13px; color: var(--muted); padding: 14px; background: var(--panel); border-top: 1px solid var(--line); }

/* ---------- 侧抽屉 / 详情 ---------- */
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 320px; max-width: 100%; background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 10; display: flex; flex-direction: column; }
.drawer .content { flex: 1; overflow-y: auto; padding: 8px 0 20px; }
.drawer .block { padding: 10px 16px; border-bottom: 1px solid var(--line); }
.drawer .block h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px 6px; }
.member { text-align: center; font-size: 12px; position: relative; }
.member .av { margin: 0 auto 4px; }
.member .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .tag { font-size: 10px; color: var(--brand); }
.member .rm { position: absolute; top: -6px; right: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; display: none; }
.member:hover .rm { display: block; }
.member.add .av { background: var(--panel-2) !important; color: var(--muted); border: 1px dashed var(--line); }
.kv { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; gap: 10px; }
.kv .v { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row { display: flex; gap: 10px; padding: 7px 0; align-items: center; font-size: 13px; text-decoration: none; color: inherit; }
.file-row .fm { flex: 1; min-width: 0; }
.file-row .fn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row .fs { font-size: 11px; color: var(--muted); }

.profile { flex: 1; display: grid; place-items: center; padding: 20px; }
.profile-card { background: var(--panel); border-radius: 16px; padding: 28px; width: 100%; max-width: 400px; box-shadow: var(--shadow); text-align: center; }
.profile-card h3 { margin: 12px 0 2px; font-size: 19px; }
.profile-card .uname { color: var(--muted); margin-bottom: 18px; }
.profile-card .actions { display: flex; gap: 10px; justify-content: center; }
.settings { flex: 1; overflow-y: auto; padding: 24px 16px; }
.settings .card { background: var(--panel); border-radius: 14px; padding: 20px; max-width: 460px; margin: 0 auto 16px; }
.settings h3 { margin: 0 0 14px; font-size: 15px; }
.req { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--panel); border-radius: 12px; margin-bottom: 10px; }
.req .meta { flex: 1; min-width: 0; }
.req .msgtxt { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.req-wrap { flex: 1; overflow-y: auto; padding: 20px 16px; max-width: 640px; width: 100%; margin: 0 auto; }

/* ---------- 弹窗 ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 16, 30, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal .mh { padding: 16px 20px 8px; font-size: 16px; font-weight: 600; display: flex; align-items: center; }
.modal .mh span { flex: 1; }
.modal .mb { padding: 8px 20px; overflow-y: auto; flex: 1; }
.modal .mf { padding: 12px 20px 18px; display: flex; gap: 10px; justify-content: flex-end; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 9px; cursor: pointer; }
.pick:hover { background: var(--panel-2); }
.pick input { width: 18px; height: 18px; accent-color: var(--brand); }
.pick.disabled { opacity: .5; cursor: default; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 60; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }
.lightbox a { position: fixed; right: 20px; bottom: 20px; color: #fff; background: rgba(255,255,255,.15); padding: 8px 14px; border-radius: 9px; text-decoration: none; }
#toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast div { background: rgba(20, 26, 40, .92); color: #fff; padding: 9px 16px; border-radius: 10px; font-size: 13px; animation: fade .2s; max-width: 90vw; }
.conn { position: absolute; top: 60px; left: 0; right: 0; text-align: center; font-size: 12px; background: #fff4d6; color: #8a6200; padding: 4px; z-index: 4; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 4px 0 calc(4px + env(safe-area-inset-bottom)); gap: 0; }
  .rail .me-av, .rail .spacer { display: none; }
  .rail-btn { width: 64px; height: 46px; }
  .list-pane { grid-row: 1; border-right: 0; }
  .chat-pane { position: fixed; inset: 0; z-index: 20; transform: translateX(100%); transition: transform .2s ease; }
  .app.show-main .chat-pane { transform: none; }
  .back-btn { display: grid; }
  .messages { padding: 12px 12px 6px; }
  .msg .body { max-width: 78%; }
  .drawer { width: 100%; }
}
