/**
 * PicForms — Frontend form styles.
 * BEM methodology with .pf- prefix.
 * Themeable via CSS custom properties (--pf-*).
 * Designed to not conflict with common WordPress themes.
 */

/* ─── Form wrapper ─── */
.pf-form-wrapper {
	max-width: 100%;
	background: var(--pf-bg, transparent);
	color: var(--pf-text, inherit);
	padding: var(--pf-form-padding, 0);
	border-radius: var(--pf-form-radius, 0);
}

.pf-form {
	display: flex;
	flex-direction: column;
	gap: var(--pf-row-gap, 1.25rem);
}

/* ─── Row / Column grid ─── */
.pf-form__row {
	display: flex;
	flex-wrap: wrap;
	gap: var(--pf-row-gap, 1rem);
}

.pf-form__col { flex: 1 1 100%; min-width: 0; }
.pf-form__col--12 { flex: 0 0 100%; }
.pf-form__col--6  { flex: 0 0 calc(50% - 0.5rem); }
.pf-form__col--4  { flex: 0 0 calc(33.333% - 0.667rem); }
.pf-form__col--3  { flex: 0 0 calc(25% - 0.75rem); }

@media (max-width: 600px) {
	.pf-form__col--6,
	.pf-form__col--4,
	.pf-form__col--3 {
		flex: 0 0 100%;
	}
}

/* ─── Fields ─── */
.pf-form__field {
	display: flex;
	flex-direction: column;
	gap: var(--pf-field-gap, 0.375rem);
}

.pf-form__label {
	display: var(--pf-label-display, block);
	font-weight: var(--pf-label-weight, 600);
	font-size: var(--pf-label-size, 0.875rem);
	line-height: 1.4;
	color: var(--pf-label-color, inherit);
	margin: var(--pf-label-margin, 0);
}

.pf-form__required {
	color: var(--pf-required-color, #dc2626);
	margin-left: 0.125rem;
}

.pf-form__input {
	display: block;
	width: 100%;
	padding: var(--pf-input-padding, 0.625rem 0.75rem);
	font-size: var(--pf-input-font-size, 1rem);
	line-height: var(--pf-input-line-height, 1.5);
	color: var(--pf-input-color, #1f2937);
	background-color: var(--pf-input-bg, #fff);
	border: 1px solid var(--pf-input-border, #d1d5db);
	border-radius: var(--pf-input-radius, 0.375rem);
	transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
	box-sizing: border-box;
	font-family: inherit;
}

.pf-form__input::placeholder {
	color: var(--pf-input-placeholder, #6b7280);
}

.pf-form__input:focus {
	outline: none;
	border-color: var(--pf-input-focus-border, #2563eb);
	box-shadow: var(--pf-input-focus-shadow, 0 0 0 3px rgba(37, 99, 235, 0.15));
}

.pf-form__input--textarea {
	resize: vertical;
	min-height: var(--pf-textarea-min-height, 7.5rem);
	border-radius: var(--pf-textarea-radius, var(--pf-input-radius, 0.375rem));
	padding: var(--pf-textarea-padding, var(--pf-input-padding, 0.625rem 0.75rem));
}

.pf-form__input--select {
	appearance: none;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 0.75rem center;
	padding-right: 2.5rem;
}

/* ─── Radio / Checkbox options ─── */
.pf-form__field--radio fieldset,
.pf-form__field--checkboxes fieldset {
	border: 0;
	margin: 0;
	padding: 0;
}

.pf-form__field--radio legend,
.pf-form__field--checkboxes legend {
	font-weight: 600;
	font-size: 0.875rem;
	margin-bottom: 0.375rem;
}

.pf-form__options {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.pf-form__option {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	cursor: pointer;
	font-weight: normal;
}

.pf-form__radio,
.pf-form__checkbox {
	width: 1rem;
	height: 1rem;
	margin: 0;
	cursor: pointer;
}

.pf-form__option-label {
	font-size: 0.9375rem;
	line-height: 1.4;
}

/* ─── Error states ─── */
.pf-form__field--error .pf-form__input {
	border-color: #dc2626;
}

.pf-form__field--error .pf-form__input:focus {
	box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.pf-form__error-message {
	font-size: 0.8125rem;
	color: #dc2626;
	min-height: 0;
}

.pf-form__error-message:empty {
	display: none;
}

/* Error summary */
.pf-form__errors {
	background: #fef2f2;
	border: 1px solid #fecaca;
	border-radius: var(--pf-input-radius, 0.375rem);
	padding: 0.75rem 1rem;
	color: var(--pf-error-color, #991b1b);
	font-size: 0.875rem;
}

.pf-form__error-message {
	color: var(--pf-error-color, #dc2626);
}

/* ─── Submit button ─── */
.pf-form__submit-wrap {
	padding-top: 0.25rem;
	display: flex;
	justify-content: var(--pf-submit-align, flex-start);
}

.pf-form__submit {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: var(--pf-submit-padding, 0.75rem 1.5rem);
	font-size: var(--pf-submit-size, var(--pf-submit-font-size, 1rem));
	font-weight: var(--pf-submit-weight, var(--pf-submit-font-weight, 600));
	line-height: var(--pf-submit-line-height, 1);
	color: var(--pf-submit-color, #fff);
	background-color: var(--pf-submit-bg, #2563eb);
	border: solid 1px !important;
	border-radius: var(--pf-submit-radius, 0.375rem);
	cursor: pointer;
	transition: background-color 0.15s ease-in-out;
	font-family: inherit;
	text-transform: var(--pf-submit-text-transform, none);
	letter-spacing: var(--pf-submit-letter-spacing, normal);
}

.pf-form__submit:hover {
	color: var(--pf-submit-hover-color, #1d4ed8);
	background-color: var(--pf-submit-hover-bg, #1d4ed8);
	border: solid 1px !important;
	border-color: var(--pf-submit-hover-br, #1d4ed8);
}

.pf-form__submit:focus-visible {
	outline: 1px solid #2563eb;
}

.pf-form__submit:disabled,
.pf-form__submit--loading {
	opacity: 0.7;
	cursor: not-allowed;
}

.pf-form__submit-spinner {
	display: inline-flex;
	align-items: center;
}

/* ─── Honeypot (hidden from humans) ─── */
.pf-form__hp {
	display: none !important;
}

/* ─── Confirmation ─── */
.pf-form__confirmation {
	padding: 1.5rem;
	background: var(--pf-confirm-bg, #f0fdf4);
	border: 1px solid var(--pf-confirm-border, #bbf7d0);
	border-radius: var(--pf-input-radius, 0.375rem);
	color: var(--pf-confirm-color, #166534);
	font-size: 1rem;
	line-height: 1.5;
}

/* ─── Turnstile ─── */
.pf-form__turnstile {
	margin-top: 0.25rem;
}

/* ─── Phase 2: Advanced Field Styles ─── */

/* File Upload */
.pf-form__file-drop {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 2rem 1rem;
	border: 2px dashed #d1d5db;
	border-radius: 0.5rem;
	cursor: pointer;
	transition: border-color 0.15s, background-color 0.15s;
}

.pf-form__file-drop:hover,
.pf-form__file-drop--dragover {
	border-color: #2563eb;
	background-color: #eff6ff;
}

.pf-form__file-input { display: none; }

.pf-form__file-list {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	margin-top: 0.5rem;
	font-size: 0.875rem;
}

.pf-form__file-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.375rem 0.5rem;
	background: #f9fafb;
	border: 1px solid #e5e7eb;
	border-radius: 0.25rem;
}

.pf-form__file-remove {
	background: none;
	border: none;
	color: #dc2626;
	cursor: pointer;
	font-size: 1rem;
	padding: 0;
}

/* Address */
.pf-form__address-grid {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
}

.pf-form__address-row--full { flex: 0 0 100%; }
.pf-form__address-row--half { flex: 0 0 calc(50% - 0.375rem); }

@media (max-width: 600px) {
	.pf-form__address-row--half { flex: 0 0 100%; }
}

.pf-form__label--sub {
	font-weight: 400;
	font-size: 0.75rem;
	color: #6b7280;
	margin-bottom: 0.125rem;
}

/* Name */
.pf-form__name-group {
	display: flex;
	gap: 0.75rem;
}

.pf-form__name-segment { flex: 1; }
.pf-form__name-segment--prefix { flex: 0 0 5rem; }

.pf-form__sublabel {
	display: block;
	font-size: 0.75rem;
	color: #6b7280;
	margin-top: 0.125rem;
}

@media (max-width: 600px) {
	.pf-form__name-group { flex-direction: column; }
	.pf-form__name-segment--prefix { flex: 0 0 auto; }
}

/* Currency */
.pf-form__currency-wrapper {
	display: flex;
	align-items: stretch;
}

.pf-form__currency-symbol {
	display: flex;
	align-items: center;
	padding: 0 0.75rem;
	background: #f3f4f6;
	border: 1px solid #d1d5db;
	border-right: 0;
	border-radius: 0.375rem 0 0 0.375rem;
	font-weight: 600;
	color: #6b7280;
	font-size: 0.875rem;
}

.pf-form__input--currency {
	border-radius: 0 0.375rem 0.375rem 0;
}

/* Rating */
.pf-form__rating {
	display: flex;
	gap: 0.25rem;
	font-size: 1.5rem;
}

/* Visually hidden but focusable — display:none would remove the radios
   from the tab order and make the rating mouse-only. */
.pf-form__rating-input {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
}

.pf-form__rating-label {
	cursor: pointer;
	color: #d1d5db;
	transition: color 0.1s;
}

.pf-form__rating-input:focus-visible + .pf-form__rating-label {
	outline: 2px solid #2563eb;
	outline-offset: 2px;
	border-radius: 2px;
}

.pf-form__rating-input:checked ~ .pf-form__rating-label { color: #d1d5db; }
.pf-form__rating-label:hover,
.pf-form__rating-label:hover ~ .pf-form__rating-label { color: #fbbf24; }

/* Reverse order trick for CSS-only star highlighting */
.pf-form__rating {
	direction: rtl;
}

.pf-form__rating-input:checked + .pf-form__rating-label,
.pf-form__rating-input:checked + .pf-form__rating-label ~ .pf-form__rating-label {
	color: #fbbf24;
}

.pf-form__rating-label {
	direction: ltr;
}

/* ─── Phase 3: Multi-step Forms ─── */

/* Steps */
.pf-form__step {
	display: none;
}

.pf-form__step--active {
	display: block;
}

.pf-form__step > .pf-form__row,
.pf-form__step > .pf-form__col {
	margin-bottom: 1.25rem;
}

/* Progress bar */
.pf-form__progress {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 1.5rem;
}

.pf-form__progress-track {
	flex: 1;
	height: 0.375rem;
	background: #e5e7eb;
	border-radius: 9999px;
	overflow: hidden;
}

.pf-form__progress-bar {
	height: 100%;
	background: #2563eb;
	border-radius: 9999px;
	transition: width 0.3s ease-in-out;
}

.pf-form__progress-text {
	flex-shrink: 0;
	font-size: 0.8125rem;
	font-weight: 600;
	color: #6b7280;
	white-space: nowrap;
}

/* Step navigation buttons */
.pf-form__step-nav {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	padding-top: 1rem;
	margin-top: 0.5rem;
}

.pf-form__step-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	padding: 0.625rem 1.25rem;
	font-size: 0.9375rem;
	font-weight: 600;
	line-height: 1;
	border: none;
	border-radius: 0.375rem;
	cursor: pointer;
	transition: background-color 0.15s ease-in-out;
	font-family: inherit;
}

.pf-form__step-btn--prev {
	color: #374151;
	background-color: #e5e7eb;
}

.pf-form__step-btn--prev:hover {
	background-color: #d1d5db;
}

.pf-form__step-btn--next {
	color: #fff;
	background-color: #2563eb;
	margin-left: auto;
}

.pf-form__step-btn--next:hover {
	background-color: #1d4ed8;
}

.pf-form__step-btn:focus-visible {
	outline: 2px solid #2563eb;
	outline-offset: 2px;
}

/* Page break marker (hidden in rendered form) */
.pf-form__page-break {
	display: none;
}

/* ─── Section Break ─── */
.pf-form__section-break {
	padding: 0.25rem 0 0.5rem;
	border-bottom: 2px solid #e5e7eb;
	margin-bottom: 0.25rem;
}

.pf-form__section-title {
	font-size: 1.125rem;
	font-weight: 700;
	color: #1f2937;
	margin: 0 0 0.25rem;
	line-height: 1.4;
}

.pf-form__section-desc {
	font-size: 0.875rem;
	color: #6b7280;
	margin: 0;
	line-height: 1.5;
}

/* ─── HTML Block ─── */
.pf-form__html-block {
	font-size: 0.9375rem;
	line-height: 1.6;
	color: #374151;
}

.pf-form__html-block p:last-child {
	margin-bottom: 0;
}

.pf-form__html-block a {
	/* blue-700 — blue-600 is 4.0:1 on the warm form panels, under AA. */
	color: #1d4ed8;
	text-decoration: underline;
}

/* ─── Tooltips ─── */
.pf-form__tooltip {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 16px;
	height: 16px;
	margin-left: 4px;
	font-size: 11px;
	font-weight: 600;
	line-height: 1;
	color: #fff;
	background: #6b7280;
	border-radius: 50%;
	cursor: help;
	position: relative;
	vertical-align: middle;
	user-select: none;
}

.pf-form__tooltip:hover,
.pf-form__tooltip:focus {
	background: #2563eb;
	outline: none;
}

/* The trigger is a <button>; strip the UA chrome the span never had. */
button.pf-form__tooltip {
	border: 0;
	padding: 0;
	font-family: inherit;
}

.pf-form__tooltip:focus-visible {
	outline: 2px solid #2563eb;
	outline-offset: 2px;
}

.pf-form__tooltip::after {
	content: attr(data-tip);
	position: absolute;
	bottom: calc(100% + 6px);
	left: 50%;
	transform: translateX(-50%);
	padding: 6px 10px;
	background: #1f2937;
	color: #fff;
	font-size: 12px;
	font-weight: 400;
	line-height: 1.4;
	border-radius: 4px;
	white-space: normal;
	width: max-content;
	max-width: 240px;
	text-align: left;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s ease;
	z-index: 100;
}

.pf-form__tooltip::before {
	content: '';
	position: absolute;
	bottom: calc(100% + 1px);
	left: 50%;
	transform: translateX(-50%);
	border: 5px solid transparent;
	border-top-color: #1f2937;
	pointer-events: none;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.15s ease;
	z-index: 100;
}

.pf-form__tooltip:hover::after,
.pf-form__tooltip:hover::before,
.pf-form__tooltip:focus::after,
.pf-form__tooltip:focus::before {
	opacity: 1;
	visibility: visible;
}

/* Escape pressed (WCAG 1.4.13 dismissal) — suppress until blur/mouseleave. */
.pf-form__tooltip.is-dismissed::after,
.pf-form__tooltip.is-dismissed::before {
	opacity: 0;
	visibility: hidden;
}

/* Screen-reader-only text. Templates use this instead of WooCommerce's
   .screen-reader-text so PicForms carries no dependency on WC styles. */
.pf-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	border: 0;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	clip-path: inset(50%);
	white-space: nowrap;
}
