/**
 * KnowScapes AI Client — front-end widget styles.
 *
 * Layout properties on the launcher carry !important because several themes
 * (Neve among them) set global button dimensions that would otherwise distort
 * the round launcher into an oval and hide the icon.
 */

#knowscapes-ai-client-root,
.ksaic-root {
	--ksaic-accent: #4f46e5;
	--ksaic-bg: #ffffff;
	--ksaic-fg: #1f2328;
	--ksaic-muted: #6b7280;
	--ksaic-border: #e5e7eb;
	--ksaic-user-bg: var(--ksaic-accent);
	--ksaic-user-fg: #ffffff;
	--ksaic-assist-bg: #f3f4f6;
	--ksaic-assist-fg: #1f2328;
	--ksaic-shadow: 0 12px 32px rgba(0, 0, 0, .18);
	font-size: 14px;
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
}

#knowscapes-ai-client-root[data-theme="dark"],
.ksaic-root[data-theme="dark"] {
	--ksaic-bg: #1b1e24;
	--ksaic-fg: #e6e8eb;
	--ksaic-muted: #9ba1a9;
	--ksaic-border: #2c313a;
	--ksaic-assist-bg: #262b33;
	--ksaic-assist-fg: #e6e8eb;
	--ksaic-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}

.ksaic-launcher {
	position: fixed !important;
	right: var(--ksaic-offset, 20px) !important;
	bottom: var(--ksaic-offset, 20px) !important;
	z-index: 99999 !important;
	width: 56px !important;
	height: 56px !important;
	border-radius: 50% !important;
	background: var(--ksaic-accent) !important;
	color: #fff !important;
	border: none !important;
	cursor: pointer !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	box-shadow: var(--ksaic-shadow) !important;
	transition: transform .15s ease !important;
	padding: 0 !important;
	margin: 0 !important;
	box-sizing: content-box !important;
}

.ksaic-launcher:hover {
	transform: scale(1.05);
}

.ksaic-launcher[hidden] {
	display: none !important;
}

.ksaic-panel {
	position: fixed;
	right: var(--ksaic-offset, 20px);
	bottom: var(--ksaic-offset, 20px);
	z-index: 99999;
	box-sizing: border-box; /* Firefox clips border-box panels otherwise. */
	width: 370px;
	max-width: calc(100vw - 24px);
	height: 560px;
	max-height: calc(100vh - 40px);
	background: var(--ksaic-bg);
	color: var(--ksaic-fg);
	border: 1px solid var(--ksaic-border);
	border-radius: 16px;
	box-shadow: var(--ksaic-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.ksaic-panel[hidden] {
	display: none;
}

.ksaic-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 14px;
	background: var(--ksaic-accent);
	color: #fff;
}

.ksaic-title {
	font-weight: 600;
	font-size: 15px;
}

.ksaic-close {
	background: transparent;
	border: none;
	color: #fff;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
}

.ksaic-log {
	flex: 1;
	overflow-y: auto;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.ksaic-msg {
	display: flex;
}

.ksaic-msg-user {
	justify-content: flex-end;
}

.ksaic-msg-assistant {
	justify-content: flex-start;
}

.ksaic-bubble {
	max-width: 82%;
	padding: 8px 12px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.ksaic-msg-user .ksaic-bubble {
	background: var(--ksaic-user-bg);
	color: var(--ksaic-user-fg);
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}

.ksaic-msg-assistant .ksaic-bubble {
	background: var(--ksaic-assist-bg);
	color: var(--ksaic-assist-fg);
	border-bottom-left-radius: 4px;
}

.ksaic-pending .ksaic-bubble::after {
	content: '\275A';
	animation: ksaic-blink 1s steps(2) infinite;
	color: var(--ksaic-muted);
}

.ksaic-pending .ksaic-bubble:has(.ksaic-dots)::after {
	display: none;
}

@keyframes ksaic-blink {
	50% {
		opacity: 0;
	}
}

.ksaic-dots {
	display: inline-flex;
	gap: 5px;
	align-items: center;
	padding: 2px 0;
}

.ksaic-dots span {
	display: block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--ksaic-muted);
	animation: ksaic-dot-pulse 1.2s ease-in-out infinite;
}

.ksaic-dots span:nth-child(2) {
	animation-delay: .2s;
}

.ksaic-dots span:nth-child(3) {
	animation-delay: .4s;
}

@keyframes ksaic-dot-pulse {
	0%, 80%, 100% {
		transform: scale(.75);
		opacity: .4;
	}

	40% {
		transform: scale(1);
		opacity: 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	.ksaic-launcher,
	.ksaic-dots span,
	.ksaic-pending .ksaic-bubble::after {
		transition: none;
		animation: none;
	}
}

.ksaic-think {
	margin-bottom: 8px;
	font-size: 12.5px;
	color: var(--ksaic-muted);
	border-left: 2px solid var(--ksaic-border);
	padding-left: 8px;
}

.ksaic-think summary {
	cursor: pointer;
	user-select: none;
}

.ksaic-think-body {
	margin-top: 4px;
}

.ksaic-markdown > *:first-child {
	margin-top: 0;
}

.ksaic-markdown > *:last-child {
	margin-bottom: 0;
}

.ksaic-markdown p {
	margin: 0 0 8px;
}

.ksaic-markdown h1,
.ksaic-markdown h2,
.ksaic-markdown h3 {
	font-size: 1.02em;
	margin: 10px 0 6px;
	font-weight: 600;
}

.ksaic-markdown ul,
.ksaic-markdown ol {
	margin: 0 0 8px;
	padding-left: 20px;
}

.ksaic-markdown li {
	margin: 2px 0;
}

.ksaic-markdown a {
	color: var(--ksaic-accent);
	text-decoration: underline;
}

.ksaic-markdown code {
	background: rgba(127, 127, 127, .16);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: .9em;
}

.ksaic-markdown pre {
	background: rgba(127, 127, 127, .14);
	padding: 10px;
	border-radius: 8px;
	overflow-x: auto;
	margin: 0 0 8px;
}

.ksaic-markdown pre code {
	background: none;
	padding: 0;
}

.ksaic-markdown table {
	border-collapse: collapse;
	font-size: .92em;
}

.ksaic-markdown th,
.ksaic-markdown td {
	border: 1px solid var(--ksaic-border);
	padding: 4px 8px;
}

.ksaic-markdown blockquote {
	margin: 0 0 8px;
	padding-left: 10px;
	border-left: 3px solid var(--ksaic-border);
	color: var(--ksaic-muted);
}

.ksaic-input {
	display: flex;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid var(--ksaic-border);
	align-items: flex-end;
	box-sizing: border-box; /* Keeps the padding inside the panel width. */
}

.ksaic-textarea {
	flex: 1;
	min-width: 0; /* Stops the textarea overflowing its flex container. */
	resize: none;
	border: 1px solid var(--ksaic-border);
	border-radius: 10px;
	padding: 8px 10px;
	font: inherit;
	font-size: 14px;
	background: var(--ksaic-bg);
	color: var(--ksaic-fg);
	max-height: 120px;
	outline: none;
	box-sizing: border-box;
}

.ksaic-textarea:focus {
	border-color: var(--ksaic-accent);
}

.ksaic-send {
	flex: 0 0 38px; /* Fixed basis keeps the button out of flow calculations. */
	width: 38px;
	height: 38px;
	min-width: 38px;
	border-radius: 10px;
	border: none;
	background: var(--ksaic-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: visible; /* Stops themes clipping the icon inside the button. */
}

.ksaic-send svg {
	display: block;
	flex-shrink: 0;
}

.ksaic-send:disabled {
	opacity: .5;
	cursor: default;
}

@media (max-width: 480px) {
	.ksaic-launcher {
		right: max(16px, env(safe-area-inset-right)) !important;
		bottom: max(16px, env(safe-area-inset-bottom)) !important;
	}

	.ksaic-panel {
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100vh;
		/* stylelint-disable-next-line declaration-block-no-duplicate-properties */
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		right: auto;
		bottom: auto;
	}

	.ksaic-header {
		padding-top: max(12px, env(safe-area-inset-top));
		padding-left: max(14px, env(safe-area-inset-left));
		padding-right: max(14px, env(safe-area-inset-right));
	}

	.ksaic-input {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
		padding-left: max(10px, env(safe-area-inset-left));
		padding-right: max(10px, env(safe-area-inset-right));
	}

	.ksaic-textarea {
		font-size: 16px;
	}

	.ksaic-send {
		flex: 0 0 44px;
		width: 44px;
		height: 44px;
		min-width: 44px;
	}

	.ksaic-close {
		font-size: 28px;
		padding: 4px 8px;
	}
}

/* ── Launcher on the left instead of the right ───────────────────────────── */

.ksaic-side-left .ksaic-launcher {
	right: auto !important;
	left: var(--ksaic-offset, 20px) !important;
}

.ksaic-side-left .ksaic-panel {
	right: auto;
	left: var(--ksaic-offset, 20px);
}

/* ── Hidden on small screens, when the site owner asked for that ─────────── */

@media (max-width: 600px) {
	.ksaic-hide-mobile {
		display: none !important;
	}
}

/* ── Inline chat placed with the shortcode ───────────────────────────────────
 *
 * Same panel, taken out of the fixed corner and put into the flow of the page.
 * The height comes from the shortcode, with a floor so a mistyped value cannot
 * collapse the chat to nothing.
 */

.ksaic-root-inline {
	display: block;
	margin: 1.5em 0;
}

.ksaic-root-inline .ksaic-panel {
	position: static;
	right: auto;
	bottom: auto;
	width: 100%;
	max-width: 100%;
	height: var(--ksaic-inline-height, 480px);
	min-height: 240px;
	max-height: none;
	z-index: auto;
}

/* ── Starter questions in the empty chat ─────────────────────────────────── */

.ksaic-starters {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 2px;
}

.ksaic-starter {
	font: inherit;
	font-size: 13px;
	line-height: 1.4;
	text-align: left;
	background: transparent;
	color: var(--ksaic-accent);
	border: 1px solid var(--ksaic-border);
	border-radius: 14px;
	padding: 6px 10px;
	cursor: pointer;
	max-width: 100%;
}

.ksaic-starter:hover,
.ksaic-starter:focus-visible {
	background: var(--ksaic-assist-bg);
	border-color: var(--ksaic-accent);
}

/* ── The row under a finished reply ──────────────────────────────────────── */

.ksaic-actions {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 6px;
}

.ksaic-copy {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	background: transparent;
	border: none;
	border-radius: 6px;
	color: var(--ksaic-muted);
	cursor: pointer;
	opacity: .7;
}

.ksaic-copy:hover,
.ksaic-copy:focus-visible {
	opacity: 1;
	background: var(--ksaic-border);
}

.ksaic-copy.ksaic-copied {
	color: var(--ksaic-accent);
	opacity: 1;
}

/* Note under a reply the model could not finish inside the length cap. */
.ksaic-cut-short {
	font-size: 12px;
	font-style: italic;
	color: var(--ksaic-muted);
	line-height: 1.3;
}

/* ── Avatars, drawn locally — no avatar service is ever contacted ───────── */

.ksaic-msg {
	gap: 8px;
	align-items: flex-end;
}

.ksaic-avatar {
	flex: 0 0 28px;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
}

.ksaic-avatar-assistant {
	background: var(--ksaic-accent);
}

.ksaic-avatar-user {
	background: var(--ksaic-assist-bg);
	color: var(--ksaic-muted);
	border: 1px solid var(--ksaic-border);
}

/* AI notice: always visible between the conversation and the input. */
.ksaic-root .ksaic-ai-notice {
	display: block !important;
	visibility: visible !important;
	margin: 0;
	padding: 6px 12px;
	font-size: 11.5px;
	line-height: 1.35;
	color: var(--ksaic-muted);
	border-top: 1px solid var(--ksaic-border);
	text-align: center;
}
