On Election Day, Hillary Clinton’s campaign was confident she would win.

Almost every poll and projection confirmed it. The numbers had looked good for Clinton for months; it would be an early victory, with a strong electoral map — maybe even a blowout.

The party was planned: She would stand on a blue stage shaped like the United States in the Javits Center, a glass building — a not-so-subtle nod to the glass ceiling Clinton would be shattering.

But there was no celebration that night. She lost states her campaign was all but certain she would win. Donald Trump shattered her seemingly unbreakable electoral firewall in three crucial states: Michigan, Wisconsin, and Pennsylvania. The glass ceiling, however, stayed perfectly intact.

Democrats across the nation were horrified, shocked, and angry. As exit polls, however fallible, began confirming a too-familiar narrative of Clinton’s unfavorability, so began the endless stream of valid critiques from the left:

How was Clinton’s campaign so tone-deaf to a growing populist movement among the white working class? Why did she ignore Michigan, Iowa, and Wisconsin? Why didn’t she campaign where it mattered?

But there is a simple explanation for all of this. The country — even some in Trump’s own campaign — thought Clinton was going to win. So did Clinton’s campaign. They were more confident than the general public, one staffer told me. And they strategized accordingly.

There are many things Clinton’s campaign should have done

Clinton’s campaign maintains that her loss was the culmination of two main factors: the country’s hardened want for a change candidate, and FBI Director James Comey’s letter to Congress reopening — and then closing again — an investigation into Clinton’s private email server.

The revelations of the possible damning evidence-that-never-was struck enough of a negative chord with undecided American voters that it stopped people from coming out to the polls for Clinton on Election Day, a senior Clinton aide tells me.

But that doesn’t change the fact that there are many things Clinton’s campaign should have done differently.

Trump overperformed with the white working class, a demographic that has historically voted Democrat though has been voting Republican increasingly more in recent years. Either Clinton’s campaign simply thought it could stem the tide away from the party, or that it wouldn’t need them to win. In both scenarios, it was proved wrong.

That’s the message rightfully being drilled home by critical factions on the left. Political analyst Thomas Frank described what he saw as the complete tone-deafness of Clinton’s elite base for the Guardian:

What could possibly have gone wrong with such an approach? Put this question in slightly more general terms and you are confronting the single great mystery of 2016. The American white-collar class just spent the year rallying around a super-competent professional (who really wasn’t all that competent) and either insulting or silencing everyone who didn’t accept their assessment. And then they lost. Maybe it’s time to consider whether there’s something about shrill self-righteousness, shouted from a position of high social status, that turns people away.

In other words, there was something going on in America — an anger toward Washington elites, a want for an outsider, racial anxiety, economic anxiety — that was not addressed by the Democratic candidate. And whatever that was, Clinton’s campaign missed it, allowing for an unqualified man, running on a xenophobic and racist platform with a seemingly unorganized campaign, to beat a competent, highly qualified woman running on a platform similar to an extremely popular sitting president, with an incredibly professional and extensive team behind her.

In a postmortem press conference, President Barack Obama, too, reminded Democrats of the need to harness more than just strong liberal coalitions.

“And one of the issues the Democrats have to be clear on is the given population distribution across the country,” Obama said. “We have to compete everywhere. We have to show up everywhere.”

He went on to say:

I won Iowa not because the demographics dictated that I would win Iowa. It was because I spent 87 days going to every small town and fair and fish fry and VFW Hall, and there were some counties where I might have lost, but maybe I lost by 20 points instead of 50 points. There's some counties maybe I won, that people didn't expect, because people had a chance to see you and listen to you and get a sense of who you stood for and who you were fighting for.

Whether Obama was directly taking a dig at the Clinton campaign for not campaigning in Iowa — or states like Wisconsin — is not entirely clear. But his message is simple: Democrats can’t afford to lose the white Midwestern and Rust Belt states. Clinton’s loss proves that.

Sure, in hindsight, Clinton and her team should have guarded themselves from that outcome. They should have had a good response to attacks that Clinton was an elite outsider taking money from Goldman Sachs. They should have done more in Michigan and Wisconsin — especially in light of establishing field offices in reach states like Arizona and Texas. And looking back, even with their already 200-person-strong staff in Michigan, and millions of dollars spent in advertising, if they could go back and do more for those 10,000 votes that went to Trump instead, of course they would, a senior Clinton campaign aide tells me. (Although Iowa looked simply impossible to win.)

But then again, it didn’t look like they needed to.

You don’t need to answer for your weaknesses if they don’t seem to be hurting you

There was every indication that a Clinton victory was near certain. Early voting turnout — although not an indicator of Election Day results — was confirming polling that had Clinton consistently in the lead.

On ground game, Clinton was ahead. She had a bigger, more organized staff. According to an exit poll of early voters, Clinton’s campaign contacted twice as many American voters as Trump’s did.

Clinton’s campaign strategy was tested; Clinton would never be the agent of change Trump could claim to be (she has had a career in Washington after all), but she could easily proclaim Trump’s case for change too risky. And polls suggested that it was a line of attack that was working.

But as my colleague Jeff Stein explained, the polls “badly underestimated” the strength of the Republican coalition — lowballing both the number of white voters without a college education who would turn out at the polls on Election Day and the number of anti-Trump Republicans who ended up supporting the GOP nominees.

“So it was a very different electorate than we expected,” Matt Grossmann, a political scientist at Michigan State University, told Stein. “And Republican-leaning women and conservatives who hadn’t made up their minds almost all ended up voting for Trump.”

In 2012, Mitt Romney’s aides were found saying the similar thing; they were a numbers campaign that had bad numbers, John Dickerson wrote for Slate:

During the summer, they targeted more than 2 million voters who had not voted in party primaries. Those were the independents they believed would be the key to the race. Since the strategy seemed to be paying off with internal and external polls showing Romney leading among independents, the Romney team felt like they were working their plan. “We did everything we set out to do,” says a top strategist about the Ohio effort. “We just didn’t expect the African-American vote to be so high.” African-American participation in Ohio jumped from 11 percent of the electorate to 15 percent between the 2008 and 2012 elections. "We could never see that coming. We thought they'd gotten a lot last time."

Romney lost by much more than Clinton, but it was a similar reality.

“There was a belief, going into the election, based on internal and every public source of data, that we were on the right track,” a senior Clinton aide tells me. “There was no doubt that the race had closed in the final days, but there was no belief that it had closed to the point that Trump would win.”

Clinton’s campaign did everything by the book — and the book happened to be wrong.

Watch: A look back at Trump vs. Clinton through the polls