What happens if my Portuguese visa expires before I get my residence card?
Short answer: Your long-stay visa lets you enter and stay until your AIMA appointment — the residence card is issued separately and the visa expiry doesn't put you out of status.
The 4-month long-stay visa is an entry document. Once stamped on arrival, your legal-stay clock is tied to the AIMA appointment date in your passport, not the visa expiry. The cartão de residência issued post-AIMA is the actual 2-year permit. Don't leave Portugal until you have the card — re-entry without it can be problematic.