/*
 * Loading and feedback. Nothing here changes how a page looks once it has loaded; it only fills the
 * gaps where the visitor would otherwise wait and see nothing.
 *
 * Where there is a real wait on this site:
 *   - Moving to a page. The listing pages are built from the CRM on every request and are not
 *     cached, so a click can take a second or two before anything changes. A thin bar at the top and
 *     a spinner on the card that was chosen say the click was received.
 *   - Photos. Cards and the property gallery show a quiet shimmer until each photo has arrived, then
 *     the photo fades in, rather than appearing in pieces.
 *   - Forms. Sending an enquiry or the sign-up waits for the CRM, so the button shows it is working
 *     and cannot be pressed twice.
 *
 * Search, Sort by and Filter work on the cards already in the page, so they are instant and have
 * nothing to wait for. They get a short, staggered entrance for the cards that remain, so the change
 * reads as a change instead of a jump.
 *
 * Every state is added by assets/js/loading.js and listings.js. Without the script none of them
 * exists, and nothing is hidden. The timing is the design's own: 400ms on cubic-bezier(0.44, 0, 0.56, 1).
 */

/* ---------------------------------------------------------------------------------------------
 * 1. The bar across the top while a page is on its way.
 * ------------------------------------------------------------------------------------------- */

.as-progress {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 1000;
	width: 100%;
	height: 3px;
	background: var(--as-red);
	box-shadow: 0 0 8px rgba(238, 43, 61, 0.55);
	transform: scaleX(0);
	transform-origin: 0 50%;
	opacity: 0;
	pointer-events: none;
}

.as-progress.is-active {
	opacity: 1;
	/* Most of the way across quickly, then a slow creep: it never claims to be finished. */
	transform: scaleX(0.82);
	transition: transform 9s cubic-bezier(0.08, 0.7, 0.2, 1), opacity 0.15s ease;
}

/* ---------------------------------------------------------------------------------------------
 * 2. The card that was chosen.
 * ------------------------------------------------------------------------------------------- */

@keyframes as-spin {
	to {
		transform: rotate(360deg);
	}
}

.as-card__photo::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	margin: -17px 0 0 -17px;
	border: 3px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s ease;
}

.as-listing.is-opening .as-card__photo::after {
	opacity: 1;
	animation: as-spin 0.8s linear infinite;
}

.as-listing.is-opening .as-listing__wash {
	opacity: 1;
}

.as-listing.is-opening .as-listing__wash span {
	opacity: 0;
}

/* The archive cards have no wash, so they get a light veil to carry the spinner. */
.as-listing--archive.is-opening .as-card__photo::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	background: rgba(2, 8, 22, 0.45);
}

.as-listing--archive.is-opening .as-card__photo::after {
	z-index: 2;
}

.as-listing.is-opening {
	cursor: progress;
}

/* ---------------------------------------------------------------------------------------------
 * 3. Photos on their way.
 * ------------------------------------------------------------------------------------------- */

@keyframes as-shimmer {
	from {
		background-position: 150% 0;
	}
	to {
		background-position: -50% 0;
	}
}

@keyframes as-photo-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.as-card__photo.is-loading,
.as-property__photo.is-loading {
	position: relative;
	background-color: #e3e3e3;
}

.as-card__photo.is-loading img,
.as-property__photo.is-loading img {
	opacity: 0;
}

.as-card__photo.is-loading::before,
.as-property__photo.is-loading::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	background: linear-gradient(100deg, rgba(255, 255, 255, 0) 25%, rgba(255, 255, 255, 0.6) 50%, rgba(255, 255, 255, 0) 75%);
	background-size: 200% 100%;
	animation: as-shimmer 1.4s ease-in-out infinite;
	pointer-events: none;
}

.as-card__photo.is-loaded img,
.as-property__photo.is-loaded img {
	animation: as-photo-in var(--as-duration) var(--as-ease) both;
}

/* The photo band on Sale and Lease: navy while its photo arrives, instead of the page's white showing through the overlay. */
.as-listings-hero {
	background-color: var(--as-navy-deep);
}

/* ---------------------------------------------------------------------------------------------
 * 4. Forms that wait for the CRM.
 * ------------------------------------------------------------------------------------------- */

.as-contact-form__submit.is-sending,
.as-enquiry__submit.is-sending,
.as-signup__submit.is-sending {
	position: relative;
	gap: 10px;
	cursor: progress;
	pointer-events: none;
}

.as-contact-form__submit.is-sending,
.as-enquiry__submit.is-sending {
	background: #d4202f;
}

.as-contact-form__submit.is-sending::before,
.as-enquiry__submit.is-sending::before,
.as-signup__submit.is-sending::before {
	content: "";
	flex: 0 0 auto;
	width: 16px;
	height: 16px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: #fff;
	border-radius: 50%;
	animation: as-spin 0.7s linear infinite;
}

.as-signup__submit.is-sending::before {
	border-color: rgba(0, 0, 0, 0.2);
	border-top-color: var(--as-black);
}

/* ---------------------------------------------------------------------------------------------
 * 5. Search, Sort by and Filter. The cards that are left rise in, a few at a time.
 * ------------------------------------------------------------------------------------------- */

@keyframes as-card-in {
	from {
		opacity: 0;
		transform: translateY(14px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

/* listings.js sets --as-i on each card inline to its place in the row (capped at 11); 0 is the value
   a card has before that, so nothing waits. Declared here so every token the stylesheets read has a
   declaration the release check can see. */
.as-listings__item {
	--as-i: 0;
}

.as-listings__grid.is-entering > .as-listings__item:not([hidden]),
.as-listings__grid > .as-listings__item.is-new {
	animation: as-card-in var(--as-duration) var(--as-ease) both;
	animation-delay: calc(var(--as-i, 0) * 35ms);
}

@keyframes as-menu-in {
	from {
		opacity: 0;
		transform: translateY(-6px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

.as-tool__menu:not([hidden]) {
	animation: as-menu-in 0.16s var(--as-ease) both;
}

.as-listings__empty:not([hidden]) {
	animation: as-card-in var(--as-duration) var(--as-ease) both;
}

.as-tool__button {
	transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
	.as-progress.is-active {
		transition: opacity 0.15s ease;
		transform: scaleX(1);
	}

	.as-card__photo.is-loading::before,
	.as-property__photo.is-loading::before {
		animation: none;
	}

	.as-card__photo.is-loaded img,
	.as-property__photo.is-loaded img,
	.as-listings__grid.is-entering > .as-listings__item:not([hidden]),
	.as-listings__grid > .as-listings__item.is-new,
	.as-tool__menu:not([hidden]),
	.as-listings__empty:not([hidden]) {
		animation: none;
	}

	.as-listing.is-opening .as-card__photo::after,
	.as-contact-form__submit.is-sending::before,
	.as-enquiry__submit.is-sending::before,
	.as-signup__submit.is-sending::before {
		animation-duration: 2s;
	}
}
