/* ============================================================
 * 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); }

.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; }

input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: var(--panel);
  color: var(--text);
  min-width: 0;
}
input:focus { border-color: var(--brand); }
input:disabled { background: var(--panel-soft); color: var(--muted); }

/* ---------------- 弹窗 ---------------- */
.mask {
  position: fixed;
  inset: 0;
  background: var(--mask);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border-radius: 14px;
  width: 100%;
  max-width: 380px;
  padding: 18px;
  box-shadow: var(--shadow);
  max-height: 92vh;
  overflow-y: auto;
}

.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 17px; }
.x {
  border: none; background: none; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}

.tabs { display: flex; gap: 6px; margin: 14px 0 12px; }
.tab {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 7px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.tab.active { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); font-weight: 600; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form .row { display: flex; gap: 6px; }
.form .row input { flex: 1; }
.form-msg { margin: 0; font-size: 12px; min-height: 18px; color: var(--danger); }
.form-msg.ok { color: var(--ok); }
.desc { font-size: 12px; color: var(--muted); margin: 10px 0 14px; line-height: 1.6; }

/* ---------------- 轻提示 ---------------- */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 80;
  pointer-events: none;
}
.toast {
  background: rgba(28, 32, 40, .94);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  max-width: 88vw;
  animation: pop .18s ease-out;
}
.toast.warn { background: rgba(178, 106, 0, .95); }
.toast.err { background: rgba(200, 40, 30, .95); }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------- 手机端 ---------------- */
@media (max-width: 640px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
  }
  .msg { max-width: 88%; }
  .brand span { display: none; }
  .status span { display: none; }        /* 手机上门只留状态灯 */
  .member-list { display: flex; flex-wrap: wrap; gap: 2px; }
  .member { padding: 3px 8px; }
}
