/* =============================================================================
   Mororat Design System — "إداري واضح" (light) + "غرفة القيادة" (dark)
   One token set, two themes. Components read tokens only; no literal colors.
   Theme: <html data-theme="dark|light">, stored in localStorage "moi_theme".
   ============================================================================= */
@import url("/vendor/fonts/fonts.css");

:root {
  /* Surfaces */
  --c-bg: #f5f7f8;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafb;
  --c-sunken: #eef2f4;
  --c-line: #e2e8eb;
  --c-line-strong: #cfd8dd;
  /* Text */
  --c-text: #17262f;
  --c-text-2: #3f505b;
  --c-muted: #6f7f8a;
  /* Brand */
  --c-accent: #0f766e;
  --c-accent-hover: #0c6760;
  --c-accent-soft: #e2f2ef;
  --c-accent-text: #0b5f58;
  --c-on-accent: #ffffff;
  /* Status (separate from the accent) */
  --c-ok: #16855a;   --c-ok-soft: #e3f4ec;
  --c-warn: #a86a12; --c-warn-soft: #fbf0dc;
  --c-bad: #c0392f;  --c-bad-soft: #fbe7e5;
  --c-info: #2c5f99; --c-info-soft: #e5eef8;
  /* Drawer */
  --c-drawer: #ffffff;
  --c-drawer-hover: #eef3f4;
  /* Effects */
  --shadow-1: 0 1px 2px rgba(15, 30, 40, .05);
  --shadow-2: 0 4px 16px -4px rgba(15, 30, 40, .12);
  --shadow-pop: 0 24px 60px -16px rgba(10, 25, 35, .35);
  --scrim: rgba(20, 32, 40, .38);
  --focus: 0 0 0 3px color-mix(in srgb, var(--c-accent) 28%, transparent);

  /* Type */
  --f-ui: "Readex Pro", "Segoe UI", Tahoma, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .875rem; --fs-lg: 1rem; --fs-xl: 1.25rem; --fs-2xl: 1.6rem;
  /* Shape & space */
  --r-sm: 6px; --r-md: 9px; --r-lg: 12px; --r-pill: 999px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 24px; --s-8: 32px;
  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: .12s; --t-med: .22s; --t-slow: .35s;
  /* Shell */
  --drawer-w: 256px; --drawer-w-collapsed: 68px; --topbar-h: 56px;
  color-scheme: light;

  /* RGB channels of the tokens, for the compiled Tailwind layer (supports /opacity modifiers) */
  --rgb-bg: 245 247 248; --rgb-surface: 255 255 255; --rgb-surface-2: 248 250 251; --rgb-sunken: 238 242 244;
  --rgb-line: 226 232 235; --rgb-line-strong: 207 216 221; --rgb-text: 23 38 47; --rgb-text-2: 63 80 91; --rgb-muted: 111 127 138;
  --rgb-accent: 15 118 110; --rgb-accent-hover: 12 103 96; --rgb-on-accent: 255 255 255;
  --rgb-ok: 22 133 90; --rgb-warn: 168 106 18; --rgb-bad: 192 57 47; --rgb-info: 44 95 153;
}

:root[data-theme="dark"] {
  --c-bg: #0c131a;
  --c-surface: #121b24;
  --c-surface-2: #0f1720;
  --c-sunken: #0a1016;
  --c-line: #1f2b37;
  --c-line-strong: #2b3a48;
  --c-text: #e6ecf1;
  --c-text-2: #b6c2cc;
  --c-muted: #7f8d9a;
  --c-accent: #c9a24a;
  --c-accent-hover: #d9b45c;
  --c-accent-soft: rgba(201, 162, 74, .13);
  --c-accent-text: #e6c574;
  --c-on-accent: #12171d;
  --c-ok: #3fb68b;   --c-ok-soft: rgba(63, 182, 139, .14);
  --c-warn: #e0a43a; --c-warn-soft: rgba(224, 164, 58, .15);
  --c-bad: #e66a61;  --c-bad-soft: rgba(230, 106, 97, .14);
  --c-info: #6aa6dc; --c-info-soft: rgba(106, 166, 220, .14);
  --c-drawer: #0a1016;
  --c-drawer-hover: #141e28;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 6px 20px -6px rgba(0, 0, 0, .5);
  --shadow-pop: 0 28px 70px -14px rgba(0, 0, 0, .7);
  --scrim: rgba(3, 7, 11, .62);
  color-scheme: dark;

  --rgb-bg: 12 19 26; --rgb-surface: 18 27 36; --rgb-surface-2: 15 23 32; --rgb-sunken: 10 16 22;
  --rgb-line: 31 43 55; --rgb-line-strong: 43 58 72; --rgb-text: 230 236 241; --rgb-text-2: 182 194 204; --rgb-muted: 127 141 154;
  --rgb-accent: 201 162 74; --rgb-accent-hover: 217 180 92; --rgb-on-accent: 18 23 29;
  --rgb-ok: 63 182 139; --rgb-warn: 224 164 58; --rgb-bad: 230 106 97; --rgb-info: 106 166 220;
}

/* ---------------------------------------------------------------- Base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--c-bg); color: var(--c-text);
  font-family: var(--f-ui); font-size: var(--fs-md); line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.3; text-wrap: balance; font-weight: 600; }
a { color: var(--c-accent-text); }
code, kbd, .mono { font-family: var(--f-mono); }
.num { font-variant-numeric: tabular-nums; }
::selection { background: var(--c-accent-soft); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
[hidden], .hidden { display: none !important; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-4); border-radius: var(--r-md);
  border: 1px solid transparent; background: transparent; color: var(--c-text);
  font: 500 var(--fs-sm)/1 var(--f-ui); cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn svg, .btn i[data-lucide] { width: 16px; height: 16px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); color: var(--c-on-accent); }
.btn-primary:hover { background: var(--c-accent-hover); }
.btn-ghost { border-color: var(--c-line-strong); background: var(--c-surface); }
.btn-ghost:hover { border-color: var(--c-accent); color: var(--c-accent-text); }
.btn-danger { background: var(--c-bad-soft); color: var(--c-bad); }
.btn-danger:hover { background: color-mix(in srgb, var(--c-bad) 20%, transparent); }
.btn-quiet { color: var(--c-text-2); }
.btn-quiet:hover { background: var(--c-sunken); color: var(--c-text); }
.btn-sm { height: 30px; padding: 0 var(--s-3); font-size: var(--fs-xs); }
.btn-icon { width: 36px; padding: 0; }

/* ---------------------------------------------------------------- Forms */
.field { display: grid; gap: 4px; font-size: var(--fs-xs); font-weight: 500; color: var(--c-muted); }
.input, select.input, textarea.input {
  height: 36px; padding: 0 var(--s-3); border-radius: var(--r-md);
  border: 1px solid var(--c-line-strong); background: var(--c-surface); color: var(--c-text);
  font: 400 var(--fs-sm) var(--f-ui); min-width: 0;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
select.input[multiple] { height: auto; min-height: 84px; padding: var(--s-1); }
textarea.input { height: auto; padding: var(--s-2) var(--s-3); }
.input:focus { outline: none; border-color: var(--c-accent); box-shadow: var(--focus); }
.check { display: inline-flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--c-text-2); cursor: pointer; }
.check input { accent-color: var(--c-accent); width: 16px; height: 16px; }

/* ---------------------------------------------------------------- Surfaces */
.card {
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1); padding: var(--s-4); min-width: 0;
}
.card-title { font-size: var(--fs-lg); font-weight: 600; color: var(--c-text); }
.card-sub { font-size: var(--fs-xs); color: var(--c-muted); margin-top: 2px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.callout { border-radius: var(--r-md); padding: var(--s-3) var(--s-4); font-size: var(--fs-sm); border: 1px solid var(--c-line); background: var(--c-surface-2); }
.callout-ok { background: var(--c-ok-soft); border-color: color-mix(in srgb, var(--c-ok) 30%, transparent); color: var(--c-text); }
.callout-bad { background: var(--c-bad-soft); border-color: color-mix(in srgb, var(--c-bad) 30%, transparent); color: var(--c-text); }
.empty { padding: var(--s-6); text-align: center; color: var(--c-muted); font-size: var(--fs-sm); }

/* ---------------------------------------------------------------- Stat tiles */
.kpi-row { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.kpi { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg); padding: var(--s-3) var(--s-4); display: grid; gap: 2px; box-shadow: var(--shadow-1); }
.kpi > span { font-size: var(--fs-xs); color: var(--c-muted); }
.kpi > b { font-size: var(--fs-2xl); font-weight: 600; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi > small { font-size: var(--fs-xs); color: var(--c-muted); }

/* ---------------------------------------------------------------- Tables */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th {
  text-align: right; font-weight: 500; font-size: var(--fs-xs); color: var(--c-muted);
  padding: 9px var(--s-3); background: var(--c-surface-2); border-bottom: 1px solid var(--c-line); white-space: nowrap;
}
td { padding: 10px var(--s-3); border-bottom: 1px solid var(--c-line); vertical-align: top; }
tbody tr { transition: background var(--t-fast); }
tbody tr:hover td { background: color-mix(in srgb, var(--c-accent) 4%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td code { font-size: var(--fs-xs); color: var(--c-muted); direction: ltr; unicode-bidi: isolate; }

/* ---------------------------------------------------------------- Pills & badges */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 500; white-space: nowrap;
  background: var(--c-sunken); color: var(--c-text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.ok   { background: var(--c-ok-soft);   color: var(--c-ok); }
.pill.warn { background: var(--c-warn-soft); color: var(--c-warn); }
.pill.bad  { background: var(--c-bad-soft);  color: var(--c-bad); }
.pill.info { background: var(--c-info-soft); color: var(--c-info); }
.pill.muted { background: var(--c-sunken); color: var(--c-muted); }
.pill.plain::before { display: none; }
kbd {
  font-size: .7rem; padding: 0 5px; border-radius: 4px; border: 1px solid var(--c-line-strong);
  border-bottom-width: 2px; background: var(--c-surface); color: var(--c-muted);
}

/* ---------------------------------------------------------------- Tabs (in-page sections) */
.tabs { display: flex; gap: var(--s-1); flex-wrap: wrap; border-bottom: 1px solid var(--c-line); }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 10px var(--s-3); font-size: var(--fs-sm); font-weight: 500; color: var(--c-muted);
  cursor: pointer; border: 0; background: none; transition: color var(--t-fast);
}
.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-accent-text); }
.tab.active::after {
  content: ""; position: absolute; inset-inline: var(--s-2); bottom: -1px; height: 2px;
  border-radius: 2px; background: var(--c-accent); animation: tabIn var(--t-med) var(--ease);
}
@keyframes tabIn { from { transform: scaleX(.3); opacity: 0; } }

/* ---------------------------------------------------------------- Toast */
.toast-host { position: fixed; bottom: calc(var(--s-5) + env(safe-area-inset-bottom, 0px)); left: var(--s-5); z-index: 90; display: grid; gap: var(--s-2); }
.toast {
  display: flex; align-items: center; gap: var(--s-2); min-width: 240px; max-width: 420px;
  padding: 11px var(--s-4); border-radius: var(--r-md); font-size: var(--fs-sm);
  background: var(--c-text); color: var(--c-surface); box-shadow: var(--shadow-2);
  animation: toastIn var(--t-med) var(--ease);
}
.toast.bad { background: var(--c-bad); color: #fff; }
.toast.leaving { animation: toastOut var(--t-med) var(--ease) forwards; }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(8px); opacity: 0; } }

/* ---------------------------------------------------------------- Skeleton */
.skeleton { display: grid; gap: var(--s-2); padding: var(--s-2) 0; }
.skeleton i { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--c-sunken), var(--c-line), var(--c-sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.skeleton i:nth-child(2) { width: 80%; } .skeleton i:nth-child(3) { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- Shell: drawer + topbar */
body.ds-shell { display: grid; grid-template-columns: var(--drawer-w) 1fr; min-height: 100%; transition: grid-template-columns var(--t-slow) var(--ease); }
body.ds-shell.drawer-collapsed { grid-template-columns: var(--drawer-w-collapsed) 1fr; }
.ds-drawer {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto auto 1fr auto;
  background: var(--c-drawer); border-left: 1px solid var(--c-line); overflow: hidden; z-index: 30;
}
.ds-brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-4) var(--s-3); white-space: nowrap; text-decoration: none; color: var(--c-text); }
.ds-brand-mark {
  flex: none; width: 36px; height: 36px; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--c-accent); color: var(--c-on-accent); font-weight: 700; font-size: 1.05rem;
}
.ds-brand b { display: block; font-size: var(--fs-lg); font-weight: 600; }
.ds-brand small { display: block; font-size: var(--fs-xs); color: var(--c-muted); }
.ds-search-trigger {
  margin: 0 var(--s-3) var(--s-2); display: flex; align-items: center; gap: var(--s-2); height: 38px; padding: 0 var(--s-3);
  border-radius: var(--r-md); border: 1px solid var(--c-line); background: var(--c-surface-2); color: var(--c-muted);
  font: 400 var(--fs-sm) var(--f-ui); cursor: pointer; white-space: nowrap; overflow: hidden;
  transition: border-color var(--t-fast);
}
.ds-search-trigger:hover { border-color: var(--c-accent); }
.ds-search-trigger svg { flex: none; width: 16px; height: 16px; }
.ds-search-trigger kbd { margin-inline-start: auto; }
.ds-nav { overflow-y: auto; padding: var(--s-1) var(--s-3) var(--s-3); display: grid; gap: 2px; align-content: start; }
.ds-nav-group { font-size: .7rem; color: var(--c-muted); padding: var(--s-3) var(--s-2) var(--s-1); white-space: nowrap; }
.ds-nav-item {
  position: relative; display: flex; align-items: center; gap: var(--s-3); height: 38px; padding: 0 var(--s-3);
  border-radius: var(--r-md); color: var(--c-text-2); text-decoration: none; font-size: var(--fs-sm); white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.ds-nav-item svg { flex: none; width: 18px; height: 18px; }
.ds-nav-item:hover { background: var(--c-drawer-hover); color: var(--c-text); }
.ds-nav-item.active { background: var(--c-accent-soft); color: var(--c-accent-text); font-weight: 500; }
.ds-nav-item.active::before {
  content: ""; position: absolute; right: calc(-1 * var(--s-3)); top: 9px; bottom: 9px; width: 3px;
  border-radius: 3px 0 0 3px; background: var(--c-accent);
}
.ds-nav-item .badge { margin-inline-start: auto; font-size: .7rem; padding: 0 7px; border-radius: var(--r-pill); background: var(--c-accent-soft); color: var(--c-accent-text); font-family: var(--f-mono); }
.ds-drawer-foot { border-top: 1px solid var(--c-line); padding: var(--s-3); display: flex; align-items: center; gap: var(--s-2); white-space: nowrap; overflow: hidden; }
.ds-avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--c-sunken); color: var(--c-text-2); font-weight: 600; font-size: var(--fs-xs); }
.ds-user { min-width: 0; line-height: 1.35; font-size: var(--fs-xs); }
.ds-user b { display: block; font-weight: 500; color: var(--c-text); overflow: hidden; text-overflow: ellipsis; }
.ds-user span { color: var(--c-muted); }
body.drawer-collapsed .ds-brand > div, body.drawer-collapsed .ds-search-trigger span,
body.drawer-collapsed .ds-search-trigger kbd, body.drawer-collapsed .ds-nav-group, body.drawer-collapsed .ds-nav-item span,
body.drawer-collapsed .ds-nav-item .badge, body.drawer-collapsed .ds-user, body.drawer-collapsed .ds-drawer-foot .btn-label { display: none; }
body.drawer-collapsed .ds-search-trigger { justify-content: center; padding: 0; }
body.drawer-collapsed .ds-nav-item { justify-content: center; padding: 0; }

.ds-main { min-width: 0; display: grid; grid-template-rows: auto 1fr; }
.ds-topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-5); background: color-mix(in srgb, var(--c-bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px); border-bottom: 1px solid var(--c-line);
}
.ds-crumbs { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); color: var(--c-muted); min-width: 0; }
.ds-crumbs b { color: var(--c-text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-top-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s-2); }
.ds-live { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--c-muted); }
.ds-live i { width: 8px; height: 8px; border-radius: 50%; background: var(--c-ok); animation: livePulse 2.2s infinite; }
.ds-live.off i { background: var(--c-bad); animation: none; }
@keyframes livePulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-ok) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.ds-content { padding: var(--s-5) max(var(--s-5), env(safe-area-inset-right, 0px)) var(--s-8) max(var(--s-5), env(safe-area-inset-left, 0px)); display: grid; gap: var(--s-4); align-content: start; min-width: 0; animation: pageIn var(--t-slow) var(--ease); }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-3); }
.page-title { font-size: var(--fs-xl); font-weight: 600; }
.page-sub { font-size: var(--fs-sm); color: var(--c-muted); margin-top: 2px; }
.ds-scrim { display: none; }

@media (max-width: 900px) {
  body.ds-shell, body.ds-shell.drawer-collapsed { grid-template-columns: 1fr; }
  .ds-drawer { position: fixed; inset-block: 0; right: 0; width: min(86vw, var(--drawer-w)); transform: translateX(0); transition: transform var(--t-slow) var(--ease); box-shadow: var(--shadow-pop); }
  body.drawer-collapsed .ds-drawer { transform: translateX(105%); box-shadow: none; }
  body.drawer-collapsed .ds-brand > div, body.drawer-collapsed .ds-search-trigger span, body.drawer-collapsed .ds-nav-group,
  body.drawer-collapsed .ds-nav-item span, body.drawer-collapsed .ds-user { display: revert; }
  .ds-scrim { display: block; position: fixed; inset: 0; background: var(--scrim); z-index: 25; opacity: 1; transition: opacity var(--t-med); }
  body.drawer-collapsed .ds-scrim { opacity: 0; pointer-events: none; }
  .ds-topbar { padding: 0 var(--s-4); }
  .ds-live span { display: none; }
}

/* ---------------------------------------------------------------- Command palette */
.cmdk-backdrop {
  position: fixed; inset: 0; z-index: 80; background: var(--scrim); display: grid; place-items: start center;
  padding: 12vh var(--s-4) var(--s-4); opacity: 0; pointer-events: none; transition: opacity var(--t-med);
}
.cmdk-backdrop.open { opacity: 1; pointer-events: auto; }
.cmdk {
  width: min(620px, 100%); background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 14px;
  box-shadow: var(--shadow-pop); overflow: hidden; transform: translateY(-10px) scale(.985);
  transition: transform var(--t-med) var(--ease);
}
.cmdk-backdrop.open .cmdk { transform: none; }
.cmdk-input { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-4); border-bottom: 1px solid var(--c-line); }
.cmdk-input svg { flex: none; width: 18px; height: 18px; color: var(--c-muted); }
.cmdk-input input { flex: 1; height: 54px; border: 0; background: transparent; color: var(--c-text); font: 400 1rem var(--f-ui); outline: none; min-width: 0; }
.cmdk-list { max-height: min(420px, 55vh); overflow-y: auto; padding: var(--s-2); }
.cmdk-group { font-size: .7rem; color: var(--c-muted); padding: var(--s-2) var(--s-3) var(--s-1); }
.cmdk-item { display: flex; align-items: center; gap: var(--s-3); padding: 9px var(--s-3); border-radius: var(--r-md); cursor: pointer; font-size: var(--fs-md); }
.cmdk-item svg { flex: none; width: 17px; height: 17px; color: var(--c-muted); }
.cmdk-item .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item small { margin-inline-start: auto; color: var(--c-muted); font-size: var(--fs-xs); white-space: nowrap; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.cmdk-item mark { background: color-mix(in srgb, var(--c-accent) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.cmdk-item.sel { background: var(--c-accent-soft); color: var(--c-accent-text); }
.cmdk-item.sel svg { color: var(--c-accent-text); }
.cmdk-empty, .cmdk-loading { padding: var(--s-6); text-align: center; color: var(--c-muted); font-size: var(--fs-sm); }
.cmdk-foot { display: flex; gap: var(--s-4); padding: var(--s-2) var(--s-4); border-top: 1px solid var(--c-line); font-size: var(--fs-xs); color: var(--c-muted); background: var(--c-surface-2); }

/* ---------------------------------------------------------------- Layout utilities (small, intentional set) */
.stack { display: grid; gap: var(--s-4); align-content: start; }
.stack-sm { display: grid; gap: var(--s-2); align-content: start; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s-3); }
.row-center { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); }
.grid-2 { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.grow { flex: 1 1 auto; min-width: 0; }
.mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); } .mt-4 { margin-top: var(--s-4); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); }
.text-xs { font-size: var(--fs-xs); } .text-sm { font-size: var(--fs-sm); }
.text-muted { color: var(--c-muted); } .text-accent { color: var(--c-accent-text); } .text-danger { color: var(--c-bad); }
.text-center { text-align: center; } .nowrap { white-space: nowrap; } .break-all { word-break: break-all; }
.w-xs { width: 6rem; } .w-sm { width: 8rem; } .w-md { width: 11rem; } .w-lg { width: 15rem; } .w-xl { width: 20rem; max-width: 100%; }
.scroll-y { max-height: 24rem; overflow-y: auto; }
.select-all { user-select: all; }
.label-strong { font-size: var(--fs-xs); font-weight: 600; color: var(--c-text-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------------------------------------------------------------- Page-specific helpers (operations tools) */
.table-card { padding: var(--s-3); }
.list-row { padding: var(--s-1) 0; border-bottom: 1px solid var(--c-line); }
.key-code { font-family: var(--f-mono); font-size: var(--fs-lg); direction: ltr; unicode-bidi: isolate; }
td.group-row { padding-top: var(--s-4); font-weight: 600; background: transparent !important; }

/* ---------------------------------------------------------------- Feeds & device lists (operations room) */
.feed { display: grid; gap: 2px; align-content: start; }
.feed-item, .device-row {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; padding: 10px var(--s-2);
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--c-text); text-align: right;
  font: inherit; cursor: default; transition: background var(--t-fast);
}
.feed-item { cursor: pointer; animation: feedIn var(--t-slow) var(--ease); }
.feed-item:hover { background: var(--c-surface-2); }
.feed-item.badge-scan-flash, .feed-item.is-new { background: var(--c-accent-soft); }
@keyframes feedIn { from { opacity: 0; transform: translateY(-4px); } }
.feed-time { flex: none; width: 3.6rem; font-size: var(--fs-xs); color: var(--c-muted); }
.feed-body { flex: 1; min-width: 0; display: grid; line-height: 1.35; }
.feed-body b { font-weight: 500; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-body small { font-size: var(--fs-xs); color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-item + .feed-item, .device-row + .device-row { border-top: 1px solid var(--c-line); border-radius: 0; }
.device-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c-line-strong); }
.device-dot.online { background: var(--c-ok); box-shadow: 0 0 0 3px var(--c-ok-soft); }
.overview-grid { display: grid; gap: var(--s-4); grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); }
.overview-grid > .card { display: flex; flex-direction: column; min-height: 0; }
.overview-grid .feed { max-height: 520px; overflow-y: auto; margin-inline: calc(-1 * var(--s-2)); }
.segmented { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--r-md); background: var(--c-sunken); }
.segmented button { border: 0; background: transparent; color: var(--c-muted); font: 500 var(--fs-xs) var(--f-ui); padding: 5px 10px; border-radius: var(--r-sm); cursor: pointer; }
.segmented button.active { background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-1); }
@media (max-width: 1100px) { .overview-grid { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70; background: var(--scrim); display: flex; align-items: flex-start; justify-content: center;
  padding: max(5vh, var(--s-4)) var(--s-4) var(--s-4); overflow-y: auto; animation: fadeIn var(--t-med) var(--ease);
}
.modal {
  width: min(720px, 100%); max-height: calc(100vh - 8vh); display: flex; flex-direction: column;
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 14px; box-shadow: var(--shadow-pop);
  animation: modalIn var(--t-med) var(--ease);
}
.modal.sm { width: min(460px, 100%); } .modal.lg { width: min(980px, 100%); } .modal.xl { width: min(1240px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-line); }
.modal-title { font-size: var(--fs-lg); font-weight: 600; }
.modal-sub { font-size: var(--fs-xs); color: var(--c-muted); margin-top: 2px; }
.modal-body { padding: var(--s-5); overflow-y: auto; display: grid; gap: var(--s-4); align-content: start; min-height: 0; }
.modal-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-5); border-top: 1px solid var(--c-line); background: var(--c-surface-2); border-radius: 0 0 14px 14px; }
.modal-foot .actions { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-inline-start: auto; }
body.modal-open { overflow: hidden; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.985); } }

/* ---------------------------------------------------------------- Detail lists & media */
.meta-grid { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.meta { display: grid; gap: 2px; min-width: 0; }
.meta > span { font-size: var(--fs-xs); color: var(--c-muted); }
.meta > b { font-weight: 500; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.meta > code { font-size: var(--fs-sm); direction: ltr; unicode-bidi: isolate; text-align: right; }
.panel { border: 1px solid var(--c-line); border-radius: var(--r-md); padding: var(--s-3) var(--s-4); display: grid; gap: var(--s-2); background: var(--c-surface-2); }
.panel-title { font-size: var(--fs-xs); font-weight: 600; color: var(--c-muted); }
.person { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.person img { flex: none; width: 48px; height: 48px; border-radius: 12px; object-fit: cover; background: var(--c-sunken); }
.person.sm img { width: 32px; height: 32px; border-radius: 50%; }
.person b { display: block; font-weight: 500; }
.person small { display: block; font-size: var(--fs-xs); color: var(--c-muted); }
.photo-frame { position: relative; border-radius: var(--r-md); overflow: hidden; background: var(--c-sunken); }
.photo-frame img { display: block; width: 100%; max-height: 60vh; object-fit: contain; }
.photo-stamp { position: absolute; inset-inline: 0; bottom: 0; display: flex; justify-content: space-between; gap: var(--s-2); padding: var(--s-2) var(--s-3); font-size: var(--fs-xs); color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); }
.map-box { height: 380px; border-radius: var(--r-md); overflow: hidden; background: var(--c-sunken); }
.qr-card { display: grid; justify-items: center; gap: var(--s-2); padding: var(--s-5); border: 1px dashed var(--c-line-strong); border-radius: var(--r-md); text-align: center; }
.qr-card img.qr { width: 220px; height: 220px; image-rendering: pixelated; }
.qr-card img.seal { width: 56px; height: 56px; object-fit: contain; }
.note-list { display: grid; gap: 2px; font-size: var(--fs-xs); }
.note-list .bad { color: var(--c-bad); font-weight: 500; }
.check-grid { display: grid; gap: var(--s-2); grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.field-span-2 { grid-column: 1 / -1; }
.form-grid { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.form-grid .input { width: 100%; }
.input-sm { height: 30px; font-size: var(--fs-xs); padding: 0 var(--s-2); }
.btn-reset { background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; text-align: inherit; cursor: pointer; border-radius: var(--r-md); }
.btn-reset:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
/* Leaflet popup content */
.map-pop { display: grid; gap: 2px; min-width: 180px; font-family: var(--f-ui); direction: rtl; text-align: right; color: #1a2b33; }
.map-pop b { font-weight: 600; font-size: 13px; }
.map-pop small { font-size: 11px; color: #5b6b74; }

/* ---------------------------------------------------------------- Unit cards (sectors, divisions, stations) */
.unit-grid { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.unit-card {
  display: grid; gap: var(--s-3); padding: var(--s-4); border: 1px solid var(--c-line); border-radius: var(--r-lg);
  background: var(--c-surface); box-shadow: var(--shadow-1); color: inherit; text-decoration: none;
  transition: border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.unit-card:hover { border-color: var(--c-accent); transform: translateY(-2px); box-shadow: var(--shadow-2, var(--shadow-1)); }
.unit-card:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.unit-card > div > b { display: block; font-weight: 600; }
.unit-card > div > small { display: block; font-size: var(--fs-xs); color: var(--c-muted); margin-top: 2px; }
.unit-stats { display: flex; flex-wrap: wrap; gap: var(--s-4); font-size: var(--fs-xs); color: var(--c-muted); border-top: 1px solid var(--c-line); padding-top: var(--s-3); }
.unit-stats span { display: grid; }
.unit-stats b { font-size: var(--fs-lg); font-weight: 600; color: var(--c-text); }

/* ---------------------------------------------------------------- Operations room: map */
.page { display: grid; gap: var(--s-5); width: 100%; max-width: 1440px; margin-inline: auto; min-width: 0; align-content: start; }
#map { height: 520px; min-height: 360px; width: 100%; background: var(--c-sunken); border-radius: var(--r-md); }
/* Leaflet layers use z-index 400–1000; isolate keeps them inside the map so search, windows and the top bar stay above it. */
.leaflet-container { font-family: var(--f-ui); isolation: isolate; z-index: 0; }
.map-pin-checkpoint span { display: block; width: 16px; height: 16px; border-radius: 50%; background: var(--c-accent); border: 3px solid var(--c-surface); box-shadow: var(--shadow-2); }
.map-pin-device span { display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--c-muted); border: 3px solid var(--c-surface); box-shadow: var(--shadow-2); }
.map-pin-device.online span { background: var(--c-ok); animation: pinPulse 2.2s infinite; }
@keyframes pinPulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c-ok) 60%, transparent); }
  70% { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.badge-scan-flash { animation: flashOk 1.8s ease-out; }
@keyframes flashOk { 0% { background-color: var(--c-ok-soft); } 100% { background-color: transparent; } }

/* ---------------------------------------------------------------- Official printing (QR card, reports) */
@media print {
  @page { size: landscape; margin: 0; }
  html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; color: #000 !important; display: block !important; }
  body * { visibility: hidden !important; }
  .ds-drawer, .ds-topbar, .no-print { display: none !important; }
  #printArea, #printArea *, #officialReportPrintArea, #officialReportPrintArea * { visibility: visible !important; }
  #printArea, #officialReportPrintArea {
    position: absolute; left: 0; top: 0; width: 100%; margin: 0 !important; padding: 12mm 15mm !important;
    box-sizing: border-box; display: block !important; background: #fff !important; color: #000 !important; border: 0 !important;
  }
  #officialReportPrintArea img, #printArea img { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #officialReportPrintArea th, #officialReportPrintArea td { border: 1px solid #333 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------------------------------------------------------------- Accounts without print permission */
body.readonly-security-active { -webkit-user-select: none; user-select: none; }
body.security-screen-blackout > :not(#securityShieldOverlay) { filter: blur(40px) brightness(.2); pointer-events: none; }
#securityShieldOverlay { position: fixed; inset: 0; z-index: 999; display: grid; place-items: center; padding: var(--s-5); background: var(--c-bg); }
#securityWatermarkOverlay { position: fixed; inset: 0; z-index: 998; pointer-events: none; opacity: .13; background-repeat: repeat; }
.btn-print-prohibited { opacity: .6; cursor: not-allowed; }
@media print {
  body.readonly-security-active * { display: none !important; }
  body.readonly-security-active::after {
    content: "هذا الحساب للاطلاع فقط ولا يملك صلاحية طباعة المستندات.";
    display: block; font: 600 20px var(--f-ui); color: #000; text-align: center; margin-top: 100px;
  }
}

/* ---------------------------------------------------------------- Report preview (report-preview.html) */
.preview-body { background: var(--c-sunken); min-height: 100vh; }
.preview-bar { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-5); background: var(--c-surface); border-bottom: 1px solid var(--c-line); }
.preview-canvas { display: grid; justify-items: center; padding: var(--s-5); overflow: auto; }
.paper { width: 297mm; min-height: 210mm; background: #fff; color: #000; box-shadow: var(--shadow-2); transform-origin: top center; transition: transform var(--t-med) var(--ease); }
.paper #officialReportPrintArea { padding: 12mm 15mm; }
@media print { .paper { box-shadow: none; transform: none !important; } }
.map-pin-scan span { display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--c-warn); border: 3px solid var(--c-surface); box-shadow: var(--shadow-2); }

/* ---------------------------------------------------------------- Qawam rows in the service form */
.qawam-rows { display: grid; gap: var(--s-2); }
.qawam-rows:empty::before { content: "لم يُضف شيء بعد"; font-size: var(--fs-xs); color: var(--c-muted); }
.qawam-row { display: grid; grid-template-columns: minmax(90px, auto) minmax(140px, 1fr) 110px auto; align-items: center; gap: var(--s-2); }
.qawam-row > b { font-weight: 500; font-size: var(--fs-sm); }
.qawam-row .input { width: 100%; }

/* Service tree (users: data scope) */
.tree { border: 1px solid var(--c-line); border-radius: var(--r-md, 8px); }
.tree-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--c-line); }
.tree-body { max-height: 420px; overflow: auto; padding: var(--s-1) 0; }
.tree-row { display: flex; align-items: center; gap: var(--s-2); padding: var(--s-1) var(--s-3); }
.tree-row:hover { background: var(--c-surface-2, rgba(0,0,0,.03)); }
.tree-caret { border: 0; background: none; cursor: pointer; width: 1.5rem; font-size: 1rem; color: var(--c-muted); padding: 0; }
.tree-label { flex: 1; display: flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.tree-services { display: grid; gap: 2px; padding: 0 var(--s-3) var(--s-2) calc(var(--s-3) + 2rem); }
.tree-service { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-sm); cursor: pointer; padding: 2px 0; }
.tree-service code { color: var(--c-muted); }
.tree-all { display: flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.perm-groups { display: grid; gap: var(--s-2); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.perm-group b { display: block; font-size: var(--fs-xs); color: var(--c-muted); margin-bottom: 2px; }
.perm-group span { display: block; font-size: var(--fs-sm); }
.perm-group span.off { color: var(--c-muted); text-decoration: line-through; opacity: .6; }
