/* ==========================================================================
   الفارس - ابتدائية أسامة بن زيد - نظام التصميم الشامل
   RTL, متجاوب، مريح للعين، مناسب للمرحلة الابتدائية، مهيأ للطباعة الاحترافية A4
   ========================================================================== */

:root {
  --primary-50: #f0f9ff;
  --primary-100: #e0f2fe;
  --primary-200: #bae6fd;
  --primary-300: #7dd3fc;
  --primary-400: #38bdf8;
  --primary-500: #0ea5e9;
  --primary-600: #0284c7;
  --primary-700: #0369a1;
  --primary-800: #075985;
  --primary-900: #0c4a6e;

  --navy-50: #f8fafc;
  --navy-100: #f1f5f9;
  --navy-200: #e2e8f0;
  --navy-300: #cbd5e1;
  --navy-700: #334155;
  --navy-800: #1e293b;
  --navy-900: #0f172a;
  --navy-950: #020617;

  --gold-400: #facc15;
  --gold-500: #eab308;
  --gold-600: #ca8a04;

  --emerald-500: #10b981;
  --emerald-600: #059669;

  --rose-500: #f43f5e;
  --rose-600: #e11d48;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.12);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  direction: rtl;
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, Arial, sans-serif;
  background-color: var(--navy-50);
  color: var(--navy-900);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* Typography */
h1, h2, h3, h4, h5 {
  font-weight: 700;
  color: var(--navy-900);
  line-height: 1.3;
}

a {
  color: var(--primary-600);
  text-decoration: none;
  transition: var(--transition);
}

button, input, select, textarea {
  font-family: inherit;
}

/* App Header / Topbar */
.app-header {
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 100%);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-bottom: 3px solid var(--primary-500);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.1);
  padding: 4px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.brand-title-wrap h1 {
  font-size: 1.35rem;
  font-weight: 800;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-title-wrap h1 span.app-name {
  color: var(--primary-300);
  background: linear-gradient(to left, #38bdf8, #facc15);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--navy-300);
}

/* Header User Profile & Balance Counters */
.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.student-balance-capsules {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.capsule {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.capsule-purchasing {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.capsule-earned {
  background: rgba(250, 204, 21, 0.15);
  border: 1px solid rgba(250, 204, 21, 0.4);
  color: #fde047;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-600);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.user-info-text {
  line-height: 1.2;
}

.user-name-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
}

.user-role-label {
  font-size: 0.7rem;
  color: var(--primary-300);
}

/* Nav Tabs */
.app-nav {
  background: #ffffff;
  border-bottom: 1px solid var(--navy-200);
  box-shadow: var(--shadow-sm);
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.4rem 1.5rem;
  scrollbar-width: thin;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--navy-700);
  white-space: nowrap;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: var(--transition);
}

.nav-link:hover {
  background: var(--primary-50);
  color: var(--primary-700);
}

.nav-link.active {
  background: var(--primary-600);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);
}

/* Main Container */
.main-content {
  max-width: 1400px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  flex: 1;
}

/* Cards & Layout */
.card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--navy-200);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: var(--transition);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--navy-100);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--navy-900);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--navy-700);
  margin-top: 0.2rem;
}

/* Grid Utilities */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .header-container { flex-wrap: wrap; }
  .main-content { padding: 0 1rem; margin: 1rem auto; }
}

/* Stat Widgets */
.stat-widget {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  border: 1px solid var(--navy-200);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.stat-icon.blue { background: var(--primary-100); color: var(--primary-600); }
.stat-icon.green { background: #d1fae5; color: var(--emerald-600); }
.stat-icon.gold { background: #fef3c7; color: var(--gold-600); }
.stat-icon.rose { background: #ffe4e6; color: var(--rose-600); }

.stat-info h3 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--navy-900);
}

.stat-info p {
  font-size: 0.85rem;
  color: var(--navy-700);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
}

.btn-primary {
  background: var(--primary-600);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-700);
}

.btn-secondary {
  background: var(--navy-100);
  color: var(--navy-800);
  border-color: var(--navy-200);
}
.btn-secondary:hover {
  background: var(--navy-200);
}

.btn-success {
  background: var(--emerald-600);
  color: #fff;
}
.btn-success:hover {
  background: var(--emerald-500);
}

.btn-danger {
  background: var(--rose-600);
  color: #fff;
}
.btn-danger:hover {
  background: var(--rose-500);
}

.btn-outline {
  background: transparent;
  border-color: var(--navy-300);
  color: var(--navy-800);
}
.btn-outline:hover {
  background: var(--navy-100);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* Form Controls */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--navy-800);
  margin-bottom: 0.4rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--navy-200);
  background: #ffffff;
  color: var(--navy-900);
  font-size: 0.9rem;
  transition: var(--transition);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

/* Tables */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--navy-200);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 0.9rem;
}

.table th {
  background: var(--navy-50);
  color: var(--navy-700);
  font-weight: 700;
  padding: 0.85rem 1rem;
  border-bottom: 1.5px solid var(--navy-200);
}

.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--navy-100);
  color: var(--navy-800);
}

.table tr:hover td {
  background: var(--primary-50);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-blue { background: var(--primary-100); color: var(--primary-800); }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-gold { background: #fef3c7; color: #92400e; }
.badge-rose { background: #ffe4e6; color: #9f1239; }
.badge-gray { background: var(--navy-200); color: var(--navy-700); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius-xl);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
  transform: translateY(15px);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-backdrop.active .modal-dialog {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--navy-100);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--navy-700);
}

/* Toast Alerts */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 200;
}

.toast {
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s ease;
}

.toast-success { background: var(--emerald-600); }
.toast-error { background: var(--rose-600); }
.toast-info { background: var(--primary-600); }

@keyframes slideIn {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--navy-700);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.6;
}

.empty-state h3 {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
}

/* Rewards Grid */
.rewards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.reward-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--navy-200);
  overflow: hidden;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}

.reward-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.reward-image-wrap {
  width: 100%;
  height: 160px;
  background: var(--navy-100);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.reward-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reward-body {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.reward-price-tag {
  background: rgba(250, 204, 21, 0.2);
  color: #a16207;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-weight: 800;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

/* Auction Live Widget */
.auction-card {
  border: 2px solid var(--primary-400);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: linear-gradient(180deg, #ffffff 0%, var(--primary-50) 100%);
  position: relative;
  overflow: hidden;
}

.auction-live-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: var(--rose-600);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ==========================================================================
   قوالب وأنماط الطباعة A4 الاحترافية (Print Stylesheet)
   تمنع الصفحات البيضاء، تمنع قص البطاقات، تضمن وضوح رموز QR وجودتها
   ========================================================================== */
@page {
  size: A4 portrait;
  margin: 10mm;
}

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
  }

  .app-header, .app-nav, .no-print, .toast-container, .modal-backdrop {
    display: none !important;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  /* بطاقات الدخول (Student & Teacher Login Cards Grid) */
  .print-cards-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8mm !important;
    page-break-inside: auto;
  }

  .login-card-print {
    border: 1.5pt solid #0f172a !important;
    border-radius: 6mm !important;
    padding: 5mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    min-height: 58mm !important;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .login-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1pt dashed #94a3b8;
    padding-bottom: 3mm;
    margin-bottom: 3mm;
  }

  .login-card-school {
    font-size: 10pt;
    font-weight: 700;
  }

  .login-card-program {
    font-size: 12pt;
    font-weight: 900;
    color: #0284c7;
  }

  .login-card-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .login-card-details h4 {
    font-size: 12pt;
    font-weight: 800;
    margin-bottom: 2mm;
  }

  .login-card-code-badge {
    background: #f1f5f9;
    border: 1pt solid #cbd5e1;
    padding: 1.5mm 3mm;
    border-radius: 2mm;
    font-size: 11pt;
    font-family: monospace;
    font-weight: 700;
    display: inline-block;
  }

  .login-card-qr {
    width: 25mm;
    height: 25mm;
  }

  /* بطاقات مكافآت QR المطبوعة */
  .print-qr-rewards-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6mm !important;
  }

  .qr-reward-card-print {
    border: 2pt solid #0284c7 !important;
    border-radius: 5mm !important;
    padding: 4mm !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    background: #ffffff !important;
  }

  .qr-reward-points-badge {
    background: #0284c7 !important;
    color: #ffffff !important;
    padding: 3mm 5mm !important;
    border-radius: 4mm !important;
    font-size: 14pt !important;
    font-weight: 900 !important;
    text-align: center !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* جداول الكشوفات للطباعة */
  .print-roster-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin-top: 5mm !important;
  }

  .print-roster-table th, .print-roster-table td {
    border: 1pt solid #475569 !important;
    padding: 3mm 4mm !important;
    font-size: 10pt !important;
  }

  .print-roster-table th {
    background: #f1f5f9 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .print-roster-table thead {
    display: table-header-group !important;
  }

  .print-roster-table tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}

/* ==========================================================================
   معاينة ورق A4 داخل المنصة قبل الطباعة (In-App A4 Print Preview)
   ========================================================================== */
.a4-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(4px);
  z-index: 9500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.a4-preview-toolbar {
  background: #0f172a;
  color: #ffffff;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-bottom: 1px solid #334155;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.a4-preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.a4-preview-sheet {
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  background: #ffffff;
  color: #0f172a;
  padding: 12mm;
  border-radius: 6px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
}

/* تنسيقات البطاقات والكشوفات داخل المعاينة على الشاشة */
.a4-preview-sheet .print-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5mm;
}

.a4-preview-sheet .login-card-print {
  border: 1.5pt solid #0f172a;
  border-radius: 4mm;
  padding: 4mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 58mm;
  background: #ffffff;
  break-inside: avoid;
}

.a4-preview-sheet .login-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1pt dashed #94a3b8;
  padding-bottom: 3mm;
  margin-bottom: 3mm;
}

.a4-preview-sheet .login-card-program {
  font-size: 12pt;
  font-weight: 900;
  color: #0284c7;
}

.a4-preview-sheet .login-card-school {
  font-size: 10pt;
  font-weight: 700;
}

.a4-preview-sheet .login-card-body {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 3mm;
}

.a4-preview-sheet .login-card-details h4 {
  font-size: 11.5pt;
  font-weight: 800;
  margin-bottom: 2mm;
}

.a4-preview-sheet .login-card-code-badge {
  background: #f1f5f9;
  border: 1pt solid #cbd5e1;
  padding: 1.5mm 3mm;
  border-radius: 2mm;
  font-size: 10.5pt;
  font-family: monospace;
  font-weight: 700;
  display: inline-block;
}

.a4-preview-sheet .login-card-qr {
  width: 25mm;
  height: 25mm;
  flex-shrink: 0;
}

.a4-preview-sheet .print-qr-rewards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6mm;
}

.a4-preview-sheet .qr-reward-card-print {
  border: 2pt solid #0284c7;
  border-radius: 5mm;
  padding: 4mm;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
}

.a4-preview-sheet .qr-reward-points-badge {
  background: #0284c7;
  color: #ffffff;
  padding: 3mm 5mm;
  border-radius: 4mm;
  font-size: 13pt;
  font-weight: 900;
  text-align: center;
}

.a4-preview-sheet .print-roster-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 5mm;
}

.a4-preview-sheet .print-roster-table th,
.a4-preview-sheet .print-roster-table td {
  border: 1pt solid #475569;
  padding: 3mm 4mm;
  font-size: 10pt;
  word-break: break-word;
}

.a4-preview-sheet .print-roster-table th {
  background: #f1f5f9;
  font-weight: 800;
}

@media (max-width: 768px) {
  .a4-preview-sheet {
    padding: 0.85rem;
    min-height: auto;
  }
  .a4-preview-sheet .print-cards-grid,
  .a4-preview-sheet .print-qr-rewards-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  .a4-preview-overlay {
    display: none !important;
  }
}
