\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[french]{babel} % Césure en français

\usepackage{graphicx}
\graphicspath{{Images/}}

\usepackage{lipsum}
\usepackage{tikz}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{xcolor}

\definecolor{turquoisefonce}{RGB}{3, 152, 158}
\definecolor{vertdeau}{RGB}{0, 194, 203}
\definecolor{turquoisevif}{RGB}{92, 225, 230}
\definecolor{black}{RGB}{0, 0, 0}

% options
\setlist{nolistsep}

\usepackage{geometry}

\geometry{
	paper=letterpaper, 
	top=2cm,
	bottom=2cm,
	left=2cm,
	right=2cm,
	headheight=16pt,
	footskip=1.4cm, 
	headsep=12pt,
}

\usepackage{avant}
\usepackage{mathptmx}
\usepackage{microtype}


\usepackage[style=reading,citestyle=reading,sorting=nyt]{biblatex}
\addbibresource{guide-preparation-vacances.bib}
\defbibheading{bibempty}{}

\usepackage{calc}
\usepackage{makeidx} 
\makeindex

\usepackage{titletoc} % Required for manipulating the table of contents

\contentsmargin{0cm} % Removes the default margin

% styles de titres
\titlecontents{part}
	[0cm]
	{\addvspace{20pt}\bfseries}
	{}
	{}
	{}
\titlecontents{chapter}
	[1cm] 
	{\addvspace{12pt}\large\sffamily\bfseries}
	{\color{turquoisefonce!60}\contentslabel[\Large\thecontentslabel]{1.25cm}\color{turquoisefonce}}
	{\color{turquoisefonce}} {\color{turquoisefonce!60}\normalsize\;\titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{section}
	[1cm]
	{\addvspace{4pt}\sffamily\bfseries}
	{\contentslabel[\thecontentslabel]{1cm}}
	{}
	{\hfill\color{black}\thecontentspage}
\titlecontents{subsection}
	[1cm]
	{\addvspace{2pt}\sffamily\small}
	{\contentslabel[\thecontentslabel]{1cm}}
	{}
	{\ \titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{figure}
	[1cm]
	{\addvspace{2pt}\sffamily\small}
	{\thecontentslabel\hspace*{1em}}
	{}
	{\ \titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{table}
	[1]
	{\addvspace{2pt}\sffamily\small}
	{\thecontentslabel\hspace*{1em}}
	{}
	{\ \titlerule*[.5pc]{.}\;\thecontentspage}

% styles de titres sur page de partie
\titlecontents{lchapter}
	[0em]
	{\addvspace{15pt}\large\sffamily\bfseries}
	{\color{turquoisefonce}\contentslabel[\Large\thecontentslabel]{1cm}\color{turquoisefonce}}
	{}
	{\color{turquoisefonce}\normalsize\sffamily\bfseries\;\titlerule*[.5pc]{.}\;\thecontentspage}
\titlecontents{lsection}
	[0em] 
	{\sffamily\small} 
	{\contentslabel[\thecontentslabel]{1cm}}
	{}
	{}
\titlecontents{lsubsection}
	[.5em] % Left indentation
	{\sffamily\footnotesize} % Spacing and font options for subsections
	{\contentslabel[\thecontentslabel]{1cm}}
	{}
	{}

% entête et pied de page

\usepackage{fancyhdr}

\pagestyle{fancy}

\newcommand*\parttitle{}
\let\origpart\part
\renewcommand*{\part}[2][]{%
	\ifx\\#1\\
	\origpart{#2}%
	\renewcommand*\parttitle{#2}%
	\else
	\origpart[#1]{#2}%
	\renewcommand*\parttitle{#1}%
	\fi
}

\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries\chaptername\ \thechapter.\ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}}

\fancyhf{}
\fancyhead[LE,RO]{\sffamily\normalsize\thepage} 
\fancyhead[LO]{\rightmark} 
\fancyhead[RE]{\leftmark} 
%\fancyfoot[C]{\thepart. \parttitle} 

\renewcommand{\headrulewidth}{0.5pt}

\fancypagestyle{plain}{\fancyhead{}\renewcommand{\headrulewidth}{0pt}}

\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}

\makeatletter
\renewcommand{\@seccntformat}[1]{\llap{\textcolor{turquoisefonce}{\csname the#1\endcsname}\hspace{1em}}}                    
\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-4ex \@plus -1ex \@minus -.4ex}
{1ex \@plus.2ex }
{\normalfont\large\sffamily\bfseries}}
\renewcommand{\subsection}{\@startsection {subsection}{2}{\z@}
{-3ex \@plus -0.1ex \@minus -.4ex}
{0.5ex \@plus.2ex }
{\normalfont\sffamily\bfseries}}
\renewcommand{\subsubsection}{\@startsection {subsubsection}{3}{\z@}
{-2ex \@plus -0.1ex \@minus -.2ex}
{.2ex \@plus.2ex }
{\normalfont\small\sffamily\bfseries}}                        
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}
{-2ex \@plus-.2ex \@minus .2ex}
{.1ex}
{\normalfont\small\sffamily\bfseries}}

\newcommand{\@mypartnumtocformat}[2]{%
	\setlength\fboxsep{0pt}%
	\noindent\colorbox{turquoisefonce!20}{\strut\parbox[c][.7cm]{\ecart}{\color{turquoisefonce!70}\Large\sffamily\bfseries\centering#1}}\hskip\esp\colorbox{turquoisefonce!40}{\strut\parbox[c][.7cm]{\linewidth-\ecart-\esp}{\Large\sffamily\centering#2}}%
}

\newcommand{\@myparttocformat}[1]{%
	\setlength\fboxsep{0pt}%
	\noindent\colorbox{turquoisefonce!40}{\strut\parbox[c][.7cm]{\linewidth}{\Large\sffamily\centering#1}}%
}

\newlength\esp
\setlength\esp{4pt}
\newlength\ecart
\setlength\ecart{1.2cm-\esp}
\newcommand{\thepartimage}{}%
\newcommand{\partimage}[1]{\renewcommand{\thepartimage}{#1}}%
\def\@part[#1]#2{%
\ifnum \c@secnumdepth >-2\relax%
\refstepcounter{part}%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@mypartnumtocformat{\thepart}{#1}}{\partname~\thepart\ ---\ #1}}
\else%
\addcontentsline{toc}{part}{\texorpdfstring{\protect\@myparttocformat{#1}}{#1}}%
\fi%
\startcontents%
\markboth{}{}%
{\thispagestyle{empty}%
\begin{tikzpicture}[remember picture,overlay]%
\node at (current page.north west){\begin{tikzpicture}[remember picture,overlay]%	
\fill[turquoisefonce!10](0cm,0cm) rectangle (\paperwidth,-\paperheight);
\node[anchor=south east] at (\paperwidth-1cm,-\paperheight+1cm){\parbox[t][][t]{15cm}{
\printcontents{l}{0}{\setcounter{tocdepth}{1}}
}};
\node[anchor=north east] at (\paperwidth-1.5cm,-3.25cm){\parbox[t][][t]{18cm}{\strut\raggedleft\color{turquoisefonce!60!white}\fontsize{30}{30}\sffamily\bfseries\thepart.#2}};
\end{tikzpicture}};
\end{tikzpicture}}%
\@endpart}
\def\@spart#1{%
\startcontents%
\phantomsection
{\thispagestyle{empty}%
\begin{tikzpicture}[remember picture,overlay]%
\node at (current page.north west){\begin{tikzpicture}[remember picture,overlay]%	
\fill[turquoisefonce!10](0cm,0cm) rectangle (\paperwidth,-\paperheight);
\node[anchor=north east] at (\paperwidth-1.5cm,-3.25cm){\parbox[t][][t]{15cm}{\strut\raggedleft\color{turquoisefonce!60!white}\fontsize{30}{30}\sffamily\bfseries#1}};
\end{tikzpicture}};
\end{tikzpicture}}
\addcontentsline{toc}{part}{\texorpdfstring{%
\setlength\fboxsep{0pt}%
\noindent\protect\colorbox{turquoisefonce!40}{\strut\protect\parbox[c][.7cm]{\linewidth}{\Large\sffamily\protect\centering #1\quad\mbox{}}}}{#1}}%
\@endpart}
\def\@endpart{\vfil\newpage
\if@twoside
\if@openright
\null
\thispagestyle{empty}%
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi}

\newif\ifusechapterimage
\usechapterimagetrue
\newcommand{\thechapterimage}{}%
\newcommand{\chapterimage}[1]{\ifusechapterimage\renewcommand{\thechapterimage}{#1}\fi}%
\newcommand{\autodot}{.}
\def\@makechapterhead#1{%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=turquoisefonce,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-9cm) node {\huge\sffamily\bfseries\color{black}\thechapter\autodot~#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\else
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-9cm) node [line width=2pt,rounded corners=15pt,draw=turquoisefonce,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-9cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\fi\fi\par\vspace*{270\p@}}}

%-------------------------------------------

\def\@makeschapterhead#1{%
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.north west)
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north west,inner sep=0pt] at (0,0) {\ifusechapterimage\includegraphics[width=\paperwidth]{\thechapterimage}\fi};
\draw[anchor=west] (\Gm@lmargin,-5cm) node [line width=2pt,rounded corners=15pt,draw=turquoisefonce,fill=white,fill opacity=0.5,inner sep=15pt]{\strut\makebox[22cm]{}};
\draw[anchor=west] (\Gm@lmargin+.3cm,-5cm) node {\huge\sffamily\bfseries\color{black}#1\strut};
\end{tikzpicture}};
\end{tikzpicture}
\par\vspace*{270\p@}}
\makeatother

\usepackage{hyperref}
\usepackage{xcolor}
\hypersetup{
	colorlinks,
	linkcolor={turquoisefonce!50!black},
	citecolor={turquoisevif!50!black},
	urlcolor={turquoisevif!80!black}
}

\usepackage{bookmark}
\bookmarksetup{
open,
numbered,
addtohook={%
\ifnum\bookmarkget{level}=0 % chapter
\bookmarksetup{bold}%
\fi
\ifnum\bookmarkget{level}=-1 % part
\bookmarksetup{color=turquoisefonce,bold}%
\fi
}
}
