In waves other than electromagnetic waves (e.g. waves on a string assuming small transverse displacement), when propagating across the boundary between two media, a fraction of a wave will be reflected with a phase shift of $\pi$ if the impedance of the second medium is larger than that of the first, or generally if the amplitude reflection coefficient $r$ is negative. Otherwise, the reflected wave will have no phase shift, implying positive $r$.
For electromagnetic waves, the amplitude reflection and transmission coefficients are governed by the Fresnel equations, which take into account the component polarization of light incident to the interface between to media with different indices of refraction. Looking at the behavior of the amplitude coefficients for light incident on glass from air with respect to the angle of incidence:
S. Berg-Johansen, CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0, via Wikimedia Commons
we see that despite the transition from a medium of lower to one of higher impedance (considering that impedance for electromagnetic waves is proportional to index of refraction), the amplitude reflection coefficients are not always negative, suggesting that the light does not acquire a phase shift of $\pi$ upon reflection. Does this mean that light incident to an optically denser medium does not always reflect with a phase shift of $\pi$?