The reason Hillary lost can be boiled down to one single factor: She was the worst campaigner since…I dunno…Bob Dole? Walter Mondale? Actually I think she’s worse than either of them. They at least seemed to be trying, in their own incompetent way.
Rightly or wrongly, she’d been perceived as a person who’d lie even when the truth would serve her better since at least 2008 (remember her infamous claim that she landed under sniper fire in Bosnia and had to run to her vehicle while under a hail of bullets, only to have video show up of her skipping happily across the tarmac with a little girl who read poems to her and gave her hugs?). That was the sort of thing she should have been on guard about this time round, since it was one of the big nails in the coffin that made her lose to Obama (another is that Obama is likable and perceived to be honest).
Every possible problem this election, Hillary lied which made things worse. If she’d said “Yeah, I had a private e-mail server, and so does person A, B, and C. It’s just the way things are done.” it would have been over or spread thinner as the investigation spread to Republicans she could have mentioned who also had private servers. Instead, first she didn’t have one. Then she might have had one. Then no, she didn’t have one–until it was found. Then she wiped it. Then she claimed that she didn’t know what wiping a server was (“What? Like with Windex?”) etc. She took a story that had a normal lifespan of maybe a week and managed to make it last for like 5 months by constantly lying. Her lies became the story, rather than the initial accusation.
Ditto with her illness. People report that she looks sick/tired/ill and catch her on film staggering, tripping etc. She likes and says she’s fine. Rinse and repeat for weeks. Then she kinda faints on cam and she had…what? a drug reaction? Again, the truth “I have the flu (or whatever), but I’ll be fine and it won’t hold me back” would have done better than the constant string of lies.
There were bunches more micro-scandals that Hillary made worse by lying or being condescending and dismissive about.
The reason that things were tight enough for Comey’s letter to be able to affect anything at all (if it did) was that Hillary was such a terrible candidate that she let things get that bad in the first place. If she’d campaigned as well as Bernie (who’s a solid, middle-of-the-pack campaigner, but nothing special*) she would have been 8-10 points ahead of Trump, easily, by the time Comey’s letter hit.
*Best three campaigners I can think of are Obama, Bill Clinton (who’s the only one who seemed to genuinely enjoy campaigning…the others are merely good at it. Bill loved it) and Reagan.