The benefits and costs of agglomeration: insights from economics and complexity