:root{
  --bg:#080c10;
  --bg-gradient:radial-gradient(circle at 50% 0%, #111a24 0%, #070a0e 100%);
  --bg-elevated:#131d27;
  --card:#182330;
  --card-hover:rgba(255,255,255,0.04);
  --line:rgba(255,255,255,0.08);
  --line-strong:rgba(255,255,255,0.15);
  --text:#f8fafc;
  --text-muted:#94a3b8;
  --c-user:#fbbf24;
  --c-admin:#a855f7;
  --c-chat-tab:#10b981;
  --c-call-tab:#0ea5e9;
  --danger:#ef4444;
  --success:#22c55e;
  --accent:#f59e0b;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;margin:0;padding:0}
html,body{
  height:100%;
  height:100dvh;
  width:100%;
  overflow:hidden;
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  user-select:none;
}
.screen{
  position:fixed;
  inset:0;
  height:100%;
  height:100dvh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}
[hidden]{display:none !important}
button{font-family:inherit;cursor:pointer;outline:none}

#networkBanner{
  background:var(--danger);
  color:#fff;
  font-size:12px;
  font-weight:800;
  text-align:center;
  padding:6px 10px;
  z-index:999;
  flex-shrink:0;
  transition:transform .3s;
}
#networkBanner.online{background:var(--success)}

/* MAIN SCREEN / LOBBY */
#lobby{
  background:var(--bg-gradient);
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding:calc(14px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  align-items:center;
}
.header{
  width:100%;
  max-width:480px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom:16px;
  flex-shrink:0;
}
.user-title{
  font-size:24px;
  font-weight:900;
  color:var(--c-user);
  letter-spacing:0.3px;
  max-width:210px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  text-shadow:0 0 18px rgba(251,191,36,0.35);
}
.header-actions{display:flex;align-items:center;gap:10px}
.admin-badge{
  font-size:11.5px;
  color:#fff;
  background:linear-gradient(135deg,#9333ea,#6b21a8);
  padding:6px 14px;
  border-radius:20px;
  font-weight:900;
  border:1px solid rgba(168,85,247,0.4);
  display:none;
  box-shadow:0 2px 10px rgba(147,51,234,0.3);
}

.icon-hdr-btn{
  background:rgba(255,255,255,0.06);
  border:1px solid var(--line-strong);
  width:42px;
  height:42px;
  border-radius:50%;
  display:grid;
  place-items:center;
  backdrop-filter:blur(10px);
  transition:transform 0.15s, background 0.2s;
}
.icon-hdr-btn:active{transform:scale(0.92)}
.icon-hdr-btn svg{width:20px;height:20px;fill:currentColor}
.btn-apk-dl{color:#34d399;background:rgba(16,185,129,0.14);border-color:rgba(16,185,129,0.35)}
.btn-gear{color:#38bdf8;background:rgba(14,165,233,0.14);border-color:rgba(14,165,233,0.35)}

.search-wrap{width:100%;max-width:480px;margin-bottom:14px;position:relative;flex-shrink:0}
.search-input{
  width:100%;
  height:44px;
  background:rgba(255,255,255,0.05);
  border:1px solid var(--line-strong);
  border-radius:22px;
  padding:0 16px 0 42px;
  color:#fff;
  font-size:15px;
  outline:none;
  transition:border-color 0.2s, background 0.2s;
}
.search-input:focus{background:rgba(255,255,255,0.08);border-color:rgba(255,255,255,0.3)}
.search-icon{position:absolute;left:15px;top:50%;transform:translateY(-50%);color:#64748b;font-size:16px;pointer-events:none}

.lobby-tabs{
  width:100%;
  max-width:480px;
  display:flex;
  background:rgba(255,255,255,0.04);
  border:1px solid var(--line);
  border-radius:16px;
  padding:5px;
  margin-bottom:14px;
  gap:6px;
  flex-shrink:0;
}
.tab-btn{
  flex:1;
  padding:10px;
  border-radius:12px;
  border:0;
  background:transparent;
  color:var(--text-muted);
  font-size:14px;
  font-weight:800;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  transition:all .2s;
}
.tab-btn.active-chat{background:linear-gradient(135deg,#10b981,#059669);color:#fff;box-shadow:0 4px 14px rgba(16,185,129,0.35)}
.tab-btn.active-call{background:linear-gradient(135deg,#0284c7,#0369a1);color:#fff;box-shadow:0 4px 14px rgba(2,132,199,0.35)}

.tab-content{width:100%;max-width:480px;flex:1}
.contact-card{
  background:transparent;
  border:0;
  border-bottom:1px solid rgba(255,255,255,0.06);
  padding:14px 4px;
  display:flex;
  align-items:center;
  gap:14px;
  cursor:pointer;
  transition:background 0.2s;
}
.contact-card:active{background:var(--card-hover)}
.contact-avatar{
  width:50px;
  height:50px;
  border-radius:50%;
  background:linear-gradient(145deg, #1e293b, #0f172a);
  border:1.5px solid rgba(255,255,255,0.12);
  display:grid;
  place-items:center;
  color:#cbd5e1;
  flex-shrink:0;
}
.contact-avatar svg{width:26px;height:26px;fill:currentColor}
.contact-content{flex:1;min-width:0;display:flex;align-items:center;justify-content:space-between;gap:8px}

.contact-left-col{flex:1;min-width:0;display:flex;flex-direction:column;gap:5px}
.contact-name{font-size:16px;font-weight:800;letter-spacing:0.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#fff}
.contact-last-msg{font-size:14px;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;display:flex;align-items:center;gap:4px}

.contact-right-col{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  justify-content:center;
  gap:4px;
  flex-shrink:0;
  min-width:80px;
}
.msg-time-label{font-size:12px;color:#94a3b8;font-weight:700;white-space:nowrap}
.contact-live-status{font-size:11.5px;font-weight:700;white-space:nowrap;color:#64748b}
.contact-live-status.online{color:var(--success)}
.badge-unread{
  background:var(--success);
  color:#fff;
  font-size:12px;
  font-weight:900;
  min-width:22px;
  height:22px;
  padding:0 6px;
  border-radius:11px;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:0 2px 8px rgba(34,197,94,0.45);
}

/* TICKS - SENT (GREY), DELIVERED (WHITE), READ (RED) */
.tick-mark{font-size:12px;font-weight:900;letter-spacing:-1px}
.tick-sent{color:rgba(255,255,255,0.4)}
.tick-delivered{color:rgba(255,255,255,0.75)}
.tick-read{color:#ef4444 !important;font-weight:900;text-shadow:0 0 6px rgba(239,68,68,0.4)}

.call-log-badge{display:inline-flex;align-items:center;gap:4px;font-size:13px;font-weight:700}
.call-missed{color:var(--danger)}
.call-incoming{color:var(--success)}
.call-outgoing{color:var(--c-call-tab)}
.call-action-btn{
  width:40px;
  height:40px;
  border-radius:50%;
  background:rgba(14,165,233,0.14);
  border:1px solid rgba(14,165,233,0.3);
  color:var(--c-call-tab);
  display:grid;
  place-items:center;
  flex-shrink:0;
  transition:transform 0.15s;
}
.call-action-btn:active{transform:scale(0.9)}
.call-action-btn svg{width:20px;height:20px;fill:currentColor}

/* CHAT SCREEN */
#chatScreen{
  position:fixed;
  inset:0;
  height:100%;
  height:100dvh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  background:#090d10;
  z-index:40;
}
.chat-header{
  position:sticky;
  top:0;
  padding:calc(12px + env(safe-area-inset-top)) 14px 12px;
  background:#111822;
  border-bottom:1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:space-between;
  flex-shrink:0;
  z-index:50;
  box-shadow:0 3px 12px rgba(0,0,0,0.4);
}
.chat-header-actions{display:flex;align-items:center;gap:8px}
.chat-body{
  flex:1 1 0;
  min-height:0;
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:10px;
  background:#0a0e14;
}

.wp-call-btn{
  background:transparent;
  border:0;
  color:#10b981;
  width:40px;
  height:40px;
  border-radius:50%;
  display:grid;
  place-items:center;
  transition:transform 0.15s, background 0.2s;
}
.wp-call-btn:active{transform:scale(0.9);background:rgba(255,255,255,0.06)}
.wp-call-btn svg{width:22px;height:22px;fill:currentColor}

.chat-bubble{
  max-width:78%;
  padding:10px 14px;
  border-radius:18px;
  font-size:15px;
  line-height:1.45;
  display:flex;
  flex-direction:column;
  position:relative;
  word-break:break-word;
  box-shadow:0 1px 4px rgba(0,0,0,0.4);
}
.chat-bubble.me{
  align-self:flex-end;
  background:linear-gradient(135deg,#005c4b,#025142);
  color:#f1f5f9;
  border-bottom-right-radius:4px;
  border:1px solid rgba(16,185,129,0.25);
}
.chat-bubble.them{
  align-self:flex-start;
  background:#1b242e;
  border:1px solid var(--line);
  color:#e2e8f0;
  border-bottom-left-radius:4px;
}
.chat-img-thumb{width:100%;max-width:240px;border-radius:12px;margin-bottom:4px;display:block;cursor:pointer}
.chat-meta{font-size:11.5px;color:rgba(255,255,255,.6);margin-top:4px;display:flex;align-items:center;justify-content:flex-end;gap:4px}

.voice-note-bubble{display:flex;align-items:center;gap:10px;padding:4px 0;min-width:190px}
.voice-play-circle{
  width:38px;
  height:38px;
  border-radius:50%;
  background:#10b981;
  border:0;
  color:#fff;
  display:grid;
  place-items:center;
  font-size:14px;
  font-weight:900;
  flex-shrink:0;
  transition:transform 0.15s;
}
.voice-play-circle:active{transform:scale(0.92)}
.voice-meta-area{flex:1;display:flex;flex-direction:column;gap:5px}
.voice-progress-bg{width:100%;height:6px;background:rgba(255,255,255,0.2);border-radius:3px;overflow:hidden;position:relative;cursor:pointer}
.voice-progress-bar{width:0%;height:100%;background:#10b981;pointer-events:none}
.voice-meta-row{display:flex;align-items:center;justify-content:space-between}
.voice-time-label{font-size:12px;color:rgba(255,255,255,0.85);font-family:monospace}
.voice-spd-btn{background:rgba(255,255,255,0.12);border:0;color:#fff;font-size:11px;font-weight:800;padding:2px 7px;border-radius:8px}

.chat-footer{
  position:relative;
  padding:8px 12px calc(10px + env(safe-area-inset-bottom));
  background:#111822;
  border-top:1px solid var(--line);
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0;
  z-index:50;
}
.attach-btn{
  width:44px;
  height:44px;
  border-radius:50%;
  background:rgba(255,255,255,0.05);
  border:1px solid var(--line);
  color:#94a3b8;
  display:grid;
  place-items:center;
  font-size:19px;
  flex-shrink:0;
  transition:transform 0.15s;
}
.attach-btn:active{transform:scale(0.92)}
.input-wrap{flex:1;position:relative;display:flex;align-items:center}

.chat-input{
  width:100%;
  min-height:44px;
  max-height:110px;
  background:#1a232f;
  border:1px solid var(--line);
  border-radius:22px;
  padding:11px 16px;
  color:#fff;
  outline:none;
  font-size:15px;
  box-sizing:border-box;
  resize:none;
  line-height:20px;
  font-family:inherit;
  transition:border-color 0.2s;
}
.chat-input:focus{border-color:rgba(255,255,255,0.25)}

.action-btn{
  width:44px;
  height:44px;
  border-radius:50%;
  background:#f59e0b;
  border:0;
  color:#000;
  display:grid;
  place-items:center;
  flex-shrink:0;
  transition:transform 0.15s, background 0.2s;
}
.action-btn.send-mode{background:#10b981 !important;color:#fff !important}
.action-btn:active{transform:scale(0.92)}
.action-btn svg{width:22px;height:22px;fill:currentColor;pointer-events:none}

.voice-dock{
  position:absolute;
  left:0;
  right:0;
  bottom:0;
  background:#111822;
  border-top:2px solid #10b981;
  z-index:90;
  display:flex;
  flex-direction:column;
  gap:8px;
  padding:10px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow:0 -6px 20px rgba(0,0,0,0.8);
}
.voice-dock-top{display:flex;align-items:center;gap:12px}
.voice-dock-timer{font-size:14.5px;font-weight:900;color:var(--danger);font-family:monospace;display:flex;align-items:center;gap:6px;min-width:75px}
.voice-dock-timer .blink-dot{width:9px;height:9px;border-radius:50%;background:var(--danger);animation:recordBlink 1s infinite}
@keyframes recordBlink{0%,100%{opacity:1}50%{opacity:0.3}}
.voice-dock-bottom{display:flex;align-items:center;justify-content:space-between}
.dock-btn-trash{background:rgba(244,63,94,0.16);border:1px solid var(--danger);color:var(--danger);width:42px;height:42px;border-radius:50%;display:grid;place-items:center;font-size:18px}
.dock-btn-send{background:#10b981;border:0;color:#fff;width:44px;height:44px;border-radius:50%;display:grid;place-items:center;box-shadow:0 0 12px rgba(16,185,129,0.5)}
.dock-btn-send svg{width:20px;height:20px;fill:currentColor}

/* ============================================================
   WHATSAPP STYLE CALL SCREEN (VOICE & VIDEO)
   ============================================================ */
.wp-call-screen{
  position:fixed;
  inset:0;
  z-index:999;
  background:#0b141a;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
}

/* Voice Call Dark WhatsApp Doodle Pattern */
.wp-call-screen.voice-mode{
  background-color:#0c1317;
  background-image:radial-gradient(rgba(255,255,255,0.04) 1px, transparent 0);
  background-size:24px 24px;
}

/* Video Call Mode */
.wp-call-screen.video-mode{
  background:#000;
}

/* Top Call Header */
.wp-call-top-bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:calc(16px + env(safe-area-inset-top)) 16px 10px;
  z-index:50;
}
.wp-round-tool-btn{
  width:40px;
  height:40px;
  border-radius:50%;
  background:rgba(255,255,255,0.1);
  border:0;
  color:#fff;
  display:grid;
  place-items:center;
  backdrop-filter:blur(10px);
  transition:transform 0.15s;
}
.wp-round-tool-btn:active{transform:scale(0.92)}
.wp-round-tool-btn svg{width:22px;height:22px;fill:currentColor}

.wp-call-info-box{text-align:center}
.wp-call-name{
  font-size:20px;
  font-weight:700;
  color:#fff;
  letter-spacing:0.2px;
  text-shadow:0 2px 8px rgba(0,0,0,0.6);
}
.wp-call-status{
  font-size:13.5px;
  color:#94a3b8;
  font-weight:600;
  margin-top:2px;
  font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Center Avatar for Voice Call */
.wp-voice-avatar-wrap{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
}
.wp-large-avatar{
  width:160px;
  height:160px;
  border-radius:50%;
  background:linear-gradient(145deg, #1e293b, #0f172a);
  border:2px solid rgba(255,255,255,0.15);
  display:grid;
  place-items:center;
  box-shadow:0 12px 40px rgba(0,0,0,0.6);
}
.wp-avatar-txt{
  font-size:64px;
  font-weight:800;
  color:#fcd34d;
}

/* Side Tools for Video Call (Flip Camera, Filters) */
.wp-video-side-tools{
  position:absolute;
  top:calc(75px + env(safe-area-inset-top));
  right:16px;
  display:flex;
  flex-direction:column;
  gap:14px;
  z-index:60;
}
.wp-side-tool-btn{
  width:44px;
  height:44px;
  border-radius:50%;
  background:rgba(0,0,0,0.55);
  border:1px solid rgba(255,255,255,0.2);
  color:#fff;
  display:grid;
  place-items:center;
  backdrop-filter:blur(8px);
  transition:transform 0.15s;
}
.wp-side-tool-btn:active{transform:scale(0.9)}
.wp-side-tool-btn svg{width:22px;height:22px;fill:currentColor}

/* Remote Video Full-screen */
#remoteGrid{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  z-index:1;
  background:#000;
}
#remoteGrid video{
  width:100%;
  height:100%;
  object-fit:cover;
}

/* Local Video PiP */
.pip-wrap{
  position:absolute;
  top:calc(75px + env(safe-area-inset-top));
  left:16px;
  width:95px;
  aspect-ratio:3/4;
  border-radius:14px;
  overflow:hidden;
  border:2px solid rgba(255,255,255,0.3);
  z-index:40;
  box-shadow:0 8px 24px rgba(0,0,0,0.6);
}
.pip-wrap video{width:100%;height:100%;object-fit:cover}
.pip-wrap.mirror video{transform:scaleX(-1)}

/* VOICE CALL BOTTOM CONTROLS (WhatsApp 6-Button Rounded Sheet) */
.wp-voice-sheet{
  background:#10171d;
  border-radius:28px 28px 0 0;
  padding:26px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow:0 -10px 30px rgba(0,0,0,0.6);
  z-index:50;
  border-top:1px solid rgba(255,255,255,0.06);
}
.wp-voice-grid{
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  row-gap:22px;
  column-gap:16px;
  max-width:340px;
  margin:0 auto;
}
.wp-ctl-item{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:8px;
}
.wp-ctl-item span{
  font-size:12.5px;
  font-weight:600;
  color:#cbd5e1;
}
.wp-circle-btn{
  width:58px;
  height:58px;
  border-radius:50%;
  background:#202c33;
  border:0;
  color:#fff;
  display:grid;
  place-items:center;
  transition:transform 0.15s, background 0.2s;
}
.wp-circle-btn:active{transform:scale(0.92)}
.wp-circle-btn svg{width:26px;height:26px;fill:currentColor}

.wp-circle-btn.active-on{
  background:#fff;
  color:#000;
}
.wp-circle-btn.active-off{
  background:rgba(239,68,68,0.25);
  color:#ef4444;
}
.wp-circle-btn.wp-btn-end{
  background:#ea0038 !important;
  color:#fff !important;
  box-shadow:0 4px 18px rgba(234,0,56,0.4);
}

/* VIDEO CALL FLOATING CONTROLS (WhatsApp Bottom Bar) */
.wp-video-floating-bar{
  position:absolute;
  bottom:calc(20px + env(safe-area-inset-bottom));
  left:50%;
  transform:translateX(-50%);
  background:rgba(16,23,29,0.85);
  backdrop-filter:blur(16px);
  border-radius:36px;
  padding:8px 14px;
  display:flex;
  align-items:center;
  gap:12px;
  z-index:60;
  box-shadow:0 8px 30px rgba(0,0,0,0.6);
  border:1px solid rgba(255,255,255,0.1);
}
.wp-vid-btn{
  width:48px;
  height:48px;
  border-radius:50%;
  background:#202c33;
  border:0;
  color:#fff;
  display:grid;
  place-items:center;
  transition:transform 0.15s;
}
.wp-vid-btn:active{transform:scale(0.92)}
.wp-vid-btn svg{width:22px;height:22px;fill:currentColor}
.wp-vid-btn.active-on{background:#fff;color:#000}
.wp-vid-btn.active-off{background:rgba(239,68,68,0.25);color:#ef4444}
.wp-vid-btn.wp-btn-end{background:#ea0038 !important;color:#fff !important}

/* INCOMING CALL MODAL */
.call-dialog{
  position:fixed;
  inset:0;
  background:rgba(7,11,15,0.98);
  backdrop-filter:blur(10px);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:space-around;
  z-index:9999;
  padding:40px 16px;
}
.caller-photo{
  width:92px;
  height:92px;
  border-radius:50%;
  background:#182330;
  border:2.5px solid var(--c-user);
  display:grid;
  place-items:center;
  font-size:40px;
  box-shadow:0 0 28px rgba(251,191,36,0.3);
}
.circle-btn{
  width:68px;
  height:68px;
  border-radius:50%;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  border:0;
  color:#fff;
  font-weight:800;
  font-size:12px;
  box-shadow:0 4px 16px rgba(0,0,0,0.5);
  transition:transform 0.15s;
}
.circle-btn:active{transform:scale(0.92)}
.btn-accept{background:#10b981;box-shadow:0 4px 22px rgba(16,185,129,0.5)}
.btn-reject{background:var(--danger);box-shadow:0 4px 22px rgba(244,63,94,0.5)}

/* NAME REGISTRATION SCREEN */
.modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(5,9,14,0.85);
  backdrop-filter:blur(8px);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:99;
  padding:16px;
}
.modal-box{
  background:linear-gradient(165deg, #182330 0%, #0d141e 100%);
  border:1px solid rgba(255,255,255,0.14);
  border-radius:24px;
  padding:26px 20px;
  width:100%;
  max-width:340px;
  text-align:center;
  box-shadow:0 12px 35px rgba(0,0,0,0.7);
}
.modal-box h2{font-size:20px;font-weight:900;margin-bottom:10px;color:#fff;letter-spacing:0.2px}
.modal-box p{font-size:13.5px;color:var(--text-muted);margin-bottom:16px;line-height:1.4}
.modal-input{
  width:100%;
  height:48px;
  padding:0 16px;
  border-radius:14px;
  border:1.5px solid rgba(255,255,255,0.15);
  background:#090e15;
  color:#fff;
  font-size:16px;
  font-weight:700;
  outline:none;
  text-align:center;
  margin-bottom:14px;
  transition:border-color 0.2s, box-shadow 0.2s;
}
.modal-input:focus{
  border-color:var(--c-user);
  box-shadow:0 0 12px rgba(251,191,36,0.25);
}
.btn-gold{
  width:100%;
  height:46px;
  background:linear-gradient(180deg,#fcd34d,#f59e0b);
  color:#000;
  border:0;
  border-radius:14px;
  font-size:15px;
  font-weight:900;
  box-shadow:0 4px 14px rgba(245,158,11,0.35);
  transition:transform 0.15s;
}
.btn-gold:active{transform:scale(0.97)}

/* TOAST / POP-UP NOTIFICATION */
#toast{
  position:fixed;
  top:calc(16px + env(safe-area-inset-top));
  left:50%;
  transform:translateX(-50%);
  background:#131d27;
  border:1px solid var(--c-user);
  color:#fff;
  padding:10px 22px;
  border-radius:24px;
  font-size:13.5px;
  font-weight:700;
  z-index:10000;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s, transform .2s;
  box-shadow:0 6px 18px rgba(0,0,0,0.6);
  width:max-content;
  max-width:88%;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  text-align:center;
}
#toast.show{
  opacity:1;
  transform:translateX(-50%) translateY(0);
}
