Afghanistan was lost because it was an inherently unwinnable war. You can't win a war against an insurgent force with an untouchable source of backing.
What "untouchable source of backing" do you refer to? The Taliban was largely self-financing due to opium production and its military strength.
The U.S. spent at least 2.5 Trillion dollars on its adventures in Afghanistan.
That's 500 times larger than the country's GDP in 2001, and works out to $60,000 for every Afghan man, woman and child. If those numbers aren't astounding, there is an innumeracy problem!
Turning that country into a stable democracy was always going to be a difficult task, but not necessarily impossible.
In simple fact, however, the USA didn't even try, at least in any remotely intelligent way.
HUGE sums of money were spent on infrastructure projects. Should Afghan people and Afghan companies have been given the major role? Nah, how could "we" pass up the chance to enrich American companies and our friends, the hyper-billionaires of Saudi and Kuwait?
America provided many thousands of non-military workers and contractors to help Afghanistan recover and develop. Do you think it might have been good to send experts, perhaps even some fluent in local languages? Nah, it was more important to send young Republican ideologues so the Afghans would develop "politically correct" (according to Bush and Cheney) values.
Military and police force were necessary. But was it necessary to permit, even encourage, widespread collateral civilian casualties?
Success would have been difficult even if the U.S. had rational adult leadership during 2001-2008. But it was especially difficult when the Idiot-in-Chief decided to ignore the country and start another multi-trillion-dollar adventure against Iraq, the country which was already "in a box" and helpless.
So no, "Afghanistan was lost because it was an inherently unwinnable war" is a poor summary. Afghanistan was lost because every single part of the U.S. response was mismanaged.