/**
 * AI Knowledge Base — frontend chat widget styles.
 *
 * Every color/spacing token is a CSS custom property scoped to `.aikb-chat`
 * / `.aikb-bubble`, defaulting to a light theme with a `prefers-color-scheme`
 * dark fallback. This is the extension point the Appearance customizer (a
 * later phase) hooks into: it only ever needs to override these properties
 * on a specific instance, never rewrite these rules.
 */

.aikb-chat {
	--aikb-bg: #ffffff;
	--aikb-fg: #1f2328;
	--aikb-muted: #6b7280;
	--aikb-border: #e5e7eb;
	--aikb-accent: #2563eb;
	--aikb-accent-fg: #ffffff;
	--aikb-user-bubble-bg: var(--aikb-accent);
	--aikb-user-bubble-fg: var(--aikb-accent-fg);
	--aikb-assistant-bubble-bg: #f3f4f6;
	--aikb-assistant-bubble-fg: var(--aikb-fg);
	--aikb-error-bg: #fef2f2;
	--aikb-error-fg: #b91c1c;
	--aikb-radius: 12px;
	--aikb-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
	--aikb-code-font: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
	--aikb-font-size: 14px;

	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	min-height: 320px;
	max-height: 100%;
	background: var(--aikb-bg);
	color: var(--aikb-fg);
	border: 1px solid var(--aikb-border);
	border-radius: var(--aikb-radius);
	font-family: var(--aikb-font);
	font-size: var(--aikb-font-size);
	line-height: 1.5;
	overflow: hidden;
}

.aikb-chat--theme-dark {
	--aikb-bg: #16181d;
	--aikb-fg: #e5e7eb;
	--aikb-muted: #9ca3af;
	--aikb-border: #2a2e37;
	--aikb-assistant-bubble-bg: #23262e;
	--aikb-assistant-bubble-fg: var(--aikb-fg);
	--aikb-error-bg: #3a1a1a;
	--aikb-error-fg: #fca5a5;
}

.aikb-chat--theme-glass {
	--aikb-bg: rgba(255, 255, 255, 0.6);
	--aikb-assistant-bubble-bg: rgba(255, 255, 255, 0.45);
	--aikb-border: rgba(255, 255, 255, 0.35);
	backdrop-filter: blur(18px) saturate(160%);
	-webkit-backdrop-filter: blur(18px) saturate(160%);
}

.aikb-chat--theme-minimal {
	--aikb-border: rgba(127, 127, 127, 0.14);
	--aikb-assistant-bubble-bg: transparent;
	--aikb-radius: 4px;
}

@media (prefers-color-scheme: dark) {
	.aikb-chat:not([class*='aikb-chat--theme-']) {
		--aikb-bg: #16181d;
		--aikb-fg: #e5e7eb;
		--aikb-muted: #9ca3af;
		--aikb-border: #2a2e37;
		--aikb-assistant-bubble-bg: #23262e;
		--aikb-assistant-bubble-fg: var(--aikb-fg);
		--aikb-error-bg: #3a1a1a;
		--aikb-error-fg: #fca5a5;
	}
}

.aikb-chat *,
.aikb-chat *::before,
.aikb-chat *::after {
	box-sizing: border-box;
}

.aikb-chat__header {
	flex: 0 0 auto;
	padding: 12px 16px;
	border-bottom: 1px solid var(--aikb-border);
	font-weight: 600;
}

.aikb-chat__title {
	display: block;
}

.aikb-chat__messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.aikb-chat__message {
	display: flex;
	flex-direction: column;
	gap: 6px;
	max-width: 88%;
}

.aikb-chat__message--user {
	align-self: flex-end;
}

.aikb-chat__message--assistant {
	align-self: flex-start;
}

.aikb-chat__bubble {
	padding: 10px 14px;
	border-radius: var(--aikb-radius);
	overflow-wrap: break-word;
	word-break: break-word;
}

.aikb-chat__message--user .aikb-chat__bubble {
	background: var(--aikb-user-bubble-bg);
	color: var(--aikb-user-bubble-fg);
	border-bottom-right-radius: 4px;
}

.aikb-chat__message--assistant .aikb-chat__bubble {
	background: var(--aikb-assistant-bubble-bg);
	color: var(--aikb-assistant-bubble-fg);
	border-bottom-left-radius: 4px;
}

.aikb-chat__message--error .aikb-chat__bubble {
	background: var(--aikb-error-bg);
	color: var(--aikb-error-fg);
}

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

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

.aikb-chat__bubble p,
.aikb-chat__bubble ul,
.aikb-chat__bubble ol,
.aikb-chat__bubble blockquote,
.aikb-chat__bubble h1,
.aikb-chat__bubble h2,
.aikb-chat__bubble h3,
.aikb-chat__bubble h4,
.aikb-chat__bubble pre {
	margin: 0 0 8px;
}

.aikb-chat__bubble h1,
.aikb-chat__bubble h2,
.aikb-chat__bubble h3,
.aikb-chat__bubble h4 {
	line-height: 1.3;
	font-weight: 600;
}

.aikb-chat__bubble h1 {
	font-size: 1.25em;
}

.aikb-chat__bubble h2 {
	font-size: 1.15em;
}

.aikb-chat__bubble h3,
.aikb-chat__bubble h4 {
	font-size: 1.05em;
}

.aikb-chat__bubble ul,
.aikb-chat__bubble ol {
	padding-left: 1.4em;
}

.aikb-chat__bubble li {
	margin-bottom: 4px;
}

.aikb-chat__bubble blockquote {
	margin-left: 0;
	padding: 4px 12px;
	border-left: 3px solid var(--aikb-border);
	color: var(--aikb-muted);
}

.aikb-chat__bubble hr {
	border: none;
	border-top: 1px solid var(--aikb-border);
	margin: 12px 0;
}

.aikb-chat__bubble a {
	color: var(--aikb-accent);
}

.aikb-chat__bubble code {
	font-family: var(--aikb-code-font);
	font-size: 0.9em;
	background: rgba(127, 127, 127, 0.16);
	padding: 0.1em 0.35em;
	border-radius: 4px;
}

.aikb-code-block {
	margin: 0 0 8px;
	padding: 10px 12px;
	border-radius: 8px;
	background: rgba(127, 127, 127, 0.12);
	overflow-x: auto;
}

.aikb-code-block .aikb-code {
	background: none;
	padding: 0;
	font-family: var(--aikb-code-font);
	font-size: 0.85em;
	line-height: 1.5;
	white-space: pre;
}

.aikb-tok-comment {
	color: var(--aikb-muted);
	font-style: italic;
}

.aikb-tok-string {
	color: #16794f;
}

.aikb-tok-number {
	color: #b45309;
}

.aikb-tok-keyword {
	color: #7c3aed;
	font-weight: 600;
}

.aikb-chat--theme-dark .aikb-tok-string {
	color: #6ee7b7;
}

.aikb-chat--theme-dark .aikb-tok-number {
	color: #fbbf24;
}

.aikb-chat--theme-dark .aikb-tok-keyword {
	color: #c4b5fd;
}

@media (prefers-color-scheme: dark) {
	.aikb-chat:not([class*='aikb-chat--theme-']) .aikb-tok-string {
		color: #6ee7b7;
	}

	.aikb-chat:not([class*='aikb-chat--theme-']) .aikb-tok-number {
		color: #fbbf24;
	}

	.aikb-chat:not([class*='aikb-chat--theme-']) .aikb-tok-keyword {
		color: #c4b5fd;
	}
}

.aikb-chat__typing {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	padding: 2px 0;
}

.aikb-chat__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.35;
	animation: aikb-typing 1.2s infinite ease-in-out;
}

.aikb-chat__typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.aikb-chat__typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes aikb-typing {
	0%, 80%, 100% {
		opacity: 0.35;
		transform: translateY(0);
	}

	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

.aikb-chat__sources {
	margin-top: 6px;
	font-size: 0.85em;
	color: var(--aikb-muted);
}

.aikb-chat__sources summary {
	cursor: pointer;
	user-select: none;
}

.aikb-chat__sources ul {
	margin: 6px 0 0;
	padding-left: 1.2em;
}

.aikb-chat__sources a {
	color: var(--aikb-accent);
}

.aikb-chat__actions {
	display: flex;
	gap: 6px;
	margin-top: 6px;
}

.aikb-chat__action {
	border: 1px solid var(--aikb-border);
	background: transparent;
	color: var(--aikb-muted);
	border-radius: 6px;
	padding: 3px 8px;
	font-size: 0.8em;
	cursor: pointer;
	line-height: 1.4;
}

.aikb-chat__action:hover {
	background: rgba(127, 127, 127, 0.12);
	color: var(--aikb-fg);
}

.aikb-chat__action:disabled {
	cursor: default;
	opacity: 0.6;
}

.aikb-chat__action.is-active {
	border-color: var(--aikb-accent);
	color: var(--aikb-accent);
}

.aikb-chat__suggestions {
	flex: 0 0 auto;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 16px 12px;
}

.aikb-chat__suggestions[hidden] {
	display: none;
}

.aikb-chat__suggestion {
	border: 1px solid var(--aikb-border);
	background: var(--aikb-assistant-bubble-bg);
	color: var(--aikb-fg);
	border-radius: 999px;
	padding: 6px 12px;
	font-size: 0.85em;
	cursor: pointer;
}

.aikb-chat__suggestion:hover {
	border-color: var(--aikb-accent);
	color: var(--aikb-accent);
}

.aikb-chat__form {
	flex: 0 0 auto;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid var(--aikb-border);
}

.aikb-chat__input {
	flex: 1 1 auto;
	resize: none;
	max-height: 140px;
	min-height: 38px;
	padding: 8px 12px;
	border: 1px solid var(--aikb-border);
	border-radius: 8px;
	background: var(--aikb-bg);
	color: var(--aikb-fg);
	font: inherit;
}

.aikb-chat__input:focus {
	outline: 2px solid var(--aikb-accent);
	outline-offset: -1px;
}

.aikb-chat__send {
	flex: 0 0 auto;
	border: none;
	background: var(--aikb-accent);
	color: var(--aikb-accent-fg);
	border-radius: 8px;
	padding: 9px 16px;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.aikb-chat__send:hover {
	filter: brightness(1.08);
}

/*
 * Floating bubble: wraps a `.aikb-chat` instance in a fixed-position
 * toggle + panel. Positioning only — the widget inside looks identical to
 * an embedded shortcode/block instance.
 */
.aikb-bubble {
	position: fixed;
	z-index: 999999;
	bottom: 20px;
}

.aikb-bubble--bottom-right {
	right: 20px;
}

.aikb-bubble--bottom-left {
	left: 20px;
}

.aikb-bubble__panel {
	position: absolute;
	bottom: 72px;
	width: min(380px, calc(100vw - 40px));
	height: min(600px, calc(100vh - 120px));
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
	border-radius: 12px;
	overflow: hidden;
}

.aikb-bubble--bottom-right .aikb-bubble__panel {
	right: 0;
}

.aikb-bubble--bottom-left .aikb-bubble__panel {
	left: 0;
}

.aikb-bubble__panel[hidden] {
	display: none;
}

.aikb-bubble__panel .aikb-chat {
	width: 100%;
	height: 100%;
	border-radius: 12px;
}

.aikb-bubble__toggle {
	position: relative;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--aikb-bubble-accent, #2563eb);
	color: #ffffff;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.aikb-bubble__toggle svg {
	position: absolute;
}

.aikb-bubble__icon-close {
	opacity: 0;
	transform: scale(0.6);
	transition: opacity 0.15s ease, transform 0.15s ease;
}

.aikb-bubble__icon-open {
	opacity: 1;
	transform: scale(1);
	transition: opacity 0.15s ease, transform 0.15s ease;
}

.aikb-bubble.is-open .aikb-bubble__icon-open {
	opacity: 0;
	transform: scale(0.6);
}

.aikb-bubble.is-open .aikb-bubble__icon-close {
	opacity: 1;
	transform: scale(1);
}

@media (max-width: 480px) {
	.aikb-bubble__panel {
		width: calc(100vw - 24px);
		height: calc(100vh - 140px);
	}

	.aikb-bubble--bottom-right,
	.aikb-bubble--bottom-left {
		right: 12px;
		left: 12px;
		bottom: 12px;
	}

	.aikb-bubble__toggle {
		margin-left: auto;
	}
}
