%#!pdflatex --synctex=1 test-pdfmanagement
% =====================================================================
% test-pdfmanagement.tex — Issue #2 reproduction & compatibility test
% =====================================================================
% This file tests spotxcolor with pdfmanagement active.
%
% pdfmanagement (part of l3backend/l3pdf) takes over PDF resource
% management. Direct \pdfpageresources access (or \special{pdf:put})
% causes conflicts when pdfmanagement is active.
%
% v1.5 of spotxcolor should detect pdfmanagement and switch to the
% \pdfmanagement_add:nnn API automatically.
%
% Expected behavior:
%   - Compiles without error on pdflatex and lualatex
%   - Spot colors render correctly in text and TikZ
%   - No "pdfmanagement is active" warnings from l3backend
%   - PDF structure contains proper /ColorSpace entries
% =====================================================================

\DocumentMetadata{}  % Activates pdfmanagement (l3pdf)

\documentclass{article}\listfiles\pagestyle{empty}

\usepackage[table]{xcolor}
\usepackage{tikz}
\usetikzlibrary{patterns.meta}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\usepackage{spotxcolor}
\definespotcolor{DIC161s}{DIC 161s*}{0, 0.64, 1, 0}   % Vermilion
\definespotcolor{DIC256s}{DIC 256s*}{0.9, 0, 0.4, 0}   % Green
\definespotcolor{DIC200s}{DIC 200s*}{0.5, 0.8, 0, 0}   % Purple

\newcommand\onelineskip{\par\vspace{\baselineskip}\par}

\begin{document}

\sffamily\bfseries

\section{pdfmanagement Active --- Basic Tests}

\subsection*{Text Color}

\textcolor{DIC161s}{DIC 161s (Vermilion) --- 100\%}\par
\textcolor{DIC256s}{DIC 256s (Green) --- 100\%}\par
\textcolor{DIC200s}{DIC 200s (Purple) --- 100\%}

\onelineskip

\textcolor{DIC161s!50}{DIC 161s --- 50\%}\par
\textcolor{DIC256s!50}{DIC 256s --- 50\%}\par
\textcolor{DIC200s!50}{DIC 200s --- 50\%}

\subsection*{Page Color}

\clearpage
\pagecolor{DIC161s!20}

This page has a 20\% DIC 161s background (via pdfmanagement pathway).

\clearpage
\nopagecolor

\section{pdfmanagement Active --- TikZ Tests}

\subsection*{Simple Shapes (Three Colors)}

\begin{tikzpicture}
  \fill[DIC161s] (0,0) circle (1.2);
  \fill[DIC256s!50] (3,0) circle (1.2);
  \draw[DIC200s, ultra thick, fill=DIC200s!15, rounded corners]
    (5.5,-1.2) rectangle (8.5,1.2);
  \node[DIC200s] at (7,0) {\textsf{200s}};
\end{tikzpicture}

\onelineskip

\subsection*{Pattern Fills (Three Colors)}

\begin{tikzpicture}
  \draw[DIC161s, ultra thick,
    pattern={Lines[angle=45, distance=6pt, line width=1.5pt]},
    pattern color=DIC161s!60]
    (0,0) rectangle (3, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC161s] {161s};

  \draw[DIC256s, ultra thick,
    pattern={Lines[angle=-45, distance=6pt, line width=1.5pt]},
    pattern color=DIC256s!60]
    (4,0) rectangle (7, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC256s] {256s};

  \draw[DIC200s, ultra thick,
    pattern={Dots[distance=3mm, radius=1mm]},
    pattern color=DIC200s!50]
    (8,0) rectangle (11, 2)
    node[pos=0.5, fill=white, inner sep=2pt, font=\sffamily\small, text=DIC200s] {200s};
\end{tikzpicture}

\onelineskip

\subsection*{Multiply Blend Mode}

\begin{tikzpicture}
  \fill[gray!10] (-1.5,-2) rectangle (4.5,3);
  \begin{scope}[blend mode=multiply]
    \fill[DIC161s] (90:1) circle (1.3);
    \fill[DIC256s] (210:1) circle (1.3);
    \fill[DIC200s] (330:1) circle (1.3);
  \end{scope}
  \node[font=\sffamily\small] at (1.5, 2.8) {Multiply blend (pdfmanagement active)};
\end{tikzpicture}

\section{pdfmanagement Active --- tcolorbox}

\begin{tcolorbox}[
  enhanced,
  colframe=DIC256s,
  colback=DIC256s!5,
  coltitle=white,
  colbacktitle=DIC256s!80,
  fonttitle=\sffamily\bfseries\Large,
  title={pdfmanagement + spotxcolor},
  drop fuzzy shadow=DIC256s!30
]
If this box renders correctly with green frame, title, and shadow,
then \textsf{spotxcolor} is working with pdfmanagement active.

\onelineskip

\textcolor{DIC161s}{\textbf{Vermilion}},
\textcolor{DIC256s}{\textbf{Green}},
\textcolor{DIC200s}{\textbf{Purple}} ---
all three spot colors in one box.
\end{tcolorbox}

\section{pdfmanagement Active --- l3color Interface}

\begingroup
\ExplSyntaxOn
\color_select:n{DIC161s}
This~text~uses~\texttt{\string\color_select:n\{DIC161s\}}~(l3color~API).
\ExplSyntaxOff
\endgroup

\onelineskip

\begingroup
\ExplSyntaxOn
\color_select:n{DIC256s!50}
This~text~uses~\texttt{\string\color_select:n\{DIC256s!50\}}~at~50\%~tint.
\ExplSyntaxOff
\endgroup

\end{document}
