:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #61707f;
  --border: #d9dee3;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --success: #146c2e;
  --success-bg: #e6f4ea;
  --warning: #8a4b00;
  --warning-bg: #fff1dc;
  --yellow: #5c4700;
  --yellow-bg: #fff6c2;
  --neutral: #3d4650;
  --neutral-bg: #eceff2;
  /* تمييز "أُضيف للتو" (صفوف/بطاقات): ليس لون حالة، فيتكيف مع الوضع الداكن خلافاً لما فوق */
  --highlight-bg: #fff6c2;
  --radius: 8px;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
}

/* الوضع الداكن (L10): فقط الألوان المحايدة تتغيّر. ألوان الحالة (نجاح/تحذير/خطأ/أصفر/محايد) أعلاه تبقى
   ثابتة بالقصد (قرار المعلم 2026-11-05/2026-11-08) حتى لا يتغيّر معناها؛ كلها شارات أو رسائل لها خلفية
   فاتحة خاصة بها فتبقى مقروءة في الوضعين. صفحة طباعة الأكواد لا تحمّل theme-init.js، فتبقى فاتحة دائماً */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12171d;
  --surface: #1b222b;
  --text: #e6eaef;
  --muted: #a3afbc;
  --border: #313b46;
  --highlight-bg: #4a3f10;
}

/* لون التمييز (L10): --accent/--accent-hover لخلفيات الأزرار الملوّنة (نفس القيمة في الوضعين؛ التباين
   مع نص أبيض محسوب ويمر >= 4.5). --accent-text/--accent-soft للنص والخلفية الخفيفة (روابط، تبويبات،
   تحويم الأزرار الثانوية)، ولهما قيمة أفتح في الوضع الداكن حتى تبقى مقروءة على خلفية داكنة.
   لإضافة لون تمييز جديد: كتلة [data-accent="الاسم"] هنا (+ كتلة وضع داكن لها إن أردت نصاً أفتح)،
   وقاعدة .accent-swatch[data-accent-option="الاسم"] .dot تحت (لون المعاينة)، وسطر في ACCENTS
   بملف js/theme-init.js. لا تغيير آخر مطلوب. */
:root,
:root[data-accent="blue"]    { --accent: #1d6fb8; --accent-hover: #175c99; --accent-text: #1d6fb8; --accent-soft: #e8f1fa; }
:root[data-accent="cyan"]    { --accent: #0e7490; --accent-hover: #155e75; --accent-text: #0e7490; --accent-soft: #e0f3f7; }
:root[data-accent="indigo"]  { --accent: #4f46e5; --accent-hover: #4338ca; --accent-text: #4f46e5; --accent-soft: #ecebfc; }
:root[data-accent="purple"]  { --accent: #7e22ce; --accent-hover: #6b21a8; --accent-text: #7e22ce; --accent-soft: #f3e8fb; }
:root[data-accent="fuchsia"] { --accent: #a21caf; --accent-hover: #86198f; --accent-text: #a21caf; --accent-soft: #f9e6fa; }
:root[data-accent="slate"]   { --accent: #475569; --accent-hover: #334155; --accent-text: #475569; --accent-soft: #e9edf2; }

:root[data-theme="dark"][data-accent="blue"]    { --accent-text: #7dbbf0; --accent-soft: #1f3447; }
:root[data-theme="dark"][data-accent="cyan"]    { --accent-text: #67cfe6; --accent-soft: #16363f; }
:root[data-theme="dark"][data-accent="indigo"]  { --accent-text: #a5a0f5; --accent-soft: #2b2a52; }
:root[data-theme="dark"][data-accent="purple"]  { --accent-text: #cf9df5; --accent-soft: #38244d; }
:root[data-theme="dark"][data-accent="fuchsia"] { --accent-text: #eb93f2; --accent-soft: #43204a; }
:root[data-theme="dark"][data-accent="slate"]   { --accent-text: #b4c0cf; --accent-soft: #2d3642; }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

h1, h2, h3 { margin: 0 0 12px; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; }

.muted { color: var(--muted); margin: 0 0 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

label { display: block; margin: 12px 0 4px; font-weight: 600; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.6; cursor: default; }
button.secondary {
  color: var(--accent-text);
  background: transparent;
}
button.secondary:hover { background: var(--accent-soft); }

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius);
}

.noscript { padding: 16px; text-align: center; }

/* شاشة الدخول */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card { width: 100%; max-width: 380px; }
.login-card button { width: 100%; margin-top: 20px; }

/* لوحة التحكم */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; }
.spacer { flex: 1; }
.admin-name { color: var(--muted); }

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav button {
  color: var(--text);
  background: transparent;
  border-color: var(--border);
}
.nav button:hover { background: var(--bg); }
.nav button[aria-current="page"] {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

/* مجموعة "إعدادات المنصة": قائمة منسدلة تحت الزر في القائمة العلوية (وتحت 900px)، وتُطوى داخل القائمة الجانبية */
.nav-group { position: relative; }
.nav-group-toggle::after {
  content: "\25BE";
  margin-inline-start: 8px;
  display: inline-block;
}
.nav-group-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }
.nav .nav-group-toggle[aria-current="true"] {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.nav-group-panel {
  position: absolute;
  z-index: 20;
  inset-block-start: calc(100% + 4px);
  inset-inline-start: 0;
  min-width: 200px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.nav-group-panel[data-align="start"] { inset-inline-start: auto; inset-inline-end: auto; left: 0; right: auto; }
.nav-group-panel[data-align="end"] { inset-inline-start: auto; inset-inline-end: auto; right: 0; left: auto; }
.nav .nav-group-panel button { width: 100%; text-align: start; }

/* شريط المظهر (L10): يُفتح تحت الشريط العلوي مباشرة */
.theme-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: center;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.theme-bar .group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.theme-bar .group-label { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.accent-swatch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.accent-swatch:hover { background: var(--bg); }
.accent-swatch[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 1px; }
.accent-swatch .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); flex: 0 0 auto; }
/* معاينة كل لون: نفس --accent الخاص به دائماً، بغض النظر عن الاختيار الحالي أو الوضع الداكن */
.accent-swatch[data-accent-option="blue"] .dot    { background: #1d6fb8; }
.accent-swatch[data-accent-option="cyan"] .dot    { background: #0e7490; }
.accent-swatch[data-accent-option="indigo"] .dot  { background: #4f46e5; }
.accent-swatch[data-accent-option="purple"] .dot  { background: #7e22ce; }
.accent-swatch[data-accent-option="fuchsia"] .dot { background: #a21caf; }
.accent-swatch[data-accent-option="slate"] .dot   { background: #475569; }

/* قائمة جانبية (L10): من عرض 900px فأكثر فقط؛ تحت ذلك ترجع القائمة للأعلى تلقائياً مهما كان المحفوظ،
   بدون أي جافاسكريبت إضافي (استعلام الوسائط نفسه لا يُفعَّل) */
@media (min-width: 900px) {
  html[data-nav="side"] #app-view {
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-areas: "topbar topbar" "bar bar" "nav main";
    min-height: 100vh;
  }
  html[data-nav="side"] .topbar { grid-area: topbar; }
  html[data-nav="side"] .theme-bar { grid-area: bar; }
  html[data-nav="side"] .nav {
    grid-area: nav;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    align-self: start;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    border-bottom: none;
    border-inline-start: 1px solid var(--border);
  }
  html[data-nav="side"] .nav button { width: 100%; text-align: start; }
  html[data-nav="side"] .nav-group { display: flex; flex-direction: column; gap: 8px; }
  html[data-nav="side"] .nav-group-panel {
    position: static;
    min-width: 0;
    max-width: none;
    padding: 0;
    padding-inline-start: 12px;
    border: none;
    box-shadow: none;
    background: transparent;
  }
  html[data-nav="side"] .main { grid-area: main; max-width: none; margin: 0; min-width: 0; }
}

/* المحتوى يستخدم عرض الشاشة حتى 1600px، مع هامش جانبي */
.main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px 24px;
}
@media (max-width: 600px) {
  .main { padding: 16px; }
}

.section-list { margin: 0; padding: 0 20px 0 0; }
.section-list li { margin-bottom: 6px; }

/* رسائل النجاح والخطأ */
.message {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
}
.message.success { color: var(--success); background: var(--success-bg); }
.message.error { color: var(--danger); background: var(--danger-bg); }

/* النماذج والبطاقات */
.stack { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.form-row button[type="submit"] { margin-top: 16px; }
.field label { margin-top: 10px; }

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.card-header h3 { margin: 0; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}
.inline-form input { flex: 1 1 200px; width: auto; }
.inline-form input.num { flex: 0 0 90px; }

input.num { text-align: left; }

button.small { padding: 6px 12px; font-size: 0.9rem; }

textarea { resize: vertical; }
.hint { margin: 10px 0 0; font-size: 0.9rem; }
.button-row { display: flex; gap: 8px; margin-top: 16px; }
.button-row button[type="submit"] { margin-top: 0; }
.add-row { margin-top: 16px; }

/* رابط بشكل زر */
a.button {
  display: inline-block;
  padding: 10px 18px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
a.button.secondary { color: var(--accent-text); background: transparent; }
a.button.report-link { color: #fff; background: var(--accent); }
a.button.report-link:hover { background: var(--accent-hover); }
a.button.disabled { opacity: 0.6; pointer-events: none; }

/* الأكواد وحالتها */
td.code {
  font-family: Consolas, "Courier New", monospace;
  white-space: nowrap;
}
.badge {
  display: inline-block;
  padding: 2px 10px;
  font-size: 0.85rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.unused { color: var(--success); background: var(--success-bg); }
.badge.handed_out { color: var(--warning); background: var(--warning-bg); }
.badge.used { color: var(--muted); background: var(--bg); }

/* حالة الطالب والجهاز: شارات كبيرة، نص داكن على خلفية فاتحة، والنص موجود دائماً */
.badge.lg { padding: 4px 12px; font-size: 0.95rem; font-weight: 600; border: 1px solid transparent; }
.st-active   { color: var(--success); background: var(--success-bg); border-color: #b7dfc2; }
.st-expiring { color: var(--warning); background: var(--warning-bg); border-color: #f3c98b; }
.st-expired,
.st-never    { color: var(--danger);  background: var(--danger-bg);  border-color: #f2b8b2; }
.st-total    { color: var(--text);    background: var(--surface);    border-color: var(--border); }
.dev-unbound { color: var(--yellow);  background: var(--yellow-bg);  border-color: #ecd77a; }
.dev-bound   { color: var(--neutral); background: var(--neutral-bg); border-color: #d3d8de; }

/* جدول الطلاب: خلايا أضيق، الاسم والتاريخ يلتفان بدل القص، والأزرار تحت بعضها */
.students-table th,
.students-table td { padding: 8px 6px; }
.students-table td.name-cell { min-width: 9rem; overflow-wrap: anywhere; font-weight: 600; }
.students-table td.phone-cell { white-space: nowrap; }
.students-table td.grade-cell { min-width: 8rem; }
.students-table td.date-cell { min-width: 7rem; font-size: 0.9rem; }
.students-table .badge.lg { white-space: nowrap; }
.action-stack { display: flex; flex-direction: column; gap: 6px; }
.students-table .not-set { color: var(--muted); }
.parent-form .muted { margin-bottom: 8px; }
/* تقرير ولي الأمر (13b): أزرار الفترة، مربع النص، رابط واتساب */
/* اللوحة داخل صف جدول عريض: عرضها لا يتجاوز النافذة حتى لا تحتاج تمريراً أفقياً على الهاتف */
.report-box { max-width: min(100%, 44rem, calc(100vw - 72px)); }
.report-periods { flex-wrap: wrap; margin-top: 8px; }
.report-periods button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-text); }
.report-result { margin-top: 12px; }
.report-text { min-height: 16rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.action-stack button { width: 100%; }
td.actions .action-stack button + button { margin-right: 0; }

/* فلاتر الطلاب وسطر الأعداد */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.filter-grid select:disabled { opacity: 0.6; }
.counts-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; }
.count-chip {
  padding: 8px 14px;
  font-size: 1rem;
  font-weight: 700;
  border: 1px solid;
  border-radius: 999px;
}
.count-chip:hover { filter: brightness(0.96); background-image: none; }
.count-chip.st-active:hover { background: var(--success-bg); }
.count-chip.st-expiring:hover { background: var(--warning-bg); }
.count-chip.st-expired:hover,
.count-chip.st-never:hover { background: var(--danger-bg); }
.count-chip.st-total:hover { background: var(--surface); }
.count-chip.selected { outline: 3px solid var(--text); outline-offset: 1px; }

.filter-row { margin-bottom: 12px; }
.filter-row select { width: auto; min-width: 200px; }
td.actions input.note-input { width: 170px; min-width: 0; padding: 6px 8px; margin-left: 6px; }

/* درس بدون فيديو Bunny */
.no-video { color: var(--muted); }

/* ملفات PDF للدرس: رسالة خطأ تحت نموذج الرفع، وزر الحذف باللون الأحمر */
.error-text { color: var(--danger); }
button.secondary.danger-text { color: var(--danger); border-color: var(--danger); }
button.secondary.danger-text:hover { background: var(--danger-bg); }

/* رفع فيديو للدرس (U3): الحالة بشارة ثابتة الألوان، شريط التقدم بلون التمييز، والأزرار في سطر يلتف */
.video-upload { margin-top: 8px; }
.video-upload .upload-file { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 8px; }
.video-upload progress { display: block; width: 100%; max-width: 520px; height: 16px; accent-color: var(--accent); }
.video-upload .upload-amount { margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.video-upload .upload-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.video-upload .upload-actions input[type="file"] { flex: 1 1 220px; }
.video-upload button[hidden] { display: none; }

/* معرّف الفيديو: سطر واحد مقصوص، والمعرّف الكامل يظهر عند الوقوف عليه */
.url-text {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* الجداول */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* محاذاة الأعمدة: العنوان وقيمه دائماً بنفس المحاذاة. الأعمدة القصيرة في المنتصف (col-center على th و td معاً) */
th.col-center,
td.col-center { text-align: center; }

/* نص يُقرأ من اليسار لليمين (هاتف، كود، رابط) داخل خلية عربية: اتجاهه معزول، ومكانه تحدده محاذاة الخلية */
.ltr-text { display: inline-block; direction: ltr; unicode-bidi: isolate; }
td input { min-width: 80px; }
td.actions { white-space: nowrap; }
td.actions button + button { margin-right: 6px; }

/* الامتحانات */
h4 { margin: 0 0 8px; font-size: 1.05rem; }
td.strong { font-weight: 700; }
tr.final-row td { background: var(--bg); }
.badge-row { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.notice {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: var(--radius);
}
.notice.warning { color: var(--warning); background: var(--warning-bg); border-color: #f3c98b; }
.sub-card {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
.publish-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: var(--radius);
}
.publish-box .publish-state { margin: 0; font-weight: 600; }
.publish-box .hint { flex-basis: 100%; margin: 0; }
.publish-box .message { flex-basis: 100%; margin: 0; }
/* سطر نتيجة تحت سؤال، وسؤال أُضيف للتو (يختفي التمييز تدريجياً، وثابت بدون حركة عند "تقليل الحركة") */
.question-item .item-note { margin: 8px 0 0; }
.question-item.just-added { animation: just-added-item 3s ease-out 1; }
@keyframes just-added-item {
  from { background-color: var(--highlight-bg); }
  to { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .question-item.just-added { animation: none; background: var(--highlight-bg); }
}
.question-list { margin: 0; padding: 0; list-style: none; }
.question-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.question-item:last-child { border-bottom: 0; }
.question-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.question-text { margin: 8px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.option-list { margin: 0; padding: 0 16px 0 0; list-style: none; }
.option-list .option { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; overflow-wrap: anywhere; }
/* خلفية فاتحة ثابتة (مثل الشارات) حتى تبقى الإجابة الصحيحة مقروءة في الوضع الداكن أيضاً (نص بلا خلفية
   خاصة لا يكفي تباينه على خلفية داكنة، خلافاً للشارات والرسائل التي لها خلفية فاتحة دائماً) */
.option-list .option.correct { color: var(--success); background: var(--success-bg); font-weight: 600; border-radius: var(--radius); padding: 2px 8px; }
.option-mark { flex: 0 0 1.2em; text-align: center; }
.correct-label { font-size: 0.85rem; }
.question-form { padding: 12px; background: var(--bg); border-radius: var(--radius); }
.option-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.option-row { display: flex; align-items: center; gap: 8px; }
.option-row input[type="text"] { flex: 1 1 auto; width: auto; }
input.radio { width: auto; margin: 0; }
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 0 16px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.field-title { margin: 12px 0 4px; font-weight: 600; }
.tf-box .radio-label { margin-top: 4px; }

/* نتائج الامتحانات (11g) */
.results-note { margin: 12px 0 0; color: var(--text); background: var(--bg); border-color: var(--border); }
/* خلفية فاتحة ثابتة (كالشارات) لنفس سبب .option.correct أعلاه: نص النتيجة بلا خلفية خاصة */
td.result-passed { color: var(--success); background: var(--success-bg); font-weight: 600; border-radius: var(--radius); }
td.result-failed { color: var(--danger); background: var(--danger-bg); font-weight: 600; border-radius: var(--radius); }
td.muted-cell { color: var(--muted); }
tr.attempts-row > td { padding: 0 8px 12px; background: var(--bg); text-align: right; white-space: normal; }
.attempts-panel { padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.attempts-title { margin: 0 0 4px; font-weight: 700; }
.attempt-details-holder { flex-basis: 100%; }
.attempt-details-holder:empty { display: none; }
.attempt-details { margin-top: 8px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.attempt-list { margin: 0; padding: 0; list-style: none; }
.attempt-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.attempt-item:last-child { border-bottom: 0; }
.attempt-line { font-weight: 600; }
.attempt-date { margin: 0; }
.option-list .option.chosen-wrong { color: var(--danger); background: var(--danger-bg); font-weight: 600; border-radius: var(--radius); padding: 2px 8px; }
.option-text { overflow-wrap: anywhere; }

/* تقرير المشاهدة (11k) */
.tab-row { display: flex; gap: 8px; border-bottom: 2px solid var(--border); }
.tab-row .tab-button {
  margin: 0 0 -2px;
  color: var(--accent-text);
  background: transparent;
  border: 2px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab-row .tab-button:hover { background: var(--accent-soft); }
.tab-row .tab-button.selected {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  font-weight: 700;
}
.badge.older-video { margin-right: 6px; color: var(--muted); background: var(--neutral-bg); font-size: 0.8rem; }
.watch-table td.date-cell,
.watch-lessons-table td.date-cell { white-space: nowrap; font-size: 0.9rem; }
.watch-lessons-table { width: 100%; }
.page-back { margin-top: 0; }
.details-section { margin: 16px 0 6px; font-size: 1rem; }
.attempts-panel .details-section:first-of-type { margin-top: 8px; }
td.last-exam-cell { min-width: 9rem; white-space: normal; }
.watch-table td.name-cell { min-width: 7rem; overflow-wrap: anywhere; font-weight: 600; }
/* صف التفاصيل لا يوسّع جدول الطلاب: عرضه = عرض الجدول، وجداوله الداخلية تتحرك أفقياً داخله */
.watch-table tr.attempts-row .attempts-panel { width: 0; min-width: 100%; box-sizing: border-box; }

/* صف يُفتح مباشرة تحت صف في جدول (قاعدة تخطيط لوحة التحكم): بعرض كل الأعمدة، ولا يوسّع الجدول؛
   جداوله الداخلية تتحرك أفقياً داخله */
tr.expand-row > td { padding: 0 8px 12px; background: var(--bg); text-align: right; white-space: normal; }
.expand-panel {
  width: 0;
  min-width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.expand-panel .message { margin-bottom: 12px; }
.expand-panel .table-wrap { margin-top: 8px; }
.expand-panel h4 { margin: 0 0 8px; font-size: 1rem; }
tr.message-row > td { padding-top: 4px; }
/* نموذج التفعيل تحت صف الطالب: حقول بعرض مناسب بدل عرض الجدول كله */
.activate-form .field input { max-width: 10rem; }
.activate-form .field select { max-width: 24rem; }
tr.message-row .message { margin: 0; }
/* صف أُضيف للتو: خلفية خفيفة تختفي تدريجياً، وثابتة بدون حركة عند "تقليل الحركة" */
tr.just-added > td { animation: just-added 3s ease-out 1; }
@keyframes just-added {
  from { background-color: var(--highlight-bg); }
  to { background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  tr.just-added > td { animation: none; background: var(--highlight-bg); }
}

/* بطاقة أُضيفت للتو (فئة جديدة): خلفية خفيفة تختفي تدريجياً، وثابتة بدون حركة عند "تقليل الحركة" */
.card.just-added { animation: just-added-card 3s ease-out 1; }
@keyframes just-added-card {
  from { background-color: var(--highlight-bg); }
  to { background-color: var(--surface); }
}
@media (prefers-reduced-motion: reduce) {
  .card.just-added { animation: none; background: var(--highlight-bg); }
}

@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; }
  .admin-name { order: 3; width: 100%; }
}

/* صفحة الأقسام: الصورة المصغرة (صورة أو مربع بأول حرف من الاسم). ألوان من متغيرات المظهر فتعمل في الوضعين وكل الألوان */
.section-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 1.2rem;
  font-weight: 700;
}
.section-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.links-table td.name-cell { min-width: 9rem; overflow-wrap: anywhere; font-weight: 600; }
.links-table td.link-value-cell { overflow-wrap: anywhere; }
.links-table .muted-cell { color: var(--muted); }
.links-table .link-full { margin-top: 4px; font-size: 0.85rem; color: var(--muted); }
.sections-table td.thumb-cell { width: 60px; }
.sections-table td.name-cell { overflow-wrap: anywhere; font-weight: 600; }

/* محرر صورة القسم (M4c): معاينة مربعة تُسحب بالماوس أو اللمس، وشريط تكبير. touch-action: none حتى لا تتحرك الصفحة أثناء السحب */
.image-editor { margin-top: 12px; }
.crop-canvas {
  display: block;
  width: 256px;
  max-width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  margin: 8px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.crop-canvas:active { cursor: grabbing; }
.crop-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.crop-zoom-row { display: flex; align-items: center; gap: 12px; max-width: 320px; }
.crop-zoom-row label { margin: 0; font-weight: 600; }
input.crop-zoom { flex: 1 1 auto; width: auto; min-width: 0; padding: 0; accent-color: var(--accent); }
.crop-zoom-value { min-width: 3.5rem; text-align: left; color: var(--muted); }
.remove-image-box { margin-top: 12px; }
/* معاينة قص صورة بطاقة المدرس (D3e-4): مستطيل طولي 3:4 (600 × 800). نفس السحب والتكبير */
.crop-canvas.tall { width: 288px; aspect-ratio: 3 / 4; }
/* معاينة قص البانر (12-5b): مستطيل 2:1 بدل المربع. نفس السحب والتكبير */
.crop-canvas.wide { width: 480px; aspect-ratio: 2 / 1; }

/* صفحة البانر (12-5b): صورة مصغرة 2:1، أزرار الترتيب، والتحذير الثابت. ألوان من متغيرات المظهر فقط */
.banner-warning { margin: 0 0 12px; font-weight: 600; }
.banner-counter-line { margin: 0 0 12px; }
.banner-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}
.banner-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.banners-table td.thumb-cell { width: 136px; }
.banners-table td.target-cell { min-width: 9rem; overflow-wrap: anywhere; font-weight: 600; }
.banners-table td.move-cell { width: 84px; }
.button-row.tight { margin-top: 0; gap: 4px; justify-content: center; }

/* تأكيد نقل كورس إلى قسم آخر (M4d): داخل نموذج التعديل تحت صف الكورس. ألوان من متغيرات المظهر فقط (تعمل في الوضعين وكل الألوان) */
.confirm-box {
  margin-top: 16px;
  padding: 12px 16px;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.confirm-box p { margin: 6px 0; }
.confirm-box .confirm-title { font-weight: 700; overflow-wrap: anywhere; }
.confirm-box .hint { color: var(--text); }
.confirm-box .button-row { margin-top: 12px; }

/* خانات اختيار الأقسام (M4e) وعمود الأقسام في جدول الدفعات. ألوان من متغيرات المظهر فقط */
.section-checks { margin: 16px 0 0; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); }
.section-checks legend { padding: 0 8px; font-weight: 600; }
.section-checks .check-actions { margin: 0 0 8px; }
.section-checks .check-list { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.section-checks label.check-item { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-weight: 400; max-width: 100%; }
.section-checks input[type="checkbox"] { width: auto; margin: 0; padding: 0; accent-color: var(--accent); flex: 0 0 auto; }
.section-checks .check-name { overflow-wrap: anywhere; }
.batches-table td.sections-cell { min-width: 8rem; overflow-wrap: anywhere; }

/* M4f: ملخص التفعيل / التمديد وعدّاد الملاحظة */
.activate-form .access-summary { margin: 12px 0; padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.activate-form .access-summary ul { margin: 8px 0; padding-inline-start: 20px; }
.activate-form .access-summary[hidden] { display: none; }
.activate-form textarea { width: 100%; max-width: 32rem; }
.activate-form .note-counter { margin: 4px 0 0; }

/* M4g: أسطر أقسام الطالب (الألوان نفسها وخلفياتها الثابتة في الوضعين) */
.students-table .sections-cell { min-width: 15rem; }
.sec-line { display: block; margin: 2px 0; padding: 2px 8px; border: 1px solid transparent; border-radius: var(--radius); font-size: 0.9rem; font-weight: 600; }

/* M5b: صفحة بلا صلاحية */
.no-permission .strong { font-weight: 700; font-size: 1.1rem; margin: 0 0 4px; }

/* M5c: صفحة الموظفين */
.staff-table td.name-cell { overflow-wrap: anywhere; font-weight: 600; }
/* لوحة الصلاحيات: مجموعات بعمودين على الشاشة العريضة وعمود واحد تحت 700px؛ خانة الاختيار بجانب نصها */
.perm-list { display: grid; grid-template-columns: 1fr; gap: 16px 32px; margin-top: 8px; }
@media (min-width: 700px) { .perm-list { grid-template-columns: 1fr 1fr; align-items: start; } }
.perm-group h5 { margin: 0 0 4px; padding-bottom: 4px; border-bottom: 2px solid var(--border); font-size: 0.95rem; }
.perm-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.perm-form label.check-item { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; max-width: 100%; cursor: pointer; }
.perm-form input[type="checkbox"] { width: auto; min-width: 0; margin: 0; padding: 0; accent-color: var(--accent); flex: 0 0 auto; }
.perm-form .check-name { overflow-wrap: anywhere; }
.perm-form .perm-desc, .perm-form .perm-opens, .perm-note { margin: 2px 0 0; padding-inline-start: 26px; font-size: 0.85rem; }
.perm-form .perm-menus { margin: 16px 0 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); font-weight: 600; }
.perm-warnings .notice { margin: 8px 0 0; }

/* M5d: صفحة سجل التدقيق (شارات المنفّذ بألوان ثابتة في الوضعين، والنص دائماً داخل الشارة) */
.audit-table td.time-cell { white-space: nowrap; font-size: 0.9rem; }
.audit-table td.target-cell { overflow-wrap: anywhere; }
.audit-table .actor-cell { white-space: normal; }
.audit-table .actor-name { margin-inline-start: 6px; overflow-wrap: anywhere; }
.badge.actor-owner { color: #6b3a00; background: #ffe8c2; border: 1px solid #f0c98a; }
.badge.actor-staff { color: #14416f; background: #dfeafb; border: 1px solid #b3cdee; }
.audit-lines { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 8px 0 0; }
.audit-lines dt { font-weight: 600; }
.audit-lines dd { margin: 0; overflow-wrap: anywhere; }
.audit-sensitive { margin-top: 12px; }

/* 12-6b: صفحة التقييمات. النجوم تُقرأ بالشكل (★ ممتلئة و☆ فارغة) فلا تعتمد على لون، والألوان كلها من متغيرات المظهر */
.ratings-public-line { margin: 0 0 12px; font-weight: 600; }
.ratings-public-line:empty { display: none; }
.ratings-tabs-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px; margin-top: 8px; }
.ratings-tabs-row .tab-row { flex-wrap: wrap; border-bottom: 0; }
.ratings-table .rating-stars { font-size: 1.1rem; letter-spacing: 1px; white-space: nowrap; }
.ratings-table td.comment-cell { min-width: 12rem; max-width: 28rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.ratings-table td.name-cell { overflow-wrap: anywhere; font-weight: 600; }
.ratings-table td.student-cell { min-width: 9rem; overflow-wrap: anywhere; }
.ratings-table td.date-cell { min-width: 7rem; font-size: 0.9rem; }
.ratings-table .student-name { font-weight: 600; }
.ratings-table .small-text { margin: 0; font-size: 0.85rem; }
.pager-row { align-items: center; margin-top: 12px; }
.pager-text { margin: 0 8px; }

/* D2c: صفحة "ألوان التطبيق". ألوان المعاينة نفسها في app-palettes.css (مُولَّد)، وهنا الشكل فقط.
   المعاينة تعرض ألوان التطبيق وليست ألوان لوحة التحكم، فلا تتغير مع الوضع الداكن أو لون التمييز. */
.palette-table td { vertical-align: middle; }
.palette-table td.name-cell { font-weight: 600; min-width: 8rem; }
.palette-table .palette-marks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-weight: 400; }
.palette-table .palette-default { font-size: 0.85rem; color: var(--muted); }
.palette-mode-caption { margin: 0 0 4px; font-size: 0.85rem; color: var(--muted); }
.palette-preview { min-width: 11rem; padding: 10px; border: 1px solid var(--pv-outline); border-radius: 10px; background: var(--pv-background); }
.palette-preview .pv-card { display: flex; flex-direction: column; gap: 4px; padding: 8px; border: 1px solid var(--pv-outline); border-radius: 8px; background: var(--pv-surface); }
.palette-preview .pv-title { font-weight: 700; font-size: 0.9rem; color: var(--pv-on-surface); }
.palette-preview .pv-muted { font-size: 0.8rem; color: var(--pv-on-surface-muted); }
.palette-preview .pv-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.palette-preview .pv-button { padding: 3px 12px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; color: var(--pv-on-primary); background: var(--pv-primary); }
.palette-preview .pv-chip { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; color: var(--pv-on-primary-container); background: var(--pv-primary-container); }
.palette-preview .pv-chip-alt { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; color: var(--pv-on-secondary-container); background: var(--pv-secondary-container); }
.palette-preview .pv-ring { display: inline-block; width: 22px; height: 22px; box-sizing: border-box; border: 5px solid var(--pv-surface-alt); border-top-color: var(--pv-secondary); border-radius: 50%; }
.palette-confirm .button-row { margin-top: 10px; }

/* D3e-4: بطاقة القسم وصفحة المنصة وروابط التواصل. ألوان من متغيرات المظهر فقط */
.char-counter { display: block; margin-top: 4px; font-size: 0.85rem; color: var(--muted); }
.multiline { white-space: pre-line; overflow-wrap: anywhere; }
.sections-table td.card-cell { font-size: 0.85rem; }
.sections-table td.card-cell div:first-child { font-weight: 600; font-size: 0.95rem; }
.card-style-options { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.card-style-options label { display: flex; align-items: flex-start; gap: 8px; margin: 0; font-weight: 400; }
.card-style-options input[type="radio"] { width: auto; min-width: 0; margin: 4px 0 0; padding: 0; accent-color: var(--accent); flex: 0 0 auto; }
.card-style-options .option-help { display: block; color: var(--muted); font-size: 0.85rem; }
.card-preview {
  display: flex; flex-direction: column; gap: 4px; margin: 12px 0; padding: 12px;
  max-width: 20rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.card-preview[data-style="teacher"] { max-width: 11rem; min-height: 9rem; }
.card-preview .cp-style { font-size: 0.8rem; color: var(--muted); }
.card-preview .cp-title { font-weight: 700; overflow-wrap: anywhere; }
.card-preview .cp-line { font-size: 0.9rem; overflow-wrap: anywhere; }
.portrait-current { display: block; width: 90px; aspect-ratio: 3 / 4; object-fit: cover; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); }
.platform-table td.name-cell { font-weight: 600; white-space: nowrap; }
.platform-table .muted-cell { color: var(--muted); }
.social-heading { margin-top: 24px; }

/* صفحة الترحيب (D4c): صور مصغرة، دوائر الصور الرمزية بالرقم، اختيار الأيقونة. الألوان بقواعد CSS لأن CSP يمنع style داخل الصفحة.
   ألوان الصور الرمزية ثابتة في الوضعين (نفس ألوان التطبيق، ونص الرقم داكن أو أبيض حسب التباين) */
.landing-thumb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; aspect-ratio: 1 / 1; overflow: hidden;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--accent-soft); color: var(--muted); font-size: 0.75rem; text-align: center;
}
.landing-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.landing-features-table td.name-cell { font-weight: 600; overflow-wrap: anywhere; }
.landing-opinions-table td.comment-cell { min-width: 12rem; overflow-wrap: anywhere; }
.landing-opinions-table td.stars-cell { white-space: nowrap; }
.landing-words-note { margin: 0 0 12px; font-weight: 600; }
.opinions-counter-line { margin: 0 0 12px; }
.avatar-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  border: 2px solid transparent; font-size: 0.9rem; font-weight: 700; line-height: 1;
}
button.avatar-dot { cursor: pointer; }
button.avatar-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.avatar-dot.selected { border-color: var(--text); box-shadow: 0 0 0 3px var(--accent); }
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.avatar-chosen { margin: 4px 0 0; }
.icon-picker { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
button.icon-option { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.icon-option.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); font-weight: 700; }
.field-label { display: block; font-weight: 600; margin-bottom: 4px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }
.avatar-dot[data-n="1"] { background: #86C5E3; color: #16202a; }
.avatar-dot[data-n="2"] { background: #E07044; color: #16202a; }
.avatar-dot[data-n="3"] { background: #E1E2E4; color: #16202a; }
.avatar-dot[data-n="4"] { background: #F67E9F; color: #16202a; }
.avatar-dot[data-n="5"] { background: #205658; color: #ffffff; }
.avatar-dot[data-n="6"] { background: #B39BCF; color: #16202a; }
.avatar-dot[data-n="7"] { background: #4A99D8; color: #16202a; }
.avatar-dot[data-n="8"] { background: #F7C732; color: #16202a; }
.avatar-dot[data-n="9"] { background: #B84656; color: #ffffff; }
.avatar-dot[data-n="10"] { background: #3A8794; color: #16202a; }
.avatar-dot[data-n="11"] { background: #6C4978; color: #ffffff; }
.avatar-dot[data-n="12"] { background: #A4ADB3; color: #16202a; }
.avatar-dot[data-n="13"] { background: #1F6848; color: #ffffff; }
.avatar-dot[data-n="14"] { background: #244A7B; color: #ffffff; }
.avatar-dot[data-n="15"] { background: #EEA6B3; color: #16202a; }

/* المنتدى (Step 17b-1): ألوان من متغيرات الثيم فقط (فاتح وداكن)، بلا ألوان ثابتة */
.forum-search { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; margin-top: 8px; }
.forum-search .field { flex: 1 1 18rem; margin: 0; }
.forum-search .button-row { margin-top: 0; }
.forum-count { margin: 0 0 8px; }
.forum-table td { vertical-align: top; }
.forum-table td.forum-question-cell { min-width: 14rem; max-width: 28rem; white-space: normal; }
.forum-table .small-text { margin: 4px 0 0; font-size: 0.85rem; }
.forum-excerpt { overflow-wrap: anywhere; }
.forum-table td.num-cell,
.forum-table td.date-cell { white-space: nowrap; font-size: 0.9rem; }
.forum-row-hidden > td { opacity: 0.75; }
.forum-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.forum-head h3 { margin: 0; }
.forum-meta { margin: 4px 0; }
.forum-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; line-height: 1.7; }
.forum-actions { flex-wrap: wrap; margin-top: 12px; }
.forum-note { margin: 8px 0; }
.forum-replies { display: flex; flex-direction: column; gap: 12px; }
.forum-reply { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); }
.forum-reply.staff { border-inline-start: 4px solid var(--accent); }
.forum-reply.is-hidden { opacity: 0.8; border-style: dashed; }
.forum-reply-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.forum-reply .forum-actions { margin-top: 8px; }
.forum-reply.just-added { animation: just-added-item 3s ease-out 1; }
@media (prefers-reduced-motion: reduce) {
  .forum-reply.just-added { animation: none; background: var(--highlight-bg); }
}
.forum-stop-form { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-top: 12px; background: var(--bg); }
.forum-reply-form textarea { width: 100%; max-width: 40rem; }
@media (max-width: 600px) {
  .forum-table td.forum-question-cell { min-width: 11rem; }
}

/* المنتدى، التبويبات (Step 17b-2): ألوان من متغيرات الثيم فقط */
.forum-tabs { flex-wrap: wrap; margin: 12px 0 0; }
.forum-tab[hidden] { display: none; }
.forum-notes-list { margin: 4px 0 8px; padding-inline-start: 20px; }
.forum-notes-list li { margin: 4px 0; overflow-wrap: anywhere; }
.forum-add-form { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.forum-add-form h4,
.expand-panel h4 { margin: 12px 0 4px; }
.forum-add-form input { max-width: 24rem; }
.forum-rename-form input { max-width: 24rem; }
.forum-reports-table td.forum-question-cell { max-width: 20rem; }
.forum-names-table td.strong,
.forum-modes-table td.strong { font-weight: 700; }
