You're right to think it through rather than wing it. Generally, doing work for a foreign employer while you get your long-stay status sorted is a normal situation a lot of us have been in — but the specifics genuinely depend on the country, so don't take any one person's setup as a template. Portugal has proper routes for this; the Visa section of the guide points at the long-stay options. Getting onto the right visa early saved me a lot of stress.
Slightly nervous posting this. I moved to Portugal still employed by my company back in Sweden, working remotely while I sort out my longer-term status. It feels a bit grey and I don't want to jeopardise my residency.
How did others handle the gap between arriving and having proper long-stay paperwork? Not looking to do anything dodgy — just want to understand the shape of it.