/* ==========================================================
   微信界面 · 视觉层
   色值/尺寸对齐 iOS 微信：背景 #EDEDED、自己气泡 #95EC69、
   主绿 #07C160、未读 #FA5151、分割线 #E5E5E5
   ========================================================== */

:root {
  --green: #07C160;
  --bubble-me: #95EC69;
  --bubble-other: #FFFFFF;
  --bg: #EDEDED;
  --nav: #EDEDED;
  --card: #FFFFFF;
  --pressed: #E5E5E5;
  --text: #191919;
  --text-2: #888888;
  --text-3: #9A9A9A;
  --line: #E5E5E5;
  --red: #FA5151;
  --blue: #576B95;
  --tab: #F7F7F7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 44px;
  --tab-h: 50px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button {
  font: inherit; color: inherit; background: none; border: 0;
  padding: 0; margin: 0; cursor: pointer; text-align: left;
}
svg { width: 24px; height: 24px; display: block; flex: none; }
input, textarea { font: inherit; color: inherit; }

/* ---------- 主容器 ---------- */
.app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
}

.page { display: none; flex: 1; min-height: 0; flex-direction: column; }
.page.active { display: flex; }

.scroll {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ---------- 顶部导航 ---------- */
.nav {
  flex: none;
  height: calc(var(--nav-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center;
  background: var(--nav);
  position: relative;
}
.nav::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0;
  height: 0.5px; background: rgba(0,0,0,.12);
  transform: scaleY(.5); transform-origin: bottom;
}
.nav h1 {
  flex: 1; margin: 0;
  font-size: 17px; font-weight: 600; letter-spacing: .2px;
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 8px;
}
/* 微信列表页标题是左对齐的 */
#p-chats .nav h1, #p-contacts .nav h1, #p-discover .nav h1 { text-align: left; padding-left: 16px; font-size: 17px; }

.nav-acts { display: flex; align-items: center; gap: 2px; padding-right: 6px; }
.ibtn {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: #181818; flex: none;
}
.ibtn:active { opacity: .5; }
.nav-acts .ibtn svg { width: 22px; height: 22px; }

/* ---------- 会话列表 ---------- */
#p-chats .scroll { background: var(--card); }
#chat-list { background: var(--card); }

.chat-row {
  display: flex; align-items: center;
  width: 100%;
  padding: 10px 16px;
  background: var(--card);
  position: relative;
  transition: background .08s;
}
.chat-row:active { background: var(--pressed); }
.chat-row::after {
  content: ""; position: absolute; left: 76px; right: 0; bottom: 0;
  height: 0.5px; background: var(--line);
  transform: scaleY(.5); transform-origin: bottom;
}
.chat-row:last-child::after { display: none; }
.chat-row.pinned { background: #F5F5F5; }
.chat-row.pinned:active { background: #E8E8E8; }

.avatar {
  width: 48px; height: 48px; flex: none;
  border-radius: 5px;
  background: #C9C9C9 center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 19px; font-weight: 500;
  overflow: hidden; position: relative;
  user-select: none;
}
.avatar.lg { width: 64px; height: 64px; border-radius: 7px; font-size: 26px; }
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar.xs { width: 30px; height: 30px; border-radius: 3px; font-size: 13px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chat-main {
  flex: 1; min-width: 0;
  padding-left: 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.chat-top { display: flex; align-items: baseline; gap: 8px; }
.chat-name {
  flex: 1; min-width: 0;
  font-size: 16.5px; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-time { font-size: 12px; color: var(--text-3); flex: none; }
.chat-bottom { display: flex; align-items: center; gap: 8px; }
.chat-preview {
  flex: 1; min-width: 0;
  font-size: 13.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-preview .tag { color: var(--red); }

.badge {
  flex: none; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--red); color: #fff;
  font-size: 11.5px; font-weight: 500; line-height: 18px; text-align: center;
}
.badge.dot { min-width: 9px; width: 9px; height: 9px; padding: 0; border-radius: 50%; }
.mute-ico { flex: none; color: #B2B2B2; }
.mute-ico svg { width: 15px; height: 15px; }

/* ---------- 通讯录 ---------- */
#contact-list { background: var(--card); }

.group { margin-top: 9px; background: var(--card); }
.group:first-child { margin-top: 0; }

.cell {
  display: flex; align-items: center;
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  background: var(--card);
  position: relative;
}
.cell:active { background: var(--pressed); }
.cell::after {
  content: ""; position: absolute; left: 52px; right: 0; bottom: 0;
  height: 0.5px; background: var(--line);
  transform: scaleY(.5); transform-origin: bottom;
}
.group .cell:last-child::after { display: none; }
.cell-icon { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; margin-right: 12px; flex: none; }
.cell-icon svg { width: 22px; height: 22px; }
.cell-label { flex: 1; font-size: 16px; }
.cell-arrow { width: 16px; height: 16px; color: #C8C8CD; flex: none; }
.cell-badge { font-size: 13px; color: var(--text-3); margin-right: 2px; }
.cell.danger .cell-label { color: var(--red); }

.contact-letter {
  padding: 5px 16px;
  font-size: 13px; color: var(--text-2);
  background: #F7F7F7;
  position: sticky; top: 0; z-index: 2;
}
.contact-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 8px 16px;
  background: var(--card); position: relative;
}
.contact-row:active { background: var(--pressed); }
.contact-row::after {
  content: ""; position: absolute; left: 68px; right: 0; bottom: 0;
  height: 0.5px; background: var(--line);
  transform: scaleY(.5); transform-origin: bottom;
}
.contact-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 右侧字母索引 */
.alpha-index {
  position: absolute; right: 2px; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center;
  z-index: 5;
  padding: 4px 3px;
}
.alpha-index b {
  font-size: 10px; font-weight: 500; color: #555;
  line-height: 14px; padding: 0 3px;
  font-family: -apple-system, sans-serif;
}

/* ---------- 我 ---------- */
#p-me { background: var(--bg); }
#p-me .scroll { background: var(--bg); }

.me-header {
  display: flex; align-items: center; gap: 14px;
  width: 100%; padding: 30px 20px 26px;
  background: var(--card);
  position: relative;
}
.me-header:active { background: #F2F2F2; }
.me-info { flex: 1; min-width: 0; }
.me-name { font-size: 21px; font-weight: 600; letter-spacing: .2px; }
.me-id { font-size: 13.5px; color: var(--text-2); margin-top: 7px; }
.me-qr { color: #B2B2B2; }
.me-qr svg { width: 18px; height: 18px; }

/* ---------- 底部 Tab ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--tab);
  z-index: 40;
}
.tabbar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0;
  height: 0.5px; background: rgba(0,0,0,.15);
  transform: scaleY(.5); transform-origin: top;
}
.tab {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
  color: #7A7A7A; position: relative;
}
.tab svg { width: 26px; height: 26px; }
.tab span { font-size: 10px; line-height: 12px; }
.tab.active { color: var(--green); }
.tab .dot {
  position: absolute; top: 5px; left: 50%; margin-left: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); display: none;
}
.tab .dot.on { display: block; }

/* ---------- 覆盖层 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: none; flex-direction: column;
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.32,.72,0,1);
}
.overlay.show { display: flex; transform: translateX(0); }
.overlay.instant { transition: none; }

/* ---------- 聊天页 ---------- */
#v-chat { background: var(--bg); }
.chat-nav h1 { font-size: 17px; font-weight: 600; }
.chat-nav .ibtn:first-child { margin-left: 2px; }

.msg-scroll {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 8px;
  background: var(--bg);
}

.time-sep {
  text-align: center; margin: 12px 0 14px;
  font-size: 12px; color: #B2B2B2;
}

.msg {
  display: flex; gap: 11px;
  margin-bottom: 16px;
  align-items: flex-start;
}
.msg.me { flex-direction: row-reverse; }
.msg .avatar { width: 40px; height: 40px; border-radius: 4px; font-size: 16px; }

.bubble-wrap { max-width: 68%; display: flex; flex-direction: column; }
.msg.me .bubble-wrap { align-items: flex-end; }

.bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: 5px;
  font-size: 16px;
  line-height: 1.42;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--bubble-other);
  color: #191919;
  min-height: 38px;
}
.msg.me .bubble { background: var(--bubble-me); }

/* 气泡小尖角 */
.bubble::before {
  content: ""; position: absolute;
  top: 13px; left: -5px;
  width: 0; height: 0;
  border: 5px solid transparent;
  border-right-color: var(--bubble-other);
  border-left: 0;
}
.msg.me .bubble::before {
  left: auto; right: -5px;
  border-right-color: transparent;
  border-left: 5px solid var(--bubble-me);
  border-left-width: 5px;
}

.bubble.img { padding: 0; background: transparent !important; min-height: 0; }
.bubble.img::before { display: none; }
.bubble.img img { display: block; max-width: 190px; border-radius: 5px; }

.bubble.voice {
  display: flex; align-items: center; gap: 6px;
  min-width: 90px; cursor: pointer;
}
.bubble.voice .wv { color: #4A4A4A; }
.bubble.voice .wv svg { width: 17px; height: 17px; }

.bubble.sys {
  background: rgba(0,0,0,.045);
  color: #7A7A7A; font-size: 12.5px;
  padding: 5px 10px; border-radius: 4px;
  margin: 0 auto; text-align: center;
}
.bubble.sys::before { display: none; }

.msg-foot { font-size: 11px; color: #B2B2B2; margin-top: 4px; padding: 0 2px; }

.msg-name { font-size: 11.5px; color: var(--text-3); margin-bottom: 3px; padding-left: 2px; }

/* 输入栏 */
.input-bar {
  flex: none;
  display: flex; align-items: flex-end; gap: 4px;
  padding: 7px 6px calc(7px + var(--safe-bottom));
  background: var(--tab);
  position: relative;
}
.input-bar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0;
  height: 0.5px; background: rgba(0,0,0,.12);
  transform: scaleY(.5); transform-origin: top;
}
.input-bar .ibtn { width: 36px; height: 40px; color: #3A3A3A; }
.input-bar .ibtn svg { width: 27px; height: 27px; }

.input-box {
  flex: 1; position: relative;
  background: #fff; border-radius: 5px;
  min-height: 40px; max-height: 110px;
  display: flex; align-items: center;
}
.input-box textarea {
  width: 100%; border: 0; outline: 0; background: transparent;
  resize: none; padding: 9px 10px;
  font-size: 16px; line-height: 1.35;
  max-height: 110px;
  display: block;
}
.input-ph {
  position: absolute; left: 11px; top: 10px;
  color: #B2B2B2; font-size: 16px; pointer-events: none;
}
#msg-input:focus + .input-ph, .input-box.has .input-ph { display: none; }

#btn-send.sending { color: var(--green); }
#btn-send.sending svg { transform: rotate(90deg); }

/* ---------- 朋友圈 ---------- */
#v-moments { background: var(--card); }
.moments-nav { background: #EDEDED; }

.moments-cover {
  position: relative;
  height: 300px;
  background: linear-gradient(160deg, #6E7B8B 0%, #4A5568 45%, #2D3748 100%);
  background-position: center; background-size: cover;
  margin-bottom: 44px;
}
.cover-veil {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.12), rgba(0,0,0,.28));
}
.cover-me {
  position: absolute; right: 16px; bottom: -26px;
  display: flex; align-items: center; gap: 8px;
}
.cover-me .me-name {
  font-size: 17px; font-weight: 600; color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.45);
  margin-bottom: 4px;
  white-space: nowrap;
}
.cover-me .avatar {
  width: 66px; height: 66px; border-radius: 8px;
  border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15);
  font-size: 26px;
}

.moment {
  display: flex; gap: 10px;
  padding: 18px 16px 6px;
  position: relative;
}
.moment::after {
  content: ""; position: absolute; left: 16px; right: 16px; bottom: 0;
  height: 0.5px; background: var(--line);
  transform: scaleY(.5); transform-origin: bottom;
}
.moment .avatar { width: 42px; height: 42px; border-radius: 4px; font-size: 17px; }

.moment-body { flex: 1; min-width: 0; }
.moment-name { font-size: 15.5px; font-weight: 600; color: var(--blue); margin-bottom: 4px; }
.moment-text {
  font-size: 15.5px; line-height: 1.44;
  white-space: pre-wrap; word-break: break-word;
  margin-bottom: 6px;
}
.moment-imgs {
  display: grid; gap: 3px;
  grid-template-columns: repeat(3, 1fr);
  max-width: 100%;
  margin: 6px 0 4px;
}
.moment-imgs.n1 { grid-template-columns: minmax(0, 62%); }
.moment-imgs.n2 { grid-template-columns: repeat(2, minmax(0, 46%)); }
.moment-imgs.n4 { grid-template-columns: repeat(2, minmax(0, 46%)); }
.moment-img {
  position: relative;
  height: 0; padding-bottom: 100%;
  border-radius: 2px;
  background: #DDD center/cover no-repeat;
  overflow: hidden;
}
.moment-imgs.n1 .moment-img { padding-bottom: 75%; }

.moment-loc { font-size: 12.5px; color: var(--blue); margin: 2px 0 6px; }

.moment-bar {
  display: flex; align-items: center; gap: 14px;
  margin: 6px 0 4px;
}
.moment-time { font-size: 12.5px; color: var(--text-3); flex: 1; }
.moment-op {
  width: 30px; height: 22px;
  border-radius: 4px; background: #F2F2F2;
  display: flex; align-items: center; justify-content: center;
  color: #576B95;
}
.moment-op svg { width: 15px; height: 15px; }
.moment-op:active { background: #E5E5E5; }

.moment-social {
  background: #F7F7F7; border-radius: 3px;
  padding: 7px 9px; margin: 4px 0 8px;
  font-size: 14px; line-height: 1.5;
}
.moment-likes {
  display: flex; align-items: flex-start; gap: 4px;
  color: var(--blue);
  padding-bottom: 5px;
}
.moment-likes svg { width: 14px; height: 14px; margin-top: 3px; flex: none; }
.moment-likes span { flex: 1; }
.moment-likes + .moment-comments { border-top: 0.5px solid #E2E2E2; padding-top: 4px; }
.moment-comments { padding-top: 4px; }
.moment-comment { font-size: 14px; line-height: 1.5; }
.moment-comment b { color: var(--blue); font-weight: 400; }

/* ---------- 数据面板 ---------- */
.panel-note {
  padding: 14px 16px 10px;
  font-size: 13px; line-height: 1.55; color: var(--text-2);
}
.cell-file { position: relative; cursor: pointer; }
.cell-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cell-col { flex-direction: column; align-items: stretch; padding: 14px 16px 16px; gap: 10px; }
.cell-col .cell-label { font-size: 15px; }
.cell-col textarea {
  width: 100%; min-height: 130px; resize: vertical;
  border: 0.5px solid var(--line); border-radius: 6px;
  padding: 10px; font-size: 14px; line-height: 1.5;
  outline: 0; background: #FAFAFA;
}
.btn-primary {
  height: 42px; border-radius: 6px;
  background: var(--green); color: #fff;
  font-size: 16px; text-align: center;
}
.btn-primary:active { opacity: .85; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22%;
  transform: translate(-50%, 10px);
  background: rgba(0,0,0,.78); color: #fff;
  font-size: 14px; padding: 9px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 300; max-width: 76vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 空态 ---------- */
.empty {
  padding: 60px 30px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px; line-height: 1.7;
}

/* ---------- 桌面预览：约束成手机尺寸 ---------- */
@media (min-width: 600px) {
  body { background: #D8D8D8; }
  .app, .overlay {
    max-width: 430px; left: 50%; right: auto;
    transform: translateX(-50%);
    box-shadow: 0 0 0 1px rgba(0,0,0,.06), 0 18px 50px rgba(0,0,0,.16);
  }
  .overlay { display: none; }
  .overlay.show { display: flex; transform: translateX(-50%); }
  .overlay.instant { transition: none; }
  .tabbar { max-width: 430px; left: 50%; transform: translateX(-50%); }
  /* 侧滑动画在桌面端弱化 */
  .overlay:not(.show) { transform: translateX(calc(-50% + 100%)); }
}
