/* ==========================================================================
   JLEARN MODERN DESIGN ENHANCEMENTS
   Smooth animations, modern layout, responsive improvements, loading states
   Load after styles.css to enhance and override
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. MODERN DESIGN TOKENS (CSS Variables)
   -------------------------------------------------------------------------- */
:root {
  /* Smooth easing curves */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);

  /* Animation durations */
  --duration-fast: 0.15s;
  --duration-normal: 0.3s;
  --duration-slow: 0.5s;
  --duration-page: 0.6s;

  /* Modern shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 0 3px rgba(79, 70, 229, 0.15);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.5);
  --glass-blur: 16px;

  /* Border radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Typography */
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

  /* Z-index scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  --z-toast: 1080;
  --z-loader: 1090;
}

[data-theme="dark"] {
  --glass-bg: rgba(15, 23, 42, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
}

/* --------------------------------------------------------------------------
   2. GLOBAL BASE STYLES
   -------------------------------------------------------------------------- */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
  /* Prevent layout shifts */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Smooth scrolling for anchor links without jumping */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------------
   3. MODERN SCROLLBAR
   -------------------------------------------------------------------------- */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-color);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-color);
  transition: background var(--duration-fast) var(--ease-smooth);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) var(--bg-color);
}

/* --------------------------------------------------------------------------
   4. SMOOTH PAGE TRANSITIONS
   -------------------------------------------------------------------------- */
.page {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--duration-slow) var(--ease-out),
              transform var(--duration-slow) var(--ease-out);
}

.page.active {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered children animation for active pages */
.page.active > * {
  animation: fadeInUp 0.5s var(--ease-out) both;
}

.page.active > *:nth-child(1) { animation-delay: 0.05s; }
.page.active > *:nth-child(2) { animation-delay: 0.1s; }
.page.active > *:nth-child(3) { animation-delay: 0.15s; }
.page.active > *:nth-child(4) { animation-delay: 0.2s; }
.page.active > *:nth-child(5) { animation-delay: 0.25s; }
.page.active > *:nth-child(6) { animation-delay: 0.3s; }

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

/* --------------------------------------------------------------------------
   5. GLOBAL LOADING STATES
   -------------------------------------------------------------------------- */
#global-loader,
.global-loader {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: var(--z-loader);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-slow) var(--ease-smooth),
              visibility var(--duration-slow) var(--ease-smooth);
}

#global-loader.active,
.global-loader.active {
  opacity: 1;
  visibility: visible;
}

.loader-spinner {
  width: 56px;
  height: 56px;
  border: 4px solid transparent;
  border-top-color: var(--primary-color);
  border-right-color: var(--secondary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loader-text {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* --------------------------------------------------------------------------
   6. SKELETON LOADING SCREENS
   -------------------------------------------------------------------------- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-color) 25%,
    var(--hover-bg) 50%,
    var(--bg-color) 75%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  animation: skeleton-loading 1.5s ease-in-out infinite;
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}

.skeleton * {
  visibility: hidden;
}

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

/* --------------------------------------------------------------------------
   7. MODERN CARDS & SURFACES
   -------------------------------------------------------------------------- */
.card,
.feature-card,
.login-card,
.lesson-card,
.stat-card,
.results-card,
.completion-card,
.video-card,
.video-info-card,
.material-card,
.instruction-item,
.question-card,
.answer-option {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-normal) var(--ease-spring),
              box-shadow var(--duration-normal) var(--ease-spring),
              border-color var(--duration-fast) var(--ease-smooth);
  will-change: transform, box-shadow;
}

.card:hover,
.feature-card:hover,
.lesson-card:hover,
.stat-card:hover,
.material-card:hover,
.question-card:hover,
.answer-option:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

/* --------------------------------------------------------------------------
   8. MODERN BUTTONS
   -------------------------------------------------------------------------- */
.btn,
button,
[role="button"] {
  border-radius: var(--radius-md);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform var(--duration-fast) var(--ease-spring),
              background-color var(--duration-fast) var(--ease-smooth),
              box-shadow var(--duration-fast) var(--ease-smooth),
              color var(--duration-fast) var(--ease-smooth);
  will-change: transform, box-shadow;
}

.btn:hover,
button:hover,
[role="button"]:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active,
button:active,
[role="button"]:active {
  transform: translateY(0) scale(0.98);
}

.btn:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
  border-color: var(--primary-color);
}

/* Ripple effect */
.btn {
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.35) 0%, transparent 70%);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity var(--duration-fast) var(--ease-smooth),
              transform var(--duration-fast) var(--ease-smooth);
}

.btn:active::after {
  opacity: 1;
  transform: scale(2);
  transition: opacity 0s, transform 0s;
}

/* --------------------------------------------------------------------------
   9. MODERN FORMS
   -------------------------------------------------------------------------- */
input,
textarea,
select,
.form-control {
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  padding: 0.875rem 1rem;
  font-size: 1rem;
  transition: border-color var(--duration-fast) var(--ease-smooth),
              box-shadow var(--duration-fast) var(--ease-smooth),
              background-color var(--duration-fast) var(--ease-smooth);
}

input:hover,
textarea:hover,
select:hover,
.form-control:hover {
  border-color: var(--text-muted);
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
  outline: none;
}

/* Floating labels support */
.form-group {
  position: relative;
}

.form-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* --------------------------------------------------------------------------
   10. MODERN NAVBAR
   -------------------------------------------------------------------------- */
.navbar {
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  background: var(--glass-bg);
  border-bottom: 1px solid var(--glass-border);
  transition: background var(--duration-normal) var(--ease-smooth),
              box-shadow var(--duration-normal) var(--ease-smooth);
}

.navbar.scrolled {
  box-shadow: var(--shadow-md);
}

.nav-brand {
  font-weight: 800;
  letter-spacing: -0.02em;
  transition: transform var(--duration-fast) var(--ease-spring);
}

.nav-brand:hover {
  transform: scale(1.02);
}

/* --------------------------------------------------------------------------
   11. MODERN HERO SECTION
   -------------------------------------------------------------------------- */
.hero {
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 40%),
              radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 40%);
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 1;
}

.hero h1 {
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.hero p {
  font-size: 1.25rem;
  opacity: 0.92;
}

/* --------------------------------------------------------------------------
   12. MODERN TABLES
   -------------------------------------------------------------------------- */
table {
  border-collapse: separate;
  border-spacing: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

thead {
  background: var(--hover-bg);
}

th {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 1rem;
}

td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--duration-fast) var(--ease-smooth);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: var(--hover-bg);
}

/* --------------------------------------------------------------------------
   13. MODERN MODALS
   -------------------------------------------------------------------------- */
.modal {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background-color: rgba(0, 0, 0, 0.5);
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

.modal-content {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  transform: scale(0.96) translateY(10px);
  transition: transform var(--duration-normal) var(--ease-spring),
              opacity var(--duration-normal) var(--ease-smooth);
}

.modal.active .modal-content {
  transform: scale(1) translateY(0);
}

/* --------------------------------------------------------------------------
   14. MODERN TOASTS & NOTIFICATIONS
   -------------------------------------------------------------------------- */
.toast,
.notification {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.4s var(--ease-out) both;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

/* --------------------------------------------------------------------------
   15. ASSESSMENT MODERNIZATION
   -------------------------------------------------------------------------- */
.assessment-section {
  background: var(--surface-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
}

.question-card {
  background: var(--bg-color);
  border: 2px solid var(--border-color);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.answer-option {
  background: var(--surface-color);
  border: 2px solid var(--border-color);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.answer-option:hover {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

.answer-option.selected {
  border-color: var(--primary-color);
  background: var(--primary-light);
  box-shadow: var(--shadow-glow);
}

/* --------------------------------------------------------------------------
   16. PROGRESS BARS & TIMERS
   -------------------------------------------------------------------------- */
.progress-bar,
.quiz-timer {
  border-radius: var(--radius-full);
  overflow: hidden;
  transition: width var(--duration-slow) var(--ease-smooth);
}

.progress-fill {
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-smooth);
}

/* --------------------------------------------------------------------------
   17. RESPONSIVE IMPROVEMENTS
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .container {
    padding: 0 1rem;
  }

  .hero {
    padding: 3rem 0;
  }

  .hero h1 {
    font-size: 2.5rem;
  }
}

@media (max-width: 768px) {
  :root {
    --radius-lg: 14px;
    --radius-xl: 18px;
  }

  .hero {
    padding: 2.5rem 0;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero p {
    font-size: 1rem;
  }

  .login-card {
    padding: 1.75rem;
    margin: 0 1rem;
  }

  .assessment-section {
    padding: 1.25rem;
    margin: 0.5rem;
  }

  .question-card {
    padding: 1rem;
  }

  .answer-option {
    padding: 0.875rem 1rem;
  }

  .btn {
    min-height: 44px;
    min-width: 44px;
  }

  .btn-block {
    width: 100%;
  }

  .feature-grid,
  .materials-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    margin: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    min-height: 50vh;
    max-height: 90vh;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .hero p {
    font-size: 0.95rem;
  }

  .login-card {
    padding: 1.5rem;
    margin: 0;
    border-radius: 0;
    min-height: 100vh;
  }

  .btn {
    width: 100%;
    padding: 0.75rem 1rem;
  }

  .hero-buttons {
    flex-direction: column;
  }

  .hero-buttons .btn {
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   18. UTILITY CLASSES
   -------------------------------------------------------------------------- */
.fade-in {
  animation: fadeIn 0.5s var(--ease-out) both;
}

.slide-up {
  animation: fadeInUp 0.5s var(--ease-out) both;
}

.scale-in {
  animation: scaleIn 0.4s var(--ease-spring) both;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* --------------------------------------------------------------------------
   19. IMAGE & VIDEO RESPONSIVE
   -------------------------------------------------------------------------- */
img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* --------------------------------------------------------------------------
   20. LAYOUT STABILITY FIXES
   -------------------------------------------------------------------------- */
/* Prevent layout shift from scrollbars */
html {
  overflow-y: scroll;
}

/* Consistent box model */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove tap highlight on mobile */
button,
a,
input,
textarea,
select,
label {
  -webkit-tap-highlight-color: transparent;
}

/* Better text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --------------------------------------------------------------------------
   21. CONNECTION LOST OVERLAY ENHANCEMENT
   -------------------------------------------------------------------------- */
#connection-lost-overlay {
  animation: fadeIn 0.3s var(--ease-out) both;
}

#connection-lost-overlay > div {
  background: rgba(15, 23, 42, 0.92);
  border-radius: var(--radius-xl);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-xl);
}

/* --------------------------------------------------------------------------
   22. DASHBOARD MODERNIZATION
   -------------------------------------------------------------------------- */
.dashboard-sidebar {
  background: linear-gradient(180deg, var(--surface-color) 0%, var(--bg-color) 100%);
  border-right: 1px solid var(--border-color);
}

.sidebar-menu .menu-item {
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-spring);
}

.sidebar-menu .menu-item:hover,
.sidebar-menu .menu-item.active {
  background: var(--primary-light);
  color: var(--primary-color);
  transform: translateX(4px);
}

.stat-card {
  border-radius: var(--radius-lg);
  background: var(--surface-color);
  border: 1px solid var(--border-color);
}

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

/* --------------------------------------------------------------------------
   23. EMPTY STATES & ILLUSTRATIONS
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
  animation: fadeInUp 0.5s var(--ease-out) both;
}

.empty-state i {
  font-size: 4rem;
  opacity: 0.3;
  margin-bottom: 1rem;
}

/* --------------------------------------------------------------------------
   24. SELECTION COLORS
   -------------------------------------------------------------------------- */
::selection {
  background: var(--primary-color);
  color: white;
}

::-moz-selection {
  background: var(--primary-color);
  color: white;
}

/* --------------------------------------------------------------------------
   25. PREVENT LAYOUT SHIFTS & GLITCHES
   -------------------------------------------------------------------------- */
/* Ensure images don't cause layout shifts */
img {
  height: auto;
  max-width: 100%;
}

/* Prevent horizontal overflow on mobile */
html, body {
  overflow-x: hidden;
}

/* Smooth width transitions for containers */
.container {
  width: 100%;
  max-width: min(1200px, 95%);
  margin-left: auto;
  margin-right: auto;
}

/* Fix any inline-styled buttons to be responsive */
button[style*="width: 100%"],
.btn[style*="width: 100%"] {
  width: 100% !important;
}

/* --------------------------------------------------------------------------
   26. ASSESSMENT MOBILE STICKY TIMER ENHANCEMENT
   -------------------------------------------------------------------------- */
#mobile-sticky-timer,
.mobile-sticky-timer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--glass-border);
  padding: 0.75rem 1rem;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
  transition: transform var(--duration-normal) var(--ease-out);
}

/* --------------------------------------------------------------------------
   27. DASHBOARD TABLE MOBILE SCROLL
   -------------------------------------------------------------------------- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.table-responsive table {
  min-width: 600px;
  width: 100%;
}

/* --------------------------------------------------------------------------
   28. BETTER BADGES & TAGS
   -------------------------------------------------------------------------- */
.badge,
.tag,
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  transition: transform var(--duration-fast) var(--ease-spring);
}

.badge:hover,
.tag:hover {
  transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   29. SILENT DATA UPDATE TRANSITIONS
   -------------------------------------------------------------------------- */
tbody, .lesson-grid, .materials-grid, .stats-grid, .feature-grid {
  transition: opacity 0.2s ease;
}

/* Subtle highlight on updated rows */
@keyframes flashUpdate {
  0% { background-color: rgba(79, 70, 229, 0.15); }
  100% { background-color: transparent; }
}

.row-updated {
  animation: flashUpdate 0.6s ease;
}

/* --------------------------------------------------------------------------
   30. PRINT STYLES
   -------------------------------------------------------------------------- */
@media print {
  .navbar,
  .btn,
  .no-print {
    display: none !important;
  }

  .page {
    display: block !important;
    opacity: 1 !important;
  }
}
