:root {
  --bg: #080a10;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf6;
  --muted: #8b93a7;
  --accent: #7c8cff;
  --accent-2: #a06bff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 18px;
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system,
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 18% -12%, rgba(124, 140, 255, 0.2), transparent 62%),
    radial-gradient(900px 520px at 102% -4%, rgba(160, 107, 255, 0.16), transparent 58%),
    var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

/* ----------------------------------------------------------- 布局 */

.app {
  display: flex;
  height: 100dvh;
  gap: 0;
}

.sidebar {
  width: 286px;
  flex: 0 0 286px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 16px;
  background: rgba(10, 13, 20, 0.62);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 14px;
  background: linear-gradient(140deg, rgba(124, 140, 255, 0.35), rgba(160, 107, 255, 0.28));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 24px -12px rgba(124, 140, 255, 0.9);
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.4px;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.online-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #cfd6e6;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}

.online-card strong {
  color: var(--text);
  font-size: 15px;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55);
  animation: pulse 2.4s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(74, 222, 128, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
  }
}

.side-title {
  padding: 0 8px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.user-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0 4px;
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 12px;
  font-size: 13.5px;
  color: #dbe2f0;
  transition: background 0.15s ease;
}

.user-list li:hover {
  background: var(--panel);
}

.user-list .you-tag {
  margin-left: auto;
  padding: 1px 7px;
  font-size: 10px;
  color: var(--accent);
  background: rgba(124, 140, 255, 0.14);
  border-radius: 999px;
}

.side-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.me-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}

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

.me-info span {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.me-info small {
  font-size: 11px;
  color: var(--muted);
}

.tip {
  margin: 0 4px;
  font-size: 11px;
  line-height: 1.6;
  color: #6b7387;
}

/* ----------------------------------------------------------- 头像 */

.avatar {
  --c: #7c8cff;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  color: #0b0e15;
  background: var(--c);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  user-select: none;
}

.avatar.sm {
  width: 28px;
  height: 28px;
  flex-basis: 28px;
  font-size: 11.5px;
}

/* ----------------------------------------------------------- 聊天区 */

.chat {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(10, 13, 20, 0.7), rgba(10, 13, 20, 0.25));
  backdrop-filter: blur(14px);
}

.chat-title {
  flex: 1;
  min-width: 0;
}

.chat-title h2 {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  font-size: 16.5px;
  font-weight: 650;
}

.chat-title .hash {
  color: var(--accent);
  font-weight: 500;
}

.chat-title p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.status[data-state="online"] .dot {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.status[data-state="offline"] .dot {
  background: var(--bad);
}

.status[data-state="online"] {
  color: #b9f6ce;
}

.status[data-state="offline"] {
  color: #ffc0c0;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

/* 消息少的时候贴着输入框底边排，更像聊天软件 */
.grow-spacer {
  flex: 1 0 auto;
  min-height: 0;
}

.welcome {
  margin: auto;
  max-width: 460px;
  padding: 30px 28px;
  text-align: center;
  background: radial-gradient(circle at 50% 0%, rgba(124, 140, 255, 0.14), transparent 70%), var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
}

.welcome-emoji {
  font-size: 34px;
}

.welcome h3 {
  margin: 10px 0 8px;
  font-size: 17px;
}

.welcome p {
  margin: 0;
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted);
}

/* ----------------------------------------------------------- 消息 */

.msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(78%, 720px);
  padding: 2px 0;
  animation: enter 0.18s ease both;
}

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

.msg.mine {
  margin-left: auto;
  flex-direction: row-reverse;
}

.msg.grouped {
  padding-top: 0;
}

.msg.grouped .avatar {
  visibility: hidden;
  height: 0;
  margin-top: -2px;
}

.msg-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg.mine .msg-body {
  align-items: flex-end;
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 4px;
}

.msg.mine .meta {
  flex-direction: row-reverse;
}

.meta .who {
  font-size: 12.5px;
  font-weight: 600;
  color: #c9d2e6;
}

.msg.mine .meta .who {
  color: #cbb8ff;
}

.meta .time {
  font-size: 10.5px;
  color: #646c80;
}

.bubble {
  padding: 9px 14px;
  font-size: 14.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #171c28;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px 16px 16px 16px;
  color: #e7ecf8;
}

.msg.mine .bubble {
  background: linear-gradient(135deg, #6d7dff, #9161f0);
  border-color: transparent;
  color: #fff;
  border-radius: 16px 4px 16px 16px;
  box-shadow: 0 10px 26px -16px rgba(124, 140, 255, 0.95);
}

.day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 10px;
  font-size: 11px;
  color: #6d7588;
}

.day::before,
.day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.09), transparent);
}

.system {
  align-self: center;
  max-width: 82%;
  margin: 6px 0;
  padding: 4px 12px;
  font-size: 11.5px;
  color: #8a93a8;
  text-align: center;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 999px;
}

/* ----------------------------------------------------------- 正在输入 */

.typing {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 22px;
  padding: 0 26px 4px;
  font-size: 12px;
  color: var(--muted);
}

.dots {
  display: inline-flex;
  gap: 3px;
}

.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.3s infinite ease-in-out;
}

.dots i:nth-child(2) {
  animation-delay: 0.16s;
}

.dots i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* ----------------------------------------------------------- 输入区 */

.composer {
  padding: 10px 22px calc(18px + env(safe-area-inset-bottom));
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  background: rgba(20, 25, 36, 0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-box:focus-within {
  border-color: rgba(124, 140, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(124, 140, 255, 0.1);
}

.composer textarea {
  flex: 1;
  min-height: 24px;
  max-height: 132px;
  padding: 7px 0;
  font-size: 14.5px;
  line-height: 1.55;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
}

.composer textarea::placeholder {
  color: #5d6578;
}

.send-btn {
  flex: 0 0 auto;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #6d7dff, #9161f0);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease, opacity 0.15s ease;
}

.send-btn:hover {
  filter: brightness(1.08);
}

.send-btn:active {
  transform: scale(0.97);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ghost-btn {
  padding: 7px 12px;
  font-size: 12px;
  color: #c3cbe0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 16px;
  color: #d6dcf0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}

.only-mobile {
  display: none;
}

.jump-btn {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  padding: 7px 14px;
  font-size: 12px;
  color: #dfe5f6;
  background: rgba(32, 38, 54, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 10px 30px -14px #000;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

/* ----------------------------------------------------------- 弹层 */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 6, 11, 0.66);
  backdrop-filter: blur(6px);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(400px, 100%);
  padding: 26px;
  text-align: center;
  background: #10141d;
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 60px -30px #000;
}

.modal-emoji {
  font-size: 30px;
}

.modal-card h3 {
  margin: 10px 0 6px;
  font-size: 17px;
}

.modal-card p {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

.modal-card input {
  width: 100%;
  padding: 11px 14px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}

.modal-card input:focus {
  border-color: rgba(124, 140, 255, 0.6);
}

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

.modal-actions .send-btn {
  flex: 1;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 80;
  transform: translateX(-50%);
  padding: 9px 16px;
  font-size: 12.5px;
  color: #ffe6c7;
  background: rgba(60, 40, 20, 0.92);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 999px;
  box-shadow: 0 14px 34px -18px #000;
}

.toast[hidden] {
  display: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(3, 5, 9, 0.6);
  backdrop-filter: blur(2px);
}

.overlay[hidden] {
  display: none;
}

/* ----------------------------------------------------------- 滚动条 */

.messages::-webkit-scrollbar,
.user-list::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb:hover,
.user-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ----------------------------------------------------------- 移动端 */

@media (max-width: 780px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 268px;
    transform: translateX(-102%);
    transition: transform 0.24s ease;
    box-shadow: 30px 0 60px -30px #000;
  }

  .sidebar.open {
    transform: none;
  }

  .only-mobile {
    display: grid;
  }

  .messages {
    padding: 16px 14px 8px;
  }

  .msg {
    max-width: 88%;
  }

  .chat-header {
    padding: 12px 14px;
  }

  .composer {
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .composer-box {
    padding-left: 14px;
  }

  .status span:last-child {
    display: none;
  }

  .jump-btn {
    bottom: 88px;
  }
}

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