/**
 * 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);
	}
}

/* Field Order Sequence for Classic Checkout */
.woocommerce-billing-fields__field-wrapper,
.woocommerce-shipping-fields__field-wrapper {
	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;
}

/* Product Page PIN Code Checker */
.ipaa-product-checker {
	margin: 18px 0;
	padding: 14px 16px;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	background: #f8fafc;
	max-width: 420px;
	font-family: inherit;
}
.ipaa-checker-title {
	font-size: 13.5px;
	font-weight: 600;
	color: #1e293b;
	margin-bottom: 10px;
	display: flex;
	align-items: center;
	gap: 6px;
}
.ipaa-checker-input-wrap {
	display: flex;
	gap: 8px;
}
.ipaa-checker-input {
	flex: 1;
	padding: 8px 12px;
	border: 1px solid #cbd5e1;
	border-radius: 6px;
	font-size: 14px;
	background: #ffffff;
	outline: none;
	transition: border-color 0.2s ease;
}
.ipaa-checker-input:focus {
	border-color: #3b82f6;
	box-shadow: 0 0 0 1px #3b82f6;
}
.ipaa-checker-btn {
	padding: 8px 16px;
	background: #1e293b;
	color: #ffffff;
	border: none;
	border-radius: 6px;
	font-size: 13.5px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.2s ease;
}
.ipaa-checker-btn:hover {
	background: #0f172a;
}
.ipaa-checker-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}
.ipaa-checker-result {
	margin-top: 10px;
	padding: 10px 14px;
	border-radius: 6px;
	font-size: 13px;
	line-height: 1.5;
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.ipaa-checker-success {
	background: #ecfdf5;
	color: #065f46;
	border: 1px solid #a7f3d0;
}
.ipaa-checker-warning {
	background: #fffbeb;
	color: #92400e;
	border: 1px solid #fde68a;
}
.ipaa-checker-error {
	background: #fef2f2;
	color: #991b1b;
	border: 1px solid #fecaca;
}
.ipaa-checker-row-delivery {
	font-weight: 500;
}
.ipaa-checker-row-cod {
	font-size: 13px;
	line-height: 1.45;
}
.ipaa-checker-row-delivery + .ipaa-checker-row-cod {
	margin-top: 4px;
	padding-top: 5px;
	border-top: 1px dashed rgba(0, 0, 0, 0.12);
}
.ipaa-checker-cod-ok {
	color: #047857;
	font-weight: 600;
}
.ipaa-checker-cod-blocked {
	color: #b45309;
	font-weight: 600;
}

/* COD Restriction & RTO Protection Banners */
.ipaa-cod-blocked-banner {
	display: flex;
	align-items: center;
	gap: 10px;
	background: #fffbeb;
	color: #92400e;
	border: 1px solid #fde68a;
	border-left: 4px solid #f59e0b;
	padding: 12px 16px;
	margin: 16px 0;
	border-radius: 6px;
	font-size: 13.5px;
	font-weight: 500;
	line-height: 1.5;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
	animation: ipaa-fade-in 0.25s ease-out;
}

.ipaa-cod-blocked-banner .ipaa-cod-icon {
	font-size: 18px;
	line-height: 1;
	color: #d97706;
	flex-shrink: 0;
}

/* Prevent flex layout wrapping on error notice */
.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),
#billing_postcode_field,
#shipping_postcode_field {
	min-width: 0 !important;
}

.ipaa-cod-inline-notice {
	display: flex;
	align-items: flex-start;
	gap: 6px;
	background: #fffbeb;
	color: #b45309;
	border: 1px solid #fef3c7;
	border-left: 3px solid #f59e0b;
	padding: 6px 10px;
	margin-top: 6px;
	font-size: 0.82rem;
	line-height: 1.4;
	border-radius: 4px;
	animation: ipaa-fade-in 0.2s ease-out;
	width: 100% !important;
	max-width: 100% !important;
	min-width: 0 !important;
	box-sizing: border-box !important;
	word-break: break-word !important;
	overflow-wrap: break-word !important;
	white-space: normal !important;
}

.ipaa-cod-inline-notice .ipaa-cod-icon {
	font-size: 14px;
	color: #d97706;
	flex-shrink: 0;
	margin-top: 1px;
}

/* Payment Section Dynamic Loading State */
.ipaa-payment-updating {
	position: relative !important;
	min-height: 80px !important;
	pointer-events: none !important;
	user-select: none !important;
}

.ipaa-payment-updating > *:not(.ipaa-payment-loader-overlay) {
	opacity: 0.25 !important;
	filter: grayscale(60%);
	transition: opacity 0.2s ease, filter 0.2s ease;
}

/* Hide stale no-payment-methods notice while actively refreshing */
.ipaa-payment-updating .wc-block-components-notice-banner,
.ipaa-payment-updating .wc-block-checkout__no-payment-methods-notice,
.ipaa-payment-updating .woocommerce-error,
.ipaa-payment-updating .woocommerce-notice,
.ipaa-payment-updating .woocommerce-info {
	opacity: 0 !important;
	visibility: hidden !important;
	pointer-events: none !important;
	display: none !important;
}

.ipaa-payment-loader-overlay {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	height: 100%;
	min-height: 80px;
	background: rgba(255, 255, 255, 0.88);
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	z-index: 50;
	border-radius: 8px;
	box-sizing: border-box;
	animation: ipaa-fade-in 0.2s ease-out;
}

.ipaa-payment-spinner {
	width: 26px;
	height: 26px;
	border: 3px solid #e2e8f0;
	border-top-color: #2563eb;
	border-radius: 50%;
	animation: ipaa-spin 0.65s linear infinite;
	margin-bottom: 8px;
}

.ipaa-payment-loader-text {
	font-size: 13px;
	font-weight: 500;
	color: #334155;
	letter-spacing: 0.2px;
	animation: ipaa-pulse 1.4s ease-in-out infinite alternate;
}

@keyframes ipaa-pulse {
	from {
		opacity: 0.65;
	}
	to {
		opacity: 1;
	}
}

/* Direct COD Disabled State */
.ipaa-cod-disabled {
	display: none !important;
	visibility: hidden !important;
	pointer-events: none !important;
}

.ipaa-disabled-btn {
	opacity: 0.5 !important;
	cursor: not-allowed !important;
	pointer-events: none !important;
}

/* Inline COD Notice (Directly Under Postcode Input) */
.ipaa-cod-inline-notice {
	display: flex !important;
	align-items: flex-start !important;
	gap: 8px !important;
	background: #fffbeb !important;
	color: #92400e !important;
	border: 1px solid #fde68a !important;
	border-left: 3px solid #f59e0b !important;
	padding: 8px 12px !important;
	margin-top: 8px !important;
	margin-bottom: 6px !important;
	border-radius: 6px !important;
	font-size: 12.5px !important;
	font-weight: 500 !important;
	line-height: 1.45 !important;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
	clear: both !important;
	width: 100% !important;
	box-sizing: border-box !important;
	animation: ipaa-fade-in 0.2s ease-out;
}

.ipaa-cod-inline-notice .ipaa-cod-icon {
	font-size: 15px;
	font-weight: 700;
	color: #d97706;
	line-height: 1;
	flex-shrink: 0;
	margin-top: 1px;
}

/* Payment Section Notice Banners (Above Gateway List) */
.ipaa-cod-payment-banner,
.ipaa-cod-blocked-banner,
.ipaa-cod-only-notice {
	display: flex !important;
	align-items: flex-start !important;
	gap: 10px !important;
	background: #fffbeb !important;
	color: #92400e !important;
	border: 1px solid #fde68a !important;
	border-left: 4px solid #f59e0b !important;
	padding: 12px 16px !important;
	margin: 12px 0 16px 0 !important;
	border-radius: 6px !important;
	font-size: 13.5px !important;
	font-weight: 500 !important;
	line-height: 1.5 !important;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
	box-sizing: border-box !important;
	animation: ipaa-fade-in 0.2s ease-out;
}

.ipaa-cod-payment-banner .ipaa-cod-icon,
.ipaa-cod-blocked-banner .ipaa-cod-icon,
.ipaa-cod-only-notice .ipaa-cod-icon {
	font-size: 16px;
	font-weight: 700;
	color: #d97706;
	line-height: 1.1;
	flex-shrink: 0;
}

