/* Mây Chat v1.0.0 */
:root{
  --bg:#eef1f6; --surface:#fff; --soft:#f4f6fa; --chatbg:#f7f8fb; --bubble:#fff; --line:#e8ebf1;
  --text:#14171f; --muted:#7b8394; --brand:#3b6cf6; --brandsoft:#eef2ff;
  --green:#1fbf75; --red:#f04848; --me:linear-gradient(135deg,#3b6cf6,#6a5cf6);
}
body.dark{
  --bg:#05060a; --surface:#12141b; --soft:#1c1f29; --chatbg:#0c0e14; --bubble:#1e2230; --line:#232734;
  --text:#eef0f5; --muted:#8c93a5; --brandsoft:#1e2440;
}
*{box-sizing:border-box;margin:0;padding:0;-webkit-tap-highlight-color:transparent}
html,body{height:100%}
body{font-family:'Be Vietnam Pro',system-ui,sans-serif;background:var(--bg);color:var(--text);overflow:hidden}
button{font:inherit;border:0;background:none;color:inherit;cursor:pointer}
input{font:inherit;color:inherit}
svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}

.app{position:relative;max-width:480px;height:100vh;height:100dvh;margin:0 auto;background:var(--surface);overflow:hidden}
@media (min-width:600px){ .app{box-shadow:0 0 60px rgba(20,30,60,.12)} }

.screen{position:absolute;inset:0;display:flex;flex-direction:column;background:var(--surface);transition:transform .3s cubic-bezier(.2,.8,.2,1);padding-top:env(safe-area-inset-top)}
.screen.hidden{transform:translateX(100%);visibility:hidden}
.screen.under{transform:translateX(-25%)}
#auth.hidden{transform:none;display:none}

/* auth */
.auth-wrap{margin:auto;width:100%;padding:24px 28px;display:flex;flex-direction:column;align-items:center}
.logo img{width:84px;height:84px;border-radius:24px;box-shadow:0 12px 30px rgba(59,108,246,.35)}
.auth-wrap h1{font-size:28px;margin-top:16px}
.sub{color:var(--muted);margin:4px 0 24px}
.seg{display:flex;background:var(--soft);border-radius:14px;padding:4px;width:100%;margin-bottom:16px}
.seg button{flex:1;height:40px;border-radius:11px;font-weight:600;color:var(--muted)}
.seg button.on{background:var(--surface);color:var(--text);box-shadow:0 1px 4px rgba(0,0,0,.08)}
#authForm{width:100%;display:flex;flex-direction:column;gap:10px}
.inp{height:50px;border-radius:14px;border:1px solid var(--line);background:var(--soft);padding:0 16px;font-size:15px;outline:0}
.inp:focus{border-color:var(--brand)}
.reg-only{display:none}
.register .reg-only{display:block}
.btn{height:50px;border-radius:14px;background:var(--me);color:#fff;font-weight:600;font-size:16px;margin-top:6px}
.btn:disabled{opacity:.6}
.err{color:var(--red);font-size:14px;min-height:18px}

/* header */
.tabcontent{flex:1;display:flex;flex-direction:column;min-height:0}
.top{padding:14px 20px 12px;display:flex;align-items:center;justify-content:space-between}
.top h1{font-size:28px;font-weight:700;letter-spacing:-.5px}
.iconbtn{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;background:var(--soft)}
.iconbtn svg{width:19px;height:19px}
.search{margin:0 20px 10px;background:var(--soft);border-radius:14px;display:flex;align-items:center;gap:8px;padding:0 14px;height:44px;color:var(--muted)}
.search svg{width:18px;height:18px}
.search input{border:0;outline:0;background:none;flex:1;font-size:15px}
.content{flex:1;overflow-y:auto;overscroll-behavior:contain}
.content::-webkit-scrollbar,.msgs::-webkit-scrollbar,.stories::-webkit-scrollbar,.quick::-webkit-scrollbar{display:none}
.conn{display:none;background:#ffb547;color:#3a2600;font-size:13px;text-align:center;padding:4px}
.conn.show{display:block}

.stories{display:flex;gap:14px;padding:6px 20px 14px;overflow-x:auto}
.story{display:flex;flex-direction:column;align-items:center;gap:6px;font-size:12px;color:var(--muted);width:58px;flex-shrink:0;cursor:pointer}
.story span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:58px}

.av{border-radius:50%;display:grid;place-items:center;color:#fff;font-weight:600;position:relative;flex-shrink:0}
.av.online::after{content:"";position:absolute;right:1px;bottom:1px;width:24%;height:24%;background:var(--green);border:2.5px solid var(--surface);border-radius:50%}
.av56{width:56px;height:56px;font-size:20px}.av52{width:52px;height:52px;font-size:18px}
.av40{width:40px;height:40px;font-size:15px}.av120{width:120px;height:120px;font-size:42px}

.row{display:flex;align-items:center;gap:14px;padding:10px 20px;cursor:pointer}
.row:active{background:var(--soft)}
.row .mid{flex:1;min-width:0}
.row .name{font-weight:600;font-size:16px;display:flex;justify-content:space-between;gap:8px}
.row .name small{font-weight:400;font-size:12px;color:var(--muted);flex-shrink:0}
.row .preview{font-size:14px;color:var(--muted);margin-top:3px;display:flex;justify-content:space-between;gap:8px;align-items:center}
.row .preview span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.row.unread .preview{color:var(--text);font-weight:500}
.badge{background:var(--brand);color:#fff;font-size:11px;font-weight:600;min-width:20px;height:20px;padding:0 6px;border-radius:10px;display:grid;place-items:center;flex-shrink:0}
.section-title{font-size:13px;font-weight:600;color:var(--muted);padding:14px 20px 6px;text-transform:uppercase;letter-spacing:.5px}
.calltype{display:flex;align-items:center;gap:4px;font-size:13px;color:var(--muted);margin-top:3px}
.calltype svg{width:14px;height:14px}
.missed{color:var(--red)!important}
.rowact{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;color:var(--brand);background:var(--brandsoft)}
.rowact svg{width:19px;height:19px}
.empty{text-align:center;color:var(--muted);padding:50px 30px;font-size:14px;line-height:1.6}

.tabbar{display:flex;justify-content:space-around;padding:8px 10px calc(8px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--surface);flex-shrink:0}
.tab{display:flex;flex-direction:column;align-items:center;gap:4px;font-size:11px;font-weight:500;color:#a3aab8;padding:4px 14px;position:relative}
.tab.active{color:var(--brand)}
.tab .dot{position:absolute;top:0;right:12px;background:var(--red);color:#fff;font-size:10px;min-width:16px;height:16px;border-radius:8px;display:none;place-items:center;padding:0 4px}

/* chat */
.chathead{display:flex;align-items:center;gap:10px;padding:8px 12px 10px;border-bottom:1px solid var(--line)}
.chathead .who{flex:1;min-width:0}
.chathead .who b{font-size:16px;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chathead .who small{font-size:12px;color:var(--muted)}
.chathead .who small.on{color:var(--green)}
.headact{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;color:var(--brand)}
.headact:active{background:var(--soft)}
.msgs{flex:1;overflow-y:auto;padding:14px 14px 6px;display:flex;flex-direction:column;gap:4px;background:var(--chatbg)}
.day{align-self:center;font-size:12px;color:var(--muted);background:var(--bubble);padding:4px 12px;border-radius:10px;margin:8px 0}
.m{max-width:76%;padding:9px 14px;border-radius:20px;font-size:15px;line-height:1.4;word-wrap:break-word;white-space:pre-wrap;animation:pop .2s ease}
.m.them{background:var(--bubble);align-self:flex-start;border-bottom-left-radius:6px;box-shadow:0 1px 2px rgba(0,0,0,.04)}
.m.me{background:var(--me);color:#fff;align-self:flex-end;border-bottom-right-radius:6px}
.m .t{display:block;font-size:10.5px;opacity:.6;margin-top:3px;text-align:right}
.m.callmsg{display:flex;align-items:center;gap:10px;cursor:pointer}
.m.callmsg .ic{width:34px;height:34px;border-radius:50%;display:grid;place-items:center;background:rgba(255,255,255,.22)}
.m.them.callmsg .ic{background:var(--brandsoft);color:var(--brand)}
.m.callmsg svg{width:18px;height:18px}
.m.callmsg .t{text-align:left}
.seen{align-self:flex-end;font-size:11px;color:var(--muted);margin:2px 4px 6px}
@keyframes pop{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
.typing{align-self:flex-start;background:var(--bubble);padding:12px 16px;border-radius:20px;border-bottom-left-radius:6px;display:flex;gap:4px}
.typing i{width:7px;height:7px;border-radius:50%;background:#b7bdca;animation:blink 1.2s infinite}
.typing i:nth-child(2){animation-delay:.2s}.typing i:nth-child(3){animation-delay:.4s}
@keyframes blink{0%,60%,100%{opacity:.3}30%{opacity:1;transform:translateY(-3px)}}
.quick{display:flex;gap:8px;padding:8px 14px 0;overflow-x:auto;background:var(--chatbg)}
.quick button{background:var(--bubble);border:1px solid var(--line);border-radius:16px;padding:6px 12px;font-size:13px;white-space:nowrap;color:var(--brand)}
.composer{display:flex;align-items:center;gap:8px;padding:10px 12px calc(10px + env(safe-area-inset-bottom));background:var(--chatbg)}
.composer .field{flex:1;display:flex;align-items:center;background:var(--bubble);border-radius:22px;padding:0 6px 0 16px;height:44px;border:1px solid var(--line)}
.composer input{flex:1;border:0;outline:0;font-size:16px;background:none;min-width:0}
.emo{color:var(--muted);width:34px;height:34px;display:grid;place-items:center}
.send{width:44px;height:44px;border-radius:50%;background:var(--me);color:#fff;display:grid;place-items:center;flex-shrink:0}
.send:active{transform:scale(.9)}
.send svg{width:20px;height:20px}
.emojis{display:none;flex-wrap:wrap;gap:4px;padding:8px 14px;background:var(--surface);border-top:1px solid var(--line)}
.emojis.show{display:flex}
.emojis button{font-size:24px;width:42px;height:42px;border-radius:10px}

/* call */
.call{position:absolute;inset:0;z-index:20;display:flex;flex-direction:column;align-items:center;color:#fff;background:radial-gradient(120% 80% at 50% 0%,#4a63d8 0%,#2b2f6b 55%,#151730 100%);transform:translateY(100%);visibility:hidden;transition:transform .35s cubic-bezier(.2,.8,.2,1)}
.call.show{transform:none;visibility:visible}
.call .remote{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:none;background:#000}
.call.video.connected .remote{display:block}
.shade{position:absolute;inset:0;pointer-events:none;display:none;background:linear-gradient(180deg,rgba(0,0,0,.45),transparent 25%,transparent 65%,rgba(0,0,0,.6))}
.call.video.connected .shade{display:block}
.call .info{margin-top:calc(90px + env(safe-area-inset-top));text-align:center;display:flex;flex-direction:column;align-items:center;gap:14px;position:relative;z-index:2;padding:0 20px}
.call .info h2{font-size:28px;font-weight:600}
.call .info p{font-size:15px;opacity:.8}
.call.video.connected .info{margin-top:calc(24px + env(safe-area-inset-top));gap:4px}
.call.video.connected .info .pulse{display:none}
.call.video.connected .info h2{font-size:20px}
.pulse{position:relative}
.pulse::before,.pulse::after{content:"";position:absolute;inset:-14px;border-radius:50%;border:2px solid rgba(255,255,255,.25);animation:ring 2s infinite}
.pulse::after{animation-delay:1s}
.call.connected .pulse::before,.call.connected .pulse::after{display:none}
@keyframes ring{from{transform:scale(.9);opacity:1}to{transform:scale(1.45);opacity:0}}
.selfview{position:absolute;right:16px;top:calc(90px + env(safe-area-inset-top));width:104px;height:150px;border-radius:18px;overflow:hidden;background:#2a2d3d;z-index:3;display:none;box-shadow:0 8px 24px rgba(0,0,0,.35);border:2px solid rgba(255,255,255,.35)}
.call.video .selfview{display:block}
.call .selfview.none{display:none}
.selfview video{width:100%;height:100%;object-fit:cover;transform:scaleX(-1)}
.selfview.back video{transform:none}
.selfview span{position:absolute;inset:0;display:none;place-items:center;font-size:12px}
.selfview.off video{display:none}.selfview.off span{display:grid}
.call .controls{margin-top:auto;margin-bottom:calc(46px + env(safe-area-inset-bottom));display:grid;grid-template-columns:repeat(3,76px);gap:22px 26px;justify-items:center;position:relative;z-index:2}
.cbtn{display:flex;flex-direction:column;align-items:center;gap:8px;font-size:12px;text-align:center}
.cbtn .c{width:64px;height:64px;border-radius:50%;background:rgba(255,255,255,.18);display:grid;place-items:center;backdrop-filter:blur(10px)}
.cbtn.on .c{background:#fff;color:#2b2f6b}
.cbtn .c:active{transform:scale(.92)}
.cbtn svg{width:26px;height:26px}
.cbtn.end .c{background:var(--red)}
.cbtn.end svg{transform:rotate(135deg)}
.cbtn.accept .c{background:var(--green);animation:shake 1.2s infinite}
@keyframes shake{0%,100%{transform:none}10%,30%{transform:rotate(-12deg)}20%,40%{transform:rotate(12deg)}50%{transform:none}}

/* profile */
.me-card{display:flex;flex-direction:column;align-items:center;gap:6px;padding:30px 20px 24px}
.me-card h2{font-size:22px;display:flex;align-items:center;gap:6px}
.me-card p{color:var(--muted);font-size:14px}
.setting{display:flex;align-items:center;gap:14px;padding:14px 20px;font-size:15px;cursor:pointer;width:100%;text-align:left}
.setting .ic{width:36px;height:36px;border-radius:10px;display:grid;place-items:center;color:#fff}
.setting .ic svg{width:19px;height:19px}
.setting .grow{flex:1}
.toggle{width:46px;height:28px;border-radius:14px;background:#c9ced9;position:relative;transition:.2s;flex-shrink:0}
.toggle::after{content:"";position:absolute;left:3px;top:3px;width:22px;height:22px;border-radius:50%;background:#fff;transition:.2s;box-shadow:0 1px 3px rgba(0,0,0,.2)}
.toggle.on{background:var(--green)}.toggle.on::after{left:21px}
.version{text-align:center;color:var(--muted);font-size:12px;padding:20px}

/* modal */
.modal{position:absolute;inset:0;background:rgba(0,0,0,.4);z-index:40;display:flex;align-items:flex-end}
.sheet{background:var(--surface);width:100%;border-radius:22px 22px 0 0;padding:20px 20px calc(20px + env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:12px}
.sheet h3{font-size:18px}
.sheet .row2{display:flex;gap:10px}
.sheet .row2 button{flex:1}
.btn.ghost{background:var(--soft);color:var(--text)}

.toast{position:absolute;left:50%;bottom:110px;transform:translateX(-50%) translateY(20px);background:#1d2130;color:#fff;font-size:14px;padding:10px 18px;border-radius:14px;opacity:0;transition:.25s;pointer-events:none;z-index:50;max-width:90%;text-align:center}
.toast.show{opacity:1;transform:translateX(-50%)}
