% ---------------------------------------------------------------
% Define constants
% ---------------------------------------------------------------
\newcommand{\version}{Version 1.31}

\newcommand{\userhome}{\textasciitilde}

% ---------------------------------------------------------------
% Define some custom colours
% ---------------------------------------------------------------
\definecolor{darkrose}{RGB}{136, 0, 85}
\definecolor{darkred}{RGB}{139, 0, 0}
\definecolor{tanaccent}{RGB}{255,243,204}
\definecolor{aquaaccent}{rgb}{0.85, 0.95, 1}
\definecolor{greenaccent}{rgb}{0.8, 0.95, 0.8}
\definecolor{royalblue}{rgb}{0.255, 0.412, 0.882}
\definecolor{navyblue}{RGB}{0, 51, 102}
% Darker 50% Lavender Accent 5
\definecolor{lavenderaccent5darker}{rgb}{0.429, 0.282, 0.571}
% Adjusted lighter Lavender Accent 5
\definecolor{lavenderaccent5lighter}{rgb}{0.902, 0.85, 0.926}
% Adjusted lighter Rose Accent 5 
\definecolor{roseaccent5lighter}{rgb}{0.94, 0.88, 0.91}    


% ---------------------------------------------------------------
% Define  custom title
% ---------------------------------------------------------------
% Define a custom title box with red text and background
\newcommand{\customtitle}[1]{%
    \begin{tcolorbox}[
        colback=darkred,    % Background color
        colframe=black,    % Border color
        coltext=white,    % Dark red text color
        fonttitle=\bfseries\huge, % Bold and large text
        arc=5pt,           % Rounded corners
        boxrule=1.5pt,     % Border thickness
        width=\textwidth,  % Full width
        boxsep=10pt,       % Padding inside box
        center             % Centered text
    ]
        #1
    \end{tcolorbox}
}

\makeatletter
\renewcommand{\maketitle}{
    \begin{center}
        \vspace*{5cm}
        {\Huge \bfseries \@title \par}
        \vspace{7cm} % Space between title and author
        {\Large \@author \par}
        \vspace{0.5cm} % Space between author and date
        {\large \@date \par}
        \vspace{1cm} % Space before additional text
        {\large \version \par}
    \end{center}
}
\makeatother

% ---------------------------------------------------------------
% Define custom section
% ---------------------------------------------------------------
% Define a custom section format with numbering inside the box
\newcommand{\customsection}[1]{%
    \begin{tcolorbox}[
        colback=orange,    % Background color
        colframe=black,    % Border color
        coltext=white,    % Dark red text color
        fontupper=\bfseries\large, % Bold large text
        arc=5pt,           % Rounded corners
        boxrule=1pt,       % Border thickness
        width=\textwidth,  % Full width
        center             % Centered text
    ]
        \ifnum\value{section}>0 % Only print numbering if section number exists
            \thesection\quad 
        \fi
        #1
    \end{tcolorbox}
}

% Redefine section format to use custom box with numbering
\titleformat{\section}
  {\normalfont\newpage} % No additional formatting before
  {}  % No extra numbering outside
  {0pt}          % No spacing before title
  {\customsection} % Custom command for styling
  
% ---------------------------------------------------------------
% Define custom sub-section
% ---------------------------------------------------------------
% Define a custom subsection format with numbering inside the box
\newcommand{\customsubsection}[1]{%
    \begin{tcolorbox}[
        colback=orange!50, % Lighter orange background
        colframe=black,    % Border color
        coltext=darkred,     % text color
        fontupper=\bfseries\normalsize, % Bold normal-size text
        arc=3pt,           % Slightly rounded corners
        boxrule=0.8pt,     % Thinner border
        width=\textwidth,  % Full width
        left=5pt, right=5pt, top=3pt, bottom=3pt, % Padding
        center             % Centered text
    ]
        \thesubsection\quad #1
    \end{tcolorbox}
}

% Redefine subsection format to use custom box with numbering
\titleformat{\subsection}
  {\normalfont} % No additional formatting before
  {} % No extra numbering outside
  {0pt} % No spacing before title
  {\customsubsection} % Custom command for styling

% ---------------------------------------------------------------
% Define custom sub-sub-section
% ---------------------------------------------------------------
% Define a custom subsection format with numbering inside the box
\newcommand{\customsubsubsection}[1]{%
    \begin{tcolorbox}[
        colback=orange!25, % Lighter orange background
        colframe=black,    % Border color
        coltext=black,     % text color
        fontupper=\bfseries\normalsize, % Bold normal-size text
        boxrule=0.1pt,     % Thinner border
        sharp corners, 
        width=\textwidth,  % Full width
        left=5pt, right=5pt, top=3pt, bottom=3pt, % Padding
        center             % Centered text
    ]
        #1
    \end{tcolorbox}
}


% Redefine subsection format to use custom box with numbering
\titleformat{\subsubsection}
  {} % No additional formatting before
  {} % No extra numbering outside
  {0pt} % No spacing before title
  {\customsubsubsection} % Custom command for styling


% ---------------------------------------------------------------
% Define custom note-section
% ---------------------------------------------------------------
% Define a custom subsection format with numbering inside the box
\newcommand{\note}[1]{%
    \begin{tcolorbox}[
        colback=tanaccent, % Lighter orange background
        colframe=black,    % Border color
        coltext=black,     % text color
        fontupper=\bfseries\normalsize, % Bold normal-size text
        boxrule=0.1pt,     % Thinner border
        sharp corners, 
        width=\textwidth,  % Full width
        left=5pt, right=5pt, top=3pt, bottom=3pt, % Padding
        center             % Centered text
    ]
        #1
    \end{tcolorbox}
}

% ---------------------------------------------------------------
% Define custom code box (without title or numbering)
% ---------------------------------------------------------------
% Define a custom style for the code box with syntax highlighting
\newtcolorbox[auto counter, number within=section]{bcodebox}[2][]{
    colback=pink!20!white, 
    colframe=black!75!white, 
    coltitle=pink!80!white,
    colbacktitle=pink!80!black,
    sharp corners, 
    fonttitle=\bfseries
    ,#1}

% Custom style for code without numbering
\lstdefinestyle{nonumbering}{
    numbers=none,               % Disable line numbers
    basicstyle=\ttfamily\small, % Font for code
    keywordstyle=\color{blue},   % Keywords in blue
    commentstyle=\color{green},  % Comments in green
    stringstyle=\color{red},     % Strings in red
    showstringspaces=false,     % Don't show spaces in strings
    %frame=single,               % Frame around the code
    tabsize=2,                  % Number of spaces per tab
    upquote=true                % Correct quote style for code
}

% ---------------------------------------------------------------
% Define custom code box (with title or numbering)
% ---------------------------------------------------------------
% Define a custom style for the code box with syntax highlighting
\newtcolorbox[auto counter, number within=section]{codebox}[2][]{
    colback=pink!20!white, 
    colframe=black!75!white, 
    coltitle=black,
    colbacktitle=pink!80!black,
    sharp corners, 
    fonttitle=\bfseries, 
    title={#2},#1}


% Configure listings for Python and Bash with custom settings
\lstset{
    basicstyle=\ttfamily\small, % Font for code
    keywordstyle=\color{blue},   % Keywords in blue
    commentstyle=\color{green},  % Comments in green
    stringstyle=\color{red},     % Strings in red
    numbers=left,               % Line numbers on the left
    numberstyle=\small\color{lightgray}, % Style for line numbers
    stepnumber=1,               % Line numbers step
    numbersep=7.5pt,             % Distance from code to numbers
    showstringspaces=false,     % Don't show spaces in strings
    %frame=single,               % Frame around the code
    tabsize=2,                  % Number of spaces per tab
    upquote=true                % Correct quote style for code
}

% ---------------------------------------------------------------
% Custom in line code box
% ---------------------------------------------------------------
\DeclareRobustCommand{\lstcode}[1]{%
  \colorbox{pink!20!white}{\lstinline{#1}}%
}

% ---------------------------------------------------------------
% Custom in line path box
% ---------------------------------------------------------------
% Custom style for code without numbering
\lstdefinestyle{path}{
    language=None,
    basicstyle=\ttfamily\color{black}, % General code text color
}

\newcommand{\lstpath}[1]{
    \colorbox{aquaaccent}{\lstinline{#1}}
}

% ---------------------------------------------------------------
% Custom general table
% ---------------------------------------------------------------
% Define a custom table environment with alternating row colors
\newenvironment{gentable}{
    \vspace{2mm}
    \begin{tblr}{
      colspec={XXXX},
      row{odd}={bg=lavenderaccent5lighter},
      row{even}={bg=roseaccent5lighter},
      row{1}={bg=lavenderaccent5darker,fg=white},
      width=\textwidth
    }
}{%
    \end{tblr}
}

\newenvironment{dgentable}{
    \vspace{2mm}
    \begin{tblr}{
      colspec={XXXX},
      row{odd}={bg=lavenderaccent5lighter},
      row{even}={bg=roseaccent5lighter},
      row{1}={bg=lavenderaccent5darker,fg=white},
      row{2}={bg=lavenderaccent5darker,fg=white},
      width=\textwidth
    }
}{%
    \end{tblr}
}

% ------------------------------------------------------------------
% Important text
% ------------------------------------------------------------------
\newcommand{\important}[1]{
    \textcolor{red}{#1}
}

% ------------------------------------------------------------------
% eng-sub-test commands
% ------------------------------------------------------------------
\newcommand{\enghyperref}[1]{
    \hyperref[#1]{\texttt{\detokenize{#1}}}
}

\newcommand{\engtext}[1]{
    \texttt{\detokenize{#1}}
}


% ---------------------------------------------------------------
% Navigation bar header
% ---------------------------------------------------------------
\newcommand{\DrawHeaderBar}{%
  \begin{tikzpicture}[remember picture, overlay]
    % Taller bar: from top down to -3.5em
    \fill[navyblue] (current page.north west) rectangle ([yshift=-3.5em]current page.north east);

    \hypersetup{linkcolor=white} % Only affects this group
    
    \node[anchor=north, yshift=-1em] at (current page.north) {%
      \color{white}\sffamily\bfseries\small
        \hyperref[sec:step_by_step_written]{Step-by-step} |
        \hyperref[sec:raw_checks:current_tests]{Raw checks} |
        \hyperref[sec:red_checks:current_tests]{Red checks} |
        \hyperref[sec:manual_trigger:overview]{Manual trigger} |
        \hyperref[sec:how_to]{How to}
      };
    \end{tikzpicture}%
  }

% Set up a custom page style with the nav bar on every page
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[C]{%
  \AddToShipoutPictureBG{\DrawHeaderBar}%
}

% Add vertical space to prevent text from overlapping nav
\setlength{\topmargin}{1em}
\setlength{\headheight}{30pt}
\setlength{\headsep}{3em}

% ---------------------------------------------------------------
% Custom contact table
% ---------------------------------------------------------------
\input{contacts.tex}




% ---------------------------------------------------------------
% Must disable some commands from the pdf navigation
% ---------------------------------------------------------------
\pdfstringdefDisableCommands{%
  % \def\lstcode#1{#1}%
  % \def\lstinline#1{#1}%
  % \def\colorbox#1#2{#2}%
  \def\tblr{}%
  \def\SetCell#1{}%
  \def\rowcolor#1{}%
}


\hypersetup{
  bookmarksdepth=3
}