Image caption The children separated included babies that could not speak properly

More than 700 migrant children taken from their parents at the US border with Mexico remain in federal custody, despite a court-ordered deadline on Thursday to reunite them. Bringing the distraught families together has proved chaotic.

The journey from Guatemala through the Mexico desert had been "Todo bien, gracias a Dios" (all fine, thanks to God) and, in May, Lilian Martinez Lopes finally crossed into the United States carrying her only son, aged five.

The 24-year-old, who had planned to seek asylum here, did not speak a word of English and hoped Google Translate would help in her new life. Her husband had come four years earlier and they planned to reunite in Houston, where he now lived.

Then the immigration agents came to her. "They told me, 'We'll take your son to a shelter.'" She was surprised. Nobody had told her that migrant families caught crossing illegally were being separated, part of a "zero-tolerance" policy of the Trump administration.

She had little time to say goodbye. "Don't let them take me," Ms Martinez recalled her boy plead. "But what could I do?" Crying, she watched him go.

Image caption Many of the children separated could not mention the countries they came from or explain their cases

"I didn't know we'd be separated," Ms Martinez said. "If I knew it I wouldn't have come."

The more than 2,500 separations were often traumatic. Shouting officers caught people by surprise and took scared children from their parents in the middle of the night, activists said. One mother in Texas said agents had told her the migrants were criminals and the children would be given up for adoption, leaving her in panic.

Adding to the chaos was the fact that adults and youths had to go through two separate immigration systems. In theory, they received the same identification number, known as A-file, which would make it easier for them to be located. That, however, was not the case for everyone. Some families had different numbers; others no number at all.

Media playback is unsupported on your device Media caption Mother in Texas: 'It's been 50 days since I heard of my son'

Ms Martinez was taken to Arizona's Eloy Detention Center, operated by Immigration and Customs Enforcement (ICE), part of the Department of Homeland Security. Her son, now classified as an unaccompanied minor, was in the care of the Office of Refugee Resettlement, a division of Health and Human Services, and had been sent to one of the many shelters across the country.

She just did not know where.

To help the migrants navigate the mess, non-profit groups and volunteers played detective. With no official protocols in place, they tried, first, to guess the A-file of the parent based on the number of the child. If this failed, they looked at where they crossed the border to call detention facilities. "It [was] hard to describe the level of uncertainty and fear," said Megan McKenna, senior director of communications at Kids in Need of Defense (Kind).

For many, it felt a bit like a cat-and-mouse game.

Image caption The parents are being released with electronic ankle monitors

"I prayed to God to help me. I had to be strong because of my son," Ms Martinez said about her time in custody. Despite the network of support the mothers had built - "They told me, 'Don't get depressed, your son needs you'" - the uncertainty was driving some of them desperate.

People had given up on their asylum requests and agreed with voluntary deportations believing this would speed up the reunifications, despite no proof of that, according to advocacy groups. They said some were pressured to sign papers they could not read or were not being told of all their rights. (Officials said 431 parents had left the country, without specifying if their departures were voluntary or not, and could not be reunited for now.)

Ms Martinez, however, felt lucky in a way as she had been able to call her son a few times. Many at her prison and elsewhere waited for weeks to hear from their children.

"[My son] told me 'Mami, I love you.' He said he was behaving well and that he cried for me every night." Ms Martinez said she had told him not to, but he said he would anyway, that he missed her. "When I talked to him, I kept myself under control. But later I'd collapse crying... You can only imagine what went through my mind to hear these words."

Yet she still did not know where he was. All she had was a picture of him with a number annotated by pen on its back and something else that she could not understand. "I told [the officers] that I needed to call my husband," her main bet to locate their son. "I begged to them. But they said, 'No, you have to wait.'"

Media playback is unsupported on your device Media caption The BBC has captured the first drone footage of the "tent city" in Tornillo, Texas

At the heart of the policy, which the Trump administration maintained was necessary to deter illegal immigration, was a decision to prosecute all adults with irregular entry in the country. (Despite the criticism towards the separations, the president's crackdown on illegal immigration enjoys strong support, especially among conservatives.)

Given the mammoth task, cases were being heard in groups in courtrooms at the border.

One morning in McAllen, Texas, in June a judge welcomed at once about a dozen men, aged between 20 and 50. One tried to ask him in broken English where his children were, in vain. The shelters for the minors included caged areas separated by chain-link fencing, warehouses and desert tents in places where temperatures regularly reach 40C (105F). Some later said they were forced to clean bathrooms as part of the rules.

Another man cried to the judge saying he did not care if he got deported as long as he had his son back. Pleas like this had become so common that those who witnessed it were apparently left untouched.

Media playback is unsupported on your device Media caption Trump supporters talk family separations and border security

With their parents in custody, children, including toddlers, were forced to appear by themselves in hearings, many unable to properly explain their stories let alone understand proceedings. They were often seen crawling around or playing with a pen, said Lisa LeSage, a lawyer from the non-profit group Immigration Counseling Service.

"Even a five-year-old who wasn't traumatised can't always tell you their address or what their parents look like or their last names. How do you expect a child to do all that?"

And so, there were those who could not say which country they came from. Others did not even know what a lawyer was. "It [was] horrific," Ms LeSage said. Outrage grew even bigger when, days later, an audio emerged, reportedly from a border facility in which children cried for their parents. An agent joked: "We have an orchestra here."

Read more on US immigration

The Trump administration, at first, stuck by its policy, defying critical media coverage, uproar from activists and politicians, and protests across the country. Even First Lady Melania and Mr Trump's daughter, Ivanka, were said to be against the policy. A visit by Melania to a shelter meant to be a show of solidarity became another source of discord when she wore a jacket emblazoned with the slogan, "I really don't care do u?"

Ms Martinez was losing hope that any official help would come to her. "Even when we asked about the time or the day, [the officers] didn't give us any answer. They told us: 'Why do you want to know it?'"

Hearing her son cry on their calls made her wonder how he was processing it all. Health experts were concerned that the children's immune systems, the development of their brains and even their personalities could be affected. They were also said to be at greater risk of suffering from long-term psychological conditions like post-traumatic stress disorder or heart disease and diabetes later in life.

"This is really extreme, it's nothing like we have seen before," said Michelle Brané, director of Migrant Rights and Justice at the Women's Refugee Commission, a New York-based non-governmental organisation. "It's like torture."

With domestic and international fury growing and a number of legal challenges, Mr Trump - who initially tried to blame Democrats for the measure - was forced to reverse his own policy. (He insisted, though, that people should come to the US legally.) Judge Dana Sabraw, from San Diego, California, then gave the administration 30 days to reunite all the families.

A "Herculean task", said Tony Martinez, mayor of the border city of Brownsville, Texas.

Media playback is unsupported on your device Media caption The sound of migrant children separated from parents

Weeks after being detained, Ms Martinez was finally given an indication of where his son could be, when a social worker told her that what she had on the picture was the name of a shelter in Houston. (The number was their A-file.) But her case was not a priority. Judge Sabraw ruled that those under the age of five were to be sent to their families first.

The usual method of identifying the children involved going through all birth certificates, which would take a very long time. Officials, under enormous pressure to meet the deadlines, said even DNA tests were to be carried out. Many saw there a proof that there was no clear policy in place.

Then came a breakthrough for Ms Martinez. Her asylum request was deemed credible - criteria includes proving fears of persecution in an applicant's home country. She was ready to search for her son.

As the adults were being released with electronic ankle monitors, non-profit groups, again, provided help. Immigrant Families Together (IFT), a movement that assists detained families, raised $50,000 (£38,000) to pay for Ms Martinez's $25,000 bail and cover her expenses. (Reports said people had left custody without anywhere to stay, or unable to pay for transportation costs.)

"It was a surprise [when they said,] 'You can go.' I cried. I couldn't believe it."

Image caption Health experts have warned of the psychological impacts the separation could have on the children

When Ms Martinez was released earlier this month, Dionne Ukleja, a volunteer with IFT, picked her up. They went to a nearby department store to buy her some clothing and other essentials. Later, as they met, Ms Martinez gave the photograph she had to a lawyer who came with Ms Ukleja and a translator.

On Google, they searched for the word written on the picture only to find out that the shelter was in a different city, some three hours away in southern Texas. Ms Martinez, who had felt she was about to see her son again, was left devastated.

The volunteers drove her and her husband, who had now joined them, to Corpus Christi. They called the local press and other activists to follow the reunification but when they arrived at the shelter they were perplexed: nobody would receive them. Many parents had already complained about the difficulties of contacting those who had taken the minors, complicating their efforts even further.

The shelter's supervisor eventually came to meet them, and reported Ms Ukleja to the police, angry that people were filming the property. (They were also live tweeting it.) Sometime later Ms Martinez was allowed to enter the building. She came back sobbing and silent. The translator who had gone with her broke the news to those outside.

"The son is not here. They don't know where he is." They were back at square one.

Media playback is unsupported on your device Media caption Cisary Reynaud has not spoken to his daughter since they were separated

As other families were slowly being reunited, pain was already giving space to relief while they tried to readapt their lives. There were, however, stories of those who blamed their parents for the separation or could not recognise their own mothers and fathers.

For Ms Martinez, the question was still, where could her son be. They called the social worker who had said her son was in Houston. It was a weekend and the worker said there was nothing she could do. Ms Ukleja was left fuming. They kept calling her, but she stopped answering the phone.

When she replied, she gave them a different number, of her supervisor. Getting in touch with her was also difficult but when they reached her, she gave them something new. Her son was in foster care. They did not know what to do. Ms Martinez had everything: his birth certificate, her bail paper, the A-file numbers connected in the system. Still, it seemed almost impossible to be reunited with her son.

As they met in a cafe to discuss their options, Ms Ukleja's phone rang. It was another social worker, who gave them an address, of the local Health and Human Services office, and said her son's documents were ready. He was, in fact, already waiting for his mother.

When they met, they hugged each other for a long time, exchanged kisses and cried together. "It was amazing and heart warming," Ms Ukleja said.

Image caption Many of the families face now an uncertain and lengthy legal process

Even now, there is little clue of what comes next. Officials said more than 1,800 migrants children were reunified with their families. They now faced a lengthy and tortuous legal process to determine their asylum requests, and many could end up being deported. Children whose parents were no longer in the US were likely to be sent to a relative in the country or placed in foster care. A few may never see their parents again.

Ms Martinez and her family were still adjusting to their new lives. Her son often had nightmares and feared he could be taken away again. It was not being easy for her either.

"It was the greatest pain one could suffer," she said. "Children are sacred. You do not play with them."

With reporting by the BBC's Aleem Maqbool, Haley Thomas and Miguel Amaya in Houston; Angélica M Casas in McAllen, Texas; Colleen Hagerty in Phoenix; Jessica Lussenhop and Ritu Prasad in Washington; pictures by Alejandra S Casas in McAllen

Follow Hugo on Twitter: @hugobachega