/**
 * ys-savings-label.css — Product Label (Horizontal Strip) storefront styles.
 *
 * Loaded only on discovery-context storefront pages.
 *
 * Positioning approach:
 *
 *   Loop (shop/archive): When Quick Badge is also active, QB's .ys-qb-wrap
 *   (position:relative) serves as the shared positioning context — no extra
 *   wrapper is needed.  When only PL is active, the WC product image link is
 *   given position:relative here so the label spans the image correctly.
 *
 *   Gallery (single product): .woocommerce-product-gallery__image already has
 *   position:relative (also set by QB's CSS; this declaration is idempotent).
 */

/* ─── Loop — positioning context when QB is absent ──────────────────────────── */

/* Ensure the product image link is a block-level positioning context.         */
/* When QB is active, QB's .ys-qb-wrap supersedes this as the nearest ancestor. */
.woocommerce ul.products li.product .woocommerce-loop-product__link {
	display: block;
	position: relative;
}

/* ─── Gallery — positioning context (idempotent with QB's CSS) ──────────────── */

.woocommerce-product-gallery .woocommerce-product-gallery__image {
	position: relative;
}

/* ─── Label — shared by loop and gallery ────────────────────────────────────── */

/*
 * The label is a <span> so it does not introduce </div> tags that could
 * interfere with Quick Badge's strpos-based gallery injection at p:15.
 *
 * Position is relative to the nearest positioned ancestor:
 *   Loop + QB active  → .ys-qb-wrap (p:relative, added by QB at p:15)
 *   Loop + QB absent  → .woocommerce-loop-product__link (p:relative, above)
 *   Gallery           → .woocommerce-product-gallery__image (p:relative, above)
 */
.ys-sl-label {
	display: block;
	position: absolute;
	left: 0;
	right: 0;
	z-index: 10;
	padding: 6px 10px;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.4;
	text-align: center;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	box-sizing: border-box;
}

.ys-sl-label--top    { top: 0;    bottom: auto; }
.ys-sl-label--bottom { bottom: 0; top: auto;    }

/* ─── Coexistence with Quick Badge ──────────────────────────────────────────── */

/*
 * When both PL and QB target the same product, QB occupies a corner/edge
 * and PL occupies the full-width horizontal strip at top or bottom.
 * z-index 10 keeps the label below QB badges (QB badges default to z-index 20+).
 * Savings-only host corrections below use the same :has() support as existing previews.
 */

/* Page content can add an empty paragraph after block images. Keep Savings
   overlays anchored to the image, including Bottom strips alongside Quick Badges. */
.ys-qb-wrap:has(> .ys-sl-label) > p:empty { display:none; margin:0; }
.woocommerce ul.products li.product .ys-qb-wrap:has(> .ys-sl-label) > img,
.woocommerce ul.products li.product a.woocommerce-loop-product__link:has(> .ys-sl-label) > img { margin-bottom:0; }

.wc-block-components-product-image:has(.ys-sl-label) p:empty { display:none; margin:0; }
.wc-block-components-product-image:has(.ys-sl-label) img { margin-bottom:0; }
/* wpautop may also leave a paragraph containing only a duplicate empty link. */
.wc-block-components-product-image:has(.ys-sl-label) > p:has(> a:empty) { margin:0; padding:0; min-height:0; }
