There are various reasons why Hillary lost. I'd like to mention two:
i) Although this reason is blindingly obvious, Democrats were blind to the obvious. Increasingly, Democrats have focused on the "rights" of fringe constituencies. By that I mean, constituencies that comprise a minuscule fraction of the electorate. Most recently, homosexuals–followed by the even more statistically infinitesimal transgendered.
Conversely, Democrats keep antagonizing large voting blocks. For instance, they just can't leave gun rights alone. Yet, as a voting block, gun owners vastly outnumber homosexuals and transgenders (although, in theory, these groups could overlap to some small degree).
So voters see the tail wagging the dog. Democrats demand that 99% of the population adapt to 1% of the population. The whole nation must use transgender pronouns, accept coed public restrooms, locker rooms, sports teams, and women's shelters, force Orthodox Jews and Christians to cater queer marriages, &c.
That's a surefire formulate for alienating voters en masse.
(BTW, I don't object to protecting the rights of minorities. But a group isn't entitled to special treatment just because it whines.)
This is in large part because the Democrat party is on a never-ending quest for some new cause, some new social mascot, and so the latest protected classes become ever more esoteric and artificial.
ii) Another reason is that leftwing academics have become (in effect) the speechwriters for Democrat candidates. There are different sources of policy. Sometimes policy has a bottomup source. An exigent crisis that demands a policy solution.
But oftentimes, policy has a topdown source. Pointy-headed academics with bold new ideas. These can be liberals, libertarians, conservatives, whatever.
Yet even when it originates with pointy-headed academics, historically there's been a vetting process. Academics don't set the agenda directly. Rather, new ideas take time to percolate. There's an effort to create a constituency for the ideas. Op-ed columnists popularize and promote the ideas. Aspiring political candidates float new ideas as trial balloons.
The intent is to get voters behind new ideas by gradually exposing them to new ideas, until they become accustomed to them. If successful, that lays the groundwork for the political agenda. Of course, some policy initiatives never catch on. The public just doesn't like them.
But more recently, Democrats have bypassed that filter. Radical ideas by leftwing academics immediately set the political agenda of Democrat politicians. Voters are informed in no uncertain terms that these are moral imperatives. The lightning speed with which transgenderism captured the Democrat party and became an instant necessity is a case in point. Even faster than the two-step from gay domestic partnerships through gay civil unions to gay marriage.
But of course, normal Americans don't share these outre priorities. That doesn't speak to their needs.