Even Donald Trump seemed pleasantly surprised when the Supreme Court delivered his administration a decisive victory on Tuesday, upholding the travel ban the White House enacted within days of him taking office. “Wow!” he tweeted, along with an all-caps headline announcing the news. But his victory was shadowed by a loss when San Diego Judge Dana Sabraw ordered his administration to return the approximately 2,000 children still in the government’s care to their families in the next 30 days, imposing a time frame on a chaotic process. “This situation has reached a crisis level,” Sabraw wrote, ruling that children under 5 must be returned to their parents within 14 days of the order; that all parents should be allowed to speak to their children by phone within 10 days; and that parents cannot be detained and deported without their children unless minors are in danger or their parents have consented.

The ruling was seen as a blow to the Justice Department, which had insisted it simply needed more time to reunite families, and that the executive order Trump signed last week had cleared up the issue. Speaking before the conservative Criminal Justice Legal Foundation, Attorney General Jeff Sessions defended the widely condemned “zero-tolerance” policy, arguing that in enacting it, Trump was merely fulfilling his mandate as president. “This is the Trump era,” he said. “We are enforcing our laws again. We know whose side we are on—so does this group—and we’re on the side of police, and we’re on the side of the public safety of the American people.”

Sabraw rejected Sessions’s stance as well as his department’s bid for more time, blaming the Trump administration for “a chaotic circumstance of the government’s own making . . . the unfortunate reality,” he added, “is that under the present system, migrant children are not accounted for with the same efficiency and accuracy as property.” It’s so far unclear how authorities will meet Sabraw’s deadline. Speaking to Congress Tuesday, Health and Human Services secretary Alex Azar said his department still has custody of 2,047 immigrant children split from their parents at the border—only six fewer children than the number in custody a week ago. Recent accounts have detailed the bureaucratic chaos in action at the border—at a recent hearing, a D.O.J. attorney reportedly told lawmakers that the Office of Refugee Resettlement doesn’t always know when a child’s parents are released, and that there is no designated process for reuniting children with their families.

Sabraw’s ruling is perhaps the most significant piece in an increasingly robust wave of opposition to Trump’s policy. In fact, it came just hours after 17 states filed a federal lawsuit over family separation, arguing that policy, which the suit calls “abhorrent and indefensible,” violates the constitutional rights of separated families, and is motivated by “animus” toward Latinos. The suit further argues that the separation of children from their parents detrimentally impacts the interests of the states’ residents and affects the states’ ability to shield children from abuse. “This case, like all our cases against this Administration, says something important about who we are as a people,” said Washington state Attorney General Bob Ferguson, who is leading the suit. “We will stand up for the Constitution, basic decency and fundamental American values."

The issue is equally unpopular among voters—a Politico/Morning Consult poll published Wednesday shows that just 44 percent of voters approve of the White House’s stance on immigration, while 74 percent say they support Trump’s decision to reverse the family-separation policy. Yet in the past week, Trump has seemed unwilling to budge on his hard-line rhetoric, even reportedly confessing to aides that he regretted signing the order to end separations in the first place. The Supreme Court ruling in favor of the travel ban, Trump allies say, may embolden him to strengthen his control over the nation’s borders, whether or not doing so is popular: “Travel ban vindication big deal for his psyche,” ex-White House aide Steve Bannon reportedly texted Axios’s Jonathan Swan. “Reinforces his instincts are right and the haters are wrong.” Mark Krikorian, executive director of the Center for Immigration Studies, echoed this view, though with far less enthusiasm. “Of course he does—why not?” Krikorian said when asked whether he believed Trump felt empowered by the ruling. “The question is, how he will use it? What will he do?”