(Reuters) - Macy's Inc M.N on Wednesday said its gross margins would shrink in the fall season as delivery expenses rise, overshadowing a quarterly sales and profit beat and sending shares down more than 13 percent.

FILE PHOTO: A customer exits after shopping at a Macy's store in the Brooklyn borough of New York, U.S., May 11, 2017. REUTERS/Brendan McDermid/File Photo

The department store operator reported a surprise rise in quarterly same-store sales and also upped its full-year sales and profit forecasts. Overall quarterly sales were lower, though better than analysts had expected.

Macy’s has been closing stores, controlling inventory, building its Backstage off-price business and selling or leasing out prime real estate properties to grapple with falling mall foot traffic and online competition.

It launched a revamped loyalty program in October 2017, which executives on Wednesday said would result in a bigger hit from delivery expenses to third-quarter margins this year.

“We expect our gross margin rate as a percent of sales to be slightly up for the year, this means that the gross margin rate is assumed to be slightly below last year in the fall,” Chief Financial Officer Paula Price said on a post earnings call.

The sharp share move also comes after Macy's stock has surged 66 percent this year, far outperforming the S&P 500 retailing index .SPXRT. It has more than doubled since touching a seven-year low of $17.40 in November.

Shares were last down 13.8 percent at $36.02 on Wednesday.

“Macy’s shares may be selling off this morning as result of profit taking, despite healthy second-quarter beat and raised full-year guidance,” RBC Capital Markets analyst Brian Tunick said.

Macy's results also pulled down shares of rival department store operators J.C. Penney Co Inc JCP.N, Nordstrom Inc JWN.N and Kohl's Corp KSS.N, all down more than 5 percent.

Research firm Retail Metrics analyst Ken Perkins echoed Tunick’s view, while also flagging a dip in second-quarter margins.

Perkins said based on his calculation Macy’s gross margins dipped 20 basis points in the quarter even when some full-price selling should have translated into higher margins.

Macy’s operates its namesake stores as well as Bloomingdale’s and Bluemercury.

Macy’s now expects full-year adjusted earnings of $3.95 to $4.15 per share, up from its prior forecast of $3.75 to $3.95 per share, and total sales to range from flat to up 0.7 percent, also above its previous target.

Macy’s executives said they had seen particular strength in men’s, kids, furniture and activewear, and that they were encouraged by a good start to the back-to-school season at the end of the second quarter.

Sales at Macy’s stores open more than 12 months, including sales in departments licensed to third parties, rose 0.5 percent, compared with the average analyst estimate of a 0.9 percent drop, according to Thomson Reuters I/B/E/S.

The sales and EPS outlook raise, analysts said, suggests expectations for continued momentum in the business through the year despite harder year-over-year comparisons and unfavorable timing shifts.

Excluding one-time items, the company earned 70 cents per share, much higher than analysts’ expectations of 51 cents.

Net income attributable to Macy’s shareholders rose to $166 million in the second quarter ended Aug. 4 from $111 million a year earlier.

Net sales fell 1.1 percent to $5.57 billion, but still topped estimates of $5.55 billion.