Ionization conditions in the expanding envelopes of O and B stars