/* ---------- 聊天 ---------- */
.chat-app {
  height: 100vh; height: 100dvh;
  padding-top: env(safe-area-inset-top);
  display: flex; flex-direction: column;
  background: var(--canvas);
}
.chat-layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}
.conv-pane {
  border-right: 1px solid var(--hairline-soft);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  background: var(--canvas);
}
.conv-search { padding: 12px; }
.conv-search input { height: 36px; }
.conv-list {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 0 8px 96px;
}
.conv {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  margin-bottom: 2px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
  transition: background .12s;
}
.conv:hover { background: var(--surface); }
.conv.is-active { background: var(--surface-card); }
.conv-avatar {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--surface-elevated);
  border: 1px solid var(--hairline-soft);
  color: var(--body);
  font-size: 14px;
}
.conv-avatar.private { color: var(--blue); background: var(--blue-soft); border-color: transparent; }
.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conv-name {
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-top time { flex: 0 0 auto; font-size: 12px; color: var(--ash); font-family: var(--mono); }
.conv-preview {
  display: block; margin-top: 2px;
  font-size: 12px; color: var(--ash);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.unread {
  min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: 9999px;
  background: var(--red); color: #ffffff;
  font-size: 12px; line-height: 1;
}
.conv-empty { padding: 24px 16px; color: var(--ash); font-size: 12px; line-height: 1.6; }

.chat-main { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--canvas); }
.chat-empty {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
}
.chat-empty h2 { font-size: 20px; font-weight: 500; color: var(--ink); margin: 12px 0 4px; }
.chat-room { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.room-head {
  height: 56px; flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--hairline-soft);
}
.chat-back { display: inline-flex; }
.room-title { min-width: 0; }
.room-title h2 {
  margin: 0; font-size: 16px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-title div { font-size: 12px; color: var(--ash); font-family: var(--mono); }
.room-admin { margin-left: auto; }

.msg-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex; flex-direction: column;
}
#bubbleList { display: flex; flex-direction: column; gap: 2px; }
.load-earlier { align-self: center; margin: 0 0 12px; }
.msg-row { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; }
.msg-row.out { justify-content: flex-end; }
.msg-avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--surface-elevated);
  border: 1px solid var(--hairline-soft);
  color: var(--body);
  font-size: 12px;
}
.msg-avatar.out { background: var(--surface-card); color: var(--green); }
.msg-body { max-width: min(68%, 560px); min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-row.out .msg-body { align-items: flex-end; }
.msg-name { font-size: 12px; color: var(--ash); padding: 0 4px; }
.bubble {
  padding: 8px 12px;
  border-radius: var(--r-lg);
  background: var(--surface-elevated);
  border: 1px solid var(--hairline-soft);
  color: var(--body);
  font-size: 14px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}
.msg-row.out .bubble {
  background: rgba(89, 212, 153, .16);
  border-color: rgba(89, 212, 153, .28);
  color: var(--ink);
}
.bubble.deleted { opacity: .5; text-decoration: line-through; }
.msg-time { font-size: 12px; color: var(--ash); font-family: var(--mono); padding: 0 4px; }
.date-sep { align-self: center; padding: 12px 0 4px; font-size: 12px; color: var(--ash); }

.attach-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--hairline-soft);
  background: var(--canvas);
}
.attach-thumb {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  border: 1px solid var(--hairline-soft);
  background: var(--surface-elevated);
  overflow: hidden;
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-thumb svg { width: 18px; height: 18px; color: var(--mute); }
.attach-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.attach-name {
  font-size: 12px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attach-size { font-size: 12px; color: var(--ash); }
.attach-btn { flex: 0 0 36px; }

.media-box {
  display: flex; align-items: center; gap: 8px;
  min-width: 160px; padding: 8px;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, .04);
}
.media-box svg { width: 20px; height: 20px; flex: 0 0 20px; color: var(--mute); }
.media-box.photo { justify-content: center; min-height: 88px; }
.media-photo {
  display: block;
  max-width: min(260px, 62vw);
  max-height: 260px;
  border-radius: var(--r-md);
  object-fit: cover;
  background: var(--surface-card);
}
.media-photo-link { display: block; }
.media-link { color: inherit; text-decoration: none; }
.media-link:hover { background: rgba(255, 255, 255, .07); }
.media-name {
  font-size: 13px; color: var(--ink);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.media-size { font-size: 12px; color: var(--ash); margin-left: auto; }
.media-caption { margin-top: 4px; font-size: 14px; }
.msg-row.out .media-box { background: rgba(0, 0, 0, .16); }

.composer {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--hairline-soft);
  background: var(--canvas);
}
.composer textarea { flex: 1; min-height: 36px; max-height: 120px; resize: none; padding: 8px 12px; line-height: 1.5; }
.composer .btn { height: 36px; }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: minmax(0, 1fr); }
  .conv-pane { border-right: 0; }
  .chat-main { display: none; }
  .chat-app.room-open .conv-pane { display: none; }
  .chat-app.room-open .chat-main { display: flex; }
  .chat-back { display: inline-flex; }
  .msg-scroll { padding: 12px; }
  .msg-body { max-width: 78%; }
  .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
