/*
 * LorePort signup form.
 *
 * Takes its fonts and text colour from the site, and mixes its borders and
 * backgrounds from the text colour, so it suits light and dark themes alike.
 * Every rule uses :where(), so a theme's own styles (such as its button
 * style) win without a fight.
 *
 * To restyle, set these on .loreport-signup (or any parent):
 *   --loreport-accent         button and focus ring (default: the theme's primary colour, or a deep blue)
 *   --loreport-accent-text    text on the button (default: white)
 *   --loreport-radius         the card's corners (default: 12px)
 *   --loreport-field-radius   field and button corners (default: 8px)
 *   --loreport-surface        the card's background
 *   --loreport-line           borders
 */

:where(.loreport-signup) {
	--loreport-accent: var(--wp--preset--color--primary, #3f4fb8);
	--loreport-accent-text: #fff;
	--loreport-radius: 12px;
	--loreport-field-radius: 8px;
	--loreport-line: color-mix(in srgb, currentColor 16%, transparent);
	--loreport-surface: color-mix(in srgb, currentColor 4%, transparent);
	--loreport-field-bg: color-mix(in srgb, currentColor 3%, transparent);
	--loreport-good: #1a7f4b;
	--loreport-bad: #b42318;
	box-sizing: border-box;
	max-width: 40rem;
	margin-block: 1.5em;
}

:where(.loreport-signup *, .loreport-signup *::before, .loreport-signup *::after) {
	box-sizing: inherit;
}

/* Card: a soft panel. Plain: just the fields. */
:where(.loreport-signup--card) {
	padding: clamp(1.1rem, 3vw, 1.75rem);
	border: 1px solid var(--loreport-line);
	border-radius: var(--loreport-radius);
	background: var(--loreport-surface);
}

:where(.loreport-signup__form) {
	display: grid;
	gap: .9rem;
	margin: 0;
}

:where(.loreport-signup__header) {
	display: grid;
	gap: .3rem;
}

:where(.loreport-signup__title) {
	margin: 0;
	font-size: 1.2em;
	font-weight: 650;
	line-height: 1.25;
}

:where(.loreport-signup__description) {
	margin: 0;
	line-height: 1.5;
	opacity: .78;
}

/* Fields sit side by side when there's room. */
:where(.loreport-signup__fields) {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
	gap: .75rem;
	align-items: end;
}

/* Labels share one row and boxes the next (a subgrid), so side-by-side
   fields line up whatever is inside them. */
:where(.loreport-signup__field) {
	display: grid;
	grid-row: span 2;
	grid-template-rows: subgrid;
	row-gap: .35rem;
	align-items: end;
	margin: 0;
	padding: 0;
}

:where(.loreport-signup__field label) {
	display: block;
	margin: 0;
	font-size: .9em;
	font-weight: 600;
	line-height: 1.3;
}

:where(.loreport-signup__optional) {
	font-weight: 400;
	opacity: .65;
}

:where(.loreport-signup__field input) {
	display: block;
	width: 100%;
	height: 2.9em;
	margin: 0;
	padding: .65em .85em;
	border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
	border-radius: var(--loreport-field-radius);
	background: var(--loreport-field-bg);
	color: inherit;
	font: inherit;
	line-height: 1.3;
	transition: border-color .15s ease, box-shadow .15s ease;
}

:where(.loreport-signup__field input::placeholder) {
	color: currentColor;
	opacity: .45;
}

:where(.loreport-signup__field input:focus) {
	outline: none;
	border-color: var(--loreport-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--loreport-accent) 25%, transparent);
}

/* With the email field alone, it takes the whole row. */
:where(.loreport-signup__fields:not(:has(.loreport-signup__field--name))) {
	grid-template-columns: 1fr;
}

/* The button spans the row in the stacked layout. */
:where(.loreport-signup__submit) {
	grid-column: 1 / -1;
	margin: 0;
}

:where(.loreport-signup__button) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .5em;
	min-height: 2.9em;
	padding: .65em 1.4em;
	border: 0;
	border-radius: var(--loreport-field-radius);
	background: var(--loreport-accent);
	color: var(--loreport-accent-text);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: filter .15s ease, transform .05s ease;
}

:where(.loreport-signup__button:hover) {
	filter: brightness(1.08);
}

:where(.loreport-signup__button:active) {
	transform: translateY(1px);
}

:where(.loreport-signup__button:focus-visible) {
	outline: 2px solid var(--loreport-accent);
	outline-offset: 2px;
}

/* A spinner while the form is being sent. */
:where(.loreport-signup__form[aria-busy="true"] .loreport-signup__button) {
	pointer-events: none;
	opacity: .85;
}

:where(.loreport-signup__form[aria-busy="true"] .loreport-signup__button)::after {
	content: "";
	width: 1em;
	height: 1em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: loreport-spin .7s linear infinite;
}

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

/* The consent checkbox gets a row of its own, above the button. */
:where(.loreport-signup__consent) {
	grid-column: 1 / -1;
	margin: 0;
	font-size: .9em;
	line-height: 1.45;
}

:where(.loreport-signup__consent span) {
	opacity: .85;
}

/* Inline: email and button on one line. Labels stay for screen readers. */
:where(.loreport-signup--inline .loreport-signup__fields) {
	display: flex;
	flex-wrap: wrap;
	align-items: stretch;
	gap: .5rem;
}

:where(.loreport-signup--inline .loreport-signup__field) {
	display: block;
	flex: 1 1 12rem;
}

:where(.loreport-signup--inline .loreport-signup__submit) {
	display: flex;
	flex: 0 0 auto;
}

/* Inline: the checkbox goes under the email and button. */
:where(.loreport-signup--inline .loreport-signup__consent) {
	flex: 1 1 100%;
	order: 3;
}

:where(.loreport-signup--inline .loreport-signup__field label) {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

@media (max-width: 30rem) {
	:where(.loreport-signup--inline .loreport-signup__submit, .loreport-signup--inline .loreport-signup__button) {
		flex: 1 1 100%;
		width: 100%;
	}
}

/* Hidden from people; bots fill it in. */
:where(.loreport-signup__trap) {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* The answer after sending; hidden until there is one. */
:where(.loreport-signup__message) {
	display: none;
	align-items: flex-start;
	gap: .6rem;
	padding: .75rem .9rem;
	border-radius: var(--loreport-field-radius);
	line-height: 1.45;
}

:where(.loreport-signup__message.is-good, .loreport-signup__message.is-bad) {
	display: flex;
}

:where(.loreport-signup__message.is-good) {
	border: 1px solid color-mix(in srgb, var(--loreport-good) 30%, transparent);
	background: color-mix(in srgb, var(--loreport-good) 10%, transparent);
	color: var(--loreport-good);
}

:where(.loreport-signup__message.is-bad) {
	border: 1px solid color-mix(in srgb, var(--loreport-bad) 28%, transparent);
	background: color-mix(in srgb, var(--loreport-bad) 8%, transparent);
	color: var(--loreport-bad);
}

:where(.loreport-signup__check) {
	flex: 0 0 auto;
	width: 1.4em;
	height: 1.4em;
}

:where(.loreport-signup__message.is-bad .loreport-signup__check) {
	display: none;
}

/* Once signed up, the fields step aside and the answer takes their place. */
:where(.loreport-signup.is-done .loreport-signup__fields) {
	display: none;
}

/* Opt-in checkboxes (signup forms, comment form, Statamic forms). */
:where(.comment-form-loreport label, .loreport-optin) {
	cursor: pointer;
	display: flex;
	align-items: flex-start;
	gap: .55em;
	line-height: 1.45;
}

:where(.comment-form-loreport input[type="checkbox"], .loreport-optin input[type="checkbox"]) {
	flex: 0 0 auto;
	width: 1.15em;
	height: 1.15em;
	cursor: pointer;
	margin: .18em 0 0;
	accent-color: var(--loreport-accent, currentColor);
}

/* Only admins see this, when the form isn't set up yet. */
:where(.loreport-signup__setup) {
	padding: .75em 1em;
	border: 1px dashed currentColor;
	border-radius: 8px;
	opacity: .8;
}

@media (prefers-reduced-motion: reduce) {
	:where(.loreport-signup *) {
		transition: none !important;
	}

	:where(.loreport-signup__form[aria-busy="true"] .loreport-signup__button)::after {
		animation-duration: 2s;
	}
}

/*
 * Popup: a <dialog> with the form inside. Its panel borrows the page's
 * background (form.js); set --loreport-popup-bg on the dialog to choose one.
 */
/* Real specificity here: themes space out page content (margins on every
   block), and the dialog must stay centred whatever they do. */
dialog.loreport-popup {
	box-sizing: border-box;
	width: min(34rem, calc(100vw - 2rem));
	max-width: none;
	height: fit-content;
	max-height: calc(100dvh - 2rem);
	inset: 0;
	/* !important: block themes zero the first and last child's margins with
	   stronger selectors, which would pin the popup to the top. */
	margin: auto !important;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	overflow: visible;
}

dialog.loreport-popup:not([open]) {
	display: none;
}

dialog.loreport-popup::backdrop {
	background: rgb(10 12 20 / .62);
	backdrop-filter: blur(3px);
}

:where(.loreport-popup__panel) {
	position: relative;
	max-height: calc(100dvh - 2rem);
	overflow: auto;
	padding: clamp(1.25rem, 4vw, 2rem);
	border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
	border-radius: var(--loreport-radius, 14px);
	background: var(--loreport-popup-bg, Canvas);
	box-shadow: 0 24px 60px rgb(0 0 0 / .35);
}

/* Inside the popup the form needs no card of its own. */
:where(.loreport-popup .loreport-signup) {
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
}

:where(.loreport-popup .loreport-signup__title) {
	padding-right: 2.25rem;
	font-size: 1.4em;
}

:where(.loreport-popup__close) {
	position: absolute;
	top: .6rem;
	right: .6rem;
	display: grid;
	place-items: center;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 1.6rem;
	line-height: 1;
	opacity: .65;
	cursor: pointer;
}

:where(.loreport-popup__close:hover, .loreport-popup__close:focus-visible) {
	background: color-mix(in srgb, currentColor 10%, transparent);
	opacity: 1;
}

:where(html.loreport-popup-open) {
	overflow: hidden;
}

@media (prefers-reduced-motion: no-preference) {
	dialog.loreport-popup[open] .loreport-popup__panel {
		animation: loreport-pop .18s ease-out;
	}

	dialog.loreport-popup[open]::backdrop {
		animation: loreport-fade .18s ease-out;
	}
}

@keyframes loreport-pop {
	from { opacity: 0; transform: translateY(8px) scale(.98); }
}

@keyframes loreport-fade {
	from { opacity: 0; }
}

/* A ready-made button to open the popup ([loreport_popup_button] / {{ loreport:popup_button }}). */
:where(.loreport-popup-button) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 2.9em;
	padding: .65em 1.4em;
	border: 0;
	border-radius: var(--loreport-field-radius, 8px);
	background: var(--loreport-accent, var(--wp--preset--color--primary, #3f4fb8));
	color: var(--loreport-accent-text, #fff);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}
