The Taliban's advances in Afghanistan have put neighbouring Iran on edge, but the Islamic republic appears to be adopting a pragmatic approach and seeking a rapprochement with the resurgent militia.
With US and allied forces rushing for the exit and the Afghan government wobbling after a string of victories by the hardline Sunni group, Shiite Iran fears an influx of refugees fleeing sectarian violence alongside the danger of an ideological rival taking power next door.
Reformist newspaper Etemad warned Sunday of "unpleasant consequences if extremist and violent movements like the Taliban come to power, from a flood of refugees to the empowerment of dangerous sects, who share the Taliban's thinking, on our eastern borders."
Less than seven weeks before the last US soldier is set to leave Afghanistan after two decades, the Taliban say they control around 85 percent of the country.
That has unnerved officials in Iran, which shares a more than 900-kilometre (550-mile) border with Afghanistan.
While Iran has long called for the forces of its arch-enemy the United States to leave Afghanistan, it also fears the consequences should the Taliban, who ruled from 1996 until the 2001 US-led invasion, return to power or should the country fall once again into chaos.
Iran is "trying to balance between the Islamic republic's ideological preference of militant anti-Americanism and the other major necessity of preserving security on the country's eastern flank," Clement Therme, a researcher at the European University Institute in Italy, told AFP.
One key fear is a new influx of refugees from a country where the UN refugee agency has already warned of "imminent humanitarian crisis".
The agency says Iran already hosts nearly 3.5 million Afghans, who make up nearly four percent of its population.
Any further influx would add to the challenges facing a country already mired in economic crisis since Washington re-imposed sanctions in 2018.
Iran has also been hit by the Middle East's deadliest coronavirus outbreak and is struggling to contain a fifth wave of infections.
Iranian officials confirmed last week that the border with Afghanistan was "peaceful and secure" after the Taliban said they had seized a key crossing.
But ultraconservative Iranian newspaper Kayhan warned of potential spillovers from sectarian violence next door.
"The Taliban insists that it has nothing against Shiites and that it respects the borders of Iran, but the Taliban's approach built on force, means Shiites and the borders of our country face an uncertain future," it said.
The Taliban's comeback has also sparked fears that jihadists linked to the Islamic State group could also gain a more solid foothold in Afghanistan.
Iran's Shiite clerical leaders had tense relations with the Taliban between 1996 when they took power and 2001 when they were toppled in an American-led invasion over their links to Al-Qaeda and the 9/11 attacks.
After Taliban troops entered the main northern Afghan city of Mazar-i-Sharif in 1998, fighters stormed the Iranian consulate, killing 10 diplomats and an official news agency journalist.
Tehran never recognised the Taliban's rule, accusing the hardline Sunni group of persecuting Afghanistan's sizeable Shiite minority.
Tehran even went as far as cooperating with its nemesis Washington against the Taliban.
But then-deputy foreign minister and now top diplomat Mohammad Javad Zarif, who had pushed for that partnership, this month hosted an "inter-Afghan meeting" which included a Taliban delegation.
Iranian officials have repeatedly stressed that while the Taliban are not a solution to Afghanistan's problems, they are "a reality" and must be "part of a future solution" agreed by Afghans themselves.
In a recent interview with Etemad, academic Saeed Laylaz called for "balanced relations" with the group, saying it could be "a very powerful tool for Iran's diplomatic goals in the region and the world."
Support for that position is far from unanimous, and recent days have seen intense debate in the Iranian press and among the clergy.
On Thursday, senior cleric Grand Ayatollah Safi Golpayegani issued a statement warning the government that "it would be a grave, irreparable error to trust" the Taliban.
But Therme said Iranian officials are taking a pragmatic approach based on the premise that the Taliban "appears less dangerous than IS", which Iran-backed groups in Iraq and Syria have been fighting for years.
The Taliban are "an Islamist-nationalist movement, rather than a transnational jihadist group," Therme said.