/* 圈子 · 样式（移动优先，CSS 变量驱动主题） */
:root {
  --accent: #0f6e56;
  --accent-weak: #e1f5ee;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --ink: #22271f;
  --ink-2: #6b7168;
  --ink-3: #9aa096;
  --line: #e4e7e2;
  --danger: #d64541;
  --amber: #ba7517;
  --amber-weak: #faeeda;
  --radius: 14px;
  --bubble-in: #ffffff;
  --bubble-out: #d8f3e7;
}
:root[data-theme='blue'] { --accent: #185fa5; --accent-weak: #e6f1fb; --bubble-out: #dbeafc; }
:root[data-theme='sunset'] { --accent: #d85a30; --accent-weak: #faece7; --bubble-out: #fbe3d8; }
:root[data-theme='midnight'] { --accent: #534ab7; --accent-weak: #eeedfe; --bubble-out: #e4e1fa; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
button { font: inherit; border: 0; background: none; cursor: pointer; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-2); }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: 300px; min-width: 300px; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 0; border-right: 0; }
  .main { display: none; }
  .app.chatting .sidebar { display: none; }
  .app.chatting .main { display: flex; }
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel); min-height: 56px;
}
.topbar .title { font-weight: 600; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  color: var(--ink-2); flex: none;
}
.iconbtn:hover { background: var(--bg); color: var(--ink); }
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn.accent { color: var(--accent); }

/* ---------- 会话列表 ---------- */
.roomlist { flex: 1; overflow-y: auto; }
.me-card { padding: 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.me-card .name { font-weight: 600; }
.me-card .tag { font-size: 11px; color: var(--amber); background: var(--amber-weak); border-radius: 6px; padding: 1px 6px; margin-left: 6px; }
.room-item {
  display: flex; gap: 10px; padding: 12px 14px; align-items: center; width: 100%; text-align: left;
  border-bottom: 1px solid var(--line);
}
.room-item:hover { background: var(--bg); }
.room-item.active { background: var(--accent-weak); }
.room-item .info { flex: 1; min-width: 0; }
.room-item .rname { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.room-item .rname time { font-size: 11px; color: var(--ink-3); font-weight: 400; flex: none; }
.room-item .lastmsg { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  min-width: 18px; height: 18px; border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; display: grid; place-items: center; padding: 0 5px; flex: none;
}
.empty { text-align: center; color: var(--ink-3); padding: 48px 20px; font-size: 13px; }

/* ---------- 头像 ---------- */
.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 17px;
}
.avatar.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 9px; }

/* ---------- 消息区 ---------- */
.msgs { flex: 1; overflow-y: auto; padding: 14px 14px 6px; scroll-behavior: smooth; }
.daysep { text-align: center; margin: 14px 0 8px; }
.daysep span { font-size: 11px; color: var(--ink-3); background: var(--bg); padding: 2px 10px; border-radius: 10px; }
.sysmsg { text-align: center; margin: 8px 0; }
.sysmsg span { font-size: 12px; color: var(--ink-3); background: var(--panel); border: 1px solid var(--line); padding: 3px 12px; border-radius: 12px; }
.newsep { text-align: center; margin: 10px 0; }
.newsep span { font-size: 11px; color: var(--danger); border: 1px solid var(--danger); padding: 2px 10px; border-radius: 10px; }
.row { display: flex; gap: 8px; margin: 6px 0; align-items: flex-end; }
.row.out { flex-direction: row-reverse; }
.row .col { max-width: min(78%, 560px); display: flex; flex-direction: column; gap: 3px; }
.row.out .col { align-items: flex-end; }
.who { font-size: 11px; color: var(--ink-3); padding: 0 4px; }
.bubble {
  background: var(--bubble-in); border: 1px solid var(--line);
  padding: 8px 12px; border-radius: 4px 14px 14px 14px; word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,.03);
}
.row.out .bubble { background: var(--bubble-out); border-color: transparent; border-radius: 14px 4px 14px 14px; }
.bubble.pending { opacity: .55; }
.bubble.failed { border-color: var(--danger); color: var(--danger); }
.bubble img { max-width: 100%; max-height: 300px; border-radius: 10px; display: block; }
.tick { font-size: 10px; color: var(--ink-3); padding: 0 4px; }
.tick.read { color: var(--accent); }

/* 投票 */
.poll { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; min-width: 240px; }
.poll .q { font-weight: 600; margin-bottom: 8px; }
.poll .opt { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 10px; margin: 6px 0; width: 100%; text-align: left; position: relative; overflow: hidden; }
.poll .opt .bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-weak); z-index: 0; transition: width .3s; }
.poll .opt .lbl { position: relative; z-index: 1; flex: 1; }
.poll .opt .n { position: relative; z-index: 1; font-size: 12px; color: var(--ink-2); }
.poll .opt.mine { border-color: var(--accent); }
.poll .total { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* ---------- 输入区 ---------- */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.composer .rowline { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 12px; max-height: 120px; background: var(--bg); outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  background: var(--accent); color: #fff; border-radius: 12px; padding: 9px 16px; flex: none; font-weight: 600;
}
.send:disabled { opacity: .5; }
.emoji-bar { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 4px; max-height: 132px; overflow-y: auto; }
.emoji-bar button { font-size: 22px; padding: 4px 6px; border-radius: 8px; }
.emoji-bar button:hover { background: var(--bg); }
.menu-pop { position: absolute; bottom: 64px; left: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; z-index: 30; min-width: 160px; }
.menu-pop button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 8px; }
.menu-pop button:hover { background: var(--bg); }
.typing { font-size: 12px; color: var(--ink-3); padding: 0 6px 4px; min-height: 18px; }
.announce {
  background: var(--amber-weak); color: var(--amber); font-size: 12px; padding: 6px 14px;
  display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line);
}
.announce .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guest-tip {
  background: var(--accent-weak); color: var(--accent); font-size: 12px; padding: 7px 14px;
  display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line);
}
.guest-tip button { color: var(--accent); font-weight: 600; text-decoration: underline; }

/* ---------- 表单 / 弹窗 ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; width: 100%; max-width: 400px; }
.card h1 { font-size: 22px; margin: 0 0 4px; }
.card .sub2 { color: var(--ink-2); font-size: 13px; margin-bottom: 18px; }
.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); background: var(--panel); }
.btn { display: block; width: 100%; background: var(--accent); color: #fff; border-radius: 12px; padding: 11px; font-weight: 600; margin-top: 16px; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.linkline { text-align: center; font-size: 13px; color: var(--ink-2); margin-top: 14px; }
.err-line { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 18px; z-index: 50; }
.modal { background: var(--panel); border-radius: 18px; padding: 22px 20px; width: 100%; max-width: 420px; max-height: 86dvh; overflow-y: auto; }
.modal h3 { margin: 0 0 12px; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(30,34,28,.92); color: #fff; padding: 9px 18px; border-radius: 20px; font-size: 13px; z-index: 99;
}
.qrbox { display: grid; place-items: center; padding: 10px 0; }
.qrbox svg { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: #fff; }
.invlink { font-size: 12px; color: var(--ink-2); word-break: break-all; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; }
.member-row .mn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-tag { font-size: 11px; color: var(--accent); background: var(--accent-weak); border-radius: 6px; padding: 1px 6px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.on { background: #3b9e3b; }
.theme-grid { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.theme-dot { width: 44px; height: 44px; border-radius: 14px; position: relative; border: 2px solid transparent; }
.theme-dot.sel { border-color: var(--ink); }
.theme-dot.locked { opacity: .45; }
.theme-dot .lock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 16px; }
.install-tip { background: var(--accent-weak); color: var(--accent); border-radius: 12px; font-size: 13px; padding: 10px 12px; margin-top: 12px; }
.search-hit { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 10px; border-bottom: 1px solid var(--line); }
.search-hit:hover { background: var(--bg); }
.search-hit .h1x { font-size: 12px; color: var(--ink-3); }
.search-hit .h2x { font-size: 14px; }
