/**
 * IGSHOP Shop Kit — product badges (includes/class-qav-badges.php): short
 * labels laid over a product photo, in one of nine spots.
 *
 * The markup is a layer that fills the photo, one box per spot in use, one
 * label per badge:
 *
 *   div.qav-badges[.qav-badges--pdp][.qav-badges--sale]
 *     > div.qav-badge-spot[data-pos="tl|tc|tr|cl|cc|cr|bl|bc|br"]
 *       > span.qav-badge
 *
 * The label's text and background colours are set inline on span.qav-badge
 * (they are the shop owner's choice). Everything else is here.
 *
 * Every number worth changing is a custom property on .qav-badges, so a theme
 * can retune a badge without copying these rules. Example override:
 *
 *   .qav-badges { --qav-badge-edge: 16px; --qav-badge-sale-clear: 48px; }
 *
 * This file is also loaded on the category and product edit screens, where it
 * draws the preview photo.
 */

/* ---------------------------------------------------------------------------
   The box the layer fills
   A shop card: the .qav-thumb box around the photo (archive-variations.css
   gives it the same rule; it is repeated because that file loads only when the
   size pills, the price style or the hidden Add to cart button are on).
   The product page: the photo's own wrapper in the gallery, set only where the
   layer is, so no other gallery rule is touched.
   --------------------------------------------------------------------------- */

.qav-thumb {
	position: relative;
}

.woocommerce-product-gallery__image:has(> .qav-badges) {
	position: relative;
}

/* ---------------------------------------------------------------------------
   The layer
   --------------------------------------------------------------------------- */

.qav-badges {
	--qav-badge-edge: 10px;           /* Gap between a badge and the photo edge. */
	--qav-badge-gap: 4px;             /* Gap between badges in one stack. */
	--qav-badge-sale-clear: 42px;     /* How far in the corner stack starts, to clear the percent-off tag. */
	--qav-badge-radius: 4px;
	--qav-badge-size: 12px;
	--qav-badge-pad: 4px 9px;

	--qav-badge-top: var(--qav-badge-edge);       /* Where the top row of stacks starts. */
	--qav-badge-bottom: var(--qav-badge-edge);    /* Where the bottom row of stacks starts. */

	/* A corner stack, or the centre stack of an edge, can start further in than
	   its row, to clear a tag, the Atome badge or the photo counter. */
	--qav-badge-tl: var(--qav-badge-top);
	--qav-badge-tc: var(--qav-badge-top);
	--qav-badge-tr: var(--qav-badge-top);
	--qav-badge-bl: var(--qav-badge-bottom);
	--qav-badge-bc: var(--qav-badge-bottom);
	--qav-badge-br: var(--qav-badge-bottom);

	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: 2;
	/* A label only: taps and clicks go through to the product link. */
	pointer-events: none;
}

.qav-badge-spot {
	position: absolute;
	display: flex;
	flex-direction: column;
	gap: var(--qav-badge-gap);
	/* A long label in a centred spot must not be squeezed to half the photo. */
	width: max-content;
	max-width: calc(100% - (2 * var(--qav-badge-edge)));
}

.qav-badge-spot[data-pos$="l"] {
	left: var(--qav-badge-edge);
	align-items: flex-start;
}

.qav-badge-spot[data-pos$="c"] {
	left: 50%;
	align-items: center;
}

.qav-badge-spot[data-pos$="r"] {
	right: var(--qav-badge-edge);
	align-items: flex-end;
}

.qav-badge-spot[data-pos^="t"] {
	top: var(--qav-badge-top);
}

.qav-badge-spot[data-pos="tl"] {
	top: var(--qav-badge-tl);
}

.qav-badge-spot[data-pos="tc"] {
	top: var(--qav-badge-tc);
}

.qav-badge-spot[data-pos="tr"] {
	top: var(--qav-badge-tr);
}

.qav-badge-spot[data-pos^="c"] {
	top: 50%;
}

/* Bottom spots stack upward. */
.qav-badge-spot[data-pos^="b"] {
	bottom: var(--qav-badge-bottom);
	flex-direction: column-reverse;
}

.qav-badge-spot[data-pos="bl"] {
	bottom: var(--qav-badge-bl);
}

.qav-badge-spot[data-pos="bc"] {
	bottom: var(--qav-badge-bc);
}

.qav-badge-spot[data-pos="br"] {
	bottom: var(--qav-badge-br);
}

/* Centred spots are pulled back by half their own size, so a stack grows
   around the middle. */
.qav-badge-spot[data-pos="tc"],
.qav-badge-spot[data-pos="bc"] {
	transform: translateX(-50%);
}

.qav-badge-spot[data-pos="cl"],
.qav-badge-spot[data-pos="cr"] {
	transform: translateY(-50%);
}

.qav-badge-spot[data-pos="cc"] {
	transform: translate(-50%, -50%);
}

/* ---------------------------------------------------------------------------
   One label
   Bold and small, like the percent-off tag, with a hair of shadow so a pale
   badge still reads on a pale photo.
   --------------------------------------------------------------------------- */

.qav-badge {
	display: block;
	/* Border-box, so the 100% cap below includes the padding: a long label stays inside the photo
	   on a theme (and in the admin preview) that has no global border-box rule. */
	box-sizing: border-box;
	max-width: 100%;
	margin: 0;
	padding: var(--qav-badge-pad);
	overflow: hidden;
	border-radius: var(--qav-badge-radius);
	font-family: inherit;
	font-size: var(--qav-badge-size);
	font-weight: 700;
	line-height: 1.35;
	letter-spacing: 0.02em;
	text-align: left;
	text-decoration: none;
	text-overflow: ellipsis;
	text-transform: none;
	white-space: nowrap;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ---------------------------------------------------------------------------
   Things on the photo that a stack must clear
   Each rule below moves one row, one corner or one centre stack in by the size
   of the thing in the way. The size pills and the Atome badge are printed just
   before this layer, so a sibling selector (~) finds them. A theme's own chip
   is printed after the photo, so :has() finds that one; each :has() rule
   stands alone, because a browser without :has() drops the whole rule it is in.
   A theme that needs something else can set the same properties itself, e.g.
   .qav-badges { --qav-badge-bottom: 48px; }
   --------------------------------------------------------------------------- */

/* Shop card: the percent-off tag keeps the top-right corner. */
.qav-badges--sale {
	--qav-badge-tr: var(--qav-badge-sale-clear);
}

/* Product page: the percent-off tag sits top left of the gallery instead. */
.qav-badges--pdp.qav-badges--sale {
	--qav-badge-tr: var(--qav-badge-top);
	--qav-badge-tl: var(--qav-badge-sale-clear);
}

/* Size pills along the bottom of the photo: the whole bottom row sits above one
   row of them. */
.qav-sizes--bottom-left ~ .qav-badges,
.qav-sizes--bottom-center ~ .qav-badges,
.qav-sizes--bottom-right ~ .qav-badges {
	--qav-badge-bottom: calc(var(--qav-inset, 0.625rem) + 26px);
}

/* Size pills top left: that corner starts below them. */
.qav-sizes--top-left ~ .qav-badges {
	--qav-badge-tl: calc(var(--qav-inset, 0.625rem) + 26px);
}

/* A combo chip that the theme prints over the bottom of the photo (Heejab and
   Nelle: span.hj-chip, after the photo): the whole bottom row sits above it. */
.qav-thumb:has(~ .hj-chip) .qav-badges {
	--qav-badge-bottom: 42px;
}

/* The Atome badge takes one corner of the photo. A stack in that corner starts
   beyond it, and so does the centre stack of that edge: a centred label can be
   wide enough to touch the badge. */
.qav-atome--archive.qav-atome--top-left ~ .qav-badges {
	--qav-badge-tl: 40px;
	--qav-badge-tc: 40px;
}

.qav-atome--archive.qav-atome--top-right ~ .qav-badges {
	--qav-badge-tr: 40px;
	--qav-badge-tc: 40px;
}

/* Along the bottom the row may already be lifted (pills, chip), so never lower it. */
.qav-atome--archive.qav-atome--bottom-left ~ .qav-badges {
	--qav-badge-bl: max(var(--qav-badge-bottom), 40px);
	--qav-badge-bc: max(var(--qav-badge-bottom), 40px);
}

.qav-atome--archive.qav-atome--bottom-right ~ .qav-badges {
	--qav-badge-br: max(var(--qav-badge-bottom), 40px);
	--qav-badge-bc: max(var(--qav-badge-bottom), 40px);
}

/* ---------------------------------------------------------------------------
   Phones
   Product cards drop to two per row, so the photo is small: smaller labels, a
   smaller edge and a shorter step past the percent-off tag.
   --------------------------------------------------------------------------- */

@media (max-width: 767px) {
	.qav-badges {
		--qav-badge-edge: 8px;
		--qav-badge-sale-clear: 35px;
		--qav-badge-size: 11px;
		--qav-badge-pad: 3px 7px;
	}

	.qav-thumb:has(~ .hj-chip) .qav-badges {
		--qav-badge-bottom: 35px;
	}

	/* The Shop Kit gallery's slide counter ("1/3") sits in the bottom-right
	   corner of the gallery on a phone. */
	.qav-gallery .qav-badges--pdp {
		--qav-badge-br: 44px;
	}
}
