Middle-class Afghans turned jihadists have assisted the Islamic State group's expansion from its stronghold in Afghanistan's restive east to Kabul, analysts say, helping to make the capital one of the deadliest places in the country.
IS has claimed nearly 20 attacks across Kabul in 18 months, with cells including students, professors and shopkeepers evading Afghan and US security forces to bring carnage to the highly fortified city.
It is an alarming development for Kabul's war-weary civilians and beleaguered security forces, who are already struggling to beat back the resurgent Taliban, as well as the US counter-terrorism mission in Afghanistan.
"This is not just a group that has a rural bastion in eastern Afghanistan - it is staging high casualty, high visibility attacks in the nation's capital and I think that's something to be worried about," said analyst Michael Kugelman of the Wilson Center in Washington.
The Islamic State-Khorasan Province (IS-K), the Middle East group's affiliate in Afghanistan and Pakistan, emerged in the region in 2014, largely made up of disaffected fighters from the Taliban and other jihadist groups in Afghanistan, Pakistan and Central Asia.
It claimed its first attack in Kabul in the summer of 2016. Since then the Sunni group has struck at security forces and Shiites with increasing frequency, helped by its growing network in the capital.
There is no shortage of recruits, analysts say. IS has successfully tapped a rich vein of extremism in Afghanistan that has existed for decades and crosses socio-economic groups, fanned by growing internet access among urban youth.
"We are talking about a generation which has been desensitised to different types of violence and violent extremism," said Borhan Osman, a senior analyst with the International Crisis Group.
"It should not come as a surprise that some of the youth inculcated in the ideology of jihadism embrace the next version of jihadism, the most violent one."
Members and supporters of IS cells in Kabul hide in the open, living with their families and going to classes or work every day, Osman said.
The militants meet at night to discuss jihad, or holy war, and plot attacks on targets in the city they know well - well enough to adapt to changes, such as tightened security in the wake of a massive truck bomb in May that killed around 150 people.
"It's an adaptive structure reacting to the counter measures," a Western diplomat told AFP.
"From May to December what we have seen is different types of attacks, smaller attacks that are getting through."
An Afghan security source previously told AFP that "20 or more" IS-K cells were operating in the city.
Osman, an expert on militant networks in Afghanistan, said it was difficult to know how many IS-K fighters were in Kabul but their ranks were constantly being replenished by the group's recruitment efforts on social media as well as in universities, schools and mosques.
"You can't say they are all poor - a number of them come from middle-class Kabuli families. Some are university educated. Some have a high school education," he said, adding that most have some religious education as well.
An Afghan security source agreed. "The new wave of extremists is not an uneducated farmer. It is mainly people with a good level of education," he told AFP on condition of anonymity.