Set camera Z position in base of screen size

Hi guys,
I’m developing a 3d configurator for desktop and mobile.

I would like to know (or find some doc)
how to set the correct Z value for the camera
so that the model fit the viewport.

I attached two images about the issue.

Thanks in advance for helping and support.
Kind regards