File CA tax as non-resident

We are full time ID resident, and need to file CA tax because we earned and sold a rental property in 2021. My husband work from home (in ID) as self-employed, and his client is based in CA. 

So, my questions are:

1. when Turbo tax ask income from CA sources, I should enter all the income from CA which includes the property sold and income earned from CA. But how about the capital gain? I purchase the stock while in CA, but sold it while I was ID resident. 

2. when Turbo Tax ask about the self-401k retirement account contribution, which state should I put it? 

 

Thank you very much for helping.