\documentclass[a4paper,12pt,twoside]{report}

% libraries
\usepackage[top=0.79in,left=0.79in,bottom=0.79in,right=0.59in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{rotating}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage[backend=biber,style=numeric,sorting=none,giveninits=true]{biblatex}
\usepackage{indentfirst}
\usepackage[nobottomtitles*]{titlesec}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows.meta,positioning,fit,backgrounds,calc}
% --- packages needed by the ported (pandoc) tables ---
\usepackage{longtable,booktabs,array}
\usepackage{calc}        % for table column width arithmetic (\real)
\usepackage{etoolbox}
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\providecommand{\ul}[1]{\underline{#1}}     % pandoc underline
\usepackage[export]{adjustbox}
\usepackage[center,font=small]{caption}
\usepackage{subcaption}
\usepackage{listings}
\usepackage{color}
\usepackage{float}
\usepackage{pythonhighlight}
\usepackage[newfloat]{minted}
\usemintedstyle{manni}
\usepackage{hyperref}
\usepackage{setspace}
\usepackage{tocloft}
\usepackage{fontspec}

% renaming set-ups
\renewcommand\thesection{\arabic{section}}
\renewcommand{\contentsname}{Cuprins}
\renewcommand{\figurename}{Fig.}
\renewcommand{\tablename}{Tabelul}

% --- Headings -------------------------------------------------------------
% TOC title (\chapter*): "Cuprins" 14pt, Bold, centered
\titleformat{\chapter}[block]
  {\normalfont\fontsize{14}{17}\selectfont\bfseries\filcenter}
  {}{0pt}{}
\titlespacing*{\chapter}{0pt}{0pt}{18pt}
% Main sections: "N. TITLU", 14pt Bold UPPERCASE centered (project-style, no "CAPITOLUL")
\titleformat{\section}[block]
  {\normalfont\fontsize{14}{17}\selectfont\bfseries\filcenter}
  {\thesection{}.}{0.4em}{\MakeUppercase}
\titlespacing*{\section}{0pt}{0pt}{18pt}
% Subchapters (subcapitole): 12pt Bold, left-aligned
\titleformat{\subsection}[block]
  {\normalfont\fontsize{12}{15}\selectfont\bfseries}
  {\thesubsection.}{0.6em}{}
\titlespacing*{\subsection}{0pt}{12pt}{6pt}
\titleformat{\subsubsection}[block]
  {\normalfont\fontsize{12}{15}\selectfont\bfseries\itshape}
  {\thesubsubsection.}{0.6em}{}
\titlespacing*{\subsubsection}{0pt}{10pt}{4pt}
% Paragraphs (level 4) used as headings after merging chapters: block, bold, numbered
\titleformat{\paragraph}[block]
  {\normalfont\fontsize{12}{15}\selectfont\bfseries}
  {\theparagraph.}{0.6em}{}
\titlespacing*{\paragraph}{0pt}{8pt}{4pt}

% --- Table of contents -----------------------------------------------------
% "CUPRINS" title is printed manually (centered, 14pt, bold) before \tableofcontents
\renewcommand{\contentsname}{}
\setlength{\cftbeforetoctitleskip}{0pt}
\setlength{\cftaftertoctitleskip}{0pt}
% Main chapters bold; subchapters regular weight
\renewcommand{\cftsecfont}{\bfseries}
\renewcommand{\cftsecpagefont}{\bfseries}
\renewcommand{\cftsubsecfont}{\normalfont}
\renewcommand{\cftsubsecpagefont}{\normalfont}
\renewcommand{\cftsubsubsecfont}{\normalfont}
\renewcommand{\cftsubsubsecpagefont}{\normalfont}
% trailing period after entry numbers: "1.", "1.1.", "1.1.1."
\renewcommand{\cftsecaftersnum}{.}
\renewcommand{\cftsubsecaftersnum}{.}
\renewcommand{\cftsubsubsecaftersnum}{.}
% vertical spacing between entries
\setlength{\cftbeforesecskip}{8pt}
\setlength{\cftbeforesubsecskip}{5pt}
\setlength{\cftbeforesubsubsecskip}{4pt}

% --- Captions -------------------------------------------------------------
% Tables: caption ABOVE the table, left-aligned, bold, "Tabelul N...."
\captionsetup[table]{position=above,justification=raggedright,
  singlelinecheck=false,labelsep=period,font={normalsize,bf},skip=4pt}
% Figures: caption BELOW the figure, centered, bold, 12pt, "Fig. N...."
\captionsetup[figure]{position=below,justification=centering,
  singlelinecheck=false,labelsep=period,font={normalsize,bf},skip=4pt}
% Table numbering follows the section: "Tabelul 3.1", "3.2", ... reset per chapter.
\counterwithin{table}{section}
\counterwithin{figure}{section}
% Optional source line. Place inside the float after the content. 12pt, not bold.
\newcommand{\sursa}[1]{{\normalfont\normalsize Sursa: #1}}
% bold lead-in line that stays attached to the paragraph that follows it (no page break after)
\newcommand{\leadin}[1]{\noindent\textbf{#1}\par\nobreak}
% Access screenshot: shows images/#1 if present, otherwise a labelled placeholder box.
% #1 = filename in images/, #2 = caption, #3 = width fraction (e.g. 0.85)
% #1 = base filename (no extension) in images/, #2 = caption, #3 = width fraction.
% Uses images/#1.png if present, else images/#1.pdf (auto-exported), else a placeholder.
\newcommand{\captura}[3]{%
  \begin{figure}[H]\centering
  \IfFileExists{images/#1.png}%
    {\includegraphics[width=#3\linewidth,frame]{#1.png}}%
    {\IfFileExists{images/#1.pdf}%
      {\includegraphics[width=#3\linewidth,frame]{#1.pdf}}%
      {\setlength{\fboxsep}{0pt}\fbox{\begin{minipage}[c][3.4cm][c]{#3\linewidth}\centering
         \itshape\small[Captură de ecran din Microsoft Access --- de inserat]\\[4pt]
         \ttfamily\footnotesize\detokenize{images/#1}\end{minipage}}}}%
  \caption{#2}\end{figure}}
% relational-schema helpers: PK underlined, FK prefixed with #
\newcommand{\pk}[1]{\underline{#1}}
\newcommand{\fk}[1]{\##1}

% --- Bibliography: SEAA faculty format -------------------------------------
%   Nume, I. (an), Titlu, Editură, Oraș.
%   Articole:..., Revistă, vol, nr, pp. x-y.
%   Fără autor: *** (an), Titlu, Sursă.
%   Web: URL, consultat la data de...
\addbibresource{bibliography.bib}
\urlstyle{same}  % URLs in body font, not monospace
% names: "Family, I.", authors separated by commas (incl. the last one)
\DeclareNameAlias{author}{family-given}
\renewcommand*{\multinamedelim}{\addcomma\space}
\renewcommand*{\finalnamedelim}{\addcomma\space}
% bibliography label "1." instead of "[1]"
\DeclareFieldFormat{labelnumberwidth}{#1\adddot}
% plain text everywhere (no italics, no quotes), bare URL, raw page numbers
\DeclareFieldFormat{title}{#1}
\DeclareFieldFormat{citetitle}{#1}
\DeclareFieldFormat[article]{title}{#1}
\DeclareFieldFormat{journaltitle}{#1}
\DeclareFieldFormat{pages}{#1}
\DeclareFieldFormat{url}{\url{#1}}
% in-text \cite as "[1]" (numeric, unchanged)
\DeclareBibliographyDriver{book}{%
  \printnames{author}%
  \iffieldundef{year}{}{\setunit{\addspace}\printtext{\mkbibparens{\printfield{year}}}}%
  \setunit{\addcomma\space}\printfield{title}%
  \setunit{\addcomma\space}\printlist{publisher}%
  \setunit{\addcomma\space}\printlist{location}%
  \finentry}
\DeclareBibliographyDriver{article}{%
  \printnames{author}%
  \iffieldundef{year}{}{\setunit{\addspace}\printtext{\mkbibparens{\printfield{year}}}}%
  \setunit{\addcomma\space}\printfield{title}%
  \setunit{\addcomma\space}\printfield{journaltitle}%
  \setunit{\addcomma\space}\printfield{volume}%
  \setunit{\addcomma\space}\printfield{number}%
  \setunit{\addcomma\space}\printtext{pp.\space}\printfield{pages}%
  \finentry}
\DeclareBibliographyDriver{misc}{%
  \printnames{author}%
  \iffieldundef{year}{}{\setunit{\addspace}\printtext{\mkbibparens{\printfield{year}}}}%
  \setunit{\addcomma\space}\printfield{title}%
  \setunit{\addcomma\space}\printlist{organization}%
  \setunit{\addcomma\space}\printlist{publisher}%
  \finentry}
\DeclareBibliographyDriver{online}{%
  \printfield{url}%
  \setunit{\addcomma\space}\printtext{consultat la data de \dots}%
  \finentry}
% bibliography categories (grouped sub-lists)
\DeclareBibliographyCategory{legislatie}
\DeclareBibliographyCategory{carti}
\DeclareBibliographyCategory{interne}
\addtocategory{legislatie}{lege82,lege227,omfp1802}
\addtocategory{carti}{feleaga,ristea,vasile,valceanu,petrescu,margulescu}
\addtocategory{interne}{intern_bilant,intern_cpp,intern_primare,intern_saga}

% configurations
\setmainfont[
Path=fonts/,
Extension=.ttf,
AutoFakeSlant=0.3,
BoldFont=UTSans-Bold,
ItalicFont=UTSans-Regular,
BoldItalicFont=UTSans-Bold,
SmallCapsFont=UTSans-SC
]{UTSans-Regular}

\setcounter{tocdepth}{6}
\setcounter{secnumdepth}{6}

\graphicspath{ {./images/} }

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{1,1,1}

\lstdefinestyle{mystyle}{
	backgroundcolor=\color{backcolour}, commentstyle=\color{codegreen}, keywordstyle=\color{blue}, numberstyle=\tiny\color{codegray}, stringstyle=\color{codepurple}, basicstyle=\fontsize{10}{10}\selectfont\ttfamily, breakatwhitespace=false, breaklines=true, captionpos=b, keepspaces=true, numbers=left, numbersep=2pt, showspaces=false, showstringspaces=false, showtabs=false, tabsize=2
}
\lstset{style=mystyle}
\setminted{
  autogobble=true,
  breaklines=true,
  breaksymbolleft={},
  breaksymbolright={},
  fontsize=\small
}
\setminted[sql]{
  tabsize=2,
  breakanywhere=true,        % SQL formulas have no spaces; allow mid-token wrapping
  breakautoindent=true,
  fontsize=\footnotesize
}

\hypersetup{
    colorlinks, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black
}

\setstretch{1}

\newcommand*\sepline{%
  \begin{center}
    \rule[.1ex]{\textwidth}{.1pt}
  \end{center}}

\raggedbottom   % avoid vertical-justification gaps around tables/figures

% --- page-break protection ---
\clubpenalty=10000          % no orphan lines (first line of paragraph alone)
\widowpenalty=10000         % no widow lines (last line of paragraph alone)
\displaywidowpenalty=10000
\emergencystretch=2em       % absorb rare overfull lines (long RO compounds) without \sloppy
\begin{document}
\input{constants}

\include{parts/cover}
\include{parts/innercover}

\clearpage
{\centering\fontsize{14}{17}\selectfont\bfseries CUPRINS\par}
\vspace{2.5em}
\tableofcontents
\clearpage

\pagestyle{fancy}
\fancyhead{}
\fancyhead[L]{\small\itshape \DegreeType{} \FacultyShort{} \Year{}}
\fancyhead[R]{\small\itshape \StudentName{}}
\fancyfoot{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\setlength{\headheight}{15pt}
\begin{spacing}{1.5}

% --- Proiect APSI: Sistemul informatic al restaurantului Gourmet Hungaricum ---
\include{sections/introducere}
\clearpage
\include{sections/01_obiective}
\clearpage
\include{sections/02_analiza}
\clearpage
\include{sections/03_proiectare}
\clearpage
\include{sections/04_concluzii}
\clearpage
\include{parts/anexe}

\end{spacing}

\end{document}
