# =============================================================================
# AVANZATO TECNOLOGIA - .htaccess para React SPA
# =============================================================================

# -----------------------------------------------------------------------------
# 1. REDIRECIONAMENTO PARA index.html (SPA - Single Page Application)
# -----------------------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Não reescrever arquivos/diretórios reais
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    # Redirecionar tudo para index.html
    RewriteRule ^ index.html [L]
</IfModule>

# -----------------------------------------------------------------------------
# 2. COMPRESSÃO GZIP (melhora performance)
# -----------------------------------------------------------------------------
<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    
    SetEnvIfNoCase Request_URI \
        \.(?:gif|jpe?g|png|webp|ico|svgz)$ no-gzip dont-vary
    
    SetEnvIfNoCase Request_URI \
        \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/atom+xml
    AddOutputFilterByType DEFLATE font/truetype
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# -----------------------------------------------------------------------------
# 3. CACHE DE BROWSER (performance)
# -----------------------------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    
    ExpiresByType text/html "access plus 0 seconds"
    
    <FilesMatch "\.(js|css)$">
        ExpiresDefault "access plus 1 year"
    </FilesMatch>
    
    ExpiresByType image/gif "access plus 6 months"
    ExpiresByType image/png "access plus 6 months"
    ExpiresByType image/jpeg "access plus 6 months"
    ExpiresByType image/webp "access plus 6 months"
    ExpiresByType image/svg+xml "access plus 6 months"
    ExpiresByType image/x-icon "access plus 1 year"
    
    ExpiresByType font/ttf "access plus 1 year"
    ExpiresByType font/otf "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
    
    ExpiresByType application/json "access plus 1 hour"
    ExpiresByType application/xml "access plus 1 hour"
</IfModule>

# -----------------------------------------------------------------------------
# 4. HEADERS DE SEGURANÇA
# -----------------------------------------------------------------------------
<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# -----------------------------------------------------------------------------
# 5. TIPOS MIME CORRETOS
# -----------------------------------------------------------------------------
<IfModule mod_mime.c>
    AddType application/javascript .js
    AddType application/javascript .mjs
    AddType text/css .css
    AddType image/svg+xml .svg
    AddType font/woff2 .woff2
    AddType font/woff .woff
    AddType font/ttf .ttf
    AddType font/otf .otf
    AddType application/json .json
    AddType application/manifest+json .webmanifest
</IfModule>

# -----------------------------------------------------------------------------
# 6. PROTEÇÃO DE ARQUIVOS SENSÍVEIS
# -----------------------------------------------------------------------------
<IfModule mod_rewrite.c>
    RewriteRule (^|/)\. - [F]
    
    <FilesMatch "^\.">
        Order allow,deny
        Deny from all
    </FilesMatch>
    
    <FilesMatch "\.(git|gitignore|env|log|sql|sh|bash|zsh)$">
        Order allow,deny
        Deny from all
    </FilesMatch>
</IfModule>

# -----------------------------------------------------------------------------
# 7. CHARSET PADRÃO
# -----------------------------------------------------------------------------
AddDefaultCharset UTF-8

# -----------------------------------------------------------------------------
# 8. DESATIVAR LISTAGEM DE DIRETÓRIOS
# -----------------------------------------------------------------------------
Options -Indexes
