html {
  font-size: 14px;
  direction: rtl;
  text-align: right;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f8f9fa;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* Hero Section Styles */
.hero-section {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>') repeat;
  opacity: 0.1;
}

.hero-section > * {
  position: relative;
  z-index: 1;
}

/* Feature Cards */
.hover-card {
  transition: all 0.3s ease;
  border: none;
  border-radius: 15px;
}

.hover-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1) !important;
}

.feature-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

/* Stats Section */
.stats-card {
  padding: 2rem;
}

.stats-icon {
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

/* Gradient Backgrounds */
.bg-gradient-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
}

.bg-gradient-success {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%) !important;
}

.bg-gradient-info {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%) !important;
}

.bg-gradient-warning {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%) !important;
}

.bg-gradient-danger {
  background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%) !important;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-up {
  animation: fadeInUp 0.8s ease-out;
}

/* Custom Buttons */
.btn-custom {
  border-radius: 50px;
  padding: 12px 30px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.3s ease;
}

.btn-custom:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

/* RTL Support */
.navbar-nav {
  direction: rtl;
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.navbar-brand {
  margin-right: 0;
  margin-left: auto;
}

/* Card Enhancements */
.card {
  border: none;
  border-radius: 15px;
  overflow: hidden;
}

.card-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  font-weight: 600;
}

/* Form Enhancements */
.form-control, .form-select {
  border-radius: 10px;
  border: 2px solid #e9ecef;
  padding: 12px 15px;
  transition: all 0.3s ease;
}

.form-control:focus, .form-select:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Tables */
.table {
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.table thead th {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  font-weight: 600;
}

/* Responsive Design - Enhanced for all screen sizes */

/* Large screens (desktops, 1200px and up) */
@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }
  
  #sidebar {
    min-width: 280px;
    max-width: 280px;
  }
}

/* Medium screens (tablets, 768px to 1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
  #sidebar {
    min-width: 250px;
    max-width: 250px;
  }
  
  .hero-section h1 {
    font-size: 2.5rem;
  }
  
  .container {
    padding-left: 15px;
    padding-right: 15px;
  }
}

/* Small screens (phones, 576px to 767px) */
@media (max-width: 767px) {
  .hero-section {
    padding: 2rem 0 !important;
  }
  
  .hero-section h1 {
    font-size: 1.8rem !important;
  }
  
  .feature-icon {
    width: 50px;
    height: 50px;
    font-size: 1.3rem;
  }
  
  .stats-icon {
    width: 45px;
    height: 45px;
    font-size: 1.1rem;
  }
  
  /* Sidebar adjustments for small screens */
  #sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    height: 100vh;
    z-index: 10001;
    transition: all 0.3s ease;
    min-width: 270px;
    max-width: 270px;
    pointer-events: auto;
  }
  
  #sidebar.show {
    left: 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
  }
  
  /* Ensure sidebar content is interactive */
  #sidebar * {
    pointer-events: auto;
  }
  
  #sidebar .nav-link,
  #sidebar .dropdown-item,
  #sidebar button,
  #sidebar a {
    pointer-events: auto !important;
    cursor: pointer !important;
  }
  
  .page-content {
    margin-right: 0 !important;
    width: 100%;
    padding: 0 10px;
  }
  
  /* Mobile overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    pointer-events: auto;
    cursor: pointer;
  }
  
  .sidebar-overlay.show {
    display: block;
    pointer-events: auto;
  }
  
  /* Navigation adjustments */
  .navbar-brand {
    font-size: 1.1rem;
  }
  
  .navbar-brand .ess-logo {
    height: 30px !important;
  }
  
  /* Button improvements for touch */
  .btn {
    min-height: 44px;
    padding: 12px 16px;
  }
  
  /* Form improvements */
  .form-control, .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }
  
  /* Table responsiveness */
  .table-responsive {
    border: none;
  }
  
  .table {
    font-size: 0.9rem;
  }
  
  .table th, .table td {
    padding: 0.5rem;
  }
  
  /* Card adjustments */
  .card {
    margin-bottom: 1rem;
  }
  
  .card-body {
    padding: 1rem;
  }
}

/* Extra small screens (phones, less than 576px) */
@media (max-width: 575px) {
  .hero-section {
    padding: 1.5rem 0 !important;
  }
  
  .hero-section h1 {
    font-size: 1.5rem !important;
  }
  
  .container-fluid {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  .btn {
    font-size: 0.9rem;
  }
  
  .card-header {
    padding: 0.75rem;
    font-size: 0.95rem;
  }
  
  .table th, .table td {
    padding: 0.3rem;
    font-size: 0.8rem;
  }
  
  /* Stack columns on very small screens */
  .row.g-4 > [class*="col-"] {
    margin-bottom: 1rem;
  }
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Sidebar Styles */
.wrapper {
  display: flex;
  width: 100%;
  align-items: stretch;
}

#sidebar {
  min-width: 270px;
  max-width: 270px;
  min-height: 100vh;
  transition: all 0.3s;
  z-index: 999;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

#sidebar.active {
  min-width: 80px;
  max-width: 80px;
}

#sidebar.active .sidebar-header {
  padding: 10px;
}

#sidebar.active .sidebar-title {
  display: none;
}

#sidebar.active .sidebar-text {
  display: none;
}

#sidebar.active .section-title {
  display: none;
}

#sidebar.active .submenu {
  position: fixed;
  right: 70px; /* تقليل المسافة لتسهيل الانتقال */
  top: auto;
  width: 250px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  z-index: 9999;
  display: none !important;
  border: 1px solid rgba(0, 0, 0, 0.1);
  padding: 10px 0;
  max-height: 400px;
  overflow-y: auto;
  /* إضافة مساحة للماوس للتنقل */
  margin-right: -10px; /* تمديد المنطقة القابلة للنقر */
}

#sidebar.active .nav-item {
  position: relative;
}

/* تحسين التفاعل مع القوائم المنسدلة */
#sidebar.active .nav-item:has(.submenu) {
  /* إضافة مساحة إضافية للماوس */
  padding-left: 15px;
}

#sidebar.active .nav-item .submenu::before {
  content: '';
  position: absolute;
  top: 0;
  right: 100%;
  width: 20px; /* مساحة إضافية للماوس */
  height: 100%;
  background: transparent;
  z-index: 9998;
}

#sidebar.active .submenu.show {
  display: block !important;
  animation: fadeInSubmenu 0.2s ease-in-out;
}

@keyframes fadeInSubmenu {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#sidebar.active .submenu .dropdown-item {
  color: #333;
  font-size: 0.9rem;
  padding: 15px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  transition: all 0.2s ease;
  cursor: pointer;
  position: relative;
  z-index: 10000;
  white-space: nowrap;
}

#sidebar.active .submenu .dropdown-item:last-child {
  border-bottom: none;
}

#sidebar.active .submenu .dropdown-item:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: translateX(-3px);
}

#sidebar.active .submenu .dropdown-item:active {
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

/* ضمان عمل الروابط في جميع الحالات */
#sidebar .submenu a,
#sidebar .dropdown-item {
  pointer-events: auto !important;
  cursor: pointer !important;
  text-decoration: none;
  display: block;
  position: relative;
  z-index: 1001;
}

#sidebar .submenu a:hover,
#sidebar .dropdown-item:hover {
  text-decoration: none;
}

/* تأثير النقر على الروابط */
#sidebar.active .submenu .dropdown-item.clicked {
  background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
  transform: scale(0.98);
  transition: all 0.1s ease;
}

/* تحسين الانتقالات */
#sidebar.active .submenu {
  animation-duration: 0.25s;
  animation-fill-mode: both;
}

#sidebar.active .submenu.fadeIn {
  animation-name: slideInFromLeft;
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.sidebar-header {
  padding: 20px;
  background: rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
}

#sidebar .nav-item {
  padding: 0;
  margin: 0;
  width: 100%;
}

#sidebar .nav-link {
  padding: 15px 20px;
  color: white;
  font-weight: 500;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.3s ease;
}

/* مؤشر للعناصر التي تحتوي على قوائم فرعية */
#sidebar .nav-item:has(.submenu) > .nav-link {
  cursor: pointer;
}

#sidebar .nav-item:has(.submenu) > .nav-link:hover {
  background: rgba(255, 255, 255, 0.15);
}

#sidebar .nav-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* تحسين عرض الأيقونات في الوضع المطوي */
#sidebar.active .nav-link {
  text-align: center;
  padding: 15px 10px;
}

#sidebar.active .nav-link i {
  font-size: 1.2rem;
}

/* تحسين موضع القوائم المنسدلة */
#sidebar.active .nav-item .submenu {
  min-height: fit-content;
  max-height: 400px;
  overflow-y: auto;
}

/* إضافة مؤشر للعناصر التي لها قوائم فرعية */
#sidebar.active .dropdown-toggle::after {
  display: none;
}

#sidebar.active .dropdown-toggle {
  position: relative;
}

#sidebar.active .dropdown-toggle::before {
  content: '▶';
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  opacity: 0.7;
  transition: transform 0.2s ease;
}

/* تدوير السهم عندما تكون القائمة مفتوحة */
#sidebar.active .nav-item:has(.submenu.show) > .dropdown-toggle::before {
  transform: translateY(-50%) rotate(90deg);
}

/* تحسين مظهر العناصر النشطة */
#sidebar .nav-item:has(.submenu.show) > .nav-link {
  background: rgba(255, 255, 255, 0.1);
  border-left: 3px solid rgba(255, 255, 255, 0.6);
}

#sidebar .section-title {
  padding: 15px 10px 5px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

#sidebar:not(.active) .submenu {
  background: white;
  border-radius: 0;
  border: none;
  box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
}

#sidebar:not(.active) .submenu .dropdown-item {
  padding: 10px 25px 10px 15px;
  transition: all 0.3s ease;
}

#sidebar:not(.active) .submenu .dropdown-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.page-content {
  width: 100%;
  transition: all 0.3s;
}

.page-content.active {
  margin-right: 80px;
}

#sidebarCollapse {
  background: transparent;
  border: none;
  box-shadow: none;
}

#sidebarCollapse:hover {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 768px) {
  #sidebar {
    min-width: 80px;
    max-width: 80px;
  }
  
  #sidebar .sidebar-title,
  #sidebar .sidebar-text,
  #sidebar .section-title {
    display: none;
  }
  
  .page-content {
    margin-right: 80px;
  }
}

/* Enhanced Button and Icon Styles for Touch */
.btn {
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: -1;
}

.btn:hover::before {
  transform: translateX(0);
}

/* Touch-friendly button sizing */
.btn-sm {
  min-height: 38px;
  padding: 0.5rem 1rem;
}

.btn {
  min-height: 42px;
  padding: 0.75rem 1.5rem;
}

.btn-lg {
  min-height: 50px;
  padding: 1rem 2rem;
}

/* Icon improvements */
.fas, .far, .fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn .fas, .btn .far, .btn .fab {
  margin-left: 0.5rem;
  font-size: 1.1em;
}

/* Navigation icons */
.nav-link i {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.5rem;
}

/* Custom Tooltips for Collapsed Sidebar */
.custom-tooltip {
  position: fixed;
  background: #2c3e50;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  display: none;
  font-family: 'Cairo', sans-serif;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.custom-tooltip::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: #2c3e50;
}

/* تحسين مظهر tooltips في الوضع المطوي */
#sidebar.active .nav-link:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateX(-2px);
  transition: all 0.2s ease;
}

/* تحسين مظهر الأيقونات في الوضع المطوي */
#sidebar.active .nav-link i {
  font-size: 1.3rem;
  transition: all 0.2s ease;
}

#sidebar.active .nav-link:hover i {
  transform: scale(1.1);
}

/* Enhanced media queries for comprehensive responsive design */

/* Very large screens (1400px and up) */
@media (min-width: 1400px) {
  .container {
    max-width: 1320px;
  }
  
  .hero-section h1 {
    font-size: 3.5rem;
  }
  
  .feature-icon {
    width: 90px;
    height: 90px;
    font-size: 2.2rem;
  }
  
  .stats-icon {
    width: 80px;
    height: 80px;
    font-size: 2rem;
  }
}

/* Large tablets and small desktops (992px to 1199px) */
@media (min-width: 992px) and (max-width: 1199px) {
  .hero-section h1 {
    font-size: 3rem;
  }
  
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }
  
  .card {
    margin-bottom: 1.5rem;
  }
}

/* Portrait tablets (768px to 991px) */
@media (min-width: 768px) and (max-width: 991px) {
  .row.g-4 {
    gap: 1.5rem !important;
  }
  
  .card-body {
    padding: 1.25rem;
  }
  
  .btn {
    padding: 0.65rem 1.25rem;
  }
  
  /* Stack some elements earlier */
  .d-md-flex {
    flex-direction: column;
  }
  
  .d-md-flex > * {
    margin-bottom: 1rem;
  }
}

/* Large phones (576px to 767px) */
@media (min-width: 576px) and (max-width: 767px) {
  .container {
    max-width: 540px;
    padding-left: 15px;
    padding-right: 15px;
  }
  
  .row {
    margin-left: -10px;
    margin-right: -10px;
  }
  
  .row > * {
    padding-left: 10px;
    padding-right: 10px;
  }
  
  .btn-group {
    flex-direction: column;
  }
  
  .btn-group .btn {
    margin-bottom: 0.5rem;
  }
}

/* Landscape orientation specific rules */
@media (orientation: landscape) and (max-height: 600px) {
  .hero-section {
    padding: 1rem 0 !important;
  }
  
  .navbar {
    padding: 0.25rem 0.5rem;
  }
  
  #sidebar {
    height: 100vh;
    overflow-y: auto;
  }
  
  .modal-dialog {
    margin: 1rem auto;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .ess-logo, .school-logo {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Print styles */
@media print {
  #sidebar,
  .navbar,
  .footer,
  .btn,
  .sidebar-overlay {
    display: none !important;
  }
  
  .page-content {
    margin: 0 !important;
    width: 100% !important;
  }
  
  .container,
  .container-fluid {
    padding: 0;
    margin: 0;
    max-width: none;
  }
  
  .card {
    border: 1px solid #000;
    break-inside: avoid;
  }
  
  .table {
    font-size: 0.8rem;
  }
  
  .table th,
  .table td {
    padding: 0.25rem;
  }
}

/* Focus improvements for accessibility */
.btn:focus,
.form-control:focus,
.form-select:focus,
.nav-link:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }
  
  .card {
    border-width: 2px;
  }
  
  .table {
    border-collapse: separate;
    border-spacing: 1px;
  }
  
  .table th,
  .table td {
    border: 1px solid;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .hover-card:hover {
    transform: none;
  }
  
  .btn::before {
    display: none;
  }
}

/* Dark mode preparation (for future implementation) */
@media (prefers-color-scheme: dark) {
  /* This will be activated if dark mode is implemented */
  .card {
    background-color: var(--bs-dark, #212529);
    color: var(--bs-light, #f8f9fa);
  }
  
  .table {
    --bs-table-bg: var(--bs-dark, #212529);
    --bs-table-color: var(--bs-light, #f8f9fa);
  }
}