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

:root {
  --bg: #fafafa;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #9a9a9a;
  --border: #e6e6e6;
  --mine: #1a1a1a;
  --ok: #1a1a1a;
}

html, body { height: 100%; }

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

.hidden { display: none !important; }

/* ---------- 等待登记页 ---------- */
.screen {
  height: 100vh;
  height: 100dvh;
}

/* ---------- 聊天页 ---------- */
#chat {
  display: flex;
  flex-direction: column;
  max-width: 680px;
  height: calc(100vh - 20px);
  height: calc(100dvh - 20px);
  margin: 10px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

header .peer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  flex-shrink: 0;
}
.dot.online { background: var(--ok); border-color: var(--ok); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 12px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

.date-divider {
  text-align: center;
  margin: 14px 0 12px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.msg-row {
  display: flex;
  margin-bottom: 14px;
}
.msg-row.mine { justify-content: flex-end; }
.msg-row.peer { justify-content: flex-start; }

.msg-wrap { max-width: 70%; }

.msg-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  padding: 0 2px;
}
.msg-row.mine .msg-meta { text-align: right; }

.read-mark {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
}

.bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  border-radius: 14px;
}

.msg-row.mine .bubble {
  background: var(--mine);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.peer .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* ---------- 输入区 ---------- */
footer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
}

footer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  background: var(--card);
}

footer button {
  padding: 9px 22px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--mine);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
footer button:hover { background: #333; }
footer button:disabled { opacity: .4; cursor: default; }

footer .attach-btn {
  width: 40px;
  padding: 9px 0;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
}
footer .attach-btn:hover { border-color: var(--text); background: none; }

.msg-img {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 8px;
  cursor: pointer;
}

.msg-file {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  color: inherit;
}
.msg-file-name { word-break: break-all; }
.msg-file-size { font-size: 11px; color: var(--muted); }
.msg-row.peer .msg-file-size { color: var(--muted); }

.msg-actions { margin-left: 8px; display: none; }
.msg-wrap:hover .msg-actions { display: inline; }
@media (hover: none) { .msg-actions { display: inline; } }

.msg-action {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
}
.msg-action:hover { color: var(--text); }

.recalled-text {
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

.edited-hint {
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
}

.edit-box {
  width: 100%;
  min-height: 42px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  background: var(--card);
}

.edit-row {
  margin-top: 6px;
  text-align: right;
}
.edit-row button {
  margin-left: 8px;
  font-size: 12px;
  padding: 3px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.edit-row button:hover { border-color: var(--text); }

.upload-status {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 6px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
}
