:root {
  --bg: #f4f5f7;
  --surface: #fff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --brand: #07c160;
  --bubble-me: #95ec69;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: #e9edf3;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif;
  color: var(--text);
}
.hidden { display:none !important; }

.auth-screen { width: 100%; max-width: 430px; }
.auth-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  border: 1px solid #dbe1ea;
  box-shadow: 0 12px 30px rgba(15,23,42,.12);
}
.auth-card h1 { margin: 0; }
.auth-card p, .auth-card small { color: var(--muted); }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin: 10px 0; }
.auth-form { display:grid; gap:8px; }
.auth-form input, #searchInput, #messageInput, #friendSearchInput {
  border:1px solid #d8dee8; border-radius:10px; padding:10px; width:100%;
}
button { border:none; border-radius:10px; background:#eef2f7; padding:8px 10px; }
button.primary, .auth-tabs .active, .send-btn, .card .actions button.primary, .home-tabbar .tab-item.active { background: var(--brand); color:#fff; }

.mobile-shell {
  width:100%; max-width:430px; height:min(920px,96vh);
  background: var(--bg); border:1px solid #d8dde8; border-radius:24px;
  display:grid; grid-template-rows:auto 1fr auto auto; overflow:hidden;
  box-shadow: 0 16px 40px rgba(31,41,55,.2);
}
.topbar {
  border-bottom:1px solid var(--line);
  background:#f8fafc;
  padding:max(12px,env(safe-area-inset-top)) 12px 10px;
  display:grid; grid-template-columns:34px 1fr 34px; align-items:center; gap:8px;
}
.icon-btn { width:34px; height:34px; padding:0; font-size:20px; }
.topbar-title { text-align:center; }
.topbar-title h2 { margin:0; font-size:1.05rem; }
.topbar-title p { margin:3px 0 0; color:var(--muted); font-size:.75rem; }

.chat-list-view { overflow:auto; padding:10px; }
.toolbar { display:grid; grid-template-columns:1fr auto; gap:8px; margin-bottom:10px; }
.chat-list, .friend-list { display:grid; gap:8px; }
.chat-item, .friend-item {
  background:#fff; border:1px solid #e0e5ef; border-radius:12px; padding:10px;
  display:grid; grid-template-columns:38px 1fr auto; align-items:center; gap:8px;
}
.chat-item .preview, .friend-item .preview { color:var(--muted); font-size:.78rem; margin-top:3px; }
.badge { background:#ef4444; color:#fff; border-radius:999px; font-size:.72rem; padding:2px 7px; }
.unread-btn {
  background:#ef4444;
  color:#fff;
  border-radius:999px;
  font-size:.72rem;
  padding:4px 8px;
}
.group-title { font-size:.78rem; color:#64748b; padding:6px 4px; }

.messages { overflow:auto; padding:10px 12px; display:grid; gap:6px; background:#f0f3f7; }
.message-row { display:flex; gap:6px; max-width:94%; align-items:flex-start; }
.message-row.me { margin-left:auto; flex-direction:row-reverse; }
.avatar {
  width:34px; height:34px; border-radius:10px; background:linear-gradient(135deg,#93c5fd,#60a5fa);
  color:#fff; display:grid; place-items:center; font-weight:700;
}
.message-row.me .avatar { background:linear-gradient(135deg,#86efac,#22c55e); }
.clickable-avatar { cursor:pointer; }
.content-wrap { display:grid; gap:2px; }
.sender { font-size:.68rem; color:var(--muted); }
.message-row.me .sender { text-align:right; }
.bubble,.card { background:#fff; border:1px solid #e4e9f2; border-radius:12px; padding:8px 10px; }
.message-row.me .bubble { background:var(--bubble-me); border-color:#85d35f; }
.image-bubble { padding:4px !important; }
.image-bubble img { width:170px; max-width:56vw; border-radius:8px; display:block; }
.card { min-width:220px; max-width:280px; }
.chip { background:#dcfce7; color:#166534; border-radius:999px; padding:2px 8px; font-size:.7rem; }
.description { margin:7px 0; font-size:.84rem; }
.meta { color:var(--muted); font-size:.75rem; margin-bottom:8px; }
.card .actions { display:flex; flex-wrap:wrap; gap:6px; }

.composer-panel {
  background:#f7f7f8; border-top:1px solid var(--line);
  padding:8px 10px calc(10px + env(safe-area-inset-bottom)); display:grid; gap:8px;
}
.action-panel { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; }
.action-panel button { font-size:.74rem; padding:8px 4px; display:grid; gap:4px; justify-items:center; background:#eef2f7; }
.action-panel button img { width:24px; height:24px; display:block; }
.action-panel button span { line-height:1; }
.composer { display:grid; grid-template-columns:34px 1fr auto; gap:8px; }
.plus-btn { width:34px; height:34px; padding:0; font-size:20px; }

.home-tabbar {
  display:grid;
  grid-template-columns:1fr 1fr auto 1fr 1fr;
  gap:8px;
  align-items:end;
  padding:6px 10px calc(8px + env(safe-area-inset-bottom));
  border-top:1px solid var(--line);
  background:#fff;
}
.tab-item { font-size:.82rem; padding:9px 8px; }
.publish-tab {
  width:52px;
  height:52px;
  border-radius:50%;
  padding:0;
  font-size:28px;
  line-height:1;
  background:var(--brand);
  color:#fff;
  box-shadow:0 8px 20px rgba(7,193,96,.35);
  transform:translateY(-12px);
}
#logoutBtn { width:100%; }

.publish-sheet {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.35);
  display: grid;
  align-items: end;
  z-index: 25;
}
.publish-card {
  background:#fff;
  border-radius:16px 16px 0 0;
  padding:14px;
  display:grid;
  gap:8px;
}
.publish-card h3 { margin: 0; }
.publish-card p { margin: 0; color: var(--muted); font-size:.86rem; }

.profile-card { max-height: 72vh; overflow: auto; }
.profile-header { display:grid; grid-template-columns:48px 1fr; gap:10px; align-items:center; }
.profile-avatar { width:48px; height:48px; border-radius:14px; font-size:1.15rem; }

.call-panel {
  position: fixed;
  inset: 12px;
  max-width: 430px;
  margin: 0 auto;
  background: rgba(17,24,39,.95);
  color: #fff;
  border-radius: 18px;
  z-index: 30;
  padding: 12px;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 8px;
}
.call-panel video { width: 100%; background: #000; border-radius: 10px; min-height: 120px; }
#localVideo { width: 42%; justify-self: end; }
.call-actions { display:flex; gap:8px; justify-content:center; }

@media (max-width:450px) {
  body { padding:0; }
  .mobile-shell { max-width:100%; height:100vh; border:none; border-radius:0; box-shadow:none; }
  .auth-screen { max-width:100%; padding:10px; }
  .call-panel { inset: 0; border-radius: 0; max-width: 100%; }
}
