Options -MultiViews
DirectoryIndex index.html

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Preserve backend/API routing exactly as supplied.
    RewriteRule ^api(?:/.*)?$ backend/public/index.php [L,QSA]
    RewriteRule ^sanctum(?:/.*)?$ backend/public/index.php [L,QSA]
    RewriteRule ^validate(?:/.*)?$ backend/public/index.php [L,QSA]
    RewriteRule ^webhook(?:/.*)?$ backend/public/index.php [L,QSA]
    RewriteRule ^backend/ - [L]

    # Serve shared public assets directly.
    RewriteRule ^assets/ - [L]

    # Panel entry point. The panel application itself is preserved unchanged.
    RewriteRule ^panel/?$ panel.html [L,QSA]

    # Compatibility for URLs created by the previously modified panel bundle.
    # Redirect them to the original panel routes rather than changing panel code.
    RewriteRule ^panel/(dashboard|clients|visits|antibots|telegram|settings|builder)(/.*)?$ /$1$2 [R=302,L,NE]
    RewriteRule ^panel/action(/.*)?$ /action$1 [R=302,L,NE]

    # Original panel application routes after sign-in.
    RewriteRule ^(dashboard|clients|visits|antibots|telegram|settings|builder)(/.*)?$ panel.html [L,QSA]
    RewriteRule ^action(/.*)?$ panel.html [L,QSA]
    RewriteRule ^panel/actions(/.*)?$ panel.html [L,QSA]

    # Existing files and directories remain directly accessible.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # All other browser routes belong to the Claro public flow.
    RewriteRule ^ index.html [L]
</IfModule>
