// Two-factor step of the sign-in form (components/Landing/TwoFactor.js and
// OtpInput.js). It follows the same step of the easy.jobs app: sizes and
// colours come from its TwoFactorChallenge.vue and OtpInput.vue.
//
// The selectors start at .ej-two-factor and name the element, so they win over
// the wp-admin styles for inputs and buttons.
.ej-two-factor {
	&__form {
		display: flex;
		flex-direction: column;
		align-items: center;
		text-align: center;
		padding: 8px 4px 4px;
	}
	&__icon {
		width: 64px;
		height: 64px;
		border-radius: 18px;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		background: linear-gradient(135deg, #2fc1e1 0%, #597dfc 100%);
		box-shadow: 0 12px 24px -8px rgba(89, 125, 252, 0.45);
		margin-bottom: 18px;
	}
	h3.ej-two-factor__title {
		font-size: 20px;
		font-weight: 600;
		line-height: 1.3;
		color: #1c2238;
		margin: 0 0 6px;
		padding: 0;
	}
	p.ej-two-factor__text {
		font-size: 13px;
		color: #7d8091;
		margin: 0 0 24px;
		max-width: 300px;
		line-height: 1.55;
	}

	// The six boxes of the code.
	.ej-otp {
		display: flex;
		justify-content: center;
		gap: 10px;
		width: 100%;
		&--shake {
			animation: ej-otp-shake 0.4s ease;
		}
	}
	input.ej-otp__box {
		// 48px wide, and narrower when the card has no room for six of them.
		flex: 0 1 48px;
		width: 48px;
		min-width: 0;
		height: 56px;
		min-height: 0;
		margin: 0;
		padding: 0;
		border: 1.5px solid #e3e7f2;
		border-radius: 10px;
		background: #f5f7fd;
		box-shadow: none;
		color: #1c2238;
		font-size: 22px;
		font-weight: 600;
		line-height: 1;
		text-align: center;
		caret-color: #2fc1e1;
		outline: none;
		transition:
			border-color 0.15s ease,
			box-shadow 0.15s ease,
			background-color 0.15s ease;
		// A wider gap after the third box: 3 + 3.
		&:nth-child(3) {
			margin-right: 10px;
		}
		&:focus {
			border-color: #2fc1e1;
			background: #fff;
			box-shadow: 0 0 0 4px rgba(47, 193, 225, 0.15);
		}
		&:disabled {
			opacity: 0.6;
		}
	}
	input.ej-otp__box--filled {
		background: #fff;
		border-color: #c9d3ec;
	}
	.ej-otp--error input.ej-otp__box {
		border-color: #ff5f74;
		background: #fff6f7;
		&:focus {
			box-shadow: 0 0 0 4px rgba(255, 95, 116, 0.15);
		}
	}

	input.ej-two-factor__recovery {
		width: 100%;
		max-width: 320px;
		height: 52px;
		min-height: 0;
		margin: 0;
		padding: 0 12px;
		border: 1.5px solid #e3e7f2;
		border-radius: 10px;
		background: #f5f7fd;
		box-shadow: none;
		color: #1c2238;
		font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
		font-size: 18px;
		letter-spacing: 2px;
		line-height: 1;
		text-align: center;
		outline: none;
		transition:
			border-color 0.15s ease,
			box-shadow 0.15s ease,
			background-color 0.15s ease;
		&:focus {
			border-color: #2fc1e1;
			background: #fff;
			box-shadow: 0 0 0 4px rgba(47, 193, 225, 0.15);
		}
		&:disabled {
			opacity: 0.6;
		}
	}
	input.ej-two-factor__recovery--error {
		border-color: #ff5f74;
		background: #fff6f7;
		&:focus {
			box-shadow: 0 0 0 4px rgba(255, 95, 116, 0.15);
		}
	}

	p.ej-two-factor__error {
		color: #ff5f74;
		font-size: 12.5px;
		line-height: 1.5;
		margin: 12px 0 0;
		max-width: 320px;
	}

	button.ej-two-factor__submit {
		width: 100%;
		max-width: 320px;
		height: 46px;
		margin: 22px 0 0;
		padding: 0 16px;
		border: 0;
		border-radius: 10px;
		background: #2fc1e1;
		color: #fff;
		font-family: inherit;
		font-size: 14px;
		font-weight: 600;
		line-height: 1;
		cursor: pointer;
		box-shadow: 0 10px 18px -8px rgba(47, 193, 225, 0.6);
		transition:
			background-color 0.15s ease,
			transform 0.1s ease,
			box-shadow 0.15s ease;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		gap: 8px;
		&:hover:not(:disabled) {
			background: #23b0cf;
		}
		&:active:not(:disabled) {
			transform: translateY(1px);
		}
		&:focus-visible {
			outline: 2px solid #597dfc;
			outline-offset: 2px;
		}
		&:disabled {
			opacity: 0.75;
			cursor: default;
		}
	}
	&__spinner {
		width: 16px;
		height: 16px;
		border: 2px solid rgba(255, 255, 255, 0.45);
		border-top-color: #fff;
		border-radius: 50%;
		animation: ej-two-factor-spin 0.7s linear infinite;
	}

	p.ej-two-factor__expiry {
		font-size: 12px;
		color: #a0a3b5;
		margin: 12px 0 0;
		strong {
			color: #7d8091;
			font-variant-numeric: tabular-nums;
		}
	}

	&__divider {
		display: flex;
		align-items: center;
		width: 100%;
		max-width: 320px;
		margin: 20px 0 14px;
		color: #a0a3b5;
		font-size: 12px;
		&::before,
		&::after {
			content: "";
			flex: 1;
			height: 1px;
			background: #eceef5;
		}
		span {
			padding: 0 12px;
		}
	}

	button.ej-two-factor__alt {
		width: 100%;
		max-width: 320px;
		height: 42px;
		margin: 0;
		padding: 0 16px;
		border: 1.5px solid #e3e7f2;
		border-radius: 10px;
		background: #fff;
		color: #1c2238;
		font-family: inherit;
		font-size: 13px;
		font-weight: 500;
		line-height: 1;
		cursor: pointer;
		transition:
			border-color 0.15s ease,
			background-color 0.15s ease;
		&:hover:not(:disabled) {
			border-color: #597dfc;
			background: #f7f9ff;
		}
		&:focus-visible {
			outline: 2px solid #597dfc;
			outline-offset: 2px;
		}
		&:disabled {
			opacity: 0.6;
			cursor: default;
		}
	}

	// The two text links under the form.
	button.ej-two-factor__back,
	button.ej-two-factor__api {
		display: inline-flex;
		align-items: center;
		gap: 4px;
		padding: 0;
		border: 0;
		background: none;
		font-family: inherit;
		line-height: 1.4;
		cursor: pointer;
		&:focus-visible {
			outline: 2px solid #597dfc;
			outline-offset: 2px;
			border-radius: 2px;
		}
		&:disabled {
			opacity: 0.6;
			cursor: default;
		}
	}
	button.ej-two-factor__back {
		margin: 18px 0 0;
		font-size: 13px;
		color: #597dfc;
		&:hover:not(:disabled) {
			color: #3f63e6;
		}
	}
	button.ej-two-factor__api {
		margin: 10px 0 0;
		font-size: 12px;
		color: #7d8091;
		text-decoration: underline;
		&:hover:not(:disabled) {
			color: #1c2238;
		}
	}

	@media (max-width: 420px) {
		.ej-otp {
			gap: 6px;
		}
		input.ej-otp__box {
			flex-basis: 40px;
			width: 40px;
			height: 48px;
			font-size: 19px;
			&:nth-child(3) {
				margin-right: 6px;
			}
		}
	}

	// No movement for a user who asked for less of it.
	@media (prefers-reduced-motion: reduce) {
		.ej-otp--shake {
			animation: none;
		}
		&__spinner {
			animation-duration: 1.5s;
		}
	}
}

@keyframes ej-otp-shake {
	0%,
	100% {
		transform: translateX(0);
	}
	20%,
	60% {
		transform: translateX(-6px);
	}
	40%,
	80% {
		transform: translateX(6px);
	}
}

@keyframes ej-two-factor-spin {
	to {
		transform: rotate(360deg);
	}
}
