/* ==========================================================================
   مساعد المدرّس v2 — طبقة الهوية فوق Bootstrap RTL
   الهوية: نيلي → بنفسجي · خط Tajawal · وضع ليلي كامل
   ========================================================================== */

:root {
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef2ff;
  --brand-ink: #3730a3;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -12px rgba(79, 70, 229, .18);
  --shadow-lg: 0 24px 48px -16px rgba(79, 70, 229, .28);
}

[data-bs-theme="dark"] {
  --brand: #818cf8;
  --brand-2: #a78bfa;
  --brand-soft: #1e1b4b;
  --brand-ink: #c7d2fe;
  --ok: #4ade80;
  --ok-bg: #14321f;
  --warn: #fbbf24;
  --warn-bg: #3a2b0a;
  --bad: #f87171;
  --bad-bg: #3b1212;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .5);
  --shadow-lg: 0 24px 48px -16px rgba(0, 0, 0, .6);
}

/* ---------- أساسيات ---------- */
body {
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  letter-spacing: .1px;
}
h1, h2, h3, .navbar-brand { font-weight: 800; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.13rem; }
h3 { font-size: 1rem; }

.container-app {
  max-width: 1020px;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

/* ---------- إعادة تلوين Bootstrap بهويتنا ---------- */
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-2);
  --bs-btn-hover-border-color: var(--brand-2);
  --bs-btn-active-bg: var(--brand-2);
  --bs-btn-active-border-color: var(--brand-2);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-font-weight: 700;
}
.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand);
  --bs-btn-active-border-color: var(--brand);
  --bs-btn-font-weight: 700;
}
.btn-outline-secondary { --bs-btn-font-weight: 600; }
.text-bg-primary { background-color: var(--brand) !important; }
.bg-primary { background-color: var(--brand) !important; }
.text-primary { color: var(--brand) !important; }
.border-primary { border-color: var(--brand) !important; }
a { color: var(--brand); }
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--brand) 18%, transparent);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--brand) 20%, transparent); }
.progress-bar { background-color: var(--brand); }
.alert { border-radius: 14px; border: 1px solid transparent; }
.navbar {
  --bs-navbar-brand-color: var(--brand-ink);
  background: color-mix(in srgb, var(--bs-body-bg) 82%, transparent);
  backdrop-filter: blur(10px);
}
.card {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  --bs-card-border-color: color-mix(in srgb, var(--brand) 12%, var(--bs-border-color));
}
.table { --bs-table-striped-bg: color-mix(in srgb, var(--brand) 3%, transparent); }
.table > :not(caption) > * > * { padding: .65rem .75rem; }

/* ---------- الشعار ---------- */
.brand-mark {
  width: 34px; height: 34px; flex: 0 0 auto;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; line-height: 1;
  box-shadow: 0 4px 10px -3px rgba(79, 70, 229, .55);
}
.brand-name { font-weight: 800; font-size: 1.05rem; }

/* ---------- شرائح وشارات ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--brand-soft); color: var(--brand-ink);
  font-size: .78rem; font-weight: 700;
  padding: .28em .85em; border-radius: 999px; white-space: nowrap;
}
[data-bs-theme="dark"] .chip { color: var(--brand-ink); }
.chip.plain { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }
.pill {
  display: inline-block; font-size: .74rem; font-weight: 700;
  padding: .25em .8em; border-radius: 999px; color: #fff;
}

/* ---------- أزرار مصغّرة ---------- */
.mini { --bs-btn-padding-y: .28rem; --bs-btn-padding-x: .7rem; --bs-btn-font-size: .82rem; }

/* ---------- بطاقة إحصائية ---------- */
.stat-card {
  display: flex; align-items: center; gap: 12px;
  height: 100%;
}
.stat-card .stat-icon {
  width: 46px; height: 46px; border-radius: 13px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  background: var(--brand-soft); color: var(--brand);
}
[data-bs-theme="dark"] .stat-card .stat-icon { color: var(--brand-2); }
.stat-card .stat-num { font-size: 1.35rem; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { font-size: .8rem; color: var(--bs-secondary-color); }

/* ---------- لوحة الدخول المقسومة ---------- */
.auth-shell { max-width: 780px; margin: 4vh auto 0; }
.auth-panel {
  overflow: hidden; border-radius: 22px;
  box-shadow: var(--shadow-lg);
}
.auth-side {
  background:
    radial-gradient(120% 90% at 85% 10%, rgba(255,255,255,.22), transparent 55%),
    linear-gradient(160deg, var(--brand), var(--brand-2));
  color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 300px;
}
.auth-side .big-mark {
  width: 64px; height: 64px; border-radius: 18px;
  background: rgba(255,255,255,.18); backdrop-filter: blur(4px);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800;
}
.auth-side ul { list-style: none; margin: 0; padding: 0; }
.auth-side li { display: flex; gap: 10px; align-items: center; margin-top: 12px; opacity: .94; }
.pin-input {
  font-size: 1.5rem; font-weight: 700; letter-spacing: .55em;
  text-align: center; direction: ltr;
}

/* ---------- شريط التنقل السفلي للطالب ---------- */
.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 1030;
  background: color-mix(in srgb, var(--bs-body-bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--bs-border-color);
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottom-nav a, .bottom-nav button {
  background: none; border: none; text-decoration: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .72rem; font-weight: 700; color: var(--bs-secondary-color);
  padding: 6px 18px; border-radius: 12px; cursor: pointer;
}
.bottom-nav a i, .bottom-nav button i { font-size: 1.25rem; line-height: 1; }
.bottom-nav a.active {
  color: var(--brand);
  background: var(--brand-soft);
}
@media (min-width: 768px) {
  .bottom-nav { max-width: 480px; margin-inline: auto; border-radius: 18px 18px 0 0; border-inline: 1px solid var(--bs-border-color); }
}

/* ---------- حلقة التقدم ---------- */
.ring-wrap { position: relative; width: 74px; height: 74px; flex: 0 0 auto; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-wrap .ring-val {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .95rem;
}
.ring-track { stroke: var(--bs-border-color); }
.ring-fill { stroke: url(#ringGrad); transition: stroke-dashoffset .6s ease; }

/* ---------- بطاقات الخيارات في السؤال ---------- */
.choice-card {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1.5px solid var(--bs-border-color); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  background: var(--bs-body-bg);
}
.choice-card:hover { border-color: var(--brand); }
.choice-card input { margin-top: 5px; accent-color: var(--brand); width: 1.15em; height: 1.15em; }
.choice-card:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  box-shadow: 0 0 0 1px var(--brand);
}
.choice-key {
  width: 26px; height: 26px; flex: 0 0 auto; border-radius: 8px;
  background: var(--bs-tertiary-bg); color: var(--bs-secondary-color);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .82rem;
}
.choice-card:has(input:checked) .choice-key { background: var(--brand); color: #fff; }

/* ---------- نقاط المستوى ---------- */
.diff-dots { color: var(--warn); letter-spacing: 2px; font-size: .8rem; }
.diff-dots .off { opacity: .25; }

/* ---------- شاشة الإتمام الاحتفالية ---------- */
@keyframes pop-in {
  0% { transform: scale(.4); opacity: 0; }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes float-up {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-120px) rotate(40deg); opacity: 0; }
}
.big-check {
  width: 86px; height: 86px; margin-inline: auto;
  border-radius: 50%;
  background: var(--ok-bg); color: var(--ok);
  display: flex; align-items: center; justify-content: center;
  font-size: 44px;
  animation: pop-in .5s cubic-bezier(.2, 1.4, .4, 1) both;
}
.confetti { pointer-events: none; }
.confetti span {
  position: absolute; width: 9px; height: 14px; border-radius: 3px;
  animation: float-up 1.6s ease-out both;
}
.confetti span:nth-child(1) { inset-inline-start: 18%; background: #f59e0b; animation-delay: .15s; }
.confetti span:nth-child(2) { inset-inline-start: 32%; background: #4f46e5; animation-delay: .3s; }
.confetti span:nth-child(3) { inset-inline-start: 50%; background: #ec4899; animation-delay: .1s; }
.confetti span:nth-child(4) { inset-inline-start: 66%; background: #10b981; animation-delay: .35s; }
.confetti span:nth-child(5) { inset-inline-start: 80%; background: #f59e0b; animation-delay: .22s; }

/* ---------- سلّم المفاهيم (صفحة الوحدة) ---------- */
.step-item {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 13px 4px; border-bottom: 1px dashed var(--bs-border-color);
}
.step-item:last-child { border-bottom: none; }
.step-num {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .9rem;
}
[data-bs-theme="dark"] .step-num { color: var(--brand-2); }

/* ---------- الخريطة الحرارية ---------- */
.heatmap th:first-child, .heatmap td:first-child {
  position: sticky; inset-inline-start: 0;
  background: var(--bs-body-bg);
  z-index: 1;
  box-shadow: -6px 0 8px -6px rgba(0,0,0,.15);
}
.heatmap td.hcell {
  text-align: center; font-size: .78rem; color: #fff;
  border: 3px solid var(--bs-body-bg); border-radius: 10px; font-weight: 600;
}
.legend-dot {
  display: inline-block; width: 13px; height: 13px;
  border-radius: 4px; margin-inline-end: 5px; vertical-align: -2px;
}

/* ---------- سبارك-لاين التطور ---------- */
.spark-box {
  background: var(--brand-soft);
  border-radius: 14px; padding: 12px 16px;
}
.spark-line { stroke: var(--brand); stroke-width: 2.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.spark-dot { fill: var(--brand-2); }
.spark-grid { stroke: var(--bs-border-color); stroke-width: 1; }

/* ---------- حالة فارغة ---------- */
.empty-state {
  text-align: center; color: var(--bs-secondary-color);
  padding: 40px 20px;
}
.empty-state .es-icon { font-size: 2.2rem; opacity: .45; display: block; margin-bottom: 8px; }

/* ---------- منطقة رفع CSV ---------- */
.drop-zone {
  border: 2px dashed color-mix(in srgb, var(--brand) 40%, var(--bs-border-color));
  border-radius: 16px; padding: 30px 20px; text-align: center;
  background: var(--brand-soft); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--bs-body-bg));
}

/* ---------- مفيد عام ---------- */
.sub { color: var(--bs-secondary-color); font-size: .87rem; }
.inline-form { display: inline; }
code {
  background: var(--bs-tertiary-bg); padding: 2px 7px;
  border-radius: 6px; font-size: .82em; direction: ltr; display: inline-block;
}
pre.code {
  background: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color);
  border-radius: 12px; padding: 12px 16px; font-size: .78rem;
  overflow-x: auto; direction: ltr; text-align: left;
}
.theme-toggle { border: none; background: none; font-size: 1.15rem; color: var(--bs-secondary-color); padding: 6px 10px; border-radius: 10px; }
.theme-toggle:hover { background: var(--brand-soft); color: var(--brand); }

/* الشريط العلوي على الموبايل: صف واحد يُسحب أفقيًا بدل تكدس الأسطر */
@media (max-width: 767.98px) {
  .navbar .container-app {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .navbar .container-app::-webkit-scrollbar { display: none; }
  .navbar-brand { white-space: nowrap; }

  /* منع تكبير iOS التلقائي عند لمس الحقول الصغيرة */
  .form-control-sm, .form-select-sm { font-size: 1rem; }
}

/* زر تحقق من الإجابة: بعرض كامل بالهاتف، وبحجم طبيعي بالشاشات الأكبر */
.btn-q-submit { width: 100%; min-height: 50px; }
@media (min-width: 576px) {
  .btn-q-submit { width: auto; min-width: 240px; }
}
