/* 01-msg.css（style.css 拆分片段，按顺序加载）
 * 主要类：hidden、spacer、muted、nowrap、topbar、brand、status、dot
 */
/* ============================================================
 * style.css —— 极简聊天室样式（无框架、无外部字体）
 *   支持深色模式：默认跟随系统，可用右上角按钮手动切换
 * ============================================================ */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-soft: #f2f4f7;
  --line: #e6e8ec;
  --text: #1f2329;
  --muted: #8b93a1;
  --brand: #2f6fed;
  --brand-soft: #eaf1ff;
  --brand-line: #d6e3ff;
  --warn: #b26a00;
  --danger: #d93025;
  --ok: #1a9c5b;
  --radius: 10px;
  --shadow: 0 18px 50px rgba(15, 20, 30, .22);
  --mask: rgba(20, 24, 32, .45);
  --mine: #eaf1ff;
  --mine-line: #d6e3ff;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #14171c;
  --panel: #1b1f26;
  --panel-soft: #232833;
  --line: #2c323d;
  --text: #e6e8ec;
  --muted: #8d96a5;
  --brand: #5b8dff;
  --brand-soft: #1f2b45;
  --brand-line: #2b3a5c;
  --warn: #e0a458;
  --danger: #ff6b5e;
  --ok: #47c78a;
  --shadow: 0 18px 50px rgba(0, 0, 0, .5);
  --mask: rgba(0, 0, 0, .6);
  --mine: #1f2b45;
  --mine-line: #2b3a5c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { color: var(--muted); font-weight: 400; }

.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted);
  transition: background .2s;
}
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); }

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--brand-soft);
  color: var(--brand);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.guest { background: var(--panel-soft); color: var(--muted); }
.badge.restricted { background: #fff3e0; color: var(--warn); }
html[data-theme="dark"] .badge.restricted { background: #33291a; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; display: block; }
.btn.icon { padding: 6px 9px; line-height: 1; }

/* ---------------- 布局 ---------------- */
.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;               /* 关键：让子元素内部滚动 */
}

/* ---------------- 侧栏 ---------------- */
.sidebar {
  width: 220px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.sidebar-head, .members-head {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px 8px;
  font-size: 12px;
  color: var(--muted);
}
.members-head { border-top: 1px solid var(--line); margin-top: 4px; }

.room-list, .member-list {
  list-style: none;
  margin: 0;
  padding: 0 8px;
  overflow-y: auto;
  flex: 0 1 auto;
  min-height: 0;
}
.member-list { flex: 1 1 auto; }

.room-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}
.room-list li:hover { background: var(--panel-soft); }
.room-list li.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.room-list li.locked { color: var(--muted); }
.room-list .rname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-list .rcount { font-size: 11px; color: var(--muted); }

/* 自己创建的房间：显示删除按钮 */
.room-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, color .15s, background .15s;
}
.room-list li:hover .room-del { opacity: .55; }
.room-del:hover { opacity: 1; color: #fff; background: var(--danger); }

.member {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  font-size: 13px;
  border-radius: var(--radius);
}
.member.me { background: var(--panel-soft); }
.member-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}
.member-dot.ok { background: var(--ok); }
.member-dot.warn { background: var(--warn); }
.member-dot.guest { background: var(--muted); }
.member-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-tag { font-size: 10px; color: var(--muted); }

.sidebar-foot { padding: 10px; border-top: 1px solid var(--line); flex: 0 0 auto; }

.create-bar { display: flex; gap: 6px; margin-top: 8px; }
.create-bar input { flex: 1; min-width: 0; }

.tip { font-size: 11px; color: var(--muted); margin: 10px 2px 0; line-height: 1.5; }

/* ---------------- 聊天区 ---------------- */
.chat {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.hint { font-size: 12px; color: var(--warn); }

/* 禁言 / 被踢 提示条 */
.system-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #fff3e0;
  color: var(--warn);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
html[data-theme="dark"] .system-bar { background: #33291a; }
.system-bar.danger { background: #fdecea; color: var(--danger); }
html[data-theme="dark"] .system-bar.danger { background: #3a1f1c; }

/* 成员列表里的管理按钮 */
.member-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.member:hover .member-actions { opacity: 1; }
.member-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
}
.member-btn:hover { transform: scale(1.15); }
.member.muted .member-name { text-decoration: line-through; opacity: .6; }

/* 房间列表里的锁 */
.room-list .rlock { font-size: 11px; }

/* 搜索框 */
.search-input {
  width: 120px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 999px;
}
@media (max-width: 640px) { .search-input { width: 84px; } }

/* 房间公告条 */
.announce-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: linear-gradient(90deg, var(--brand-soft), transparent);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.announce-tag {
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  flex: 0 0 auto;
}
.announce-text { flex: 1; white-space: pre-wrap; word-break: break-word; }
.announce-edit {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
}
.announce-edit:hover { color: var(--brand); }

/* 搜索命中高亮 */
.msg.search-hit { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.msg.search-dim { opacity: .35; }

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.msg {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  max-width: 76%;
  align-self: flex-start;
  word-break: break-word;
  white-space: pre-wrap;        /* 保留换行，同时不解析 HTML */
}
.msg .meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.msg .name { font-size: 12px; color: var(--brand); font-weight: 600; }
.msg .time { font-size: 11px; color: var(--muted); }
.msg .text { font-size: 14px; }
.msg.mine { align-self: flex-end; background: var(--mine); border-color: var(--mine-line); }
.msg.revoked .text { color: var(--muted); font-style: italic; }
.msg.system {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 0;
}

.revoke {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 0 2px;
  opacity: .25;
  transition: opacity .15s;
}
.msg:hover .revoke { opacity: 1; }
.revoke:hover { color: var(--danger); }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 16px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.composer input { flex: 1; }

/* 引用回复预览条 */
.quote-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--brand-soft);
  border-top: 1px solid var(--brand-line);
  font-size: 12px;
  color: var(--muted);
}
.quote-bar .quote-label { color: var(--brand); font-weight: 600; }
.quote-bar .quote-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quote-x { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }

/* 消息里的引用块 */
.msg .quote-block {
  border-left: 3px solid var(--brand-line);
  padding: 2px 8px;
  margin-bottom: 4px;
  background: var(--panel-soft);
  border-radius: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  max-height: 3.2em;
  overflow: hidden;
}
.msg .quote-block b { color: var(--brand); font-weight: 600; }

/* @提及高亮 */
.mention { color: var(--brand); font-weight: 600; }
.msg.mentioned { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand-line); }

/* ============================================================
   表情面板：贴在输入框下方展开（微信那种布局）
   —— 它不是浮层，而是占据聊天区底部的一块空间，
      显示时上面的消息区自动收缩（.chat 是纵向 flex，消息区 flex:1）
   ============================================================ */
.chat { position: relative; }        /* @候选浮层的定位基准 */

.emoji-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  height: 208px;                     /* 固定高度，布局可预测 */
  max-height: 38vh;                  /* 小屏幕上不占满 */
  background: var(--panel);
  border-top: 1px solid var(--line);
  overflow: hidden;
  animation: emoji-in .16s ease-out;
}
/* 注意：不能用 translateY(100%) —— 那会把面板整体推出容器外，
   在无头浏览器/动画被暂停时看起来就像"跑出去了"。
   用位移 8px + 透明度，既有效果又不会撑破布局。 */
@keyframes emoji-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.emoji-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
}
.emoji-close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0 3px;
}
.emoji-close:hover { color: var(--text); }

.emoji-grid {
  flex: 1 1 auto;
  min-height: 0;                     /* 关键：允许内部滚动，而不是把面板撑开 */
  display: grid;
  /* 固定 34px 单元格，列数随宽度自动增减。
     不能用 1fr —— 那样在宽屏上列会被撑到 100px+，表情稀稀拉拉散开很难看 */
  grid-template-columns: repeat(auto-fill, 34px);
  grid-auto-rows: 34px;              /* 固定行高：不加这句，grid 默认 align-content:stretch
                                        会把多余空间摊到每一行，行距被撑到 60px+ */
  justify-content: center;           /* 整组表情居中 */
  align-content: start;
  gap: 3px;
  padding: 4px 10px 10px;
  overflow-y: auto;
}