:root {
  --bg: #e8edf3;
  --wechat-green: #07c160;
  --text: #1f2329;
  --panel: #ffffff;
  --muted: #808a98;
  --line: #e9edf3;
  --sidebar: #f7f9fc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: #efefef;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.auth-card {
  width: min(92vw, 420px);
  margin: 11vh auto;
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.06);
}

.auth-card h1 {
  margin: 0 0 16px;
  font-size: 40px;
  letter-spacing: 1px;
}

.sub {
  margin: 0 0 16px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tabs button,
form button,
.call-buttons button,
#logoutBtn,
.call-actions button {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  background: #f1f1f1;
  font-weight: 600;
}

.tabs button.active,
form button,
.call-buttons button,
#acceptBtn {
  background: var(--wechat-green);
  color: white;
}

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #6d7380;
  user-select: none;
}

.remember-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

input {
  border: 1px solid #d7d7d7;
  border-radius: 12px;
  padding: 14px 16px;
  background: #fff;
  font-size: 16px;
}

input:focus {
  outline: none;
  border-color: #07c160;
  box-shadow: 0 0 0 3px rgba(7, 193, 96, 0.13);
}

.msg {
  min-height: 28px;
  color: #d83030;
  margin-top: 10px;
  font-size: 18px;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: 72px 1fr;
  height: 100vh;
  max-width: 1360px;
  margin: 0 auto;
  overflow: hidden;
  box-shadow: 0 16px 44px rgba(18, 38, 63, 0.12);
  background: #fff;
}

.desktop-rail {
  background: #f2f3f5;
  border-right: 1px solid #e6e9ef;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 12px;
}

.rail-top {
  width: 100%;
  display: grid;
  place-items: center;
  padding: 4px 0 10px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #07c160 0%, #2ad38b 100%);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: center;
}

.rail-item {
  width: 56px;
  height: 36px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #596273;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}

.rail-item.active {
  background: rgba(7, 193, 96, 0.14);
  color: #07c160;
}

.badge {
  display: inline-flex;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ff4d4f;
  color: #fff;
  font-size: 11px;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  margin-left: 6px;
}

.main-stack {
  height: 100%;
  overflow: hidden;
}

.app-view {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100%;
}

.mobile-view {
  height: 100%;
  padding: 14px;
  background: #f7f7f7;
}

.mobile-view h3 {
  margin: 4px 0 12px;
}

.simple-list {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
}

.simple-item {
  padding: 14px 12px;
  border-bottom: 1px solid #ececec;
}

.simple-item:last-child {
  border-bottom: none;
}

.contacts-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100% - 36px);
  background: #f5f6fa;
  border-radius: 10px;
  overflow: hidden;
}

.contacts-left {
  background: #f3f4f7;
  border-right: 1px solid #e5e8ef;
  position: relative;
}

.contacts-search {
  padding: 10px 12px;
}

.contacts-search input {
  width: 100%;
}

.contacts-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  color: #5f6878;
  font-size: 13px;
  border-top: 1px solid #eceff5;
  border-bottom: 1px solid #eceff5;
}

.contacts-list {
  height: calc(100% - 92px);
  overflow-y: auto;
}

.contact-group-title {
  background: #eceff4;
  color: #7f8898;
  font-size: 13px;
  padding: 6px 12px;
  display: none;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid #edf0f5;
  cursor: pointer;
}

.contact-avatar {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: #dfe7f3;
  overflow: hidden;
  flex: 0 0 auto;
}

.contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.contact-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contacts-index {
  position: absolute;
  right: 4px;
  top: 108px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  display: none;
}

.contacts-index button {
  border: none;
  background: transparent;
  color: #727b8c;
  font-size: 11px;
  line-height: 1;
  padding: 1px 2px;
}

.contacts-right {
  display: grid;
  place-items: center;
  background: #fff;
}

.contacts-empty {
  font-size: 66px;
  opacity: 0.12;
}

#avatarUploadBtn {
  border: none;
}

.me-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
}

.me-top {
  display: flex;
  gap: 12px;
  padding: 14px 12px;
  border-bottom: 1px solid #ececec;
  align-items: center;
}

.me-avatar {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: #e7eef7;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
}

.me-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.me-meta {
  min-width: 0;
  flex: 1;
}

.me-nick {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 4px;
}

.me-sub {
  color: #6c7688;
  font-size: 13px;
  line-height: 1.4;
}

.me-actions {
  padding: 12px;
}

.primary-btn {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  background: rgba(7, 193, 96, 0.12);
  color: #07c160;
  cursor: pointer;
}

.edit-box {
  background: #fff;
  color: #1f2329;
}

.edit-title {
  margin: 0 0 12px;
  font-weight: 800;
}

.edit-form label {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: #576070;
}

.edit-form input {
  border: 1px solid #d7d7d7;
  border-radius: 12px;
  padding: 12px 14px;
}

.save-btn {
  background: #07c160 !important;
  color: #fff !important;
}

.sidebar {
  background: var(--sidebar);
  color: #213040;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.me {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 16px 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f7faff 100%);
}

.me p {
  margin: 2px 0 0;
  color: #40b977;
}

#logoutBtn {
  background: #f2f4f8;
  color: #344355;
}

.search-wrap {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.user-list {
  overflow-y: auto;
}

.user-item {
  padding: 14px 12px;
  border-bottom: 1px solid #eef2f7;
  cursor: pointer;
  transition: background 0.2s ease;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
}

.user-item.active {
  background: #e8f3ff;
}

.user-item span {
  color: #07a65a;
  font-size: 12px;
  margin-left: 4px;
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #e7eef7;
  overflow: hidden;
}

.conv-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.conv-main {
  min-width: 0;
}

.conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.conv-name {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 12px;
  color: #98a1b2;
  white-space: nowrap;
}

.conv-preview {
  margin-top: 4px;
  font-size: 13px;
  color: #8a93a5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-panel {
  position: relative;
  background: #f2f5fa;
}

.chat-blank {
  width: 100%;
  height: 100%;
  background: #f2f5fa;
}

.chat-content {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.chat-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-nav-btn {
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  width: 86px;
  height: 52px;
  margin: -12px 0;
  margin-left: -12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #202020;
  cursor: pointer;
  border-radius: 10px;
}

#chatWith {
  margin: 0;
}

.messages {
  padding: 20px 22px;
  overflow-y: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0.58)),
    radial-gradient(circle at top right, #f9fbfe 0, #edf2f8 35%, #e9eff8 100%);
}

.msg-row {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
}

.msg-row.row-theirs {
  justify-content: flex-start;
}

.msg-row.row-mine {
  justify-content: flex-end;
}

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: min(72%, 520px);
  padding: 10px 13px;
  border-radius: 14px;
  line-height: 1.4;
  box-shadow: 0 4px 10px rgba(33, 48, 64, 0.06);
  transition: transform 0.18s ease;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.recalled {
  color: #6d7788;
  background: #eef2f7;
}

.bubble img {
  max-width: 220px;
  border-radius: 10px;
  display: block;
}

.bubble a {
  color: #2b5fc7;
  text-decoration: none;
}

.bubble-mine {
  background: #95ec69;
}

.bubble-theirs {
  background: #fff;
  border: 1px solid #edf2f7;
}

.bubble audio {
  width: min(260px, 100%);
  display: block;
}

.recall-btn {
  border: none;
  border-radius: 10px;
  background: #ff4d4f;
  color: #fff;
  padding: 8px 10px;
  min-width: 54px;
  height: 38px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(8px);
  transition: all 0.18s ease;
}

.msg-row.row-mine.recall-open .bubble {
  transform: translateX(-8px);
}

.msg-row.row-mine.recall-open .recall-btn {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.send-form {
  padding: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  background: var(--panel);
  position: relative;
}

.chat-tools {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.chat-tools button {
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  background: #f1f3f7;
  color: #4a5568;
}

.emoji-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #fff;
  border: 1px solid #e8ecf3;
  border-radius: 10px;
  padding: 8px;
}

.emoji-panel button {
  border: none;
  background: #f6f8fc;
  border-radius: 8px;
  padding: 4px 6px;
}

.bottom-nav {
  display: none;
}

.call-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
}

.call-box {
  background: #101114;
  color: #fff;
  border-radius: 16px;
  width: min(92vw, 760px);
  padding: 18px;
}

.videos {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 10px;
}

video {
  width: 100%;
  height: 220px;
  background: black;
  border-radius: 10px;
  object-fit: cover;
}

.call-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

#rejectBtn,
#hangupBtn {
  background: #dc4545;
  color: #fff;
}

@media (max-width: 900px) {
  .app {
    height: 100vh;
    display: block;
    box-shadow: none;
    overflow: hidden;
    padding-bottom: 64px;
  }

  .desktop-rail {
    display: none;
  }

  .app-view {
    grid-template-columns: 1fr;
    height: calc(100vh - 64px);
    padding-bottom: 64px;
    position: relative;
    z-index: 1;
  }

  .sidebar {
    height: 40%;
  }

  .chat-panel {
    height: 60%;
  }

  /* 微信里：未进入会话时只显示列表，不显示下方聊天面板 */
  .app.mobile-chat-list .chat-panel {
    display: none;
  }

  .app.mobile-chat-list .sidebar {
    height: calc(100vh - 64px);
  }

  .app.mobile-chat-open .sidebar {
    display: none;
  }

  .app.mobile-chat-open .chat-panel {
    height: calc(100vh - 64px);
  }

  .app.mobile-chat-open .chat-content {
    height: 100%;
  }

  .mobile-view {
    height: calc(100vh - 64px);
    overflow-y: auto;
    padding-bottom: 80px;
    position: relative;
    z-index: 1;
  }

  .contacts-layout {
    display: block;
    height: auto;
    background: transparent;
  }

  .contacts-left {
    border-right: none;
    background: #f5f6fa;
  }

  .contacts-right {
    display: none;
  }

  .contacts-list {
    height: auto;
    max-height: calc(100vh - 240px);
  }

  .contact-group-title {
    display: block;
  }

  .contacts-index {
    display: flex;
  }

  .bubble {
    max-width: min(85%, 420px);
  }

  .videos {
    grid-template-columns: 1fr;
  }

  .chat-header {
    padding: 12px;
    background: #f3f3f3;
    justify-content: space-between;
  }

  #chatWith {
    flex: 1;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
  }

  .call-buttons button {
    padding: 8px 10px;
    font-size: 13px;
  }

  .send-form {
    background: #f4f4f4;
    grid-template-columns: 1fr auto;
  }

  .send-form button {
    border-radius: 16px;
    padding: 10px 14px;
  }

  .bottom-nav {
    display: grid;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    grid-template-columns: repeat(4, 1fr);
    background: #fff;
    border-top: 1px solid #e5e5e5;
    height: 64px;
    z-index: 9999;
    pointer-events: auto;
  }

  .nav-item {
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7a7a7a;
    font-size: 14px;
    height: 64px;
    touch-action: manipulation;
    pointer-events: auto;
  position: relative;
  }

  .nav-item.active {
    color: #07c160;
    font-weight: 600;
  }

  .nav-item .badge {
    position: absolute;
    top: 8px;
    right: 18px;
    margin-left: 0;
  }
}

.moment-list {
  margin-top: 12px;
}

.moment-item {
  padding: 12px;
  border-bottom: 1px solid #ececec;
}

.moment-head {
  font-size: 13px;
  color: #6a7384;
  margin-bottom: 6px;
}

.moment-body {
  white-space: pre-wrap;
}

.moment-body img {
  width: 100%;
  max-width: 280px;
  border-radius: 10px;
  margin-top: 8px;
}

#momentInput {
  width: 100%;
  border: 1px solid #d7d7d7;
  border-radius: 10px;
  padding: 10px;
  resize: vertical;
}

.moment-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.moment-actions button {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  background: #edf1f7;
}

.moment-preview {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}

.moment-preview-item {
  background: #f8fafd;
  border: 1px solid #e5e9f1;
  border-radius: 10px;
  padding: 6px;
  cursor: grab;
  touch-action: pan-y;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.moment-preview-item.dragging {
  cursor: grabbing;
  transform: scale(0.98);
  box-shadow: 0 8px 18px rgba(52, 76, 109, 0.16);
}

.moment-preview img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

.moment-body-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  margin-top: 8px;
  max-width: 320px;
}

.moment-body-images img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
}
