Ancient balancing selection on heterocyst function in a cosmopolitan cyanobacterium