How do I rotate a camera on the Z axis relative to it's rotation on the X axis.

I have a camera that is currently rotated on the X axis, i want to rotate it on the Z axis relative to the X axis rotation. Here is a better example:

What it currently does:

What I would like it to do:

This is the closest I have gotten to fixing it:

if (Input.GetKey(KeyCode.RightArrow)) {

    rotateZ = getnew(rotateZ + time*(90-rotateX));
	rotateY = getnew(rotateY - rotateX*time);
			
}

here is the entire script:

you found a solution? im at a loss here as well