<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  
  # Serve static files directly
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule ^ - [L]
  
  # Correctly serve module scripts
  AddType application/javascript .js
  AddType application/json .json
  AddType application/manifest+json .webmanifest

  # Exclude existing files and directories
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Exclude the server folder from rewrites (for API)
  RewriteCond %{REQUEST_URI} !^/server/

  # Redirect everything else to index.html for SPA routing
  RewriteRule ^ index.html [L]
</IfModule>
