server {
    listen 80;
    root /usr/share/nginx/html;
    index index.html;

    location = /favicon.ico {
        rewrite ^ /favicon.png permanent;
    }

    # HTML, manifest y service worker: nunca en cache
    location ~* \.(html|json)$ {
        expires -1;
        add_header Cache-Control "no-cache, no-store, must-revalidate";
        add_header Pragma "no-cache";
        try_files $uri $uri/ /index.html;
    }

    # JS: revalidar siempre (304 si no cambió → rápido, pero nunca sirve stale)
    location ~* \.js$ {
        expires 0;
        add_header Cache-Control "no-cache, must-revalidate";
        try_files $uri =404;
    }

    # Imágenes, fuentes e íconos: cache larga (no cambian sin renombrar)
    location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Flutter Web SPA
    location / {
        try_files $uri $uri/ /index.html;
    }

    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/javascript;
}
