/* =====================================================================
   رسائل — نظام التصميم
   لوحة: صنوبر عميق + ورق بارد، وألوان الحالة هي بطل الواجهة
   ===================================================================== */

:root {
  /* الأساس */
  --ink:        #0D2B25;
  --ink-soft:   #1D4A40;
  --muted:      #5B6B66;
  --faint:      #8A9A95;
  --paper:      #EDF1EF;
  --card:       #FFFFFF;
  --line:       #D7E0DC;
  --line-soft:  #E6EDEA;

  /* الفعل */
  --brand:      #14614F;
  --brand-dark: #0E4B3D;
  --brand-tint: #E4EFEB;

  /* الحالات — هذه هي لغة النظام */
  --st-pending:   #7A8A85;
  --st-queued:    #A87A12;
  --st-sent:      #C08A1E;
  --st-delivered: #1E7A54;
  --st-read:      #1F6FA8;
  --st-failed:    #B3261E;
  --st-skipped:   #97A5A0;

  --st-pending-bg:   #EEF2F1;
  --st-queued-bg:    #FBF2DF;
  --st-sent-bg:      #FBF2DF;
  --st-delivered-bg: #E2F1EA;
  --st-read-bg:      #E4EEF7;
  --st-failed-bg:    #FAE7E5;
  --st-skipped-bg:   #EEF2F1;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(13, 43, 37, .06), 0 8px 24px -16px rgba(13, 43, 37, .28);
  --rail:      248px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  direction: rtl;
}

code, .mono, .sid, .phone {
  font-family: "IBM Plex Mono", ui-monospace, "Courier New", monospace;
  font-size: .86em;
  direction: ltr;
  unicode-bidi: embed;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p  { margin: 0 0 12px; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------- التخطيط ---------------- */

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

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  background: var(--ink);
  color: #CFE0DA;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.rail-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 20px; }
.rail-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  flex: 0 0 34px;
}
.rail-name { color: #fff; font-weight: 600; font-size: 17px; }
.rail-sub  { color: #7FA096; font-size: 11.5px; margin-top: -3px; }

.rail-group { margin-top: 18px; }
.rail-group-title {
  color: #6E8F85; font-size: 11.5px; padding: 0 8px 6px; letter-spacing: .01em;
}

.rail a.nav {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: #CFE0DA; font-size: 14.5px; text-decoration: none;
  transition: background .12s ease;
}
.rail a.nav:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.rail a.nav.active { background: var(--brand); color: #fff; font-weight: 500; }
.rail a.nav svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }
.rail a.nav.active svg { opacity: 1; }

.rail-foot {
  margin-top: 24px; padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 13px;
}
.rail-user { color: #9FBAB2; padding: 0 8px 8px; }
.rail-user b { color: #fff; font-weight: 500; display: block; }

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

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { color: var(--muted); font-size: 13px; }
.topbar .crumb a { color: var(--muted); }

.content { padding: 26px 28px 60px; max-width: 1320px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap;
}
.page-head .lede { color: var(--muted); font-size: 14px; margin-top: 4px; max-width: 62ch; }

/* ---------------- البطاقات ---------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 15px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 13px 18px; border-top: 1px solid var(--line-soft);
  background: #FAFCFB; border-radius: 0 0 var(--radius) var(--radius);
}

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* ---------------- الأرقام الرئيسية ---------------- */

.metric {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.metric .label { color: var(--muted); font-size: 13px; }
.metric .value { font-size: 27px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.metric .foot  { font-size: 12.5px; color: var(--faint); margin-top: 2px; }
.metric.is-delivered .value { color: var(--st-delivered); }
.metric.is-failed .value    { color: var(--st-failed); }
.metric.is-read .value      { color: var(--st-read); }

/* ---------------- شريط التسليم (بطل صفحة الحملة) ---------------- */

.spine { margin: 4px 0 0; }
.spine-bar {
  display: flex; height: 34px; width: 100%;
  border-radius: 8px; overflow: hidden; background: var(--line-soft);
  border: 1px solid var(--line);
}
.spine-bar span {
  display: block; height: 100%;
  transition: width .5s cubic-bezier(.2,.7,.3,1);
}
.spine-bar .seg-read      { background: var(--st-read); }
.spine-bar .seg-delivered { background: var(--st-delivered); }
.spine-bar .seg-sent      { background: var(--st-sent); }
.spine-bar .seg-queued    { background: var(--st-queued); opacity: .55; }
.spine-bar .seg-pending   { background: var(--st-pending); opacity: .3; }
.spine-bar .seg-failed    { background: var(--st-failed); }
.spine-bar .seg-skipped   { background: var(--st-skipped); opacity: .5; }

.spine-key {
  display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 12px;
  font-size: 13px; color: var(--muted);
}
.spine-key i {
  width: 9px; height: 9px; border-radius: 2px; display: inline-block;
  margin-left: 6px; vertical-align: baseline;
}
.spine-key b { color: var(--ink); font-weight: 600; }

/* ---------------- الجداول ---------------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: right; font-weight: 500; color: var(--muted);
  padding: 11px 16px; border-bottom: 1px solid var(--line);
  background: #FAFCFB; white-space: nowrap; font-size: 13px;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #FAFCFB; }
table.data td.num { font-variant-numeric: tabular-nums; }

.row-title { font-weight: 500; }
.row-sub { color: var(--faint); font-size: 12.5px; }

/* شريط لوني على حافة صف المستلم يوضح حالته */
tr[data-st] td:first-child { border-right: 3px solid transparent; }
tr[data-st="delivered"] td:first-child { border-right-color: var(--st-delivered); }
tr[data-st="read"] td:first-child      { border-right-color: var(--st-read); }
tr[data-st="failed"] td:first-child,
tr[data-st="undelivered"] td:first-child { border-right-color: var(--st-failed); }
tr[data-st="sent"] td:first-child,
tr[data-st="queued"] td:first-child    { border-right-color: var(--st-sent); }
tr[data-st="pending"] td:first-child   { border-right-color: var(--st-pending); }

/* ---------------- الشارات ---------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 100px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  background: var(--st-pending-bg); color: var(--st-pending);
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.badge.pending   { background: var(--st-pending-bg);   color: var(--st-pending); }
.badge.queued    { background: var(--st-queued-bg);    color: var(--st-queued); }
.badge.sent      { background: var(--st-sent-bg);      color: var(--st-sent); }
.badge.delivered { background: var(--st-delivered-bg); color: var(--st-delivered); }
.badge.read      { background: var(--st-read-bg);      color: var(--st-read); }
.badge.failed, .badge.undelivered, .badge.invalid { background: var(--st-failed-bg); color: var(--st-failed); }
.badge.skipped, .badge.canceled { background: var(--st-skipped-bg); color: var(--st-skipped); }
.badge.running   { background: var(--brand-tint);      color: var(--brand); }
.badge.scheduled { background: var(--st-read-bg);      color: var(--st-read); }
.badge.completed { background: var(--st-delivered-bg); color: var(--st-delivered); }
.badge.draft, .badge.ready, .badge.paused { background: var(--st-queued-bg); color: var(--st-queued); }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-sm);
  background: var(--brand-tint); color: var(--brand-dark);
  font-size: 12.5px; font-weight: 500;
}
.chip.neutral { background: #EEF2F1; color: var(--muted); }

/* ---------------- الأزرار ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--brand); color: #fff;
  font-family: inherit; font-size: 14.5px; font-weight: 500; cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
  text-decoration: none;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn svg { width: 16px; height: 16px; }
.btn.ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: #F4F8F6; border-color: var(--faint); color: var(--ink); }
.btn.danger { background: var(--st-failed); }
.btn.danger:hover { background: #8F1D17; }
.btn.warn { background: var(--st-queued); }
.btn.warn:hover { background: #8A6210; }
.btn.sm { padding: 6px 11px; font-size: 13.5px; }
.btn.block { width: 100%; }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }

.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--card); color: var(--muted); cursor: pointer;
}
.icon-btn:hover { border-color: var(--faint); color: var(--ink); }
.icon-btn.danger:hover { border-color: var(--st-failed); color: var(--st-failed); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------------- النماذج ---------------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.field .req { color: var(--st-failed); }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=time], input[type=datetime-local], input[type=tel], select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink);
  font-family: inherit; font-size: 14.5px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(20, 97, 79, .12);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.7; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%235B6B66'><path d='M5.5 7.5L10 12l4.5-4.5z'/></svg>");
  background-repeat: no-repeat; background-position: left 10px center; background-size: 18px; padding-left: 34px; }

.check { display: flex; align-items: flex-start; gap: 9px; font-size: 14.5px; }
.check input { margin-top: 4px; accent-color: var(--brand); width: 16px; height: 16px; }

.form-grid { display: grid; gap: 0 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: #FAFCFB; padding: 26px; text-align: center; cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-tint); }
.dropzone .big { font-weight: 500; }
.dropzone .small { color: var(--muted); font-size: 13px; }
.dropzone input[type=file] { display: none; }

/* ---------------- التنبيهات ---------------- */

.alert {
  padding: 12px 15px; border-radius: var(--radius-sm);
  border: 1px solid; margin-bottom: 16px; font-size: 14.5px;
  display: flex; gap: 10px; align-items: flex-start;
}
.alert.success { background: var(--st-delivered-bg); border-color: #BEE0CF; color: #14563B; }
.alert.error   { background: var(--st-failed-bg);    border-color: #F0C4C0; color: #8F1D17; }
.alert.warning { background: var(--st-queued-bg);    border-color: #EDD9A6; color: #7A5610; }
.alert.info    { background: var(--st-read-bg);      border-color: #C3DAEC; color: #1A5480; }

/* ---------------- الحالة الفارغة ---------------- */

.empty { text-align: center; padding: 44px 24px; }
.empty .mark {
  width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 12px;
  background: var(--brand-tint); color: var(--brand);
  display: grid; place-items: center;
}
.empty .mark svg { width: 22px; height: 22px; }
.empty h3 { margin-bottom: 5px; }
.empty p { color: var(--muted); max-width: 44ch; margin: 0 auto 16px; }

/* ---------------- شريط الخطوات ---------------- */

.steps { display: flex; gap: 0; margin-bottom: 22px; border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; background: var(--card); }
.steps .step {
  flex: 1; padding: 12px 16px; font-size: 14px; color: var(--muted);
  border-left: 1px solid var(--line); display: flex; align-items: center; gap: 9px;
}
.steps .step:last-child { border-left: 0; }
.steps .step .n {
  width: 22px; height: 22px; border-radius: 50%; background: var(--line-soft);
  color: var(--muted); display: grid; place-items: center; font-size: 12.5px; font-weight: 600;
}
.steps .step.now { color: var(--ink); font-weight: 500; background: #FAFCFB; }
.steps .step.now .n { background: var(--brand); color: #fff; }
.steps .step.done .n { background: var(--st-delivered); color: #fff; }

/* ---------------- المعاينة ---------------- */

.preview-bubble {
  background: #E7F5D8; border: 1px solid #CDE5B8;
  border-radius: 12px 12px 12px 3px; padding: 12px 14px;
  font-size: 14.5px; line-height: 1.75; white-space: pre-wrap;
  max-width: 46ch;
}
.preview-meta { color: var(--faint); font-size: 12px; margin-top: 6px; }

/* ---------------- شريط الفلاتر ---------------- */

.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
  padding: 14px 18px; border-bottom: 1px solid var(--line-soft);
}
.filters .f { min-width: 150px; }
.filters .f label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 4px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 12px; border-radius: 100px; font-size: 13.5px;
  color: var(--muted); background: transparent; text-decoration: none;
}
.tabs a:hover { background: #EEF2F1; text-decoration: none; }
.tabs a.on { background: var(--ink); color: #fff; }

/* ---------------- ترقيم الصفحات ---------------- */

.pager { display: flex; gap: 5px; padding: 14px 18px; align-items: center; flex-wrap: wrap; }
.pager a, .pager span {
  padding: 5px 11px; border-radius: var(--radius-sm); font-size: 13.5px;
  border: 1px solid var(--line); color: var(--muted); background: var(--card);
}
.pager a:hover { border-color: var(--faint); color: var(--ink); text-decoration: none; }
.pager .on { background: var(--ink); border-color: var(--ink); color: #fff; }
.pager .info { border: 0; background: transparent; margin-inline-start: auto; color: var(--faint); }

/* ---------------- تسجيل الدخول ---------------- */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: var(--ink);
}
.login-card {
  width: 100%; max-width: 390px; background: var(--card);
  border-radius: 14px; padding: 30px 28px; box-shadow: 0 24px 60px -24px rgba(0,0,0,.5);
}
.login-card .mark {
  width: 42px; height: 42px; border-radius: 11px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; margin-bottom: 16px;
}
.login-card h1 { font-size: 21px; margin-bottom: 3px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }

/* ---------------- أدوات ---------------- */

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; }
.hidden { display: none !important; }

.bar-mini { height: 6px; background: var(--line-soft); border-radius: 3px; overflow: hidden; min-width: 90px; }
.bar-mini i { display: block; height: 100%; background: var(--st-delivered); }

/* ---------------- الاستجابة ---------------- */

.rail-toggle { display: none; }

@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-side { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .rail {
    position: fixed; inset-inline-end: 0; top: 0; z-index: 60;
    transform: translateX(100%); transition: transform .2s ease;
  }
  body.rail-open .rail { transform: translateX(0); }
  body.rail-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(13,43,37,.45); z-index: 50;
  }
  .rail-toggle { display: inline-grid; }
  .content { padding: 18px 16px 60px; }
  .topbar { padding: 12px 16px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .steps { flex-direction: column; }
  .steps .step { border-left: 0; border-bottom: 1px solid var(--line); }
  h1 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .rail, .topbar, .btn, .filters, .pager { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; }
}
