NHS Scotland faces a staffing crisis unless workforce planning is dramatically improved, the public spending watchdog has warned.

Audit Scotland said urgent changes were needed if the health service is to have sufficient staff to meet future demands.

The watchdog said that despite increasing numbers of staff - the NHS employed the equivalent of 139,431 full-time workers at the end of March 2017 - there are still "major issues to be addressed".

Opposition politicians and organisations representing doctors and nurses have repeatedly highlighted pressures many health workers can face.

Audit Scotland has now warned there may not be enough staff to meet the challenges presented by an ageing population and recruitment difficulties.

Its report said: "Processes for determining training numbers risk not training enough doctors, nurses and midwives with the right skills for the future.

"Medical recruitment numbers are based on replacing current numbers rather than looking at the impact of changing demand."

Spending on NHS staff amounted to £6.5bn in 2016-17, accounting for 57% of day-to-day running costs.

In the period between 2011-12 and 2016-17, the cost of bringing in agency staff increased by 107%, going from £82.8m to £171.4m.

One in three staff in NHS Scotland are aged 50 or above, the report said, adding "upcoming retirements may increase vacancy levels in parts of the NHS where the age profile of the staff is older".

While the number of staff in the NHS is at a record high, the watchdog said the Scottish Government and health boards "have not planned their NHS workforce effectively for the long-term".

Major reforms are taking place to allow more people to be cared for at home or in their local community but Audit Scotland said funding for this "does not clearly identify associated workforce costs".

Caroline Gardner, auditor general for Scotland, said: "Thousands of people work hard in Scotland's NHS to deliver vital public services every day but there are signs that the health service is under stress and that staff face increasing workload pressures.

"The Scottish Government and NHS boards recognise the challenges but urgently need to improve their understanding of future demand, staff projections and associated costs, and set out in detail how they plan to create a workforce that can meet the long-term health needs of the population."

Theresa Fyffe, director of the Royal College of Nursing Scotland (RCN), said: "The RCN has warned for some time that the Scottish Government has failed to future-proof NHS Scotland's workforce.

"Today's report echoes that sentiment and impresses upon the Scottish Government, NHS boards and integration authorities the urgency with which workforce planning now needs to be addressed."

Labour's Anas Sarwar claimed the report was "absolutely damning".

"It reinforces our warnings that the SNP has presided over a workforce crisis in our NHS, leaving staff over-worked, under-valued and under-resourced," he said.

Health secretary Shona Robison said the Scottish Government was committed to having "the right number of staff" as well as "the right mix of skills".

She added: "The first part of our National Health and Social Care Workforce Plan, published last month, sets out how we will recruit, develop and retain the flexible, multidisciplinary workforce we need.

"It shows how we'll improve national, regional and local workforce planning. We are also committed to enshrining safe and effective staffing for our NHS in law.

"Ensuring effective workforce planning not only has to account for changes in the nature of the demands being placed on our health and care services, but also for the challenges that are presented by external factors like the impact of Brexit on Scotland's ability to attract and retain workers from across Europe."