/* نظام تصميم المنصة (لوحة المعلم، الدخول، الصفحة الرئيسية، لوحة المالك)
   الشعور: «موثوق وهادئ» — إردوازي + أزرق سماوي غامق، عناوين Alexandria ونصوص Tajawal */

:root {
  --ink: #0F172A;
  --text: #1E293B;
  --muted: #526077;
  --line: #E2E8F0;
  --line-strong: #CBD5E1;
  --bg: #F6F8FB;
  --surface: #FFFFFF;
  --sunken: #EEF2F6;
  --brand: #0369A1;
  --brand-hover: #075985;
  --brand-soft: #E0F2FE;
  --brand-ink: #0C4A6E;
  --ok: #15803D;   --ok-soft: #DCFCE7;
  --warn: #A16207; --warn-soft: #FEF3C7;
  --danger: #B91C1C; --danger-soft: #FEE2E2;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r-sm: 8px; --r: 12px; --r-full: 999px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 4px 16px rgb(15 23 42 / .05);
  --shadow-lg: 0 4px 12px rgb(15 23 42 / .08), 0 24px 48px rgb(15 23 42 / .12);
  --font: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --hfont: 'Alexandria', 'Tajawal', system-ui, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 16px; line-height: 1.8; letter-spacing: 0;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; color: var(--ink); line-height: 1.4; font-weight: 700; font-family: var(--hfont); }
h3 { font-family: var(--font); }
h1 { font-size: clamp(1.6rem, 2vw + 1rem, 2.1rem); }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
.ic { flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; line-height: 1.7; }
.num { font-variant-numeric: tabular-nums; }
.lead-text { font-size: 1.05rem; color: var(--muted); }
.stack > * + * { margin-block-start: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden, [hidden] { display: none !important; }

/* ——— أزرار ——— */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s5); border-radius: var(--r-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s;
  text-decoration: none !important;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--sunken); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: .875rem; }
.btn-block { width: 100%; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #fff; border-block-start-color: transparent; animation: spin .7s linear infinite;
}
.btn-secondary.loading::after, .btn-ghost.loading::after { border-color: var(--brand); border-block-start-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-sm);
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--sunken); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ——— حقول ——— */
.field { display: grid; gap: var(--s1); }
.field > label, .label { font-weight: 600; font-size: .9rem; color: var(--ink); }
.field .hint { font-size: .8rem; color: var(--muted); line-height: 1.6; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 1rem; line-height: 1.6;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.8; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(3 105 161 / .15); }
.input[dir="ltr"] { text-align: start; }
/* حقل لاتيني بتلميح عربي: التلميح يظهر من اليمين، والكتابة من اليسار */
.input.ph-rtl::placeholder { direction: rtl; text-align: right; }
.grid-2 { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.check { display: flex; align-items: flex-start; gap: var(--s2); cursor: pointer; font-size: .95rem; }
.check input { width: 18px; height: 18px; margin-block-start: 5px; accent-color: var(--brand); }
.input-group { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.input-group:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(3 105 161 / .15); }
.input-group .addon { display: grid; place-items: center; padding: 0 var(--s3); background: var(--sunken); color: var(--muted); font-size: .9rem; direction: ltr; white-space: nowrap; }
.input-group .input { border: 0; box-shadow: none !important; min-width: 0; }

/* ——— بطاقات ——— */
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: var(--s5); }
.card-head { display: flex; align-items: center; gap: var(--s3); margin-block-end: var(--s4); }
.card-head h2, .card-head h3 { flex: 1; }
.badge {
  display: inline-flex; align-items: center; gap: var(--s1); padding: 2px var(--s2); border-radius: var(--r-full);
  font-size: .78rem; font-weight: 600; background: var(--sunken); color: var(--muted); line-height: 1.7; white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-brand { background: var(--brand-soft); color: var(--brand-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--sunken); }
.avatar-fallback { display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }

.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--muted); }
.empty .ic { margin-inline: auto; margin-block-end: var(--s3); color: var(--line-strong); }
.empty h3 { margin-block-end: var(--s2); }
.empty .btn { margin-block-start: var(--s4); }

.skeleton { background: linear-gradient(90deg, var(--sunken), #f8fafc, var(--sunken)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.page-loading { display: grid; gap: var(--s4); }
.page-loading .skeleton { height: 96px; }

.progress { height: 8px; border-radius: var(--r-full); background: var(--sunken); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .6s var(--ease); }

/* ——— نافذة ——— */
.modal { border: 0; padding: 0; background: transparent; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px); }
.modal-wide { width: min(820px, calc(100% - 24px)); }
.modal::backdrop { background: rgb(15 23 42 / .45); }
.modal[open] { animation: pop .18s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5); border-block-end: 1px solid var(--line); }
.modal-head h2 { flex: 1; font-size: 1.15rem; }
.modal-body { padding: var(--s5); overflow-y: auto; display: grid; gap: var(--s4); }
.modal-foot { display: flex; gap: var(--s2); padding: var(--s4) var(--s5); border-block-start: 1px solid var(--line); }

/* ——— تنبيهات ——— */
#toasts { position: fixed; inset-block-end: var(--s5); inset-inline-start: 50%; translate: 50% 0; z-index: 100; display: grid; gap: var(--s2); width: max-content; max-width: calc(100% - 32px); }
.toast { background: var(--ink); color: #fff; padding: var(--s3) var(--s5); border-radius: var(--r-sm); box-shadow: var(--shadow-lg); font-weight: 600; font-size: .95rem; animation: pop .2s var(--ease); transition: opacity .3s; }
.toast-err { background: var(--danger); }
.toast.out { opacity: 0; }

.demo-bar { display: flex; align-items: center; justify-content: center; gap: var(--s2); padding: var(--s2) var(--s4); background: var(--warn-soft); color: #713F12; font-size: .85rem; font-weight: 600; text-align: center; line-height: 1.6; }

/* ——— شعار ——— */
.logo { display: inline-flex; align-items: center; gap: var(--s2); font-family: var(--hfont); font-weight: 700; font-size: 1.2rem; color: var(--ink); text-decoration: none !important; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.05rem; }
.logo small { font-size: .75rem; font-weight: 400; color: var(--muted); display: block; line-height: 1.2; }

/* ——— جداول ——— */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: start; font-weight: 600; color: var(--muted); font-size: .8rem; padding: var(--s2) var(--s3); border-block-end: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--s3); border-block-end: 1px solid var(--line); vertical-align: middle; }
.table tr:hover td { background: #FAFBFD; }
.table .num { text-align: end; }

.tabs { display: flex; gap: var(--s1); padding: var(--s1); background: var(--sunken); border-radius: var(--r-sm); width: max-content; max-width: 100%; overflow-x: auto; }
.tab { border: 0; background: transparent; padding: var(--s1) var(--s4); border-radius: 6px; font: inherit; font-weight: 600; font-size: .9rem; color: var(--muted); cursor: pointer; white-space: nowrap; min-height: 36px; }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
