// Dashboard chart and progress bar animations

document.addEventListener('DOMContentLoaded', function() {
  // Animate progress bars
  document.querySelectorAll('.progress-fill').forEach(function(fill) {
    var label = fill.closest('.progress-item')?.querySelector('.progress-label span:last-child');
    var percent = label ? parseInt(label.textContent) : 0;
    fill.style.width = '0%';
    setTimeout(function() {
      fill.style.width = percent + '%';
    }, 200);
  });

  // Animate bar chart bars
  document.querySelectorAll('.bar-chart .bar').forEach(function(bar) {
    var value = bar.getAttribute('data-value');
    bar.style.height = '0';
    setTimeout(function() {
      bar.style.height = value + '%';
    }, 300);
  });

  // Animate donut charts
  document.querySelectorAll('.donut-chart').forEach(function(donut) {
    var label = donut.querySelector('.donut-label');
    var percent = label ? parseInt(label.textContent) : 0;
    donut.style.setProperty('--donut-percent', '0%');
    setTimeout(function() {
      donut.style.setProperty('--donut-percent', percent + '%');
    }, 400);
  });

  // Animate KPI cards
  document.querySelectorAll('.kpi-card').forEach(function(card, i) {
    card.style.opacity = '0';
    card.style.transform = 'translateY(20px)';
    setTimeout(function() {
      card.style.opacity = '1';
      card.style.transform = 'translateY(0)';
    }, 150 * i + 100);
  });
});
