The physical and chemical structure of Sagittarius B2, I. Three-dimensional thermal dust and free-free continuum modeling on 100 au to 45 pc scales