/**
 * 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;
	}
}

/* On a computer too the staff favourite's jacket is narrow (112 pixels), and
   "Award winner" at the cards' size was cut to "Award winn" (local test, 16
   October 2026): a size smaller and closer to the edges, so both tags read
   whole. */
.diwan-staff-card .diwan-badges--card {
	max-inline-size: calc(100% - 12px);
}

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

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

.diwan-staff-card .diwan-badges--card .diwan-badge {
	font-size: 10px;
	letter-spacing: 0;
	padding: 3px 4px;
	/* Where even that is too wide (a laptop, a tablet), the tag breaks onto a
	   second line between its words rather than losing the end of one. */
	text-overflow: clip;
	white-space: normal;
}

/* 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;
	}
}

/*
 * The "Sold Out Badge for WooCommerce" plugin's badge, on the copy of the live
 * shop, is set to stand at layer 9999 with nothing round it to hold it: on a
 * book's cover it stood over the header's menu as it opened (Ahmad, 25
 * October 2026). It belongs to its cover; a layer of 2 keeps it over the
 * picture and under everything that opens over the page.
 */
.wcsob_soldout {
	z-index: 2 !important;
}

/*
 * The badges on a card at 8 pixels (Ahmad, 26 October 2026), and never as far
 * as the heart: on a narrower cover (the home page's bands, Complete the
 * Collection, a phone) "Coming soon" ran on under it. On a card with a heart,
 * at the top of the reading side, they stop short of it in the far corner
 * (its size, its 10 pixels from the edge, and a gap); a longer tag takes a
 * second line between its words rather than reaching it. A staff favourite's
 * jacket has no heart: its tags keep one line across it (Ahmad, 26 October
 * 2026: held to the heart's room there, they all broke onto two).
 */
.diwan-badges--card .diwan-badge,
.diwan-staff-card .diwan-badges--card .diwan-badge {
	font-size: 8px;
	letter-spacing: 0.03em;
	padding: 3px 5px;
	text-overflow: clip;
	white-space: normal;
}

.e-loop-item:has(.diwan-wish) .diwan-badges--card.diwan-badges--top-start {
	max-inline-size: calc(100% - var(--diwan-wish-size, 34px) - 26px);
}

.diwan-staff-card .diwan-badges--card .diwan-badge {
	white-space: nowrap;
}

@media (max-width: 1024px) {
	.diwan-badges--card .diwan-badge,
	.diwan-staff-card .diwan-badges--card .diwan-badge {
		font-size: 8px;
		padding: 2px 4px;
	}

	/* The jacket is 94 pixels wide on a tablet: "New arrival" fits on its
	   one line with its letters closer and less room round them. */
	.diwan-staff-card .diwan-badges--card .diwan-badge {
		letter-spacing: 0;
		padding: 2px 3px;
	}
}
