The way I was taught, the Catholic Church managed secular affairs for a long time (the middle ages)
Well, not when you really look into the details. It was often the Christian kings, particularly the French kings trying to control the Church.
But, the big thing that you really need to understand is the concept of Christendom and what that meant. Nations weren’t nation states they way they are now. Christendom was a thing, and yes, church and state were tied together in ways that they are not tied together now.
and generally tried to legislate morality
That’s a modern concept. That isn’t what the secular lords and kings would have thought they were doing nor the Church.
And, don’t we still “legislate morality”? We regulate drugs, alcohol, gambling, prostitution, the speed limit, abortion, whether or not you can use plastic bags-- any number of things based on SOMEONE’S idea of right, wrong, or “best”. Society makes decisions, in a democracy or republic that might look different than in a socialist or communist regime, an oligarchy, a monarchy. Sometimes those are based on religions, sometimes on a different basis for what is "right’ or “good” or “just”. But ultimately, we are always making such decisions in the things we as a corporate body choose to fund, support, endorse, make legal, make illegal.
So, really, “legislating morality” is pretty much a non-issue.
Also, I believe in separation of Church and State, so this meta-story is a major hangup for me.
Don’t know why. That too is a pretty modern concept. Frankly the concept of the modern concept of the state is only about 400 years old.
There is no one right or wrong political theory. The Church exists outside of that. At some points in the past the two have been aligned or intertwined, at present they are not in most places.
What is the Church’s teaching about the relationship between Church and State? And how is it good/true/beautiful?
The Church has a rich teaching on this, it can’t really be summed up in a sentence or two.
The Church’s documents on social teaching, the Church in the modern world, economics, etc. There are a LOT of documents.
The Catechism has some information:
http://www.vatican.va/archive/ccc_css/archive/catechism/p3s2c2a7.htm