/**
 * Password strength meter
 *
 * The text always says what the bar shows, so neither the colors nor the bar
 * carry anything the text does not.
 */

.password-requirements-strength-meter {
	--password-requirements-strength-meter-fill: #d63638;
	--password-requirements-strength-meter-track: #dcdcde;

	box-sizing: border-box;

	// The script sets this to the field's width, which can be narrower than the parent or, on a narrow screen, overflow it.
	width: var(--password-requirements-strength-meter-width, 100%);
	margin: 8px 0 0;

	// Front-end themes set large body text; this keeps the meter at the size of a field's help text, and at 13px in wp-admin.
	font-size: min(0.875rem, 1em);
	line-height: 1.5;
	text-align: start;

	// Keeps long feedback from widening a shrink-to-fit parent, such as core's password wrapper on the admin screens.
	contain: inline-size;

	&[data-level="2"] {
		--password-requirements-strength-meter-fill: #e26f1b;
	}

	&[data-level="3"] {
		--password-requirements-strength-meter-fill: #dba617;
	}

	&[data-level="4"] {
		--password-requirements-strength-meter-fill: #00a32a;
	}

	&__bar {
		display: flex;
		gap: 4px;
	}

	&__segment {
		flex: 1 1 0;
		height: 4px;
		border-radius: 2px;
		background-color: var(--password-requirements-strength-meter-track);
		transition: background-color 150ms ease-out;

		&--filled {
			background-color: var(--password-requirements-strength-meter-fill);
		}
	}

	&__status,
	&__requirement {
		margin: 6px 0 0;
		padding: 0;
		font-size: inherit;

		&:empty {
			display: none;
		}
	}

	&__status strong {
		font-weight: 600;
	}

	&__requirement {
		display: flex;
		align-items: baseline;
		gap: 6px;

		&[hidden] {
			display: none;
		}
	}

	/**
	 * The check mark and the cross are drawn with borders rather than typed as
	 * characters, which render as empty boxes where no installed font has them.
	 * The icon sits on the text's baseline and is about as tall as a capital.
	 */
	&__icon {
		position: relative;
		flex: none;
		width: 0.75em;
		height: 0.75em;

		&::before,
		&::after {
			content: "";
			position: absolute;
			box-sizing: border-box;
		}
	}

	&__requirement--met &__icon {
		color: #008a20;

		&::before {
			top: 0;
			left: 0.24em;
			width: 0.3em;
			height: 0.6em;
			border-right: 0.14em solid currentColor;
			border-bottom: 0.14em solid currentColor;
			transform: rotate(45deg);
		}
	}

	&__requirement--unmet &__icon {
		color: #d63638;

		&::before,
		&::after {
			top: calc(50% - 0.07em);
			left: 0;
			width: 100%;
			border-top: 0.14em solid currentColor;
			transform: rotate(45deg);
		}

		&::after {
			transform: rotate(-45deg);
		}
	}

	&__feedback {
		margin: 4px 0 0;
		padding: 0 0 0 1.25em;
		list-style: disc;
		font-size: 0.923em;
		color: inherit;
		opacity: 0.85;

		&[hidden] {
			display: none;
		}

		li {
			margin: 2px 0 0;
			padding: 0;
			font-size: inherit;
		}
	}

	@media (prefers-reduced-motion: reduce) {
		&__segment {
			transition: none;
		}
	}

	@media (forced-colors: active) {
		&__segment {
			border: 1px solid CanvasText;
			background-color: Canvas;
			forced-color-adjust: none;

			&--filled {
				background-color: CanvasText;
			}
		}

		&__requirement--met &__icon,
		&__requirement--unmet &__icon {
			color: CanvasText;
		}

		&__feedback {
			opacity: 1;
		}
	}
}

// The reset password form on "wp-login.php" leaves no margin under the field's wrapper.
.login .password-requirements-strength-meter {
	margin-bottom: 16px;
}

// The admin screens fit their password field to its wrapper; on narrow screens core makes both full width.
.password-input-wrapper .password-requirements-strength-meter {
	max-width: 25em;

	@media screen and (max-width: 782px) {
		max-width: none;
	}
}
