/* ===== الألوان والخطوط ===== */
:root {
  --ink: #1E1B4B;        /* نيلي غامق: القايمة الجانبية والعناوين */
  --primary: #4338CA;    /* نيلي: الأزرار والروابط */
  --primary-soft: #EEF0FF;
  --amber: #F59E0B;      /* كهرماني: علامة الصفحة الحالية والتنبيهات */
  --amber-soft: #FEF3C7;
  --paper: #F6F6FA;      /* خلفية الصفحة */
  --line: #E4E4EE;       /* الخطوط بين الصفوف */
  --text: #1F2033;
  --muted: #6B6C80;
  --ok: #15803D;
  --ok-soft: #DCFCE7;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--paper);
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.3; margin: 0; color: var(--ink); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ===== الأزرار ===== */
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: #3730A3; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: #fff; }
.btn.ghost-light { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; }

/* ===== الحقول ===== */
label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; color: var(--ink); }
input, select {
  font: inherit; font-weight: 400;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled { background: var(--paper); color: var(--muted); }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin: 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 0; font-weight: 400; }

/* ===== شاشة الدخول ===== */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-brand {
  background: var(--ink); color: #fff;
  display: flex; flex-direction: column; justify-content: center; padding: 64px;
}
.login-brand .lotus { width: 72px; height: 72px; margin-bottom: 24px; }
.login-brand h1 { color: #fff; font-size: 40px; font-weight: 700; }
.login-brand p { color: #C7C6E8; font-size: 18px; margin: 8px 0 0; }
.login-form { align-self: center; justify-self: center; width: min(400px, 90%); display: grid; gap: 18px; }
.login-form h2 { font-size: 26px; margin-bottom: 6px; }

.lotus path { fill: var(--amber); stroke: var(--amber); }

/* ===== الهيكل العام ===== */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: #fff;
  display: flex; flex-direction: column; padding: 22px 14px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 10px 26px; }
.side-brand .lotus { width: 32px; height: 32px; }
.nav { display: grid; gap: 4px; }
.nav a {
  color: #D4D3F0; text-decoration: none; padding: 10px 14px; border-radius: 10px;
  border-inline-start: 3px solid transparent; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; border-inline-start-color: var(--amber); font-weight: 700; }
.side-user {
  margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.12);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.side-user strong { display: block; font-size: 14px; }
.role { font-size: 12px; color: var(--amber); }

.page { padding: 32px clamp(16px, 4vw, 48px); max-width: 1280px; width: 100%; }

/* ===== رأس الصفحة وشريط الأدوات ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; }
.page-head .sub { margin: 4px 0 0; color: var(--muted); }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1 1 280px; max-width: 420px; }
.toolbar select { flex: 0 1 240px; }

/* ===== الجدول ===== */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; min-width: 820px; }
.data th {
  text-align: start; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: #FAFAFD;
}
.data td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data tr:last-child td { border-bottom: 0; }
.data tbody tr:hover { background: #FAFAFF; }
.data .name { font-weight: 600; color: var(--ink); }
.data .email { color: var(--muted); font-size: 13px; direction: ltr; text-align: end; }
.data .phone { direction: ltr; text-align: end; white-space: nowrap; }
.data tr.inactive .name { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 20px; white-space: nowrap; }
.none { color: var(--muted); font-size: 13px; }

.device { font-size: 13px; }
.device.bound { color: var(--ink); }
.device.bound::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-inline-end: 6px; }
.device small { display: block; color: var(--muted); }

.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* قايمة الإجراءات في كل صف */
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--ink); background: #fff;
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { border-color: var(--primary); }
.menu-list {
  position: absolute; inset-inline-end: 0; top: calc(100% + 4px); z-index: 10;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(30, 27, 75, .14); min-width: 210px; padding: 6px; display: grid;
}
.menu-list button {
  font: inherit; text-align: start; background: none; border: 0; padding: 9px 12px;
  border-radius: 8px; cursor: pointer; color: var(--text);
}
.menu-list button:hover { background: var(--paper); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ===== النوافذ ===== */
.modal {
  border: 0; border-radius: 16px; padding: 0; width: min(560px, 94vw);
  box-shadow: 0 24px 64px rgba(30, 27, 75, .25); color: var(--text);
}
.modal::backdrop { background: rgba(30, 27, 75, .45); }
.modal form, .modal .modal-body { padding: 26px; display: grid; gap: 16px; }
.modal h2 { font-size: 21px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 4px; }
.confirm { width: min(440px, 94vw); }
.confirm p { margin: 0; color: var(--muted); }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; }

fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0; }
legend { font-weight: 600; font-size: 14px; color: var(--ink); padding: 0 6px; }
.checks { display: grid; gap: 8px; max-height: 180px; overflow-y: auto; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

.cred {
  background: var(--paper); border: 1px dashed var(--line); border-radius: 12px;
  padding: 14px; white-space: pre-line;
}

/* ===== الرسايل الصغيرة ===== */
.toasts { position: fixed; bottom: 20px; inset-inline-start: 20px; display: grid; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(30,27,75,.3); max-width: 360px;
  border-inline-start: 4px solid #4ADE80;
}
.toast.error { border-inline-start-color: #F87171; }

/* ===== الموبايل والتابلت ===== */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 40px 24px; }
  .login-brand h1 { font-size: 30px; }
  .login-form { padding: 32px 0; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .side-brand { padding: 4px 6px 12px; }
  .nav { display: flex; overflow-x: auto; }
  .nav a { white-space: nowrap; border-inline-start: 0; border-bottom: 3px solid transparent; }
  .nav a.active { border-bottom-color: var(--amber); }
  .side-user { padding-top: 10px; margin-top: 10px; }
  .row2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===== الدورات والدروس ===== */
.back { display: inline-block; color: var(--primary); text-decoration: none; font-weight: 600; margin-bottom: 10px; }
.back:hover { text-decoration: underline; }
.course-cell { display: flex; align-items: center; gap: 12px; }
.thumb {
  width: 64px; height: 40px; border-radius: 8px; flex: none; background: var(--primary-soft);
  background-size: cover; background-position: center;
}
.course-cell a { color: var(--ink); font-weight: 600; text-decoration: none; }
.course-cell a:hover { color: var(--primary); }
.desc { color: var(--muted); font-size: 13px; max-width: 520px; }
.count { font-weight: 600; color: var(--ink); }

.course-head { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: start; margin-bottom: 26px; }
.course-head .cover { aspect-ratio: 16/9; border-radius: 14px; background: var(--primary-soft) center/cover no-repeat; }
.course-head h1 { font-size: 28px; }
.course-head p { margin: 6px 0 12px; color: var(--muted); max-width: 640px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.order-cell { width: 92px; }
.order-num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px; }
.move { font: inherit; background: none; border: 1px solid var(--line); border-radius: 6px; width: 26px; height: 26px; cursor: pointer; color: var(--muted); line-height: 1; }
.move:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.move:disabled { opacity: .35; cursor: default; }
.parts { font-size: 13px; color: var(--muted); }
.parts b { color: var(--ink); font-weight: 600; }

/* نافذة عريضة لفورم الدرس */
.modal.wide { width: min(780px, 96vw); }
.modal form { max-height: 88vh; overflow-y: auto; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title h3 { font-size: 16px; }
.list { display: grid; gap: 8px; }
.list-row { display: flex; gap: 8px; align-items: center; }
.list-row input { flex: 1; }
.list-row .tag { flex: none; font-size: 13px; color: var(--muted); width: 58px; }
.icon-btn {
  font: inherit; flex: none; width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 18px; line-height: 1;
}
.icon-btn:hover { border-color: var(--danger); color: var(--danger); }
.add-btn { font: inherit; background: none; border: 1px dashed var(--line); border-radius: 10px; padding: 9px; cursor: pointer; color: var(--primary); font-weight: 600; width: 100%; }
.add-btn:hover { border-color: var(--primary); background: var(--primary-soft); }

.q-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; background: #FCFCFE; }
.q-top { display: flex; gap: 8px; align-items: flex-start; }
.q-num { flex: none; font-weight: 700; color: var(--primary); padding-top: 9px; width: 28px; }
.q-top input { flex: 1; }
.opt { display: flex; gap: 8px; align-items: center; }
.opt input[type=radio] { width: 18px; height: 18px; flex: none; accent-color: var(--ok); margin-inline-start: 34px; }
.opt input[type=text] { flex: 1; }
.opt.correct input[type=text] { border-color: var(--ok); background: var(--ok-soft); }
.q-actions { display: flex; justify-content: space-between; align-items: center; margin-inline-start: 34px; }
.small-link { font: inherit; background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }
.small-link.danger { color: var(--danger); }

@media (max-width: 860px) {
  .course-head { grid-template-columns: 1fr; }
}

/* ===== معاينة الاستيراد ===== */
.preview { max-height: 300px; overflow: auto; }
.preview table.data { min-width: 560px; }
.preview .data td, .preview .data th { padding: 8px 12px; font-size: 13px; }
.row-bad td { background: var(--danger-soft); }
.bad { color: var(--danger); font-weight: 600; }

/* ===== النتايج ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 16px; }
.stats div { background: #fff; padding: 16px 18px; }
.stats b { display: block; font-size: 26px; color: var(--ink); line-height: 1.2; }
.stats span { color: var(--muted); font-size: 13px; }
.bar { width: 140px; height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--primary); border-radius: 8px; }
.score { font-weight: 700; }
.score.good { color: var(--ok); }
.score.low { color: var(--danger); }
@media (max-width: 860px) { .stats { grid-template-columns: 1fr 1fr; } }
