% Optics Beamer Theme
% Author: admin
% Usage: \usetheme{Optics}
% Optics Beamer Theme
% Professional minimal theme which I use for optics presentations
% Author: admin
% Usage: \usetheme{Optics}


\mode<presentation>
\usepackage[default]{lato}
\usepackage[T1]{fontenc}

% Base theme
\usetheme{default}
\usecolortheme{default}

% Improved color palette
\definecolor{primary}{RGB}{20,40,120}      % Darker blue for better contrast
\definecolor{secondary}{RGB}{95,95,95}     % Professional gray
\definecolor{accent}{RGB}{0,82,155}        % Accessible blue
\definecolor{lightgray}{RGB}{248,249,250}  % Very light gray for backgrounds
\definecolor{darkgreen}{RGB}{0,140,0}

% Keep original darkblue for compatibility
\definecolor{darkblue}{RGB}{20,40,120}
\newcommand{\descr}[1]{{\footnotesize\color{secondary}#1}}

% Remove navigation symbols
\setbeamertemplate{navigation symbols}{}
% Captions
\setbeamerfont{caption}{size=\tiny}
\setbeamerfont{caption name}{size=\tiny} 
\setbeamertemplate{caption}{\tiny\color{darkblue}\insertcaptionname~\insertcaptionnumber: \color{black}\insertcaption}
\setlength{\abovecaptionskip}{-6pt}
\setlength{\belowcaptionskip}{6pt}

% Custom command for location
\newcommand{\location}[1]{\def\insertlocation{#1}}
\location{} % Default empty
\newcommand{\email}[1]{\def\insertemail{#1}}
\email{} % Default empty
\newcommand{\website}[2]{\def\insertwebsitename{#1}\def\insertwebsiteurl{#2}}
\newcommand{\insertwebsite}{%
  \ifx\insertwebsitename\empty%
  \else%
    \href{\insertwebsiteurl}{\faGlobe\ \insertwebsitename}%
  \fi%
}
\website{}{} % Default empty
% Clean header with presentation title in dark blue

\setbeamertemplate{headline}{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1ex]{title in head/foot}%
    \usebeamerfont{title in head/foot}%
    \begin{minipage}[c]{0.33\paperwidth}%
      \color{darkblue}\hspace{1em}\insertsection%
    \end{minipage}%
    \begin{minipage}[c]{0.67\paperwidth}%
      \ifnum\value{framenumber}>1% Only show author after title page
        \color{darkblue}%
        \ifx\insertwebsitename\empty%
          % No website: flush author right
          \raggedleft%
          \ifx\insertemail\empty%
            \insertauthor\hspace{1em}%
          \else%
              \href{mailto:\insertemail}{\faEnvelope\ \insertauthor\hspace{1em}}%
          \fi%
        \else%
          % Website exists: center website, then flush author right
          \begin{minipage}[c]{0.5\linewidth}%
            \centering%
            \insertwebsite%
          \end{minipage}%
          \begin{minipage}[c]{0.5\linewidth}%
            \raggedleft%
            \ifx\insertemail\empty%
              \insertauthor\hspace{1em}%
            \else%
              \href{mailto:\insertemail}{\faEnvelope\ \insertauthor\hspace{1em}}%
            \fi%
          \end{minipage}%
        \fi%
      \fi%
    \end{minipage}%
  \end{beamercolorbox}%
  \vskip0pt%
}


% Custom title page with location
\setbeamertemplate{title page}{%
  \vbox{}
  \vfill
  \begingroup
    \centering
    \begin{beamercolorbox}[sep=8pt,center]{title}
      \usebeamerfont{title}\color{darkblue}\bfseries\inserttitle\par%
      \ifx\insertsubtitle\@empty%
      \else%
        \vskip0.25em%
        {\usebeamerfont{subtitle}\insertsubtitle\par}%
      \fi%     
    \end{beamercolorbox}%
    \vskip1em\par
    \ifx\insertwebsitename\empty%
    \else%
      \begin{beamercolorbox}[sep=4pt,center]{author}
        \usebeamerfont{author}\insertwebsite
      \end{beamercolorbox}
    \fi%
    \begin{beamercolorbox}[sep=8pt,center]{author}
      \usebeamerfont{author}%
      \ifx\insertemail\empty%
        \insertauthor%
      \else%
            \href{mailto:\insertemail}{\faEnvelope\ \insertauthor}%
      \fi%
    \end{beamercolorbox}
    \begin{beamercolorbox}[sep=8pt,center]{date}
        \usebeamerfont{date}\textit{\insertdate}
      \ifx\insertlocation\empty%
      \else%
        \par\vskip0.25em%
        \insertlocation%
      \fi%
    \end{beamercolorbox}
  \endgroup
  \vfill
}

% Enhanced footer with title, date, location, and page numbers
\setbeamertemplate{footline}{%
  \begin{beamercolorbox}[wd=\paperwidth,ht=0.5pt]{primary}%
    \color{darkblue}\hrule height 0.5pt%
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.5ex,dp=1ex]{title in head/foot}%
    \usebeamerfont{title in head/foot}%
    \color{secondary}%
    \begin{minipage}[c]{0.33\paperwidth}%
      \hspace{1em}\insertshorttitle $\cdot$ \insertsubtitle%
    \end{minipage}%
    \begin{minipage}[c]{0.34\paperwidth}%
      \centering%
      \ifx\insertlocation\empty%
        \insertdate%
      \else%
        \insertdate\ $\cdot$ \insertlocation%
      \fi%
    \end{minipage}%
    \begin{minipage}[c]{0.33\paperwidth}%
      \raggedleft%
      \insertframenumber{} / \inserttotalframenumber \hspace*{1em}%
    \end{minipage}%
  \end{beamercolorbox}%
}

% Frame title with dark blue and underline
% Fixed positioning for consistency
\setbeamertemplate{frametitle}{%
  \nointerlineskip%
  \begin{beamercolorbox}[wd=\paperwidth,ht=2.2ex,dp=0.8ex,leftskip=1em]{frametitle}%
    \usebeamerfont{frametitle}\color{darkblue}\bfseries\Large\insertframetitle%
  \end{beamercolorbox}%
  \nointerlineskip%
  \begin{beamercolorbox}[wd=\paperwidth,ht=0.1pt,dp=0pt,leftskip=1em,rightskip=1em]{frametitle}%
    \color{darkblue}\hrule height 0.8pt%
  \end{beamercolorbox}%
    \vspace{-0.8em}%
}

% List items
\setbeamertemplate{itemize item}{\raisebox{0.2ex}{\textcolor{accent}{\rule{0.4em}{0.4em}}}\hspace{0.3em}}
\setbeamertemplate{itemize subitem}{\raisebox{0.2ex}{\textcolor{darkblue}{\textbullet}}\hspace{0.3em}}
\setbeamertemplate{itemize subsubitem}{\raisebox{0.1ex}{\textcolor{darkblue}{--}}\hspace{0.3em}}

% Improved spacing for readability
\setlength{\leftmargini}{1.5em}
\setlength{\leftmarginii}{1.2em}
\setbeamertemplate{itemize/enumerate body begin}{\vspace{0.5em}}
\setbeamertemplate{itemize/enumerate body end}{\vspace{0.3em}}

% Add space between items
\let\olditem\item
\renewcommand{\item}{\olditem\vspace{0.4em}}

% Table of contents customization
\setbeamertemplate{section in toc}{\Large\bfseries\color{darkblue}\inserttocsection}
\setbeamertemplate{section in toc shaded}{\Large\bfseries\color{secondary}\inserttocsection}
\setbeamertemplate{subsection in toc}{\normalsize\par\hspace{1.2em}$\bullet$~\inserttocsubsection}
\setbeamertemplate{subsection in toc shaded}{\normalsize\par\hspace{1.2em}\color{secondary}$\bullet$~\inserttocsubsection}

% Color Scheme
\setbeamercolor{title}{fg=darkblue}
\setbeamercolor{frametitle}{fg=darkblue,bg=white}
\setbeamercolor{normal text}{fg=black,bg=white}
\setbeamercolor{item}{fg=darkblue}
\setbeamercolor{title in head/foot}{fg=darkblue}

% Bibliography formatting
\setbeamercolor{bibliography entry author}{fg=darkblue}
\setbeamercolor{bibliography entry title}{fg=black}
\setbeamercolor{bibliography entry location}{fg=gray}
\setbeamercolor{bibliography entry note}{fg=gray}
\setbeamertemplate{bibliography item}{\insertbiblabel}

\AtBeginSection[ ]
{
\begingroup
\def\insertsection{}
\begin{frame}{Contents}
    \tableofcontents[currentsection,hideallsubsections]
\end{frame}
\endgroup
}
\addtobeamertemplate{frame begin}{%
  \ifx\insertsubsectionhead\empty%
  \else%
    \frametitle{\insertsubsectionhead}%
  \fi%
}{}
\mode<all>
