/* Plugin A frontend — swatch grid + gallery. References tokens.css only. */

/* ==================================================================== */
/*  Gallery                                                              */
/* ==================================================================== */

.pm-gallery {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

/* ---- Main image area ---- */

/*
 * Safari (≤17) doesn't always compute `max-height: 100%` correctly when the
 * parent's height is derived from `aspect-ratio` alone — the inner <img>
 * renders at intrinsic size and overflows. Locking the image to
 * `width/height: 100%` with `object-fit: contain` is the cross-browser
 * recipe: the square frame is enforced by `aspect-ratio` on the parent and
 * the image scales inside it without cropping, regardless of source size.
 */
.pm-gallery__main {
	position: relative;
	width: 100%;
	aspect-ratio: 1 / 1;
	background: var(--pm-color-surface);
	overflow: hidden;
}

.pm-gallery__image {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	object-position: center;
	transition: opacity 0.2s ease;
}

/* ---- Arrows ---- */

.pm-gallery__arrow {
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--pm-color-surface);
	border: 1px solid var(--pm-color-border);
	border-radius: 50%;
	color: var(--pm-color-ink);
	cursor: pointer;
	z-index: 2;
	transition: background 0.15s ease, border-color 0.15s ease;
	padding: 0;
}

.pm-gallery__arrow:hover {
	background: var(--pm-color-ink);
	color: var(--pm-color-surface);
	border-color: var(--pm-color-ink);
}

.pm-gallery__arrow:focus-visible {
	outline: 2px solid var(--pm-color-accent);
	outline-offset: 2px;
}

.pm-gallery__arrow--prev {
	left: 12px;
}

.pm-gallery__arrow--next {
	right: 12px;
}

/* ---- Thumbnail strip ---- */

.pm-gallery__thumbs {
	display: flex;
	gap: 8px;
	justify-content: center;
}

/*
 * Neutralize Storefront's default `button` styles (background-color #43454b,
 * padding, focus outline in WC purple). Plain `:focus` is suppressed and
 * keyboard focus is opted back in via `:focus-visible` below.
 */
.pm-gallery__thumb,
.pm-gallery__thumb:hover,
.pm-gallery__thumb:focus,
.pm-gallery__thumb:active {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
	padding: 4px;
	border: 0;
	background: transparent;
	background-color: transparent;
	color: inherit;
	cursor: pointer;
	outline: none;
	box-shadow: none;
	font-weight: 400;
	-webkit-appearance: none;
	appearance: none;
	transition: opacity 0.15s ease;
}

.pm-gallery__thumb img {
	width: 64px;
	height: 64px;
	object-fit: contain;
	border-radius: var(--pm-radius-sm);
	display: block;
}

.pm-gallery__thumb-label {
	font-family: var(--pm-font-sans);
	font-size: 11px;
	color: var(--pm-color-muted);
	text-align: center;
	white-space: nowrap;
}

.pm-gallery__thumb--active .pm-gallery__thumb-label {
	color: var(--pm-color-ink);
	font-weight: 600;
}

.pm-gallery__thumb:hover:not(.pm-gallery__thumb--active) .pm-gallery__thumb-label {
	color: var(--pm-color-ink);
}

.pm-gallery__thumb:focus-visible {
	outline: 2px solid var(--pm-color-accent);
	outline-offset: 2px;
}

/* ==================================================================== */
/*  Swatch section                                                       */
/* ==================================================================== */

.pm-swatches {
	margin: 4px 0 16px;
}

.pm-swatches__header {
	display: flex;
	align-items: baseline;
	gap: 10px;
	margin-bottom: 12px;
}

.pm-swatches__title {
	font-family: var(--pm-font-sans);
	font-size: 14px;
	font-weight: 600;
	color: var(--pm-color-ink);
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.pm-swatches__selected-label {
	font-family: var(--pm-font-sans);
	font-size: 14px;
	font-weight: 400;
	color: var(--pm-color-muted);
}

/* ---- Grid ---- */

.pm-swatches__grid {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

/* ---- Individual swatch ---- */

/*
 * Same Storefront-button neutralization as the gallery thumb. Without this,
 * Storefront's `button:focus { outline: 2px solid #7f54b3 }` paints a purple
 * ring around the swatch on click.
 */
.pm-swatch,
.pm-swatch:hover,
.pm-swatch:focus,
.pm-swatch:active {
	position: relative;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 2px solid transparent;
	border-radius: 50%;
	background: transparent;
	background-color: transparent;
	color: inherit;
	cursor: pointer;
	outline: none;
	box-shadow: none;
	font-weight: 400;
	-webkit-appearance: none;
	appearance: none;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: border-color 0.15s ease, transform 0.15s ease;
}

/* Day 10 a11y — expand the touch target without changing the visual
   footprint. ::before sits behind the visible swatch and gives every
   click within ±6 px a hit. Total hit area = 44 × 44 (Apple HIG floor).
   Uses ::before (not ::after) so it doesn't collide with the tooltip
   ::after rule further down — properties of two same-element pseudos
   on the same selector merge in unpredictable ways, which surfaced as
   a malformed tooltip overlay on the selected swatch (QA 2026-05-30). */
.pm-swatch::before {
	content: '';
	position: absolute;
	inset: -6px;
	border-radius: inherit;
	pointer-events: auto;
}

.pm-swatch__fill {
	display: block;
	width: 24px;
	height: 24px;
	border-radius: 50%;
}

/* Light colors get a hairline so they're visible on white */
.pm-swatch--light .pm-swatch__fill {
	box-shadow: inset 0 0 0 1px var(--pm-color-border);
}

/* Checkmark — hidden by default */
.pm-swatch__check {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: var(--pm-color-surface);
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.15s ease;
	line-height: 0;
}

/* Dark-on-light: swap check color so it's visible */
.pm-swatch--light .pm-swatch__check {
	color: var(--pm-color-ink);
}

/* ---- Selected state ---- */

/*
 * `.pm-swatch.pm-swatch--selected` (specificity 0,2,0) is needed to beat the
 * base `.pm-swatch:hover` reset above (also 0,2,0) — without the doubled
 * class, hovering the selected swatch would erase the ink-color ring.
 */
.pm-swatch.pm-swatch--selected {
	border-color: var(--pm-color-ink);
}

.pm-swatch--selected .pm-swatch__check {
	opacity: 1;
}

/* ---- Hover ---- */

.pm-swatch:hover:not(.pm-swatch--selected) {
	border-color: var(--pm-color-muted);
}

/* ---- Focus (keyboard only) ---- */

.pm-swatch:focus-visible {
	outline: 2px solid var(--pm-color-accent);
	outline-offset: 2px;
}

/* ---- Tooltip ---- */

/*
 * `display: block` is required — Storefront's stylesheet sets
 * `button::after { display: none }` which would otherwise hide the tooltip
 * regardless of our content/opacity values.
 */
.pm-swatch::after {
	content: attr(data-label);
	display: block;
	visibility: visible;
	position: absolute;
	bottom: calc(100% + 8px);
	left: 50%;
	transform: translateX(-50%);
	padding: 4px 8px;
	background: var(--pm-color-ink);
	color: var(--pm-color-surface);
	font-family: var(--pm-font-sans);
	font-size: 12px;
	line-height: 1.2;
	white-space: nowrap;
	border-radius: var(--pm-radius-sm);
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.15s ease;
	z-index: 10;
}

.pm-swatch:hover::after,
.pm-swatch:focus-visible::after {
	opacity: 1;
}

/* ==================================================================== */
/*  Mobile                                                               */
/* ==================================================================== */

@media (max-width: 768px) {
	.pm-gallery__arrow {
		/* Day 10 — bumped from 32px to 44px so touch users hit reliably.
		   Visual feels chunkier but it's the only way to make a circular
		   button on a gallery image actually tappable on phones. */
		width: 44px;
		height: 44px;
	}

	.pm-gallery__arrow--prev {
		left: 8px;
	}

	.pm-gallery__arrow--next {
		right: 8px;
	}

	.pm-gallery__thumb img {
		width: 52px;
		height: 52px;
	}

	.pm-gallery__thumb-label {
		font-size: 10px;
	}

	.pm-swatch {
		width: 30px;
		height: 30px;
	}

	.pm-swatch__fill {
		width: 22px;
		height: 22px;
	}

	.pm-swatches__grid {
		gap: 5px;
	}

	.pm-swatch::after {
		display: none;
	}
}
