/* Trinity Chat —— 亮/深双主题，全部颜色走 token（宪法 §28） */
:root {
  --bg:        #ffffff;
  --panel:     #f6f7f9;
  --panel-2:   #eceef2;
  --line:      #dfe2e8;
  --text:      #16181d;
  --muted:     #5b6270;
  --brand:     #3d63e0;
  --brand-ink: #ffffff;
  --brand-soft:#e8edfd;
  --bubble:    #eceef2;
  --bubble-ink:#16181d;
  --danger:    #c8342b;
  --ok:        #1f8a4c;
  --shadow:    0 1px 2px rgba(16,20,30,.06), 0 8px 24px rgba(16,20,30,.08);
  --radius:    14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --panel:     #161922;
    --panel-2:   #1e2230;
    --line:      #2a3040;
    --text:      #e7e9ee;
    --muted:     #a1a8b8;
    --brand:     #5b7cff;
    --brand-ink: #0b0e16;
    --brand-soft:#1c2338;
    --bubble:    #232838;
    --bubble-ink:#e7e9ee;
    --danger:    #ff6b60;
    --ok:        #4ad07f;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* 作者样式里的 display 会盖掉 [hidden] 的 UA 规则 —— 必须显式压回去，
   否则 .reply-bar(flex) / #btn-admin(.icon-btn grid) 这类元素带着 hidden 也照样显示 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
        "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------------- 登录页 ---------------- */
.login-page { display: grid; place-items: center; padding: 24px; background: var(--panel); }
.login-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 20px;
  padding: 40px 32px; max-width: 400px; width: 100%; text-align: center; box-shadow: var(--shadow);
}
.login-logo { border-radius: 18px; }
.login-card h1 { font-size: 24px; margin: 16px 0 8px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); margin: 0 0 28px; font-size: 14px; }
.gbtn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 48px; border-radius: 12px; text-decoration: none;
  background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.gbtn:hover { filter: brightness(1.08); }
.gbtn svg { background: #fff; border-radius: 4px; padding: 2px; }
.login-foot { color: var(--muted); font-size: 12.5px; margin: 24px 0 0; line-height: 1.7; }

/* ---------------- 应用骨架 ---------------- */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }

.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head {
  display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px;
}
.side-head h2 { font-size: 16px; margin: 0; flex: 1; letter-spacing: -.01em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.search { padding: 0 14px 10px; }
.search input {
  width: 100%; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); padding: 0 12px;
}
.search input::placeholder { color: var(--muted); }

.room-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.room {
  display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 8px; border-radius: 12px; cursor: pointer; position: relative;
}
.room:hover { background: var(--panel-2); }
.room.active { background: var(--brand-soft); }
.room.drop-target { outline: 2px dashed var(--brand); outline-offset: -2px; }
.avatar {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 600; font-size: 16px; flex: none;
  overflow: hidden;
}
.avatar.group { background: var(--panel-2); color: var(--text); font-size: 20px; }
.room-main { min-width: 0; }
.room-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.room-time { color: var(--muted); font-size: 11.5px; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 11.5px; font-weight: 700;
  display: grid; place-items: center;
}
.badge.at { background: var(--danger); }
.online-dot {
  position: absolute; left: 38px; top: 40px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--panel);
}

.side-foot {
  border-top: 1px solid var(--line); padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}
.side-foot .me { min-width: 0; flex: 1; }
.side-foot .me b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .me span { color: var(--muted); font-size: 12px; }

/* ---------------- 会话区 ---------------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); min-height: 58px;
}
.chat-head .t { flex: 1; min-width: 0; }
.chat-head .t b { display: block; font-size: 15px; }
.chat-head .t span { color: var(--muted); font-size: 12.5px; }
.back-btn { display: none; }

.timeline { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 2px; }
.day-sep { align-self: center; color: var(--muted); font-size: 12px; margin: 14px 0 8px; }
.sys-msg { align-self: center; color: var(--muted); font-size: 12.5px; background: var(--panel); padding: 4px 12px; border-radius: 12px; margin: 6px 0; }

.msg { display: flex; gap: 8px; max-width: min(680px, 82%); margin-top: 8px; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.tight { margin-top: 2px; }
.msg .av { width: 32px; height: 32px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--panel-2); font-size: 13px; font-weight: 600; }
.msg.tight .av { visibility: hidden; }
.msg-body { min-width: 0; }
.msg-who { font-size: 12.5px; color: var(--muted); margin: 0 4px 3px; }
.msg.me .msg-who { text-align: right; }
.bubble {
  background: var(--bubble); color: var(--bubble-ink); padding: 8px 12px; border-radius: var(--radius);
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
}
.msg.me .bubble { background: var(--brand); color: var(--brand-ink); }
.bubble.media { padding: 4px; background: transparent; }
.msg.me .bubble.media { background: transparent; }
.bubble .mention { color: var(--brand); font-weight: 600; }
.msg.me .bubble .mention { color: var(--brand-ink); text-decoration: underline; }
.bubble.mention-me { box-shadow: inset 0 0 0 2px var(--brand); }
.bubble img, .bubble video { max-width: min(340px, 70vw); max-height: 360px; border-radius: 10px; display: block; }
.bubble .reply-quote {
  border-left: 3px solid var(--brand); padding-left: 8px; margin-bottom: 6px;
  font-size: 13px; opacity: .85; white-space: pre-wrap;
}
.msg-time { font-size: 11px; color: var(--muted); margin: 3px 4px 0; }
.msg.me .msg-time { text-align: right; }
/* 回复/撤回默认藏起来，鼠标悬停才出现，时间线才干净 */
.msg-del { color: var(--muted); font-size: 11px; margin-left: 8px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-del, .msg:focus-within .msg-del { opacity: 1; }
@media (hover: none) { .msg-del { opacity: 1; } }

.voice {
  display: flex; align-items: center; gap: 10px; min-width: 180px;
  background: var(--bubble); border-radius: var(--radius); padding: 8px 12px;
}
.msg.me .voice { background: var(--brand); color: var(--brand-ink); }
.voice button { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: rgba(127,127,127,.25); }
.voice .wave { flex: 1; height: 3px; background: currentColor; opacity: .35; border-radius: 2px; }
.voice .len { font-size: 12px; font-variant-numeric: tabular-nums; }

.typing { color: var(--muted); font-size: 12.5px; padding: 2px 18px 6px; min-height: 20px; }

/* ---------------- 输入区 ---------------- */
.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--panel);
  border-radius: 12px; padding: 10px 12px; max-height: 160px; min-height: 42px; line-height: 1.5;
}
.composer textarea:focus { outline: none; border-color: var(--brand); }
.send-btn {
  width: 42px; height: 42px; border-radius: 12px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; flex: none;
}
.send-btn[disabled] { opacity: .4; cursor: default; }
.rec-btn.recording { background: var(--danger); color: #fff; }
.reply-bar {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 10px;
  padding: 6px 10px; margin-bottom: 8px; font-size: 13px; color: var(--muted);
}
.reply-bar .q { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.pending {
  position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
  background: var(--panel-2); display: grid; place-items: center; font-size: 11px; color: var(--muted);
}
.pending img, .pending video { width: 100%; height: 100%; object-fit: cover; }
.pending .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff;
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; }

/* ---------------- 浮层 ---------------- */
.panel-pop {
  position: absolute; bottom: 62px; left: 12px; right: 12px; max-width: 380px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  z-index: 40; overflow: hidden;
}
.pop-tabs { display: flex; gap: 2px; padding: 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.pop-tabs button { padding: 6px 10px; border-radius: 8px; font-size: 17px; line-height: 1; }
.pop-tabs button.on { background: var(--brand-soft); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px;
  max-height: 280px; overflow-y: auto; padding: 8px; }
.emoji-grid button { font-size: 23px; height: 40px; border-radius: 8px; line-height: 1; }
.emoji-grid button:hover { background: var(--panel-2); }
.emoji-head { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 8px 4px 2px; font-weight: 600; }
.gif-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 300px; overflow-y: auto; padding: 8px; }
.gif-grid img { width: 100%; border-radius: 8px; cursor: pointer; display: block; background: var(--panel-2); }
.pop-search { padding: 8px; border-bottom: 1px solid var(--line); }
.pop-search input { width: 100%; height: 36px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); padding: 0 10px; }

.mention-pop {
  position: absolute; bottom: 62px; left: 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 45; min-width: 220px; max-height: 240px;
  overflow-y: auto; padding: 4px;
}
.mention-pop div { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.mention-pop div.on { background: var(--brand-soft); }

/* ---------------- 对话框 / 成员面板 ---------------- */
.mask { position: fixed; inset: 0; background: rgba(8,10,16,.5); display: grid; place-items: center;
  z-index: 60; padding: 20px; }
.dialog { background: var(--bg); border-radius: 18px; box-shadow: var(--shadow); width: min(480px, 100%);
  max-height: 82dvh; display: flex; flex-direction: column; overflow: hidden; }
.dialog h3 { margin: 0; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 16px; }
.dialog .body { padding: 14px 18px; overflow-y: auto; }
.dialog .foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.btn { padding: 9px 16px; border-radius: 10px; background: var(--panel-2); font-weight: 500; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.field { width: 100%; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); padding: 0 12px; margin-bottom: 12px; }

.people { display: flex; flex-direction: column; gap: 2px; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.person:hover { background: var(--panel-2); }
.person.picked { background: var(--brand-soft); }
.person .n { flex: 1; min-width: 0; }
.person .n b { display: block; font-size: 14px; font-weight: 600; }
.person .n span { color: var(--muted); font-size: 12px; }
.person[draggable="true"] { cursor: grab; }
.person.dragging { opacity: .4; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 90;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow);
}

.empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }

/* ---------------- 移动端 ---------------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: absolute; inset: 0; z-index: 20; }
  .app.in-room .sidebar { display: none; }
  .app:not(.in-room) .chat { display: none; }
  .back-btn { display: grid; }
  .msg { max-width: 90%; }
  .panel-pop { left: 8px; right: 8px; max-width: none; }
}
