Image copyright Getty Images Image caption US troops are part of a Nato-led mission to train and assist Afghan forces

The Trump administration is planning to withdraw thousands of troops from Afghanistan, US media say.

Reports, citing unnamed officials, say about 7,000 troops - roughly half the remaining US military presence in the country - could go home within months.

The reports come a day after the president announced the country's military withdrawal from Syria.

Earlier on Thursday, Mr Trump's Defence Secretary Jim Mattis announced his resignation from his post.

Reports about the sharp reduction of forces emerged on Thursday, but have not been confirmed by US defence officials.

Analysts have warned that a withdrawal could have a "devastating" impact and offer Taliban militants a propaganda victory.

A Taliban official told AFP news agency: "Frankly speaking, we weren't expecting that immediate US response... we are more than happy."

The Taliban - a hardline Islamist movement that carries out frequent suicide bombings and attacks against government and military targets - is active in much of Afghanistan.

They ruled Afghanistan from 1996-2001, imposing a brutal version of Sharia law, including public executions and amputations, and banned women from public life.

Why is the US in Afghanistan?

The US has been in Afghanistan since 2001, after the 11 September attacks. It is the longest war in US history, and has claimed more than 2,300 American lives.

When the Taliban, who controlled Afghanistan, refused to hand over al-Qaeda leader Osama Bin Laden - who said he had organised the 11 September attack - then US President George W Bush launched a military operation to find Bin Laden and remove the Taliban from power.

US special forces eventually found and killed Bin Laden in Pakistan in 2011. American-led combat operations in Afghanistan officially ended in 2014.

Image copyright AFP Image caption US troops have been in Afghanistan for 17 years

But in the years since then, the Taliban's power and reach have soared - and US troops have stayed on the ground in an effort to stabilise the country.

Before his election, Mr Trump repeatedly publicly advocated leaving Afghanistan, describing it as a waste of money.

However, last year he indicated he would keep boots on the ground indefinitely to prevent the country's collapse, and said the US would send 3,000 extra troops to the country.

Does Afghanistan need the US?

Afghan officials have insisted they are not concerned about the reported withdrawal.

"The fact that a few thousand foreign troops whose roles are primarily advisory and technical support will exit from Afghanistan will not have an impact on security situation," presidential spokesman Harun Chukhansori told the BBC's Afghan service.

He added that "Afghan security forces have had full responsibility of security affairs" since 2014.

However, a recent US military report says Taliban control over Afghanistan has increased in recent months, and the government currently controls or influences only 55.5% of the country's districts - the lowest level recorded since it began tracking the data in 2015.

Earlier this week, Afghan President Ashraf Ghani emphasised that Afghan security forces had borne the highest casualties in the battle against the Taliban.

"We are not only dying for our own freedom, but for your security," he told the BBC's Today programme. "The daily operations, the fighting and the dying is done by us."

He added that his country did not want "charity" from the US, but a "partnership that is meaningful".

"Countries don't have permanent friends or permanent enemies, they have permanent interests," he said. "The US is here because of its global and national security interests."

A positive sign for the militants?

By Auliya Atrafi, BBC Afghan service, Mazar-e Sharif

On the frontline of the conflict in the north, there's been no let-up in the fighting, even though peace talks have been going on.

Security forces I spoke to here said they wouldn't feel the effect of pulling out 7,000 US troops, as long as the US continued its weapon of choice - air support.

They may have a point. More than 100,000 US troops were withdrawn in 2014. Since then, Afghan forces have had responsibility for security - but they have also lost lots of ground.

While any US troop reduction might not affect current anti-Taliban operations, it would be seen as a positive hint to the militants who have been demanding all US troops leave.

Thousands of Afghans displaced by the war fear they may never return home. For them and many others, a withdrawal would be welcomed if it helped peace talks.

What reaction has there been?

The Washington Post reports the potential move is being met with opposition by some of Mr Trump's senior cabinet officials, including outgoing White House Chief of Staff John Kelly and National Security Adviser John Bolton.

Republican Senator Lindsey Graham said the withdrawal could pave the way towards "a second 9/11".

Image copyright Getty Images Image caption Earlier this year, the Taliban claimed a suicide bomb attack outside a compound in Kabul

"The conditions in Afghanistan make American troop withdrawals a high risk strategy," he said on Twitter. "We are setting in motion the loss of all our gains."

Meanwhile, Michael Kugelman, deputy director of the Asia programme at the US think-tank Wilson Center, said the impact of the withdrawal could be "devastating" and "would be a soaring propaganda victory for the Taliban, as it could boast that it managed to expel US troops even without a peace deal".

"It [would also] be a major psychological blow for Afghan forces. They have struggled mightily and [this] would be quite demoralising," he told the BBC.

It appears that US allies were not made aware of the potential withdrawal.

The UK's chief of the defence staff, General Sir Nick Carter, spoke to the BBC's Today programme during a visit to Afghanistan this week, before the latest media reports emerged.

He told the BBC: "Everything I've seen during my visit over the last 24 hours would suggest they're wholeheartedly committed to this mission, as is Nato and the international community."

Is this why General Mattis quit?

In his letter of departure on Thursday, General Mattis strongly hinted at policy differences with the president, but did not cite troop withdrawals directly.

The possibility of withdrawing from Afghanistan could have been a factor but the Syria withdrawal was likely to have been the "main trigger", says Mr Kugelman.

However, the general's departure is likely to have an impact on the Trump administration's future Afghan policy.

Image copyright Getty Images Image caption A successor will take over from General Mattis in February

"He's one of the only remaining senior officials in the administration who supports a continued US military presence in Afghanistan," said Mr Kugelman.

"Now that Mattis is on his way out, Trump will face even less resistance in his decision to withdraw troops."