\documentclass[11pt,letterpaper]{article}
\usepackage[margin=0.75in]{geometry}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{needspace}

\hypersetup{colorlinks=true,linkcolor=blue,urlcolor=blue}
\pagestyle{plain}
\setlength{\parindent}{0pt}
\setlength{\parskip}{4pt}

% Section styling with underline for clear separation
\newcommand{\resumesection}[1]{\needspace{5\baselineskip}\section*{#1}\vspace{-4pt}\hrule\vspace{6pt}}

{{- if .Layout }}
{{- if eq (default "standard" .Layout.Density) "compact" }}
% Compact density overrides
\geometry{margin=0.5in}
\setlength{\parskip}{2pt}
{{- else if eq .Layout.Density "detailed" }}
% Detailed density overrides
\geometry{margin=1in}
\setlength{\parskip}{6pt}
{{- end }}
{{- if eq (default "classic" .Layout.Typography) "modern" }}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
{{- else if eq .Layout.Typography "elegant" }}
\usepackage{charter}
{{- end }}
{{- end }}

\begin{document}

% Header
\begin{center}
{\LARGE\bfseries {{ escape .Contact.Name }}}\\[4pt]
{{- if .Contact.Headline }}
{\large\itshape {{ escape .Contact.Headline }}}\\[4pt]
{{- end }}
{{ escape .Contact.Email }}
{{- if .Contact.Phone }} $|$ {{ escape .Contact.Phone }}{{ end -}}
{{- if .Contact.Credentials }} $|$ {{ escape .Contact.Credentials }}{{ end -}}
{{- if .Contact.Links }}\\{{ end }}
{{- range $i, $link := .Contact.Links }}{{ if $i }} $|$ {{ end }}\url{ {{- $link.URI -}} }{{ end }}
\end{center}

\vspace{8pt}

{{/* ============================================================================
     SECTION DEFINITIONS
     ============================================================================ */}}

{{- define "cv-section-summary" -}}
{{- if .Summary }}
\resumesection{Professional Summary}
{{ emphasize .Summary .Layout }}
{{- end }}
{{- end -}}

{{- define "cv-section-certifications" -}}
{{- if .Certifications }}
{{- if .Certifications.Items }}
\resumesection{ {{- escape (default "Certifications" .Certifications.Title) -}} }
\begin{itemize}[leftmargin=*,nosep]
{{- range .Certifications.Items }}
\item {{ escape .Name }}{{- if .Issuer }} --- {{ escape .Issuer }}{{- end }}{{- if .Notes }} ({{ escape .Notes }}){{- end }}
{{- end }}
\end{itemize}
{{- end }}
{{- end }}
{{- end -}}

{{- define "cv-section-experience" -}}
{{- if .Experience.Positions }}
\resumesection{ {{- escape (default "Professional Experience" .Experience.Title) -}} }

{{- range $exp := sortExperienceByOrder .Experience.Positions }}
\needspace{6\baselineskip}
\noindent\textbf{ {{- escape $exp.Title -}} }{{ if $exp.EmploymentType }} ({{ employmentType $exp.EmploymentType }}){{ end }} \hfill {{ fmtDateLegal $exp.Dates.Start }} - {{ if $exp.Dates.End }}{{ fmtDateLegal $exp.Dates.End }}{{ else }}Present{{ end }}\nopagebreak

\textbf{ {{- escape $exp.Company -}} }

{{- if $exp.Location }}

\textit{ {{- formatLocationFull $exp.Location -}} }
{{- end }}

{{- if $exp.Notes }}

\textit{Note: {{ escape $exp.Notes }}}
{{- end }}

{{- if $exp.Technologies }}

\textit{Technologies: {{ join ", " $exp.Technologies }}}
{{- end }}

{{- $duties := $exp.Duties }}
{{- if not $duties }}{{ $duties = $exp.Highlights }}{{ end }}
{{- if $duties }}

\needspace{3\baselineskip}
\textbf{Job Description:}
\begin{itemize}[leftmargin=*,nosep]
{{- range $duties }}
\item {{ emphasize . $.Layout }}
{{- end }}
\end{itemize}
{{- end }}

{{- if and $exp.Highlights $exp.Duties }}

\needspace{3\baselineskip}
\textbf{Notable Achievements:}
\begin{itemize}[leftmargin=*,nosep]
{{- range $exp.Highlights }}
\item {{ emphasize . $.Layout }}
{{- end }}
\end{itemize}
{{- end }}

\vspace{6pt plus 4pt minus 2pt}
\pagebreak[2]
{{- end }}
{{- end }}
{{- end -}}

{{- define "cv-section-education" -}}
{{- if .Education.Institutions }}
\resumesection{ {{- escape (default "Education" .Education.Title) -}} }

{{- range $edu := sortEducationByOrder .Education.Institutions }}
\needspace{3\baselineskip}
\noindent\textbf{ {{- escape $edu.Institution -}} } \hfill {{ fmtDateLegal $edu.Dates.Start }} - {{ if $edu.Dates.End }}{{ fmtDateLegal $edu.Dates.End }}{{ else }}In Progress{{ end }}
{{- if $edu.Location }}

\textit{ {{- formatLocationFull $edu.Location -}} }
{{- end }}

\textit{ {{- escape $edu.Degree.Name -}} }

{{- if $edu.GPA }}

\textbf{GPA:} {{ $edu.GPA.GPA }}{{ if $edu.GPA.MaxGPA }} / {{ $edu.GPA.MaxGPA }}{{ end }}
{{- end }}

{{- if $edu.Specializations }}

\textbf{Specialization(s):} {{ join ", " $edu.Specializations }}
{{- end }}

{{- if $edu.Thesis }}

\textbf{Thesis:} {{ escape $edu.Thesis.Title }}
{{- if $edu.Thesis.Link.URI }} (\url{ {{- $edu.Thesis.Link.URI -}} }){{ end }}
{{- end }}

{{- if $edu.Awards }}

\textbf{Awards:}
\begin{itemize}[leftmargin=*,nosep]
{{- range $edu.Awards }}
\item {{ escape .Name }}{{ if .Date }} ({{ fmtDateLegal .Date }}){{ end }}{{ if .Notes }} -- {{ escape .Notes }}{{ end }}
{{- end }}
\end{itemize}
{{- end }}

\vspace{6pt plus 4pt minus 2pt}
{{- end }}
{{- end }}
{{- end -}}

{{- define "cv-section-skills" -}}
{{- if .Skills.Categories }}
\resumesection{ {{- escape (default "Skills" .Skills.Title) -}} }
\begin{description}
{{- range .Skills.Categories }}
    \item[{{ escape .Category }}:] {{ join ", " .Items }}
{{- end }}
\end{description}
{{- end }}
{{- end -}}

{{- define "cv-section-projects" -}}
{{- if .Projects }}
{{- if .Projects.Projects }}
\resumesection{ {{- escape (default "Projects" .Projects.Title) -}} }

{{- range sortProjectsByOrder .Projects.Projects }}

\noindent\textbf{ {{- escape .Name -}} }
{{- if .Link.URI }} --- \url{ {{- .Link.URI -}} }{{ end }}
{{- if .Technologies }}

\textit{Technologies: {{ join ", " .Technologies }}}
{{- end }}
{{- if .Highlights }}
\begin{itemize}[leftmargin=*,nosep]
{{- range .Highlights }}
\item {{ emphasize . $.Layout }}
{{- end }}
\end{itemize}
{{- end }}

\vspace{6pt plus 4pt minus 2pt}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

{{- define "cv-section-languages" -}}
{{- if .Languages }}
{{- if .Languages.Languages }}
\resumesection{ {{- escape (default "Languages" .Languages.Title) -}} }
\begin{itemize}[leftmargin=*,nosep]
{{- range .Languages.Languages }}
\item {{ escape .Name }}{{- if .Proficiency }} --- {{ escape .Proficiency }}{{- end }}
{{- end }}
\end{itemize}
{{- end }}
{{- end }}
{{- end -}}

{{/* ============================================================================
     SECTION DISPATCH
     ============================================================================ */}}

{{- $root := . -}}
{{- range .SectionOrder -}}
{{- if eq . "summary"}}{{template "cv-section-summary" $root}}
{{- else if eq . "certifications"}}{{template "cv-section-certifications" $root}}
{{- else if eq . "experience"}}{{template "cv-section-experience" $root}}
{{- else if eq . "education"}}{{template "cv-section-education" $root}}
{{- else if eq . "skills"}}{{template "cv-section-skills" $root}}
{{- else if eq . "projects"}}{{template "cv-section-projects" $root}}
{{- else if eq . "languages"}}{{template "cv-section-languages" $root}}
{{- end}}
{{- end}}

{{- if and .Layout .Layout.References }}

\vfill
\begin{center}\textit{References available upon request}\end{center}
{{- end }}

\end{document}
