/**
 * FFA Brand Assistant — persistent widget styles.
 *
 * Colours come from theme.json where the theme provides them, with FFA blue as
 * the fallback so the widget stays on-brand on a site that has not defined them.
 */

.ffaba {
	--ffaba-blue: var( --wp--preset--color--ffa-blue, #004c97 );
	--ffaba-surface: #ffffff;
	--ffaba-text: #1a1a1a;
	--ffaba-line: rgba( 0, 0, 0, 0.12 );

	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.75rem;
	/* 14px, not 16: answers are several sentences long and the panel is small,
	   so the larger size forced constant scrolling. rem-based controls
	   (launcher, rating, citations) are root-relative and keep their size. */
	font-size: 14px;
	line-height: 1.5;
}

/* Launcher */

.ffaba__launcher {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	height: 56px;
	padding: 0 1.25rem 0 0.5rem;
	border: 0;
	border-radius: 28px;
	background: var( --ffaba-blue );
	color: #fff;
	font: inherit;
	font-weight: 700;
	box-shadow: 0 4px 16px rgba( 0, 0, 0, 0.25 );
	cursor: pointer;
	transition: transform 0.15s ease;
}

.ffaba__launcher:hover {
	transform: scale( 1.04 );
}

.ffaba__launcher img {
	width: 40px;
	height: 40px;
	display: block;
	flex: 0 0 auto;
}

.ffaba__launchertext {
	white-space: nowrap;
	font-size: 1rem;
	line-height: 1;
}

/* Panel — hidden until opened, and kept out of the tab order while closed. */

.ffaba__panel {
	display: none;
	flex-direction: column;
	width: min( 380px, calc( 100vw - 2.5rem ) );
	height: min( 540px, calc( 100vh - 8rem ) );
	background: var( --ffaba-surface );
	color: var( --ffaba-text );
	border-radius: 12px;
	box-shadow: 0 12px 40px rgba( 0, 0, 0, 0.28 );
	overflow: hidden;
}

.ffaba.is-open .ffaba__panel {
	display: flex;
}

.ffaba__header {
	display: flex;
	align-items: center;
	gap: 0.625rem;
	padding: 0.75rem 1rem;
	background: var( --ffaba-blue );
	color: #fff;
}

.ffaba__avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
}

.ffaba__title {
	font-weight: 700;
	flex: 1;
}

.ffaba__close {
	background: none;
	border: 0;
	color: #fff;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
	padding: 0 0.25rem;
}

.ffaba__log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
	padding: 1rem;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.ffaba__row {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
}

.ffaba__row--user {
	justify-content: flex-end;
}

.ffaba__msgavatar {
	flex: 0 0 auto;
	width: 28px;
	height: 28px;
	border-radius: 50%;
}

.ffaba__msg {
	padding: 0.625rem 0.875rem;
	border-radius: 12px;
	max-width: 82%;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.ffaba__msg--bot {
	background: rgba( 0, 76, 151, 0.07 );
	border-bottom-left-radius: 4px;
}

/* Answers render a small Markdown subset, so the bubble holds real elements
   rather than a single text node. Collapse the outer margins so a one-paragraph
   answer sits flush in the bubble. */

.ffaba__msg > :first-child {
	margin-top: 0;
}

.ffaba__msg > :last-child {
	margin-bottom: 0;
}

.ffaba__msg p {
	margin: 0 0 0.625rem;
}

.ffaba__msg ul {
	margin: 0 0 0.625rem;
	padding-left: 1.125rem;
}

.ffaba__msg li {
	margin: 0 0 0.25rem;
}

.ffaba__msg--user {
	background: var( --ffaba-blue );
	color: #fff;
	border-bottom-right-radius: 4px;
}

.ffaba__cites {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.25rem;
	margin-top: 0.625rem;
	padding-top: 0.5rem;
	border-top: 1px solid rgba( 0, 0, 0, 0.08 );
	font-size: 0.8125rem;
}

.ffaba__cite {
	opacity: 0.75;
}

.ffaba__cite--link {
	color: var( --ffaba-blue );
	font-weight: 600;
	opacity: 1;
	text-decoration: underline;
}

.ffaba__cite--link::after {
	content: " →";
	text-decoration: none;
}

/*
 * Was-this-helpful control. Sits quietly under the answer: no colour, no icons,
 * small type. It should read as available rather than asked for.
 */
.ffaba__rating {
	display: flex;
	align-items: center;
	gap: 0.375rem;
	margin-top: 0.5rem;
	font-size: 0.8125rem;
	opacity: 0.7;
}

.ffaba__rating-label {
	margin-right: 0.125rem;
}

.ffaba__rating-btn {
	padding: 0.125rem 0.5rem;
	border: 1px solid rgba( 0, 0, 0, 0.15 );
	border-radius: 999px;
	background: none;
	color: inherit;
	font: inherit;
	line-height: 1.5;
	cursor: pointer;
}

.ffaba__rating-btn:hover,
.ffaba__rating-btn:focus-visible {
	border-color: var( --ffaba-blue );
	color: var( --ffaba-blue );
}

.ffaba__form {
	display: flex;
	gap: 0.5rem;
	padding: 0.75rem 1rem;
	border-top: 1px solid var( --ffaba-line );
}

.ffaba__form input {
	flex: 1;
	min-width: 0;
	padding: 0.5rem 0.75rem;
	border: 1px solid var( --ffaba-line );
	border-radius: 6px;
	font: inherit;
	color: inherit;
}

.ffaba__form button {
	padding: 0.5rem 1rem;
	border: 0;
	border-radius: 6px;
	background: var( --ffaba-blue );
	color: #fff;
	font: inherit;
	cursor: pointer;
}

.ffaba__form input:disabled,
.ffaba__form button:disabled {
	opacity: 0.6;
}

.ffaba__note {
	margin: 0;
	padding: 0 1rem 0.75rem;
	font-size: 0.75rem;
	opacity: 0.7;
}

.ffaba__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	white-space: nowrap;
}

/* On small screens the panel takes the viewport, which is the only way a
   380px panel stays usable next to a mobile keyboard. */

@media ( max-width: 480px ) {
	.ffaba {
		right: 1rem;
		bottom: 1rem;
	}

	.ffaba.is-open {
		inset: 0;
		right: 0;
		bottom: 0;
	}

	.ffaba.is-open .ffaba__panel {
		width: 100vw;
		height: 100vh;
		border-radius: 0;
	}

	.ffaba.is-open .ffaba__launcher {
		display: none;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.ffaba__launcher {
		transition: none;
	}
}
