/* ── المتغيرات الأساسية ── */
:root {
  --primary:       #1e5fa8;
  --primary-light: #e8f1fb;
  --primary-dark:  #1a4f90;
  --accent:        #f5a623;
  --success:       #27ae60;
  --danger:        #e74c3c;
  --warning:       #f39c12;
  --bg:            #f4f7fb;
  --card:          #ffffff;
  --text:          #2d3748;
  --text-muted:    #718096;
  --border:        #e2e8f0;
  --shadow:        0 2px 12px rgba(0, 0, 0, 0.07);
  --radius:        12px;
  --radius-lg:     20px;
  --sat: env(safe-area-inset-top,    0px);
  --sar: env(safe-area-inset-right,  0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left,   0px);
}

/* ── Reset وأساسيات ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  padding-top:    var(--sat);
  padding-right:  var(--sar);
  padding-bottom: var(--sab);
  padding-left:   var(--sal);
}

/* ── التفاعل باللمس ── */
* {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, a, [role="button"] {
  cursor: pointer;
  user-select: none;
}

/* ── Header ── */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  padding-top: calc(14px + var(--sat));
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.app-header h1 { font-size: clamp(14px, 4vw, 18px); font-weight: 700; }
.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Container متجاوب ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ── بطاقات الدروس — Grid متجاوب ── */
.lessons-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}
@media (min-width: 540px) {
  .lessons-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .lessons-grid { grid-template-columns: repeat(2, 1fr); gap: 20px; }
}
@media (min-width: 1024px) {
  .lessons-grid { grid-template-columns: repeat(3, 1fr); gap: 24px; }
}
@media (min-width: 1280px) {
  .lessons-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── بطاقة الدرس ── */
.lesson-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  border: 1px solid var(--border);
}
.lesson-card:hover,
.lesson-card:focus-within {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.lesson-card.locked { opacity: 0.65; pointer-events: none; }
.lesson-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--primary-light);
}
.lesson-info { padding: 14px; }
.lesson-title {
  font-weight: 700;
  font-size: clamp(13px, 3.5vw, 15px);
  color: var(--text);
  margin-bottom: 6px;
}
.lesson-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.subject-badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
}

/* ── مشغل الفيديو متجاوب ── */
.video-section {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.video-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}
.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.video-wrapper video::-webkit-media-controls {
  pointer-events: auto;
}
@media (max-width: 480px) {
  .video-section {
    border-radius: 0;
    margin: 0 -16px;
  }
}

/* ── Watermark فوق الفيديو ── */
.watermark {
  position: absolute;
  color: rgba(255,255,255,0.22);
  font-size: clamp(10px, 2vw, 15px);
  font-family: 'Cairo', sans-serif;
  font-weight: 700;
  pointer-events: none;
  user-select: none;
  z-index: 10;
  white-space: nowrap;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.6);
  transition: top 3s ease, right 3s ease;
}

/* ── أزرار الـ Controls المخصصة ── */
.video-controls {
  background: rgba(0,0,0,0.7);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  direction: rtl;
}
.ctrl-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background 0.15s;
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.15); }
.progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.3);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s;
}

/* ── نموذج الأسئلة ── */
.question-form textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: 'Cairo', sans-serif;
  font-size: 15px;
  direction: rtl;
  resize: vertical;
  transition: border-color 0.2s;
}
.question-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,95,168,0.1);
}
.question-item {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.question-status {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.question-status.pending { background: #fef3cd; color: #856404; }
.question-status.answered { background: #d4edda; color: #155724; }

/* ── أزرار عامة ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 10px;
  font-family: 'Cairo', sans-serif;
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  text-decoration: none;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-light); color: var(--primary); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-block     { width: 100%; }

/* ── Toast notifications ── */
.toast {
  position: fixed;
  bottom: calc(20px + var(--sab));
  right: 50%;
  transform: translateX(50%);
  background: #2d3748;
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-family: 'Cairo', sans-serif;
  font-size: 14px;
  font-weight: 600;
  z-index: 9999;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
}
@keyframes toastIn  { from { opacity:0; transform:translateX(50%) translateY(20px); } }
@keyframes toastOut { to   { opacity:0; transform:translateX(50%) translateY(20px); } }

/* ── Navigation Bottom (موبايل) ── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: var(--sab);
  z-index: 200;
  flex-direction: row;
  justify-content: space-around;
}
@media (max-width: 767px) {
  .bottom-nav { display: flex; }
  .container  { padding-bottom: calc(70px + var(--sab)); }
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10px;
  font-family: 'Cairo', sans-serif;
  gap: 4px;
  transition: color 0.2s;
}
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item svg    { width: 24px; height: 24px; }

/* ── Typography Responsive ── */
h1 { font-size: clamp(20px, 5vw, 28px); font-weight: 700; }
h2 { font-size: clamp(17px, 4vw, 22px); font-weight: 700; }
h3 { font-size: clamp(15px, 3.5vw, 18px); font-weight: 600; }

/* ── نموذج تسجيل الدخول ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #153e6f 100%);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo h1 {
  color: var(--primary);
  font-size: clamp(18px, 5vw, 24px);
  margin-bottom: 4px;
}
.login-logo p {
  color: var(--text-muted);
  font-size: 13px;
}
.form-group {
  margin-bottom: 18px;
}

/* Password toggle button inside form-group */
.form-group{position:relative}
.password-toggle{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  right:12px;
  background:none;
  border:none;
  padding:4px;
  cursor:pointer;
  color:var(--text-muted);
  font-size:16px;
}
.form-group label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-family: 'Cairo', sans-serif;
  font-size: 15px;
  direction: rtl;
  transition: border-color 0.2s;
  min-height: 48px;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,95,168,0.1);
}
.form-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 4px;
  display: none;
}

/* ── الإحصائيات (لوحة التحكم) ── */
.stats-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.stat-value {
  font-size: clamp(24px, 5vw, 32px);
  font-weight: 800;
  color: var(--primary);
}
.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Admin Layout ── */
.admin-layout {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
}
@media (min-width: 768px) {
  .admin-layout {
    grid-template-columns: 240px 1fr;
  }
}
.admin-sidebar {
  background: var(--primary);
  color: #fff;
  padding: 24px 0;
  padding-top: calc(24px + var(--sat));
}
@media (max-width: 767px) {
  .admin-sidebar { display: none; }
}
.admin-sidebar a {
  display: block;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 12px 20px;
  font-size: 14px;
  transition: all 0.2s;
}
.admin-sidebar a:hover,
.admin-sidebar a.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}
.admin-content {
  padding: 20px;
  padding-top: calc(20px + var(--sat));
}

/* ── جداول لوحة الإدارة ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  background: var(--primary-light);
  color: var(--primary);
  padding: 12px 16px;
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover { background: #f8fafc; }

@media (max-width: 640px) {
  .data-table, .data-table thead, .data-table tbody,
  .data-table th, .data-table td, .data-table tr {
    display: block;
  }
  .data-table thead { display: none; }
  .data-table tr {
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: var(--shadow);
  }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    font-size: 12px;
    min-width: 100px;
  }
}

/* ── Print ── */
@media print { body { display: none !important; } }

/* ── Touch Zones ── */
[data-touch-zone] {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  font-size: 28px;
  color: rgba(255,255,255,0.8);
  pointer-events: auto;
  transition: opacity 0.2s;
}
[data-touch-zone="right"] { right: 0; }
[data-touch-zone="left"]  { left: 0; }
[data-touch-zone].flash   { opacity: 1; animation: flash 0.5s ease; }
@keyframes flash { 0%,100%{opacity:0} 50%{opacity:1} }

/* ── Skeleton Loaders ── */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Student Card ── */
.student-card {
  background: linear-gradient(135deg, var(--primary) 0%, #153e6f 100%);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.student-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.student-info { flex: 1; }
.student-name { font-weight: 700; font-size: clamp(16px,4vw,20px); }
.student-meta { font-size: 13px; opacity: 0.85; margin-top: 4px; }
.student-meta span { display: inline-flex; align-items: center; gap: 6px; }
.student-sub-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(255,255,255,0.2);
  margin-top: 6px;
}

/* ── Badges ── */
.badges-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.badge-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
}
.badge-item .icon { font-size: 18px; }

/* ── Quiz Styles ── */
.quiz-container {
  max-width: 700px;
  margin: 0 auto;
}
.quiz-question {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.quiz-question h3 {
  font-size: 16px;
  margin-bottom: 14px;
  color: var(--text);
}
.quiz-option {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 8px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-family: 'Cairo', sans-serif;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: right;
}
.quiz-option:hover { border-color: var(--primary); background: var(--primary-light); }
.quiz-option.selected { border-color: var(--primary); background: var(--primary-light); }
.quiz-option.correct { border-color: var(--success); background: #d4edda; color: #155724; }
.quiz-option.wrong { border-color: var(--danger); background: #f8d7da; color: #721c24; }
.quiz-option.disabled { pointer-events: none; opacity: 0.7; }
.quiz-result {
  text-align: center;
  padding: 30px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.quiz-score {
  font-size: clamp(36px,8vw,56px);
  font-weight: 800;
  color: var(--primary);
}
.quiz-score-text { font-size: 18px; color: var(--text-muted); margin-top: 8px; }

/* ── Play Overlay على بطاقة الدرس ── */
.lesson-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.lesson-card:hover .lesson-play-overlay {
  opacity: 1;
}
.lesson-play-overlay i {
  font-size: 48px;
  color: #fff;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}

/* ── Modal مشغل الفيديو ── */
.video-player-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: modalFadeIn 0.3s ease;
}
.video-player-modal.active {
  display: flex;
  flex-direction: column;
}
@keyframes modalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.player-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.player-video-wrapper {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-controls {
  width: 100%;
  background: rgba(0,0,0,0.8);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  direction: rtl;
  border-radius: 0 0 8px 8px;
  flex-wrap: wrap;
}

.player-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.player-btn:hover {
  background: rgba(255,255,255,0.3);
}

.player-progress {
  flex: 1;
  min-width: 150px;
  height: 6px;
  background: rgba(255,255,255,0.3);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
}
.player-progress-fill {
  height: 100%;
  background: #f5a623;
  border-radius: 3px;
  width: 0%;
}

.player-time {
  color: #fff;
  font-size: 12px;
  font-family: monospace;
  min-width: 90px;
  text-align: center;
}

.player-close-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  margin-right: auto;
}
.player-close-btn:hover {
  background: rgba(255,255,255,0.3);
}

.player-title {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  font-family: 'Cairo', sans-serif;
  margin-bottom: 16px;
  text-align: center;
}

.player-no-video {
  color: #fff;
  text-align: center;
  font-family: 'Cairo', sans-serif;
  font-size: 16px;
}

/* Fullscreen support */
.player-video-wrapper:fullscreen {
  width: 100vw;
  height: 100vh;
}
.player-video-wrapper:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
}

@media (max-width: 640px) {
  .player-video-wrapper {
    border-radius: 0;
  }
  .player-controls {
    border-radius: 0;
  }
  .player-container {
    padding: 0;
  }
}
