:root {
  --wx-green: #07C160;
  --wx-green-dark: #06AD56;
  --wx-bubble-me: #95EC69;
  --wx-bubble-me-active: #89DF5E;
  --wx-bubble-other: #FFFFFF;
  --wx-bg: #EDEDED;
  --wx-chat-bg: #EDEDED;
  --wx-sidebar: #F7F7F7;
  --wx-white: #FFFFFF;
  --wx-rail: #2E2E2E;
  --wx-border: #DCDCDC;
  --wx-border-light: #EAEAEA;
  --wx-text: #181818;
  --wx-text-sub: #7F7F7F;
  --wx-text-muted: #A6A6A6;
  --wx-red: #FA5151;
  --wx-blue: #576B95;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vh: 100dvh;
}

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

html, body {
  width: 100%;
  height: var(--vh);
  overflow: hidden;
  background: var(--wx-bg);
  color: var(--wx-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

svg {
  display: block;
  flex-shrink: 0;
}

/* ================= TOAST ================= */
.toast {
  position: fixed;
  top: calc(18px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(24, 24, 24, 0.88);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  z-index: 20000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================= AUTH VIEW ================= */
.auth-view {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #F5F7F6 0%, #E7ECE9 100%);
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: #fff;
  border-radius: 16px;
  padding: 32px 26px 28px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.logo-mark {
  width: 62px;
  height: 62px;
  border-radius: 16px;
  background: var(--wx-green);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(7, 193, 96, 0.28);
}

.auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--wx-text);
  margin-top: 2px;
}

.auth-logo p {
  font-size: 13px;
  color: var(--wx-text-sub);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #F2F2F2;
  border-radius: 10px;
  padding: 3px;
}

.auth-tab {
  height: 38px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--wx-text-sub);
  transition: all 0.15s;
}
.auth-tab.active {
  background: #fff;
  color: var(--wx-text);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 13px;
  color: var(--wx-text-sub);
  font-weight: 500;
}

.input-group input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid #E0E0E0;
  background: #FAFAFA;
  color: var(--wx-text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.input-group input:focus {
  border-color: var(--wx-green);
  background: #fff;
}

.auth-error {
  font-size: 13px;
  color: var(--wx-red);
  min-height: 18px;
  line-height: 1.4;
}

.btn-wechat-primary {
  width: 100%;
  height: 48px;
  border-radius: 10px;
  background: var(--wx-green);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  transition: background 0.15s, transform 0.08s;
}
.btn-wechat-primary:active {
  background: var(--wx-green-dark);
  transform: scale(0.99);
}
.btn-wechat-primary:disabled {
  opacity: 0.6;
}

.btn-wechat-small {
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--wx-green);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
}
.btn-wechat-small:active { background: var(--wx-green-dark); }
.btn-wechat-small.secondary {
  background: #F0F0F0;
  color: #333;
}
.btn-wechat-small.danger {
  background: #FFF0F0;
  color: var(--wx-red);
}

/* ================= AVATAR ================= */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  user-select: none;
}
.avatar.sm { width: 38px; height: 38px; font-size: 15px; border-radius: 5px; }
.avatar.lg { width: 58px; height: 58px; font-size: 24px; border-radius: 8px; }

.online-dot {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #B8B8B8;
}
.online-dot.on { background: var(--wx-green); }

/* ================= MAIN WECHAT SHELL (DESKTOP) ================= */
.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  background: var(--wx-bg);
}

.wx-rail {
  width: 60px;
  background: var(--wx-rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0 14px;
  gap: 20px;
  flex-shrink: 0;
}

.rail-avatar-btn {
  padding: 0;
  border-radius: 6px;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.rail-bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-item {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #9A9A9A;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: color 0.15s, background 0.15s;
}
.rail-item:hover { color: #D8D8D8; background: rgba(255, 255, 255, 0.06); }
.rail-item.active { color: var(--wx-green); }

.badge-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--wx-red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.badge-dot.show { display: inline-flex; }

/* List Pane */
.list-pane {
  width: 300px;
  background: var(--wx-white);
  border-right: 1px solid var(--wx-border);
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  flex-shrink: 0;
}

.pane-header {
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 14px 0;
  background: var(--wx-bg);
  border-bottom: 1px solid var(--wx-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pane-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pane-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--wx-text);
}

.ws-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #E2E2E2;
  color: #666;
}
.ws-tag.ok { background: #DFF6E7; color: #06964B; }
.ws-tag.err { background: #FDE8E8; color: #D93838; }

.header-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: var(--wx-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.header-icon-btn:active { background: rgba(0, 0, 0, 0.06); }

.list-search-wrap {
  padding: 10px 12px;
  background: var(--wx-sidebar);
  border-bottom: 1px solid var(--wx-border-light);
  flex-shrink: 0;
}

.search-box {
  height: 34px;
  background: #EAEAEA;
  border-radius: 6px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--wx-text-muted);
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  color: var(--wx-text);
}

.scroll-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--wx-white);
}

/* Conversation Row */
.conv-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--wx-white);
  border-bottom: 1px solid #F2F2F2;
  transition: background 0.1s;
}
.conv-row:hover { background: #F5F5F5; }
.conv-row.active { background: #E6E6E6; }

.conv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.conv-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--wx-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  font-size: 11px;
  color: var(--wx-text-muted);
  flex-shrink: 0;
}

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

.conv-preview {
  font-size: 13px;
  color: var(--wx-text-sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--wx-red);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Contacts sections */
.section-label {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--wx-text-sub);
  background: #F4F4F4;
  border-bottom: 1px solid #EBEBEB;
}

.req-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #F2F2F2;
  background: #fff;
}

.req-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Me Pane */
.me-pane {
  background: var(--wx-bg);
}

.me-card {
  background: #fff;
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--wx-border-light);
}

.me-info h2 {
  font-size: 18px;
  font-weight: 600;
}
.me-info p {
  font-size: 13px;
  color: var(--wx-text-sub);
  margin-top: 4px;
}

.me-section {
  margin-top: 10px;
  background: #fff;
  border-top: 1px solid var(--wx-border-light);
  border-bottom: 1px solid var(--wx-border-light);
}

.me-row {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid #F2F2F2;
  font-size: 15px;
}
.me-row:last-child { border-bottom: none; }

.color-dots {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
}
.color-dot.selected {
  border-color: #181818;
  transform: scale(1.1);
}

.me-logout-wrap {
  padding: 16px;
}
.btn-logout {
  width: 100%;
  height: 46px;
  background: #fff;
  color: var(--wx-red);
  font-size: 16px;
  font-weight: 500;
  border-radius: 10px;
  border: 1px solid #EAEAEA;
}
.btn-logout:active { background: #FFF5F5; }

/* Mobile TabBar (hidden on desktop) */
.mobile-tabbar {
  display: none;
}

/* Mini call bar */
.mini-call-bar {
  background: #E8F8EF;
  border-bottom: 1px solid #C6EED8;
  color: #068944;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.mini-call-bar span:nth-child(2) { flex: 1; }
.mini-call-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--wx-green);
  animation: pulseDot 1.3s infinite;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

/* ================= CHAT PANE ================= */
.chat-pane {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: var(--wx-chat-bg);
  display: flex;
  flex-direction: column;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--wx-text-muted);
  font-size: 14px;
  padding: 20px;
  text-align: center;
}

.chat-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat-header {
  height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 10px 0 14px;
  background: var(--wx-bg);
  border-bottom: 1px solid var(--wx-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.chat-back-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  color: var(--wx-text);
  margin-left: -8px;
}

.chat-peer-info {
  min-width: 0;
}
.chat-peer-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--wx-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-peer-status {
  font-size: 11px;
  color: var(--wx-text-sub);
}
.chat-peer-status.on { color: #06964B; }

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* Messages Stream */
.messages-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-time-divider {
  align-self: center;
  font-size: 12px;
  color: var(--wx-text-muted);
  padding: 2px 8px;
}

.msg-sys {
  align-self: center;
  font-size: 12px;
  color: var(--wx-text-sub);
  background: rgba(0, 0, 0, 0.06);
  padding: 4px 12px;
  border-radius: 6px;
  max-width: 86%;
  text-align: center;
  line-height: 1.4;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}
.msg-row.me {
  flex-direction: row-reverse;
}

.msg-status-spin {
  width: 15px;
  height: 15px;
  border: 2px solid #CCCCCC;
  border-top-color: #666666;
  border-radius: 50%;
  margin-top: 13px;
  animation: wxSpin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes wxSpin { to { transform: rotate(360deg); } }

.msg-status-fail {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--wx-red);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-bubble {
  position: relative;
  max-width: min(72%, 440px);
  padding: 10px 13px;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--wx-text);
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--wx-bubble-other);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

.msg-row.me .msg-bubble {
  background: var(--wx-bubble-me);
}

/* Authentic WeChat Speech Triangle */
.msg-row.other .msg-bubble::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 13px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 6px solid var(--wx-bubble-other);
}
.msg-row.me .msg-bubble::before {
  content: '';
  position: absolute;
  right: -6px;
  top: 13px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 6px solid var(--wx-bubble-me);
}

.msg-bubble.call-bubble {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
}

.msg-bubble.img-bubble {
  padding: 0;
  background: transparent !important;
  box-shadow: none;
}
.msg-bubble.img-bubble::before { display: none; }
.msg-bubble.img-bubble img {
  display: block;
  max-width: 210px;
  max-height: 260px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* WeChat Composer */
.wx-composer-wrap {
  background: #F7F7F7;
  border-top: 1px solid var(--wx-border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

.wx-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}

.wx-composer input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 6px;
  background: #FFFFFF;
  font-size: 16px;
  color: var(--wx-text);
  outline: none;
}

.composer-icon-btn {
  width: 36px;
  height: 36px;
  color: #181818;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send {
  height: 36px;
  padding: 0 15px;
  border-radius: 6px;
  background: var(--wx-green);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.btn-send:active { background: var(--wx-green-dark); }

.composer-drawer {
  border-top: 1px solid var(--wx-border-light);
  background: #F6F6F6;
  padding: 14px 16px 18px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.emoji-btn {
  height: 38px;
  font-size: 24px;
  border-radius: 8px;
}
.emoji-btn:active { background: rgba(0, 0, 0, 0.08); }

.plus-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.plus-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--wx-text-sub);
}
.plus-box {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.plus-item:active .plus-box { background: #EAEAEA; }

/* ================= MODALS ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 5000;
}

.modal-sheet {
  width: 100%;
  max-width: 400px;
  max-height: 82dvh;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.modal-header {
  padding: 14px 16px;
  background: var(--wx-bg);
  border-bottom: 1px solid var(--wx-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  width: 32px;
  height: 32px;
  font-size: 18px;
  color: var(--wx-text-sub);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-search-row {
  display: flex;
  gap: 8px;
}
.modal-search-row input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  font-size: 16px;
  border: 1px solid #DCDCDC;
  border-radius: 8px;
  outline: none;
}
.modal-search-row input:focus { border-color: var(--wx-green); }

.search-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: #F8F8F8;
  border-radius: 10px;
}
.search-user-info {
  flex: 1;
  min-width: 0;
}
.search-user-info .name { font-size: 15px; font-weight: 500; }
.search-user-info .sub { font-size: 12px; color: var(--wx-text-sub); margin-top: 2px; }

.empty-hint {
  text-align: center;
  padding: 28px 12px;
  font-size: 13px;
  color: var(--wx-text-muted);
  line-height: 1.6;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 15000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 6px;
}

/* ================= FULLSCREEN CALL OVERLAY ================= */
.call-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--vh);
  z-index: 9999;
  background: linear-gradient(160deg, #1d2633 0%, #10151d 52%, #0a0d12 100%);
  color: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.call-video-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#remoteVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #090c11;
  z-index: 1;
}
#remoteVideo.fit-contain {
  object-fit: contain;
}

#localVideo {
  position: absolute;
  top: calc(74px + var(--safe-top));
  right: 14px;
  width: 104px;
  height: 156px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  background: #141920;
  z-index: 12;
  display: none;
  cursor: pointer;
}
#localVideo.landscape-pip {
  width: 156px;
  height: 100px;
}
#localVideo.show { display: block; }
#localVideo.mirrored { transform: scaleX(-1); }

/* Swapped PiP */
.call-video-layer.swapped #remoteVideo {
  inset: auto;
  top: calc(74px + var(--safe-top));
  right: 14px;
  width: 104px;
  height: 156px;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  z-index: 12;
}
.call-video-layer.swapped #remoteVideo.landscape-pip {
  width: 156px;
  height: 100px;
}
.call-video-layer.swapped #localVideo {
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  z-index: 1;
}
.call-video-layer.swapped #localVideo.fit-contain {
  object-fit: contain;
}

/* Avatar Stage (Ringing / Incoming / Audio-only) */
.call-avatar-stage {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-bottom: 130px;
  pointer-events: none;
}

.call-avatar-ring {
  padding: 8px;
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.08);
  animation: ringPulse 2s ease-in-out infinite;
}
@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(7, 193, 96, 0.35); }
  50% { box-shadow: 0 0 0 16px rgba(7, 193, 96, 0); }
}

.call-avatar-box {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  background: var(--wx-green);
  color: #fff;
  font-size: 40px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-peer-title {
  margin-top: 20px;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.call-sub-status {
  margin-top: 8px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.72);
}

/* Call Top HUD */
.call-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 25;
  padding: calc(14px + var(--safe-top)) 14px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55) 0%, transparent 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.call-top-btn {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.call-hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.call-timer {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.call-net-chip {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.9);
  font-variant-numeric: tabular-nums;
  max-width: 68vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Call Bottom Controls (Elevated well above mobile browser bars & gesture home indicator!) */
.call-controls-incoming,
.call-controls-ringing,
.call-controls-active {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  pointer-events: auto;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.5) 68%, transparent 100%);
  padding: 26px 20px max(42px, calc(30px + var(--safe-bottom)));
}

.call-controls-incoming {
  display: flex;
  align-items: center;
  justify-content: space-around;
  max-width: 380px;
  margin: 0 auto;
}

.call-controls-ringing {
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-controls-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.call-tools-row {
  width: 100%;
  max-width: 400px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  justify-items: center;
}

.call-hangup-row {
  display: flex;
  justify-content: center;
}

.call-btn-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
}

.call-round-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.1s ease, background 0.15s ease;
  position: relative;
  z-index: 31;
  pointer-events: auto;
}
.call-round-btn:active { transform: scale(0.92); }
.call-round-btn.lg { width: 68px; height: 68px; }
.call-round-btn.glass {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.call-round-btn.glass.on-state {
  background: #ffffff;
  color: #181818;
}
.call-round-btn.red {
  background: var(--wx-red);
  box-shadow: 0 8px 24px rgba(250, 81, 81, 0.45);
}
.call-round-btn.green {
  background: var(--wx-green);
  box-shadow: 0 8px 24px rgba(7, 193, 96, 0.45);
}

/* ================= MOBILE RESPONSIVE (<= 768px) ================= */
@media (max-width: 768px) {
  .wx-rail {
    display: none;
  }

  .app-shell {
    position: relative;
    overflow: hidden;
  }

  .list-pane {
    width: 100%;
    border-right: none;
  }

  .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: #F7F7F7;
    border-top: 1px solid var(--wx-border);
    padding: 6px 0 max(6px, var(--safe-bottom));
    flex-shrink: 0;
  }

  .tabbar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 11px;
    color: #555;
    min-height: 46px;
  }
  .tabbar-item.active { color: var(--wx-green); }

  .tabbar-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 26px;
  }
  .tabbar-icon .badge-dot {
    top: -4px;
    right: -8px;
  }

  /* Mobile Chat Slide-Over Secondary Screen */
  .chat-pane {
    position: fixed;
    inset: 0;
    width: 100%;
    height: var(--vh);
    z-index: 40;
    transform: translateX(100%);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .app-shell.mobile-in-chat .chat-pane {
    transform: translateX(0);
  }

  .chat-back-btn {
    display: inline-flex;
  }

  .chat-empty {
    display: none;
  }

  .msg-bubble {
    max-width: 76%;
  }

  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
  }
}
