:root {
	--ai-chat-primary: #E4023A;
	--ai-chat-primary-dark: #C30232;
	--ai-chat-text-on-primary: #fff;
	--ai-chat-bg: #fff;
	--ai-chat-secondary-bg: #f5f5f5;
	--ai-chat-border: #e0e0e0;
}

/* ── Popup shell ─────────────────────────────────────────────────────── */

.ai-chatbox-wrapper {
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 9999;
	font-family: inherit;
}

.ai-action-btn {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
	transition: background 0.2s ease;
}
.ai-action-btn:hover { background: var(--ai-chat-primary-dark); }

.ai-action-chat {
	display: none;
	flex-direction: column;
	position: absolute;
	right: 0;
	bottom: 72px;
	width: 520px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 120px);
	background: var(--ai-chat-bg);
	border-radius: 0;
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
	overflow: hidden;
}

/* The panel is anchored bottom-right (right:0/bottom:72px), so growing its
   width/height extends it up and to the left - the resize grip lives in that
   top-left corner, not the bottom-right corner a native CSS `resize: both`
   handle would use (which would sit right on top of the anchor point and be
   awkward to drag meaningfully). */
/* User-supplied dashed diagonal resize-arrow glyph (fill baked in as white,
   rather than relying on currentColor resolution inside a background-image
   data URI). The icon's native arrowhead points up-right; rotate(-90deg)
   turns it up-left, matching this handle's own corner and the direction
   dragging it actually grows the window (up and to the left - see the
   .ai-action-chat comment above). Inset top/left rather than flush at 0/0
   so it sits as far from the corner as the close button does from its own
   corner (.ai-header's 12px/16px padding + that button's own 2px padding),
   for visual symmetry with the top-right close icon rather than looking
   jammed into the raw window edge. */
.ai-chat-resize-handle {
	position: absolute;
	top: 14px;
	left: 18px;
	width: 18px;
	height: 18px;
	cursor: nwse-resize;
	z-index: 10;
	background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48cGF0aCBmaWxsPSIjZmZmIiBkPSJtMjkgMzBsMSA5MGgzNlY2NmgyNlYzMHptOTkgMHYzNmg3MlYzMHptMTA4IDB2MzZoNzJWMzB6bTEwOCAwdjM2aDcyVjMwem0xMDIgMHY3OGgzNlYzMHptLTIwNiA4MHYzNmgxMDAuNTQzbC0xMTggMTE4SDMwdjIxOGgyMThWMjg5LjQ1N2wxMTgtMTE4VjI3MmgzNlYxMTB6bTIwNiAzNHY3MmgzNnYtNzJ6TTMwIDE1NnY3MmgzNnYtNzJ6bTQxNiA5NnY3MmgzNnYtNzJ6bTAgMTA4djcyaDM2di03MnptLTE2NiA4NnYzNmg3MnYtMzZ6bTEwOCAwdjM2aDcydi0zNnoiLz48L3N2Zz4=");
	background-size: contain;
	background-repeat: no-repeat;
	transform: rotate(-90deg);
	opacity: 0.85;
	transition: opacity 0.15s ease;
}
.ai-chat-resize-handle:hover {
	opacity: 1;
}
.ai-action-chat.show { display: flex; }

.ai-header {
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	padding: 12px 16px;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	position: relative;
}
/* Centered on the header's own full width via absolute positioning, not
   flex auto-margins - the actions div's width varies (the clear button is
   only shown once there's a real conversation), so centering relative to
   the remaining flex space after actions would shift the title sideways
   the moment that button appears. Absolute + translateX keeps it fixed
   regardless. */
.ai-header h3 {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	pointer-events: none;
}
.ai-header-actions { display: flex; align-items: center; gap: 4px; }
.ai-header button {
	background: none;
	border: none;
	color: inherit;
	cursor: pointer;
	display: flex;
	align-items: center;
	padding: 2px;
}

/* ── Messages ────────────────────────────────────────────────────────── */

.ai-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

/* The embed can be placed inside a page's own content-styling wrapper (e.g.
   research.tpl's .apply-research-styles-small), which sets font-size/
   line-height/color on every plain <div>/<p>/<li> via broad selectors like
   ".apply-research-styles-small div" - and, for color specifically, this
   site's own manual dark-mode toggle (darkmode.js's ".dark" class, distinct
   from the OS-level "prefers-color-scheme" media query below) adds a second,
   even more specific layer: ".dark .apply-research-styles-small div". Rather
   than rely on stylesheet load order (fragile - this embed can be dropped
   into any page), every rule here is deliberately specificity-padded to sit
   safely above both:
     - layout/type (max-width, padding, font-size, line-height): compounded
       with the role class -> two classes (".ai-chat-message.ai-chat-message-
       user"), beats the host's "class + element" tier.
     - color/background/links: additionally ancestor-qualified with the
       messages container -> three classes, beats the host's own dark-mode
       "two classes + element" tier too, in either color scheme. */
.ai-chat-message.ai-chat-message-user,
.ai-chat-message.ai-chat-message-assistant {
	max-width: 85%;
	padding: 8px 12px;
	border-radius: 10px;
	font-size: 14px;
	line-height: 1.4;
	word-wrap: break-word;
	margin: 0;
}
.ai-chat-messages .ai-chat-message.ai-chat-message-user,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-user {
	align-self: flex-end;
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
}
.ai-chat-messages .ai-chat-message.ai-chat-message-assistant,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-assistant {
	align-self: flex-start;
	background: var(--ai-chat-secondary-bg);
	color: #222;
}
.ai-chat-messages .ai-chat-message.ai-chat-message-user a,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-user a,
.ai-chat-messages .ai-chat-message.ai-chat-message-assistant a,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-assistant a {
	color: inherit;
	text-decoration: underline;
}
/* Same host-page leak as everywhere else in this file, hitting the <ul>/<li>
   safeFormat() now emits for markdown bullet lists - research.tpl's
   .apply-research-styles-small sets its own font-size/line-height/color/
   margin directly on "li"/"ul" (0,1,1 specificity, beating a bare single
   class), which is exactly the sudden 14px-to-16px jump mid-message a
   screenshot caught. Same two-tier fix as the <a> rule above: layout
   compounded with the role class (two classes, beats the host's class+
   element tier); color additionally ancestor-qualified (three classes, beats
   the host's ".dark"-qualified two-classes-plus-element tier too). */
.ai-chat-message.ai-chat-message-user ul,
.ai-chat-message.ai-chat-message-assistant ul,
.ai-chat-message.ai-chat-message-user li,
.ai-chat-message.ai-chat-message-assistant li {
	font-size: 14px;
	line-height: 1.4;
	margin: 0 0 4px;
	padding-left: 0;
}
.ai-chat-message.ai-chat-message-user ul,
.ai-chat-message.ai-chat-message-assistant ul {
	margin: 4px 0;
	padding-left: 20px;
	list-style-position: outside;
}
.ai-chat-message.ai-chat-message-user li:last-child,
.ai-chat-message.ai-chat-message-assistant li:last-child {
	margin-bottom: 0;
}
.ai-chat-messages .ai-chat-message.ai-chat-message-user li,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-user li,
.ai-chat-messages .ai-chat-message.ai-chat-message-assistant li,
.ai-chat-embed-messages .ai-chat-message.ai-chat-message-assistant li {
	color: inherit;
}

/* Shown inside the assistant bubble from the moment it's created until real
   content replaces it (ai-chat-core.js's send()) - previously that gap (which
   can be several real seconds while tool calls resolve) had no visible
   indicator at all, just an empty bubble. `background: currentColor` picks up
   whatever text color the bubble already correctly resolves to (light/dark
   both handled by the existing message-color rules above), so this needs no
   color rule of its own. */
.ai-chat-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 2px 0;
}
.ai-chat-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.4;
	animation: ai-chat-typing-bounce 1.2s infinite ease-in-out;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-chat-typing-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
	30% { transform: translateY(-4px); opacity: 1; }
}

/* Sample-query chips rendered inside the greeting bubble (ai-chat-embed.js's
   buildGreetingHtml, opt-in via data-sample-queries) - quick-reply-style
   suggestions as part of the welcome message, rather than a separate row
   above the widget. */
.ai-chat-message.ai-chat-message-assistant .ai-chat-greeting-text {
	margin-bottom: 8px;
	/* Same host-page leak as everywhere else in this file: a plain nested
	   <div> with no font-size of its own is directly matched by the host's
	   broad ".apply-research-styles-small div" rule (16-20px) - the outer
	   bubble's own 14px hardening doesn't cascade down to override a
	   separate direct match on this inner div. */
	font-size: 14px;
	line-height: 1.4;
}
.ai-chat-message.ai-chat-message-assistant .ai-chat-sample-queries {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}
.ai-chat-message.ai-chat-message-assistant .ai-chat-sample-chip {
	font-size: 13px;
	line-height: 1.3;
	color: inherit;
	background: rgba(0, 0, 0, 0.05);
	border: 1px solid rgba(0, 0, 0, 0.14);
	border-radius: 999px;
	padding: 6px 12px;
	cursor: pointer;
	text-align: left;
}
.ai-chat-message.ai-chat-message-assistant .ai-chat-sample-chip:hover {
	background: rgba(0, 0, 0, 0.09);
}

.ai-chat-confirmation {
	align-self: stretch;
	background: var(--ai-chat-secondary-bg);
	border: 1px solid var(--ai-chat-border);
	border-radius: 10px;
	padding: 10px 12px;
	font-size: 14px;
}
.ai-chat-confirmation p { margin: 0 0 8px; }
.ai-chat-confirmation-actions { display: flex; gap: 8px; }
.ai-chat-confirmation-actions button {
	flex: 1;
	padding: 6px 10px;
	border-radius: 6px;
	border: 1px solid var(--ai-chat-border);
	background: var(--ai-chat-bg);
	cursor: pointer;
	font-size: 13px;
}
.ai-chat-confirmation-actions button:first-child {
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	border-color: var(--ai-chat-primary);
}

/* ── Input ───────────────────────────────────────────────────────────── */

.ai-chat-input-container {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--ai-chat-border);
}
/* Explicit background+color, not left to inherit/default - `color` is an
   inherited property (a dark-mode `color:#fff` further up the tree reaches
   this plain <input> with nothing here to stop it) while `background` never
   inherits and was never set here either, so the input silently kept the
   browser's native white background under inherited light text - exactly a
   light-on-light input in dark mode, reported live. */
/* Explicit height + border-box on both this and the send button below, not
   left to each element's own intrinsic sizing (padding + native form-control
   line-height for the input vs. a bare fixed width/height for the button) -
   those two sizing methods don't reliably land on the same pixel height as
   each other, which is exactly the misalignment reported live. Same fixed
   height + border-box on both guarantees an exact match regardless. */
.ai-chat-input {
	flex: 1;
	box-sizing: border-box;
	height: 40px;
	border: 1px solid var(--ai-chat-border);
	border-radius: 0;
	padding: 0 14px;
	font-size: 14px;
	outline: none;
	background: var(--ai-chat-bg);
	color: #222;
}
.ai-chat-send-btn {
	box-sizing: border-box;
	width: 40px;
	height: 40px;
	border-radius: 0;
	border: none;
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.ai-chat-send-btn:disabled { opacity: 0.6; cursor: default; }

.ai-chat-disclaimer {
	padding: 0 12px 8px;
	text-align: center;
}
/* Doubled-class specificity, same host-page-leak reason as the embed's
   container divs below - this only actually matters in the embed placement
   (research.tpl's .apply-research-styles-small), but applying it everywhere
   is harmless and keeps this file's pattern consistent, rather than
   special-casing it per placement. */
.ai-chat-disclaimer.ai-chat-disclaimer {
	font-size: 11px;
	line-height: 1.4;
	margin: 0;
	color: #888;
}

/* ── Anonymous "log in to chat" inline link ─────────────────────────────
   Sits in the exact same slot the input+send button occupy when logged in
   (ai_chat.tpl's .ai-chat-input-container, ai-chat-embed.js's
   .ai-chat-embed-input) - the rest of the chrome (header, greeting,
   disclaimer) stays visible and identical for an anonymous visitor, only
   this one row changes, so the widget still reads as "the real thing" and
   works as an effective teaser rather than going blank. Square corners
   deliberately, matching the site's own corner language - this replaces an
   earlier pill-shaped, full-panel version. Same height/box-sizing treatment
   as .ai-chat-input/.ai-chat-send-btn above so it lines up exactly when it's
   the sole child of their shared flex row. */
.ai-chat-login-link {
	flex: 1;
	box-sizing: border-box;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	text-decoration: none;
	font-size: 14px;
	border-radius: 0;
}
/* Research embed wraps in .apply-research-styles-small, whose broad "a"
   (and ".dark"-qualified "a") selectors would otherwise leak color/underline
   into this link exactly like every other embed element in this file -
   compounded 3 classes deep, same technique used for the message bubbles. */
.ai-chat-embed .ai-chat-login-link.ai-chat-login-link {
	color: var(--ai-chat-text-on-primary);
	text-decoration: none;
}

/* ── Inline embed variant ────────────────────────────────────────────── */

.ai-chat-embed {
	display: flex;
	flex-direction: column;
	height: auto;
	min-height: 50px;
	border: 1px solid var(--ai-chat-border);
	border-radius: 0;
	overflow: hidden;
	background: var(--ai-chat-bg);
}
/* Collapsed is the plain CSS default - no class needed - so there is no gap
   between the page's initial render and JS running where the embed would
   flash open at full height before folding. Only expanding needs a class,
   added by ai-chat-embed.js's toggle click handler.
   resize:vertical + overflow:auto let a visitor drag it taller if they want -
   .ai-chat-embed-messages is a flex:1 child with its own overflow-y:auto, so
   resizing this outer box just changes how much conversation is visible at
   once, header/input stay a fixed height. This 2-class selector safely wins
   over the base .ai-chat-embed rule above regardless of source order (not an
   equal-specificity tie, unlike the event-page block's own override, which
   needs 3 classes specifically because it has to out-rank this exact rule
   from a separate, later-loading stylesheet). */
.ai-chat-embed.ai-chat-embed-expanded {
	height: 420px;
	min-height: 260px;
	max-height: 90vh;
	resize: vertical;
	overflow: auto;
}

/* Same host-page leak as .ai-chat-message above, hitting these container
   <div>s directly (each is independently matched by .apply-research-styles-
   small's broad div selectors, 0,1,1 specificity beating each one's bare
   single class) rather than just cascading into them. Two separate host
   rules are involved: one sets font-size/line-height (which these divs don't
   visibly show themselves, but DO pass down to any child that doesn't set
   its own, e.g. the "Send" button); the other - confirmed via DevTools'
   computed box model, not guessed - sets `margin-bottom: 30px` on every
   plain div, which is what actually created the oversized gap below the
   input row reported in testing (line-height was a real but ultimately
   unrelated leak from the same host page). Doubled class selectors, same
   specificity-padding technique used for .ai-chat-login-link above - none of
   these divs have another class to compound with. */
.ai-chat-embed.ai-chat-embed,
.ai-chat-embed-header.ai-chat-embed-header,
.ai-chat-embed-header-actions.ai-chat-embed-header-actions,
.ai-chat-embed-messages.ai-chat-embed-messages,
.ai-chat-embed-input.ai-chat-embed-input {
	font-size: 14px;
	line-height: 1.4;
	margin: 0;
}

/* Same red header treatment as the popup's .ai-header, so a visitor sees one
   consistent "this is Kuppi" visual identity regardless of placement. */
.ai-chat-embed-header {
	background: var(--ai-chat-primary);
	display: flex;
	align-items: center;
	justify-content: flex-end;
	padding: 10px 12px;
}
/* Same host-page-leak concern as everywhere else in this file - `color` on a
   bare single class loses to .apply-research-styles-small's "div" selector.
   The title span and icon buttons use `color: inherit`/no color of their
   own, so they need their nearest *actual* ancestor div to resolve to white -
   .ai-chat-embed-header-actions sits directly between the header and the
   icon buttons and is ITSELF a plain div independently matched by the same
   host rule, so it needs its own override too - fixing the header alone
   isn't enough, since inheritance only looks at the immediate parent's
   resolved color, not "the nearest ancestor with an explicit rule". */
.ai-chat-embed-header.ai-chat-embed-header,
.ai-chat-embed-header-actions.ai-chat-embed-header-actions {
	color: var(--ai-chat-text-on-primary);
}
.ai-chat-embed-header-with-title { justify-content: space-between; }
.ai-chat-embed-title {
	font-size: 14px;
	font-weight: 600;
}
/* min-height reserves space for a 28px icon (the toggle's own size, see
   .ai-chat-embed-toggle below) even when no icon is currently rendered here -
   without it, an always-expanded embed with no toggle button (data-always-
   expanded) has nothing but the ~17px title text holding this row's height
   until the clear button's JS-driven inline style (ai-chat-core.js) flips it
   visible once there's a real conversation, visibly growing the header at
   that moment instead of staying a constant height throughout. */
.ai-chat-embed-header-actions { display: flex; align-items: center; gap: 4px; min-height: 28px; }
/* Clearing only makes sense once there's a visible conversation to clear -
   hidden while folded (the plain default, see .ai-chat-embed-expanded below),
   alongside the messages/input it acts on. */
.ai-chat-embed-clear {
	background: none;
	border: none;
	color: inherit;
	cursor: pointer;
	align-items: center;
	padding: 2px;
	display: none;
}
.ai-chat-embed.ai-chat-embed-expanded .ai-chat-embed-clear { display: flex; }
/* The toggle is the primary call-to-action while collapsed (it's the whole
   way in to a collapsed embed) - deliberately larger and more visually
   distinct than the secondary "clear chat" utility icon next to it, rather
   than matching its small, understated size. */
.ai-chat-embed-toggle {
	background: rgba(255, 255, 255, 0.15);
	border: none;
	border-radius: 50%;
	color: inherit;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
}
.ai-chat-embed-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.ai-chat-embed-toggle svg { transition: transform 0.2s ease; }
.ai-chat-embed.ai-chat-embed-expanded .ai-chat-embed-toggle svg { transform: rotate(180deg); }

/* Hidden by the same plain-CSS-default logic as .ai-chat-embed-clear above -
   only shown once .ai-chat-embed-expanded is added. */
.ai-chat-embed-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	flex-direction: column;
	gap: 8px;
	display: none;
}
.ai-chat-embed.ai-chat-embed-expanded .ai-chat-embed-messages { display: flex; }
.ai-chat-embed-input {
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--ai-chat-border);
	display: none;
}
.ai-chat-embed.ai-chat-embed-expanded .ai-chat-embed-input { display: flex; }
/* Only relevant once there's an actual input box in view - same collapsed-by-
   default reasoning as the messages/input themselves, scoped to the embed
   placement only (the popup always shows it whenever the chat is open at
   all, no collapse state there). */
.ai-chat-embed .ai-chat-disclaimer { display: none; }
.ai-chat-embed.ai-chat-embed-expanded .ai-chat-disclaimer { display: block; }
/* Same fix as .ai-chat-input above, same reason: an inherited dark-mode
   `color` with no background ever set here of its own. */
/* Same explicit-height + border-box fix as .ai-chat-input/.ai-chat-send-btn
   above, same reason - this input's intrinsic (padding-derived) height and
   this button's padding-derived height don't reliably match each other
   without both being pinned to the same fixed height. */
.ai-chat-embed-input input {
	flex: 1;
	box-sizing: border-box;
	height: 40px;
	border: 1px solid var(--ai-chat-border);
	border-radius: 0;
	padding: 0 14px;
	font-size: 14px;
	outline: none;
	background: var(--ai-chat-bg);
	color: #222;
}
.ai-chat-embed-input button {
	box-sizing: border-box;
	height: 40px;
	padding: 0 16px;
	border-radius: 0;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	cursor: pointer;
	font-size: 14px;
}

@media (prefers-color-scheme: dark) {
	.ai-chatbox-wrapper, .ai-chat-embed {
		--ai-chat-bg: #1e1e1e;
		--ai-chat-secondary-bg: #2a2a2a;
		--ai-chat-border: #3a3a3a;
	}
	.ai-chat-messages .ai-chat-message.ai-chat-message-assistant,
	.ai-chat-embed-messages .ai-chat-message.ai-chat-message-assistant { color: #eee; }
	.ai-chat-input,
	.ai-chat-embed-input input { color: #eee; }
}

/* Report pages, logged in: the popup's switch between this report's assistant and the site-wide one
   (ai_chat.tpl #aiChatScope, ai-chat-popup.js) - a small segmented control under the header */
.ai-chat-scope.ai-chat-scope {
	display: flex;
	justify-content: center;
	gap: 0;
	margin: 0;
	padding: 8px 12px;
	border-bottom: 1px solid var(--ai-chat-border);
	background: var(--ai-chat-bg);
}
.ai-chat-scope button {
	flex: none;
	padding: 5px 14px;
	border: 1px solid var(--ai-chat-border);
	background: var(--ai-chat-bg);
	color: #555;
	font-size: 13px;
	line-height: 1.4;
	cursor: pointer;
}
.ai-chat-scope button + button { border-left: none; }
.ai-chat-scope button:first-child { border-radius: 4px 0 0 4px; }
.ai-chat-scope button:last-child { border-radius: 0 4px 4px 0; }
.ai-chat-scope button[aria-pressed="true"] {
	border-color: var(--ai-chat-primary);
	background: var(--ai-chat-primary);
	color: var(--ai-chat-text-on-primary);
	font-weight: 600;
}
.ai-chat-scope button:disabled { cursor: wait; opacity: 0.6; }
.ai-chat-scope button:focus-visible { outline: 2px solid var(--ai-chat-primary); outline-offset: 2px; }
