/* ============================================================
   磨砂玻璃（Frosted Glass）设计系统
   参照 iOS / iMessage 的层级与动效节奏：
   - 彩色弥散光斑在最底层缓慢漂移，磨砂面板对其取样模糊
   - 全局细颗粒噪点叠加，形成"磨砂"而非"液态"的质感
   - 弹簧曲线（linear() 逼近阻尼弹簧）驱动弹框 / 气泡 / 按钮
   - 弹框开合用 @starting-style + allow-discrete 做入场/退场过渡
   ============================================================ */

:root {
  color-scheme: light dark;

  --bg-base: #eef1f7;
  --panel-rgb: 255, 255, 255;
  --text: #1c1c22;
  --muted: #71717c;
  --accent: #007aff;
  --accent-2: #4aa3ff;
  --accent-rgb: 0, 122, 255;
  --bad: #e0304e;
  --good: #30b558;

  /* 玻璃面板 */
  --glass: rgba(var(--panel-rgb), .58);
  --glass-strong: rgba(var(--panel-rgb), .74);
  --glass-input: rgba(255, 255, 255, .55);
  --hairline: rgba(20, 24, 46, .1);
  --glass-edge: rgba(255, 255, 255, .62);
  --fill: rgba(120, 120, 128, .14);
  --fill-strong: rgba(120, 120, 128, .26);
  --seg-thumb: rgba(255, 255, 255, .94);
  --bubble-peer: rgba(255, 255, 255, .82);
  --bubble-edge: rgba(255, 255, 255, .6);
  --shadow-panel: 0 18px 50px rgba(24, 32, 74, .16);
  --shadow-soft: 0 6px 22px rgba(24, 32, 74, .1);
  --grain-opacity: .028;
  --mask-bg: rgba(28, 32, 58, .28);
  --mask-bg-0: rgba(28, 32, 58, 0);
  --notice-bg: rgba(255, 205, 110, .5);
  --notice-text: #7a4a08;

  /* 背景弥散光斑（两层，供 body::before / ::after 使用） */
  --blob-a:
    radial-gradient(42% 52% at 12% 18%, rgba(88, 146, 255, .5), transparent 68%),
    radial-gradient(38% 44% at 88% 12%, rgba(255, 133, 196, .38), transparent 70%),
    radial-gradient(46% 52% at 82% 86%, rgba(110, 220, 190, .45), transparent 70%);
  --blob-b:
    radial-gradient(40% 46% at 22% 88%, rgba(167, 139, 250, .4), transparent 70%),
    radial-gradient(30% 36% at 55% 45%, rgba(255, 203, 148, .32), transparent 72%);

  --blur-lg: 26px;
  --blur-md: 16px;
  --r-lg: 22px;
  --r-md: 14px;

  /* 阻尼弹簧（约 12% 过冲后回稳）与常用缓动 */
  --spring: linear(0, 0.06 4%, 0.25 10%, 0.48 16%, 0.72 22%, 0.93 28%,
    1.06 34%, 1.12 40%, 1.13 44%, 1.10 50%, 1.04 58%, 0.99 66%,
    0.973 74%, 0.982 84%, 1);
  --spring-soft: cubic-bezier(.3, 1.25, .4, 1);
  --ease-out: cubic-bezier(.22, .61, .36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-base: #0a0c13;
    --panel-rgb: 28, 30, 42;
    --text: #f2f3f7;
    --muted: #9c9daa;
    --accent: #0a84ff;
    --accent-2: #4aa3ff;
    --accent-rgb: 10, 132, 255;
    --bad: #ff5470;
    --good: #32d47e;

    --glass: rgba(var(--panel-rgb), .5);
    --glass-strong: rgba(34, 37, 52, .68);
    --glass-input: rgba(255, 255, 255, .07);
    --hairline: rgba(255, 255, 255, .1);
    --glass-edge: rgba(255, 255, 255, .14);
    --fill: rgba(120, 120, 128, .22);
    --fill-strong: rgba(120, 120, 128, .36);
    --seg-thumb: rgba(126, 130, 148, .55);
    --bubble-peer: rgba(64, 66, 82, .78);
    --bubble-edge: rgba(255, 255, 255, .08);
    --shadow-panel: 0 24px 70px rgba(0, 0, 0, .55);
    --shadow-soft: 0 6px 22px rgba(0, 0, 0, .35);
    --grain-opacity: .05;
    --mask-bg: rgba(2, 4, 12, .5);
    --mask-bg-0: rgba(2, 4, 12, 0);
    --notice-bg: rgba(122, 84, 10, .55);
    --notice-text: #ffd98a;

    --blob-a:
      radial-gradient(42% 52% at 12% 18%, rgba(43, 92, 235, .32), transparent 68%),
      radial-gradient(38% 44% at 88% 12%, rgba(233, 78, 161, .18), transparent 70%),
      radial-gradient(46% 52% at 82% 86%, rgba(20, 184, 158, .2), transparent 70%);
    --blob-b:
      radial-gradient(40% 46% at 22% 88%, rgba(122, 59, 255, .22), transparent 70%),
      radial-gradient(30% 36% at 55% 45%, rgba(255, 122, 84, .1), transparent 72%);
  }
}

/* ===== 基础 ===== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg-base); }

/* 全屏细颗粒噪点：磨砂质感的来源，盖在一切之上但极淡 */
html::before {
  content: "";
  position: fixed; inset: 0; z-index: 2147483647;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 240px 240px;
}

body {
  background: transparent; color: var(--text);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  overflow: hidden;
}

/* 弥散光斑：缓慢漂移，磨砂面板隔着模糊取样它们 */
body::before, body::after {
  content: "";
  position: fixed; inset: -14%; z-index: -1;
  pointer-events: none;
  will-change: transform;
}
body::before {
  background: var(--blob-a);
  animation: drift-a 30s ease-in-out infinite alternate;
}
body::after {
  background: var(--blob-b);
  animation: drift-b 42s ease-in-out infinite alternate;
}

::selection { background: rgba(var(--accent-rgb), .28); }

.hidden { display: none !important; }
.error { color: var(--bad); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; }

/* 细窄半透明滚动条 */
#messages, #conv-list, #members-list, .modal {
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 120, 128, .35) transparent;
}
#messages::-webkit-scrollbar, #conv-list::-webkit-scrollbar,
#members-list::-webkit-scrollbar, .modal::-webkit-scrollbar { width: 10px; }
#messages::-webkit-scrollbar-thumb, #conv-list::-webkit-scrollbar-thumb,
#members-list::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb {
  background: rgba(120, 120, 128, .32);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

/* ===== 按钮与输入 ===== */
button {
  padding: 10px 18px; border: none; border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff; font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), .3),
    inset 0 1px 0 rgba(255, 255, 255, .28);
  transition: transform .45s var(--spring), box-shadow .25s var(--ease-out),
    filter .2s, background .25s, opacity .2s;
}
button:hover { filter: brightness(1.07); box-shadow: 0 7px 20px rgba(var(--accent-rgb), .38), inset 0 1px 0 rgba(255, 255, 255, .28); }
button:active { transform: scale(.95); transition-duration: .1s; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .35); }

button.ghost {
  background: var(--fill); color: var(--text);
  border: 1px solid var(--hairline); box-shadow: none;
}
button.ghost:hover { background: var(--fill-strong); filter: none; box-shadow: none; }

input {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--hairline); border-radius: var(--r-md);
  background: var(--glass-input); color: var(--text);
  font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .3s var(--ease-out), background .2s;
}
input::placeholder { color: var(--muted); opacity: .75; }
input:focus {
  border-color: rgba(var(--accent-rgb), .55);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .15);
  background: rgba(var(--panel-rgb), .8);
}

/* ===== 顶栏 ===== */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 18px; padding-top: env(safe-area-inset-top);
  min-height: calc(54px + env(safe-area-inset-top)); z-index: 20;
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  border-bottom: 1px solid var(--hairline);
  animation: bar-in .6s var(--ease-out) both;
}
#topbar h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .3px; }
#userbox { display: flex; align-items: center; gap: 12px; animation: fade-up .5s var(--ease-out) both; }
#current-username { font-size: 13px; font-weight: 600; }
#logout-btn { padding: 7px 14px; font-size: 13px; border-radius: 999px; }

#conn-status {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block;
  transition: background .3s, box-shadow .3s;
}
#conn-status[data-state="open"] { background: var(--good); box-shadow: 0 0 8px rgba(48, 200, 120, .8); }
#conn-status[data-state="connecting"] { background: #f5a623; animation: ping 1.2s var(--ease-out) infinite; }
#conn-status[data-state="closed"] { background: var(--bad); }

/* ===== 主布局 ===== */
#layout { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 280px; padding: 14px; gap: 12px;
  display: flex; flex-direction: column;
  background: rgba(var(--panel-rgb), .42);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(1.6);
  backdrop-filter: blur(var(--blur-lg)) saturate(1.6);
  border-right: 1px solid var(--hairline);
  animation: slide-in-left .55s var(--ease-out) both;
}
#create-conv-btn { width: 100%; }
#conv-list {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  list-style: none; margin: 0 -6px; padding: 0 6px;
  display: flex; flex-direction: column; gap: 4px;
}
.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r-md); cursor: pointer;
  border: 1px solid transparent;
  transition: background .2s, border-color .2s, transform .35s var(--spring-soft);
}
.conv-item:hover { background: var(--fill); }
.conv-item:active { transform: scale(.97); }
.conv-item.active {
  background: linear-gradient(180deg, rgba(var(--accent-rgb), .18), rgba(var(--accent-rgb), .1));
  border-color: rgba(var(--accent-rgb), .3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2);
}
.conv-in { animation: rise-in .5s var(--ease-out) both; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 700;
  background: linear-gradient(180deg, hsl(var(--hue, 215) 80% 66%), hsl(var(--hue, 215) 72% 52%));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35),
    0 2px 6px hsla(var(--hue, 215), 60%, 40%, .35);
}
.conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conv-count { color: var(--muted); font-size: 12px; }
.badge {
  background: linear-gradient(180deg, #ff6b81, #e93a52); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700; padding: 2px 8px;
  box-shadow: 0 2px 8px rgba(233, 58, 82, .45);
  animation: badge-pop .45s var(--spring) both;
}

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#empty-state {
  flex: 1; display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
  animation: fade-up .6s var(--ease-out) both;
}
#empty-state::before {
  content: "💬"; font-size: 30px;
  width: 76px; height: 76px; display: grid; place-items: center;
  border-radius: 26px;
  background: var(--glass); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(var(--blur-md));
  backdrop-filter: blur(var(--blur-md));
  box-shadow: var(--shadow-soft);
  animation: float 5.5s ease-in-out infinite alternate;
}

/* ===== 聊天区：消息在磨砂顶栏 / 输入条下方穿行 ===== */
#chat { flex: 1; position: relative; min-height: 0; }

#chat-header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 18px; min-height: 56px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  border-bottom: 1px solid var(--hairline);
  animation: bar-in .5s var(--ease-out) both;
}
#chat-title { font-weight: 700; font-size: 15px; }
#chat-subtitle { color: var(--muted); margin-left: 8px; font-size: 12px; }
#members-btn { padding: 7px 14px; font-size: 13px; border-radius: 999px; }

/* 返回按钮：仅手机端可见（媒体查询里恢复显示） */
#chat-back-btn {
  display: none;
  width: 34px; height: 34px; padding: 0; flex: none;
  border-radius: 50%; place-items: center;
}

#chat-notice {
  position: absolute; top: 66px; left: 0; right: 0; z-index: 6;
  margin-inline: auto; width: fit-content; max-width: 78%;
  padding: 8px 16px; border-radius: 999px; font-size: 13px;
  background: var(--notice-bg); color: var(--notice-text);
  border: 1px solid rgba(255, 255, 255, .35);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
  animation: notice-in .5s var(--spring) both;
}

#messages {
  position: absolute; inset: 0;
  padding: 76px 18px 92px;
  overflow-y: auto; overscroll-behavior: contain;
  list-style: none; margin: 0;
  display: flex; flex-direction: column; gap: 10px;
}

.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 100%; }
.msg.self { align-items: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); margin: 0 8px 3px; }
.msg .bubble {
  padding: 9px 14px; max-width: 70%;
  font-size: 15px; line-height: 1.42;
  white-space: pre-wrap; word-break: break-word;
  background: var(--bubble-peer);
  border: 1px solid var(--bubble-edge);
  border-radius: 20px 20px 20px 8px;
  box-shadow: 0 2px 8px rgba(24, 32, 74, .08);
}
.msg.self .bubble {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border: none; color: #fff;
  border-radius: 20px 20px 8px 20px;
  box-shadow: 0 4px 14px rgba(var(--accent-rgb), .35),
    inset 0 1px 0 rgba(255, 255, 255, .3);
}
.msg .bubble.undecryptable { color: var(--muted); font-style: italic; }

/* 新消息：从发送方一侧弹簧放大入场 */
.msg-new { animation: bubble-in .55s var(--spring) both; transform-origin: 0 100%; }
.msg-new.self { transform-origin: 100% 100%; }
/* 打开会话：末尾若干条依次浮现 */
.msg-cascade { animation: rise-in .5s var(--ease-out) both; animation-delay: var(--d, 0ms); }

/* ===== 输入中指示（docs/技术方案-输入中状态.md §5.3）===== */
.typing-msg {
  transform-origin: 0 100%;
  transition: opacity .16s var(--ease-out), transform .16s var(--ease-out);
}
.typing-msg.typing-out { opacity: 0; transform: scale(.9) translateY(6px); }
.typing-bubble { display: inline-flex; align-items: center; gap: 5px; padding: 13px 15px; }
.typing-bubble .dot, .conv-typing .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: typing-dot 1.3s ease-in-out infinite;
}
.typing-bubble .dot:nth-child(2), .conv-typing .dot:nth-child(2) { animation-delay: .18s; }
.typing-bubble .dot:nth-child(3), .conv-typing .dot:nth-child(3) { animation-delay: .36s; }

/* 侧栏迷你三点：有人输入时替换成员数（未读角标不受影响） */
.conv-typing { display: none; align-items: center; gap: 3px; padding: 4px 2px; }
.conv-typing .dot { width: 5px; height: 5px; background: var(--accent); }
.conv-item.typing .conv-typing { display: inline-flex; }
.conv-item.typing .conv-count { display: none; }

/* ===== 输入条 ===== */
#composer {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; gap: 8px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--glass);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  backdrop-filter: blur(var(--blur-lg)) saturate(1.7);
  border-top: 1px solid var(--hairline);
}
#composer .ghost {
  width: 38px; height: 38px; padding: 0; flex: none;
  border-radius: 50%; display: grid; place-items: center; font-size: 17px;
}
#composer .ghost:hover { transform: scale(1.08); }
#composer .ghost:active { transform: scale(.9); }

.input-pill {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: var(--glass-input);
  border: 1px solid var(--hairline); border-radius: 999px;
  padding: 3px 3px 3px 16px;
  transition: border-color .25s, box-shadow .3s var(--ease-out), background .25s;
}
.input-pill:focus-within {
  border-color: rgba(var(--accent-rgb), .5);
  box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .14);
  background: rgba(var(--panel-rgb), .75);
}
#msg-input {
  flex: 1; border: none; background: none; padding: 8px 0; font-size: 15px;
}
#msg-input:focus { box-shadow: none; background: none; }

#send-btn {
  width: 34px; height: 34px; padding: 0; flex: none;
  border-radius: 50%; display: grid; place-items: center;
  box-shadow: 0 3px 10px rgba(var(--accent-rgb), .4);
}
/* 输入框为空时收灰缩小，输入内容后弹簧回弹成蓝色 —— iMessage 的↑按钮 */
#composer:has(#msg-input:placeholder-shown) #send-btn {
  background: var(--fill-strong); color: var(--muted);
  box-shadow: none; transform: scale(.92);
}

/* ===== 弹框：磨砂玻璃卡片 + 弹簧开合 ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 50; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: var(--mask-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  transition: background-color .35s var(--ease-out),
    backdrop-filter .35s var(--ease-out),
    -webkit-backdrop-filter .35s var(--ease-out),
    display .35s allow-discrete, overlay .35s allow-discrete;
}
.modal-mask.hidden {
  background: var(--mask-bg-0);
  -webkit-backdrop-filter: blur(0px) saturate(1);
  backdrop-filter: blur(0px) saturate(1);
  transition: background-color .22s var(--ease-out),
    backdrop-filter .22s var(--ease-out),
    -webkit-backdrop-filter .22s var(--ease-out),
    display .25s allow-discrete, overlay .25s allow-discrete;
}
.modal {
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(var(--blur-lg)) saturate(1.8);
  backdrop-filter: blur(var(--blur-lg)) saturate(1.8);
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-lg);
  padding: 24px; width: min(420px, 92vw); max-height: 86vh; overflow-y: auto;
  box-shadow: var(--shadow-panel), inset 0 1px 0 var(--glass-edge);
  transition: transform .6s var(--spring), opacity .3s var(--ease-out);
}
.modal-mask.hidden .modal {
  opacity: 0; transform: scale(.94) translateY(12px);
  transition: transform .22s var(--ease-out), opacity .2s var(--ease-out);
}
@starting-style {
  .modal-mask:not(.hidden) {
    background: var(--mask-bg-0);
    -webkit-backdrop-filter: blur(0px) saturate(1);
    backdrop-filter: blur(0px) saturate(1);
  }
  .modal-mask:not(.hidden) .modal {
    opacity: 0; transform: scale(.85) translateY(30px);
  }
}

.modal h2 { margin: 0 0 12px; font-size: 17px; font-weight: 700; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; }
.modal-head .ghost {
  width: 30px; height: 30px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 16px;
}
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.modal label input { margin-top: 6px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal form > button[type="submit"] { width: 100%; margin-top: 14px; }
.modal .actions button { width: auto; margin-top: 0; }
#login-form, #register-form, #unlock-form { animation: form-in .4s var(--ease-out) both; }

/* 品牌头：登录 / 解锁弹框顶部 */
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin: 4px 0 18px; }
.brand h2 { margin: 0; font-size: 18px; }
.brand .hint { margin: 0; }
.brand-logo {
  width: 64px; height: 64px; font-size: 30px;
  display: grid; place-items: center; border-radius: 22px;
  background: linear-gradient(160deg, rgba(var(--accent-rgb), .85), rgba(var(--accent-rgb), .5));
  box-shadow: 0 10px 26px rgba(var(--accent-rgb), .35),
    inset 0 1px 0 rgba(255, 255, 255, .4);
  animation: float 5s ease-in-out infinite alternate;
}

/* 分段控件（登录 / 注册）：滑动药丸 */
.tabs {
  position: relative; display: flex; padding: 4px;
  background: var(--fill); border-radius: 14px; margin-bottom: 16px;
}
.tabs::before {
  content: ""; position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px); border-radius: 10px;
  background: var(--seg-thumb);
  box-shadow: 0 2px 8px rgba(10, 14, 40, .16), inset 0 1px 0 rgba(255, 255, 255, .3);
  transition: transform .45s var(--spring-soft);
}
.tabs[data-active="register"]::before { transform: translateX(100%); }
.tab {
  flex: 1; position: relative; z-index: 1;
  background: none; border: none; box-shadow: none;
  padding: 8px; color: var(--muted); font-weight: 600;
  transition: color .25s;
}
.tab:hover { filter: none; box-shadow: none; background: none; }
.tab.active { color: var(--text); }

.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.row button { white-space: nowrap; padding: 10px 16px; }

.search-result { margin-top: 10px; font-size: 13px; color: var(--muted); }
.search-hit {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--hairline);
  border-radius: var(--r-md); color: var(--text);
  background: var(--glass-input);
  animation: rise-in .35s var(--ease-out) both;
}
.search-hit button { padding: 7px 14px; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--fill); border: 1px solid var(--hairline);
  border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 13px;
  animation: chip-in .35s var(--spring) both;
}
.chip button {
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px;
  background: var(--fill-strong); color: var(--muted); box-shadow: none;
}
.chip button:hover { background: var(--bad); color: #fff; filter: none; }

/* ===== 附件 ===== */
.msg .bubble.att-img { padding: 4px; line-height: 0; }
.att-img img { display: block; border-radius: 17px; background: var(--fill); object-fit: cover; }
.att-img img.blur { filter: blur(6px); }
.att-img img.loaded { cursor: zoom-in; filter: none; }
.att-status { line-height: 1.4; font-size: 12px; color: var(--muted); padding: 4px 8px; }
.msg.self .att-status { color: rgba(255, 255, 255, .85); }

.msg .bubble.file-card {
  display: flex; align-items: center; gap: 10px; min-width: 230px; max-width: 70%;
}
.msg.self .file-card {
  background: var(--bubble-peer); border: 1px solid var(--bubble-edge); color: var(--text);
}
.file-icon { font-size: 24px; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 14px; word-break: break-all; }
.file-size { font-size: 12px; color: var(--muted); margin-top: 2px; }
.file-card button { white-space: nowrap; padding: 7px 14px; font-size: 13px; }
.bubble.pending { color: var(--muted); font-style: italic; }
.bubble.failed { color: var(--bad); font-style: normal; }

/* 大图查看：更深的遮罩通过变量传入，保证退场时同样能淡出 */
#lightbox { cursor: zoom-out; --mask-bg: rgba(6, 8, 18, .6); --mask-bg-0: rgba(6, 8, 18, 0); }
#lightbox img {
  max-width: 92vw; max-height: 92vh; border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .5);
  animation: lightbox-in .5s var(--spring) backwards;
  transition: transform .22s var(--ease-out), opacity .2s var(--ease-out);
}
.modal-mask.hidden img { opacity: 0; transform: scale(.92); }

/* ===== 成员列表 ===== */
#members-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; }
#members-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 6px; border-bottom: 1px solid var(--hairline); font-size: 14px;
  animation: rise-in .4s var(--ease-out) both;
}
#members-list li:last-child { border-bottom: none; }
#members-list .avatar { width: 30px; height: 30px; font-size: 13px; }
.member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#members-more { width: 100%; margin-top: 8px; }
#add-member-row { margin-top: 14px; border-top: 1px solid var(--hairline); padding-top: 6px; }

/* ===== 动画 ===== */
@keyframes drift-a {
  from { transform: translate3d(-3%, -2%, 0) scale(1.04) rotate(-2deg); }
  to { transform: translate3d(3%, 4%, 0) scale(1.12) rotate(2deg); }
}
@keyframes drift-b {
  from { transform: translate3d(3%, 2%, 0) scale(1.1) rotate(2deg); }
  to { transform: translate3d(-3%, -3%, 0) scale(1.02) rotate(-2deg); }
}
@keyframes bar-in { from { opacity: 0; transform: translateY(-12px); } }
@keyframes slide-in-left { from { opacity: 0; transform: translateX(-18px); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(14px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes bubble-in { from { opacity: 0; transform: translateY(18px) scale(.5); } }
@keyframes badge-pop { from { opacity: 0; transform: scale(.4); } }
@keyframes chip-in { from { opacity: 0; transform: scale(.7); } }
@keyframes form-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes notice-in { from { opacity: 0; transform: translateY(-14px) scale(.95); } }
@keyframes lightbox-in { from { opacity: 0; transform: scale(.86); } }
@keyframes float { from { transform: translateY(-3px); } to { transform: translateY(4px); } }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(245, 166, 35, .55); }
  100% { box-shadow: 0 0 0 8px rgba(245, 166, 35, 0); }
}

/* ============================================================
   手机端（≤768px）：列表 / 聊天双视图
   两屏各占整宽，聊天从右侧推入（iOS push）：列表左移与聊天右入
   同幅同速，边缘严丝合缝，无需为遮挡补不透明背景。
   data-view 由 ui/mobileView.js 维护；宽屏下这些选择器不生效。
   ============================================================ */
@media (max-width: 768px) {
  #layout { position: relative; overflow: hidden; }

  #sidebar {
    width: 100%; border-right: none;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    /* 入场动画会以 fill 模式占住 transform，禁用以免与滑动过渡打架 */
    animation: none;
    transition: transform .4s var(--ease-out), visibility 0s;
  }
  #main {
    position: absolute; inset: 0; z-index: 5;
    transform: translateX(100%); visibility: hidden;
    /* visibility 延迟到滑出动画结束再隐藏（列表屏时聊天不可聚焦/点击） */
    transition: transform .4s var(--ease-out), visibility 0s .4s;
  }
  #layout[data-view="chat"] #sidebar {
    transform: translateX(-100%); visibility: hidden;
    transition: transform .4s var(--ease-out), visibility 0s .4s;
  }
  #layout[data-view="chat"] #main {
    transform: none; visibility: visible;
    transition: transform .4s var(--ease-out), visibility 0s;
  }

  #chat-back-btn { display: grid; }
  #chat-header { padding: 10px 12px; gap: 10px; }
  #chat-header > div {
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  .conv-item { padding: 12px; }
  #messages { padding: 76px 12px 92px; }
  .msg .bubble { max-width: 85%; }
  .msg .bubble.file-card { max-width: 85%; }

  /* iOS Safari：输入框字号小于 16px 时聚焦会自动放大页面（#msg-input 提高优先级压过 15px 的桌面值） */
  input, #msg-input { font-size: 16px; }
}

/* 尊重系统"减弱动态效果" */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001s !important;
    transition-delay: 0s !important;
  }
}
