:root {
  --accent: #3390ec;
  --accent-dark: #2b7fd4;
  --bg: #ffffff;
  --bg-chat: #e6ebee;
  --line: #e4e9ed;
  --text: #17212b;
  --text-dim: #8b9aa8;
  --bubble-out: #eeffde;
  --bubble-in: #ffffff;
  --shadow: 0 2px 8px rgba(16, 35, 47, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：hidden 必须能盖住下面所有 display:flex/grid */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* ---------------- 登录 ---------------- */
.auth {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, #4aa3f0, #2b7fd4 60%, #1f6cb8);
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 30px 26px 22px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.auth-logo { color: var(--accent); display: flex; justify-content: center; margin-bottom: 6px; }
.brand {
  text-align: center; font-size: 13px; letter-spacing: 3px; font-weight: 700;
  color: var(--accent); margin-bottom: 10px; opacity: .8;
}
.auth-card h1 { font-size: 22px; text-align: center; margin: 0 0 18px; font-weight: 600; }
.auth-tabs { display: flex; gap: 4px; background: #f1f4f7; border-radius: 10px; padding: 4px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 8px; border-radius: 8px; font-size: 14px; color: var(--text-dim);
  transition: .15s;
}
.tab.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 500; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .modal-body input {
  width: 100%; padding: 11px 12px; border: 1.5px solid var(--line); border-radius: 9px;
  font-size: 15px; outline: none; transition: .15s; background: #fff;
}
.field input:focus, .modal-body input:focus { border-color: var(--accent); }
.primary {
  width: 100%; padding: 12px; background: var(--accent); color: #fff;
  border-radius: 9px; font-size: 15px; font-weight: 500; margin-top: 6px; transition: .15s;
}
.primary:hover { background: var(--accent-dark); }
.primary:active { transform: scale(.99); }
.primary.sm { padding: 9px; font-size: 14px; margin-top: 10px; }
.auth-msg { min-height: 18px; font-size: 13px; color: #e53935; margin: 10px 0 0; text-align: center; }
.auth-tip { font-size: 12px; color: var(--text-dim); text-align: center; margin: 6px 0 0; }

/* ---------------- 布局 ---------------- */
.app { display: flex; height: 100%; height: 100dvh; }

.sidebar {
  width: 380px; min-width: 380px; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: #fff;
}
.side-head {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 18px; border-bottom: 1px solid var(--line);
}
.side-title { font-size: 17px; font-weight: 600; }
.side-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  color: #5b6b7b; transition: .15s;
}
.icon-btn:hover { background: #f1f4f7; }
.icon-btn.on { color: var(--accent); }

.search-wrap { padding: 8px 12px; }
.search-wrap input {
  width: 100%; padding: 9px 14px; border-radius: 18px; border: 0;
  background: #f1f4f7; font-size: 14px; outline: none;
}
.search-wrap input:focus { background: #e9eef3; }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 6px 12px; }
.chat-item {
  display: flex; gap: 11px; padding: 9px 12px; border-radius: 10px;
  align-items: center; transition: .12s; cursor: pointer;
}
.chat-item:hover { background: #f4f7fa; }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .chat-preview, .chat-item.active .chat-time { color: rgba(255,255,255,.85); }
.chat-item.active .badge { background: #fff; color: var(--accent); }
.chat-item-text { flex: 1; min-width: 0; }
.chat-row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.chat-row2 { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.chat-preview {
  font-size: 13.5px; color: var(--text-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.badge {
  min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center;
  padding: 0 6px; flex-shrink: 0;
}
.badge.mute { visibility: hidden; }
.side-empty { padding: 40px 20px; text-align: center; color: var(--text-dim); font-size: 14px; line-height: 1.8; }
.side-empty span { font-size: 12.5px; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 17px; flex-shrink: 0; user-select: none;
}
.avatar.sm { width: 36px; height: 36px; font-size: 14px; }
.avatar.lg { width: 54px; height: 54px; font-size: 20px; }

/* ---------------- 聊天区 ---------------- */
.chat-panel {
  flex: 1; position: relative; display: flex; flex-direction: column;
  background-color: var(--bg-chat);
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255,255,255,.55) 0 2px, transparent 2.5px),
    radial-gradient(circle at 72% 15%, rgba(255,255,255,.45) 0 1.5px, transparent 2px),
    radial-gradient(circle at 45% 68%, rgba(255,255,255,.5) 0 2px, transparent 2.5px),
    radial-gradient(circle at 88% 78%, rgba(255,255,255,.4) 0 1.5px, transparent 2px);
  background-size: 220px 220px, 180px 180px, 260px 260px, 200px 200px;
}
.welcome { flex: 1; display: grid; place-items: center; }
.welcome-badge {
  background: rgba(255,255,255,.85); color: #6b7c8c; padding: 7px 14px;
  border-radius: 16px; font-size: 13.5px;
}
.chat-view { flex: 1; display: flex; flex-direction: column; height: 100%; }
.chat-head {
  height: 56px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; padding: 0 14px; flex-shrink: 0;
}
.back { display: none; margin-left: -8px; }
.chat-head-text { min-width: 0; }
.chat-head-title { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-sub { font-size: 12.5px; color: var(--text-dim); margin-top: 1px; }

.messages { flex: 1; overflow-y: auto; padding: 18px 20px 10px; scroll-behavior: smooth; }
.day { text-align: center; margin: 12px 0 14px; }
.day span {
  background: rgba(74, 96, 115, .45); color: #fff; font-size: 12.5px;
  padding: 3px 11px; border-radius: 12px;
}
.msg {
  max-width: min(72%, 620px); margin-bottom: 8px; padding: 7px 11px 6px;
  border-radius: 12px; box-shadow: 0 1px 1px rgba(16,35,47,.08);
  font-size: 14.5px; line-height: 1.45; word-break: break-word; position: relative;
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.in { background: var(--bubble-in); border-bottom-left-radius: 4px; }
.msg.out { background: var(--bubble-out); margin-left: auto; border-bottom-right-radius: 4px; }
.msg.lead-in { border-top-left-radius: 12px; }
.msg .meta {
  float: right; font-size: 11px; color: #7f9aa8; margin: 6px 0 -2px 8px; user-select: none;
}
.msg.out .meta { color: #6aa87a; }
.msg-name { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 16px 14px;
  background: #fff; border-top: 1px solid var(--line); flex-shrink: 0;
}
.composer textarea {
  flex: 1; resize: none; border: 0; outline: none; font-size: 15px; line-height: 1.45;
  padding: 9px 4px; max-height: 140px; background: transparent;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex-shrink: 0; transition: .15s;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:active { transform: scale(.94); }

/* ---------------- 弹窗 ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(17, 27, 36, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-card { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; overflow: hidden; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 14px 18px; font-size: 16px; font-weight: 600; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 14px 16px 18px; max-height: 70vh; overflow-y: auto; }
.user-results { margin-top: 8px; max-height: 190px; overflow-y: auto; }
.user-row {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; cursor: pointer;
}
.user-row:hover { background: #f4f7fa; }
.user-row .nm { font-size: 14.5px; }
.user-row .un { font-size: 12px; color: var(--text-dim); }
.user-row .uinfo { flex: 1; min-width: 0; }
.add-btn {
  width: 30px; height: 30px; border-radius: 50%; background: #eef3f8; color: var(--accent);
  font-size: 19px; line-height: 1; display: grid; place-items: center; flex-shrink: 0;
}
.add-btn:hover { background: #e2ebf5; }
.pick-hint { font-size: 12.5px; color: var(--text-dim); padding: 6px 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; background: #eaf3fd; color: var(--accent);
  padding: 5px 10px; border-radius: 14px; font-size: 13px; margin: 0 6px 6px 0; cursor: pointer;
}
.chip:hover { background: #dcebfa; }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0 12px; color: var(--text-dim); font-size: 12.5px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translate(-50%, 20px);
  background: rgba(23, 33, 43, .92); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: .22s; z-index: 99; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 手机 ---------------- */
@media (max-width: 820px) {
  .sidebar { width: 100%; min-width: 0; border-right: 0; }
  .chat-panel { display: none; }
  .app.mobile-chat .sidebar { display: none; }
  .app.mobile-chat .chat-panel { display: flex; }
  .back { display: grid; }
  .messages { padding: 12px 10px 8px; }
  .msg { max-width: 82%; font-size: 15px; }
  .composer textarea { font-size: 16px; } /* 小于 16px 时 iOS 会自动放大页面 */
  .composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }
  .chat-head { height: 54px; }
}
