/* SmartWPAssistant chat widget — RTL-first, mobile-first (road.md §22). */

/* ---------------------------------------------------------------------------
 * Theme-isolation reset. Themes aggressively style button/input/a/p/ul, set
 * odd box-sizing, line-heights and margins. We scope a defensive reset to the
 * widget subtree so it renders consistently on ANY theme — without leaking out
 * to the rest of the page. (We avoid `all:initial` because it would also wipe
 * our own inherited values; this targeted reset is safer.)
 * ------------------------------------------------------------------------- */
.swa-widget,
.swa-widget * ,
.swa-widget *::before,
.swa-widget *::after {
	box-sizing: border-box;
}
.swa-widget {
	--swa-color: #2563eb;
	--swa-launcher-bg: #1976d2;
	--swa-launcher-icon: #fff;
	font-family: Tahoma, IRANSans, Vazirmatn, system-ui, sans-serif;
	font-size: 14px;
	line-height: 1.7;
	direction: rtl;
	text-align: right;
	color: #1f2937;
	letter-spacing: normal;
	-webkit-font-smoothing: antialiased;
}
.swa-widget :where(button),
.swa-widget :where(input),
.swa-widget :where(textarea),
.swa-widget :where(select) {
	font-family: inherit;
	margin: 0;
	box-shadow: none;
	text-transform: none;
	letter-spacing: normal;
	min-height: 0;
	line-height: normal;
}
.swa-widget :where(button) {
	cursor: pointer;
	border: none;
	background: none;
	width: auto;
}
.swa-widget a {
	box-shadow: none;
	text-decoration: none;
}
.swa-widget a:hover,
.swa-widget a:focus {
	box-shadow: none;
}
.swa-widget p,
.swa-widget ul,
.swa-widget ol {
	margin: 0;
	padding: 0;
}
.swa-widget img { max-width: none; }

/* ---- Floating launcher ---- */
.swa-mode-floating {
	position: fixed;
	bottom: 20px;
	z-index: 2147483600; /* sit above sticky theme headers/overlays */
}
.swa-pos-bottom_right { right: 20px; }
.swa-pos-bottom_left  { left: 20px; right: auto; }

	.swa-launcher {
		width: 68px;
		height: 68px;
		border-radius: 50%;
		border: none;
		background: var(--swa-launcher-bg);
		color: var(--swa-launcher-icon);
		cursor: pointer;
		box-shadow: 0 14px 36px rgba(15, 23, 42, .22);
		display: flex;
		align-items: center;
		justify-content: center;
	transition: transform .15s ease;
}
.swa-launcher svg {
	width: 38px;
	height: 38px;
	color: var(--swa-launcher-icon);
	filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .22));
}
.swa-launcher:hover { transform: scale(1.06); }

/* ---- Panel ---- */
.swa-panel {
	display: none;
	flex-direction: column;
		width: 376px;
		max-width: calc(100vw - 28px);
		height: 560px;
		max-height: 78vh;
		background: #fff;
		border: 1px solid rgba(15, 23, 42, .06);
		border-radius: 22px;
		box-shadow: 0 24px 64px rgba(15, 23, 42, .22), 0 4px 14px rgba(15, 23, 42, .08);
		overflow: hidden;
	}
	.swa-widget.swa-open .swa-panel { animation: swa-panel-in .22s cubic-bezier(.2,.8,.25,1); }
	@keyframes swa-panel-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.swa-mode-floating .swa-panel {
	position: fixed;
	bottom: 90px;
	z-index: 2147483600;
}
.swa-pos-bottom_right .swa-panel { right: 20px; }
.swa-pos-bottom_left  .swa-panel { left: 20px; }

.swa-mode-inline .swa-panel {
	display: flex;
	position: relative;
	width: 100%;
	max-width: 100%;
	margin: 16px 0;
	height: 560px;
}

.swa-widget.swa-open .swa-panel { display: flex; }
.swa-widget.swa-open .swa-launcher { display: none; }

/* ---- Header ---- */
.swa-header {
		background: var(--swa-color);
		background: linear-gradient(135deg, color-mix(in srgb, var(--swa-color) 88%, #fff), var(--swa-color) 60%, color-mix(in srgb, var(--swa-color) 78%, #000));
		color: #fff;
		padding: 15px 16px;
		display: flex;
		align-items: center;
		gap: 11px;
		justify-content: flex-start;
		box-shadow: 0 2px 10px color-mix(in srgb, var(--swa-color) 30%, transparent);
		position: relative;
		z-index: 1;
}
.swa-header-info { display: flex; flex-direction: column; }
.swa-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, .22);
	border: 2px solid rgba(255, 255, 255, .45);
	box-shadow: 0 2px 8px rgba(0,0,0,.12);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	overflow: hidden;
	flex-shrink: 0;
}
.swa-avatar img { width: 100%; height: 100%; object-fit: cover; }
.swa-avatar-icon { color: #fff; }
.swa-bot-name { font-weight: 700; font-size: 14.5px; }
.swa-status { font-size: 11px; opacity: .9; display: inline-flex; align-items: center; gap: 5px; }
.swa-status::before {
	content: ""; width: 7px; height: 7px; border-radius: 50%;
	background: #34d399; box-shadow: 0 0 0 2px rgba(52,211,153,.35);
	display: inline-block;
}
	.swa-close {
		background: none; border: none; color: #fff;
		font-size: 24px; line-height: 1; cursor: pointer;
		margin-inline-start: auto;
	}

	/* ---- Pre-chat lead gate ---- */
	.swa-prechat {
		flex: 1;
		background: #f7f8fb;
		padding: 16px;
		overflow-y: auto;
	}
	.swa-prechat[hidden] { display: none; }
	.swa-prechat-content {
		display: flex;
		flex-direction: column;
		gap: 12px;
		min-height: 100%;
		justify-content: center;
	}
	.swa-prechat-kicker {
		width: fit-content;
		padding: 4px 10px;
		border-radius: 999px;
		background: #e8f7ef;
		color: #166534;
		font-size: 11px;
		font-weight: 700;
	}
	.swa-prechat h3 {
		margin: 0;
		font-size: 18px;
		line-height: 1.6;
		color: #111827;
	}
	.swa-prechat p {
		margin: 0;
		color: #5b6472;
		font-size: 13px;
		line-height: 1.8;
	}
	.swa-prechat-fields {
		display: grid;
		gap: 9px;
	}
	.swa-prechat input,
	.swa-prechat textarea,
	.swa-lead-form input,
	.swa-lead-form textarea {
		width: 100%;
		box-sizing: border-box;
		background: #fff;
		border: 1px solid #d8dce3;
		border-radius: 12px;
		color: #111827;
		font-family: inherit;
		font-size: 13px;
		transition: border-color .15s ease, box-shadow .15s ease;
	}
	.swa-prechat input,
	.swa-prechat textarea {
		padding: 11px 12px;
	}
	.swa-prechat textarea { resize: vertical; min-height: 72px; }
	.swa-prechat input:focus,
	.swa-prechat textarea:focus,
	.swa-lead-form input:focus,
	.swa-lead-form textarea:focus {
		outline: none;
		border-color: var(--swa-color);
		box-shadow: 0 0 0 3px color-mix(in srgb, var(--swa-color) 16%, transparent);
	}
	.swa-prechat-actions {
		display: grid;
		grid-template-columns: 1fr;
		gap: 8px;
		margin-top: 2px;
	}
	.swa-prechat-error {
		background: #fff1f2;
		border: 1px solid #fecdd3;
		border-radius: 12px;
		color: #be123c;
		font-size: 12px;
		line-height: 1.7;
		padding: 8px 10px;
	}
	.swa-prechat-error[hidden] { display: none; }
	.swa-prechat-submit,
	.swa-prechat-skip {
		border: none;
		border-radius: 12px;
		cursor: pointer;
		font-family: inherit;
		font-weight: 700;
		padding: 11px 12px;
	}
	.swa-prechat-submit {
		background: var(--swa-color);
		color: #fff;
		box-shadow: 0 10px 20px color-mix(in srgb, var(--swa-color) 24%, transparent);
	}
	.swa-prechat-skip {
		background: #eef1f5;
		color: #374151;
	}
	.swa-prechat-submit:disabled,
	.swa-prechat-skip:disabled {
		opacity: .6;
		cursor: default;
	}
	.swa-widget.swa-chat-locked .swa-messages,
	.swa-widget.swa-chat-locked .swa-input-area,
	.swa-widget.swa-chat-locked .swa-lead-form,
	.swa-widget.swa-chat-locked .swa-branding {
		display: none;
	}

/* ---- Messages ---- */
.swa-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 14px;
	background: linear-gradient(180deg, #fbfbfd, #f4f5f8);
	display: flex;
	flex-direction: column;
	gap: 11px;
	scrollbar-width: thin;
	scrollbar-color: rgba(15,23,42,.18) transparent;
}
.swa-messages::-webkit-scrollbar { width: 7px; }
.swa-messages::-webkit-scrollbar-thumb { background: rgba(15,23,42,.16); border-radius: 8px; }
.swa-msg {
	max-width: 86%;
	padding: 11px 14px;
	border-radius: 16px;
	line-height: 1.8;
	font-size: 14px;
	white-space: pre-wrap;
	word-break: break-word;
	animation: swa-msg-in .22s ease;
}
@keyframes swa-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.swa-msg-bot {
	background: #fff;
	border: 1px solid #eceef2;
	align-self: flex-start;
	border-bottom-right-radius: 5px;
	box-shadow: 0 2px 8px rgba(15, 23, 42, .05);
	color: #1f2430;
}
.swa-msg-user {
	background: var(--swa-color);
	background: linear-gradient(135deg, var(--swa-color), color-mix(in srgb, var(--swa-color) 80%, #000));
	color: #fff;
	align-self: flex-end;
	border-bottom-left-radius: 5px;
	box-shadow: 0 4px 12px color-mix(in srgb, var(--swa-color) 32%, transparent);
}

/* ---- Typing ---- */
.swa-typing { display: inline-flex; gap: 4px; align-items: center; }
.swa-typing span {
	width: 7px; height: 7px; border-radius: 50%;
	background: #b7bdc7; animation: swa-bounce 1s infinite;
}
.swa-typing span:nth-child(2) { animation-delay: .15s; }
.swa-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes swa-bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

/* ---- Sources ---- */
.swa-sources { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.swa-source-link {
	font-size: 12px;
	background: #eef2ff;
	color: var(--swa-color);
	padding: 3px 9px;
	border-radius: 999px;
	text-decoration: none;
}

/* ---- Product cards ---- */
.swa-products { display: flex; flex-direction: column; gap: 11px; margin-top: 8px; align-self: stretch; }
.swa-product-card {
	display: flex;
	flex-direction: column;
	gap: 10px;
	border: 1px solid #eceef2;
	border-radius: 16px;
	padding: 12px;
	background: #fff;
	align-self: stretch;
	max-width: 100%;
	box-shadow: 0 4px 14px rgba(15, 23, 42, .07);
	transition: transform .15s ease, box-shadow .15s ease;
}
.swa-product-card:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(15, 23, 42, .12); }
.swa-product-main { display: flex; gap: 11px; align-items: center; }
.swa-product-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; flex-shrink: 0; border: 1px solid #f0f1f4; }
.swa-product-info { display: flex; flex-direction: column; gap: 4px; }
.swa-product-title { font-weight: 700; font-size: 13.5px; color: #1f2430; }
.swa-product-price { color: var(--swa-color); font-size: 14px; font-weight: 800; }
.swa-product-reason { font-size: 12px; color: #6b7280; line-height: 1.7; }
.swa-product-oos { font-size: 11px; color: #dc2626; font-weight: 600; }

/* Inline product action button row */
.swa-product-actions { display: flex; gap: 8px; }
.swa-inline-btn {
	flex: 1;
	text-align: center;
	background: var(--swa-color);
	background: linear-gradient(135deg, var(--swa-color), color-mix(in srgb, var(--swa-color) 80%, #000));
	color: #fff;
	text-decoration: none;
	font-size: 13px;
	font-weight: 700;
	padding: 10px 12px;
	border-radius: 12px;
	box-shadow: 0 4px 12px color-mix(in srgb, var(--swa-color) 28%, transparent);
	transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.swa-inline-btn:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 7px 18px color-mix(in srgb, var(--swa-color) 38%, transparent); }
.swa-inline-btn:active { transform: scale(.97); }

/* ---- Human handoff ---- */
.swa-handoff {
	display: flex;
	gap: 8px;
	padding: 8px 12px;
	border-top: 1px solid #e6e8ec;
	background: #fff;
}
.swa-handoff-link {
	flex: 1;
	text-align: center;
	border: 1px solid color-mix(in srgb, var(--swa-color) 24%, #d8dce3);
	color: var(--swa-color);
	background: color-mix(in srgb, var(--swa-color) 7%, #fff);
	border-radius: 10px;
	font-size: 12px;
	font-weight: 700;
	padding: 7px 10px;
}
.swa-theme-emerald { --swa-color: #059669; }
.swa-theme-sunset { --swa-color: #ea580c; }
.swa-theme-mono { --swa-color: #374151; }

/* ---- Lead form ---- */
.swa-lead-form {
	position: relative;
	padding: 12px 14px;
	border-top: 1px solid #e6e8ec;
	background: #fff;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.swa-lead-form[hidden] { display: none; }
.swa-lead-text {
	padding-inline-end: 32px;
	font-size: 12px;
	line-height: 1.7;
	color: #4b5563;
}
.swa-lead-close {
	position: absolute;
	top: 8px;
	inset-inline-end: 10px;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 1px solid #e5e7eb;
	border-radius: 50%;
	background: #f9fafb;
	color: #6b7280;
	cursor: pointer;
	font: 22px/24px Arial, sans-serif;
	transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.swa-lead-close:hover,
.swa-lead-close:focus-visible {
	border-color: #cbd5e1;
	background: #f1f5f9;
	color: #111827;
	outline: none;
}
	.swa-lead-form input,
	.swa-lead-form textarea {
		padding: 9px 11px;
	}
.swa-lead-form textarea { resize: vertical; min-height: 58px; }
.swa-lead-submit {
	background: var(--swa-color);
	color: #fff;
	border: none;
	padding: 9px;
	border-radius: 10px;
	cursor: pointer;
	font-family: inherit;
}

/* ---- Input ---- */
.swa-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e6e8ec;
	background: #fff;
}
.swa-input {
	flex: 1;
	resize: none;
	border: 1px solid #d8dce3;
	border-radius: 12px;
	padding: 10px 12px;
	font-family: inherit;
	font-size: 14px;
	max-height: 110px;
	line-height: 1.6;
}
.swa-input:focus { outline: none; border-color: var(--swa-color); }
.swa-send {
	background: var(--swa-color); /* fallback for browsers without color-mix */
	background: linear-gradient( 135deg, var(--swa-color), color-mix( in srgb, var(--swa-color) 78%, #000 ) );
	color: #fff;
	border: none;
	width: 44px; height: 44px;
	border-radius: 14px;
	cursor: pointer;
	flex-shrink: 0;
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 6px 16px color-mix( in srgb, var(--swa-color) 45%, transparent );
	transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.swa-send svg { transform: scaleX(-1); } /* point the paper-plane toward RTL */
.swa-send:hover:not(:disabled) {
	transform: translateY(-1px) scale(1.05);
	box-shadow: 0 10px 22px color-mix( in srgb, var(--swa-color) 55%, transparent );
	filter: brightness(1.05);
}
.swa-send:active:not(:disabled) { transform: scale(.94); }
.swa-send:disabled { opacity: .45; cursor: default; box-shadow: none; }

/* Theme resets often apply `svg{width:auto}` which, inside our flex buttons,
   collapses the icon to 0 width (invisible). Pin explicit dimensions so the
   send + launcher icons always render regardless of the host theme. */
.swa-send svg { width: 20px; height: 20px; flex-shrink: 0; }
.swa-launcher svg { width: 34px; height: 34px; flex-shrink: 0; }

.swa-branding {
	text-align: center;
	font-size: 11px;
	color: #9aa1ad;
	padding: 4px 0 8px;
	background: #fff;
}

/* ---- Mobile ---- */
@media (max-width: 480px) {
	.swa-mode-floating .swa-panel {
		width: 100vw;
		max-width: 100vw;
		height: 85vh;
		max-height: 85vh;
		right: 0;
		left: 0;
		bottom: 0;
		border-radius: 16px 16px 0 0;
	}
}
