/*
 * Foundry Agent Chat — front-end styles.
 *
 * Every color/size is driven through a CSS custom property with a sensible
 * fallback, e.g. var(--fac-accent, #c41e3a). A theme can restyle the whole
 * widget without fighting specificity by declaring the variables it wants to
 * change, for example:
 *
 *   :root {
 *     --fac-accent: #7c3aed;
 *     --fac-assistant-bg: #eef2ff;
 *     --fac-font-size: 0.875rem;
 *   }
 *
 * Font-family inherits from the theme by default; font-size defaults to 0.9rem
 * so the chat is denser than typical theme body text. Override via --fac-font-size.
 */

.foundry-agent-chat {
	--fac-accent: #c41e3a;
	--fac-accent-contrast: #fff;
	--fac-bg: #ffffff;
	--fac-color: #111827;
	--fac-muted: #6b7280;
	--fac-border-color: #e5e7eb;
	--fac-assistant-bg: #f3f4f6;
	--fac-assistant-color: #111827;
	--fac-user-bg: var(--fac-accent);
	--fac-user-color: #fff;
	--fac-input-bg: #f3f4f6;
	--fac-bubble-radius: 18px;
	--fac-card-radius: 14px;

	max-width: var(--fac-max-width, 760px);
	width: 100%;
	box-sizing: border-box;
	border: 1px solid var(--fac-border-color);
	border-radius: var(--fac-radius, 10px);
	background: var(--fac-bg);
	color: var(--fac-color);
	font-family: var(--fac-font-family, inherit);
	font-size: var(--fac-font-size, 0.9rem);
	display: flex;
	flex-direction: column;
}

/* Drawer layout: shortcode root is a zero-size mount point; visible UI is portaled. */
.foundry-agent-chat--drawer {
	border: 0;
	border-radius: 0;
	background: transparent;
	max-width: none;
	width: 0;
	height: 0;
	overflow: visible;
	padding: 0;
	margin: 0;
}

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

/* --- Header / brand --- */

.foundry-agent-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 16px 14px;
	border-bottom: 1px solid var(--fac-border-color);
	gap: 12px;
}

.foundry-agent-chat__brand {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.foundry-agent-chat__avatar {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(
		--fac-avatar-bg,
		linear-gradient(
			145deg,
			var(--fac-avatar-gradient-start, #ef4b5c) 0%,
			var(--fac-accent, #c41e3a) 48%,
			var(--fac-avatar-gradient-end, #8f1028) 100%
		)
	);
	color: var(--fac-accent-contrast);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.foundry-agent-chat__brand-text {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1 1 auto;
}

.foundry-agent-chat__title-row {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	min-height: var(--fac-title-row-height, calc(0.8em + 14px));
	flex-wrap: nowrap;
	line-height: 1;
	overflow: visible;
}

.foundry-agent-chat__title {
	font-weight: 700;
	font-size: 1.05em;
	line-height: 1;
	color: var(--fac-color);
	flex: 0 1 auto;
	min-width: 0;
	margin: 0;
}

.foundry-agent-chat__header-auth {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-width: 0;
	flex: 1 1 auto;
	line-height: 1;
	overflow: visible;
}

.foundry-agent-chat__title-row .foundry-agent-chat__account {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	line-height: 1;
	margin: 0;
	min-width: 0;
	max-width: 100%;
	overflow: hidden;
}

.foundry-agent-chat__title-row .foundry-agent-chat__account-name {
	flex: 1 1 auto;
	min-width: 0;
	line-height: 1;
	margin: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.foundry-agent-chat__title-row .foundry-agent-chat__signin,
.foundry-agent-chat__title-row .foundry-agent-chat__signout {
	display: inline-flex;
	align-items: center;
	line-height: 1;
	margin: 0;
	font-family: inherit;
	flex-shrink: 0;
}

.foundry-agent-chat__title-row .foundry-agent-chat__signin {
	white-space: nowrap;
}

.foundry-agent-chat__header-auth .foundry-agent-chat__account {
	color: var(--fac-muted);
}

.foundry-agent-chat__header-auth .foundry-agent-chat__signout:hover {
	color: var(--fac-color, #111827);
}

.foundry-agent-chat__subtitle {
	font-size: 0.8em;
	line-height: 1.35;
	color: var(--fac-muted);
}

.foundry-agent-chat__signin {
	background: none;
	border: 1px solid var(--fac-accent);
	box-sizing: border-box;
	color: var(--fac-accent);
	cursor: pointer;
	font-size: 0.8em;
	line-height: 1;
	padding: 5px 10px;
	border-radius: 999px;
	white-space: nowrap;
}

.foundry-agent-chat__signin:hover:not(:disabled) {
	background: var(--fac-accent);
	color: var(--fac-accent-contrast);
}

.foundry-agent-chat__signin:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.foundry-agent-chat__signin:focus-visible,
.foundry-agent-chat__signout:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 0;
}

.foundry-agent-chat__account {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-size: 0.8em;
	color: var(--fac-muted);
	min-width: 0;
	max-width: 100%;
}

.foundry-agent-chat__account-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.foundry-agent-chat__signout {
	background: none;
	border: 0;
	color: var(--fac-accent);
	cursor: pointer;
	font-size: inherit;
	padding: 0;
	text-decoration: underline;
	white-space: nowrap;
}

.foundry-agent-chat__header-actions {
	flex-shrink: 0;
	align-self: center;
	display: inline-flex;
	align-items: center;
	/* Wide gap so a tap aimed at Close rarely lands on Clear. */
	gap: var(--fac-header-actions-gap, 16px);
}

.foundry-agent-chat__clear-icon {
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--fac-muted);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
	padding: 0;
}

.foundry-agent-chat__clear-icon:hover {
	background: var(--fac-assistant-bg);
	color: var(--fac-accent);
}

.foundry-agent-chat__clear-icon:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

.foundry-agent-chat__close {
	flex-shrink: 0;
	align-self: center;
	width: 36px;
	height: 36px;
	border: 0;
	border-radius: 50%;
	background: var(--fac-assistant-bg);
	color: #374151;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
	padding: 0;
}

.foundry-agent-chat__close:hover {
	background: #e5e7eb;
	color: var(--fac-color);
}

.foundry-agent-chat__close:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

/* --- Messages --- */

.foundry-agent-chat__messages {
	height: var(--fac-messages-height, 360px);
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.foundry-agent-chat__welcome {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.foundry-agent-chat__turn {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 10px;
	max-width: 100%;
}

.foundry-agent-chat__message {
	padding: 12px 14px;
	border-radius: var(--fac-bubble-radius);
	max-width: 92%;
	line-height: 1.45;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.foundry-agent-chat__message p {
	margin: 0 0 8px;
}

.foundry-agent-chat__message p:last-child {
	margin-bottom: 0;
}

.foundry-agent-chat__message ul,
.foundry-agent-chat__message ol {
	margin: 0 0 8px;
	padding-left: 20px;
	list-style-position: outside !important;
}

/*
 * Set on li itself, not just its ul/ol parent — a theme rule targeting `li`
 * directly (e.g. a WordPress theme's own `li { list-style: none; }` reset,
 * confirmed live 2026-07-29) always wins over an inherited list-style-type
 * from the parent regardless of that parent's own specificity or !important:
 * inheritance is the fallback of last resort, not a competing declaration, so
 * it loses to ANY explicit rule on the element itself, however weak. Setting
 * list-style-type here, on li, is what actually needs !important — the ul/ol
 * rule above was never the level the fight was happening at.
 */
.foundry-agent-chat__message ul li {
	list-style-type: disc !important;
}

.foundry-agent-chat__message ol li {
	list-style-type: decimal !important;
}

.foundry-agent-chat__message li:not(:last-child) {
	margin-bottom: 2px;
}

/*
 * Explicit font-weight here isn't decorative — some themes (e.g. Twenty
 * Twenty-Five) reset h1-h6 site-wide to font-weight: 400, and without our
 * own weight these headings would be visually indistinguishable from body
 * text regardless of font-size.
 */
.foundry-agent-chat__message h3,
.foundry-agent-chat__message h4,
.foundry-agent-chat__message h5,
.foundry-agent-chat__message h6 {
	margin: 14px 0 4px;
	line-height: 1.3;
	font-weight: var(--fac-heading-weight, 700);
	color: var(--fac-heading-color, inherit);
}

.foundry-agent-chat__message h3:first-child,
.foundry-agent-chat__message h4:first-child,
.foundry-agent-chat__message h5:first-child,
.foundry-agent-chat__message h6:first-child {
	margin-top: 0;
}

.foundry-agent-chat__message h3 {
	font-size: 1.2em;
}

.foundry-agent-chat__message h4 {
	font-size: 1.1em;
}

.foundry-agent-chat__message h5 {
	font-size: 1.05em;
}

.foundry-agent-chat__message h6 {
	font-size: 0.85em;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.foundry-agent-chat__message code {
	background: var(--fac-code-bg, rgba(0, 0, 0, 0.08));
	padding: 1px 4px;
	border-radius: 4px;
	font-size: 0.9em;
}

.foundry-agent-chat__message a {
	color: inherit;
	text-decoration: underline;
}

.foundry-agent-chat__message--user {
	align-self: flex-end;
	background: var(--fac-user-bg);
	color: var(--fac-user-color);
	white-space: pre-wrap;
	border-bottom-right-radius: 6px;
}

.foundry-agent-chat__message--assistant {
	align-self: flex-start;
	background: var(--fac-assistant-bg);
	color: var(--fac-assistant-color);
	border-bottom-left-radius: 6px;
}

.foundry-agent-chat__message--error {
	align-self: flex-start;
	background: var(--fac-error-bg, #fdecea);
	color: var(--fac-error-color, #b3261e);
}

/* --- Suggestions --- */

.foundry-agent-chat__suggestions {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.foundry-agent-chat__suggestion {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	padding: 12px 14px;
	border: 1px solid var(--fac-border-color);
	border-radius: var(--fac-card-radius);
	background: var(--fac-bg);
	color: var(--fac-color);
	cursor: pointer;
	font: inherit;
	text-align: left;
	line-height: 1.35;
}

.foundry-agent-chat__suggestion span {
	min-width: 0;
}

.foundry-agent-chat__suggestion svg {
	flex-shrink: 0;
	color: var(--fac-muted);
}

.foundry-agent-chat__suggestion:hover:not(:disabled) {
	border-color: #d1d5db;
	background: #fafafa;
}

.foundry-agent-chat__suggestion:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

/* --- Source cards --- */

.foundry-agent-chat__sources {
	display: flex;
	flex-direction: column;
	align-self: flex-start;
	gap: 8px;
	width: 100%;
	max-width: 92%;
}

.foundry-agent-chat__source-card {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 10px 12px;
	border: 1px solid var(--fac-border-color);
	border-radius: var(--fac-source-radius, 8px);
	background: var(--fac-bg);
	min-width: 0;
	width: 100%;
}

.foundry-agent-chat__source-card:hover {
	border-color: #d1d5db;
}

.foundry-agent-chat__source-card--busy {
	opacity: 0.6;
}

.foundry-agent-chat__source-row {
	display: flex;
	align-items: center;
	gap: 8px;
}

.foundry-agent-chat__source-main {
	display: flex;
	align-items: center;
	gap: 12px;
	flex: 1 1 auto;
	min-width: 0;
	border: none;
	background: none;
	padding: 0;
	margin: 0;
	color: inherit;
	text-decoration: none;
	box-shadow: none;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.foundry-agent-chat__source-card--busy .foundry-agent-chat__source-main {
	cursor: default;
}

.foundry-agent-chat__source-info-toggle {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: none;
	border-radius: 999px;
	background: transparent;
	color: var(--fac-muted, #9ca3af);
	cursor: pointer;
}

.foundry-agent-chat__source-info-toggle:hover,
.foundry-agent-chat__source-info-toggle[aria-expanded='true'] {
	color: var(--fac-accent);
}

.foundry-agent-chat__source-info-toggle:focus-visible,
.foundry-agent-chat__source-main:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

.foundry-agent-chat__source-info {
	font-size: 0.8em;
	line-height: 1.4;
	color: var(--fac-muted);
	padding-top: 8px;
	border-top: 1px solid var(--fac-border-color);
}

.foundry-agent-chat__source-info ul {
	margin: 0;
	padding-left: 18px;
}

.foundry-agent-chat__source-icon {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 8px;
	background: var(--fac-source-icon-bg, #fce8eb);
	color: var(--fac-accent);
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.foundry-agent-chat__source-body {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.foundry-agent-chat__source-meta {
	font-size: 0.7em;
	font-weight: 600;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--fac-muted);
}

.foundry-agent-chat__source-title {
	font-size: 0.95em;
	font-weight: 700;
	line-height: 1.3;
	color: var(--fac-color);
	overflow-wrap: anywhere;
	word-break: break-word;
}

.foundry-agent-chat__source-detail {
	font-size: 0.75em;
	line-height: 1.3;
	color: var(--fac-muted);
}

.foundry-agent-chat__source-action {
	flex-shrink: 0;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 12px;
	border: none;
	border-radius: 999px;
	background: #111827;
	color: #fff;
	font: inherit;
	font-size: 0.75em;
	font-weight: 700;
	letter-spacing: 0.02em;
	cursor: pointer;
}

.foundry-agent-chat__source-card--busy .foundry-agent-chat__source-action {
	cursor: default;
}

.foundry-agent-chat__source-action:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

/* --- Feedback (thumbs up/down) --- */

.foundry-agent-chat__feedback {
	display: flex;
	align-items: center;
	align-self: flex-start;
	gap: 3px;
	margin-top: 1px;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.foundry-agent-chat__turn:hover .foundry-agent-chat__feedback,
.foundry-agent-chat__feedback:focus-within,
.foundry-agent-chat__feedback--rated {
	opacity: 1;
}

.foundry-agent-chat__feedback-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 4px;
	border: 1px solid var(--fac-muted, #9ca3af);
	border-radius: 999px;
	background: transparent;
	color: var(--fac-muted, #9ca3af);
	cursor: pointer;
}

.foundry-agent-chat__feedback-btn:hover {
	border-color: var(--fac-accent);
	color: var(--fac-accent);
}

.foundry-agent-chat__feedback-btn--active {
	border-color: var(--fac-accent);
	color: var(--fac-accent);
	background: var(--fac-source-icon-bg, #fce8eb);
}

.foundry-agent-chat__feedback-thanks {
	font-size: 0.75em;
	color: var(--fac-muted);
}

.foundry-agent-chat__feedback-comment {
	display: flex;
	flex-direction: column;
	gap: 6px;
	align-self: flex-start;
	width: 100%;
	max-width: 92%;
	margin-top: 4px;
}

.foundry-agent-chat__feedback-comment-input {
	width: 100%;
	resize: vertical;
	border: 1px solid var(--fac-muted, #9ca3af);
	border-radius: 8px;
	padding: 6px 8px;
	font: inherit;
	font-size: 0.85em;
	color: inherit;
	background: var(--fac-bg, #fff);
}

.foundry-agent-chat__feedback-comment-input:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 1px;
}

.foundry-agent-chat__feedback-comment-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.foundry-agent-chat__feedback-comment-skip {
	border: 0;
	background: transparent;
	color: var(--fac-muted);
	font: inherit;
	font-size: 0.8em;
	cursor: pointer;
	padding: 4px 6px;
}

.foundry-agent-chat__feedback-comment-send {
	border: 0;
	border-radius: 999px;
	background: var(--fac-accent);
	color: var(--fac-accent-contrast);
	font: inherit;
	font-size: 0.8em;
	cursor: pointer;
	padding: 4px 12px;
}

.foundry-agent-chat__feedback-comment-send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.foundry-agent-chat__feedback-comment-display {
	display: flex;
	align-items: baseline;
	gap: 8px;
	align-self: flex-start;
	width: 100%;
	max-width: 92%;
	margin-top: 4px;
	font-size: 0.8em;
	color: var(--fac-muted);
}

.foundry-agent-chat__feedback-comment-text {
	font-style: italic;
	overflow-wrap: anywhere;
}

.foundry-agent-chat__feedback-comment-edit {
	flex: none;
	border: 0;
	background: transparent;
	color: var(--fac-accent);
	font: inherit;
	cursor: pointer;
	padding: 0;
	text-decoration: underline;
}

.foundry-agent-chat__feedback-comment-add {
	align-self: flex-start;
	margin-top: 4px;
	border: 0;
	background: transparent;
	color: var(--fac-accent);
	font: inherit;
	font-size: 0.8em;
	cursor: pointer;
	padding: 0;
	text-decoration: underline;
}

/* --- Sign-in prompt --- */

.foundry-agent-chat__signin-cta {
	display: inline-block;
	margin-top: 8px;
	padding: 8px 16px;
	border: 0;
	border-radius: 999px;
	background: var(--fac-accent);
	color: var(--fac-accent-contrast);
	cursor: pointer;
	font: inherit;
	font-size: 0.95em;
}

.foundry-agent-chat__signin-cta:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.foundry-agent-chat__signin-prompt {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.foundry-agent-chat__signin-prompt p {
	margin: 0 0 8px;
	font-size: 0.95em;
	color: var(--fac-muted);
}

/* --- Confirm dialog --- */

.foundry-agent-chat__confirm-backdrop {
	position: fixed;
	inset: 0;
	z-index: calc(var(--fac-drawer-z, 100000) + 2);
	background: var(--fac-backdrop, rgba(15, 23, 42, 0.4));
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	box-sizing: border-box;
}

.foundry-agent-chat__confirm-dialog {
	width: 100%;
	max-width: 320px;
	background: var(--fac-bg);
	color: var(--fac-color);
	border-radius: var(--fac-card-radius, 14px);
	box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
	padding: 20px;
	box-sizing: border-box;
}

.foundry-agent-chat__confirm-message {
	margin: 0 0 16px;
	font-size: 0.95em;
	line-height: 1.4;
}

.foundry-agent-chat__confirm-actions {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.foundry-agent-chat__confirm-cancel {
	background: none;
	border: 1px solid var(--fac-border-color);
	border-radius: 999px;
	color: var(--fac-color);
	cursor: pointer;
	font: inherit;
	font-size: 0.9em;
	padding: 8px 16px;
}

.foundry-agent-chat__confirm-accept {
	border: 0;
	border-radius: 999px;
	background: var(--fac-accent);
	color: var(--fac-accent-contrast);
	cursor: pointer;
	font: inherit;
	font-size: 0.9em;
	padding: 8px 16px;
}

/* --- Typing --- */

.foundry-agent-chat__typing-wrap {
	display: inline-flex;
	gap: 8px;
	align-items: center;
	padding: 4px 0;
}

.foundry-agent-chat__typing-label {
	color: var(--fac-muted);
	font-size: 0.9em;
}

.foundry-agent-chat__typing {
	display: inline-flex;
	gap: 3px;
	align-items: center;
}

.foundry-agent-chat__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--fac-typing-dot, #9ca3af);
	animation: foundry-agent-chat-blink 1.2s infinite ease-in-out both;
}

.foundry-agent-chat__typing span:nth-child(2) {
	animation-delay: 0.2s;
}

.foundry-agent-chat__typing span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes foundry-agent-chat-blink {
	0%, 80%, 100% { opacity: 0.3; }
	40% { opacity: 1; }
}

/* --- Conversation + jump-to-bottom --- */

.foundry-agent-chat__conversation {
	position: relative;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.foundry-agent-chat__scroll-bottom {
	position: absolute;
	left: 50%;
	bottom: 10px;
	transform: translateX(-50%);
	z-index: 2;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 1px solid var(--fac-border-color);
	border-radius: 50%;
	background: var(--fac-bg);
	color: var(--fac-color);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
}

.foundry-agent-chat__scroll-bottom:hover {
	background: var(--fac-assistant-bg);
}

.foundry-agent-chat__scroll-bottom:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

/* --- Composer --- */

.foundry-agent-chat__composer {
	padding: 12px 16px 16px;
	border-top: 1px solid var(--fac-border-color);
	background: var(--fac-bg);
}

.foundry-agent-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 6px 6px 6px 16px;
	border: 0;
	/* Fixed radius (not 999px) so multi-line growth stays rounded, not oval. */
	border-radius: var(--fac-composer-radius, 24px);
	background: var(--fac-input-bg);
}

/* The focus ring belongs to the whole pill-shaped composer, not the bare
   textarea rectangle inside it — :focus-within promotes the textarea's focus
   up to this element. Outline follows border-radius in all current browsers,
   so this still renders as a rounded ring matching the pill shape. */
.foundry-agent-chat__form:focus-within {
	outline: 2px solid var(--fac-accent) !important;
	outline-offset: 2px !important;
}

.foundry-agent-chat__input {
	flex: 1;
	padding: 10px 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--fac-color);
	resize: none;
	max-height: 96px;
	font: inherit;
	line-height: 1.4;
}

/* !important + every focus state: themes commonly set their own global
   `textarea:focus` outline (often a different color, or none at all). The
   textarea itself must never show its own ring — the ring lives on
   .foundry-agent-chat__form above — regardless of the host theme's selector
   specificity or stylesheet load order. */
.foundry-agent-chat__input,
.foundry-agent-chat__input:focus,
.foundry-agent-chat__input:focus-visible {
	outline: none !important;
}

.foundry-agent-chat__input::placeholder {
	color: var(--fac-muted);
}

.foundry-agent-chat__send {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--fac-accent);
	color: var(--fac-accent-contrast);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 0;
}

.foundry-agent-chat__send:hover:not(:disabled) {
	filter: brightness(0.95);
}

.foundry-agent-chat__send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.foundry-agent-chat__send:focus-visible {
	outline: 2px solid var(--fac-accent);
	outline-offset: 2px;
}

.foundry-agent-chat__disclaimer {
	margin: 10px 4px 0;
	padding: 0;
	text-align: center;
	font-size: 0.65em;
	line-height: 1.35;
	color: var(--fac-muted);
}

/* --- Floating action button + sidebar drawer --- */

.foundry-agent-chat__fab {
	position: fixed;
	right: var(--fac-fab-offset, 24px);
	bottom: var(--fac-fab-offset, 24px);
	z-index: var(--fac-fab-z, 100001);
	width: var(--fac-fab-size, 56px);
	height: var(--fac-fab-size, 56px);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(
		--fac-fab-bg,
		linear-gradient(
			145deg,
			var(--fac-avatar-gradient-start, #ef4b5c) 0%,
			var(--fac-accent, #c41e3a) 48%,
			var(--fac-avatar-gradient-end, #8f1028) 100%
		)
	);
	color: var(--fac-accent-contrast, #fff);
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(
		--fac-fab-shadow,
		0 6px 18px rgba(196, 30, 58, 0.4),
		0 2px 6px rgba(0, 0, 0, 0.18),
		inset 0 1px 0 rgba(255, 255, 255, 0.22)
	);
	transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.foundry-agent-chat__fab:hover {
	box-shadow: var(
		--fac-fab-shadow-hover,
		0 8px 22px rgba(196, 30, 58, 0.48),
		0 3px 8px rgba(0, 0, 0, 0.2),
		inset 0 1px 0 rgba(255, 255, 255, 0.22)
	);
	transform: translateY(-1px);
}

.foundry-agent-chat__fab:focus-visible {
	outline: 2px solid var(--fac-accent, #c41e3a);
	outline-offset: 3px;
}

.foundry-agent-chat__fab--hidden {
	opacity: 0;
	pointer-events: none;
	transform: scale(0.85);
}

.foundry-agent-chat__fab-icon {
	display: block;
}

.foundry-agent-chat__backdrop {
	position: fixed;
	inset: 0;
	z-index: var(--fac-drawer-z, 100000);
	background: var(--fac-backdrop, rgba(15, 23, 42, 0.4));
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.25s ease, visibility 0.25s ease;
}

.foundry-agent-chat__backdrop--open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
}

.foundry-agent-chat__drawer {
	--fac-accent: #c41e3a;
	--fac-accent-contrast: #fff;
	--fac-bg: #ffffff;
	--fac-color: #111827;
	--fac-muted: #6b7280;
	--fac-border-color: #e5e7eb;
	--fac-assistant-bg: #f3f4f6;
	--fac-assistant-color: #111827;
	--fac-user-bg: var(--fac-accent);
	--fac-user-color: #fff;
	--fac-input-bg: #f3f4f6;
	--fac-bubble-radius: 18px;
	--fac-card-radius: 14px;

	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: calc(var(--fac-drawer-z, 100000) + 1);
	width: min(var(--fac-drawer-width, 640px), 100vw);
	max-height: 100vh;
	display: flex;
	flex-direction: column;
	background: var(--fac-drawer-bg, var(--fac-bg));
	color: var(--fac-color);
	font-family: var(--fac-font-family, inherit);
	font-size: var(--fac-font-size, 0.9rem);
	border-left: 1px solid var(--fac-border-color);
	box-shadow: var(--fac-drawer-shadow, -8px 0 24px rgba(0, 0, 0, 0.12));
	transform: translateX(100%);
	transition: transform 0.25s ease;
	box-sizing: border-box;
}

.foundry-agent-chat__drawer *,
.foundry-agent-chat__drawer *::before,
.foundry-agent-chat__drawer *::after {
	box-sizing: border-box;
}

.foundry-agent-chat__drawer--open {
	transform: translateX(0);
}

.foundry-agent-chat__drawer .foundry-agent-chat__header {
	flex-shrink: 0;
}

.foundry-agent-chat__drawer .foundry-agent-chat__conversation {
	flex: 1 1 auto;
	min-height: 0;
}

.foundry-agent-chat__drawer .foundry-agent-chat__messages {
	flex: 1 1 auto;
	height: auto;
	min-height: 0;
}

.foundry-agent-chat__drawer .foundry-agent-chat__composer {
	flex-shrink: 0;
}

/* Full-screen drawer — toggled by DrawerShell below the configured breakpoint. */
.foundry-agent-chat__drawer--fullscreen {
	width: 100vw;
	border-left: 0;
	box-shadow: none;
}

/* Height cap is toggled by DrawerShell once the configured breakpoint matches. Clamped
 * with 100vh so an admin-configured --fac-max-height (up to 1200px) can never push the
 * composer/input off-screen on a shorter viewport than the configured height. */
.foundry-agent-chat__drawer--height-capped {
	top: auto;
	bottom: 0;
	max-height: min(var(--fac-max-height, 600px), 100vh);
	/* Without a floor, this box only grows as tall as its content (header +
	 * whatever messages exist + composer) up to the max-height cap above — with
	 * few or no messages it can look like a squashed strip. Clamped with 100vh
	 * for the same reason as max-height: never force more height than an actual
	 * short viewport has room for. */
	min-height: min(var(--fac-min-height, 500px), 100vh);
	/* Only top-left is rounded, and only in this capped (not full-height) state: the
	 * drawer is anchored right:0 + bottom:0 here, so top and left are the only edges
	 * actually floating free of a screen edge — top-left is the one corner where both
	 * adjacent sides are floating. Reuses --fac-radius, the same variable/default
	 * already used on the widget's own (non-drawer) container, so a site's theme can
	 * override both consistently with one variable. */
	border-top-left-radius: var(--fac-radius, 10px);
}

@media (max-width: 480px) {
	.foundry-agent-chat {
		max-width: 100%;
	}

	.foundry-agent-chat__fab {
		right: 16px;
		bottom: 16px;
	}
}
