/* =====================================================================
   كلية إمبريال الجامعية — نظام التصميم (Mobile First)
   هوية هادئة وعصرية: سطوح بيضاء، حدود رفيعة، ظلال خفيفة جدًا، وحركة شبه معدومة.
   ===================================================================== */

:root {
  color-scheme: light;

  /* الهوية */
  --navy: #112d4e;
  --navy-900: #0b1f38;
  --blue: #3f72af;
  --blue-600: #2f5d94;
  --blue-100: #dbe2ef;
  --blue-50: #eef3fa;
  --gold: #b8912f;

  /* السطوح والنصوص */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f1b2d;
  --text-2: #334155;
  --text-muted: #64748b;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;

  /* الحالات */
  --success: #15803d;
  --success-bg: #ecfdf3;
  --danger: #c0262d;
  --danger-bg: #fef2f2;
  --warning: #a15c07;
  --warning-bg: #fff8eb;
  --info: #2f5d94;
  --info-bg: #eef3fa;

  /* المقاسات */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.05);
  --shadow: 0 1px 3px rgba(15, 27, 45, 0.06), 0 8px 24px -12px rgba(15, 27, 45, 0.12);
  --shadow-lg: 0 24px 48px -16px rgba(15, 27, 45, 0.28);
  --gutter: clamp(1rem, 3vw, 2rem);
  --tap: 44px;
  --focus: 0 0 0 3px rgba(63, 114, 175, 0.35);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --transition: 120ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  overflow-x: hidden;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

img, svg, canvas { display: block; max-width: 100%; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.35; color: var(--text); font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.45rem, 1.15rem + 1.3vw, 2.1rem); }
h2 { font-size: clamp(1.15rem, 1.05rem + 0.5vw, 1.4rem); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
a { color: var(--blue-600); text-underline-offset: 3px; }
a:hover { color: var(--navy); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
::selection { background: var(--blue-100); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; inset-inline-start: 1rem; top: -100px; z-index: 1000;
  padding: 0.6rem 1rem; background: var(--navy); color: #fff; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 1rem; color: #fff; }

.ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.ltr.strong { font-weight: 600; color: var(--text); }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }

/* ---------- الأيقونات والتحميل ---------- */
.icon { width: 1.2rem; height: 1.2rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.spinner {
  width: 1.05em; height: 1.05em; flex: none; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- الأزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  min-height: var(--tap); padding: 0.5rem 1.05rem;
  font: inherit; font-weight: 600; font-size: 0.95rem; line-height: 1.2; text-decoration: none; white-space: nowrap;
  color: var(--text-2); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  cursor: pointer; transition: background-color var(--transition), border-color var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); border-color: #b6c2d3; color: var(--text); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 1.1em; height: 1.1em; }

.btn-primary { color: #fff; background: var(--navy); border-color: var(--navy); }
.btn-primary:hover { color: #fff; background: var(--navy-900); border-color: var(--navy-900); }
.btn-secondary { color: #fff; background: var(--blue); border-color: var(--blue); }
.btn-secondary:hover { color: #fff; background: var(--blue-600); border-color: var(--blue-600); }
.btn-success { color: #fff; background: var(--success); border-color: var(--success); }
.btn-success:hover { color: #fff; background: #116a33; border-color: #116a33; }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { color: #fff; background: #a11f25; border-color: #a11f25; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--blue-50); border-color: transparent; }
.btn-sm { min-height: 36px; padding: 0.3rem 0.75rem; font-size: 0.86rem; border-radius: 10px; }
.btn-lg { min-height: 52px; padding: 0.7rem 1.5rem; font-size: 1.02rem; }
.btn-block { width: 100%; }

/* ---------- النماذج ---------- */
.field { display: grid; gap: 0.4rem; margin-bottom: 1rem; min-width: 0; }
.field label, .field .label { font-weight: 600; font-size: 0.9rem; color: var(--text-2); }
.field .hint { font-size: 0.84rem; color: var(--text-muted); }
.field .error-text { font-size: 0.86rem; color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 0.55rem 0.85rem;
  font: inherit; font-size: 1rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { min-height: 110px; resize: vertical; }
.input:hover, .select:hover { border-color: #b6c2d3; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--blue); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input.ltr { text-align: left; }
.input.ltr::placeholder { text-align: right; direction: rtl; }
input[type="file"].input { padding: 0.45rem; }
input[type="file"]::file-selector-button {
  margin-inline-end: 0.75rem; padding: 0.4rem 0.9rem; font: inherit; font-weight: 600; font-size: 0.88rem;
  color: var(--navy); background: var(--blue-50); border: 0; border-radius: 8px; cursor: pointer;
}

.checkbox { display: inline-flex; align-items: center; gap: 0.55rem; min-height: var(--tap); cursor: pointer; }
.checkbox input, .choice input { width: 1.2rem; height: 1.2rem; accent-color: var(--navy); }

.form-grid { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) { .form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }

.choice-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0; padding: 0; border: 0; }
.choice-list legend { width: 100%; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-2); }
.choice {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: var(--tap); padding: 0.4rem 0.85rem;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; font-weight: 500;
}
.choice:has(input:checked) { border-color: var(--navy); background: var(--blue-50); }

/* ---------- البطاقات ---------- */
.card {
  min-width: 0; padding: clamp(1rem, 2.5vw, 1.5rem);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card + .card, .card + section, section + .card { margin-top: 1rem; }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.card-header h2, .card-header h3 { margin: 0; }

/* ---------- التنبيهات ---------- */
.alert {
  display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.85rem 1rem;
  border-radius: var(--radius); border: 1px solid transparent; background: var(--info-bg); color: var(--info);
}
.alert .icon { margin-top: 0.2rem; }
.alert p:last-child { margin-bottom: 0; }
.alert-title { margin: 0 0 0.15rem; font-weight: 700; font-size: 0.98rem; color: inherit; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #c6ecd4; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #f6cfd1; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f3dfb8; }
.alert-info { border-color: #d5e1f0; }

/* ---------- الشارات والتقديرات ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.12rem 0.6rem;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap;
  color: var(--navy); background: var(--blue-50); border-radius: 999px;
}
.badge .icon { width: 0.9rem; height: 0.9rem; }
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-danger { color: var(--danger); background: var(--danger-bg); }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-muted { color: var(--text-muted); background: #eef1f5; }

.grade {
  display: inline-flex; align-items: center; justify-content: center; min-width: 2.9rem; padding: 0.22rem 0.55rem;
  font-weight: 700; font-size: 0.98rem; direction: ltr; border-radius: 8px; border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}
.grade-Ap { color: #0b5a2e; background: #dcf5e6; border-color: #b4e5c7; }
.grade-A  { color: #15803d; background: #ecfaf1; border-color: #c9eed7; }
.grade-Bp { color: #1d4ed8; background: #e5edff; border-color: #c4d4fb; }
.grade-B  { color: #2f5d94; background: #eef4fb; border-color: #d3e0f0; }
.grade-Cp { color: #3f5f7a; background: #edf2f7; border-color: #d4dee8; }
.grade-Cp { color: #3f5f7a; background: #edf2f7; border-color: #d4dee8; }
.grade-C  { color: #475569; background: #f1f4f8; border-color: #dde3ea; }
.grade-Dp { color: #8a5a12; background: #fdf3e2; border-color: #efd9b0; }
.grade-D  { color: #a15c07; background: #fff4e0; border-color: #f4d7a6; }
.grade-F  { color: #b91c1c; background: #fdecec; border-color: #f5c3c3; }

/* ---------- الجداول ---------- */
.table-wrap {
  width: 100%; overflow-x: auto; container-type: inline-size;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.94rem; }
.table th, .table td { padding: 0.75rem 0.9rem; text-align: start; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  color: var(--text-muted); font-weight: 600; font-size: 0.8rem; white-space: nowrap;
}
.table tbody tr:last-child > * { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.table .actions { white-space: nowrap; text-align: end; }
.table .actions .btn + .btn { margin-inline-start: 0.3rem; }
.table-empty { padding: 2.25rem 1rem; text-align: center; color: var(--text-muted); }

@container (width < 640px) {
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td, .table.stack th { display: block; }
  .table.stack thead { display: none; }
  .table.stack tr { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); }
  .table.stack tbody tr:last-child { border-bottom: 0; }
  .table.stack td, .table.stack tbody th {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 0.3rem 0; border: 0; text-align: end;
  }
  .table.stack td::before, .table.stack tbody th::before {
    content: attr(data-label); flex: none; text-align: start; font-weight: 600; font-size: 0.82rem; color: var(--text-muted);
  }
  .table.stack td.actions { justify-content: flex-end; flex-wrap: wrap; padding-top: 0.5rem; }
  .table.stack td.actions::before { content: none; }
}

/* ---------- الترقيم ---------- */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-top: 1rem; }
.pager-buttons { display: flex; gap: 0.5rem; }

/* ---------- النوافذ المنبثقة ---------- */
dialog.modal {
  width: min(620px, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); padding: 0;
  color: var(--text); background: var(--surface); border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
dialog.modal.wide { width: min(980px, calc(100vw - 1.5rem)); }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal::backdrop { background: rgba(11, 31, 56, 0.45); }
.modal-header, .modal-footer { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.25rem; flex: none; }
.modal-header { justify-content: space-between; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { flex: 1 1 auto; padding: 1.25rem; overflow-y: auto; overscroll-behavior: contain; }
.modal-footer { justify-content: flex-start; flex-wrap: wrap; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- الإشعارات ---------- */
.toast-region { position: fixed; inset-inline: 0.75rem; bottom: 0.75rem; z-index: 2000; display: grid; gap: 0.5rem; pointer-events: none; }
@media (min-width: 640px) { .toast-region { inset-inline-start: auto; inset-inline-end: 1.5rem; bottom: 1.5rem; width: 360px; } }
.toast {
  padding: 0.8rem 1rem; color: #fff; font-weight: 500; font-size: 0.94rem;
  background: var(--navy); border-radius: var(--radius); box-shadow: var(--shadow-lg); pointer-events: auto;
}
.toast.success { background: #146c34; }
.toast.error { background: var(--danger); }

/* ---------- أدوات ---------- */
.stack-sm > * + * { margin-top: 0.5rem; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.kv { display: grid; grid-template-columns: minmax(7rem, max-content) 1fr; gap: 0.45rem 1rem; margin: 0; }
.kv dt { color: var(--text-muted); font-weight: 500; }
.kv dd { margin: 0; font-weight: 600; min-width: 0; }
details > summary { cursor: pointer; font-weight: 600; padding: 0.35rem 0; }
pre.json {
  margin: 0; padding: 0.75rem; max-height: 320px; overflow: auto; direction: ltr; text-align: left;
  font-size: 0.8rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
.danger-text { color: var(--danger) !important; }
.danger-text:hover { background: var(--danger-bg) !important; }

/* جداول كثيرة الأعمدة: تتحول إلى بطاقات تحت 900px */
@container (width < 900px) {
  .table.stack-lg, .table.stack-lg tbody, .table.stack-lg tr, .table.stack-lg td { display: block; }
  .table.stack-lg thead { display: none; }
  .table.stack-lg tr { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); }
  .table.stack-lg tbody tr:last-child { border-bottom: 0; }
  .table.stack-lg td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.3rem 0; border: 0; text-align: end; }
  .table.stack-lg td::before { content: attr(data-label); flex: none; font-weight: 600; font-size: 0.82rem; color: var(--text-muted); }
  .table.stack-lg td.actions { justify-content: flex-end; }
  .table.stack-lg td.actions::before { content: none; }
  .table.stack-lg .dev { justify-items: end; text-align: end; }
}
