/*
 * PIXVA v12 — the challenge widget. One definition, used everywhere.
 *
 * Before this file the same widget had four different looks: one block in
 * member-assistant.css (`.px7-captcha-box`), one in staff-card-v10.php
 * (`.px10-captcha`), one line in technician-portal-v10.php (`.px10-captcha-box`)
 * and nothing at all on some front-end forms. They disagreed, and all of them
 * were broken by the theme's global `svg { width: 24px; height: 24px }`, which
 * outranks the width/height attributes on the generated image.
 *
 * This is the single source of truth. Load it wherever a challenge is printed
 * and delete the local copies.
 *
 * Proportions follow the mainstream challenges: the image is a 3:1 box with
 * digits at roughly 40% of its height (reCAPTCHA v2 is 300x74, hCaptcha 300x78;
 * ours is 180x60 so it still fits a 320px phone without being scaled down).
 */

/* ============================================================ the image = */

/*
 * The `svg[width]` guard matters: the theme sizes its own icons from CSS with
 * `svg { width: 24px; height: 24px }`, and an attribute is a weaker signal than
 * any stylesheet rule. Without this the image collapses to a 24px stamp inside
 * a full-width panel.
 *
 * The matching `img` rules cover the bitmap challenge. The image is a 200x64
 * data URI, so it is given a width and left to size its own height rather than
 * being forced into the 3:1 box the SVG variant used.
 */
.px10-captcha-image svg,
.px10-captcha-box svg,
.px7-captcha-box svg,
svg.px10-captcha-svg,
.px10-captcha-image img,
.px10-captcha-box img,
.px7-captcha-box img {
	display: block;
	inline-size: 200px;
	max-inline-size: 100%;
	block-size: auto;
	flex: none;
	border: 1px solid #c9dae1;
	border-radius: 10px;
	background: #fff;
	user-select: none;
	-webkit-user-drag: none;
}

/* The SVG variant is drawn at its own 3:1 shape; the bitmap is not. */
.px10-captcha-image svg,
.px10-captcha-box svg,
.px7-captcha-box svg,
svg.px10-captcha-svg {
	aspect-ratio: 3 / 1;
}

/*
 * Google's checkbox is a fixed 304px wide. On a narrow phone it would push the
 * whole form sideways, so let the box scroll instead of letting the page
 * overflow.
 */
.px10-captcha .g-recaptcha,
.px10-captcha-side .g-recaptcha,
.px7-captcha-box .g-recaptcha {
	max-inline-size: 100%;
	overflow-x: auto;
	margin-block: 8px;
}

/* ====================================================== the component = */

.px10-captcha,
.px10-captcha-box,
.px7-captcha-box {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 12px;
	margin-block: 12px;
	padding: 12px;
	border: 1px solid #dfe8ec;
	border-radius: 12px;
	background: #f7fbfc;
	box-sizing: border-box;
	max-inline-size: 100%;
}

/* The dialog keeps an empty placeholder that JS fills; give it no chrome. */
.px7-captcha { margin-block: 10px; }
.px7-captcha:empty { display: none; }

/* ---- the answer field -------------------------------------------------- */

.px10-captcha-side,
.px7-captcha-field {
	flex: 1 1 150px;
	min-inline-size: 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.px10-captcha-side label,
.px7-captcha-box label {
	display: block;
	margin: 0;
}

.px10-captcha-side label > span,
.px7-captcha-box label > span {
	display: block;
	margin-block-end: 5px;
	font-size: 12px;
	line-height: 1.7;
	color: #33586a;
}

.px10-captcha-side input[type='text'],
.px10-captcha-box input[type='text'],
.px7-captcha-box input[type='text'] {
	display: block;
	box-sizing: border-box;
	inline-size: 100%;
	max-inline-size: 160px;
	min-block-size: 48px;
	padding: 8px 12px;
	border: 1px solid #c9dae1;
	border-radius: 10px;
	background: #fff;
	color: #183b48;
	font: inherit;
	font-size: 20px;
	font-weight: 700;
	letter-spacing: 0.42em;
	text-align: center;
	text-indent: 0.42em; /* balances the trailing letter-spacing */
	direction: ltr;
}

.px10-captcha-side input[type='text']:focus,
.px10-captcha-box input[type='text']:focus,
.px7-captcha-box input[type='text']:focus {
	border-color: #0b5b78;
	box-shadow: 0 0 0 3px rgba(11, 91, 120, .22);
	outline: none;
}

/* ---- refresh ----------------------------------------------------------- */

.px10-captcha-refresh,
.px7-captcha-refresh {
	flex: 0 0 auto;
	align-self: flex-end;
	min-block-size: 44px;
	padding: 8px 14px;
	border: 1px solid #bcd3dd;
	border-radius: 10px;
	background: #fff;
	color: #0b5b78;
	font: inherit;
	font-size: 13px;
	font-weight: 700;
	line-height: 1.4;
	cursor: pointer;
	transition: background-color 160ms ease, border-color 160ms ease;
}

.px10-captcha-refresh:hover,
.px7-captcha-refresh:hover {
	background: #eef6f9;
	border-color: #0b5b78;
}

.px10-captcha-refresh:focus-visible,
.px7-captcha-refresh:focus-visible {
	outline: 2px solid #0b5b78;
	outline-offset: 2px;
}

/* ---- helper text ------------------------------------------------------- */

.px10-captcha-side small,
.px7-captcha-box small {
	display: block;
	margin: 0;
	font-size: 11px;
	line-height: 1.8;
	color: #7b93a0;
}

/* In the dialog the note is a sibling of the field, so give it its own row. */
.px7-captcha-box > small {
	flex: 1 0 100%;
	margin-block-start: 2px;
}

/* ---- the "no challenge available" notice ------------------------------- */

.px10-captcha-off {
	margin-block: 12px;
	padding: 12px 14px;
	border: 1px solid #f2b3ad;
	border-radius: 10px;
	background: #fff6f5;
	color: #8a1f1a;
	font-size: 13px;
	line-height: 1.9;
}

.px10-captcha-off a { color: #8a1f1a; text-decoration: underline; }

/* ---- Turnstile keeps the same rhythm ----------------------------------- */

.cf-turnstile { margin-block: 12px; }

/* ======================================================== narrow screens = */

@media (max-width: 419px) {
	.px10-captcha,
	.px10-captcha-box,
	.px7-captcha-box {
		flex-direction: column;
		align-items: stretch;
	}

	/* Full width image, no clipping. */
	.px10-captcha-image svg,
	.px10-captcha-box svg,
	.px7-captcha-box svg,
	svg.px10-captcha-svg,
	.px10-captcha-image img,
	.px10-captcha-box img,
	.px7-captcha-box img {
		inline-size: 100%;
		max-inline-size: 300px;
	}

	.px10-captcha-side input[type='text'],
	.px10-captcha-box input[type='text'],
	.px7-captcha-box input[type='text'],
	.px10-captcha-refresh,
	.px7-captcha-refresh {
		max-inline-size: none;
		inline-size: 100%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.px10-captcha-refresh,
	.px7-captcha-refresh { transition: none; }
}

@media print {
	.px10-captcha,
	.px10-captcha-box,
	.px7-captcha-box,
	.px7-captcha,
	.cf-turnstile { display: none !important; }
}
