:root {
  --bg: #ededed;
  --me: #95ec69;
  --other: #ffffff;
  --line: #dcdcdc;
  --text: #191919;
  --muted: #9a9a9a;
  --accent: #2f6fed;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: #f2f3f5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.screen { height: 100%; height: 100dvh; }

/* ---------- 登录 ---------- */
#login {
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: #0d0f16 url("/bg-music.jpg") center / cover no-repeat;
}
.login-box {
  width: 100%; max-width: 340px; padding: 26px 22px 22px;
  background: rgba(255, 255, 255, .94); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.site-title { font-size: 22px; font-weight: 600; letter-spacing: 2px; color: #2a2f37; text-align: center; margin-bottom: 6px; }
.login-sub { font-size: 12px; letter-spacing: 2px; color: #8b919a; text-align: center; margin-bottom: 22px; }
.login-foot {
  position: fixed; left: 0; right: 0; bottom: 18px; text-align: center;
  font-size: 11px; letter-spacing: 1px; color: rgba(255, 255, 255, .42); pointer-events: none;
}
.field { display: block; margin-bottom: 14px; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px; color: var(--text);
  background: #f7f7f8; border: 1px solid #e4e5e8; border-radius: 8px; outline: none;
}
.field input:focus { border-color: #b9c9ea; background: #fff; }
.primary {
  width: 100%; margin-top: 8px; padding: 12px; font-size: 15px; font-weight: 600;
  color: #fff; background: #2f6fed; border: none; border-radius: 8px; cursor: pointer;
}
.primary:active { background: #2559c2; }
.tip { min-height: 18px; margin-top: 12px; font-size: 13px; color: #d0544b; text-align: center; }
.tip.strong { color: #333; font-size: 14px; margin: 0 0 14px; }

/* ---------- 主界面 ---------- */
#main.no-top { padding-top: 0; }
#main.no-top .topbar { display: none; }
#main { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; padding-top: calc(50px + env(safe-area-inset-top)); }
.topbar {
  height: 50px; flex: 0 0 auto; display: flex; align-items: center; justify-content: flex-end;
  padding: 0 14px; background: #ededed; border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  height: calc(50px + env(safe-area-inset-top));
}
.topbar { position: fixed; left: 0; right: 0; top: 0; z-index: 100; }
.topbar .title {
  position: absolute; left: 0; right: 0; text-align: center; pointer-events: none;
  font-size: 16px; font-weight: 500; color: #2a2f37;
}
.tools { display: flex; align-items: center; gap: 8px; }
.icon {
  background: none; border: none; font-size: 17px; color: #5b626b; cursor: pointer;
  width: 32px; height: 32px; border-radius: 6px;
}
.icon:active { background: rgba(0,0,0,.05); }
.ghost {
  background: none; border: 1px solid #cfd2d7; color: #5b626b;
  padding: 5px 11px; border-radius: 6px; font-size: 13px; cursor: pointer;
}

.chat {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background-color: var(--bg);
  background-image: none;
  background-size: cover;
  background-position: center;
}
.unread-pill {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 30; padding: 5px 14px; font-size: 12px; line-height: 1.5;
  color: #576b95; background: rgba(255, 255, 255, .94); border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12); cursor: pointer; white-space: nowrap;
}
#main.no-top .unread-pill { top: 10px; }

.chat.bg-default { background-color: #ededed; }
.chat.bg-paper { background-color: #f4ede1; }
.chat.bg-gray { background-color: #dfe3e8; }
.chat.bg-dark { background-color: #303338; }
.chat-inner { padding: 12px 12px 12px; min-height: 100%; }

.row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.row.me { flex-direction: row-reverse; }
.avatar {
  width: 40px; height: 40px; border-radius: 4px; flex: 0 0 auto; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff; background: #8f97a3;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.a05 { background: #4a7bd1; }
.avatar.a06 { background: #3f9c6d; }
.col { max-width: 70%; }
.bubble {
  position: relative; padding: 8px 12px; border-radius: 4px; font-size: 17px; line-height: 1.4;
  word-break: break-word; white-space: pre-wrap; background: var(--other);
}
.bubble::before {
  content: ""; position: absolute; top: 11px; width: 0; height: 0;
  border: 5px solid transparent;
}
.row.other .bubble::before { left: -9px; border-right-color: var(--other); }
.row.me .bubble { background: var(--me); }
.row.me .bubble.bubble-emoji, .row.other .bubble.bubble-emoji { background: none; padding: 0; }
.row.me .bubble::before { right: -9px; border-left-color: var(--me); }
.tag-recall {
  display: inline-block; margin-top: 4px; font-size: 12px; line-height: 1.6; color: #a3a3a3;
}.time-sep { text-align: center; font-size: 12px; color: #b2b2b2; margin: 4px 0 16px; }
.recall-sep { text-align: center; margin: 2px 0 16px; }
.recall-sep span { display: inline-block; padding: 3px 10px; font-size: 12px; line-height: 1.5; color: #8f8f8f; background: rgba(255, 255, 255, .72); border-radius: 4px; }
.chat.bg-dark .tag-recall { color: #a3a3a3; }.chat.bg-dark .time-sep { color: #c9ccd2; }

.composer {
  flex: 0 0 auto; display: flex; gap: 6px; align-items: flex-end;
  padding: 7px 10px calc(7px + env(safe-area-inset-bottom));
  background: #f7f7f7; border-top: 1px solid #e5e5e5;
}
.composer .textbox {
  flex: 1; min-width: 0; box-sizing: border-box; min-height: 40px; max-height: 120px; overflow-y: auto;
  padding: 9px 12px; font-size: 17px; font-family: inherit; color: var(--text); line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  background: #fff; border: none; border-radius: 4px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.composer .textbox img.emo {
  display: inline-block; width: 24px; height: 24px; vertical-align: -6px; margin: 0 1px;
  -webkit-user-drag: none;
}
.send {
  flex: 0 0 auto; height: 32px; margin-bottom: 4px; padding: 0 13px; font-size: 15px; font-weight: 500;
  color: #fff; background: #07c160; border: none; border-radius: 4px; cursor: pointer;
}
.send:active { background: #06ad56; }

.mini, .attach {
  flex: 0 0 auto; height: 40px; width: 32px; margin: 0 2px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  color: #181818; background: none; border: none; border-radius: 4px; cursor: pointer;
}
.mini:active, .attach:active { background: rgba(0, 0, 0, .05); }
.mini svg, .attach svg { display: block; }
#mb-lock { width: 26px; margin-left: 0; font-size: 15px; color: #57606a; }

@media (min-width: 620px) {
  .bubble { font-size: 15px; }
  .composer .textbox { font-size: 15px; }
  .bubble.bubble-img .img-note { font-size: 15px; }
}
.col.img-col { max-width: 62%; }
.bubble.bubble-img { padding: 0; background: none; }
.row.other .bubble.bubble-img { background: none; }
.bubble.bubble-img::before { display: none; }
.bubble.bubble-img img { display: block; max-width: 100%; max-height: 320px; width: auto; height: auto; border-radius: 4px; cursor: pointer; }
.bubble.bubble-img .img-note { padding: 8px 12px; font-size: 17px; background: var(--other); border-radius: 4px; }
.row.me .bubble.bubble-img .img-note { background: var(--me); }
.bubble.bubble-img .img-loading { padding: 10px 12px; font-size: 13px; color: #8a8a8a; background: var(--other); border-radius: 4px; }
/* ---------- 配对弹层 ---------- */
.pair {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); padding: 24px;
}
.pair-box {
  width: 100%; max-width: 360px; background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.pair-title { font-size: 16px; font-weight: 600; color: #2a2f37; margin-bottom: 10px; }
.pair-tip { font-size: 13px; color: #6b6b6b; line-height: 1.6; margin-bottom: 12px; }
.pair-input {
  width: 100%; padding: 10px 12px; font-size: 13px; color: var(--text); letter-spacing: .4px;
  background: #f7f7f8; border: 1px solid #e4e5e8; border-radius: 8px; outline: none; margin-bottom: 12px;
}
.pair-input[readonly] { color: #2f6fed; user-select: all; }

/* ---------- 位置面板 ---------- */
.pair-link {
  display: block; text-align: center; text-decoration: none; padding: 11px;
  border-radius: 8px; background: #2f6fed; color: #fff; font-size: 15px; font-weight: 600;
  margin-bottom: 8px;
}
.pair-close {
  width: 100%; padding: 10px; border: 1px solid #cfd2d7; background: #fff; color: #5b626b;
  border-radius: 8px; font-size: 14px; cursor: pointer;
}

/* ---------- 顶栏菜单 ---------- */
.menu {
  position: fixed; bottom: calc(120px + env(safe-area-inset-bottom)); right: 12px; z-index: 95; min-width: 150px;
  background: #fff; border: 1px solid #e4e5e8; border-radius: 8px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px; background: none;
  border: none; font-size: 14px; color: #2a2f37; border-radius: 6px; cursor: pointer;
}
.menu-item:active { background: #f2f3f5; }

/* ---------- 登录设备 ---------- */
.device-box { max-width: 400px; }
.device-list {
  max-height: 52vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  margin: 0 -2px 12px; padding: 0 2px;
}
.device-group + .device-group {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid #eceef1;
}
.device-account {
  font-size: 13px; font-weight: 600; color: #6b6b6b; margin-bottom: 7px;
}
.device-row {
  padding: 10px 12px; margin-bottom: 8px;
  background: #fafbfc; border: 1px solid #eceef1; border-radius: 8px;
}
.device-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.device-name { font-size: 14px; font-weight: 600; color: #2a2f37; }
.device-state {
  flex: 0 0 auto; padding: 2px 7px; border-radius: 10px;
  font-size: 11px; line-height: 16px;
}
.device-state.on { color: #1f7a4d; background: #e5f5ec; }
.device-state.off { color: #8a8f98; background: #f0f1f3; }
.device-meta { margin-top: 5px; font-size: 12px; color: #8a8f98; line-height: 1.5; }
.device-empty { padding: 8px 0; font-size: 13px; color: #9a9a9a; }
.act-row { display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px solid #f2f3f5; }
.act-row:last-child { border-bottom: none; }
.act-time { flex: 0 0 auto; width: 46px; font-size: 12px; line-height: 20px; color: #9a9a9a; }
.act-main { flex: 1 1 auto; min-width: 0; }
.act-title { font-size: 14px; line-height: 20px; color: #2a2f37; }
.act-sub { margin-top: 2px; font-size: 12px; line-height: 1.5; color: #8a8f98; word-break: break-word; }

/* ---------- 发送状态 / 消息菜单 / 新设备 ---------- */
.send-status {
  padding: 7px 14px; font-size: 12px; line-height: 1.5; color: #a35c00;
  background: #fff7e8; border-top: 1px solid #f0e2c8; cursor: pointer;
}
.send-status.hidden { display: none; }
.msg-menu {
  position: fixed; z-index: 70; min-width: 118px; padding: 5px;
  background: #fff; border: 1px solid #e4e5e8; border-radius: 9px;
  box-shadow: 0 8px 24px rgba(0,0,0,.16);
}
.msg-menu button {
  display: block; width: 100%; padding: 9px 12px; border: none; background: none;
  font-size: 14px; color: #2a2f37; text-align: left; border-radius: 6px; cursor: pointer;
}
.msg-menu button:active { background: #f2f3f5; }
.msg-menu button.hidden { display: none; }
.device-new {
  display: inline-block; margin-left: 6px; padding: 1px 5px; border-radius: 4px;
  font-size: 10px; line-height: 15px; font-weight: 600; color: #b26a00; background: #fff3d6;
}

/* ---------- 引用 / 图片查看 / 保存通知 ---------- */
.quote-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; background: #f2f3f5; border-top: 1px solid var(--line);
  font-size: 12px; color: #6b7280;
}
.quote-bar-text {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-left: 3px solid #b9c2cf; padding-left: 8px;
}
.quote-bar-x { background: none; border: none; font-size: 18px; color: #8b919a; cursor: pointer; padding: 0 6px; }
.quote-in {
  margin-bottom: 4px; padding: 6px 9px; font-size: 12px; line-height: 1.45;
  color: #5b626b; background: rgba(0, 0, 0, .055); border-radius: 5px;
  border-left: 3px solid #c3cad4; word-break: break-word;
}
.row.me .quote-in { border-left: none; border-right: 3px solid #7bbf5a; text-align: right; }
.bubble img { cursor: zoom-in; }
.imgview {
  position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px; padding: 22px;
  background: rgba(0, 0, 0, .93);
}
.imgview img { max-width: 100%; max-height: 76%; object-fit: contain; }
.imgview-bar { display: flex; gap: 22px; }
.imgview-bar button {
  padding: 9px 22px; font-size: 15px; color: #fff; background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .3); border-radius: 22px; cursor: pointer;
}
.saved-note { padding: 7px 10px; }
.saved-text { font-size: 13px; color: #4b5563; }
.saved-thumb { margin-top: 6px; font-size: 12px; color: #9a9a9a; }
.saved-thumb img { max-width: 138px; max-height: 138px; border-radius: 5px; display: block; cursor: zoom-in; }
.file-hidden { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }


/* ---------- 表情与更多 ---------- */
.emoji-panel {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom));
  z-index: 80; display: flex; flex-direction: column;
  height: 42vh; max-height: 380px; background: #f7f7f7; border-top: 1px solid var(--line);
}
.emoji-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; background: #f7f7f7; border-bottom: 1px solid #e8eaed;
}
.emoji-search-btn {
  flex: 0 0 auto; width: 30px; height: 30px; padding: 0; font-size: 15px; line-height: 1;
  color: #57606a; background: none; border: none; border-radius: 15px; cursor: pointer;
}
.emoji-search-btn.on { background: #e6e8eb; }
.emoji-cats {
  flex: 1 1 auto; display: flex; gap: 5px; overflow-x: auto; overflow-y: hidden;
  white-space: nowrap; padding: 2px 2px; -ms-overflow-style: none; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.emoji-cats::-webkit-scrollbar { display: none; }
.emoji-cat {
  flex: 0 0 auto; padding: 5px 11px; font-size: 12.5px; line-height: 1.2; color: #57606a;
  background: #fff; border: 1px solid #e3e5e8; border-radius: 14px; cursor: pointer;
}
.emoji-cat.on { color: #1a1a1a; background: #95ec69; border-color: #8bdd5f; font-weight: 600; }
.emoji-search {
  flex: 0 0 auto; display: flex; gap: 8px; align-items: center;
  padding: 6px 8px; background: #f7f7f7; border-bottom: 1px solid #e8eaed;
}
.emoji-search input {
  flex: 1; min-width: 0; height: 32px; padding: 0 12px; font-size: 14px; color: var(--text);
  background: #fff; border: 1px solid #e3e5e8; border-radius: 16px; outline: none;
  -webkit-appearance: none;
}
.emoji-search button {
  flex: 0 0 auto; padding: 0 6px; height: 32px; font-size: 13px; color: #57606a;
  background: none; border: none; cursor: pointer;
}
.emoji-grid {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  padding: 8px 6px; align-content: start;
}
.emoji-item {
  height: 42px; padding: 0; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 8px; cursor: pointer;
}
.emoji-item:active { background: #e6e8eb; }
.emoji-item img { width: 34px; height: 34px; object-fit: contain; display: block; }
.emoji-empty { padding: 22px 0; text-align: center; font-size: 13px; color: #9aa0a6; }
.emoji-credit {
  flex: 0 0 auto; padding: 3px 8px calc(3px + env(safe-area-inset-bottom));
  text-align: center; font-size: 10px; color: #b7bcc3; background: #f7f7f7;
}
#main.emoji-open .chat-inner { padding-bottom: 44vh; }
@media (min-width: 620px) {
  .emoji-panel { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 10px 10px 0 0; }
}
.col.emoji-col { max-width: 46%; }
.bubble.bubble-emoji { padding: 0; background: none; }
.bubble.bubble-emoji::before { display: none; }
.bubble.bubble-emoji img { display: block; width: 112px; height: 112px; object-fit: contain; }
.bubble img.emoji-inline {
  display: inline-block; width: 1.3em; height: 1.3em; vertical-align: -0.28em; margin: 0 1px;
}

.sheet {
  position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end;
}
.sheet-box {
  width: 100%; background: #fff; border-radius: 12px 12px 0 0;
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.sheet-item {
  display: block; width: 100%; padding: 15px 10px; font-size: 16px; color: #2a2f37;
  background: none; border: none; border-bottom: 1px solid #f0f0f0; cursor: pointer;
}
.sheet-item:active { background: #f2f3f5; }
.sheet-cancel { margin-top: 6px; border-bottom: none; color: #5b627b; border-radius: 8px; }


/* ---------- 图片上传进度 ---------- */
.bubble.bubble-img { position: relative; }
.img-progress {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .18); border-radius: 4px;
}
.img-progress.done { display: none; }
.img-progress svg { width: 46px; height: 46px; transform: rotate(-90deg); }
.img-progress .ring-bg { fill: rgba(0, 0, 0, .35); stroke: rgba(255, 255, 255, .35); stroke-width: 2.5; }
.img-progress .ring-fg { fill: none; stroke: #fff; stroke-width: 2.5; stroke-linecap: round; transition: stroke-dashoffset .2s linear; }
.img-progress-num { position: absolute; font-size: 11px; color: #fff; }
