Quaternions are not Euler angles, they are not a 3-axis system and should not be considered rotations about xyz.
Don't read the individual components of a Quaternion.
xyz and w are for advanced use cases only.
Read from localEulerAngles or eulerAngles instead of a Quaternion like transform.rotation.
These are Vector3 properties that represent the traditional XYZ rotations you are likely familiar with.
-transform.rotation.x
+transform.eulerAngles.x
-transform.localRotation.x
+transform.localEulerAngles.xAngles read in code may differ from those displayed in the Inspector because they are derived from the internal representation, which is a Quaternion.
If you can't work with this, consider either:
The inspector often displays user-authored rotations, where you can set rotations beyond 180° for authoring convenience. However, Quaternions don't over-rotate, and when storing Euler angles as a Quaternion that information is lost. Although, the same orientation is represented in the end.
See Quaternion overview for more information.