It's quantum mechanical, so the maths gets complex. It can be simplified in a useful way however.
Basically, atoms can absorb photons and then re-emit them. You can think of the photon flying past at C, but getting absorbed and emitted along the way, adding delays. In QM however, neat particles don't exist, it deals with quantised, probabilistic waves. The above effect gets blurred over the waveform. No one atom definitely absorbs it or doesn't, it gets blurred together into a general slowing of the wavefront.