Selection Shapes Transcriptional Logic and Regulatory Specialization in Genetic Networks