But despite all of that, she only lost by a few thousand votes in a few key states.
More like a few hundred thousand, but it's a valid point. Trump won only six states that Romney did not win--Florida, Ohio, Iowa, Wisconsin, Michigan, Pennsylvania--plus one vote in Maine. Florida was paper thin in 2012 and could easily have gone the other way. That would have made the electoral vote 303-235 Obama, which is much more indicative of the popular vote margin.
Of the six, Trump only got more than 10% movement only in Iowa and Ohio. In Florida it was 2.07%, which is indicative of how hard fought the state was. Pennsylvania moved 6.1%, Wisconsin 7.70, Michigan 6.96. Those four states are a 150 electoral-vote swing. The popular margin, for Trump to sweep them, is less than a quarter million out of well over 20 million votes cast.
One thing which causes constant misjudgments about the election outcome is California's obscene 4.27 million vote margin, compared to 2.87 million nationally. One state is 40% more than the national. It is not unfair to say that Clinton won California by 4.3 Million and Trump won the rest of the country by 1.4 million. Given that Trump is running as an incumbent, usually about 1% to 1.5% advantage, the Democrats have some work to do.
All stats
https://uselectionatlas.org/