/*
 * Verification controls.
 *
 * Borrows the theme's palette and radii through its own custom properties,
 * falling back to literal PRISTORA values so the control still looks right on a
 * screen the theme has not styled (and if the theme is ever swapped out, it
 * degrades to something plain rather than something broken).
 *
 * Everything is scoped under .pristora-verify. No WooCommerce or theme selector
 * is touched.
 */

/*
 * ---------------------------------------------------------------------------
 * Colour is chosen by SURFACE, not by element
 * ---------------------------------------------------------------------------
 * This control renders on two very different backgrounds: the white classic
 * checkout and My Account, and the dark forest registration card. The original
 * single palette was written for the light one, and on the dark card it failed
 * badly — the call to action was forest green on a forest green card, so only
 * its border showed, and the explanatory and error lines were #5C6B55 on
 * #173f35, which is 2.1:1 and 1.8:1. Neither is readable.
 *
 * So every colour that depends on what is behind it is a role token, set once
 * per surface below. Ratios quoted are measured against the surface the token
 * is used on; "AA" means at least 4.5:1 for text and 3:1 for a focus ring or a
 * control boundary.
 */
.pristora-verify,
.pristora-verify-group,
.pristora-verify-state {
	/* Light surface: white checkout and account panels. */
	--pv-cta-bg: #173F35;          /* forest  — white text on it: 11.7:1 */
	--pv-cta-fg: #FFFFFF;
	--pv-cta-bg-hover: #12352B;    /* forest-deep — white text: 14.2:1 */
	--pv-cta-bg-disabled: #C9D2CB;
	--pv-cta-fg-disabled: #4A544D;     /* 5.1:1 on the disabled background */
	--pv-cta-border-disabled: #8A968A; /* 3.1:1 against white, so the shape survives */
	--pv-focus: #173F35;               /* 11.7:1 against white */

	--pv-text: #4A5A48;            /* body text on white: 7.4:1 */
	--pv-text-ok: #1B5E20;
	--pv-text-error: #A4221B;      /* 6.2:1 on white */

	--pv-ink: var(--wp--preset--color--ink, #1E1E1E);
	--pv-line: #D7DDD2;
	--pv-panel: #FBFCFA;

	margin: 8px 0 0;
	font-size: 14px;
	line-height: 1.5;
}

/*
 * Dark surface: the forest registration card, #173f35 → #123029.
 *
 * The call to action becomes lime with forest lettering, which is the same
 * treatment the card's own "Create account" button already uses, so the two
 * read as one family rather than as two competing buttons.
 */
.pristora-verify--dark,
.pristora-verify-group--dark {
	--pv-cta-bg: #B7E33B;          /* lime — forest text on it: 7.9:1, and 7.9:1 against the card */
	--pv-cta-fg: #173F35;
	--pv-cta-bg-hover: #A5CF2F;    /* forest text: 6.4:1 */
	--pv-cta-bg-disabled: #2B4136;     /* muted, so it reads as unavailable */
	--pv-cta-fg-disabled: #C6CFC0;     /* 6.7:1 on the disabled background */
	--pv-cta-border-disabled: #8FA56F; /* 4.3:1 against the card, so the button keeps its shape */
	--pv-focus: #B7E33B;               /* 7.9:1 against the card */

	--pv-text: rgba(247, 242, 231, 0.88); /* ≈ #DCDCD2 on the card: 8.5:1 */
	--pv-text-ok: #A5D6A7;         /* 7.1:1 on the card */
	--pv-text-error: #FFB4AB;      /* 6.9:1 on the card */
}

/*
 * `[hidden]` is only `display: none` in the user-agent stylesheet, which any
 * class selector here outranks — so the status pill and the challenge box both
 * stayed on screen while carrying the attribute. Restoring it explicitly, and
 * scoped to this component, is what makes hidden actually mean hidden.
 */
.pristora-verify [hidden] {
	display: none !important;
}

.pristora-verify__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.pristora-verify__send,
.pristora-verify__check {
	appearance: none;
	border: 1px solid var(--pv-cta-bg);
	background: var(--pv-cta-bg);
	color: var(--pv-cta-fg);
	border-radius: 8px;
	padding: 8px 16px;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	min-height: 40px;
}

.pristora-verify__send:hover,
.pristora-verify__check:hover {
	background: var(--pv-cta-bg-hover);
	border-color: var(--pv-cta-bg-hover);
	color: var(--pv-cta-fg);
}

/*
 * Disabled is drawn, not faded. `opacity: 0.6` let the card's own background
 * bleed through, so the same rule produced a different — and on the dark card
 * an unreadable — result on each surface.
 */
.pristora-verify__send:disabled,
.pristora-verify__check:disabled {
	background: var(--pv-cta-bg-disabled);
	border-color: var(--pv-cta-border-disabled);
	color: var(--pv-cta-fg-disabled);
	cursor: default;
}

.pristora-verify__send:focus-visible,
.pristora-verify__check:focus-visible,
.pristora-verify__resend:focus-visible,
.pristora-verify__code:focus-visible {
	outline: 2px solid var(--pv-focus);
	outline-offset: 2px;
}

/*
 * The challenge panel is light on every card, so inside it the whole surface
 * goes back to the light set. Without this the dark card's lime button carried
 * on into the panel, where lime on near-white is only 1.5:1 and the control
 * read as washed out rather than as the primary action.
 */
.pristora-verify--dark .pristora-verify__challenge,
.pristora-verify-group--dark .pristora-verify__challenge {
	--pv-cta-bg: #173F35;
	--pv-cta-fg: #FFFFFF;
	--pv-cta-bg-hover: #12352B;
	--pv-cta-bg-disabled: #C9D2CB;
	--pv-cta-fg-disabled: #4A544D;
	--pv-cta-border-disabled: #8A968A;
	--pv-focus: #173F35;

	--pv-text: #4A5A48;
	--pv-text-ok: #1B5E20;
	--pv-text-error: #A4221B;
}

/*
 * The verified pill carries its own solid ground on purpose. It appears on the
 * registration card, which is dark forest, and inside classic checkout, which is
 * white; a bare green word is unreadable on one or the other. A chip with its
 * own background reads on both, and stops this component depending on what the
 * theme happens to put behind it.
 */
.pristora-verify__status {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	font-weight: 600;
	padding: 5px 12px;
	border-radius: 999px;
}

.pristora-verify__status--ok {
	background: #E6F4E8;
	color: #1B5E20;
}

/*
 * Pending is amber rather than red: nothing has gone wrong, there is simply a
 * step left. Red would read as an error on an account screen the customer has
 * only just opened.
 */
.pristora-verify__status--pending {
	background: #FDF3DC;
	color: #7A5300;
}

/*
 * The state pill above a control, on the account screen. It carries the same
 * [hidden] correction as the component itself because it is rendered outside
 * .pristora-verify.
 */
.pristora-verify-state {
	margin: 8px 0 0;
	font-size: 14px;
	line-height: 1.5;
}

.pristora-verify-state [hidden] {
	display: none !important;
}

/*
 * The email control is a link, not a button: it hands over to WooCommerce's own
 * send-the-link request. It is styled as the button beside it so the two
 * channels read as one pair of controls.
 */
.pristora-verify__send--link {
	display: inline-flex;
	align-items: center;
	text-decoration: none;
}

.pristora-verify__send--link:hover,
.pristora-verify__send--link:focus {
	color: #FFF;
	text-decoration: none;
}

/*
 * The challenge panel keeps its own light background on every surface. A code
 * field has to be unambiguously readable while it is being typed, and giving it
 * one known background is a stronger guarantee than tinting it per surface.
 */
.pristora-verify__challenge {
	margin-top: 10px;
	padding: 12px;
	border: 1px solid var(--pv-line);
	border-radius: 10px;
	background: var(--pv-panel);
	color: var(--pv-ink);
}

.pristora-verify__label {
	display: block;
	margin-bottom: 6px;
	font-weight: 600;
	color: var(--pv-ink);
}

.pristora-verify__code {
	flex: 0 1 160px;
	min-width: 0;
	padding: 8px 12px;
	border: 1px solid #8A968A;
	border-radius: 8px;
	background: #FFFFFF;
	color: var(--pv-ink);
	font: inherit;
	/* A code is read back digit by digit; spacing them helps. */
	letter-spacing: 0.3em;
	text-align: center;
	min-height: 40px;
}

.pristora-verify__resend {
	appearance: none;
	border: 0;
	background: none;
	padding: 8px 0 0;
	font: inherit;
	font-size: 13px;
	/* Sits inside the light challenge panel on every surface: 11.1:1. */
	color: #173F35;
	text-decoration: underline;
	cursor: pointer;
}

.pristora-verify__resend:disabled {
	color: #596258;
	text-decoration: none;
	cursor: default;
}

.pristora-verify__message {
	margin: 8px 0 0;
	font-size: 13px;
	color: var(--pv-text);
}

.pristora-verify__message.is-ok {
	color: var(--pv-text-ok);
}

.pristora-verify__message.is-error {
	color: var(--pv-text-error);
	font-weight: 600;
}

/*
 * The explanatory line under the control. This was the worst offender: #5C6B55
 * on the forest card is 2.1:1, and it is the line that tells the customer what
 * the number will be used for.
 */
.pristora-verify__consent {
	margin: 8px 0 0;
	font-size: 13px;
	color: var(--pv-text);
}

/*
 * The checkout group. The server renders both controls here after the billing
 * fields; the script then lifts each one up against its own field, at which
 * point these items are no longer siblings and the group wrapper is left
 * holding only the consent line. Both arrangements have to look deliberate.
 */
.pristora-verify-group__item {
	margin: 12px 0 0;
}

.pristora-verify-group__label {
	display: block;
	font-size: 13px;
	font-weight: 600;
	color: #5C6B55;
}

/*
 * Once a control sits directly under its field, the field's own label already
 * names it and repeating it would read as a stray heading.
 */
.form-row + .pristora-verify-group__item > .pristora-verify-group__label {
	display: none;
}

.pristora-verify-group > .pristora-verify__consent {
	margin-top: 12px;
}

/* Phones: the buttons go full width so they are not a 60px target beside an input. */
@media (max-width: 600px) {
	.pristora-verify__send,
	.pristora-verify__check {
		flex: 1 1 100%;
	}

	.pristora-verify__code {
		flex: 1 1 100%;
		text-align: left;
	}
}
