After years of close ties with President Donald Trump, Mexico must now reshape its complex relations with the United States under Joe Biden, the president-elect, including on the key issues of trade and immigration. The country's awkward position was underscored by President Andres Manuel Lopez Obrador's reluctance on Saturday to congratulate Mr Biden while Mr Trump is still mounting a slew of legal challenges. The left-wing populist said he would wait for "all legal issues" in the US presidential election to be resolved. "We don't want to be imprudent. We don't want to act lightly," Mr Lopez Obrador told a news conference. "We have a very good relationship with the two candidates," he said, as messages of congratulations for Mr Biden and Kamala Harris, the vice president-elect, poured in from other world leaders. Mr Trump sparked anger during his 2016 election campaign when he branded Mexican migrants "rapists" and drug dealers and vowed to build a wall across the southern US border. Even so, Mr Lopez Obrador maintained cordial relations with Mr Trump, and experts say that the presidency of Mr Biden will bring a different set of challenges for Mexico. "Trump's anti-Mexican rhetoric is very unpleasant, but in fact, there were important agreements," said Miguel Angel Jimenez, an analyst at the Mexican Council on Foreign Relations, told the Agence France-Presse. "The relationship with the Democrats has always been cold and Biden could keep more distance." Mexico has previously gained more from Republican administrations, such as the immigration amnesty granted by Ronald Reagan and the Nafta free trade agreement negotiated under George HW Bush, Mr Jimenez said. Mr Lopez Obrador's cautious reaction to Mr Biden's win reflects his close relationship with Mr Trump and the fact that the Republican still has weeks left in office, he said. "It's an unpleasant situation for the Mexican government," Mr Jimenez said. The Mexican leader chose to visit Mr Trump in the US in July on his first foreign trip since taking office. Mr Lopez Obrador's close ties with Mr Trump mean his defeat "could be a political setback," said Gabriela Siller, an analyst at Banco Base. "Biden already omitted Mexico when congratulating Latin American countries celebrating their independence" anniversaries in September, she said. While Mr Biden is unlikely to make any radical policy announcements concerning Mexico, his victory could still have repercussions, particularly in trade, analysts said. The renegotiation of the trade agreement between the US, Canada and Mexico was the climax of a complicated relationship with Mr Trump. The future of the US-Mexico-Canada Agreement (USMCA), which entered into force in July, replacing Nafta, is a major concern for Mexican authorities as Mr Biden prepares to move into the White House. "Trump already did what he wanted with Mexico, the risk with him would be less," said Ms Siller. Ms Harris "was an opponent of USMCA and they could put obstacles in its path", she said. The Democrats are expected to demand punctual compliance with labour reform that they requested in return for approving the agreement with the key trading partner, Mr Jimenez said. Last year, Mr Trump threatened to slap tariffs on imports from Mexico if it did not stop a wave of Central American migrants heading overland to the US. Even if Mr Biden cancels Mr Trump's planned construction of a border wall, strict restrictions against undocumented migration will continue, said Maria Dolores Paris Pombo, an expert at the Colegio de la Frontera Norte in Tijuana in north-west Mexico. He may revive a programme put in place by then-president Barack Obama in 2012 to regularise the immigration status of hundreds of thousands of young people, known as "dreamers," who had arrived illegally as children. Mr Biden has fiercely criticised Mr Trump's efforts to shut down the Deferred Action for Childhood Arrivals (Daca). But previous Democratic administrations have also applied laws passed in the late 1990s criminalising undocumented immigration, Paris Pombo said. "Barack Obama's administration was tougher in terms of the number of deportations, but without the media impact or levels of Trump's cruelty," she said.