:root {
  --side: #0E1726; --side2: #16223A; --sidet: #C9D3E6; --gold: #E0A82E; --top: #0B0F19;
  --bg: #F3F5FA; --card: #FFFFFF; --ink: #111827; --mut: #6B7280; --line: #E5E7EB;
  --blue: #2563EB; --blue2: #3B82F6; --ok: #16A34A; --warn: #D97706; --bad: #DC2626; --r: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Tajawal, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; }
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
.material-icons-round { font-size: 20px; vertical-align: middle; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(900px 600px at 80% 0, #1B2A52, #0B0F19); padding: 16px; }
.lcard { width: 100%; max-width: 420px; background: #fff; border-radius: 28px; padding: 36px 30px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.llogo { width: 86px; height: 86px; margin-bottom: 14px; }
.lcard h1 { font-size: 22px; margin-bottom: 22px; }
.inp { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 14px; margin-bottom: 12px; }
.inp input { border: 0; outline: 0; flex: 1; padding: 13px 0; background: transparent; }
.err { color: var(--bad); min-height: 20px; font-size: 14px; margin-bottom: 8px; }

/* layout */
#app { display: flex; min-height: 100vh; }
aside { width: 270px; background: var(--side); color: var(--sidet); flex: none; height: 100vh; position: sticky; top: 0; overflow-y: auto; }
.me { text-align: center; padding: 26px 12px 18px; border-bottom: 1px solid rgba(255,255,255,.06); }
.me .av { width: 76px; height: 76px; border-radius: 50%; background: #1F2937; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; }
.me .av span { font-size: 40px; color: #E5E7EB; }
.me b { display: block; color: #fff; font-size: 17px; }
.me small { color: #94A3B8; }
nav { padding: 10px; }
.ni { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: var(--sidet); margin-bottom: 2px; font-weight: 500; }
.ni:hover { background: var(--side2); }
.ni.on { background: #1E293B; color: #fff; box-shadow: inset -3px 0 0 var(--gold); }
.ni .material-icons-round { color: var(--gold); }
.ng { margin: 10px 4px 4px; color: #64748B; font-size: 12.5px; font-weight: 700; padding: 0 10px; }
.main { flex: 1; min-width: 0; }
.top { height: 60px; background: var(--top); color: #fff; display: flex; align-items: center; gap: 12px; padding: 0 16px; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 900; color: var(--gold); font-size: 18px; white-space: nowrap; }
.brand span { color: #fff; font-weight: 700; font-size: 15px; }
.tops { margin-right: auto; display: flex; gap: 4px; align-items: center; }
.tb { background: none; border: 0; color: #E5E7EB; display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px; position: relative; font-size: 14px; }
.tb:hover { background: rgba(255,255,255,.08); }
.tb.danger { color: #F87171; }
.dot { position: absolute; top: 4px; left: 4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-style: normal; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.ib { background: none; border: 0; color: inherit; width: 38px; height: 38px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.ib:hover { background: rgba(0,0,0,.06); }
.top .ib:hover { background: rgba(255,255,255,.1); }
#menuBtn { display: none; }
#view { padding: 22px; max-width: 1500px; }

/* blocks */
.h { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.h h2 { font-size: 21px; font-weight: 800; }
.h .sp { flex: 1; }
.card { background: var(--card); border-radius: var(--r); padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.06); border: 1px solid #EEF0F4; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.hero { background: linear-gradient(135deg, #1D4ED8, #3B82F6); color: #fff; border: 0; }
.hero h3 { font-size: 18px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: rgba(255,255,255,.12); border-radius: 14px; padding: 12px 14px; }
.kpi small { opacity: .85; display: block; font-size: 13px; }
.kpi b { font-size: 21px; font-weight: 900; }
.stat { display: flex; align-items: center; gap: 14px; }
.stat .ic { width: 50px; height: 50px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #fff; flex: none; }
.stat small { color: var(--mut); display: block; }
.stat b { font-size: 22px; font-weight: 900; }
.btn { border: 0; border-radius: 11px; padding: 9px 16px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; background: #EEF2FF; color: var(--blue); white-space: nowrap; }
.btn.pri { background: var(--blue); color: #fff; }
.btn.dark { background: #0F172A; color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: #FEE2E2; color: var(--bad); }
.btn.gold { background: var(--gold); color: #1F1300; }
.btn.wide { width: 100%; justify-content: center; padding: 13px; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .5; cursor: default; }
.f { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.f label { font-size: 13px; color: var(--mut); font-weight: 700; }
.f input, .f select, .f textarea, .in { border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff; outline: 0; width: 100%; }
.f input:focus, .f select:focus, .f textarea:focus, .in:focus { border-color: var(--blue2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .f { flex: 1; min-width: 160px; }
.chk { display: inline-flex; align-items: center; gap: 6px; margin: 4px 10px 4px 0; font-weight: 500; }
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: right; color: var(--mut); font-weight: 700; padding: 10px; border-bottom: 1.5px solid var(--line); white-space: nowrap; background: #FAFBFD; }
td { padding: 10px; border-bottom: 1px solid #F1F2F5; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #F8FAFF; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 700; background: #F1F5F9; color: #334155; white-space: nowrap; }
.t-ok { background: #DCFCE7; color: #15803D; } .t-bad { background: #FEE2E2; color: #B91C1C; } .t-warn { background: #FEF3C7; color: #B45309; } .t-blue { background: #DBEAFE; color: #1D4ED8; } .t-gray { background: #F1F5F9; color: #475569; }
.pv { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 800; color: #fff; }
.mut { color: var(--mut); }
.num { direction: ltr; unicode-bidi: plaintext; }
.empty { text-align: center; color: var(--mut); padding: 40px 10px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 8px 14px; border-radius: 10px; background: #fff; border: 1.5px solid var(--line); font-weight: 700; }
.tab.on { background: #0F172A; color: #fff; border-color: #0F172A; }
.cat { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; }
.cat:hover { border-color: var(--blue2); }
.cat img, .cat .ph { width: 54px; height: 54px; border-radius: 12px; object-fit: cover; background: #EEF2F7; flex: none; display: flex; align-items: center; justify-content: center; }
.cat .t { flex: 1; min-width: 0; }
.cat .t b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.off { opacity: .5; }
.chart { width: 100%; height: 220px; }

/* modal / toast / drawer */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; z-index: 50; overflow-y: auto; }
.mbox { background: #fff; border-radius: 20px; width: 100%; max-width: 680px; box-shadow: 0 30px 90px rgba(0,0,0,.35); }
.mbox.wide { max-width: 980px; }
.mhead { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.mhead b { flex: 1; font-size: 17px; }
.mbody { padding: 18px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #0F172A; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 60; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.bad { background: var(--bad); }
.drawer { position: fixed; top: 60px; left: 12px; width: 360px; max-height: 70vh; overflow-y: auto; background: #fff; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); z-index: 40; padding: 10px; }
.al { padding: 10px; border-radius: 10px; border-bottom: 1px solid #F1F2F5; font-size: 14px; }
.al small { color: var(--mut); display: block; }
.chatw { display: grid; grid-template-columns: 300px 1fr; grid-template-rows: minmax(0, 1fr); height: calc(100vh - 150px); height: calc(100dvh - 150px); gap: 0; padding: 0; overflow: hidden; }
.clist { border-left: 1px solid var(--line); overflow-y: auto; }
.ci { padding: 12px 14px; border-bottom: 1px solid #F1F2F5; cursor: pointer; }
.ci.on, .ci:hover { background: #F5F8FF; }
.ci b { display: block; } .ci small { color: var(--mut); }
.cmsgs { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px; background: #F8FAFC; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 14px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.msg.adm { align-self: flex-start; background: #DBEAFE; border-color: #BFDBFE; }
.msg.usr { align-self: flex-end; }
.msg small { display: block; color: var(--mut); font-size: 11px; margin-top: 3px; }
.msg { flex-shrink: 0; }
.msg img { max-width: 220px; max-height: 300px; object-fit: contain; border-radius: 10px; display: block; cursor: zoom-in; }
.cin { flex-shrink: 0; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.qr { flex-shrink: 0; display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 10px 0; }
.codes { background: #0F172A; color: #A7F3D0; border-radius: 10px; padding: 10px; font-family: Consolas, monospace; direction: ltr; white-space: pre-wrap; }
.g-dash { grid-template-columns: 2fr 1fr 1fr; }
.g-side { grid-template-columns: 1fr 2fr; }
.chead { display: none; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.scrim { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 25; }
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; }
  .g-dash { grid-template-columns: 1fr 1fr; } .g-dash > .hero { grid-column: 1 / -1; }
  .g-side { grid-template-columns: 1fr; }
}
/* ---- phone ---- */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  body { font-size: 14.5px; }
  #app { display: block; }
  .main { width: 100%; min-width: 0; }
  .card, .grid > * { min-width: 0; }
  .hero h3 { font-size: 16px; }
  #pvBal .row, #waits .row { flex-wrap: nowrap; }
  aside { position: fixed; right: 0; top: 0; z-index: 30; transform: translateX(100%); transition: transform .2s; width: 82vw; max-width: 300px; }
  aside.open { transform: none; box-shadow: -20px 0 60px rgba(0,0,0,.4); }
  #menuBtn { display: inline-flex; }
  .top { padding: 0 8px; gap: 4px; height: 56px; }
  .brand { font-size: 16px; } .brand span { display: none; }
  .tops { gap: 0; } .tb { font-size: 0; gap: 0; padding: 8px; } .tb .material-icons-round { font-size: 22px; }
  #view { padding: 12px; }
  .grid { gap: 10px; }
  .g2, .g3, .g4, .g-dash, .g-side { grid-template-columns: 1fr; }
  #k2, #cs, #rk { grid-template-columns: 1fr 1fr !important; }
  .card { padding: 14px; border-radius: 14px; }
  .stat { gap: 10px; } .stat .ic { width: 40px; height: 40px; border-radius: 12px; } .stat b { font-size: 18px; }
  .kpis { grid-template-columns: 1fr 1fr; } .kpi b { font-size: 17px; }
  .h { gap: 8px; } .h h2 { font-size: 18px; width: 100%; } .h .sp { display: none; }
  .h .in, .h select { max-width: none !important; flex: 1 1 140px; }
  .h .btn { flex: 1 1 auto; justify-content: center; }
  .row > .f { min-width: 100%; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; } .tab { white-space: nowrap; }
  /* tables → cards */
  .tw table, .tw tbody, .tw tr, .tw td { display: block; width: 100%; }
  .tw tr:first-child:has(th) { display: none; }
  .tw tr { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; margin-bottom: 10px; }
  .tw td { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 0; padding: 6px 0; text-align: left; }
  .tw td::before { content: attr(data-label); color: var(--mut); font-weight: 700; font-size: 12.5px; text-align: right; flex: none; }
  .tw td[data-label=""]::before { content: none; }
  .tw td.num { direction: rtl; unicode-bidi: normal; }
  .tw td > * { max-width: 70%; }
  .tw td input.in { max-width: 60%; }
  .tw tr.click:hover td { background: none; }
  .modal { padding: 0; align-items: flex-end; }
  .mbox, .mbox.wide { max-width: 100%; border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto; }
  .mbody { padding: 14px; }
  .chatw { grid-template-columns: 1fr; height: calc(100vh - 82px); height: calc(100dvh - 82px); }
  .chatw.open .clist { display: none; } .chatw:not(.open) .cmsgs { display: none; }
  .chead { display: flex; }
  .msg { max-width: 88%; }
  .qr { flex-wrap: nowrap; overflow-x: auto; }
  .drawer { left: 8px; right: 8px; width: auto; top: 60px; }
  .toast { left: 12px; right: 12px; transform: none; text-align: center; }
  .chart { height: 180px; }
}
@media print { aside, .top, .noprint, .h .btn { display: none !important; } #view { padding: 0; } .card { box-shadow: none; border: 0; } }

/* provider editor (custom API) + code stock */
.custom h4 { margin: 16px 0 8px; font-size: 15px; }
.imp { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: #F5F8FF; border: 1.5px dashed #BFD2FF; border-radius: 14px; padding: 12px 14px; margin: 6px 0 4px; }
.imp > .material-icons-round { color: var(--blue); font-size: 28px; }
.imp small { display: block; }
details.op { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
details.op > summary { cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.op > summary::before { content: 'expand_more'; font-family: 'Material Icons Round'; font-size: 20px; color: var(--mut); transition: transform .2s; }
details.op[open] > summary::before { transform: rotate(180deg); }
details.op[open] > summary { margin-bottom: 10px; }
.mapg { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 10px; }
.vh { font-size: 12.5px; line-height: 1.9; margin-top: 10px; }
.vh code { background: #EEF2FF; border-radius: 6px; padding: 1px 5px; direction: ltr; display: inline-block; }
.probe { border: 1.5px solid #BBF7D0; background: #F0FDF4; border-radius: 14px; padding: 12px; margin-top: 10px; }
.probe pre, details pre { direction: ltr; text-align: left; background: #0B0F19; color: #D1E3FF; border-radius: 10px; padding: 10px; max-height: 280px; overflow: auto; font-size: 12px; margin-top: 8px; white-space: pre-wrap; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { border: 1px solid #C7D2FE; background: #EEF2FF; color: #3730A3; border-radius: 999px; padding: 3px 10px; font-size: 12px; direction: ltr; }
.chip:hover { background: #C7D2FE; }
@media (max-width: 860px) { .mapg { grid-template-columns: 1fr 1fr; } .imp .sp { display: none; } }

/* أضيفت 2026-11-09: زر التأمين بالشريط + فلتر الفترة + قائمة بحث العملاء */
.tb.ins { background: #fff; color: #111827; font-weight: 700; }
.tb.ins:hover { background: #F3F4F6; }
.rng { display: inline-flex; align-items: center; gap: 6px; }
.rng span { color: var(--mut, #6B7280); font-size: 13px; white-space: nowrap; }
.rng .in { max-width: 160px; }
.cpk { position: relative; }
.cpk .in { padding-left: 36px; }
.cpk > .material-icons-round { position: absolute; left: 9px; top: 9px; color: #9CA3AF; pointer-events: none; }
.cpl { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1.5px solid var(--line); border-radius: 10px; max-height: 280px; overflow-y: auto; z-index: 30; box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.cpl.hidden { display: none; }
.cpi { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; }
.cpi small { color: var(--mut, #6B7280); }
.cpi span { margin-right: auto; font-size: 13px; }
.cpi.on, .cpi:hover { background: #EEF2FF; }
@media (max-width: 860px) {
  .tb.ins { font-size: 13px; gap: 4px; padding: 6px 8px; }
  .h .rng { flex: 1 1 140px; } .h .rng .in { max-width: none; }
  .cpi { flex-wrap: wrap; gap: 2px 10px; }
}
/* شاشات الموبايل: الأيقونات تاخذ كل عرض الشريط حتى يبقى زر الخروج ظاهر */
@media (max-width: 480px) { .brand { display: none; } .tops { margin-right: 0; flex: 1; justify-content: space-between; } }
