/**
 * PAYUNi Pro – checkout UI (payment method icons, on-site card form, Click to Pay panel).
 * Colors derive from the theme's text color (currentColor) so the form fits light and dark themes.
 */

.twps-cc,
.twps-trust,
.twps-c2p,
.twps-payuni-icons {
	--payuni-accent: #5c3a93;
	--payuni-ok: #1a7f37;
	--payuni-err: #c0392b;
	--payuni-line: rgba(0, 0, 0, 0.16);
	--payuni-line: color-mix(in srgb, currentColor 18%, transparent);
	--payuni-muted: rgba(0, 0, 0, 0.62);
	--payuni-muted: color-mix(in srgb, currentColor 68%, transparent);
	--payuni-soft: rgba(92, 58, 147, 0.07);
	--payuni-soft: color-mix(in srgb, var(--payuni-accent) 7%, transparent);
}

/* ---------- Payment method icons (next to the gateway title) ---------- */

.twps-payuni-icons {
	display: inline-flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px;
	margin-left: 0.5em;
	vertical-align: middle;
	line-height: 1;
}

#payment .payment_methods li .twps-payuni-icons img,
.twps-payuni-icons img {
	display: block;
	float: none;
	height: 22px;
	width: auto;
	max-height: 22px;
	margin: 0;
	padding: 0;
	border-radius: 3px;
	box-shadow: none;
}

/* ---------- Shared: description + option selects (PAYUNi and SmilePay) ---------- */

.twps-pay-desc > :last-child {
	margin-bottom: 0;
}

.twps-pay-desc + .twps-pay-option,
.twps-pay-desc + fieldset.twps-cc,
.twps-pay-desc + .twps-c2p {
	margin-top: 0.75em;
}

#payment .payment_box .twps-pay-option,
.twps-pay-option {
	margin: 0.75em 0 0;
	padding: 0;
}

.twps-pay-option label {
	display: block;
	margin: 0 0 4px;
	font-size: 0.875em;
	font-weight: 600;
}

.twps-pay-option select {
	width: 100%;
	max-width: 320px;
	min-height: 42px;
	padding: 0 10px;
	border: 1px solid rgba(0, 0, 0, 0.16);
	border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
	border-radius: 8px;
	font-size: 16px;
}

/* ---------- On-site card form ---------- */

#payment .payment_box fieldset.twps-cc,
fieldset.twps-cc {
	position: relative;
	margin: 0.75em 0 0;
	padding: 14px 16px 6px;
	border: 1px solid var(--payuni-line);
	border-radius: 12px;
	background: transparent;
	min-width: 0;
}

fieldset.twps-cc--cvc-only {
	padding-top: 10px;
}

.twps-cc__head {
	float: left; /* lets a <legend> lay out like a normal block */
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0 0 10px;
	padding: 0;
	font-size: 0.95em;
	font-weight: 600;
}

/* Heading lock icon: inline glyph-style alignment (see the trust notes below). */
.twps-cc__title {
	display: block;
	line-height: 1.4;
}

.twps-cc__title .twps-svg {
	display: inline;
}

.twps-cc__title .twps-ui-icon {
	color: var(--payuni-accent);
}

/* Icons that sit next to text: 1em, lowered 0.125em (Bootstrap Icons / Font Awesome / Iconify convention). */
.twps-cc__title .twps-ui-icon,
ul.twps-trust .twps-ui-icon {
	display: inline-block;
	width: 1em;
	height: 1em;
	margin: 0 0.4em 0 0;
	vertical-align: -0.125em;
	overflow: visible;
}

.twps-cc .twps-cc__field {
	position: relative;
	margin: 0 0 10px;
	padding: 0;
}

.twps-cc .twps-cc__field label {
	display: block;
	margin: 0 0 4px;
	font-size: 0.875em;
	font-weight: 600;
	line-height: 1.4;
}

.twps-cc .twps-cc__field .required {
	color: var(--payuni-err);
	text-decoration: none;
	border: 0;
}

.twps-cc__control {
	position: relative;
	display: block;
}

#payment .twps-cc input.input-text,
.twps-cc input.input-text {
	display: block;
	width: 100%;
	height: 46px;
	margin: 0;
	padding: 0 44px 0 14px;
	box-sizing: border-box;
	border: 1px solid var(--payuni-line);
	border-radius: 8px;
	font-size: 16px; /* 16px avoids iOS zoom-on-focus */
	line-height: 46px;
	letter-spacing: 0.04em;
	font-variant-numeric: tabular-nums;
	box-shadow: none;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
	/* WooCommerce core paints its own brand icon on identified card fields; we draw ours. */
	background-image: none !important;
}

/*
 * Card number field: when empty it shows the accepted brands as small logos on the right
 * (like Stripe / Shopify checkout); once a brand is detected only that brand is shown.
 */
/* Two classes so this wins over the fixed 30px width of .twps-cc__suffix defined further down. */
.twps-cc__suffix.twps-cc__brand {
	width: auto;
	min-width: 30px;
}

.twps-cc__accepted-inline {
	display: inline-flex;
	align-items: center;
	gap: 3px;
}

#payment .payment_methods li .twps-cc__accepted-inline img,
.twps-cc__accepted-inline img {
	display: block;
	float: none;
	height: 16px;
	width: auto;
	max-height: 16px;
	margin: 0 !important;
	border-radius: 2px;
	box-shadow: none;
}

.twps-cc__brand[data-brand]:not([data-brand=""]) .twps-cc__accepted-inline {
	display: none;
}

#payment .twps-cc [data-field="number"]:has(.twps-cc__accepted-inline) input.input-text,
.twps-cc [data-field="number"]:has(.twps-cc__accepted-inline) input.input-text {
	padding-right: 96px;
}

/* Phones / narrow checkout columns: smaller brand logos and less reserved space, so the field does not feel cramped. */
@media (max-width: 480px) {
	#payment .payment_methods li .twps-cc__accepted-inline img,
	.twps-cc__accepted-inline img {
		height: 12px;
		max-height: 12px;
	}

	.twps-cc__accepted-inline {
		gap: 2px;
	}

	.twps-cc__suffix.twps-cc__brand {
		min-width: 24px;
		height: 16px;
	}

	#payment .twps-cc [data-field="number"]:has(.twps-cc__accepted-inline) input.input-text,
	.twps-cc [data-field="number"]:has(.twps-cc__accepted-inline) input.input-text {
		padding-right: 72px;
	}

	.twps-block-field.has-accepted input {
		padding-right: 72px !important;
	}
}

/* Same for a narrow block checkout column (WooCommerce sets a size container on the checkout). */
@container (max-width: 400px) {
	.twps-cc__accepted-inline img {
		height: 12px;
		max-height: 12px;
	}

	.twps-cc__accepted-inline {
		gap: 2px;
	}

	.twps-cc__suffix.twps-cc__brand {
		min-width: 24px;
		height: 16px;
	}

	.twps-block-field.has-accepted input {
		padding-right: 72px !important;
	}
}

/* Expiry has no icon inside, so it does not need the right-hand space reserved for one. */
#payment .twps-cc [data-field="expiry"] input.input-text,
.twps-cc [data-field="expiry"] input.input-text {
	padding-right: 14px;
}

.twps-cc input.input-text::placeholder {
	color: var(--payuni-muted);
	opacity: 0.7;
	letter-spacing: 0.08em;
}

#payment .twps-cc input.input-text:focus,
.twps-cc input.input-text:focus {
	outline: none;
	border-color: var(--payuni-accent);
	box-shadow: 0 0 0 3px rgba(92, 58, 147, 0.18);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--payuni-accent) 22%, transparent);
}

#payment .twps-cc .is-valid input.input-text,
.twps-cc .is-valid input.input-text {
	border-color: var(--payuni-ok);
}

#payment .twps-cc .is-invalid input.input-text,
.twps-cc .is-invalid input.input-text {
	border-color: var(--payuni-err);
	box-shadow: 0 0 0 1px var(--payuni-err);
}

#payment .twps-cc .is-invalid input.input-text:focus,
.twps-cc .is-invalid input.input-text:focus {
	box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.2);
}

.twps-cc__suffix {
	position: absolute;
	top: 50%;
	right: 10px;
	transform: translateY(-50%);
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 20px;
	color: var(--payuni-muted);
	pointer-events: none;
	background: no-repeat center / contain;
}

.twps-cc__brand[data-brand]:not([data-brand=""]) .twps-ui-icon {
	display: none;
}

.twps-cc__suffix .twps-ui-icon {
	width: 20px;
	height: 20px;
}

.twps-cc__hint {
	display: block;
	margin-top: 4px;
	font-size: 0.78em;
	color: var(--payuni-muted);
	line-height: 1.4;
}

.twps-cc__error {
	display: block;
	min-height: 0;
	font-size: 0.8em;
	line-height: 1.4;
	color: var(--payuni-err);
}

.twps-cc__error:not(:empty) {
	margin-top: 4px;
}

.twps-cc .is-invalid .twps-cc__hint {
	display: none;
}

/* Two columns for expiry + CVC, also on phones (fields are short). */
.twps-cc .form-row-first,
.twps-cc .form-row-last {
	width: calc(50% - 6px);
}

.twps-cc .form-row-first {
	float: left;
	clear: left;
}

.twps-cc .form-row-last {
	float: right;
}

.twps-cc .form-row-wide {
	clear: both;
	width: 100%;
}

/* Inline SVG icons: block-level inside a flex box, so no baseline gap pushes them off-centre. */
.twps-ui-icon {
	display: block;
	flex: none;
}

.twps-svg {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
}

/* ==========================================================================
   Block checkout (Cart & Checkout Blocks)
   Inputs, labels, selects and error messages use WooCommerce Blocks' own markup
   (wc-block-components-text-input / wc-blocks-components-select), so their look comes
   from WooCommerce and the store theme. The rules below only handle layout and make
   our own accents follow the theme text colour instead of a fixed brand colour.
   ========================================================================== */

.twps-block-pay .twps-trust,
.twps-block-pay .twps-c2p,
.twps-block-pay .twps-cc--block {
	--payuni-accent: currentColor;
	--payuni-ok: currentColor;
	--payuni-line: rgba(0, 0, 0, 0.12);
	--payuni-line: color-mix(in srgb, currentColor 14%, transparent);
	--payuni-muted: rgba(0, 0, 0, 0.62);
	--payuni-muted: color-mix(in srgb, currentColor 72%, transparent);
	--payuni-soft: transparent;
}

.twps-block-pay .twps-pay-desc p {
	margin: 0;
}

.twps-cc--block {
	margin-top: 12px;
}

.twps-cc--block .twps-cc__head {
	float: none;
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 8px;
	margin: 0;
	font-size: var(--wp--preset--font-size--small, 0.875em);
	font-weight: 600;
}

.twps-cc--block .wc-block-components-text-input {
	margin-top: 12px;
}

.twps-block-row {
	display: flex;
	gap: 12px;
}

/* WooCommerce removes the top margin of the first input in a container (:first-of-type);
   keep both fields of the row aligned. */
.twps-cc--block .twps-block-row > .wc-block-components-text-input {
	margin-top: 12px;
}

.twps-block-row > * {
	flex: 1 1 0;
	min-width: 0;
}

/* Brand / CVC icon inside the WooCommerce input (centred on the input box). */
.twps-block-field__control {
	position: relative;
}

.twps-block-field.has-suffix input {
	padding-right: 48px !important;
}

.twps-block-field .twps-cc__suffix {
	color: inherit;
	opacity: 0.6;
}

/* Brand logos are shown in full colour; only the outline icons are muted. */
.twps-block-field .twps-cc__brand {
	opacity: 1;
}

.twps-block-field.has-accepted input {
	padding-right: 96px !important;
}

/* ==========================================================================
   Optional (setting "Full-width order button", body class added on the checkout page):
   Place order button spans the full width, return-to-cart link moves below it.
   ========================================================================== */

.twps-full-width-place-order .wc-block-checkout__actions .wc-block-checkout__actions_row {
	flex-direction: column-reverse;
	align-items: stretch;
	justify-content: center;
	gap: 16px;
}

.twps-full-width-place-order .wc-block-checkout__actions .wc-block-components-checkout-place-order-button {
	width: 100%;
}

.twps-full-width-place-order .wc-block-checkout__actions .wc-block-components-checkout-return-to-cart-button {
	align-self: center;
}

body.twps-full-width-place-order #payment #place_order {
	float: none;
	display: block;
	width: 100%;
}

.twps-block-field .twps-cc__brand[data-brand]:not([data-brand=""]) {
	opacity: 1;
}

/* Hint under a field: same size / spacing as WooCommerce's validation message, muted theme colour. */
.twps-block-field .wc-block-components-text-input__help {
	margin: 0;
	padding: 8px 0 0;
	font-size: var(--wp--preset--font-size--small, 14px);
	line-height: 1.4;
	white-space: normal;
	color: var(--payuni-muted);
}

.twps-block-select {
	margin-top: 12px;
}

.twps-block-pay .twps-c2p {
	margin-top: 12px;
	padding: 0;
	border: 0;
}

/* Step numbers: outlined in the theme text colour (works on light and dark themes). */
.twps-block-pay ol.twps-c2p__steps li::before {
	background: transparent;
	color: inherit;
	border: 1.5px solid currentColor;
	line-height: calc(1.5em - 3px); /* circle height minus the two borders */
	box-sizing: border-box;
}

/* ---------- Trust notes ---------- */

ul.twps-trust {
	display: flex;
	flex-wrap: wrap;
	gap: 6px 14px;
	margin: 10px 0 0;
	padding: 10px 2px 0;
	list-style: none;
	font-size: 0.78em;
	line-height: 1.45;
	color: var(--payuni-muted);
}

/*
 * Icon + text alignment — the community-standard approach used by Bootstrap Icons, Font Awesome and Iconify:
 * the icon sits inline in the text like a glyph, sized 1em and lowered by 0.125em. It follows the text's own
 * font and size, does not depend on line-height or flex centring, and stays on the first line when text wraps.
 * A hanging indent (padding-left + negative text-indent) keeps wrapped lines aligned with the first line's text.
 */
#payment ul.payment_methods ul.twps-trust li,
ul.twps-trust li {
	display: block;
	margin: 0;
	padding: 0 0 0 1.4em;
	text-indent: -1.4em;
	line-height: 1.45;
	list-style: none;
}

ul.twps-trust li::before {
	content: none;
}

ul.twps-trust .twps-trust__icon {
	display: inline;
	color: var(--payuni-ok);
}

/* ---------- Click to Pay panel ---------- */

.twps-c2p {
	margin: 0.5em 0 0;
	padding: 12px 14px;
	border: 1px solid var(--payuni-line);
	border-radius: 12px;
	background: var(--payuni-soft);
}

ol.twps-c2p__steps {
	margin: 0;
	padding: 0;
	list-style: none;
	counter-reset: payuni-step;
	font-size: 0.9em;
}

/*
 * Step numbers: the circle is exactly one line tall (1.5em = the line-height, i.e. 1lh) and sits at the
 * top of the item, so its centre is the centre of the first text line — also when the step wraps.
 */
#payment ul.payment_methods ol.twps-c2p__steps li,
ol.twps-c2p__steps li {
	position: relative;
	margin: 0 0 6px;
	padding-left: 2.1em;
	line-height: 1.5;
	counter-increment: payuni-step;
}

ol.twps-c2p__steps li::before {
	content: counter(payuni-step);
	position: absolute;
	left: 0;
	top: 0;
	width: 1.5em;
	height: 1.5em;
	border-radius: 50%;
	background: var(--payuni-accent);
	color: #fff;
	font-size: 1em;
	font-weight: 700;
	line-height: 1.5em;
	text-align: center;
	/* Slightly smaller circle, scaled around its centre — so it stays centred on the first line. */
	transform: scale(0.85);
	box-sizing: border-box;
}

.twps-c2p__note {
	margin: 8px 0 0 !important;
	font-size: 0.8em;
	color: var(--payuni-muted);
}

@media (prefers-reduced-motion: reduce) {
	.twps-cc input.input-text {
		transition: none;
	}
}
