\usepackage[ngerman,english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage[a4paper,margin=2.7cm]{geometry}
\usepackage{setspace}
\onehalfspacing
\usepackage{xcolor}
\definecolor{unibremenred}{HTML}{C8102E}
\definecolor{lightgraybox}{HTML}{F4F4F4}
\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{booktabs,longtable,tabularx,array,multirow,enumitem,csquotes,caption,subcaption,float,pdflscape}
\usepackage{amsmath}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=unibremenred,citecolor=unibremenred,urlcolor=unibremenred,pdfauthor={\ReportAuthors},pdftitle={\ReportTitle}}
\usepackage[nameinlink,noabbrev]{cleveref}
\usepackage[backend=biber,style=apa,sorting=nyt,maxcitenames=2,maxbibnames=99]{biblatex}
\DeclareLanguageMapping{ngerman}{ngerman-apa}
\addbibresource{references.bib}
\usepackage[acronym,toc,nonumberlist]{glossaries-extra}

\makeglossaries
\newacronym{ai}{KI}{Künstliche Intelligenz}
\newacronym{ml}{ML}{Machine Learning}
\newacronym{api}{API}{Application Programming Interface}
\newacronym{ui}{UI}{User Interface}
\newacronym{ux}{UX}{User Experience}
\newacronym{mvp}{MVP}{Minimum Viable Product}
\newacronym{iot}{IoT}{Internet of Things}
\newacronym{saas}{SaaS}{Software as a Service}
\newacronym{dma}{DMA}{Digital Markets Act}


\newglossaryentry{benchmark}{name={Benchmark},description={Standardisierter Vergleich zur nachvollziehbaren Bewertung einer L\"osung}}
\newglossaryentry{relatedwork}{name={Related Work},description={Einordnung der eigenen L\"osung gegen\"uber einschl\"agigen wissenschaftlichen Arbeiten}}
\newglossaryentry{digitaltransformation}{name={Digitale Transformation},description={Prozess der grundlegenden Ver\"anderung von Organisationen durch den Einsatz digitaler Technologien, der neue Gesch\"aftsmodelle, Prozesse und Wertsch\"opfungslogiken erm\"oglicht (vgl.\ Baiyere et al., 2020)}}
\newglossaryentry{govtech}{name={GovTech},description={Sammelbegriff f\"ur Technologieunternehmen und -l\"osungen, die digitale Innovation im \"offentlichen Sektor vorantreiben (vgl.\ Bharosa, 2022)}}
\newglossaryentry{interoperabilitaet}{name={Interoperabilit\"at},description={F\"ahigkeit unterschiedlicher Systeme, Daten und Dienste reibungslos auszutauschen und gemeinsam zu nutzen; rechtlich geregelt u.\,a.\ durch den Interoperable Europe Act (EU) 2024/903}}

\addtokomafont{chapter}{\color{unibremenred}}
\addtokomafont{section}{\color{unibremenred}}
\addtokomafont{subsection}{\color{unibremenred}}

\usepackage[automark,headsepline]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\CourseName}
\ohead{\ReportShortTitle}
\ifoot{Universität Bremen | Digital Public}
\ofoot{\pagemark}

\usepackage[most]{tcolorbox}
\newtcolorbox{guidancebox}[1][]{colback=lightgraybox,colframe=unibremenred,fonttitle=\bfseries,title=#1,boxrule=0.8pt,arc=1mm}
\newenvironment{templateinstruction}{\begin{guidancebox}[Erwarteter Inhalt]\small}{\end{guidancebox}}
\makeatletter
% --- Participant & Contribution Tracking ---
\newcommand{\showparticipants}[1]{%
  \def\ptcp@sep{}%
  \@for\ptcpkey:=#1\do{%
    \ptcp@sep
    \expandafter\ifx\csname ptcpDISP\ptcpkey\endcsname\relax
      \ptcpkey%
    \else
      \csname ptcpDISP\ptcpkey\endcsname
    \fi
    \def\ptcp@sep{;\space}%
  }%
}
% Helper: outputs one longtable row given a participant key
\newcommand{\ptcp@tablerow}[1]{%
  \csname ptcpLAST#1\endcsname &
  \csname ptcpFIRST#1\endcsname &
  \csname ptcpMATNO#1\endcsname &
  \csname ptcpEMAIL#1\endcsname \\%
}
% Auto-generate Projektbeteiligte table from all \participant definitions in metadata.tex
\newcommand{\participanttable}{%
  \ifptcplistempty
    \textit{Keine Beteiligten in \texttt{metadata.tex} eingetragen.}%
  \else
    % Pre-build row calls outside the table to avoid longtable cell-group scoping issues
    \def\ptcp@rows{}%
    \@for\ptcpkeylocal:=\ptcplist\do{%
      \edef\ptcp@rows{\ptcp@rows\noexpand\ptcp@tablerow{\ptcpkeylocal}}%
    }%
    \begin{longtable}{@{}p{0.22\textwidth}p{0.20\textwidth}p{0.18\textwidth}p{0.32\textwidth}@{}}
    \toprule
    \textbf{Nachname} & \textbf{Vorname} & \textbf{Matrikelnummer} & \textbf{E-Mail-Adresse} \\
    \midrule\endhead
    \ptcp@rows
    \bottomrule
    \end{longtable}%
  \fi
}
% Store contribution rows in memory, grouped by participant. Registered participants
% appear first; unregistered names/keys used directly in author commands follow.
\protected\def\ptcp@contribrow#1#2#3{\showparticipants{#1} & #2 & #3 \\}
\ExplSyntaxOn
\seq_new:N \g_ptcp_matrix_keys_seq
\prop_new:N \g_ptcp_contributions_prop
\tl_new:N \g_ptcp_matrix_rows_tl

\exp_args:Nx \clist_map_inline:nn { \ptcplist }
  { \seq_gput_right:Nn \g_ptcp_matrix_keys_seq {#1} }

\cs_new_protected:Npn \ptcp_record_contributions:nnn #1#2#3
  {
    \clist_map_inline:nn {#1}
      {
        \seq_if_in:NnF \g_ptcp_matrix_keys_seq {##1}
          { \seq_gput_right:Nn \g_ptcp_matrix_keys_seq {##1} }
        \tl_set:Nx \l_tmpa_tl
          {
            \exp_not:N \ptcp@contribrow
              { \exp_not:n {##1} }
              {#2}
              { \exp_not:n {#3} }
          }
        \prop_get:NnNTF \g_ptcp_contributions_prop {##1} \l_tmpb_tl
          {
            \tl_put_right:NV \l_tmpb_tl \l_tmpa_tl
            \prop_gput:NnV \g_ptcp_contributions_prop {##1} \l_tmpb_tl
          }
          { \prop_gput:NnV \g_ptcp_contributions_prop {##1} \l_tmpa_tl }
      }
  }

\cs_new_protected:Npn \ptcp_build_matrix_rows:
  {
    \tl_gclear:N \g_ptcp_matrix_rows_tl
    \seq_map_inline:Nn \g_ptcp_matrix_keys_seq
      {
        \prop_get:NnNTF \g_ptcp_contributions_prop {##1} \l_tmpa_tl
          { \tl_gput_right:NV \g_ptcp_matrix_rows_tl \l_tmpa_tl }
          {
            \tl_gput_right:Nn \g_ptcp_matrix_rows_tl
              { \ptcp@contribrow{##1}{---}{\textit{Keine Beiträge erfasst}} }
          }
      }
  }

\cs_new_eq:NN \ptcp@recordcontributions \ptcp_record_contributions:nnn
\cs_new_protected:Npn \ptcp@buildmatrixrows { \ptcp_build_matrix_rows: }
\cs_new:Npn \ptcp@matrixrows { \tl_use:N \g_ptcp_matrix_rows_tl }
\ExplSyntaxOff
% Contribution matrix table (called from appendix A)
\newcommand{\contribtable}{%
  \ptcp@buildmatrixrows
  \begingroup
  \small
  \begin{longtable}{@{}p{0.28\textwidth}lp{0.44\textwidth}@{}}
  \toprule
  \textbf{Beteiligte} & \textbf{Abschnitt} & \textbf{Art des Beitrags} \\
  \midrule\endhead
  \bottomrule\endfoot
  \ptcp@matrixrows
  \end{longtable}%
  \endgroup
}
% \chapterauthors[Art des Beitrags]{kuerzel1,kuerzel2}
\newcommand{\chapterauthors}[2][---]{%
  \par\noindent\textbf{Beteiligte an diesem Kapitel:} \showparticipants{#2}\par\vspace{0.5\baselineskip}%
  \ptcp@recordcontributions{#2}{Kap. \thechapter}{#1}%
}
% \sectionauthors[Art des Beitrags]{kuerzel1,kuerzel2}
\newcommand{\sectionauthors}[2][---]{%
  \par\noindent\textit{Beteiligte an diesem Abschnitt:} \showparticipants{#2}\par\vspace{0.25\baselineskip}%
  \ptcp@recordcontributions{#2}{\thesection}{#1}%
}
\makeatother
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\usepackage{listings}
\lstset{basicstyle=\ttfamily\small,breaklines=true,frame=single,columns=fullflexible}
\usepackage[colorinlistoftodos,prependcaption,textsize=small]{todonotes}
