What just happened?

The Senate’s failure to pass a bill to repeal and replace Obamacare was not shocking, in a broad sense. FiveThirtyEight and other news outlets have been writing for months about the unpopularity of this legislation, both with the public and with Republican senators.

But it would have been hard to predict the particular sequence of events that led to the bill’s collapse early Friday morning. Senate Republican leaders unveiled a fairly narrow repeal proposal, set up the process for a vote and had Vice President Mike Pence come to the Senate chamber. It seemed obvious what would happen: All the Democrats would join Alaska’s Lisa Murkowski and Maine’s Susan Collins in voting “no,” 50 Republicans would vote “yes,” and Pence would cast a dramatic tie-breaking vote to approve the bill.

Instead, it was Arizona Sen. John McCain whose vote proved decisive. With a silent, emphatic “thumbs down” shortly before 1:30 a.m., McCain torpedoed Republicans’ seven-year effort to repeal the Affordable Care Act. (Of course, this isn’t the first time the repeal effort has looked dead. It’s still possible Republicans will revive the process once again.)

McCain’s decision to vote “no” surprised senators and staffers of both parties whom I talked to after the vote. But McCain’s decision was only the final nail in the coffin — there have been plenty of other decisions over the past few months that also played a key role in the bill’s ultimate failure.

1. McCain and McConnell

Senate Majority Leader Mitch McConnell has spent weeks trying to figure out what Republican senators would vote for. So it’s odd that he brought forward a bill that didn’t have 50 votes.

More reporting may explain this. But the immediate question coming out of Thursday night is what exactly drove McCain to vote against this bill when other Republicans who had been on the fence ended up coming around. Rob Portman of Ohio, for example, had faced pressure from his state’s governor not to vote for anything that could endanger the expansion of Medicaid under the Affordable Care Act; he voted “yes” to McConnell’s “skinny repeal” bill, which would have preserved Medicaid funding, at least at this stage of the process. Also voting for the bill were senators such as Lindsey Graham of South Carolina who had raised objections to the bill on process grounds. Graham and McCain had even held a joint press conference earlier on Thursday, but ended up voting in different directions.

Was McCain’s “no” based on policy? Process? The statement he released explaining his vote was somewhat vague, saying that Senate Republicans, “offered no replacement to actually reform our health care system and deliver affordable, quality health care to our citizens.”

Perhaps McCain felt more free than other Republican senators to vote against the bill because of his reputation as a maverick, or because he just won re-election in 2016, or because of his recent brain cancer diagnosis. At this point, we can’t do much more than speculate. Whatever his reasons, McCain’s decision apparently caught McConnell off-guard. That leads to even more questions: Did McCain decide to vote no at the last minute, and not tell McConnell his reservations earlier? Did McConnell not ask?

2. The process

McConnell decided to draft this bill outside the usual committee process, initially turning the job over to a 13-person all-male working group. The approach drew vocal criticism from several senators, including all three eventual Republican “no” votes: McCain, Collins and Murkowski.

Then, this week introduced a new dynamic, with McConnell writing a bill that was unveiled two hours before it was to be voted on — and that even senators who voted for it said they didn’t want to become law. Instead, the bill was essentially a placeholder, which the Senate would pass so that House and Senate negotiators could work out the real bill in a conference committee. That led to the bizarre spectacle of several senators publicly demanding that House Speaker Paul Ryan promise not to let the House vote on the bill they were about to pass. (Or, as it turned out, fail to pass.) McCain hinted after the vote that the process was a big part of why he ended up voting “no.”

“We must now return to the correct way of legislating and send the bill back to committee, hold hearings, receive input from both sides of aisle, heed the recommendations of nation’s governors, and produce a bill that finally delivers affordable health care for the American people,” McCain said in his statement after the vote.

It’s easy, in retrospect, to say McConnell blew his chance to pass the bill by choosing an unusual, secretive and convoluted process — and that may be right. But it’s also possible that the process is the only way the bill ever got so close to passage. After all, McConnell was trying to stitch together a 50-vote majority out of a deeply divided Republican caucus. Which brings us to the real source of trouble …

3. The policy

The “skinny repeal” that the Senate voted on Friday morning was not as politically toxic as the previous versions of Obamacare repeal, such as the bill that was passed in the House or some of McConnell’s earlier drafts. It did not include huge tax cuts that would disproportionately benefit the wealthy or cut Medicaid spending drastically. But the “skinny repeal,” as health care experts were arguing on the eve of the vote, still had huge shortcomings as policy, with the Congressional Budget Office estimating that it would increase health care premiums by 20 percent.

The real question, to me, is why both Ryan and McConnell spent months pushing two ideas that anyone could have told them would be unpopular: huge Medicaid cuts and large tax cuts for the wealthy.

By pushing such a conservative bill, Republicans galvanized not just liberals but essentially the entire health care community and several Republican governors against them. By the time “skinny repeal” was unveiled, there was already a powerful movement ready to bash anything that the Republicans put forward. Why didn’t Republicans start this process with either a bill that would have been more popular (a “skinny repeal”-style bill that only repealed the employer mandate, for example) or at least a less politically toxic version of a more comprehensive repeal (getting rid of the Obamacare Medicaid expansion, not rolling back the traditional program)? That, more than the process issues, may have been the GOP leadership’s real strategic error.

4. The ‘Resistance’

The Democrats made this hard for Republicans. None of them would come to the table with the GOP and give the Obamacare repeal effort the veneer of bipartisanship. (Of course, they weren’t really invited to the table anyway.) They all voted against both the House and Senate versions of repeal.

Perhaps more importantly, liberal activists flooded the phone lines of senators and showed up at town halls, making it clear to the Senate that they could face a backlash if they passed this legislation. That may have given senators pause and led to the more moderate “skinny repeal” that the Senate ended up considering. Nevada’s Dean Heller, the only Republican up for re-election in 2018 in a blue state, ended up backing the bill. But courting Heller’s vote complicated this process for Republicans, who risked losing support for the bill from conservative members, and it seemed that Heller was leery of backing a bill that would damage his chances of wooing more liberal and centrist voters.

5. The Republicans’ internal division

McConnell and Ryan were struggling to get bills through their chambers for a reason: The divide between more establishment Republicans (say Portman and McCain) and deeply conservative members (the House Freedom Caucus, Rand Paul of Kentucky) is substantial. I think that dynamic contributed to the messy bill process that McCain criticized. Could President Trump, with a more defined White House version of a health care policy, have bridged that gap? Perhaps. Instead, the president largely played the role of imploring Republicans to vote for anything, without really acknowledging the ideological divide in the party.

I’m not sure which of these factors best explains what happened Friday. The particular way this health care bill failed, with a fairly conservative senator (McCain) deciding to vote it down, was perhaps just a kind of black swan event. McCain, if not a maverick, is a wild card. On the other hand, Senate Republican leaders — and Trump to some extent — built a bad foundation: an unpopular bill that was probably bad policy too and didn’t have any real constituency beyond the 49 senators who voted for it. Ultimately, that foundation cracked.