/* ==========================================================================
   مديد — Components (Phase 1)
   - RTL أولًا: كل المسافات والاتجاهات بخصائص منطقية (inline-start/end)
     ليعمل نفس الكود مع dir="ltr" مستقبلًا بلا تعديل.
   - التسمية: .c-{component}  /  .c-{component}--{variant}  /  .is-{state}
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
/* hidden يجب أن يتغلب دائمًا على display الخاص بالمكونات */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--text-body);
  line-height: var(--lh-body);
  font-weight: var(--font-regular);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* الأرقام: أرقام لاتينية (0-9) بعرض ثابت لتسهيل قراءة الهوية والجوال والأوقات */
.num, .c-table td.num, .c-kpi__value { font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- Typography ---------- */
.t-h1 { font-size: var(--text-h1); line-height: var(--lh-h1); font-weight: var(--font-bold); margin: 0; }
.t-h2 { font-size: var(--text-h2); line-height: var(--lh-h2); font-weight: var(--font-bold); margin: 0; }
.t-h3 { font-size: var(--text-h3); line-height: var(--lh-h3); font-weight: var(--font-semibold); margin: 0; }
.t-h4 { font-size: var(--text-h4); line-height: var(--lh-h4); font-weight: var(--font-semibold); margin: 0; }
.t-body { font-size: var(--text-body); line-height: var(--lh-body); }
.t-small { font-size: var(--text-small); line-height: var(--lh-small); }
.t-caption { font-size: var(--text-caption); line-height: var(--lh-caption); color: var(--color-text-muted); }
.t-table { font-size: var(--text-table); line-height: var(--lh-table); }
.t-muted { color: var(--color-text-muted); }

@media (max-width: 639px) {
  :root {
    --text-h1: 1.625rem; --lh-h1: 2.25rem;
    --text-h2: 1.375rem; --lh-h2: 2rem;
    --text-h3: 1.1875rem; --lh-h3: 1.75rem;
  }
}

/* ---------- Icon ---------- */
.c-icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.c-icon--sm { width: 16px; height: 16px; }
.c-icon--lg { width: 24px; height: 24px; }
/* أيقونات الاتجاه تنعكس في RTL */
/* الأيقونات الاتجاهية مرسومة للعربية (RTL، اللغة الأساسية): chevron-left = «التالي/فتح/فاصل المسار»، chevron-right = «رجوع/السابق».
   تنعكس في LTR فقط. :dir() يأخذ أقرب اتجاه، فتعمل مناطق LTR داخل صفحة RTL والعكس (المرحلة 38). */
.c-icon--directional:dir(ltr) { transform: scaleX(-1); }

/* ==========================================================================
   Button
   ========================================================================== */
.c-btn {
  --btn-bg: var(--color-primary);
  --btn-fg: var(--color-text-inverse);
  --btn-border: transparent;
  --btn-bg-hover: var(--color-primary-dark);
  --btn-bg-active: var(--color-primary-darker);
  --btn-ring: var(--focus-ring);

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-md);
  padding-inline: var(--space-5);
  font: inherit;
  font-size: var(--text-body);
  font-weight: var(--font-semibold);
  line-height: 1;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              transform var(--duration-fast) var(--ease-out);
}
.c-btn:hover, .c-btn.is-hover { background: var(--btn-bg-hover); }
.c-btn:active, .c-btn.is-active { background: var(--btn-bg-active); transform: translateY(1px); }
.c-btn:focus-visible, .c-btn.is-focus { outline: none; box-shadow: var(--btn-ring); }

.c-btn--secondary {
  --btn-bg: var(--color-secondary-50);
  --btn-fg: var(--color-secondary-text);
  --btn-border: var(--color-secondary-100);
  --btn-bg-hover: var(--color-secondary-100);
  --btn-bg-active: #B3E0D9;
}
.c-btn--outline {
  --btn-bg: var(--color-surface);
  --btn-fg: var(--color-primary);
  --btn-border: var(--color-primary-200);
  --btn-bg-hover: var(--color-primary-50);
  --btn-bg-active: var(--color-primary-100);
}
.c-btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--color-text);
  --btn-bg-hover: var(--color-neutral-50);
  --btn-bg-active: var(--color-neutral-100);
}
.c-btn--danger {
  --btn-bg: var(--color-danger);
  --btn-bg-hover: var(--color-danger-dark);
  --btn-bg-active: #823030;
  --btn-ring: var(--focus-ring-danger);
}
.c-btn--success {
  --btn-bg: var(--color-success-solid);
  --btn-bg-hover: #156A45;
  --btn-bg-active: #115A3A;
  --btn-ring: var(--focus-ring-success);
}

.c-btn--sm { min-height: var(--control-sm); padding-inline: var(--space-3); font-size: var(--text-small); border-radius: var(--radius-sm); }
.c-btn--lg { min-height: var(--control-lg); padding-inline: var(--space-6); font-size: 1.0625rem; }
.c-btn--block { display: flex; width: 100%; }
.c-btn--icon { padding-inline: 0; width: var(--control-md); }
.c-btn--icon.c-btn--sm { width: var(--control-sm); }

.c-btn:disabled, .c-btn.is-disabled {
  cursor: not-allowed;
  transform: none;
  color: var(--color-text-disabled);
  background: var(--color-neutral-50);
  border-color: var(--color-neutral-100);
  box-shadow: none;
}
.c-btn--ghost:disabled, .c-btn--ghost.is-disabled { background: transparent; border-color: transparent; }

.c-btn.is-loading { cursor: progress; pointer-events: none; }
.c-btn.is-loading .c-btn__label { opacity: 0.85; }
.c-spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: c-spin 700ms linear infinite;
}
.c-spinner--lg { width: 32px; height: 32px; border-width: 3px; color: var(--color-primary); }
@keyframes c-spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Form field
   ========================================================================== */
.c-field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.c-field__label { font-size: var(--text-small); font-weight: var(--font-semibold); color: var(--color-text); }
.c-field__req { color: var(--color-danger); margin-inline-start: 2px; }
.c-field__hint { font-size: var(--text-caption); line-height: var(--lh-caption); color: var(--color-text-muted); display: flex; align-items: center; gap: var(--space-1); }
.c-field.is-error .c-field__hint { color: var(--color-danger-text); }
.c-field.is-success .c-field__hint { color: var(--color-success-text); }

.c-input {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-md);
  padding-inline: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.c-input:hover { border-color: #9DB3AD; }
.c-input:focus-within, .c-input.is-focus { border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.c-field.is-error .c-input { border-color: var(--color-danger); }
.c-field.is-error .c-input:focus-within { box-shadow: var(--focus-ring-danger); }
.c-field.is-success .c-input { border-color: var(--color-success); }
.c-field.is-disabled .c-input { background: var(--color-neutral-50); border-color: var(--color-neutral-100); cursor: not-allowed; }
.c-field.is-disabled .c-field__label { color: var(--color-text-muted); }

.c-input__control {
  flex: 1;
  min-width: 0;
  height: calc(var(--control-md) - 2px);
  padding: 0;
  font: inherit;
  font-size: var(--text-body);
  color: var(--color-text);
  background: transparent;
  border: 0;
  outline: none;
}
.c-input__control::placeholder { color: var(--color-text-disabled); }
.c-input__control:disabled { color: var(--color-text-disabled); cursor: not-allowed; }
.c-input__control[type="number"] { -moz-appearance: textfield; }
.c-input__control::-webkit-outer-spin-button,
.c-input__control::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
/* الأرقام والجوال تُكتب LTR داخل واجهة RTL */
/* حقل الجوال كاملًا LTR: البادئة +966 قبل الرقم كما يُقرأ */
.c-input--phone { direction: ltr; }
.c-input--phone .c-input__control { text-align: left; } /* i18n-ok: رقم الجوال LTR دائمًا */
.c-input__control--ltr { direction: ltr; text-align: end; }

.c-input__icon { color: var(--color-text-muted); display: inline-flex; }
.c-field.is-error .c-input__state { color: var(--color-danger); }
.c-field.is-success .c-input__state { color: var(--color-success); }
.c-input__affix {
  display: inline-flex; align-items: center;
  padding-inline-end: var(--space-3);
  margin-block: var(--space-2);
  border-inline-end: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-small);
  direction: ltr;
}
.c-input__toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; margin-inline-end: calc(var(--space-1) * -1);
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--color-text-muted); cursor: pointer;
}
.c-input__toggle:hover { background: var(--color-neutral-50); color: var(--color-text); }
.c-input__toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Select (native) */
.c-input--select .c-input__control { appearance: none; -webkit-appearance: none; cursor: pointer; padding-inline-end: var(--space-6); }
.c-input--select::after {
  content: "";
  position: absolute; inset-inline-end: var(--space-3); top: 50%;
  width: 8px; height: 8px; margin-top: -6px;
  border-inline-start: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(-45deg);
  pointer-events: none;
}

/* Textarea */
.c-input--textarea { align-items: stretch; padding-block: var(--space-2); }
.c-input--textarea .c-input__control { height: auto; min-height: 104px; resize: vertical; line-height: var(--lh-body); }
.c-field__counter { margin-inline-start: auto; font-variant-numeric: tabular-nums; }

/* Date / time — نحافظ على المنتقي الأصلي للجوال، مع أيقونة موحدة */
.c-input__control[type="date"], .c-input__control[type="time"], .c-input__control[type="datetime-local"] { direction: ltr; text-align: end; }
.c-input__control::-webkit-calendar-picker-indicator { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; }

/* Multi-select */
.c-multiselect { position: relative; }
.c-multiselect .c-input { flex-wrap: wrap; padding-block: 5px; cursor: text; }
.c-multiselect .c-input__control { min-width: 80px; height: 32px; }
.c-tag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 30px; padding-inline: var(--space-3) var(--space-1);
  font-size: var(--text-small); font-weight: var(--font-semibold);
  color: var(--color-primary);
  background: var(--color-primary-50);
  border-radius: var(--radius-sm);
}
.c-tag__remove {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; padding: 0;
  color: inherit; background: none; border: 0; border-radius: 4px; cursor: pointer;
}
.c-tag__remove:hover { background: var(--color-primary-100); }
.c-tag__remove:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Checkbox */
.c-check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-body); }
.c-check input { appearance: none; -webkit-appearance: none; margin: 0; width: 20px; height: 20px; border: 1.5px solid var(--color-border-strong); border-radius: 5px; background: var(--color-surface); display: grid; place-content: center; cursor: pointer; }
.c-check input::after { content: ""; width: 10px; height: 6px; border-left: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; } /* i18n-ok: علامة ✓ متماثلة */
.c-check input:checked { background: var(--color-primary); border-color: var(--color-primary); }
.c-check input:checked::after { opacity: 1; }
.c-check input:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* ==========================================================================
   Card
   ========================================================================== */
.c-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.c-card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.c-card__body { padding: var(--space-5); }
.c-card__footer { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--color-border); background: var(--color-surface-muted); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.c-card--interactive { cursor: pointer; transition: border-color var(--duration-fast), box-shadow var(--duration-fast); }
.c-card--interactive:hover { border-color: var(--color-primary-200); box-shadow: var(--shadow-sm); }
.c-card--interactive:focus-visible { outline: none; box-shadow: var(--focus-ring); }
/* Accent strip on the start edge for status-aware cards */
.c-card--accent { border-inline-start: 4px solid var(--card-accent, var(--color-primary)); }

/* ==========================================================================
   KPI card
   ========================================================================== */
.c-kpi { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); }
.c-kpi__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.c-kpi__label { font-size: var(--text-small); color: var(--color-text-muted); font-weight: var(--font-semibold); }
.c-kpi__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--kpi-tint, var(--color-primary-50)); color: var(--kpi-color, var(--color-primary)); }
.c-kpi__value { font-size: var(--text-kpi); line-height: var(--lh-kpi); font-weight: var(--font-bold); color: var(--color-text); }
.c-kpi__unit { font-size: var(--text-small); font-weight: var(--font-semibold); color: var(--color-text-muted); margin-inline-start: var(--space-1); }
.c-kpi__meta { font-size: var(--text-caption); line-height: var(--lh-caption); color: var(--color-text-muted); }
.c-kpi__bar { height: 6px; border-radius: var(--radius-pill); background: var(--color-neutral-50); overflow: hidden; }
.c-kpi__bar > span { display: block; height: 100%; background: var(--kpi-color, var(--color-primary)); border-radius: inherit; }

/* ==========================================================================
   Badge / Status chip
   ========================================================================== */
.c-badge {
  --badge-bg: var(--color-neutral-50);
  --badge-fg: var(--color-neutral-text);
  --badge-dot: var(--color-text-muted);
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding-inline: 10px;
  font-size: var(--text-small); font-weight: var(--font-semibold); line-height: 1;
  color: var(--badge-fg); background: var(--badge-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.c-badge__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--badge-dot); flex: none; }
.c-badge .c-icon { width: 14px; height: 14px; stroke-width: 2.2; }
.c-badge--sm { height: 22px; padding-inline: 8px; font-size: var(--text-caption); }
.c-badge--count { min-width: 20px; height: 20px; padding-inline: 6px; justify-content: center; font-size: 11px; font-weight: var(--font-bold); background: var(--color-critical); color: #fff; }

/* Tones */
.c-badge--neutral  { --badge-bg: var(--color-neutral-50);   --badge-fg: var(--color-neutral-text);   --badge-dot: #8A9B97; }
.c-badge--primary  { --badge-bg: var(--color-primary-50);   --badge-fg: var(--color-primary);         --badge-dot: var(--color-primary); }
.c-badge--secondary{ --badge-bg: var(--color-secondary-50); --badge-fg: var(--color-secondary-text);  --badge-dot: var(--color-secondary); }
.c-badge--teal     { --badge-bg: var(--color-teal-50);      --badge-fg: var(--color-teal-text);       --badge-dot: var(--color-teal); }
.c-badge--success  { --badge-bg: var(--color-success-50);   --badge-fg: var(--color-success-text);    --badge-dot: var(--color-success); }
.c-badge--warning  { --badge-bg: var(--color-warning-50);   --badge-fg: var(--color-warning-text);    --badge-dot: var(--color-warning); }
.c-badge--danger   { --badge-bg: var(--color-danger-50);    --badge-fg: var(--color-danger-text);     --badge-dot: var(--color-danger); }
/* Solid — حالات تتطلب انتباهًا فوريًا */
.c-badge--solid-primary { --badge-bg: var(--color-primary);      --badge-fg: #fff; --badge-dot: #fff; }
.c-badge--solid-success { --badge-bg: var(--color-success-solid);--badge-fg: #fff; --badge-dot: #fff; }
.c-badge--solid-danger  { --badge-bg: var(--color-danger);       --badge-fg: #fff; --badge-dot: #fff; }
.c-badge--solid-teal    { --badge-bg: var(--color-teal);         --badge-fg: #fff; --badge-dot: #fff; }
.c-badge--outline-warning { --badge-bg: var(--color-surface); --badge-fg: var(--color-warning-text); --badge-dot: var(--color-warning); border-color: var(--color-warning-100); }
.c-badge--strike { text-decoration: line-through; text-decoration-thickness: 1px; }
.c-badge__dot--pulse { animation: c-pulse 1.4s ease-in-out infinite; }
@keyframes c-pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ==========================================================================
   Tabs
   ========================================================================== */
.c-tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); overflow-x: auto; scrollbar-width: none; }
.c-tabs::-webkit-scrollbar { display: none; }
.c-tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--control-md); padding-inline: var(--space-4);
  font: inherit; font-size: var(--text-body); font-weight: var(--font-semibold);
  color: var(--color-text-muted); background: none; border: 0; cursor: pointer; white-space: nowrap;
}
.c-tab:hover { color: var(--color-text); }
.c-tab:focus-visible { outline: none; box-shadow: inset var(--focus-ring); border-radius: var(--radius-sm); }
.c-tab[aria-selected="true"] { color: var(--color-primary); }
.c-tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: var(--space-2); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--color-primary); }
.c-tab__count { font-size: var(--text-caption); font-weight: var(--font-bold); padding: 0 7px; border-radius: var(--radius-pill); background: var(--color-neutral-50); color: var(--color-neutral-text); line-height: 20px; }
.c-tab[aria-selected="true"] .c-tab__count { background: var(--color-primary-50); color: var(--color-primary); }
.c-tabpanel { padding-block: var(--space-4); }
.c-tabpanel[hidden] { display: none; }

/* Segmented (variant for filters) */
.c-segmented { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 4px; gap: 4px; background: var(--color-neutral-50); border-radius: var(--radius-md); }
.c-segmented button { flex: none; }
.c-segmented button { min-height: 36px; padding-inline: var(--space-4); font: inherit; font-size: var(--text-small); font-weight: var(--font-semibold); color: var(--color-text-muted); background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer; }
.c-segmented button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-xs); }

/* ==========================================================================
   Table → Cards on mobile
   ========================================================================== */
.c-table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.c-table-scroll { overflow-x: auto; }
.c-table { width: 100%; border-collapse: collapse; font-size: var(--text-table); line-height: var(--lh-table); }
.c-table th {
  position: sticky; top: 0;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-small); font-weight: var(--font-semibold); color: var(--color-text-muted);
  text-align: start; white-space: nowrap;
  background: var(--color-surface-muted);
  border-bottom: 1px solid var(--color-border);
}
.c-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.c-table tbody tr:last-child td { border-bottom: 0; }
.c-table tbody tr:hover td { background: var(--color-surface-muted); }
.c-table tbody tr.is-selected td { background: var(--color-primary-50); }
.c-table__primary { font-weight: var(--font-semibold); color: var(--color-text); }
.c-table__sub { display: block; font-size: var(--text-caption); line-height: var(--lh-caption); color: var(--color-text-muted); }
.c-table__actions { text-align: end; white-space: nowrap; }
.c-table__toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-4); border-bottom: 1px solid var(--color-border); }
.c-table__toolbar .c-field { flex: 1 1 240px; }
.c-th-sort { display: inline-flex; align-items: center; gap: 4px; font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.c-th-sort:hover { color: var(--color-text); }

@media (max-width: 767px) {
  .c-table--stack thead { display: none; }
  .c-table--stack, .c-table--stack tbody, .c-table--stack tr, .c-table--stack td { display: block; width: 100%; }
  .c-table--stack tr { display: flex; flex-direction: column; padding: var(--space-4); border-bottom: 1px solid var(--color-border); }
  .c-table--stack td[data-primary] { order: -1; }
  .c-table--stack tbody tr:last-child { border-bottom: 0; }
  .c-table--stack td { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-1) 0; border: 0; }
  .c-table--stack td::before { content: attr(data-label); font-size: var(--text-small); color: var(--color-text-muted); flex: none; }
  .c-table--stack td[data-primary] { padding-bottom: var(--space-2); }
  .c-table--stack td[data-primary]::before { display: none; }
  .c-table--stack tbody tr:hover td { background: none; }
  .c-table--stack td.c-table__actions { justify-content: flex-start; padding-top: var(--space-3); }
  .c-table--stack td.c-table__actions::before { display: none; }
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.c-pagination { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--color-border); }
.c-pagination__info { font-size: var(--text-small); color: var(--color-text-muted); }
.c-pagination__list { display: flex; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.c-page {
  display: inline-grid; place-items: center; min-width: 36px; height: 36px; padding-inline: var(--space-2);
  font: inherit; font-size: var(--text-small); font-weight: var(--font-semibold); font-variant-numeric: tabular-nums;
  color: var(--color-text); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm); cursor: pointer;
}
.c-page:hover { background: var(--color-neutral-50); }
.c-page:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.c-page[aria-current="page"] { color: #fff; background: var(--color-primary); border-color: var(--color-primary); }
.c-page:disabled { color: var(--color-text-disabled); background: var(--color-surface-muted); cursor: not-allowed; }
.c-page--gap { border: 0; background: none; cursor: default; }
@media (max-width: 639px) { .c-page--hide-sm { display: none; } }

/* ==========================================================================
   Dropdown
   ========================================================================== */
.c-dropdown { position: relative; display: inline-block; }
.c-dropdown__menu {
  position: absolute; inset-inline-start: 0; top: calc(100% + 6px); z-index: var(--z-dropdown);
  min-width: 220px; padding: var(--space-1);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(-4px); pointer-events: none; visibility: hidden;
  transition: opacity var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out), visibility var(--duration-fast);
}
.c-dropdown.is-open .c-dropdown__menu { opacity: 1; transform: none; pointer-events: auto; visibility: visible; }
.c-dropdown__menu--end { inset-inline-start: auto; inset-inline-end: 0; }
.c-dropdown__item {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 40px; padding-inline: var(--space-3);
  font: inherit; font-size: var(--text-body); color: var(--color-text); text-align: start;
  background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer;
}
.c-dropdown__item:hover, .c-dropdown__item:focus-visible { background: var(--color-neutral-50); outline: none; }
.c-dropdown__item .c-icon { color: var(--color-text-muted); }
.c-dropdown__item--danger { color: var(--color-danger-text); }
.c-dropdown__item--danger .c-icon { color: var(--color-danger); }
.c-dropdown__item[aria-disabled="true"] { color: var(--color-text-disabled); cursor: not-allowed; }
.c-dropdown__sep { height: 1px; margin: var(--space-1) 0; background: var(--color-border); }
.c-dropdown__label { padding: var(--space-2) var(--space-3) var(--space-1); font-size: var(--text-caption); color: var(--color-text-muted); font-weight: var(--font-semibold); }

/* ==========================================================================
   Tooltip
   ========================================================================== */
.c-tooltip { position: relative; display: inline-flex; }
.c-tooltip__bubble {
  position: absolute; bottom: calc(100% + 8px); left: 50%; z-index: var(--z-tooltip); /* i18n-ok: توسيط */
  max-width: 240px; width: max-content; padding: 6px 10px;
  font-size: var(--text-small); line-height: 1.5; color: #fff; background: var(--color-text);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  transform: translate(-50%, 4px); opacity: 0; pointer-events: none;
  transition: opacity var(--duration-fast), transform var(--duration-fast);
}
.c-tooltip__bubble::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: var(--color-text); } /* i18n-ok: توسيط */
.c-tooltip:hover .c-tooltip__bubble, .c-tooltip:focus-within .c-tooltip__bubble, .c-tooltip.is-open .c-tooltip__bubble { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Alert (inline)
   ========================================================================== */
.c-alert {
  --alert-bg: var(--color-teal-50); --alert-border: var(--color-teal-100); --alert-fg: var(--color-teal-text); --alert-icon: var(--color-teal);
  display: flex; gap: var(--space-3); padding: var(--space-4);
  background: var(--alert-bg); border: 1px solid var(--alert-border); border-inline-start: 4px solid var(--alert-icon);
  border-radius: var(--radius-md);
}
.c-alert__icon { color: var(--alert-icon); padding-top: 3px; }
.c-alert__body { flex: 1; min-width: 0; }
.c-alert__title { font-weight: var(--font-bold); color: var(--alert-fg); margin: 0; font-size: var(--text-body); }
.c-alert__text { margin: 2px 0 0; font-size: var(--text-small); line-height: var(--lh-small); color: var(--color-text); }
.c-alert__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }
.c-alert--success { --alert-bg: var(--color-success-50); --alert-border: var(--color-success-100); --alert-fg: var(--color-success-text); --alert-icon: var(--color-success); }
.c-alert--warning { --alert-bg: var(--color-warning-50); --alert-border: var(--color-warning-100); --alert-fg: var(--color-warning-text); --alert-icon: var(--color-warning); }
.c-alert--danger  { --alert-bg: var(--color-danger-50);  --alert-border: var(--color-danger-100);  --alert-fg: var(--color-danger-text);  --alert-icon: var(--color-danger); }

/* ==========================================================================
   Toast
   ========================================================================== */
.c-toast-region {
  position: fixed; z-index: var(--z-toast);
  inset-inline-start: var(--space-6); bottom: var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}
@media (max-width: 639px) { .c-toast-region { inset-inline: var(--space-4); bottom: var(--space-4); width: auto; } }
.c-toast {
  --toast-accent: var(--color-primary);
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-inline-start: 4px solid var(--toast-accent);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: c-toast-in var(--duration-base) var(--ease-out);
}
.c-toast .c-icon { color: var(--toast-accent); margin-top: 3px; }
.c-toast__body { flex: 1; min-width: 0; }
.c-toast__title { font-weight: var(--font-bold); font-size: var(--text-body); margin: 0; }
.c-toast__text { font-size: var(--text-small); color: var(--color-text-muted); margin: 0; line-height: var(--lh-small); }
.c-toast__close { background: none; border: 0; padding: 4px; color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-sm); display: inline-flex; }
.c-toast__close:hover { background: var(--color-neutral-50); }
.c-toast--success { --toast-accent: var(--color-success); }
.c-toast--warning { --toast-accent: var(--color-warning); }
.c-toast--danger  { --toast-accent: var(--color-danger); }
.c-toast.is-leaving { animation: c-toast-out var(--duration-base) var(--ease-out) forwards; }
.c-toast--static { animation: none; box-shadow: var(--shadow-sm); }
@keyframes c-toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes c-toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ==========================================================================
   Modal / Confirmation / Danger confirmation
   ========================================================================== */
.c-overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--space-4);
  background: var(--overlay);
  opacity: 0; visibility: hidden;
  transition: opacity var(--duration-base) var(--ease-out), visibility var(--duration-base);
}
.c-overlay.is-open { opacity: 1; visibility: visible; }
.c-modal {
  width: min(560px, 100%); max-height: calc(100vh - 2 * var(--space-4));
  display: flex; flex-direction: column;
  background: var(--color-surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(.98); transition: transform var(--duration-base) var(--ease-out);
}
.c-overlay.is-open .c-modal { transform: none; }
.c-modal--sm { width: min(440px, 100%); }
.c-modal__header { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-6) var(--space-3); }
.c-modal__title { margin: 0; font-size: var(--text-h4); line-height: var(--lh-h4); font-weight: var(--font-bold); flex: 1; }
.c-modal__body { padding: 0 var(--space-6) var(--space-5); overflow-y: auto; color: var(--color-text); }
.c-modal__body p { margin: 0 0 var(--space-3); }
.c-modal__footer { display: flex; justify-content: flex-start; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border); background: var(--color-surface-muted); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.c-modal__close { margin-inline-start: auto; }
.c-modal__icon { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--color-primary-50); color: var(--color-primary); }
.c-modal--danger .c-modal__icon { background: var(--color-danger-50); color: var(--color-danger); }
.c-modal--danger { border-top: 4px solid var(--color-danger); }
.c-modal__summary { padding: var(--space-3) var(--space-4); background: var(--color-surface-muted); border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: var(--text-small); }
.c-modal__summary dl { display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-4); margin: 0; }
.c-modal__summary dt { color: var(--color-text-muted); }
.c-modal__summary dd { margin: 0; font-weight: var(--font-semibold); }
@media (max-width: 639px) {
  .c-overlay { place-items: end stretch; padding: 0; }
  .c-modal { width: 100%; max-height: 92vh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; transform: translateY(24px); }
  .c-modal__footer { flex-direction: column-reverse; border-radius: 0; padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom)); }
  .c-modal__footer .c-btn { width: 100%; min-height: var(--control-lg); }
}

/* ==========================================================================
   Drawer (يفتح من جهة البداية في RTL = اليمين... ونستخدم جهة النهاية = اليسار للتفاصيل)
   ========================================================================== */
.c-drawer-overlay { position: fixed; inset: 0; z-index: var(--z-drawer); background: var(--overlay); opacity: 0; visibility: hidden; transition: opacity var(--duration-base), visibility var(--duration-base); }
.c-drawer-overlay.is-open { opacity: 1; visibility: visible; }
.c-drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; z-index: calc(var(--z-drawer) + 1);
  width: min(440px, 100vw);
  display: flex; flex-direction: column;
  background: var(--color-surface); box-shadow: var(--shadow-lg);
  transform: translateX(-100%); transition: transform var(--duration-base) var(--ease-out);
  visibility: hidden;
}
[dir="ltr"] .c-drawer { transform: translateX(100%); }
.c-drawer.is-open { transform: none; visibility: visible; }
.c-drawer__header { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); }
.c-drawer__title { margin: 0; font-size: var(--text-h4); font-weight: var(--font-bold); flex: 1; }
.c-drawer__body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.c-drawer__footer { display: flex; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); }
@media (max-width: 639px) {
  .c-drawer { inset-inline: 0; top: auto; width: 100%; max-height: 88vh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; transform: translateY(100%); }
  [dir="ltr"] .c-drawer { transform: translateY(100%); }
}

/* ==========================================================================
   Timeline
   ========================================================================== */
.c-timeline { list-style: none; margin: 0; padding: 0; }
.c-timeline__item { position: relative; display: grid; grid-template-columns: 32px 1fr; gap: var(--space-3); padding-bottom: var(--space-5); }
.c-timeline__item:last-child { padding-bottom: 0; }
.c-timeline__item:not(:last-child)::before { content: ""; position: absolute; inset-inline-start: 15px; top: 32px; bottom: 0; width: 2px; background: var(--color-border); }
.c-timeline__item.is-done:not(:last-child)::before { background: var(--color-primary-200); }
.c-timeline__marker { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--color-surface); border: 2px solid var(--color-border); color: var(--color-text-muted); z-index: 1; }
.c-timeline__marker .c-icon { width: 16px; height: 16px; stroke-width: 2.2; }
.c-timeline__item.is-done .c-timeline__marker { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.c-timeline__item.is-current .c-timeline__marker { border-color: var(--color-primary); color: var(--color-primary); box-shadow: 0 0 0 4px var(--color-primary-50); }
.c-timeline__item.is-failed .c-timeline__marker { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.c-timeline__item.is-warning .c-timeline__marker { background: var(--color-warning-50); border-color: var(--color-warning); color: var(--color-warning-text); }
.c-timeline__content { padding-top: 4px; min-width: 0; }
.c-timeline__title { margin: 0; font-weight: var(--font-semibold); font-size: var(--text-body); line-height: 1.5; }
.c-timeline__item.is-pending .c-timeline__title { color: var(--color-text-muted); font-weight: var(--font-regular); }
.c-timeline__meta { margin: 2px 0 0; font-size: var(--text-small); color: var(--color-text-muted); display: flex; flex-wrap: wrap; gap: 4px var(--space-3); }
.c-timeline__note { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); font-size: var(--text-small); background: var(--color-surface-muted); border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.c-timeline__diff { display: inline-flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.c-timeline__diff del { color: var(--color-danger-text); }
.c-timeline__diff ins { color: var(--color-success-text); text-decoration: none; font-weight: var(--font-semibold); }

/* ==========================================================================
   Empty / Loading / Skeleton
   ========================================================================== */
.c-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); padding: var(--space-10) var(--space-6); }
.c-empty__icon { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: var(--space-2); border-radius: 50%; background: var(--color-primary-50); color: var(--color-primary); }
.c-empty__icon .c-icon { width: 28px; height: 28px; stroke-width: 1.6; }
.c-empty__title { margin: 0; font-size: var(--text-h4); font-weight: var(--font-bold); }
.c-empty__text { margin: 0; max-width: 380px; font-size: var(--text-small); line-height: var(--lh-small); color: var(--color-text-muted); }
.c-empty__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; justify-content: center; }
.c-empty--error .c-empty__icon { background: var(--color-danger-50); color: var(--color-danger); }

.c-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-10); color: var(--color-text-muted); font-size: var(--text-small); }
.c-progress { height: 4px; border-radius: var(--radius-pill); background: var(--color-primary-50); overflow: hidden; position: relative; }
.c-progress::after { content: ""; position: absolute; inset-block: 0; width: 35%; border-radius: inherit; background: var(--color-primary); animation: c-indeterminate 1.2s var(--ease-out) infinite; }
@keyframes c-indeterminate { from { inset-inline-start: -35%; } to { inset-inline-start: 100%; } }

.c-skeleton {
  display: block; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--color-neutral-50) 0%, var(--color-neutral-100) 50%, var(--color-neutral-50) 100%);
  background-size: 200% 100%;
  animation: c-shimmer 1.4s ease-in-out infinite;
}
.c-skeleton--text { height: 12px; }
.c-skeleton--title { height: 18px; }
.c-skeleton--circle { border-radius: 50%; }
@keyframes c-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .c-skeleton, .c-progress::after, .c-spinner, .c-badge__dot--pulse { animation: none; } }

/* Avatar (initials — لا صور للطلاب) */
.c-avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--color-teal-50); color: var(--color-teal-text); font-size: var(--text-small); font-weight: var(--font-bold); }

/* Visually hidden */
.u-sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ==========================================================================
   WhatsAppContact — أيقونة بلون واتساب للتعرف السريع (الاستثناء اللوني الوحيد)
   ========================================================================== */
.wa-trigger { --btn-fg: #128C4A; }
.wa-trigger:hover { --btn-bg-hover: #E7F7EE; }
.wa-icon { background: #E7F7EE !important; color: #128C4A !important; }
.wa-btn { --btn-bg: #128C4A; --btn-bg-hover: #0E7A40; --btn-bg-active: #0C6A37; }
.wa-done { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: var(--radius-pill); background: #E7F7EE; color: #0E6B38; font-size: var(--text-caption); font-weight: var(--font-semibold); white-space: nowrap; }
.wa-done .c-icon { width: 13px; height: 13px; }
.wa-to { display: grid; gap: var(--space-2); }
.wa-guard { padding: var(--space-3); }
.wa-prev { display: flex; align-items: center; gap: 6px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--color-surface-muted); font-size: var(--text-small); }
.wa-prev[hidden] { display: none; }

/* خدمات المدرسة حسب باقتها (common/service-gate.js · 2026-10-25) */
.is-locked { color: var(--color-text-muted) !important; }
.is-locked .c-icon:not(.l-nav-lock) { opacity: .55; }
.l-nav-lock { margin-inline-start: auto; flex: none; color: var(--color-text-muted); }
.svc-gate { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4); margin-bottom: var(--space-5); border-radius: var(--radius-lg); background: var(--color-warning-50); border: 1px solid var(--color-warning); color: var(--color-warning-text); }
.svc-gate > .c-icon { flex: none; margin-top: 2px; }
.svc-gate strong { display: block; color: var(--color-text); }
.svc-gate span { display: block; margin-top: 4px; font-size: var(--text-small); }
.svc-gate--full { flex-direction: column; align-items: center; text-align: center; padding: var(--space-8) var(--space-5); margin: var(--space-6) auto; max-width: 460px; background: var(--color-surface); border-color: var(--color-border); color: var(--color-text-muted); }
.svc-gate--full > .c-icon { width: 40px; height: 40px; color: var(--color-text-muted); }
.svc-gate--full h1 { margin: 0; font-size: 1.25rem; color: var(--color-text); }
.svc-gate--full p { margin: 0 0 var(--space-3); }
.l-bottom-nav a.is-locked { position: relative; }
.l-bottom-nav .l-nav-lock { position: absolute; top: 4px; inset-inline-start: calc(50% + 6px); width: 13px; height: 13px; margin: 0; padding: 1px; border-radius: 50%; background: var(--color-surface); }
