:root {
  --brand-1: #5b7cfa;
  --brand-2: #8b5cf6;
  --brand-soft: #eef2ff;
  --ink: #1c2333;
  --ink-2: #5a6478;
  --ink-3: #98a1b3;
  --line: #e9edf6;
  --bg: #f5f7ff;
  --card: #ffffff;
  --green: #22c55e;
  --danger: #ef4444;
  --radius: 18px;
  --shadow-sm: 0 2px 8px rgba(28, 35, 51, .05);
  --shadow-md: 0 10px 30px rgba(60, 80, 150, .10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 15px; }

/* ---------------- 通用：头像 ---------------- */
.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  user-select: none;
  box-shadow: 0 3px 10px rgba(91, 124, 250, .28);
}

/* ---------------- 登录页 ---------------- */
.auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  background:
    radial-gradient(1200px 600px at 10% -10%, #e6ecff 0%, rgba(230, 236, 255, 0) 60%),
    radial-gradient(900px 500px at 100% 110%, #f0e9ff 0%, rgba(240, 233, 255, 0) 55%),
    var(--bg);
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 26px;
  padding: 32px 26px 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, .8);
  animation: rise .45s cubic-bezier(.22, 1, .36, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.brand { text-align: center; margin-bottom: 22px; }

.brand-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  display: block;
  border-radius: 50%;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: .5px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: #f2f4fb;
  border-radius: 13px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  padding: 9px 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: all .18s ease;
}

.tab.active {
  background: #fff;
  color: var(--brand-1);
  box-shadow: 0 2px 6px rgba(28, 35, 51, .08);
}

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

.field span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: .3px;
}

.field input {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fbfcff;
  border-radius: 12px;
  padding: 12px 13px;
  outline: none;
  transition: border-color .16s, background .16s, box-shadow .16s;
}

.field input:focus {
  border-color: var(--brand-1);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(91, 124, 250, .10);
}

.field input::placeholder { color: #b6bfd2; }

.form-err {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--danger);
  background: #fff1f1;
  padding: 8px 11px;
  border-radius: 10px;
}

.btn-primary {
  width: 100%;
  border: 0;
  border-radius: 13px;
  padding: 13px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 8px 18px rgba(91, 124, 250, .30);
  transition: transform .12s ease, box-shadow .16s, opacity .16s;
}

.btn-primary:hover { box-shadow: 0 10px 24px rgba(91, 124, 250, .38); }
.btn-primary:active { transform: translateY(1px) scale(.995); }
.btn-primary:disabled { opacity: .6; cursor: default; box-shadow: none; }

/* ---------------- 主布局 ---------------- */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 320px 1fr;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 12px;
}

.me {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 1;
  min-width: 0;
}

.avatar-wrap {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  line-height: 0;
  border-radius: 14px;
  cursor: pointer;
}

.avatar-wrap:active .avatar { transform: scale(.96); }
.avatar-wrap .avatar { transition: transform .12s ease; }

.avatar-edit {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  color: var(--brand-1);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  box-shadow: 0 1px 4px rgba(28, 35, 51, .16);
}

.avatar.has-photo,
.msg-avatar.has-photo {
  background-size: cover;
  background-position: center;
  color: transparent;
}

/* 聊天窗口里好友头像可点开看大图（首字母色块不可点） */
.chat-head .avatar.has-photo,
.msg-avatar.has-photo {
  cursor: zoom-in;
}

.chat-head .avatar.has-photo:hover,
.msg-avatar.has-photo:hover {
  filter: brightness(1.06);
  box-shadow: 0 0 0 2px rgba(91, 124, 250, .35);
}

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

.me-info strong {
  font-size: 15.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-status {
  font-size: 12px;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 4px;
}

.me-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: #f2f4fb; color: var(--ink); }

.user-list {
  list-style: none;
  margin: 0;
  padding: 6px 8px 12px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
}

.user-item:hover { background: #f6f8ff; }
.user-item.active { background: var(--brand-soft); }

.user-item .avatar { width: 44px; height: 44px; flex-basis: 44px; border-radius: 15px; font-size: 16px; }

.user-main { flex: 1; min-width: 0; }

.user-top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  justify-content: space-between;
}

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

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

.user-sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

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

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

.dot-online {
  position: absolute;
  left: 42px;
  top: 42px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--green);
  border: 2.5px solid #fff;
}

.list-empty {
  padding: 40px 28px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.7;
}

.list-empty .empty-emoji { font-size: 30px; margin-bottom: 8px; }
.list-empty p { margin: 0 0 4px; color: var(--ink-2); font-weight: 600; }
.list-empty span { font-size: 12.5px; }

/* ---------------- 聊天区 ---------------- */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(800px 420px at 12% 0%, #eef2ff 0%, rgba(238, 242, 255, 0) 62%),
    radial-gradient(700px 400px at 100% 100%, #f4eeff 0%, rgba(244, 238, 255, 0) 58%),
    var(--bg);
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  gap: 4px;
  text-align: center;
  padding: 24px;
}

.ph-emoji { font-size: 42px; margin-bottom: 8px; opacity: .85; }
.chat-placeholder p { margin: 0; font-size: 14.5px; color: var(--ink-2); font-weight: 600; }
.chat-placeholder span { font-size: 12.5px; }

.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 20px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.back { display: none; }

.peer-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.head-action { margin-left: auto; }
.peer-info strong { font-size: 15.5px; font-weight: 700; }
.peer-status { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 5px; }
.peer-status.online { color: var(--green); }

.peer-status.online::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  animation: pop .18s ease-out both;
}

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

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

.bubble {
  max-width: min(560px, 74%);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.6px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-row.other .bubble {
  background: #fff;
  color: var(--ink);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}

.msg-row.mine .bubble {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(91, 124, 250, .26);
}

.bubble.bubble-media {
  padding: 4px;
  line-height: 0;
  background: #fff;
}

.msg-row.mine .bubble.bubble-media {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
}

.bubble-image {
  display: block;
  max-width: 240px;
  max-height: 320px;
  border-radius: 13px;
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(12, 16, 26, .93);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

.msg-meta {
  font-size: 11px;
  color: var(--ink-3);
  align-self: flex-end;
  padding-bottom: 2px;
  flex: 0 0 auto;
}

.msg-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  align-self: flex-end;
  margin-bottom: 6px;
  color: #c6cddb;
  line-height: 0;
  transition: color .18s ease;
}

.msg-state .tick {
  opacity: 0;
  transition: opacity .18s ease;
}

.msg-state.read { color: #8194b8; }
.msg-state.read .tick { opacity: 1; }

.msg-avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  margin-bottom: 2px;
}

.day-sep {
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-3);
  margin: 6px 0;
}

.day-sep span {
  background: rgba(255, 255, 255, .7);
  padding: 3px 10px;
  border-radius: 10px;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.8;
}

.chat-empty b { color: var(--ink-2); display: block; font-size: 14px; margin-bottom: 2px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--line);
  background: #fbfcff;
  border-radius: 15px;
  padding: 11px 14px;
  max-height: 132px;
  line-height: 1.5;
  outline: none;
  transition: border-color .16s, background .16s;
  overflow-y: auto;
}

.composer textarea:focus { border-color: var(--brand-1); background: #fff; }
.composer textarea::placeholder { color: #b6bfd2; }

.attach-btn {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: #f4f6fc;
  color: var(--ink-2);
}

.attach-btn:hover { background: #e9edf9; color: var(--brand-1); }
.attach-btn:disabled { opacity: .5; }

.composer textarea { min-width: 0; }

.send-btn {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 14px rgba(91, 124, 250, .30);
  transition: transform .12s, opacity .16s;
}

.send-btn:active { transform: scale(.94); }
.send-btn:disabled { opacity: .45; box-shadow: none; }

/* ---------------- 提示条 ---------------- */
.side-foot {
  flex: 0 0 auto;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  text-align: center;
}

.link-danger,
.link-soft {
  border: 0;
  background: transparent;
  color: #b4bccb;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}

.link-danger:hover { color: #e5484d; background: #fff5f5; }
.link-soft:hover { color: var(--brand-1); background: #f2f5ff; }

.foot-dot {
  color: #dde3ee;
  font-size: 12px;
  user-select: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(20, 26, 40, .38);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 322px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border-radius: 20px;
  padding: 22px 20px 16px;
  box-shadow: 0 18px 50px rgba(20, 30, 60, .22);
  animation: rise .2s cubic-bezier(.22, 1, .36, 1) both;
}

.modal-card h3 {
  margin: 0 0 8px;
  font-size: 16.5px;
  letter-spacing: .3px;
}

.modal-card p {
  margin: 0 0 20px;
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.65;
}

.modal-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.modal-check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand-1);
  cursor: pointer;
}

.link-plain {
  display: block;
  margin: 12px auto 0;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px;
}

.link-plain:hover { color: var(--ink-2); }

.modal-actions { display: flex; gap: 10px; }

.btn-ghost, .btn-danger {
  flex: 1;
  border: 0;
  border-radius: 12px;
  padding: 11px;
  font-size: 14.5px;
  font-weight: 600;
  transition: transform .12s, opacity .16s;
}

.btn-ghost { background: #f2f4fb; color: var(--ink-2); }
.btn-danger { background: #fff0f0; color: #e5484d; }
.btn-ghost:active, .btn-danger:active { transform: scale(.98); }

/* .modal-card p 的选择器比 .form-err 更具体，弹窗内的错误提示必须显式盖回来 */
.modal-card .form-err {
  margin: 0 0 14px;
  color: var(--danger);
  background: #fff1f1;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
}

.modal-card .modal-tip {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.6;
}

/* 弹窗底部的确认按钮：跟 .btn-ghost 等宽等高的蓝色版本 */
.modal-actions .btn-primary {
  flex: 1;
  width: auto;
  padding: 11px;
  font-size: 14.5px;
  letter-spacing: 0;
  border-radius: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translate(-50%, 10px);
  background: rgba(28, 35, 51, .92);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 12px;
  z-index: 99;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 82vw;
  text-align: center;
}

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

/* ---------------- 滚动条 ---------------- */
.user-list::-webkit-scrollbar,
.messages::-webkit-scrollbar { width: 6px; }

.user-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb {
  background: #dfe4f0;
  border-radius: 3px;
}

/* ---------------- 移动端 ---------------- */
@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    position: relative;
  }

  .sidebar { border-right: 0; }

  .chat {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: none;
  }

  .app.chat-open .chat { display: flex; }
  .app.chat-open .sidebar { display: none; }

  .back { display: flex; }

  .chat-head { padding: 10px 12px; }
  .messages { padding: 14px 12px 6px; }
  .bubble { max-width: 80%; }
  .composer { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .chat-placeholder { display: none; }
}
