:root {
  --bg: #f2f5f9;
  --card: #ffffff;
  --accent: #0ea5a4;
  --accent-dark: #0b8584;
  --text: #1f2937;
  --text-soft: #6b7280;
  --border: #e5e9f0;
  --mine: #e0f4f3;
  --other: #f1f4f8;
  --danger: #dc2626;
}

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

html, body { height: 100%; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ---------- 通用屏幕 ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- 登录页 ---------- */
#login-screen { align-items: center; justify-content: center; }

.login-card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(31, 41, 55, 0.12);
  padding: 40px 36px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.logo { font-size: 44px; text-align: center; }

.login-card h1 { font-size: 22px; text-align: center; }

.subtitle { color: var(--text-soft); text-align: center; font-size: 14px; margin-bottom: 6px; }

.login-card input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--accent); }

#login-btn {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}
#login-btn:hover { background: var(--accent-dark); }
#login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.error { color: var(--danger); font-size: 13px; text-align: center; }

/* ---------- 聊天头部 ---------- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-left .title { font-size: 16px; font-weight: 600; }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.online { background: #22c55e; box-shadow: 0 0 0 4px rgba(34,197,94,0.15); }
.dot.offline { background: #9ca3af; }

.header-right { display: flex; align-items: center; gap: 12px; }
.my-name { color: var(--text-soft); font-size: 14px; }

.ghost-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-soft);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.ghost-btn:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- 消息区 ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty-tip { color: var(--text-soft); text-align: center; margin-top: 40px; font-size: 14px; }

.msg { max-width: 78%; display: flex; flex-direction: column; gap: 4px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg:not(.mine) { align-self: flex-start; align-items: flex-start; }

.msg-meta { font-size: 12px; color: var(--text-soft); }

.msg-body {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--other);
  display: flex;
  flex-direction: column;
  gap: 8px;
  word-break: break-word;
}
.msg.mine .msg-body { background: var(--mine); border-top-right-radius: 4px; }
.msg:not(.mine) .msg-body { border-top-left-radius: 4px; }

.msg-text { font-size: 15px; line-height: 1.5; white-space: pre-wrap; }

.msg-img {
  max-width: 260px;
  max-height: 240px;
  border-radius: 10px;
  cursor: zoom-in;
  display: block;
  object-fit: cover;
}

/* ---------- 输入区 ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.icon-btn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}
.icon-btn:hover { background: #e9eef5; }

#input {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
}
#input:focus { border-color: var(--accent); }

.send-btn {
  height: 40px;
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-dark); }
.send-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* 待发送图片 */
.attachment {
  position: relative;
  flex-shrink: 0;
}
.attachment img {
  width: 52px; height: 52px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.attachment .remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- 表情面板 ---------- */
.emoji-panel {
  position: absolute;
  bottom: 64px;
  left: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(31,41,55,0.16);
  padding: 12px;
  width: 292px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 20;
}
.emoji-panel button {
  background: none;
  border: none;
  font-size: 22px;
  padding: 5px;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-panel button:hover { background: var(--bg); }

/* ---------- 灯箱 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 40px;
}
.lightbox img {
  max-width: 92vw;
  max-height: 86vh;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.lightbox-btn {
  position: absolute;
  background: rgba(255,255,255,0.14);
  border: none;
  color: #fff;
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  padding: 10px 14px;
}
.lightbox-btn:hover { background: rgba(255,255,255,0.26); }
.lightbox-btn.close { top: 20px; right: 20px; font-size: 28px; padding: 6px 16px; line-height: 1; }
.lightbox-btn.download { bottom: 24px; left: 50%; transform: translateX(-50%); }

/* 移动端适配 */
@media (max-width: 640px) {
  .msg { max-width: 88%; }
  .msg-img { max-width: 200px; }
}
