/* WP RAG Agent — chat widget. Themed via CSS custom properties:
   --wpra-primary (set inline from settings), --wpra-z. */

.wpra-chat {
	position: fixed;
	z-index: var(--wpra-z, 99990);
	--wpra-radius: 14px;
	--wpra-bg: #fff;
	--wpra-text: #1e1e1e;
	--wpra-muted: #667085;
	--wpra-border: #e4e7ec;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 14px;
	line-height: 1.5;
}

.wpra-chat [hidden] {
	display: none !important;
}

.wpra-chat--bottom-right { right: 20px; bottom: 20px; }
.wpra-chat--bottom-left  { left: 20px;  bottom: 20px; }
.wpra-chat--top-right    { right: 20px; top: 20px; }
.wpra-chat--top-left     { left: 20px;  top: 20px; }

/* Launcher button */
.wpra-chat__launcher {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border: 0;
	border-radius: 50%;
	background: var(--wpra-primary, #2271b1);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 6px 24px rgba(16, 24, 40, 0.25);
	transition: transform 0.15s ease;
}

.wpra-chat__launcher:hover,
.wpra-chat__launcher:focus-visible { transform: scale(1.06); }

.wpra-chat__icon-close { display: none; }
.wpra-chat.is-open .wpra-chat__icon-close { display: block; }
.wpra-chat.is-open .wpra-chat__icon-open { display: none; }

/* Window */
.wpra-chat__window {
	position: absolute;
	display: flex;
	flex-direction: column;
	width: 370px;
	max-width: calc(100vw - 40px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--wpra-bg);
	color: var(--wpra-text);
	border: 1px solid var(--wpra-border);
	border-radius: var(--wpra-radius);
	box-shadow: 0 12px 48px rgba(16, 24, 40, 0.22);
	overflow: hidden;
}

.wpra-chat--bottom-right .wpra-chat__window { right: 0; bottom: 70px; }
.wpra-chat--bottom-left  .wpra-chat__window { left: 0;  bottom: 70px; }
.wpra-chat--top-right    .wpra-chat__window { right: 0; top: 70px; }
.wpra-chat--top-left     .wpra-chat__window { left: 0;  top: 70px; }

/* Header */
.wpra-chat__header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 16px;
	background: var(--wpra-primary, #2271b1);
	color: #fff;
}

.wpra-chat__avatar img {
	display: block;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	object-fit: cover;
}

.wpra-chat__title {
	flex: 1;
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	color: inherit;
}

.wpra-chat__close {
	border: 0;
	background: transparent;
	color: #fff;
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
}

/* Messages */
.wpra-chat__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	scroll-behavior: smooth;
}

.wpra-chat__msg {
	max-width: 85%;
	padding: 9px 13px;
	border-radius: 12px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.wpra-chat__content {
	white-space: pre-wrap;
}

.wpra-chat__msg--assistant .wpra-chat__content {
	white-space: normal;
}

.wpra-chat__msg--assistant .wpra-chat__content > :first-child {
	margin-top: 0;
}

.wpra-chat__msg--assistant .wpra-chat__content > :last-child {
	margin-bottom: 0;
}

.wpra-chat__msg--assistant .wpra-chat__content p,
.wpra-chat__msg--assistant .wpra-chat__content blockquote,
.wpra-chat__msg--assistant .wpra-chat__content pre,
.wpra-chat__msg--assistant .wpra-chat__content ul,
.wpra-chat__msg--assistant .wpra-chat__content ol {
	margin: 0 0 0.75em;
}

.wpra-chat__msg--assistant .wpra-chat__content h1,
.wpra-chat__msg--assistant .wpra-chat__content h2,
.wpra-chat__msg--assistant .wpra-chat__content h3,
.wpra-chat__msg--assistant .wpra-chat__content h4,
.wpra-chat__msg--assistant .wpra-chat__content h5,
.wpra-chat__msg--assistant .wpra-chat__content h6 {
	margin: 0.9em 0 0.35em;
	color: inherit;
	font-weight: 650;
	line-height: 1.25;
}

.wpra-chat__msg--assistant .wpra-chat__content h1 { font-size: 1.35em; }
.wpra-chat__msg--assistant .wpra-chat__content h2 { font-size: 1.25em; }
.wpra-chat__msg--assistant .wpra-chat__content h3 { font-size: 1.15em; }
.wpra-chat__msg--assistant .wpra-chat__content h4,
.wpra-chat__msg--assistant .wpra-chat__content h5,
.wpra-chat__msg--assistant .wpra-chat__content h6 { font-size: 1em; }

.wpra-chat__msg--assistant .wpra-chat__content ul,
.wpra-chat__msg--assistant .wpra-chat__content ol {
	padding-left: 1.5em;
}

.wpra-chat__msg--assistant .wpra-chat__content blockquote {
	padding-left: 0.75em;
	border-left: 3px solid var(--wpra-border);
	color: var(--wpra-muted);
}

.wpra-chat__msg--assistant .wpra-chat__content a {
	color: var(--wpra-primary, #2271b1);
	text-decoration: underline;
}

.wpra-chat__msg--assistant .wpra-chat__content code {
	padding: 0.1em 0.35em;
	border-radius: 4px;
	background: rgba(16, 24, 40, 0.08);
	font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
	font-size: 0.9em;
}

.wpra-chat__msg--assistant .wpra-chat__content pre {
	max-width: 100%;
	padding: 0.7em;
	overflow-x: auto;
	border-radius: 7px;
	background: #1d2939;
	color: #f9fafb;
	white-space: pre;
}

.wpra-chat__msg--assistant .wpra-chat__content table {
	width: 100%;
	margin: 0 0 0.75em;
	border-collapse: collapse;
}

.wpra-chat__msg--assistant .wpra-chat__content th,
.wpra-chat__msg--assistant .wpra-chat__content td {
	padding: 0.35em 0.5em;
	border: 1px solid var(--wpra-border);
	text-align: left;
	vertical-align: top;
}
.wpra-chat__msg--assistant .wpra-chat__content pre code {
	padding: 0;
	background: transparent;
	color: inherit;
}

.wpra-chat__msg--user {
	align-self: flex-end;
	background: var(--wpra-primary, #2271b1);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.wpra-chat__msg--assistant {
	align-self: flex-start;
	background: #f2f4f7;
	color: var(--wpra-text);
	border-bottom-left-radius: 4px;
}

.wpra-chat__msg--system {
	align-self: center;
	background: #fef3f2;
	color: #b42318;
	font-size: 13px;
	border-radius: 8px;
}

/* Sources footnote */
.wpra-chat__sources {
	margin: 8px 0 0;
	padding: 8px 0 0;
	border-top: 1px solid var(--wpra-border);
	font-size: 12px;
	color: var(--wpra-muted);
}

/* Inline citation links: [1], [2] within the response text */
.wpra-chat__msg--assistant .wpra-chat__content a.wpra-citation {
	color: var(--wpra-primary, #2271b1);
	text-decoration: none;
	font-size: 0.8em;
	vertical-align: super;
	font-weight: 600;
}

.wpra-chat__sources strong {
	display: block;
	margin-bottom: 2px;
	font-weight: 600;
}

.wpra-chat__sources ol {
	margin: 0;
	padding-left: 18px;
}

.wpra-chat__sources a {
	color: var(--wpra-primary, #2271b1);
	text-decoration: underline;
}

/* Predefined question chips */
.wpra-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 16px 12px;
}

.wpra-chat__chip {
	border: 1px solid var(--wpra-primary, #2271b1);
	border-radius: 999px;
	padding: 6px 12px;
	background: transparent;
	color: var(--wpra-primary, #2271b1);
	font: inherit;
	font-size: 12.5px;
	line-height: 1.3;
	cursor: pointer;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.wpra-chat__chip:hover,
.wpra-chat__chip:focus-visible {
	background: var(--wpra-primary, #2271b1);
	color: #fff;
}

.wpra-chat__chip:disabled {
	opacity: 0.6;
	cursor: default;
}

/* Typing indicator */
.wpra-chat__typing {
	display: flex;
	gap: 4px;
	padding: 0 16px 10px;
}

.wpra-chat__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--wpra-muted);
	animation: wpra-bounce 1.2s infinite;
}

.wpra-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.wpra-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes wpra-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-5px); opacity: 1; }
}

/* Input form */
.wpra-chat__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--wpra-border);
}

.wpra-chat__input {
	flex: 1;
	resize: none;
	border: 1px solid var(--wpra-border);
	border-radius: 10px;
	padding: 9px 12px;
	font: inherit;
	color: var(--wpra-text);
	background: var(--wpra-bg);
	max-height: 110px;
}

.wpra-chat__input:focus {
	outline: 2px solid var(--wpra-primary, #2271b1);
	outline-offset: -1px;
	border-color: transparent;
}

.wpra-chat__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: 0;
	border-radius: 10px;
	background: var(--wpra-primary, #2271b1);
	color: #fff;
	cursor: pointer;
	flex-shrink: 0;
}

.wpra-chat__send:disabled { opacity: 0.5; cursor: default; }

.wpra-chat__actions {
	padding: 5px 12px 8px;
	text-align: center;
}

.wpra-chat__new-conversation {
	border: 0;
	padding: 0;
	background: transparent;
	color: var(--wpra-muted);
	font: inherit;
	font-size: 12px;
	text-decoration: underline;
	cursor: pointer;
}

.wpra-chat__new-conversation:hover,
.wpra-chat__new-conversation:focus-visible {
	color: var(--wpra-primary, #2271b1);
}

.wpra-chat__new-conversation:disabled {
	opacity: 0.5;
	cursor: default;
}

.wpra-chat__powered {
	margin: 0;
	padding: 0 12px 10px;
	font-size: 11px;
	color: var(--wpra-muted);
	text-align: center;
}

/* Inline embed ([wp_rag_agent] shortcode) */
.wpra-chat--inline {
	position: static;
	z-index: auto;
	width: 100%;
	max-width: 720px;
	margin: 0 auto;
}

.wpra-chat--inline .wpra-chat__window {
	position: static;
	width: 100%;
	max-width: none;
	height: var(--wpra-inline-height, 560px);
	max-height: none;
}

/* Mobile: full-screen sheet (floating widget only) */
@media (max-width: 480px) {
	.wpra-chat--floating .wpra-chat__window {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: none;
		height: 100%;
		max-height: none;
		border-radius: 0;
		border: 0;
	}
}
