:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e8ecf3;
  --text: #1a2233;
  --text-2: #6b7688;
  --text-3: #9aa4b5;
  --brand: #3b82f6;
  --brand-dark: #2563eb;
  --bubble-me: #3b82f6;
  --bubble-other: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-view {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e4ecff 0%, #f4f6fb 55%);
}
.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 36px 30px 26px;
  text-align: center;
}
.login-logo { font-size: 46px; line-height: 1; }
.login-title { margin: 12px 0 6px; font-size: 24px; font-weight: 700; letter-spacing: .5px; }
.login-sub { margin: 0 0 24px; color: var(--text-2); font-size: 14px; }

.user-grid { display: grid; gap: 12px; }
.user-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  cursor: pointer;
  transition: .18s;
  text-align: left;
  width: 100%;
}
.user-item:hover { border-color: var(--brand); background: #f2f7ff; transform: translateY(-1px); }
.user-item:disabled { opacity: .55; cursor: default; transform: none; }
.user-item .nick { font-weight: 600; font-size: 15px; }
.user-item .uid { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.user-item .enter { margin-left: auto; color: var(--text-3); font-size: 18px; }

.login-tip { margin: 20px 0 0; font-size: 12px; color: var(--text-3); line-height: 1.7; }
.login-status { margin-top: 10px; font-size: 13px; color: #e11d48; min-height: 18px; }

.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  background: #eef2f8;
  flex-shrink: 0;
  user-select: none;
}
.avatar.small { width: 36px; height: 36px; font-size: 18px; }

/* ---------- 聊天布局 ---------- */
.chat-view { display: flex; height: 100%; }

.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-me {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar-me-info { min-width: 0; flex: 1; }
.sidebar-me-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-me-id { font-size: 12px; color: var(--text-3); }
.btn-switch, .btn-back {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-2);
  border-radius: 9px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: .15s;
}
.btn-switch:hover { border-color: var(--brand); color: var(--brand); }

.conv-list { flex: 1; overflow-y: auto; padding: 8px; }
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: .15s;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: #eaf2ff; }
.conv-item .conv-main { flex: 1; min-width: 0; }
.conv-item .conv-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-last { font-size: 12px; color: var(--text-3); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-3);
  display: flex; align-items: center; gap: 6px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #d1d5db; }
.dot.online { background: #22c55e; }
.dot.offline { background: #ef4444; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat-header {
  height: 62px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-info { min-width: 0; }
.chat-title { font-size: 15px; font-weight: 600; }
.chat-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.btn-back { display: none; margin-right: -4px; }

.msg-area { flex: 1; overflow-y: auto; padding: 20px 22px; }
.msg-empty { text-align: center; color: var(--text-3); font-size: 13px; padding: 24px 0; }

.msg-row { display: flex; gap: 10px; margin-bottom: 16px; align-items: flex-start; }
.msg-row.me { flex-direction: row-reverse; }
.msg-body { max-width: min(62%, 560px); min-width: 0; }
.msg-meta { font-size: 11px; color: var(--text-3); margin: 0 2px 5px; }
.msg-row.me .msg-meta { text-align: right; }
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bubble-other);
  border: 1px solid var(--line);
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
  display: inline-block;
}
.msg-row.me .bubble {
  background: var(--bubble-me);
  border-color: var(--bubble-me);
  color: #fff;
}
.bubble.pending { opacity: .6; }
.bubble.failed { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.msg-row.me .bubble.failed { color: #b91c1c; }

.msg-sys { text-align: center; margin: 10px 0 18px; }
.msg-sys span { font-size: 12px; color: var(--text-3); background: rgba(0,0,0,.04); padding: 4px 10px; border-radius: 10px; }

.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  position: relative;
  flex-shrink: 0;
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  background: var(--panel-2);
  color: var(--text);
}
#input:focus { border-color: var(--brand); background: #fff; }
.btn-send {
  border: none;
  background: var(--brand);
  color: #fff;
  border-radius: 12px;
  padding: 11px 20px;
  font-size: 14px;
  cursor: pointer;
  transition: .15s;
  height: 44px;
}
.btn-send:hover:not(:disabled) { background: var(--brand-dark); }
.btn-send:disabled { background: #cbd5e1; cursor: not-allowed; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  height: 44px; width: 44px;
  font-size: 19px;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--brand); }

.emoji-panel {
  position: absolute;
  bottom: 68px; left: 16px;
  width: 292px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 20;
}
.emoji-panel span {
  font-size: 21px;
  text-align: center;
  padding: 4px 0;
  cursor: pointer;
  border-radius: 8px;
}
.emoji-panel span:hover { background: var(--panel-2); }

.toast {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  background: rgba(26, 34, 51, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 999;
  box-shadow: var(--shadow);
}

/* ---------- 响应式 ---------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 30;
    width: 82%;
    max-width: 300px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .btn-back { display: inline-block; }
  .msg-body { max-width: 74%; }
  .msg-area { padding: 14px; }
}
