:root{
  --ink:#1A1F2E; --muted:#5B6475; --line:#E4DFD3; --bg:#F6F3EC; --card:#fff;
  --blue:#1E3A8A; --blue-soft:#E6ECFA; --navy:#12204F; --gold:#E8B84B; --danger:#B3261E;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{font-family:'Kantumruy Pro','Noto Sans Khmer',system-ui,sans-serif;color:var(--ink);background:var(--bg);line-height:1.6}
.hidden{display:none!important}
button,input{font-family:inherit;font-size:15px}
button{cursor:pointer}
.muted{color:var(--muted);font-size:14px;margin:0 0 16px}
.err{color:var(--danger);font-size:14px;min-height:22px;margin:8px 0 0;text-align:center}

/* logo */
.logo{width:64px;height:64px;border-radius:20px;background:var(--gold);display:flex;align-items:center;justify-content:center}
.logo.sm{width:36px;height:36px;border-radius:11px;background:var(--blue);margin-right:10px}

/* auth */
.auth{min-height:100%;display:flex;flex-direction:column;background:var(--blue)}
.auth-top{flex:0 0 auto;padding:56px 24px 72px;text-align:center;color:#fff}
.auth-top h1{margin:10px 0 0;font-size:32px}
.auth-top p{margin:0;color:#C9D3F0;font-size:14px}
.auth-top .logo{margin:0 auto}
.auth-card{flex:1;background:var(--bg);border-radius:28px 28px 0 0;margin-top:-28px;padding:32px 24px;width:100%;max-width:480px;align-self:center}
.auth-card h2{margin:0 0 4px;font-size:22px}
.step label{display:block;font-size:14px;font-weight:600;margin:12px 0 8px}
.step input{width:100%;height:56px;padding:0 16px;border-radius:14px;border:2px solid var(--line);background:#fff;font-size:18px;font-weight:500;outline:0}
.step input:focus{border-color:var(--blue)}
.phone-row{display:flex;gap:10px}
.prefix{height:56px;padding:0 16px;border-radius:14px;background:#fff;border:1px solid var(--line);display:flex;align-items:center;font-weight:600;font-size:16px}
input.otp{text-align:center;letter-spacing:.4em;font-size:26px;font-weight:700}
.btn{width:100%;height:56px;margin-top:20px;border:0;border-radius:14px;background:var(--blue);color:#fff;font-size:16px;font-weight:700}
.btn.ghost{background:transparent;color:var(--blue);margin-top:8px;height:48px}
.btn:disabled{opacity:.6}
.dev-hint{background:#FBF0D5;color:#7A5200;border-radius:12px;padding:10px 14px;font-size:14px;margin-bottom:8px}
.dev-hint b{font-size:18px;letter-spacing:.15em}

/* app */
.app{height:100%;display:flex}
.side{flex:0 0 340px;display:flex;flex-direction:column;background:#fff;border-right:1px solid var(--line);min-height:0}
.side-head{display:flex;align-items:center;justify-content:space-between;padding:14px 16px}
.brand{display:flex;align-items:center;font-size:20px;font-weight:700}
.icon-btn{width:44px;height:44px;border-radius:12px;border:0;background:var(--blue-soft);color:var(--blue);display:flex;align-items:center;justify-content:center}
.conn{background:#FBF0D5;color:#7A5200;font-size:13px;text-align:center;padding:4px}
.chat-list{flex:1;overflow-y:auto;padding:0 8px}
.hint{padding:24px 16px;color:var(--muted);font-size:14px;text-align:center}
.chat{display:flex;align-items:center;gap:12px;width:100%;height:72px;padding:0 10px;border:0;border-radius:14px;background:transparent;text-align:left}
.chat:hover{background:#F6F3EC}
.chat.on{background:var(--blue-soft)}
.av{position:relative;flex:0 0 52px;width:52px;height:52px;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:20px;font-weight:700}
.av.sm{flex-basis:36px;width:36px;height:36px;font-size:16px}
.av.sq{border-radius:16px}
.av .dot{position:absolute;right:-1px;bottom:-1px;width:14px;height:14px;border-radius:50%;background:#1F8A4C;border:2px solid #fff}
.c0{background:#DCE5FA;color:#1E3A8A}.c1{background:#F8E8C4;color:#6B4A00}.c2{background:#DDF0E5;color:#14653A}
.c3{background:#F7DDE0;color:#8E1B14}.c4{background:#E8E1F5;color:#4B2E83}
.chat .mid{flex:1;min-width:0}
.chat .row{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
.chat .name{font-size:15px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat .time{font-size:12px;color:var(--muted);flex:0 0 auto}
.chat .prev{font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.badge{flex:0 0 auto;min-width:22px;height:22px;padding:0 7px;border-radius:11px;background:var(--gold);color:var(--navy);font-size:12px;font-weight:700;display:flex;align-items:center;justify-content:center}
.me-bar{display:flex;align-items:center;gap:10px;padding:12px 16px;border:0;border-top:1px solid var(--line);background:#fff;text-align:left;font-weight:600}
.me-bar .av{background:var(--gold);color:var(--navy)}

.conv{flex:1;min-width:0;display:flex;flex-direction:column;background:#EFEADD}
.empty{margin:auto;color:var(--muted);text-align:center;padding:24px}
.conv-view{flex:1;display:flex;flex-direction:column;min-height:0}
.conv-head{display:flex;align-items:center;gap:12px;padding:10px 16px;background:#fff;border-bottom:1px solid var(--line)}
.conv-head .av{flex-basis:44px;width:44px;height:44px;font-size:18px}
.conv-head .t{font-size:16px;font-weight:700;line-height:1.4}
.conv-head .s{font-size:13px;color:var(--muted);line-height:1.4}
.conv-head .s.on{color:#14653A}
.back{display:none;background:transparent}
.msgs{flex:1;overflow-y:auto;padding:16px 20px;display:flex;flex-direction:column;gap:6px}
.day{align-self:center;background:rgba(26,31,46,.55);color:#fff;font-size:12px;padding:0 12px;border-radius:12px;margin:8px 0}
.row-m{display:flex}
.row-m.mine{justify-content:flex-end}
.bubble{max-width:72%;padding:8px 14px;border-radius:16px 16px 16px 4px;background:#fff;font-size:15px;white-space:pre-wrap;word-break:break-word}
.mine .bubble{background:var(--blue);color:#fff;border-radius:16px 16px 4px 16px}
.bubble .who{font-size:12px;font-weight:700;color:var(--blue);line-height:1.4}
.bubble .meta{display:flex;justify-content:flex-end;gap:6px;font-size:11px;color:var(--muted);line-height:1.3}
.mine .bubble .meta{color:#C9D3F0}
.meta .tick.read{color:var(--gold)}
.bubble.failed{background:#FBE4E2;color:#8E1B14}
.composer{display:flex;gap:8px;align-items:center;padding:12px 16px;background:#fff;border-top:1px solid var(--line)}
.composer input{flex:1;min-width:0;height:46px;border-radius:23px;border:1px solid var(--line);background:var(--bg);padding:0 18px;outline:0}
.composer input:focus{border-color:var(--blue)}
.send{width:48px;height:48px;border-radius:50%;border:0;background:var(--blue);display:flex;align-items:center;justify-content:center}

/* modal */
.modal{position:fixed;inset:0;background:rgba(18,32,79,.5);display:flex;align-items:center;justify-content:center;padding:16px;z-index:10}
.modal-card{background:#fff;border-radius:20px;width:100%;max-width:440px;max-height:90vh;overflow:auto;padding:20px}
.modal h3{margin:0 0 12px;font-size:18px}
.tabs{display:flex;gap:8px;margin-bottom:14px}
.tab{flex:1;height:40px;border-radius:20px;border:0;background:transparent;color:var(--muted);font-weight:600}
.tab.on{background:var(--blue-soft);color:var(--blue)}
.field{width:100%;height:48px;border-radius:12px;border:1px solid var(--line);padding:0 14px;margin-bottom:10px;outline:0;background:#fff}
.field:focus{border-color:var(--blue)}
.res{display:flex;align-items:center;gap:12px;width:100%;padding:8px 6px;border:0;background:transparent;border-radius:12px;text-align:left}
.res:hover{background:var(--bg)}
.res small{color:var(--muted);display:block}
.row-btns{display:flex;gap:8px;margin-top:8px}
.row-btns .btn{margin-top:0;height:48px}
.btn.danger{background:#fff;color:var(--danger);border:1px solid var(--danger)}

@media (max-width:760px){
  .side{flex:1 1 100%}
  .conv{display:none}
  .app.chat-open .side{display:none}
  .app.chat-open .conv{display:flex}
  .back{display:flex}
  .bubble{max-width:84%}
}

.rep{border:0;background:none;color:var(--muted);font:inherit;font-size:11px;cursor:pointer;padding:0;opacity:0;text-decoration:underline}
.bubble:hover .rep,.rep:focus-visible{opacity:1}
@media(hover:none){.rep{opacity:.7}}
.btn.block{display:block;width:100%;margin-top:8px;text-align:left}
a.btn{display:inline-block;text-decoration:none;text-align:center}

.bubble.act{cursor:pointer}
.quote{border-left:3px solid var(--gold);background:rgba(0,0,0,.06);border-radius:6px;padding:2px 8px;margin:2px 0 4px;font-size:13px;display:block;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;max-width:100%}
.quote b{display:block;font-size:12px;color:var(--gold)}
.mine .quote{background:rgba(255,255,255,.16)}
.row-m{flex-wrap:wrap}
.chips{display:flex;gap:4px;flex-wrap:wrap;margin:3px 6px 0;flex-basis:100%}
.mine .chips{justify-content:flex-end}
.chip{border:1px solid var(--line);background:#fff;border-radius:99px;padding:0 9px;font:inherit;font-size:13px;line-height:24px;cursor:pointer}
.chip.me{border-color:var(--blue);background:#E8EEFF}
.compose-bar{display:flex;align-items:center;gap:10px;padding:8px 16px;background:#fff;border-top:1px solid var(--line);border-left:4px solid var(--gold)}
.compose-bar .cb-text{flex:1;min-width:0;font-size:13px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.compose-bar b{color:var(--gold);margin-right:8px}
.compose-bar button{border:0;background:none;font-size:18px;cursor:pointer;color:var(--muted)}
.emoji-row{display:flex;justify-content:space-around;margin:4px 0 10px}
.emo{border:0;background:none;font-size:28px;cursor:pointer;padding:4px 6px;border-radius:10px}
.emo:hover{background:var(--bg)}
.btn.del{color:var(--danger)}

.composer .icon-btn{flex:none;color:var(--muted)}
.pic{display:block;max-width:100%;width:260px;max-height:320px;object-fit:cover;border-radius:12px;margin:2px 0 4px;cursor:zoom-in;background:#0001}
.upl{font-size:13px;opacity:.8;padding:4px 0}
.voice{display:flex;align-items:center;gap:8px;margin:2px 0}.voice audio{height:36px;max-width:220px}.vd{font-size:12px;opacity:.8}
.filecard{display:flex;align-items:center;gap:10px;text-decoration:none;color:inherit;background:rgba(0,0,0,.06);border-radius:10px;padding:8px 10px;margin:2px 0 4px}
.mine .filecard{background:rgba(255,255,255,.16)}
.fi{font-size:26px}.fn{display:flex;flex-direction:column;min-width:0}.fn b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:200px;font-size:14px}.fn small{opacity:.75}
.lightbox{position:fixed;inset:0;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center;z-index:30;cursor:zoom-out}
.lightbox img{max-width:96vw;max-height:94vh;border-radius:6px}
.lb-x{position:absolute;right:16px;top:12px;border:0;background:none;color:#fff;font-size:26px;cursor:pointer}
.compose-bar.rec{border-left-color:var(--danger)}
.rec-dot{width:10px;height:10px;border-radius:50%;background:var(--danger);animation:blink 1s infinite}
@keyframes blink{50%{opacity:.25}}
.rec-send{background:var(--blue)!important;color:#fff!important;border-radius:18px;padding:6px 16px;font-size:14px!important}

.titles.click{cursor:pointer}
.rec-send.leave{background:#fff!important;color:var(--danger)!important;border:1px solid var(--danger)}
.btn.danger.block{background:#fff}

.sys{align-self:center;text-align:center;margin:8px auto;padding:4px 14px;border-radius:14px;background:rgba(20,33,61,.08);color:var(--muted);font-size:13px}
.sys small{margin-left:8px;opacity:.8}
.toast{position:fixed;left:50%;bottom:90px;transform:translateX(-50%);background:#14213D;color:#fff;padding:10px 18px;border-radius:20px;font-size:14px;z-index:60;max-width:90vw}
.call{position:fixed;inset:0;z-index:50;background:#0d1530;color:#fff;display:flex;flex-direction:column;align-items:center;justify-content:center}
.call .rv{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;background:#0d1530}
.call .lv{position:absolute;right:16px;top:16px;width:120px;max-height:30vh;aspect-ratio:3/4;object-fit:cover;border-radius:12px;border:2px solid rgba(255,255,255,.4);background:#000;transform:scaleX(-1);z-index:2}
.call.audio .rv,.call.audio .lv{display:none}
.call-info{position:relative;z-index:1;text-align:center;text-shadow:0 1px 6px rgba(0,0,0,.6)}
.call-info .av.big{width:96px;height:96px;font-size:40px;margin:0 auto 14px;display:flex}
.call:not(.audio) .call-info{position:absolute;top:18px;left:0;right:0}
.call:not(.audio) .call-info .av.big{display:none}
.cn{font-size:22px;font-weight:700}.cs{opacity:.9;margin-top:4px;font-variant-numeric:tabular-nums}
.call-actions{position:absolute;bottom:36px;left:0;right:0;display:flex;gap:22px;justify-content:center;z-index:2}
.ca{width:62px;height:62px;border-radius:50%;border:0;background:rgba(255,255,255,.18);color:#fff;display:flex;align-items:center;justify-content:center;cursor:pointer;backdrop-filter:blur(6px)}
.ca.green{background:#1E8E5A}.ca.red{background:#C9352B}
.ca .slash{display:none}.ca.off{background:#fff;color:#14213D}.ca.off .slash{display:block}
.ca:focus-visible{outline:3px solid var(--gold)}
