Modal Theory for Thick Holographic Gratings with Sharp Boundaries: I. General treatment