* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", -apple-system, "Segoe UI", sans-serif;
  background: #f3f4f6;
  color: #1f2937;
}
.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.view .form-wrap { flex: 1; min-height: 0; }

.icon-btn { border: none; background: rgba(255,255,255,.2); color: #fff; width: 32px; height: 32px; border-radius: 8px; font-size: 18px; cursor: pointer; line-height: 1; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.icon-btn:hover { background: rgba(255,255,255,.35); }

/* 联系人列表 */
.contacts { flex: 1; overflow-y: auto; background: #fff; }
.contact-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.contact-item:hover { background: #f9fafb; }
.avatar { width: 46px; height: 46px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; font-weight: 600; overflow: hidden; background: #e5e7eb; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.unread-badge { position: absolute; top: -5px; right: -5px; background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; min-width: 18px; height: 18px; border-radius: 9px; text-align: center; padding: 0 5px; box-sizing: border-box; font-weight: 600; }
.contact-main { flex: 1; min-width: 0; }
.contact-top { display: flex; justify-content: space-between; align-items: baseline; }
.contact-name { font-size: 15px; font-weight: 600; color: #1f2937; }
.contact-time { font-size: 11px; color: #9ca3af; flex-shrink: 0; margin-left: 8px; }
.contact-preview { font-size: 13px; color: #9ca3af; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.rel-badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; margin-left: 6px; }
.rel-mirror { background: #ede9fe; color: #6d28d9; }
.rel-friend { background: #d1fae5; color: #047857; }
.rel-lover { background: #fce7f3; color: #be185d; }
.contacts-empty { padding: 40px 20px; text-align: center; color: #9ca3af; }
header {
  padding: 14px 18px;
  background: #4f46e5;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header .title { font-size: 18px; font-weight: 600; }
header a { color: #e0e7ff; text-decoration: none; font-size: 18px; }
header a:hover { text-decoration: underline; }
.header-right { display: flex; align-items: center; gap: 8px; }
#archiveSel { max-width: 160px; padding: 5px 8px; border-radius: 8px; border: none; font-size: 13px; background: rgba(255,255,255,.92); color: #1f2937; }
#newArchive { border: none; background: rgba(255,255,255,.2); color: #fff; width: 30px; height: 30px; border-radius: 8px; font-size: 18px; cursor: pointer; line-height: 1; }
#newArchive:hover { background: rgba(255,255,255,.35); }
.backend-badge {
  font-size: 12px;
  background: rgba(255,255,255,.2);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}
.backend-badge:empty { display: none; }  /* 无未读时不显示 */

/* 聊天区 */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; animation: bubbleIn .18s ease; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: #4f46e5; color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid #e5e7eb; border-bottom-left-radius: 4px; }
.msg.bare { background: transparent !important; border: none !important; padding: 0 !important; }
.msg .meta { font-size: 11px; color: #9ca3af; margin-top: 4px; }
.time-divider { align-self: center; font-size: 12px; color: #9ca3af; margin: 8px 0; }
#chatBg img { display: block; width: 100%; max-height: 130px; object-fit: cover; }
.msg .sticker { display: block; max-width: 160px; max-height: 160px; width: auto; height: auto; border-radius: 10px; margin: 6px 0; }
.msg .photo { display: block; max-width: 200px; max-height: 240px; border-radius: 10px; margin: 6px 0; }
.link-card { display: block; max-width: 240px; border: 1px solid #e5e7eb; border-radius: 10px; overflow: hidden; text-decoration: none; color: inherit; background: #fff; margin: 4px 0; }
.link-card img { display: block; width: 100%; max-height: 150px; object-fit: cover; }
.link-card-title { padding: 8px 10px; font-size: 14px; color: #1f2937; line-height: 1.4; }
.link-card:hover { border-color: #a5b4fc; }
#lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.85); align-items: center; justify-content: center; z-index: 1000; cursor: zoom-out; }
#lightbox img { max-width: 92%; max-height: 92%; border-radius: 8px; }
.composer #photoBtn { background: #eef2ff; color: #4f46e5; padding: 8px 12px; font-size: 18px; }
.msg .quote { border-left: 3px solid #c7d2fe; background: rgba(99,102,241,.08); color: #6b7280; font-size: 13px; padding: 4px 8px; margin-bottom: 6px; border-radius: 4px; }
.msg.user .quote { border-left-color: #c7d2fe; background: rgba(255,255,255,.18); color: #e0e7ff; }

.quote-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #eef2ff; border-top: 1px solid #e5e7eb; font-size: 13px; color: #4b5563; }
.quote-bar-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar-x { border: none; background: transparent; color: #6b7280; font-size: 14px; cursor: pointer; padding: 2px 6px; }
.msg.assistant.quotable { cursor: pointer; }

.composer { display: flex; gap: 8px; padding: 12px; background: #fff; border-top: 1px solid #e5e7eb; }
.composer input { flex: 1; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; font-size: 15px; }
.composer button { padding: 10px 18px; background: #4f46e5; color: #fff; border: none; border-radius: 10px; font-size: 15px; cursor: pointer; }
.composer button:disabled { opacity: .5; cursor: default; }
.composer #imgBtn { background: #eef2ff; color: #4f46e5; padding: 8px 12px; font-size: 18px; }

/* 表情选择面板 */
.sticker-panel { display: grid; grid-template-columns: repeat(auto-fill, 56px); gap: 8px; padding: 10px 12px; max-height: 220px; overflow-y: auto; background: #fff; border-top: 1px solid #e5e7eb; }
.sticker-tile { width: 56px; height: 56px; border: 1px solid #eee; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; background: #fafafa; overflow: hidden; }
.sticker-tile img { max-width: 100%; max-height: 100%; }
.sticker-tile:hover { background: #eef2ff; }
.upload-tile { font-size: 12px; color: #6b7280; text-align: center; line-height: 1.2; }
.sticker-tile.sortable { cursor: grab; border-color: #c7d2fe; }
.sticker-tile.sortable:active { cursor: grabbing; }

/* 表单（引导 / 设置） */
.form-wrap { padding: 22px; overflow-y: auto; }
.form-wrap h2 { margin-top: 0; }
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; margin-bottom: 8px; }
.field input[type=text], .field input[type=password], .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px;
}
.field textarea { min-height: 70px; resize: vertical; }
.tag-group { margin-bottom: 10px; }
.tag-group .cat { font-size: 13px; color: #6b7280; margin-bottom: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  padding: 6px 12px; border: 1px solid #c7d2fe; border-radius: 16px; cursor: pointer; font-size: 13px; user-select: none; background: #fff;
}
.tag.active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.hint { font-size: 12px; color: #6b7280; margin-top: 4px; }
.primary-btn { padding: 11px 20px; background: #4f46e5; color: #fff; border: none; border-radius: 10px; font-size: 15px; cursor: pointer; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.saved-note { color: #059669; font-size: 14px; margin-left: 10px; }

/* 登录 / 注册页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 16px; padding: 28px 24px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.login-logo { font-size: 26px; font-weight: 700; color: #4f46e5; text-align: center; margin-bottom: 18px; }
.login-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.login-tab { flex: 1; padding: 9px 0; border: none; background: #f3f4f6; color: #6b7280; border-radius: 10px; font-size: 15px; cursor: pointer; }
.login-tab.active { background: #4f46e5; color: #fff; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input { padding: 11px 13px; border: 1px solid #d1d5db; border-radius: 10px; font-size: 15px; }
.login-form .primary-btn { width: 100%; margin-top: 4px; }
.login-err { color: #ef4444; font-size: 13px; margin-top: 12px; min-height: 18px; text-align: center; }
