<IfModule mod_rewrite.c>
    Options -Indexes
    RewriteEngine On
    RewriteBase /POS26/

    # --- Hub admin (never send hub/ into public/) ---
    RewriteRule ^hub/public/ - [L]
    RewriteRule ^hub/?$ hub/public/login.php [L,R=302]
    RewriteRule ^hub/(.*)$ hub/public/$1 [L,QSA]

    # --- Store short URL: /POS26/{slug}/ → stores/{slug}/public/ ---
    RewriteCond %{REQUEST_URI} !/stores/
    RewriteCond %{DOCUMENT_ROOT}/POS26/stores/$1 -d
    RewriteRule ^([a-z0-9][a-z0-9-]*)/(.*)$ stores/$1/public/$2 [L,QSA]
    RewriteCond %{REQUEST_URI} !/stores/
    RewriteCond %{DOCUMENT_ROOT}/POS26/stores/$1 -d
    RewriteRule ^([a-z0-9][a-z0-9-]*)/?$ stores/$1/public/ [L,QSA]

    # install-new → hub store creator
    RewriteRule ^install-new\.php$ hub/public/install-new.php [L,QSA]

    # Old URLs: /POS26/public/... → /POS26/...
    RewriteCond %{THE_REQUEST} \s/POS26/public/(\S*) [NC]
    RewriteRule ^ /POS26/%1 [R=301,L,NE]

    # Main POS app → /public (exclude hub + stores)
    RewriteCond %{REQUEST_URI} !/POS26/hub/ [NC]
    RewriteCond %{REQUEST_URI} !/POS26/stores/ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ public/$1 [L,QSA]
</IfModule>
