Nucleon-pair approximation of the shell model: Unified formalism for both odd and even systems