@font-face { font-family: Plex; font-weight: 400; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; font-weight: 600; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; font-weight: 700; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: Plex; font-weight: 400; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: Plex; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: Plex; font-weight: 600; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }
@font-face { font-family: Plex; font-weight: 700; font-display: swap; src: url(/fonts/ibm-plex-sans-arabic-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+2000-206F, U+20AC; }

:root {
  --ink: #1C2433;
  --ink-2: #3A4459;
  --muted: #667085;
  --line: #E3E7EC;
  --paper: #F3F5F7;
  --surface: #FFFFFF;
  --saffron: #F2A93B;
  --saffron-deep: #A86A0E;
  --saffron-wash: #FFF4E0;
  --green: #2F7D5B;
  --green-wash: #E6F3EC;
  --red: #B8432F;
  --red-wash: #FBEAE6;
  --blue-wash: #E9EEFA;
  --r-panel: 14px;
  --r-ctl: 8px;
  --t1: 13px; --t2: 15px; --t3: 17px; --t4: 21px; --t5: 28px; --t6: 40px;
  font-family: Plex, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font-size: var(--t2); line-height: 1.65; -webkit-font-smoothing: antialiased; }
a { color: var(--ink); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; line-height: 1.3; font-weight: 600; }
h1 { font-size: var(--t5); }
h2 { font-size: var(--t4); }
h3 { font-size: var(--t3); }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: var(--t1); }
.num { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; overflow-wrap: anywhere; max-width: 100%; }
td.ltr { display: table-cell; text-align: end; }
:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- عناصر التحكم ---------- */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--r-ctl); padding: 8px 16px; font-weight: 500; transition: background .15s, border-color .15s; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { border-color: #C9D0D8; background: #FAFBFC; }
button.primary, .btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
button.primary:hover { background: var(--ink-2); }
button.danger { color: var(--red); border-color: #EBC3BA; }
button.ghost { border-color: transparent; background: transparent; padding: 6px 10px; }
button.ghost:hover { background: rgba(28,36,51,.06); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); width: 100%; border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 9px 12px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--saffron-deep); box-shadow: 0 0 0 3px var(--saffron-wash); }
textarea { resize: vertical; line-height: 1.7; }
label.f { display: block; margin: 0 0 14px; }
label.f > span { display: block; font-size: var(--t1); color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
label.f > small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; margin: 6px 0; }
.check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--ink); flex: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; padding: 6px 14px; border-radius: 6px; background: transparent; font-weight: 500; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- الهيكل ---------- */
.bar { background: var(--ink); color: #fff; display: flex; align-items: center; gap: 18px; padding: 0 24px; height: 58px; }
.bar .brand { display: flex; white-space: nowrap; align-items: center; gap: 10px; font-weight: 600; font-size: var(--t3); color: #fff; text-decoration: none; }
.bar .brand img { width: 28px; height: 28px; }
.bar nav { display: flex; gap: 4px; }
.bar nav a { color: #C9D1DE; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.bar nav a[aria-current="page"], .bar nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.bar .sp { flex: 1; }
.bar button { background: transparent; color: #fff; border-color: rgba(255,255,255,.22); padding: 5px 12px; }
.bar button:hover { background: rgba(255,255,255,.08); }
.bar .who { color: #C9D1DE; font-size: var(--t1); }
main { max-width: 1240px; margin: 0 auto; padding: 28px 24px 60px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head .sub { color: var(--muted); margin-top: 4px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 22px; }
.panel + .panel { margin-top: 18px; }
.panel > h2, .panel > h3 { margin-bottom: 14px; }
.grid { display: grid; gap: 18px; }
.grid > .panel + .panel { margin-top: 0; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-side { grid-template-columns: 330px 1fr; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 0 22px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 11px 14px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--saffron); }
.tabs a .n { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; margin-inline-start: 5px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- الحالة ---------- */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px; border-radius: 99px; font-size: var(--t1); font-weight: 500; background: var(--paper); color: var(--ink-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #9AA3B2; }
.pill.on { background: var(--green-wash); color: var(--green); } .pill.on::before { background: var(--green); }
.pill.wait { background: var(--saffron-wash); color: var(--saffron-deep); } .pill.wait::before { background: var(--saffron); }
.pill.off { background: var(--red-wash); color: var(--red); } .pill.off::before { background: var(--red); }
.pill.plain::before { display: none; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 6px; font-size: 12.5px; background: var(--paper); color: var(--ink-2); font-weight: 500; }
.tag.hot { background: var(--saffron-wash); color: var(--saffron-deep); }
.tag.bad { background: var(--red-wash); color: var(--red); }
.meter { height: 8px; border-radius: 99px; background: var(--paper); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.meter.warn > i { background: var(--saffron); }
.meter.over > i { background: var(--red); }

/* ---------- كشف العملاء (الصفحة الرئيسية للمسؤول) ---------- */
.roster { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.roster th { text-align: start; font-size: var(--t1); color: var(--muted); font-weight: 500; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #FAFBFC; }
.roster td { padding: 16px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.roster tr:last-child td { border-bottom: 0; }
.roster tbody tr { cursor: pointer; }
.roster tbody tr:hover td { background: #FBFCFD; }
.who-cell { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--ink); color: var(--saffron); display: grid; place-items: center; font-weight: 700; font-size: var(--t3); flex: none; }
.who-cell b { display: block; font-weight: 600; }
.who-cell span { color: var(--muted); font-size: var(--t1); }
.usage { min-width: 150px; }
.usage .num { font-size: var(--t1); color: var(--ink-2); margin-bottom: 5px; display: block; }
.kpis { display: flex; gap: 36px; flex-wrap: wrap; margin: 6px 0 22px; }
.kpis div b { display: block; font-size: var(--t5); font-weight: 600; line-height: 1.2; }
.kpis div span { color: var(--muted); font-size: var(--t1); }

/* ---------- بطاقة الموظف ---------- */
.badge-wrap { position: relative; padding-top: 34px; }
.lanyard { position: absolute; top: 0; inset-inline: 0; margin: 0 auto; width: 18px; height: 40px; background: var(--saffron); z-index: 2; }
.lanyard::after { content: ""; position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%); width: 34px; height: 14px; border-radius: 4px; background: var(--ink); box-shadow: inset 0 0 0 3px #2E3A50; }
.badge { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px 24px 22px; text-align: center; box-shadow: 0 14px 30px -18px rgba(28,36,51,.35); }
.badge .company { font-size: var(--t1); color: var(--muted); font-weight: 500; }
.badge .portrait { width: 92px; height: 92px; margin: 14px auto 12px; border-radius: 26px; background: var(--ink); color: var(--saffron); display: grid; place-items: center; font-size: var(--t6); font-weight: 700; }
.badge .name { font-size: var(--t5); font-weight: 700; line-height: 1.2; }
.badge .name small { display: block; font-size: var(--t2); font-weight: 500; color: var(--muted); margin-top: 2px; }
.badge .role { color: var(--ink-2); margin: 6px 0 14px; }
.badge .shift { display: flex; justify-content: center; margin-bottom: 18px; }
.badge dl { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; border-top: 1px dashed var(--line); padding-top: 16px; }
.badge dl div + div { border-inline-start: 1px solid var(--line); }
.badge dt { font-size: 12px; color: var(--muted); }
.badge dd { margin: 0; font-size: var(--t4); font-weight: 600; }
.badge .serial { margin-top: 16px; font-size: 12px; color: var(--muted); letter-spacing: .5px; }

/* ---------- سجل اليوم والرسوم ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 54px 1fr; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed time { color: var(--muted); font-size: var(--t1); padding-top: 2px; }
.feed b { font-weight: 600; }
.feed p { margin: 2px 0 0; color: var(--ink-2); font-size: var(--t1); white-space: pre-line; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.bars .d { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.bars .stack2 { width: 100%; max-width: 26px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; }
.bars .in { background: #C9D1DE; border-radius: 4px 4px 0 0; }
.bars .bot { background: var(--ink); border-radius: 0 0 4px 4px; }
.bars small { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: var(--t1); color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }

/* ---------- المحادثات ---------- */
.conv { display: grid; grid-template-columns: 340px 1fr; gap: 18px; height: calc(100vh - 260px); min-height: 520px; }
.clist { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.clist .tools { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.clist .items { overflow: auto; flex: 1; }
.citem { display: block; width: 100%; text-align: start; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 13px 16px; background: transparent; font-weight: 400; }
.citem:hover { background: #FAFBFC; }
.citem[aria-current="true"] { background: var(--saffron-wash); }
.citem .top { display: flex; gap: 8px; align-items: center; }
.citem .top b { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.citem .top time { color: var(--muted); font-size: 12px; }
.citem .last { color: var(--muted); font-size: var(--t1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.citem .row { flex-wrap: nowrap; }
.conv > .panel + .panel, .files > .panel + .panel { margin-top: 0; }
.thread { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.thread .th-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.thread .summary { margin-top: 8px; font-size: var(--t1); color: var(--ink-2); background: var(--paper); border-radius: var(--r-ctl); padding: 8px 12px; }
.msgs { flex: 1; overflow: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: #F7F8FA; }
.msg { max-width: 74%; padding: 9px 13px 6px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; }
.msg.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-start-start-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--saffron-wash); border-start-end-radius: 4px; }
.msg.human { background: var(--blue-wash); }
.msg.campaign, .msg.template { background: #F1EDFB; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; align-items: center; }
.msg .teach { font-size: 11.5px; padding: 0 6px; border: 0; background: transparent; color: var(--saffron-deep); text-decoration: underline; text-underline-offset: 3px; font-weight: 500; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { min-height: 44px; max-height: 150px; }
.manual-note { font-size: var(--t1); color: var(--saffron-deep); margin-top: 6px; }

/* ---------- جداول وقوائم ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; font-size: var(--t1); color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.alert-item { padding: 14px 0; border-bottom: 1px solid var(--line); }
.alert-item:last-child { border-bottom: 0; }
.alert-item.unread { box-shadow: inset -3px 0 0 var(--saffron); padding-inline-start: 14px; }
.alert-item p { white-space: pre-line; color: var(--ink-2); margin: 6px 0 0; }
.route { display: grid; grid-template-columns: minmax(200px, 1fr) 28px minmax(240px, 1.3fr) auto; gap: 14px; align-items: start; padding: 16px 0; border-bottom: 1px solid var(--line); }
.route .arrow { color: var(--saffron-deep); font-size: 22px; line-height: 1; padding-top: 30px; text-align: center; }
.route .stage input[name=name] { font-weight: 600; font-size: var(--t3); border-color: transparent; background: var(--paper); }
.route .stage input[name=hint] { border-color: transparent; color: var(--muted); padding-block: 6px; }
.route .stage input:focus { border-color: var(--line-strong, #C9D1DE); background: #fff; }
.route.new .stage input[name=name] { background: var(--saffron-wash); }
details.more-stages { margin-top: 8px; }
details.more-stages > summary { cursor: pointer; color: var(--muted); font-size: var(--t1); padding: 10px 0; }
.route:last-child { border-bottom: 0; }
.route .stage b { font-weight: 600; font-size: var(--t3); }
.route .stage p { color: var(--muted); font-size: var(--t1); margin: 2px 0 0; }
.lesson { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.lesson .q { font-weight: 600; }
.lesson .a { color: var(--ink-2); white-space: pre-line; }
.lesson.off { opacity: .55; }
.files { display: grid; grid-template-columns: 250px 1fr; gap: 18px; }
.flist button { display: flex; width: 100%; justify-content: space-between; border: 0; background: transparent; padding: 9px 12px; border-radius: var(--r-ctl); font-weight: 500; }
.flist button[aria-current="true"] { background: var(--saffron-wash); }
.editor { min-height: 58vh; font-size: 15px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; direction: ltr; text-align: left; font-size: 13px; min-height: 55vh; }
.qr { background: #fff; padding: 12px; border: 1px solid var(--line); border-radius: 14px; display: inline-block; }
.steps { list-style: none; padding: 0; margin: 0 0 18px; display: flex; gap: 8px; }
.steps li { flex: 1; padding: 8px 10px; border-radius: var(--r-ctl); background: var(--paper); color: var(--muted); font-size: var(--t1); font-weight: 500; }
.steps li[aria-current="step"] { background: var(--ink); color: #fff; }
.steps li.done { background: var(--green-wash); color: var(--green); }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice label { border: 1.5px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; display: block; }
.choice label:has(input:checked) { border-color: var(--ink); background: #FAFBFC; }
.choice input { display: none; }
.choice b { display: block; font-size: var(--t3); margin-bottom: 4px; }
.choice span { color: var(--muted); font-size: var(--t1); }
.callout { background: var(--saffron-wash); border-radius: var(--r-ctl); padding: 12px 14px; color: #6B4A12; font-size: var(--t1); }
.callout.ok { background: var(--green-wash); color: #1E5A40; }
.callout.bad { background: var(--red-wash); color: #7E2A1C; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: var(--t1); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details.adv summary { cursor: pointer; color: var(--ink-2); font-weight: 500; padding: 6px 0; }
.sandbox .msgs { min-height: 420px; }
.sandbox .note { align-self: center; font-size: 12.5px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 99px; padding: 3px 12px; text-align: center; }

/* ---------- نوافذ وتنبيهات ---------- */
.modal { position: fixed; inset: 0; background: rgba(28,36,51,.5); display: grid; place-items: center; padding: 16px; z-index: 30; }
.modal .panel { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; }
#toasts { position: fixed; bottom: 22px; inset-inline-start: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 500; animation: rise .2s ease-out; }
.toast.bad { background: var(--red); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- الدخول ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .panel { width: 100%; max-width: 410px; padding: 30px; }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; font-weight: 600; font-size: var(--t3); }
.auth .logo img { width: 34px; height: 34px; }
.auth h1 { font-size: var(--t4); margin-bottom: 6px; }

@media (max-width: 900px) {
  .cols-2, .cols-side, .files, .conv, .choice { grid-template-columns: 1fr; }
  .conv { height: auto; }
  .conv .thread { min-height: 70vh; }
  .route { grid-template-columns: 1fr; }
  .route .arrow { display: none; }
  main { padding: 18px 14px 50px; }
  .bar { padding: 10px 14px; gap: 8px 10px; height: auto; flex-wrap: wrap; }
  .bar .who { display: none; }
  .bar .brand { font-size: var(--t2); white-space: nowrap; }
  .bar button { white-space: nowrap; padding: 4px 10px; font-size: var(--t1); }
  .bar nav { order: 5; width: 100%; overflow-x: auto; }
  .bar nav a { white-space: nowrap; }
  .roster .hide-sm { display: none; }
  .roster, .roster tbody, .roster tr, .roster td { display: block; }
  .roster thead { display: none; }
  .roster tr { padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .roster tr:last-child { border-bottom: 0; }
  .roster td { padding: 0; border: 0; }
  .roster td + td { margin-top: 10px; }
  .roster tbody tr:hover td { background: transparent; }
  .kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .kpis div b { font-size: var(--t4); }
  .panel { overflow-x: auto; }
  .msg { max-width: 88%; }
}

/* نص مختلط عربي/إنجليزي: كل فقرة تاخذ اتجاه أول حرف فيها */
.msg, .citem .last, .feed p, .alert-item p, .summary, .lesson .q, .lesson .a, .callout { unicode-bidi: plaintext; }
