Afghan spymaster resigns over civilian casualties