/* ══════════════════════════════════════════════
   نظام إدارة رسائل واتساب — التصميم العربي RTL
   لا يوجد Node على الخادم، فالأنماط مكتوبة يدويًا
   ══════════════════════════════════════════════ */

:root {
  --sky-50:  #f0f9ff;
  --sky-100: #e0f2fe;
  --sky-200: #bae6fd;
  --sky-400: #38bdf8;
  --sky-500: #0ea5e9;
  --sky-600: #0284c7;
  --sky-700: #0369a1;

  --bg:      #f1f5f9;
  --card:    #ffffff;
  --txt:     #0f172a;
  --txt-mut: #64748b;
  --bd:      #e2e8f0;

  --ok:   #059669;
  --ok-bg:#d1fae5;
  --warn: #b45309;
  --warn-bg:#fef3c7;
  --err:  #dc2626;
  --err-bg:#fee2e2;

  --sidebar-w: 250px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--sky-700); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─────────── الهيكل ─────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-inline-start: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--bd);
}
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--sky-500);
  color: #fff;
  border-radius: 9px;
  font-weight: 700;
  font-size: 18px;
}
.brand-text { font-weight: 600; font-size: 15px; }

.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--txt-mut);
  font-size: 14.5px;
  margin-bottom: 2px;
  transition: background .12s, color .12s;
}
.nav-link:hover { background: var(--sky-50); color: var(--sky-700); text-decoration: none; }
.nav-link.is-active { background: var(--sky-100); color: var(--sky-700); font-weight: 600; }
.nav-link.is-disabled { opacity: .5; cursor: not-allowed; }
.nav-link.is-disabled:hover { background: transparent; color: var(--txt-mut); }
.nav-ico { width: 20px; text-align: center; font-size: 15px; }

.soon {
  margin-inline-start: auto;
  font-size: 10.5px;
  background: var(--bd);
  color: var(--txt-mut);
  padding: 1px 7px;
  border-radius: 20px;
}

/* كل مجموعة روابط مفصولة بخط رفيع وعنوان صغير */
.nav-group {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--bd);
}

.nav-sep {
  font-size: 11.5px;
  color: var(--txt-mut);
  padding: 6px 12px 4px;
  font-weight: 600;
  letter-spacing: .3px;
  opacity: .85;
}

.sidebar-foot { padding: 14px; border-top: 1px solid var(--bd); }

.conn {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; padding: 8px 10px; border-radius: 8px;
}
.conn .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.conn-ok   { background: var(--ok-bg);   color: var(--ok); }
.conn-ok .dot   { background: var(--ok); }
.conn-warn { background: var(--warn-bg); color: var(--warn); }
.conn-warn .dot { background: var(--warn); }
.conn-err  { background: var(--err-bg);  color: var(--err); }
.conn-err .dot  { background: var(--err); }

/* ─────────── المحتوى ─────────── */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--bd);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 17px; font-weight: 600; margin: 0; }
.topbar-end { margin-inline-start: auto; display: flex; align-items: center; gap: 14px; }

.user { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--sky-100); color: var(--sky-700);
  border-radius: 50%;
  font-weight: 600; font-size: 13.5px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.3; }
.user-meta strong { font-size: 13.5px; font-weight: 600; }
.user-meta small  { font-size: 11.5px; color: var(--txt-mut); }

.icon-btn {
  display: none;
  background: none; border: 1px solid var(--bd);
  border-radius: 8px; padding: 6px 10px;
  cursor: pointer; font-size: 16px;
}

.content { padding: 24px; flex: 1; max-width: 1400px; width: 100%; }

/* ─────────── المكوّنات ─────────── */

.card {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat { position: relative; }
.stat-label { font-size: 13px; color: var(--txt-mut); margin-bottom: 6px; }
.stat-value { font-size: 27px; font-weight: 700; line-height: 1.2; }
.stat.is-pending .stat-value { color: var(--bd); }
.stat-note { font-size: 11.5px; color: var(--txt-mut); margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 9px;
  font: inherit; font-size: 14.5px; font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.btn-primary { background: var(--sky-600); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--sky-700); }
.btn-ghost { background: transparent; border-color: var(--bd); color: var(--txt-mut); }
.btn-ghost:hover { background: var(--bg); }
/* الرابط الذي يلبس هيئة الزر لا يُسطَّر عند المرور، وإلا اختلف شكله عن الأزرار المجاورة */
a.btn:hover { text-decoration: none; }

label { display: block; font-size: 13.5px; font-weight: 500; margin: 14px 0 6px; }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=url], input[type=search], input[type=date],
input[type=datetime-local], input[type=time], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--bd);
  border-radius: 9px;
  font: inherit; font-size: 14.5px;
  background: #fff;
  color: var(--txt);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--sky-400);
  outline-offset: -1px;
  border-color: var(--sky-400);
}
input.has-error { border-color: var(--err); }

/* ─────────── حقول التاريخ والوقت ───────────
   المتصفح يرسم محتواها بنفسه، فبلا هذه القواعد تظهر بخط النظام وارتفاع
   مختلف عن بقية الحقول في الصف نفسه. الاتجاه ltr مقصود: التاريخ يُقرأ
   يوم/شهر/سنة من اليسار حتى داخل صفحة عربية، والمحاذاة تُعيده إلى يمين
   الحقل ليصطفّ مع جيرانه. */
input[type=date], input[type=datetime-local], input[type=time] {
  direction: ltr;
  text-align: end;
  min-height: 46px;
  appearance: none;
  cursor: pointer;
}
input[type=date]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator {
  margin-inline-start: 0;
  margin-inline-end: auto;
  padding: 3px;
  border-radius: 5px;
  opacity: .55;
  cursor: pointer;
  transition: opacity .12s, background .12s;
}
input[type=date]:hover::-webkit-calendar-picker-indicator,
input[type=datetime-local]:hover::-webkit-calendar-picker-indicator,
input[type=time]:hover::-webkit-calendar-picker-indicator {
  opacity: 1;
  background: var(--sky-100);
}
/* الحقل الفارغ يظهر بلون خافت كالعنصر النائب، فلا يبدو ممتلئًا وهو فارغ */
input[type=date]:not(:focus):in-range::-webkit-datetime-edit-year-field,
input[type=date]:not(:focus):in-range::-webkit-datetime-edit-month-field,
input[type=date]:not(:focus):in-range::-webkit-datetime-edit-day-field,
input[type=date]:not(:focus):in-range::-webkit-datetime-edit-text {
  color: var(--txt);
}
input[type=date]:invalid::-webkit-datetime-edit { color: var(--txt-mut); }

.field-error { color: var(--err); font-size: 12.5px; margin-top: 5px; }
.hint { font-size: 12.5px; color: var(--txt-mut); margin-top: 5px; }

.alert {
  padding: 12px 16px;
  border-radius: 9px;
  margin-bottom: 18px;
  font-size: 14px;
  border-inline-start: 4px solid;
}
.alert-ok   { background: var(--ok-bg);   color: #065f46; border-color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: #92400e; border-color: var(--warn); }
.alert-err  { background: var(--err-bg);  color: #991b1b; border-color: var(--err); }

.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--txt-mut);
}
.empty-ico { font-size: 34px; opacity: .35; margin-bottom: 10px; }
.empty h3  { margin: 0 0 6px; font-size: 15.5px; color: var(--txt); font-weight: 600; }
.empty p   { margin: 0; font-size: 13.5px; }

/* ─────────── شاشة الدخول ─────────── */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--sky-50), var(--bg));
}
.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 16px;
  padding: 34px 30px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .07);
}
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { margin: 0 auto 12px; width: 46px; height: 46px; font-size: 23px; }
.auth-head h1 { font-size: 19px; margin: 0 0 4px; font-weight: 600; }
.auth-head p  { font-size: 13.5px; color: var(--txt-mut); margin: 0; }

.checkbox { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 13.5px; }
.checkbox input { width: auto; }
.checkbox label { margin: 0; font-weight: 400; }

/* ─────────── جداول وشارات وأدوات الشاشات الإدارية ─────────── */

.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-bottom: 18px;
}
.page-head .spacer { margin-inline-start: auto; }
.page-head p { margin: 0; font-size: 13.5px; color: var(--txt-mut); flex-basis: 100%; }

.card-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 0 0 14px;
}
.card-head h2, .card-head h3 { margin: 0; font-size: 15.5px; font-weight: 600; }
.card-head .spacer { margin-inline-start: auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.toolbar form { margin: 0; }

.btn-auto   { width: auto; }
.btn-sm     { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: var(--err-bg); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }

/* شبكة الحقول: عمودان على الشاشات الواسعة.
   السقف 980px يمنع تمدُّد الحقل إلى عرض الشاشة كاملًا فيصعب تتبُّع سطره. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 20px;
  max-width: 980px;
}
.form-grid .col-full { grid-column: 1 / -1; }
/* الحقول القصيرة كالأعداد لا تُمنح عرض العمود كله */
.input-narrow { max-width: 200px; }

/* عنوان لمجموعة حقول لا يخص عنصر إدخال واحدًا، فلا يصلح أن يكون <label> */
.field-label { font-size: 13.5px; font-weight: 500; margin: 14px 0 6px; }

/* مجموعة خيارات محاطة: تُغني عن إزاحة علوية بمقدار ثابت لمحاكاة ارتفاع العنوان،
   وتبدأ من حيث تبدأ حقول العمود المجاور لأن عنوانها يسبقها كسائر الحقول. */
.check-group {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bd);
  border-radius: 9px;
}
.check-group .checkbox:first-child { margin-top: 0; }

/* شريط إجراءات أسفل البطاقة، مفصول عن محتواها بخط */
.card-foot {
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--bd);
}
.card-foot form { margin: 0; }
.card-foot .spacer { margin-inline-start: auto; }

/* بطاقات حالة صغيرة: تستعمل عرض الشاشة بدل صفٍّ ضيق من المفاتيح والقيم */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}
.status-item {
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--bd);
  border-radius: 10px;
}
.status-key { font-size: 12px; color: var(--txt-mut); margin-bottom: 5px; }
.status-val { font-size: 14px; line-height: 1.5; }
.status-val .hint { margin-top: 3px; }

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: start; vertical-align: middle; }
.tbl thead th {
  font-size: 12.5px; font-weight: 600; color: var(--txt-mut);
  border-bottom: 1px solid var(--bd); white-space: nowrap;
}
.tbl tbody tr { border-bottom: 1px solid var(--bd); }
.tbl tbody tr:last-child { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--sky-50); }
.tbl .num { white-space: nowrap; }
.tbl .actions { white-space: nowrap; text-align: end; }
.tbl .actions form { display: inline-block; margin: 0 0 0 4px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-ok   { background: var(--ok-bg);   color: #065f46; }
.badge-warn { background: var(--warn-bg); color: #92400e; }
.badge-err  { background: var(--err-bg);  color: #991b1b; }
.badge-info { background: var(--sky-100); color: var(--sky-700); }
.badge-mut  { background: var(--bd);      color: var(--txt-mut); }

/* المعرِّفات والروابط تُقرأ من اليسار دائمًا ولو كانت الصفحة RTL */
.ltr {
  direction: ltr; text-align: left; unicode-bidi: isolate;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}
.id-cell { display: flex; flex-direction: column; gap: 2px; }
.id-cell .id-label { font-size: 11px; color: var(--txt-mut); font-weight: 600; }

/* المفاتيح والقيم في صفوف مفصولة بخطوط: العمود الأول بعرض محكوم حتى لا
   يتباعد المفتاح عن قيمته، والخط الفاصل يمنع اختلاط قيمة بسطر تفسير جارها. */
.kv {
  display: grid;
  grid-template-columns: minmax(140px, 230px) minmax(0, 1fr);
  font-size: 13.5px;
  margin: 0;
}
.kv dt, .kv dd { padding: 10px 0; border-top: 1px solid var(--bd); }
.kv dt { color: var(--txt-mut); padding-inline-end: 16px; }
.kv dd { margin: 0; }
.kv dt:first-child, .kv dt:first-child + dd { border-top: 0; padding-top: 0; }

.copy-row { display: flex; gap: 8px; align-items: stretch; }
.copy-row input { flex: 1; min-width: 0; }

.note-box {
  background: var(--bg); border: 1px solid var(--bd); border-radius: 9px;
  padding: 12px 14px; font-size: 13px; color: var(--txt-mut);
}
.note-box strong { color: var(--txt); }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.tabs a {
  padding: 8px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--bd); color: var(--txt-mut); background: var(--card);
}
.tabs a:hover { text-decoration: none; background: var(--sky-50); }
.tabs a.is-active { background: var(--sky-100); border-color: var(--sky-200); color: var(--sky-700); }

@media (max-width: 700px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dt { padding: 10px 0 0; padding-inline-end: 0; }
  .kv dd { padding-top: 2px; border-top: 0; }
  .kv dt:first-child + dd { padding-top: 2px; }
  .card-foot .spacer { display: none; }
}

/* ─────────── جهات الاتصال ─────────── */

/* شرائح المجموعات والوسوم — اللون يأتي من قاعدة البيانات فيُمرَّر بنمط سطري */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
  background: var(--sky-50); color: var(--sky-700);
  border: 1px solid var(--sky-100);
  white-space: nowrap;
}
.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* شبكة التصفية: تتقلّص إلى عمود واحد على الجوال */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; align-items: end; }
.filters label { margin: 10px 0 6px; }
.filters .filters-actions { display: flex; gap: 8px; align-items: end; padding-bottom: 1px; }

/* قوائم اختيار متعددة بمرتفع محدود بدل select متعدد الذي لا يُستعمل بسهولة */
.check-list {
  max-height: 170px; overflow-y: auto;
  border: 1px solid var(--bd); border-radius: 9px;
  padding: 8px 10px; background: #fff;
}
.check-list .row { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13.5px; }
.check-list input { width: auto; }
.check-list .row label { margin: 0; font-weight: 400; }
.check-list-empty { font-size: 12.5px; color: var(--txt-mut); padding: 4px 0; }

/* شريط الإجراءات الجماعية — يظهر أعلى الجدول ويبقى مرئيًا عند التمرير */
.bulk {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  background: var(--sky-50); border: 1px solid var(--sky-100);
  border-radius: 9px; padding: 10px 12px; margin-bottom: 14px;
  font-size: 13.5px;
}
.bulk select { width: auto; min-width: 150px; padding: 7px 10px; font-size: 13px; }
.bulk .count { font-weight: 600; color: var(--sky-700); }
.bulk .spacer { margin-inline-start: auto; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 16px; font-size: 13.5px; color: var(--txt-mut); }
.pager .spacer { margin-inline-start: auto; }

/* سجل التواصل: خط زمني بسيط بعلامة لكل نوع حدث */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li {
  position: relative; padding: 0 22px 16px 0;
  border-inline-end: 2px solid var(--bd); margin-inline-end: 6px;
}
.tl li:last-child { border-inline-end-color: transparent; padding-bottom: 0; }
.tl li::before {
  content: ''; position: absolute; inset-inline-end: -7px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bd); border: 2px solid var(--card);
}
.tl li.is-in::before      { background: var(--ok); }
.tl li.is-out::before     { background: var(--sky-500); }
.tl li.is-consent::before { background: var(--warn); }
.tl .tl-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.tl .tl-head strong { font-size: 13.5px; font-weight: 600; }
.tl .tl-head time { font-size: 11.5px; color: var(--txt-mut); }
.tl .tl-body { font-size: 13px; color: var(--txt-mut); margin-top: 2px; white-space: pre-wrap; }

/* شريط تقدّم الاستيراد */
.meter { height: 8px; background: var(--bd); border-radius: 20px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--sky-500); }

/* مطابقة أعمدة الاستيراد: حقل النظام مقابل عمود الملف */
.map-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid var(--bd);
}
.map-row:last-child { border-bottom: 0; }
.map-row .map-field { font-size: 13.5px; font-weight: 500; }
.map-row .map-field small { display: block; font-weight: 400; font-size: 11.5px; color: var(--txt-mut); }
.map-row select { padding: 8px 10px; font-size: 13.5px; }
.map-row.is-required .map-field { color: var(--sky-700); }

/* معاينة الملف: جدول ضيق يُقرأ أفقيًا */
.preview-tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
.preview-tbl th, .preview-tbl td { padding: 7px 9px; border: 1px solid var(--bd); text-align: start; }
.preview-tbl th { background: var(--bg); font-weight: 600; color: var(--txt-mut); }
.preview-tbl td { max-width: 190px; overflow: hidden; text-overflow: ellipsis; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; align-items: start; }

.mut { color: var(--txt-mut); }
.nowrap { white-space: nowrap; }
.row-check { width: 30px; }

@media (max-width: 700px) {
  .map-row { grid-template-columns: minmax(0, 1fr); }
}

/* ─────────── صندوق المحادثات ─────────── */

/* الشاشة ثلاثية الأعمدة، وكل عمود يمرَّر داخل نفسه.
   إطار الجوال المرسوم داخل عمود «المحادثة» يأخذ ارتفاع عموده، فطول الشبكة
   هو طوله. زيادةٌ على ارتفاع الشاشة بالربع تقريبًا: تتسع المحادثة لفقاعات
   أكثر بوضوح، والصفحة تُمرَّر قليلًا لا كثيرًا. */
.inbox {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 320px;
  gap: 16px;
  height: calc(125vh - 150px);
  min-height: 860px;
}

.inbox-col {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.inbox-head {
  padding: 11px 14px;
  border-bottom: 1px solid var(--bd);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.inbox-head h2, .inbox-head h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.inbox-head .spacer { margin-inline-start: auto; }

/* min-height:0 شرط لعمل التمرير داخل عنصر grid — بدونه يتمدد العمود */
.inbox-scroll { flex: 1; min-height: 0; overflow-y: auto; }

.inbox-filters { padding: 10px 14px; border-bottom: 1px solid var(--bd); }
.inbox-filters input[type=search], .inbox-filters select {
  padding: 7px 10px; font-size: 13px; border-radius: 8px;
}
.inbox-filters .row { display: flex; gap: 7px; margin-top: 7px; }
.inbox-filters .row > * { flex: 1; min-width: 0; }

.inbox-tabs { display: flex; flex-wrap: wrap; gap: 5px; padding: 9px 14px 0; }
.inbox-tabs a {
  font-size: 12px; padding: 4px 9px; border-radius: 20px;
  background: var(--bg); color: var(--txt-mut); border: 1px solid var(--bd);
}
.inbox-tabs a:hover { text-decoration: none; background: var(--sky-50); }
.inbox-tabs a.is-active { background: var(--sky-100); border-color: var(--sky-200); color: var(--sky-700); }
.inbox-tabs .n { font-weight: 600; }

.conv-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bd);
  color: var(--txt);
}
.conv-item:hover { background: var(--sky-50); text-decoration: none; }
.conv-item.is-active { background: var(--sky-100); }
.conv-item.is-unread .conv-name { font-weight: 700; }

.conv-top { display: flex; align-items: center; gap: 9px; }
.conv-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--sky-100); color: var(--sky-700);
  border-radius: 50%; font-size: 12.5px; font-weight: 600;
}
.conv-name {
  flex: 1; min-width: 0;
  font-size: 13.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-time { font-size: 11px; color: var(--txt-mut); white-space: nowrap; }
.conv-preview {
  font-size: 12.5px; color: var(--txt-mut); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.conv-badge {
  font-size: 10.5px; padding: 1px 7px; border-radius: 20px;
  background: var(--bd); color: var(--txt-mut);
}
.conv-badge.is-unread { background: var(--sky-600); color: #fff; font-weight: 600; }
.conv-badge.is-win-open { background: var(--ok-bg); color: #065f46; }
.conv-badge.is-win-shut { background: var(--bd); color: var(--txt-mut); }
.conv-star { color: var(--warn); font-size: 12px; }

/* ── عمود الرسائل: محادثة حيّة داخل إطار هاتف ──
   الإطار وألوانه وخلفية المحادثة من ملف الأنماط المشترك مع معاينة القوالب
   (‎admin/templates/_preview-styles‎)، فما هنا هو ما تختصّ به المحادثة الحيّة
   وحدها: مسرح الهاتف، والفقاعات الحقيقية، ومربع الإرسال داخل الشاشة.

   ألوان واتساب هنا ثابتة مقصودة ولا تأخذ من متغيّرات النظام، للسبب نفسه
   المشروح في ملف المعاينة: المطلوب ما يراه العميل لا ما تراه لوحتنا. */

.wa-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 14px;
  background: var(--bg);
}

.wa-phone.wa-live { flex: 0 0 auto; width: min(100%, 384px); padding: 10px; border-radius: 34px; }
.wa-live .wa-screen { height: 100%; border-radius: 26px; }

.wa-back { color: #fff; flex: none; display: grid; place-items: center; }
.wa-back:hover { text-decoration: none; opacity: .75; }
.wa-who span.ltr { display: block; text-align: start; }

/* الرسائل أبناء مباشرون لـ wa-chat لأن الاستقصاء يُلحق الجديد بها،
   فأي غلاف بينهما كان سيستقبل الملحق خارجه. */
.wa-live .wa-chat { display: flex; flex-direction: column; gap: 5px; padding: 12px 9px; }
/* الهامش التلقائي على الأول يُلصق محادثةً قصيرة بالأسفل، ويتلاشى عند
   الفيض فلا يُقصّ أعلى المحتوى كما يفعل justify-content */
.wa-live .wa-chat > :first-child { margin-top: auto; }

.msg { max-width: 85%; display: flex; flex-direction: column; }
/* في RTL يبدأ المحور من اليمين: الوارد إلى البداية والصادر إلى النهاية */
.msg.is-in  { align-self: flex-start; }
.msg.is-out { align-self: flex-end; }

.msg-bubble {
  position: relative;
  background: #fff;
  color: #111b21;
  padding: 6px 9px 7px;
  border-radius: 8px;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  font-size: 14.2px;
  line-height: 1.52;
}
/* الذيل: إحداثيات clip-path فيزيائية لا منطقية، فلكل اتجاه مثلثه */
.msg-bubble::before { content: ''; position: absolute; top: 0; width: 8px; height: 13px; background: inherit; }
.msg.is-in  .msg-bubble { border-start-start-radius: 0; }
.msg.is-in  .msg-bubble::before { inset-inline-start: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg.is-out .msg-bubble { background: #d9fdd3; border-start-end-radius: 0; }
.msg.is-out .msg-bubble::before { inset-inline-end: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.msg.is-failed .msg-bubble { background: #ffe1de; }
.msg-bubble.has-media { padding: 4px 4px 7px; }

.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-bubble.has-media .msg-text { padding: 2px 5px 0; }
.msg-plain { color: #667781; font-style: italic; }

/* الوقت والعلامة أسفل الفقاعة إلى جهة النهاية، وبـ ltr ليقرأ 10:32 ✓✓ */
.msg-stamp {
  display: flex; align-items: center; gap: 3px; direction: ltr;
  width: max-content; margin-inline-start: auto; margin-top: 2px;
  font-size: 11px; line-height: 1; color: #667781;
}
.msg-tick { display: inline-flex; color: #667781; }
.msg-tick.is-read { color: #53bdeb; }
.msg-tick.is-failed { color: #c0362c; }

.msg-media { display: block; max-width: 100%; max-height: 260px; border-radius: 6px; }
.msg-doc {
  display: flex; align-items: center; gap: 9px; margin-bottom: 3px;
  background: #f5f6f6; border-radius: 6px; padding: 8px 9px; color: #3b4a54;
}
.msg-doc:hover { text-decoration: none; background: #eceff1; }
.msg-doc-ico {
  width: 30px; height: 36px; flex: none; display: grid; place-items: center;
  background: #fff; border-radius: 4px; color: #d93025;
}
.msg-doc-txt { min-width: 0; font-size: 12.5px; line-height: 1.4; }
.msg-doc-txt b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-doc-txt span { display: block; color: #8696a0; font-size: 11.5px; }

/* أزرار القالب أسفل الفقاعة، بشكل واتساب نفسه وبنفس مظهر معاينة القالب.
   عرضها ملازم للفقاعة لأن align-items يمطّطها، فتُقرأ الرسالة كما تُقرأ في
   هاتف العميل. ليست عناصر تفاعلية: الموظف لا يضغطها، والعميل وحده يفعل. */
.msg-btns { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.msg-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: #fff; border-radius: 8px; padding: 8px 10px;
  color: #027eb5; font-size: 13.5px; font-weight: 500; line-height: 1.35;
  text-align: center; overflow-wrap: anywhere;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
}
.msg-btn svg { flex: none; }
/* الفاشلة لم يرها العميل قط، فأزرارها باهتة لا تُقرأ كخيارات معروضة عليه */
.msg.is-failed .msg-btns { opacity: .55; }

.msg-fail {
  font-size: 11.5px; color: #c0362c; margin-top: 3px;
  background: #fff; border-radius: 6px; padding: 3px 8px;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
}

/* بيانات تشغيلية لا وجود لها في واتساب — النوع والمصدر والمرسِل —
   فمكانها تحت الفقاعة لا داخلها حتى لا تُشوَّه صورة ما يراه العميل */
.msg-meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.msg.is-out .msg-meta { justify-content: flex-end; }
.msg-tag {
  font-size: 10px; padding: 1px 7px; border-radius: 20px;
  background: rgba(255, 255, 255, .74); color: #54656f;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .1);
}

.wa-blank {
  margin: auto; text-align: center; color: #54656f;
  background: #fff; border-radius: 10px; padding: 18px 14px;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
}
.wa-blank h3 { margin: 6px 0 4px; font-size: 14px; }
.wa-blank p { margin: 0; font-size: 12.5px; }
.wa-blank .empty-ico { font-size: 26px; }

/* ── شريط النافذة ومربع الكتابة ── */

.window-bar {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 8px 14px; font-size: 12.5px;
  border-top: 1px solid var(--bd);
}
.window-bar.is-open { background: var(--ok-bg); color: #065f46; }
.window-bar.is-shut { background: var(--warn-bg); color: #92400e; }
.window-bar .spacer { margin-inline-start: auto; }

.composer { border-top: 1px solid var(--bd); padding: 12px 14px; }
.composer textarea { min-height: 68px; resize: vertical; font-size: 14px; }
.composer label { margin: 10px 0 5px; }
.composer-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 9px; }
.composer-row .spacer { margin-inline-start: auto; }
.composer-row select, .composer-row input[type=file] { width: auto; padding: 7px 10px; font-size: 13px; }

.composer-kinds { display: flex; gap: 6px; }
.composer-kinds button {
  font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 5px 12px; border-radius: 20px;
  border: 1px solid var(--bd); background: var(--bg); color: var(--txt-mut);
}
.composer-kinds button.is-active { background: var(--sky-100); border-color: var(--sky-200); color: var(--sky-700); font-weight: 600; }
.composer-kinds button:disabled { opacity: .45; cursor: not-allowed; }

.qr-menu { position: relative; }
.qr-pop {
  position: absolute; inset-block-end: calc(100% + 6px); inset-inline-start: 0;
  width: 280px; max-height: 240px; overflow-y: auto; z-index: 15;
  background: var(--card); border: 1px solid var(--bd);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(15, 23, 42, .14);
  padding: 5px;
}
.qr-pop button {
  display: block; width: 100%; text-align: start;
  font: inherit; font-size: 13px; cursor: pointer;
  background: none; border: 0; border-radius: 7px; padding: 7px 9px; color: var(--txt);
}
.qr-pop button:hover { background: var(--sky-50); }
.qr-pop button small { display: block; color: var(--txt-mut); font-size: 11.5px; }

/* مربع الإرسال داخل شاشة الهاتف: هو شريط الإدخال، فيأخذ لون واتساب وحجمه
   الضيق. السقف على لوحة القالب وحدها لا على المربع كله: القالب كثير
   المتغيّرات هو ما قد يبتلع المحادثة، ووضع overflow على المربع كان
   سيقصّ قائمة الردود السريعة المنبثقة فوق زرها. */
.wa-live .window-bar { flex: none; border-top: 0; padding: 6px 11px; font-size: 11.5px; }
.wa-live .composer { flex: none; border-top: 0; background: #f0f2f5; padding: 9px 10px; }
.wa-live .composer textarea { min-height: 52px; font-size: 13.5px; border-radius: 14px; }
.wa-live .composer label { margin: 8px 0 4px; font-size: 12px; }
.wa-live .composer .hint { font-size: 11px; }
.wa-live .composer [data-pane="template"] { max-height: 32vh; overflow-y: auto; }
.wa-live .composer-kinds { flex-wrap: wrap; }
.wa-live .composer-kinds button { font-size: 11.5px; padding: 4px 10px; }
.wa-live .composer-row { margin-top: 8px; }
.wa-live .qr-pop { width: 100%; max-width: 280px; }

/* ── العمود الثالث ── */

.side-sec { padding: 13px 14px; border-bottom: 1px solid var(--bd); }
.side-sec:last-child { border-bottom: 0; }
.side-sec h4 { margin: 0 0 9px; font-size: 12.5px; font-weight: 600; color: var(--txt-mut); }
.side-sec .kv dt, .side-sec .kv dd { padding: 6px 0; font-size: 12.5px; }
.side-sec form { margin: 0; }
.side-sec .btn { margin-top: 8px; }
.side-sec select, .side-sec textarea, .side-sec input[type=text] { padding: 8px 10px; font-size: 13px; }

.note-item { border-top: 1px solid var(--bd); padding: 8px 0; font-size: 12.5px; }
.note-item:first-child { border-top: 0; padding-top: 0; }
.note-item .who { color: var(--txt-mut); font-size: 11px; display: flex; gap: 6px; }
.note-item .what { white-space: pre-wrap; margin-top: 2px; }

@media (max-width: 1200px) {
  .inbox { grid-template-columns: 280px minmax(0, 1fr); height: calc(125vh - 150px); min-height: 860px; }
  .inbox-col.is-panel { display: none; }
  .inbox.show-panel { grid-template-columns: minmax(0, 1fr) 320px; }
  .inbox.show-panel .inbox-col.is-list { display: none; }
  .inbox.show-panel .inbox-col.is-panel { display: flex; }
}

@media (max-width: 860px) {
  /* عمود واحد مهما كانت الحالة.
     ‎.inbox.show-panel‎ في استعلام 1200px أعلى تخصيصًا من ‎.inbox‎ هنا، فلو
     كُتبت القاعدة بمُحدِّد واحد لبقيت الشبكة عمودين على الجوال: مسار 320px
     ثابت للوحة البيانات، وما تبقّى للمحادثة شريطٌ من عشرات البكسلات. هذا
     كان أصل الضغط، لا الارتفاع وحده. */
  .inbox,
  .inbox.show-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    height: auto;
    min-height: 0;
  }

  .inbox .inbox-col { height: auto; }
  .inbox .inbox-head { padding: 9px 12px; }

  /* الأطوال مثبَّتة بالبكسل أولًا ثم تتمدّد مع الشاشة الطويلة، ولا تنكمش أبدًا.
     svh لا vh ولا dvh: الأول يتجاهل أشرطة متصفح الجوال فيُقصّ الأسفل، والثاني
     يتغيّر مع ظهورها واختفائها فيقفز الطول أثناء التمرير.
     الصناديق أطول من الشاشة عمدًا: الصفحة تُمرَّر، والمحتوى يتنفّس داخلها. */

  /* المحادثات */
  .inbox .inbox-col.is-list {
    height: 820px;
    height: max(820px, calc(100svh - 110px));
  }

  /* المحادثة: إطار الجوال بداخلها يأخذ ارتفاعها، فتتبع قاعدة الشاشات
     الكبيرة نفسها — 860px حدًّا أدنى ثم تزيد مع الشاشة الطويلة */
  .inbox .inbox-col.is-thread,
  .inbox.show-panel .inbox-col.is-thread {
    height: 860px;
    height: max(860px, calc(125svh - 90px));
  }

  /* إطار الهاتف زينة، والجهاز هنا هاتف فعلًا: الحافة والشقّ وشريط الحالة
     المزيّف يأكلون عرضًا وارتفاعًا تحتاجهما المحادثة، فيُطوَون على الجوال.
     max-width يبطل سقف 318px الآتي من أنماط المعاينة المشتركة. */
  .wa-stage { padding: 0; }
  .wa-phone.wa-live {
    width: 100%; max-width: none; padding: 0;
    border-radius: 0; box-shadow: none; background: transparent;
  }
  .wa-live .wa-screen { height: 100%; border-radius: 0; }
  .wa-live .wa-notch, .wa-live .wa-statusbar { display: none; }
  .wa-live .wa-chat { padding: 12px 10px; }
  .wa-live .composer textarea { min-height: 62px; }
  /* سقف أدنى للوحة القالب: مع كثرة متغيّراته كانت تبتلع ما بقي للرسائل */
  .wa-live .composer [data-pane="template"] { max-height: 26vh; }

  /* بيانات المحادثة: طول أدنى مضمون لا سقف، فهي تُقرأ بتمرير الصفحة لا
     بتمرير صندوق قصير داخلها — وإن طال محتواها زادت معه بلا قصّ. */
  .inbox .inbox-col.is-panel {
    height: auto;
    min-height: 780px;
    min-height: max(780px, calc(100svh - 110px));
  }
  .inbox .inbox-col.is-panel .inbox-scroll { overflow: visible; }
  .inbox .inbox-col.is-panel .side-sec { padding: 16px 14px; }
}

/* العمود الفارغ («اختر محادثة») لا يستحق هذا الطول: سطرٌ واحد يكفيه */
@media (max-width: 860px) {
  .inbox:not(.show-panel) .inbox-col.is-thread { height: auto; }
}

/* ─────────── لوحة القالب في نموذج الحملة ───────────
   كل ما يتوقّف على القالب المختار: ما يطلبه القالب من المستخدم في عمود،
   والرسالة كما تصل هاتف العميل في العمود المقابل. */

.is-hidden { display: none !important; }

.tpl-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: start;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--bd);
}
.tpl-panel-fields { min-width: 0; }
.tpl-panel-preview { width: 318px; flex: none; }
.tpl-panel-preview-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
  font-size: 13.5px;
}
.tpl-panel-preview .wa-phone { margin: 0; }

.tpl-panel-empty {
  margin-top: 18px; padding: 30px 18px;
  border: 1px dashed var(--bd); border-radius: var(--radius);
  background: var(--bg); text-align: center; color: var(--txt-mut);
}
.tpl-panel-empty-ico { font-size: 30px; opacity: .4; margin-bottom: 8px; }
.tpl-panel-empty h4 { margin: 0 0 6px; font-size: 15px; color: var(--txt); font-weight: 600; }
.tpl-panel-empty p  { margin: 0 auto; font-size: 13.5px; max-width: 46ch; }

/* ما يطلبه القالب: صندوق واحد لكل مطلب، فيراه المستخدم قائمةً لا نصًّا مبعثرًا */
.tpl-need {
  border: 1px solid var(--bd); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; background: var(--card);
}
.tpl-need.is-quiet { background: var(--bg); }
.tpl-need:last-child { margin-bottom: 0; }
.tpl-need-head {
  display: flex; align-items: center; gap: 9px;
  flex-wrap: wrap; margin-bottom: 8px; font-size: 14px;
}

/* صفّ المتغيّر: الاختيار بين حقل جهة الاتصال ونصّ ثابت، وحقل كلٍّ تحته */
.var-row {
  padding: 12px 0;
  border-top: 1px solid var(--bd);
}
.var-row:first-of-type { border-top: 0; padding-top: 4px; }
.var-row-head {
  display: flex; align-items: center; gap: 9px;
  flex-wrap: wrap; margin-bottom: 8px;
}
.var-modes { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 9px; }
.var-mode {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 0; padding: 7px 12px;
  border: 1px solid var(--bd); border-radius: 9px;
  background: var(--card); cursor: pointer;
  font-size: 13px; font-weight: 400;
  transition: border-color .12s, background .12s;
}
.var-mode:hover { border-color: var(--sky-400); }
.var-mode input { width: auto; margin: 0; cursor: pointer; }
.var-mode:has(input:checked) {
  border-color: var(--sky-500);
  background: var(--sky-50);
  color: var(--sky-700);
  font-weight: 600;
}

/* مفتاح رمز QR داخل الصورة: يتبع صندوق الرفع فيُقرأ امتدادًا له لا حقلًا منفصلًا */
.qr-toggle {
  display: flex; align-items: flex-start; gap: 9px;
  margin: 10px 0 0; padding: 11px 13px;
  border: 1px solid var(--bd); border-radius: 10px;
  background: var(--bg); cursor: pointer;
  font-size: 13px; font-weight: 400;
  transition: border-color .12s, background .12s;
}
.qr-toggle:hover { border-color: var(--sky-400); }
.qr-toggle input[type="checkbox"] { width: auto; margin: 2px 0 0; flex: none; cursor: pointer; }
.qr-toggle:has(input:checked) { border-color: var(--sky-500); background: var(--sky-50); }
.qr-toggle .hint { font-weight: 400; }

/* حقل الرفع: يستضيف نظامنا الملف وينشر رابطه، فلا يُطلب من المستخدم استضافته */
.up-drop {
  display: flex; align-items: center; gap: 13px;
  padding: 16px; margin: 0;
  border: 1.5px dashed var(--bd); border-radius: 10px;
  background: var(--bg); cursor: pointer;
  font-weight: 400;
  transition: border-color .12s, background .12s;
}
.up-drop:hover, .up-drop.is-over { border-color: var(--sky-400); background: var(--sky-50); }
.up-ico { flex: none; color: var(--sky-600); display: grid; place-items: center; }
.up-txt { min-width: 0; font-size: 13px; color: var(--txt-mut); line-height: 1.6; }
.up-txt b { display: block; font-size: 13.5px; color: var(--txt); font-weight: 600; }

.up-done {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border: 1px solid var(--bd); border-radius: 10px; background: var(--card);
}
.up-done img {
  width: 62px; height: 62px; flex: none;
  object-fit: cover; border-radius: 8px; background: var(--bg);
}
.up-done-txt { min-width: 0; flex: 1; font-size: 13px; }
.up-done-txt b { display: block; color: var(--ok); font-size: 13.5px; }
.up-done-txt a {
  display: block; font-size: 11.5px; color: var(--txt-mut);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.up-busy { margin-top: 9px; font-size: 13px; color: var(--sky-700); }

/* بلوك قالب الردّ: إعداد القالب الذي يُرسل عند ضغط الزرّ، لهذه الحملة وحدها.
   مُزاح ومحدَّد بخطّ جانبيّ ليُقرأ تابعًا للزرّ فوقه لا قسمًا مستقلًّا. */
.reply-block {
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--bd);
  border-inline-start: 3px solid var(--sky-700);
  border-radius: var(--radius);
  background: var(--bg);
}
.reply-block-head {
  display: flex; align-items: center; gap: 9px;
  flex-wrap: wrap; margin-bottom: 6px; font-size: 14px;
}
.reply-block-head a { text-decoration: none; }
.reply-block-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
}
.reply-block-fields { min-width: 0; }
.reply-block-preview { width: 280px; flex: none; }
.reply-block-preview .wa-phone { margin: 0; transform: scale(.94); transform-origin: top center; }

@media (max-width: 1100px) {
  .tpl-panel { grid-template-columns: minmax(0, 1fr); }
  .tpl-panel-preview { width: 100%; max-width: 318px; margin-inline: auto; }
  .reply-block-body { grid-template-columns: minmax(0, 1fr); }
  .reply-block-preview { width: 100%; max-width: 300px; margin-inline: auto; }
}

/* ─────────── الجوال ─────────── */

@media (max-width: 860px) {
  .icon-btn { display: block; }
  .sidebar {
    position: fixed;
    inset-inline-end: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s;
    box-shadow: -4px 0 20px rgba(15, 23, 42, .12);
  }
  html[dir=rtl] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0) !important; }
  .content { padding: 16px; }
  .user-meta { display: none; }
}

/* ═══════════════════════════════════════════════════════
   الحملات والتقارير — المرحلة السابعة
   ═══════════════════════════════════════════════════════ */

/* شريط تقدّم الحملة */
.progress {
  height: 10px;
  border-radius: 20px;
  background: var(--bd);
  overflow: hidden;
  display: flex;
}
.progress span { display: block; height: 100%; }
.progress .is-sent    { background: var(--ok); }
.progress .is-failed  { background: var(--err); }
.progress .is-skipped { background: var(--warn); }
.progress-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--txt-mut);
}
.progress-legend b { color: var(--txt); font-weight: 600; }
.progress-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-inline-end: 5px;
}

/* حالة المزامنة فوق كل تقرير */
.freshness {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  align-items: center;
  border: 1px solid var(--sky-200);
  background: var(--sky-50);
  color: var(--sky-700);
  border-radius: var(--radius);
  padding: 11px 15px;
  margin-bottom: 16px;
  font-size: 13px;
}
.freshness.is-stale {
  border-color: #fcd34d;
  background: var(--warn-bg);
  color: var(--warn);
}
.freshness b { font-weight: 600; }

/* رسم بياني شريطي بلا جافاسكربت */
.chart {
  display: grid;
  gap: 7px;
  margin-top: 4px;
}
.chart-row {
  display: grid;
  grid-template-columns: minmax(90px, 170px) minmax(0, 1fr) 76px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.chart-row .chart-label {
  color: var(--txt-mut);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-track {
  background: var(--bd);
  border-radius: 20px;
  height: 12px;
  overflow: hidden;
}
.chart-bar {
  display: block;
  height: 100%;
  background: var(--sky-500);
  border-radius: 20px;
  min-width: 2px;
}
.chart-row .chart-value { text-align: end; font-variant-numeric: tabular-nums; }

/* بطاقات مؤشرات التقرير */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--txt-mut); }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi-note { font-size: 12px; color: var(--txt-mut); margin-top: 3px; }
.kpi-delta { font-size: 12.5px; margin-top: 4px; }
.kpi-delta.is-up { color: var(--ok); }
.kpi-delta.is-down { color: var(--err); }

/* قائمة التقارير */
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}
.report-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
  color: inherit;
}
.report-card:hover { border-color: var(--sky-400); text-decoration: none; }
.report-card strong { display: block; font-size: 14.5px; margin-bottom: 5px; }
.report-card span { font-size: 12.5px; color: var(--txt-mut); line-height: 1.75; }

/* خطوات معالج الحملة */
.steps {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding: 0;
  list-style: none;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}
.steps li {
  border: 1px solid var(--bd);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  background: var(--card);
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.steps li.is-done { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); }
.steps li.is-blocked { border-color: #fcd34d; background: var(--warn-bg); color: var(--warn); }
.steps .step-num {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 18px;
}

/* ── جرس الإشعارات ──
   مبني على <details> لا على جافاسكربت: الفتح والإغلاق سلوك أصلي في
   المتصفح، ويعمل بلوحة المفاتيح وقارئ الشاشة بلا كود منا. */
.bell { position: relative; }
.bell > summary { list-style: none; cursor: pointer; position: relative; }
.bell > summary::-webkit-details-marker { display: none; }

.bell-count {
  position: absolute;
  inset-block-start: -4px;
  inset-inline-end: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--err);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bell-panel {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  width: min(360px, calc(100vw - 32px));
  max-height: 70vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgb(15 23 42 / 14%);
  z-index: 40;
}

.bell-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-block-end: 1px solid var(--bd);
  font-size: 13px;
}
.bell-head a { font-size: 12.5px; }

.bell-item {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 10px 12px;
  border-block-end: 1px solid var(--bd);
  color: inherit;
  text-decoration: none;
}
.bell-item:last-child { border-block-end: 0; }
.bell-item:hover { background: var(--bg); }
.bell-item.is-unread { background: var(--sky-100); }
.bell-item.is-unread:hover { filter: brightness(0.98); }

.bell-item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bell-item-body strong { font-size: 13px; }
.bell-item-body small { font-size: 12px; color: var(--txt-mut); line-height: 1.5; }

.bell-empty { padding: 22px 12px; text-align: center; color: var(--txt-mut); font-size: 13px; }

/* ─────────── النافذة المنبثقة ───────────
   نافذة واحدة تُعاد تعبئتها بجافاسكربت بدل نافذةٍ لكل صف: عشرون ردًّا
   تعني عشرين نموذجًا مكرَّرًا في الصفحة، وكلها معرِّفات حقول متشابهة.

   العنصر مثبَّت على الشاشة ويُمرَّر داخل نفسه، فالنافذة الطويلة على شاشة
   قصيرة تُمرَّر ولا تُقصّ. */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
  overflow-y: auto;
  padding: 24px 16px;
}
.modal.is-open { display: block; }

/* الغطاء عنصر مستقل لا خلفيةً على .modal، ليُلتقط النقر عليه وحده
   فلا يُغلق النقر داخل البطاقة النافذةَ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .48);
}

.modal-card {
  position: relative;
  width: min(100%, 700px);
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .24);
  overflow: hidden;
}

@keyframes modal-rise {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
.modal.is-open .modal-card { animation: modal-rise .16s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .modal.is-open .modal-card { animation: none; }
}

/* تثبيت الجسم يمنع تمرير الصفحة خلف النافذة المفتوحة */
body.modal-open { overflow: hidden; }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--bd);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head .spacer { margin-inline-start: auto; }
.modal-head .hint { margin: 2px 0 0; }

.modal-body { padding: 2px 20px 20px; }

.modal-foot {
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--bd);
  background: var(--bg);
}
.modal-foot .spacer { margin-inline-start: auto; }

.modal-close {
  background: transparent; border: 0;
  color: var(--txt-mut);
  font-size: 21px; line-height: 1;
  padding: 3px 9px; border-radius: 8px;
  cursor: pointer;
}
.modal-close:hover { background: var(--bg); color: var(--txt); }

/* شرائح المتغيرات: نقرها يدرج الرمز في موضع المؤشر داخل نص الرد */
.token-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.token-chip {
  direction: ltr; unicode-bidi: isolate;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--sky-50);
  color: var(--sky-700);
  border: 1px solid var(--sky-100);
  cursor: pointer;
}
.token-chip:hover { background: var(--sky-100); }

/* عدّاد الأحرف تحت مربع النص */
.count-hint { display: flex; gap: 6px; }
.count-hint .spacer { margin-inline-start: auto; }

/* ─────────── إضافات الجداول ─────────── */

/* الاختصار والمعرِّفات القصيرة داخل الجدول */
.code-pill {
  display: inline-block;
  direction: ltr; unicode-bidi: isolate;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; font-weight: 600;
  background: var(--bg);
  border: 1px solid var(--bd);
  border-radius: 7px;
  padding: 2px 8px;
}

/* القصّ يحتاج عنصرًا كتليًّا داخل الخلية: max-width على td وحدها
   لا تلتزم به المتصفحات مع table-layout التلقائي */
.trunc {
  display: block;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-title { display: flex; flex-direction: column; gap: 1px; }
.cell-title strong { font-size: 13.5px; font-weight: 600; }
.cell-title small { font-size: 11.5px; color: var(--txt-mut); }

/* أزرار الصف في صفٍّ واحد: القاعدة أخصّ من ‎.tbl .actions form‎ فتلغي هامشها */
.row-actions { display: inline-flex; gap: 6px; align-items: center; }
.tbl .actions .row-actions form { display: inline-block; margin: 0; }

/* صف «لا نتائج» الذي يظهره البحث الفوري حين لا يطابق شيء */
.tbl .no-match td {
  text-align: center;
  color: var(--txt-mut);
  font-size: 13.5px;
  padding: 26px 12px;
}

/* شريط بحث وتصفية فوق الجدول — حقول مضغوطة لا تأخذ عرض البطاقة */
.tbl-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tbl-filter input[type=search],
.tbl-filter select {
  width: auto;
  padding: 7px 11px;
  font-size: 13px;
  border-radius: 8px;
}
.tbl-filter input[type=search] { min-width: 220px; }

/* بطاقة قابلة للطيّ: المثلث يشير يسارًا في RTL وينقلب لأسفل عند الفتح */
.disclose summary {
  display: flex; align-items: center; gap: 8px;
  font-size: 14.5px; font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.disclose summary::-webkit-details-marker { display: none; }
.disclose summary::before {
  content: '◂';
  color: var(--txt-mut);
  transition: transform .12s;
}
.disclose[open] summary::before { transform: rotate(-90deg); }
.disclose[open] summary { margin-bottom: 12px; }

/* صفحة الطباعة — تخرج PDF من المتصفح */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .shell, .main { display: block; }
  .content { padding: 0; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
  a[href]::after { content: ''; }
}

/* ──────────────────────────────────────────────────────────────
   سجل الإرسال — الخط الزمني لحالة الرسالة وكتل النداءات الخام
   ────────────────────────────────────────────────────────────── */

/* خط رأسي واحد تتعلّق به النقاط، مزاح للبداية ليعمل في RTL وLTR معًا */
.tl { list-style: none; margin: 0; padding: 0; position: relative; }
.tl::before {
  content: '';
  position: absolute;
  inset-block: 6px;
  inset-inline-start: 6px;
  width: 2px;
  background: var(--bd);
}
.tl-item { position: relative; padding-inline-start: 24px; padding-block: 9px; }
.tl-dot {
  position: absolute;
  inset-inline-start: 0;
  top: 14px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--bd);
}
.tl-dot.is-ok   { border-color: var(--ok); }
.tl-dot.is-err  { border-color: var(--err); }
.tl-dot.is-warn { border-color: var(--warn); }
.tl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13.5px; }
.tl-time { font-size: 11.5px; color: var(--txt-mut); margin-top: 2px; }
.tl-note { font-size: 12.5px; color: var(--txt-mut); margin-top: 4px; line-height: 1.6; }

/* الطلب والرد كما هما — التفاف إجباري لأن الرد سطر واحد طويل عادةً */
.raw {
  margin: 0;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--bd);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.65;
  max-height: 340px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.raw-label { font-size: 12px; color: var(--txt-mut); margin: 0 0 5px; }
.raw + .raw-label { margin-top: 12px; }
