/* X-DUCK 交流室样式
   ============================================================
   颜色一律取自 `account.css` 的 token（--bg / --surface / --brand / --border…），
   本文件只写版式。这样账号中心、社区、交流室是同一套视觉语言，
   换主题时三页一起变，不会出现"点进来像换了家公司"。

   版式：顶栏 44 + 消息流（占满剩余高度）+ 输入区（固定底部）。
   消息流自己滚动，页面本身**不滚** —— 聊天室滚整页是最常见的实现错误，
   一滚输入框就跑了。
   ============================================================ */

.ch-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* 手机浏览器地址栏收起/展开时不抖 */
  min-height: 420px;
  background: var(--bg);
}

/* ------------------------------------------------------------------ 顶栏 */
.ch-top {
  flex: 0 0 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.ch-crumb {
  font-size: 12px;
  color: var(--muted);
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.ch-presence {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
}

.ch-presence b {
  color: var(--fg-strong);
  font-variant-numeric: tabular-nums;
}

.ch-presence .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.16);
}

.ch-nav {
  margin-left: auto;
  display: flex;
  gap: 14px;
}

.ch-link {
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
}

.ch-link:hover {
  color: var(--brand);
}

.ch-me {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--fg);
  max-width: 180px;
}

.ch-me b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

/* ------------------------------------------------------------------ 提示条 */
.ch-banner {
  margin: 0;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--warning);
  background: rgba(210, 153, 34, 0.1);
  border-bottom: 1px solid var(--border);
}

.ch-banner.bad {
  color: var(--danger);
  background: rgba(242, 54, 69, 0.1);
}

/* ------------------------------------------------------------------ 消息流 */
.ch-main {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.ch-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px clamp(12px, 3vw, 32px) 8px;
  scrollbar-width: thin;
}

.ch-loading,
.ch-empty {
  padding: 48px 0;
  text-align: center;
  color: var(--muted-2);
  font-size: 12.5px;
}

.ch-day {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 12px;
  color: var(--muted-2);
  font-size: 11px;
}

.ch-day::before,
.ch-day::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* 一条消息：头像 + 气泡。自己发的整行右对齐并镜像顺序。 */
.ch-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: flex-start;
}

.ch-msg.mine {
  flex-direction: row-reverse;
}

.ch-msg .avatar {
  width: 30px;
  height: 30px;
  font-size: 11px;
  flex: 0 0 auto;
  margin-top: 2px;
}

.ch-body {
  min-width: 0;
  max-width: min(78%, 620px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ch-msg.mine .ch-body {
  align-items: flex-end;
}

.ch-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  color: var(--muted-2);
}

.ch-meta b {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
}

.ch-msg.mine .ch-meta {
  flex-direction: row-reverse;
}

.ch-bubble {
  padding: 8px 12px;
  border-radius: 12px;
  border-top-left-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.ch-msg.mine .ch-bubble {
  border-top-left-radius: 12px;
  border-top-right-radius: 4px;
  background: var(--brand-soft);
  border-color: rgba(242, 169, 59, 0.34);
  color: var(--fg-strong);
}

/* 只有图没有文字时，气泡退化成"边框"：图片自己撑形状 */
.ch-bubble.media {
  padding: 4px;
  background: var(--surface-2);
}

.ch-bubble img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  cursor: zoom-in;
}

.ch-bubble .cap {
  padding: 6px 8px 2px;
  font-size: 12.5px;
}

.ch-jump {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  height: 28px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--fg);
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  z-index: 5;
}

.ch-jump:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* ------------------------------------------------------------------ 输入区 */
.ch-composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px clamp(10px, 3vw, 28px) 12px;
}

.ch-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}

.ch-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.ch-tool:hover,
.ch-tool.on {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: rgba(242, 169, 59, 0.28);
}

.ch-hint {
  margin-left: 6px;
  color: var(--muted-2);
  font-size: 11px;
}

.ch-count {
  margin-left: auto;
  color: var(--muted-2);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.ch-count.over {
  color: var(--danger);
}

/* 表情面板：贴在工具条下方，四列滚动的网格 */
.ch-emoji {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
  max-height: 168px;
  overflow-y: auto;
  padding: 6px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.ch-emoji button {
  height: 32px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.ch-emoji button:hover {
  background: var(--surface-3);
}

.ch-attach {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.ch-attach img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--surface-3);
}

.ch-attach-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
}

.ch-attach-meta b {
  color: var(--fg);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ch-attach-x {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.ch-attach-x:hover {
  background: var(--surface-3);
  color: var(--danger);
}

.ch-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.ch-input-row textarea {
  flex: 1;
  min-height: 38px;
  max-height: 132px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

.ch-input-row textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}

.ch-send {
  flex: 0 0 auto;
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ch-send:hover:not(:disabled) {
  background: var(--brand-hover);
}

.ch-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ------------------------------------------------------------------ 看图 */
.ch-lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(6, 8, 14, 0.86);
  cursor: zoom-out;
}

.ch-lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* ------------------------------------------------------------------ 窄屏 */
@media (max-width: 720px) {
  .ch-nav,
  .ch-hint {
    display: none;
  }

  .ch-me {
    max-width: 120px;
  }

  .ch-body {
    max-width: 84%;
  }

  .ch-bubble img {
    max-height: 240px;
  }
}
