/*
 * The offer bar across the top of the site.
 *
 * Emblem at the left, offer in the middle, close at the right. The emblem and
 * the close button keep those sides in Arabic too, as they do on the existing
 * site; only the words run right to left.
 */

.diwan-topbar {
	background: var(--diwan-topbar-bg, #f9f6db);
	color: var(--diwan-topbar-text, #806a48);
	font-family: var(--diwan-font-body, "Loew", "Rubik", system-ui, sans-serif);
	/* The height and the type that fits it are set in Offers → Top bar
	   settings and written onto the bar. */
	font-size: var(--diwan-topbar-font, 14px);
	font-weight: 700;
	line-height: 1.5;
	overflow: hidden;
	position: relative;
	transition: max-height 0.28s ease, opacity 0.2s ease;
	z-index: 1001;
}

.diwan-topbar[hidden] {
	display: none !important;
}

.diwan-topbar.is-closing {
	max-height: 0 !important;
	opacity: 0;
}

.diwan-topbar__inner {
	align-items: center;
	direction: ltr;
	display: grid;
	gap: 16px;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	/* The height set for the bar, with everything in it centred and sized to
	   fit inside it, so the bar is that height and not a padding taller. */
	min-height: var(--diwan-topbar-h, 44px);
	padding-block: 0;
}

/* The two outer cells are the same width, so the offer sits in the true
   middle of the bar however wide the emblem is. */
/* Written one step past WooCommerce's and Elementor's own img rules, which
   set height: auto and on a shop page drew the emblem at its full 96 pixels,
   more than doubling the bar. */
.diwan-topbar img.diwan-topbar__icon,
.diwan-topbar span.diwan-topbar__icon {
	/* 24 pixels, or less in a bar too shallow for it: 4 pixels of air a side. */
	block-size: min(24px, calc(var(--diwan-topbar-h, 44px) - 8px)) !important;
	display: block;
	inline-size: auto !important;
	justify-self: start;
	margin: 0;
	max-block-size: min(24px, calc(var(--diwan-topbar-h, 44px) - 8px));
	max-inline-size: 100%;
	object-fit: contain;
}

.diwan-topbar .diwan-topbar__close {
	align-items: center;
	background: transparent;
	border: 0;
	border-radius: 50%;
	color: var(--diwan-topbar-close, #5d492b);
	cursor: pointer;
	display: inline-flex;
	block-size: min(32px, var(--diwan-topbar-h, 44px));
	inline-size: min(32px, var(--diwan-topbar-h, 44px));
	justify-content: center;
	justify-self: end;
	padding: 0;
	transition: background-color 0.16s ease;
}

.diwan-topbar__close svg {
	block-size: min(20px, calc(var(--diwan-topbar-h, 44px) - 6px));
	inline-size: min(20px, calc(var(--diwan-topbar-h, 44px) - 6px));
}

/* ------------------------------------------------------ stays at the top */

/*
 * The bar holds the top of the screen and the header sticks under it: the
 * header script reads --diwan-topbar-stick, which top-bar.js keeps at the bar's
 * height while it is showing and at nothing once a visitor has closed it. One
 * above the header's own layer, so the header's rows pass under the bar as the
 * page scrolls and not over it.
 */
.diwan-topbar--sticky {
	inset-block-start: 0;
	position: sticky;
	z-index: 1002;
}

body.admin-bar .diwan-topbar--sticky {
	inset-block-start: 32px;
}

@media (max-width: 782px) {
	body.admin-bar .diwan-topbar--sticky {
		inset-block-start: 46px;
	}
}

/* WordPress stops fixing its own bar at this width and lets it scroll away. */
@media (max-width: 600px) {
	body.admin-bar .diwan-topbar--sticky {
		inset-block-start: 0;
	}
}

/* The menu's hover: papyrus behind, wood in front. Stated with the bar in
   front, so a theme's rules for every button (Hello Elementor paints them pink,
   and white on pink when hovered) cannot win over it. */
.diwan-topbar .diwan-topbar__close:hover,
.diwan-topbar .diwan-topbar__close:focus-visible {
	background: var(--diwan-hover, #e0b070);
	color: var(--diwan-hover-text, #3b0f00);
	outline: none;
}

.diwan-topbar__close:focus-visible {
	box-shadow: 0 0 0 2px var(--diwan-topbar-close, #5d492b);
}

/* The window the offers pass through: as wide as the bar allows between the
   emblem and the close button, one line tall. */
.diwan-topbar__window {
	block-size: 1.5em;
	inline-size: min(62vw, 820px);
	overflow: hidden;
	position: relative;
}

html[dir="rtl"] .diwan-topbar__window,
body.diwan-lang-ar .diwan-topbar__window {
	direction: rtl;
}

.diwan-topbar__track {
	list-style: none;
	margin: 0;
	padding: 0;
}

.diwan-topbar__message {
	inset: 0;
	overflow: hidden;
	position: absolute;
	text-align: center;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.diwan-topbar__link,
.diwan-topbar__text {
	color: inherit;
	text-decoration: none;
}

/* The whole line is the link, not only its letters. */
.diwan-topbar__link {
	display: block;
	overflow: hidden;
	text-overflow: ellipsis;
}

.diwan-topbar__link::after {
	content: " \2192";
	display: inline-block;
	margin-inline-start: 6px;
	transition: transform 0.18s ease;
}

html[dir="rtl"] .diwan-topbar__link::after,
body.diwan-lang-ar .diwan-topbar__link::after {
	content: " \2190";
}

.diwan-topbar__link:hover::after {
	transform: translateX(3px);
}

html[dir="rtl"] .diwan-topbar__link:hover::after,
body.diwan-lang-ar .diwan-topbar__link:hover::after {
	transform: translateX(-3px);
}

.diwan-topbar__link:hover,
.diwan-topbar__link:focus-visible {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* ------------------------------------------------------------- one offer */

.diwan-topbar--still .diwan-topbar__message {
	position: static;
}

/* --------------------------------------------------------------- sliding */

.diwan-topbar--slide .diwan-topbar__message {
	opacity: 0;
	transform: translateY(100%);
	transition: transform 0.45s ease, opacity 0.45s ease;
}

.diwan-topbar--slide .diwan-topbar__message.is-active {
	opacity: 1;
	transform: translateY(0);
}

.diwan-topbar--slide .diwan-topbar__message.is-leaving {
	opacity: 0;
	transform: translateY(-100%);
}

/* ---------------------------------------------------------------- fading */

.diwan-topbar--fade .diwan-topbar__message {
	opacity: 0;
	transition: opacity 0.5s ease;
	visibility: hidden;
}

.diwan-topbar--fade .diwan-topbar__message.is-active {
	opacity: 1;
	visibility: visible;
}

/* ---------------------------------------------------------------- ticker */

.diwan-topbar--ticker .diwan-topbar__window {
	-webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
	mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}

.diwan-topbar--ticker .diwan-topbar__track {
	animation: diwan-topbar-ticker var(--diwan-topbar-duration, 30s) linear infinite;
	display: flex;
	inline-size: max-content;
}

.diwan-topbar--ticker .diwan-topbar__message {
	padding-inline-end: 64px;
	position: static;
}

.diwan-topbar--ticker:hover .diwan-topbar__track,
.diwan-topbar--ticker:focus-within .diwan-topbar__track {
	animation-play-state: paused;
}

@keyframes diwan-topbar-ticker {
	from {
		transform: translateX(0);
	}

	to {
		transform: translateX(-50%);
	}
}

/* Right to left, the words run the other way. */
@keyframes diwan-topbar-ticker-rtl {
	from {
		transform: translateX(0);
	}

	to {
		transform: translateX(50%);
	}
}

html[dir="rtl"] .diwan-topbar--ticker .diwan-topbar__track,
body.diwan-lang-ar .diwan-topbar--ticker .diwan-topbar__track {
	animation-name: diwan-topbar-ticker-rtl;
}

/* ----------------------------------------------------------- less motion */

@media (prefers-reduced-motion: reduce) {
	.diwan-topbar--slide .diwan-topbar__message,
	.diwan-topbar--fade .diwan-topbar__message {
		transition: none;
	}

	.diwan-topbar--ticker .diwan-topbar__track {
		animation: none;
	}

	.diwan-topbar {
		transition: none;
	}
}

/* ----------------------------------------------------------------- phone */

@media (max-width: 720px) {
	.diwan-topbar {
		font-size: var(--diwan-topbar-font-phone, 13px);
	}

	.diwan-topbar__inner {
		gap: 10px;
		grid-template-columns: auto minmax(0, 1fr) auto;
		min-height: var(--diwan-topbar-h-phone, 40px);
	}

	.diwan-topbar img.diwan-topbar__icon {
		block-size: min(18px, calc(var(--diwan-topbar-h-phone, 40px) - 8px)) !important;
		max-block-size: min(18px, calc(var(--diwan-topbar-h-phone, 40px) - 8px));
	}

	.diwan-topbar__window {
		inline-size: 100%;
	}

	.diwan-topbar .diwan-topbar__close {
		block-size: min(28px, var(--diwan-topbar-h-phone, 40px));
		inline-size: min(28px, var(--diwan-topbar-h-phone, 40px));
	}

	.diwan-topbar__close svg {
		block-size: min(18px, calc(var(--diwan-topbar-h-phone, 40px) - 6px));
		inline-size: min(18px, calc(var(--diwan-topbar-h-phone, 40px) - 6px));
	}
}

/* ------------------------------------------------- an offer on a small phone */

/*
 * One line and an ellipsis is how "buy 2, get the third free" became "buy 2, get
 * the thi…" on a 360px screen. The bar is the only place the offer is stated, so
 * on a narrow phone it is given a second line: the window grows to fit, the
 * message centres in it whether it takes one line or two, and a third line is
 * clipped rather than pushing the whole site down the page.
 *
 * The ticker is left out on purpose — it scrolls sideways, and a line that wraps
 * has nothing to scroll.
 */
@media (max-width: 560px) {
	.diwan-topbar:not(.diwan-topbar--ticker):not(.diwan-topbar--one-line) .diwan-topbar__window {
		block-size: 2.8em;
	}

	.diwan-topbar:not(.diwan-topbar--ticker):not(.diwan-topbar--one-line) .diwan-topbar__message {
		align-items: center;
		display: flex;
		justify-content: center;
		text-overflow: clip;
		white-space: normal;
	}

	.diwan-topbar:not(.diwan-topbar--ticker):not(.diwan-topbar--one-line) .diwan-topbar__link,
	.diwan-topbar:not(.diwan-topbar--ticker):not(.diwan-topbar--one-line) .diwan-topbar__text {
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		display: -webkit-box;
		line-height: 1.35;
		overflow: hidden;
	}
}
