:root {
  --bg: #0f1012;
  --bg2: #17181b;
  --bg3: #26282c;
  --bg4: #313438;
  --line: #232529;
  --fg: #eceef0;
  --fg2: #8b8f95;
  --fg3: #5f6368;
  --blue: #12b7f5;
  --blue2: #4fc9ff;
  --red: #ff4d4f;
  --safe: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 15px; display: flex; flex-direction: column;
  overscroll-behavior: none;
}
button { font-family: inherit; }

/* 顶部 */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 6px; background: var(--bg); position: sticky; top: 0; z-index: 20;
}
body.in-chat .top { display: none; }
.me { display: flex; align-items: center; gap: 11px; min-width: 0; }
.me:active .avatar { transform: scale(.94); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none; overflow: hidden;
  background: linear-gradient(160deg, #3a3d42, #26282b);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #cfd3d8; position: relative;
  transition: transform .18s var(--ease);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { min-width: 0; }
.name { font-size: 17px; font-weight: 600; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 11.5px; color: var(--fg2); margin-top: 2px; display: flex; align-items: center; gap: 4px; }
.dot-online { width: 6px; height: 6px; border-radius: 50%; background: #22c55e; display: inline-block; }
.ops { display: flex; gap: 2px; }
.ops button {
  width: 38px; height: 38px; border: 0; border-radius: 50%;
  background: transparent; color: var(--fg); display: grid; place-items: center;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.ops button:active { background: var(--bg3); transform: scale(.9); }

/* 视图容器 */
main { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.view {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(66px + var(--safe));
  opacity: 0; visibility: hidden; transform: translateX(12px);
  transition: opacity .22s var(--ease), transform .26s var(--ease), visibility .26s;
}
.view.on { opacity: 1; visibility: visible; transform: none; }
.view.chat { display: flex; flex-direction: column; padding-bottom: 0; transform: translateX(24px); }
.view.chat.on { transform: none; }

/* 搜索 */
.searchbar { padding: 4px 14px 10px; display: flex; gap: 8px; }
.searchbar input {
  flex: 1; height: 38px; border-radius: 11px; border: 0; padding: 0 14px;
  background: var(--bg3); color: var(--fg); font-size: 14px; outline: none;
  transition: background .18s var(--ease), box-shadow .18s var(--ease);
}
.searchbar input:focus { background: var(--bg4); box-shadow: 0 0 0 2px rgba(18,183,245,.35); }
.searchbar .mini-btn {
  flex: none; height: 38px; padding: 0 13px; border: 0; border-radius: 11px;
  background: rgba(18,183,245,.14); color: var(--blue); font-size: 13.5px;
  display: flex; align-items: center; gap: 5px;
  transition: transform .12s var(--ease), background .15s;
}
.searchbar .mini-btn:active { transform: scale(.95); background: rgba(18,183,245,.24); }

/* 会话行 */
.list { padding-bottom: 10px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  cursor: pointer; position: relative;
  transition: background .16s var(--ease), transform .12s var(--ease);
}
.row:active { background: var(--bg2); transform: scale(.992); }
.row .avatar { width: 50px; height: 50px; font-size: 18px; }
.row .mid { flex: 1; min-width: 0; }
.row .nm {
  font-size: 16px; font-weight: 500; display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .nm .tag {
  font-size: 10.5px; color: var(--fg2); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 4px; line-height: 15px; flex: none;
}
.row .pv {
  font-size: 13px; color: var(--fg2); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row .right { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.row .time { font-size: 11.5px; color: var(--fg3); }
.row .badge {
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 11px; line-height: 19px; text-align: center;
  box-shadow: 0 1px 6px rgba(255,77,79,.45);
  animation: pop .25s var(--ease);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.row .mute { color: var(--fg3); display: grid; place-items: center; }

/* 对话 */
.chat-top {
  display: flex; align-items: center; gap: 4px; padding: 8px;
  background: var(--bg); border-bottom: 1px solid var(--line); flex: none;
}
.chat-top button {
  width: 38px; height: 38px; border: 0; background: transparent; color: var(--fg);
  display: grid; place-items: center; border-radius: 50%;
  transition: background .15s var(--ease), transform .12s var(--ease);
}
.chat-top button:active { background: var(--bg3); transform: scale(.9); }
.chat-title {
  flex: 1; text-align: center; font-size: 16.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.chat-title .t {
  font-size: 10.5px; font-weight: 400; color: #f0b429;
  border: 1px solid rgba(240,180,41,.45); border-radius: 4px; padding: 0 4px; line-height: 15px;
}

.msgs {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth;
}
.line { display: flex; gap: 9px; align-items: flex-start; animation: rise .26s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.line.me { flex-direction: row-reverse; }
.line .avatar { width: 40px; height: 40px; font-size: 14px; }

.bubble {
  max-width: 70%; padding: 10px 14px; border-radius: 16px; font-size: 15.5px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  transition: transform .15s var(--ease);
}
.line.them .bubble { background: var(--bg3); color: var(--fg); border-top-left-radius: 6px; }
.line.me .bubble {
  background: linear-gradient(160deg, var(--blue2), var(--blue));
  color: #fff; border-top-right-radius: 6px;
  box-shadow: 0 2px 10px rgba(18,183,245,.22);
}
.line .bubble:active { transform: scale(.98); }
.bubble.img { padding: 0; background: transparent !important; box-shadow: none !important; }
.bubble.img img { max-width: 190px; max-height: 240px; border-radius: 12px; display: block; }

.time-sep { text-align: center; font-size: 11.5px; color: var(--fg3); margin: 2px 0 4px; }

/* 输入区 */
.composer { flex: none; background: var(--bg); border-top: 1px solid var(--line); }
.toolbar { display: flex; align-items: center; gap: 4px; padding: 8px 10px 0; }
.toolbar button {
  width: 38px; height: 38px; border: 0; background: transparent; color: var(--fg2);
  display: grid; place-items: center; border-radius: 10px;
  transition: background .15s var(--ease), color .15s var(--ease), transform .12s var(--ease);
}
.toolbar button:active { background: var(--bg3); color: var(--fg); transform: scale(.9); }
.inputrow { display: flex; align-items: flex-end; gap: 8px; padding: 6px 10px calc(10px + var(--safe)); }
.inputrow textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 40px;
  border: 0; border-radius: 10px; padding: 10px 13px; font: inherit;
  background: var(--bg3); color: var(--fg); outline: none;
  transition: background .18s var(--ease), box-shadow .18s var(--ease);
}
.inputrow textarea:focus { background: var(--bg4); box-shadow: 0 0 0 2px rgba(18,183,245,.3); }
.inputrow .send {
  height: 40px; padding: 0 18px; border-radius: 10px; border: 0;
  background: var(--blue); color: #fff; font-size: 14.5px;
  transition: transform .12s var(--ease), opacity .18s var(--ease);
}
.inputrow .send:active { transform: scale(.95); }
.inputrow .send:disabled { opacity: .45; }

/* 底部 tab */
.tabbar {
  flex: none; display: flex; background: var(--bg2);
  border-top: 1px solid var(--line); padding-bottom: var(--safe);
  position: relative; z-index: 30;
}
body.in-chat .tabbar { display: none; }
.tabbar button {
  flex: 1; border: 0; background: transparent; color: var(--fg3);
  padding: 7px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; position: relative;
  transition: color .2s var(--ease), transform .12s var(--ease);
}
.tabbar button:active { transform: scale(.94); }
.tabbar button.on { color: var(--blue); }
.tabbar button .badge-mini {
  position: absolute; top: 4px; right: 22%;
  min-width: 16px; height: 16px; border-radius: 8px; background: var(--red);
  color: #fff; font-size: 10px; line-height: 16px; padding: 0 4px;
}
.tabbar .slider {
  position: absolute; top: 0; height: 2px; width: 26px; border-radius: 2px;
  background: var(--blue); box-shadow: 0 0 8px rgba(18,183,245,.7);
  transition: transform .32s var(--ease), width .32s var(--ease);
}

/* 弹层通用 */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none;
  align-items: flex-end; z-index: 99; backdrop-filter: blur(2px);
}
.sheet.on { display: flex; }
.sheet-inner {
  width: 100%; max-height: 90vh; overflow-y: auto;
  background: var(--bg2); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + var(--safe));
  animation: sheetUp .28s var(--ease);
}
@keyframes sheetUp { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-inner h3 { margin: 0 0 16px; font-size: 16.5px; }

/* 表单字段 */
.fld { display: block; margin-bottom: 14px; }
.fld > span { display: block; font-size: 12.5px; color: var(--fg2); margin-bottom: 6px; }
.fld input, .fld textarea, .fld select {
  width: 100%; border: 0; border-radius: 10px;
  background: var(--bg3); color: var(--fg);
  padding: 11px 13px; font: inherit; font-size: 14.5px; outline: none;
  transition: box-shadow .18s var(--ease), background .18s;
}
.fld textarea { resize: vertical; line-height: 1.6; font-size: 14px; }
.fld input:focus, .fld textarea:focus, .fld select:focus {
  background: var(--bg4); box-shadow: 0 0 0 2px rgba(18,183,245,.35);
}
.fld .tip { display: block; margin-top: 5px; font-size: 11.5px; color: var(--fg3); line-height: 1.5; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 头像行 */
.ava-row { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.ava-row .avatar { width: 62px; height: 62px; font-size: 22px; }
.ava-row .ava-hint { font-size: 12.5px; color: var(--fg2); line-height: 1.5; }
.ava-row .ava-hint b { color: var(--blue); font-weight: 500; }

.sheet-ops { display: flex; gap: 10px; margin-top: 4px; }
.sheet-ops button {
  flex: 1; height: 44px; border-radius: 11px; border: 0; font-size: 14.5px;
  background: var(--bg3); color: var(--fg);
  transition: transform .12s var(--ease);
}
.sheet-ops button:active { transform: scale(.97); }
.sheet-ops .primary { background: var(--blue); color: #fff; }
.sheet-ops .danger { background: rgba(255,77,79,.15); color: var(--red); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px);
  background: rgba(0,0,0,.86); color: #fff; font-size: 13px; padding: 9px 17px;
  border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease), transform .25s var(--ease); z-index: 200;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 头像可换提示 */
.avatar.editable::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: rgba(0,0,0,.55) url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 8h3l1.5-2h7L17 8h3v11H4z'/%3E%3Ccircle cx='12' cy='13' r='3.2'/%3E%3C/svg%3E") center/18px no-repeat;
  opacity: 0; transition: opacity .2s var(--ease);
}
.avatar.editable:active::after { opacity: 1; }

/* 空状态 */
.empty { padding: 40px 20px; text-align: center; color: var(--fg3); font-size: 13.5px; line-height: 1.7; }
.empty b { color: var(--fg2); font-weight: 500; }

/* 群聊：气泡上方显示发送者名字 */
.line .stack { display: flex; flex-direction: column; gap: 4px; max-width: 72%; }
.line.me .stack { align-items: flex-end; }
.line .stack .bubble { max-width: 100%; }
.line .who { font-size: 11.5px; color: var(--fg3); padding-left: 2px; }

/* 成员选择 */
.members { display: grid; gap: 8px; }
.member {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 12px; background: var(--bg3);
  font-size: 14.5px;
}
.member input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--blue); flex: none;
}
.member .avatar { width: 34px; height: 34px; font-size: 13px; }
.member span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint2 { color: var(--fg3); font-size: 13px; padding: 10px 2px; }

/* 预设卡片上的小元信息 */
.preset .pmeta { margin-top: 4px; font-size: 11.5px; color: var(--fg3); }
.preset.off { opacity: .55; }
.ptag.off { color: var(--fg3); background: rgba(255,255,255,.06); }