Why didnt the Persians invade the Maghreb

They did go out to Marathon but lurked in the hills to avoid the Persian cavalry. They were awaiting the arrival of the Spartan army to help them.

However when they saw the Persian cavalry being embarked on ships they took the opportunity and ran down and defeated the inferior unarmoured Persian infantry caught without the protection of their cavalry.

After defeating the Persian infantry, the Athenian infantry realised the Persian cavalry was being shipped around the coast to Athens to take the city in their absence, with traitors to open the city gates to let them in. The 9,000 Athenoan infantry ran back the 26 miles to Athens carrying their weapons and armour, and arrived to form up in front of their city as the Persian cavalry was being disembarked. The Persians gave up and went home.

This run by the Athenian army is celebrated today in the marathon race. Today's runners get it easy, not having to run in sandals carrying weapons and armour. Much tougher lot in those days, and of course they had the incentive of saving their homes and families.