<IfModule mod_rewrite.c>
    RewriteEngine On

    # 1. Automatically direct root traffic to the frontend build
    RewriteRule ^$ frontend/dist/ [L]

    # 2. Let backend requests pass through directly
    RewriteCond %{REQUEST_URI} ^/HZ-ProjectHub-v2/backend/ [NC]
    RewriteRule ^ - [L]

    # 3. Serve actual existing files (CSS, JS, images)
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # 4. Fall back all React routes to frontend/dist/index.html
    RewriteRule ^(.*)$ frontend/dist/index.html [QSA,L]
</IfModule>