/* ==========================================================================
   منصة إدارة الصلاحيات — نظام التصميم (app.css)
   RTL أولًا، خصائص منطقية، بلا أطر، متوافق مع CSP صارمة (لا data: URIs).
   المرجع: docs/design/design-system.md
   ========================================================================== */

/* ---------- 1. الخطوط (محلية — OFL، راجع assets/fonts/LICENSE.txt) ---------- */
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2190-2199, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2190-2199, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2190-2199, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("../fonts/ibm-plex-sans-arabic-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-200B, U+2012-204E, U+2050-206F, U+20AC, U+2122, U+2190-2199, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- 2. Design Tokens ---------- */
:root {
  /* الهوية */
  --navy-950: #081729;
  --navy-900: #0B1F3A;
  --navy-800: #122B4D;
  --navy-700: #163A63;
  --navy-600: #1F4C7F;
  --navy-100: #E6EDF6;
  --teal-700: #0B6966;
  --teal-600: #0F7774;
  --teal-400: #5FD0C9;
  --teal-100: #E2F4F2;
  --gold-600: #B08D3C;
  --gold-400: #D4B36A;
  --gold-800: #6B5313;
  --gold-100: #F6EEDA;

  /* الرماديات */
  --gray-0: #FFFFFF;
  --gray-50: #F3F5F8;
  --gray-100: #EDF0F4;
  --gray-200: #DCE2EA;
  --gray-300: #C5CDD8;
  --gray-400: #98A3B3;
  --gray-600: #566275;
  --gray-700: #3E4A5C;
  --gray-900: #14213A;

  /* الأدوار الدلالية */
  --color-bg: var(--gray-50);
  --color-surface: var(--gray-0);
  --color-surface-2: var(--gray-100);
  --color-border: var(--gray-200);
  --color-border-strong: var(--gray-300);
  --color-text: var(--gray-900);
  --color-text-muted: var(--gray-600);
  --color-text-soft: var(--gray-700);
  --color-primary: var(--navy-700);
  --color-primary-hover: var(--navy-800);
  --color-primary-soft: var(--navy-100);
  --color-accent: var(--teal-600);
  --color-accent-hover: var(--teal-700);
  --color-accent-soft: var(--teal-100);
  --color-link: var(--teal-700);
  --color-focus: #1A8C88;

  --color-success: #166B45;  --color-success-bg: #E5F3EB;  --color-success-border: #A9D8BE;
  --color-danger: #B42318;   --color-danger-bg: #FDECEA;   --color-danger-border: #F3B8B1;
  --color-warning: #8A4B00;  --color-warning-bg: #FDF1DC;  --color-warning-border: #EDCB8F;
  --color-info: #1D5A9E;     --color-info-bg: #E7F0FA;     --color-info-border: #B3CDEB;

  /* الشريط الجانبي (خلفية داكنة) */
  --sidebar-bg: var(--navy-900);
  --sidebar-text: #C9D3E1;
  --sidebar-muted: #8FA3BF;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active: rgba(95, 208, 201, 0.14);
  --sidebar-width: 264px;

  /* الطباعة */
  --font-sans: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --fs-xs: 0.75rem;     /* 12 */
  --fs-sm: 0.8125rem;   /* 13 */
  --fs-base: 0.875rem;  /* 14 */
  --fs-md: 0.9375rem;   /* 15 */
  --fs-lg: 1.0625rem;   /* 17 */
  --fs-xl: 1.25rem;     /* 20 */
  --fs-2xl: 1.5rem;     /* 24 */
  --fs-3xl: 1.875rem;   /* 30 */
  --lh-tight: 1.3;
  --lh-base: 1.65;

  /* المسافات (4px أساس) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  /* الحواف والظلال */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-xs: 0 1px 2px rgba(11, 31, 58, 0.06);
  --shadow-sm: 0 1px 3px rgba(11, 31, 58, 0.08), 0 1px 2px rgba(11, 31, 58, 0.04);
  --shadow-md: 0 6px 16px -4px rgba(11, 31, 58, 0.12), 0 2px 4px rgba(11, 31, 58, 0.05);
  --shadow-lg: 0 20px 40px -12px rgba(11, 31, 58, 0.28);
  --ring: 0 0 0 3px rgba(15, 119, 116, 0.28);

  /* الطبقات والحركة */
  --z-sticky: 20; --z-sidebar: 40; --z-drawer: 60; --z-modal: 70; --z-toast: 90;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 120ms; --dur: 200ms; --dur-slow: 280ms;

  --topbar-height: 60px;
  --content-max: 1440px;
  --control-h: 36px;
}

/* ---------- 3. أساسيات ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--color-text);
  background: var(--color-bg);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, h5, h6 { margin: 0; line-height: var(--lh-tight); font-weight: 600; color: var(--color-text); }
h1 { font-size: var(--fs-2xl); font-weight: 700; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
p:last-child { margin-block-end: 0; }
a { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { display: inline-block; vertical-align: middle; max-width: 100%; }
/* أيقونة <svg><use/></svg> بلا مقاس صريح: 1em افتراضيًا (خصوصية صفرية، تتغلب عليها أي قاعدة مكوّن) */
:where(svg:not([width]):has(> use)) { width: 1em; height: 1em; flex: none; }
hr { border: 0; border-block-start: 1px solid var(--color-border); margin: var(--sp-6) 0; }
small { font-size: var(--fs-sm); }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
::selection { background: rgba(15, 119, 116, 0.22); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: var(--radius-sm); }

.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;
}
.skip-link {
  position: absolute; inset-inline-start: var(--sp-4); inset-block-start: -100px; z-index: 100;
  background: var(--color-primary); color: #fff; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
}
.skip-link:focus { inset-block-start: var(--sp-3); }

/* ---------- 4. الهيكل ---------- */
.app-shell {
  display: grid;
  background: linear-gradient(to left, var(--sidebar-bg) var(--sidebar-width), transparent var(--sidebar-width));
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  inset-block-start: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  z-index: var(--z-sidebar);
  border-inline-end: 1px solid rgba(255, 255, 255, 0.04);
}
.sidebar :focus-visible { outline-color: var(--teal-400); }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-block-end: 1px solid rgba(255, 255, 255, 0.07);
  color: #fff;
  text-decoration: none;
}
.sidebar__brand:hover { text-decoration: none; }
.brand-mark {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--navy-700);
  color: var(--teal-400);
  box-shadow: inset 0 0 0 1px rgba(212, 179, 106, 0.45);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: var(--fs-md); font-weight: 700; color: #fff; line-height: 1.35; }
.brand-sub { font-size: var(--fs-xs); color: var(--sidebar-muted); line-height: 1.4; }

.sidebar__nav { padding: var(--sp-3) var(--sp-3) var(--sp-6); flex: 1; }
.nav-group { margin-block-end: var(--sp-4); }
.nav-group__title {
  margin: 0;
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--sidebar-muted);
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 38px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  color: var(--sidebar-text);
  font-size: var(--fs-base);
  font-weight: 500;
  text-decoration: none;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--sidebar-active); color: #fff; }
.nav-link.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(-1 * var(--sp-3));
  inset-block: 8px;
  width: 3px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: var(--teal-400);
}
.nav-icon { flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; color: var(--sidebar-muted); }
.nav-icon svg { width: 18px; height: 18px; }
.nav-link:hover .nav-icon, .nav-link.is-active .nav-icon { color: var(--teal-400); }
.nav-count {
  margin-inline-start: auto;
  min-width: 22px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav-count--alert { background: var(--gold-400); color: var(--navy-900); }
.sidebar__footer {
  padding: var(--sp-4) var(--sp-5);
  border-block-start: 1px solid rgba(255, 255, 255, 0.07);
  font-size: var(--fs-xs);
  color: var(--sidebar-muted);
}

[dir="ltr"] .app-shell { background: linear-gradient(to right, var(--sidebar-bg) var(--sidebar-width), transparent var(--sidebar-width)); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 23, 41, 0.5);
  z-index: calc(var(--z-sidebar) - 1);
}

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

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--topbar-height);
  padding: var(--sp-2) var(--sp-6);
  background: rgba(255, 255, 255, 0.94);
  border-block-end: 1px solid var(--color-border);
  backdrop-filter: saturate(1.2) blur(6px);
}
.menu-toggle {
  display: none;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.menu-toggle svg { width: 20px; height: 20px; }
.menu-toggle:hover { background: var(--color-surface-2); }

.topbar__search { position: relative; flex: 1; max-width: 520px; }
.topbar__search .input { padding-inline-start: 36px; background: var(--color-surface-2); border-color: transparent; }
.topbar__search .input:hover { border-color: var(--color-border); }
.topbar__search .input:focus { background: var(--color-surface); border-color: var(--color-accent); }
.search-icon {
  position: absolute;
  inset-inline-start: 11px;
  inset-block-start: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.search-results {
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(100% + 6px);
  max-height: min(420px, 70vh);
  overflow-y: auto;
  margin: 0;
  padding: var(--sp-1);
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: calc(var(--z-sticky) + 1);
}
.search-results__group {
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--color-text-muted);
}
.search-result {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 40px;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text);
  text-align: start;
  text-decoration: none;
}
.search-result:hover, .search-result.is-active, .search-result[aria-selected="true"] { background: var(--color-primary-soft); text-decoration: none; }
.search-result .mono { white-space: nowrap; }
.search-result__type { margin-inline-start: auto; font-size: var(--fs-xs); color: var(--color-text-muted); }
.search-result mark { background: var(--gold-100); color: inherit; border-radius: 2px; padding: 0 1px; }
.search-results__empty { padding: var(--sp-4); text-align: center; color: var(--color-text-muted); }

.topbar__end { display: flex; align-items: center; gap: var(--sp-3); margin-inline-start: auto; }
.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-md);
  border: 0;
  background: transparent;
  text-align: start;
}
button.topbar__user:hover { background: var(--color-surface-2); }
.topbar__user-text { display: flex; flex-direction: column; line-height: 1.3; }
.user-name { font-size: var(--fs-base); font-weight: 600; color: var(--color-text); }
.user-role { font-size: var(--fs-xs); color: var(--color-text-muted); }

.avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--navy-100);
  color: var(--navy-700);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1;
}
.avatar--sm { width: 26px; height: 26px; font-size: var(--fs-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-xl); }
.avatar--teal { background: var(--teal-100); color: var(--teal-700); }
.avatar--gold { background: var(--gold-100); color: var(--gold-800); }

.demo-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 2px 10px;
  border: 1px dashed var(--gold-600);
  border-radius: var(--radius-pill);
  background: var(--gold-100);
  color: var(--gold-800);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
}
.demo-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-600);
}

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-12);
}
.section { margin-block-end: var(--sp-6); }
.section__title { font-size: var(--fs-lg); margin-block-end: var(--sp-3); }
.stack > * + * { margin-block-start: var(--sp-4); }
.stack-sm > * + * { margin-block-start: var(--sp-2); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.spacer { flex: 1; }

/* ---------- 5. ترويسة الصفحة ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-block-end: var(--sp-6);
}
.page-header__text { min-width: 0; flex: 1 1 360px; }
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 var(--sp-2);
  padding: 0;
  list-style: none;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.breadcrumb ol { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
nav.breadcrumb { display: block; }
.breadcrumb li { display: inline-flex; align-items: center; gap: 6px; }
.breadcrumb li + li::before { content: "‹"; color: var(--gray-400); }
.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb a:hover { color: var(--color-link); }
.breadcrumb [aria-current="page"] { color: var(--color-text); font-weight: 500; }
.page-header__title { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.3; }
.page-header__title .badge { vertical-align: middle; margin-inline-start: var(--sp-2); }
.page-header__desc { margin: var(--sp-1) 0 0; max-width: 72ch; color: var(--color-text-muted); font-size: var(--fs-md); }
.page-header__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }

/* ---------- 6. الأزرار ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--control-h);
  padding: 0 var(--sp-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.btn--primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn--primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn--primary:active { background: var(--navy-900); }

.btn--secondary { background: var(--color-surface); border-color: var(--color-border-strong); color: var(--color-text); box-shadow: var(--shadow-xs); }
.btn--secondary:hover { background: var(--color-surface-2); border-color: var(--gray-400); }
.btn--secondary:active { background: var(--gray-200); }

.btn--danger { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.btn--danger:hover { background: #962017; border-color: #962017; }

.btn--success { background: var(--color-success); border-color: var(--color-success); color: #fff; }
.btn--success:hover { background: #115638; border-color: #115638; }

.btn--accent { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.btn--accent:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn--ghost { background: transparent; color: var(--color-text-soft); }
.btn--ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn--ghost.btn--danger-text { color: var(--color-danger); }
.btn--ghost.btn--danger-text:hover { background: var(--color-danger-bg); }

.btn--sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn--icon { width: var(--control-h); padding: 0; }
.btn--icon.btn--sm { width: 30px; }
.btn--block { width: 100%; }

.btn[disabled], .btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 1;
  background: var(--gray-100);
  border-color: var(--gray-200);
  color: var(--gray-400);
  box-shadow: none;
}
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-block-start-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.btn--secondary.is-loading::after, .btn--ghost.is-loading::after { border-color: var(--gray-300); border-block-start-color: var(--color-primary); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-start-start-radius: var(--radius); border-end-start-radius: var(--radius); }
.btn-group .btn:last-child { border-start-end-radius: var(--radius); border-end-end-radius: var(--radius); }
.btn-group .btn + .btn { margin-inline-start: -1px; }
.btn-group .btn.is-active { background: var(--color-primary-soft); border-color: var(--navy-600); color: var(--navy-700); position: relative; }

/* ---------- 7. البطاقات والشبكات ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}
.card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-block-end: 1px solid var(--color-border);
}
.card__title { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.card__subtitle { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.card__body { padding: var(--sp-5); }
.card__footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-block-start: 1px solid var(--color-border);
  background: var(--gray-50);
  border-end-start-radius: var(--radius-md);
  border-end-end-radius: var(--radius-md);
  font-size: var(--fs-sm);
}
.card--flush .card__body { padding: 0; }
.card--flush .table-wrap, .card > .table-wrap { border: 0; border-radius: 0; }
.card--accent { border-block-start: 3px solid var(--color-accent); }

.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--sp-5); }
.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-aside { display: grid; gap: var(--sp-5); grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.span-2 { grid-column: span 2; }

/* KPI */
.kpi-grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-block-end: var(--sp-6);
}
@media (min-width: 1360px) { .kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } .kpi { padding-inline: var(--sp-4); } }
.kpi-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (min-width: 1360px) { .kpi-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
/* 7–8 مؤشرات: 4 أعمدة (صفّان متوازنان) بدل 6 + يتيمين */
@media (min-width: 1100px) { .kpi-grid:has(> .kpi:nth-child(7)) { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 641px) and (max-width: 1099.98px) { .kpi-grid:has(> .kpi:nth-child(7)) { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
a.kpi:hover { border-color: var(--gray-400); box-shadow: var(--shadow-md); text-decoration: none; }
a.kpi::after {
  content: "‹";
  position: absolute;
  inset-inline-end: var(--sp-4);
  inset-block-start: var(--sp-3);
  color: var(--gray-400);
  font-size: var(--fs-lg);
  transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
a.kpi:hover::after { color: var(--color-accent); transform: translateX(-3px); }
.kpi__label { font-size: var(--fs-sm); font-weight: 500; color: var(--color-text-muted); padding-inline-end: var(--sp-4); }
.kpi__value { font-size: var(--fs-3xl); font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.kpi__meta { font-size: var(--fs-xs); color: var(--color-text-muted); }
.kpi__meta .up { color: var(--color-success); font-weight: 600; }
.kpi__meta .down { color: var(--color-danger); font-weight: 600; }
.kpi--alert { border-inline-start: 3px solid var(--color-danger); }
.kpi--alert .kpi__value { color: var(--color-danger); }
.kpi--warn { border-inline-start: 3px solid #C98A1B; }
.kpi--warn .kpi__value { color: var(--color-warning); }
.kpi--accent { border-inline-start: 3px solid var(--color-accent); }

/* ---------- 8. الجداول ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-block-end: var(--sp-3);
}
.card > .toolbar { margin: 0; padding: var(--sp-3) var(--sp-4); border-block-end: 1px solid var(--color-border); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); flex: 1 1 auto; min-width: 0; }
.filters .input { width: auto; min-width: 150px; }
.filters .input[type="search"] { min-width: 220px; flex: 1 1 220px; max-width: 320px; }
.toolbar__actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
/* حقول مباشرة داخل .toolbar (بلا .filters): عرض طبيعي بدل التمدد */
.toolbar > .input, .toolbar > div:not(.filters):not(.toolbar__actions) > .input { width: auto; flex: 0 1 auto; min-width: 200px; max-width: 280px; }
.toolbar > .field__label { margin: 0; }
.toolbar:has(> .field__label), .toolbar:has(> .btn-group) { justify-content: flex-start; }

.table-wrap {
  position: relative;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.table-wrap:focus-visible { outline-offset: -2px; }
.table-wrap--scroll { max-height: 70vh; overflow-y: auto; }

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
  font-variant-numeric: tabular-nums;
}
.data-table caption { caption-side: top; text-align: start; padding: var(--sp-3) var(--sp-4); font-weight: 600; }
.data-table th, .data-table td {
  padding: 10px var(--sp-4);
  text-align: start;
  vertical-align: middle;
  border-block-end: 1px solid var(--color-border);
}
.data-table thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 1;
  background: var(--gray-50);
  color: var(--color-text-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}
.data-table tbody tr:last-child td { border-block-end: 0; }
.data-table tbody tr:hover td { background: #F8FAFC; }
.data-table tr.is-clickable { cursor: pointer; }
.data-table tr.is-clickable:hover td { background: var(--color-primary-soft); }
.data-table tr.is-clickable:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.data-table tr.is-selected td { background: var(--teal-100); }
.data-table td.num, .data-table th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table td.actions, .data-table th.actions { text-align: end; white-space: nowrap; width: 1%; }
.data-table td.actions .btn + .btn { margin-inline-start: var(--sp-1); }
.data-table .cell-main { font-weight: 600; color: var(--color-text); }
.cell-sub { display: block; font-size: var(--fs-xs); color: var(--color-text-muted); font-weight: 400; }
.data-table .cell-user { display: flex; align-items: center; gap: var(--sp-3); min-width: 180px; }
.data-table--compact th, .data-table--compact td { padding: 6px var(--sp-3); }
.data-table--zebra tbody tr:nth-child(even) td { background: #FAFBFC; }

th.sortable { padding: 0; }
th.sortable > button, th.sortable > .sort-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px var(--sp-4);
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}
th.sortable > button:hover { color: var(--color-text); background: var(--gray-100); }
th.sortable:not(:has(> button)) { padding: 10px var(--sp-4); cursor: pointer; }
th.sortable > button::after, th.sortable:not(:has(> button))::after {
  content: "↕";
  font-size: 11px;
  color: var(--gray-400);
  margin-inline-start: 4px;
}
th.sortable[aria-sort="ascending"] > button::after, th.sortable[aria-sort="ascending"]:not(:has(> button))::after { content: "▲"; color: var(--color-accent); font-size: 9px; }
th.sortable[aria-sort="descending"] > button::after, th.sortable[aria-sort="descending"]:not(:has(> button))::after { content: "▼"; color: var(--color-accent); font-size: 9px; }
th.sortable[aria-sort="ascending"], th.sortable[aria-sort="descending"] { color: var(--color-text); }

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
}
.card > .pagination { border-block-start: 1px solid var(--color-border); }
.pagination__info { color: var(--color-text-muted); }
.pagination__pages { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.pagination__pages .btn { min-width: 32px; }
.pagination__pages .btn[aria-current="page"] { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-12) var(--sp-6);
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state__icon {
  display: inline-grid; place-items: center;
  width: 52px; height: 52px;
  margin-block-end: var(--sp-2);
  border-radius: 50%;
  background: var(--color-surface-2);
  color: var(--gray-600);
}
.empty-state__icon svg { width: 24px; height: 24px; }
.empty-state__title { margin: 0; font-size: var(--fs-md); font-weight: 600; color: var(--color-text); }
.empty-state__text { margin: 0 0 var(--sp-3); max-width: 46ch; font-size: var(--fs-base); }
.empty-state--error .empty-state__icon { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---------- 9. الشارات ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
  vertical-align: middle;
}
.badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.badge--danger  { background: var(--color-danger-bg);  color: var(--color-danger);  border-color: var(--color-danger-border); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-border); }
.badge--info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: var(--color-info-border); }
.badge--neutral { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-200); }
.badge--gold    { background: var(--gold-100); color: var(--gold-800); border-color: #E3CF9E; }
.badge--primary { background: var(--navy-100); color: var(--navy-700); border-color: #C3D2E6; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding-block: 2px;
  padding-inline: 10px 4px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--fs-sm);
  line-height: 1.3;
}
.chip:not(:has(.chip__remove)) { padding-inline-end: 10px; }
.chip__remove {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 15px;
  line-height: 1;
}
.chip__remove:hover { background: var(--color-danger-bg); color: var(--color-danger); }
.chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* شارة القرار الكبيرة */
.decision {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-5) var(--sp-2) var(--sp-4);
  border: 1px solid;
  border-radius: var(--radius-md);
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: 1.3;
}
.decision::before {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}
.decision__sub { display: block; font-size: var(--fs-sm); font-weight: 500; }
.decision--allow { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.decision--allow::before { content: "✓"; background: var(--color-success); }
.decision--deny { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger-border); }
.decision--deny::before { content: "✕"; background: var(--color-danger); }
.decision--conditional { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning-border); }
.decision--conditional::before { content: "!"; background: #B26A00; }

/* نطاق الوصول */
.scope {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px 1px 9px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 20px;
  white-space: nowrap;
  border: 1px solid;
}
.scope::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.scope--all  { background: #EEE9F8; color: #4B2F8C; border-color: #D3C6EE; }
.scope--org  { background: var(--navy-100); color: var(--navy-700); border-color: #C3D2E6; }
.scope--dept { background: var(--color-info-bg); color: var(--color-info); border-color: var(--color-info-border); }
.scope--team { background: var(--teal-100); color: var(--teal-700); border-color: #AEDDD8; }
.scope--own  { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-300); }
.scope--deny { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger-border); }
.scope--deny::before { content: "⊘"; width: auto; height: auto; background: none; font-size: 12px; line-height: 1; }

/* مستوى المخاطر — مقياس 4 أعمدة بصري + نص */
.risk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.risk::before {
  content: "";
  width: 22px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(to left, currentColor 0 25%, var(--gray-200) 25% 100%);
}
.risk--low { color: var(--color-success); }
.risk--medium { color: #9A6100; }
.risk--medium::before { background: linear-gradient(to left, currentColor 0 50%, var(--gray-200) 50% 100%); }
.risk--high { color: #B4470F; }
.risk--high::before { background: linear-gradient(to left, currentColor 0 75%, var(--gray-200) 75% 100%); }
.risk--critical { color: var(--color-danger); }
.risk--critical::before { background: currentColor; }

/* ---------- 10. النماذج ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4) var(--sp-5);
}
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-section { grid-column: 1 / -1; padding-block-start: var(--sp-2); margin-block-start: var(--sp-2); border-block-start: 1px solid var(--color-border); }
.form-section:first-child { border: 0; margin: 0; padding: 0; }
.form-section__title { font-size: var(--fs-md); font-weight: 600; margin: var(--sp-2) 0 0; }
.form-section__desc { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field__label { font-size: var(--fs-sm); font-weight: 600; color: var(--color-text); }
.field__label .req { color: var(--color-danger); margin-inline-start: 2px; }
.field__hint { font-size: var(--fs-xs); color: var(--color-text-muted); }
.field__error { display: none; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 600; color: var(--color-danger); }
.field__error::before { content: "!"; display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; background: var(--color-danger); color: #fff; font-size: 10px; }
.field.has-error .field__error { display: inline-flex; }
.field.has-error .input { border-color: var(--color-danger); background: #FFFBFA; }
.field.has-error .input:focus { box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.18); }
.field.has-error .field__label { color: var(--color-danger); }
fieldset.field { border: 0; margin: 0; padding: 0; }
fieldset.field > legend { padding: 0; margin-block-end: 6px; }

.input {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  padding: 7px var(--sp-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--fs-base);
  line-height: 1.45;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--gray-400); }
.input:hover { border-color: var(--gray-400); }
.input:focus { outline: none; border-color: var(--color-accent); box-shadow: var(--ring); }
.input:focus-visible { outline: none; }
.input[disabled], .input[readonly] { background: var(--gray-50); color: var(--color-text-muted); cursor: not-allowed; }
.input[readonly] { cursor: default; }
textarea.input { min-height: 88px; resize: vertical; }
select.input { padding-inline-end: var(--sp-6); cursor: pointer; }
.input--sm { min-height: 30px; padding: 4px var(--sp-2); font-size: var(--fs-sm); }
.input--ltr, input[type="email"].input, input[type="url"].input { direction: ltr; text-align: end; }
.input--ltr::placeholder { text-align: end; }
input[type="date"].input, input[type="datetime-local"].input, input[type="number"].input { font-variant-numeric: tabular-nums; }
.input-group { display: flex; }
.input-group .input { border-start-end-radius: 0; border-end-end-radius: 0; }
.input-group .btn { border-start-start-radius: 0; border-end-start-radius: 0; margin-inline-start: -1px; }
.cond-row .input-group { align-items: center; min-width: 0; }
.cond-row .input-group > .input--sm { flex: 0 0 auto; width: auto; min-height: 32px; }
.cond-row .input-group > .input:not(.input--sm) { flex: 1 1 auto; min-width: 0; }
.cond-row .input-group > .input + .input { margin-inline-start: -1px; border-start-start-radius: 0; border-end-start-radius: 0; border-start-end-radius: var(--radius); border-end-end-radius: var(--radius); }
.cond-row .input-group > .checkbox { flex: none; margin-inline-start: var(--sp-2); align-items: center; min-height: 0; }
.cond-row .input-group > .checkbox input { margin: 0; }

.checkbox, .radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  min-height: 24px;
  font-size: var(--fs-base);
  cursor: pointer;
}
.checkbox input, .radio input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}
.checkbox input:focus-visible, .radio input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.checkbox__desc { display: block; font-size: var(--fs-xs); color: var(--color-text-muted); }
.option-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.option-list--inline { flex-direction: row; flex-wrap: wrap; gap: var(--sp-4); }

/* المفتاح: <label class="switch"><input type="checkbox" role="switch"><span class="switch__track"></span><span>نص</span></label> */
.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); min-height: 24px; cursor: pointer; font-size: var(--fs-base); }
.switch input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch__track {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border-radius: var(--radius-pill);
  background: var(--gray-300);
  transition: background-color var(--dur) var(--ease);
}
.switch__track::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch__track { background: var(--color-accent); }
.switch input:checked + .switch__track::after { transform: translateX(-16px); }
[dir="ltr"] .switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.switch input:disabled + .switch__track { opacity: 0.5; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: var(--sp-2);
  margin-block-start: var(--sp-6);
  padding-block-start: var(--sp-4);
  border-block-start: 1px solid var(--color-border);
}
.form-actions .spacer { flex: 1; }

/* ---------- 11. الطبقات: Drawer / Modal ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 23, 41, 0.5);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}
.backdrop.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }

.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: flex;
  justify-content: flex-end; /* في RTL: يظهر اللوح من جهة اليسار (inline-end) مقابل الشريط الجانبي */
  background: rgba(8, 23, 41, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur-slow);
}
.drawer.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }
.drawer__panel {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  height: 100%;
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(-24px);
  transition: transform var(--dur-slow) var(--ease);
}
[dir="ltr"] .drawer__panel { transform: translateX(24px); }
.drawer.is-open .drawer__panel { transform: none; }
.drawer--wide .drawer__panel { width: min(760px, 100%); }
.drawer__header, .modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-block-end: 1px solid var(--color-border);
}
.drawer__title, .modal__title { margin: 0; font-size: var(--fs-lg); font-weight: 600; }
.drawer__subtitle, .modal__subtitle { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--color-text-muted); }
.drawer__body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-5); }
.drawer__body .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.drawer__footer, .modal__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-block-start: 1px solid var(--color-border);
  background: var(--gray-50);
}
.drawer__footer .spacer, .modal__footer .spacer { flex: 1; }
.close-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin: -4px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 20px;
  line-height: 1;
}
.close-btn:hover { background: var(--color-surface-2); color: var(--color-text); }

.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(8, 23, 41, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}
.modal.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }
.modal__dialog {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(8px) scale(0.98);
  transition: transform var(--dur) var(--ease);
  overflow: hidden;
}
.modal.is-open .modal__dialog { transform: none; }
.modal--lg .modal__dialog { width: min(760px, 100%); }
.modal__body { padding: var(--sp-5); overflow-y: auto; }
.modal--danger .modal__header { border-block-start: 3px solid var(--color-danger); }
.modal__footer { justify-content: flex-start; }

/* للعرض المرجعي فقط (components.html): طبقة ثابتة داخل التدفق */
.is-demo-static { position: relative; inset: auto; z-index: auto; opacity: 1; visibility: visible; background: var(--gray-200); padding: var(--sp-5); border-radius: var(--radius-md); }
.drawer.is-demo-static { height: 520px; justify-content: flex-start; overflow: hidden; }
.drawer.is-demo-static .drawer__panel { transform: none; box-shadow: var(--shadow-md); border-radius: var(--radius-md); }
.modal.is-demo-static .modal__dialog { transform: none; }

body.has-overlay { overflow: hidden; }

/* ---------- 12. التنبيهات ---------- */
.toast-region {
  position: fixed;
  inset-block-end: var(--sp-5);
  inset-inline-end: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
body:has(.drawer.is-open) .toast-region, body:has(.modal.is-open) .toast-region { inset-block-end: auto; inset-block-start: var(--sp-5); }
.toast-region.is-demo-static { position: static; padding: 0; background: none; width: min(380px, 100%); }
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-md);
  background: var(--navy-900);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-base);
  pointer-events: auto;
  border-inline-start: 4px solid var(--teal-400);
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast__icon { flex: none; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; font-weight: 700; margin-block-start: 1px; }
.toast__body { flex: 1; min-width: 0; }
.toast__title { display: block; font-weight: 600; }
.toast__text { display: block; color: #C9D3E1; font-size: var(--fs-sm); }
.toast__close { flex: none; border: 0; background: transparent; color: #C9D3E1; font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: var(--radius-sm); }
.toast__close:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.toast--success { border-inline-start-color: #4CC38A; }
.toast--success .toast__icon { background: #4CC38A; color: var(--navy-900); }
.toast--error { border-inline-start-color: #F97066; }
.toast--error .toast__icon { background: #F97066; color: var(--navy-900); }
.toast--info { border-inline-start-color: var(--teal-400); }
.toast--info .toast__icon { background: var(--teal-400); color: var(--navy-900); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-inline-start-width: 4px;
  border-radius: var(--radius);
  font-size: var(--fs-base);
  line-height: 1.6;
}
.alert__title { display: block; font-weight: 700; margin-block-end: 2px; }
.alert__body { flex: 1; min-width: 0; }
.alert__body ul { margin: var(--sp-1) 0 0; padding-inline-start: var(--sp-5); }
.alert svg { flex: none; width: 18px; height: 18px; margin-block-start: 2px; }
.alert--info { background: var(--color-info-bg); border-color: var(--color-info-border); border-inline-start-color: var(--color-info); color: #163F6E; }
.alert--warning { background: var(--color-warning-bg); border-color: var(--color-warning-border); border-inline-start-color: #C98A1B; color: #6B3A00; }
.alert--danger { background: var(--color-danger-bg); border-color: var(--color-danger-border); border-inline-start-color: var(--color-danger); color: #8C1C13; }
.alert--success { background: var(--color-success-bg); border-color: var(--color-success-border); border-inline-start-color: var(--color-success); color: #0F4F32; }

/* ---------- 13. التبويبات ---------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  margin-block-end: var(--sp-5);
  border-block-end: 1px solid var(--color-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 var(--sp-4);
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--fs-base);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab:hover { color: var(--color-text); background: var(--gray-100); text-decoration: none; }
.tab.is-active, .tab[aria-selected="true"] { color: var(--navy-700); }
.tab.is-active::after, .tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--sp-3);
  inset-block-end: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--color-accent);
}
.tab:focus-visible { outline-offset: -2px; }
.tab .nav-count, .tab__count {
  min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill);
  background: var(--gray-100); color: var(--gray-700);
  font-size: var(--fs-xs); line-height: 18px; text-align: center;
}
.tab.is-active .tab__count { background: var(--navy-100); color: var(--navy-700); }
.tab-panel:focus-visible { outline-offset: 4px; }
.card > .tabs { margin: 0; padding-inline: var(--sp-3); }

/* ---------- 14. عرض البيانات ---------- */
.kv {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: var(--sp-2) var(--sp-5);
  margin: 0;
  font-size: var(--fs-base);
}
.kv dt { color: var(--color-text-muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--color-text); font-weight: 500; overflow-wrap: anywhere; }
.kv--2col { grid-template-columns: minmax(110px, max-content) minmax(0, 1fr) minmax(110px, max-content) minmax(0, 1fr); }
.kv--stacked { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-4); }
.kv--stacked > div { display: flex; flex-direction: column; gap: 2px; }
.kv--stacked dt { font-size: var(--fs-xs); }

/* الخط الزمني للموافقات */
.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline__item {
  position: relative;
  padding-inline-start: 36px;
  padding-block-end: var(--sp-5);
}
.timeline__item::before { /* الخط الرابط */
  content: "";
  position: absolute;
  inset-inline-start: 11px;
  inset-block: 26px 0;
  width: 2px;
  background: var(--gray-200);
}
.timeline__item:last-child { padding-block-end: 0; }
.timeline__item:last-child::before { display: none; }
.timeline__item::after { /* العلامة */
  content: "";
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 0;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  box-sizing: border-box;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--gray-300);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.timeline__item--done::after { content: "✓"; background: var(--color-success); border-color: var(--color-success); color: #fff; }
.timeline__item--done::before { background: var(--color-success-border); }
.timeline__item--current::after { border-color: var(--color-accent); background: var(--color-surface); box-shadow: 0 0 0 4px var(--teal-100); content: ""; }
.timeline__item--current .timeline__title { color: var(--teal-700); }
.timeline__item--rejected::after { content: "✕"; background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.timeline__item--pending::after { border-style: dashed; }
.timeline__item--pending .timeline__title { color: var(--color-text-muted); }
.timeline__title { display: block; font-weight: 600; line-height: 24px; }
.timeline__meta { display: block; font-size: var(--fs-sm); color: var(--color-text-muted); }
.timeline__note {
  margin-block-start: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--gray-50);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  color: var(--color-text-soft);
}
.timeline__item--rejected .timeline__note { background: var(--color-danger-bg); border-color: var(--color-danger-border); color: #8C1C13; }

/* المؤشر المرحلي */
.stepper { display: flex; margin: 0 0 var(--sp-5); padding: 0; list-style: none; counter-reset: step; overflow-x: auto; }
.step {
  position: relative;
  flex: 1 1 0;
  min-width: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding-inline: var(--sp-2);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  counter-increment: step;
}
.step::before {
  content: counter(step);
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: var(--color-surface);
  font-weight: 700;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.step::after {
  content: "";
  position: absolute;
  inset-block-start: 13px;
  inset-inline-start: calc(50% + 18px);
  inset-inline-end: calc(-50% + 18px);
  height: 2px;
  background: var(--gray-200);
}
.step:last-child::after { display: none; }
.step.is-done { color: var(--color-text-soft); }
.step.is-done::before { content: "✓"; background: var(--color-success); border-color: var(--color-success); color: #fff; }
.step.is-done::after { background: var(--color-success); }
.step.is-current { color: var(--color-text); font-weight: 600; }
.step.is-current::before { border-color: var(--color-accent); color: var(--teal-700); box-shadow: 0 0 0 4px var(--teal-100); }
.step.is-rejected::before { content: "✕"; background: var(--color-danger); border-color: var(--color-danger); color: #fff; }

/* الشجرة */
.tree, .tree__children { list-style: none; margin: 0; padding: 0; }
.tree__children {
  position: relative;
  margin-inline-start: 14px;
  padding-inline-start: 14px;
  border-inline-start: 1px solid var(--gray-200);
}
.tree__node {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  min-height: 36px;
  padding: 4px var(--sp-2);
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text);
  text-align: start;
  font-size: var(--fs-base);
}
button.tree__node:hover, a.tree__node:hover { background: var(--gray-100); text-decoration: none; }
.tree__node.is-selected { background: var(--color-primary-soft); color: var(--navy-700); font-weight: 600; }
.tree__toggle {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 11px;
  transition: transform var(--dur-fast) var(--ease);
}
.tree__toggle::before { content: "◀"; }
.tree__toggle[aria-expanded="true"] { transform: rotate(-90deg); }
[dir="ltr"] .tree__toggle::before { content: "▶"; }
[dir="ltr"] .tree__toggle[aria-expanded="true"] { transform: rotate(90deg); }
.tree__toggle:hover { background: var(--gray-200); color: var(--color-text); }
.tree__spacer { flex: none; width: 22px; }
.tree__type {
  flex: none;
  padding: 0 6px;
  border-radius: var(--radius-sm);
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
}
.tree__type--platform { background: var(--navy-100); color: var(--navy-700); }
.tree__type--module { background: var(--teal-100); color: var(--teal-700); }
.tree__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree__meta { flex: none; font-size: var(--fs-xs); color: var(--color-text-muted); }
[role="treeitem"][aria-expanded="false"] > .tree__children { display: none; }

/* أسباب القرار */
.explain-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--sp-2); }
.explain-item {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--color-border);
  border-inline-start: 3px solid var(--gray-300);
  border-radius: var(--radius);
  background: var(--color-surface);
  font-size: var(--fs-base);
}
.explain-item::before {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-block-start: 1px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  content: "i";
  background: var(--gray-600);
}
.explain-item__body { flex: 1; min-width: 0; }
.explain-item__title { display: block; font-weight: 600; }
.explain-item__meta { display: block; font-size: var(--fs-xs); color: var(--color-text-muted); margin-block-start: 2px; }
.explain-item--allow { border-inline-start-color: var(--color-success); }
.explain-item--allow::before { content: "✓"; background: var(--color-success); }
.explain-item--deny { border-inline-start-color: var(--color-danger); background: #FFFBFA; }
.explain-item--deny::before { content: "✕"; background: var(--color-danger); }
.explain-item--info { border-inline-start-color: var(--color-info); }
.explain-item--info::before { content: "i"; background: var(--color-info); }
.explain-item--warning { border-inline-start-color: #C98A1B; }
.explain-item--warning::before { content: "!"; background: #B26A00; }

/* الشيفرة / التجزئة */
.code {
  display: block;
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  background: var(--navy-950);
  color: #D7E1EE;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  direction: ltr;
  text-align: left;
  white-space: pre;
  tab-size: 2;
}
.code--inline, code.code:not(pre code) {
  display: inline;
  padding: 1px 6px;
  background: var(--gray-100);
  color: var(--gray-900);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.86em;
  white-space: nowrap;
}
.code--wrap { white-space: pre-wrap; word-break: break-all; }
.mono { font-family: var(--font-mono); font-size: 0.92em; direction: ltr; unicode-bidi: isolate; }
.hash { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--color-text-muted); direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-strong { font-weight: 600; }
.ltr, time, .date { direction: ltr; unicode-bidi: isolate; }
.data-table td time, .kv time { display: inline-block; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 15. المصفوفة ---------- */
.matrix-wrap { max-height: 72vh; overflow: auto; }
.matrix {
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
  width: 100%;
  min-width: 860px;          /* عمود أول 220 + 8 عمليات × 80 */
  table-layout: fixed;       /* أعمدة العمليات متساوية بغض النظر عن محتوى الخلايا */
}
.matrix thead th:first-child { width: 220px; }
.matrix thead th { overflow: hidden; text-overflow: ellipsis; }
.matrix td { overflow: hidden; }
.matrix th, .matrix td {
  border-block-end: 1px solid var(--color-border);
  border-inline-end: 1px solid var(--color-border);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}
.matrix thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  padding: var(--sp-2) var(--sp-2);
  min-width: 72px;
  background: var(--gray-50);
  color: var(--color-text-soft);
  font-weight: 600;
  white-space: nowrap;
}
.matrix thead tr + tr th { inset-block-start: 37px; font-weight: 500; font-size: var(--fs-xs); }
.matrix tbody th, .matrix thead th:first-child {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  min-width: 220px;
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-surface);
  text-align: start;
  font-weight: 600;
  color: var(--color-text);
  border-inline-end: 2px solid var(--color-border-strong);
}
.matrix thead th:first-child { z-index: 3; background: var(--gray-50); }
.matrix tbody th .cell-sub { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--color-text-muted); }
.matrix tbody tr:hover th, .matrix tbody tr:hover td { background-color: #F8FAFC; }
.matrix__group th { background: var(--gray-100) !important; color: var(--color-text-soft); font-size: var(--fs-xs); text-align: start; padding: 6px var(--sp-3); }
.matrix__cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-width: 56px;
  min-height: 36px;
  padding: 4px;
  border: 0;
  background: transparent;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--color-text-muted);
}
td.matrix__cell { display: table-cell; padding: 8px 4px; }
.matrix__cell::before { font-size: 13px; font-weight: 700; line-height: 1; }
.matrix__cell.cell--allow { background: var(--color-success-bg); color: var(--color-success); }
.matrix__cell.cell--allow::before { content: "✓"; }
.matrix__cell.cell--deny { background: var(--color-danger-bg); color: var(--color-danger); }
.matrix__cell.cell--deny::before { content: "✕"; }
.matrix__cell.cell--conditional { background: var(--color-warning-bg); color: var(--color-warning); }
.matrix__cell.cell--conditional::before { content: "◐"; }
.matrix__cell.cell--none { background: transparent; color: var(--gray-400); }
.matrix__cell.cell--none::before { content: "—"; font-weight: 400; }
button.matrix__cell { cursor: pointer; transition: box-shadow var(--dur-fast) var(--ease), filter var(--dur-fast) var(--ease); }
button.matrix__cell:hover { box-shadow: inset 0 0 0 2px var(--navy-600); }
button.matrix__cell:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -3px; border-radius: 0; }
button.matrix__cell.is-changed { box-shadow: inset 0 0 0 2px var(--gold-600); }
.matrix-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); margin-block-end: var(--sp-3); font-size: var(--fs-sm); color: var(--color-text-soft); }
.matrix-legend > span:not(.matrix__cell) { display: inline-flex; align-items: center; gap: 6px; }
/* الشكلان مدعومان: <span class="matrix__cell cell--allow">سماح</span> (رمز + نص كشارة صغيرة) أو خلية فارغة كعينة بجانب نص */
.matrix-legend .matrix__cell {
  display: inline-flex;
  flex: none;
  width: auto;
  min-width: 26px;
  min-height: 24px;
  padding: 0 var(--sp-2);
  gap: 6px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  line-height: 1;
  white-space: nowrap;
}
.matrix-legend .matrix__cell.cell--none { border: 1px dashed var(--color-border-strong); }

/* ---------- 16. محرر الشروط ---------- */
.cond-group {
  --cond-color: var(--navy-600);
  --cond-bg: #F5F8FC;
  position: relative;
  padding: var(--sp-3);
  border: 1px solid var(--color-border);
  border-inline-start: 4px solid var(--cond-color);
  border-radius: var(--radius-md);
  background: var(--cond-bg);
}
.cond-group--and { --cond-color: var(--navy-600); --cond-bg: #F5F8FC; }
.cond-group--or { --cond-color: var(--teal-600); --cond-bg: #F2FAF9; }
.cond-group--not { --cond-color: var(--color-danger); --cond-bg: #FFF8F7; }
.cond-group__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-block-end: var(--sp-3);
}
.cond-group__op {
  width: auto;
  min-width: 96px;
  min-height: 30px;
  padding-block: 3px;
  font-weight: 700;
  color: var(--cond-color);
  border-color: var(--cond-color);
}
.cond-group__label { font-size: var(--fs-sm); color: var(--color-text-muted); }
.cond-group__actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-inline-start: auto; }
.cond-not {
  min-height: 30px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-soft);
  font-size: var(--fs-sm);
  font-weight: 700;
}
.cond-not[aria-pressed="true"] { background: var(--color-danger); border-color: var(--color-danger); color: #fff; }
.cond-children { --join-color: var(--cond-color); display: flex; flex-direction: column; gap: var(--sp-5); }
.cond-children > .cond-group { background: var(--color-surface); }
.cond-children > * + *::before { /* موصل منطقي بين الأبناء */
  content: attr(data-join);
  position: absolute;
  inset-block-start: calc(-1 * var(--sp-5) / 2 - 9px);
  inset-inline-start: var(--sp-4);
  padding: 0 6px;
  border-radius: var(--radius-sm);
  background: var(--join-color);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
}
.cond-children > *:not([data-join])::before { display: none; }
.cond-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(140px, 1.3fr) minmax(110px, 0.8fr) minmax(140px, 1.4fr) auto;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.cond-row .input { min-height: 32px; padding-block: 4px; font-size: var(--fs-sm); }
.cond-row.has-error { border-color: var(--color-danger); }
.cond-row__error { grid-column: 1 / -1; font-size: var(--fs-xs); color: var(--color-danger); font-weight: 600; }
.cond-limit { font-size: var(--fs-xs); color: var(--color-text-muted); }

/* ---------- 17. شاشات الدخول (تسجيل الدخول / تغيير كلمة المرور) ----------
   Mobile-first: الأساس للهاتف الصغير، ثم min-width/orientation صعودًا.
   هاتف: شريط هوية مضغوط + بطاقة الدخول هي العنصر الأبرز. لوحي عمودي: مكدّس.
   لوحي أفقي/حاسوب: عمودان بحافة مائلة. هاتف أفقي: عمودان مضغوطان.
   كل الزخارف CSS/SVG محلية (متوافقة مع CSP)، والحركة تحترم prefers-reduced-motion. */
.login-page {
  --auth-bg: #F3F6FA;
  --auth-line: rgba(22, 58, 99, 0.075);
  --auth-card: #FFFFFF;
  --auth-card-border: rgba(11, 31, 58, 0.07);
  --auth-card-shadow: 0 28px 56px -28px rgba(11, 31, 58, 0.28), 0 2px 6px rgba(11, 31, 58, 0.05);
  --auth-input-bg: #FFFFFF;
  --auth-placeholder: #667387; /* 4.7:1 على الأبيض */
  --auth-focus: var(--navy-600);
  --auth-focus-ring: 0 0 0 4px rgba(31, 76, 127, 0.18);
  --auth-link: var(--navy-600);
  --auth-btn: var(--navy-800);
  --auth-btn-hover: var(--navy-900);
  --auth-note-bg: #EEF4FB;
  --auth-note-border: #CBDBEE;
  --auth-value-icon: var(--navy-600);
  --auth-hero-muted: #A9B8CC; /* ≥ 7:1 على الكحلي */
  --auth-slant: 24px;
  --auth-gutter: var(--sp-4);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--auth-bg);
  color: var(--color-text);
}
.login-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

/* — اللوحة التعريفية (شريط هوية على الهاتف) — */
.auth-hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--auth-gutter) calc(var(--auth-slant) + var(--sp-10));
  color: #C9D3E1;
  background:
    radial-gradient(60% 50% at 22% 58%, rgba(95, 208, 201, 0.12), transparent 70%),
    radial-gradient(40% 35% at 85% 8%, rgba(212, 179, 106, 0.08), transparent 70%),
    linear-gradient(165deg, #10294A 0%, #0B1F3A 48%, #071427 100%);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--auth-slant)), 0 100%);
}
[dir="ltr"] .auth-hero { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 calc(100% - var(--auth-slant))); }
.auth-hero::before { /* شبكة تقنية خافتة */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(159, 200, 240, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(159, 200, 240, 0.055) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(75% 70% at 30% 60%, #000 20%, transparent 80%);
  -webkit-mask-image: radial-gradient(75% 70% at 30% 60%, #000 20%, transparent 80%);
}

.auth-brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.auth-brand__mark {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  color: var(--teal-400);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14), 0 8px 20px -8px rgba(0, 0, 0, 0.5);
}
.auth-brand__mark svg { width: 24px; height: 24px; }
.auth-brand__text { display: flex; flex-direction: column; min-width: 0; }
.auth-brand__name { font-size: var(--fs-md); font-weight: 700; color: #FFFFFF; line-height: 1.35; }
.auth-brand__sub { font-size: var(--fs-sm); color: var(--auth-hero-muted); line-height: 1.5; }

.auth-hero__body { flex: 1; display: flex; align-items: center; min-width: 0; }
.auth-hero__copy { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%; }
.auth-hero__rule { display: block; width: 40px; height: 3px; border-radius: 2px; background: var(--gold-400); margin-block-end: var(--sp-3); }
.auth-hero__title {
  margin: 0;
  color: #FFFFFF;
  font-size: clamp(1.25rem, 0.9rem + 1.6vw, 1.5rem);
  font-weight: 700;
  line-height: 1.4;
  text-wrap: balance;
}
.auth-hero__lead { display: none; margin: var(--sp-3) 0 0; max-width: 60ch; font-size: 1rem; line-height: 1.85; color: #C7D2E1; text-wrap: pretty; }
.auth-features { display: none; list-style: none; margin: var(--sp-8) 0 0; padding: 0; flex-direction: column; gap: var(--sp-4); }
.auth-feature { display: flex; align-items: center; gap: var(--sp-4); }
.auth-feature__icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-lg);
  color: var(--teal-400);
  background: rgba(255, 255, 255, 0.045);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.auth-feature__icon svg { width: 22px; height: 22px; }
.auth-feature__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.auth-feature__title { font-size: var(--fs-md); font-weight: 600; color: #FFFFFF; line-height: 1.5; }
.auth-feature__desc { font-size: var(--fs-sm); color: var(--auth-hero-muted); line-height: 1.6; }

.auth-hero__art { display: none; }
.auth-art { width: 100%; height: auto; filter: drop-shadow(0 30px 40px rgba(0, 0, 0, 0.35)); }
.auth-art__float { transform-box: fill-box; transform-origin: center; animation: auth-float 7s ease-in-out infinite; }
.auth-art__float--b { animation-delay: -2.3s; }
.auth-art__float--c { animation-delay: -4.6s; }
@keyframes auth-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.auth-hero__foot {
  display: none;
  margin: 0;
  max-width: 430px;
  padding-block-start: var(--sp-4);
  border-block-start: 1px solid rgba(255, 255, 255, 0.1);
  font-size: var(--fs-sm);
  color: var(--auth-hero-muted);
}

/* — لوحة الدخول — */
.auth-panel {
  position: relative;
  isolation: isolate;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0 var(--auth-gutter) var(--sp-8);
  min-width: 0;
}
.auth-panel::before { /* نمط معيّنات هندسي يتلاشى من الزاوية */
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background-image:
    repeating-linear-gradient(45deg, var(--auth-line) 0 1px, transparent 1px 36px),
    repeating-linear-gradient(-45deg, var(--auth-line) 0 1px, transparent 1px 36px);
  mask-image: radial-gradient(circle at 0% 100%, #000 0%, transparent 70%);
  -webkit-mask-image: radial-gradient(circle at 0% 100%, #000 0%, transparent 70%);
}
.auth-panel__inner {
  position: relative;
  width: 100%;
  max-width: 460px;
  margin-block-start: calc(var(--sp-8) * -1);
}

.login-card {
  padding: clamp(20px, 5vw, 40px);
  background: var(--auth-card);
  border: 1px solid var(--auth-card-border);
  border-radius: 16px;
  box-shadow: var(--auth-card-shadow);
  animation: auth-card-in 360ms var(--ease) both;
}
@keyframes auth-card-in { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
.login-card__head { margin-block-end: var(--sp-5); }
.login-card__title { margin: 0; font-size: clamp(1.375rem, 1.1rem + 1.2vw, 1.75rem); font-weight: 700; line-height: 1.3; color: var(--color-text); }
.login-card__desc { margin: var(--sp-2) 0 0; font-size: var(--fs-base); line-height: 1.8; color: var(--color-text-muted); text-wrap: pretty; }
.login-card > .alert { margin-block-end: var(--sp-5); }

.auth-form > * + * { margin-block-start: var(--sp-5); }
.auth-form .field { gap: var(--sp-2); }
.auth-form .field__label { font-size: var(--fs-base); font-weight: 600; }
.auth-form .input {
  min-height: 52px;
  padding-inline: var(--sp-4);
  border-radius: 10px;
  background: var(--auth-input-bg);
  font-size: 1rem; /* ≥16px: يمنع تكبير iOS التلقائي */
}
.auth-form .input::placeholder { color: var(--auth-placeholder); opacity: 1; }
.auth-form .input:hover { border-color: var(--color-text-muted); }
.auth-form .input:focus { border-color: var(--auth-focus); box-shadow: var(--auth-focus-ring); }

.auth-input { position: relative; }
.auth-input__icon {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 14px;
  width: 20px;
  height: 20px;
  translate: 0 -50%;
  color: var(--auth-placeholder);
  pointer-events: none;
  transition: color var(--dur-fast) var(--ease);
}
.auth-input:focus-within .auth-input__icon { color: var(--auth-focus); }
/* الحقول ذات اتجاه ltr، لذا الحشوة فيزيائية: الأيقونة يمينًا وزر الإظهار يسارًا */
.auth-form .auth-input .input { padding-right: 46px; }
.auth-form .auth-input--pw .input { padding-left: 54px; }
.auth-input__toggle {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: 4px;
  translate: 0 -50%;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.auth-input__toggle:hover { background: var(--color-surface-2); color: var(--color-text); }
.auth-input__toggle:focus-visible { outline: 2px solid var(--auth-focus); outline-offset: -2px; }
.auth-input__toggle svg { width: 20px; height: 20px; }
.auth-input__toggle[aria-pressed="false"] .is-hide,
.auth-input__toggle[aria-pressed="true"] .is-show { display: none; }

.auth-form .auth-form__row { display: flex; justify-content: flex-start; margin-block-start: var(--sp-1); }
.auth-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--sp-1);
  margin-inline-start: calc(var(--sp-1) * -1);
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--auth-link);
  font-size: var(--fs-md);
  font-weight: 600;
  text-underline-offset: 4px;
  transition: color var(--dur-fast) var(--ease);
}
.auth-link:hover, .auth-link[aria-expanded="true"] { text-decoration: underline; }
.auth-link:focus-visible { outline: 2px solid var(--auth-focus); outline-offset: 0; }

.auth-form .auth-note { margin-block-start: var(--sp-1); }
.auth-note {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--auth-note-border);
  border-radius: var(--radius-lg);
  background: var(--auth-note-bg);
  color: var(--color-text-soft);
  font-size: var(--fs-sm);
  line-height: 1.75;
  animation: auth-note-in var(--dur) var(--ease);
}
.auth-note:focus-visible { outline: 2px solid var(--auth-focus); outline-offset: 2px; border-radius: var(--radius-lg); }
.auth-note__icon { flex: none; color: var(--auth-link); margin-block-start: 3px; }
.auth-note__icon svg { width: 18px; height: 18px; }
.auth-note__body { flex: 1; min-width: 0; padding-block-start: 2px; }
.auth-note__title { margin: 0 0 2px; font-size: var(--fs-base); font-weight: 700; color: var(--color-text); }
.auth-note p { margin: 0; }
.auth-note strong { color: var(--color-text); font-weight: 600; }
.auth-note__close {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-block: -8px;
  margin-inline-end: -12px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
}
.auth-note__close:hover { background: rgba(11, 31, 58, 0.06); color: var(--color-text); }
.auth-note__close:focus-visible { outline: 2px solid var(--auth-focus); outline-offset: -2px; }
.auth-note__close svg { width: 16px; height: 16px; }
@keyframes auth-note-in { from { opacity: 0; translate: 0 -4px; } to { opacity: 1; translate: 0 0; } }

.auth-form .auth-submit {
  gap: var(--sp-2);
  min-height: 52px;
  margin-block-start: var(--sp-6);
  border-radius: 10px;
  background: var(--auth-btn);
  border-color: var(--auth-btn);
  color: #FFFFFF;
  font-size: 1rem;
  font-weight: 700;
  box-shadow: 0 10px 20px -12px rgba(11, 31, 58, 0.6);
  transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), translate var(--dur) var(--ease);
}
.auth-form .auth-submit:hover { background: var(--auth-btn-hover); border-color: var(--auth-btn-hover); box-shadow: 0 14px 24px -12px rgba(11, 31, 58, 0.7); translate: 0 -1px; }
.auth-form .auth-submit:active { translate: 0 0; }
.auth-form .auth-submit:focus-visible { outline: 2px solid var(--auth-focus); outline-offset: 3px; }
/* حالة التحميل: يبقى الزر بلونه مع مؤشر دوران (لا يتحول إلى رمادي "معطّل") */
.auth-form .auth-submit.is-loading, .auth-form .auth-submit[aria-busy="true"] { background: var(--auth-btn); border-color: var(--auth-btn); cursor: progress; translate: 0 0; }
.auth-submit .auth-submit__icon { width: 20px; height: 20px; }
[dir="rtl"] .auth-submit__icon { transform: scaleX(-1); }
.auth-form .btn--ghost { min-height: 44px; margin-block-start: var(--sp-2); }

.auth-values {
  list-style: none;
  margin: var(--sp-6) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.auth-value {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding-inline: var(--sp-2);
  text-align: center;
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--color-text-soft);
}
.auth-value + .auth-value { border-inline-start: 1px solid var(--color-border-strong); }
.auth-value__icon { color: var(--auth-value-icon); }
.auth-value__icon svg { width: 22px; height: 22px; }
.auth-panel__foot { margin: var(--sp-6) 0 0; text-align: center; font-size: var(--fs-xs); color: var(--color-text-muted); }

/* — هاتف كبير / لوحي صغير (≥ 480px) — */
@media (min-width: 480px) {
  .login-page { --auth-gutter: var(--sp-6); --auth-slant: 32px; }
  .auth-value { font-size: var(--fs-sm); }
  .auth-value__icon svg { width: 24px; height: 24px; }
}

/* — لوحي عمودي (≥ 640px): الوصف يظهر، البطاقة تتوسط — */
@media (min-width: 640px) {
  .login-page { --auth-gutter: var(--sp-8); --auth-slant: 44px; }
  .auth-hero { padding-block: var(--sp-8) calc(var(--auth-slant) + var(--sp-12)); gap: var(--sp-6); }
  .auth-brand__mark { width: 52px; height: 52px; }
  .auth-brand__mark svg { width: 28px; height: 28px; }
  .auth-brand__name { font-size: var(--fs-lg); }
  .auth-hero__rule { width: 56px; margin-block-end: var(--sp-4); }
  .auth-hero__title { font-size: 2rem; max-width: 20ch; }
  .auth-hero__lead { display: block; }
  .auth-panel { padding-block-end: var(--sp-10); }
  .auth-panel__inner { margin-block-start: calc(var(--sp-12) * -1); }
  .login-card { border-radius: 20px; }
  .login-card__desc { font-size: var(--fs-md); }
  .auth-values { margin-block-start: var(--sp-8); }
}

/* — لوحي عمودي طويل (iPad Pro عمودي): الميزات تظهر كصف من ثلاثة — */
@media (min-width: 768px) and (min-height: 1200px) and (orientation: portrait) {
  .auth-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-5); margin-block-start: var(--sp-6); }
  .auth-feature { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
  .auth-panel__inner { max-width: 500px; }
}

/* — عمودان: لوحي أفقي / حاسوب (≥ 1024px أفقي أو ≥ 1280px) — */
@media (min-width: 1024px) and (orientation: landscape), (min-width: 1280px) {
  .login-page { --auth-slant: 64px; --auth-gutter: var(--sp-10); }
  .login-main { grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr); grid-template-rows: none; }
  .auth-hero {
    gap: var(--sp-8);
    padding: var(--sp-10) var(--sp-10) var(--sp-8);
    padding-inline-end: calc(var(--auth-slant) + var(--sp-6));
    clip-path: polygon(var(--auth-slant) 0, 100% 0, 100% 100%, 0 100%);
  }
  [dir="ltr"] .auth-hero { clip-path: polygon(0 0, calc(100% - var(--auth-slant)) 0, 100% 100%, 0 100%); }
  .auth-hero__copy { max-width: 430px; }
  .auth-hero__title { font-size: clamp(1.875rem, 0.9rem + 1.6vw, 2.75rem); max-width: 14ch; line-height: 1.32; }
  .auth-hero__lead { margin-block-start: var(--sp-5); max-width: 44ch; }
  .auth-features { display: flex; margin-block-start: var(--sp-8); }
  .auth-hero__foot { display: block; }
  .auth-panel { align-items: center; padding: var(--sp-10) var(--auth-gutter); }
  .auth-panel::before { mask-image: radial-gradient(circle at 0% 100%, #000 0%, transparent 52%); -webkit-mask-image: radial-gradient(circle at 0% 100%, #000 0%, transparent 52%); }
  .auth-panel::after { /* توهج هادئ خلف البطاقة */
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: radial-gradient(50% 40% at 50% 42%, rgba(95, 208, 201, 0.08), transparent 70%);
  }
  .auth-panel__inner { margin-block-start: 0; }
  .auth-panel__foot { display: none; }
}
/* لوحي أفقي قصير (1024×768): ضغط الإيقاع العمودي ليبقى كل شيء ظاهرًا */
@media (min-width: 1024px) and (orientation: landscape) and (max-height: 820px) {
  .auth-hero { gap: var(--sp-6); padding-block: var(--sp-8) var(--sp-6); }
  .auth-hero__lead { line-height: 1.75; }
  .auth-features { gap: var(--sp-3); margin-block-start: var(--sp-6); }
}

/* — حاسوب (≥ 1280px): الرسم التوضيحي يعود حيث تتسع المساحة — */
@media (min-width: 1280px) {
  .login-main { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
  .login-page { --auth-gutter: var(--sp-12); --auth-slant: 72px; }
  .auth-hero { padding: var(--sp-12) var(--sp-12) var(--sp-10); padding-inline-end: calc(var(--auth-slant) + var(--sp-6)); }
  .auth-hero__copy { max-width: 400px; }
  .auth-hero__art {
    display: block;
    position: absolute;
    z-index: 0;
    inset-block-start: 50%;
    inset-inline-end: var(--sp-2);
    width: min(36%, 460px);
    translate: 0 -46%;
    pointer-events: none;
  }
}
@media (min-width: 1440px) {
  .auth-hero__copy { max-width: 430px; }
  .auth-hero__art { width: min(38%, 460px); }
}
/* — شاشات عريضة (≥ 1920px): المحتوى مقيّد ومتمركز داخل كل لوحة — */
@media (min-width: 1920px) {
  .login-main { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
  .auth-hero { padding-inline-start: max(var(--sp-16), calc((100% - 1000px) / 2)); }
  .auth-hero__art { inset-inline-end: max(var(--sp-6), calc((100% - 1000px) / 2 - 40px)); width: 460px; }
  .auth-hero__title { font-size: 3rem; }
  .auth-panel__inner { max-width: 480px; }
}

/* — هاتف أفقي / تكبير 200% (عرض ≥ 640 وارتفاع قصير): عمودان مضغوطان، النموذج قابل للتمرير — */
@media (orientation: landscape) and (min-width: 640px) and (max-height: 560px) {
  .login-page { --auth-slant: 28px; --auth-gutter: var(--sp-6); }
  .login-main { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr); grid-template-rows: none; }
  .auth-hero {
    gap: var(--sp-4);
    padding: var(--sp-5) var(--sp-5) var(--sp-5);
    padding-inline-end: calc(var(--auth-slant) + var(--sp-4));
    clip-path: polygon(var(--auth-slant) 0, 100% 0, 100% 100%, 0 100%);
  }
  [dir="ltr"] .auth-hero { clip-path: polygon(0 0, calc(100% - var(--auth-slant)) 0, 100% 100%, 0 100%); }
  .auth-hero__body { align-items: flex-start; }
  .auth-brand__mark { width: 44px; height: 44px; }
  .auth-brand__mark svg { width: 24px; height: 24px; }
  .auth-brand__name { font-size: var(--fs-md); }
  .auth-hero__title { font-size: 1.375rem; max-width: 14ch; }
  .auth-hero__lead, .auth-features, .auth-hero__art { display: none; }
  .auth-hero__foot { display: block; max-width: none; font-size: var(--fs-xs); }
  .auth-panel { align-items: flex-start; padding: var(--sp-4) var(--auth-gutter) var(--sp-6); }
  .auth-panel__inner { margin-block-start: 0; }
  .auth-panel::after { content: none; }
  .login-card { padding: var(--sp-5); border-radius: 16px; }
  .login-card__head { margin-block-end: var(--sp-4); }
  .auth-form > * + * { margin-block-start: var(--sp-4); }
  .auth-form .auth-form__row, .auth-form .auth-note { margin-block-start: var(--sp-1); }
  .auth-values, .auth-panel__foot { display: none; }
}

/* — الوضع الداكن (محصور بشاشات الدخول) — */
@media (prefers-color-scheme: dark) {
  .login-page {
    --auth-bg: #08152A;
    --auth-line: rgba(159, 200, 240, 0.06);
    --auth-card: #0F213B;
    --auth-card-border: rgba(255, 255, 255, 0.08);
    --auth-card-shadow: 0 28px 56px -24px rgba(0, 0, 0, 0.6);
    --auth-input-bg: #0A1A31;
    --auth-placeholder: #8EA0B8;
    --auth-focus: #7FB6EA;
    --auth-focus-ring: 0 0 0 4px rgba(127, 182, 234, 0.22);
    --auth-link: #8EC5F0;
    --auth-btn: #2A5D96;
    --auth-btn-hover: #336BA8;
    --auth-note-bg: rgba(127, 182, 234, 0.08);
    --auth-note-border: rgba(127, 182, 234, 0.28);
    --auth-value-icon: var(--teal-400);
    --color-surface: #0F213B;
    --color-surface-2: #17304F;
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-strong: #2C4769;
    --color-text: #E8EEF6;
    --color-text-muted: #A3B3C9;
    --color-text-soft: #C3CFDE;
    --gray-400: #8193AB;
    color-scheme: dark;
  }
  .login-page .auth-hero { background:
    radial-gradient(60% 50% at 22% 58%, rgba(95, 208, 201, 0.1), transparent 70%),
    linear-gradient(165deg, #0D2342 0%, #091A31 50%, #050F1F 100%); }
  .login-page .auth-note__close:hover { background: rgba(255, 255, 255, 0.08); }
  .login-page .alert--danger { background: rgba(240, 82, 66, 0.12); border-color: rgba(243, 184, 177, 0.3); border-inline-start-color: #F07A6E; color: #FFC9C2; }
  .login-page .alert--info { background: rgba(127, 182, 234, 0.1); border-color: rgba(127, 182, 234, 0.3); border-inline-start-color: #7FB6EA; color: #CFE3F7; }
  .login-page .password-rules li.is-ok, .login-page .password-rules li.is-ok::before { color: #6FD9A2; }
}

@media (prefers-reduced-motion: reduce) {
  .auth-art__float, .auth-note, .login-card { animation: none; }
  .auth-form .auth-submit:hover { translate: none; }
}
@media (forced-colors: active) {
  .login-card, .auth-note { border: 1px solid CanvasText; }
  .auth-hero { clip-path: none; }
}

.password-rules { margin: var(--sp-2) 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); color: var(--color-text-muted); }
.password-rules li { display: flex; align-items: center; gap: 6px; }
.password-rules li::before { content: "○"; color: var(--gray-400); }
.password-rules li.is-ok { color: var(--color-success); }
.password-rules li.is-ok::before { content: "✓"; color: var(--color-success); }

/* ---------- 18. المؤشرات ---------- */
.bar {
  position: relative;
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--gray-200);
}
.bar--sm { height: 6px; }
.bar__fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--color-accent);
  transition: width var(--dur-slow) var(--ease);
}
.bar__fill--success { background: var(--color-success); }
.bar__fill--warning { background: #C98A1B; }
.bar__fill--danger { background: var(--color-danger); }
.bar__fill--primary { background: var(--navy-600); }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label num" "bar bar"; align-items: center; gap: 6px var(--sp-3); font-size: var(--fs-sm); }
.bar-row > :first-child { grid-area: label; min-width: 0; }
.bar-row > .bar { grid-area: bar; }
.bar-row > .num { grid-area: num; }
.bar-row + .bar-row { margin-block-start: var(--sp-4); }
.bar-row .num { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }

.w-0 { width: 0%; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; } .w-20 { width: 20%; }
.w-25 { width: 25%; } .w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; } .w-45 { width: 45%; }
.w-50 { width: 50%; } .w-55 { width: 55%; } .w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; }
.w-75 { width: 75%; } .w-80 { width: 80%; } .w-85 { width: 85%; } .w-90 { width: 90%; } .w-95 { width: 95%; }
.w-100 { width: 100%; }

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-block-start-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
.spinner--lg { width: 32px; height: 32px; border-width: 3px; }
.loading-block { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-10); color: var(--color-text-muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  display: block;
  height: 12px;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--gray-100) 0%, var(--gray-200) 50%, var(--gray-100) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton + .skeleton { margin-block-start: var(--sp-2); }
.skeleton--title { height: 20px; width: 40%; }
.skeleton--block { height: 72px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* أنماط مساعدة للوحة */
.list-plain { margin: 0; padding: 0; list-style: none; }
.event-list { margin: 0; padding: 0; list-style: none; }
.event-list li { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-block-end: 1px solid var(--color-border); }
.event-list li:last-child { border-block-end: 0; }
.event-list__body { flex: 1; min-width: 0; }
.event-list__time { flex: none; font-size: var(--fs-xs); color: var(--color-text-muted); white-space: nowrap; }
.divider-v { width: 1px; align-self: stretch; background: var(--color-border); }

.profile-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-4); }
.profile-head__text { flex: 1; min-width: 0; }
.profile-head__name { font-size: var(--fs-xl); font-weight: 700; margin: 0; }
.profile-head__meta { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-block-start: var(--sp-1); font-size: var(--fs-sm); color: var(--color-text-muted); }

/* مصمم النماذج */
.builder { display: grid; grid-template-columns: 220px minmax(0, 1fr) 300px; gap: var(--sp-4); align-items: start; }
.builder__palette, .builder__props { position: sticky; inset-block-start: calc(var(--topbar-height) + var(--sp-4)); }
.palette-item {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%;
  min-height: 36px; padding: 6px var(--sp-3); margin-block-end: var(--sp-1);
  border: 1px dashed var(--color-border-strong); border-radius: var(--radius);
  background: var(--color-surface); color: var(--color-text); text-align: start; font-size: var(--fs-sm);
}
.palette-item:hover { border-style: solid; border-color: var(--color-accent); background: var(--teal-100); }
.field-card {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3); border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-surface);
}
.field-card + .field-card { margin-block-start: var(--sp-2); }
.field-card.is-selected { border-color: var(--color-accent); box-shadow: var(--ring); }
.field-card__handle { color: var(--gray-400); font-size: 14px; letter-spacing: -2px; cursor: grab; }
.field-card__name { font-weight: 600; }
.field-card__meta { display: block; font-size: var(--fs-xs); color: var(--color-text-muted); }
.perm-select { display: inline-flex; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.perm-select button { min-height: 28px; padding: 0 8px; border: 0; background: var(--color-surface); color: var(--color-text-muted); font-size: var(--fs-xs); font-weight: 600; }
.perm-select button + button { border-inline-start: 1px solid var(--color-border-strong); }
.perm-select button[aria-pressed="true"] { background: var(--navy-700); color: #fff; }

.state-flow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.state-flow__arrow { color: var(--gray-400); }
.state-flow__arrow::before { content: "←"; }

/* ---------- 19. التجاوب ---------- */
@media (max-width: 1280px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .builder { grid-template-columns: 200px minmax(0, 1fr); }
  .builder__props { grid-column: 1 / -1; position: static; }
}

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-aside { grid-template-columns: minmax(0, 1fr); }
  .kv--2col { grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); }
}

/* الشريط الجانبي يتحول لدرج من 960px وأقل (يشمل الجوال ≤640 والأجهزة اللوحية) */
@media (max-width: 960px) {
  .app-shell, [dir="ltr"] .app-shell { grid-template-columns: minmax(0, 1fr); background: none; }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(var(--sidebar-width), 86vw);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
    box-shadow: var(--shadow-lg);
  }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: none; visibility: visible; transition-delay: 0s; }
  .sidebar.is-open ~ .sidebar-backdrop, .sidebar-backdrop.is-open { display: block; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding-inline: var(--sp-4); gap: var(--sp-3); }
  .main { padding: var(--sp-5) var(--sp-4) var(--sp-10); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}

@media (max-width: 640px) {
  :root { --control-h: 40px; }
  body { font-size: var(--fs-md); }
  .topbar__user-text { display: none; }
  /* صف 1: زر القائمة (البداية = يمين) ثم الوسم … المستخدم وإجراءاته (النهاية) · صف 2: البحث */
  .topbar { flex-wrap: wrap; row-gap: var(--sp-2); column-gap: var(--sp-2); padding-block: var(--sp-2); }
  .topbar .menu-toggle { order: 0; }
  .topbar__end { display: contents; }
  .topbar__end > .demo-badge { order: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
  .topbar__end > .topbar__user { order: 2; margin-inline-start: auto; padding: 0; }
  .topbar__end > .btn { order: 3; padding-inline: var(--sp-2); }
  .topbar__search { order: 10; flex: 1 0 100%; max-width: none; }
  .topbar .demo-badge { padding: 2px 8px; }
  .main { padding: var(--sp-4) var(--sp-4) var(--sp-10); }
  .page-header { flex-direction: column; align-items: stretch; margin-block-end: var(--sp-5); }
  .page-header__text { flex-basis: auto; }
  .page-header__title { font-size: var(--fs-xl); }
  .page-header__actions .btn { flex: 1 1 auto; }
  .grid-3, .grid-4, .form-grid, .form-grid--3, .drawer__body .form-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .kpi { padding: var(--sp-3) var(--sp-4); }
  .kpi__value { font-size: var(--fs-2xl); }
  .card__header, .card__body { padding-inline: var(--sp-4); }
  .card__body { padding-block: var(--sp-4); }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .input, .filters .input[type="search"] { flex: 0 0 auto; width: 100%; max-width: none; min-width: 0; }
  .toolbar__actions .btn { flex: 1 1 auto; }
  .toolbar > .input, .toolbar > div:not(.filters):not(.toolbar__actions) > .input { width: 100%; max-width: none; min-width: 0; }
  .nav-link { min-height: 44px; }
  .btn--sm { min-height: 36px; }
  .btn--icon.btn--sm { width: 36px; }
  .tab { min-height: 44px; }
  .tree__node { min-height: 42px; }
  .chip__remove { width: 28px; height: 28px; }
  .checkbox, .radio, .switch { min-height: 40px; align-items: center; }
  .checkbox input, .radio input { width: 20px; height: 20px; margin-block-start: 0; }
  .drawer__panel, .drawer--wide .drawer__panel { width: 100%; }
  .drawer__footer .btn, .modal__footer .btn { flex: 1 1 auto; }
  .modal { align-items: flex-end; padding: 0; }
  .modal__dialog { width: 100%; max-height: 92dvh; border-end-start-radius: 0; border-end-end-radius: 0; }
  .form-actions .btn { flex: 1 1 auto; }
  .kv, .kv--2col { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-block-end: var(--sp-2); }
  .cond-row { grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr) auto; }
  .cond-row > :nth-child(1) { grid-column: 1 / 3; grid-row: 1; }
  .cond-row > :nth-child(4) { grid-column: 3; grid-row: 1; }
  .cond-row > :nth-child(2) { grid-column: 1; grid-row: 2; }
  .cond-row > :nth-child(3) { grid-column: 2 / 4; grid-row: 2; }
  .cond-row > .cond-row__error { grid-row: 3; }
  .cond-children .cond-children { margin-inline-start: 0; }
  .cond-group { padding: var(--sp-2); }
  .cond-group__actions { margin-inline-start: 0; width: 100%; }
  .decision { font-size: var(--fs-lg); }
  .matrix tbody th, .matrix thead th:first-child { min-width: 150px; }
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder__palette { position: static; }
  .pagination { justify-content: center; }
  .toast-region { inset-inline: var(--sp-4); inset-block-end: var(--sp-4); width: auto; }
  .stepper { overflow: visible; }
  .stepper .step { min-width: 0; padding-inline: 2px; font-size: 11px; line-height: 1.35; }
  .step::after { inset-inline-start: calc(50% + 16px); inset-inline-end: calc(-50% + 16px); }
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar .demo-badge { font-size: 11px; }
}

/* ---------- 20. تفضيلات الحركة والتباين والطباعة ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .skeleton { animation: none; }
}

@media (forced-colors: active) {
  .badge, .scope, .decision, .chip, .demo-badge, .matrix__cell, .explain-item, .cond-group { border: 1px solid CanvasText; }
  .nav-link.is-active { outline: 2px solid Highlight; }
  .bar__fill { background: Highlight; }
}

@media print {
  .sidebar, .sidebar-backdrop, .topbar, .page-header__actions, .toolbar, .pagination, .toast-region, .drawer, .modal, .menu-toggle { display: none !important; }
  .app-shell { display: block; }
  body { background: #fff; font-size: 11pt; }
  .main { padding: 0; max-width: none; }
  .card, .table-wrap { box-shadow: none; border-color: #999; break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .data-table thead th { position: static; }
  a { color: inherit; }
}
