/**
 * COA Manager
 *
 * Inherits the theme rather than fighting it: no font-family, no font-size, no
 * hard-coded width, sizes in em, and colour literals confined to the token block
 * below. Every selector is scoped under .coa-storefront or .coa-lightbox, and
 * there is exactly one !important (print).
 */

.coa-storefront {
	/* Colour literals live ONLY here, and only as the pre-color-mix fallback: an
	   old browser gets the measured greys, a modern one derives them from the
	   theme's own text colour so the card follows a dark theme instead of
	   punching a light hole in it. A site that wants the measured hexes forever
	   re-declares these properties and nothing else. */
	--coa-surface: #f9f9f9;
	--coa-surface: color-mix(in srgb, currentColor 4%, transparent);

	--coa-border: #e2e2e2;
	--coa-border: color-mix(in srgb, currentColor 14%, transparent);

	--coa-text: #777777;
	--coa-text: color-mix(in srgb, currentColor 72%, transparent);

	--coa-label: #999999;
	--coa-label: color-mix(in srgb, currentColor 55%, transparent);

	/* The raised inner box has to be LIGHTER than the card, which a translucent
	   tint cannot be — so this one needs an opaque value. Canvas is the page's
	   own canvas colour and flips with the colour scheme. */
	--coa-raised: #ffffff;
	--coa-raised: Canvas;

	--coa-radius: 0.25em;
	--coa-card-radius: 0;
	--coa-card-pad: 1.5em; /* 24px at a 16px base */

	display: grid;
	gap: 1em;
	padding: var(--coa-card-pad);
	margin-block-end: 2em; /* 32px */
	background: var(--coa-surface);
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-card-radius);
	color: var(--coa-text);
}

/* Not every theme sets this globally, and padding + border on the card make it
   load-bearing here. Scoped, so it cannot leak. */
.coa-storefront,
.coa-storefront *,
.coa-storefront *::before,
.coa-storefront *::after {
	box-sizing: border-box;
}

.coa-storefront__heading {
	margin: 0;
	color: inherit;
}

.coa-storefront__body {
	display: grid;
	gap: 1em;
}

.coa-storefront[aria-busy="true"] .coa-storefront__body {
	opacity: 0.5;
	transition: opacity 0.12s ease;
}

@media (prefers-reduced-motion: reduce) {
	.coa-storefront__body {
		transition: none;
	}
}

.coa-storefront__prompt,
.coa-storefront__empty,
.coa-storefront__error {
	margin: 0;
	color: var(--coa-label);
}

/* ---------- the latest box ---------- */

.coa-latest {
	display: grid;
	gap: 1em;
	padding: 1em;
	background: var(--coa-raised);
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-card-radius);
}

.coa-latest__note {
	margin: 0;
	font-size: 0.85em;
	color: var(--coa-label);
}

/* ---------- the facts grid ---------- */

.coa-facts {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(8em, 1fr));
	gap: 0.75em 1em;
	margin: 0;
}

.coa-facts__cell--wide {
	grid-column: 1 / -1;
}

.coa-facts__label {
	margin: 0 0 0.15em;
	font-size: 0.72em;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--coa-label);
}

/* Punctuation belongs to the design, not to the translator. */
.coa-facts__label::after {
	content: ":";
}

.coa-facts__value {
	margin: 0;
	font-weight: 600;
	color: inherit;
	/* Lot codes are unspaced and can overflow a narrow sidebar column. */
	overflow-wrap: anywhere;
}

/* ---------- the view controls ---------- */

.coa-view {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4em;
	cursor: pointer;
	text-decoration: none;
}

.coa-view--primary {
	width: 100%;
	padding: 0.7em 1em;
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-radius);
	font-weight: 600;
}

.coa-view--link {
	margin-inline-start: auto; /* right-aligns the row's View */
	padding: 0.25em 0.6em;
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-radius);
	font-size: 0.85em;
	white-space: nowrap;
}

/* Themes routinely remove outlines; restore one locally. */
.coa-view:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

/* ---------- history ---------- */

.coa-history {
	background: var(--coa-raised);
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-card-radius);
}

.coa-history__toggle {
	display: flex;
	align-items: center;
	gap: 0.75em;
	padding: 0.7em 0.9em;
	cursor: pointer;
	list-style: none;
	font-weight: 600;
}

/* Replace the disclosure marker with a CSS chevron so nothing is announced. */
.coa-history__toggle::-webkit-details-marker {
	display: none;
}

.coa-history__toggle::after {
	content: "";
	margin-inline-start: auto;
	width: 0.5em;
	height: 0.5em;
	border-right: 2px solid currentColor;
	border-bottom: 2px solid currentColor;
	transform: rotate(45deg) translate(-0.1em, -0.1em); /* down */
	opacity: 0.6;
}

.coa-history[open] .coa-history__toggle::after {
	transform: rotate(-135deg) translate(-0.1em, -0.1em); /* up */
}

.coa-history__toggle:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.coa-history__list {
	list-style: none;
	margin: 0;
	padding: 0;
}

/* Hairlines BETWEEN rows only — a border on every row would double up against
   the container's own edge. */
.coa-history__item + .coa-history__item {
	border-top: 1px solid var(--coa-border);
}

.coa-row {
	display: flex;
	align-items: center;
	gap: 0.6em;
	flex-wrap: wrap;
	padding: 0.6em 0.9em;
}

.coa-row__date {
	font-weight: 700;
	color: inherit;
}

.coa-row__lot,
.coa-row__unavailable {
	font-size: 0.85em;
	color: var(--coa-label);
	overflow-wrap: anywhere;
}

.coa-row__unavailable {
	margin-inline-start: auto;
	font-style: italic;
}

/* ---------- no-JS page links ---------- */

.coa-pagelinks {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 0.5em;
}

.coa-pages__note {
	margin: 0;
	color: var(--coa-label);
}

/* ---------- lightbox ---------- */

.coa-lightbox {
	border: 0;
	padding: 0;
	max-width: min(96vw, 1100px);
	max-height: 94vh;
	background: transparent;
}

.coa-lightbox::backdrop {
	background: rgba(0, 0, 0, 0.8);
}

.coa-lightbox__img {
	display: block;
	max-width: 100%;
	max-height: 84vh;
	margin: 0 auto;
	object-fit: contain;
}

.coa-lightbox__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75em;
	padding: 0.5em;
	color: #fff;
}

.coa-lightbox__bar button {
	cursor: pointer;
}

.coa-lightbox__counter {
	font-variant-numeric: tabular-nums;
}

/* The accessible name of every View control now depends on this class, so do
   not assume the theme defines it. */
.coa-storefront .screen-reader-text,
.coa-lightbox .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* ---------- print ---------- */

@media print {
	/* Customers do print certificates — force the history list open. Note the
	   page images are no longer in the document at all, so what prints is the
	   lot/date record, not the scans. */
	.coa-history:not([open]) > .coa-history__list {
		display: block !important;
	}

	.coa-storefront__prompt,
	.coa-storefront__retry,
	.coa-view,
	.coa-lightbox {
		display: none;
	}
}

/* ---------- lookup page ---------- */

.coa-lookup {
	display: grid;
	gap: 1.5em;
	--coa-border: #e2e2e2;
	--coa-border: color-mix(in srgb, currentColor 14%, transparent);
	--coa-label: #999999;
	--coa-label: color-mix(in srgb, currentColor 55%, transparent);
	--coa-radius: 0.25em;
}

.coa-lookup__form {
	display: grid;
	gap: 0.4em;
}

.coa-lookup__label {
	font-weight: 600;
}

.coa-lookup__controls {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5em;
}

.coa-lookup__input {
	flex: 1 1 14em;
	min-width: 0;
}

.coa-lookup__hint,
.coa-lookup__note,
.coa-lookup__message {
	margin: 0;
	font-size: 0.9em;
	color: var(--coa-label);
}

.coa-lookup__count {
	margin: 0 0 0.5em;
}

.coa-lookup__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 0.75em;
}

.coa-result {
	display: grid;
	gap: 0.6em;
	padding: 1em;
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-radius);
}

.coa-result__title {
	margin: 0;
}

.coa-result__note {
	margin: 0;
	font-size: 0.85em;
	color: var(--coa-label);
}

/* The result card reuses .coa-facts and .coa-view from the product-page card,
   but those are scoped under .coa-storefront — restate the few rules the
   lookup page needs so it does not depend on a product section being present. */
.coa-lookup .coa-facts {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(8em, 1fr));
	gap: 0.5em 1em;
	margin: 0;
}

.coa-lookup .coa-facts__cell--wide {
	grid-column: 1 / -1;
}

.coa-lookup .coa-facts__label {
	margin: 0 0 0.15em;
	font-size: 0.72em;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--coa-label);
}

.coa-lookup .coa-facts__label::after {
	content: ":";
}

.coa-lookup .coa-facts__value {
	margin: 0;
	font-weight: 600;
	overflow-wrap: anywhere;
}

.coa-lookup .coa-view {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4em;
	justify-self: start;
	padding: 0.4em 0.9em;
	border: 1px solid var(--coa-border);
	border-radius: var(--coa-radius);
	text-decoration: none;
	cursor: pointer;
}

.coa-lookup .coa-view:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.coa-lookup .screen-reader-text {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}
