/**
 * Book badges: on a card's cover, on the book page's picture, under its title.
 *
 * Each badge's colours come in as --diwan-badge-bg and --diwan-badge-ink from
 * Offers -> Book badges; the corner and the spot are chosen there too. Logical
 * properties throughout, so "start" is the left in English and the right in
 * Arabic without a mirrored copy.
 */

.diwan-badge {
	align-items: center;
	background: var(--diwan-badge-bg, #000);
	border: 1px solid color-mix(in srgb, var(--diwan-badge-ink, #fff) 18%, transparent);
	box-sizing: border-box;
	color: var(--diwan-badge-ink, #fff);
	display: inline-flex;
	font-family: inherit;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.04em;
	line-height: 1.2;
	max-inline-size: 100%;
	overflow: hidden;
	padding: 4px 8px;
	text-overflow: ellipsis;
	text-transform: uppercase;
	white-space: nowrap;
}

/* Arabic has no capitals, and spacing its letters apart breaks the joins. */
body.rtl .diwan-badge,
html[dir="rtl"] .diwan-badge,
.diwan-badge:lang(ar) {
	letter-spacing: 0;
	text-transform: none;
}

.diwan-badge--square {
	border-radius: 0;
}

.diwan-badge--rounded {
	border-radius: 4px;
}

.diwan-badge--pill {
	border-radius: 999px;
	padding-inline: 10px;
}

.diwan-badges {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	pointer-events: none;
}

/* ------------------------------------------------------- on a card's cover */

/* The cover the badges sit on is the widget they are drawn into, or for a
   book with no cover yet, the cover's frame. Not the covers on the shop's own
   cards: those are already pinned to their frame (books.css), which holds the
   badges just as well, and made relative here a book on sale lost its frame
   and stood taller than the rest of its row. */
.e-con:has(> .diwan-badges--card),
.elementor-widget-theme-post-featured-image:not(.diwan-book-card__cover-widget):not(.diwan-staff-card__cover-widget):not(.diwan-explore-card__cover-widget):has(.diwan-badges--card),
.elementor-widget-theme-post-featured-image > .elementor-widget-container:has(> .diwan-badges--card),
.elementor-widget-woocommerce-product-images:has(.diwan-badges--gallery),
.elementor-widget-woocommerce-product-images > .elementor-widget-container:has(> .diwan-badges--gallery) {
	position: relative;
}

.diwan-badges--card,
.diwan-badges--gallery {
	flex-direction: column;
	max-inline-size: calc(100% - 20px);
	position: absolute;
	/* Over the picture and the heart's frame, under the heart itself (4) and
	   the add-to-cart bar, which rises over the foot of the cover (3). */
	z-index: 2;
}

.diwan-badges--card.diwan-badges--top-start,
.diwan-badges--gallery.diwan-badges--top-start {
	align-items: flex-start;
	inset-block-start: 10px;
	inset-inline-start: 10px;
}

.diwan-badges--card.diwan-badges--top-end {
	align-items: flex-end;
	/* Below the heart, which holds the top corner on this side. */
	inset-block-start: calc(var(--diwan-wish-size, 34px) + 18px);
	inset-inline-end: 10px;
}

.diwan-badges--card.diwan-badges--bottom-start {
	align-items: flex-start;
	inset-block-end: 10px;
	inset-inline-start: 10px;
}

.diwan-badges--card.diwan-badges--bottom-end {
	align-items: flex-end;
	inset-block-end: 10px;
	inset-inline-end: 10px;
}

/* A bottom badge steps out of the way of the add-to-cart bar as it rises. */
.e-loop-item:hover .diwan-badges--card.diwan-badges--bottom-start,
.e-loop-item:hover .diwan-badges--card.diwan-badges--bottom-end,
.e-loop-item:focus-within .diwan-badges--card.diwan-badges--bottom-start,
.e-loop-item:focus-within .diwan-badges--card.diwan-badges--bottom-end {
	opacity: 0;
	transition: opacity 0.16s ease;
}

.diwan-badges--gallery {
	z-index: 5;
}

/* ----------------------------------------------------- under the book title */

.diwan-badges--title {
	margin-block: 8px 4px;
}

.diwan-badges--title .diwan-badge {
	font-size: 12px;
	padding: 5px 10px;
}

@media (max-width: 767px) {
	.diwan-badges--card .diwan-badge {
		font-size: 10px;
		padding: 3px 6px;
	}

	.diwan-badges--card.diwan-badges--top-start,
	.diwan-badges--card.diwan-badges--bottom-start {
		inset-inline-start: 6px;
	}

	.diwan-badges--card.diwan-badges--top-start {
		inset-block-start: 6px;
	}
}

/* A staff favourite's jacket is a thumbnail, 80 pixels wide on a tablet where
   six of them stand three across (Diwan, 5 October 2026): its tags a size
   smaller there and inside the jacket's edges, so a word is cut short
   rather than spilling over the picture beside it. */
@media (max-width: 1024px) {
	.diwan-staff-card .diwan-badges--card {
		inset-inline: 4px;
	}

	.diwan-staff-card .diwan-badges--card .diwan-badge {
		font-size: 9px;
		padding: 2px 5px;
	}
}
