/* ============================================================
   الوضع الليلي — ورشة جافا
   يُفعَّل بوضع السمة html[data-theme="dark"] — زر التبديل في app.js
   يحفظ الاختيار في localStorage ويتبع تفضيل الجهاز عند أول زيارة.
   ============================================================ */
html[data-theme="dark"] {
  --paper: #171713;
  --paper-2: #1f1f1a;
  --ink: #ece7d8;
  --ink-soft: #b5ae9c;
  --ink-faint: #7d7768;
  --mustard: #d8a92a;
  --mustard-deep: #c9971c;
  --mustard-wash: rgba(201, 151, 28, .13);
  --line: #35332b;
  --ok: #8fb877;
}
html[data-theme="dark"] body {
  background-image: radial-gradient(#2c2b23 1px, transparent 1px);
}

/* ===== عناصر بألوان صلبة خرجت من نظام المتغيرات ===== */
html[data-theme="dark"] .sidebar { background: #14140f; border-color: #2c2b23; }
html[data-theme="dark"] .codebar { background: #262622; }
html[data-theme="dark"] .codebox { box-shadow: 0 4px 14px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.4); }
html[data-theme="dark"] .note { background: rgba(201,151,28,.08); border-color: #4a3f1e; }
html[data-theme="dark"] .warn { background: rgba(190,90,70,.09); border-color: #5a3226; }
html[data-theme="dark"] table.types { background: #1c1c17; }
html[data-theme="dark"] table.types th { background: #23231c; }
html[data-theme="dark"] .kw-chips span { background: rgba(201,151,28,.10); border-color: #4a3f1e; }
html[data-theme="dark"] .fig { background: #1a1a15; }
html[data-theme="dark"] .fig figcaption { color: #8a8474; }
html[data-theme="dark"] .hint-box { background: rgba(201,151,28,.07); border-color: #4a3f1e; }
html[data-theme="dark"] .hint-box .hint-text { color: #c9c2ae; }
html[data-theme="dark"] .explainer { background: #1c1c17; }
html[data-theme="dark"] .explainer .lc { color: #e3c26a; }
html[data-theme="dark"] .quiz { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] .quiz-opts button { background: #23231c; color: #ece7d8; border-color: #3a382e; }
html[data-theme="dark"] .quiz-opts button:hover { border-color: var(--mustard); }
/* تنبيهات الإجابة: ألوان styles.css الصلبة (بني/أخضر داكن على خلفية فاتحة) لا تُقرأ على الغامق */
html[data-theme="dark"] .quiz-fb { color: #e3c26a; }
html[data-theme="dark"] .quiz-fb b { color: #f0d27a; }
html[data-theme="dark"] .quiz-tag { color: #d8a92a; }
html[data-theme="dark"] .quiz-opts button.ok { background: rgba(143,184,119,.12); border-color: #3c4a33; color: #8fb877; }
html[data-theme="dark"] .quiz-opts button.no { background: rgba(190,90,70,.10); border-color: #5a3226; color: #d98c7a; }
html[data-theme="dark"] .bug-fb.no, html[data-theme="dark"] .vb-msg.err, html[data-theme="dark"] .tro-msg.err { color: #d98c7a; }
html[data-theme="dark"] .tu-chip.on { background: rgba(143,184,119,.12); border-color: #3c4a33; }
html[data-theme="dark"] .output { background: #14140f; }
html[data-theme="dark"] .flipcard .face { background: #1c1c17; border-color: #35332b; color: #ece7d8; }
html[data-theme="dark"] .flipcard .face.back { background: #23231c; }
html[data-theme="dark"] .run-note { color: #6b675c; border-color: #2c2b23; }
html[data-theme="dark"] .lesson-num { color: #d8a92a; border-color: #4a3f1e; background: rgba(201,151,28,.08); }
html[data-theme="dark"] .inline-code { background: #26261f; border-color: #3a382e; }
html[data-theme="dark"] .quiz-code { background: #26261f; border-color: #3a382e; }

/* ===== الرئيسية: بطاقات الوحدات + لوحة التقدم + الأوسمة ===== */
html[data-theme="dark"] .uo-card { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] .uo-card:hover { border-color: #4a3f1e; box-shadow: 0 8px 22px rgba(0,0,0,.4); }
html[data-theme="dark"] .uo-num { color: rgba(216,169,42,.16); }
html[data-theme="dark"] .dash-overall, html[data-theme="dark"] .dash-unit, html[data-theme="dark"] .badge-item { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] .badge-item.locked { opacity: .55; }
html[data-theme="dark"] .tbar, html[data-theme="dark"] .tbar2 { background: #2c2b23; }
html[data-theme="dark"] .chip-done { background: rgba(143,184,119,.14); color: #8fb877; border-color: #3c4a33; }
html[data-theme="dark"] .tro, html[data-theme="dark"] .tstat { background: #1c1c17; border-color: #35332b; }

/* ===== بطاقة ترويسة الوحدة (.ub-card) + مكوّنات فاتحة أخرى موجّهة للطالب ===== */
html[data-theme="dark"] .ub-card { background: linear-gradient(135deg, #1c1c17, #23231c); border-color: #4a3f1e; }
html[data-theme="dark"] .ub-card::after { color: rgba(216,169,42,.10); }
html[data-theme="dark"] .ub-num { color: #d8a92a; background: rgba(201,151,28,.10); border-color: #4a3f1e; }
html[data-theme="dark"] .ub-chip { background: #23231c; color: #b5ae9c; border-color: #3a382e; }
html[data-theme="dark"] .ub-chip.on { background: rgba(143,184,119,.12); color: #8fb877; border-color: #3c4a33; }
html[data-theme="dark"] .ubp-track { background: #35332b; }
html[data-theme="dark"] .lvl.easy { background: rgba(143,184,119,.12); color: #8fb877; border-color: #3c4a33; }
html[data-theme="dark"] .lvl.mid { border-color: #4a3f1e; }
html[data-theme="dark"] .cert-btn { background: rgba(201,151,28,.10); }
html[data-theme="dark"] .cert-btn:hover { background: rgba(201,151,28,.18); }
html[data-theme="dark"] .cert-btn.armed:hover { background: rgba(190,90,70,.2); }
html[data-theme="dark"] .auth-err, html[data-theme="dark"] .terr { background: rgba(190,90,70,.10); border-color: #5a3226; color: #d98c7a; }
html[data-theme="dark"] .auth-roster.ok { background: rgba(120,170,100,.12); border-color: #3c5a32; color: #9cc98a; }
html[data-theme="dark"] .auth-roster.bad { background: rgba(190,90,70,.10); border-color: #5a3226; color: #d98c7a; }
html[data-theme="dark"] .tu-chip:not(.on) { background: rgba(190,90,70,.10); border-color: #5a3226; color: #d98c7a; }
html[data-theme="dark"] #authName[data-roster] { background: rgba(143,184,119,.10); border-color: #3c4a33; }
html[data-theme="dark"] .stu-del:hover { background: rgba(190,90,70,.12); color: #d98c7a; border-color: #5a3226; }
html[data-theme="dark"] ::-webkit-scrollbar-track { background: #1a1a15; }

/* ===== نوافذ وتنبيهات ===== */
html[data-theme="dark"] .toast { background: #26261f; color: #ece7d8; border: 1px solid #3a382e; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
html[data-theme="dark"] .modal-card, html[data-theme="dark"] .auth-card { background: #1f1f1a; border-color: #35332b; color: #ece7d8; }
html[data-theme="dark"] input, html[data-theme="dark"] textarea, html[data-theme="dark"] select { background: #23231c; color: #ece7d8; border-color: #3a382e; }
html[data-theme="dark"] .aw-btn, html[data-theme="dark"] .tbtn2 { border-color: #3a382e; }

/* ===== رسوم SVG التوضيحية في الدروس: إعادة رسم الألوان الفاتحة ===== */
html[data-theme="dark"] .fig svg [fill="#fdf3d7"] { fill: #262420; }
html[data-theme="dark"] .fig svg [fill="#e9f2e4"] { fill: #24301e; }
html[data-theme="dark"] .fig svg [fill="#f3e9f7"] { fill: #2b2430; }
html[data-theme="dark"] .fig svg [fill="#8a7a4a"] { fill: #b3a171; }
html[data-theme="dark"] .fig svg [fill="#6b5a1e"] { fill: #e3c26a; }
html[data-theme="dark"] .fig svg [fill="#3c5c31"] { fill: #9cc184; }
html[data-theme="dark"] .fig svg [fill="#5e3a70"] { fill: #c39ad6; }
html[data-theme="dark"] .fig svg [fill="#4a4232"] { fill: #d8d2c2; }
html[data-theme="dark"] .fig svg [fill="#6b6353"] { fill: #a8a192; }
html[data-theme="dark"] .fig svg [fill="#8a7a4a"] { fill: #b3a171; }
html[data-theme="dark"] .fig svg [fill="#6a8a5a"] { fill: #93b078; }
html[data-theme="dark"] .fig svg [fill="#8a6a9a"] { fill: #ab8cba; }
/* حدود ونصوص تبقى كما هي وتظهر جيدًا على الغامق: c9971c / 5d8a4e / 9b6bb0 / fff / d8b56a */

/* ===== زر تبديل السمة (يُنشئه app.js في الشريط الجانبي) ===== */
.theme-toggle {
  margin-top: 14px; align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono, 'JetBrains Mono', monospace); font-size: 12px; font-weight: 700;
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 16px; cursor: pointer; transition: all .18s ease;
}
.theme-toggle:hover { color: var(--mustard); border-color: var(--mustard); }

/* ===== أوسمة/حالات نجاح فاتحة خاصة بالشهادة والتنبيهات ===== */
html[data-theme="dark"] .verdict.pass { background: rgba(143,184,119,.1); color: #8fb877; border-color: #3c4a33; }
html[data-theme="dark"] .verdict { background: #1c1c17; border-color: #35332b; color: #c9c2ae; }
html[data-theme="dark"] .run-panel { background: #14140f; }
html[data-theme="dark"] .run-head { color: #c9c2ae; }

/* ===== لوحة المدرس ===== */
html[data-theme="dark"] .tcls { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] .tcls.on { border-color: #4a3f1e; }
html[data-theme="dark"] .tchip { background: #23231c; color: #b5ae9c; border-color: #3a382e; }
html[data-theme="dark"] .tchip.b { background: rgba(201,151,28,.1); color: #d8a92a; border-color: #4a3f1e; }
html[data-theme="dark"] .tnote { background: rgba(201,151,28,.07); border-color: #4a3f1e; color: #c9c2ae; }
html[data-theme="dark"] .srow.spend td { color: #7d7768; background: #1a1a15; }
html[data-theme="dark"] .stu-table th { color: #8a8474; }
html[data-theme="dark"] .stu-table td { border-color: #2c2b23; }
html[data-theme="dark"] .att-chip { background: rgba(190,90,70,.1); color: #d98c7a; border-color: #5a3226; }
html[data-theme="dark"] .exrow { border-color: #2c2b23; color: #b5ae9c; }
html[data-theme="dark"] .exrow.ok { color: #8fb877; }
html[data-theme="dark"] .tunit { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] .tunit .tu-top { color: #c9c2ae; }
html[data-theme="dark"] .hm-cell { border-color: #2c2b23; }
html[data-theme="dark"] .hm-0 { background: #1c2018; color: #7a8a72; }
html[data-theme="dark"] .hm-1 { background: #2c2116; color: #c98d4a; }
html[data-theme="dark"] .hm-2 { background: #332016; color: #d07a4a; }

/* ===== الصفحات ذات الخلفيات المخصصة (cheat) ===== */
html[data-theme="dark"] body { color-scheme: dark; }

/* ===== المكوّنات التعليمية التفاعلية ===== */
html[data-theme="dark"] .mq-opts button { background: #23231c; color: #ece7d8; border-color: #3a382e; }
html[data-theme="dark"] .mq-opts button.right { background: rgba(143,184,119,.12); border-color: #3c4a33; color: #8fb877; }
html[data-theme="dark"] .mq-opts button.wrong { background: rgba(190,90,70,.10); border-color: #5a3226; color: #d98c7a; }
html[data-theme="dark"] .ann-panel { background: #1f1f1a; }
html[data-theme="dark"] .continue-cta { box-shadow: 0 4px 12px rgba(0,0,0,.4); }
html[data-theme="dark"] .continue-cta.cta-done { color: #e3c26a; border-color: #4a3f1e; }
html[data-theme="dark"] .vb-row select, html[data-theme="dark"] .vb-row input { background: #23231c; color: #ece7d8; border-color: #3a382e; }
/* ===== [طالب] إعدادات الشريط الجانبي (يضيفها وكيل واجهة الطالب) ===== */
html[data-theme="dark"] .cert-btn.armed { background: rgba(190,90,70,.14); border-color: #7a3a2a; color: #e59a88; }

/* ===== [لوحة المدرس] تحسينات لوحة المتابعة ===== */
html[data-theme="dark"] .stu-tag.stuck { background: rgba(190,90,70,.12); color: #d98c7a; border-color: #5a3226; }
html[data-theme="dark"] .stu-tag.absent { background: rgba(201,141,74,.12); color: #c98d4a; border-color: #5a4326; }
html[data-theme="dark"] .stu-tag.zero { background: #23231c; color: #b5ae9c; border-color: #3a382e; }
html[data-theme="dark"] .tprev-link { background: rgba(201,151,28,.10); color: #d8a92a; border-color: #4a3f1e; }
html[data-theme="dark"] .tprev-units .tprev-link.off { background: #23231c; color: #8a8474; border-color: #3a382e; }
html[data-theme="dark"] .tcls-pill { background: #23231c; color: #b5ae9c; border-color: #3a382e; }
html[data-theme="dark"] .cls-stuck.is-warn { color: #d98c7a; }
html[data-theme="dark"] .cls-stuck.is-good { color: #8fb877; }
html[data-theme="dark"] .treteach { background: #1c1c17; border-color: #35332b; }
html[data-theme="dark"] #stuFilterNote { background: rgba(201,151,28,.07); border-color: #4a3f1e; }
html[data-theme="dark"] .hm-3 { background: #44201a; color: #e08f78; }
html[data-theme="dark"] .hm-cell.sel { outline-color: #d8a92a; }
html[data-theme="dark"] .ex-fails { color: #d98c7a; }
html[data-theme="dark"] .tdanger:hover { background: rgba(190,90,70,.12); color: #d98c7a; border-color: #5a3226; }
html[data-theme="dark"] .att-go { color: #d8a92a; }

/* ===== الملخص العام (cheat) ===== */
html[data-theme="dark"] .cheat-traps { background: rgba(190,90,70,.09); border-color: #5a3226; }
html[data-theme="dark"] .cheat-traps-h { color: #e59a88; }
html[data-theme="dark"] .cheat-traps li::before { background: #d98c7a; }
html[data-theme="dark"] .cheat-status.is-done { color: #8fb877; border-color: #3c4a33; }
html[data-theme="dark"] .cheat-main .key { color: #e3c26a; }

/* الطباعة: ألوان فاتحة قسرًا مهما كانت السمة (يغلب قواعد السمة الداكنة أعلاه) */
@media print {
  html[data-theme="dark"] body.cheat-page,
  body.cheat-page { background: #fff !important; background-image: none !important; color: #000 !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main,
  html[data-theme="dark"] body.cheat-page .cheat-main * { color: #111 !important; border-color: #888 !important; text-shadow: none !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main table.types,
  html[data-theme="dark"] body.cheat-page .cheat-main table.types td { background: #fff !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main table.types th { background: #eee !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main .inline-code { background: #f3f3f3 !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main .cheat-traps { background: #fff !important; border: 1px solid #888 !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main .cheat-hint { background: #fff !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main .cheat-code { background: #fff !important; color: #111 !important; }
  body.cheat-page .cheat-main .cheat-code { white-space: pre-wrap !important; overflow: visible !important; }
  html[data-theme="dark"] body.cheat-page .cheat-main .key { color: #6b4a00 !important; font-weight: 700 !important; }
  body.cheat-page .cheat-main table.types, body.cheat-page .cheat-main table.types th, body.cheat-page .cheat-main table.types td { border: 1px solid #888 !important; }
  body.cheat-page .cheat-main .key { color: #6b4a00 !important; }
  body.cheat-page .cheat-main .cheat-tldr { background: #fff !important; border: 0 !important; border-inline-start: 3px solid #888 !important; }
}

/* ===== الرسوم خطوة بخطوة (stepfig) ===== */
html[data-theme="dark"] .stepfig .sf-btn { background: #2a2618; color: #e8e2d0; border-color: #8a6d1a; }
html[data-theme="dark"] .stepfig .sf-btn:hover:not(:disabled) { background: #c9971c; color: #1a1a15; }
html[data-theme="dark"] .stepfig .sf-status { color: #b0aa98; }
html[data-theme="dark"] .stepfig .sf-reset { color: #8a8474; }
html[data-theme="dark"] .stepfig .sf-reset:hover { color: #e8e2d0; }
html[data-theme="dark"] .stepfig figcaption { color: #e8e2d0; background: #22211b; border-inline-start-color: #c9971c; }
html[data-theme="dark"] p.step-q { background: #2a2618; border-color: #8a6d1a; color: #e8e2d0; }
html[data-theme="dark"] p.step-q::before { color: #e3c26a; }

/* ===== رأس سؤال «اختبر نفسك» ===== */
html[data-theme="dark"] .quiz-head .quiz-pill { color: #f0cd6e; background: rgba(201,151,28,.18); }
html[data-theme="dark"] .quiz-head .quiz-num { color: #c9c4b4; }
html[data-theme="dark"] .quiz-head .quiz-pts { color: #9a9585; }
html[data-theme="dark"] .quiz-head .quiz-pts.done { color: #6fcf86; }
html[data-theme="dark"] .quiz-head .quiz-alt-btn:focus-visible { outline-color: #d8a92a; }

/* ===== عدّادات الأسئلة (وضع داكن) ===== */
:root[data-theme="dark"] .nav a .nav-qbadge.full { color: #7fd08f; border-color: #7fd08f; }
:root[data-theme="dark"] .quiz-retry { color: var(--mustard); }

/* ===== ميزان المقارنة (وضع داكن) ===== */
html[data-theme="dark"] .cmp-pill.cmp-true { background: rgba(80,160,90,.18); color: #8fe09b; border-color: #3d6b45; }
html[data-theme="dark"] .cmp-pill.cmp-false { background: rgba(190,90,70,.18); color: #f0a898; border-color: #6b3a30; }
html[data-theme="dark"] .cmp-num, html[data-theme="dark"] .cmp-op { background: #14140f; color: #eae6d6; border-color: #3a392e; }
html[data-theme="dark"] .cmp-scale.cmp-ready, html[data-theme="dark"] .cheat-code { background: #1b1a14; border-color: #2c2b23; }

/* ===== [لوحة المدرس] ألوان الحالات (td-*) في الوضع الليلي ===== */
html[data-theme="dark"] .tpage {
  --td-stuck-fg: #e0988a; --td-stuck-bg: rgba(190, 90, 70, .16); --td-stuck-bd: #5a3226; --td-stuck-dot: #d9715b;
  --td-ok-fg: #8fb877; --td-ok-bg: rgba(143, 184, 119, .13); --td-ok-bd: #3c4a33; --td-ok-dot: #8fb877;
  --td-done-fg: #d8a92a; --td-done-bg: rgba(201, 151, 28, .13); --td-done-bd: #4a3f1e; --td-done-dot: #d8a92a;
}
html[data-theme="dark"] .td-menu { box-shadow: 0 8px 22px rgba(0, 0, 0, .5); }
html[data-theme="dark"] .td-pin-form input, html[data-theme="dark"] .td-search { background: #23231c; color: #ece7d8; border-color: #3a382e; }
