Amazon.com (AMZN 0.81%) has been a great stock for long-term investors since its IPO in 1997. In fact, it was Motley Fool co-founder David Gardner's first 100-bagger!

Amazon's ascent has slowed more recently. Investors have started to worry more about its falling profit margin and moderating growth rate. In fact, the online retail king's stock has underperformed the broader market over the past two years.

AMZN Chart

Amazon.com Two-Year Stock Chart, data by YCharts.

However, Amazon still has a long runway for growth. As it continues to gain scale and its recent growth investments mature, its margins should rebound to levels more in line with those of its competitors. If these investments pay off, the stock could soon be back on track for big long-term gains.

E-commerce is still young
The main reason to be optimistic about Amazon stock is that e-commerce is still in its infancy. Physical stores will probably never go away, but over time, an increasing number of people will order more and more goods online.

US E-Commerce Sales as Percent of Retail Sales Chart

US E-Commerce Sales as Percent of Retail Sales, data by YCharts.

E-commerce has been growing steadily as a percentage of retail sales more or less since Amazon opened up shop two decades ago. With e-commerce penetration still in the single-digits -- just 6.4% of total U.S. retail sales as of June -- there is clearly plenty of room for further growth.

Furthermore, Amazon absolutely dominates domestic e-commerce sales. The company's net sales in North America totaled $44.5 billion last year, virtually all of which came from the U.S. The next-biggest e-commerce retailers were Staples and Wal-Mart, which each generated about $10 billion of revenue from online sales.

This actually understates Amazon's dominance. The company has a rapidly growing "marketplace" business in which other retailers can sell goods on Amazon's website. Amazon's revenue only includes the commissions on these sales, not the full value of the merchandise sold. If Amazon just maintains its leading position in e-commerce, it can generate massive growth by riding the tide of online sales growth.

Current investments will have a big payoff
Of course, Amazon ultimately must boost earnings, not just revenue. Recently, it hasn't done so well on this front. Analysts expect Amazon to lose money in 2014, and margins have been very thin for several years now.

AMZN Operating Margin (TTM) Chart

AMZN Operating Margin (TTM), data by YCharts.

However, much of Amazon's margin woes can be explained by the company's numerous growth investments. Amazon has introduced new product lines such as Kindle Fire tablets and the Fire Phone, increasing research and development costs.

The company has also invested heavily to propel growth at its Amazon Web Services cloud-computing unit. This has involved developing new features and adding server capacity, and has enabled Amazon Web Services to post high double-digit growth. Lastly, Amazon is adding new fulfillment centers to enable faster deliveries and support higher sales volumes.

It's impossible to be sure where Amazon's profit margin will end up in the long run. However, as the leader in both e-commerce and cloud computing, Amazon should be able to leverage its fixed costs over time. As it drives more and more competitors out of business, it might also gain more pricing power, creating another route to margin growth.

Plenty of new categories to conquer
Fortunately for Amazon bulls, there are plenty of categories left for the retailer to conquer. One of the biggest opportunities is groceries. The U.S. food retail market is a nearly $1 trillion industry.For the past decade, one of Amazon's main tactics for growing sales has been adding new categories. In 2004, two-thirds of Amazon's revenue came from media: i.e., selling books, CDs, and DVDs. Today, media accounts for just one-quarter of Amazon's revenue -- and that includes an array of new digital items, including e-books, MP3 downloads, and Instant Video streaming.

Amazon is taking baby steps toward becoming a major food retailer. First, it is is rolling out its AmazonFresh grocery delivery service in new cities, after operating a pilot program in Seattle since 2007. Additionally, Amazon recently introduced Prime Pantry, a program that allows members of its Prime service to have 45 pounds of nonperishable groceries shipped to them for a $6 flat fee.

There's also plenty of room for growth in Amazon Web Services. The server market is a $50 billion industry, and that represents just one piece of the current hardware/software ecosystem that Amazon Web Services aims to replace. By contrast, Amazon Web Services generates about $4 billion of annual revenue today.

It's all about growth
Amazon.com hasn't produced much profit in the last five years, but it has nearly quadrupled its revenue in that time. The company is on pace to surpass $90 billion in annual sales this year, and it is still growing at about 20% per year. Furthermore, Amazon has huge growth opportunities ahead, as e-commerce still accounts for just a small portion of total retail sales.

Investing in Amazon requires a leap of faith that its profit margin will eventually rebound to a reasonable level (perhaps 5%-8% before taxes). So far there hasn't been much tangible proof that this will happen. However, CEO Jeff Bezos has succeeded many times before in spite of others' skepticism. He might have yet another trick up his sleeve.