/* ============================================================================
 * 组件（Components）
 * 只引用 tokens.css 的变量，不出现具体色值（语义色除外）。
 * ==========================================================================*/

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }

/* ---------- 复位 ---------- */
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; background: none; border: 0; outline: none; }
ul { margin: 0; padding: 0; list-style: none; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible { outline: 2px solid var(--c-brand); outline-offset: 1px; }

/* ==========================================================================
 * 图标栏
 * ========================================================================*/
.rail__me {
  position: relative;
  width: 34px; height: 34px;
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600; color: #fff;
}
.rail__badge {
  position: absolute; top: -5px; right: -5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  background: var(--c-danger); color: #fff;
  font-size: 10px; font-weight: 600; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px var(--bg-rail);
  display: none;
}
.rail__badge.is-on { display: block; }

.rail__spacer { flex: 1; }

.rail-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  color: var(--fg-on-rail);
  transition: color .12s, background .12s;
}
.rail-btn svg { width: 21px; height: 21px; }
.rail-btn:hover { color: var(--fg-on-rail-hover); background: #3f3f3f; }
.rail-btn.is-active { color: var(--c-brand); }

/* ==========================================================================
 * 列表（房间 / 成员 / 状态 / 设置）
 * ========================================================================*/
.panel-head {
  flex: none; height: var(--head-h);
  display: flex; align-items: center; gap: 6px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
}

.search {
  flex: 1; min-width: 0; height: 28px;
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  color: var(--fg-faint);
}
.search input { flex: 1; min-width: 0; font-size: var(--fs-sm); }
.search input::placeholder { color: var(--fg-faint); }

.icon-btn {
  flex: none;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: var(--fg-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }

/* 房间行 */
.row {
  display: flex; gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background .1s;
}
.row:hover { background: var(--bg-hover); }
.row.is-active { background: var(--bg-active); }
.row.is-active:hover { background: var(--bg-active-hover); }

.row__meta { flex: 1; min-width: 0; }
.row__line1 { display: flex; align-items: baseline; gap: 6px; }
.row__name {
  flex: 1; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row__time { flex: none; font-size: var(--fs-xs); color: var(--fg-faint); }
.row__line2 { display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.row__preview {
  flex: 1; font-size: var(--fs-sm); color: var(--fg-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  flex: none; min-width: 17px; height: 17px; padding: 0 5px;
  border-radius: 9px;
  background: var(--c-danger); color: #fff;
  font-size: 10.5px; font-weight: 600; line-height: 17px; text-align: center;
}

/* 头像色块 */
.avatar {
  flex: none;
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  font-size: 15px; font-weight: 600; color: #fff;
  user-select: none;
}
.avatar--sm { width: 34px; height: 34px; font-size: 13px; }

/* 成员行 */
.peer { display: flex; gap: 10px; align-items: center; padding: 8px 12px; }
.peer:hover { background: var(--bg-hover); }
.peer__body { flex: 1; min-width: 0; }
.peer__name {
  display: block; font-size: var(--fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.peer__sub {
  font-size: var(--fs-xs); color: var(--fg-faint);
  font-family: ui-monospace, Menlo, monospace;
}

/* 键值行 / 设置行 */
.kv {
  display: flex; gap: 10px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.kv__k { flex: none; width: 66px; color: var(--fg-faint); }
.kv__v { flex: 1; min-width: 0; word-break: break-all; }
.kv__v.is-ok { color: #3fae74; }
.kv__v.is-bad { color: #e05a52; }

.set-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-md);
  cursor: pointer;
}
.set-row:hover { background: var(--bg-hover); }
.set-row__label { flex: 1; }
.set-row__value { font-size: var(--fs-sm); color: var(--fg-faint); }

.section-title {
  padding: 14px 14px 6px;
  font-size: var(--fs-xs);
  color: var(--fg-faint);
  letter-spacing: .04em;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  font-size: var(--fs-sm);
  line-height: 1.9;
  color: var(--fg-faint);
}

/* ==========================================================================
 * 对话头部
 * ========================================================================*/
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  background: var(--bg-head);
  border-bottom: 1px solid var(--line-strong);
}
.chat-head__title { font-size: var(--fs-lg); cursor: pointer; }
.chat-head__spacer { flex: 1; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-hover);
  color: var(--fg-dim);
  font-size: var(--fs-xs);
}
.pill__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-faint); }
.pill.is-ok { color: #3fae74; }
.pill.is-ok .pill__dot { background: var(--c-brand); }
.pill.is-bad { color: #e05a52; }
.pill.is-bad .pill__dot { background: var(--c-danger); }

/* ==========================================================================
 * 消息时间线
 * ========================================================================*/
.timeline-inner {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 20px 8px;
}

.tl-hint { text-align: center; font-size: var(--fs-sm); color: var(--fg-faint); }
.tl-day { text-align: center; font-size: var(--fs-sm); color: var(--fg-faint); margin: 6px 0 2px; }
.tl-note { text-align: center; font-size: var(--fs-sm); color: var(--fg-faint); }

/* 新消息分隔 */
.tl-unread-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--c-danger); font-size: var(--fs-xs);
}
.tl-unread-divider::before,
.tl-unread-divider::after { content: ''; flex: 1; height: 1px; background: var(--c-danger); opacity: .5; }

/* 消息 */
.msg { display: flex; gap: 10px; max-width: 76%; align-items: flex-start; }
.msg__body { min-width: 0; }
.msg__meta { margin-bottom: 4px; padding-left: 2px; font-size: 12px; color: var(--fg-faint); }
.bubble {
  display: inline-block;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-bubble);
  font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}

.msg--me { align-self: flex-end; flex-direction: row-reverse; }
.msg--me .msg__meta { padding-left: 0; padding-right: 2px; text-align: right; }
.msg--me .bubble { background: var(--bg-bubble-me); color: var(--text-on-bubble-me); }
.msg--hist .bubble { opacity: .85; }
.msg--failed .bubble { background: #5a2b2b; color: #fff; }

.bubble img { display: block; max-width: 260px; max-height: 240px; border-radius: var(--radius-sm); cursor: zoom-in; }

/* 回到最新 */
.jump-btn {
  position: absolute; right: 26px; bottom: 152px;
  z-index: 5;
  padding: 5px 12px;
  border-radius: 16px;
  background: var(--bg-card);
  color: var(--fg);
  font-size: var(--fs-sm);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .25);
  display: none;
}
.jump-btn.is-on { display: block; }

/* ==========================================================================
 * 输入区
 * ========================================================================*/
.composer {
  position: relative;
  padding: 0 20px 14px;
  border-top: 1px solid var(--line-strong);
}

.composer__box {
  padding: 10px 12px 6px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
}
html[data-theme='light'] .composer__box { border: 1px solid var(--line); }

.composer__input {
  display: block;
  width: 100%;
  height: 22px; max-height: 132px;
  overflow-y: auto;
  line-height: 22px;
  resize: none;
}
.composer__input::placeholder { color: var(--fg-faint); }

.composer__tools { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.tool-btn {
  width: 26px; height: 26px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  color: var(--fg-dim);
}
.tool-btn:hover { background: var(--bg-hover); color: var(--fg); }
.tool-btn.is-on { color: var(--c-brand); }

.composer__spacer { flex: 1; }
.composer__tip { font-size: var(--fs-xs); color: var(--fg-faint); margin-right: 4px; }

.btn-primary {
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  background: var(--c-brand);
  color: #fff;
  font-size: var(--fs-md);
}
.btn-primary:hover { background: var(--c-brand-hover); }
.btn-primary:disabled { background: var(--scroll-thumb); color: var(--fg-faint); cursor: not-allowed; }

/* 表情面板 */
.emoji-pop {
  position: absolute; left: 20px; bottom: 86px;
  z-index: var(--z-pop);
  width: 328px; max-height: 224px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
  display: none;
  grid-template-columns: repeat(10, 1fr);
  gap: 2px;
}
.emoji-pop.is-on { display: grid; }
.emoji-pop button { padding: 5px 0; border-radius: var(--radius-sm); font-size: 19px; line-height: 1; }
.emoji-pop button:hover { background: var(--bg-hover); }

/* ==========================================================================
 * 空状态
 * ========================================================================*/
.blank {
  flex: 1;
  display: grid; place-items: center;
  text-align: center; line-height: 2;
  font-size: var(--fs-md);
  color: var(--fg-faint);
}
.blank small { font-size: var(--fs-sm); }

/* ==========================================================================
 * 对话框
 * ========================================================================*/
.modal {
  position: fixed; inset: 0;
  z-index: var(--z-dialog);
  display: none; place-items: center;
  background: var(--scrim);
}
.modal.is-on { display: grid; }

.dialog {
  width: 330px; max-width: calc(100vw - 40px);
  padding: 20px 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .4);
}
.dialog__title { margin: 0 0 14px; font-size: var(--fs-lg); font-weight: 600; }
.dialog__body { font-size: var(--fs-md); }
.dialog__label { display: block; margin: 10px 0 5px; font-size: var(--fs-sm); color: var(--fg-faint); }
.dialog__field {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-app);
  font-size: var(--fs-md);
}
.dialog__hint { margin-top: 8px; font-size: var(--fs-xs); line-height: 1.7; color: var(--fg-faint); }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog__actions button { padding: 6px 14px; border-radius: var(--radius-md); font-size: var(--fs-md); }
.btn-ghost { border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg-hover); }


/* ==========================================================================
 * 文件传输卡片（邀约 / 进度）
 * ========================================================================*/
.msg--file { max-width: 84%; }

.filecard {
  display: flex; gap: 12px; align-items: flex-start;
  min-width: 280px; max-width: 380px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}
.filecard__icon { font-size: 26px; line-height: 1.1; flex: none; }
.filecard__body { flex: 1; min-width: 0; }
.filecard__name {
  font-size: var(--fs-md); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.filecard__meta { margin-top: 2px; font-size: var(--fs-xs); color: var(--fg-faint); }
.filecard__bar {
  margin-top: 8px; height: 4px; border-radius: 2px;
  background: var(--scroll-thumb); overflow: hidden;
}
.filecard__bar i {
  display: block; height: 100%; width: 0;
  background: var(--c-brand);
  transition: width .2s var(--ease);
}
.filecard__err { margin-top: 6px; font-size: var(--fs-xs); color: #e05a52; }

.filecard__actions { display: flex; flex-direction: column; gap: 6px; flex: none; }
.filecard__btn {
  width: 30px; height: 30px; border-radius: 50%;
  font-size: 15px; line-height: 1;
  display: grid; place-items: center;
  border: 1px solid transparent;
  transition: background .12s;
}
.filecard__btn.is-yes { background: var(--c-brand); color: #fff; }
.filecard__btn.is-yes:hover { background: var(--c-brand-hover); }
.filecard__btn.is-no { background: var(--bg-hover); color: var(--fg-dim); }
.filecard__btn.is-no:hover { background: var(--scroll-thumb); color: var(--fg); }
.filecard__btn:disabled { opacity: .4; cursor: not-allowed; }
