* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
}

.hidden {
  display: none !important;
}

.screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* ---------- 进入界面 ---------- */
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.login-card .subtitle {
  color: #888;
  font-size: 13px;
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  border-color: #764ba2;
}

.login-card button {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-card button:hover {
  opacity: 0.9;
}

.status {
  margin-top: 12px;
  font-size: 13px;
  color: #c0392b;
  min-height: 18px;
}

/* ---------- 聊天界面 ---------- */
#chat-screen {
  flex-direction: column;
}

#chat-screen header {
  width: 100%;
  max-width: 720px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px 12px 0 0;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.15);
}

.users {
  font-weight: 600;
  font-size: 14px;
}

.hint {
  font-size: 12px;
  color: #e67e22;
}

#messages {
  width: 100%;
  max-width: 720px;
  flex: 1;
  overflow-y: auto;
  background: #f2f3f7;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* 系统消息 */
.sys-msg {
  align-self: center;
  background: rgba(0, 0, 0, 0.06);
  color: #666;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 12px;
}

/* 普通消息 */
.msg {
  max-width: 78%;
  display: flex;
  gap: 8px;
}

/* 头像 */
.msg .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  user-select: none;
  overflow: hidden;
}

/* 图片头像：填满并裁成圆形 */
.avatar .avatar-pic {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 消息主体（气泡+时间） */
.msg .body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(100% - 46px);
}

.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.msg .meta {
  font-size: 11px;
  color: #999;
  margin: 3px 4px 0;
}

/* 发送的消息：右侧 */
.msg.mine {
  align-self: flex-end;
}
.msg.mine .body {
  align-items: flex-end;
}
.msg.mine .avatar {
  background: linear-gradient(135deg, #667eea, #764ba2);
}
.msg.mine .bubble {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* 接收的消息：左侧 */
.msg.theirs {
  align-self: flex-start;
}
.msg.theirs .body {
  align-items: flex-start;
}
.msg.theirs .avatar {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}
.msg.theirs .bubble {
  background: #fff;
  color: #333;
  border-bottom-left-radius: 4px;
}

/* 图片消息 */
.msg .bubble img {
  display: block;
  max-width: min(100%, 320px);
  max-height: 320px;
  border-radius: 8px;
  cursor: zoom-in;
}

/* 文件消息（下载链接） */
.msg .bubble .file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
  word-break: break-all;
}
.msg .bubble .file-link:hover {
  text-decoration: underline;
}
.msg.mine .bubble .file-link {
  color: #fff;
}

/* 收到消息的顶部“冒泡”提示 */
.msg-toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-16px);
  z-index: 9999;
  max-width: 90%;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  cursor: pointer;
}

.msg-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

#chat-screen footer {
  width: 100%;
  max-width: 720px;
  background: #fff;
  border-radius: 0 0 12px 12px;
  padding: 10px 12px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.15);
}

#chat-screen footer .attach-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

#chat-screen footer .attach-row button {
  padding: 6px 12px;
  font-size: 13px;
  color: #555;
  background: #f1f2f6;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

#chat-screen footer .attach-row button:hover {
  background: #e8e9ee;
}

.upload-status {
  font-size: 12px;
  color: #e67e22;
  min-height: 16px;
  margin-left: auto;
}

#chat-screen footer .input-row {
  display: flex;
  gap: 10px;
}

#text-input {
  flex: 1;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
}

#text-input:focus {
  border-color: #764ba2;
}

#send-btn {
  padding: 0 22px;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

#send-btn:hover {
  opacity: 0.9;
}

/* ---------- 头像 ---------- */
/* 登录页头像 */
.login-avatar-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}
.avatar.big {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 34px;
  background: #667eea;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}
.avatar-btn {
  border: none;
  background: none;
  color: #764ba2;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}
.avatar-btn:hover {
  text-decoration: underline;
}

/* 聊天页顶栏自己的头像（点击可更换） */
#chat-screen header .header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar.self {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  background: #667eea;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}
.avatar.self:hover {
  transform: scale(1.1);
}

/* ---------- 头像选择弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 360px);
  text-align: center;
}
.modal-card h3 {
  margin-bottom: 14px;
  font-size: 16px;
}
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.avatar-opt {
  width: 56px;
  height: 56px;
  margin: auto;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  transition: transform 0.15s;
}
.avatar-opt:hover {
  transform: scale(1.12);
}
#avatar-close {
  padding: 8px 26px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f1f2f6;
  cursor: pointer;
  font-size: 14px;
}

