I have to get the extrema of function $f(x,y)=\cos^2(x)+\cos^2(y)$ restricted to $x+y=\frac{\pi}{2}$. So this is what I did:

$$g(x,y)=x+y=\frac{\pi}{2}$$

$$\nabla f(x,y)=\lambda.\nabla g(x,y)$$

So I got the gradients of both functions:

$$\nabla f(x,y)=<-2\cos(x)\sin(x); -2\cos(y)\sin(y)>$$

$$\nabla g(x,y)=<1;1>$$

From where I got the equation system where:
$$
\begin{cases}
-2\cos(x)\sin(x)=1 \\
-2\cos(y)\sin(y)=1 \\
x+y=\frac{\pi}{2}
\end{cases}
$$

I solved the first one as:

$$\sin(2x)=-1 \\
x=\frac{arcsin(-1)}{2} \\
x=-\frac{\pi}{4}
$$
So, since the second equation is the same for $y$, then also $y=-\frac{\pi}{4}$

From all this, I get the extrema must be at $(-\frac{\pi}{4}; -\frac{\pi}{4})$. However, this contradicts my restriction of $x+y=\frac{\pi}{2}$ because of $x$ and $y$ signs.

So, where have I gone wrong?