:root {
  color-scheme: light;
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --ink: #111114;
  --muted: #8e8e93;
  --line: #dedee3;
  --surface: #ffffff;
  --background: #f7f7fa;
}

* { box-sizing: border-box; }
html { min-height: 100%; overflow-x: hidden; overscroll-behavior-x: none; background: var(--background); }
body {
  min-height: 100vh;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  margin: 0;
  background: var(--background);
  color: var(--ink);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { color: inherit; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.root-edge-guard {
  position: fixed;
  z-index: 30;
  top: 0;
  bottom: 0;
  left: 0;
  width: 20px;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 18px calc(92px + env(safe-area-inset-bottom));
}
.tab-page { display: none; }
.tab-page.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  min-height: 82px;
  padding: 10px 2px 13px;
}
.eyebrow { display: block; margin-bottom: 1px; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .08em; }
.page-header h1 { margin: 0; font-size: 34px; line-height: 1.05; letter-spacing: -.035em; }
.header-actions { display: flex; align-items: center; gap: 13px; padding-bottom: 1px; }
.round-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  background: #e7f1ff;
  color: var(--blue);
  font-size: 27px;
  font-weight: 350;
}
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #c7c7cc; box-shadow: 0 0 0 5px #c7c7cc25; }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 5px #34c75922; }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 5px #ff3b3020; }

.search {
  display: flex;
  align-items: center;
  height: 38px;
  margin: 1px 0 10px;
  padding: 0 7px 0 12px;
  border-radius: 11px;
  background: #e9e9ee;
}
.search > span { width: 14px; height: 14px; margin-right: 8px; border: 2px solid #8e8e93; border-radius: 50%; position: relative; }
.search > span::after { content: ""; position: absolute; width: 6px; height: 2px; right: -5px; bottom: -2px; transform: rotate(45deg); border-radius: 1px; background: #8e8e93; }
.search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 16px; }
.search button { padding: 6px 7px; border: 0; background: transparent; color: var(--blue); font-size: 14px; }

.conversation-list { overflow: hidden; margin: 0 -18px; transform: translateZ(0); backface-visibility: hidden; background: var(--surface); border-top: .5px solid var(--line); border-bottom: .5px solid var(--line); }
.conversation { display: flex; align-items: center; min-height: 76px; gap: 12px; padding: 9px 16px 9px 18px; cursor: pointer; }
.conversation + .conversation .conversation-main { border-top: .5px solid var(--line); }
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(145deg, #77a8ff, #4f72df);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -.03em;
}
.conversation:nth-child(3n+2) .avatar { background: linear-gradient(145deg, #79d0a2, #2ba467); }
.conversation:nth-child(3n+3) .avatar { background: linear-gradient(145deg, #bf9cfa, #7d5ad5); }
.avatar.small { width: 38px; height: 38px; font-size: 11px; }
.conversation-main { min-width: 0; flex: 1; padding: 11px 0; }
.conversation-head, .conversation-foot { display: flex; align-items: center; gap: 8px; }
.conversation-head strong { overflow: hidden; flex: 1; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.conversation time { color: var(--muted); font-size: 13px; }
.conversation-foot { margin-top: 3px; }
.preview { overflow: hidden; flex: 1; color: var(--muted); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.message-total { flex: 0 0 auto; color: #b0b0b5; font-size: 11px; }
.chevron { color: #c4c4c8; font-size: 27px; font-weight: 300; }
.empty { padding: 70px 20px; text-align: center; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 15px; border-radius: 50%; background: #e7f1ff; color: var(--blue); font-size: 22px; letter-spacing: 2px; }
.empty strong, .empty > span:last-child { display: block; }
.empty strong { color: var(--ink); font-size: 18px; }
.empty > span:last-child { margin-top: 5px; font-size: 13px; }

.chat-view {
  position: fixed;
  z-index: 10;
  top: var(--visual-viewport-top, 0px);
  right: 0;
  bottom: auto;
  left: 0;
  width: min(100%, 720px);
  height: var(--visual-viewport-height, 100dvh);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
  box-shadow: -8px 0 20px #00000012;
  -webkit-overflow-scrolling: touch;
  backface-visibility: hidden;
  contain: layout paint;
  touch-action: pan-y;
}
.chat-view.entering { animation: chat-enter 250ms cubic-bezier(.22,.76,.24,1) both; will-change: transform; }
.chat-view.leaving { animation: chat-leave 230ms cubic-bezier(.4,0,.8,.25) both; pointer-events: none; will-change: transform; }
.chat-view.swiping { animation: none; will-change: transform; }
@keyframes chat-enter { from { transform: translate3d(100%,0,0); } to { transform: translate3d(0,0,0); } }
@keyframes chat-leave { from { transform: translate3d(0,0,0); } to { transform: translate3d(100%,0,0); } }
.chat-header {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: calc(60px + env(safe-area-inset-top));
  padding: max(8px, env(safe-area-inset-top)) 14px 7px;
  border-bottom: .5px solid var(--line);
  background: #f7f7fa;
}
.back-button { justify-self: start; min-width: 104px; min-height: 52px; margin: -7px 0 -7px -10px; padding: 9px 20px 9px 10px; border: 0; background: transparent; color: var(--blue); font-size: 30px; line-height: 1; text-align: left; }
.back-button span { vertical-align: 4px; font-size: 16px; }
.chat-identity { display: grid; justify-items: center; min-width: 132px; }
.chat-identity strong { max-width: 210px; overflow: hidden; margin-top: 3px; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.chat-identity small { color: var(--muted); font-size: 10px; }
.chat-spacer { width: 55px; justify-self: end; }
.message-list { min-height: 0; flex: 1 1 auto; overflow-y: auto; overscroll-behavior-y: contain; padding: 18px 14px; background: #fff; -webkit-overflow-scrolling: touch; }
.message-list.loading::before { content: "正在载入消息…"; display: block; padding: 28px 0; color: var(--muted); font-size: 13px; text-align: center; }
.message-row { display: flex; margin-top: 9px; }
.message-row:first-child { margin-top: 0; }
.message-row.outbound { justify-content: flex-end; }
.bubble-stack { max-width: min(78%, 500px); }
.bubble { padding: 8px 12px; border-radius: 18px; font-size: 16px; line-height: 1.35; word-break: break-word; }
.inbound .bubble { border-bottom-left-radius: 5px; background: #e9e9eb; }
.outbound .bubble { border-bottom-right-radius: 5px; background: var(--blue); color: #fff; }
.bubble-meta { margin: 3px 5px 0; color: var(--muted); font-size: 10px; }
.outbound .bubble-meta { text-align: right; }
.load-more { display: block; margin: 10px auto; padding: 7px 13px; border: 0; border-radius: 16px; background: #e7f1ff; color: var(--blue); font-size: 13px; }
.chat-composer {
  position: relative;
  z-index: 12;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  padding: 8px 13px calc(8px + env(safe-area-inset-bottom));
  border-top: .5px solid var(--line);
  background: #f7f7fa;
}
body.keyboard-open .chat-composer { padding-bottom: 8px; }
.chat-composer textarea { min-height: 36px; max-height: 105px; flex: 1; resize: none; padding: 7px 13px; border: 1px solid #c7c7cc; border-radius: 18px; outline: 0; background: #fff; }
.chat-composer button { width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%; background: var(--blue); color: #fff; font-size: 23px; font-weight: 700; }

.group-card, .device-card, .settings-group { border: .5px solid #e5e5e8; border-radius: 15px; background: #fff; box-shadow: 0 8px 28px #22223a0a; }
.group-card { overflow: hidden; padding: 0 16px 18px; }
.field-row { display: flex; align-items: center; min-height: 54px; border-bottom: .5px solid var(--line); }
.field-row label { flex: 0 0 78px; font-size: 15px; }
.field-row input { min-width: 0; flex: 1; height: 45px; border: 0; outline: 0; background: transparent; color: var(--blue); }
.field-block { padding: 17px 0 0; }
.field-block > label { display: block; margin-bottom: 9px; color: #5b5b62; font-size: 13px; font-weight: 600; }
.composer textarea { width: 100%; min-height: 148px; padding: 12px; resize: vertical; border: .5px solid #d5d5da; border-radius: 12px; outline: 0; background: #f8f8fa; }
.composer textarea:focus { border-color: #78b3f5; background: #fff; box-shadow: 0 0 0 3px #007aff12; }
.channels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.channel { position: relative; min-width: 0; padding: 12px; text-align: left; border: 1.5px solid #e0e0e5; border-radius: 13px; background: #fafafa; }
.channel.selected { border-color: var(--blue); background: #edf6ff; }
.channel strong, .channel small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel strong { font-size: 14px; }
.channel small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.channel .check { position: absolute; top: 8px; right: 9px; color: var(--blue); }
.primary, .primary-link { display: block; width: 100%; margin-top: 18px; padding: 13px; border: 0; border-radius: 12px; background: var(--blue); color: #fff; font-weight: 700; text-align: center; text-decoration: none; }
.primary:disabled { background: #b7b7bc; }

.device-card { display: flex; align-items: center; gap: 12px; padding: 16px; }
.device-icon, .login-mark { display: grid; place-items: center; background: linear-gradient(145deg, #2f79ef, #644bdb); color: #fff; font-weight: 800; }
.device-icon { width: 47px; height: 47px; border-radius: 12px; font-size: 20px; }
.device-card > div { min-width: 0; flex: 1; }
.device-card strong, .device-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-card small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.secure { padding: 5px 8px; border-radius: 10px; background: #eaf8ef; color: #248348; font-size: 11px; font-weight: 700; }
.settings-group { overflow: hidden; margin-top: 18px; }
.settings-row { display: flex; align-items: center; min-height: 58px; gap: 12px; width: 100%; padding: 8px 14px; border: 0; background: #fff; text-align: left; }
.settings-row + .settings-row { border-top: .5px solid var(--line); }
.settings-row > div { min-width: 0; flex: 1; }
.settings-row strong, .settings-row small { display: block; }
.settings-row strong { font-size: 15px; }
.settings-row small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.button-row { cursor: pointer; }
.settings-icon { display: grid; place-items: center; flex: 0 0 auto; width: 31px; height: 31px; border-radius: 8px; background: #5856d6; color: #fff; font-size: 12px; font-weight: 700; }
.settings-icon.blue { background: var(--blue); font-size: 22px; font-weight: 400; }
.settings-icon.red { background: var(--red); }
.connection-dot { width: 13px; height: 13px; margin: 0 9px; border-radius: 50%; background: #c7c7cc; box-shadow: 0 0 0 5px #c7c7cc22; }
.connection-dot.good { background: var(--green); box-shadow: 0 0 0 5px #34c75922; }
.group-title { margin: 26px 3px 7px; color: #67676d; font-size: 13px; font-weight: 600; text-transform: uppercase; }
.fine-print { margin: 11px 14px; color: var(--muted); font-size: 11px; text-align: center; }

.tab-bar {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 720px);
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding: 5px 24px env(safe-area-inset-bottom);
  transform: translateX(-50%);
  border-top: .5px solid #c9c9ce;
  background: #f8f8fa;
}
.tab-button { display: grid; justify-items: center; align-content: center; gap: 2px; border: 0; background: transparent; color: #8e8e93; }
.tab-button.active { color: var(--blue); }
.tab-button b { font-size: 10px; font-weight: 600; }
.tab-icon { position: relative; display: block; width: 25px; height: 24px; }
.messages-icon { height: 19px; margin-top: 2px; border: 2px solid currentColor; border-radius: 11px; }
.messages-icon::after { content: ""; position: absolute; left: 3px; bottom: -5px; width: 7px; height: 7px; border-left: 2px solid currentColor; transform: skew(-30deg); }
.compose-icon { display: grid; place-items: center; border: 2px solid currentColor; border-radius: 6px; font-size: 20px; font-weight: 300; line-height: 1; }
.status-icon::before, .status-icon::after { content: ""; position: absolute; left: 1px; right: 1px; height: 7px; border: 2px solid currentColor; border-radius: 6px; }
.status-icon::before { top: 2px; }
.status-icon::after { bottom: 2px; }
body.chat-open .tab-bar { display: none; }
body.chat-open .shell { padding-bottom: 0; }
body.chat-open { overflow: hidden; }

.login-panel { max-width: 380px; margin: 18vh auto 0; padding: 28px 22px; border: .5px solid var(--line); border-radius: 22px; background: #fff; text-align: center; box-shadow: 0 18px 60px #22223a14; }
.login-mark { width: 68px; height: 68px; margin: 0 auto 18px; border-radius: 18px; font-size: 28px; }
.login-panel h1 { margin: 0; font-size: 25px; }
.login-panel p { margin: 7px 0 22px; color: var(--muted); font-size: 13px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom)); max-width: 86vw; transform: translateX(-50%); padding: 11px 15px; border-radius: 12px; background: #202024ed; color: #fff; font-size: 13px; box-shadow: 0 10px 30px #0003; }
body.chat-open .toast { bottom: calc(62px + env(safe-area-inset-bottom)); }

@media (min-width: 721px) {
  body { background: #ececf1; }
  .shell { min-height: calc(100vh - 24px); margin-top: 12px; border-radius: 24px 24px 0 0; background: var(--background); box-shadow: 0 14px 60px #22223a1c; }
  .conversation-list { margin-left: 0; margin-right: 0; border: .5px solid var(--line); border-radius: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-view.entering, .chat-view.leaving { animation-duration: 1ms; }
}
