:root {
  --bg: #f2f5ff;
  --bg-2: #e8edff;
  --panel: #ffffff;
  --text: #1e2440;
  --muted: #7d86a6;
  --line: #e7eaf6;
  --brand: #6d7cff;
  --brand-dark: #5564e8;
  --brand-soft: #eef0ff;
  --mine: #6d7cff;
  --shadow: 0 18px 60px rgba(63, 76, 150, .14);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.chat-app {
  width: min(980px, 100%);
  height: min(860px, calc(100vh - 48px));
  background: var(--panel);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部 */
.chat-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 26px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(120deg, #ffffff 20%, #f7f8ff 100%);
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-icon {
  width: 44px; height: 44px; flex: none;
  border-radius: 13px;
  background: linear-gradient(135deg, #7c8bff, #5a6bef);
  box-shadow: 0 8px 18px rgba(109, 124, 255, .3);
  display: flex; align-items: center; justify-content: center;
}
.brand-icon svg { width: 27px; height: 27px; fill: #fff; }
.brand-text h1 { margin: 0; font-size: 19px; letter-spacing: .3px; }
.brand-text p { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill, .online-pill {
  font-size: 12px; color: var(--muted);
  background: #f5f7fd; border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 11px; white-space: nowrap;
}
.status-pill i {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #35c48a; margin-right: 6px; vertical-align: 1px;
  box-shadow: 0 0 0 3px rgba(53, 196, 138, .15);
}
.status-pill.offline i { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.15); }
.online-pill b { color: var(--brand-dark); }
.user-pill {
  font-size: 12px; color: #4b5580; background: #eef0ff;
  border: 1px solid #dfe3fb; border-radius: 999px; padding: 6px 11px; white-space: nowrap;
  cursor: pointer; transition: background .2s;
}
.user-pill:hover { background: #e2e6ff; }
.user-pill b { color: var(--brand-dark); }
.header-actions .text-btn { border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.header-actions .text-btn:hover { color: var(--danger, #e05b6b); }
.admin-link {
  font-size: 12px; text-decoration: none; color: var(--brand-dark);
  background: var(--brand-soft); padding: 7px 13px; border-radius: 9px;
  transition: background .2s;
}
.admin-link:hover { background: #e2e6ff; }

/* 消息区 */
.chat-body { flex: 1; min-height: 0; background: #fbfcff; }
.messages { height: 100%; overflow-y: auto; padding: 24px 28px 10px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-thumb { background: #d7dcf2; border-radius: 10px; }
.empty-state {
  height: 100%; min-height: 260px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-align: center;
}
.empty-icon {
  width: 66px; height: 66px; border-radius: 20px;
  background: #eef0ff; display: flex; align-items: center; justify-content: center;
  font-size: 30px; margin-bottom: 14px;
}
.empty-state h2 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
.empty-state p { margin: 0; font-size: 13px; }
.load-more { display: flex; justify-content: center; padding: 4px 0 16px; }
.load-more button {
  border: 1px solid #dfe4f5; background: #fff; color: var(--brand-dark);
  border-radius: 999px; padding: 7px 16px; font-size: 12px;
}
.load-more button:hover { background: var(--brand-soft); border-color: #c9d0ff; }
.load-more button:disabled { opacity: .6; cursor: default; }
.date-divider { text-align: center; margin: 14px 0 20px; }
.date-divider span {
  font-size: 11px; color: #9aa2bd; background: #f0f2fa;
  padding: 4px 12px; border-radius: 999px;
}
.msg { display: flex; gap: 11px; margin-bottom: 18px; align-items: flex-start; }
.msg .avatar {
  width: 36px; height: 36px; flex: none; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 700;
  background: linear-gradient(135deg, #8b9aff, #6676f0);
}
.msg .msg-main { max-width: min(74%, 620px); min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 9px; margin-bottom: 6px; }
.msg-name { font-size: 12px; font-weight: 600; color: #404866; }
.msg-time { font-size: 11px; color: #a3aac2; }
.bubble {
  display: inline-block; padding: 11px 14px; border-radius: 4px 14px 14px 14px;
  background: #fff; border: 1px solid var(--line); color: #2b3150;
  font-size: 14px; line-height: 1.65; word-break: break-word; white-space: normal;
  box-shadow: 0 4px 14px rgba(50, 60, 120, .04);
}
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-main { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .msg-meta { flex-direction: row-reverse; }
.msg.mine .bubble {
  background: linear-gradient(135deg, #7382ff, #5d6cf0); color: #fff;
  border-color: transparent; border-radius: 14px 4px 14px 14px;
  box-shadow: 0 6px 16px rgba(109, 124, 255, .22);
}

/* 输入区 */
.chat-footer { flex: none; border-top: 1px solid var(--line); padding: 14px 22px 12px; position: relative; background: #fff; }
.composer {
  display: flex; align-items: flex-end; gap: 9px;
  border: 1px solid #dfe4f5; border-radius: 14px; padding: 7px 8px 7px 10px;
  background: #fafbff; transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: #b9c2ff; box-shadow: 0 0 0 3px rgba(109,124,255,.09); }
.icon-btn {
  width: 34px; height: 34px; flex: none; border: 0; border-radius: 9px;
  background: transparent; color: #8a93b5; font-size: 21px; line-height: 1;
}
.icon-btn:hover { background: #eef0ff; color: var(--brand-dark); }
#messageInput {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  font-size: 14px; line-height: 1.5; color: var(--text); padding: 8px 2px; max-height: 110px;
}
#messageInput::placeholder { color: #aab1c9; }
.counter { font-size: 11px; color: #b1b8cd; align-self: center; white-space: nowrap; }
.send-btn {
  flex: none; border: 0; border-radius: 10px; padding: 9px 15px;
  display: flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #7382ff, #5868ea); color: #fff;
  font-size: 13px; font-weight: 600; box-shadow: 0 6px 14px rgba(88,104,234,.24);
  transition: transform .15s, opacity .15s;
}
.send-btn:hover { transform: translateY(-1px); }
.send-btn:active { transform: translateY(0); }
.send-btn svg { width: 15px; height: 15px; fill: #fff; }
.emoji-panel {
  display: none; flex-wrap: wrap; gap: 4px; padding: 9px 4px 2px;
}
.emoji-panel.show { display: flex; }
.emoji-panel button {
  border: 0; background: transparent; font-size: 19px; padding: 4px;
  border-radius: 7px; line-height: 1;
}
.emoji-panel button:hover { background: #eef0ff; }
.composer-bottom {
  display: flex; align-items: center; gap: 10px;
  margin-top: 9px; font-size: 11px; color: #9aa2bd;
}
.composer-bottom b { color: var(--brand-dark); }
.text-btn { border: 0; background: transparent; color: var(--brand-dark); font-size: 11px; padding: 0; }
.text-btn:hover { text-decoration: underline; }
.footer-tip { margin-left: auto; }

/* 昵称弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(28, 34, 68, .38); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.hidden { display: none; }
.modal-card {
  width: min(400px, 100%); background: #fff; border-radius: 20px;
  padding: 32px 30px 28px; box-shadow: 0 24px 70px rgba(30,36,80,.22);
  text-align: center;
}
.modal-icon {
  width: 58px; height: 58px; margin: 0 auto 14px; border-radius: 18px;
  background: #eef0ff; display: flex; align-items: center; justify-content: center; font-size: 27px;
}
.modal-card h2 { margin: 0 0 8px; font-size: 20px; }
.modal-card p { margin: 0 0 22px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.modal-card label { display: block; text-align: left; font-size: 12px; margin-bottom: 7px; color: #5b6380; }
.modal-card input {
  width: 100%; border: 1px solid #dfe4f5; border-radius: 11px;
  padding: 11px 13px; font-size: 14px; outline: 0; background: #fafbff;
}
.modal-card input:focus { border-color: #b9c2ff; box-shadow: 0 0 0 3px rgba(109,124,255,.1); }
.modal-error { min-height: 18px; text-align: left; color: #e05b5b; font-size: 11px; padding-top: 5px; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.ghost-btn, .primary-btn {
  flex: 1; border-radius: 11px; padding: 11px 10px; font-size: 13px; font-weight: 600;
}
.ghost-btn { border: 1px solid #dfe4f5; background: #fff; color: #5b6380; }
.primary-btn { border: 0; background: linear-gradient(135deg, #7382ff, #5868ea); color: #fff; }
.ghost-btn:hover { background: #f6f7ff; }
.primary-btn:hover { opacity: .92; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px);
  background: #2d3455; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 80;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 720px) {
  .page { padding: 0; }
  .chat-app { height: 100vh; border-radius: 0; }
  .chat-header { padding: 14px 16px; flex-wrap: wrap; }
  .brand-text p { display: none; }
  .header-actions { width: 100%; justify-content: flex-start; }
  .messages { padding: 18px 14px 8px; }
  .msg .msg-main { max-width: 80%; }
  .chat-footer { padding: 10px 12px; }
  .counter, .footer-tip { display: none; }
}
