/* ===== APEX EVENTS CRM — هوية بصرية: Navy / Charcoal / Gold (Premium Enterprise) ===== */

:root {
  /* APEX LIGHT */
  --brand: #020d1d;
  --brand-2: #10233e;
  --brand-soft: color-mix(in srgb, var(--brand) 7%, transparent);
  --accent: #d4af37;
  --accent-soft: color-mix(in srgb, var(--accent) 20%, transparent);
  --logo-gold: #d4af37;
  --teal: #3c7d78;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --blue: #0ea5e9;

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --line: #e7eaee;
  --text: #17233a;
  --muted: #5b6b7a;
  --shadow: 0 1px 2px rgba(11, 31, 58, .03), 0 6px 18px rgba(11, 31, 58, .045);
  --shadow-lg: 0 12px 30px rgba(11, 31, 58, .10);
  --r: 9px;
  --r-sm: 7px;
  --sidebar-w: 218px;
  --sidebar-w-collapsed: 68px;
  --sidebar-bg: #ffffff;
  --sidebar-text: #020d1d;
  --sidebar-text-muted: #5b6b7a;
  --sidebar-border: #e7eaee;
  --sidebar-hover-bg: #f4f6f8;
  --sidebar-active-bg: #f2f4f6;
}

/* APEX DARK — أسود عميق + شارستون + ذهبي فاتح كـAccent فقط (وليس لون أساسي) */
html[data-theme="dark"] {
  --brand: #d4af37;
  --brand-2: #e1c060;
  --brand-soft: color-mix(in srgb, var(--brand) 15%, transparent);
  --accent: #d4af37;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
  --logo-gold: #c9a55c;
  --teal: #2dd4bf;
  --green: #22c55e;
  --amber: #f7b955;
  --red: #ff5c5c;
  --blue: #38bdf8;

  --bg: #020d1d;
  --surface: #0b1930;
  --surface-2: #102946;
  --line: rgba(231,234,238,.14);
  --text: #f8fafc;
  --muted: #bdc8d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, .6);
  --sidebar-bg: #010f25;
  --sidebar-text: #f8fafc;
  --sidebar-text-muted: #bdc8d6;
  --sidebar-border: rgba(255, 255, 255, .07);
  --sidebar-hover-bg: rgba(255, 255, 255, .06);
  --sidebar-active-bg: rgba(212,175,106,.16);
}

/* وضع "تلقائي" (Auto/System) — يسري فقط لو المستخدم لم يختر صراحةً Dark أو Light */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --brand: #d4af37;
    --brand-2: #e1c060;
    --brand-soft: color-mix(in srgb, var(--brand) 15%, transparent);
    --accent: #d4af37;
    --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
    --logo-gold: #c9a55c;
    --teal: #2dd4bf;
    --green: #22c55e;
    --amber: #f7b955;
    --red: #ff5c5c;
    --blue: #38bdf8;

    --bg: #020d1d;
    --surface: #0b1930;
    --surface-2: #102946;
    --line: rgba(231,234,238,.14);
    --text: #f8fafc;
    --muted: #bdc8d6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 20px 56px rgba(0, 0, 0, .6);
    --sidebar-bg: #010f25;
    --sidebar-text: #f8fafc;
    --sidebar-text-muted: #bdc8d6;
    --sidebar-border: rgba(255, 255, 255, .07);
    --sidebar-hover-bg: rgba(255, 255, 255, .06);
    --sidebar-active-bg: rgba(212,175,106,.16);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* بدون القاعدة دي، أي عنصر عنده display صريح في كلاسه (زي .field) بيكسر خاصية hidden */

body {
  margin: 0;
  /* Dubai is included with Windows and gives Arabic labels a clearer, calmer rhythm than the generic UI fallback. */
  font-family: "Cairo", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.5; font-weight: 700; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
/* Native dropdown menus can use a light OS background with inherited light text. */
select option, select optgroup { background-color: var(--surface); color: var(--text); }

/* ===== التخطيط ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  border-inline-end: 1px solid var(--sidebar-border);
  transition: background .25s ease, color .25s ease;
}

.brand { display: flex; align-items: center; gap: 8px; padding: 12px 12px 10px; position: relative; }
.brand-lockup { height: 68px; min-width: 0; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 8px; overflow: hidden; border-radius: 7px; background: #010f25; }
.brand-logo { display: block; width: 148px; height: 48px; max-width: 100%; object-fit: cover; object-position: center 57%; }
.brand-descriptor { direction: ltr; color: #f5e6c8; font-family: Georgia, "Times New Roman", serif; font-size: 8px; letter-spacing: .95px; line-height: 1.1; white-space: nowrap; }
.sidebar-collapse-btn {
  width: 22px; height: 22px; border-radius: 6px; font-size: 11px; flex: none;
  background: transparent; border-color: var(--sidebar-border); color: var(--sidebar-text-muted);
}
.sidebar-collapse-btn:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }

.sidebar-clock { display: flex; align-items: baseline; gap: 6px; padding: 2px 14px 12px; overflow: hidden; white-space: nowrap; }
.sidebar-clock .time { font-size: 21px; font-weight: 300; color: var(--sidebar-text); font-variant-numeric: tabular-nums; }
.sidebar-clock .meridiem { font-size: 10px; color: var(--sidebar-text-muted); text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 1px; padding: 8px; overflow-y: auto; overflow-x: hidden; flex: 1; }
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--sidebar-text-muted); padding: 13px 10px 4px; white-space: nowrap;
}
.nav-group-label:first-child { padding-top: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  color: var(--sidebar-text-muted); font-size: 12.5px; font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap; overflow: hidden;
}
.nav a .ico { font-size: 14px; width: 20px; text-align: center; transition: transform .15s ease; flex: none; }
.nav a:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }
.nav a:hover .ico { transform: scale(1.12); }
.nav a.active { background: var(--sidebar-active-bg); color: var(--brand); box-shadow: inset 2px 0 0 0 var(--brand); font-weight: 600; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.nav-badge {
  background: var(--accent); color: #fff; font-size: 9.5px; font-weight: 700;
  border-radius: 999px; padding: 0 7px; margin-inline-start: auto; min-width: 18px; text-align: center;
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1);
}

.sidebar-foot { padding: 12px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--sidebar-border); gap: 8px; overflow: hidden; }
.sidebar-foot .ver { font-size: 9.5px; color: var(--sidebar-text-muted); white-space: nowrap; }
.sidebar-foot .btn-ghost { color: var(--sidebar-text-muted); border-color: var(--sidebar-border); }
.sidebar-foot .btn-ghost:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }

.sidebar-scrim { display: none; }

/* ===== طي القائمة الجانبية (Collapse — أيقونات فقط) — ديسكتوب فقط ===== */
.sidebar.collapsed { width: var(--sidebar-w-collapsed); flex-basis: var(--sidebar-w-collapsed); }
.sidebar.collapsed .brand { padding-inline-end: 8px; justify-content: center; }
.sidebar.collapsed .brand-lockup,
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav a span:not(.ico),
.sidebar.collapsed .sidebar-clock .time,
.sidebar.collapsed .sidebar-clock .meridiem,
.sidebar.collapsed .sidebar-foot .ver,
.sidebar.collapsed .sidebar-foot #langBtn,
.sidebar.collapsed .nav-badge { display: none; }
.sidebar.collapsed .nav a { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .sidebar-collapse-btn { transform: rotate(180deg); }
.sidebar.collapsed .sidebar-foot { flex-direction: column; gap: 10px; }
.sidebar.collapsed .theme-select { flex-direction: column; height: auto; }
.sidebar.collapsed .theme-select button + button { border-inline-start: none; border-top: 1px solid var(--sidebar-border); }
.only-desktop { display: inline-flex; }

/* محدد الوضع (Dark/Light/Auto) — ثلاثي مقسّم داخل تذييل القائمة الجانبية */
.theme-select {
  display: flex; border: 1px solid var(--sidebar-border); border-radius: 9px; overflow: hidden; flex: none;
}
.theme-select button {
  border: none; background: transparent; color: var(--sidebar-text-muted);
  width: 28px; height: 28px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.theme-select button + button { border-inline-start: 1px solid var(--sidebar-border); }
.theme-select button.active { background: var(--sidebar-active-bg); color: var(--brand); }
.theme-select button:not(.active):hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }

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

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  backdrop-filter: none;
  border-bottom: 1px solid var(--line);
}
.search-wrap { position: relative; flex: 1; max-width: 560px; }
.search-wrap input {
  width: 100%; padding: 10px 38px 10px 14px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface-2); color: var(--text);
}
.search-wrap input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; border-color: var(--brand); }
.search-ico { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); opacity: .55; font-size: 13px; }
.search-results {
  position: absolute; inset-inline: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg); max-height: 60vh; overflow-y: auto; padding: 6px; z-index: 50;
}
.search-results .group { font-size: 10px; color: var(--muted); padding: 8px 10px 4px; font-weight: 700; }
.search-results a { display: block; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.search-results a:hover { background: var(--surface-2); }
.search-results a small { color: var(--muted); font-size: 11px; }
.topbar-actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }

.bell-wrap { position: relative; }
.bell-wrap .icon-btn { position: relative; }
.bell-badge {
  position: absolute; top: -5px; inset-inline-end: -5px;
  background: var(--red); color: #fff; font-size: 9.5px; font-weight: 700;
  border-radius: 999px; padding: 0 5px; min-width: 16px; height: 16px; line-height: 16px; text-align: center;
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1);
}
.bell-panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + 8px); width: 340px; max-width: 88vw;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-lg); max-height: 70vh; overflow-y: auto; padding: 6px; z-index: 60;
}
.bell-panel .group { font-size: 10px; color: var(--muted); padding: 8px 10px 4px; font-weight: 700; text-transform: uppercase; }
.bell-item { display: block; padding: 8px 10px; border-radius: 8px; }
.bell-item:hover { background: var(--surface-2); }
.bell-item .r { display: flex; justify-content: space-between; gap: 8px; }
.bell-item .title { font-size: 12.5px; font-weight: 600; }
.bell-item .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.bell-item.overdue .title { color: var(--red); }
.bell-empty { padding: 22px 10px; text-align: center; color: var(--muted); font-size: 12px; }
.bell-foot {
  border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 6px 4px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
}
.bell-foot label { font-size: 10.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }

.view { padding: 16px 20px; flex: 1; perspective: 1200px; }
.view.page-anim { animation: fadeSlideUp .18s ease-out; }
@keyframes pageIn {
  from { opacity: 0; transform: rotateX(5deg) translateY(16px) scale(.98); }
  to { opacity: 1; transform: rotateX(0) translateY(0) scale(1); }
}

/* Flip ثلاثي الأبعاد كامل — لتبديل نمط العرض (List ⇄ Cards) تحديداً، مستوحى من حركة المرجع بالظبط */
.view-flip, .card.view-flip { animation: viewFlip .55s cubic-bezier(.22,.8,.25,1) backwards; transform-style: preserve-3d; perspective: 1400px; }
@keyframes viewFlip {
  0% { opacity: 0; transform: perspective(1400px) rotateY(-16deg) rotateX(4deg) scale(.92); filter: brightness(.55); }
  55% { opacity: 1; filter: brightness(.9); }
  100% { opacity: 1; transform: perspective(1400px) rotateY(0) rotateX(0) scale(1); filter: brightness(1); }
}

/* شريط تقدّم رفيع أعلى الصفحة عند الانتقال بين الشاشات (زي التطبيقات الحديثة) */
.route-progress {
  position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 300;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transform: scaleX(0); transform-origin: 0 0; opacity: 0;
  transition: transform .35s cubic-bezier(.2,.7,.3,1), opacity .2s ease;
  box-shadow: 0 0 8px color-mix(in srgb, var(--brand) 60%, transparent);
}
html[dir="rtl"] .route-progress { transform-origin: 100% 0; }
.route-progress.active { transform: scaleX(.75); opacity: 1; }
.route-progress.done { transform: scaleX(1); opacity: 0; transition: transform .2s ease, opacity .35s ease .12s; }
.foot { padding: 14px 22px 26px; color: var(--muted); font-size: 10.5px; text-align: center; }

/* ===== عناصر عامة ===== */
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { font-size: 18px; }
.page-head p { margin: 1px 0 0; color: var(--muted); font-size: 11px; }
.page-head .spacer { margin-inline-start: auto; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== نظام الأنيميشن العام ===== */
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cardPop { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes popIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: none;
  animation: none;
}
.card-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 12.5px; }
.card-head .spacer { margin-inline-start: auto; }
.card-body { padding: 14px; }
.card-body.tight { padding: 6px; }

/* دخول متتابع (Stagger) للكروت داخل شبكة أو عمود — إحساس أكثر حيوية من ظهورها كلها مرة واحدة */
.grid > .card:nth-child(1), .stack > .card:nth-child(1) { animation-delay: 0ms; }
.grid > .card:nth-child(2), .stack > .card:nth-child(2) { animation-delay: 45ms; }
.grid > .card:nth-child(3), .stack > .card:nth-child(3) { animation-delay: 90ms; }
.grid > .card:nth-child(4), .stack > .card:nth-child(4) { animation-delay: 135ms; }
.grid > .card:nth-child(n+5), .stack > .card:nth-child(n+5) { animation-delay: 175ms; }

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

/* أزرار */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 13px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 12px;
  cursor: pointer; transition: transform .08s, box-shadow .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-danger { background: var(--red); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 11.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 9px; width: 34px; height: 34px; cursor: pointer; font-size: 15px;
}

.profile-btn {
  border: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-soft); color: var(--brand); font-weight: 800; font-size: 12.5px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.profile-panel-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.profile-panel-body .field input { width: 100%; }

/* شارات — بشكل Outline (حدّ ملوّن + نص ملوّن) مستوحى من نمط بطاقات الأولوية */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 9px; border-radius: 999px; font-size: 9.5px; font-weight: 700;
  background: var(--surface-2); border: 1.5px solid var(--line); white-space: nowrap;
  letter-spacing: .3px; text-transform: uppercase;
  transition: transform .12s ease;
}
.badge:hover { transform: translateY(-1px); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-soft { border: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px;
  border-radius: 999px; background: var(--brand-soft); color: var(--brand);
  font-size: 10.5px; font-weight: 600; animation: popIn .3s cubic-bezier(.34,1.56,.64,1) backwards;
}

/* KPI */
.kpi {
  min-height: 112px; padding: 15px 16px !important; display: flex; flex-direction: column;
  justify-content: flex-start; gap: 3px; position: relative; overflow: hidden;
}
.kpi::after { display: none; }
.kpi .label { font-size: 11.5px; color: var(--muted); font-weight: 500; order: 0; }
.kpi .value { font-family: "Segoe UI", "Dubai", sans-serif; font-size: 24px; line-height: 1.25; font-weight: 600; letter-spacing: -.2px; font-variant-numeric: tabular-nums; order: 1; color: var(--brand); }
.kpi .value small { font-size: 10.5px; font-weight: 500; color: var(--muted); }
.kpi .sub { margin-top: auto; font-size: 10.5px; color: var(--muted); order: 2; }
.kpi-link { cursor: pointer; transition: border-color .16s ease, box-shadow .16s ease; }
.kpi-link:hover { transform: none; box-shadow: 0 6px 18px rgba(11, 31, 58, .08); border-color: #d9e0e7; }
.kpi-icon {
  position: absolute; top: 14px; inset-inline-end: 14px; width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--accent) 13%, var(--surface)); color: var(--accent);
}
.kpi-icon svg { width: 16px; height: 16px; }

/* شاشة التحليلات تتعامل مع معلومات تشغيلية، لا تقرير مطبوع: أدوات مدمجة وبطاقات كثيفة. */
.analytics-head { align-items: center; margin-bottom: 6px; }
.analytics-head h1 { font-size: 20px; }
.analytics-toolbar {
  margin-inline-start: auto; display: flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 5px 6px 5px 10px; border: 1px solid var(--line);
  border-radius: 9px; background: var(--surface);
}
.analytics-toolbar-label { color: var(--muted); font-size: 11px; font-weight: 500; }
.analytics-toolbar select, .analytics-toolbar input {
  height: 30px; padding: 4px 28px 4px 9px; border: 0; border-inline-start: 1px solid var(--line);
  background: transparent; color: var(--text); font: inherit; font-size: 12px; outline: none;
}
.analytics-toolbar .field { display: block; }
.analytics-toolbar .btn { min-height: 30px; padding: 4px 10px; }
.analytics-range { margin: 0 0 10px; }
.analytics-kpi-grid { gap: 12px; margin-bottom: 12px; }
.analytics-kpi {
  min-height: 96px; padding: 13px 16px !important; gap: 2px; border-radius: 8px;
  box-shadow: none;
}
.analytics-kpi::after { display: none; }
.analytics-kpi .label { font-size: 11.5px; }
.analytics-kpi .value { font-size: 23px; }
.analytics-kpi .sub { font-size: 10px; }

/* ===== مخططات SVG (Analytics Charts) ===== */
.chart-card .sub { font-size: 11px; color: var(--muted); margin: -6px 0 8px; }
svg.viz-chart { display: block; width: 100%; height: auto; overflow: visible; }
.viz-tick { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.viz-cat { font-size: 10px; fill: var(--text); opacity: .85; }
.viz-val { font-size: 10px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.viz-axis { stroke: var(--line); stroke-width: 1; }
.viz-grid { stroke: var(--line); stroke-width: 1; opacity: .6; }
.viz-hit { cursor: pointer; }

.viz-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; }
.viz-legend .item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.viz-legend .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }

.delta-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; width: fit-content; }
.delta-pill.good { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.delta-pill.bad { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }

.viz-tooltip {
  position: fixed; pointer-events: none; z-index: 80; background: var(--text); color: var(--surface);
  font-size: 11.5px; font-weight: 500; padding: 6px 10px; border-radius: 8px; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translate(-50%, calc(-100% - 10px)); transition: opacity .1s; white-space: nowrap;
}
.viz-tooltip.show { opacity: 1; }
.viz-tooltip .tt-title { font-weight: 800; }

/* جداول */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th {
  text-align: start; font-size: 10.5px; color: var(--muted); font-weight: 700;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2);
}
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tbody tr { animation: fadeSlideUp .3s ease backwards; transition: background .12s ease; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:nth-child(1) { animation-delay: 0ms; }
table.tbl tbody tr:nth-child(2) { animation-delay: 18ms; }
table.tbl tbody tr:nth-child(3) { animation-delay: 36ms; }
table.tbl tbody tr:nth-child(4) { animation-delay: 54ms; }
table.tbl tbody tr:nth-child(5) { animation-delay: 72ms; }
table.tbl tbody tr:nth-child(6) { animation-delay: 90ms; }
table.tbl tbody tr:nth-child(7) { animation-delay: 108ms; }
table.tbl tbody tr:nth-child(8) { animation-delay: 126ms; }
table.tbl tbody tr:nth-child(n+9) { animation-delay: 144ms; }
table.tbl .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }
.link { color: var(--brand); font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* فلاتر */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--text); min-width: 140px;
}
.filters .grow { flex: 1; min-width: 200px; }

/* شريط أدوات الوحدة (Module Toolbar) — بحث + فلترة + ترتيب + أعمدة + محول العرض */
.module-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.module-toolbar .grow { flex: 1; min-width: 200px; }
.module-toolbar select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); }
.popover-wrap { position: relative; }
.popover-wrap .bell-panel { inset-inline-start: 0; inset-inline-end: auto; width: 300px; padding: 12px; }
.popover-wrap .bell-panel .field { margin-bottom: 10px; }
.popover-wrap .bell-panel .foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; }
.popover-wrap .bell-panel label.check-row { display: flex; align-items: center; gap: 8px; padding: 6px 2px; font-size: 12.5px; }

/* شرائح العروض المحفوظة (Saved Views) */
.saved-views { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1.5px solid var(--line);
  font-size: 11.5px; font-weight: 600; cursor: pointer; transition: all .15s ease;
}
.chip-btn:hover { color: var(--text); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.chip-btn.active { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 55%, transparent); }

/* جدول قابل للتمرير الرأسي مع رأس ثابت (Sticky Header) */
.table-wrap.tall { max-height: 62vh; overflow-y: auto; }
.table-wrap.tall table.tbl thead th { position: sticky; top: 0; z-index: 2; }
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--text); }
table.tbl th.sortable .arrow { opacity: .55; margin-inline-start: 3px; }
table.tbl td.col-check, table.tbl th.col-check { width: 34px; }
table.tbl td.col-check input, table.tbl th.col-check input { width: 15px; height: 15px; accent-color: var(--brand); }

/* شريط الإجراءات الجماعية (Bulk Action Bar) */
.bulk-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
  border-radius: var(--r); padding: 8px 12px; margin-bottom: 12px; font-size: 12.5px; font-weight: 600; color: var(--brand);
}
.bulk-bar .spacer { flex: 1; }

/* ترقيم الصفحات (Pagination) */
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-size: 12px; color: var(--muted); }

/* نماذج */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand);
}
.field textarea { resize: vertical; min-height: 92px; line-height: 1.7; }
.field .hint { font-size: 10px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

/* نافذة منبثقة */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 11, 14, .55);
  backdrop-filter: blur(3px); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: min(760px, 100%); margin: auto; animation: pop .18s ease-out; border: 1px solid var(--line);
}
.modal.wide { width: min(1000px, 100%); }
.modal.narrow { width: min(480px, 100%); }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 15px; }
.modal-head .x { margin-inline-start: auto; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 18px 18px; }

/* تنبيهات */
.toast-root { position: fixed; inset-block-end: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--surface); padding: 11px 16px; border-radius: 11px;
  box-shadow: var(--shadow-lg); font-size: 12.5px; font-weight: 600; animation: pop .18s;
}
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: var(--green); color: #fff; }

/* Pipeline (Kanban) */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol {
  flex: 0 0 250px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  display: flex; flex-direction: column; max-height: calc(100vh - 210px);
  animation: fadeSlideUp .3s cubic-bezier(.2,.7,.3,1) backwards;
  transition: background .18s ease, outline-color .18s ease;
}
.kcol.drag-over { outline: 2px dashed var(--brand); background: var(--brand-soft); transform: scale(1.01); }
.kcol.kcol-flash { animation: kcolFlash 1.1s ease-out 2; }
@keyframes kcolFlash {
  0%, 100% { box-shadow: none; outline: 2px solid transparent; }
  40% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 55%, transparent), var(--shadow-lg); outline: 2px solid color-mix(in srgb, var(--brand) 70%, transparent); }
}
.kcol-head { padding: 9px 11px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: inherit; border-radius: var(--r) var(--r) 0 0; z-index: 1; }
.kcol-head .t { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 11px; }
.kcol-head .t .dot { width: 7px; height: 7px; border-radius: 50%; transition: transform .2s ease; }
.kcol-head:hover .t .dot { transform: scale(1.35); }
.kcol-head .m { font-size: 9px; color: var(--muted); margin-top: 2px; display: flex; justify-content: space-between; }
.kcol-body { padding: 7px; display: flex; flex-direction: column; gap: 7px; overflow-y: auto; min-height: 80px; }
.kcard {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 9px;
  cursor: grab; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  transition: box-shadow .18s ease, transform .18s cubic-bezier(.2,.7,.3,1), border-color .18s ease;
  animation: cardPop .32s cubic-bezier(.2,.7,.3,1) backwards;
  will-change: transform;
}
.kcard:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.kcard:active { cursor: grabbing; }
.kcard.dragging {
  opacity: .55; transform: scale(1.04) rotate(-1.2deg); box-shadow: var(--shadow-lg);
  cursor: grabbing; animation: none;
}
.kcard .t { font-weight: 700; font-size: 11.5px; margin-bottom: 2px; }
.kcard .o { font-size: 10px; color: var(--muted); }
.kcard .meta { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; font-size: 9px; }
.kcard .money { font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.kcard .warn { color: var(--red); font-weight: 700; }

.next-action {
  margin-top: 6px; padding: 5px 7px; border-radius: 7px;
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 3px; font-size: 9.5px;
}
.next-action .na-text { font-weight: 600; color: var(--text); }
.next-action .na-date {
  display: inline-flex; width: fit-content; padding: 1.5px 8px; border-radius: 999px;
  background: var(--surface); color: var(--muted); font-size: 8.5px; font-weight: 700;
  transition: background .2s ease, color .2s ease;
}

/* CRM workspace: density is deliberate. Keep scanning and decisions in one line. */
.sidebar { width: 232px; flex-basis: 232px; }
.sidebar-clock { display: none; }
.brand { padding: 10px 12px; }
.brand-lockup { height: 164px; border-radius: 6px; }
.brand-logo { width: 176px; height: 138px; max-width: 100%; object-fit: contain; object-position: center; }
.brand-descriptor { font-size: 10px; letter-spacing: 0; white-space: normal; text-align: center; line-height: 1.4; }
.brand-type b { font-size: 17px; }
.nav { gap: 2px; padding: 8px 10px; }
.nav-group-label { font-size: 9.5px; letter-spacing: .7px; padding: 16px 8px 5px; }
.nav a { padding: 7px 8px; min-height: 32px; font-size: 12px; border-radius: 6px; }
.nav a .ico { width: 18px; font-family: Arial, sans-serif; font-size: 15px; font-weight: 400; }
.nav a:hover .ico { transform: none; }
.nav a.active { box-shadow: inset 3px 0 0 var(--brand); }
.nav-advanced { margin-top: 8px; border-top: 1px solid var(--sidebar-border); padding-top: 8px; }
.nav-advanced summary { list-style: none; cursor: pointer; padding: 7px 8px; color: var(--sidebar-text-muted); font-size: 11px; font-weight: 600; }
.nav-advanced summary::-webkit-details-marker { display: none; }
.nav-advanced summary::before { content: '+'; display: inline-block; width: 18px; color: var(--brand); font-size: 15px; font-weight: 400; }
.nav-advanced[open] summary::before { content: '−'; }
.nav-advanced .nav-group-label { display: block; }
.nav-advanced a { display: flex; }
.sidebar-foot { padding: 9px 12px; }

.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 20px; letter-spacing: -.25px; }
.page-head p { margin-top: 3px; font-size: 11px; }
.filters { padding: 8px; gap: 7px; margin-bottom: 14px; background: transparent; border: 0; }
.filters input, .filters select { min-height: 34px; }
.kanban { gap: 12px; padding-bottom: 16px; }
.kcol { flex-basis: 276px; background: var(--surface); border-radius: 8px; max-height: calc(100vh - 190px); }
.kcol-head { padding: 11px 12px 9px; background: var(--surface); }
.kcol-head .t { font-size: 11.5px; }
.kcol-head .m { margin-top: 4px; font-size: 9.5px; }
.kcol-body { padding: 8px; gap: 8px; background: var(--surface-2); }
.kcard { border-radius: 7px; padding: 11px; box-shadow: none; }
.kcard:hover { box-shadow: 0 4px 12px rgba(15, 23, 42, .08); transform: translateY(-1px); }
.kcard-top { display: flex; align-items: start; gap: 10px; justify-content: space-between; }
.kcard .t { margin: 0; font-size: 12px; line-height: 1.35; }
.kcard .o { margin-top: 4px; font-size: 10.5px; }
.kcard .money { color: var(--text); font-size: 11px; white-space: nowrap; }
.kcard-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9.5px; }
.next-dot { color: var(--muted); white-space: nowrap; }
.next-dot.today { color: #9a6e11; font-weight: 700; }
.next-dot.overdue { color: var(--red); font-weight: 700; }
/* تاريخ المتابعة العاجلة يتحول لشارة برتقالية مصمتة — نفس منطق تمييز الاستعجال في التصميم المرجعي */
.next-action.today .na-date { background: var(--accent); color: #fff; }
.next-action.overdue .na-date { background: var(--red); color: #fff; }
.next-action.overdue .na-text { color: var(--red); font-weight: 700; }

/* زرار التبديل جدول/كروت */
.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; height: fit-content; }
.view-toggle button {
  padding: 7px 12px; border: none; background: var(--surface); color: var(--muted);
  font-weight: 600; font-size: 11.5px; cursor: pointer; transition: background .15s ease, color .15s ease;
}
.view-toggle button + button { border-inline-start: 1px solid var(--line); }
.view-toggle button.active { background: var(--brand); color: #fff; }
.view-toggle button:not(.active):hover { background: var(--surface-2); color: var(--text); }

/* ---------- التقويم (Calendar — Part P-2) ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head-row { margin-bottom: 6px; }
.cal-headcell { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-cell { min-height: 92px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--surface); }
.cal-cell.cal-out { opacity: .45; }
.cal-cell.cal-today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.cal-cell.drag-over { background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.cal-daynum { font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.cal-chips { display: flex; flex-direction: column; gap: 3px; }
.cal-chip {
  font-size: 10.5px; padding: 2px 6px; border-radius: 5px; background: var(--surface-2); cursor: grab;
  border-inline-start: 3px solid var(--brand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 4px;
}
.cal-chip .dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.cal-chip.dragging { opacity: .4; }
.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; align-items: start; }
.cal-weekcol { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); min-height: 160px; }
.cal-weekcol.cal-today { border-color: var(--brand); }
.cal-weekhead { text-align: center; font-size: 11.5px; font-weight: 700; padding: 8px 4px; background: var(--surface-2); }
.cal-weekbody { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.cal-agenda-item { padding: 6px 8px; border-radius: 8px; background: var(--surface-2); cursor: pointer; font-size: 12px; }
.cal-agenda-item:hover { background: color-mix(in srgb, var(--brand) 10%, var(--surface-2)); }
.link-row { cursor: pointer; }
.link-row:hover { background: var(--surface-2); }
.chip-x {
  border: none; background: none; color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
  padding: 0 4px;
}
.chip-x:hover { color: var(--red); }

/* نظام كروت العملاء/الجهات */
.org-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 14px; }
.org-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  animation: cardPop .35s cubic-bezier(.2,.7,.3,1) backwards;
  transition: transform .18s cubic-bezier(.2,.7,.3,1), box-shadow .18s ease, border-color .18s ease;
}
.org-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); }
.org-card-top { display: flex; align-items: flex-start; gap: 10px; }
.org-avatar {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.org-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.org-name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 10px 0;
  border-top: 1px dashed var(--line); border-bottom: 1px dashed var(--line);
}
.org-stats > div { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.org-stats strong { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.org-stats span { font-size: 9px; color: var(--muted); }
.org-card-foot { display: flex; gap: 6px; align-items: center; margin-top: auto; }
.org-card-foot .btn-block { flex: 1; }

/* الخط الزمني */
.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before { content: ""; position: absolute; inset-inline-start: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: 0 0 16px; animation: fadeSlideUp .3s ease backwards; }
.tl-item:nth-child(1) { animation-delay: 0ms; }
.tl-item:nth-child(2) { animation-delay: 20ms; }
.tl-item:nth-child(3) { animation-delay: 40ms; }
.tl-item:nth-child(4) { animation-delay: 60ms; }
.tl-item:nth-child(5) { animation-delay: 80ms; }
.tl-item:nth-child(6) { animation-delay: 100ms; }
.tl-item:nth-child(n+7) { animation-delay: 120ms; }
.tl-item::before {
  content: ""; position: absolute; inset-inline-start: -20px; top: 7px;
  width: 11px; height: 11px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand);
}
.tl-item.done::before { background: var(--green); border-color: var(--green); }
.tl-item.overdue::before { background: var(--red); border-color: var(--red); }
.tl-item .tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-item .tl-title { font-weight: 700; font-size: 12.5px; }
.tl-item .tl-date { font-size: 10px; color: var(--muted); }
.tl-item .tl-body { font-size: 12px; color: var(--muted); white-space: pre-wrap; margin-top: 3px; }

/* أدوات مساعدة */
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.strong { font-weight: 700; }
.mono-num { font-variant-numeric: tabular-nums; }
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 28px; display: block; margin-bottom: 6px; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.sep { height: 1px; background: var(--line); margin: 14px 0; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i {
  display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2));
  width: 0; transition: width .7s cubic-bezier(.2,.7,.3,1);
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  padding: 9px 15px; border: none; background: none; cursor: pointer; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.only-mobile { display: none; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 12.5px; align-items: baseline; }
.info-list dt { color: var(--muted); font-size: 11px; }
.info-list dd { margin: 0; font-weight: 600; }
.tpl-body {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.8; max-height: 320px; overflow-y: auto;
}
.tpl-body mark { background: var(--accent-soft); color: var(--accent); font-weight: 700; border-radius: 4px; padding: 0 3px; }

/* الطباعة */
@media print {
  .sidebar, .topbar, .foot, .head-actions, .no-print, .tabs { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .view { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .grid.side { grid-template-columns: 1fr; }
}

/* الاستجابة */
@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none !important; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    transform: translateX(100%); transition: transform .22s ease;
  }
  /* الطي مخصّص للديسكتوب فقط — على الموبايل القائمة دايماً بعرضها الكامل حتى لو كانت متطوية قبل تصغير الشاشة */
  .sidebar.collapsed { width: var(--sidebar-w); flex-basis: var(--sidebar-w); }
  .sidebar.collapsed .brand-text, .sidebar.collapsed .nav-group-label,
  .sidebar.collapsed .nav a span:not(.ico), .sidebar.collapsed .sidebar-clock .time,
  .sidebar.collapsed .sidebar-clock .meridiem, .sidebar.collapsed .sidebar-foot .ver,
  .sidebar.collapsed .sidebar-foot #langBtn, .sidebar.collapsed .nav-badge { display: revert; }
  .sidebar.collapsed .nav a { justify-content: flex-start; padding-inline: 12px; }
  .sidebar.collapsed .sidebar-foot { flex-direction: row; }
  .sidebar.collapsed .theme-select { flex-direction: row; }
  .sidebar.collapsed .theme-select button + button { border-inline-start: 1px solid var(--sidebar-border); border-top: none; }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0) !important; }
  .sidebar-scrim.show { display: block; position: fixed; inset: 0; background: rgba(10, 11, 14, .5); z-index: 35; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr; }
  .cal-grid, .cal-week { grid-template-columns: 1fr; }
  .cal-head-row { display: none; }
  .cal-cell { min-height: unset; }
  .cal-cell.cal-out { display: none; }
  .cal-daynum::after { content: attr(data-weekday); margin-inline-start: 6px; font-weight: 400; }
  .form-grid { grid-template-columns: 1fr; }
  .view { padding: 14px; }
  .topbar { padding: 10px 12px; }
  .page-head h1 { font-size: 17px; }
  .kpi .value { font-size: 18px; }
  .kcol { flex-basis: 82vw; max-height: none; }
  .modal-foot { position: sticky; bottom: 0; }
  .org-grid { grid-template-columns: 1fr; }
}

/* ===== لوحة تحكم "زجاجية" (Glass) — خيار عرض ثانٍ اختياري للوحة التحكم فقط =====
   مقصود إنه معزول تماماً عن نظام ألوان التطبيق (--brand/--accent/--bg...) ولا يتأثر بالوضع الفاتح/الغامق —
   كروت زجاجية بتدرجات وردي/بنفسجي دايماً، بناءً على طلب صريح من صاحب النظام رغم تعارضه مع قاعدة "لا تصميم زائد" العامة */
.dash-glass {
  background: #0b1f3a;
  border-radius: 20px;
  padding: 22px;
  color: #f3f0ff;
}
.dash-glass .gheader h2 { margin: 0 0 3px; font-size: 19px; font-weight: 800; }
.dash-glass .gheader p { margin: 0; font-size: 12px; color: rgba(243, 240, 255, .65); }

.dash-glass .gcard {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(245, 230, 200, .16);
  border-radius: 12px;
  box-shadow: none;
  padding: 16px 18px;
}
.dash-glass .gcard-title { font-size: 12.5px; font-weight: 700; margin: 0 0 12px; opacity: .95; }

.dash-glass .gkpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0; }
.dash-glass .gkpi { display: flex; flex-direction: column; gap: 8px; color: #fff; border: none; }
.dash-glass .gkpi .gicon {
  width: 36px; height: 36px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; background: rgba(255, 255, 255, .2);
}
.dash-glass .gkpi.p1, .dash-glass .gkpi.p2, .dash-glass .gkpi.p3, .dash-glass .gkpi.p4 { background: rgba(255, 255, 255, .04); }
.dash-glass .gkpi .glabel { font-size: 11px; font-weight: 600; opacity: .85; }
.dash-glass .gkpi .gvalue { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dash-glass .gdelta {
  display: inline-flex; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .22); width: fit-content;
}
.dash-glass .gdelta.down { background: rgba(0, 0, 0, .2); }

.dash-glass .gchart-row { display: grid; grid-template-columns: 1.7fr 1fr; gap: 14px; margin-bottom: 14px; }
.dash-glass svg.viz-chart .viz-tick, .dash-glass svg.viz-chart .viz-cat { fill: rgba(243, 240, 255, .65) !important; }
.dash-glass svg.viz-chart .viz-val { fill: #f3f0ff !important; }
.dash-glass svg.viz-chart .viz-grid { stroke: rgba(255, 255, 255, .12) !important; }
.dash-glass svg.viz-chart .viz-axis { stroke: rgba(255, 255, 255, .25) !important; }

.dash-glass .gsignal-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.dash-glass .gsignal { display: flex; align-items: flex-start; gap: 9px; padding: 9px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.dash-glass .gsignal:first-child { border-top: none; padding-top: 0; }
.dash-glass .gsignal .gdot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: none; }
.dash-glass .gsignal .gtext strong { display: block; font-size: 12.5px; font-weight: 700; }
.dash-glass .gsignal .gtext span { font-size: 11px; opacity: .72; }

.dash-glass .gbar-row { margin-bottom: 11px; }
.dash-glass .gbar-row:last-child { margin-bottom: 0; }
.dash-glass .gbar-row .grow { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 4px; }
.dash-glass .gbar-track { height: 8px; border-radius: 5px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.dash-glass .gbar-fill { height: 100%; border-radius: 5px; background: var(--logo-gold); }

.dash-glass .ghealth-row {
  display: flex; justify-content: space-between; align-items: center; padding: 7px 0;
  border-top: 1px solid rgba(255, 255, 255, .1); font-size: 12px;
}
.dash-glass .ghealth-row:first-child { border-top: none; padding-top: 0; }
.dash-glass .ghealth-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-inline-end: 6px; }

@media (max-width: 880px) {
  .dash-glass .gkpi-row { grid-template-columns: repeat(2, 1fr); }
  .dash-glass .gchart-row, .dash-glass .gsignal-row { grid-template-columns: 1fr; }
}

/* من يفضّل تقليل الحركة (إعداد نظام التشغيل) — نلغي كل الأنيميشن فوراً */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* صفحة البداية: نعرض القرارات العاجلة أولاً، أما الأرقام المرجعية فتُفتح عند الحاجة. */
.dashboard-secondary {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.dashboard-secondary > summary {
  cursor: pointer;
  list-style: none;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  user-select: none;
}
.dashboard-secondary > summary::-webkit-details-marker { display: none; }
.dashboard-secondary > summary::before {
  content: '+';
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-inline-end: 7px;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--brand);
  font-size: 15px;
  font-weight: 400;
  vertical-align: -2px;
}
.dashboard-secondary[open] > summary { border-bottom: 1px solid var(--line); color: var(--text); }
.dashboard-secondary[open] > summary::before { content: '−'; }
.dashboard-secondary .card { border: 0; border-radius: 0; }
.dashboard-secondary .card:last-child { margin-bottom: 0 !important; }
.dashboard-secondary .card-head { padding-inline: 14px; }





