/* @import("/static/css/variables.css"); */

.wizard__back {
	display: inline-block;
	margin-bottom: 1.5rem;
	font-weight: 600;
	color: var(--color-dark-muted);
}

/* ---------------------------------------- */
/* PHASE TOGGLING                           */
/* ---------------------------------------- */

/*
 * Both phases stay in the DOM — see enrollment.js — so visibility is driven by the
 * wrapper's `data-phase`.
 */
.wizard__phase {
	display: none;
}

.wizard[data-phase="1"] .wizard__phase[data-phase="1"],
.wizard[data-phase="2"] .wizard__phase[data-phase="2"] {
	display: block;
}

/* ---------------------------------------- */
/* PROGRESS                                 */
/* ---------------------------------------- */

.wizard__steps {
	display: flex;
	gap: 0.5rem;
	list-style: none;
	margin-bottom: 2rem;
}

.wizard__stepper {
	flex: 1;
	padding-top: 0.6rem;
	border-top: 4px solid var(--color-grey-pastel);
	font-size: 0.8rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--color-dark-muted);
}

.wizard[data-phase="1"] .wizard__stepper[data-step="1"],
.wizard[data-phase="2"] .wizard__stepper[data-step="1"],
.wizard[data-phase="2"] .wizard__stepper[data-step="2"],
.wizard[data-phase="3"] .wizard__stepper {
	border-top-color: var(--color-green-accent);
	color: var(--color-green-dark);
}

.wizard__step-count {
	font-size: 0.85rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--color-green-dark);
	margin-bottom: 0.35rem;
}

.wizard__lead {
	font-size: 1.05rem;
	color: var(--color-dark-muted);
	line-height: 1.6;
	margin: 0.75rem 0 1.75rem;
}

/* ---------------------------------------- */
/* CERTIFICATE PICKER                       */
/* ---------------------------------------- */

.wizard__filepick {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	height: 13rem;
	padding: 1.5rem;
	border: 3px dashed var(--color-green-dark);
	border-radius: 14px;
	background-color: var(--color-green-pastel);
	cursor: pointer;
	text-align: center;
	box-sizing: border-box;
}

.wizard__filepick[hidden] {
	display: none;
}

.wizard__filepick:hover,
.wizard__filepick:focus-within {
	background-color: var(--color-green);
}

/* Hidden but still focusable, so keyboard and screen readers keep working. */
.wizard__filepick input[type="file"] {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	pointer-events: none;
}

.wizard__filepick-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 3rem;
	height: 3rem;
	border-radius: var(--radius-full);
	background-color: var(--color-green-accent);
	color: var(--color-light);
	font-size: 1.8rem;
	font-weight: 800;
	line-height: 1;
}

.wizard__filepick-text {
	font-size: 1.05rem;
	font-weight: 700;
	color: var(--color-green-dark);
}

.wizard__chosen {
	min-height: 1.5rem;
	margin: 1rem 0 1.5rem;
	font-weight: 600;
	color: var(--color-green-hover);
	text-align: center;
	word-break: break-word;
}

/* ---------------------------------------- */
/* EMERGENCY CONTACTS                       */
/* ---------------------------------------- */

.contact-row {
	display: flex;
	align-items: flex-end;
	gap: 1rem;
	padding-bottom: 1.25rem;
	margin-bottom: 1.25rem;
	border-bottom: 1px solid var(--color-grey-pastel);
}

.contact-row__fields {
	flex: 1;
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 1rem;
	/* As `.membership-form__row`: one field carrying a message must not leave the row. */
	align-items: end;
}

.contact-row__remove {
	flex: 0 0 auto;
	padding: 0.6rem 1rem;
	border: 2px solid var(--color-grey-pastel);
	border-radius: var(--radius-full);
	background: none;
	color: var(--color-dark-muted);
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 700;
	cursor: pointer;
}

.contact-row__remove:hover {
	border-color: var(--color-orange);
	color: var(--color-orange);
}

/* ---------------------------------------- */
/* ACTIONS                                  */
/* ---------------------------------------- */

.wizard__next,
.wizard__actions .btn[type="submit"] {
	font-size: 1.1rem;
}

.wizard__actions {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	margin-top: 2rem;
}

.wizard__back-step {
	align-self: flex-start;
	padding: 0;
	border: none;
	background: none;
	color: var(--color-dark-muted);
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	cursor: pointer;
	text-decoration: underline;
}

.wizard__hint {
	font-size: 0.9rem;
	color: var(--color-dark-muted);
	text-align: center;
}

.wizard__loading {
	justify-content: center;
	padding: 0.75rem;
	border-radius: 8px;
	background-color: var(--color-green-pastel);
	color: var(--color-green-hover);
	font-weight: 600;
	text-align: center;
}

#wizard-feedback:not(:empty) {
	margin-top: 1.5rem;
}

/* ---------------------------------------- */
/* FINAL STEP                               */
/* ---------------------------------------- */

.wizard__done {
	padding: 2rem 0;
	text-align: center;
}

.wizard__done .wizard__lead {
	margin-inline: auto;
	max-width: 32rem;
}

.wizard__whatsapp {
	margin-top: 0.5rem;
	font-size: 1.15rem;
}

.wizard__notice {
	padding: 1rem 1.25rem;
	border-radius: 8px;
	font-weight: 600;
}

.wizard__notice--warn {
	background-color: var(--color-orange-pastel);
	color: var(--color-orange-hover);
}

.wizard__back-home {
	display: inline-block;
	margin-top: 1.5rem;
	color: var(--color-dark-muted);
	font-weight: 600;
	text-decoration: underline;
}

/* ---------------------------------------- */
/* CERTIFICATE PICKER — EXTRAS              */
/* ---------------------------------------- */

.wizard__filepick-hint {
	font-size: 0.83rem;
	font-weight: 400;
	color: var(--color-dark-muted);
}

.wizard__filepick--dragover {
	border-color: var(--color-green-hover);
	background-color: var(--color-green);
	transform: scale(1.01);
}

/* ---------------------------------------- */
/* CERTIFICATE PREVIEW                      */
/* ---------------------------------------- */

.wizard__preview[hidden] {
	display: none;
}

.wizard__preview {
	position: relative;
	height: 13rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 2px solid var(--color-green-accent);
	border-radius: 14px;
	overflow: hidden;
	background-color: var(--color-green-pastel);
	box-sizing: border-box;
}

.wizard__preview-remove {
	position: absolute;
	top: 0.6rem;
	right: 0.6rem;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	border: none;
	border-radius: var(--radius-full);
	background-color: rgba(0, 0, 0, 0.55);
	color: var(--color-light);
	font-size: 1.3rem;
	line-height: 1;
	cursor: pointer;
}

.wizard__preview-remove:hover {
	background-color: var(--color-orange);
}

.wizard__preview-content {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	padding: 0.75rem;
	box-sizing: border-box;
}

.wizard__preview-img {
	display: block;
	/* constrain to the content area; natural aspect ratio is preserved because only
	   the max values are set — the browser picks whichever axis hits its limit first */
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	border-radius: 6px;
}

.wizard__preview-pdf {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 6rem;
	height: 7rem;
	border-radius: 8px;
	background-color: var(--color-orange);
	color: var(--color-light);
	font-size: 1.3rem;
	font-weight: 900;
	letter-spacing: 0.05em;
}

.wizard__preview-name {
	margin: 0.5rem 0 0;
	font-size: 0.875rem;
	font-weight: 600;
	color: var(--color-dark-muted);
	word-break: break-all;
	text-align: center;
}

.wizard__error {
	margin: 0.5rem 0 0;
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--color-orange);
	text-align: center;
}

/* ---------------------------------------- */
/* PAGE HEADER                              */
/* ---------------------------------------- */

.membership-form__header {
	margin-top: 1.5rem;
	margin-bottom: 2rem;
}

.membership-form__intro {
	color: var(--color-dark-muted);
	margin-top: 0.5rem;
}

/* ---------------------------------------- */
/* FIELDSETS                                */
/* ---------------------------------------- */

.membership-form__fieldset {
	border: 1px solid var(--color-grey-pastel);
	border-radius: 8px;
	padding: 1.5rem;
	margin-bottom: 2rem;
}

.membership-form__legend {
	font-weight: 700;
	padding: 0 0.5rem;
}

/* ---------------------------------------- */
/* FIELD GRID                               */
/* ---------------------------------------- */

.membership-form__row {
	display: grid;
	gap: 1rem;
	margin-top: 1rem;
	/*
	 * A message above one field makes that field taller than the others sharing its row.
	 * Ending the row rather than stretching it keeps the row a row: the untouched fields drop
	 * to the bottom of the track, so every input in it stays on the same line as the one being
	 * complained about, instead of that one alone sliding down.
	 */
	align-items: end;
}

/* The first row sits directly under the legend, which already provides spacing. */
.membership-form__row:first-of-type {
	margin-top: 0;
}

.membership-form__row--halves {
	grid-template-columns: 1fr 1fr;
}

.membership-form__row--wide-narrow-wide {
	grid-template-columns: 2fr 1fr 2fr;
}

.membership-form__row--wide-wide-narrow {
	grid-template-columns: 2fr 2fr 1fr;
}

.membership-form__field {
	display: flex;
	flex-direction: column;
	/*
	 * A grid item is `min-width: auto` by default, which is "never narrower than my contents"
	 * — that is what lets one wide control push its column, and the row, past the edge of the
	 * form. Every field here is happy to be as narrow as its track.
	 */
	min-width: 0;
}

.membership-form__label {
	font-size: 0.85rem;
	margin-bottom: 0.35rem;
}

.membership-form__input {
	width: 100%;
	padding: 0.6rem 0.8rem;
	border: 1px solid var(--color-grey-pastel);
	border-radius: 6px;
	background-color: var(--color-light);
	color: var(--color-dark);
	font-family: var(--font-base), sans-serif;
	font-size: 0.95rem;
}

.membership-form__input:focus-visible {
	outline: 2px solid var(--color-green-accent);
	outline-offset: 1px;
	border-color: var(--color-green-accent);
}

.membership-form__input--upper {
	text-transform: uppercase;
}

/* ---------------------------------------- */
/* DATE FIELD                               */
/* ---------------------------------------- */

/*
 * One box, two controls. `.date-field__typed` is the field — the name, the rule, the value, and
 * the eight digits typed into it. `.date-field__native` is a `type="date"` lying invisible over
 * the calendar icon at its right, and all it does is open the platform picker for whoever would
 * rather choose than type.
 *
 * The obvious arrangement — one `type="date"` and nothing else — was tried and cannot work: on
 * a phone that control refuses the keyboard outright, iOS offering a spinner and Android a
 * calendar, so somebody who knows their own birthday still has to travel back forty years to
 * reach it. Typing has to be the way in, and the picker the shortcut.
 */
.date-field {
	--icon-calendar: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2'/%3E%3Cpath d='M8 3v4M16 3v4M3 10h18'/%3E%3C/svg%3E");
	position: relative;
	display: flex;
	/* A grid item is "never narrower than my contents" by default, and this one sits in the
	   three-column row that used to be pushed past the edge of the form on iOS. */
	min-width: 0;
}

.date-field__typed {
	/* Room for the icon, so a typed date never runs underneath it. */
	padding-right: 2.7rem;
	/* Below 16px iOS zooms the page when the control takes focus, and does not zoom back. */
	font-size: 1rem;
	/* Digits of one width, so the grey remainder below does not shift as they are typed. */
	font-variant-numeric: tabular-nums;
}

/*
 * The grey `gg/mm/aaaa` the date is typed over. The eight digits are typed without separators,
 * so the two slashes have to be on screen before they are reached: until they are, `1012` is a
 * number, and where the mask is about to cut it is a guess.
 *
 * The part already typed is repeated here in transparent ink rather than measured, so the grey
 * remainder begins exactly where the real text ends whatever its glyphs happen to be worth. Over
 * the input rather than under it, so the field keeps its own background — white, or the orange of
 * one that has been refused.
 */
.date-field__ghost {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	/* The input's own padding and border, so both texts start on the same column. */
	padding: 0.6rem 2.7rem 0.6rem 0.8rem;
	border: 1px solid transparent;
	overflow: hidden;
	font-family: var(--font-base), sans-serif;
	font-size: 1rem;
	font-variant-numeric: tabular-nums;
	color: var(--color-dark-muted);
	opacity: 0.55;
	/* The input underneath is what takes the click and shows the caret. */
	pointer-events: none;
}

.date-field__ghost-typed {
	color: transparent;
}

/*
 * Drawn as a mask rather than a coloured SVG, so the glyph takes the text colour instead of
 * repeating a palette value that would then have to be kept in step with it.
 */
.date-field__icon {
	position: absolute;
	top: 50%;
	right: 0.75rem;
	width: 1.15rem;
	height: 1.15rem;
	transform: translateY(-50%);
	background-color: currentColor;
	opacity: 0.45;
	-webkit-mask: var(--icon-calendar) center / contain no-repeat;
	mask: var(--icon-calendar) center / contain no-repeat;
	/* The input over it is what takes the tap. */
	pointer-events: none;
}

/*
 * Invisible, but rendered and sized to the icon it covers: `display: none` would take the tap
 * target away with it, and a picker cannot be opened from a control the browser is not drawing.
 */
.date-field__native {
	position: absolute;
	top: 0;
	right: 0;
	/*
	 * WebKit sizes this control from its own contents and ignores `width` until the native
	 * appearance is gone. That is not cosmetic here: at full width the box would reach back
	 * across the field it sits on and, being invisible, swallow the taps meant for typing.
	 */
	appearance: none;
	-webkit-appearance: none;
	width: 2.7rem;
	min-width: 0;
	height: 100%;
	padding: 0;
	border: 0;
	background: transparent;
	opacity: 0;
	cursor: pointer;
}

/* One rejected field, said above the field itself — created by enrollment.js on blur and on a
   refused submission, hidden again as soon as the field is edited. It sits before the label
   rather than after the input so a two-line message pushes the field down instead of pushing
   whatever follows it, and so the reader meets the problem before the box to fix. */
.membership-form__error {
	margin: 0 0 0.35rem;
	font-size: 0.8rem;
	font-weight: 600;
	line-height: 1.3;
	color: var(--color-orange-hover);
}

.membership-form__error[hidden] {
	display: none;
}

/* Set alongside the message above, and removed with it. */
.membership-form__input[aria-invalid="true"] {
	border-color: var(--color-orange);
	background-color: var(--color-orange-pastel);
}

/* ---------------------------------------- */
/* CHECKBOXES                               */
/* ---------------------------------------- */

.membership-form__check {
	display: flex;
	gap: 0.5rem;
	cursor: pointer;
}

.membership-form__check--inline {
	align-items: center;
}

.membership-form__check + .membership-form__check {
	margin-top: 1rem;
}

/* The checkbox that reveals a conditional section. */
.membership-form__check--toggle {
	margin-bottom: 1rem;
}

/* ---------------------------------------- */
/* CONDITIONAL SECTIONS                     */
/* Toggled by :has() on the checkbox state, */
/* so no JS is needed to show or hide them. */
/* ---------------------------------------- */

.section-minor,
.section-autonomy {
	display: none;
}

.wrapper-minor:has(#is_minor:checked) .section-minor {
	display: block;
}

.wrapper-autonomy:has(#commute_alone:checked) .section-autonomy {
	display: block;
}

.wrapper-autonomy {
	border-top: 1px solid var(--color-grey-pastel);
	margin-top: 1.5rem;
	padding-top: 1.5rem;
}

.membership-form__disclaimer {
	color: var(--color-dark-muted);
	margin-bottom: 1rem;
}

/* ---------------------------------------- */
/* SIGNATURE PAD                            */
/* ---------------------------------------- */

.signature-box {
	border: 1px solid var(--color-grey-pastel);
	border-radius: 4px;
	background: var(--color-grey-pastel-light);
	touch-action: none;
}

canvas.signature-canvas {
	width: 100%;
	height: 140px;
	display: block;
	cursor: crosshair;
}

.membership-form__signature-actions {
	margin-top: 0.5rem;
	text-align: right;
}

.btn--clear-signature {
	background: var(--color-grey-pastel);
	color: var(--color-dark);
}

/* ---------------------------------------- */
/* MEMBERSHIP FORM ACTIONS                  */
/* ---------------------------------------- */

.membership-form__actions {
	text-align: center;
	margin-top: 2rem;
}

.membership-form__submit {
	padding: 0.9rem 2.2rem;
	font-size: 1.05rem;
}

/* ---------------------------------------- */
/* HTMX REQUEST STATES                      */
/* ---------------------------------------- */

/* ---------------------------------------- */
/* LOADING DOTS (shown inside submit button) */
/* ---------------------------------------- */

@keyframes dot-pulse {
	0%, 100% {
		opacity: 0.15;
	}
	50% {
		opacity: 1;
	}
}

.loading-dots {
	display: inline-flex;
	gap: 2px;
	vertical-align: middle;
	margin-left: 3px;
}

.loading-dots span {
	display: inline-block;
	animation: dot-pulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(1) {
	animation-delay: 0s;
}

.loading-dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
	animation-delay: 0.4s;
}

.htmx-indicator {
	display: none;
}

.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
}

/*
 * Set together with `inert` by enrollment.js while the submission is out. `inert` already
 * blocks every click; `pointer-events` repeats it for anything that might ignore the
 * attribute, and the dim tells the applicant the page is frozen.
 *
 * The dim skips `.wizard__actions`: opacity on an ancestor cannot be undone by a descendant,
 * and the button has to keep "Invio in corso" readable.
 */
.main-wrapper--sending {
	pointer-events: none;
}

.main-wrapper--sending .wizard__back,
.main-wrapper--sending .wizard__steps,
.main-wrapper--sending .wizard__phase > :not(.wizard__actions) {
	opacity: 0.45;
}

/* The submit button hides its idle label while its own indicator is showing. */
.htmx-request .wizard__submit-label {
	display: none;
}

button:disabled,
input:disabled {
	cursor: not-allowed;
	opacity: 0.6;
}

.membership-form__loading {
	margin-top: 1rem;
	color: var(--color-green-accent);
	font-weight: 500;
}

/* ---------------------------------------- */
/* FEEDBACK FRAGMENTS (#wizard-feedback)    */
/* Swapped in by HTMX after submitting.     */
/* ---------------------------------------- */

/* Only failures that are ours land here. A refused submission answers with an empty body and
   says what is wrong above each field instead — see `.membership-form__error`. */
#wizard-feedback {
	margin-top: 1.5rem;
	text-align: center;
}

.form-feedback {
	padding: 1rem 1.25rem;
	border-radius: 8px;
	border: 1px solid transparent;
}

.form-feedback__text {
	margin-top: 0.35rem;
	font-size: 0.9rem;
}

.form-feedback--success {
	background-color: var(--color-green-pastel);
	border-color: var(--color-green-accent);
	color: var(--color-green-hover);
}

.form-feedback--error {
	background-color: var(--color-orange-pastel);
	border-color: var(--color-orange);
	color: var(--color-orange-hover);
}

/* ---------------------------------------- */
/* PHASE 2 ZONES                            */
/* ---------------------------------------- */

.wizard__zone {
	border-top: 3px solid var(--color-green-accent);
	padding-top: 1.25rem;
	margin-bottom: 2.5rem;
}

.wizard__zone-title {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin: 0 0 1.25rem;
	font-size: 1rem;
	font-weight: 700;
	color: var(--color-dark);
}

.wizard__zone-num {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 1.6rem;
	height: 1.6rem;
	border-radius: var(--radius-full);
	background-color: var(--color-green-accent);
	color: var(--color-light);
	font-size: 0.8rem;
	font-weight: 800;
}

.wizard__zone-optional {
	font-size: 0.875rem;
	font-weight: 400;
	color: var(--color-dark-muted);
}

/* ---------------------------------------- */
/* CONSENT CHECKBOXES                       */
/* ---------------------------------------- */

.wizard__consents {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	margin-bottom: 1.5rem;
	padding: 1.25rem;
	border: 1px solid var(--color-grey-pastel);
	border-radius: 8px;
	background-color: var(--color-grey-pastel-light);
}

.wizard__consent-check {
	display: flex;
	align-items: flex-start;
	gap: 0.6rem;
}

.wizard__consent-check input[type="checkbox"] {
	margin-top: 0.2rem;
	flex-shrink: 0;
	width: 1rem;
	height: 1rem;
	cursor: pointer;
	accent-color: var(--color-green-accent);
}

.wizard__consent-check label {
	display: flex;
	align-items: flex-start;
	gap: 0.6rem;
	font-size: 0.9rem;
	line-height: 1.55;
	cursor: pointer;
	color: var(--color-dark-muted);
}

.wizard__consent-check label a {
	color: var(--color-green-accent);
	font-weight: 600;
	text-decoration: underline;

	&:hover {
		color: var(--color-green-dark);
	}
}

/* Disabled submit: grey until both consent checkboxes are checked */
.wizard__actions button[type="submit"]:disabled {
	background-color: var(--color-grey-pastel);
	color: var(--color-dark-muted);
	opacity: 1;
	cursor: not-allowed;
}

/* ---------------------------------------- */
/* RESPONSIVE                               */
/* ---------------------------------------- */

@media (max-width: 640px) {
	.contact-row {
		flex-direction: column;
		align-items: stretch;
	}

	.contact-row__fields {
		grid-template-columns: 1fr;
	}

	.wizard__stepper {
		font-size: 0.7rem;
	}

	.membership-form__row--halves,
	.membership-form__row--wide-narrow-wide,
	.membership-form__row--wide-wide-narrow {
		grid-template-columns: 1fr;
	}

	.membership-form__fieldset {
		padding: 1rem;
	}
}
