@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --bg:#0a0c10; --bg2:#111318; --bg3:#181c24;
  --text:#dde1ed; --muted:#5a6175; --dim:#3a3f50;
  --accent:#4f8ef7; --accent2:#7ab0ff;
  --green:#3ecf8e; --red:#f76f6f; --amber:#f5a623;
  --border:rgba(255,255,255,0.06); --border2:rgba(255,255,255,0.1);
  --mono:'IBM Plex Mono', monospace;
  --sans:'DM Sans', sans-serif;
}

*, *::before, *::after { box-sizing:border-box; margin:0; padding:0; }
html, body { height:100%; background:var(--bg); color:var(--text); font-family:var(--sans); overflow:hidden; }

/* Splash ─────────────────────────────────────────────────── */
#splash {
  position:fixed; inset:0; background:var(--bg); z-index:200;
  display:flex; align-items:center; justify-content:center; flex-direction:column; gap:14px;
  transition:opacity .3s;
}
#splash.out { opacity:0; pointer-events:none; }
.splash-icon { font-size:44px; }
.splash-txt { font-family:var(--mono); font-size:12px; color:var(--muted); }

/* Login ──────────────────────────────────────────────────── */
#login {
  position:fixed; inset:0; display:flex; align-items:center; justify-content:center;
  background:var(--bg); z-index:100;
  transition:opacity .35s, transform .35s;
}
#login.out { opacity:0; transform:scale(.96); pointer-events:none; }
.lcard {
  width:340px; background:var(--bg2);
  border:0.5px solid var(--border2); border-radius:18px;
  padding:38px 32px; display:flex; flex-direction:column; gap:14px; align-items:center;
}
.brand { display:flex; align-items:center; gap:10px; }
.brand-icon {
  width:40px; height:40px; background:var(--accent); border-radius:11px;
  display:flex; align-items:center; justify-content:center; font-size:19px;
}
.brand-name { font-size:21px; font-weight:600; letter-spacing:-.5px; }
.pills { display:flex; gap:5px; flex-wrap:wrap; justify-content:center; }
.pill {
  font-family:var(--mono); font-size:9px; padding:3px 7px; border-radius:20px;
  border:0.5px solid; letter-spacing:.3px;
}
.pill.g { color:var(--green); border-color:rgba(62,207,142,.25); background:rgba(62,207,142,.07); }
.pill.b { color:var(--accent2); border-color:rgba(122,176,255,.25); background:rgba(122,176,255,.07); }
.field { width:100%; display:flex; flex-direction:column; gap:5px; }
.flabel { font-family:var(--mono); font-size:10px; color:var(--muted); }
.fin {
  width:100%; background:var(--bg3); border:0.5px solid var(--border2); border-radius:10px;
  padding:11px 13px; font-family:var(--sans); font-size:14px; color:var(--text);
  outline:none; transition:border-color .2s;
}
.fin:focus { border-color:var(--accent); }
.fin::placeholder { color:var(--muted); }
.err { font-family:var(--mono); font-size:11px; color:var(--red); text-align:center; min-height:14px; }
.lbtn {
  width:100%; background:var(--accent); color:#fff; border:none; border-radius:10px;
  padding:12px; font-family:var(--sans); font-size:14px; font-weight:500;
  cursor:pointer; transition:opacity .2s;
}
.lbtn:hover { opacity:.88; }
.lbtn:disabled { opacity:.4; cursor:not-allowed; }
.hint { font-family:var(--mono); font-size:10px; color:var(--muted); text-align:center; line-height:1.5; }

/* App layout ─────────────────────────────────────────────── */
#app {
  display:flex; height:100vh; height:100dvh;
  opacity:0; transition:opacity .3s;
}
#app.visible { opacity:1; }

.sidebar {
  width:272px; flex-shrink:0; background:var(--bg2);
  border-right:0.5px solid var(--border);
  display:flex; flex-direction:column;
}
.sb-hdr { padding:16px 14px 10px; border-bottom:0.5px solid var(--border); }
.sb-top { display:flex; align-items:center; justify-content:space-between; margin-bottom:8px; }
.sb-logo { font-size:14px; font-weight:600; }
.proto {
  font-family:var(--mono); font-size:8px; color:var(--accent2);
  background:rgba(122,176,255,.08); border:0.5px solid rgba(122,176,255,.2);
  padding:2px 6px; border-radius:20px;
}
.me-row { display:flex; align-items:center; gap:6px; font-size:11px; color:var(--muted); }
.me-dot { width:6px; height:6px; border-radius:50%; background:var(--green); flex-shrink:0; }
.logout-btn {
  background:none; border:none; color:var(--muted); cursor:pointer;
  font-size:11px; font-family:var(--mono); margin-left:auto; padding:0;
}
.logout-btn:hover { color:var(--text); }

.sb-search { display:flex; gap:6px; padding:8px 12px; }
.sb-search input {
  flex:1; background:var(--bg3); border:0.5px solid var(--border);
  border-radius:8px; padding:6px 10px;
  font-family:var(--sans); font-size:12px; color:var(--text); outline:none;
}
.sb-search input::placeholder { color:var(--muted); }
.sb-search button {
  width:32px; height:32px; border-radius:8px; border:0.5px solid var(--border2);
  background:transparent; color:var(--muted); cursor:pointer; font-size:16px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
  transition:color .15s;
}
.sb-search button:hover { color:var(--accent); }

.contacts { flex:1; overflow-y:auto; }
.contacts::-webkit-scrollbar { width:2px; }
.contacts::-webkit-scrollbar-thumb { background:var(--dim); }

.ci {
  display:flex; align-items:center; gap:8px; padding:8px 12px;
  cursor:pointer; transition:background .12s; border-bottom:0.5px solid var(--border);
}
.ci:hover { background:var(--bg3); }
.ci.active { background:var(--bg3); border-left:2px solid var(--accent); }
.av {
  width:34px; height:34px; border-radius:9px;
  display:flex; align-items:center; justify-content:center;
  font-size:12px; font-weight:600; flex-shrink:0; position:relative;
}
.av.on::after {
  content:''; position:absolute; bottom:-1px; right:-1px;
  width:8px; height:8px; border-radius:50%; background:var(--green);
  border:1.5px solid var(--bg2);
}
.ci-body { flex:1; min-width:0; }
.ci-name { font-size:12px; font-weight:500; }
.ci-sub {
  font-size:10px; color:var(--muted);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; margin-top:1px;
}
.ci-meta { display:flex; flex-direction:column; align-items:flex-end; gap:3px; }
.ci-time { font-family:var(--mono); font-size:9px; color:var(--muted); }
.badge {
  min-width:16px; height:16px; border-radius:8px;
  background:var(--accent); color:#fff; font-size:9px;
  display:flex; align-items:center; justify-content:center; padding:0 3px;
}
.no-users {
  padding:20px 12px; text-align:center;
  font-family:var(--mono); font-size:11px; color:var(--muted); line-height:1.8;
}

/* Modal ──────────────────────────────────────────────────── */
.modal-bg {
  position:fixed; inset:0; background:rgba(0,0,0,.6); z-index:300;
  display:none; align-items:center; justify-content:center;
}
.modal-bg.visible { display:flex; }
.modal {
  background:var(--bg2); border:0.5px solid var(--border2); border-radius:16px;
  padding:24px; width:320px; display:flex; flex-direction:column; gap:12px;
}
.modal h3 { font-size:14px; font-weight:500; }
.modal-input {
  width:100%; background:var(--bg3); border:0.5px solid var(--border2);
  border-radius:8px; padding:9px 12px;
  font-family:var(--sans); font-size:13px; color:var(--text); outline:none;
}
.modal-input:focus { border-color:var(--accent); }
.member-list { display:flex; flex-direction:column; gap:4px; max-height:200px; overflow-y:auto; }
.member-item {
  display:flex; align-items:center; gap:8px; padding:6px 8px;
  border-radius:8px; cursor:pointer; transition:background .12s;
}
.member-item:hover { background:var(--bg3); }
.member-item input { accent-color:var(--accent); }
.member-item span { font-size:13px; }
.modal-btns { display:flex; gap:8px; }
.modal-btn {
  flex:1; padding:9px; border-radius:8px; border:none; cursor:pointer;
  font-family:var(--sans); font-size:13px; font-weight:500;
}
.modal-btn.primary { background:var(--accent); color:#fff; }
.modal-btn.secondary { background:var(--bg3); color:var(--muted); }

/* Chat ───────────────────────────────────────────────────── */
.chat {
  flex:1; display:flex; flex-direction:column;
  min-width:0; min-height:0; background:var(--bg); overflow:hidden;
}
.no-chat {
  flex:1; display:flex; flex-direction:column;
  align-items:center; justify-content:center; gap:12px; color:var(--muted);
}
.no-chat-icon { font-size:40px; opacity:.15; }
.no-chat-main { font-size:13px; }
.no-chat-sub { font-family:var(--mono); font-size:10px; opacity:.6; }
#chatView { display:none; flex:1; flex-direction:column; min-height:0; overflow:hidden; }

.ch-hdr {
  padding:11px 16px; border-bottom:0.5px solid var(--border);
  background:var(--bg2);
  display:flex; align-items:center; justify-content:space-between; flex-shrink:0;
}
.ch-left { display:flex; align-items:center; gap:10px; }
.ch-info h3 { font-size:13px; font-weight:500; }
.ch-info p { font-size:10px; color:var(--muted); font-family:var(--mono); margin-top:1px; }

.hbtn {
  width:30px; height:30px; border-radius:7px; border:0.5px solid var(--border2);
  background:transparent; color:var(--muted); cursor:pointer; font-size:13px;
  display:flex; align-items:center; justify-content:center; transition:background .12s;
}
.hbtn:hover { background:var(--bg3); color:var(--text); }
#backBtn { display:none; font-size:18px; }
#callBtn { display:none; }

.msgs {
  flex:1; overflow-y:auto; padding:16px;
  display:flex; flex-direction:column; gap:3px; scroll-behavior:smooth;
}
.msgs::-webkit-scrollbar { width:4px; }
.msgs::-webkit-scrollbar-thumb { background:var(--dim); border-radius:2px; }

.dsep { text-align:center; margin:6px 0 3px; }
.dsep span {
  font-family:var(--mono); font-size:9px; color:var(--muted);
  background:var(--bg3); padding:2px 8px; border-radius:20px;
}
.mrow { display:flex; margin:1px 0; animation:fu .18s ease; }
@keyframes fu { from{opacity:0;transform:translateY(4px)} to{opacity:1;transform:none} }
.mrow.out { justify-content:flex-end; }
.mrow.in  { justify-content:flex-start; }
.bubble {
  max-width:65%; padding:8px 12px; border-radius:12px;
  font-size:13px; line-height:1.55; word-break:break-word;
}
.mrow.out .bubble { background:var(--accent); color:#fff; border-bottom-right-radius:3px; }
.mrow.in  .bubble { background:var(--bg3); color:var(--text); border-bottom-left-radius:3px; border:0.5px solid var(--border); }
.btime {
  margin-top:4px; font-family:var(--mono); font-size:9px; opacity:.5;
  display:flex; align-items:center; gap:3px; justify-content:flex-end;
}
.tick.ok { color:var(--green); opacity:1; }

.file-bubble {
  display:flex; align-items:center; gap:9px; padding:9px 12px; border-radius:12px;
  max-width:260px; cursor:pointer; transition:opacity .15s;
}
.file-bubble:hover { opacity:.85; }
.mrow.out .file-bubble { background:var(--accent); color:#fff; border-bottom-right-radius:3px; }
.mrow.in  .file-bubble { background:var(--bg3); color:var(--text); border-bottom-left-radius:3px; border:0.5px solid var(--border); }
.ficon { font-size:22px; flex-shrink:0; }
.finfo .fname {
  font-size:12px; font-weight:500;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:150px;
}
.finfo .fmeta { font-size:10px; opacity:.6; margin-top:2px; font-family:var(--mono); }

.img-bubble {
  max-width:280px; border-radius:12px; overflow:hidden;
  cursor:pointer; position:relative;
}
.mrow.out .img-bubble { background:var(--accent); color:#fff; border-bottom-right-radius:3px; }
.mrow.in  .img-bubble { background:var(--bg3); border:0.5px solid var(--border); border-bottom-left-radius:3px; }
.img-bubble img { width:100%; display:block; max-height:320px; object-fit:cover; }
.img-bubble .img-meta {
  padding:5px 10px 7px; font-family:var(--mono); font-size:9px;
  opacity:.6; display:flex; justify-content:flex-end; gap:4px;
}

.prog-wrap { margin-top:5px; height:2px; background:rgba(255,255,255,.2); border-radius:1px; }
.prog-bar { height:100%; background:rgba(255,255,255,.8); border-radius:1px; transition:width .3s; }

.empty {
  flex:1; display:flex; flex-direction:column;
  align-items:center; justify-content:center; gap:10px;
}
.empty-icon { font-size:30px; opacity:.2; }
.empty-txt { font-family:var(--mono); font-size:11px; color:var(--muted); text-align:center; line-height:1.7; }

.input-wrap {
  padding:10px 14px; border-top:0.5px solid var(--border); background:var(--bg2);
  display:flex; align-items:flex-end; gap:7px; flex-shrink:0;
}
#fileInput { display:none; }
.msg-ta {
  flex:1; background:var(--bg3); border:0.5px solid var(--border2); border-radius:10px;
  padding:9px 12px; font-family:var(--sans); font-size:13px; color:var(--text);
  outline:none; resize:none; max-height:110px; line-height:1.5;
  transition:border-color .2s;
}
.msg-ta:focus { border-color:var(--accent); }
.msg-ta::placeholder { color:var(--muted); }

.abtn {
  width:34px; height:34px; border-radius:9px;
  border:0.5px solid var(--border2); background:transparent; color:var(--muted);
  cursor:pointer; font-size:15px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.abtn:hover { background:var(--bg3); color:var(--text); }
.sbtn {
  width:34px; height:34px; border-radius:9px; background:var(--accent);
  border:none; color:#fff; cursor:pointer; font-size:14px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
  transition:opacity .15s, transform .1s;
}
.sbtn:hover { opacity:.85; }
.sbtn:active { transform:scale(.94); }

.tdots {
  display:flex; gap:3px; padding:8px 12px;
  background:var(--bg3); border-radius:12px; border-bottom-left-radius:3px;
}
.tdots span {
  width:4px; height:4px; border-radius:50%;
  background:var(--muted); animation:b 1.1s infinite;
}
.tdots span:nth-child(2) { animation-delay:.18s; }
.tdots span:nth-child(3) { animation-delay:.36s; }
@keyframes b { 0%,80%,100%{transform:scale(.7);opacity:.4} 40%{transform:scale(1);opacity:1} }

.av0 { background:rgba(79,142,247,.15);  color:var(--accent2); }
.av1 { background:rgba(62,207,142,.12);  color:var(--green);   }
.av2 { background:rgba(245,166,35,.12);  color:var(--amber);   }
.av3 { background:rgba(247,111,111,.12); color:var(--red);     }
.av4 { background:rgba(167,139,250,.12); color:#a78bfa;        }
.av5 { background:rgba(251,146,60,.12);  color:#fb923c;        }

/* Mobile ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #app { position:relative; }
  .sidebar {
    position:fixed; left:0; top:0; width:100%; height:100%;
    z-index:50; transition:transform .25s; background:var(--bg2);
  }
  .sidebar.hide { transform:translateX(-100%); }
  .chat { width:100%; display:flex; flex-direction:column; }
  .ch-hdr { position:sticky; top:0; z-index:10; background:var(--bg2); }
  #backBtn { display:flex !important; }
  .input-wrap {
    padding-bottom:max(18px, env(safe-area-inset-bottom));
    position:sticky; bottom:0;
  }
  .msgs { flex:1; overflow-y:auto; }
}

/* Calls ──────────────────────────────────────────────────── */
.call-overlay {
  position:fixed; inset:0; background:rgba(10,12,16,.96); z-index:500;
  display:none; flex-direction:column; align-items:center; justify-content:center; gap:20px;
}
.call-overlay.visible { display:flex; }
.call-avatar {
  width:80px; height:80px; border-radius:20px;
  display:flex; align-items:center; justify-content:center;
  font-size:28px; font-weight:600; margin-bottom:4px;
}
.call-name { font-size:20px; font-weight:500; color:var(--text); }
.call-status { font-family:var(--mono); font-size:12px; color:var(--muted); }
#callVideos { display:none; position:relative; width:90%; max-width:800px; }
#remoteVideo {
  width:100%; height:280px;
  border-radius:12px; background:#000; object-fit:cover;
}
#localVideo {
  width:120px; height:90px;
  position:absolute; bottom:12px; right:12px;
  border-radius:10px; background:#000; object-fit:cover;
  border:2px solid var(--bg3);
}
.call-btns { display:flex; gap:16px; margin-top:8px; }
.call-btn {
  width:56px; height:56px; border-radius:50%; border:none; cursor:pointer;
  font-size:20px; display:flex; align-items:center; justify-content:center;
  transition:opacity .15s, transform .1s;
}
.call-btn:active { transform:scale(.92); }
.call-btn.end { background:var(--red); }
.call-btn.mute, .call-btn.cam { background:var(--bg3); }

.incoming-call {
  position:fixed; top:20px; left:50%; transform:translateX(-50%);
  background:var(--bg2); border:0.5px solid var(--border2); border-radius:16px;
  padding:18px 24px; z-index:600;
  display:none; flex-direction:column; align-items:center; gap:12px;
  min-width:260px; box-shadow:0 8px 32px rgba(0,0,0,.4);
}
.incoming-call.visible { display:flex; }
.incoming-call .ic-name { font-size:15px; font-weight:500; }
.incoming-call .ic-type { font-family:var(--mono); font-size:11px; color:var(--muted); }
.incoming-call .ic-btns { display:flex; gap:12px; }
.ic-btn {
  width:48px; height:48px; border-radius:50%; border:none; cursor:pointer;
  font-size:18px; display:flex; align-items:center; justify-content:center;
}
.ic-btn.ans { background:var(--green); }
.ic-btn.rej { background:var(--red); }

.toast {
  position:fixed; bottom:22px; left:50%; transform:translateX(-50%);
  background:var(--bg3); color:var(--text);
  padding:7px 16px; border-radius:20px;
  font-family:var(--mono); font-size:11px; z-index:999;
  border:0.5px solid var(--border2); transition:opacity .3s;
}
.toast.red { background:var(--red); color:#fff; }
