Media playback is unsupported on your device Media caption Nick Kwek toured the border dividing the US state of Arizona and Mexico's Sonora

Democratic and Republican negotiators are working into the night to try to reach a deal on border security and avoid another government shutdown.

They remain divided on the detention of undocumented immigrants and on funding for President Donald Trump's promised border wall with Mexico.

Mr Trump said on Monday "it is up Democrats" to make a deal or take the blame for a renewed shutdown.

The previous shutdown lasted 35 days and was the longest in US history.

Congress has until Friday to pass legislation before the current federal funding agreement runs out. The previous shutdown ended on 25 January as lawmakers agreed to negotiate.

If a new agreement is not reached by both the House of Representatives and the Senate - and signed by the president - a partial government shutdown will begin again on Saturday.

During the last shutdown, hundreds of thousands of workers were furloughed (put on unpaid leave) in December and January while others in essential services, such as hospital care, air traffic control and law enforcement, worked without pay.

Mr Trump approved a congressional measure to pay back federal workers last month, but many say they have yet to receive their paycheques, according to US media.

It remains unclear whether contracted workers will get any such payments.

The shutdown's cost to the US economy was estimated at $11bn (£8.5bn).

The talks are taking place in Washington, just as President Trump is about to hold a rally in the border city of El Paso, in Texas, aimed at gathering support for the border wall.

Democratic Senator Patrick Leahy and Republican Senator Richard Shelby said they hoped to strike a deal on Monday.

Sen Leahy said the goal was to "wrap this up tonight, do it tonight and not tomorrow".

What is the latest impasse about?

Some 17 Republican and Democratic negotiators from the Senate and the House have been holding talks to try to reach a border security agreement that can be accepted by Congress.

The latest impasse seems to be centred on a Democratic demand to limit the number of undocumented migrants already in the US who can be detained by Immigration and Customs Enforcement (ICE).

Democrats want to cap the number of beds at detention centres reserved for those cases at 16,500.

By doing that, they hope to force ICE to focus on detaining irregular migrants with criminal records instead of those who have overstayed their visas and, Democrats say, are productive and offer no threat.

Media playback is unsupported on your device Media caption Other presidents got money for a border barrier - why not Trump?

ICE Deputy Director Matt Albence said on Monday that the proposal would be "damaging to public safety".

"This is a crucial public safety issue… There really shouldn't be a debate about us taking dangerous criminals and immigration violators off the street and out of our communities," he said during a White House conference call with reporters.

On Monday, Mr Trump tweeted that the "Democrats do not want us to detain, or send back, criminal aliens! This is a brand new demand. Crazy!."

During a later White House event before his departure for Texas Mr Trump continued the attack: "Not only don't they want to give us the money for the wall, they don't want to give us the space to detain murderers, criminals, drug dealers, human smugglers."

The Democrats are also looking at between $1.3bn and $2bn in funding for Mr Trump's proposed border wall, a long way off the $5.7bn the president has been demanding.

President Trump tweeted that "angry" Democrats needed to "loosen up and have some fun".

The president had earlier said that Democrats were "behaving, all of a sudden, irrationally".

What is the situation at the border?

As wall discussions labour on, Mr Trump plans on sending more than 3,700 active troops to the US-Mexico border to help agents with security efforts this month. With more than 2,000 troops already at the border, the new deployment would top November's mid-term election-time numbers of 5,900.

Meanwhile, pushing back against the Trump administration's call for border states to help with security, California's Democratic Governor Gavin Newsom has recalled hundreds of the state's national guard from the border.

Gov Newsom's move follows that of his Democratic colleague, Gov Michelle Grisham of New Mexico, who pulled her state's troops from the border last week.

Both governors have cited the withdrawal as retaliation against Mr Trump's "fear-mongering".

Why is there the risk of another shutdown?

On 25 January, President Trump agreed to a three-week spending deal to end the shutdown and allow Congress to reach an agreement.

That funding ends at midnight on Friday. Another short-term deal could prevent a new shutdown, according to the New York Times.

Mr Trump made building a wall on the border with Mexico one of his key promises in the 2016 campaign.

The president has backed away from calls to make Mexico pay for a concrete wall but during his State of the Union speech last Tuesday - delayed because of the previous shutdown - he insisted on a "smart, strategic, see-through steel barrier".

Media playback is unsupported on your device Media caption Just why did the US government partially shut down?

He has previously threatened to declare a national emergency and fund the wall without Congress. But this idea is disliked even by some fellow Republicans, and Democrats are likely to challenge it in the courts.