Sen. John McCain has repeatedly come under attack from GOP nominee Donald Trump. Here are just a few of their rocky moments. (Peter Stevenson/The Washington Post)

Sen. John McCain is already thinking about life after Donald Trump.

The Arizona Republican turned a recent question about millennial farmers into a soul-searching answer about the Republican Party’s future once, presumably, Trump loses the presidential election.

“Speaking as a proud Republican, we’re going to have to look at our party and look at how we can get back to the party of Abraham Lincoln and Teddy Roosevelt and Ronald Reagan,” McCain told leaders of the Arizona Farm Bureau. “Ronald Reagan used to say if a fellow agrees with me 80 percent of the time, then I’m with him.”

He lamented the purist ideological approach that many conservatives now apply.

“You’ve got to be 110 percent, otherwise you’re out,” McCain said. “We’ve got to be a big-tent party.”

Rep. Ann Kirkpatrick (D-Ariz.), McCain’s opponent, talks with reporters before Chelsea Clinton addresses a crowd at Arizona State University on Oct. 19 in Tempe, Ariz. (Ross D. Franklin/AP)

McCain, 80, can afford to think about his party’s future, largely because he is improbably well ahead in his bid for a sixth term. Following a competitive August primary against a tea party conservative in which he barely cleared 50 percent, the senator is now leading Rep. Ann Kirkpatrick (D-Ariz.) by about 10 percentage points in a state where some polling shows Hillary Clinton pulling ahead of Trump.

An Arizona Republic poll found McCain with a solid establishment coalition, garnering more than 75 percent of Republican voters, 50 percent of independents and 25 percent of Democrats. It’s a surprising turnaround for a man whose introduction on the national stage came as an anti-establishment truth-teller riding his “Straight Talk Express” in an unsuccessful bid for the 2000 Republican presidential nomination.

Trump has targeted the senator in this year of deep anti-establishment fervor, first by slamming the former Vietnam prisoner of war as not being a “war hero” because he was captured. Yet McCain made a clean break from Trump only after the release early this month of a 2005 videotape in which Trump openly bragged about lewd sexual advances.

Public polling is split on whether that decision has cost McCain among deeply conservative voters. But Democratic strategists continue to privately say this race is not among their top targets. The Democratic Senatorial Campaign Committee and its liberal super PAC allies have not spent on the airwaves here in the general election, believing that Kirkpatrick can topple McCain only if Clinton routs Trump in the presidential race.

To that end, Clinton’s campaign has gone all-in trying to win Arizona, something only one Democrat, Bill Clinton, has done in a presidential race since Harry S. Truman in 1948.

Clinton’s campaign dispatched Michelle Obama to the state for a rally Thursday — Sen. Bernie Sanders (Vt.) was in Flagstaff on Tuesday — and has invested $2 million to be spent largely on the ground. The key demographic will be the state’s burgeoning Hispanic vote, which might top 20 percent for the first time and is largely against Trump’s nativist campaign.

Kirkpatrick is trying to lasso this late burst of activity to pull off what would be the biggest upset of the election season. She is focusing on highlighting McCain’s shifting positions on issues, with TV ads showing McCain sounding like Trump in his last reelection rodeo, in 2010, as he called for a “danged fence” along the border. McCain’s back-and-forth on Trump’s candidacy plays into the idea that he is not taking firm stands.

“They can’t believe John McCain didn’t stand up for himself when Trump insulted him, and they really believe if he can’t stand up for himself, he’s not going to stand up for voters in Arizona,” Kirkpatrick said after an event with several dozen retired federal workers in Tempe.

But McCain has built a modern campaign organization that has helped shield him from the turmoil of the presidential race, modeled in large part after the 2014 reelection bid by Sen. Mitch McConnell (R-Ky.), now the Senate majority leader, who like McCain first had to fend off a primary challenge from the right.

The octogenarian has a small army of college and high school interns who knock on doors in search of likely McCain supporters. It’s a more aggressive and data-driven approach than Senate campaigns have normally taken, having previously relied more heavily on state Republican parties and the Republican National Committee for get-out-the-vote operations.

Another prince of the Republican establishment, Sen. Rob Portman (Ohio), a former member of House GOP leadership and an adviser to both Bush presidents, used a similar model. It has helped position Portman for a surprisingly easy victory over former governor Ted Strickland, who was essentially abandoned by Democrats in the late summer because he fell so far behind.

McCain and Portman have adopted the overwhelming-force doctrine in their campaigns, amassing huge stockpiles of campaign cash and dispensing it early and often. Even as McCain navigated a primary challenge that did not conclude until the end of August, his campaign ran a heavy dose of ads portraying Kirkpatrick as a liberal ally of President Obama and Hillary Clinton.

One such ad shows Kirkpatrick walking away from angry voters during the run-up to her vote for the 2010 Affordable Care Act, then cuts to images of McCain’s time as a POW.

Polls over the summer showed Kirkpatrick within a few points of McCain in a head-to-head matchup, but Democrats in Washington think those numbers were false positives. They suggest that McCain’s vote was underestimated because some conservatives were unwilling to support the incumbent until his primary was over. They cite a similar dynamic in the presidential primary, with Sanders supporters unwilling to back Clinton before that contest ended.

Following his primary victory, McCain quickly pivoted to the general election. During the primary, his campaign literature called only for making “the border stronger, safer and more secure,” without mentioning a 2013 immigration bill he co-authored. But this week, McCain, unprompted, brought up his support for a path to U.S. citizenship for undocumented immigrants.

“Sooner or later we’re bound to take up immigration reform again, because there’s 11 million people that are in this country illegally,” he told the farm leaders. “We’re going to have to address it.”

Some Arizonans have grown tired of McCain’s pivots. Jim Keyser, the head of the local federal employees union, said he backed McCain as recently as 2008 in his race against Obama. “It’s time for a change,” said Keyser, 69. “He’s been there forever.”

Joyce Vogt, 45, became upset when she asked McCain about Trump’s behavior toward women and its contribution to “rape culture.”

The senator handed the microphone to his wife, Cindy McCain, who has worked for years fighting sex trafficking and other issues related to abuse of women.

“He dodged it. He handed it off to his wife,” Vogt said after an event with business leaders in Chandler, southeast of Phoenix. “He needs to retire.”

For now, however, more voters appear to be taking the view of Stefanie Smallhouse, vice president of the state’s farm bureau. She is happily voting for McCain and reluctantly backing Trump.

“When people ask me and talk to me about the election, I just tell them I’m voting for the Supreme Court,” she said.

Smallhouse told McCain that she suffers “extreme anxiety” and sleepless nights, disgusted by Trump’s behavior but fearful of more Democratic regulations on farm policy.

“I’ve heard more people express exactly what you just expressed in my campaign than I’ve ever heard before,” he said, trying to ease her concerns.

Of course, by his own actions, McCain is effectively rejecting a Trump presidency. He’s not certain Clinton will win, but he’s ready to begin the conversation about what Republicans do after the race is over.

As he searched for answers, he acknowledged that there were no easy solutions.

“Stay engaged,” McCain told the audience.

Correction: An earlier version of this article misspelled Stefanie Smallhouse’s name.