:root{
  --bg:#F2F4F6; --surface:#fff; --ink:#15202B; --ink2:#33414E; --muted:#5B6875; --line:#DCE2E8; --soft:#EEF1F4;
  --brand:#0B6B63; --brand-soft:#E3F1EF; --brand-line:#BFE3D7;
  --warn:#8A4205; --warn-soft:#FCEFD9; --blue:#1F4E8C; --blue-soft:#E4ECF7; --purple:#5B3A8C; --purple-soft:#EEE8F6;
  --danger:#9B2C2C; --danger-soft:#F8E4E4; --nav:#15202B;
  --font:'IBM Plex Sans Arabic', system-ui, sans-serif;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{background:var(--bg);color:var(--ink);font:14px/1.6 var(--font);-webkit-font-smoothing:antialiased}
button,input,select,textarea{font:inherit;color:inherit}
a{color:var(--brand)}
h1,h2,h3{margin:0;line-height:1.3}
.hidden{display:none!important}
.muted{color:var(--muted)}
.small{font-size:12px}
.num{direction:ltr;unicode-bidi:isolate;display:inline-block}

/* layout */
.shell{display:flex;height:100dvh;overflow:hidden}
.side{width:76px;background:var(--nav);display:flex;flex-direction:column;align-items:center;padding:14px 0;gap:6px;flex-shrink:0}
.side .logo{width:44px;height:44px;border-radius:12px;margin-bottom:10px;display:block}
.brand-name{font-family:'Lalezar',var(--font);font-weight:400;font-size:34px;line-height:1.1}
.navlink{width:60px;padding:8px 0;border-radius:10px;color:#B8C3CE;display:flex;flex-direction:column;align-items:center;gap:3px;text-decoration:none;font-size:11px;position:relative}
.navlink.on{background:#2A3947;color:#fff}
.navlink svg{width:22px;height:22px}
.badge{position:absolute;top:4px;inset-inline-start:10px;min-width:18px;height:18px;border-radius:9px;background:#B45309;color:#fff;font-size:10px;display:grid;place-items:center;padding:0 4px}
.main{flex:1;min-width:0;display:flex;flex-direction:column;overflow:hidden}
.bottomnav{display:none}

@media (max-width:860px){
  .side{display:none}
  .bottomnav{display:grid;grid-template-columns:repeat(var(--n,4),1fr);height:64px;background:#fff;border-top:1px solid var(--line);flex-shrink:0}
  .bottomnav a{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;font-size:11px;color:var(--muted);text-decoration:none;position:relative}
  .bottomnav a.on{color:var(--brand);font-weight:600}
  .bottomnav svg{width:22px;height:22px}
  .bottomnav .badge{inset-inline-start:auto;inset-inline-end:28%}
}

/* top bar */
.topbar{background:#fff;border-bottom:1px solid var(--line);padding:12px 16px;display:flex;align-items:center;gap:10px;flex-shrink:0}
.topbar h1{font-size:20px;flex:1}
.status-btn{height:36px;padding:0 12px;border-radius:18px;border:1px solid var(--line);background:#fff;display:flex;align-items:center;gap:6px;cursor:pointer;font-size:13px}
.status-btn .dot{width:9px;height:9px;border-radius:50%;background:#9AA8B5}
.status-btn.online{background:var(--brand-soft);border-color:var(--brand-line);color:var(--brand);font-weight:600}
.status-btn.online .dot{background:#1E9C74}

/* generic */
.page{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:12px}
.page.narrow{max-width:760px;width:100%;margin:0 auto}
.card{background:#fff;border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px}
.card h2{font-size:15px}
.row{display:flex;gap:8px;align-items:center}
.row.wrap{flex-wrap:wrap}
.grow{flex:1;min-width:0}
.grid2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.grid3{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
@media (max-width:520px){.grid3{grid-template-columns:repeat(2,minmax(0,1fr))}}
.btn{height:44px;padding:0 16px;border-radius:10px;border:1px solid var(--line);background:#fff;cursor:pointer;font-size:14px;display:inline-flex;align-items:center;justify-content:center;gap:6px;text-decoration:none;color:var(--ink2);white-space:nowrap}
.btn.pri{background:var(--brand);border-color:var(--brand);color:#fff;font-weight:600}
.btn.dark{background:var(--ink);border-color:var(--ink);color:#fff;font-weight:600}
.btn.danger{color:var(--danger)}
.btn.sm{height:34px;padding:0 12px;font-size:12px;border-radius:8px}
.btn.ghost{border-style:dashed;background:transparent}
.btn:disabled{opacity:.5;cursor:default}
.chip{height:34px;padding:0 12px;border-radius:17px;border:1px solid var(--line);background:#fff;font-size:12px;cursor:pointer;white-space:nowrap}
.chip.on{background:var(--ink);border-color:var(--ink);color:#fff}
a.chip{display:inline-flex;align-items:center;text-decoration:none;color:var(--ink2)}
a.chip.on{color:#fff}
.tag{font-size:11px;padding:2px 8px;border-radius:6px;font-weight:600;white-space:nowrap;background:var(--soft);color:var(--ink2)}
.tag.warn{background:var(--warn-soft);color:var(--warn)} .tag.blue{background:var(--blue-soft);color:var(--blue)}
.tag.ok{background:var(--brand-soft);color:var(--brand)} .tag.purple{background:var(--purple-soft);color:var(--purple)} .tag.danger{background:var(--danger-soft);color:var(--danger)}
label.f{display:flex;flex-direction:column;gap:4px;font-size:12px;color:var(--muted)}
input.in,select.in,textarea.in{width:100%;border:1px solid #C9D2DB;border-radius:10px;padding:10px 12px;font-size:14px;background:#fff;color:var(--ink);outline:none}
input.in,select.in{height:44px;padding:0 12px}
input.in:focus,select.in:focus,textarea.in:focus{border-color:var(--brand)}
.switch{width:50px;height:30px;border-radius:15px;border:none;padding:3px;cursor:pointer;display:flex;flex-shrink:0;background:#C9D2DB;justify-content:flex-end}
.switch.on{background:var(--brand);justify-content:flex-start}
.switch span{width:24px;height:24px;border-radius:50%;background:#fff}
.note{border-radius:10px;padding:8px 12px;font-size:12px;line-height:1.7}
.note.warn{background:var(--warn-soft);color:#6E3504} .note.ok{background:var(--brand-soft);color:var(--brand)} .note.info{background:var(--blue-soft);color:var(--blue)}
.empty{padding:40px 16px;text-align:center;color:var(--muted)}
.seg{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;gap:4px;background:var(--soft);border-radius:10px;padding:4px}
.seg button{height:38px;border:none;border-radius:8px;background:transparent;color:var(--muted);cursor:pointer;font-size:13px}
.seg button.on{background:#fff;color:var(--ink);font-weight:700;box-shadow:0 1px 3px rgba(21,32,43,.15)}
.kpi{background:#fff;border-radius:12px;padding:10px 12px;display:flex;flex-direction:column}
.kpi b{font-size:22px} .kpi span{font-size:11px;color:var(--muted)}
table.t{width:100%;border-collapse:collapse;font-size:13px}
table.t th{color:var(--muted);font-weight:500;text-align:right;padding:6px 4px;font-size:12px}
table.t td{border-top:1px solid var(--soft);padding:8px 4px}

/* inbox */
.inbox{flex:1;display:grid;grid-template-columns:330px minmax(0,1fr) 370px;overflow:hidden}
.col{display:flex;flex-direction:column;overflow:hidden;min-width:0}
.list{background:#fff;border-left:1px solid var(--line)}
.panel{background:#fff;border-right:1px solid var(--line)}
@media (max-width:1180px){.inbox{grid-template-columns:320px minmax(0,1fr)} .panel{display:none} .inbox.show-panel .panel{display:flex;position:fixed;inset:0 auto 0 0;width:min(380px,100%);z-index:20;box-shadow:0 0 40px rgba(0,0,0,.2)}}
@media (max-width:860px){
  .inbox{grid-template-columns:1fr}
  .inbox .chat{display:none} .inbox.show-chat .list{display:none} .inbox.show-chat .chat{display:flex}
  .inbox.show-panel .panel{inset:0;width:100%}
}
.list-head{padding:12px 14px;display:flex;flex-direction:column;gap:10px;border-bottom:1px solid var(--soft)}
.search{display:flex;align-items:center;gap:8px;background:var(--soft);border-radius:12px;padding:0 12px;height:42px;color:var(--muted)}
.search input{border:none;background:transparent;outline:none;flex:1;font-size:14px}
.chips{display:flex;gap:6px;overflow-x:auto;scrollbar-width:none}
.items{flex:1;overflow-y:auto}
.item{display:flex;gap:12px;padding:12px 14px;border-bottom:1px solid var(--soft);cursor:pointer;width:100%;background:#fff;border-inline:none;border-top:none;text-align:right}
.item.on{background:var(--brand-soft);box-shadow:inset -3px 0 0 var(--brand)}
.av{width:44px;height:44px;border-radius:50%;background:#E6EBF0;color:var(--ink2);display:grid;place-items:center;font-weight:600;font-size:16px;flex-shrink:0;position:relative}
.av .ch{position:absolute;bottom:0;left:0;width:13px;height:13px;border-radius:50%;border:2px solid #fff}
.item .meta{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.item .l1{display:flex;justify-content:space-between;gap:8px}
.item .name{font-weight:600}
.item .pv{color:var(--muted);font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.unread{min-width:20px;height:20px;border-radius:10px;background:var(--brand);color:#fff;font-size:11px;font-weight:700;display:grid;place-items:center;padding:0 5px}
.chat{background:#F2F4F6}
.chat-head{background:#fff;border-bottom:1px solid var(--line);padding:8px 12px;display:flex;align-items:center;gap:8px;flex-shrink:0}
.iconbtn{width:44px;height:44px;border:none;background:transparent;border-radius:10px;display:grid;place-items:center;cursor:pointer;color:var(--ink);flex-shrink:0}
.iconbtn svg{width:22px;height:22px}
.asbar{background:#fff;border-bottom:1px solid var(--soft);padding:6px 14px;font-size:12px;color:var(--muted);display:flex;gap:8px;align-items:center;flex-wrap:wrap;flex-shrink:0}
.pagetag{font-size:11px;padding:1px 8px;border-radius:6px;color:#fff;font-weight:600}
.waitbar{padding:6px 14px;font-size:12px;flex-shrink:0;background:var(--warn-soft);color:#6E3504}
.msgs{flex:1;overflow-y:auto;padding:14px;display:flex;flex-direction:column;gap:8px}
.msg{max-width:78%;display:flex;flex-direction:column;gap:2px}
.msg .b{padding:9px 12px;border-radius:14px;line-height:1.6;white-space:pre-wrap;word-wrap:break-word}
.msg.in{align-self:flex-start} .msg.in .b{background:#fff;border-radius:14px 14px 14px 4px}
.msg.out{align-self:flex-end;align-items:flex-end} .msg.out .b{background:var(--brand);color:#fff;border-radius:14px 14px 4px 14px}
.msg.out.auto .b{background:#2F7E77}
.msg .t{font-size:11px;color:var(--muted)}
.msg img,.msg video{max-width:240px;border-radius:10px;display:block}
.msg audio{width:240px}
.sys{align-self:center;font-size:12px;color:var(--muted);background:#E6EBF0;padding:4px 12px;border-radius:14px;text-align:center;max-width:90%}
.ai{margin:0 8px;background:#fff;border:1px solid var(--brand-line);border-bottom:none;border-radius:16px 16px 0 0;padding:12px 14px;display:flex;flex-direction:column;gap:8px;box-shadow:0 -6px 18px rgba(21,32,43,.08);flex-shrink:0}
.ai .txt{font-size:13px;line-height:1.7;color:var(--ink2);max-height:120px;overflow-y:auto;white-space:pre-wrap}
.why{display:flex;gap:4px;flex-wrap:wrap}
.why span{font-size:11px;padding:2px 8px;border-radius:10px;background:var(--brand-soft);color:var(--brand)}
.composer{background:#fff;border-top:1px solid var(--line);padding:8px 10px 10px;display:flex;flex-direction:column;gap:8px;flex-shrink:0}
.composer textarea{flex:1;resize:none;border:1px solid #C9D2DB;border-radius:20px;padding:10px 14px;font-size:14px;line-height:1.5;outline:none;min-height:44px;max-height:160px}
.send{width:44px;height:44px;border-radius:22px;border:none;background:var(--brand);color:#fff;display:grid;place-items:center;cursor:pointer;flex-shrink:0}
.send svg{width:18px;height:18px;transform:scaleX(-1)}
.panel .body{flex:1;overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:12px;background:var(--bg)}
.field{background:var(--soft);border-radius:10px;padding:6px 10px;display:flex;flex-direction:column}
.field span{font-size:11px;color:var(--muted)}
.field input{border:none;background:transparent;outline:none;font-weight:600;font-size:13px;padding:2px 0}
.field.missing{background:var(--warn-soft)}
.stages{display:grid;grid-template-columns:repeat(7,1fr);gap:4px}
.stages i{height:6px;border-radius:3px;background:var(--line)} .stages i.on{background:var(--brand)}

/* modal */
.modal{position:fixed;inset:0;background:rgba(15,20,30,.45);z-index:50;display:flex;align-items:flex-end;justify-content:center}
.sheet{background:var(--bg);width:min(560px,100%);max-height:92dvh;border-radius:18px 18px 0 0;display:flex;flex-direction:column;overflow:hidden}
@media (min-width:861px){.modal{align-items:center}.sheet{border-radius:18px}}
.sheet-head{background:#fff;padding:12px 14px;display:flex;align-items:center;gap:8px;border-bottom:1px solid var(--line)}
.sheet-head h2{flex:1;font-size:17px}
.sheet-body{overflow-y:auto;padding:12px;display:flex;flex-direction:column;gap:12px}
.sheet-foot{background:#fff;border-top:1px solid var(--line);padding:12px}
.opt{display:flex;flex-direction:column;gap:4px;align-items:flex-start;text-align:right;padding:10px 12px;border-radius:12px;cursor:pointer;border:1px solid var(--line);background:#fff}
.opt.on{border:2px solid var(--brand);background:var(--brand-soft)}
.qr{width:260px;height:260px;border:1px solid var(--line);border-radius:12px;background:#fff;display:grid;place-items:center;margin:0 auto}
.qr img{width:240px;height:240px}

/* login */
.login{min-height:100dvh;display:grid;place-items:center;padding:16px}
.login .card{width:min(380px,100%);padding:24px;gap:14px}

#toast{position:fixed;bottom:80px;left:50%;transform:translateX(-50%);background:var(--ink);color:#fff;padding:10px 16px;border-radius:12px;font-size:13px;z-index:100;opacity:0;pointer-events:none;transition:opacity .2s;max-width:90%}
#toast.show{opacity:1}
#toast.bad{background:var(--danger)}

.btn.fb{background:#1877F2;color:#fff;border-color:#1877F2;gap:10px;height:50px;font-size:16px;text-decoration:none;display:inline-flex;align-items:center;justify-content:center}
.btn.fb:hover{background:#166FE5}
details.adv{border-top:1px solid var(--soft);padding-top:8px;display:flex;flex-direction:column;gap:8px}
details.adv>summary{cursor:pointer;font-weight:600;color:var(--muted);font-size:14px;padding:4px 0}
details.adv[open]{display:flex}
details.adv[open]>*:not(summary){margin-top:8px}
