I understand that for a semiconductor p-n junction under zero voltage, the Fermi level is constant throughout the junction because that is the condition for a system in thermodynamic equilibrium. I also understand that p-n junction under applied voltage (forward or reverse) is not a system in thermal equilibrium because there is a nonzero total current that obviously tries to revert the system back to equilibrium. Then I don't understand how come away from the junction we still use two Fermi levels to describe the electron distribution in energies, one for the left side and one for the right. Most importantly how come those Fermi levels differ exactly by the applied voltage? I've consulted 2 textbooks in semiconductor devices and Ashcroft-Mermin solid state textbook. They all state the difference in the Fermi levels must be equal to the applied voltage without any derivation as if that is something obvious. Can someone enlighten me where that formula comes from?