The factories went bankrupt because of corruption as far as I know. An often cited scheme in the press was that the management will buy raw materials at higher than normal prices and sell the products at low prices, of course in exchange for bribes. Other sectors of the economy were similarly brought down in various ways. Trade was not done only with the Eastern Bloc, so you can’t blame everything on the loss of those markets. The people who wanted democracy didn’t anticipate all that corruption and lack of accountability.
The economy was organised around USSR and suddenly it didn't made sense anymore once USSR was gone. The corruption on epic scale happened when restructuring was going on. The restructuring had to happen, but of course it shouldn't have had been handled that bad.