# Enable caching for static assets with long cache times
<IfModule mod_expires.c>
  ExpiresActive On

  # Cache JavaScript files for 1 year (with hash in filename, safe to cache long)
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType text/javascript "access plus 1 year"

  # Cache CSS files for 1 year
  ExpiresByType text/css "access plus 1 year"

  # Cache images for 1 year
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Cache fonts for 1 year
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"

  # Cache HTML files for 1 hour (shorter for dynamic content)
  ExpiresByType text/html "access plus 1 hour"
</IfModule>

# Cache-Control headers for modern browsers
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  <FilesMatch "\.(jpg|jpeg|png|svg|ico|woff|woff2)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  <FilesMatch "\.html$">
    Header set Cache-Control "public, max-age=3600, must-revalidate"
  </FilesMatch>

  # Critical page chunks get special treatment
  <FilesMatch "page-(dashboard|board|aistudio)-.*\.js$">
    Header set Cache-Control "public, max-age=31536000, immutable"
    Header set X-Cache-Status "Critical-Page-Chunk"
  </FilesMatch>
</IfModule>

# Enable gzip compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>

# Prevent directory listing
Options -Indexes
