/* ============================================================
 * 05-messages.css  （475 行）
 * style.css 的拆分片段（按顺序加载，与原来完全等价）。
 *
 * 这一片主要管这些类：
 *   · .messages（27 处）
 *   · .msg（10 处）
 *   · .room-list（9 处）
 *   · .rank-no（4 处）
 *   · .chat-head（4 处）
 *   · .side-foot（4 处）
 *   · .sticker-cat-tab（3 处）
 *   · .more-panel（3 处）
 *   · .composer（3 处）
 *   · .dm-list-head（2 处）
 *   · .btn（2 处）
 *   · .coins-me（2 处）
 *   · .bg-cell（2 处）
 *   · .more-cell（2 处）
 *   · .mini-btn（2 处）
 *   · .msg-act（2 处）
 *   · .hint（2 处）
 *   · .search-input（2 处）
 * ============================================================ */
.modal-x:hover { background: var(--panel-soft); color: var(--text); }

/* 私聊列表页标题行 */
.dm-list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dm-list-head h3 { margin: 0; }

/* 图标按钮的"忙"状态：转圈遮罩，不覆盖图标 */
.btn.icon.busy { position: relative; opacity: .6; pointer-events: none; }
.btn.icon.busy::after {
  content: ''; position: absolute; inset: 8px;
  border: 2px solid var(--brand-line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin .8s linear infinite;
}

/* ==================== 瓜子 ==================== */
.coins-me {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 10px;
  background: var(--brand-soft); border-radius: 10px; font-size: 14px;
}
.coins-me b { color: var(--brand); font-size: 17px; }
.rank-row { gap: 8px; }
.rank-no {
  width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--muted); background: var(--panel-soft);
}
.rank-no.top1 { background: #ffd700; color: #7a5c00; }
.rank-no.top2 { background: #d8d8d8; color: #555; }
.rank-no.top3 { background: #e2a76f; color: #5c3a17; }
.rank-coins { font-size: 13px; color: var(--brand); font-weight: 600; white-space: nowrap; }
.card-stats { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

/* 自定义背景槽 */
.bg-cell.bg-custom {
  background: var(--panel-soft) center/cover no-repeat;
  color: var(--text); font-weight: 500;
}
.bg-cell.bg-custom.active { border-color: var(--brand); }

/* ==================== 表情包分类 ==================== */
.sticker-cats {
  display: flex; gap: 4px; overflow-x: auto; padding: 6px 0 2px;
  border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.sticker-cat-tab {
  border: 1px solid var(--line); background: var(--panel-soft);
  color: var(--muted); border-radius: 999px; padding: 3px 10px;
  font-size: 12px; cursor: pointer; white-space: nowrap;
}
.sticker-cat-tab:hover { border-color: var(--brand); color: var(--brand); }
.sticker-cat-tab.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* ==================== 资料：多行签名 + 生日 ==================== */
#profile-bio {
  width: 100%; min-height: 72px; max-height: 200px;
  border-radius: 10px; padding: 10px 12px;
  border: 1px solid var(--line); background: var(--panel-soft);
  color: var(--text); font-size: 14px; font-family: inherit;
  line-height: 1.6; resize: vertical; overflow-y: auto;
}
#profile-bio:focus { outline: none; border-color: var(--brand); background: var(--panel); }
#profile-birthday { width: 100%; border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); background: var(--panel-soft); color: var(--text); font-size: 14px; }
#profile-birthday:focus { outline: none; border-color: var(--brand); }
.card-extra { margin: 6px 0 0; font-size: 12.5px; color: var(--brand); font-weight: 500; }

/* ============================================================
 * 界面优化 v4 —— 解决"一排小图标 + 侧栏堆按钮"的别扭感
 * ============================================================ */

/* 图标统一：粗细和大小更清楚 */
.ico { stroke-width: 1.85; }

/* 聊天区标题栏：按钮少而大，间距拉开 */
.chat-head { gap: 8px; }
.chat-head .head-btn {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent;
  color: var(--muted); cursor: pointer; transition: background .14s, color .14s, border-color .14s;
}
.chat-head .head-btn:hover { background: var(--panel-soft); color: var(--text); }
.chat-head .head-btn.has-new { color: var(--brand); background: var(--brand-soft); border-color: var(--brand-line); }
#btn-more { font-size: 20px; font-weight: 600; letter-spacing: 1px; line-height: 1; }

/* 「更多」面板：九宫格 + 文字标签 */
.more-panel {
  position: absolute; right: 14px; top: 56px; z-index: 40;
  width: 300px; padding: 14px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 10px 34px rgba(0,0,0,.13);
}
.more-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 6px; }
.more-slot { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.more-cell {
  width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--panel-soft);
  color: var(--text); cursor: pointer; position: relative;
  transition: background .14s, border-color .14s, transform .1s;
}
.more-cell:hover { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); transform: translateY(-1px); }
.more-label { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.more-badge {
  position: absolute; top: -5px; right: -5px;
  background: #fa5151; color: #fff; font-size: 10px; line-height: 15px;
  min-width: 15px; height: 15px; border-radius: 999px; padding: 0 4px; text-align: center;
}
.more-panel .rbadge, .more-panel #dm-count, .more-panel #mentions-count {
  position: absolute; top: -5px; right: -5px; margin: 0;
}
.more-panel .ico { display: block; }

/* 侧栏底部：一行小按钮，不再堆四大块 */
.side-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; }
.side-foot .btn.block { flex: 1 1 100%; }        /* 新建房间占满一行 */
.mini-btn {
  flex: 1; min-width: 0;
  padding: 7px 4px; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel-soft); color: var(--text); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mini-btn:hover { border-color: var(--brand); color: var(--brand); }
.support-link { margin: 6px 10px 10px; padding: 6px 10px; font-size: 12px; }
#guest-tip { margin: 0 10px 10px; font-size: 11.5px; line-height: 1.55; }

/* 消息区：更舒服的行距与气泡 */
.messages { padding: 18px 20px 12px; }
.msg { margin-bottom: 14px; gap: 10px; }
.msg .avatar, .msg .avatar-wrap { width: 38px; height: 38px; flex: 0 0 38px; font-size: 15px; }
.msg .text {
  border-radius: 10px; padding: 9px 13px;
  font-size: 14.5px; line-height: 1.62; max-width: 62%;
}
.msg .meta { margin-bottom: 4px; }
.msg .name { font-size: 12.5px; }
.msg .time { font-size: 11px; opacity: .75; }
.msg.system { justify-content: center; margin: 10px 0 16px; }
.msg.system .text { background: rgba(0,0,0,.045); font-size: 12px; padding: 4px 10px; border-radius: 999px; }
html[data-theme="dark"] .msg.system .text { background: rgba(255,255,255,.07); }

/* 顶栏 */
.topbar { padding: 0 16px; height: 52px; }

/* 侧栏 */
.sidebar { padding-top: 4px; }
.members-head { padding: 8px 12px 6px; font-size: 12.5px; }

/* 输入区 */
.composer { padding: 9px 12px; gap: 6px; }
.composer .btn.icon { width: 36px; height: 36px; border-radius: 10px; }
#input-msg { font-size: 14.5px; padding: 10px 14px; }

/* ============================================================
 * 界面优化 v4（续）
 * ============================================================ */
/* 系统消息一行显示，不再被挤成两行 */
.msg.system .text { white-space: nowrap; max-width: 80%; }

/* 消息悬停操作：统一样式，别抢戏 */
.msg-actions { display: inline-flex; gap: 4px; margin-left: 6px; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-act {
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); font-size: 11.5px; line-height: 1;
  padding: 4px 7px; border-radius: 7px; cursor: pointer;
  transition: color .12s, border-color .12s;
}
.msg-act:hover { color: var(--brand); border-color: var(--brand-line); }

/* 配额提示不要抢视觉 */
#rate-hint { font-size: 11.5px; }

/* 输入区里的图标按钮统一 36x36、圆角一致 */
.composer .btn.icon { flex: 0 0 36px; }

.side-foot .btn.block {
  font-weight: 600; padding: 9px 12px; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); border: 1px solid var(--brand-line);
}
.side-foot .btn.block:hover { background: var(--brand); color: #fff; }

/* 隐藏的工具提示不占位 */
.hint.hidden { display: none; }
/* 搜索框：平时低调，聚焦时明显 */
.search-input { transition: box-shadow .15s, border-color .15s, width .15s; }
.search-input:focus { box-shadow: 0 0 0 3px var(--brand-soft); }

/* ============================================================
 * 专注聊天模式（iirose 那种"只有聊天"的范式）
 * ============================================================ */
body.zen .topbar,
body.zen .sidebar,
body.zen .announce-bar,
body.zen .notice-bar,
body.zen .pinned-bar,
body.zen .quote-bar { display: none !important; }

body.zen .layout {
  grid-template-columns: 1fr !important;
  max-width: 900px; margin: 0 auto;
  padding: 0 12px;
}
body.zen .chat-pane { background: var(--bg); }

/* 顶部只剩一行极简信息 */
.zen-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.zen-room { font-weight: 600; font-size: 14px; }
.zen-online { font-size: 12px; color: var(--muted); }
.zen-exit {
  margin-left: auto; border: 1px solid var(--line); background: var(--panel-soft);
  color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 999px; cursor: pointer;
}
.zen-exit:hover { color: var(--brand); border-color: var(--brand-line); background: var(--brand-soft); }

/* 聊天标题栏在专注模式下只留搜索（且低调） */
body.zen .chat-head { background: transparent; border-bottom: none; padding: 8px 4px 4px; }
body.zen .chat-head strong { font-size: 15px; color: var(--muted); font-weight: 500; }
body.zen #room-online { display: none; }
body.zen .search-input { width: 170px; background: transparent; border-color: transparent; }
body.zen .search-input:focus { background: var(--panel-soft); border-color: var(--brand-line); }

/* 消息流：更松的行距、居中窄栏、没有多余边框 */
body.zen { padding-top: 42px; }
body.zen .messages { background: transparent !important; padding: 12px 0 8px; }
body.zen .msg { margin-bottom: 18px; }
body.zen .msg .text { max-width: 72%; font-size: 15px; line-height: 1.75; }
body.zen .msg .meta { opacity: .8; }
body.zen .msg.system { margin: 14px 0 20px; }

/* 输入区：悬浮在底部，居中 */
body.zen .composer {
  max-width: 900px; margin: 0 auto; width: 100%;
  border-top: none; background: transparent; padding: 10px 0 16px;
}
body.zen #input-msg {
  background: var(--panel); box-shadow: 0 2px 14px rgba(0,0,0,.06);
  border-color: var(--line);
}

/* 配额提示平时彻底不出现 */
#rate-hint:empty { display: none; }
.hint:empty { display: none; }

/* ============================================================
 * 专注模式 v2：一屏只有聊天
 * ============================================================ */
body.zen .chat-head { display: none; }          /* 房间名已经在顶部细条里了，不用重复 */

body.zen { padding-top: 46px; }
body.zen .messages {
  padding: 4px 0 6px;
  flex: 1 1 auto;
}
/* 消息列与输入框对齐：同一条窄栏 */
body.zen .messages > * { max-width: 860px; }

body.zen .composer {
  position: sticky; bottom: 0;
  max-width: 860px; margin: 0 auto; width: 100%;
  padding: 10px 0 18px;
  gap: 8px;
}
body.zen .composer .btn.icon { flex: 0 0 36px; }
body.zen #input-msg { flex: 1 1 auto; min-width: 0; }

/* 专注模式下消息更松弛，气泡不贴边 */
body.zen .msg { padding: 0 4px; }
body.zen .msg .text { border-radius: 12px; }

/* 顶部细条：半透明毛玻璃，滚动时始终可见 */
#zen-bar { box-shadow: 0 1px 0 rgba(0,0,0,.03); }

/* 输入框在专注模式下必须撑开 */
body.zen .composer { display: flex; align-items: center; justify-content: center; }
body.zen #input-msg { flex: 1 1 auto !important; width: auto !important; min-width: 0 !important; }

/* 专注模式：强制输入区占满整行（父容器居中导致的窄条） */
body.zen .chat-pane { display: flex; flex-direction: column; align-items: stretch; }
body.zen .composer { align-self: stretch; width: 100% !important; max-width: 860px; margin: 0 auto; }
body.zen .messages { align-self: stretch; }

/* 专注模式最终版：底部悬浮输入栏（用 fixed 绕开父容器的宽度限制） */
body.zen .composer {
  position: fixed !important;
  left: 0 !important; right: 0 !important; bottom: 0 !important;
  max-width: none !important; width: 100% !important;
  margin: 0 !important;
  padding: 10px max(16px, calc((100vw - 860px) / 2)) 16px !important;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--panel) 93%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 55;
}
body.zen .messages { padding-bottom: 96px !important; }
body.zen #input-msg { flex: 1 1 auto !important; width: auto !important; min-width: 0 !important; }

/* ============================================================
 * 房间项 · 最终版（flex 嵌套，不依赖 grid 自动排版）
 * 覆盖前面几层的 grid 写法：靠后 + 更具体的选择器
 * ============================================================ */
.room-list .room-item {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  padding: 9px 10px !important;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
}
.room-list .room-item .room-main {
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.room-list .room-item .room-line1 {
  display: flex; align-items: baseline; gap: 8px; min-width: 0;
}
.room-list .room-item .rname {
  flex: 1 1 auto; min-width: 0;
  font-size: 14px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  grid-column: auto !important;
}
.room-list .room-item .rtime {
  flex: 0 0 auto; font-size: 11px; color: var(--muted);
}
.room-list .room-item .rpreview {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  grid-column: auto !important;
}
.room-list .room-item .rbadge {
  flex: 0 0 auto;
  background: #fa5151; color: #fff; font-size: 10.5px;
  min-width: 17px; height: 17px; line-height: 17px; text-align: center;
  border-radius: 999px; padding: 0 5px; font-weight: 600;
}
.room-list .room-item .rbadge.hidden { display: none; }
.room-list .room-item .rright { grid-column: auto !important; }

/* ============================================================
 * 消息布局 · 最终修正
 * 明确指定网格位置，避免自动排版把气泡塞到头像下面
 *
 * 布局： [头像] [用户名 时间]
 *                 [ 气泡文字 ]
 * 自己的消息左右镜像
 * ============================================================ */
.messages .msg {
  /* 消息行本身是透明的容器，白底属于气泡 */
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  max-width: 100% !important;
  margin: 0 0 14px 0 !important;

  display: grid !important;
  grid-template-columns: 38px minmax(0, 1fr) !important;
  column-gap: 10px;
  row-gap: 4px;
  align-items: start;
}
/* 头像：占第 1 列，跨两行 */
.messages .msg > .avatar,
.messages .msg > .avatar-wrap {
  grid-column: 1 !important;
  grid-row: 1 / span 3 !important;
  align-self: start;
  width: 38px; height: 38px;
}
/* 用户名 + 时间：第 2 列第 1 行 */
.messages .msg > .meta {
  grid-column: 2 !important;
  grid-row: 1 !important;
  display: flex; align-items: baseline; gap: 8px;
  margin: 0 !important;
}
/* 气泡：第 2 列第 2 行 */
.messages .msg > .text {
  grid-column: 2 !important;
  grid-row: 2 !important;
  justify-self: start;
  max-width: 100% !important;
  width: fit-content;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 13px;
  font-size: 14.5px; line-height: 1.62;
  word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
/* 图片/语音/沙币等附加内容跟着气泡列 */
.messages .msg > audio,
.messages .msg > img,
.messages .msg > .msg-img,
.messages .msg > .packet,
.messages .msg > .reactions {
  grid-column: 2 !important;
  justify-self: start;
}
.messages .msg > .reactions { grid-row: auto; }

/* 自己的消息：镜像（头像靠右、内容靠右） */
.messages .msg.mine {
  grid-template-columns: minmax(0, 1fr) 38px !important;
}
.messages .msg.mine > .avatar,
.messages .msg.mine > .avatar-wrap { grid-column: 2 !important; }
.messages .msg.mine > .meta {
  grid-column: 1 !important;
  justify-content: flex-end;
}
.messages .msg.mine > .text {
  grid-column: 1 !important;
  justify-self: end;
  background: var(--mine);
  border-color: var(--brand-line);
  color: #14300f;
}
html[data-theme="dark"] .messages .msg.mine > .text { color: #eafce2; }

/* 系统消息：居中的灰色胶囊，不受上面的网格影响 */
.messages .msg.system {
  display: flex !important;
  justify-content: center;
  background: transparent !important;
  border: none !important;
}
.messages .msg.system > .text {
  background: rgba(0, 0, 0, .045) !important;
  border: none !important;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  max-width: 84%;
  white-space: nowrap;
  box-shadow: none;
}
html[data-theme="dark"] .messages .msg.system > .text { background: rgba(255,255,255,.08) !important; }

/* 被 @ 的消息：左侧一道绿线，不整块高亮 */
.messages .msg.mentioned > .text {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}

/* 连续同一个人发言：不重复显示头像和用户名 */
.messages .msg.bunched > .meta { display: none; }
.messages .msg.bunched > .avatar,
.messages .msg.bunched > .avatar-wrap { visibility: hidden; }
.messages .msg.bunched { margin-top: -8px !important; }

/* 表情回应：没有回应时不占位，鼠标悬停才出现"加回应"入口 */
.messages .msg > .reactions {
  margin: 0 !important;
  opacity: 0; height: 0; overflow: hidden;
  transition: opacity .14s;
}
.messages .msg:hover > .reactions {
  opacity: 1; height: auto; overflow: visible; margin-top: 3px !important;
}
/* 已经有回应的消息：常驻显示 */
.messages .msg > .reactions:has(.rx-chip) {
  opacity: 1; height: auto; overflow: visible; margin-top: 3px !important;
}