/* BridgeTalk — WeChat-flavoured shell. Light + dark. Desktop rail + mobile tabs. */

:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --mine: #95ec69;
  --mine-text: #191919;
  --bg: #ededed;
  --list-bg: #f7f7f7;
  --main-bg: #f5f5f5;
  --panel: #ffffff;
  --line: #e4e4e4;
  --text: #191919;
  --sub: #8a8a8a;
  --faint: #b2b2b2;
  --badge: #fa5151;
  --hover: rgba(0, 0, 0, 0.045);
  --active: rgba(0, 0, 0, 0.07);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  --radius: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --list-bg: #141414;
    --main-bg: #111111;
    --panel: #1f1f1f;
    --line: #2b2b2b;
    --text: #e6e6e6;
    --sub: #8c8c8c;
    --faint: #666666;
    --mine: #2f7d4f;
    --mine-text: #eaffee;
    --hover: rgba(255, 255, 255, 0.06);
    --active: rgba(255, 255, 255, 0.1);
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

html[data-theme='light'] {
  --bg: #ededed; --list-bg: #f7f7f7; --main-bg: #f5f5f5; --panel: #fff;
  --line: #e4e4e4; --text: #191919; --sub: #8a8a8a; --faint: #b2b2b2;
  --mine: #95ec69; --mine-text: #191919;
  --hover: rgba(0, 0, 0, 0.045); --active: rgba(0, 0, 0, 0.07);
}
html[data-theme='dark'] {
  --bg: #111111; --list-bg: #141414; --main-bg: #111111; --panel: #1f1f1f;
  --line: #2b2b2b; --text: #e6e6e6; --sub: #8c8c8c; --faint: #666;
  --mine: #2f7d4f; --mine-text: #eaffee;
  --hover: rgba(255, 255, 255, 0.06); --active: rgba(255, 255, 255, 0.1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font-family: inherit; }
input, textarea { font-family: inherit; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.35); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(128, 128, 128, 0.55); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ auth */
.auth {
  min-height: 100dvh; display: flex; justify-content: center; align-items: flex-start;
  overflow-y: auto; padding: 24px;
  background:
    radial-gradient(800px 420px at 12% -10%, rgba(7, 193, 96, 0.14), transparent 60%),
    radial-gradient(700px 420px at 105% 110%, rgba(43, 127, 255, 0.1), transparent 55%),
    var(--bg);
}
.auth-card {
  width: min(470px, 100%); margin: auto; background: var(--panel); border-radius: 14px;
  padding: 26px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.auth-brand { display: flex; gap: 13px; align-items: center; margin-bottom: 20px; }
.auth-logo {
  width: 50px; height: 50px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, #07c160, #04924a); color: #fff;
  font-size: 17px; font-weight: 800; letter-spacing: 1px;
}
.auth-brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.auth-brand p { margin: 4px 0 0; font-size: 12.5px; color: var(--sub); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid2.single { grid-template-columns: 1fr; }
.auth-links { margin: -6px 0 12px; text-align: right; }
.auth-links .link-btn { font-size: 12px; }

.invite-banner {
  background: rgba(7, 193, 96, 0.1); border: 1px solid rgba(7, 193, 96, 0.35);
  color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 12.5px;
  margin-bottom: 14px; line-height: 1.5;
}
.invite-banner b { color: var(--green); }

.seg { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg-btn {
  flex: 1; border: 0; background: transparent; color: var(--sub); font-size: 13.5px;
  font-weight: 600; padding: 8px 6px; border-radius: 8px; cursor: pointer;
}
.seg-btn.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }

.field { display: block; margin-bottom: 13px; }
.field > span { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; font-weight: 600; }
.field input, .field select {
  width: 100%; padding: 11px 12px; font-size: 14.5px; color: var(--text);
  background: var(--bg); border: 1px solid transparent; border-radius: 8px; outline: none;
}
.field select { cursor: pointer; }
.field input:focus, .field select:focus { border-color: var(--green); background: var(--panel); }
.form-error { color: var(--badge); font-size: 12.5px; margin: 2px 0 10px; }
.captcha-block { display: flex; flex-direction: column; gap: 8px; }
.captcha-img {
  align-self: center; padding: 0; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; cursor: pointer; background: #fff; line-height: 0;
}
.captcha-img:hover { border-color: var(--green); }
.captcha-img img { display: block; width: 220px; height: 84px; }
.btn-primary {
  width: 100%; padding: 12px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--green); color: #fff; font-size: 15px; font-weight: 600;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.auth-foot { margin: 14px 0 0; text-align: center; font-size: 12px; color: var(--sub); }
.dot-sep { margin: 0 6px; }
.link-btn { border: 0; background: none; color: var(--green); cursor: pointer; font-size: 12px; padding: 0; }

/* ------------------------------------------------------------------- app */
.app {
  display: grid;
  grid-template-columns: 60px 300px 1fr;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

/* rail */
.rail {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--list-bg); border-right: 1px solid var(--line);
  padding: 14px 0 12px;
}
.rail-grow { flex: 1; }
.rail-avatar {
  width: 26px; height: 26px; border-radius: 6px;
  background-color: var(--faint); background-size: cover; background-position: center;
  color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center;
}
.rail-label { display: none; font-size: 10px; line-height: 1; letter-spacing: 0.2px; }
.rail-me .rail-avatar { width: 24px; height: 24px; font-size: 11px; }
.rail-btn {
  width: 38px; height: 38px; border-radius: 8px; border: 0; background: transparent;
  color: var(--faint); cursor: pointer; display: grid; place-items: center; position: relative;
}
.rail-btn:hover { background: var(--hover); color: var(--sub); }
.rail-btn.active { color: var(--green); background: var(--active); }
.rail-btn svg { width: 22px; height: 22px; }
.rail-badge {
  position: absolute; top: 1px; right: -3px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 8px; background: var(--badge); color: #fff; font-size: 10px; font-weight: 700;
  display: grid; place-items: center; line-height: 1;
}

/* list pane */
.list { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--list-bg); border-right: 1px solid var(--line); }
.app > * { min-width: 0; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.list-head h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.3px; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px; border: 0; background: transparent;
  color: var(--sub); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.list-search { padding: 0 12px 8px; }
.list-search input {
  width: 100%; padding: 7px 10px; font-size: 13px; color: var(--text);
  background: rgba(128, 128, 128, 0.14); border: 0; border-radius: 6px; outline: none;
}
.list-body { flex: 1; overflow-y: auto; padding: 0 6px 12px; }

.cell {
  display: flex; gap: 10px; padding: 10px 10px; border-radius: 8px; cursor: pointer; align-items: center;
  min-width: 0; overflow: hidden;
}
.cell:hover { background: var(--hover); }
.cell.active { background: var(--active); }
.cell-main { flex: 1; min-width: 0; }
.cell-top { display: flex; align-items: baseline; gap: 8px; }
.cell-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-time { font-size: 11px; color: var(--faint); flex: 0 0 auto; }
.cell-sub { display: flex; align-items: center; gap: 6px; margin-top: 3px; min-width: 0; }
.cell-last { flex: 1; min-width: 0; font-size: 12.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--badge);
  color: #fff; font-size: 10.5px; font-weight: 600; display: grid; place-items: center; flex: 0 0 auto;
}
.ava {
  width: 40px; height: 40px; border-radius: 5px; flex: 0 0 auto; position: relative;
  background-size: cover; background-position: center; background-color: var(--faint);
  color: #fff; font-weight: 600; font-size: 15px; display: grid; place-items: center; user-select: none;
}
.ava.sm { width: 34px; height: 34px; font-size: 13px; border-radius: 4px; }
.ava.lg { width: 68px; height: 68px; font-size: 26px; border-radius: 8px; }
.ava .dot-on {
  position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--list-bg);
}
.list-empty { padding: 26px 18px; text-align: center; color: var(--faint); font-size: 12.5px; line-height: 1.7; }

/* main pane */
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--main-bg); position: relative; }
.main-empty {
  flex: 1; display: grid; place-items: center; color: var(--faint); font-size: 13px; text-align: center; line-height: 2;
}
.main-empty .ghost-icon {
  width: 76px; height: 76px; border-radius: 20px; margin: 0 auto 12px; display: grid; place-items: center;
  background: rgba(7, 193, 96, 0.12); color: var(--green); font-size: 32px; font-weight: 700;
}

/* chat */
.chat { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 58px; flex: 0 0 auto;
  border-bottom: 1px solid var(--line); background: var(--list-bg); cursor: pointer;
}
.chat-head:hover { background: var(--hover); }
.chat-head-main { min-width: 0; flex: 1; }
.chat-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 11.5px; color: var(--sub); height: 15px; }
.chat-status.typing { color: var(--green); }
.back-btn { display: none; }

.msgs { flex: 1; overflow-y: auto; padding: 14px 18px 6px; scroll-behavior: auto; background: var(--bg); }
.m-time { text-align: center; margin: 10px 0 8px; }
.m-time span { font-size: 11px; color: var(--faint); }
.m-sys { text-align: center; margin: 10px 14px; }
.m-sys span {
  display: inline-block; font-size: 11.5px; color: var(--sub);
  background: rgba(128, 128, 128, 0.12); padding: 3px 9px; border-radius: 4px; line-height: 1.5;
}
.m { display: flex; gap: 9px; align-items: flex-start; margin: 10px 0; }
.m.me { flex-direction: row-reverse; }
.m-body { max-width: min(62ch, 68%); display: flex; flex-direction: column; }
.m.me .m-body { align-items: flex-end; }
.bubble {
  background: var(--panel); color: var(--text); padding: 9px 12px; border-radius: 5px;
  font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  position: relative; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}
.m.me .bubble { background: var(--mine); color: var(--mine-text); }
.bubble.tail::before {
  content: ''; position: absolute; top: 12px; width: 0; height: 0;
  border: 5px solid transparent;
}
.m:not(.me) .bubble.tail::before { left: -9px; border-right-color: var(--panel); }
.m.me .bubble.tail::before { right: -9px; border-left-color: var(--mine); }
.m-meta { font-size: 10.5px; color: var(--faint); margin: 4px 2px 0; }
.m.pending .bubble { opacity: 0.6; }
.m.failed .bubble { box-shadow: inset 0 0 0 1px var(--badge); }
.thread-empty { text-align: center; color: var(--faint); font-size: 12.5px; margin: 40px 0; line-height: 1.8; }
.load-more { text-align: center; margin: 4px 0 14px; }
.load-more button {
  border: 0; background: rgba(128, 128, 128, 0.14); color: var(--sub);
  font-size: 11.5px; padding: 6px 14px; border-radius: 14px; cursor: pointer;
}

/* composer */
.composer { position: relative; flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--list-bg); padding: 6px 14px calc(8px + var(--safe-b)); }
.composer textarea {
  width: 100%; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  font-size: 14.5px; line-height: 1.55; min-height: 44px; max-height: 140px; padding: 4px 2px;
}
@media (pointer: coarse) { .composer-hint { display: none; } }
.composer-bar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.composer-hint { font-size: 11px; color: var(--faint); margin-right: auto; }
.send-btn {
  border: 1px solid var(--green); color: var(--green); background: transparent;
  border-radius: 4px; padding: 5px 16px; font-size: 13px; cursor: pointer;
}
.send-btn:hover { background: rgba(7, 193, 96, 0.1); }
.send-btn:disabled { opacity: 0.45; cursor: default; }
.emoji-btn {
  border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer;
  padding: 2px 6px; border-radius: 6px; color: inherit;
}
.emoji-btn:hover { background: var(--hover); }
.emoji-panel {
  position: absolute; left: 12px; bottom: calc(100% - 2px); z-index: 20;
  width: min(352px, calc(100vw - 28px)); padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 236px; overflow-y: auto;
}
.emoji-panel button {
  border: 0; background: transparent; font-size: 22px; line-height: 1.2; padding: 5px 0;
  border-radius: 6px; cursor: pointer;
}
.emoji-panel button:hover { background: var(--hover); }
.bubble.emoji-only {
  background: transparent !important; box-shadow: none; padding: 2px 0; font-size: 34px; line-height: 1.25;
}
.bubble.emoji-only::before { display: none; }

/* profile / panels */
.panel { flex: 1; overflow-y: auto; padding: 22px; }
.panel-card { background: var(--panel); border-radius: 10px; padding: 18px; margin-bottom: 14px; max-width: 620px; }
.profile-hero { display: flex; gap: 16px; align-items: center; }
.profile-name { font-size: 18px; font-weight: 600; }
.profile-id { font-size: 12.5px; color: var(--sub); margin-top: 5px; }
.profile-line { font-size: 12.5px; color: var(--sub); margin-top: 4px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-label { width: 82px; flex: 0 0 auto; font-size: 13px; color: var(--sub); }
.row-value { flex: 1; min-width: 0; font-size: 13.5px; word-break: break-word; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ok:hover { background: var(--green-dark); }
.btn.danger { color: var(--badge); border-color: rgba(250, 81, 81, 0.4); }
.btn.block { width: 100%; }
.field-inline { display: flex; gap: 8px; align-items: center; }
.field-inline input, .settings-input {
  flex: 1; min-width: 0; width: 100%; display: block; padding: 8px 10px; font-size: 13.5px; color: var(--text);
  background: var(--bg); border: 1px solid transparent; border-radius: 6px; outline: none;
}
.panel-card > .settings-input + .settings-input { margin-top: 8px; }
.row select.settings-input {
  flex: 0 0 auto; width: 150px; height: 32px; padding: 0 8px; cursor: pointer;
}
.field-inline input:focus { border-color: var(--green); background: var(--panel); }
.switch {
  width: 44px; height: 24px; border-radius: 12px; border: 0; background: rgba(128, 128, 128, 0.35);
  position: relative; cursor: pointer; flex: 0 0 auto; transition: background 0.15s;
}
.switch.on { background: var(--green); }
.switch i {
  position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform 0.15s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.switch.on i { transform: translateX(20px); }
.panel-title { font-size: 15px; font-weight: 600; margin: 0 0 14px; }
.panel-sub { font-size: 12px; color: var(--sub); margin: -8px 0 16px; line-height: 1.6; }

/* requests */
.req { display: flex; gap: 10px; align-items: center; padding: 12px; background: var(--panel); border-radius: 8px; margin-bottom: 8px; }
.req-main { flex: 1; min-width: 0; }
.req-name { font-size: 14px; font-weight: 500; }
.req-note { font-size: 12px; color: var(--sub); margin-top: 3px; overflow-wrap: anywhere; }
.req-actions { display: flex; gap: 6px; flex: 0 0 auto; }

/* invite list */
.invite-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.invite-url {
  flex: 1; min-width: 0; font-size: 12.5px; color: var(--sub); font-family: ui-monospace, Menlo, Consolas, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center;
  z-index: 60; padding: 20px; animation: fade 0.12s ease;
}
.modal {
  width: min(420px, 100%); background: var(--panel); border-radius: 12px; box-shadow: var(--shadow);
  padding: 20px; border: 1px solid var(--line);
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal p.hint { margin: 0 0 14px; font-size: 12.5px; color: var(--sub); line-height: 1.6; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.search-result { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 12px; }
.search-result .who { display: flex; gap: 10px; align-items: center; }
.sr-name { font-size: 14px; font-weight: 600; }
.sr-id { font-size: 12px; color: var(--sub); margin-top: 2px; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: rgba(40, 40, 40, 0.94); color: #fff; font-size: 13px; padding: 9px 16px;
  border-radius: 6px; z-index: 70; max-width: 86vw;
}

/* --------------------------------------------------------------- mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: 100dvh; }
  .rail {
    order: 2; flex-direction: row; justify-content: space-around; align-items: center;
    border-right: 0; border-top: 1px solid var(--line); padding: 6px 10px calc(6px + var(--safe-b));
    gap: 0;
  }
  .rail-grow { display: none; }
  .rail-btn { width: auto; flex: 1; height: 46px; flex-direction: column; gap: 2px; }
  .rail-btn.active { background: transparent; }
  .rail-avatar {
    display: grid; width: 28px; height: 28px; margin: 0; font-size: 12px; border-radius: 50%;
    flex: 0 0 auto;
  }
  .rail-badge { top: 2px; right: calc(50% - 24px); }
  .list { order: 1; border-right: 0; }
  .list-head { padding: 12px 14px 6px; }
  .list-head h1 { font-size: 17px; }
  .main {
    position: fixed; inset: 0; z-index: 30; transform: translateX(102%);
    transition: transform 0.2s ease; background: var(--main-bg);
  }
  .app.detail-open .main { transform: translateX(0); }
  .back-btn { display: grid; }
  .msgs { padding: 10px 12px 4px; }
  .m-body { max-width: 76%; }
  .panel { padding: 14px; }
  .composer { padding-bottom: calc(8px + var(--safe-b)); }
}

@media (max-width: 460px) {
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .auth-card { padding: 20px; }
}

/* ---------------------------------------------- international phone input */
.phone-row { display: flex; gap: 8px; align-items: stretch; }
.phone-row .dial-select {
  flex: 0 0 auto; width: 108px; padding: 11px 8px; font-size: 14px; color: var(--text);
  background: var(--bg); border: 1px solid transparent; border-radius: 8px; outline: none; cursor: pointer;
}
.phone-row .dial-select:focus { border-color: var(--green); background: var(--panel); }
.phone-row input {
  flex: 1; min-width: 0; width: auto; padding: 11px 12px; font-size: 14.5px; color: var(--text);
  background: var(--bg); border: 1px solid transparent; border-radius: 8px; outline: none;
}
.phone-row input:focus { border-color: var(--green); background: var(--panel); }
.field-hint { display: block; margin-top: 5px; font-size: 11px; color: var(--faint); line-height: 1.4; }
.panel-back { display: none; }

/* ---------------------------------------------- mobile refinements (v2) */
@media (max-width: 860px) {
  .field input, .field select, .phone-row input, .settings-input,
  .list-search input, .composer textarea, .modal input, .modal select { font-size: 16px; }
  .phone-row .dial-select { width: 98px; padding: 11px 6px; }
  .field-hint { font-size: 11.5px; }

  .icon-btn { width: 40px; height: 40px; border-radius: 10px; }
  .icon-btn svg { width: 20px; height: 20px; }
  .back-btn { width: 40px; height: 40px; }
  .list-head { padding: 14px 14px 8px; }
  .list-head h1 { font-size: 18px; }
  .list-search input { padding: 9px 12px; border-radius: 8px; }
  .cell { padding: 11px 8px; gap: 11px; }
  .ava { width: 44px; height: 44px; font-size: 16px; border-radius: 6px; }
  .cell-name { font-size: 15.5px; }
  .cell-last { font-size: 13px; }
  .cell-time { font-size: 11.5px; }

  .chat-head { height: 54px; padding: 0 10px; gap: 8px; }
  .chat-name { font-size: 15.5px; }
  .msgs { padding: 10px 12px 4px; }
  .bubble { font-size: 15px; padding: 9px 12px; }
  .composer { padding: 6px 10px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .composer textarea { min-height: 40px; }
  .send-btn { padding: 8px 16px; font-size: 14px; }
  .emoji-panel { left: 8px; right: 8px; width: auto; max-height: 210px; }
  .emoji-panel button { font-size: 24px; padding: 6px 0; }

  .panel { padding: 10px 12px calc(24px + env(safe-area-inset-bottom, 0px)); }
  .panel-card { padding: 14px; border-radius: 12px; }
  .panel-back {
    display: grid; width: 40px; height: 40px; margin: 0 0 8px; border-radius: 10px; border: 0;
    background: var(--panel); color: var(--sub); place-items: center; cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  }
  .row { padding: 14px 0; }
  .req { flex-wrap: wrap; gap: 10px; }
  .req-actions { width: 100%; justify-content: flex-end; }
  .req-actions .btn { flex: 1; }

  .auth { padding: 14px; }
  .auth-card { padding: 18px; border-radius: 12px; }
  .captcha-img img { max-width: 100%; height: auto; }
  .grid2 { gap: 0 10px; }
}

@media (max-width: 380px) {
  .emoji-panel { grid-template-columns: repeat(7, 1fr); }
  .grid2 { grid-template-columns: 1fr; gap: 0; }
  .rail-badge { right: calc(50% - 26px); }
}

@media (max-height: 480px) and (max-width: 860px) {
  .rail { padding: 2px 10px calc(2px + env(safe-area-inset-bottom, 0px)); }
  .rail-btn { height: 38px; }
  .rail-btn svg { width: 20px; height: 20px; }
}

/* ---------------------------------------------- settings page (WeChat style) */
.panel-heading { font-size: 20px; font-weight: 700; margin: 2px 2px 12px; letter-spacing: 0.2px; }
.set-group {
  background: var(--panel); border-radius: 10px; margin-bottom: 12px; overflow: hidden; max-width: 620px;
}
.set-group-title { font-size: 12px; color: var(--sub); padding: 14px 16px 6px; }
.set-row {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-top: 1px solid var(--line); font-size: 14.5px;
}
.set-group-title + .set-row { border-top: 0; }
.set-row.tappable { cursor: pointer; }
.set-row.tappable:hover { background: var(--hover); }
.set-row-label { flex: 1; min-width: 0; }
.set-row-value { color: var(--sub); font-size: 13.5px; }
.set-row-arrow { color: var(--faint); font-size: 18px; line-height: 1; }
.set-row.danger .set-row-label { color: var(--badge); }
.set-group .switch { margin-left: auto; }
.opt-list { display: flex; flex-direction: column; margin: 4px 0 2px; }
.opt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text);
  font-size: 15px; padding: 13px 4px; cursor: pointer; text-align: left; width: 100%;
}
.opt-row:last-child { border-bottom: 0; }
.opt-row.on { color: var(--green); font-weight: 600; }
.opt-check { color: var(--green); font-weight: 700; }

/* ---------------------------------------------- bottom tabs with labels */
@media (max-width: 860px) {
  .rail { padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px)); align-items: stretch; }
  .rail-btn {
    flex: 1; height: auto; min-height: 50px; flex-direction: column; justify-content: center;
    gap: 3px; padding: 6px 0 4px; border-radius: 10px;
  }
  .rail-label { display: block; font-size: 11px; line-height: 1.1; color: var(--sub); }
  .rail-btn.active .rail-label { color: var(--green); }
  .rail-btn svg { width: 22px; height: 22px; }
  .rail-me .rail-avatar { width: 24px; height: 24px; margin: 0; border-radius: 6px; font-size: 11px; }
  .rail-badge { top: 2px; right: calc(50% - 26px); }
  .set-row { padding: 15px 14px; font-size: 15px; }
  .set-group-title { padding: 14px 14px 6px; }
}

/* ============================================================
   v1.1 评审整改：对比度 / 焦点 / 反馈 / 触控
   ============================================================ */

/* 次要文字提到 WCAG AA（≥4.5:1）；--faint 只用于装饰 */
:root { --sub: #6b6b6b; --faint: #b2b2b2; --warn: #ff9500; }
@media (prefers-color-scheme: dark) { :root { --sub: #a3a3a3; --faint: #7a7a7a; } }
html[data-theme='dark'] { --sub: #a3a3a3; --faint: #7a7a7a; }
html[data-theme='light'] { --sub: #6b6b6b; --faint: #b2b2b2; }

/* 字号统一到 15 / 13 / 12 / 11 */
.cell-name { font-size: 15px; }
.cell-last { font-size: 13px; }
.cell-time { font-size: 12px; color: var(--sub); }
.chat-status { font-size: 12px; }
.chat-name { font-size: 16px; }
.set-row { font-size: 15px; }
.auth-foot { font-size: 13px; }
.field-hint { font-size: 12px; color: var(--sub); }
.composer-hint { font-size: 12px; color: var(--sub); }
.m-time span { font-size: 11.5px; color: var(--sub); }
.m-meta { font-size: 11px; color: var(--sub); }

/* 焦点可见 */
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 8px; }
.cell:focus-visible, .set-row:focus-visible, .opt-row:focus-visible { outline-offset: -2px; }
[role='button'] { cursor: pointer; }

/* 表单字段级错误 */
.field-error { display: none; margin: 6px 0 0; font-size: 12px; color: var(--danger, #fa5151); }
.field.invalid .field-error { display: block; }
.field.invalid input, .field.invalid select,
.field.invalid .phone-row input, .field.invalid .phone-row .dial-select {
  border-color: var(--danger, #fa5151) !important;
  background: rgba(250, 81, 81, 0.06) !important;
}

/* 连接状态条 */
.netbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 12.5px; line-height: 1; padding: 8px 12px; color: #fff;
  background: var(--warn); transform: translateY(-102%); transition: transform 0.18s ease;
}
.netbar.show { transform: none; }
.netbar.ok { background: var(--green); }
.netbar.bad { background: #c93a3a; }

/* 消息状态 */
.msg-state { display: inline-flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 11px; color: var(--sub); }
.msg-state.fail { color: var(--danger, #fa5151); font-weight: 600; cursor: pointer; }
.m.failed .bubble { box-shadow: inset 0 0 0 1px var(--danger, #fa5151); }

/* 日期分隔 */
.m-day { text-align: center; margin: 14px 0 6px; }
.m-day span { font-size: 11px; color: var(--sub); }

/* 通讯录分组 & 在线人数 */
.list-section { padding: 10px 12px 4px; font-size: 12px; color: var(--sub); font-weight: 600; letter-spacing: 0.4px; }
.list-note { padding: 6px 12px 10px; font-size: 12px; color: var(--sub); }

/* 首登引导 */
.onboard { background: var(--panel); border-radius: 12px; padding: 18px; max-width: 620px; }
.onboard h3 { margin: 0 0 6px; font-size: 16px; }
.onboard ol { margin: 10px 0 14px; padding-left: 18px; line-height: 1.9; font-size: 13.5px; color: var(--text); }
.onboard .row-actions { margin-top: 4px; }

/* 邀请链接行 */
.invite-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.invite-item:last-child { border-bottom: 0; }
.invite-meta { flex: 1; min-width: 0; }
.invite-meta .u { font-size: 13px; color: var(--sub); font-family: ui-monospace, Menlo, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-meta .m { font-size: 11.5px; color: var(--sub); margin-top: 2px; }

/* 触控目标：手机端一律 ≥44 */
@media (max-width: 860px) {
  .emoji-btn { min-width: 44px; min-height: 44px; font-size: 22px; }
  .send-btn { min-height: 44px; min-width: 72px; }
  .icon-btn, .back-btn, .panel-back { min-width: 44px; min-height: 44px; }
  .list-search input { min-height: 44px; }
  .opt-row { min-height: 48px; }
  .set-row { min-height: 52px; }
  .cell { min-height: 64px; }
}

/* 引导卡在浅色空态里要可读 */
.onboard { color: var(--text); }
.onboard ol { color: var(--text); }
.main-empty .onboard { text-align: left; }

/* ============================================================
   v1.2 视觉系统：层次 / 排版 / 分隔线 / 密度 / 动效
   ============================================================ */

:root {
  --bg-0: #f2f3f5;
  --bg-1: #ffffff;
  --bg-2: #f7f8fa;
  --bg: #f2f3f5;
  --list-bg: #ffffff;
  --main-bg: #f2f3f5;
  --panel: #ffffff;
  --line: #ebedf0;
  --sub: #6b6b6b;
  --faint: #c8c8c8;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 6px 20px rgba(0, 0, 0, 0.08);
  --shadow-3: 0 16px 48px rgba(0, 0, 0, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-0: #0d0f12; --bg-1: #16191d; --bg-2: #1b1f24;
    --bg: #0d0f12; --list-bg: #16191d; --main-bg: #0d0f12; --panel: #1b1f24;
    --line: #2a2f36; --sub: #a3a3a3; --faint: #6b7280;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 6px 20px rgba(0, 0, 0, 0.5);
    --shadow-3: 0 16px 48px rgba(0, 0, 0, 0.6);
  }
}
html[data-theme='dark'] {
  --bg-0: #0d0f12; --bg-1: #16191d; --bg-2: #1b1f24;
  --bg: #0d0f12; --list-bg: #16191d; --main-bg: #0d0f12; --panel: #1b1f24;
  --line: #2a2f36; --sub: #a3a3a3; --faint: #6b7280;
}
html[data-theme='light'] {
  --bg-0: #f2f3f5; --bg-1: #ffffff; --bg-2: #f7f8fa;
  --bg: #f2f3f5; --list-bg: #ffffff; --main-bg: #f2f3f5; --panel: #ffffff;
  --line: #ebedf0; --sub: #6b6b6b; --faint: #c8c8c8;
}

/* 三栏层次：rail 最深 → 列表白 → 主区灰 */
.rail { background: #e8eaee; border-right: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .rail { background: #0a0c0e; } }
html[data-theme='dark'] .rail { background: #0a0c0e; }

/* 排版基线：禁止 line-height: normal */
body { font-size: 15px; line-height: 1.55; }
.list-head h1 { font-size: 20px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.cell-name { font-size: 16px; line-height: 1.4; font-weight: 600; }
.cell-last { font-size: 13px; line-height: 1.45; }
.cell-time { font-size: 12px; line-height: 1.4; letter-spacing: 0.02em; color: var(--sub); }
.bubble { font-size: 15px; line-height: 1.55; }
.chat-name { font-size: 16px; line-height: 1.4; font-weight: 600; }
.chat-status { font-size: 12px; line-height: 1.4; }
.panel-heading { font-size: 20px; line-height: 1.3; }

/* 列表密度 68 / 头像 44 / 文字起点 68 的 hairline */
.cell { min-height: 68px; padding: 10px 16px; border-radius: 0; position: relative; }
.cell:hover, .cell.active { background: var(--bg-2); }
.cell + .cell::before {
  content: ''; position: absolute; left: 72px; right: 0; bottom: 0;
  height: 1px; background: var(--line);
}
.ava { width: 44px; height: 44px; font-size: 16px; }
.ava.sm { width: 36px; height: 36px; font-size: 14px; }
.ava.lg { width: 72px; height: 72px; font-size: 28px; border-radius: 10px; }

/* 通讯录分组：sticky 标题 + 绿色在线信息带 */
.list-section {
  position: sticky; top: 0; z-index: 3;
  height: 28px; display: flex; align-items: center;
  padding: 0 16px; font-size: 12px; font-weight: 500; line-height: 1;
  color: var(--sub); background: var(--bg-0); letter-spacing: 0.04em;
}
.list-note {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: 12px; line-height: 1.4; color: #0a7a42;
  background: rgba(7, 193, 96, 0.09); border-bottom: 1px solid rgba(7, 193, 96, 0.16);
}
.list-note::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
@media (prefers-color-scheme: dark) { .list-note { color: #5bd39a; } }

/* 卡片：白底 + 轻阴影 + 10 圆角 */
.panel-card, .set-group, .onboard {
  background: var(--panel); border-radius: 10px; box-shadow: var(--shadow-1);
  border: 0;
}
.auth-card { width: min(520px, 100%); border: 0; box-shadow: var(--shadow-2); }
.field input, .field select, .phone-row input, .phone-row .dial-select { min-height: 44px; padding: 11px 14px; }

/* 错误提示不撑动布局 */
.field { position: relative; padding-bottom: 18px; margin-bottom: 6px; }
.field-error { position: absolute; left: 0; bottom: 0; margin: 0; }
.auth-card .field { padding-bottom: 20px; }

/* 主区内容列居中，避免 93% 空白 */
.panel { width: 100%; max-width: 760px; margin-inline: auto; }

/* 我的：分组卡片 + 图标行 */
.me-group { background: var(--panel); border-radius: 10px; box-shadow: var(--shadow-1); overflow: hidden; margin-bottom: 8px; }
.me-row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px;
  font-size: 15px; line-height: 1.4; cursor: pointer; position: relative;
}
.me-row + .me-row::before { content: ''; position: absolute; left: 56px; right: 0; top: 0; height: 1px; background: var(--line); }
.me-row .ico { width: 24px; height: 24px; color: var(--sub); flex: 0 0 auto; display: grid; place-items: center; }
.me-row .lbl { flex: 1; min-width: 0; }
.me-row .arrow { color: var(--faint); font-size: 16px; line-height: 1; }
.me-row.danger .lbl { color: var(--badge); text-align: center; }
.me-row.danger { justify-content: center; }
.me-card { display: flex; align-items: center; gap: 14px; min-height: 84px; padding: 16px; cursor: pointer; }

/* 动效 */
.cell, .me-row, .set-row, .opt-row { transition: background-color 150ms ease; }
.chat { animation: fadeIn 120ms ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.m { animation: msgIn 160ms ease-out; }
@keyframes msgIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.modal-mask { animation: fadeIn 120ms ease; }
.modal { animation: modalIn 180ms ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.badge, .rail-badge { animation: popIn 200ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes popIn { from { transform: scale(0.6); } to { transform: none; } }
@media (max-width: 860px) {
  .app.detail-open .main { transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1); }
  .cell { min-height: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 我的页卡片边距 */
.me-card { margin: 12px 12px 8px; border-radius: 10px; box-shadow: var(--shadow-1); background: var(--panel); }
.me-group { margin: 0 12px 8px; }
.me-card .profile-name { font-size: 18px; line-height: 1.35; }
.me-card .arrow { color: var(--faint); font-size: 18px; margin-left: auto; }
.me-row.active { background: var(--bg-2); }

/* 导航图标对比度（评审 §5：icon 偏灰） */
.rail-btn { color: #8b929c; }
.rail-btn:hover { color: #5c636e; }
.rail-btn.active { color: var(--green); }
.rail-me:not(.active) .rail-avatar { opacity: 0.92; }
@media (prefers-color-scheme: dark) { .rail-btn { color: #9aa3ad; } }

/* ---------------------------------------------------- V1.3 菜单与搜索 */
.cell.pinned { box-shadow: inset 3px 0 0 var(--green); }
.chat-more { margin-left: auto; }

.float-menu {
  position: fixed; z-index: 120; min-width: 168px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-3);
}
.float-item {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--text); font-size: 14px; padding: 10px 12px; border-radius: 8px; cursor: pointer;
}
.float-item:hover { background: var(--hover); }
.float-item.danger { color: var(--badge); }

.opt-row.danger { color: var(--badge); }

.search-hits { max-height: 320px; overflow-y: auto; margin-top: 10px; }
.hit-row {
  display: flex; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: transparent;
  color: var(--text); padding: 10px 4px; cursor: pointer; font-size: 13.5px;
}
.hit-row:hover { background: var(--hover); }
.hit-time { flex: 0 0 auto; color: var(--sub); font-size: 11.5px; }
.hit-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m.hit .bubble { box-shadow: 0 0 0 2px var(--green); }

/* 注册两步 */
#authForm[data-step='1'] .step2-only { display: none !important; }
#authForm[data-step='2'] .step1-only { display: none !important; }
.reg-progress { display: flex; gap: 6px; justify-content: center; margin: 2px 0 14px; }
.reg-progress .dot { width: 26px; height: 3px; border-radius: 2px; background: var(--line); transition: background 150ms; }
.reg-progress .dot.on { background: var(--green); }
.reg-back { display: block; margin: 12px auto 0; }

/* 图标按钮与标题栏操作对比度 */
.icon-btn, .list-head .icon-btn, .chat-more { color: #5f6670; }
.icon-btn:hover { background: var(--bg-2); color: #33383f; }
@media (prefers-color-scheme: dark) { .icon-btn, .chat-more { color: #b9c0c9; } }
.list-head .icon-btn { font-size: 20px; }

/* ---------------------------------------------------- V1.4 图片消息 */
.photo-btn { font-size: 18px; }
.m .msg-img {
  display: block; max-width: 260px; max-height: 320px; border-radius: 8px;
  object-fit: cover; cursor: zoom-in; background: var(--bg-2);
  box-shadow: var(--shadow-1);
}
.m.pending .msg-img { opacity: 0.65; filter: saturate(0.7); }
.m.failed .msg-img { box-shadow: 0 0 0 2px var(--badge); }
.lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, 0.82);
  display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out;
  animation: fadeIn 120ms ease;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: var(--shadow-3); }
@media (max-width: 860px) {
  .m .msg-img { max-width: 66vw; max-height: 46vh; }
}

/* P1-2 免打扰标识 / P2-3 图片失效占位 */
.cell.muted .cell-name { color: var(--sub); }
.cell-muted { margin-left: 4px; font-size: 12px; line-height: 1; opacity: 0.75; }
.img-broken {
  display: inline-flex; align-items: center; gap: 6px; padding: 12px 14px;
  border-radius: 8px; background: var(--bg-2); color: var(--sub); font-size: 13px;
}

/* ============================================================
   v1.4.2 移动端动效：侧滑返回跟手 / 更顺滑的转场
   ============================================================ */
@media (max-width: 860px) {
  .main {
    transition: transform 260ms cubic-bezier(0.32, 0.72, 0.28, 1);
    will-change: transform;
    box-shadow: none;
  }
  .app.detail-open .main {
    transition: transform 260ms cubic-bezier(0.32, 0.72, 0.28, 1);
    box-shadow: -10px 0 28px rgba(0, 0, 0, 0.14);
  }
  /* 手指拖动期间关掉过渡，完全跟手 */
  .app.dragging .main { transition: none !important; }
  .app.dragging .list { pointer-events: none; }

  /* 列表与消息区：不做橡皮筋联动，滚动更"实" */
  .list-body, .msgs {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* 会话进入时正文轻微上浮，减少"硬切"感 */
  .chat { animation: chatIn 180ms cubic-bezier(0.32, 0.72, 0.28, 1); }
  @keyframes chatIn {
    from { opacity: 0.6; transform: translateX(12px); }
    to { opacity: 1; transform: none; }
  }
  .panel { animation: chatIn 160ms cubic-bezier(0.32, 0.72, 0.28, 1); }
}

@media (prefers-reduced-motion: reduce) {
  .app.detail-open .main, .main { transition: none !important; }
  .chat, .panel { animation: none !important; }
}

/* ---------------------------------------------------- V1.6 消息翻译 */
.tr-box {
  position: relative; margin-top: 6px; padding: 8px 26px 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; line-height: 1.5; color: var(--text); max-width: 100%;
  box-shadow: var(--shadow-1);
}
.tr-tag { display: inline-block; margin-bottom: 4px; font-size: 10.5px; letter-spacing: 0.3px; color: var(--green); }
.tr-text { white-space: pre-wrap; word-break: break-word; }
.tr-loading, .tr-error { color: var(--sub); font-size: 12.5px; }
.tr-error { color: var(--badge); }
.tr-close {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px;
  border: 0; background: transparent; color: var(--sub); font-size: 15px; line-height: 1;
  cursor: pointer; border-radius: 6px;
}
.tr-close:hover { background: var(--bg-2); }
.m.me .tr-box { margin-left: auto; }
