/* SW Persian Numeric Captcha — Elementor Pro form field (responsive, RTL) */

/*
 * Shabnam is bundled in assets/fonts/ (no CDN, so it also works when the
 * international internet is down). The script paints the digits with the Bold cut.
 */
@font-face {
	font-family: 'Shabnam';
	font-style: normal;
	font-weight: 400;
	font-display: swap;
	src: url('../fonts/Shabnam.woff2') format('woff2');
}

@font-face {
	font-family: 'Shabnam';
	font-style: normal;
	font-weight: 500;
	font-display: swap;
	src: url('../fonts/Shabnam-Medium.woff2') format('woff2');
}

@font-face {
	font-family: 'Shabnam';
	font-style: normal;
	font-weight: 700;
	font-display: swap;
	src: url('../fonts/Shabnam-Bold.woff2') format('woff2');
}

.sw-captcha,
.sw-captcha button,
.sw-captcha input {
	/* Project rule: the theme's Persian font comes first; the bundled Shabnam
	   remains as the fallback (also used by the digit canvas). */
	font-family: inherit;
}

/*
 * Layout (all screen sizes):
 *   row 1: [ digits box ............ ] [ speak ][ refresh ]
 *   row 2: [ answer input, full width ]
 *   row 3: [ status / error line ]
 * One column of content keeps it comfortable on phones and tidy on desktop.
 */

.sw-captcha {
	--sw-gap: 10px;
	--sw-radius: 12px;
	--sw-accent: #4a6cf7;
	--sw-border: #dce3ef;
	--sw-danger: #e74c3c;

	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	align-items: stretch;
	gap: var(--sw-gap);
	width: 100%;
	max-width: 100%;
	direction: rtl;
	box-sizing: border-box;
	container-type: inline-size;
}

.sw-captcha *,
.sw-captcha *::before,
.sw-captcha *::after {
	box-sizing: border-box;
}

/* ---- digits box ---- */

.sw-captcha__digits {
	grid-column: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	min-width: 0;
	min-height: 64px;
	padding: 0 10px;
	overflow: hidden;
	/* Digits are numerals: always laid out left-to-right, same as the answer box. */
	direction: ltr;
	background: #f6f9ff;
	border: 1px solid #e6ebf5;
	border-radius: var(--sw-radius);
	transition: opacity .2s ease;
}

/* Placeholder dots until the first code arrives. */
.sw-captcha__digits:empty::before {
	content: "• • • • • •";
	color: #9aa7c2;
	font-size: 26px;
	letter-spacing: 4px;
}

.sw-captcha.is-loading .sw-captcha__digits {
	opacity: .55;
}

.sw-captcha__canvas {
	display: block;
	max-width: 100%;
	height: 64px;
	-webkit-user-select: none;
	user-select: none;
	pointer-events: none;
}

/* ---- buttons ---- */

.sw-captcha__tools {
	grid-column: 2;
	display: flex;
	align-items: center;
	gap: 6px;
}

.sw-captcha__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	/* 44px: comfortable touch target. */
	width: 44px;
	height: 44px;
	padding: 0;
	margin: 0;
	border: 1px solid var(--sw-border);
	border-radius: 50%;
	background: #fff;
	color: #2c3e50;
	cursor: pointer;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
}

.sw-captcha__btn:hover:not(:disabled),
.sw-captcha__btn:focus-visible {
	background: var(--sw-accent);
	border-color: var(--sw-accent);
	color: #fff;
}

.sw-captcha__btn:hover:not(:disabled) {
	transform: translateY(-2px);
}

.sw-captcha__btn:focus-visible {
	outline: 2px solid var(--sw-accent);
	outline-offset: 2px;
}

.sw-captcha__btn:disabled {
	opacity: .5;
	cursor: not-allowed;
}

.sw-captcha__btn svg {
	display: block;
	pointer-events: none;
}

.sw-captcha.is-loading .sw-captcha__refresh svg {
	animation: sw-captcha-spin .8s linear infinite;
}

@keyframes sw-captcha-spin {
	to {
		transform: rotate(-360deg);
	}
}

/* ---- answer input ---- */

.sw-captcha .sw-captcha__input {
	grid-column: 1 / -1;
	display: block;
	width: 100%;
	max-width: 100%;
	min-height: 48px;
	height: auto;
	margin: 0;
	/* Extra start padding balances the trailing letter-spacing so digits look centred. */
	padding: 6px 12px 6px calc(12px + .3em);
	/* 16px+ stops iOS Safari from zooming the page on focus. */
	font-size: 22px;
	font-weight: 600;
	letter-spacing: .3em;
	text-align: center;
	direction: ltr;
	border: 2px solid var(--sw-border);
	border-radius: var(--sw-radius);
	background: #fff;
}

.sw-captcha .sw-captcha__input::placeholder {
	font-size: 15px;
	font-weight: 400;
	letter-spacing: 0;
}

.sw-captcha .sw-captcha__input:focus {
	outline: none;
	border-color: var(--sw-accent);
	box-shadow: 0 0 0 4px rgba(74, 108, 247, .12);
}

.sw-captcha .sw-captcha__input.elementor-error,
.elementor-field-group.elementor-error .sw-captcha__input {
	border-color: var(--sw-danger);
}

/* ---- status / Elementor messages ---- */

.sw-captcha__status {
	grid-column: 1 / -1;
	margin: 0;
	font-size: 13px;
	line-height: 1.6;
	color: var(--sw-danger);
}

.sw-captcha__status:empty {
	display: none;
}

.sw-captcha__noscript {
	grid-column: 1 / -1;
	font-size: 13px;
	color: var(--sw-danger);
}

/* Optional builder credit (shown when enabled in settings): a light notice-style pill. */
.sw-captcha__brand {
	grid-column: 1 / -1;
	justify-self: center;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	width: fit-content;
	margin: 2px 0 0;
	padding: 6px 14px;
	border-radius: 999px;
	background: #f2f6fd;
	border: 1px solid #e4ebf7;
	color: #7a8699;
	font-size: 11.5px;
	line-height: 1.6;
	text-align: center;
}

.sw-captcha__brand svg {
	flex: 0 0 auto;
	opacity: .8;
}

.sw-captcha__brand a {
	color: var(--sw-accent);
	font-weight: 600;
	text-decoration: none;
}

.sw-captcha__brand a:hover {
	text-decoration: underline;
}

/* Elementor appends its own inline error text inside the field group. */
.sw-captcha .elementor-message {
	grid-column: 1 / -1;
	margin: 0;
}

/* ---- honeypot: hidden without any off-screen offset (offsets cause sideways scroll on RTL pages) ---- */

.sw-captcha__hp {
	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;
	opacity: 0;
	pointer-events: none;
}

.sw-captcha__hp .sw-captcha__hp-input {
	width: 1px;
	height: 1px;
}

/* ---- small screens ---- */

@media (max-width: 480px) {
	.sw-captcha__digits {
		min-height: 64px;
		padding: 0 4px;
	}

	.sw-captcha .sw-captcha__input {
		font-size: 20px;
	}
}

/* Very narrow phones: stack the two buttons so the digits keep their room. */
@media (max-width: 340px) {
	.sw-captcha__tools {
		flex-direction: column;
	}
}

@media (prefers-reduced-motion: reduce) {
	.sw-captcha__btn,
	.sw-captcha__digits {
		transition: none;
	}

	.sw-captcha.is-loading .sw-captcha__refresh svg {
		animation: none;
	}
}

/* ---- outside Elementor forms (wp-login, comments, WooCommerce, shortcode) ---- */

.sw-captcha--plain {
	margin: 0 0 16px;
}

.sw-captcha--plain .sw-captcha__input {
	margin: 0;
}

/* wp-login.php draws its own inputs; keep ours looking like the rest of the widget. */
.login form .sw-captcha .sw-captcha__input {
	min-height: 48px;
	padding: 6px 12px 6px calc(12px + .3em);
	font-size: 22px;
	box-shadow: none;
}

.login form .sw-captcha .sw-captcha__input:focus {
	border-color: var(--sw-accent);
	box-shadow: 0 0 0 4px rgba(74, 108, 247, .12);
}

/* While the recorded voice is playing. */
.sw-captcha.is-speaking .sw-captcha__speak {
	background: var(--sw-accent);
	border-color: var(--sw-accent);
	color: #fff;
}

/* Atomic (e-form) forms: captcha row spans the full width */
.elementor .e-form-base > .sw-captcha-group { flex: 1 0 100%; width: 100%; grid-column: 1 / -1; margin: 12px 0 4px; }


/* Atomic (e-form) forms: the Elementor kit rule .elementor-kit-6 input:not(...) is stronger than ours */
.elementor .e-form-base .sw-captcha .sw-captcha__input {
	background: #fff !important;
	border: 2px solid #dce3ef !important;
	border-radius: 12px !important;
	font-size: 22px !important;
}

/* Atomic forms: dark mode */
html.to-dark .e-form-base .sw-captcha { --sw-border: #2e4a43; }
html.to-dark .e-form-base .sw-captcha__digits { background: #101f1c; border-color: #2e4a43; }
html.to-dark .e-form-base .sw-captcha .sw-captcha__input {
	background: #14251f !important;
	border-color: #2e4a43 !important;
	color: #e9f5f1 !important;
}
html.to-dark .e-form-base .sw-captcha .sw-captcha__input::placeholder { color: #93a9a3; }

