/*
 * FEC Donativos — Donation Form
 *
 * Consumes the fecongd theme's design tokens (CSS custom properties from
 * theme.json) with sane fallbacks, so the plugin still looks reasonable on
 * another theme. No Google Fonts — font-family is inherited from the theme.
 */

.fec-donation {
	--fec-red: var(--wp--preset--color--fec-red, #b22229);
	--fec-surface-form: var(--wp--preset--color--fec-surface-form, #f1ece1);
	--fec-border: var(--wp--preset--color--fec-border, #e3e0db);
	--fec-heading: var(--wp--preset--color--fec-heading, #2a2a2a);
	--fec-body: var(--wp--preset--color--fec-body, #4a4a4a);
	--fec-muted: var(--wp--preset--color--fec-muted, #6b6b6b);
	--fec-base: var(--wp--preset--color--base, #ffffff);
	--fec-error: #b91c1c;
	--fec-error-bg: #fef2f2;
	--fec-error-border: #f87171;
	--fec-focus: var(--wp--preset--color--fec-focus, #4a4a4a);
	--fec-radius: 2px;

	max-width: 577px;
	width: 100%;
	background: var(--fec-surface-form);
	border: 1px solid var(--fec-border);
	padding: 37px;
	margin: 0 auto;
	font-family: inherit;
	color: var(--fec-body);
	box-sizing: border-box;
}

.fec-donation *,
.fec-donation *::before,
.fec-donation *::after {
	box-sizing: border-box;
}

.fec-donation__step--form > form {
	display: flex;
	flex-direction: column;
	gap: 24px;
}

/* Honeypot — hidden from everyone, real users never see or fill it in */
.fec-donation__honeypot {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.fec-donation__fieldset {
	border: none;
	margin: 0;
	padding: 0;
}

.fec-donation__label {
	display: block;
	font-size: var(--wp--preset--font-size--medium, 1.05rem);
	font-weight: 600;
	color: var(--fec-heading);
	margin: 0 0 8px;
}

.fec-donation__hint-inline {
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 400;
	color: var(--fec-muted);
	margin-left: 4px;
}

/* Frequency tabs — a real radio group styled as a tablist */
.fec-donation__tabs {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 0;
	background: var(--fec-base);
	border: 1px solid var(--fec-border);
	border-radius: var(--fec-radius);
	padding: 5px;
}

.fec-donation__tab {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 12px 16px;
	border-radius: var(--fec-radius);
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--fec-body);
	cursor: pointer;
	text-align: center;
}

.fec-donation__tab input {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
}

.fec-donation__tab input:checked + span {
	color: var(--fec-base);
}

.fec-donation__tab:has(input:checked) {
	background: var(--fec-red);
}

.fec-donation__tab:has(input:focus-visible) {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

/* Amount selector — radio group, not buttons */
.fec-donation__amounts {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 10px;
	margin-top: 12px;
}

.fec-donation__amount {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px 9px;
	border: 1px solid var(--fec-border);
	border-radius: var(--fec-radius);
	background: var(--fec-base);
	font-size: var(--wp--preset--font-size--large, 1.1rem);
	font-weight: 700;
	color: var(--fec-heading);
	cursor: pointer;
	text-align: center;
}

.fec-donation__amount--other {
	text-transform: uppercase;
	letter-spacing: 0.08em;
	font-size: var(--wp--preset--font-size--small, 0.9rem);
}

.fec-donation__amount input {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
}

.fec-donation__amount:has(input:checked) {
	background: var(--fec-red);
	border-color: var(--fec-red);
	color: var(--fec-base);
}

.fec-donation__amount:has(input:focus-visible) {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

.fec-donation__custom-amount {
	margin-top: 10px;
}

/* Inputs */
.fec-donation__input {
	width: 100%;
	height: 44px;
	padding: 0 12px;
	border: 1px solid var(--fec-border);
	border-radius: var(--fec-radius);
	background: var(--fec-base);
	font-size: var(--wp--preset--font-size--medium, 1.05rem);
	font-family: inherit;
	color: var(--fec-heading);
}

.fec-donation__input:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

.fec-donation__input[aria-invalid="true"] {
	border-color: var(--fec-error-border);
}

/* Personal data grid */
.fec-donation__grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 14px;
	margin-top: 12px;
}

.fec-donation__field {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.fec-donation__field--full {
	grid-column: 1 / -1;
}

/*
 * Each field spans three subgrid rows (label / input / error) so inputs in
 * the same row stay level when one label wraps, e.g. "NIF * (para dedução
 * fiscal)" in the narrow ~1024px column. Track gaps are zeroed and the
 * 6px label/input and 14px row spacing are rebuilt with margins, so an empty
 * error track adds nothing; the grid's negative bottom margin cancels the
 * last row's 14px.
 */
@supports (grid-template-rows: subgrid) {
	.fec-donation__grid {
		row-gap: 0;
		margin-bottom: -14px;
	}

	.fec-donation__field {
		display: grid;
		grid-row: span 3;
		grid-template-rows: subgrid;
		row-gap: 0;
		margin-bottom: 14px;
	}

	.fec-donation__field label {
		align-self: end;
	}

	.fec-donation__field .fec-donation__input {
		margin-top: 6px;
	}
}

.fec-donation__field label {
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	letter-spacing: 0.02em;
	color: var(--fec-body);
}

.fec-donation__required {
	color: var(--fec-red);
}

.fec-donation__field-error {
	font-size: var(--wp--preset--font-size--x-small, 0.8rem);
	color: var(--fec-error);
	margin: 4px 0 0;
}

/* Checkboxes */
.fec-donation__checkbox {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	cursor: pointer;
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	line-height: 1.5;
	color: var(--fec-body);
	margin-top: 16px;
}

.fec-donation__checkbox input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	width: 16px;
	height: 16px;
	margin-top: 2px;
	border: 1px solid var(--fec-border);
	border-radius: var(--fec-radius);
	background: var(--fec-base);
	flex-shrink: 0;
	cursor: pointer;
}

.fec-donation__checkbox input[type="checkbox"]:checked {
	background-color: var(--fec-red);
	border-color: var(--fec-red);
	background-image: url('data:image/svg+xml;utf8,<svg width="12" height="12" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M11.6666 3.5L5.24992 9.91667L2.33325 7" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
	background-repeat: no-repeat;
	background-position: center;
}

.fec-donation__checkbox input[type="checkbox"]:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

.fec-donation__checkbox a {
	color: var(--fec-red);
}

/* Total row */
.fec-donation__total {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px;
	border-top: 1px solid var(--fec-border);
	border-bottom: 1px solid var(--fec-border);
	padding: 16px 0;
}

.fec-donation__total-label {
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--fec-body);
}

.fec-donation__total-value {
	display: flex;
	align-items: baseline;
	gap: 8px;
}

#fec-total-value {
	font-size: var(--wp--preset--font-size--large, 1.6rem);
	font-weight: 700;
	color: var(--fec-red);
}

.fec-donation__total-qualifier {
	font-size: var(--wp--preset--font-size--x-small, 0.8rem);
	color: var(--fec-muted);
}

/* Cancellation note — docs/13-donor-emails-and-rgpd.md §2/§3, shown only
   for the monthly frequency (toggled in fec-donativos.js alongside the
   qualifiers above). */
.fec-donation__cancellation-note {
	font-size: var(--wp--preset--font-size--x-small, 0.8rem);
	color: var(--fec-muted);
	margin: 0;
}

.fec-donation__cancellation-note a {
	color: var(--fec-red);
}

/* Form-level error */
.fec-donation__error {
	background: var(--fec-error-bg);
	border: 1px solid var(--fec-error-border);
	color: var(--fec-error);
	padding: 12px 16px;
	border-radius: var(--fec-radius);
	font-size: var(--wp--preset--font-size--small, 0.9rem);
}

.fec-donation__error:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

/* Submit */
.fec-donation__actions {
	display: flex;
}

.fec-donation__submit {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	background: var(--fec-red);
	color: var(--fec-base);
	border: 2px solid var(--fec-red);
	border-radius: var(--fec-radius);
	padding: 19px 20px;
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.12em;
	font-family: inherit;
	cursor: pointer;
}

.fec-donation__submit:hover {
	background: color-mix(in srgb, var(--fec-red) 85%, black);
}

.fec-donation__submit:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

.fec-donation__submit:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.fec-donation__submit.is-loading .fec-donation__submit-text::after {
	content: "";
	display: inline-block;
	width: 14px;
	height: 14px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: var(--fec-base);
	border-radius: 50%;
	animation: fec-spin 0.6s linear infinite;
	margin-left: 8px;
	vertical-align: middle;
}

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

/* Footnote */
.fec-donation__footnote {
	font-size: var(--wp--preset--font-size--x-small, 0.8rem);
	color: var(--fec-muted);
	text-align: center;
	margin: 0;
}

/* Back button (checkout step) */
.fec-donation__back {
	background: none;
	border: none;
	color: var(--fec-red);
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	cursor: pointer;
	padding: 0;
	margin-bottom: 16px;
	font-family: inherit;
}

.fec-donation__back:hover {
	text-decoration: underline;
}

.fec-donation__back:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

/* Success */
.fec-donation__step--success {
	text-align: center;
	padding: 24px 0;
}

.fec-donation__step--success:focus-visible {
	outline: none;
}

.fec-donation__success-icon {
	width: 52px;
	height: 52px;
	border-radius: 50%;
	background: var(--fec-red);
	color: var(--fec-base);
	font-size: 1.5rem;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0 auto 16px;
}

.fec-donation__step--success .fec-donation__title {
	font-size: var(--wp--preset--font-size--large, 1.1rem);
	color: var(--fec-red);
	margin: 0 0 8px;
}

.fec-donation__step--success p {
	color: var(--fec-body);
	margin: 0;
}

/* "Fazer novo donativo" (success + reference steps) — same look as the back link */
.fec-donation__restart {
	background: none;
	border: none;
	color: var(--fec-red);
	font-size: var(--wp--preset--font-size--small, 0.9rem);
	font-weight: 700;
	cursor: pointer;
	padding: 0;
	margin-top: 24px;
	font-family: inherit;
}

.fec-donation__restart:hover {
	text-decoration: underline;
}

.fec-donation__restart:focus-visible {
	outline: 2px solid var(--fec-focus);
	outline-offset: 2px;
}

/* Reference generated (Multibanco et al. — payment still pending) */
.fec-donation__step--reference {
	padding: 24px 0;
}

.fec-donation__step--reference:focus-visible {
	outline: none;
}

.fec-donation__step--reference .fec-donation__title {
	font-size: var(--wp--preset--font-size--large, 1.1rem);
	color: var(--fec-red);
	margin: 0 0 8px;
}

.fec-donation__step--reference p {
	color: var(--fec-body);
	margin: 0 0 16px;
}

.fec-donation__reference-details {
	background: var(--fec-base);
	border: 1px solid var(--fec-border);
	border-radius: var(--fec-radius);
	padding: 16px;
	margin: 0 0 16px;
}

.fec-donation__reference-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 16px;
	padding: 8px 0;
	border-bottom: 1px solid var(--fec-border);
}

/*
 * The browser's own UA stylesheet rule ([hidden] { display: none }) loses
 * to the class rule above at equal specificity — author styles always beat
 * UA styles at a tie, regardless of source order. Confirmed as a real bug
 * 2026-08-09 (docs/10-launch-checklist.md §C6): the expiry row rendered as
 * an empty flex row instead of actually hiding when JS set its `hidden`
 * attribute (multibanco.expiration_time was null on the real payment, so
 * there was genuinely nothing to show). This is the only element in this
 * form where a `hidden`-toggled element also carries its own explicit
 * `display` — audited every other one (custom-amount, all field-errors,
 * the main error box, all three step containers) and none of them set
 * `display` on the toggled element itself.
 */
.fec-donation__reference-row[hidden] {
	display: none;
}

.fec-donation__reference-row:last-child {
	border-bottom: none;
}

.fec-donation__reference-row dt {
	color: var(--fec-muted);
	font-size: var(--wp--preset--font-size--small, 0.9rem);
}

.fec-donation__reference-row dd {
	margin: 0;
	color: var(--fec-heading);
	font-weight: 700;
	text-align: right;
}

/*
 * EasyPay checkout iframe (step 2) — styled via --fec-ep-* variables, read
 * by the JS and passed to the SDK at runtime as init options.
 */
.fec-donation {
	--fec-ep-button-bg: var(--fec-red);
	--fec-ep-button-text: var(--fec-base);
	--fec-ep-button-shadow: false;
	--fec-ep-input-bg: var(--fec-base);
	--fec-ep-input-border: var(--fec-border);
	--fec-ep-float-label: false;
	--fec-ep-link-color: var(--fec-red);
	--fec-ep-stepper-color: var(--fec-base);
	--fec-ep-font-size: 12;
	--fec-ep-bg: var(--fec-surface-form);
}

/* Keep the EasyPay iframe centred and width-capped inside the card. */
.fec-donation__step--checkout #easypay-checkout {
	display: flex;
	justify-content: center;
}

.fec-donation__step--checkout #easypay-checkout iframe {
	width: 100%;
	max-width: clamp(20rem, 100%, 30rem);
	margin: 0 auto;
}

/* Responsive — amount grid 3→2 cols, field pairs stack, ≤600px */
@media (max-width: 600px) {
	.fec-donation {
		padding: 24px;
	}

	.fec-donation__amounts {
		grid-template-columns: repeat(2, 1fr);
	}

	.fec-donation__grid {
		grid-template-columns: 1fr;
	}

	.fec-donation__field--full {
		grid-column: 1;
	}

	.fec-donation__submit {
		width: 100%;
	}
}
