/**
 * M2 Gives Donations - donation form styles.
 * Visual direction: warm off-white surfaces, black typography, light blue
 * accent, rounded cards, accessible focus states, reduced motion support.
 */

.m2gd-form-wrap {
	--m2gd-surface: #faf7f2;
	--m2gd-surface-alt: #ffffff;
	--m2gd-text: #16181c;
	--m2gd-text-muted: #55585e;
	--m2gd-accent: #7fc4e0;
	--m2gd-accent-strong: #3f9dc4;
	--m2gd-border: #e4ddd2;
	--m2gd-error: #b3261e;
	--m2gd-success: #1f7a4d;
	--m2gd-radius: 16px;
	--m2gd-radius-sm: 10px;
	--m2gd-focus-ring: 0 0 0 3px rgba(63, 157, 196, 0.45);

	background: var(--m2gd-surface);
	color: var(--m2gd-text);
	border-radius: var(--m2gd-radius);
	padding: 1.75rem;
	max-width: 640px;
	font-family: inherit;
	line-height: 1.5;
	box-shadow: 0 1px 2px rgba(22, 24, 28, 0.06);
}

.m2gd-form-wrap * {
	box-sizing: border-box;
}

/*
 * v1.0.8: authoritative closed state for every element the form toggles via the
 * native `hidden` attribute. Several plugin controls set a class-level `display`
 * (e.g. `.m2gd-btn { display: inline-flex }`, `.m2gd-endowment-modal
 * { display: flex }`), which — being author-level — defeats the user-agent
 * `[hidden] { display: none }` rule, so a `hidden` control (the "Make Another
 * Donation" button, the endowment modal, panels, notices) rendered visible on
 * first paint. Scoping to `.m2gd-form-wrap` keeps this from touching anything
 * outside the plugin's own form, and it is safe with the JS state machine
 * because every show/hide transition flips the `hidden` property itself
 * (el.hidden = true/false) rather than inline `display`, so revealing an element
 * simply removes the attribute and this rule stops applying. It also survives
 * hostile theme CSS. `input[type="hidden"]` is unaffected: that is a `type`
 * value, not the `hidden` attribute, so it does not match `[hidden]`.
 */
.m2gd-form-wrap [hidden] {
	display: none !important;
}

.m2gd-noscript-warning {
	background: #fff3cd;
	border: 1px solid #e0c46c;
	border-radius: var(--m2gd-radius-sm);
	padding: 0.75rem 1rem;
}

.m2gd-tabs {
	display: flex;
	gap: 0.5rem;
	margin-bottom: 1.5rem;
	border-bottom: 1px solid var(--m2gd-border);
}

.m2gd-tab {
	background: transparent;
	border: none;
	border-bottom: 3px solid transparent;
	padding: 0.75rem 1rem;
	font-size: 1rem;
	font-weight: 600;
	color: var(--m2gd-text-muted);
	cursor: pointer;
}

.m2gd-tab[aria-selected="true"] {
	color: var(--m2gd-text);
	border-bottom-color: var(--m2gd-accent-strong);
}

.m2gd-tab:focus-visible,
.m2gd-btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.m2gd-radio-card input:focus-visible {
	outline: none;
	box-shadow: var(--m2gd-focus-ring);
}

.m2gd-fieldset {
	border: none;
	padding: 0;
	margin: 0 0 1.5rem;
}

.m2gd-fieldset legend {
	font-weight: 700;
	font-size: 1rem;
	margin-bottom: 0.75rem;
	padding: 0;
}

.m2gd-disclosure-toggle {
	background: none;
	border: none;
	padding: 0;
	font-weight: 700;
	font-size: 1rem;
	cursor: pointer;
	color: var(--m2gd-text);
	text-decoration: underline;
	text-decoration-color: var(--m2gd-accent);
}

.m2gd-amount-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.6rem;
}

.m2gd-radio-card {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--m2gd-surface-alt);
	border: 1px solid var(--m2gd-border);
	border-radius: var(--m2gd-radius-sm);
	padding: 0.75rem 0.5rem;
	cursor: pointer;
	font-weight: 600;
	text-align: center;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
	.m2gd-radio-card,
	.m2gd-btn,
	.m2gd-payment-fieldset {
		transition: none;
	}

	html {
		scroll-behavior: auto;
	}
}

.m2gd-radio-card input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.m2gd-radio-card:has(input:checked) {
	border-color: var(--m2gd-accent-strong);
	background: #eaf6fb;
}

/*
 * v1.0.7: the real radio/checkbox inside an amount/scholarship card is visually
 * hidden (1px, opacity 0), so a focus ring on the input alone is an invisible
 * 1px target. Promote the keyboard focus indicator to the FULL visible label
 * card via :has(input:focus-visible). Both an outline and a box-shadow are
 * drawn: the box-shadow survives hostile theme resets like `*:focus{outline:0}`
 * that some page builders apply, so a clearly visible WCAG-compliant indicator
 * remains in the integrated public context. Keyboard-only (:focus-visible), so
 * clicking a card does not paint a persistent ring.
 */
.m2gd-radio-card:has(input:focus-visible) {
	outline: 3px solid var(--m2gd-accent-strong);
	outline-offset: 2px;
	box-shadow: var(--m2gd-focus-ring);
}

.m2gd-radio-card-other {
	grid-column: span 1;
}

.m2gd-other-amount {
	margin-top: 0.75rem;
}

.m2gd-field {
	margin-bottom: 0.9rem;
}

.m2gd-field label {
	display: block;
	font-weight: 600;
	margin-bottom: 0.3rem;
}

.m2gd-field input[type="text"],
.m2gd-field input[type="email"],
.m2gd-field input[type="tel"],
.m2gd-field input[type="number"],
.m2gd-field textarea {
	width: 100%;
	padding: 0.6rem 0.75rem;
	border: 1px solid var(--m2gd-border);
	border-radius: var(--m2gd-radius-sm);
	background: var(--m2gd-surface-alt);
	color: var(--m2gd-text);
	font-size: 1rem;
}

.m2gd-field-checkbox label {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	font-weight: 500;
}

/*
 * Consent/privacy row: some WordPress themes apply a condensed, uppercase,
 * letter-spaced "display" font to all <label>/<a> elements site-wide. That
 * is appropriate for headings/nav labels but breaks legibility on this
 * legal sentence and can cause "Privacy Policy" to wrap mid-phrase. The
 * rules below are scoped to `.m2gd-form-wrap` (the plugin's own root
 * container) and use class + element selectors with enough specificity to
 * win over generic theme `label`/`a` rules without any `!important` and
 * without touching any other `.m2gd-field-checkbox` row (Patron Wall
 * opt-in, Anonymous display) or any other page/element on the site.
 */
.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field label.m2gd-consent-label {
	display: flex;
	align-items: flex-start;
	gap: 0.6rem;
	font-family: inherit;
	font-size: 1rem;
	font-weight: 400;
	font-style: normal;
	line-height: 1.5;
	text-transform: none;
	letter-spacing: normal;
	word-spacing: normal;
	color: var(--m2gd-text);
	cursor: pointer;
}

.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field input.m2gd-consent-checkbox {
	flex: 0 0 auto;
	width: 1.1em;
	height: 1.1em;
	margin: 0.2em 0 0;
	accent-color: var(--m2gd-accent-strong);
}

.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field span.m2gd-consent-text {
	display: inline;
	flex: 1 1 auto;
	font-family: inherit;
	font-size: 1rem;
	font-weight: 400;
	font-style: normal;
	line-height: 1.5;
	text-transform: none;
	letter-spacing: normal;
	word-spacing: normal;
	color: var(--m2gd-text);
	overflow-wrap: break-word;
}

.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field a.m2gd-consent-link {
	font-family: inherit;
	font-size: inherit;
	font-weight: 600;
	font-style: normal;
	text-transform: none;
	letter-spacing: normal;
	white-space: nowrap;
	color: var(--m2gd-accent-strong);
	text-decoration: underline;
	text-decoration-color: var(--m2gd-accent);
}

.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field a.m2gd-consent-link:hover,
.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field a.m2gd-consent-link:focus-visible {
	color: var(--m2gd-text);
}

.m2gd-field-row {
	display: flex;
	gap: 1rem;
	margin-bottom: 0.75rem;
	flex-wrap: wrap;
}

.m2gd-collapsible {
	margin-top: 0.5rem;
	padding: 1rem;
	background: var(--m2gd-surface-alt);
	border-radius: var(--m2gd-radius-sm);
	border: 1px solid var(--m2gd-border);
}

.m2gd-scholarship-levels {
	display: grid;
	gap: 0.6rem;
	margin-bottom: 1rem;
}

.m2gd-scholarship-levels .m2gd-radio-card {
	justify-content: flex-start;
	text-align: left;
}

.m2gd-naming-approval-note {
	background: #eaf6fb;
	border: 1px solid var(--m2gd-accent);
	border-radius: var(--m2gd-radius-sm);
	padding: 0.75rem 1rem;
	font-size: 0.9rem;
	margin-top: 0.5rem;
}

.m2gd-endowment-cta {
	background: var(--m2gd-surface-alt);
	border: 1px dashed var(--m2gd-border);
	border-radius: var(--m2gd-radius-sm);
	padding: 1rem;
	margin-bottom: 1rem;
}

.m2gd-standard-amounts-label {
	font-weight: 600;
	margin-bottom: 0.5rem;
}

.m2gd-payment-element {
	background: var(--m2gd-surface-alt);
	border: 1px solid var(--m2gd-border);
	border-radius: var(--m2gd-radius-sm);
	padding: 1rem;
	min-height: 2.5rem;
}

.m2gd-payment-status {
	margin-top: 0.5rem;
	font-size: 0.9rem;
	color: var(--m2gd-text-muted);
}

.m2gd-payment-helper {
	margin: 0 0 0.75rem;
	font-size: 0.9rem;
	color: var(--m2gd-text-muted);
}

/*
 * Two-stage checkout: the payment fieldset is rendered with the native
 * `hidden` attribute (see class-m2gd-shortcode-donation-form.php) so it is
 * removed from the accessibility tree and layout before Stripe Elements is
 * mounted, per the v1.0.3 UX requirement to never show an empty bordered
 * Payment Element area or a misleading visible "Payment details" section
 * before mounting. `[hidden]` already fully hides the element; the rules
 * below only add a subtle reveal transition for browsers that support it,
 * applied via the `.m2gd-payment-fieldset-visible` class the JS adds at
 * the same time it removes the `hidden` attribute.
 */
.m2gd-payment-fieldset {
	opacity: 1;
	transform: translateY(0);
	transition: opacity 0.25s ease, transform 0.25s ease;
}

.m2gd-payment-fieldset[hidden] {
	display: none;
}

.m2gd-payment-fieldset.m2gd-payment-fieldset-revealing {
	opacity: 0;
	transform: translateY(6px);
}

.m2gd-payment-fieldset legend[data-payment-legend] {
	outline: none;
}

/*
 * Gift-details locking (state integrity): once a PaymentIntent/Subscription
 * exists, amount/frequency/designation/tribute/patron-wall/donor-info
 * controls are disabled via the native `disabled` attribute (see
 * lockGiftDetails() in donation-form.js) so no silent mismatch between the
 * on-screen selection and the already-created Stripe object can occur.
 * `:disabled` already communicates the locked state to assistive tech; the
 * rules below add a visible affordance consistent with `.m2gd-btn:disabled`.
 */
.m2gd-gift-details-region.m2gd-gift-details-locked {
	position: relative;
}

.m2gd-gift-details-region.m2gd-gift-details-locked .m2gd-radio-card {
	opacity: 0.6;
	cursor: not-allowed;
}

.m2gd-gift-details-region.m2gd-gift-details-locked input:disabled,
.m2gd-gift-details-region.m2gd-gift-details-locked textarea:disabled {
	background: var(--m2gd-surface);
	color: var(--m2gd-text-muted);
	cursor: not-allowed;
}

.m2gd-tabs.m2gd-tabs-locked .m2gd-tab {
	opacity: 0.6;
	cursor: not-allowed;
}

.m2gd-lock-notice {
	background: #eaf6fb;
	border: 1px solid var(--m2gd-accent);
	border-radius: var(--m2gd-radius-sm);
	padding: 0.75rem 1rem;
	font-size: 0.9rem;
	margin-bottom: 1rem;
}

.m2gd-lock-notice[hidden] {
	display: none;
}

.m2gd-btn-link {
	background: none;
	border: none;
	padding: 0;
	font-weight: 600;
	font-size: 0.9rem;
	color: var(--m2gd-accent-strong);
	text-decoration: underline;
	text-decoration-color: var(--m2gd-accent);
	cursor: pointer;
	display: block;
	margin-bottom: 0.75rem;
}

.m2gd-btn-link[hidden] {
	display: none;
}

.m2gd-btn-link:hover,
.m2gd-btn-link:focus-visible {
	color: var(--m2gd-text);
}

.m2gd-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border-radius: 999px;
	padding: 0.75rem 1.5rem;
	font-weight: 700;
	font-size: 1rem;
	cursor: pointer;
	border: 2px solid transparent;
}

.m2gd-btn-primary {
	background: var(--m2gd-accent-strong);
	color: #ffffff;
}

.m2gd-btn-primary:hover {
	background: #2f87ab;
}

.m2gd-btn-secondary {
	background: transparent;
	border-color: var(--m2gd-text);
	color: var(--m2gd-text);
}

.m2gd-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.m2gd-form-footer {
	margin-top: 1.5rem;
}

.m2gd-security-note {
	font-size: 0.85rem;
	color: var(--m2gd-text-muted);
	margin-top: 0.5rem;
}

.m2gd-test-mode-badge {
	display: inline-block;
	background: #fff3cd;
	border: 1px solid #e0c46c;
	border-radius: 999px;
	padding: 0.2rem 0.75rem;
	font-size: 0.8rem;
	font-weight: 600;
	margin-top: 0.5rem;
}

.m2gd-form-message {
	margin-top: 1rem;
	padding: 0.75rem 1rem;
	border-radius: var(--m2gd-radius-sm);
	font-weight: 600;
}

.m2gd-message-error {
	background: #fdecea;
	color: var(--m2gd-error);
	border: 1px solid #f2b8b5;
}

.m2gd-message-success {
	background: #e8f5ee;
	color: var(--m2gd-success);
	border: 1px solid #a9d9bf;
}

.m2gd-help-text {
	font-size: 0.85rem;
	color: var(--m2gd-text-muted);
}

.screen-reader-text {
	position: absolute;
	left: -9999px;
	top: -9999px;
}

.m2gd-endowment-modal {
	position: fixed;
	inset: 0;
	background: rgba(22, 24, 28, 0.5);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	overflow-y: auto;
	z-index: 9999;
}

/*
 * v1.0.7: the modal is toggled purely via the native `hidden` attribute, but
 * its own `display: flex` rule (class specificity) would otherwise defeat the
 * user-agent `[hidden] { display: none }` rule, so the dialog rendered open on
 * first paint. This attribute-scoped `!important` guard is the authoritative
 * closed state: it beats the class-level `display` AND any hostile theme rule
 * (e.g. CmsMasters/Elementor) that might force a display value on the element.
 * It is intentionally limited to this one dialog element, never a blanket
 * `[hidden]` override, so it can only ever hide this modal.
 */
.m2gd-endowment-modal[hidden] {
	display: none !important;
}

.m2gd-endowment-modal-inner {
	position: relative;
	background: var(--m2gd-surface);
	border-radius: var(--m2gd-radius);
	padding: 1.5rem;
	max-width: 480px;
	width: 100%;
	/* Stay within the viewport on short screens; the dialog body scrolls
	   internally rather than being clipped off-screen (v1.0.7). */
	max-height: calc(100vh - 2rem);
	overflow-y: auto;
	margin: auto;
}

.m2gd-endowment-modal-actions {
	display: flex;
	gap: 0.75rem;
	margin-top: 1rem;
}

@media (max-width: 480px) {
	.m2gd-amount-grid {
		grid-template-columns: repeat(2, 1fr);
	}
	.m2gd-form-wrap {
		padding: 1.1rem;
	}
	.m2gd-form-wrap fieldset.m2gd-consent-fieldset .m2gd-consent-field label.m2gd-consent-label {
		gap: 0.5rem;
		font-size: 0.95rem;
	}
	.m2gd-payment-fieldset {
		margin-left: -1.1rem;
		margin-right: -1.1rem;
		padding-left: 1.1rem;
		padding-right: 1.1rem;
	}
	.m2gd-payment-element {
		padding: 0.75rem;
	}
	.m2gd-lock-notice {
		font-size: 0.85rem;
		padding: 0.65rem 0.85rem;
	}
	.m2gd-form-footer .m2gd-btn-primary {
		width: 100%;
	}
}

/* v1.0.5: tribute radio text is wrapped in a span so the accessible name has
   no leading whitespace; restore the visual gap the old inline space gave. */
.m2gd-form-wrap .m2gd-radio-text {
	margin-left: 0.4rem;
}

/* v1.0.5: selected-gift summary shown before Continue to Secure Payment. */
.m2gd-gift-summary {
	margin: 0.75rem 0 0.5rem;
	padding: 0.75rem 0.9rem;
	background: #f4f7fb;
	border: 1px solid #d8e0ea;
	border-radius: 6px;
	font-size: 0.95rem;
	line-height: 1.4;
}
.m2gd-gift-summary[hidden] {
	display: none;
}
.m2gd-gift-summary .m2gd-gift-summary-label {
	font-weight: 600;
	margin-right: 0.35rem;
}
.m2gd-gift-summary .m2gd-gift-summary-value {
	word-break: break-word;
}

/* v1.0.5: accessible close (×) control in the endowment inquiry modal header. */
.m2gd-endowment-modal-close {
	position: absolute;
	top: 0.5rem;
	right: 0.5rem;
	width: 2.25rem;
	height: 2.25rem;
	min-width: 44px;
	min-height: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 1.5rem;
	line-height: 1;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 6px;
	cursor: pointer;
	color: inherit;
}
.m2gd-endowment-modal-close:hover,
.m2gd-endowment-modal-close:focus-visible {
	border-color: #2563eb;
	outline: 2px solid #2563eb;
	outline-offset: 1px;
}
