/* =====================================================================
   نظام إدارة الامتحانات والماستر شيت — نظام التصميم RTL
   University of Al-Farahidi · Technical Medical College · Radiology Dept.
   الهوية البصرية مشتقة حرفياً من docs/SPEC.md §0
   ===================================================================== */

/* ------------------------------------------------------------------
   0. متغيرات الهوية (SPEC §0 — لا تُغيَّر)
   ------------------------------------------------------------------ */
:root {
  --brand-navy: #104B7D;
  --brand-navy-deep: #0B3557;
  --brand-navy-soft: #E8EFF6;
  --brand-gold: #C9A227;
  --brand-gold-soft: #F5EBD0;
  --brand-white: #FFFFFF;
  --warn-orange: #E8590C;
  --ok-green: #1B7F4E;
  --fail-red: #B02A37;
  --ink: #12212E;

  /* مشتقات محايدة مبنية على الهوية */
  --line: #D6DEE7;
  --line-strong: #B9C6D4;
  --muted: #5C6B7A;
  --muted-soft: #8A98A6;
  --page: #F4F7FA;
  --neutral: #EEF2F6;
  --warn-soft: #FDEBE1;
  --fail-soft: #F8E3E5;
  --ok-soft: #E3F1E9;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(18, 33, 46, .08);
  --shadow: 0 4px 14px rgba(18, 33, 46, .10);
  --shadow-lg: 0 14px 34px rgba(18, 33, 46, .16);

  --sidebar-w: 258px;
  --topbar-h: 62px;

  --font-ar: "Cairo", "Tajawal", "Noto Naskh Arabic", "Segoe UI", Tahoma,
    "Arial", "Helvetica Neue", sans-serif;
  --font-mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

/* ------------------------------------------------------------------
   1. إعادة الضبط والأساسيات
   ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-ar);
  font-size: 1rem;
  line-height: 1.75;
  direction: rtl;
  text-align: right;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 .5rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--brand-navy-deep);
}

h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 .85rem; }

a {
  color: var(--brand-navy);
  text-decoration: none;
  transition: color .15s ease;
}

a:hover { color: var(--brand-gold); }

img { max-width: 100%; height: auto; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.25rem 0;
}

::selection {
  background: var(--brand-gold-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid var(--brand-gold);
  outline-offset: 2px;
}

/* أرقام لاتينية بعرض ثابت داخل الجداول الرقمية */
.num,
.grade-cell,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: center;
}

.text-muted { color: var(--muted); }
.text-ok { color: var(--ok-green); }
.text-fail { color: var(--fail-red); }
.text-warn { color: var(--warn-orange); }
.text-navy { color: var(--brand-navy); }
.text-gold { color: var(--brand-gold); }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------
   2. الهيكل العام (شريط جانبي + ترويسة + محتوى + تذييل)
   ------------------------------------------------------------------ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr auto;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main"
    "sidebar footer";
  min-height: 100vh;
}

/* --- الشريط الجانبي --- */
.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, var(--brand-navy) 0%, var(--brand-navy-deep) 100%);
  color: #EAF1F7;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-inline-start: 4px solid var(--brand-gold);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1rem .9rem;
  border-bottom: 1px solid rgba(255, 255, 255, .14);
}

.sidebar__brand img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: var(--brand-white);
  border-radius: 50%;
  padding: 3px;
  border: 2px solid var(--brand-gold);
  flex: none;
}

.sidebar__brand-text { min-width: 0; }

.sidebar__brand-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--brand-white);
  margin: 0;
  line-height: 1.35;
}

.sidebar__brand-sub {
  font-size: .72rem;
  color: var(--brand-gold-soft);
  margin: 0;
}

.sidebar__section {
  padding: .85rem .9rem .25rem;
  font-size: .7rem;
  letter-spacing: .04em;
  color: var(--brand-gold);
  font-weight: 700;
}

.nav {
  list-style: none;
  margin: 0;
  padding: 0 .55rem 1rem;
}

.nav__link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: #DCE7F1;
  font-size: .92rem;
  margin-bottom: .15rem;
  transition: background .15s ease, color .15s ease;
}

.nav__link:hover {
  background: rgba(255, 255, 255, .10);
  color: var(--brand-white);
}

.nav__link.is-active {
  background: var(--brand-gold);
  color: var(--brand-navy-deep);
  font-weight: 700;
}

.nav__icon {
  width: 1.35rem;
  text-align: center;
  flex: none;
  font-size: 1rem;
}

.sidebar__foot {
  margin-top: auto;
  padding: .85rem;
  font-size: .7rem;
  color: #A9BDD1;
  border-top: 1px solid rgba(255, 255, 255, .14);
  line-height: 1.6;
}

/* --- الترويسة --- */
.topbar {
  grid-area: topbar;
  background: var(--brand-white);
  border-bottom: 2px solid var(--brand-navy-soft);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.topbar__title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--brand-navy-deep);
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__badge-role {
  background: var(--brand-navy-soft);
  color: var(--brand-navy-deep);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: .15rem .7rem;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
}

.topbar__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-navy);
  color: var(--brand-white);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .85rem;
  flex: none;
}

/* --- المحتوى --- */
.main {
  grid-area: main;
  padding: 1.25rem 1.4rem 2rem;
  min-width: 0;
}

/* --- التذييل --- */
.footer {
  grid-area: footer;
  background: var(--brand-navy-deep);
  color: #C7D6E4;
  padding: .8rem 1.4rem;
  font-size: .78rem;
  border-top: 3px solid var(--brand-gold);
}

.footer__credits {
  margin: 0;
  text-align: center;
  color: var(--brand-gold-soft);
}

.footer__meta {
  margin: .25rem 0 0;
  text-align: center;
  font-size: .7rem;
  color: #9DB2C6;
}

/* ------------------------------------------------------------------
   3. البطاقات والعناوين
   ------------------------------------------------------------------ */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}

.page-head h1 { margin: 0; }

.page-head__sub {
  margin: .2rem 0 0;
  color: var(--muted);
  font-size: .88rem;
}

.card {
  background: var(--brand-white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.1rem;
  overflow: hidden;
}

.card__head {
  padding: .75rem 1rem;
  background: var(--brand-navy-soft);
  border-bottom: 2px solid var(--brand-gold);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
}

.card__head h2,
.card__head h3 {
  margin: 0;
  font-size: 1rem;
}

.card__body { padding: 1rem; }
.card__body--flush { padding: 0; }

.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ------------------------------------------------------------------
   4. الأزرار
   ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  font-family: inherit;
  font-size: .9rem;
  font-weight: 700;
  line-height: 1;
  padding: .6rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease,
    transform .05s ease;
  text-decoration: none;
}

.btn:active { transform: translateY(1px); }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--brand-navy);
  color: var(--brand-white);
  border-color: var(--brand-navy);
}

.btn--primary:hover { background: var(--brand-navy-deep); color: var(--brand-white); }

.btn--gold {
  background: var(--brand-gold);
  color: var(--brand-navy-deep);
  border-color: var(--brand-gold);
}

.btn--gold:hover { background: #B8921F; color: var(--brand-navy-deep); }

.btn--ghost {
  background: var(--brand-white);
  color: var(--brand-navy);
  border-color: var(--line-strong);
}

.btn--ghost:hover { background: var(--brand-navy-soft); color: var(--brand-navy-deep); }

.btn--danger {
  background: var(--fail-red);
  color: var(--brand-white);
  border-color: var(--fail-red);
}

.btn--danger:hover { background: #8E2029; color: var(--brand-white); }

.btn--ok {
  background: var(--ok-green);
  color: var(--brand-white);
  border-color: var(--ok-green);
}

.btn--lg { padding: .8rem 1.6rem; font-size: 1rem; }
.btn--sm { padding: .35rem .7rem; font-size: .8rem; }
.btn--block { width: 100%; }

.btn-row {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ------------------------------------------------------------------
   5. الشارات والحالات
   ------------------------------------------------------------------ */
.badge {
  display: inline-block;
  padding: .12rem .6rem;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--pass { background: var(--ok-soft); color: var(--ok-green); border-color: var(--ok-green); }
.badge--fail { background: var(--fail-soft); color: var(--fail-red); border-color: var(--fail-red); }
.badge--incomplete { background: var(--warn-soft); color: var(--warn-orange); border-color: var(--warn-orange); }
.badge--carry { background: var(--brand-gold-soft); color: #7A6114; border-color: var(--brand-gold); }
.badge--locked { background: var(--neutral); color: var(--muted); border-color: var(--line-strong); }
.badge--navy { background: var(--brand-navy-soft); color: var(--brand-navy-deep); border-color: var(--brand-navy); }
.badge--gold { background: var(--brand-gold-soft); color: #7A6114; border-color: var(--brand-gold); }

.status-pass { color: var(--ok-green); font-weight: 700; }
.status-fail { color: var(--fail-red); font-weight: 700; }
.status-incomplete { color: var(--warn-orange); font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--brand-navy-soft);
  border: 1px solid var(--line-strong);
  color: var(--brand-navy-deep);
  border-radius: 999px;
  padding: .2rem .75rem;
  font-size: .8rem;
  font-weight: 600;
}

/* ------------------------------------------------------------------
   6. الجداول
   ------------------------------------------------------------------ */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  background: var(--brand-white);
}

table.data th,
table.data td {
  border: 1px solid var(--line);
  padding: .45rem .55rem;
  vertical-align: middle;
}

table.data thead th {
  background: var(--brand-navy);
  color: var(--brand-white);
  font-weight: 700;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.data thead tr.sub th {
  background: var(--brand-navy-deep);
  font-size: .8rem;
  font-weight: 600;
}

table.data tbody tr:nth-child(even) { background: var(--brand-navy-soft); }
table.data tbody tr:hover { background: var(--brand-gold-soft); }

table.data tfoot td {
  background: var(--brand-navy-soft);
  font-weight: 700;
  border-top: 2px solid var(--brand-navy);
}

.table--compact th,
.table--compact td { padding: .28rem .4rem; font-size: .82rem; }

.table--zebra-lock tbody tr.is-locked td { background: var(--neutral); color: var(--muted); }

.empty-state {
  padding: 2.2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: .9rem;
}

.empty-state__icon { font-size: 2rem; display: block; margin-bottom: .4rem; opacity: .6; }

/* ------------------------------------------------------------------
   7. النماذج
   ------------------------------------------------------------------ */
.field { margin-bottom: .9rem; }

.field__label {
  display: block;
  font-weight: 700;
  font-size: .85rem;
  margin-bottom: .3rem;
  color: var(--brand-navy-deep);
}

.field__hint {
  font-size: .75rem;
  color: var(--muted);
  margin-top: .25rem;
}

.input,
.select,
.textarea,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="email"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--brand-white);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .5rem .6rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.input:focus,
.select:focus,
.textarea:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-navy);
  box-shadow: 0 0 0 3px rgba(16, 75, 125, .16);
  outline: none;
}

.input:disabled,
select:disabled,
input:disabled {
  background: var(--neutral);
  color: var(--muted);
  cursor: not-allowed;
}

.grade-input {
  width: 5.2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  padding: .32rem .3rem;
}

.grade-input.is-invalid {
  border-color: var(--fail-red);
  background: var(--fail-soft);
}

.field-error {
  color: var(--fail-red);
  font-size: .75rem;
  margin-top: .15rem;
  display: none;
}

.field-error.is-visible { display: block; }

.checkbox,
.radio {
  display: flex;
  align-items: center;
  gap: .45rem;
  font-size: .86rem;
  cursor: pointer;
  padding: .18rem 0;
}

.checkbox input,
.radio input { width: auto; accent-color: var(--brand-navy); }

/* خلية الغياب (غ) المُفعَّلة: خلفية برتقالية --warn-orange (SPEC §3.2) */
.checkbox.absence-toggle.is-on {
  background: var(--warn-orange);
  color: var(--brand-white);
  border-radius: var(--radius-sm);
  padding: .08rem .35rem;
  font-weight: 700;
}

.checkbox.absence-toggle.is-on input { accent-color: var(--brand-white); }

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .8rem 1rem;
}

/* ------------------------------------------------------------------
   8. شاشة الأستاذ المعزولة (TEACHER) — لا قوائم ولا إحصائيات
   ------------------------------------------------------------------ */
.teacher-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
}

.teacher-topbar {
  background: var(--brand-navy);
  color: var(--brand-white);
  border-bottom: 4px solid var(--brand-gold);
  padding: .7rem 1.2rem;
  display: flex;
  align-items: center;
  gap: .9rem;
  flex-wrap: wrap;
}

.teacher-topbar img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  background: var(--brand-white);
  border-radius: 50%;
  padding: 3px;
  flex: none;
}

.teacher-topbar__org { flex: 1; min-width: 0; }

.teacher-topbar__org strong { display: block; font-size: .95rem; }
.teacher-topbar__org span { font-size: .76rem; color: var(--brand-gold-soft); }

.teacher-topbar__user {
  font-size: .82rem;
  background: rgba(255, 255, 255, .12);
  border-radius: 999px;
  padding: .25rem .8rem;
}

.teacher-main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.1rem 1.2rem 2rem;
}

.teacher-subject {
  background: var(--brand-white);
  border: 1px solid var(--line);
  border-inline-start: 6px solid var(--brand-gold);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.teacher-subject h1 {
  margin: 0 0 .2rem;
  font-size: 1.25rem;
}

.teacher-subject__meta {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--muted);
}

.teacher-subject__meta b { color: var(--brand-navy-deep); }

.teacher-locked-note {
  background: var(--brand-gold-soft);
  border: 1px solid var(--brand-gold);
  color: #6E5610;
  border-radius: var(--radius-sm);
  padding: .55rem .8rem;
  font-size: .85rem;
  margin-bottom: 1rem;
}

.coursework-cell { text-align: center; }

.row-absent td,
tr.is-absent td {
  background: var(--warn-soft) !important;
}

/* الصف الغائب: خلفية برتقالية واسم الطالب بلون برتقالي (SPEC §3.2) */
tr.is-absent .student-name,
.student-name.is-absent {
  color: var(--warn-orange);
  font-weight: 700;
}

.cell-absent {
  background: var(--warn-orange) !important;
  color: var(--brand-white) !important;
  font-weight: 700;
}

.cwk-readonly {
  font-weight: 700;
  color: var(--brand-navy-deep);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.save-bar {
  position: sticky;
  bottom: 0;
  background: var(--brand-white);
  border-top: 3px solid var(--brand-gold);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 -4px 14px rgba(18, 33, 46, .10);
  z-index: 20;
}

.save-bar__hint {
  font-size: .8rem;
  color: var(--muted);
  flex: 1;
  min-width: 180px;
}

.teacher-footer {
  background: var(--brand-navy-deep);
  color: var(--brand-gold-soft);
  text-align: center;
  padding: .7rem 1rem;
  font-size: .76rem;
  border-top: 3px solid var(--brand-gold);
}

/* ------------------------------------------------------------------
   9. الماستر شيت (A4 أفقي للطباعة)
   ------------------------------------------------------------------ */
.sheet {
  background: var(--brand-white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.sheet__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 3px solid var(--brand-navy);
  padding-bottom: .7rem;
  margin-bottom: .7rem;
}

.sheet__logo {
  width: 78px;
  height: 78px;
  object-fit: contain;
  flex: none;
}

.sheet__org { flex: 1; text-align: center; }

.sheet__org .u { font-size: 1.25rem; font-weight: 700; color: var(--brand-navy-deep); margin: 0; }
.sheet__org .c { font-size: .95rem; margin: .1rem 0 0; color: var(--ink); }
.sheet__org .d { font-size: .9rem; margin: .1rem 0 0; color: var(--muted); }
.sheet__org .t { font-size: 1rem; font-weight: 700; margin: .35rem 0 0; color: var(--brand-navy); }

.sheet__meta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .6rem;
  justify-content: center;
  margin-top: .4rem;
  font-size: .8rem;
}

.sheet__meta .chip { background: var(--brand-navy-soft); }

table.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}

table.sheet-table th,
table.sheet-table td {
  border: 1px solid var(--ink);
  padding: .22rem .3rem;
  text-align: center;
  vertical-align: middle;
}

table.sheet-table thead th {
  background: var(--brand-navy);
  color: var(--brand-white);
  font-weight: 700;
}

table.sheet-table thead tr.sub th { background: var(--brand-navy-deep); font-size: .72rem; }

table.sheet-table td.student-name {
  text-align: right;
  font-weight: 600;
  min-width: 190px;
}

/* المواد المقفلة (الناجح بها في الدور الثاني) — رمادي/أبيض */
.subject-group.is-greyed th,
.subject-group.is-greyed td,
th.is-greyed,
td.is-greyed,
td.cell-greyed,
th.cell-greyed {
  background: var(--neutral) !important;
  color: var(--muted) !important;
}

tr.sheet-locked td { background: #F7F9FB; }

td.cell-absent-sheet {
  background: var(--warn-orange) !important;
  color: var(--brand-white) !important;
  font-weight: 700;
}

.sheet-table tfoot td {
  background: var(--brand-navy-soft) !important;
  font-weight: 700;
}

.sheet__signatures {
  margin-top: 1.1rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  font-size: .8rem;
}

.sign-box {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .5rem .7rem;
  min-height: 78px;
  background: #FCFDFE;
}

.sign-box__title { font-weight: 700; color: var(--brand-navy-deep); margin-bottom: 1.6rem; }
.sign-box__line { border-top: 1px solid var(--ink); padding-top: .25rem; color: var(--muted); }

.sheet__foot {
  margin-top: .9rem;
  padding-top: .5rem;
  border-top: 1px solid var(--line);
  font-size: .7rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------
   10. منشئ الماستر شيت
   ------------------------------------------------------------------ */
.builder-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 1rem;
  align-items: start;
}

.builder-panel {
  position: sticky;
  top: calc(var(--topbar-h) + .6rem);
  max-height: calc(100vh - var(--topbar-h) - 1.4rem);
  overflow-y: auto;
}

.builder-live-badge {
  font-size: .74rem;
  color: var(--ok-green);
  font-weight: 700;
}

.col-list { list-style: none; margin: 0; padding: 0; }

.col-list li {
  border-bottom: 1px dashed var(--line);
  padding: .18rem 0;
}

.col-list li:last-child { border-bottom: 0; }

.col-group-title {
  font-size: .74rem;
  font-weight: 700;
  color: var(--brand-gold);
  padding-top: .5rem;
}

.preview-empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* ------------------------------------------------------------------
   11. الإحصائيات والرسوم (بلا مكتبات خارجية)
   ------------------------------------------------------------------ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: .85rem;
  margin-bottom: 1.1rem;
}

.stat-card {
  background: var(--brand-white);
  border: 1px solid var(--line);
  border-top: 4px solid var(--brand-navy);
  border-radius: var(--radius);
  padding: .8rem .9rem;
  box-shadow: var(--shadow-sm);
}

.stat-card--ok { border-top-color: var(--ok-green); }
.stat-card--fail { border-top-color: var(--fail-red); }
.stat-card--warn { border-top-color: var(--warn-orange); }
.stat-card--gold { border-top-color: var(--brand-gold); }

.stat-card__label { font-size: .78rem; color: var(--muted); margin: 0; }
.stat-card__value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--brand-navy-deep);
  margin: .15rem 0 0;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}
.stat-card__foot { font-size: .72rem; color: var(--muted-soft); margin: .1rem 0 0; }

.bar-chart { display: grid; gap: .45rem; }

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 74px;
  align-items: center;
  gap: .55rem;
  font-size: .82rem;
}

.bar-track {
  background: var(--neutral);
  border-radius: 999px;
  height: 16px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand-navy), var(--brand-navy-deep));
  border-radius: 999px;
  transition: width .5s ease;
}

.bar-fill--gold { background: linear-gradient(90deg, var(--brand-gold), #A8831B); }
.bar-fill--ok { background: linear-gradient(90deg, var(--ok-green), #14653D); }
.bar-fill--fail { background: linear-gradient(90deg, var(--fail-red), #8E2029); }
.bar-fill--warn { background: linear-gradient(90deg, var(--warn-orange), #B34409); }

.bar-value { text-align: center; font-variant-numeric: tabular-nums; direction: ltr; color: var(--muted); }

.donut {
  width: 100%;
  max-width: 260px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.legend { list-style: none; margin: .6rem 0 0; padding: 0; font-size: .82rem; }
.legend li { display: flex; align-items: center; gap: .45rem; padding: .12rem 0; }
.legend__swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }

.split-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.split-table th, .split-table td { border: 1px solid var(--line); padding: .4rem .55rem; text-align: center; }
.split-table thead th { background: var(--brand-navy-soft); color: var(--brand-navy-deep); }

/* ------------------------------------------------------------------
   12. الشهادات (A4 رأسي، كل شهادة صفحة)
   ------------------------------------------------------------------ */
.cert-page {
  background: var(--brand-white);
  border: 2px solid var(--brand-navy);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.cert-page::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.cert-header { text-align: center; margin-bottom: .8rem; position: relative; }

.cert-header img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  margin-bottom: .35rem;
}

.cert-header .u { font-size: 1.15rem; font-weight: 700; color: var(--brand-navy-deep); margin: 0; }
.cert-header .c { font-size: .88rem; margin: .1rem 0 0; }
.cert-header .d { font-size: .84rem; color: var(--muted); margin: .1rem 0 0; }

/* --- الترويسة المرتّبة: الشعار · الجهة · الترقيم في ثلاثة أعمدة ---
   Each column keeps its own role, so the logo never shifts when a department name is
   long, and the serial number stays with the document rather than floating. */
.cert-header__logo { flex: 0 0 auto; }
.cert-header__logo img { width: 78px; height: 78px; object-fit: contain; }
.cert-header__org { flex: 1 1 auto; text-align: center; min-width: 0; }
.cert-header__meta {
  flex: 0 0 auto;
  text-align: start;
  font-size: .74rem;
  color: var(--muted);
  min-width: 110px;
}
.cert-header__meta p { margin: 0 0 .15rem; }

.cert-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-align: start;
  margin-bottom: .9rem;
  padding-bottom: .6rem;
  border-bottom: 2px solid var(--brand-gold);
  position: relative;
}

/* --- شهادة الطالب: التقييم هو نجمها --- */
.cert-page--award .cert-title { margin-top: .4rem; }

.cert-titles { text-align: center; }

.cert-ident { margin: .8rem 0 .4rem; }
.cert-ident__lead { text-align: center; font-size: .94rem; margin: 0 0 .3rem; }
.cert-facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .35rem 1.4rem;
  margin: .5rem 0 0;
  font-size: .84rem;
}
.cert-facts > div { display: flex; gap: .35rem; margin: 0; }
.cert-facts dt { color: var(--muted); font-weight: 600; }
.cert-facts dd { margin: 0; font-weight: 600; }

.award-banner {
  text-align: center;
  border: 2px solid var(--brand-navy);
  border-radius: 12px;
  padding: 1rem;
  margin: 1rem 0 1.2rem;
  background: linear-gradient(180deg, #FFFFFF 0%, var(--brand-navy-soft) 100%);
}
.award-banner__label {
  margin: 0;
  font-size: .84rem;
  letter-spacing: .12em;
  color: var(--brand-navy);
  font-weight: 700;
}
.award-banner__value {
  margin: .3rem 0 0;
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--brand-navy-deep);
  line-height: 1.15;
}
.award-banner__meta { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); }

/* Every rating gets its own colour and faint wash, so the grade is readable at a
   glance on a printed page as well as on screen. */
.award-banner--excellent { border-color: #1B7F4C; background: linear-gradient(180deg, #FFFFFF 0%, #E7F6EC 100%); }
.award-banner--excellent .award-banner__value { color: #1B7F4C; }
.award-banner--very_good { border-color: #1F7A8C; background: linear-gradient(180deg, #FFFFFF 0%, #E6F4F7 100%); }
.award-banner--very_good .award-banner__value { color: #1F7A8C; }
.award-banner--good { border-color: var(--brand-navy); }
.award-banner--good .award-banner__value { color: var(--brand-navy); }
.award-banner--average { border-color: #C9A227; background: linear-gradient(180deg, #FFFFFF 0%, #FBF4DF 100%); }
.award-banner--average .award-banner__value { color: #8A6D12; }
.award-banner--acceptable { border-color: #B8860B; }
.award-banner--acceptable .award-banner__value { color: #8A6D12; }
.award-banner--weak { border-color: #B3261E; background: linear-gradient(180deg, #FFFFFF 0%, #FBEAE8 100%); }
.award-banner--weak .award-banner__value { color: #B3261E; }

.award-course { margin: 1rem 0; }
.award-course__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  font-size: 1rem;
  color: var(--brand-navy);
  margin: 0 0 .4rem;
  padding-bottom: .25rem;
  border-bottom: 1px solid var(--brand-navy-soft);
}
.award-course__rating {
  font-size: .84rem;
  font-weight: 700;
  padding: .15rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--brand-navy);
  color: var(--brand-navy);
}
.award-table .award-col-units { width: 80px; text-align: center; }
.award-table .award-col-rate { width: 140px; text-align: center; }
.award-rate { text-align: center; font-weight: 700; }
.award-rate--excellent { color: #1B7F4C; }
.award-rate--very_good { color: #1F7A8C; }
.award-rate--good { color: var(--brand-navy); }
.award-rate--average, .award-rate--acceptable { color: #8A6D12; }
.award-rate--weak { color: #B3261E; }
.award-empty { text-align: center; color: var(--muted); font-style: italic; }

.award-status {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  margin: 1rem 0;
}
.award-status__box {
  flex: 1 1 200px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: .55rem .8rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.award-status__box--warn { border-color: #B8860B; background: #FDF7E6; }
.award-status__label { font-size: .76rem; color: var(--muted); font-weight: 600; }
.award-status__value { font-size: 1rem; font-weight: 700; }

.award-note {
  font-size: .76rem;
  color: var(--muted);
  text-align: center;
  margin: .6rem 0 1rem;
  line-height: 1.7;
}

.cert-col-num { width: 40px; text-align: center; }
.cert-col-mark { width: 90px; text-align: center; }
.cert-total { font-weight: 700; }
.cert-table { margin-top: .4rem; }
.cert-empty { text-align: center; color: var(--muted); padding: .8rem; font-style: italic; }
.cert-note { font-size: .78rem; color: var(--muted); text-align: center; margin: .5rem 0; }

.cert-signs__role { font-weight: 600; }
.cert-signs__unit { display: block; font-size: .74rem; color: var(--muted); font-weight: 400; }

.cert-foot {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  margin-top: 1.1rem;
  padding-top: .45rem;
  border-top: 1px solid var(--brand-navy-soft);
  font-size: .72rem;
  color: var(--muted);
  flex-wrap: wrap;
}

.cert-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand-navy);
  margin: 1rem 0 .2rem;
  letter-spacing: .02em;
}

.cert-title-en {
  text-align: center;
  font-size: .78rem;
  letter-spacing: .18em;
  color: var(--brand-gold);
  margin: 0 0 1rem;
  text-transform: uppercase;
}

.cert-body { font-size: .95rem; text-align: center; margin-bottom: .9rem; }

.cert-student {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand-navy-deep);
  border-bottom: 2px dotted var(--brand-gold);
  display: inline-block;
  padding: 0 .6rem .1rem;
}

.cert-stats {
  display: flex;
  justify-content: center;
  gap: 1.6rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.cert-stat { text-align: center; }
.cert-stat__label { font-size: .74rem; color: var(--muted); margin: 0; }
.cert-stat__value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--brand-navy);
  margin: .1rem 0 0;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.cert-signs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.6rem;
  font-size: .82rem;
  text-align: center;
}

.cert-signs .sign-line { border-top: 1px solid var(--ink); margin-top: 2rem; padding-top: .25rem; }

.cert-serial {
  text-align: center;
  font-size: .72rem;
  color: var(--muted-soft);
  margin-top: 1rem;
  font-family: var(--font-mono);
  direction: ltr;
}

/* ------------------------------------------------------------------
   13. شاشة الدخول وصفحة «حول النظام»
   ------------------------------------------------------------------ */
.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 15% 20%, rgba(201, 162, 39, .18), transparent 45%),
    linear-gradient(160deg, var(--brand-navy) 0%, var(--brand-navy-deep) 100%);
}

.auth-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--brand-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border-top: 6px solid var(--brand-gold);
  overflow: hidden;
}

.auth-card__head {
  text-align: center;
  padding: 1.3rem 1.3rem .6rem;
}

.auth-card__head img { width: 96px; height: 96px; object-fit: contain; }
.auth-card__head h1 { font-size: 1.2rem; margin: .5rem 0 .2rem; }
.auth-card__head p { font-size: .82rem; color: var(--muted); margin: 0; }

.auth-card__body { padding: 1rem 1.4rem 1.5rem; }

.auth-card__foot {
  background: var(--brand-navy-soft);
  border-top: 1px solid var(--line);
  padding: .6rem 1rem;
  text-align: center;
  font-size: .72rem;
  color: var(--brand-navy-deep);
  line-height: 1.6;
}

.alert {
  border-radius: var(--radius-sm);
  padding: .55rem .8rem;
  font-size: .84rem;
  margin-bottom: .9rem;
  border: 1px solid transparent;
}

.alert--error { background: var(--fail-soft); color: var(--fail-red); border-color: var(--fail-red); }
.alert--warn { background: var(--warn-soft); color: var(--warn-orange); border-color: var(--warn-orange); }
.alert--ok,
.alert--success { background: var(--ok-soft); color: var(--ok-green); border-color: var(--ok-green); }
.alert--info { background: var(--brand-navy-soft); color: var(--brand-navy-deep); border-color: var(--brand-navy); }

.public-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
}

.public-main {
  flex: 1;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  padding: 1.6rem 1.2rem 2.4rem;
}

.about-hero {
  text-align: center;
  background: linear-gradient(160deg, var(--brand-navy) 0%, var(--brand-navy-deep) 100%);
  color: var(--brand-white);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.2rem;
  border-bottom: 5px solid var(--brand-gold);
  margin-bottom: 1.2rem;
}

.about-hero img {
  width: 110px;
  height: 110px;
  object-fit: contain;
  background: var(--brand-white);
  border-radius: 50%;
  padding: 6px;
  border: 3px solid var(--brand-gold);
}

.about-hero h1 { color: var(--brand-white); margin: .6rem 0 .2rem; }
.about-hero p { color: var(--brand-gold-soft); margin: 0; font-size: .88rem; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: .3rem .8rem; font-size: .87rem; }
.kv dt { font-weight: 700; color: var(--brand-navy-deep); }
.kv dd { margin: 0; color: var(--ink); }

.credits-block {
  background: var(--brand-navy-soft);
  border-inline-start: 5px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  font-weight: 700;
  color: var(--brand-navy-deep);
  text-align: center;
  line-height: 1.8;
}

/* ------------------------------------------------------------------
   14. أدوات مساعدة
   ------------------------------------------------------------------ */
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }
.mt-2 { margin-top: 1rem !important; }
.w-100 { width: 100% !important; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.scroll-top {
  position: fixed;
  inset-inline-start: 1.2rem;
  bottom: 1.2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brand-navy);
  color: var(--brand-white);
  border: 2px solid var(--brand-gold);
  display: none;
  place-items: center;
  cursor: pointer;
  z-index: 40;
  box-shadow: var(--shadow);
}

.scroll-top.is-visible { display: grid; }

.toast-host {
  position: fixed;
  inset-inline-start: 50%;
  transform: translateX(50%);
  bottom: 1.4rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  pointer-events: none;
}

.toast {
  background: var(--brand-navy-deep);
  color: var(--brand-white);
  border-inline-start: 5px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  padding: .6rem 1rem;
  font-size: .86rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease;
}

.toast--ok { border-inline-start-color: var(--ok-green); }
.toast--error { border-inline-start-color: var(--fail-red); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.skeleton {
  background: linear-gradient(90deg, var(--neutral) 25%, #F7F9FB 50%, var(--neutral) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s infinite;
  border-radius: var(--radius-sm);
  min-height: 1rem;
}

@keyframes skeleton {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* ------------------------------------------------------------------
   15. التجاوب — من اللابتوب الكبير إلى الهاتف

   المبدأ الحاكم: كل حاوية شبكية يجب أن تحمل `min-width: 0`. بدونها يأخذ
   العمود عرض أكبر عنصر داخله، وجدول بعشر أعمدة يستطيع توسيع الصفحة كلها
   خارج الشاشة — وهو ما كان يحدث فعلاً على الهاتف والتابلت.
   ------------------------------------------------------------------ */

/* الشبكة لا تتجاوز الشاشة مهما كان المحتوى عريضاً */
.app-shell {
  max-width: 100%;
  overflow-x: clip;
}
.app-shell > * { min-width: 0; }
.main { min-width: 0; }

/* كل شبكة داخل الصفحة تتقلّص بدل أن تفرض عرضها */
.grid,
.grid--2,
.grid--3,
.grid--4,
.filter-grid,
.kv,
.builder-layout,
.stat-grid,
.sheet__signatures,
.cert-signs { min-width: 0; }
.grid > *,
.filter-grid > *,
.stat-grid > * { min-width: 0; }

/* زر القائمة: مخفي على الشاشات الواسعة */
.nav-toggle { display: none; }
.nav-backdrop { display: none; }

/* ---------- لابتوب صغير / تابلت أفقي (≤ 1180px) ---------- */
@media (max-width: 1180px) {
  :root { --sidebar-w: 226px; }
  .main { padding: 1.1rem 1rem 1.8rem; }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .builder-layout { grid-template-columns: 1fr; }
  .builder-panel { position: static; max-height: none; }
}

/* ---------- تابلت عمودي (≤ 1024px) ---------- */
@media (max-width: 1024px) {
  .grid--4,
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 84px 1fr 64px; }
}

/* ---------- تابلت صغير / هاتف عريض (≤ 900px) ----------
   هنا تتحول القائمة الجانبية إلى دُرج منسحب. كان الحل السابق يضع القائمة
   كاملةً في أعلى الصفحة، فيضطر المستخدم على الهاتف للمرور بعشرين رابطاً
   قبل أن يصل إلى المحتوى. */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "topbar"
      "main"
      "footer";
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    background: var(--brand-white);
    cursor: pointer;
  }
  .nav-toggle__bars { display: flex; flex-direction: column; gap: 4px; }
  .nav-toggle__bars i {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--brand-navy);
    border-radius: 2px;
  }

  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(84vw, 320px);
    height: 100dvh;
    z-index: 60;
    transform: translateX(101%);
    transition: transform .22s ease;
    box-shadow: -8px 0 28px rgba(16, 75, 125, .28);
  }
  /* RTL: الدُرج يدخل من جهة البداية (اليمين) */
  html[dir="rtl"] .sidebar { transform: translateX(101%); }
  html[dir="ltr"] .sidebar { transform: translateX(-101%); }

  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open { overflow: hidden; }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(9, 32, 54, .45);
    backdrop-filter: blur(1px);
  }

  .sidebar__foot { display: block; padding-bottom: 1.4rem; }

  .nav { display: block; padding-bottom: .6rem; }
  .nav__link { margin-bottom: .15rem; }

  .grid--2,
  .grid--3,
  .grid--4 { grid-template-columns: 1fr; }

  .sheet__signatures { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: .4rem; }

  .main { padding: 1rem .85rem 1.6rem; }
  .topbar { padding: 0 .7rem; gap: .5rem; }
  .topbar__title { font-size: .95rem; }
  /* الاسم والدور يزحمان الشريط على الهاتف */
  .topbar__user { display: none; }
  .page-head { align-items: flex-start; }
}

/* ---------- هاتف (≤ 640px) ---------- */
@media (max-width: 640px) {
  html { font-size: 15px; }

  .topbar__badge-role { display: none; }
  .topbar__title { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* الفلاتر: عمود واحد وملء العرض */
  .filter-grid { grid-template-columns: 1fr !important; gap: .7rem; }
  .filter-grid .field,
  .filter-grid .input,
  .filter-grid .select { width: 100%; }

  .page-head { flex-direction: column; align-items: stretch; gap: .6rem; }
  .page-head .btn-row { flex-wrap: wrap; }
  .page-head .btn-row .btn { flex: 1 1 auto; }

  /* الأزرار تصل لعرض كافٍ للإبهام */
  .btn { min-height: 42px; }
  .btn--sm { min-height: 38px; }

  /* ---------- الجداول تتحوّل إلى بطاقات ----------
     جدول بعشرة أعمدة لا يمكن قراءته على هاتف إلا بتمرير أفقي متعب.
     عند `data-stack` يتحول كل صف إلى بطاقة، وكل خلية إلى سطر
     «التسمية ← القيمة». الجداول التي لا تحتمل هذا (الماستر شيت الرسمي
     وكشف الدرجات) تُترك قابلة للتمرير كما هي. */
  table.data[data-stack] { min-width: 0; width: 100%; }
  table.data[data-stack] thead { display: none; }
  table.data[data-stack] tbody,
  table.data[data-stack] tr,
  table.data[data-stack] td { display: block; width: 100%; }
  table.data[data-stack] tr {
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    margin-bottom: .6rem;
    padding: .35rem .55rem;
    background: var(--brand-white);
  }
  table.data[data-stack] td {
    display: grid;
    grid-template-columns: 42% 1fr;
    gap: .5rem;
    align-items: center;
    border: 0;
    border-bottom: 1px dashed var(--line);
    padding: .42rem 0;
    text-align: start;
    font-size: .9rem;
  }
  table.data[data-stack] td:last-child { border-bottom: 0; }
  table.data[data-stack] td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: .82rem;
  }
  /* الخلية بلا تسمية تُعرض بعرض كامل */
  table.data[data-stack] td:not([data-label]) { grid-template-columns: 1fr; }
  table.data[data-stack] td:not([data-label])::before { content: none; }
  table.data[data-stack] .empty-state { text-align: center; }

  /* الجداول العريضة التي تبقى جداول: تمرير أفقي سلس */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
  table.data:not([data-stack]) { min-width: 560px; }
  table.data th,
  table.data td { padding: .5rem .55rem; font-size: .86rem; }

  /* بطاقات المؤشرات: عمودان */
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .save-bar { flex-direction: column; align-items: stretch; }
  .save-bar .btn { width: 100%; }
  .cert-signs { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 64px 1fr 54px; }

  .card__body { padding: .85rem; }
  .card__head { padding: .7rem .85rem; }
}

/* ---------- حماية عامة من الفيض الأفقي ----------
   أي عنصر عريض بالخطأ يجب ألا يمنح الصفحة شريط تمرير أفقي؛ الجداول
   العريضة تُمرَّر داخل حاويتها (‎.table-wrap‎) لا على مستوى الصفحة.
   يُطبَّق على كل المقاسات الصغيرة والمتوسطة. */
@media (max-width: 1180px) {
  html { overflow-x: hidden; }
  body { overflow-x: hidden; max-width: 100vw; }
  .teacher-shell,
  .teacher-main,
  .public-page,
  .public-main { max-width: 100%; min-width: 0; }
  .teacher-main { padding-inline: .85rem; }
}

/* ---------- هاتف صغير (≤ 420px) ---------- */
@media (max-width: 420px) {
  html { font-size: 14.5px; }
  .main { padding: .8rem .6rem 1.4rem; }
  .stat-grid { grid-template-columns: 1fr; }
  table.data:not([data-stack]) { min-width: 460px; }
  .modal__panel, .dialog__panel { width: 96vw !important; max-width: 96vw !important; }
}

/* ---------- تابلت أفقي واسع / شاشة كبيرة (≥ 1500px) ----------
   The content column is allowed to grow with the window instead of stopping at a fixed
   1560px. A fixed ceiling left a wide dead margin on 1920/2560 screens — the report was
   "it does not fill the screen" — while a handful of very wide tables still benefit
   from a bound, so the bound is generous and proportional rather than absolute. */
@media (min-width: 1500px) {
  :root { --sidebar-w: 272px; }
  .main { max-width: none; }
}

/* ---------- مساحات جانبية متجاوبة على كل المقاسات ----------
   A fixed 22px gutter looks cramped on a laptop and lost on a 2560px monitor. The
   clamp keeps the content centred in its column at every width, which is what makes the
   page read as "filling the screen" rather than floating in the middle. */
.main { padding-inline: clamp(12px, 1.6vw, 32px); }

/* الجداول تمتد بعرض حاويتها على كل المقاسات، بلا سقف مصطنع */
.table-wrap { width: 100%; }
table.data { width: 100%; }

/* عمود التسمية يشارك العرض بدل أن يبتلعه */
table.data th:first-child,
table.data td:first-child { min-width: 120px; }

/* ---------- جداول «مفتاح ← قيمة» (الإعدادات وأمثالها) ----------
   The English key column holds one long unbreakable word. Left alone the browser gives
   it the width it wants and squeezes the Arabic label until the description breaks over
   four lines. A floor on the label and a matching floor on the key keep each on one
   line; the key is allowed to break only as a last resort, mid-word, and never with a
   hyphen invented for it. */
table.table--settings th.col-label,
table.table--settings td.col-label { min-width: 210px; }
table.table--settings th:nth-child(5),
table.table--settings td:nth-child(5) {
  min-width: 165px;
  overflow-wrap: break-word;
  word-break: normal;
}
table.table--settings { table-layout: auto; }

/* الوصول باللمس: أهداف أكبر عند وجود شاشة لمس */
@media (hover: none) and (pointer: coarse) {
  .nav__link { padding: .7rem .8rem; }
  .btn { min-height: 44px; }
  .btn--sm { min-height: 40px; }
  table.data td, table.data th { padding: .6rem .6rem; }
}

/* تقليل الحركة لمن يطلب ذلك */
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* ------------------------------------------------------------------
   16. الطباعة
   ------------------------------------------------------------------ */
@page {
  size: A4;
  margin: 8mm;
}

@media print {
  :root { --page: #FFFFFF; }

  body {
    background: #FFFFFF !important;
    color: #000000 !important;
    font-size: 10.5pt;
  }

  .no-print,
  .sidebar,
  .topbar,
  .footer,
  .scroll-top,
  .toast-host,
  .save-bar,
  .builder-panel,
  .btn,
  .teacher-topbar,
  .teacher-footer,
  .teacher-locked-note { display: none !important; }

  .app-shell { display: block !important; }
  .main { padding: 0 !important; }

  .card,
  .sheet,
  .cert-page {
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  a { color: #000 !important; text-decoration: none !important; }

  table.data thead th {
    background: #E8EFF6 !important;
    color: #000000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .cell-absent,
  td.cell-absent-sheet,
  .cell-absent {
    background: var(--warn-orange) !important;
    color: #FFFFFF !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .subject-group.is-greyed th,
  .subject-group.is-greyed td {
    background: #EEEEEE !important;
    color: #555555 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* الماستر شيت: A4 أفقي */
  body.print-master,
  body.print-master .sheet { page: master; }
  body.print-master { size: A4 landscape; }

  /* الشهادة: A4 رأسي، كل شهادة في صفحة مستقلة */
  body.print-certificates { size: A4 portrait; }

  .cert-page,
  .sheet-page {
    page-break-after: always;
    break-after: page;
  }

  .cert-page:last-child,
  .sheet-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .sheet__header { border-bottom-color: #000 !important; }
  table.sheet-table { font-size: 7.6pt; }
  table.sheet-table th,
  table.sheet-table td { border-color: #333 !important; }
  .sheet { padding: 0 !important; }

  tr, td, th { page-break-inside: avoid; }
}

@page master {
  size: A4 landscape;
  margin: 6mm;
}

@page certificate {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  body.print-certificates .cert-page { page: certificate; }
}


/* =====================================================================
   نماذج الإضافة داخل الصفحات الإدارية (طلبة / مواد)
   ===================================================================== */
.form-status {
  margin-top: 10px;
  font-size: 0.9rem;
  min-height: 1.2em;
}
.form-status.is-error { color: var(--warn-orange); }
.form-status.is-ok { color: var(--ok, #1b7f4b); }

.req { color: var(--warn-orange); font-weight: 700; }

/* اللوحة المطويّة تبدأ مخفية، ويُظهرها زر data-toggle-target */
[hidden] { display: none !important; }

#student-create-panel,
#subject-create-panel {
  border-inline-start: 3px solid var(--brand-gold, #C9A227);
}

#student-create-panel h3,
#subject-create-panel h3 {
  font-size: 1rem;
  margin: 6px 0 4px;
}

/* =====================================================================
   17. الملاحظات الإدارية · رصيد درجة القرار · المعدل التراكمي (task-21)
   أنماط إضافية فقط — لا تعدّل أي قاعدة سابقة.
   ===================================================================== */

/* --- عمود الملاحظات (يُطبع في كل الكشوف) --- */
.sheet-notes {
  text-align: start !important;
  min-width: 160px;
  max-width: 320px;
  white-space: normal;
  font-size: .82rem;
  line-height: 1.5;
}

.sheet-notes__hint {
  margin-top: .18rem;
  font-size: .72rem;
  color: var(--brand-navy);
  border-inline-start: 3px solid var(--brand-gold);
  padding-inline-start: .35rem;
}

/* --- لوحة رصيد درجة القرار --- */
.budget-panel {
  margin: .55rem 0 .7rem;
  padding: .5rem .7rem;
  background: var(--brand-navy-soft);
  border: 1px solid var(--line-strong);
  border-inline-start: 5px solid var(--brand-navy);
  border-radius: var(--radius-sm);
  font-size: .82rem;
}

.budget-panel.is-exhausted {
  background: var(--warn-soft);
  border-color: var(--warn-orange);
  border-inline-start-color: var(--warn-orange);
}

.budget-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .35rem;
}

.budget-panel__title { font-weight: 700; color: var(--brand-navy-deep); }

.budget-panel__flag {
  color: var(--warn-orange);
  font-weight: 700;
  white-space: nowrap;
}

.budget-panel__row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

.budget-panel__summary {
  margin: .35rem 0 0;
  font-size: .76rem;
  color: var(--muted);
}

/* خلية رصيد نافد */
td.budget-exhausted,
.budget-exhausted {
  background: var(--warn-soft) !important;
  color: var(--warn-orange) !important;
  font-weight: 700;
}

.chip--warn {
  background: var(--warn-soft);
  border-color: var(--warn-orange);
  color: var(--warn-orange);
}

/* --- لوحة حالة القيد داخل جدول الطلبة --- */
.admin-status-panel {
  margin-top: .5rem;
  padding: .6rem .7rem;
  background: var(--brand-navy-soft);
  border: 1px solid var(--line-strong);
  border-inline-start: 4px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  text-align: start;
  min-width: 230px;
}

.admin-status-panel .field { margin-bottom: .5rem; }
.admin-status-panel .field__label { font-size: .78rem; }

.admin-status-history {
  margin-top: .5rem;
  border-top: 1px dashed var(--line-strong);
  padding-top: .4rem;
}

.admin-status-history ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: .76rem;
}

.admin-status-history li {
  display: flex;
  gap: .35rem;
  align-items: baseline;
  flex-wrap: wrap;
  padding: .15rem 0;
  border-bottom: 1px dashed var(--line);
}

.admin-status-history li:last-child { border-bottom: 0; }

.admin-status-history__note { color: var(--ink); }
.admin-status-history__date { color: var(--muted); font-size: .72rem; }

/* --- أوزان المراحل في الإعدادات --- */
.stage-weights .stage-weights__total td {
  background: var(--brand-navy-soft);
  font-weight: 700;
}

/* --- المعدل التراكمي --- */
.cumulative-rule {
  border-inline-start: 6px solid var(--warn-orange);
  font-size: .88rem;
}

.cumulative-table .cumulative-weight {
  font-weight: 600;
  color: var(--brand-navy);
  margin: 0;
}

.cumulative-table .cumulative-stage-head {
  background: var(--brand-navy-deep);
  font-size: .74rem;
  font-weight: 600;
}

.cumulative-stage-cell { font-variant-numeric: tabular-nums; }
.cumulative-stage-cell .field__hint { margin-top: .12rem; font-size: .68rem; }

.cumulative-gpa {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand-navy-deep);
  background: var(--brand-gold-soft);
}

.cumulative-reasons { text-align: start; font-size: .8rem; }
.cumulative-reasons ul { margin: 0; padding-inline-start: 1rem; }
.cumulative-reasons li { color: var(--fail-red); }

/* --- الطباعة: الملاحظات ورصيد القرار تظهر ورقياً --- */
@media print {
  body.print-cumulative { size: A4 landscape; }

  .budget-panel {
    border: 1px solid #333 !important;
    background: #F6F8FA !important;
    page-break-inside: avoid;
  }

  table.data .sheet-notes,
  table.data td.budget-exhausted {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .admin-status-panel,
  .no-print.admin-status-panel { display: none !important; }
}
