/* ------------------------------------------------------------------
   私聊 · 界面样式
   iOS / iMessage 风：白底、蓝色发送气泡 #0A84FF、灰色接收气泡 #E9E9EB、
   18px 大圆角、无头像、毛玻璃顶栏、胶囊输入框。跟随系统深浅色。
------------------------------------------------------------------ */

:root {
  /* 基础表面 */
  --bg: #ffffff;            /* 聊天区 / 登录页底色 */
  --panel: #f2f2f7;         /* 侧栏 / 顶栏 / 输入栏，iOS 分组灰 */
  --bar: rgba(242, 242, 247, 0.82);  /* 毛玻璃栏（半透明） */
  --white: #ffffff;         /* 卡片 / 输入框表面 */
  --fill: #f2f2f2;          /* 浅填充：hover / 占位 */
  --fill-2: #e5e5ea;        /* 次级填充：disabled / 骨架 */
  --fill-3: #d1d1d6;        /* 更深填充：disabled 底 */

  --line: #c7c7cc;          /* 分隔线，iOS separator */
  --line-soft: #e5e5ea;

  --text: #000000;          /* 主文字，iOS label */
  --text-1: #1c1c1e;
  --text-2: #6d6d72;        /* secondary */
  --text-3: #8e8e93;        /* tertiary */

  --accent: #007aff;        /* iOS 系统蓝：按钮 / 链接 / 返回 / 开关 */
  --accent-dark: #0060df;
  --accent-soft: #e8f1ff;   /* 浅蓝底 */
  --green: #34c759;         /* 在线状态绿（不再当主题色） */

  --bubble-mine: #0a84ff;   /* iMessage 发送气泡蓝 */
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #e9e9eb; /* 接收气泡灰 */
  --bubble-theirs-text: #000000;

  --red: #ff3b30;           /* 未读角标、危险操作 */
  --overlay: rgba(242, 242, 247, 0.94);  /* 更新遮罩底 */

  --radius: 10px;
  --radius-card: 14px;
  --radius-bubble: 22px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-pop: 0 8px 30px rgba(0, 0, 0, 0.18);

  --sidebar-w: 300px;
  --head-h: 56px;
}

/* 深色模式：跟随系统。所有大面积颜色都在这里换成深色调，组件无需单独写 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --panel: #1c1c1e;
    --bar: rgba(28, 28, 30, 0.82);
    --white: #1c1c1e;
    --fill: #2c2c2e;
    --fill-2: #3a3a3c;
    --fill-3: #48484a;

    --line: #38383a;
    --line-soft: #2c2c2e;

    --text: #ffffff;
    --text-1: #ffffff;
    --text-2: #aeaeb2;
    --text-3: #8e8e93;

    --accent: #0a84ff;
    --accent-dark: #409cff;
    --accent-soft: #1a2b44;
    --green: #30d158;

    --bubble-mine: #0a84ff;
    --bubble-mine-text: #ffffff;
    --bubble-theirs: #262628;
    --bubble-theirs-text: #ffffff;

    --red: #ff453a;
    --overlay: rgba(0, 0, 0, 0.82);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* 手机浏览器地址栏收放会改变可视高度：dvh 跟着变，整页不会突然跳一下 */
  height: 100dvh;
  overflow: hidden;
  /* 滚到头不要带着整页回弹，也不要在顶部下拉触发刷新 */
  overscroll-behavior: none;
  background: var(--bg);
  /* 横屏时别自作主张放大字号 */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  /* 去掉双击缩放的那一下延迟，点按跟手很多 */
  touch-action: manipulation;
}

.is-hidden { display: none !important; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

::selection { background: rgba(0, 122, 255, 0.22); }

/* 细滚动条：微信的滚动条极不显眼 */
.messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar { width: 7px; }

.messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.16);
  border-radius: 4px;
}

.messages::-webkit-scrollbar-thumb:hover,
.user-list::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.28); }

.messages::-webkit-scrollbar-track,
.user-list::-webkit-scrollbar-track { background: transparent; }

/* ============================== 登录 ============================== */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 340px;
  background: transparent;
  border-radius: var(--radius-card);
  padding: 40px 30px 28px;
  text-align: center;
  animation: rise 0.28s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.brand-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  font-weight: 500;
  display: grid;
  place-items: center;
  user-select: none;
  box-shadow: 0 6px 18px rgba(0, 122, 255, 0.28);
}

.brand-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.brand-sub {
  margin: 0 0 24px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-2);
}

/* 登录 / 注册切换：iOS 分段控件样式 */
.auth-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 16px;
  padding: 3px;
  border-radius: 9px;
  background: var(--fill-2);
}

.auth-tab {
  flex: 1;
  height: 34px;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.auth-tab.is-active {
  background: var(--white);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--fill);
  outline: none;
  font-size: 15px;
  transition: border-color 0.15s, background 0.15s;
}

.login-form input::placeholder { color: var(--text-3); }

.login-form input:focus {
  background: var(--white);
  border-color: var(--accent);
}

#enterBtn {
  height: 44px;
  margin-top: 6px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}

#enterBtn:hover { background: var(--accent-dark); }

#enterBtn:disabled {
  background: var(--fill-3);
  color: #fff;
  cursor: default;
}

.login-error {
  margin: 12px 0 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--red);
  line-height: 1.5;
}

.login-foot {
  margin: 20px 0 0;
  font-size: 12px;
  color: var(--text-3);
}

/* ============================== 主框架 ============================== */

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

/* ------------------------------ 侧栏 ------------------------------ */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg);
  border-right: 0.5px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 14px 14px 12px;
  border-bottom: 0.5px solid var(--line);
}

.me {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 头像 + 昵称是一个按钮：点它看个人资料。负 margin 让点击区域比文字更大，
   但视觉上仍然贴着原来的位置，侧栏布局不变 */
.me-profile {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -4px -6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}

.me-profile:hover { background: var(--fill); }
.me-profile:active { background: var(--fill-2); }

.me-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.me-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn-state {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.4;
}

.conn-state.online { color: var(--green); }
.conn-state.offline { color: var(--red); }

.gear-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.gear-btn:hover { background: rgba(0, 0, 0, 0.06); color: var(--text); }

.list-label {
  padding: 14px 16px 6px;
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: 0.3px;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 12px;
}

.user-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  text-align: left;
  transition: background 0.12s;
}

.user-item:hover { background: var(--fill); }
.user-item.active { background: var(--fill-2); }

.user-item .avatar-wrap { position: relative; flex: 0 0 auto; }

.user-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.user-name {
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.user-time {
  font-size: 11px;
  color: var(--text-3);
  flex: 0 0 auto;
}

/* iOS：未读会话的时间戳变蓝加粗 */
.user-time.unread { color: var(--accent); font-weight: 600; }

.user-preview {
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-preview.unread { color: var(--text-2); font-weight: 500; }

.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  flex: 0 0 auto;
}

/* 头像：iOS 是正圆 */
.avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 500;
  font-size: 15px;
  user-select: none;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.avatar-lg {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  font-size: 24px;
  border-radius: 50%;
}

.dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--panel);
}

/* ------------------------------ 会话区 ------------------------------ */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

/* ------------------------------ 聊天背景 ------------------------------ */

/*
   背景做成独立的一层，absolute 铺满整块会话区。
   为什么不直接给 .messages 加背景？因为消息区是可滚动的，
   背景会跟着内容一起滚走；单独一层则固定不动，像壁纸。
*/
.chat-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-attachment: local;
}

/* 背景层之上还要垫一层暗色纱：自定义照片往往很亮，
   不压一下的话气泡上的白字/黑字会看不清 */
.chat-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.22s ease;
  background: rgba(0, 0, 0, 0.14);
}

.chat.has-bg .chat-bg {
  opacity: 1;
}

.chat.has-bg-image .chat-bg::after {
  opacity: 1;
}

/* 头栏、消息区、输入栏都抬到背景层之上 */
.chat-head,
.messages,
.composer {
  position: relative;
  z-index: 1;
}

/* 预设背景：用 CSS 渐变，不下载任何图片 */
.chat-bg[data-preset="default"] { background: none; }

.chat-bg[data-preset="aurora"] {
  background: linear-gradient(160deg, #6f7cf5 0%, #9d6ef0 45%, #e07bb4 100%);
}

.chat-bg[data-preset="sunset"] {
  background: linear-gradient(160deg, #ff9a5a 0%, #ff6f91 55%, #c96bd6 100%);
}

.chat-bg[data-preset="ocean"] {
  background: linear-gradient(165deg, #2f6fd0 0%, #3aa8d8 50%, #57d0c0 100%);
}

.chat-bg[data-preset="mint"] {
  background: linear-gradient(160deg, #4fbf9f 0%, #7fd6a8 50%, #b6e58f 100%);
}

.chat-bg[data-preset="dusk"] {
  background: linear-gradient(165deg, #2b2d5e 0%, #4b3f7a 50%, #7a4b83 100%);
}

.chat-bg[data-preset="paper"] {
  background: linear-gradient(170deg, #f6f1e8 0%, #ece4d6 60%, #e2d8c8 100%);
}

/* 深色模式下，纸纹和浅色系要压暗，否则气泡上的黑字会糊掉 */
@media (prefers-color-scheme: dark) {
  .chat-bg[data-preset="paper"] {
    background: linear-gradient(170deg, #2b2823 0%, #232019 60%, #1c1a15 100%);
  }
  .chat-bg[data-preset="aurora"],
  .chat-bg[data-preset="sunset"],
  .chat-bg[data-preset="ocean"],
  .chat-bg[data-preset="mint"] {
    filter: brightness(0.62) saturate(0.9);
  }
  .chat-bg::after {
    background: rgba(0, 0, 0, 0.2);
  }
}

/* 头栏和输入栏本来就是半透明毛玻璃（--bar 带 alpha + backdrop-filter），
   背景层在它们下面时会自动透上来，不用额外处理 */

.chat.has-bg .date-float {
  background: rgba(0, 0, 0, 0.28);
}

/* 顶栏右侧的「聊天背景」按钮 */
.head-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  margin-right: -6px;
  border-radius: 50%;
  color: var(--accent);
}

.head-btn:hover { background: var(--fill); }
.head-btn:active { background: var(--fill-2); }

.chat-head {
  height: var(--head-h);
  flex: 0 0 var(--head-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--line);
  position: relative;
}

.back-btn {
  display: none;
  width: 34px;
  height: 34px;
  margin-left: -8px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border-radius: var(--radius);
}

.back-btn:hover { background: var(--fill); }

.chat-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex: 1;
  min-width: 0;
  pointer-events: none;
}

.chat-title > span:first-child {
  font-size: 16px;
  font-weight: 600;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-status {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.3;
  height: 14px;
}

.peer-status.online { color: var(--green); }

/* 消息区 */

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 18px 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overscroll-behavior: contain;
}

/* 滚动时浮在顶部的日期，微信同款 */
.date-float {
  position: absolute;
  top: calc(var(--head-h) + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 3px 9px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.date-float.show { opacity: 1; }

.time-sep,
.day-sep {
  align-self: center;
  font-size: 12px;
  color: var(--text-3);
  margin: 10px 0 12px;
  padding: 0 6px;
  user-select: none;
}

/* 铺了背景时，日期分隔是压在图上的纯文字，很容易糊掉。
   给它加一层半透明胶囊底，跟背景无关，始终读得清。 */
.chat.has-bg .time-sep,
.chat.has-bg .day-sep {
  color: var(--text-2);
  background: var(--bar);
  padding: 3px 10px;
  border-radius: 999px;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.day-sep { margin-top: 18px; }
.day-sep:first-child { margin-top: 2px; }

/* 消息少时贴底：第一个子元素的 margin-top:auto 当"弹簧"，
   把整串消息顶到输入框上方。内容超出一屏时 free space 为负、auto 归零，
   正常向上翻历史不受影响。 */
.messages > :first-child { margin-top: auto; }

.placeholder {
  margin: auto;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
  padding: 20px;
}

.placeholder-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: var(--radius-card);
  background: var(--fill-2);
  color: #fff;
  font-size: 24px;
  display: grid;
  place-items: center;
}

/* 一行消息 = 只有气泡，没有头像（iMessage 私聊风格）。自己靠右，对方靠左 */

.msg-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 6px;
  animation: pop 0.16s ease-out;
}

.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

/* 同一人连续发言：收紧间距，气泡更贴近，像 iMessage 那样连成串 */
.msg-row.cont { margin-top: -3px; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: none; }
}

.msg {
  position: relative;
  max-width: min(74%, 480px);
  padding: 9px 14px;
  /* 20px：短消息时刚好等于半高 → 两头全圆的胶囊感，跟 iMessage 一样 */
  border-radius: var(--radius-bubble);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--bubble-theirs);
  color: var(--bubble-theirs-text);
}

.msg.mine {
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
}

/* 铺了背景后，气泡和背景可能同色（深色模式尤其明显）。
   加一层很轻的阴影，把气泡从背景上「托」起来。 */
.chat.has-bg .msg {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16);
}

/* 尾巴：iMessage 是「上圆下平」—— 气泡那一侧的底角不是正圆，
   而是一段从上往下扫出去的弧（横向窄、纵向长），尾巴就挂在这段弧的末端。
   所以底角用椭圆半径（横向固定 px、纵向按气泡高度的比例），
   尾巴再从底边末端往下甩出一个尖。 */
.msg.mine {
  border-bottom-right-radius: 11.5px 40%;
}
.msg.theirs {
  border-bottom-left-radius: 11.5px 40%;
}

.msg::after {
  content: "";
  position: absolute;
  bottom: -7px;
  width: 11px;
  height: 8px;
  pointer-events: none;
}

/* 自己：尾巴在右下，尖朝右下 */
.msg.mine::after {
  right: 11.5px;
  background: var(--bubble-mine);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

/* 对方：尾巴在左下，尖朝左下 */
.msg.theirs::after {
  left: 11.5px;
  background: var(--bubble-theirs);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* 连着发好几条时，只有最后一条带尾巴，前面的都收起来（iMessage 的做法） */
.msg-row.notail .msg::after { display: none; }

/* 图片还没下完时，气泡本身要留一块可见的占位，不能是透明的洞：
   手机上换 src 的瞬间浏览器会把画面清空，透明底看起来就是「聊天记录空了一块」 */
.msg.msg-image {
  padding: 0;
  background: var(--fill-2);
  border-radius: var(--radius-bubble);
  overflow: hidden;
  line-height: 0;
}

.msg.msg-image::after { display: none; }

.msg.msg-image img {
  display: block;
  max-width: 100%;
  max-height: 250px;
  border-radius: var(--radius-bubble);
  cursor: zoom-in;
  background: var(--fill-2);
  object-fit: cover;
}

/* 正在发送的图片：半透明遮罩 */
.msg.msg-image.sending img { opacity: 0.55; }

/* 抖一抖：居中的系统提示小标签，不占左右气泡 */
.msg-row.nudge { justify-content: center; margin-bottom: 6px; }

.msg-nudge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-2);
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--fill-2);
  animation: pop 0.16s ease-out;
}

/* 抖一抖：整个聊天窗口左右晃动几下（QQ 同款），iPhone 也能看到 */
.chat.nudge-shake { animation: nudge-shake 0.8s ease-in-out; }

@keyframes nudge-shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
  90% { transform: translateX(-4px); }
}

/* ------------------------------ 输入栏 ------------------------------ */

.composer {
  flex: 0 0 auto;
  position: relative; /* 新消息提示条以输入栏上沿为锚点 */
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--line);
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  margin-bottom: 3px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  /* iMessage 的规矩：输入栏里只有发送键是蓝的，其余图标一律灰色，
     一排全蓝会显得吵，也不像 iOS */
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--fill); color: var(--text); }

#input {
  flex: 1;
  min-height: 38px;
  max-height: 132px;
  padding: 8px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 19px;
  background: var(--white);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  overflow-y: auto;
  box-shadow: none;
}

#input::placeholder { color: var(--text-3); }

.send-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.1s;
}

.send-btn:hover:not(:disabled) { background: var(--accent-dark); }
.send-btn:active:not(:disabled) { transform: scale(0.94); }

.send-btn:disabled {
  /* 空输入时也保持蓝色圆形，只是淡一点 —— 灰色圆钮看着像「坏了」 */
  background: var(--accent);
  color: #fff;
  opacity: 0.55;
  cursor: default;
}

/* ============================ 长按菜单 ============================ */

.ctx-mask { display: none; }

.ctx-menu {
  position: fixed;
  z-index: 60;
  min-width: 132px;
  padding: 4px 0;
  background: var(--white);
  border-radius: 6px;
  box-shadow: var(--shadow-pop);
  animation: pop 0.12s ease-out;
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 9px 16px;
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}

.ctx-item:hover { background: var(--fill); }
.ctx-item.danger { color: var(--red); }

/* ============================== 弹窗 ============================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.4);
}

.modal-card {
  width: 100%;
  max-width: 340px;
  background: var(--white);
  border-radius: var(--radius-card);
  overflow: hidden;
  animation: rise 0.2s ease-out;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
  font-size: 16px;
  font-weight: 500;
}

.modal-close {
  width: 26px;
  height: 26px;
  border-radius: var(--radius);
  font-size: 20px;
  line-height: 1;
  color: var(--text-2);
  display: grid;
  place-items: center;
}

.modal-close:hover { background: var(--fill); }

.modal-body { padding: 6px 18px 4px; }

.avatar-editor {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.avatar-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
}

.field {
  display: block;
  margin-bottom: 6px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text-2);
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.field input:focus { background: var(--white); border-color: var(--accent); }

.field-error {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--red);
  line-height: 1.5;
}

/* ------------------------------ 背景选择器 ------------------------------ */

.bg-card {
  max-width: 400px;
}

.bg-scope {
  display: flex;
  gap: 6px;
  padding: 3px;
  border-radius: 10px;
  background: var(--panel);
  margin-bottom: 8px;
}

.bg-scope-btn {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}

.bg-scope-btn.is-on {
  background: var(--white);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bg-scope-btn:disabled {
  color: var(--text-3);
  cursor: default;
}

.bg-scope-hint {
  margin: 0 0 14px;
  font-size: 11.5px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
}

.bg-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.bg-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s, border-color 0.15s;
}

.bg-cell:active { transform: scale(0.94); }

.bg-cell.is-on {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--white), 0 0 0 4px var(--accent);
}

/* 预设色块的渐变，跟 .chat-bg[data-preset] 用同一套参数 */
.bg-cell[data-preset="default"] { background: var(--panel); }
.bg-cell[data-preset="aurora"] { background: linear-gradient(160deg, #6f7cf5, #9d6ef0 45%, #e07bb4); }
.bg-cell[data-preset="sunset"] { background: linear-gradient(160deg, #ff9a5a, #ff6f91 55%, #c96bd6); }
.bg-cell[data-preset="ocean"] { background: linear-gradient(165deg, #2f6fd0, #3aa8d8 50%, #57d0c0); }
.bg-cell[data-preset="mint"] { background: linear-gradient(160deg, #4fbf9f, #7fd6a8 50%, #b6e58f); }
.bg-cell[data-preset="dusk"] { background: linear-gradient(165deg, #2b2d5e, #4b3f7a 50%, #7a4b83); }
.bg-cell[data-preset="paper"] { background: linear-gradient(170deg, #f6f1e8, #ece4d6 60%, #e2d8c8); }

@media (prefers-color-scheme: dark) {
  .bg-cell[data-preset="paper"] { background: linear-gradient(170deg, #2b2823, #232019 60%, #1c1a15); }
  .bg-cell[data-preset="paper"] .bg-cell-label {
    color: #d8cfc0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.5), transparent);
  }
  .bg-cell[data-preset="aurora"],
  .bg-cell[data-preset="sunset"],
  .bg-cell[data-preset="ocean"],
  .bg-cell[data-preset="mint"] { filter: brightness(0.62) saturate(0.9); }
}

/* 「默认」块上画一个对角斜杠，表示「什么都不用」 */
.bg-cell[data-preset="default"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top right, transparent calc(50% - 1px), var(--fill-3) 50%, transparent calc(50% + 1px));
}

.bg-cell-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 0 4px;
  font-size: 10.5px;
  color: #fff;
  text-align: center;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.45), transparent);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.bg-cell[data-preset="default"] .bg-cell-label {
  color: var(--text-2);
  text-shadow: none;
  background: none;
}

/* 纸感是浅色底，白字看不见 —— 单独改成深色 */
.bg-cell[data-preset="paper"] .bg-cell-label {
  color: #4a4034;
  text-shadow: none;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.55), transparent);
}

/* 自定义图片块 */
.bg-cell.is-custom {
  background-size: cover;
  background-position: center;
}

.bg-upload {
  width: 100%;
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.bg-upload-hint {
  margin-top: 8px;
}

.modal-foot {
  display: flex;
  gap: 10px;
  padding: 16px 18px 18px;
}

.ghost-btn {
  flex: 1;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s;
}

.ghost-btn:hover { background: var(--fill); }
.ghost-btn:disabled { color: var(--text-3); cursor: default; }

.primary-btn {
  flex: 1;
  height: 38px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}

.primary-btn:hover { background: var(--accent-dark); }
.primary-btn:disabled { background: var(--fill-3); cursor: default; }

/* ============================== 看图 ============================== */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #000;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
  animation: fade 0.16s ease-out;
}

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

.lightbox img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  transform-origin: center center;
  transition: transform 0.16s ease-out;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox img.dragging { transition: none; }

.lightbox-hint {
  position: absolute;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* ============================== 提示 ============================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 12%;
  transform: translate(-50%, 8px);
  z-index: 90;
  padding: 9px 16px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.76);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 78vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================== 移动端 ============================== */

@media (max-width: 720px) {
  :root { --head-h: 50px; }

  .app { position: relative; }

  .sidebar {
    width: 100%;
    flex: 1 1 100%;
    border-right: none;
  }

  .chat {
    position: absolute;
    inset: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.22s ease-out;
    will-change: transform;
  }

  .app.show-chat .chat { transform: none; }

  .back-btn { display: flex; }

  .messages { padding: 12px 12px 8px; }

  .msg { max-width: 80%; }

  .msg.msg-image img { max-height: 200px; }

  .composer { padding-left: 10px; padding-right: 10px; }

  .date-float { top: calc(var(--head-h) + 8px); }

  .ctx-menu {
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    width: 100%;
    min-width: 0;
    border-radius: 10px 10px 0 0;
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.18);
    animation: sheetUp 0.18s ease-out;
  }

  /* 移动端底部动作面板，比贴着手指的小气泡更好点 */
  .ctx-mask {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 59;
    background: rgba(0, 0, 0, 0.28);
  }

  .ctx-item {
    padding: 15px 16px;
    text-align: center;
    font-size: 16px;
    border-bottom: 1px solid var(--fill);
  }

  .ctx-item:last-child { border-bottom: none; }

  .ctx-item.danger { font-weight: 500; }
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}

/* 极窄屏：收窄按钮，优先保证输入框宽度 */
@media (max-width: 380px) {
  .icon-btn { width: 28px; flex-basis: 28px; }
}

/* ==================================================================
   新增交互：正在输入 / 已读 / 新消息提示条 / 表情面板 / 上传进度
   ================================================================== */

/* 对方正在输入：复用头部副标题，用绿色与前文呼应，但不抢注意力 */
.peer-status.typing {
  color: var(--accent);
}

/* 自己气泡内的「已读」标记：跟在文字后另起一行，11px 足够轻 */
.msg .read-tag {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  line-height: 1;
  text-align: right;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.02em;
}

.msg .read-tag.is-read { color: rgba(255, 255, 255, 0.85); }

/* 消息里的链接：只给识别出的 http/https 加样式 */
.msg-link {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.msg-link:hover { text-decoration: underline; }

/* 蓝气泡里链接用白色，否则蓝底蓝字看不清 */
.msg.mine .msg-link { color: var(--bubble-mine-text); text-decoration: underline; }

/* 上滑加载更早的消息时的占位提示 */
.older-loading {
  align-self: center;
  padding: 6px 0 10px;
  font-size: 12px;
  color: var(--text-3);
}

/* 新消息提示条：贴在输入栏上沿，出现时轻微上浮 */
.new-pill {
  position: absolute;
  left: 50%;
  top: -40px;
  transform: translateX(-50%);
  z-index: 8;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 12px 0 14px;
  border-radius: 15px;
  background: var(--white);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  animation: pillIn 0.18s ease-out;
}

.new-pill:hover { background: #f6fff9; }

@keyframes pillIn {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* 表情面板：10 列等宽，滚一层就够 120 个 */
.emoji-panel {
  margin-top: 8px;
  max-height: 232px;
  overflow-y: auto;
  padding: 8px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
  overscroll-behavior: contain;
}

.emoji-item {
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 21px;
  line-height: 1;
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

.emoji-item:hover { background: var(--fill); }

/* 设置里的开关 */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
}

.switch-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.switch-hint { font-size: 12px; color: var(--text-3); }

.switch-input { position: absolute; opacity: 0; pointer-events: none; }

.switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  flex: 0 0 44px;
  border-radius: 13px;
  background: var(--fill-3);
  transition: background 0.18s;
}

.switch-track i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s;
}

.switch-input:checked + .switch-track { background: var(--accent); }

.switch-input:checked + .switch-track i { transform: translateX(18px); }

@media (max-width: 720px) {
  .emoji-panel { max-height: 200px; }
  .new-pill { top: -38px; }
}

/* ==================================================================
   锁屏通知与地址区（设置弹窗内）
   ================================================================== */

.push-help {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--fill);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-2);
}

.push-help summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  outline: none;
}

.push-help ol {
  margin: 10px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.5;
}

.push-help-tip {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-3);
  line-height: 1.5;
}

.link-row {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 10px;
  background: var(--fill);
  border-radius: 8px;
}

.link-box code {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-box .ghost-btn {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

/* 权限被拒或环境不支持时，把开关置灰，避免点了没反应 */
.switch-row.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ==================================================================
   提示音试听 / 推送自检
   ================================================================== */

/* 试听按钮：比开关轻一档，不抢焦点。现在独立成一行，贴着开关下方 */
.sound-test {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 26px;
  margin: 8px 0 0;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-2);
}

/* 开关本体单独包一层 label，避免点「试听」时连带切换开关 */
.switch-hit {
  flex: 0 0 auto;
  display: flex;
  cursor: pointer;
}

/* 自检按钮与输出：等宽字体，状态符号对齐才好扫 */
.diag-btn {
  flex: 0 0 auto;
  width: 100%;
  height: 32px;
  margin-top: 10px;
  font-size: 12.5px;
  color: var(--text-2);
}

.diag-out {
  margin: 10px 0 0;
  padding: 10px 12px;
  max-height: 280px;
  overflow: auto;
  background: var(--fill);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-all;
  -webkit-overflow-scrolling: touch;
}

/* ========================= 通知引导卡 ========================= */

.notify-card {
  max-width: 320px;
  padding: 26px 22px 18px;
  text-align: center;
}

.notify-bell {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.notify-title { margin: 0 0 8px; font-size: 17px; font-weight: 500; }

.notify-text {
  margin: 0 0 12px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text-2);
}

.notify-hint {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--red);
}

.notify-btn { width: 100%; height: 42px; }

.notify-later {
  width: 100%;
  margin-top: 8px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-2);
}

/* ========================= 表情面板：分组与图库 ========================= */

.emoji-panel {
  display: block;
  padding: 0;
  max-height: 300px;
  overflow: hidden;
}

.emoji-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 8px 4px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}

.emoji-tab {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--fill);
  cursor: pointer;
}

.emoji-tab.is-on { background: var(--accent-soft); color: var(--accent-dark); font-weight: 500; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 2px;
  padding: 8px;
  max-height: 250px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sticker-pane { padding: 8px; }

.sticker-search {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sticker-search input {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  outline: none;
}

.sticker-search input:focus { background: var(--white); border-color: var(--accent); }

.sticker-search button {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.sticker-search button:hover { background: var(--accent-dark); }

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sticker-item {
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: var(--radius);
  background: var(--fill);
  overflow: hidden;
  cursor: pointer;
}

.sticker-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sticker-item:hover { outline: 2px solid var(--accent); }

.sticker-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
}

/* 通知引导卡要压在设置弹窗下面：用户在设置里操作时不能被挡住 */
#notifyCard { z-index: 60; }

/* ========================= 新版本提示条 ========================= */

.update-bar {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 32px);
  padding: 9px 10px 9px 16px;
  border-radius: 999px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.24);
  animation: update-in 0.22s ease-out;
}

@keyframes update-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.update-bar #updateText {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.update-bar #updateGo {
  flex: 0 0 auto;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.update-bar #updateGo:hover { background: var(--accent-dark); }

.update-bar .update-x {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.72);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.update-bar .update-x:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }

/* ========================= 发送状态：进度与重发 ========================= */

/* 图片气泡要能盖一层绝对定位的遮罩 */
.msg.msg-image {
  position: relative;
  max-width: 240px;
}

@media (min-width: 720px) {
  .msg.msg-image { max-width: 300px; }
}

/* 上传中的遮罩：转圈 + 百分比 */
.msg-state {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  line-height: 1;
}

.msg-ring {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: msg-spin 0.8s linear infinite;
}

@keyframes msg-spin {
  to { transform: rotate(360deg); }
}

.msg-pct {
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* 失败的自己消息：描边泛红，但内容照旧保留，方便直接重发 */
.msg.is-failed {
  box-shadow: 0 0 0 2px rgba(226, 75, 74, 0.62);
}

/* 失败标记挂在自己这侧气泡左边（.msg-row.mine 是 row-reverse，追加即在左侧） */
.retry-mark {
  flex: 0 0 auto;
  align-self: center;
  width: 20px;
  height: 20px;
  margin: 0 6px;
  border-radius: 50%;
  background: #e24b4a;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  animation: retry-pop 0.18s ease-out;
}

@keyframes retry-pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .msg-ring { animation: none; }
  .retry-mark { animation: none; }
}

/* ========================= 手机端：锁成 App 的样子 ========================= */

@media (max-width: 720px) {
  /* iOS 聚焦字号小于 16px 的输入框时会把整页放大，看起来像排版坏了。
     这里的选择器要和各自原来的规则同权重或更高，否则被 #input 之类的 ID 规则压掉 */
  #input,
  .login-form input,
  .field input,
  .sticker-search input,
  textarea,
  select {
    font-size: 16px;
  }

  /* 消息区自己滚，滚到头不带着整页一起弹 */
  .messages {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* 顶栏和输入栏在这种布局下是固定的，别跟着页面缩放变高 */
  .chat-head { flex: 0 0 var(--head-h); }
}

/* ------------------------------------------------------------------
   拍照 → 滤镜 → 发送
   选图直接走系统选择器（iOS 会弹「照片图库 / 拍照 / 选取文件」）；
   选完先进滤镜层，点「发送」才真的发出去。
------------------------------------------------------------------ */

.photo-sheet {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  flex-direction: column;
  background: #0d0d0d;
  color: #fff;
  animation: fade 0.14s ease;
}

.photo-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 52px;
  padding: 0 8px 0 10px;
}

.photo-title { font-size: 15px; color: rgba(255, 255, 255, 0.86); }

.photo-x,
.photo-retake {
  min-width: 46px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.photo-x { font-size: 16px; }
.photo-x:active,
.photo-retake:active { background: rgba(255, 255, 255, 0.2); }

.photo-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 0 12px;
}

.photo-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  transition: filter 0.12s linear;
}

.photo-filters {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 12px 12px 4px;
  overflow-x: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.photo-filters::-webkit-scrollbar { display: none; }

.photo-filter {
  flex: 0 0 auto;
  width: 64px;
  padding: 0;
  border: 0;
  background: none;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.photo-filter img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
  transition: filter 0.12s linear, border-color 0.12s;
}

.photo-filter.is-on { color: #fff; }
.photo-filter.is-on img { border-color: var(--accent); }

.photo-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
}

.photo-btn {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 22px;
  font-size: 15px;
  cursor: pointer;
}

.photo-btn.ghost { background: rgba(255, 255, 255, 0.14); color: #fff; }
.photo-btn.main { background: var(--accent); color: #fff; font-weight: 600; }
.photo-btn:disabled { opacity: 0.55; cursor: default; }

/* ==================================================================
   语音
   - 语音气泡：宽度随时长变化，波形固定种子生成，播放时条状起伏
   - 录音浮层：按住说话时盖一层，上滑变红表示松手即取消
================================================================== */

.voice-btn { -webkit-touch-callout: none; user-select: none; touch-action: none; }
.voice-btn.is-pressed { background: rgba(0, 0, 0, 0.09); color: var(--accent); }

/* ------------------------------ 语音 ------------------------------ */

.msg.msg-audio {
  padding: 8px 10px;
  background: var(--bubble-theirs);
  line-height: 1;
  cursor: pointer;
  max-width: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  -webkit-touch-callout: none;
}

.msg.mine.msg-audio { background: var(--bubble-mine); }
.msg.msg-audio::after { display: none; }

.au-play {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  color: var(--bubble-theirs-text);
}

.msg.mine.msg-audio .au-play { color: var(--bubble-mine-text); }

.au-wave {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 20px;
  min-width: 0;
}

.au-wave i {
  flex: 1 1 0;
  min-width: 2px;
  max-width: 4px;
  border-radius: 2px;
  background: var(--text-3);
  transform-origin: center center;
}

.msg.mine.msg-audio .au-wave i { background: var(--bubble-mine-text); }

.msg.msg-audio.is-playing .au-wave i {
  animation: au-bounce 0.62s ease-in-out infinite alternate;
}

@keyframes au-bounce {
  from { transform: scaleY(0.42); }
  to { transform: scaleY(1); }
}

.au-len {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--bubble-theirs-text);
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
}

.msg.mine.msg-audio .au-len { color: var(--bubble-mine-text); opacity: 0.8; }

/* --------------------------- 录音浮层 --------------------------- */

.voice-mask {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.26);
}

.voice-card {
  width: 180px;
  padding: 20px 16px 16px;
  border-radius: 14px;
  background: rgba(28, 28, 28, 0.9);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: background 0.16s ease, transform 0.16s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.voice-card.is-cancel {
  background: rgba(198, 48, 48, 0.92);
  transform: scale(0.97);
}

.voice-mic {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: grid;
  place-items: center;
  animation: voice-pulse 1.4s ease-in-out infinite;
}

@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.18); }
  50% { box-shadow: 0 0 0 9px rgba(255, 255, 255, 0); }
}

.voice-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 26px;
}

.voice-bars i {
  width: 3px;
  height: 26px;
  border-radius: 2px;
  background: var(--white);
  opacity: 0.86;
  transform: scaleY(0.3);
  transition: transform 0.12s linear;
}

.voice-time {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.voice-tip {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .voice-mic { animation: none; }
  .msg.msg-audio.is-playing .au-wave i { animation: none; }
}

/* 手机上录音浮层窄一点，给两侧留空间 */
@media (max-width: 720px) {
  .voice-card { width: 168px; }
}

/* ==================================================================
   语音模式（微信式）：点麦克风，整条输入区变成「按住 说话」
   - 麦克风与键盘图标同占一个位置，靠 body.voice-mode 切换
   - 打字框与「按住 说话」长条等高，切换时不跳高度
================================================================== */

.voice-btn .ico-kb { display: none; }
body.voice-mode .voice-btn .ico-mic { display: none; }
body.voice-mode .voice-btn .ico-kb { display: block; }
body.voice-mode .voice-btn { color: var(--accent); }

.hold-btn {
  flex: 1 1 auto;
  height: 38px;
  min-height: 38px;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-soft);
  border-radius: 19px;
  background: var(--white);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
  box-shadow: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.hold-btn:hover { background: var(--fill); }

/* 按住期间只做轻微下沉，真正的状态由中央浮层负责说明 */
.hold-btn.is-pressed {
  background: var(--fill-2);
  color: var(--text-2);
  transform: scale(0.994);
}

@media (max-width: 720px) {
  .hold-btn { height: 36px; min-height: 36px; font-size: 14.5px; }
}

/* ==================================================================
   设置里的「个人资料」入口 / 退出登录
   ================================================================== */

.nav-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px 14px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  text-align: left;
  cursor: pointer;
}

.nav-ico {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  color: var(--text-2);
}

.nav-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-text b { font-size: 14.5px; font-weight: 500; color: var(--text); }
.nav-text i { font-size: 12px; font-style: normal; color: var(--text-3); }
.nav-arrow { color: var(--text-3); font-size: 18px; line-height: 1; }

.nav-row:hover .nav-text b { color: var(--accent); }

.danger-zone {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}

.danger-btn {
  width: 100%;
  height: 38px;
  border-radius: var(--radius);
  border: 1px solid rgba(220, 60, 60, 0.3);
  background: var(--white);
  color: var(--red);
  font-size: 14px;
  transition: background 0.15s;
}

.danger-btn:hover { background: rgba(220, 60, 60, 0.06); }
.danger-btn:disabled { color: var(--text-3); border-color: var(--line); cursor: default; }

/* ==================================================================
   没头像的一次性提醒条（列表上方，普通流式布局，不遮挡任何内容）
   ================================================================== */

.avatar-nudge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 2px;
  padding: 8px 8px 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(0, 122, 255, 0.18);
  animation: fade 0.2s ease;
}

.avatar-nudge.is-hidden { display: none; }

.nudge-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12.5px;
  color: var(--accent-dark);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nudge-go {
  flex: 0 0 auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.nudge-go:hover { background: var(--accent-dark); }

.nudge-x {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: var(--accent-dark);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.nudge-x:hover { color: var(--text); background: var(--fill); }

/* ==================================================================
   更新遮罩：点「立即更新」后先给反馈，别让人对着卡住的界面猜
   ================================================================== */

.update-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade 0.16s ease;
}

.update-overlay.is-hidden { display: none; }

.update-box {
  width: min(280px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 26px 22px 22px;
  background: var(--white);
  border-radius: var(--radius-card);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.12);
}

.update-ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid rgba(7, 193, 96, 0.18);
  border-top-color: var(--accent);
  animation: msg-spin 0.8s linear infinite;
}

.update-title {
  margin: 4px 0 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}

.update-sub {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.5;
}

.update-track {
  width: 100%;
  height: 4px;
  margin-top: 6px;
  border-radius: 2px;
  background: var(--fill-2);
  overflow: hidden;
}

.update-track i {
  display: block;
  width: 6%;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.35s ease;
}

/* ==================================================================
   历史加载骨架：没有本地缓存时别留一片空白
   ================================================================== */

.hist-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px;
}

.hist-skeleton .sk-row {
  display: flex;
  align-items: flex-start;
}

.hist-skeleton .sk-row.mine { justify-content: flex-end; }

.hist-skeleton .sk-bubble {
  height: 36px;
  width: 58%;
  border-radius: 18px;
  background: var(--fill-2);
  animation: sk-pulse 1.3s ease-in-out infinite;
}

.hist-skeleton .sk-row.mine .sk-bubble { width: 44%; background: var(--accent-soft); }
.hist-skeleton .sk-row:nth-child(3) .sk-bubble { width: 34%; }
.hist-skeleton .sk-row:nth-child(4) .sk-bubble { width: 50%; }

.hist-skeleton .sk-hint {
  margin: 6px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

@keyframes sk-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ==================================================================
   深色微调：浅色下靠黑色半透明做的细节，深色下要换成白色半透明
   否则 hover / 滚动条 / 日期浮层在深底上几乎看不见
================================================================== */

@media (prefers-color-scheme: dark) {
  .messages::-webkit-scrollbar-thumb,
  .user-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
  }
  .messages::-webkit-scrollbar-thumb:hover,
  .user-list::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.34); }

  .date-float { background: rgba(255, 255, 255, 0.18); }

  .modal { background: rgba(0, 0, 0, 0.62); }
  .ctx-mask { background: rgba(0, 0, 0, 0.5); }

  .gear-btn:hover { background: rgba(255, 255, 255, 0.1); }
  .voice-btn.is-pressed { background: rgba(255, 255, 255, 0.12); }
  .ctx-item:hover { background: var(--fill); }
}
