Structural and Thermodynamic Principles of Viral Packaging