/* مدرسة الرضوان - ملف التصميم الرئيسي */

:root {
  --primary: #1a5f2e;
  --primary-dark: #134523;
  --primary-light: #e8f5ec;
  --secondary: #0d6efd;
  --accent: #ffc107;
  --bg-light: #f4f7f2;
  --sidebar-width: 260px;
  --header-height: 60px;
  --surface: #ffffff;
  --border-soft: #e2eadf;
  --shadow-soft: 0 12px 30px rgba(15, 61, 38, 0.08);
}

/* ===== BODY & LAYOUT ===== */
body {
  font-family: 'Cairo', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255,193,7,.10), transparent 24rem),
    linear-gradient(180deg, #f7faf5 0%, var(--bg-light) 100%);
  color: #212529;
  direction: rtl;
  min-height: 100vh;
  /* منع التمرير الأفقي نهائياً */
  overflow-x: hidden;
  max-width: 100vw;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: calc(var(--app-vh, 1vh) * 100);
  max-height: 100vh;
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  box-shadow: -4px 0 12px rgba(0,0,0,0.15);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  text-align: center;
}

.sidebar-brand .brand-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.4;
}

.sidebar-brand .brand-subtitle {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.6);
}

.sidebar-nav {
  flex: 0 0 auto;
  min-height: auto;
  overflow: visible;
  padding: 0.75rem 0 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.35) transparent;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: rgba(255,255,255,0.04); }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 999px; }

.sidebar-nav .nav-section {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.55rem 1.25rem;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 0;
  transition: all 0.2s;
  position: relative;
}

.sidebar-nav .nav-link i {
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,0.1);
}

.sidebar-nav .nav-link.active {
  color: #fff;
  background: rgba(255,255,255,0.15);
  font-weight: 600;
}

.sidebar-nav .nav-link.active::before {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 2px 0 0 2px;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main-wrapper {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-right 0.3s ease;
  /* منع الطفح للخارج */
  overflow-x: hidden;
  max-width: calc(100vw - var(--sidebar-width));
  width: calc(100vw - var(--sidebar-width));
  box-sizing: border-box;
}

.top-bar {
  height: var(--header-height);
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  /* دعم safe-area لشاشات iPhone بالـ notch */
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--header-height) + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 2px 14px rgba(15,61,38,0.05);
  backdrop-filter: blur(12px);
  /* منع الطفح - لكن نسمح للـ dropdown بالظهور */
  width: 100%;
  box-sizing: border-box;
  /* overflow: hidden; ← محذوف لأنه يمنع ظهور الـ dropdown */
}

.top-bar .page-title {
  font-size: 1rem;
  font-weight: 700;
  color: #212529;
  margin: 0;
}

.top-bar .top-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.content-area {
  flex: 1;
  padding: 1.5rem;
}

/* ===== CARDS ===== */
.card {
  border-radius: 12px;
  transition: transform 0.2s, box-shadow 0.2s;
  border-color: var(--border-soft) !important;
  box-shadow: var(--shadow-soft);
}

.card.hover-lift:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1) !important;
}

.stat-card {
  border-radius: 18px;
  padding: 1.25rem;
  border: none;
  background: linear-gradient(180deg, #fff 0%, #fbfdf9 100%);
}

.stat-card .stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: #6c757d;
  margin-top: 0.25rem;
}

/* ===== TABLES ===== */
.table th {
  font-size: 0.8rem;
  font-weight: 700;
  color: #495057;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table td {
  font-size: 0.875rem;
  vertical-align: middle;
}

/* ===== FORMS ===== */
.form-label {
  font-size: 0.875rem;
}

.form-control, .form-select {
  border-radius: 8px;
  border-color: #dee2e6;
  font-size: 0.875rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem rgba(26,95,46,0.15);
}

/* ===== BUTTONS ===== */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
}

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ===== BADGES ===== */
.badge {
  font-weight: 600;
  border-radius: 6px;
  padding: 0.3em 0.6em;
}

/* ===== MODALS ===== */
.modal-content {
  border-radius: 16px;
  border: none;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-header {
  border-bottom: 1px solid #f0f0f0;
  padding: 1rem 1.25rem;
}

.modal-footer {
  border-top: 1px solid #f0f0f0;
}

/* ===== ALERTS ===== */
.alert {
  border-radius: 10px;
  border: none;
  font-size: 0.875rem;
}

/* ===== PAGINATION ===== */
.pagination .page-link {
  border-radius: 8px !important;
  margin: 0 2px;
  font-size: 0.875rem;
  color: var(--primary);
}

.pagination .page-item.active .page-link {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ===== PROGRESS BARS ===== */
.progress {
  border-radius: 99px;
  background-color: #e9ecef;
}

/* ===== TABS ===== */
.nav-tabs .nav-link {
  color: #6c757d;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}

.nav-tabs .nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}

/* ===== LOGIN PAGE ===== */
.login-bg {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 2.5rem;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-logo {
  width: 80px;
  height: 80px;
  background: var(--primary-light);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  font-size: 2.5rem;
  color: var(--primary);
}

/* ===== SIDEBAR TOGGLE (MOBILE) ===== */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #495057;
  padding: 0;
  cursor: pointer;
}

/* ===== MOBILE OVERLAY ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1039;
}

/* ===== ANIMATIONS ===== */
.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== RESPONSIVE — TABLET / SMALL DESKTOP ===== */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(100%);
    width: 280px;
    max-width: 85vw;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-wrapper {
    margin-right: 0 !important;
    max-width: 100vw !important;
    width: 100vw !important;
  }

  .sidebar-toggle {
    display: block;
  }

  .content-area {
    padding: 1rem;
  }

  .sidebar-nav .nav-link {
    padding: 0.85rem 1.25rem;
    font-size: 0.95rem;
  }

  .sidebar-nav .nav-link i {
    font-size: 1.15rem;
  }

  .top-bar {
    padding: 0 0.85rem;
  }

  .top-bar .page-title {
    font-size: 0.95rem;
    max-width: 55vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ===== RESPONSIVE — MOBILE (<= 768px) ===== */
@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  body {
    font-size: 0.92rem;
  }

  .content-area {
    padding: 0.75rem;
  }

  /* العنوان أعلى الصفحة */
  h4, h5 {
    font-size: 1.05rem;
  }

  /* الأزرار في الهيدر */
  .top-bar .top-actions {
    gap: 0.4rem;
  }

  .top-bar .btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
  }

  /* البطاقات الإحصائية: عمودان جنباً إلى جنب */
  .stat-card {
    padding: 0.85rem;
  }

  .stat-card .stat-icon {
    width: 42px;
    height: 42px;
    font-size: 1.15rem;
    border-radius: 10px;
  }

  .stat-card .stat-value {
    font-size: 1.25rem;
  }

  .stat-card .stat-label {
    font-size: 0.72rem;
  }

  .card-body {
    padding: 0.85rem;
  }

  /* الجداول: تمرير أفقي تلقائي وحجم خط أصغر */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  .table {
    font-size: 0.78rem;
    white-space: nowrap;
  }

  .table th,
  .table td {
    padding: 0.55rem 0.5rem;
    font-size: 0.78rem;
  }

  .table th {
    font-size: 0.7rem;
  }

  /* أزرار الإجراءات داخل الجداول */
  .table .btn-sm {
    padding: 0.3rem 0.45rem;
    font-size: 0.78rem;
    min-width: 32px;
  }

  /* النوافذ المنبثقة (Modals) تأخذ معظم الشاشة */
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100vw - 1rem);
  }

  .modal-dialog.modal-lg,
  .modal-dialog.modal-xl {
    max-width: calc(100vw - 1rem);
  }

  .modal-content {
    border-radius: 12px;
  }

  .modal-header,
  .modal-footer {
    padding: 0.75rem 1rem;
  }

  .modal-body {
    padding: 0.85rem 1rem;
  }

  .modal-title {
    font-size: 1rem;
  }

  /* الحقول: حجم خط 16px لمنع التكبير التلقائي على iOS */
  .form-control,
  .form-select,
  .form-control-sm,
  .form-select-sm {
    font-size: 16px;
    padding: 0.55rem 0.7rem;
    min-height: 42px;
  }

  textarea.form-control {
    min-height: 80px;
  }

  .form-label {
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
  }

  /* أزرار بحجم لمسي مريح */
  .btn {
    min-height: 40px;
    padding: 0.45rem 0.85rem;
  }

  .btn-sm {
    min-height: 34px;
  }

  /* أزرار العمليات العامة تتمدد على كامل العرض */
  .modal-footer .btn,
  .form-actions .btn {
    flex: 1 1 auto;
  }

  /* الفلاتر والمساحات بين العناصر */
  .gap-mobile-2 > * { margin-bottom: 0.5rem; }

  /* تخفيف الـ pagination */
  .pagination .page-link {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }

  /* الإشعارات */
  .alert {
    padding: 0.65rem 0.85rem;
    font-size: 0.85rem;
  }

  /* بطاقة تسجيل الدخول */
  .login-card {
    padding: 1.5rem 1.25rem;
    border-radius: 16px;
  }

  /* التبويبات */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .nav-tabs .nav-link {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.5rem 0.75rem;
  }

  /* تحسين عرض الـ dropdown */
  .dropdown-menu {
    font-size: 0.9rem;
  }

  /* الفوتر */
  footer {
    padding: 0.65rem 0.85rem !important;
    font-size: 0.75rem;
  }

  footer span {
    font-size: 0.72rem !important;
  }
}

/* ===== شاشات صغيرة جداً (<= 480px) ===== */
@media (max-width: 480px) {
  .content-area {
    padding: 0.6rem;
  }

  .top-bar {
    padding: 0 0.6rem;
  }

  .top-bar .page-title {
    font-size: 0.85rem;
    max-width: 50vw;
  }

  /* البطاقات الإحصائية واحدة في كل صف */
  .stat-card .stat-value {
    font-size: 1.1rem;
  }

  .card {
    border-radius: 10px;
  }

  /* تصغير الـ badges */
  .badge {
    font-size: 0.7rem;
    padding: 0.25em 0.5em;
  }

  /* عنوان النافذة */
  .modal-title {
    font-size: 0.95rem;
  }
}

/* ===== مرونة العناوين والصفوف العلوية ===== */
@media (max-width: 768px) {
  .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* صفوف الفلاتر تصبح عمودية */
  .filter-row,
  form.row.g-2,
  form.row.g-3 {
    --bs-gutter-y: 0.5rem;
  }
}

/* ===== دعم safe-area لأجهزة iPhone ذات الحافة ===== */
@supports (padding: max(0px)) {
  .content-area {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ===== QURAN THEMED DECORATIONS ===== */
.quran-icon {
  color: var(--primary);
}

.hifz-level-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
}

/* Scrollable content */
.scroll-x { overflow-x: auto; }

/* Empty state */
.empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: #adb5bd;
}

.empty-state i { font-size: 3rem; display: block; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.9rem; margin: 0; }

.login-mark {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(255,255,255,.14);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}

.login-mark i {
  font-size: 2.75rem;
}

/* ===== TOPBAR SEARCH ===== */
.topbar-search .input-group {
  background: #f1f3f5;
  border-radius: 8px;
  padding: 2px;
}
.topbar-search .input-group-text,
.topbar-search .form-control {
  background: transparent !important;
  box-shadow: none !important;
}
.topbar-search .form-control:focus { background: #fff !important; }

/* ===== DARK MODE ===== */
html.dark-mode {
  background: #0f1419;
  color: #e6edf3;
}
html.dark-mode body { background: #0f1419 !important; color: #e6edf3 !important; }
html.dark-mode .top-bar,
html.dark-mode footer,
html.dark-mode .card,
html.dark-mode .modal-content,
html.dark-mode .dropdown-menu,
html.dark-mode .list-group-item {
  background-color: #1c2128 !important;
  color: #e6edf3 !important;
  border-color: #30363d !important;
}
html.dark-mode .topbar-search .input-group { background: #2d333b; }
html.dark-mode .topbar-search .input-group-text,
html.dark-mode .topbar-search .form-control { color: #e6edf3 !important; }
html.dark-mode .topbar-search .form-control::placeholder { color: #8b949e; }
html.dark-mode .table { color: #e6edf3; }
html.dark-mode .table-light, html.dark-mode .table > thead {
  background-color: #2d333b !important;
  color: #e6edf3 !important;
  --bs-table-bg: #2d333b;
}
html.dark-mode .table-hover > tbody > tr:hover > * { background-color: #2d333b !important; color: #e6edf3 !important; }
html.dark-mode .table > :not(caption) > * > * { background-color: transparent !important; color: inherit !important; border-color: #30363d !important; }
html.dark-mode .form-control,
html.dark-mode .form-select {
  background-color: #2d333b !important;
  color: #e6edf3 !important;
  border-color: #30363d !important;
}
html.dark-mode .form-control::placeholder { color: #8b949e; }
html.dark-mode .text-muted { color: #8b949e !important; }
html.dark-mode .border-bottom, html.dark-mode .border-top, html.dark-mode .border { border-color: #30363d !important; }
html.dark-mode .btn-outline-secondary { color: #c9d1d9; border-color: #30363d; }
html.dark-mode .btn-outline-secondary:hover { background: #30363d; color: #fff; }
html.dark-mode .bg-white, html.dark-mode .bg-light { background-color: #1c2128 !important; color: #e6edf3 !important; }
html.dark-mode .alert-info { background: #0d4f6f; color: #cfe9ff; border-color: #1f6f99; }
html.dark-mode .alert-success { background: #1f4a2c; color: #d4edda; border-color: #2d6e3f; }
html.dark-mode .alert-warning { background: #5a4a1f; color: #ffeeba; border-color: #826b2c; }
html.dark-mode .alert-danger { background: #5a1f1f; color: #f8d7da; border-color: #822c2c; }
html.dark-mode .nav-link { color: #c9d1d9; }
html.dark-mode .progress { background: #30363d; }
/* Tabs in dark mode (used on registrations + student profile + others) */
html.dark-mode .nav-tabs { border-bottom-color: #30363d; }
html.dark-mode .nav-tabs .nav-link {
  color: #c9d1d9 !important;
  background: transparent;
  border-color: transparent;
}
html.dark-mode .nav-tabs .nav-link:hover {
  color: #fff !important;
  border-bottom-color: #30363d;
  background: rgba(255,255,255,.04);
}
html.dark-mode .nav-tabs .nav-link.active,
html.dark-mode .nav-tabs .nav-item.show .nav-link {
  color: #4ade80 !important;
  background: transparent;
  border-bottom: 2px solid #4ade80;
  font-weight: 700;
}
html.dark-mode .nav-tabs .nav-link .badge { color: #000 !important; }
/* Bootstrap default text-dark + bg-warning combo stays readable in dark mode */
html.dark-mode .badge.text-dark { color: #1a1d20 !important; }
html.dark-mode hr, html.dark-mode .dropdown-divider { border-color: #30363d; opacity: 1; }
html.dark-mode .dropdown-item { color: #e6edf3; }
html.dark-mode .dropdown-item:hover { background: #2d333b; color: #fff; }
html.dark-mode .badge.bg-light { background: #2d333b !important; color: #e6edf3 !important; }
@media print { html.dark-mode * { color: #000 !important; background: #fff !important; } }

/* ===== TEACHER DASHBOARD WIDGET ===== */
.widget-quick {
  border-right: 4px solid var(--primary);
  background: linear-gradient(135deg, rgba(45,107,86,.05), transparent);
}
.late-row { background: rgba(220,53,69,.06); }

/* ===== تحسينات الهاتف المحمول - Mobile Improvements ===== */

/* جداول على الهاتف */
@media (max-width: 767px) {
  /* إخفاء الأعمدة الثانوية في الجداول */
  .table .d-none-mobile { display: none !important; }

  /* جعل الجداول أكثر قابلية للقراءة */
  .table td, .table th { 
    padding: 0.5rem 0.4rem;
    font-size: 0.82rem;
  }

  /* تصغير الأزرار */
  .btn-sm { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
  
  /* بطاقات الإحصاءات */
  .card .fs-3, .card .fs-4 { font-size: 1.4rem !important; }

  /* الشريط الجانبي */
  .sidebar { transform: translateX(100%); }
  .sidebar.show { transform: translateX(0); }
  
  /* المحتوى الرئيسي */
  .main-wrapper { margin-right: 0 !important; }
  .content-area { padding: 1rem 0.75rem !important; }

  /* رأس الصفحة */
  .top-bar { padding: 0 0.75rem; }
  .top-bar .topbar-search { display: none; }

  /* نماذج البحث والفلاتر */
  .filter-row .form-select,
  .filter-row .form-control { font-size: 0.85rem; }

  /* Modal */
  .modal-dialog { margin: 0.5rem; }
  .modal-body { padding: 1rem; }

  /* أزرار الإجراءات في الجداول */
  .table .d-flex.gap-1 { flex-wrap: wrap; }
  .table .btn { margin-bottom: 2px; }

  /* بطاقات الطالب */
  .stu-banner { padding: 12px !important; }
  .stu-banner .name { font-size: 17px !important; }
  .stu-banner .photo { width: 58px !important; height: 58px !important; }

  /* نقاط التقييم */
  .pts-radio { grid-template-columns: repeat(5, 1fr) !important; }
  
  /* صفحة ولي الأمر */
  .parent-header { padding: 1.5rem 1rem !important; }

  /* البادينج العام */
  h4.fw-bold { font-size: 1.1rem; }
  
  /* الكروت في الشبكة */
  .row.g-3 > [class*="col-md"] { padding: 0.4rem; }
  
  /* إخفاء التسميات الطويلة */
  .btn .d-none-sm { display: none !important; }
}

/* تحسين عرض 576-767 (تابلت صغير) */
@media (max-width: 576px) {
  .d-flex.justify-content-between { 
    flex-direction: column; 
    align-items: flex-start !important; 
    gap: 0.75rem;
  }
  .d-flex.justify-content-between .d-flex.gap-2 {
    width: 100%;
    flex-wrap: wrap;
  }
  .d-flex.justify-content-between .btn {
    flex: 1;
    min-width: 120px;
    text-align: center;
  }
  
  /* رسائل flash */
  .alert { font-size: 0.85rem; padding: 0.6rem 0.9rem; }
  
  /* بطاقات الإحصاء */
  .col-md-4 .card { margin-bottom: 0; }
}

/* ===== تحسين عام للقراءة ===== */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* تمييز صفوف الجداول عند اللمس */
@media (hover: none) {
  .table-hover > tbody > tr:active > * {
    background-color: var(--primary-light) !important;
  }
}

/* أزرار أكبر للمس */
@media (max-width: 767px) {
  .btn-sm { min-height: 34px; }
  .form-control, .form-select { font-size: 16px !important; } /* يمنع zoom في iOS */
}

/* ===== تحسين القائمة الجانبية على الهاتف ===== */
@media (max-width: 991px) {
  .sidebar {
    transition: transform 0.25s ease;
    z-index: 1050;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1045;
  }
  .sidebar-overlay.show { display: block; }
}

/* ===== تحسين بطاقات الطلاب على الهاتف ===== */
@media (max-width: 575px) {
  .student-card-actions { flex-direction: column; }
  .student-card-actions .btn { width: 100%; justify-content: center; }
  
  /* صفحة التقييم السريع */
  .sticky-top { position: static !important; }
  
  /* جدول التقييمات */
  .eval-row td:nth-child(2) { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ===== تحسين صفحة الاشتراكات على الهاتف ===== */
@media (max-width: 767px) {
  .subscriptions-table .col-notes { display: none; }
}

/* ===== تحسين صفحة ولي الأمر ===== */
@media (max-width: 575px) {
  .parent-dashboard-tabs .nav-link { 
    padding: 0.4rem 0.6rem;
    font-size: 0.78rem;
  }
  .parent-dashboard-tabs .nav-link i { margin-right: 0 !important; }
}

/* ===== بطاقات الإحصاءات على لوحة المعلم ===== */
.stat-card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.stat-card:active { transform: scale(0.98); }
.stat-card .stat-icon { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; }
@media (max-width: 575px) {
  .stat-card .stat-icon { width: 44px; height: 44px; padding: 0.5rem !important; }
  .stat-card .stat-icon i { font-size: 1.25rem !important; }
  .stat-card .fs-2 { font-size: 1.4rem !important; }
}

/* ===== تحسينات عامة للموبايل (safe-area + touch targets) ===== */
body { -webkit-tap-highlight-color: transparent; }
@supports (padding: max(0px)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 767px) {
  /* يمنع التكبير التلقائي عند الكتابة في iOS */
  input, select, textarea { font-size: 16px !important; }
  /* أزرار حجم 44px (Apple HIG / Google Material) */
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; }
  /* فاصل أكبر بين العناصر القابلة للنقر */
  .list-group-item { padding: 0.85rem 0.95rem; }
  /* جداول قابلة للتمرير الأفقي */
  .table { font-size: 0.875rem; }
  .table th, .table td { padding: 0.55rem 0.5rem; }
}

/* ===== إصلاحات الموبايل - Dashboard ===== */
@media (max-width: 767px) {
  /* الـ top-bar: فقط عنصران — العنوان وأيقونات مضغوطة */
  .top-bar {
    padding: 0 0.75rem;
    gap: 0.5rem;
  }
  .top-bar .top-actions {
    gap: 0.35rem;
  }
  /* أزرار أصغر على الموبايل */
  .top-bar .btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.82rem;
    line-height: 1;
  }
  .top-bar .btn i {
    font-size: 0.95rem;
  }
  /* عنوان الصفحة لا يطغى */
  .top-bar .page-title {
    font-size: 0.88rem;
    max-width: 45vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* بطاقات الداشبورد */
  .stat-card {
    padding: 0.9rem;
    border-radius: 14px;
  }
  .stat-card .stat-value {
    font-size: 1.6rem;
  }
  .stat-card .stat-label {
    font-size: 0.78rem;
  }
  .stat-card .stat-icon {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
  }

  /* التنبيهات العلوية */
  .alert-card, .alert-section {
    border-radius: 12px;
    padding: 0.85rem;
  }

  /* dropdown أكبر على موبايل */
  .dropdown-menu {
    font-size: 0.92rem;
  }
  .dropdown-item {
    padding: 0.65rem 1rem;
  }
}

/* شاشات صغيرة جداً */
@media (max-width: 380px) {
  .top-bar .page-title {
    font-size: 0.82rem;
    max-width: 38vw;
  }
  .top-bar .btn {
    padding: 0.35rem 0.45rem;
  }
}

/* ===== إصلاح جذري لطفح المحتوى على الموبايل ===== */

/* منع أي عنصر من الخروج خارج حدود الشاشة */
.content-area,
.content-area * {
  max-width: 100%;
  box-sizing: border-box;
}

/* Bootstrap containers */
.content-area .container,
.content-area .container-fluid,
.content-area .row {
  overflow-x: hidden;
}

@media (max-width: 991.98px) {
  /* إعادة ضبط الـ main-wrapper بشكل قاطع */
  html, body {
    overflow-x: hidden;
    width: 100%;
  }

  .main-wrapper {
    margin-right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }

  .content-area {
    width: 100%;
    overflow-x: hidden;
    padding: 0.75rem !important;
  }

  /* Row gutters أصغر على الموبايل */
  .row.g-4 { --bs-gutter-x: 0.75rem; --bs-gutter-y: 0.75rem; }
  .row.g-3 { --bs-gutter-x: 0.6rem;  --bs-gutter-y: 0.6rem;  }
}

/* الـ top-bar على الموبايل */
@media (max-width: 767px) {
  .top-bar {
    padding: 0 0.65rem !important;
    padding-top: env(safe-area-inset-top, 0px) !important;
    height: calc(54px + env(safe-area-inset-top, 0px)) !important;
  }

  /* عنوان الصفحة */
  .top-bar .page-title {
    font-size: 0.85rem !important;
    max-width: 42vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* الأزرار */
  .top-bar .top-actions {
    gap: 0.3rem !important;
    flex-shrink: 0;
  }
  .top-bar .btn {
    padding: 0.38rem 0.5rem !important;
    font-size: 0.8rem !important;
  }

  /* بطاقات الداشبورد */
  .stat-card {
    padding: 0.8rem;
  }
  .stat-card .stat-value {
    font-size: 1.5rem;
  }
}
