% ---------------------------
% HOW TO USE THIS TEMPLATE
% - Change the metadata
% - Create slides in the document
% - Optional : change the other_logo.png with your logo
% ---------------------------


\documentclass[aspectratio=169]{beamer}

\usetheme{default}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{xstring}
\usetikzlibrary{calc}

% --- METADATA ---

\title{TITLE OF THE PRESENTATION}
\subtitle{SUBTITLE}
\author{AUTHOR}
\date{\today}


% ---- FONTS ----

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

% If the aptos font is installed, uncomment the following line
% \usepackage{fontspec}
% \setmainfont{Aptos} 

% ---- PARAMETERS ----

% Color for the margins
\definecolor{mycyan}{HTML}{0ca3b1}

% Size left margin
\newlength{\bandwidth}
\setlength{\bandwidth}{2.5cm}

% Size footnote
\newlength{\footermargin}
\setlength{\footermargin}{0.5cm}

% Remove menu
\setbeamertemplate{navigation symbols}{}

% Remove default title
\setbeamertemplate{frametitle}{}

% --- Frame number ---
\setbeamertemplate{footline}{%
  \leavevmode%
  \hfill
  \usebeamerfont{footline}%
  \begin{beamercolorbox}[wd=2cm,ht=2ex,dp=2ex,right, rightskip=0.3cm]{date in head/foot}
    \textcolor{white}{\insertframenumber{}}
  \end{beamercolorbox}%
  \vskip0pt%
}

% Shorten title
\newcommand{\shorttitle}{\StrLeft{\inserttitle}{30}}


% --- FIRST SLIDE WITH TITLE ---
\newcommand{\firstbackground}{
\setbeamertemplate{background canvas}{
  \begin{tikzpicture}[remember picture,overlay]

    % Define margin
    \coordinate (shifted) at ([xshift=\bandwidth]current page.north west);
     \fill[mycyan] (current page.south west) rectangle (shifted);

    % Logo left
    \node[anchor=north west] at ([xshift=\bandwidth-0.5cm,yshift=0cm]current page.north west) {
      \includegraphics[height=2cm]{img/crest_color_logo.png}
    };

    % Logo right / change with your logo
    \node[anchor=north east] 
      at ([xshift=-1cm,yshift=0cm]current page.north east) {
        \includegraphics[height=2cm]{img/other_logo.png}
    };

    % Date
    \node[anchor=south west, font=\sffamily\small]
      at ([xshift=\bandwidth,yshift=0cm]current page.south west) {\insertdate};
    
    
    % Central bloc
    \node[
      draw=white, ultra thin, inner sep=10pt, align=center,
      font=\sffamily, text width=0.6\paperwidth
    ] (mainbox) at (current page.center) {
        {\LARGE \textbf \inserttitle}\\
        \textcolor{mycyan}{\rule{3cm}{1pt}}\\[0.4cm]
        {\large \textit \insertsubtitle}\\[0.4cm]
    };
  

      % Line right
    \draw[mycyan, line width=0.3pt]
    ([xshift=-1cm]current page.north east) -- 
    ([xshift=-1cm,yshift=-0.333\paperheight]current page.north east);
    
    % CREST Title right
    \node[rotate=90, anchor=south, font=\sffamily\tiny]
      at ([xshift=-0.8cm,yshift=3cm]current page.south east)
      {\textcolor{mycyan}{CREST - }\shorttitle};
  \end{tikzpicture}
  

}
}


% --- SECOND SLIDE FOR CONTENT ---
\newcommand{\contentbackground}{
\setbeamertemplate{background canvas}{
  

     \begin{tikzpicture}[remember picture,overlay]
    % --- Footer bar ---
    \fill[mycyan] (current page.south west) rectangle ([yshift=\footermargin]current page.south east);

    % --- Logo on left side of footer ---
    \node[
      anchor=south west,
      inner sep=0pt,  
      outer sep=0pt
    ] at (current page.south west)
      {\includegraphics[height=\footermargin]{img/crest_white_logo.png}};

    % Line right
      \draw[mycyan, line width=0.3pt]
      ([xshift=-1cm]current page.north east) -- 
      ([xshift=-1cm,yshift=-0.333\paperheight]current page.north east);

     % CREST Title right
    \node[rotate=90, anchor=south, font=\sffamily\tiny]
      at ([xshift=-0.8cm,yshift=3cm]current page.south east)
      {\textcolor{mycyan}{CREST - }\shorttitle};

    % --- Top horizontal line ---
    \draw[mycyan, line width=0.3pt] 
      ([xshift=1cm,yshift=-1cm]current page.north west) --
      ([xshift=13cm,yshift=-1cm]current page.north west);

    % --- Slide title aligned flush with the line start ---
    \node[
      anchor=south west,
      text=mycyan,
      font=\sffamily\bfseries,
      inner sep=0pt, % <--- remove padding
      outer sep=0pt  % <--- avoid extra margins
    ] at ([xshift=1cm,yshift=-0.9cm]current page.north west) {\insertframetitle};
      
  \end{tikzpicture}

}
}


% --- THIRD SLIDE FOR ENDING ---
\newcommand{\finalbackground}{
\setbeamertemplate{background canvas}{
  \begin{tikzpicture}[remember picture,overlay]

    % --- Footer bar ---
    \fill[mycyan] (current page.south west) rectangle ([yshift=\footermargin]current page.south east);

    % --- Logo on left side of footer ---
    \node[
      anchor=south west,
      inner sep=0pt,
      outer sep=0pt
    ] at (current page.south west)
      {\includegraphics[height=\footermargin]{img/crest_white_logo.png}};

    % --- Vertical line right ---
    \draw[mycyan, line width=0.3pt]
      ([xshift=-1cm]current page.north east) --
      ([xshift=-1cm,yshift=-0.333\paperheight]current page.north east);

    % --- CREST Title right ---
    \node[rotate=90, anchor=south, font=\sffamily\tiny]
      at ([xshift=-0.8cm,yshift=3cm]current page.south east)
      {\textcolor{mycyan}{CREST - }\shorttitle};

    % --- Central content (logos + thank you text) ---
    \node[anchor=center] at (current page.center) {%
      \begin{minipage}{1\linewidth}
        \centering
        \includegraphics[height=2cm]{img/crest_color_logo.png}\\[0.6cm]

        {\sffamily\bfseries\Large THANK YOU FOR YOUR ATTENTION}\\

      \includegraphics[height=2cm]{img/ipp_logo.png}\\[-0.5cm]
      \includegraphics[height=0.8cm]{img/cnrs_logo.png}%
      \includegraphics[height=0.8cm]{img/x_ipp_logo.png}%
      \includegraphics[height=0.8cm]{img/gee_logo.jpg}%
      \end{minipage}
    };

    % --- Address text above footer, bottom-left ---
    \node[
      anchor=south west,
      font=\sffamily\tiny,
      text=black,
      inner sep=2pt
    ] at ([yshift=\footermargin]current page.south west) {%
      \begin{tabular}{@{}l@{}}
        Center for Research in Economics and Statistics \\
        CREST UMR 9194 - 5 avenue Henry Le Chatelier \\
        91120 Palaiseau
      \end{tabular}
    };


  \end{tikzpicture}
}
}



\begin{document}

% TITLE SLIDE
\firstbackground
\begin{frame}
\end{frame}

% CONTENT SLIDE
\contentbackground
\begin{frame}
  \frametitle{Your slide title}
\end{frame}

% CONCLUSION SLIDE
\finalbackground
\begin{frame}
\end{frame}



\end{document}
