/**
 * Puls Real-Time Stock - fulfilment choice and list popup.
 *
 * Colours are the shop's own (Möbelhof red and blue, text and panel greys), the same set the old
 * availability box used. Every value is a custom property: set any of them on an ancestor to
 * restyle without fighting the selectors below.
 *
 * @package Puls_WC_Stock
 */

.puls-buybox,
.puls-buydialog {
	--puls-buy-surface: #f7f7f7;
	--puls-buy-card: #ffffff;
	--puls-buy-border: #e2e4e8;
	--puls-buy-text: #33363b;
	--puls-buy-muted: #606060;
	--puls-buy-accent: #154094;
	--puls-buy-brand: #e40010;
	--puls-buy-available: #2e8540;
	--puls-buy-limited: #e08a00;
	--puls-buy-unavailable: #e40010;
	--puls-buy-pending: #b8bcc2;
	--puls-buy-radius: 10px;
}

.puls-buybox__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* -------------------------------------------------- Product page panel */

/*
 * Same flat grey panel and the same 25px gap the old availability box had. !important because the
 * theme zeroes the first child's margin inside a Cornerstone text element.
 */
.puls-buybox--page {
	margin-top: var(--puls-buy-offset, 25px) !important;
	padding: 14px 16px;
	background: var(--puls-buy-surface);
	color: var(--puls-buy-text);
	line-height: 1.4;
}

/* -------------------------------------------------- The options */

.puls-buybox__choices {
	display: flex;
	flex-direction: column;
	gap: 8px;
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.puls-buybox__group {
	margin: 8px 0 0;
	font-size: 0.72em;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--puls-buy-muted);
}

.puls-buybox__choice {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 0;
	padding: 12px 14px;
	background: var(--puls-buy-card);
	border: 1px solid var(--puls-buy-border);
	border-radius: var(--puls-buy-radius);
	cursor: pointer;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.puls-buybox__choice:hover:not(.puls-buybox__choice--disabled) {
	border-color: var(--puls-buy-accent);
}

.puls-buybox__choice:has(.puls-buybox__radio:checked) {
	border-color: var(--puls-buy-accent);
	box-shadow: inset 0 0 0 1px var(--puls-buy-accent);
}

.puls-buybox__choice--disabled,
.puls-buybox__choice--loading {
	cursor: default;
	background: #fbfbfb;
}

.puls-buybox__radio {
	flex: none;
	width: 18px;
	height: 18px;
	margin: 0;
	accent-color: var(--puls-buy-accent);
}

.puls-buybox__choice-body {
	display: flex;
	flex: 1;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 2px 12px;
	min-width: 0;
}

.puls-buybox__choice-title {
	font-weight: 600;
}

.puls-buybox__choice--disabled .puls-buybox__choice-title {
	color: var(--puls-buy-muted);
}

/* The dot carries the colour; the text beside it says the same thing. */
.puls-buybox__status {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 0.9em;
	color: var(--puls-buy-muted);
}

.puls-buybox__status::before {
	content: "";
	flex: none;
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--puls-buy-pending);
}

/* While the answer is on its way the dot is a small spinner, beside "Checking availability…". */
.puls-buybox__choice--loading .puls-buybox__status::before {
	box-sizing: border-box;
	width: 14px;
	height: 14px;
	background: transparent;
	border: 2px solid var(--puls-buy-border);
	border-top-color: var(--puls-buy-accent);
	animation: puls-buy-spin 0.8s linear infinite;
}

.puls-buybox__choice--available .puls-buybox__status::before {
	background: var(--puls-buy-available);
	box-shadow: 0 0 0 3px rgba(46, 133, 64, 0.18);
}

.puls-buybox__choice--limited .puls-buybox__status::before {
	background: var(--puls-buy-limited);
	box-shadow: 0 0 0 3px rgba(224, 138, 0, 0.18);
}

.puls-buybox__choice--unavailable .puls-buybox__status::before {
	background: var(--puls-buy-unavailable);
	box-shadow: 0 0 0 3px rgba(228, 0, 16, 0.14);
}

.puls-buybox__choice--available .puls-buybox__status,
.puls-buybox__choice--limited .puls-buybox__status,
.puls-buybox__choice--unavailable .puls-buybox__status {
	font-weight: 600;
	color: var(--puls-buy-text);
}

@keyframes puls-buy-spin {
	to {
		transform: rotate(360deg);
	}
}

.puls-buybox__note,
.puls-buybox__error {
	margin: 10px 0 0;
	font-size: 0.9em;
	font-weight: 600;
	color: var(--puls-buy-brand);
}

.puls-buybox__note[hidden],
.puls-buybox__error[hidden] {
	display: none;
}

/* -------------------------------------------------- Popup content */

.puls-buybox--popup {
	color: var(--puls-buy-text);
	line-height: 1.4;
}

.puls-buybox__head {
	display: flex;
	gap: 16px;
	margin-bottom: 18px;
	padding-right: 40px;
}

.puls-buybox__media {
	flex: 0 0 110px;
	width: 110px;
}

.puls-buybox__media img {
	display: block;
	width: 100%;
	height: auto;
	aspect-ratio: 1;
	object-fit: contain;
	border-radius: 8px;
	background: var(--puls-buy-surface);
}

.puls-buybox__summary {
	min-width: 0;
}

.puls-buybox__title {
	margin: 0 0 4px;
	font-size: 1.2em;
	font-weight: 700;
	line-height: 1.25;
}

.puls-buybox__sku {
	margin: 0 0 6px;
	font-size: 0.8em;
	color: var(--puls-buy-muted);
}

/* "max 2-3 lines" from the story: three, then an ellipsis. */
.puls-buybox__desc {
	display: -webkit-box;
	margin: 0 0 8px;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	line-clamp: 3;
	font-size: 0.9em;
	color: var(--puls-buy-muted);
}

.puls-buybox__price {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 4px 10px;
	margin: 0;
}

.puls-buybox__amount {
	font-size: 1.5em;
	font-weight: 700;
	color: var(--puls-buy-brand);
}

.puls-buybox__amount del {
	font-size: 0.6em;
	color: var(--puls-buy-muted);
}

.puls-buybox__amount ins {
	text-decoration: none;
}

.puls-buybox__tax {
	font-size: 0.8em;
	color: var(--puls-buy-muted);
}

.puls-buybox__actions {
	display: flex;
	gap: 10px;
	margin-top: 16px;
}

.puls-buybox__qty {
	display: flex;
	flex: none;
	align-items: center;
	height: 50px;
	padding: 0 4px;
	background: var(--puls-buy-surface);
	border-radius: 800px;
}

.puls-buybox__step {
	width: 36px;
	height: 36px;
	padding: 0;
	font: inherit;
	font-size: 1.2em;
	line-height: 1;
	color: var(--puls-buy-text);
	background: transparent;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
}

.puls-buybox__step:hover,
.puls-buybox__step:focus-visible {
	background: #ececec;
}

.puls-buybox__qty-input {
	width: 44px;
	height: 36px;
	padding: 0;
	font: inherit;
	text-align: center;
	color: var(--puls-buy-text);
	background: transparent;
	border: 0;
	-moz-appearance: textfield;
	appearance: textfield;
}

.puls-buybox__qty-input::-webkit-outer-spin-button,
.puls-buybox__qty-input::-webkit-inner-spin-button {
	margin: 0;
	-webkit-appearance: none;
}

.puls-buybox__add {
	display: inline-flex;
	flex: 1;
	align-items: center;
	justify-content: center;
	gap: 10px;
	min-height: 50px;
	padding: 5px 20px;
	font: inherit;
	font-size: 16px;
	font-weight: 700;
	color: #ffffff;
	background: var(--puls-buy-brand);
	border: 0;
	border-radius: 30px;
	cursor: pointer;
}

.puls-buybox__add:hover:not(:disabled),
.puls-buybox__add:focus-visible {
	background: #c4000e;
}

.puls-buybox__add:disabled {
	cursor: not-allowed;
	opacity: 0.45;
}

/* Adding: a spinner takes the cart icon's place and the button stays readable. */
.puls-buybox__add.is-busy {
	cursor: progress;
	opacity: 0.85;
}

.puls-buybox__add.is-busy svg {
	display: none;
}

.puls-buybox__add.is-busy::before {
	content: "";
	box-sizing: border-box;
	flex: none;
	width: 18px;
	height: 18px;
	border: 2px solid rgba(255, 255, 255, 0.45);
	border-top-color: #ffffff;
	border-radius: 50%;
	animation: puls-buy-spin 0.8s linear infinite;
}

/* The product page's own button (the theme's): the buy box disables it while nothing can be
   ordered, and the theme gives a disabled button no look of its own - it stayed bright red. */
form.cart .single_add_to_cart_button:disabled {
	cursor: not-allowed;
	opacity: 0.45;
}

.puls-buybox__details {
	display: inline-block;
	margin-top: 14px;
	font-size: 0.9em;
	font-weight: 600;
	color: var(--puls-buy-accent);
}

/* -------------------------------------------------- The dialog */

/*
 * A native <dialog> opened with showModal(), so it sits in the browser's top layer above every
 * stacking context the theme builds - the same reason the store drawer is one.
 */
.puls-buydialog {
	width: min(560px, calc(100vw - 32px));
	max-width: none;
	max-height: calc(100vh - 32px);
	margin: auto;
	padding: 0;
	color: var(--puls-buy-text);
	background: var(--puls-buy-card);
	border: 0;
	border-radius: 14px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
	overflow: auto;
}

.puls-buydialog::backdrop {
	background: rgba(0, 0, 0, 0.45);
}

html.puls-buydialog-open {
	overflow: hidden;
}

.puls-buydialog__inner {
	position: relative;
	padding: 24px;
}

.puls-buydialog__close {
	position: absolute;
	top: 14px;
	right: 14px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	color: var(--puls-buy-brand);
	background: #f2f3f5;
	border: 0;
	border-radius: 8px;
	cursor: pointer;
}

.puls-buydialog__close:hover,
.puls-buydialog__close:focus-visible {
	background: #e6e8ec;
}

.puls-buydialog__message {
	margin: 8px 48px 0 0;
	color: var(--puls-buy-muted);
}

/* The popup while the item loads: the brand spinner over "Loading…", centred in a box the size
   of a short buy box, so the dialog does not jump from a strip to full height. */
.puls-buydialog__loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	min-height: 180px;
	padding: 24px 0 16px;
	color: var(--puls-buy-muted);
}

.puls-buydialog__spinner {
	box-sizing: border-box;
	width: 40px;
	height: 40px;
	border: 3px solid var(--puls-buy-border);
	border-top-color: var(--puls-buy-brand);
	border-radius: 50%;
	animation: puls-buy-spin 0.8s linear infinite;
}

.puls-buydialog__done-title {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 4px 48px 18px 0;
	font-weight: 700;
	color: var(--puls-buy-available);
}

.puls-buydialog__item {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 14px;
	background: var(--puls-buy-surface);
	border-radius: var(--puls-buy-radius);
}

.puls-buydialog__item-image {
	flex: none;
	width: 72px;
	height: 72px;
	object-fit: contain;
	background: var(--puls-buy-card);
	border-radius: 6px;
}

.puls-buydialog__item-body p {
	margin: 0;
}

.puls-buydialog__item-name {
	font-weight: 600;
}

.puls-buydialog__item-meta {
	font-size: 0.9em;
	color: var(--puls-buy-muted);
}

.puls-buydialog__done-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 18px;
}

.puls-buydialog__primary,
.puls-buydialog__secondary {
	display: inline-flex;
	flex: 1 1 200px;
	align-items: center;
	justify-content: center;
	min-height: 50px;
	padding: 5px 20px;
	font: inherit;
	font-weight: 700;
	text-decoration: none;
	border-radius: 30px;
	cursor: pointer;
}

.puls-buydialog__primary {
	color: #ffffff;
	background: var(--puls-buy-brand);
	border: 0;
}

.puls-buydialog__primary:hover,
.puls-buydialog__primary:focus-visible {
	color: #ffffff;
	background: #c4000e;
}

.puls-buydialog__secondary {
	color: var(--puls-buy-text);
	background: var(--puls-buy-card);
	border: 1px solid var(--puls-buy-text);
}

/* Phones: a sheet from the bottom edge, full width. */
@media (max-width: 600px) {
	.puls-buydialog {
		width: 100vw;
		max-height: 92vh;
		margin: auto 0 0;
		border-radius: 14px 14px 0 0;
	}

	.puls-buydialog__inner {
		padding: 20px 16px;
	}

	.puls-buybox__media {
		flex-basis: 80px;
		width: 80px;
	}
}

/* Last, so it wins over every spinner above: slower, not gone - it still says "working". */
@media (prefers-reduced-motion: reduce) {
	.puls-buybox__choice--loading .puls-buybox__status::before,
	.puls-buybox__add.is-busy::before,
	.puls-buydialog__spinner {
		animation-duration: 2.4s;
	}
}
