Rotating camera around player on both axis but stops before the ground

I can’t find how to move my camera around the player but stop it before it reaches the ground. Here’s my code:

void Start()
    {
        offset = new Vector3(player.position.x + camPosX, player.position.y + camPosY, player.position.z + camPosZ);
        transform.rotation = Quaternion.Euler(camRotationX, camRotationY, camRotationZ);
        transform.LookAt(player.position);
    }


    // LateUpdate is called after Update each frame
    void LateUpdate()
    {

        offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * Quaternion.AngleAxis(Input.GetAxis("Mouse Y") * turnSpeed, Vector3.right) * offset;
        transform.position = player.position + offset;
        transform.LookAt(player.position);
}

To stop the camera from moving through the ground you will have to add a collider to the camera. If the collider hits something it will stop rotating further down.