Rotate world/locally aligned texture

Hello!
I’ve made a material that can be switched between world aligned or locally aligned (pre-skinned) textures. Works great as is.
Then I decided to add some more flexibility to it. I’ve added some parameters to control the offset:

And then I got stuck with how to rotate the texture.

After some research, I found this forum thread:

As well as several youtube video tutorials with the exact same solution.

HOWEVER. When I applied this to my material, I noticed that normal maps render incorrectly after rotating.
I.e. if shadows on the surface fall from top to bottom originally, and I rotate the texture 180 degrees, the shadow now goes from bottom to top. It rotates with the texture itself.

And no one addresses or even notices this issue it in all those videos. Just one commenter under one of them who noticed this exact same behavior, but was left without reply.

I can’t figure out how to do this properly.
If anyone savvy with materials could help me out, I’d be very grateful!