\usepackage{float}
\floatplacement{figure}{H}
\raggedbottom
\usepackage{etoolbox}
\makeatletter
\patchcmd{\LT@array}{\tabskip\z@}{\tabskip\fill}{}{}
\makeatother

% Rename Table prefix to Tab.
\AtBeginDocument{%
  \renewcommand{\tablename}{Tab.}
  \renewcommand{\figurename}{Abb.}
  \renewcommand{\listtablename}{Tabellenverzeichnis}
}

\usepackage[hyphens]{url}
\usepackage[hidelinks]{hyperref}
\usepackage[htt]{hyphenat}
\usepackage{microtype}
\setlength{\emergencystretch}{5em} % Increased to solve overfull lines

\usepackage{tocloft}

% Dotted lines for all levels in TOC
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsubsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cftsubsubsecleader}{\cftdotfill{\cftdotsep}}

% Bold section numbers and names
\renewcommand{\cftsecfont}{\bfseries}
\renewcommand{\cftsecpagefont}{\bfseries}

% Adjust vertical spacing before sections
\setlength{\cftbeforesecskip}{0.5em}

\usepackage{fvextra}
\fvset{breaklines=true}

\usepackage{needspace}
\let\oldShaded\Shaded
\let\oldendShaded\endShaded
\renewenvironment{Shaded}{\needspace{8\baselineskip}\oldShaded}{\oldendShaded}

\usepackage{fancyhdr}

% Define the fancy style but don't activate yet
\fancypagestyle{fancy}{
  \fancyhf{} % clear all header and footer fields
  \fancyhead[RO,LE]{\includegraphics[height=2cm]{images/preamble/logo.png}}
  \fancyhead[LO,RE]{\nouppercase{\leftmark}} 
  \fancyfoot[RO,LE]{\thepage}
  \renewcommand{\headrulewidth}{0.4pt}
  \renewcommand{\footrulewidth}{0.4pt}
  \newgeometry{top=2.5cm, bottom=4cm, left=3cm, right=2cm, includehead, includefoot, a4paper}
  \setlength{\headheight}{2cm}
  \setlength{\footskip}{1.5cm}
}

\renewcommand{\sectionmark}[1]{\markboth{#1}{}} % Set section title to \leftmark

% Default style for preamble/TOC
\pagestyle{plain}
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
