I understand that the Fermi level at the p-n junction must be the same between the materials forming the junction. To achieve this, the band energies of the n- and p-type materials are bent.
However, far away from the p-n junction, the band diagram (incl. the Fermi level) should be the same as for isolated materials. This would imply that the Fermi level is higher (lower) away from the junction than at the junction. Does that mean that the Fermi level can vary within the same material?