/* Novira Design System - v2.0 */
/* Design principles: Calm intelligence, Glanceable data, Predictable actions, Arabic-first, Performance-focused */

/* ========================================
   CSS Variables & Design Tokens
   ======================================== */
:root {
  /* Brand Colors - Novira Gradient */
  --gradient-start: #00D4FF; /* Cyan */
  --gradient-mid1: #4B7BFF; /* Blue */
  --gradient-mid2: #9F40FF; /* Purple */
  --gradient-end: #FF40FF; /* Pink */
  --brand-500: #9F40FF; /* Primary purple */
  --brand-600: #7B30CC;
  --brand-100: #F5F0FF;
  --brand-200: #E6D9FF;
  
  /* Ink (Text) Colors */
  --ink-900: #0B1220;
  --ink-700: #334155;
  --ink-500: #64748B;
  --ink-300: #CBD5E1;
  
  /* Surface Colors */
  --surface-0: #FFFFFF;
  --surface-1: #F8FAFC;
  --surface-2: #EEF2F7;
  
  /* Borders */
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  
  /* Status Colors */
  --success: #16A34A;
  --success-light: #DCFCE7;
  --info: #0EA5E9;
  --info-light: #E0F2FE;
  --warn: #F59E0B;
  --warn-light: #FEF3C7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  
  /* Chart Palette (calm hues, 20-60% saturation) */
  --chart-1: #6B7ADB; /* Muted purple */
  --chart-2: #4ECDC4; /* Calm teal */
  --chart-3: #FFB677; /* Soft orange */
  --chart-4: #95A99C; /* Sage green */
  --chart-5: #FF8FA3; /* Dusty rose */
  
  /* Border Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-card: 20px;
  --radius-modal: 24px;
  
  /* Shadows (subtle) */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.08);
  
  /* Typography Scale (rem) */
  --text-xs: 0.75rem;   /* 12px */
  --text-sm: 0.875rem;  /* 14px */
  --text-base: 1rem;    /* 16px */
  --text-lg: 1.125rem;  /* 18px */
  --text-xl: 1.25rem;   /* 20px */
  --text-2xl: 1.5rem;   /* 24px */
  --text-3xl: 1.875rem; /* 30px */
  --text-4xl: 2.25rem;  /* 36px */
  
  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  
  /* Spacing */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.25rem;  /* 20px */
  --space-6: 1.5rem;   /* 24px */
  --space-8: 2rem;     /* 32px */
  --space-10: 2.5rem;  /* 40px */
  --space-12: 3rem;    /* 48px */
  
  /* Z-index layers */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;
}

/* ========================================
   Typography
   ======================================== */
   
/* Import Inter for Latin text */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Import Cairo for Arabic text */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap');

/* Base typography */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: var(--text-base);
  font-weight: var(--font-normal);
  line-height: 1.6;
  color: var(--ink-900);
  background: linear-gradient(135deg, #00D4FF 0%, #4B7BFF 30%, #9F40FF 60%, #FF40FF 100%);
  background-attachment: fixed;
  background-size: 200% 200%;
  animation: gradientShift 15s ease infinite;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Arabic typography */
[dir="rtl"],
.arabic {
  font-family: 'Cairo', 'Inter', -apple-system, system-ui, sans-serif;
  letter-spacing: normal !important; /* Critical for Arabic readability */
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  line-height: 1.3;
  color: var(--ink-900);
  margin-bottom: var(--space-3);
}

h1 { font-size: var(--text-4xl); font-weight: var(--font-bold); }
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); }

/* Paragraph and body text */
p {
  margin-bottom: var(--space-4);
  color: var(--ink-700);
}

.text-muted {
  color: var(--ink-500) !important;
}

/* ========================================
   Layout & Containers
   ======================================== */

.container-fluid {
  max-width: 1440px;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

@media (min-width: 768px) {
  .container-fluid {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }
}

/* ========================================
   Cards & Surfaces
   ======================================== */

.card {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  overflow: hidden;
}

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

.card-header {
  background: var(--surface-0);
  border-bottom: 1px solid var(--border-light);
  padding: var(--space-5) var(--space-6);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  background: var(--surface-1);
  border-top: 1px solid var(--border-light);
  padding: var(--space-4) var(--space-6);
}

/* KPI Cards */
.kpi-card {
  background: var(--surface-0);
  border-radius: var(--radius-card);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
  border: 1px solid var(--border-light);
}

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

.kpi-value {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  color: var(--ink-900);
  margin-bottom: var(--space-2);
}

.kpi-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--ink-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-change {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  margin-top: var(--space-3);
}

.kpi-change.positive {
  color: var(--success);
}

.kpi-change.negative {
  color: var(--danger);
}

/* ========================================
   Navigation & Header
   ======================================== */

.navbar {
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3) 0;
}

.navbar-brand {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--brand-500) !important;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.navbar-brand i {
  color: var(--brand-500);
  margin-right: var(--space-2);
}

.nav-link {
  color: var(--ink-700) !important;
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-4) !important;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.nav-link:hover {
  background: var(--surface-1);
  color: var(--brand-500) !important;
}

.nav-link.active {
  background: var(--brand-100);
  color: var(--brand-600) !important;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
  font-weight: var(--font-medium);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  border: none;
  font-size: var(--text-base);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-mid1) 30%, var(--gradient-mid2) 60%, var(--gradient-end) 100%);
  color: white;
  border: none;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.btn-primary::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(255,64,255,0.2) 0%, rgba(159,64,255,0.2) 30%, rgba(75,123,255,0.2) 60%, rgba(0,212,255,0.2) 100%);
  z-index: -1;
  transition: opacity 0.3s ease;
  opacity: 0;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 30px rgba(159, 64, 255, 0.3);
}

.btn-primary:hover::after {
  opacity: 1;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--ink-700);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--ink-900);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-outline-primary {
  background: transparent;
  color: var(--brand-500);
  border: 1px solid var(--brand-500);
}

.btn-outline-primary:hover {
  background: var(--brand-500);
  color: white;
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-lg);
}

/* Button positioning (predictable actions) */
.modal-footer,
.drawer-footer,
.form-footer {
  display: flex;
  justify-content: space-between;
  padding: var(--space-4);
  border-top: 1px solid var(--border);
}

.modal-footer .btn-primary,
.drawer-footer .btn-primary,
.form-footer .btn-primary {
  order: 2; /* Primary action at right */
  margin-left: auto;
}

.modal-footer .btn-danger,
.drawer-footer .btn-danger,
.form-footer .btn-danger {
  order: 1; /* Destructive action at left */
}

/* RTL adjustments */
[dir="rtl"] .modal-footer .btn-primary,
[dir="rtl"] .drawer-footer .btn-primary,
[dir="rtl"] .form-footer .btn-primary {
  margin-left: 0;
  margin-right: auto;
}

/* ========================================
   Forms
   ======================================== */

.form-control,
.form-select {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-base);
  color: var(--ink-900);
  transition: all var(--transition-fast);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--gradient-mid2);
  box-shadow: 0 0 0 3px rgba(159, 64, 255, 0.15);
  outline: none;
}

.form-label {
  font-weight: var(--font-medium);
  color: var(--ink-700);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.form-text {
  color: var(--ink-500);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* ========================================
   Badges & Status Indicators
   ======================================== */

.badge {
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-info {
  background: var(--info-light);
  color: var(--info);
}

.badge-warning {
  background: var(--warn-light);
  color: var(--warn);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* ========================================
   Progress Bars
   ======================================== */

.progress {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  height: 8px;
  overflow: hidden;
}

.progress-bar {
  background: linear-gradient(90deg, var(--gradient-start), var(--gradient-mid1), var(--gradient-mid2), var(--gradient-end));
  transition: width var(--transition-slow);
  background-size: 200% 100%;
  animation: gradientSlide 3s ease infinite;
}

@keyframes gradientSlide {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ========================================
   Modals
   ======================================== */

.modal-content {
  border-radius: var(--radius-modal);
  border: none;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
  padding: var(--space-5) var(--space-6);
}

.modal-body {
  padding: var(--space-6);
}

.modal-title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--ink-900);
}

/* ========================================
   Tables
   ======================================== */

.table {
  background: var(--surface-0);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.table thead th {
  background: var(--surface-1);
  border-bottom: 2px solid var(--border);
  color: var(--ink-700);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-3) var(--space-4);
}

.table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-light);
  color: var(--ink-700);
}

.table tbody tr:hover {
  background: var(--surface-1);
}

/* ========================================
   Alerts
   ======================================== */

.alert {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  border: none;
  font-weight: var(--font-medium);
}

.alert-success {
  background: var(--success-light);
  color: var(--success);
}

.alert-info {
  background: var(--info-light);
  color: var(--info);
}

.alert-warning {
  background: var(--warn-light);
  color: var(--warn);
}

.alert-danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* ========================================
   Charts & Data Visualization
   ======================================== */

.chart-container {
  background: var(--surface-0);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.chart-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--ink-900);
  margin-bottom: var(--space-4);
}

/* ========================================
   Dropdown Menus
   ======================================== */

.dropdown-menu {
  background: var(--surface-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-2);
  min-width: 200px;
  z-index: 1050 !important;
  position: absolute !important;
}

/* Ensure all Bootstrap dropdowns have high z-index */
.dropdown-menu,
.dropdown-menu.show {
  z-index: 1060 !important;
}

/* Navigation dropdowns specifically */
.navbar .dropdown-menu,
.topbar .dropdown-menu {
  z-index: 1070 !important;
}

.dropdown-item {
  color: var(--ink-700);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: var(--font-medium);
  transition: all var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--surface-1);
  color: var(--brand-500);
}

.dropdown-divider {
  border-color: var(--border);
  margin: var(--space-2) 0;
}

/* ========================================
   Loading States
   ======================================== */

.spinner-border {
  color: var(--brand-500);
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-1) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ========================================
   Tooltips
   ======================================== */

.tooltip {
  background: var(--ink-900);
  color: white;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  box-shadow: var(--shadow-md);
}

/* ========================================
   Platform-specific styles
   ======================================== */

.platform-card {
  background: var(--surface-0);
  border: 2px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--space-5);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.platform-card:hover {
  border-color: var(--brand-500);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.platform-card.selected {
  background: var(--brand-100);
  border-color: var(--brand-500);
}

/* ========================================
   RTL Support
   ======================================== */

[dir="rtl"] {
  text-align: right;
  direction: rtl;
}

[dir="rtl"] .text-start {
  text-align: right !important;
}

[dir="rtl"] .text-end {
  text-align: left !important;
}

[dir="rtl"] .ms-auto {
  margin-left: 0 !important;
  margin-right: auto !important;
}

[dir="rtl"] .me-auto {
  margin-right: 0 !important;
  margin-left: auto !important;
}

[dir="rtl"] .navbar-brand i {
  margin-right: 0;
  margin-left: var(--space-2);
}

/* ========================================
   Utility Classes
   ======================================== */

.text-brand { color: var(--brand-500) !important; }
.bg-brand { background-color: var(--brand-500) !important; }
.border-brand { border-color: var(--brand-500) !important; }

.text-ink-900 { color: var(--ink-900) !important; }
.text-ink-700 { color: var(--ink-700) !important; }
.text-ink-500 { color: var(--ink-500) !important; }

.bg-surface-0 { background-color: var(--surface-0) !important; }
.bg-surface-1 { background-color: var(--surface-1) !important; }
.bg-surface-2 { background-color: var(--surface-2) !important; }

.shadow-sm { box-shadow: var(--shadow-sm) !important; }
.shadow-md { box-shadow: var(--shadow-md) !important; }
.shadow-lg { box-shadow: var(--shadow-lg) !important; }

.rounded-sm { border-radius: var(--radius-sm) !important; }
.rounded-md { border-radius: var(--radius-md) !important; }
.rounded-lg { border-radius: var(--radius-lg) !important; }
.rounded-card { border-radius: var(--radius-card) !important; }
.rounded-modal { border-radius: var(--radius-modal) !important; }

/* ========================================
   Performance Optimizations
   ======================================== */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Fast first paint optimizations */
.lazy-load {
  content-visibility: auto;
}

/* ========================================
   Dark Mode Support (Future)
   ======================================== */

@media (prefers-color-scheme: dark) {
  /* Reserved for future dark mode implementation */
}