/**
 * Erva Category Ribbon — front-end styles.
 *
 * Markup injected by the plugin:
 *   <div class="… wc-block-components-product-image has-erva-ribbon">
 *     <span class="erva-ribbon" aria-hidden="true">BF προσφορά!</span>
 *     <a>…product image…</a>
 *   </div>
 *
 * Colours come from two CSS variables printed by the plugin:
 *   --erva-ribbon-bg   background (default black)
 *   --erva-ribbon-fg   text colour (picked for contrast by the plugin)
 */

/* The image container becomes a size container, so the ribbon and the
   "Μειωμένη τιμή" pill adapt to the CARD width (not the viewport): the same
   card can be 180px wide on a phone and 310px wide on a large screen.
 *
 * Two separate rules on purpose: a selector list with :has() would be dropped
 * whole by browsers that do not understand :has(), taking the class rule with it.
 *  - .has-erva-ribbon: set by the plugin on the product-image block.
 *  - :has(> .erva-ribbon): the theme's own product markup (homepage carousel),
 *    where the plugin only prints the ribbon. */
.wc-block-components-product-image.has-erva-ribbon {
	position: relative;
	container-type: inline-size;
}

.wc-block-components-product-image:has(> .erva-ribbon) {
	position: relative;
	container-type: inline-size;
}

/* ── The ribbon ─────────────────────────────────────────────────────────── */

.erva-ribbon {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 20; /* above the hover image (2) and the sale-pill layer (10) */
	display: block;
	box-sizing: border-box;
	max-width: 100%;
	padding: 5px 15px 5px 9px; /* right padding = text padding + notch depth */
	background: var(--erva-ribbon-bg, #000000);
	color: var(--erva-ribbon-fg, #ffffff);
	font-family: inherit;
	font-size: 11px;
	font-size: clamp(11px, 4.1cqw, 13px); /* grows with the card, 11–13px */
	font-weight: 800;
	line-height: 1;
	letter-spacing: 0.02em;
	white-space: nowrap;
	text-align: center;
	pointer-events: none; /* never blocks the product link underneath */
	/* Notched end = the "ribbon tail". */
	clip-path: polygon(0 0, 100% 0, calc(100% - 7px) 50%, 100% 100%, 0 100%);
}

/* ── Ribbon + "Μειωμένη τιμή" pill ────────────────────────────────────────
 * Wide card: ribbon top-left, pill top-right (where the theme puts it).
 * Narrow card (phones, tablet grids, 5-column rows): the 120px pill leaves no
 * room beside it, so the pill moves just under the ribbon.
 * The stacking switch is the --erva-ribbon-pill-top variable: it is set on a
 * descendant of the container (a container can never query itself).
 */

/* Theme default is top:10px (products with a hover image). */
.wc-block-components-product-image.has-erva-ribbon .wc-block-components-product-sale-badge {
	top: var(--erva-ribbon-pill-top, 10px) !important;
}

/* WooCommerce default is a 12px padding (products without a hover image). */
.wc-block-components-product-image.has-erva-ribbon .wc-block-components-product-image__inner-container {
	padding-top: var(--erva-ribbon-pill-top, 12px);
}

@container (max-width: 269px) {
	.wc-block-components-product-image.has-erva-ribbon > a {
		/* ribbon height (11px text + 2 × 5px padding) + 6px gap */
		--erva-ribbon-pill-top: 27px;
	}
}

/* Browsers without container queries cannot measure the card: the ribbon stays
 * 11px there, and phones (≤768px) always stack via this viewport fallback. */
@supports not (container-type: inline-size) {
	@media (max-width: 768px) {
		.wc-block-components-product-image.has-erva-ribbon > a {
			--erva-ribbon-pill-top: 27px;
		}
	}
}
