/**
 * Pasargad Chat ↔ Rasha compatibility layer.
 *
 * Rasha bundles Materialize globally. Its high-specificity native-control
 * rules must be neutralised inside the independently styled chat widget.
 */

/* Keep late-created chat controls native. Materialize otherwise hides every
 * select and restyles text-like inputs even though they are outside its forms.
 */
#pasargad-chat-chat :where(button, input, textarea, select) {
	font-family: inherit !important;
}

#pasargad-chat-chat .pasargad-chat-field > input:not([type="checkbox"]),
#pasargad-chat-chat .pasargad-chat-field > textarea,
#pasargad-chat-chat .pasargad-chat-field > select {
	display: block;
	box-sizing: border-box;
	width: 100%;
	height: auto;
	min-height: 46px;
	margin: 0;
	padding: 11px 13px;
	border: 1px solid var(--pasargad-chat-line);
	border-bottom: 1px solid var(--pasargad-chat-line);
	border-radius: 13px;
	background-color: var(--pasargad-chat-surface);
	color: var(--pasargad-chat-ink);
	font: inherit;
	font-size: 13px;
	line-height: 1.5;
	box-shadow: none;
	outline: 0;
}

#pasargad-chat-chat .pasargad-chat-field > textarea {
	min-height: 84px;
	line-height: 1.8;
}

#pasargad-chat-chat .pasargad-chat-field > select {
	-webkit-appearance: auto;
	appearance: auto;
	padding: 11px 13px !important;
	border: 1px solid var(--pasargad-chat-line) !important;
	border-radius: 13px !important;
	background: var(--pasargad-chat-surface) !important;
	color: var(--pasargad-chat-ink) !important;
	box-shadow: none !important;
	cursor: pointer;
}

#pasargad-chat-chat .pasargad-chat-field > input:not([type="checkbox"]):focus:not([readonly]),
#pasargad-chat-chat .pasargad-chat-field > textarea:focus:not([readonly]),
#pasargad-chat-chat .pasargad-chat-field > select:focus {
	border: 1px solid var(--pasargad-chat-primary);
	border-bottom: 1px solid var(--pasargad-chat-primary);
	background-color: var(--pasargad-chat-surface);
	box-shadow: 0 0 0 3px var(--pasargad-chat-ring);
}

#pasargad-chat-chat .pasargad-chat-field > select:focus {
	border-color: var(--pasargad-chat-primary) !important;
	box-shadow: 0 0 0 3px var(--pasargad-chat-ring) !important;
}

#pasargad-chat-chat .pasargad-chat-field.has-error > input:not([type="checkbox"]),
#pasargad-chat-chat .pasargad-chat-field.has-error > textarea,
#pasargad-chat-chat .pasargad-chat-field.has-error > select {
	border-color: #ef4444;
	border-bottom-color: #ef4444;
}

#pasargad-chat-chat .pasargad-chat-field.has-error > select {
	border-color: #ef4444 !important;
}

/* Rasha declares the bare label selector with !important, which otherwise
 * replaces Pasargad Chat's configurable neutral and validation colours.
 */
#pasargad-chat-chat .pasargad-chat-field > label {
	color: var(--pasargad-chat-ink) !important;
}

#pasargad-chat-chat label.pasargad-chat-consent {
	color: var(--pasargad-chat-muted) !important;
}

#pasargad-chat-chat label.pasargad-chat-consent.has-error {
	color: #b91c1c !important;
}

/* Restore the compact native consent checkbox. Materialize globally makes all
 * checkboxes transparent and draws a second control on the adjacent span.
 */
#pasargad-chat-chat .pasargad-chat-consent > input[type="checkbox"] {
	position: static !important;
	display: block;
	flex: 0 0 16px;
	width: 16px;
	height: 16px;
	min-height: 0;
	margin: 3px 0 0;
	padding: 0;
	opacity: 1 !important;
	pointer-events: auto !important;
	accent-color: var(--pasargad-chat-primary);
	-webkit-appearance: auto;
	appearance: auto;
}

#pasargad-chat-chat .pasargad-chat-consent > input[type="checkbox"] + span:not(.lever) {
	position: static;
	display: block;
	height: auto;
	padding: 0;
	font: inherit;
	font-size: inherit;
	line-height: inherit;
	user-select: auto;
}

#pasargad-chat-chat .pasargad-chat-consent > input[type="checkbox"] + span:not(.lever)::before,
#pasargad-chat-chat .pasargad-chat-consent > input[type="checkbox"] + span:not(.lever)::after {
	display: none !important;
	content: none !important;
}

#pasargad-chat-chat .pasargad-chat-consent.has-error > input[type="checkbox"]:focus-visible {
	outline-color: #ef4444 !important;
}

/* Rasha's global button:focus color must not replace component backgrounds. */
#pasargad-chat-chat button:focus {
	background-color: transparent;
}

#pasargad-chat-chat .pasargad-chat-chat__header-actions button:focus {
	background-color: rgba(255, 255, 255, .14);
}

#pasargad-chat-chat .pasargad-chat-chat__header-actions button:hover:focus {
	background-color: rgba(255, 255, 255, .28);
}

#pasargad-chat-chat .pasargad-chat-quick button:focus,
#pasargad-chat-chat .pasargad-chat-ghost-btn:focus,
#pasargad-chat-chat .pasargad-chat-rating button:focus {
	background-color: var(--pasargad-chat-surface);
}

#pasargad-chat-chat .pasargad-chat-rating button:hover:focus,
#pasargad-chat-chat .pasargad-chat-rating button.is-active:focus {
	background-color: #fffbeb;
}

#pasargad-chat-chat .pasargad-chat-primary-btn:focus,
#pasargad-chat-chat .pasargad-chat-chat__launcher:focus,
#pasargad-chat-chat .pasargad-chat-jump:focus,
#pasargad-chat-chat .pasargad-chat-composer .pasargad-chat-send:hover,
#pasargad-chat-chat .pasargad-chat-composer .pasargad-chat-send:focus {
	background-color: var(--pasargad-chat-primary);
	background-image: var(--pasargad-chat-brand);
	color: #fff;
}

#pasargad-chat-chat .pasargad-chat-composer .pasargad-chat-send:disabled:hover,
#pasargad-chat-chat .pasargad-chat-composer .pasargad-chat-send:disabled:focus {
	background: var(--pasargad-chat-line);
	color: var(--pasargad-chat-faint);
}

#pasargad-chat-chat .pasargad-chat-emoji-toggle.is-active:focus {
	background-color: var(--pasargad-chat-tint);
}

#pasargad-chat-chat .pasargad-chat-chat__peek-open:hover:focus,
#pasargad-chat-chat .pasargad-chat-chat__peek-close:hover:focus,
#pasargad-chat-chat .pasargad-chat-composer button:not(.pasargad-chat-send):hover:focus,
#pasargad-chat-chat .pasargad-chat-emoji button:hover:focus {
	background-color: var(--pasargad-chat-soft);
}

#pasargad-chat-chat .pasargad-chat-confirm__actions .is-danger:focus {
	background-color: #dc2626;
}

#pasargad-chat-chat :where(a, button, input, select, textarea, [tabindex]):focus-visible {
	outline: 2px solid var(--pasargad-chat-primary) !important;
	outline-offset: 2px;
}

#pasargad-chat-chat .pasargad-chat-chat__header :focus-visible,
#pasargad-chat-chat .pasargad-chat-chat__launcher:focus-visible {
	outline-color: #fff !important;
	outline-offset: 3px;
}

button.pasargad-chat-inline-launcher,
button.pasargad-chat-inline-launcher:focus {
	background: linear-gradient(135deg, #5b4bdb, #8b5cf6) !important;
	color: #fff !important;
	font-family: inherit !important;
}

button.pasargad-chat-inline-launcher:focus-visible {
	outline: 2px solid #5b4bdb !important;
	outline-offset: 3px;
}

/* Temporarily remove the widget from the interaction layer while a Rasha
 * modal, full-screen player, loader or mobile navigation overlay is active.
 */
#pasargad-chat-chat.pasargad-chat-rasha-layer-active {
	visibility: hidden !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

/* Keep the launcher and incoming-message peek above Rasha's fixed mobile CTA
 * instead of covering the purchase button.
 */
#pasargad-chat-chat.pasargad-chat-rasha-has-bottom-bar {
	bottom: calc(
		var(--pasargad-chat-gap) +
		var(--pasargad-chat-safe-bottom) +
		var(--pasargad-chat-rasha-bottom-offset, 0px)
	);
}

/* A positively identified AsanClip result is a digital template, not stock. */
#pasargad-chat-chat .pasargad-chat-product.pasargad-chat-asanclip-template .pasargad-chat-product__meta .is-stock {
	color: #047857;
	font-weight: 700;
}

#pasargad-chat-chat .pasargad-chat-product.pasargad-chat-asanclip-template .pasargad-chat-product__action {
	display: inline-flex;
	max-width: 100%;
	align-items: center;
	justify-content: center;
	white-space: normal;
	line-height: 1.55;
	text-align: center;
}

/* Keep model-provided Persian product/editor links complete and readable.
 * Raw URLs need an isolated LTR run inside the RTL message, while Markdown
 * labels should retain their own natural direction. Long paths wrap without
 * changing or visually clipping the clickable address.
 */
#pasargad-chat-chat .pasargad-chat-message__text a.pasargad-chat-rasha-link {
	max-width: 100%;
	overflow-wrap: anywhere;
	word-break: break-word;
	unicode-bidi: isolate;
}

#pasargad-chat-chat .pasargad-chat-message__text a.pasargad-chat-rasha-link.is-raw-url {
	direction: ltr;
	text-align: left;
}

@media (prefers-color-scheme: dark) {
	#pasargad-chat-chat[data-scheme="auto"] .pasargad-chat-rating button:hover:focus,
	#pasargad-chat-chat[data-scheme="auto"] .pasargad-chat-rating button.is-active:focus {
		background-color: #3a2c07;
	}

	#pasargad-chat-chat[data-scheme="auto"] .pasargad-chat-product.pasargad-chat-asanclip-template .pasargad-chat-product__meta .is-stock {
		color: #6ee7b7;
	}
}
