:root{
  --navy:#0B1F3A;--blue:#17386F;--teal:#00C2A8;--teal-d:#00A892;--amber:#FFB547;
  --bg:#F3F6FA;--card:#fff;--line:#E1E7EF;--muted:#5B6B82;--danger:#D9534F;
  --out:#DDF7F2;--in:#fff;--r:16px;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;font-family:Vazirmatn,Tahoma,system-ui,sans-serif;background:var(--bg);color:var(--navy);line-height:1.7;font-size:15px;-webkit-text-size-adjust:100%}
a{color:var(--teal-d)}
button,input,textarea{font:inherit;color:inherit}
[hidden]{display:none!important}

/* ---------- auth ---------- */
body.auth{display:grid;place-items:center;padding:20px;background:linear-gradient(160deg,var(--navy) 0 38%,var(--bg) 38%)}
.auth-card{width:100%;max-width:400px;background:var(--card);border-radius:22px;padding:30px 26px 26px;box-shadow:0 20px 50px rgba(11,31,58,.18)}
.auth-logo{display:block;height:54px;margin:0 auto 6px}
.auth-sub{text-align:center;color:var(--muted);margin:0 0 20px;font-size:.92rem}
.tabs{display:grid;grid-template-columns:1fr 1fr;background:var(--bg);border-radius:12px;padding:4px;margin-bottom:16px}
.tabs button{border:0;background:none;padding:8px;border-radius:9px;cursor:pointer;color:var(--muted);font-weight:600}
.tabs button.on{background:#fff;color:var(--navy);box-shadow:0 1px 4px rgba(11,31,58,.12)}
.form{display:grid;gap:14px}
.form label{display:grid;gap:5px;font-size:.88rem;font-weight:600}
.form input{border:1.5px solid var(--line);border-radius:12px;padding:11px 14px;background:#fff;outline:none;font-weight:400}
.form input:focus{border-color:var(--teal);box-shadow:0 0 0 3px rgba(0,194,168,.18)}
.reg-only{display:none!important}
.is-register .form label.reg-only{display:grid!important}
.is-register .form .hint.reg-only{display:block!important}
.hint{margin:0;font-size:.8rem;color:var(--muted)}
.btn{border:0;border-radius:12px;background:var(--navy);color:#fff;padding:12px;font-weight:700;cursor:pointer;transition:.15s}
.btn:hover{background:var(--blue)}
.alert{background:#FDECEA;color:#9B2C27;border-radius:12px;padding:10px 14px;margin-bottom:14px;font-size:.88rem}

/* ---------- shell ---------- */
body.app{overflow:hidden}
.shell{height:100dvh;max-width:1200px;margin:0 auto;display:flex;background:var(--card)}
body.client .shell{max-width:780px;flex-direction:column;box-shadow:0 0 40px rgba(11,31,58,.08)}
.topbar{display:flex;align-items:center;gap:12px;padding:12px 16px;background:var(--navy);color:#fff;flex:none}
.topbar .mark{width:38px;height:38px;border-radius:10px;background:#fff1}
.who{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.3}
.who b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.who small{color:#9FB3D1;font-size:.78rem}
.link{background:none;border:0;color:#C9D6EC;font-size:.85rem;cursor:pointer;text-decoration:none;padding:6px 8px;border-radius:8px}
.link:hover{background:#ffffff18;color:#fff}
.link.danger:hover{color:#FFB3AE}

/* ---------- chat ---------- */
.chat{flex:1;min-width:0;display:flex;flex-direction:column;background:#EAF0F6;
  background-image:radial-gradient(circle at 20% 10%,#ffffffaa 0,transparent 40%),radial-gradient(circle at 90% 80%,#d7f5efaa 0,transparent 35%)}
.msgs{flex:1;overflow-y:auto;padding:14px 14px 8px;display:flex;flex-direction:column;gap:4px;overscroll-behavior:contain}
.older{align-self:center;border:0;background:#fff;border-radius:99px;padding:5px 14px;font-size:.8rem;color:var(--muted);cursor:pointer;margin-bottom:6px;box-shadow:0 1px 3px rgba(11,31,58,.1)}
.day{align-self:center;background:#fff9;color:var(--muted);border-radius:99px;font-size:.75rem;padding:2px 12px;margin:10px 0 6px}
.msg{display:flex}
.msg.out{justify-content:flex-start}  /* RTL: start = right */
.msg.in{justify-content:flex-end}
.bubble{max-width:min(78%,520px);padding:7px 11px 5px;border-radius:14px;box-shadow:0 1px 2px rgba(11,31,58,.1);word-break:break-word;overflow-wrap:anywhere}
.msg.out .bubble{background:var(--out);border-end-start-radius:4px}
.msg.in .bubble{background:var(--in);border-end-end-radius:4px}
.text{white-space:pre-wrap}
.bubble img{display:block;max-width:100%;max-height:340px;border-radius:10px;margin:2px 0 4px}
.bubble audio{display:block;width:min(260px,64vw);height:40px;margin:2px 0 4px}
.file{display:flex;align-items:center;gap:10px;text-decoration:none;color:inherit;padding:4px 0 6px;min-width:190px}
.file .ext{flex:none;width:42px;height:42px;border-radius:10px;background:var(--navy);color:#fff;display:grid;place-items:center;font-size:.66rem;font-weight:800;letter-spacing:.3px}
.file .fi{display:flex;flex-direction:column;min-width:0;line-height:1.35}
.file b{font-size:.88rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:200px;direction:ltr;text-align:right}
.file small{color:var(--muted)}
.meta{display:flex;justify-content:flex-end;gap:4px;font-size:.68rem;color:var(--muted);margin-top:1px}
.tick.seen{color:var(--teal-d);font-weight:700}

/* ---------- composer ---------- */
.composer{background:#fff;border-top:1px solid var(--line);padding:8px 10px calc(8px + env(safe-area-inset-bottom));flex:none}
.composer .row{display:flex;align-items:flex-end;gap:6px}
.composer textarea{flex:1;resize:none;border:1.5px solid var(--line);border-radius:20px;padding:9px 14px;max-height:140px;outline:none;background:var(--bg);line-height:1.6}
.composer textarea:focus{border-color:var(--teal);background:#fff}
.icon-btn{flex:none;width:40px;height:40px;border:0;border-radius:50%;background:none;color:var(--muted);display:grid;place-items:center;cursor:pointer;font-size:1rem}
.icon-btn:hover{background:var(--bg);color:var(--navy)}
.icon-btn.on{background:#FDECEA;color:var(--danger)}
.send{flex:none;width:42px;height:42px;border:0;border-radius:50%;background:var(--teal);color:var(--navy);display:grid;place-items:center;cursor:pointer}
.send svg{transform:scaleX(-1)}
.send:hover{background:var(--teal-d)}
.send:disabled{opacity:.5}
.pending,.rec{display:flex;align-items:center;gap:8px;background:var(--bg);border-radius:12px;padding:4px 6px 4px 12px;margin-bottom:8px;font-size:.88rem}
.pending .pname{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.rec .dot{width:10px;height:10px;border-radius:50%;background:var(--danger);animation:blink 1s infinite}
.rec .rlabel{flex:1;color:var(--muted)}
@keyframes blink{50%{opacity:.25}}

/* ---------- admin ---------- */
.side{width:330px;flex:none;border-inline-end:1px solid var(--line);display:flex;flex-direction:column;min-height:0}
.side-tabs{display:grid;grid-template-columns:1fr 1fr;border-bottom:1px solid var(--line)}
.side-tabs button{border:0;background:none;padding:11px;cursor:pointer;font-weight:600;color:var(--muted);border-bottom:2.5px solid transparent}
.side-tabs button.on{color:var(--navy);border-color:var(--teal)}
.side-body{flex:1;overflow-y:auto;padding:12px;min-height:0}
.search{width:100%;border:1.5px solid var(--line);border-radius:12px;padding:9px 14px;background:var(--bg);outline:none;margin-bottom:10px}
.search:focus{border-color:var(--teal);background:#fff}
.clients,.allowed{list-style:none;margin:0;padding:0;display:grid;gap:2px}
.clients li{display:flex;align-items:center;gap:10px;padding:10px;border-radius:12px;cursor:pointer}
.clients li:hover{background:var(--bg)}
.clients li.on{background:#E3F8F4}
.clients li.off{opacity:.55}
.clients li.none,.allowed li.none{cursor:default;color:var(--muted);justify-content:center;font-size:.88rem}
.av{flex:none;width:42px;height:42px;border-radius:50%;background:var(--blue);color:#fff;display:grid;place-items:center;font-weight:700}
.info{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.4}
.info b{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.info small{color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.badge{flex:none;min-width:22px;height:22px;border-radius:99px;background:var(--teal);color:var(--navy);font-size:.75rem;font-weight:800;display:grid;place-items:center;padding:0 6px}
.add{display:grid;gap:8px;margin-bottom:14px}
.add textarea{border:1.5px solid var(--line);border-radius:12px;padding:10px 12px;background:var(--bg);outline:none;resize:vertical}
.add textarea:focus{border-color:var(--teal);background:#fff}
.allowed li{display:flex;align-items:center;gap:8px;padding:8px 6px;border-bottom:1px solid var(--line)}
.allowed .info b{text-align:right}
.state{flex:none;font-size:.72rem;background:#FFF3DC;color:#8A5A00;border-radius:99px;padding:1px 10px}
.state.ok{background:#DDF7F2;color:#046A5B}
.chat-top .back{display:none;color:#fff}
.chat-top .back:hover{background:#ffffff22;color:#fff}
.empty{flex:1;display:grid;place-items:center;color:var(--muted);background:#EAF0F6}
.toast{position:fixed;bottom:90px;left:50%;transform:translateX(-50%);background:var(--navy);color:#fff;padding:10px 18px;border-radius:12px;font-size:.88rem;z-index:20;max-width:90vw;box-shadow:0 8px 24px rgba(11,31,58,.3)}

@media (max-width:760px){
  .admin-shell .side{width:100%;border:0}
  .admin-shell .chat{display:none}
  .admin-shell.show-chat .side{display:none}
  .admin-shell.show-chat .chat{display:flex}
  .chat-top .back{display:grid}
  .bubble{max-width:86%}
}

/* ---------- v2 additions ---------- */
@font-face{font-family:Vazirmatn;src:url(fonts/vazirmatn.woff2) format("woff2");font-weight:100 900;font-display:swap}
.alert.ok{background:#E3F8F4;color:#046A5B}
.btn.ghost{background:#fff;color:var(--navy);border:1.5px solid var(--line)}
.btn.ghost:hover{background:var(--bg)}
.center{text-align:center}
.big-icon{font-size:3rem;text-align:center;margin:6px 0}
.h1{font-size:1.2rem;text-align:center;margin:0 0 6px}
input.code{text-align:center;letter-spacing:.5em;font-size:1.4rem}
.bubble .sender{font-size:.72rem;font-weight:700;color:var(--teal-d);margin-bottom:1px}
.sec{font-size:.78rem;color:var(--muted);margin:10px 4px 6px;font-weight:600}
.side-tabs.three{grid-template-columns:repeat(3,1fr)}
.clients li.pend{cursor:default;background:#FFF8EA;border:1px solid #FFE3B0;gap:6px}
.clients li.pend button{border:0;border-radius:9px;padding:6px 12px;cursor:pointer;font-weight:700}
.clients li.pend .ok{background:var(--teal);color:var(--navy)}
.clients li.pend .no{background:#fff;color:var(--danger);border:1px solid var(--line)}
.settings{flex:1;min-width:0;display:flex;flex-direction:column;background:var(--bg);min-height:0}
.settings-body{flex:1;overflow-y:auto;padding:16px;display:grid;gap:16px;align-content:start}
.card{background:#fff;border:1px solid var(--line);border-radius:16px;padding:18px;max-width:720px;width:100%;margin-inline:auto}
.card h2{margin:0 0 8px;font-size:1.05rem}
.card h3{margin:18px 0 4px;font-size:.92rem;color:var(--blue)}
.sform{display:grid;gap:12px}
.sform label{display:grid;gap:4px;font-size:.84rem;font-weight:600}
.sform input:not([type=checkbox]),.sform select{border:1.5px solid var(--line);border-radius:10px;padding:9px 12px;background:#fff;outline:none;font-weight:400;width:100%}
.sform input:focus,.sform select:focus{border-color:var(--teal)}
.sform label.chk{display:flex;align-items:center;gap:8px;font-weight:400}
.sform .two{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.btnrow{display:flex;flex-wrap:wrap;gap:8px}
.btnrow .btn{padding:10px 16px}
.hint code{background:var(--bg);padding:0 5px;border-radius:5px;direction:ltr;display:inline-block}
.a2hs{position:fixed;inset-inline:12px;bottom:calc(76px + env(safe-area-inset-bottom));background:var(--navy);color:#fff;border-radius:14px;padding:12px 14px;font-size:.85rem;z-index:30;display:flex;gap:10px;align-items:center;box-shadow:0 10px 30px rgba(11,31,58,.35)}
.a2hs span{flex:1}
.a2hs button{border:0;border-radius:9px;padding:6px 12px;cursor:pointer;background:var(--teal);color:var(--navy);font-weight:700}
.a2hs button.x{background:none;color:#9FB3D1}
@media (max-width:760px){
  .admin-shell .settings{display:none}
  .admin-shell.show-chat .chat:not([hidden]),.admin-shell.show-chat .settings:not([hidden]){display:flex}
  .admin-shell .empty{display:none}
  .sform .two{grid-template-columns:1fr}
  .back2{color:#fff}
}
@media (min-width:761px){.back2{display:none}}
