The phrase doesn't refer to actual physical distance, but to being distracted or not present mentally. During the lecture, Sally was miles away, thinking about her vacation.
Pro Tip 2/3
Informal Usage
It's a casual expression, used more in spoken language or informal writing. Sorry, I was miles away. What did you just say?
Pro Tip 3/3
Conversation Context
Used when someone doesn't respond in a conversation, indicating they're not paying attention. You've been quiet, you seem miles away. Everything okay?