server {
    listen 3000;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;

    # Allow large CSV uploads (matches backend 500 MB limit)
    client_max_body_size 500M;

    # Proxy API requests to the backend service
    location /api/ {
        proxy_pass         http://backend:8000;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_read_timeout 300s;

        # SSE streaming support for agent assist
        proxy_buffering    off;
        proxy_cache        off;
        proxy_set_header   Connection '';
        chunked_transfer_encoding off;
    }

    # SPA fallback  serve index.html for all non-file routes
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Cache static assets
    location /static/ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }
}