/**
 * Novin Smart Assessment — AI assistant widget.
 *
 * Every rule is scoped under .nsa-ai-root. This widget renders on every page of
 * the site, on top of a theme this file has never seen, so a single unscoped
 * selector here would be a site-wide bug — and one that only shows up on the
 * pages nobody tested.
 *
 * Institutional rather than playful: navy and cyan from the site, one accent,
 * flat surfaces, short transitions. No glassmorphism and no full-panel
 * gradients — a chat window that looks like a consumer app undercuts the thing
 * it is there to sell.
 */

.nsa-ai-root {
	--nsa-ai-navy: #07365f;
	--nsa-ai-navy-deep: #052841;
	--nsa-ai-cyan: #128aa5;
	--nsa-ai-cyan-soft: #e6f4f8;
	--nsa-ai-text: #16202b;
	--nsa-ai-muted: #6b7785;
	--nsa-ai-border: #e3e8ee;
	--nsa-ai-surface: #ffffff;
	--nsa-ai-canvas: #f7f9fb;
	--nsa-ai-danger: #b4232a;
	--nsa-ai-ok: #04735c;

	--nsa-ai-radius: 16px;
	--nsa-ai-radius-sm: 10px;
	--nsa-ai-shadow: 0 18px 48px rgba(5, 26, 44, .18), 0 2px 6px rgba(5, 26, 44, .08);

	position: fixed;
	inset-block-end: 24px;
	inset-inline-start: 24px;

	/*
	 * Just under the signed 32-bit maximum. Sticky headers, cookie bars and
	 * page-builder overlays routinely sit at 99999, and losing that contest
	 * means the launcher is rendered, painted and completely unclickable —
	 * which looks identical to not being there at all.
	 */
	z-index: 2147483000;

	/* Defensive: a theme rule matching a bare div must not hide the widget. */
	display: block;
	visibility: visible;
	opacity: 1;
	pointer-events: auto;

	direction: rtl;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.95;
	color: var(--nsa-ai-text);
	text-align: start;
}

.nsa-ai-root *,
.nsa-ai-root *::before,
.nsa-ai-root *::after {
	box-sizing: border-box;
}

.nsa-ai-root :focus-visible {
	outline: 2px solid var(--nsa-ai-cyan);
	outline-offset: 2px;
	border-radius: 6px;
}

/* ============================================================ launcher */

/*
 * A 58px circle, not a pill. The pill it replaced read as an advertisement and
 * covered a strip of every page; a circular launcher is the convention people
 * already know, and it stops competing with the content behind it.
 */
.nsa-ai-root .nsa-ai-launcher {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 58px;
	height: 58px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(145deg, var(--nsa-ai-navy) 0%, var(--nsa-ai-cyan) 130%);
	color: #fff;
	font: inherit;
	cursor: pointer;
	box-shadow: 0 10px 26px rgba(5, 26, 44, .28);
	transition: transform .18s ease, box-shadow .18s ease;
}

.nsa-ai-root .nsa-ai-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 14px 32px rgba(5, 26, 44, .34);
}

.nsa-ai-root .nsa-ai-launcher:active {
	transform: translateY(0);
}

.nsa-ai-root .nsa-ai-launcher svg {
	width: 25px;
	height: 25px;
}

/* The badge says "there is something here", without a number nobody earned. */
.nsa-ai-root .nsa-ai-badge {
	position: absolute;
	inset-block-start: 2px;
	inset-inline-end: 2px;
	width: 12px;
	height: 12px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: #23c08a;
}

/* Label on hover only, so the resting state stays a small circle. */
.nsa-ai-root .nsa-ai-tip {
	position: absolute;
	inset-block-end: 50%;
	inset-inline-start: calc(100% + 10px);
	transform: translateY(50%) translateX(6px);
	padding: 6px 12px;
	border-radius: 999px;
	background: var(--nsa-ai-navy-deep);
	color: #fff;
	font-size: 12.5px;
	font-weight: 600;
	white-space: nowrap;
	opacity: 0;
	pointer-events: none;
	transition: opacity .16s ease, transform .16s ease;
}

.nsa-ai-root .nsa-ai-launcher:hover .nsa-ai-tip,
.nsa-ai-root .nsa-ai-launcher:focus-visible .nsa-ai-tip {
	opacity: 1;
	transform: translateY(50%) translateX(0);
}

/* =============================================================== panel */

.nsa-ai-root .nsa-ai-panel {
	display: flex;
	flex-direction: column;
	width: 390px;
	height: 620px;
	max-height: 75vh;
	max-width: calc(100vw - 32px);
	overflow: hidden;
	background: var(--nsa-ai-surface);
	border: 1px solid var(--nsa-ai-border);
	border-radius: var(--nsa-ai-radius);
	box-shadow: var(--nsa-ai-shadow);
	animation: nsa-ai-in .18s ease-out;
}

@keyframes nsa-ai-in {
	from { opacity: 0; transform: translateY(8px) scale(.99); }
	to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------- header */

.nsa-ai-root .nsa-ai-head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: var(--nsa-ai-navy);
	color: #fff;
	flex: none;
}

.nsa-ai-root .nsa-ai-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	flex: none;
	border-radius: 10px;
	background: rgba(255, 255, 255, .13);
}

.nsa-ai-root .nsa-ai-avatar svg { width: 19px; height: 19px; }

.nsa-ai-root .nsa-ai-head-text { flex: 1; min-width: 0; line-height: 1.5; }

.nsa-ai-root .nsa-ai-head-title {
	display: block;
	font-size: 14px;
	font-weight: 700;
}

.nsa-ai-root .nsa-ai-head-status {
	display: flex;
	align-items: center;
	gap: 5px;
	font-size: 11.5px;
	opacity: .82;
}

.nsa-ai-root .nsa-ai-dot {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #23c08a;
	flex: none;
}

.nsa-ai-root .nsa-ai-close {
	width: 32px;
	height: 32px;
	flex: none;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: #fff;
	font: inherit;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	transition: background .16s ease;
}

.nsa-ai-root .nsa-ai-close:hover { background: rgba(255, 255, 255, .16); }

/* ---------------------------------------------------------------- log */

.nsa-ai-root .nsa-ai-log {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 14px;
	background: var(--nsa-ai-canvas);
	display: flex;
	flex-direction: column;
	gap: 14px;
	scrollbar-width: thin;
}

.nsa-ai-root .nsa-ai-log::-webkit-scrollbar { width: 8px; }
.nsa-ai-root .nsa-ai-log::-webkit-scrollbar-thumb {
	background: #d5dde5;
	border-radius: 8px;
}

.nsa-ai-root .nsa-ai-msg {
	max-width: 90%;
	font-size: 14px;
	line-height: 2;
	animation: nsa-ai-msg-in .16s ease-out;
}

@keyframes nsa-ai-msg-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: none; }
}

.nsa-ai-root .nsa-ai-bubble {
	padding: 11px 14px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-break: break-word;
}

.nsa-ai-root .nsa-ai-msg--user {
	align-self: flex-start;
	max-width: 82%;
}

.nsa-ai-root .nsa-ai-msg--user .nsa-ai-bubble {
	background: var(--nsa-ai-navy);
	color: #fff;
	border-end-start-radius: 5px;
}

/* The assistant speaks on white; the visitor is the coloured one. Inverting
 * that makes every answer look like a promotion. */
.nsa-ai-root .nsa-ai-msg--bot { align-self: flex-end; }

.nsa-ai-root .nsa-ai-msg--bot .nsa-ai-bubble {
	background: var(--nsa-ai-surface);
	border: 1px solid var(--nsa-ai-border);
	border-end-end-radius: 5px;
	color: var(--nsa-ai-text);
}

/* --------------------------------------------------- sources (chips) */

.nsa-ai-root .nsa-ai-sources { margin-top: 8px; }

.nsa-ai-root .nsa-ai-sources-toggle {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 4px 10px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: 999px;
	background: var(--nsa-ai-surface);
	color: var(--nsa-ai-muted);
	font: inherit;
	font-size: 12px;
	cursor: pointer;
}

.nsa-ai-root .nsa-ai-sources-toggle:hover {
	border-color: var(--nsa-ai-cyan);
	color: var(--nsa-ai-cyan);
}

.nsa-ai-root .nsa-ai-sources-toggle svg {
	width: 11px;
	height: 11px;
	transition: transform .16s ease;
}

.nsa-ai-root .nsa-ai-sources[open] .nsa-ai-sources-toggle svg { transform: rotate(180deg); }

.nsa-ai-root .nsa-ai-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 8px;
}

.nsa-ai-root .nsa-ai-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	max-width: 100%;
	padding: 5px 10px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: 8px;
	background: var(--nsa-ai-surface);
	color: var(--nsa-ai-text);
	font-size: 12px;
	line-height: 1.7;
	text-decoration: none;
}

.nsa-ai-root .nsa-ai-chip:hover {
	border-color: var(--nsa-ai-cyan);
	background: var(--nsa-ai-cyan-soft);
}

.nsa-ai-root .nsa-ai-chip-host {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	max-width: 190px;
	direction: ltr;
}

/* The tier is shown, because "gov.uk" and "someblog.com" are not the same
 * claim and the visitor deserves to see which one this was. */
.nsa-ai-root .nsa-ai-chip-tier {
	flex: none;
	padding: 1px 6px;
	border-radius: 5px;
	background: var(--nsa-ai-cyan-soft);
	color: var(--nsa-ai-cyan);
	font-size: 10.5px;
	font-weight: 700;
}

/* ------------------------------------------------- related (Novin CTA) */

.nsa-ai-root .nsa-ai-related {
	margin-top: 10px;
	padding: 11px 12px;
	border: 1px solid var(--nsa-ai-border);
	border-inline-start: 3px solid var(--nsa-ai-cyan);
	border-radius: var(--nsa-ai-radius-sm);
	background: var(--nsa-ai-surface);
}

.nsa-ai-root .nsa-ai-related-title {
	display: block;
	margin-bottom: 2px;
	font-size: 12.5px;
	font-weight: 800;
	color: var(--nsa-ai-navy);
}

.nsa-ai-root .nsa-ai-related-hint {
	display: block;
	margin-bottom: 7px;
	font-size: 11.5px;
	color: var(--nsa-ai-muted);
}

.nsa-ai-root .nsa-ai-related-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.nsa-ai-root .nsa-ai-related-list li { margin: 4px 0; }

.nsa-ai-root .nsa-ai-related-list a {
	display: flex;
	align-items: baseline;
	gap: 6px;
	color: var(--nsa-ai-text);
	font-size: 12.5px;
	text-decoration: none;
}

.nsa-ai-root .nsa-ai-related-list a:hover { color: var(--nsa-ai-cyan); }

.nsa-ai-root .nsa-ai-related-kind {
	flex: none;
	font-size: 10.5px;
	font-weight: 700;
	color: var(--nsa-ai-muted);
}

.nsa-ai-root .nsa-ai-cta {
	display: block;
	margin-top: 9px;
	padding: 9px 14px;
	border-radius: var(--nsa-ai-radius-sm);
	background: var(--nsa-ai-cyan);
	color: #fff;
	font-size: 12.5px;
	font-weight: 700;
	text-align: center;
	text-decoration: none;
	transition: background .16s ease;
}

.nsa-ai-root .nsa-ai-cta:hover { background: #0f7690; color: #fff; }

/* ------------------------------------------------------ quick actions */

.nsa-ai-root .nsa-ai-quick {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-self: flex-end;
	max-width: 100%;
}

.nsa-ai-root .nsa-ai-quick button {
	padding: 6px 12px;
	border: 1px solid #cfe3ea;
	border-radius: 999px;
	background: var(--nsa-ai-surface);
	color: var(--nsa-ai-cyan);
	font: inherit;
	font-size: 12.5px;
	font-weight: 600;
	cursor: pointer;
	transition: background .16s ease, border-color .16s ease;
}

.nsa-ai-root .nsa-ai-quick button:hover {
	background: var(--nsa-ai-cyan-soft);
	border-color: var(--nsa-ai-cyan);
}

/* ------------------------------------------------- typing / states */

.nsa-ai-root .nsa-ai-typing {
	align-self: flex-end;
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 14px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: 14px;
	border-end-end-radius: 5px;
	background: var(--nsa-ai-surface);
	color: var(--nsa-ai-muted);
	font-size: 12.5px;
}

.nsa-ai-root .nsa-ai-dots { display: inline-flex; gap: 3px; }

.nsa-ai-root .nsa-ai-dots i {
	width: 5px;
	height: 5px;
	border-radius: 50%;
	background: var(--nsa-ai-cyan);
	animation: nsa-ai-pulse 1.1s infinite ease-in-out;
}

.nsa-ai-root .nsa-ai-dots i:nth-child(2) { animation-delay: .16s; }
.nsa-ai-root .nsa-ai-dots i:nth-child(3) { animation-delay: .32s; }

@keyframes nsa-ai-pulse {
	0%, 80%, 100% { opacity: .25; transform: translateY(0); }
	40%           { opacity: 1; transform: translateY(-3px); }
}

.nsa-ai-root .nsa-ai-note {
	align-self: center;
	max-width: 92%;
	padding: 9px 12px;
	border: 1px solid #f0d8d8;
	border-radius: var(--nsa-ai-radius-sm);
	background: #fdf6f6;
	color: var(--nsa-ai-danger);
	font-size: 12.5px;
	text-align: center;
}

.nsa-ai-root .nsa-ai-note--ok {
	border-color: #cbe8df;
	background: #f2fbf8;
	color: var(--nsa-ai-ok);
}

.nsa-ai-root .nsa-ai-note button {
	margin-inline-start: 8px;
	padding: 3px 10px;
	border: 1px solid currentColor;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-size: 12px;
	cursor: pointer;
}

/* -------------------------------------------------------------- lead */

.nsa-ai-root .nsa-ai-lead {
	align-self: stretch;
	padding: 13px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: var(--nsa-ai-radius-sm);
	background: var(--nsa-ai-surface);
}

.nsa-ai-root .nsa-ai-lead h4 {
	margin: 0 0 2px;
	font-size: 13.5px;
	font-weight: 800;
	color: var(--nsa-ai-navy);
}

.nsa-ai-root .nsa-ai-lead p {
	margin: 0 0 10px;
	font-size: 12px;
	color: var(--nsa-ai-muted);
	line-height: 1.8;
}

.nsa-ai-root .nsa-ai-lead input {
	width: 100%;
	margin-bottom: 7px;
	padding: 10px 12px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: var(--nsa-ai-radius-sm);
	background: #fff;
	color: var(--nsa-ai-text);
	font: inherit;
	font-size: 13px;
}

.nsa-ai-root .nsa-ai-lead input:focus { border-color: var(--nsa-ai-cyan); }

.nsa-ai-root .nsa-ai-lead-actions { display: flex; gap: 8px; }

.nsa-ai-root .nsa-ai-lead-actions button {
	flex: 1;
	padding: 10px;
	border: 0;
	border-radius: var(--nsa-ai-radius-sm);
	background: var(--nsa-ai-navy);
	color: #fff;
	font: inherit;
	font-size: 13px;
	font-weight: 700;
	cursor: pointer;
}

.nsa-ai-root .nsa-ai-lead-actions .nsa-ai-skip {
	flex: 0 0 auto;
	background: transparent;
	color: var(--nsa-ai-muted);
	font-weight: 500;
}

.nsa-ai-root .nsa-ai-lead-error {
	margin: 6px 0 0;
	color: var(--nsa-ai-danger);
	font-size: 12px;
}

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

.nsa-ai-root .nsa-ai-form {
	position: sticky;
	inset-block-end: 0;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	flex: none;
	padding: 10px 12px;
	border-top: 1px solid var(--nsa-ai-border);
	background: var(--nsa-ai-surface);
}

.nsa-ai-root .nsa-ai-input {
	flex: 1;
	min-width: 0;
	max-height: 112px;
	padding: 10px 13px;
	border: 1px solid var(--nsa-ai-border);
	border-radius: 12px;
	background: var(--nsa-ai-canvas);
	color: var(--nsa-ai-text);
	font: inherit;
	font-size: 13.5px;
	line-height: 1.8;
	resize: none;
	overflow-y: auto;
}

.nsa-ai-root .nsa-ai-input:focus {
	border-color: var(--nsa-ai-cyan);
	background: #fff;
}

.nsa-ai-root .nsa-ai-send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	flex: none;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: var(--nsa-ai-navy);
	color: #fff;
	cursor: pointer;
	transition: background .16s ease, opacity .16s ease;
}

.nsa-ai-root .nsa-ai-send:hover:not([disabled]) { background: var(--nsa-ai-cyan); }

.nsa-ai-root .nsa-ai-send[disabled] {
	opacity: .45;
	cursor: not-allowed;
}

/* The arrow is mirrored by the RTL context, so it is drawn pointing "forward". */
.nsa-ai-root .nsa-ai-send svg { width: 18px; height: 18px; }

/* The honeypot. Off-screen rather than display:none, which bots skip. */
.nsa-ai-root .nsa-ai-hp {
	position: absolute;
	inset-inline-start: -9999px;
	width: 1px;
	height: 1px;
	opacity: 0;
}

/* ========================================================== responsive */

@media (max-width: 520px) {
	.nsa-ai-root {
		inset-block-end: 16px;
		inset-inline-start: 16px;
	}

	/* Near-fullscreen on a phone: a 390px panel on a 360px screen is a panel
	 * with its edges cut off. */
	.nsa-ai-root.is-open {
		inset: 0;
	}

	.nsa-ai-root.is-open .nsa-ai-panel {
		width: 100%;
		height: 100%;
		max-width: none;
		max-height: none;
		border: 0;
		border-radius: 0;
	}

	.nsa-ai-root .nsa-ai-msg { max-width: 94%; }
}

@media (max-height: 600px) {
	.nsa-ai-root .nsa-ai-panel { max-height: 88vh; }
}

@media (prefers-reduced-motion: reduce) {
	.nsa-ai-root .nsa-ai-panel,
	.nsa-ai-root .nsa-ai-msg { animation: none; }

	.nsa-ai-root .nsa-ai-launcher { transition: none; }
	.nsa-ai-root .nsa-ai-launcher:hover { transform: none; }
	.nsa-ai-root .nsa-ai-dots i { animation: none; opacity: .6; }
}
