/**
 * IPA – Indian Pincode Autofill: Checkout Stylesheet
 *
 * Compatible with WooCommerce Blocks and Classic Checkout.
 *
 * @package IPA_Indian_Pincode_Autofill
 */

/* Postcode Wrapper - Position relative for loading spinner */
.woocommerce-checkout #billing_postcode_field,
.woocommerce-checkout #shipping_postcode_field,
.woocommerce-checkout #billing-postcode_field,
.woocommerce-checkout #shipping-postcode_field,
.woocommerce-page #billing_postcode_field,
.woocommerce-page #shipping_postcode_field,
.wc-block-components-text-input.ipaa-loading,
.wc-block-components-address-form .ipaa-loading,
.form-row.ipaa-loading {
	position: relative;
}

/* Loading State Spinner */
.woocommerce-checkout #billing_postcode_field.ipaa-loading .woocommerce-input-wrapper,
.woocommerce-checkout #shipping_postcode_field.ipaa-loading .woocommerce-input-wrapper,
.woocommerce-page #billing_postcode_field.ipaa-loading .woocommerce-input-wrapper,
.woocommerce-page #shipping_postcode_field.ipaa-loading .woocommerce-input-wrapper,
.wc-block-components-text-input.ipaa-loading,
.form-row.ipaa-loading {
	position: relative;
}

.woocommerce-checkout #billing_postcode_field.ipaa-loading .woocommerce-input-wrapper::after,
.woocommerce-checkout #shipping_postcode_field.ipaa-loading .woocommerce-input-wrapper::after,
.woocommerce-page #billing_postcode_field.ipaa-loading .woocommerce-input-wrapper::after,
.woocommerce-page #shipping_postcode_field.ipaa-loading .woocommerce-input-wrapper::after,
.wc-block-components-text-input.ipaa-loading::after,
.form-row.ipaa-loading::after {
	content: "";
	position: absolute;
	right: 12px;
	top: 50%;
	transform: translateY(-50%);
	width: 16px;
	height: 16px;
	border: 2px solid #e0e0e0;
	border-top-color: #2271b1;
	border-radius: 50%;
	animation: ipaa-spin 0.65s linear infinite;
	pointer-events: none;
	z-index: 5;
}

@keyframes ipaa-spin {
	0% {
		transform: translateY(-50%) rotate(0deg);
	}
	100% {
		transform: translateY(-50%) rotate(360deg);
	}
}

/* Readonly Visual Feedback */
.woocommerce-checkout input.ipaa-readonly,
.woocommerce-page input.ipaa-readonly,
.wc-block-components-text-input input.ipaa-readonly,
.wc-block-checkout input.ipaa-readonly {
	background-color: #f7f7f8 !important;
	color: #4b5563 !important;
	cursor: not-allowed !important;
	border-color: #e5e7eb !important;
	transition: background-color 0.2s ease, border-color 0.2s ease;
}

.woocommerce-checkout select.ipaa-readonly,
.woocommerce-page select.ipaa-readonly,
.wc-block-components-combobox.ipaa-readonly,
.wc-block-components-combobox.ipaa-readonly input,
.wc-block-components-combobox.ipaa-readonly button,
.wc-block-components-combobox input.ipaa-readonly,
.wc-block-checkout select.ipaa-readonly {
	background-color: #f7f7f8 !important;
	color: #4b5563 !important;
	pointer-events: none !important;
	cursor: not-allowed !important;
	border-color: #e5e7eb !important;
}

/* Inline Error Message */
.ipaa-error-message {
	display: block;
	color: #b91c1c;
	background-color: #fef2f2;
	border-left: 3px solid #ef4444;
	padding: 6px 10px;
	margin-top: 6px;
	font-size: 0.84rem;
	line-height: 1.4;
	border-radius: 0 4px 4px 0;
	animation: ipaa-fade-in 0.2s ease-out;
}

@keyframes ipaa-fade-in {
	from {
		opacity: 0;
		transform: translateY(-3px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Strict Field Order Sequence: Zipcode -> City -> District -> State */
.woocommerce-billing-fields__field-wrapper,
.woocommerce-shipping-fields__field-wrapper,
.wc-block-components-address-form {
	display: flex;
	flex-wrap: wrap;
}

#billing_postcode_field,
#shipping_postcode_field,
.wc-block-components-address-form .wc-block-components-address-form__postcode,
.wc-block-components-address-form div:has(> #billing-postcode),
.wc-block-components-address-form div:has(> #shipping-postcode),
.wc-block-components-address-form div:has(> input[autocomplete*="postal-code"]),
.wc-block-components-address-form div:has(> input[autocomplete*="postcode"]) {
	order: 65 !important;
}

#billing_city_field,
#shipping_city_field,
.wc-block-components-address-form .wc-block-components-address-form__city,
.wc-block-components-address-form div:has(> #billing-city),
.wc-block-components-address-form div:has(> #shipping-city),
.wc-block-components-address-form div:has(> input[autocomplete*="address-level2"]) {
	order: 70 !important;
}

#billing_district_field,
#shipping_district_field,
.wc-block-components-address-form div:has(> [id*="district"]),
.wc-block-components-address-form div:has(> [name*="district"]) {
	order: 75 !important;
}

#billing_state_field,
#shipping_state_field,
.wc-block-components-address-form .wc-block-components-address-form__state,
.wc-block-components-address-form div:has(> #billing-state),
.wc-block-components-address-form div:has(> #shipping-state),
.wc-block-components-address-form div:has(> [autocomplete*="address-level1"]) {
	order: 80 !important;
}

