/* 简聊 jianliao — UI */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #5b6cf9;
  --accent-2: #8b5cf6;
  --accent-grad: linear-gradient(135deg, #5b6cf9, #8b5cf6);
  --accent-soft: #eef0fe;
  --accent-text: #4553d8;

  --bg: #f4f5fa;
  --panel: #ffffff;
  --panel-2: #fafbfe;
  --line: #e8eaf1;
  --line-strong: #dde0ea;
  --text: #171d33;
  --text-sub: #7c839c;

  --bubble-mine: linear-gradient(135deg, #5f6ffa 0%, #7a5df8 100%);
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #ffffff;
  --media-ph: #e9ebf3;

  --danger: #e0526e;
  --ok: #2ea56f;
  --warn-bg: #fff6e4;
  --warn-text: #96690f;

  --shadow-sm: 0 1px 2px rgba(23, 29, 60, .05);
  --shadow-md: 0 8px 28px rgba(23, 29, 60, .10);
  --shadow-lg: 0 20px 60px rgba(23, 29, 60, .16);
  --ring: 0 0 0 3px rgba(91, 108, 249, .25);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #6d7dff;
    --accent-2: #9a6bff;
    --accent-grad: linear-gradient(135deg, #6d7dff, #9a6bff);
    --accent-soft: rgba(109, 125, 255, .14);
    --accent-text: #aab4ff;

    --bg: #0e1120;
    --panel: #171b2e;
    --panel-2: #1c2136;
    --line: rgba(255, 255, 255, .07);
    --line-strong: rgba(255, 255, 255, .12);
    --text: #e9ebf5;
    --text-sub: #8e94ad;

    --bubble-mine: linear-gradient(135deg, #5561f0 0%, #7a55ec 100%);
    --bubble-theirs: #1e2339;
    --media-ph: #232945;

    --warn-bg: rgba(255, 190, 90, .12);
    --warn-text: #e8b45c;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 28px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 70px rgba(0, 0, 0, .55);
  }
}

html, body { height: 100%; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
    "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
textarea, input { font-family: inherit; color: inherit; }

::selection { background: rgba(91, 108, 249, .28); }

/* 细滚动条 */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }

/* ---------- 通用控件 ---------- */
.btn {
  border: none; border-radius: 12px; padding: 10px 18px;
  font-size: 15px; font-weight: 600; letter-spacing: .01em;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  background: var(--accent-grad); color: #fff;
  box-shadow: 0 6px 18px rgba(91, 108, 249, .32);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-ghost {
  background: transparent; color: var(--text-sub);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: 14px; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }

.text-input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 1.5px solid var(--line-strong); border-radius: 12px; outline: none;
  background: var(--panel-2);
  transition: border-color .12s, box-shadow .12s;
}
.text-input:focus { border-color: var(--accent); box-shadow: var(--ring); }

.logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-grad);
  box-shadow: 0 10px 26px rgba(101, 92, 248, .38);
}
.logo-mark svg { display: block; }

/* ---------- 登录页 ---------- */
.auth-screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px; gap: 14px;
  background:
    radial-gradient(1100px 560px at 85% -10%, rgba(122, 93, 248, .16) 0%, transparent 60%),
    radial-gradient(900px 520px at -10% 110%, rgba(91, 108, 249, .14) 0%, transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px; padding: 44px 36px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop-in .28s cubic-bezier(.2, .9, .3, 1.2);
}
.auth-card .logo-mark { width: 76px; height: 76px; border-radius: 24px; }
.auth-title {
  font-size: 30px; font-weight: 800; letter-spacing: .22em;
  margin-top: 18px; text-indent: .22em; /* 视觉居中补偿字距 */
}
.auth-tagline {
  color: var(--text-sub); margin-top: 8px; font-size: 13.5px; letter-spacing: .04em;
}
.auth-actions { display: flex; flex-direction: column; gap: 16px; margin: 32px 0 4px; align-items: center; }
.btn-passkey { display: inline-flex; align-items: center; justify-content: center; gap: 9px; width: 100%; }
.auth-create {
  border: none; background: transparent; font-size: 13px; color: var(--text-sub);
  padding: 4px 8px; border-radius: 8px;
}
.auth-create span { color: var(--accent-text); font-weight: 600; margin-left: 2px; }
.auth-create:hover span { text-decoration: underline; text-underline-offset: 3px; }
.auth-status { min-height: 20px; font-size: 13px; color: var(--accent-text); margin-top: 10px; }
.auth-status.err { color: var(--danger); }

.create-form { display: flex; flex-direction: column; gap: 12px; margin-top: 26px; text-align: left; }
.create-hint { font-size: 12px; color: var(--text-sub); line-height: 1.5; margin-top: -4px; }
.btn-link {
  border: none; background: transparent; color: var(--text-sub);
  font-size: 13px; padding: 4px; align-self: center; border-radius: 6px;
}
.btn-link:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; }
.btn-link.inline { display: inline; padding: 0; color: var(--accent-text); font-weight: 600; }

/* 昵称非唯一,渲染时始终跟一个灰色 #ID */
.id-tag {
  color: var(--text-sub); font-weight: 500; font-size: .82em;
  font-variant-numeric: tabular-nums; margin-left: 5px;
}
.field-label { font-size: 13px; color: var(--text-sub); }

/* ---------- 主布局 ---------- */
.chat-screen { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 304px; min-width: 304px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 12px;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 800; letter-spacing: .06em; }
.brand .logo-mark { width: 28px; height: 28px; border-radius: 9px; box-shadow: 0 4px 12px rgba(101, 92, 248, .35); }
.header-actions { display: flex; align-items: center; gap: 4px; }
.me-avatar {
  width: 34px; height: 34px; border-radius: 50%; border: none; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  color: #fff; font-weight: 700; font-size: 12px; cursor: pointer;
  box-shadow: inset 0 -6px 12px rgba(0, 0, 0, .12);
  transition: transform .12s;
}
.me-avatar:hover { transform: scale(1.06); }
.me-avatar:active { transform: scale(.94); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px 10px; }
.conv-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 10px; border: none; background: transparent; border-radius: 14px;
  text-align: left; margin-bottom: 1px;
  transition: background .12s;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--accent-soft); }
/* 通用头像:可显示图片 / emoji / 首字母,背景为渐变 */
.conv-avatar, .chat-peer-avatar, .me-avatar, .profile-avatar {
  overflow: hidden;
}
.conv-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, .12), var(--shadow-sm);
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-emoji { font-weight: 400 !important; line-height: 1; }
.conv-avatar.avatar-emoji { font-size: 24px; }
.me-avatar.avatar-emoji { font-size: 18px; }
.chat-peer-avatar.avatar-emoji { font-size: 20px; }
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-weight: 650; font-size: 14.5px; }
.conv-item.active .conv-name { color: var(--accent-text); }
.conv-preview {
  font-size: 12.5px; color: var(--text-sub); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-top: 3px;
}
.conv-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.conv-time { font-size: 11px; color: var(--text-sub); font-variant-numeric: tabular-nums; }
.unread-dot {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: linear-gradient(135deg, #f4557a, #e0526e);
  color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 8px rgba(224, 82, 110, .4);
}
.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--line); text-align: center; }

/* ---------- 聊天区 ---------- */
.chat-main { flex: 1; display: flex; min-width: 0; background: var(--bg); }

.empty-pane {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; color: var(--text-sub); font-size: 14px;
}
.empty-icon {
  width: 84px; height: 84px; border-radius: 28px;
  background: var(--panel); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md); color: var(--accent);
}

.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.btn-back {
  display: none; border: none; background: transparent;
  width: 36px; height: 36px; align-items: center; justify-content: center;
  color: var(--text-sub); border-radius: 50%;
  transition: background .12s;
}
.btn-back:hover { background: var(--panel-2); color: var(--text); }
.chat-peer { display: flex; align-items: center; gap: 11px; min-width: 0; }
.chat-peer-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 11px;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 -8px 14px rgba(0, 0, 0, .12);
  flex-shrink: 0;
}
.chat-peer-name { font-weight: 700; font-size: 15.5px; }
.chat-peer-sub {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--ok); margin-top: 2px;
}
.chat-peer-sub::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 6px currentColor;
}
.chat-peer-sub.warn { color: var(--danger); }

.msg-area {
  flex: 1; overflow-y: auto; padding: 22px 20px 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.msg-row { display: flex; margin-bottom: 7px; }
.msg-row.mine { justify-content: flex-end; }
.bubble {
  max-width: min(70%, 520px); padding: 9px 14px;
  border-radius: 16px;
  font-size: 15px; line-height: 1.6; word-wrap: break-word; white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}
.msg-row.mine .bubble {
  background: var(--bubble-mine); color: var(--bubble-mine-text);
  border-bottom-right-radius: 5px;
}
.msg-row.theirs .bubble {
  background: var(--bubble-theirs);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bubble.undecryptable {
  color: var(--text-sub); font-style: italic;
  background: transparent; border: 1.5px dashed var(--line-strong);
  box-shadow: none; font-size: 13.5px;
}
/* 图片/视频消息:媒体贴边,无气泡底色 */
.bubble.media {
  padding: 0; background: transparent !important; border: none !important;
  box-shadow: none; overflow: hidden; line-height: 0;
}
.bubble img.msg-image {
  max-width: 100%; max-height: 340px; display: block; cursor: zoom-in;
  min-width: 72px; min-height: 48px;
  background: var(--media-ph);
  border-radius: 16px; border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  transition: filter .15s;
}
.bubble img.msg-image:hover { filter: brightness(.96); }
.bubble video.msg-video {
  max-width: 100%; max-height: 340px; display: block;
  border-radius: 16px; background: #000;
  box-shadow: var(--shadow-sm);
}

.attach-card {
  display: flex; align-items: center; gap: 12px; border: none;
  background: rgba(255, 255, 255, .18); border-radius: 12px; padding: 10px 13px;
  min-width: 190px; max-width: 100%; text-align: left; font-size: 14px; color: inherit;
  transition: background .12s, transform .12s;
}
.attach-card:hover { background: rgba(255, 255, 255, .3); }
.attach-card:active { transform: scale(.98); }
.msg-row.theirs .attach-card { background: var(--accent-soft); }
.msg-row.theirs .attach-card:hover { background: rgba(91, 108, 249, .2); }
.attach-card:disabled { opacity: .7; cursor: wait; }
.attach-icon {
  width: 42px; height: 42px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .25); color: #fff; position: relative;
}
.msg-row.theirs .attach-icon { background: var(--accent-grad); }
.attach-card.loading .attach-icon svg { visibility: hidden; }
.attach-card.loading .attach-icon::after {
  content: ''; position: absolute; inset: 12px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
.attach-meta { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.attach-name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px; line-height: 1.35;
}
.attach-size { font-size: 11.5px; opacity: .72; }

.msg-time-divider {
  align-self: center; font-size: 10.5px; color: var(--text-sub);
  background: var(--panel); border: 1px solid var(--line);
  padding: 3px 11px; border-radius: 999px; margin: 12px 0 9px;
  letter-spacing: .04em; font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-sm);
}

.gate-notice {
  margin: 0 20px 10px; padding: 8px 14px; border-radius: 12px;
  background: var(--warn-bg); color: var(--warn-text);
  font-size: 12.5px; text-align: center;
}

/* ---------- 输入区 ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.icon-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  border: none; background: transparent;
  border-radius: 50%; line-height: 1; color: var(--text-sub);
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, transform .12s, color .12s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent-text); }
.icon-btn .ic { display: flex; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid rgba(120, 130, 180, .3);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.msg-input {
  flex: 1; resize: none; border: 1.5px solid transparent; border-radius: 20px;
  padding: 9px 16px; font-size: 15px; line-height: 1.5; outline: none;
  max-height: 132px; background: var(--bg);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.msg-input:focus { border-color: var(--accent); background: var(--panel); box-shadow: var(--ring); }
.msg-input::placeholder { color: var(--text-sub); opacity: .8; }
.btn-send {
  width: 40px; height: 40px; flex-shrink: 0; border: none; border-radius: 50%;
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 5px 14px rgba(91, 108, 249, .38);
  transition: transform .12s, filter .12s, opacity .12s, box-shadow .12s;
}
.btn-send svg { margin-left: 2px; }
.btn-send:hover { filter: brightness(1.08); }
.btn-send:active { transform: scale(.9); }
.btn-send:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.emoji-panel {
  position: absolute; bottom: 74px; left: 14px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 10px; width: 328px; max-width: calc(100vw - 28px);
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  max-height: 244px; overflow-y: auto;
  animation: pop-in .16s cubic-bezier(.2, .9, .3, 1.15);
}
.emoji-panel button {
  border: none; background: transparent; font-size: 21px; padding: 6px;
  border-radius: 10px; transition: background .1s, transform .1s;
}
.emoji-panel button:hover { background: var(--accent-soft); transform: scale(1.12); }

/* ---------- 弹窗 / 图片查看 / 提示 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(12, 15, 30, .5);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px;
  width: 100%; max-width: 360px; box-shadow: var(--shadow-lg);
  animation: pop-in .2s cubic-bezier(.2, .9, .3, 1.2);
}
.modal h3 { font-size: 19px; font-weight: 750; }
.modal-sub { color: var(--text-sub); font-size: 13.5px; margin: 6px 0 16px; }
.modal-err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions .spacer { flex: 1; }

/* 资料弹窗 */
.profile-top { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar {
  width: 64px; height: 64px; border-radius: 50%; border: none; padding: 0; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  color: #fff; font-weight: 700; font-size: 20px; cursor: pointer; position: relative;
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, .12), var(--shadow-sm);
}
.profile-avatar.avatar-emoji { font-size: 32px; font-weight: 400; }
.profile-avatar::after {
  content: '换'; position: absolute; inset: auto 0 0 0; height: 20px;
  background: rgba(0, 0, 0, .42); color: #fff; font-size: 11px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
}
.profile-id { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.profile-id b { font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.avatar-picker {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
  margin-bottom: 16px; max-height: 132px; overflow-y: auto;
}
.avatar-picker button {
  border: none; background: var(--bg); border-radius: 10px; aspect-ratio: 1;
  font-size: 20px; line-height: 1; transition: background .1s, transform .1s;
}
.avatar-picker button:hover { background: var(--accent-soft); transform: scale(1.1); }
.avatar-picker button.sel { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { color: var(--danger); text-decoration: underline; }

.image-viewer {
  position: fixed; inset: 0; background: rgba(8, 10, 20, .9);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 28px;
}
.image-viewer img {
  max-width: 100%; max-height: 100%; border-radius: 12px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
  animation: pop-in .18s ease-out;
}

.toast-box {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(28, 33, 56, .92); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 10px 20px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, .08);
  animation: toast-in .22s cubic-bezier(.2, .9, .3, 1.2);
  max-width: min(90vw, 480px);
}
.toast.err { background: rgba(203, 60, 89, .94); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 移动端 ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; min-width: 100%; }
  .chat-screen.mobile-chat .sidebar { display: none; }
  .chat-screen:not(.mobile-chat) .chat-main { display: none; }
  .btn-back { display: block; }
  .bubble { max-width: 82%; }
  .msg-area { padding: 16px 12px 10px; }
  .composer { padding-left: 10px; padding-right: 10px; }
}
