// ============================================================================
// Theme Transitions - Smooth theme switching
// ============================================================================
//
// This file provides smooth CSS transitions when switching themes.
// The transitions are only enabled after the initial page load to prevent
// flash of unstyled content (FOUC) and transition flicker.
//
// Usage:
// - Automatically applied after page load via ThemeService
// - The body element gets the 'theme-transitions-enabled' class after 2 animation frames
// - All theme-aware properties (colors, backgrounds, borders, shadows) transition smoothly
//

// Transition timing configuration
$theme-transition-duration: 250ms;
$theme-transition-timing: ease-in-out;

// Apply transitions only after initial load via .theme-transitions-enabled class
// This class is added by ThemeService after requestAnimationFrame x2
body.theme-transitions-enabled {
  // Apply transitions to all elements
  *,
  *::before,
  *::after {
    transition-property: background-color, color, border-color, box-shadow, fill, stroke;
    transition-duration: $theme-transition-duration;
    transition-timing-function: $theme-transition-timing;
  }

  // Exclude elements that shouldn't have theme transitions
  // These elements have their own animations or should not transition
  .no-theme-transition,
  .mat-ripple,
  .mat-ripple-element,
  .mat-progress-spinner,
  .mat-progress-bar,
  .mat-slider,
  .mat-slider-thumb,
  .mat-slider-track,
  [class*="animate-"],
  [class*="animation-"],
  .animated,
  .carousel,
  .carousel-item,
  [data-bs-ride],
  [data-bs-slide] {
    transition: none !important;
  }

  // Angular Material specific exclusions
  // These components manage their own animations
  .mat-mdc-progress-spinner,
  .mdc-linear-progress,
  .mdc-circular-progress,
  .mat-step-header .mat-ripple,
  .mat-tab-label .mat-ripple,
  .mat-button .mat-ripple,
  .mat-icon-button .mat-ripple,
  .mat-fab .mat-ripple,
  .mat-mini-fab .mat-ripple {
    transition: none !important;
  }

  // Chart and visualization exclusions
  // Charts should not transition theme changes for performance
  canvas,
  svg.chart,
  .chart-container,
  [class*="chart-"],
  [id*="chart-"],
  .highcharts-container,
  .plotly,
  .d3-chart {
    transition: none !important;

    * {
      transition: none !important;
    }
  }

  // Performance optimization: Exclude large lists and grids
  // Prevents lag when transitioning themes on pages with many elements
  .gui-structure,
  .gui-structure *,
  .virtual-scroll-container,
  .virtual-scroll-container *,
  .cdk-virtual-scroll-viewport,
  .cdk-virtual-scroll-viewport * {
    transition: none !important;
  }

  // Code blocks can transition but syntax highlighting should not
  .code-block {
    transition-property: background-color, border-color, box-shadow;
    transition-duration: $theme-transition-duration;
    transition-timing-function: $theme-transition-timing;

    code,
    pre {
      transition: none !important;
    }
  }
}

// Accessibility: Respect user's motion preferences
// If user prefers reduced motion, disable all theme transitions
@media (prefers-reduced-motion: reduce) {
  body.theme-transitions-enabled * {
    transition: none !important;
  }
}
