I’m sure there’s a cleaner way to do this without switching back to Euler angles but my math is rusty and well… Whatever works until performance is not an issue!
(Note: I just used that to restrict camera rotation around Y in a small practice project, see here with source code linked)