% =============================================================================
% Style UQO pour présentations Beamer — IMM1003
% Université du Québec en Outaouais
% Auteur : Simon-Pierre Boucher — simon-pierre.boucher@uqo.ca
% © 2026 Simon-Pierre Boucher
% Design moderne « flat » : Fira Sans, accents dorés, barre de progression,
% page titre avec photo du pavillon Lucien-Brault (images/)
% =============================================================================
\ProvidesPackage{uqo-style}

% --- Packages requis ---
\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[french]{babel}
\RequirePackage{lmodern}
\RequirePackage[sfdefault,scaled=0.92]{FiraSans}
\RequirePackage{amsmath,amssymb}
\RequirePackage{graphicx}
\RequirePackage{booktabs}
\RequirePackage{array}
\RequirePackage{multirow}
\RequirePackage{colortbl}
\RequirePackage{tikz}
\RequirePackage{pgfplots}
\RequirePackage{hyperref}
\RequirePackage{fontawesome5}
\RequirePackage{tcolorbox}
% enumitem retiré car incompatible avec Beamer
\RequirePackage[backend=biber, style=authoryear, sorting=nyt, maxbibnames=6]{biblatex}
\addbibresource{references.bib}
\renewcommand*{\bibfont}{\footnotesize}
\setlength\bibitemsep{0.55\baselineskip}
\RequirePackage{listings}
\RequirePackage{eurosym}
\RequirePackage{textcomp}
\RequirePackage{pifont}
\RequirePackage{calc}
\RequirePackage{appendixnumberbeamer}

\pgfplotsset{compat=1.18}
\usetikzlibrary{shapes,arrows,arrows.meta,positioning,calc,decorations.pathreplacing,shadows,fit}

% --- Couleurs UQO ---
\definecolor{uqoBleu}{RGB}{0, 62, 126}         % Bleu principal UQO
\definecolor{uqoBleuClair}{RGB}{41, 118, 187}  % Bleu clair
\definecolor{uqoOr}{RGB}{204, 164, 36}         % Or/doré UQO
\definecolor{uqoGris}{RGB}{96, 102, 112}       % Gris foncé
\definecolor{uqoGrisClair}{RGB}{208, 213, 220} % Gris clair
\definecolor{uqoBlanc}{RGB}{255, 255, 255}     % Blanc
\definecolor{uqoVert}{RGB}{16, 124, 78}        % Vert accent
\definecolor{uqoRouge}{RGB}{178, 42, 32}       % Rouge accent
\definecolor{uqoBgClair}{RGB}{242, 246, 250}   % Fond clair
\definecolor{uqoNavy}{RGB}{9, 26, 51}          % Bleu nuit (pages titre/section)
\definecolor{uqoInk}{RGB}{38, 43, 52}          % Texte courant

% =============================================================================
% THÈME — base neutre, tout est redéfini à la main (design flat)
% =============================================================================
\usetheme{default}
\usefonttheme{professionalfonts}

\setbeamercolor{background canvas}{bg=uqoBlanc}
\setbeamercolor{normal text}{fg=uqoInk}
\setbeamercolor{structure}{fg=uqoBleu}
\setbeamercolor{alerted text}{fg=uqoRouge}
\setbeamercolor{example text}{fg=uqoVert}

\setbeamercolor{title}{fg=uqoBlanc}
\setbeamercolor{subtitle}{fg=uqoOr}
\setbeamercolor{frametitle}{fg=uqoBleu, bg=uqoBlanc}
\setbeamercolor{framesubtitle}{fg=uqoGris}
\setbeamercolor{author}{fg=uqoGris}
\setbeamercolor{institute}{fg=uqoGris}
\setbeamercolor{date}{fg=uqoGris}

\setbeamercolor{block title}{bg=uqoBleu, fg=uqoBlanc}
\setbeamercolor{block body}{bg=uqoBgClair, fg=uqoInk}
\setbeamercolor{block title alerted}{bg=uqoRouge, fg=uqoBlanc}
\setbeamercolor{block body alerted}{bg=uqoBgClair, fg=uqoInk}
\setbeamercolor{block title example}{bg=uqoVert, fg=uqoBlanc}
\setbeamercolor{block body example}{bg=uqoBgClair, fg=uqoInk}

\setbeamercolor{item}{fg=uqoBleu}
\setbeamercolor{subitem}{fg=uqoOr}
\setbeamercolor{subsubitem}{fg=uqoGris}

\setbeamercolor{section in toc}{fg=uqoBleu}
\setbeamercolor{subsection in toc}{fg=uqoGris}

\setbeamercolor{bibliography entry author}{fg=uqoInk}
\setbeamercolor{bibliography entry title}{fg=uqoBleu}
\setbeamercolor{bibliography entry location}{fg=uqoGris}
\setbeamercolor{bibliography entry note}{fg=uqoGris}

% --- Polices ---
\setbeamerfont{title}{size=\huge, series=\bfseries}
\setbeamerfont{subtitle}{size=\footnotesize, series=\bfseries}
\setbeamerfont{frametitle}{size=\large, series=\bfseries}
\setbeamerfont{framesubtitle}{size=\small}
\setbeamerfont{block title}{size=\small, series=\bfseries}
\setbeamerfont{footnote}{size=\tiny}
\setbeamerfont{footline}{size=\tiny}

% --- Navigation ---
\setbeamertemplate{navigation symbols}{}

% --- Espacement généreux : marges larges, texte aéré ---
\setlength{\parskip}{3pt}
\setbeamersize{text margin left=9mm, text margin right=9mm}
\beamerdefaultoverlayspecification{}
\linespread{1.06}

% =============================================================================
% TITRE DE CADRE — titre bleu, tiret doré + filet fin
% =============================================================================
\setbeamertemplate{frametitle}{%
  \nointerlineskip
  \vskip2.6mm
  \begin{beamercolorbox}[wd=\textwidth]{frametitle}
    \usebeamerfont{frametitle}\insertframetitle%
    \ifx\insertframesubtitle\@empty\else
      \\[0.3ex]{\usebeamerfont{framesubtitle}\usebeamercolor[fg]{framesubtitle}\insertframesubtitle}%
    \fi
  \end{beamercolorbox}
  \vskip1.2mm
  \leavevmode\hbox{%
    {\color{uqoOr}\rule[0.6pt]{9mm}{1.6pt}}%
    \hspace{1.5pt}%
    {\color{uqoGrisClair}\rule[1.1pt]{\dimexpr\textwidth-9mm-1.5pt\relax}{0.5pt}}%
  }%
  \vskip2mm
}
\setbeamertemplate{frametitle continuation}[from second][{\normalsize\color{uqoGris}~(suite)}]

% =============================================================================
% PIED DE PAGE — barre de progression dorée + infos discrètes
% =============================================================================
\setbeamertemplate{footline}{%
  \leavevmode%
  \hbox to \paperwidth{\hspace*{6mm}%
    {\usebeamerfont{footline}\color{uqoGris}%
      \insertshorttitle\ \textbullet\ \insertshortauthor\ \textbullet\ UQO}%
    \hfill
    {\usebeamerfont{footline}\color{uqoGris}%
      \insertframenumber\,/\,\inserttotalframenumber}%
    \hspace*{6mm}}%
  \vskip0.8mm
  \begin{tikzpicture}
    \fill[uqoBgClair] (0,0) rectangle (\paperwidth,0.55mm);
    \pgfmathsetlengthmacro{\uqoprogress}{%
      \paperwidth*min(1,\insertframenumber/max(1,\inserttotalframenumber))}
    \fill[uqoOr] (0,0) rectangle (\uqoprogress,0.55mm);
  \end{tikzpicture}%
  \vskip0pt%
}

% =============================================================================
% PUCES ET NUMÉROTATION
% =============================================================================
\setbeamertemplate{itemize item}{\raisebox{0.28ex}{\scriptsize\color{uqoBleu}$\blacktriangleright$}}
\setbeamertemplate{itemize subitem}{\raisebox{0.32ex}{\tiny\color{uqoOr}$\blacktriangleright$}}
\setbeamertemplate{itemize subsubitem}{\raisebox{0.25ex}{\scriptsize\color{uqoGris}--}}

\setbeamertemplate{enumerate item}{%
  \tikz[baseline=-0.68ex]\node[fill=uqoBleu, text=uqoBlanc, circle,
    inner sep=0.4pt, minimum size=2.1ex, font=\scriptsize\bfseries]{\insertenumlabel};}
\setbeamertemplate{enumerate subitem}{%
  \tikz[baseline=-0.68ex]\node[draw=uqoBleuClair, text=uqoBleuClair, circle,
    line width=0.5pt, inner sep=0.4pt, minimum size=1.9ex, font=\tiny\bfseries]{\insertsubenumlabel};}

\addtobeamertemplate{itemize/enumerate body begin}{\setlength{\itemsep}{5pt}\setlength{\parsep}{0pt}\setlength{\topsep}{4pt}\setlength{\partopsep}{0pt}}{}
\addtobeamertemplate{itemize/enumerate body end}{}{}

% =============================================================================
% TABLE DES MATIÈRES — pastilles numérotées
% =============================================================================
\setbeamertemplate{section in toc}{%
  \vskip4pt
  \leavevmode
  \tikz[baseline=-0.68ex]\node[fill=uqoBleu, text=uqoBlanc, circle,
    inner sep=0.4pt, minimum size=2.3ex, font=\scriptsize\bfseries]{\inserttocsectionnumber};%
  \hspace{0.6em}{\color{uqoBleu}\bfseries\inserttocsection}\par
}
\setbeamertemplate{subsection in toc}{%
  \vskip2pt
  \leavevmode\hspace{2.4em}%
  {\color{uqoOr}\scriptsize$\blacktriangleright$}\hspace{0.5em}%
  {\color{uqoGris}\small\inserttocsubsection}\par
}

% =============================================================================
% BIBLIOGRAPHIE
% =============================================================================
\setbeamertemplate{bibliography item}{\color{uqoOr}\small\faIcon{book}}

% =============================================================================
% PAGE DE SECTION — pleine page bleu nuit, grand numéro, filet doré
% =============================================================================
\newcommand{\uqoSectionNum}{\ifnum\insertsectionnumber<10 0\fi\insertsectionnumber}

\AtBeginSection[]{%
  \begin{frame}[plain,noframenumbering]
    \begin{tikzpicture}[remember picture,overlay]
      \fill[uqoNavy] (current page.south west) rectangle (current page.north east);
      % décorations géométriques
      \draw[uqoBleuClair, opacity=0.20, line width=0.9pt]
        ([xshift=-18mm,yshift=-6mm]current page.north east) circle (24mm);
      \draw[uqoBleuClair, opacity=0.12, line width=0.9pt]
        ([xshift=-6mm,yshift=-18mm]current page.north east) circle (33mm);
      \draw[uqoOr, opacity=0.55, line width=0.8pt]
        ([xshift=-34mm,yshift=-24mm]current page.north east) circle (9mm);
      \fill[uqoOr] ([xshift=-48mm,yshift=-12mm]current page.north east) circle (1mm);
      % grand numéro en filigrane
      \node[anchor=south east, text=uqoBlanc, opacity=0.08,
        font=\fontsize{88}{88}\selectfont\bfseries]
        at ([xshift=-6mm,yshift=-3mm]current page.south east) {\uqoSectionNum};
      % étiquette
      \node[anchor=west, text=uqoOr, font=\footnotesize\bfseries]
        at ([xshift=14mm,yshift=10mm]current page.west) {SECTION~\insertsectionnumber};
      \fill[uqoOr] ([xshift=14mm,yshift=7mm]current page.west) rectangle ++(11mm,0.55mm);
      % titre de section
      \node[anchor=north west, text=uqoBlanc, font=\LARGE\bfseries,
        text width=125mm, align=left]
        at ([xshift=14mm,yshift=4.5mm]current page.west) {\insertsectionhead};
      % rappel du cours en bas
      \node[anchor=south west, text=uqoGrisClair, font=\tiny]
        at ([xshift=14mm,yshift=6mm]current page.south west)
        {\insertshorttitle\ \textbullet\ \insertshortauthor\ \textbullet\ UQO};
    \end{tikzpicture}
  \end{frame}
}

% =============================================================================
% PAGE TITRE — panneau bleu nuit + zone blanche (auteur, logo)
%              + bandeau photo : pavillon Lucien-Brault (UQO)
% =============================================================================
\defbeamertemplate*{title page}{uqo}[1][]
{%
  \begin{tikzpicture}[remember picture,overlay]
    % panneau bleu nuit
    \fill[uqoNavy] (current page.north west) rectangle
      ([yshift=-50mm]current page.north east);
    \fill[uqoOr] ([yshift=-50mm]current page.north west) rectangle
      ([yshift=-48.9mm]current page.north east);
    % décorations géométriques (limitées au panneau)
    \begin{scope}
      \clip (current page.north west) rectangle ([yshift=-50mm]current page.north east);
      \draw[uqoBleuClair, opacity=0.28, line width=1pt]
        ([xshift=-22mm,yshift=-4mm]current page.north east) circle (25mm);
      \draw[uqoBleuClair, opacity=0.16, line width=1pt]
        ([xshift=-8mm,yshift=-18mm]current page.north east) circle (34mm);
      \draw[uqoOr, opacity=0.65, line width=0.9pt]
        ([xshift=-38mm,yshift=-30mm]current page.north east) circle (10mm);
      \fill[uqoOr] ([xshift=-52mm,yshift=-13mm]current page.north east) circle (1.1mm);
    \end{scope}
    % sous-titre (accroche dorée)
    \node[anchor=north west, text=uqoOr, font=\footnotesize\bfseries]
      at ([xshift=12mm,yshift=-9.5mm]current page.north west)
      {\MakeUppercase{\insertsubtitle}};
    \fill[uqoOr] ([xshift=12mm,yshift=-14.7mm]current page.north west)
      rectangle ++(11mm,0.55mm);
    % titre principal
    \node[anchor=north west, text=uqoBlanc, font=\LARGE\bfseries,
      text width=118mm, align=left,
      execute at begin node={\hyphenpenalty=10000\exhyphenpenalty=10000\relax}]
      at ([xshift=12mm,yshift=-18mm]current page.north west) {\inserttitle};
    % date (pastille, dans le panneau)
    \node[anchor=south west, text=uqoBlanc, font=\footnotesize,
      draw=uqoOr, line width=0.7pt, rounded corners=2pt,
      inner xsep=7pt, inner ysep=4pt]
      at ([xshift=12mm,yshift=44mm]current page.south west)
      {\faIcon{calendar-alt}\hspace{5pt}\insertdate};
    % zone blanche : auteur et coordonnées (gauche) + logo (droite)
    \node[anchor=north west, align=left]
      at ([xshift=12mm,yshift=-52mm]current page.north west)
      {\begin{minipage}{105mm}\raggedright
        {\normalsize\bfseries\color{uqoBleu}\insertauthor\par}
        \vspace{1mm}
        {\footnotesize\color{uqoGris}\insertinstitute\par}
        \vspace{1.3mm}
        {\footnotesize\color{uqoGris}%
          \textcolor{uqoOr}{\faIcon{envelope}}\hspace{4pt}%
          \href{mailto:simon-pierre.boucher@uqo.ca}{simon-pierre.boucher@uqo.ca}%
          \hspace{9pt}%
          \textcolor{uqoOr}{\faIcon{map-marker-alt}}\hspace{4pt}%
          Pavillon Lucien-Brault, Gatineau\par}
      \end{minipage}};
    \node[anchor=north east]
      at ([xshift=-10mm,yshift=-53.5mm]current page.north east)
      {\includegraphics[height=11mm]{uqo-logo.png}};
    % bandeau photo : pavillon Lucien-Brault
    \node[anchor=south west, inner sep=0pt] (plb)
      at (current page.south west)
      {\includegraphics[width=\paperwidth,height=18mm]{images/pavillon-lucien-brault-banner.jpg}};
    \fill[uqoNavy, opacity=0.22]
      (current page.south west) rectangle ([yshift=18mm]current page.south east);
    \fill[uqoOr] ([yshift=18mm]current page.south west)
      rectangle ([yshift=18.8mm]current page.south east);
    % crédit photo (attribution CC BY-SA)
    \node[anchor=south east, text=uqoBlanc, opacity=0.75, font=\fontsize{3.4}{4}\selectfont]
      at ([xshift=-1.5mm,yshift=0.8mm]current page.south east)
      {Pavillon Lucien-Brault --- photo : Denis Yuen, Wikimedia Commons, CC BY-SA 2.5};
  \end{tikzpicture}%
}

% =============================================================================
% BOÎTES tcolorbox — style « admonition » moderne (filet gauche + fond teinté)
% =============================================================================
\tcbuselibrary{skins,breakable}

\tcbset{uqobox/.style={
  enhanced,
  boxrule=0pt, frame hidden,
  arc=1.5pt,
  left=9pt, right=9pt, top=5pt, bottom=5pt,
  before skip=6pt, after skip=6pt,
  fontupper=\small,
  detach title,
  before upper={\tcbtitle\par\vspace{3pt}},
  fonttitle=\bfseries\small
}}

\newtcolorbox{defbox}[1][Définition]{
  uqobox,
  colback=uqoBleu!6,
  borderline west={2.5pt}{0pt}{uqoBleu},
  coltitle=uqoBleu,
  title={\faIcon{book-open}\hspace{5pt}#1}
}

\newtcolorbox{importbox}[1][Important]{
  uqobox,
  colback=uqoRouge!6,
  borderline west={2.5pt}{0pt}{uqoRouge},
  coltitle=uqoRouge,
  title={\faIcon{exclamation-triangle}\hspace{5pt}#1}
}

\newtcolorbox{exbox}[1][Exemple]{
  uqobox,
  colback=uqoVert!7,
  borderline west={2.5pt}{0pt}{uqoVert},
  coltitle=uqoVert,
  title={\faIcon{lightbulb}\hspace{5pt}#1}
}

\newtcolorbox{notebox}[1][Note]{
  uqobox,
  colback=uqoOr!9,
  borderline west={2.5pt}{0pt}{uqoOr},
  coltitle=uqoOr!50!uqoGris,
  title={\faIcon{pen}\hspace{5pt}#1}
}

\newtcolorbox{quizbox}[1][Question]{
  uqobox,
  colback=uqoBleuClair!8,
  borderline west={2.5pt}{0pt}{uqoBleuClair},
  coltitle=uqoBleuClair!75!uqoNavy,
  title={\faIcon{question-circle}\hspace{5pt}#1}
}

% =============================================================================
% STYLES TikZ PARTAGÉS — diagrammes de flux et cartes
% =============================================================================
\tikzset{
  uqoflow/.style={rectangle, rounded corners, draw=uqoBleu, fill=uqoBgClair,
    text centered, font=\small, minimum height=0.58cm},
  uqostep/.style={uqoflow, text width=10.5cm},
  uqocard/.style={rectangle, rounded corners=6pt, draw=uqoBleu, fill=uqoBgClair,
    text centered, font=\small},
  uqoarrow/.style={->, thick, uqoBleu},
}

% =============================================================================
% LISTINGS
% =============================================================================
\lstset{
  basicstyle=\ttfamily\scriptsize,
  keywordstyle=\color{uqoBleu}\bfseries,
  commentstyle=\color{uqoGris}\itshape,
  stringstyle=\color{uqoVert},
  backgroundcolor=\color{uqoBgClair},
  frame=single,
  rulecolor=\color{uqoGrisClair},
  breaklines=true,
  showstringspaces=false,
  numbers=left,
  numberstyle=\tiny\color{uqoGris},
  tabsize=2
}

% =============================================================================
% GRAPHIQUES pgfplots — habillage discret par défaut
% =============================================================================
\pgfplotsset{
  /pgf/number format/1000 sep={},
  every axis/.append style={
    axis line style={uqoGris!55},
    tick style={uqoGris!55},
    tick label style={font=\scriptsize, color=uqoGris},
    label style={font=\small, color=uqoInk},
    legend style={font=\tiny, draw=uqoGrisClair, fill=white, fill opacity=0.9},
  },
}

% --- Anti-overflow pour tableaux ---
\renewcommand{\arraystretch}{1.08}

% =============================================================================
% COMMANDES UTILES
% =============================================================================
\newcommand{\uqotitle}[1]{\textcolor{uqoBleu}{\textbf{#1}}}
\newcommand{\uqohighlight}[1]{\textcolor{uqoOr!75!uqoGris}{\textbf{#1}}}
\newcommand{\uqoalert}[1]{\textcolor{uqoRouge}{\textbf{#1}}}
\newcommand{\uqogreen}[1]{\textcolor{uqoVert}{\textbf{#1}}}

% Séparateur visuel
\newcommand{\uqosep}{%
  \begin{center}
    \tikz{
      \fill[uqoOr] (0,0) circle (0.5mm);
      \draw[uqoGrisClair, line width=0.5pt] (0.25,0) -- (2.6,0);
      \draw[uqoGrisClair, line width=0.5pt] (-2.6,0) -- (-0.25,0);
    }%
  \end{center}
}

% =============================================================================
% SLIDE DE CONTACT
% =============================================================================
\newcommand{\contactslide}[1][]{%
  \begin{center}
  \tikz[baseline]{\node[fill=uqoBleu, text=uqoBlanc, circle, minimum size=10mm]
    {\faIcon{comments}};}\\[1.5mm]
  {\Large\color{uqoBleu}\textbf{Questions et discussion}}

  \vspace{0.2cm}
  \begin{tcolorbox}[enhanced, width=0.72\textwidth, boxrule=0pt, frame hidden,
      colback=uqoBgClair, arc=2.5pt,
      borderline north={1.4pt}{0pt}{uqoOr},
      left=10pt, right=10pt, top=8pt, bottom=8pt]
    \centering
    {\large\textbf{\color{uqoBleu}Simon-Pierre Boucher}}\\[1.5pt]
    {\small\color{uqoGris}\textit{Professeur} --- Département des sciences administratives}\\[5pt]
    {\small\textcolor{uqoOr}{\faIcon{envelope}}\hspace{5pt}%
      \href{mailto:simon-pierre.boucher@uqo.ca}{simon-pierre.boucher@uqo.ca}}\\[3pt]
    {\small\textcolor{uqoOr}{\faIcon{map-marker-alt}}\hspace{5pt}%
      Gatineau --- Pavillon Lucien-Brault}\\[1pt]
    {\footnotesize\color{uqoGris}101, rue Saint-Jean-Bosco, Gatineau (Québec) J8X~3X7}
  \end{tcolorbox}

  \ifx\\#1\\%
  \else
    \vspace{0.2cm}
    {\small\color{uqoGris}\faIcon{arrow-circle-right}\hspace{4pt}\textit{#1}}
  \fi
  \end{center}
}

\endinput
