Media playback is unsupported on your device Media caption Nicola Sturgeon has welcomed the progress in Brexit talks

Scotland's first minister has described the last-minute deal on Brexit between the UK and EU as a "welcome step forward in the negotiations".

But Nicola Sturgeon warned the next stage of the talks, which will focus on trade arrangements after Brexit, will be "significantly tougher".

She called for the UK to stay in the single market and customs union.

And she said any special arrangements for Northern Ireland must also be available to the other UK nations.

Ms Sturgeon had earlier tweeted that the agreement on the Irish border meant that the UK government could "never again tell Scotland that independence would mean a hard border" between Scotland and the rest of the UK.

Her comments were in response to European Commission President Jean-Claude Juncker confirming that sufficient progress had been made in the Brexit talks for the negotiations to progress onto the future relationship between the UK and EU.

Skip Twitter post by @NicolaSturgeon Move to phase 2 of talks good - but devil is in the detail and things now get really tough. If #Brexit is happening (wish it wasn’t) staying in single market & customs union is only sensible option. And any special arrangements for NI must be available to other UK nations. — Nicola Sturgeon (@NicolaSturgeon) December 8, 2017 Report

Skip Twitter post 2 by @NicolaSturgeon An aside - a UK government that is able to say that come what may, it will avoid hard borders with Ireland/NI after Brexit can never again tell Scotland that independence would mean a hard border between Scotland and rUK — Nicola Sturgeon (@NicolaSturgeon) December 8, 2017 Report

The prime minister, Theresa May, is in Brussels following overnight talks on the issue of the Irish border, which had scuppered a deal on Monday.

Mrs May said there would be no hard border and the Good Friday Agreement would be upheld.

And she said the three million EU citizens in the UK "will be able to go on living as before".

The BBC understands that the so-called "divorce bill" paid by the UK will amount to between £35bn and £40bn.

Media playback is unsupported on your device Media caption The prime minister said the deal will allow more to be invested in "priorities at home"

What has been agreed?

Guarantee that there will be "no hard border" between Northern Ireland and the Republic maintaining "constitutional and economic integrity of the United Kingdom"

EU citizens living in the UK and vice versa will have their rights to live, work and study protected

Financial settlement which is "fair to the British taxpayer"

Read the full text of the agreement here

In a statement, Ms Sturgeon stressed that the Scottish government still wished that Brexit was not happening, but said the agreement on the first phase of the talks was a "welcome step forward in the negotiations".

She later told BBC Scotland: "The fact it has involved total capitulation by the UK government on all their red lines suggests that it should have happened a long time ago instead of allowing valuable negotiating time to be wasted.

"But nobody should be under any illusions - this has been the supposedly easy part of the Brexit negotiations. Moving into the trade talks will be much, much tougher and involve much more complex issues."

Special status

The first minister welcomed the agreement on Ireland, but said any special status for Northern Ireland within the single market would also need to apply to Scotland to avoid Scottish businesses being "doubly disadvantaged".

And she said the "least damaging option" would be for the UK to remain permanently in both the single market and customs union - something Mrs May has previously ruled out.

Ms Sturgeon said: "Given that the UK government appears to have been capitulating on all of its red lines up until now, I hope that that common sense position starts to prevail".

Image copyright Reuters Image caption The agreement was confirmed by Mrs May and Mr Juncker in Brussels on Friday morning

Ms Sturgeon said: "I am absolutely clear that any special arrangements for Northern Ireland must now be available to other nations of the UK - the Scottish government will not accept any arrangements which risk putting Scotland at an economic disadvantage.

"Short of continuing EU membership, the best outcome for jobs and living standards is to retain membership of the single market and customs union - both in transition and permanently."

The announcement was also welcomed by the UK government's Scottish secretary, David Mundell, who tweeted that Mrs May had "put the national interest first" in securing a deal that "protects the integrity of UK but acknowledges existing North-South Irish arrangements".

'Integrity of the UK'

But he said Ms Sturgeon's tweet on the Irish border deal was "proof if it was ever needed that for @NicolaSturgeon everything, however serious, is about independence. For her #Indyref2 is never off the table".

Scottish Conservative leader Ruth Davidson said the Brexit announcement was "a real step forward", and that the agreement "ensures the integrity of the UK".

And Scottish Labour leader Richard Leonard said the priority should now be to secure "barrier free access to the single market".

What happens to the border between Northern Ireland and the Republic of Ireland had been among the key sticking points in Brexit negotiations, with talks breaking down on Monday when the Democratic Unionist Party objected to draft plans drawn up by the UK and the EU.

The DUP - whose MPs prop up Mrs May's minority Conservative government - did not want Northern Ireland to be treated differently to the rest of the UK.

The joint report agreed by Mrs May and Mr Juncker states that, if a trade deal cannot be agreed, the UK will maintain "full alignment" with elements of the EU single market and customs union mentioned in the Good Friday agreement.

That means on issues such as agriculture and energy the whole of the UK would continue to abide by EU rules.

DUP leader Arlene Foster said on Friday she was "pleased" to see that there was now "no red line down the Irish Sea".

But the DUP said there was still "more work to be done" and how it votes on the final deal "will depend on its contents".

The EU's chief negotiator, Michel Barnier, said the agreement reached on Friday was a "turning point" in the talks, and could be the basis of the final withdrawal agreement - which will need to be in place by October 2018.

The UK is due to leave the EU in March 2019, and has been keen to open talks on a new free trade deal as soon as possible.

But the EU would only agree to discuss this when it judged that enough progress has been made on the "separation issues" - the "divorce bill", expat citizens' rights and the Northern Ireland border.

There had been considerable pressure to try to settle the Northern Ireland border issue before EU leaders meet next week.