/* =========================================================
   نظام الألوان: محايد (zinc) + بنفسجي للرسوم البيانية
   ========================================================= */
:root {
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --sidebar: #fafafa;
  --surface: #ffffff;
  --hover: #f4f4f5;
  --active: #e4e4e7;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #09090b;
  --text-2: #3f3f46;
  --muted: #52525b;
  --faint: #71717a;
  --primary: #18181b;
  --primary-fg: #fafafa;
  --ring: #a1a1aa;

  --chart: #8b5cf6;
  --chart-soft: #ddd6fe;
  --chart-2: #a1a1aa;
  --grid: #f0f0f2;

  --success: #15803d;
  --success-bg: #f0fdf4;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #b45309;
  --warn-bg: #fffbeb;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / .05);
  --shadow: 0 1px 3px rgb(0 0 0 / .06), 0 8px 24px rgb(0 0 0 / .06);
  --shadow-lg: 0 16px 48px rgb(0 0 0 / .18);

  --radius: 8px;
  --radius-lg: 12px;
  --font: "Tajawal", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sb-w: 232px;
  --sb-w-collapsed: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09090b; --bg-subtle: #0c0c0e; --sidebar: #0c0c0e; --surface: #111113;
    --hover: #1c1c1f; --active: #27272a; --border: #27272a; --border-strong: #3f3f46;
    --text: #fafafa; --text-2: #d4d4d8; --muted: #a1a1aa; --faint: #8b8b93;
    --primary: #fafafa; --primary-fg: #18181b; --ring: #52525b;
    --chart: #a78bfa; --chart-soft: #4c1d95; --chart-2: #52525b; --grid: #1c1c1f;
    --success: #4ade80; --success-bg: #0f2a19; --danger: #f87171; --danger-bg: #2c1212;
    --warn: #fbbf24; --warn-bg: #2b2210;
    --shadow-sm: none; --shadow: 0 0 0 1px var(--border); --shadow-lg: 0 16px 48px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09090b; --bg-subtle: #0c0c0e; --sidebar: #0c0c0e; --surface: #111113;
  --hover: #1c1c1f; --active: #27272a; --border: #27272a; --border-strong: #3f3f46;
  --text: #fafafa; --text-2: #d4d4d8; --muted: #a1a1aa; --faint: #8b8b93;
  --primary: #fafafa; --primary-fg: #18181b; --ring: #52525b;
  --chart: #a78bfa; --chart-soft: #4c1d95; --chart-2: #52525b; --grid: #1c1c1f;
  --success: #4ade80; --success-bg: #0f2a19; --danger: #f87171; --danger-bg: #2c1212;
  --warn: #fbbf24; --warn-bg: #2b2210;
  --shadow-sm: none; --shadow: 0 0 0 1px var(--border); --shadow-lg: 0 16px 48px rgb(0 0 0 / .6);
  color-scheme: dark;
}

/* =========================================================
   أساسيات
   ========================================================= */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
kbd {
  font: 500 11px/1 var(--mono); padding: 3px 5px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--bg); color: var(--faint); direction: ltr;
}
.ico { display: inline-flex; width: 16px; height: 16px; flex: none; }
.ico svg { width: 100%; height: 100%; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.sm { font-size: 12.5px; }
.num, .mono { font-variant-numeric: tabular-nums; }
.pos { color: var(--success); }
.warn { color: var(--warn); }
.neg { color: var(--danger); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* =========================================================
   الأزرار وعناصر الإدخال
   ========================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 500; font-size: 13.5px; white-space: nowrap; text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn.primary:hover { opacity: .9; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-soft { color: var(--danger); }
.btn.danger-soft:hover { background: var(--danger-bg); }
.btn.success-soft { color: var(--success); }
.btn.success-soft:hover { background: var(--success-bg); }
.btn.block { width: 100%; height: 40px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius);
  border: 0; background: transparent; color: var(--muted); transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link { border: 0; background: none; color: var(--muted); font-size: 13px; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }
.tbl .link { color: var(--text); text-decoration: none; font-weight: 500; text-align: start; }
.tbl .link:hover { text-decoration: underline; }

select {
  height: 32px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 0 10px; font-size: 13px; box-shadow: var(--shadow-sm);
}

/* مقطع اختيار (Segmented) */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--hover); border-radius: var(--radius); }
.seg button, .seg label span {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent;
  padding: 4px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--muted);
  transition: background-color .15s, color .15s;
}
.seg button.on, .seg input:checked + span { background: var(--primary); color: var(--primary-fg); box-shadow: var(--shadow-sm); }
.seg button:not(.on):hover { color: var(--text); }
.seg.sm button { padding: 3px 10px; font-size: 12.5px; }
.seg.xs { padding: 2px; }
.seg.xs label { cursor: pointer; }
.seg.xs input { position: absolute; opacity: 0; pointer-events: none; }
.seg.xs span { padding: 1px 10px; font-family: var(--mono); font-size: 12px; }

/* =========================================================
   الهيكل: القائمة الجانبية + المحتوى
   ========================================================= */
body.booting .shell { visibility: hidden; }
body.logged-out .shell { display: none; }

.shell { display: grid; grid-template-columns: var(--sb-w) minmax(0, 1fr); min-height: 100dvh; }
.shell.collapsed { grid-template-columns: var(--sb-w-collapsed) minmax(0, 1fr); }

.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--sidebar); border-inline-end: 1px solid var(--border); overflow: hidden; z-index: 20;
}
.sb-brand { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; flex: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: var(--primary-fg); display: grid; place-items: center; flex: none; }
.brand-mark .ico { width: 18px; height: 18px; }
.brand-mark .lg-a { stroke: var(--chart); }
.brand-mark.lg { width: 44px; height: 44px; border-radius: 11px; }
.brand-mark.lg .ico { width: 28px; height: 28px; }
.brand-name { font-weight: 700; font-size: 15px; }
.version { font: 500 11px var(--mono); color: var(--faint); margin-inline-start: auto; }

.sb-nav { flex: 1; overflow-y: auto; padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; }
.nav-group { margin: 14px 8px 4px; font-size: 12px; font-weight: 500; color: var(--faint); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 34px; padding: 0 10px;
  border: 0; border-radius: var(--radius); background: transparent; color: var(--text-2);
  font-size: 13.5px; font-weight: 500; text-align: start; transition: background-color .15s, color .15s;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.on { background: var(--primary); color: var(--primary-fg); }
.nav-item kbd { margin-inline-start: auto; }
.nav-item.on kbd { background: transparent; color: inherit; opacity: .7; }

.sb-foot { padding: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.theme-switch { display: flex; gap: 2px; padding: 3px; background: var(--hover); border-radius: var(--radius); }
.theme-switch button { flex: 1; display: grid; place-items: center; height: 26px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); }
.theme-switch button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.user-menu { position: relative; }
.user-card {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px; border: 0; border-radius: var(--radius);
  background: transparent; text-align: start;
}
.user-card:hover { background: var(--hover); }
.user-card > .ico { margin-inline-start: auto; color: var(--faint); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--chart-soft); color: var(--text); display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.user-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.user-meta strong { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { font-size: 12px; color: var(--faint); }

.menu {
  position: absolute; inset-inline: 0; z-index: 40; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 4px; display: flex; flex-direction: column;
}
.menu.up { bottom: calc(100% + 6px); }
.menu button { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; text-align: start; font-size: 13.5px; }
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button.danger { color: var(--danger); }

/* قائمة مطوية: أيقونات فقط */
.shell.collapsed .sb-label { display: none; }
.shell.collapsed .sb-brand { justify-content: center; padding: 0; }
.shell.collapsed .nav-item { justify-content: center; padding: 0; }
.shell.collapsed .user-card { justify-content: center; }

.sb-overlay { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13.5px; min-width: 0; }
.crumb { color: var(--muted); }
.crumb.current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--border-strong); }
.topbar-actions { margin-inline-start: auto; display: flex; gap: 8px; }

.content { padding: 20px 24px 48px; width: 100%; max-width: 1440px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 20px; }
.head-actions { display: flex; gap: 8px; margin-inline-start: auto; }
.page-head .seg, .page-head > .btn { margin-inline-start: auto; }

/* التبويبات */
.tabs {
  display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  box-shadow: inset 0 -1px 0 var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; border: 0; background: transparent; padding: 8px 10px 10px; font-size: 13.5px; font-weight: 500;
  color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); }
.tabs button.on::after { content: ""; position: absolute; inset-inline: 6px; bottom: 0; height: 2px; background: var(--primary); border-radius: 2px; }
.tabs.sm button { font-size: 13px; padding: 6px 8px 8px; }
.count { font: 500 11.5px var(--mono); color: var(--faint); background: var(--hover); border-radius: 999px; padding: 1px 7px; }
.count:empty { display: none; }
.count.warn { color: var(--warn); background: var(--warn-bg); }
.count.danger { color: var(--danger); background: var(--danger-bg); }

/* شريط البحث */
.searchbar {
  position: relative; display: flex; align-items: center; margin-bottom: 10px;
}
.searchbar > .ico { position: absolute; inset-inline-start: 12px; color: var(--faint); pointer-events: none; }
.searchbar input {
  width: 100%; height: 40px; padding-inline: 38px 44px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 14px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.searchbar input::placeholder { color: var(--faint); }
.searchbar input:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.searchbar kbd { position: absolute; inset-inline-end: 10px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.spacer { flex: 1; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* =========================================================
   الجداول
   ========================================================= */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto; background: var(--surface); }
.table-wrap.flat { border: 0; border-radius: 0; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  position: sticky; top: 0; z-index: 1; background: var(--bg-subtle); text-align: start; font-weight: 500; font-size: 12.5px;
  color: var(--muted); padding: 0 12px; height: 38px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl.dense td { padding: 7px 12px; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background-color .1s; }
.tbl tbody tr:hover { background: var(--bg-subtle); }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl .num { text-align: end; white-space: nowrap; }
.tbl th.num { text-align: end; }
.tbl .money { direction: ltr; unicode-bidi: isolate; }
.tbl tr.archived td { color: var(--faint); }
.tbl tr.struck td { color: var(--faint); }
.tbl tr.struck .badge { text-decoration: line-through; }
.actions-col { width: 1%; }
.sort { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; color: inherit; font: inherit; }
.sort .ico { width: 13px; height: 13px; opacity: .45; }
.sort.on { color: var(--text); }
.sort.on .ico { opacity: 1; }

.cell-name { display: flex; flex-direction: column; min-width: 0; }
.cell-name strong { font-weight: 500; }
.cell-name .sku { font: 12px var(--mono); color: var(--faint); direction: ltr; text-align: start; unicode-bidi: plaintext; }
.qty { display: inline-flex; min-width: 36px; justify-content: center; padding: 1px 8px; border-radius: 999px; font-weight: 600; font-variant-numeric: tabular-nums; }
.qty.low { background: var(--warn-bg); color: var(--warn); }
.qty.out { background: var(--danger-bg); color: var(--danger); }
.pct { font-size: 11.5px; color: var(--faint); margin-inline-start: 4px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text-2); white-space: nowrap;
}
.badge.SALE { background: color-mix(in srgb, var(--chart) 12%, transparent); border-color: transparent; color: var(--chart); }
.badge.PURCHASE, .badge.OPENING, .badge.RETURN { background: var(--success-bg); border-color: transparent; color: var(--success); }
.badge.WITHDRAW, .badge.DAMAGE { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.badge.COUNT { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.dot { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.dot.off { color: var(--faint); }
.dot.off::before { background: var(--border-strong); }
.time { font: 12.5px var(--mono); color: var(--muted); direction: ltr; unicode-bidi: isolate; white-space: nowrap; }
.by { color: var(--muted); white-space: nowrap; }
.note { color: var(--muted); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: .55; transition: opacity .15s; }
tr:hover .row-actions, .row-actions:focus-within { opacity: 1; }
.ra {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
}
.ra:hover { background: var(--active); color: var(--text); }
.ra.out:hover { color: var(--danger); background: var(--danger-bg); }
.ra.in:hover { color: var(--success); background: var(--success-bg); }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; font-weight: 600; }
.empty .btn { margin-top: 12px; }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 2px; font-size: 13px; color: var(--muted); }
.pager:empty { display: none; }
.pager .ra { border: 1px solid var(--border); background: var(--surface); }
.pager .ra[disabled] { opacity: .4; pointer-events: none; }
.pager select { height: 28px; }

/* =========================================================
   الرئيسية: البطاقات والرسوم
   ========================================================= */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; text-align: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); min-width: 0;
}
.kpi header { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.kpi header .ico { color: var(--faint); }
.kpi strong { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; direction: ltr; text-align: end; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.kpi small { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.kpi { transition: border-color .15s, background-color .15s; }
button.kpi:hover { border-color: var(--border-strong); background: var(--bg-subtle); }
.warn-kpi.has strong { color: var(--warn); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 12px; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 6px; flex-wrap: wrap; }
.card-head h2 { font-size: 14.5px; }
.card-head .muted { font-size: 12.5px; }
.card .tbl th { background: transparent; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-2 .card { margin-bottom: 0; }
.bar-cell { position: relative; }
.bar-cell .bar { position: absolute; inset-block: 6px; inset-inline-start: 0; background: color-mix(in srgb, var(--chart) 14%, transparent); border-radius: 4px; z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }

/* بدون padding: عرض SVG يجب أن يساوي clientWidth بالضبط حتى لا يتشوه */
.chart { position: relative; height: 240px; padding: 0; }
.card > .chart { margin: 4px 12px 12px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--faint); font: 11px var(--mono); }
.chart .bar { fill: var(--chart); transition: opacity .15s; }
.chart .bar.neg { fill: var(--danger); }
.chart .bar.dim { opacity: .35; }
.chart .bar-out { fill: var(--chart-2); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .zero { stroke: var(--border-strong); }

.histo-card { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 10px 12px 4px; margin-bottom: 10px; background: var(--surface); }
.histo-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; gap: 8px; flex-wrap: wrap; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-start: 6px; }
.sw.in { background: var(--chart); }
.sw.out { background: var(--chart-2); }
.chart.histo { height: 84px; padding: 0; }
.chart.histo.big { height: 300px; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; background: var(--primary); color: var(--primary-fg);
  padding: 7px 10px; border-radius: 7px; font-size: 12.5px; box-shadow: var(--shadow-lg); line-height: 1.5; white-space: nowrap;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* =========================================================
   لوحة تفاصيل الصنف (Peek)
   ========================================================= */
.drawer-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .25); z-index: 49; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(640px, 100vw); z-index: 50;
  background: var(--bg); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(-100%); visibility: hidden;
  transition: transform .2s ease, visibility .2s;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 8px; }
.drawer-head h2 { font-size: 17px; }
.drawer-head .muted { font-size: 12.5px; margin-top: 2px; }
.drawer-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 18px 12px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 18px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.stats > div { padding: 10px 12px; border-inline-end: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.stats > div:nth-child(3n) { border-inline-end: 0; }
.stats > div:nth-last-child(-n+3) { border-bottom: 0; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }
.drawer .tabs { margin: 0 18px; }
.drawer-body { flex: 1; overflow: auto; padding: 0 6px 18px; }
.drawer-body .tbl th { background: var(--bg); }
.info { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; padding: 14px 12px; margin: 0; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }

/* =========================================================
   لوحة الأوامر
   ========================================================= */
dialog.palette { width: min(560px, calc(100vw - 32px)); margin-top: 12vh; padding: 0; }
.palette-input { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border); }
.palette-input > .ico { color: var(--faint); }
.palette-input input { flex: 1; height: 50px; border: 0; background: transparent; font-size: 15px; }
.palette-input input:focus { outline: none; }
.palette-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto; }
.palette-list .grp { padding: 8px 10px 4px; font-size: 12px; color: var(--faint); }
.palette-list li[role="option"] { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.palette-list li[role="option"] .ico { color: var(--muted); }
.palette-list li[role="option"] .meta { margin-inline-start: auto; color: var(--faint); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.palette-list li[aria-selected="true"] { background: var(--hover); }
.palette-list .none { padding: 18px; text-align: center; color: var(--muted); }

/* =========================================================
   النوافذ والنماذج
   ========================================================= */
dialog {
  border: 1px solid var(--border); padding: 0; border-radius: var(--radius-lg); background: var(--bg); color: var(--text);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); box-shadow: var(--shadow-lg); overflow: hidden;
}
dialog.narrow { width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog[open] > form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
dialog header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); flex: none; }
dialog h2 { font-size: 15.5px; }
dialog .body { padding: 16px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; overflow: auto; flex: 1 1 auto; min-height: 0; align-content: start; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--bg-subtle); flex: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; }
.field small { color: var(--faint); font-weight: 400; margin-inline-start: 4px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.field input, .field textarea, .field select {
  height: 36px; border: 1px solid var(--border); border-radius: var(--radius); padding: 0 11px;
  background: var(--surface); font-weight: 400; font-size: 14px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; padding: 8px 11px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field input:disabled { opacity: .6; }
.full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.preview { background: var(--bg-subtle); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 18px; }
.preview:empty { display: none; }
.preview b { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.item-strip { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.item-strip .nm { font-weight: 600; }
.item-strip .q { color: var(--muted); font-size: 13px; }
.item-strip .q b { color: var(--text); font-size: 15px; }
.form-error { margin: 0; color: var(--danger); font-size: 13px; }
.form-error:empty { display: none; }

/* =========================================================
   الدخول
   ========================================================= */
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--bg-subtle); }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.login-card h1 { font-size: 20px; }

/* =========================================================
   التنبيهات
   ========================================================= */
.toasts { position: fixed; bottom: 16px; inset-inline-end: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 120; }
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 10px 14px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: rise .18s ease-out;
}
.toast.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); color: var(--danger); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* =========================================================
   الصلاحيات
   ========================================================= */
body.is-staff .admin-only { display: none !important; }

/* =========================================================
   الشاشات الصغيرة
   ========================================================= */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hide-md { display: none; }
}
@media (max-width: 900px) {
  .shell, .shell.collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: min(280px, 85vw); transform: translateX(100%);
    transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  .shell.mobile-open .sidebar { transform: none; }
  .shell.collapsed .sb-label { display: revert; }
  .shell.collapsed .nav-item { justify-content: flex-start; padding: 0 10px; }
  .sb-overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .3); z-index: 19; display: none; }
  .shell.mobile-open .sb-overlay { display: block; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .grid-2 .card { margin-bottom: 12px; }
}
@media (max-width: 640px) {
  .content { padding: 14px 16px 40px; }
  .topbar { padding: 0 12px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi strong { font-size: 18px; }
  .kpis > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .hide-sm { display: none; }
  .row-actions { opacity: 1; }
  .head-actions { width: 100%; margin: 0; }
  .head-actions .btn { flex: 1; }
  .searchbar input { font-size: 16px; }
  .searchbar kbd, .nav-item kbd { display: none; }
  dialog .body { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats > div:nth-child(3n) { border-inline-end: 1px solid var(--border); }
  .stats > div:nth-child(2n) { border-inline-end: 0; }
  .stats > div:nth-last-child(-n+3) { border-bottom: 1px solid var(--border); }
  .stats > div:nth-last-child(-n+2) { border-bottom: 0; }
  .topbar-actions .btn span { display: none; }
  .chart { height: 200px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
