/* ============================================================
   تنسيق الهيكل فقط — القائمة الجانبية والشريط العلوي وزر المعلومات والإطارات (2026-10-01)
   فُصل عن style.css (قاعدة الصفحات) لأن اللوحات الحيّة والمولَّدة تحمل تنسيقها الخاص: كانت قواعد
   الحقول والجداول العامة تدخل عليها فتمدّدت فلاترها على كامل العرض (ملاحظة المستخدم «الفلاتر فوق مزعجة»).
   يُحمَّل بكل الصفحات: head.ejs (قبل style.css) · shell-head.ejs للوحات الحيّة · dash-embed.ejs للمولَّدة.
   ============================================================ */
.sidebar, .shell-top, .sb-overlay, .ui-pop { font-family: var(--font); font-size: var(--font-size); line-height: 1.45; box-sizing: border-box; }
.sidebar *, .shell-top *, .ui-pop * { box-sizing: border-box; }
.shell-top input[type=search] { width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-family: inherit; font-size: 0.85rem; }
.shell-top input[type=search]:focus { outline: none; background: var(--white); border-color: var(--border-3); }
/* ============================================================
   هيكل الصفحة — قائمة جانبية يمين + شريط علوي أبيض (اعتماد المستخدم 2026-09-30)
   الصفحة لا تُغلَّف: القائمة ثابتة على اليمين والجسد يأخذ حشواً بعرضها، فتعمل مع
   71 قالباً يضع <main class="container"> بعد الرأس مباشرة بلا تعديل.
   ============================================================ */
body { padding-inline-start: var(--sidebar-w); }
.sidebar {
  position: fixed; top: var(--banner-h, 0px); inset-inline-start: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--card); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 200; overflow-y: auto; overscroll-behavior: contain;
}
.sb-brand { position: sticky; top: 0; z-index: 1; background: var(--card); display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.sb-logo { width: 30px; height: 30px; border-radius: 6px; object-fit: contain; background: var(--white); border: 1px solid var(--border); flex-shrink: 0; }
.sb-brand-text b { display: block; font-size: 0.88rem; font-weight: 700; line-height: 1.25; }
.sb-brand-text small { display: block; color: var(--muted); font-size: 0.72rem; }
.sb-nav { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sb-group { display: flex; flex-direction: column; gap: 1px; margin-top: 6px; }
.sb-group-title {
  display: flex; align-items: center; gap: 6px; width: 100%; background: none; border: 0; text-align: start; cursor: pointer;
  font-family: inherit; font-size: 0.72rem; font-weight: 500; color: var(--muted-3); letter-spacing: 0.04em; padding: 8px 8px 4px;
}
div.sb-group-title { cursor: default; }
.sb-caret { margin-inline-start: auto; width: 6px; height: 6px; border-inline-end: 1.5px solid var(--muted-3); border-bottom: 1.5px solid var(--muted-3); transform: rotate(45deg); transition: transform 0.15s; }
.sb-group.collapsed .sb-caret { transform: rotate(-45deg); }
.sb-group.collapsed .sb-items { display: none; }
.sb-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: var(--radius);
  color: var(--text); text-decoration: none; font-size: 0.88rem; font-weight: 500; line-height: 1.3;
}
.sb-item:hover { background: var(--cream-5); }
.sb-item.active { background: var(--cream-7); color: var(--primary); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.sb-single { margin-top: 2px; }
.sb-count { font-size: 0.7rem; font-weight: 700; background: var(--cream-7); color: var(--primary); border-radius: 4px; padding: 0 6px; line-height: 1.5; }
.sb-item.active .sb-count { background: var(--primary); color: var(--white); }
.sb-foot { border-top: 1px solid var(--border); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sb-user b { display: block; font-size: 0.82rem; font-weight: 700; }
.sb-user small { display: block; color: var(--muted); font-size: 0.72rem; }
.sb-logout { background: none; border: 1px solid var(--border-2); border-radius: var(--radius); font-family: inherit; font-size: 0.78rem; color: var(--muted-2); padding: 3px 9px; cursor: pointer; }
.sb-logout:hover { background: var(--cream-5); color: var(--text); }
.sb-overlay { position: fixed; inset: 0; background: rgba(26, 38, 52, 0.35); z-index: 190; }

/* الشريط العلوي الأبيض (اسم مميّز: .topbar مستعمل بأشرطة الفلاتر باللوحات الحيّة) */
.shell-top {
  position: sticky; top: var(--banner-h, 0px); z-index: 150; height: var(--topbar-h);
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 0 20px;
}
.tb-menu { display: none; width: 34px; height: 34px; border: 1px solid var(--border-2); border-radius: var(--radius); background: var(--white); cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0; }
.tb-menu span { width: 16px; height: 1.5px; background: var(--text-2); display: block; }
.tb-crumb { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.tb-crumb a { color: var(--muted); text-decoration: none; }
.tb-crumb a:hover { color: var(--primary); }
.tb-crumb b { color: var(--text); font-weight: 500; }
.tb-sep { color: var(--muted-3); }
.tb-search { margin-inline-start: auto; width: 260px; }
.tb-search input { height: 32px; background: var(--bg); border-color: var(--border); font-size: 0.82rem; }
.tb-search input:focus { background: var(--white); }
.tb-date { font-size: 0.8rem; color: var(--muted); padding-inline-start: 12px; border-inline-start: 1px solid var(--border); white-space: nowrap; }
.tb-icon { position: relative; width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--radius); display: grid; place-items: center; color: var(--muted-2); text-decoration: none; background: var(--white); }
.tb-icon:hover { color: var(--primary); border-color: var(--border-2); }
.tb-badge { position: absolute; top: -6px; inset-inline-end: -6px; background: var(--err-strong); color: var(--white); font-size: 10px; font-weight: 700; border-radius: 3px; padding: 0 4px; line-height: 1.5; }
.tb-user { position: relative; }
.tb-user-btn { display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--white); font-family: inherit; font-size: 0.82rem; color: var(--text); cursor: pointer; }
.tb-user-btn:hover, .tb-user-btn[aria-expanded="true"] { border-color: var(--border-2); background: var(--cream-4); }
.tb-avatar { width: 22px; height: 22px; border-radius: 5px; background: var(--cream-7); color: var(--primary); font-weight: 700; display: grid; place-items: center; font-size: 0.8rem; }
.tb-user-dd { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); min-width: 200px; background: var(--card); border: 1px solid var(--border-2); border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 4px; z-index: 300; }
.tb-dd-item { display: block; width: 100%; text-align: start; padding: 6px 10px; border-radius: 4px; color: var(--text); text-decoration: none; font-size: 0.85rem; font-family: inherit; background: none; border: 0; cursor: pointer; }
.tb-dd-item:hover { background: var(--cream-5); }
.tb-dd-item.active { color: var(--primary); font-weight: 700; }
.tb-dd-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.shell-top-guest { justify-content: center; }
.shell-top-guest .tb-crumb b { font-weight: 700; }
body.no-shell { padding-inline-start: 0; }

/* القائمة مخفية باختيار الموظف (2026-10-01): الصفحة تمتد على كامل الشاشة */
html.sb-collapsed body { padding-inline-start: 0; }
html.sb-collapsed .sidebar { transform: translateX(100%); visibility: hidden; }
html.sb-collapsed .container { max-width: none; }
.tb-menu { display: flex; }
.tb-menu:hover { background: var(--cream-5); }

/* اللوحات الحيّة داخل الهيكل بلا إطارات (2026-10-01): <html data-shell> — ورقة الصفحة تضع حشو body
   فيُفرض حشو القائمة، وتُخفى عناوينها ورابط العودة كما في الوضع المضمّن */
html[data-shell] body { padding-inline-start: var(--sidebar-w) !important; }
html[data-shell].sb-collapsed body { padding-inline-start: 0 !important; }
html[data-shell] [data-hub-hide] { display: none !important; }
/* رابط العودة داخل اللوحة يُخفى (القائمة الجانبية بديله) — لا عنصر القائمة نفسه: كانت القاعدة تخفي «كل اللوحات» بالقائمة (ملاحظة المستخدم 2026-10-01) */
html[data-shell] a[href="/dashboards"]:not(.sb-item):not(.tb-dd-item), html[data-shell] a[href="/dashboards/"]:not(.sb-item):not(.tb-dd-item) { display: none !important; }
html[data-shell] .hero h1 { display: none !important; }
html[data-shell] header > .meta { margin-inline-start: 0; }
/* الشريط العلوي يمتد على كامل عرض المحتوى مهما كان حشو الصفحة الحيّة: حشو النهاية يُثبَّت 16px (كان يختلف بين الصفحات فيفيض الشريط بالجوال 2026-10-01) */
html[data-shell] body { padding-inline-end: 16px !important; }
html[data-shell] .shell-top { margin: 0 var(--tb-m, -16px) 16px; }
html[data-shell] .gen-body { --tb-m: 0; padding-inline-end: 0 !important; }

/* اللوحة المولَّدة مدرجة داخل الهيكل (dash-embed.ejs): بلا حشو خارجي — ورقتها تتكفل بتخطيطها داخل #gen-root */
.gen-main { padding: 0; }
#gen-root { min-height: calc(100vh - var(--topbar-h)); }
#gen-root .hero h1 { display: none !important; }
.gen-main .dash-stale { position: static !important; box-shadow: none !important; border-bottom: 1px solid #F1D3B1 !important; font-family: var(--font) !important; font-size: 0.85rem !important; }

/* الجوال: القائمة تنزلق من اليمين بزر */
@media (max-width: 900px) {
  body, html[data-shell] body { padding-inline-start: 0 !important; }
  /* الصفحة الحيّة بالجوال تستعيد حشوها الجانبي (كان يُصفَّر مع حشو القائمة فتلتصق البطاقات بالحافة) */
  html[data-shell] body { padding-inline-start: 16px !important; }
  html[data-shell] .gen-body { padding-inline-start: 0 !important; }
  .sidebar, html.sb-collapsed .sidebar { transform: translateX(100%); visibility: visible; transition: transform 0.18s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-md); }
  .tb-menu { display: flex; }
  .tb-date, .tb-user-name { display: none; }
  .tb-search { width: auto; flex: 1; }
  .shell-top { padding: 0 12px; }
}
/* الجوال والآيباد (طلب المستخدم 2026-10-01 «القابلية لفتح البورتال من الجوال والآيباد»): الجداول العريضة باللوحات الحيّة والمولَّدة تتمرر أفقياً داخل مكانها بدل أن توسّع الصفحة */
@media (max-width: 768px) {
  html[data-shell] table:not(.heat) { display: block; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  html[data-shell] table:not(.heat) thead, html[data-shell] table:not(.heat) tbody { width: max-content; min-width: 100%; }
  /* عناصر الشبكات باللوحات الحيّة لا تتمدد تحت المحتوى (min-width:auto كان يوسّع الصفحة 40–285px فتنزاح يميناً)؛
     اللوح العريض يتمرر داخل نفسه، والصفحة نفسها لا تنزاح أبداً */
  html[data-shell] body { overflow-x: hidden; }
  html[data-shell] .wrap > *, html[data-shell] .row > *, html[data-shell] .grid2 > *, html[data-shell] .cards > *, html[data-shell] .kcards > *, html[data-shell] .panel, html[data-shell] .card { min-width: 0; max-width: 100%; }
  html[data-shell] .panel, html[data-shell] .card { overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
/* الوضع المضمّن (ريثما تُعاد الأغلفة بلا إطارات): بلا قائمة ولا شريط */
html[data-framed] body { padding-inline-start: 0; }
html[data-framed] .sidebar, html[data-framed] .shell-top { display: none; }

.inline-form { display: inline; }

/* ===== تكيّف الجوال العام =====
   الجداول العريضة كانت تكسر عرض الصفحة كلها على الشاشات الضيقة. */
@media (max-width: 768px) {
  main table:not(.heat) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  main table:not(.heat) thead,
  main table:not(.heat) tbody { width: max-content; min-width: 100%; }
}


/* ============================================================
   زر المعلومات والنافذة العائمة — الشروحات والتفاصيل خلف ضغطة (ui-formal.js)
   قاعدة المستخدم 2026-09-30: «التفاصيل تكون بعد ضغطة على المكان يظهر بوب أب»
   ============================================================ */
.ui-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--border-3); background: var(--white); color: var(--muted-2);
  font-size: 10px; font-weight: 700; font-family: var(--font); line-height: 1;
  cursor: pointer; vertical-align: middle; margin-inline-start: 5px; padding: 0; flex-shrink: 0;
}
.ui-info:hover, .ui-info[aria-expanded=true] { background: var(--cream-7); color: var(--text); border-color: var(--border-3); }
.stat-card > .ui-info, .card > .ui-info { position: absolute; top: 8px; inset-inline-end: 8px; margin: 0; }
.card { position: relative; }
/* العنصر المنقول إلى النافذة لا يُعرض بمكانه الأصلي */
.ui-moved { display: none !important; }
.ui-pop {
  position: absolute; z-index: 400; min-width: 220px; max-width: min(420px, 92vw);
  background: var(--white); color: var(--text); border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 10px 12px; font-size: 0.85rem; line-height: 1.5; text-align: start;
}
.ui-pop .ui-moved { display: block !important; }
.ui-pop .ui-pop-title { font-weight: 600; font-size: 0.8rem; color: var(--muted-2); margin-bottom: 4px; }
.ui-pop .sub, .ui-pop .hint, .ui-pop .note, .ui-pop small { font-size: 0.85rem; color: var(--text-2); }
/* قوائم الأسماء داخل النافذة: سطر لكل اسم */
.ui-pop ul { margin: 4px 0 0; padding-inline-start: 16px; }
.ui-pop .ui-names { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ui-pop .ui-names > span { background: var(--cream-5); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0 6px; font-size: 0.78rem; }


/* ===== اللوحات داخل الهيكل: إطار يملأ منطقة المحتوى + مراكز بتبويبات (2026-09-30) ===== */
body.frame-body { overflow: hidden; height: 100vh; }
.frame-main { padding: 0; height: calc(100vh - var(--topbar-h) - var(--banner-h, 0px)); display: flex; flex-direction: column; }
.dash-frame { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); flex: 1; min-height: 0; }
.hub-tabs { display: flex; align-items: center; gap: 4px; padding: 6px 16px; background: var(--card); border-bottom: 1px solid var(--border); overflow-x: auto; flex: 0 0 auto; }
.hub-name { font-weight: 700; font-size: 0.9rem; margin-inline-end: 10px; padding-inline-end: 12px; border-inline-end: 1px solid var(--border); white-space: nowrap; }
.hub-tab { appearance: none; border: 1px solid transparent; border-radius: var(--radius); background: none; color: var(--muted-2); font-family: inherit; font-size: 0.88rem; font-weight: 500; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.hub-tab:hover { background: var(--cream-5); color: var(--text); }
.hub-tab.active { background: var(--cream-7); color: var(--primary); font-weight: 700; }
.hub-panels { flex: 1; min-height: 0; position: relative; }
.hub-panel { display: none; height: 100%; position: relative; }
.hub-panel.active { display: block; }
.hub-note { padding: 24px; max-width: 560px; }
.hub-note h2 { margin: 0 0 6px; }
.hub-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; background: var(--bg); }

