Bargmann invariants, null phase curves, and a theory of the geometric phase