MCALLEN, Texas -- The clock is ticking for the Trump administration after a federal judge ordered thousands of migrant children and parents who were forcibly separated at the Mexican border reunited within 30 days, sooner for youngsters under 5.

The deadline was set Tuesday night by U.S. District Judge Dana Sabraw in San Diego after President Donald Trump's order ending his policy of separating families gave way to days of uncertainty, conflicting information and no word from the administration on when parents might see their children again.

"This situation has reached a crisis level," Sabraw wrote.

The ruling poses a host of logistical problems for the administration, and it was unclear how it would meet the deadline.

Health and Human Services, which is in charge of the children, referred questions to the Justice Department.

The Justice Department said the ruling makes it "even more imperative that Congress finally act to give federal law enforcement the ability to simultaneously enforce the law and keep families together."

"Without this action by Congress, lawlessness at the border will continue," the department said.

Sabraw, an appointee of Republican President George W. Bush, said children under 5 must reunited with their parents within 14 days.

He also issued a nationwide injunction against further family separations, unless the parent is deemed unfit or doesn't want to be with the child, and ordered the government to provide phone contact between parents and their children within 10 days.

The case was brought by the American Civil Liberties Union, which sued in March on behalf of a 7-year-old girl who was separated from her Congolese mother and a 14-year-old boy who was taken from his Brazilian mother.

"Tears will be flowing in detention centres across the country when the families learn they will be reunited," said ACLU attorney Lee Gelernt.

More than 2,000 children have been separated from their parents in recent weeks and placed in government-contracted shelters -- hundreds of miles away, in some cases -- under a "zero tolerance" policy toward families caught illegally entering the U.S. Many are from drug- and violence-wracked Guatemala, Honduras and El Salvador.

Amid an international outcry, Trump last week issued an executive order to stop the separation of families and said parents and children will instead be detained together.

But parents already separated from their children were left in the dark on when and how they would be reunited, and Homeland Security seemed only to sow more confusion over the weekend.

"The facts set forth before the Court portray reactive governance -- responses to address a chaotic circumstance of the Government's own making," Sabraw wrote. "They belie measured and ordered governance, which is central to the concept of due process enshrined in our Constitution."

Since Trump issued the executive order, the administration has been casting about for detention space for holding families together and has asked the courts to modify a 1997 settlement that generally bars the government from keeping children locked up with their parents for more than 20 days.

The task ahead could be monumental: Health and Human Services Secretary Alex Azar told Congress on Tuesday that his department still has custody of 2,047 immigrant children separated from their parents at the border -- only six fewer than last Wednesday.

Democratic senators said that wasn't nearly enough progress.

Under questioning, Azar refused to be pinned down on how long it will take to reunite families. He said his department does extensive vetting of parents to make sure they are not traffickers masquerading as parents.

Also challenging will be the requirement the judge set on phone contact.

At a Texas detention facility near Los Fresnos, immigrant advocates complained that parents have gotten busy signals or no answer from a 1-800 number set up by federal authorities to get information about their children.

"The U.S. government never had any plan to reunite these families that were separated," Simon Sandoval-Moshenberg of the Legal Aid Justice Center in Virginia said Tuesday. The government is now "scrambling to undo this terrible thing that they have done."

Robert Carey, director of the HHS refugee resettlement office during the Obama administration, said the government could face many challenges in trying to meet the judge's deadline.

Carey said the agency will probably struggle to connect children with their parents, especially if the parents are still detained or already been deported.

There have been widespread reports of children being taken from their parents unexpectedly, without identification documents on them, and with neither side knowing where the other is.

"I see all the problems. I don't know what the plan or the level of co-ordination is to overcome those," Carey said.

------

Weissert reported from Harlingen, Texas. Associated Press writers Ricardo Alonso-Zaldivar in Washington; Gene Johnson in Seattle; Robin McDowell in Austin, Texas; Amy Taxin in Santa Ana, California; and John Antczak in Los Angeles contributed to this report.