:root {
  /* === Color Palette - Light Mode === */
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #8b5cf6;
  --accent: #ec4899;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --gradient-danger: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
  --gradient-info: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  --gradient-warning: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);

  /* Background Colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-overlay: rgba(0, 0, 0, 0.5);

  /* Text Colors */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-tertiary: #94a3b8;
  --text-inverse: #ffffff;

  /* Border Colors */
  --border-color: #e2e8f0;
  --border-color-hover: #cbd5e1;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

  /* Glass Effect */
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.18);

  /* Spacing */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-arabic: 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Layout */
  --sidebar-width: 280px;
  --header-height: 70px;
  --mobile-breakpoint: 768px;
}

/* Dark Mode Variables */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-dark: #6366f1;
  --primary-light: #a5b4fc;
  --secondary: #a78bfa;
  --accent: #f472b6;

  /* Background Colors - Rich Dark Theme */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-overlay: rgba(0, 0, 0, 0.7);

  /* Text Colors */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --text-inverse: #0f172a;

  /* Border Colors */
  --border-color: #334155;
  --border-color-hover: #475569;

  /* Glass Effect - Dark */
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(148, 163, 184, 0.18);

  /* Shadows - Enhanced for Dark Mode */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

/* === Base Styles === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color var(--transition-base), color var(--transition-base);
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

/* Arabic Font Support */
body[lang="ar"] {
  font-family: var(--font-arabic);
  direction: rtl;
}

/* === Typography === */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: var(--spacing-md);
  color: var(--text-primary);
}

h1 {
  font-size: var(--text-4xl);
}

h2 {
  font-size: var(--text-3xl);
}

h3 {
  font-size: var(--text-2xl);
}

h4 {
  font-size: var(--text-xl);
}

h5 {
  font-size: var(--text-lg);
}

h6 {
  font-size: var(--text-base);
}

p {
  margin-bottom: var(--spacing-md);
  color: var(--text-secondary);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-dark);
}

/* === Layout === */
.app-container {
  display: flex;
  min-height: 100vh;
  background: var(--bg-primary);
}

.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: all var(--transition-base);
  position: relative;
}

body[lang="ar"] .main-content {
  margin-left: 0;
  margin-right: var(--sidebar-width);
}

.content-wrapper {
  padding: var(--spacing-xl);
  margin-top: var(--header-height);
  max-width: 1600px;
  margin-left: auto;
  margin-right: auto;
}

/* === Utility Classes === */
.container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--spacing-lg);
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.justify-center {
  justify-content: center;
}

.gap-sm {
  gap: var(--spacing-sm);
}

.gap-md {
  gap: var(--spacing-md);
}

.gap-lg {
  gap: var(--spacing-lg);
}

.mt-sm {
  margin-top: var(--spacing-sm);
}

.mt-md {
  margin-top: var(--spacing-md);
}

.mt-lg {
  margin-top: var(--spacing-lg);
}

.mt-xl {
  margin-top: var(--spacing-xl);
}

.mb-sm {
  margin-bottom: var(--spacing-sm);
}

.mb-md {
  margin-bottom: var(--spacing-md);
}

.mb-lg {
  margin-bottom: var(--spacing-lg);
}

.mb-xl {
  margin-bottom: var(--spacing-xl);
}

.text-center {
  text-align: center;
}

.text-sm {
  font-size: var(--text-sm);
}

.text-lg {
  font-size: var(--text-lg);
}

.text-xl {
  font-size: var(--text-xl);
}

.text-secondary {
  color: var(--text-secondary);
}

.text-tertiary {
  color: var(--text-tertiary);
}

.hidden {
  display: none;
}

/* === Grid System === */
.grid {
  display: grid;
  gap: var(--spacing-lg);
}

.grid-cols-1 {
  grid-template-columns: repeat(1, 1fr);
}

.grid-cols-2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* === Animations === */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.animate-fadeIn {
  animation: fadeIn var(--transition-base) ease-out;
}

.animate-slideInRight {
  animation: slideInRight var(--transition-base) ease-out;
}

.animate-slideInLeft {
  animation: slideInLeft var(--transition-base) ease-out;
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

/* === Responsive === */
@media (max-width: 1024px) {
  .grid-cols-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {

  /* Header Overhaul */
  .header {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--header-height) !important;
    padding: 0 var(--spacing-sm) !important;
    justify-content: space-between !important;
    gap: var(--spacing-xs) !important;
    background: var(--bg-card) !important;
    backdrop-filter: none !important;
  }

  .header-left {
    gap: var(--spacing-xs) !important;
    flex: 0 0 auto !important;
  }

  .header-right {
    gap: var(--spacing-xs) !important;
    flex: 1;
    justify-content: flex-end !important;
  }

  /* Hide unnecessary elements on mobile */
  .header-search,
  .header-user,
  .header-left>div[style*="display: flex"] {
    display: none !important;
  }

  /* Align action buttons */
  .header-actions {
    gap: var(--spacing-xs) !important;
  }

  .theme-toggle,
  .notification-btn {
    width: 36px !important;
    height: 36px !important;
  }

  .lang-toggle {
    padding: var(--spacing-xs) var(--spacing-sm) !important;
    font-size: 11px !important;
    height: 36px !important;
  }

  /* Burger Menu Button */
  .mobile-menu-btn {
    display: flex !important;
    width: 40px !important;
    height: 40px !important;
    font-size: 1.25rem !important;
    z-index: 10000 !important;
  }

  /* Sidebar Drawer Mode - Comprehensive Fixed Position */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    right: auto !important;
    width: 280px !important;
    max-width: 85vw !important;
    height: 100vh !important;
    z-index: 11000 !important;
    transform: translateX(-110%) !important;
    visibility: visible !important;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    background: var(--bg-card) !important;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.2) !important;
    border: none !important;
    margin: 0 !important;
    padding: var(--spacing-xl) 0 !important;
  }

  body[lang="ar"] .sidebar {
    left: auto !important;
    right: 0 !important;
    transform: translateX(110%) !important;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.2) !important;
  }

  /* Show state MUST anchor to the screen edges */
  .sidebar.show {
    transform: translateX(0) !important;
  }

  body[lang="ar"] .sidebar.show {
    transform: translateX(0) !important;
  }

  /* Content & Layout */
  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    display: block !important;
    /* Ensure it's not flex in mobile to prevent shifting */
  }

  .app-container {
    overflow-x: hidden !important;
    display: block !important;
    /* Stack sidebar and content */
  }

  .content-wrapper {
    padding: var(--spacing-md) !important;
    margin-top: var(--header-height) !important;
  }

  /* Cards & Grid */
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .grid-cols-5 {
    grid-template-columns: 1fr !important;
    gap: var(--spacing-md) !important;
  }

  .stat-card {
    padding: var(--spacing-md) !important;
  }

  .stat-icon {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.25rem !important;
  }

  .stat-value {
    font-size: var(--text-2xl) !important;
  }

  /* Tables */
  .table-container {
    margin: 0 -var(--spacing-md) !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
  }

  .table-wrapper {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  table {
    min-width: 600px !important;
    /* Force scroll for better layout */
  }

  /* Modal */
  .modal {
    max-width: 95% !important;
    margin: 0 auto !important;
    border-radius: var(--radius-xl) !important;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--spacing-md) !important;
  }

  /* Typography */
  h1 {
    font-size: 1.5rem !important;
  }

  h2 {
    font-size: 1.25rem !important;
  }

  h3 {
    font-size: 1.1rem !important;
  }
}

/* === Scrollbar Styling === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* === Loading State === */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--primary);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Notification System */
.header-notification {
  position: relative;
  margin-right: var(--spacing-md);
}

.notification-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--spacing-xs);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.notification-btn:hover {
  background: var(--bg-secondary);
  color: var(--primary);
}

.notification-btn i,
.theme-toggle i,
.lang-toggle i {
  pointer-events: none;
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-primary);
}

.notification-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 350px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: 1000;
  display: none;
  flex-direction: column;
  overflow: visible;
  /* Changed from hidden to allow shadow/badges */
  animation: fadeInDown 0.2s ease-out;
}

body[lang="ar"] .notification-dropdown {
  right: auto;
  left: 0;
}

.notification-dropdown.show {
  display: flex;
}

.notification-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
}

.notification-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.mark-all-btn {
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
}

.mark-all-btn:hover {
  text-decoration: underline;
}

.notification-list {
  max-height: 400px;
  overflow-y: auto;
}

.notification-item {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: var(--spacing-md);
  text-decoration: none;
  color: inherit;
  transition: background 0.2s ease;
  cursor: pointer;
  align-items: flex-start;
}

.notification-item:hover {
  background: var(--bg-secondary);
}

.notification-item.unread {
  background: rgba(99, 102, 241, 0.05);
}

.notification-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notification-icon-wrap i {
  font-size: 1rem;
  color: var(--text-secondary);
}

.notification-item.unread .notification-icon-wrap {
  background: var(--primary);
}

.notification-item.unread .notification-icon-wrap i {
  color: white;
}

.notification-content {
  flex: 1;
}

.notification-message {
  font-size: 0.85rem;
  line-height: 1.4;
  margin-bottom: 4px;
  word-break: break-word;
  overflow-wrap: break-word;
  /* Ensure long words don't clip */
}

.notification-time {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.no-notifications {
  padding: var(--spacing-xl);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.9rem;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}