Image copyright Reuters Image caption Mr Mackay had been widely tipped as a future first minister

Scotland's finance secretary has quit hours before delivering his budget amid reports that he messaged a 16-year-old boy on social media.

The Scottish Sun said that Derek Mackay contacted the schoolboy over a six-month period, and told him that he was "cute".

Mr Mackay said he had "behaved foolishly" and took full responsibility for his actions.

He also apologised "unreservedly" to the boy and his family.

First Minister Nicola Sturgeon said she did not know about Mr Mackay's "unacceptable" behaviour until Wednesday evening, and is "not aware of any further allegations" against him.

In a statement to the Scottish Parliament, she confirmed that he has been suspended by the SNP while further investigations are carried out.

Media playback is unsupported on your device Media caption Nicola Sturgeon: “It was unacceptable and falls seriously below the standard required of a minister."

Police Scotland said it had not received any complaint of criminality, but was "assessing available information from media information". The force also asked for anyone with any information to contact them.

Interim Scottish Conservative leader Jackson Carlaw called on Mr Mackay to also stand down from the Scottish Parliament, saying his behaviour could "constitute the grooming of a young individual".

And Scottish Labour leader Richard Leonard said Mr Mackay's actions had been "an abuse of power" and "nothing short of predatory".

This is a calamity, without caveat, for Derek Mackay, for the SNP, for the first minister and for the collective Scottish government.

One must also express sympathy for the youth who apparently received unwarranted and unwanted attention, together with his family.

Not only was Derek Mackay a key member of the Scottish cabinet, with responsibility for finance and the economy, he had also been tipped as a possible successor to Nicola Sturgeon.

To be amply clear, there is no such vacancy at present.

But all of this comes amid an amalgam of challenges for the Scottish government and the SNP.

Challenges over public policy, most notably in education and the NHS. Internal disquiet over how to proceed with indyref2. And a pending High Court trial.

Read more from Brian

The newspaper detailed allegations that the 42-year-old politician contacted the boy "out of the blue" in August of last year and sent about 270 messages on Instagram and through Facebook.

It has published a list of messages - the most recent of which is from earlier this week - involving Mr Mackay and the boy, in which its says the MSP invited him to dinner and to attend a rugby event.

The newspaper also reported that Mr Mackay contacted the boy several times on Christmas Day, and told him on another occasion that he was "looking good with that new haircut".

In one of the exchanges, Mr Mackay is said to have told the teenager he was "cute". In another the boy confirmed he was 16 and tells Mr Mackay "not to try anything".

The paper also quotes the boy's mother calling for Mr Mackay to be removed from his post.

Media playback is unsupported on your device Media caption Scottish Sun political editor: 'The family are not baying for blood'

Chris Musson, the political editor of the Scottish Sun, spoke to the Podlitical podcast about how the newspaper broke the Derek Mackay story, and what the boy and his family wanted to achieve by going public.

Listen to the full episode here

In a statement released on Thursday morning, Mr Mackay said: "I take full responsibility for my actions. I have behaved foolishly and I am truly sorry. I apologise unreservedly to the individual involved and his family.

"I spoke last night with the first minister and tendered my resignation with immediate effect.

"Serving in government has been a huge privilege and I am sorry to have let colleagues and supporters down."

Image caption Nicola Sturgeon speaks to the media at Holyrood

Mr Mackay, who has been widely tipped as a future first minister, came out as gay when he left his wife in 2013.

His resignation came just hours before he was due to present the Scottish government's spending plans for the next year - a major set piece event in the Scottish Parliament.

Mr Mackay would have been putting the finishing touches to his preparations to his £43bn budget when he was contacted by the Scottish Sun on Wednesday evening, before the newspaper released the story at 23:20.

The budget was presented instead by public finance minister Kate Forbes.

What is 'grooming' and how is it defined in Scots law?

Children and young people can be groomed online or in person by someone they know - or a stranger who may hide their real identity and age.

Building trust is a key tactic in grooming, and this can be appearing to have the same interests as the young person such as games and apps and offering advice or showing empathy and understanding. It can also involve invitations to events, taking them on trips or even holidays.

Grooming was defined in Scots law as a criminal offence by the Protection of Children and Prevention of Sexual Offences (Scotland) Act 2005.

It said an offence is committed if someone meets a young person who is under 16, having met or communicated with them with the intention of engaging in unlawful sexual activity. The maximum penalty for the offence is 10 years imprisonment.

There has been no suggestion in the Scottish Sun's story that Derek Mackay communicated with the boy when he was under the age of 16.