/**
 * Own-site chat launcher. The button stays in document flow.
 * The dialog is fixed only while it is open, so it does not sit on the
 * referral badge (bottom-right) as a second or third corner icon.
 *
 * In the dark Kadence header the control is a slim gold chip, the same
 * height as the menu. On light pages it is a solid button, visible without hover.
 */

.veltiara-rag-chat {
	position: static;
	margin: 1rem 0 1.25rem;
}

.veltiara-rag-chat__open,
.veltiara-rag-chat__submit,
.veltiara-rag-chat__close {
	font: inherit;
	cursor: pointer;
}

.veltiara-rag-chat__open {
	display: inline-flex;
	align-items: center;
	padding: 0.55rem 0.95rem;
	border: 1px solid #1c1c1c;
	border-radius: 999px;
	background: #1c1c1c;
	color: #fff;
	line-height: 1.2;
}

.veltiara-rag-chat__open:hover,
.veltiara-rag-chat__open:focus-visible {
	background: #3a3224;
	border-color: #c6a15a;
	color: #f6edd8;
}

.header-html .veltiara-rag-chat,
#mobile-header .veltiara-rag-chat {
	display: inline-flex;
	align-items: center;
	margin: 0;
	vertical-align: middle;
}

@media (min-width: 1025px) {
	.header-html:has(.veltiara-rag-chat),
	.site-header-section-center:has(.veltiara-rag-chat) {
		overflow: visible;
	}

	.header-html-inner:has(.veltiara-rag-chat) {
		position: relative;
		display: inline-flex;
		align-items: center;
	}

	.header-html .veltiara-rag-chat {
		position: absolute;
		right: calc(100% + 0.75rem);
		top: 0;
		bottom: 0;
		display: flex;
		align-items: center;
		margin: 0;
		width: max-content;
	}
}

.header-html .veltiara-rag-chat__open,
#mobile-header .veltiara-rag-chat__open {
	padding: 0.28rem 0.7rem;
	border: 1px solid #c6a15a;
	background: transparent;
	color: #f6edd8;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.08em;
	line-height: 1.2;
	text-transform: uppercase;
	white-space: nowrap;
}

.header-html .veltiara-rag-chat__open:hover,
.header-html .veltiara-rag-chat__open:focus-visible,
#mobile-header .veltiara-rag-chat__open:hover,
#mobile-header .veltiara-rag-chat__open:focus-visible {
	background: #c6a15a;
	border-color: #c6a15a;
	color: #1a140c;
}

/*
 * Even, tighter spacing AI - cart - menu (~12px each), so the AI chip does
 * not touch the logo on narrow phones. Kadence's 10px item margin is
 * dropped; the cart (4px) and menu button (~8px) paddings give the gap.
 */
#mobile-header .veltiara-rag-chat {
	margin-right: 12px;
}

#mobile-header .site-header-section-right:has(.veltiara-rag-chat) .site-header-item {
	margin-right: 0;
}

/* Very narrow phones: slightly smaller logo keeps a gap before the AI chip. */
@media (max-width: 380px) {
	#mobile-header:has(.veltiara-rag-chat) .site-branding img {
		max-width: 128px;
		height: auto;
	}
}

#mobile-header .veltiara-rag-chat__open {
	min-height: 40px;
	padding: 0.35rem 0.75rem;
}

/*
 * Compact label. Only the short "AI" chip is shown in the mobile header on
 * narrow screens, so the cart and the menu toggle stay inside the viewport.
 * The accessible name stays "Kérdezd az AI-t" (aria-label on the button).
 */
.veltiara-rag-chat__open-label-short {
	display: none;
}

#mobile-header .site-header-section-right:has(.veltiara-rag-chat) {
	flex-wrap: nowrap;
	min-width: 0;
}

#mobile-header .site-header-section-right:has(.veltiara-rag-chat) > * {
	flex-shrink: 0;
}

@media (max-width: 600px) {
	#mobile-header .veltiara-rag-chat__open-label {
		display: none;
	}

	#mobile-header .veltiara-rag-chat__open-label-short {
		display: inline;
	}

	#mobile-header .veltiara-rag-chat__open {
		min-width: 44px;
		min-height: 40px;
		padding: 0.35rem 0.6rem;
		justify-content: center;
		letter-spacing: 0.06em;
	}
}

.veltiara-rag-chat__open:focus-visible,
.veltiara-rag-chat__close:focus-visible,
.veltiara-rag-chat__submit:focus-visible,
.veltiara-rag-chat__input:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 2px;
}

.veltiara-rag-chat__dialog[hidden] {
	display: none;
}

.veltiara-rag-chat__dialog.is-open {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	padding: 1rem;
	background: rgba(0, 0, 0, 0.45);
	box-sizing: border-box;
}

.veltiara-rag-chat__panel {
	display: flex;
	flex-direction: column;
	width: min(100%, 40rem);
	/* Desktop: tall card so long answers have room; mobile overrides below. */
	max-height: min(85vh, 52rem);
	padding: 1rem;
	border: 1px solid rgba(198, 161, 90, 0.35);
	border-radius: 16px;
	background: #10141c;
	color: #f6f3ee;
	color-scheme: dark;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
	box-sizing: border-box;
	overflow: hidden;
}

.veltiara-rag-chat__header {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.75rem;
}

h2.veltiara-rag-chat__title {
	margin: 0;
	font-size: 1.05rem;
	line-height: 1.3;
	color: #ecc45c;
}

/* Visually hidden, still read by screen readers. */
.veltiara-rag-chat__sr {
	position: absolute !important;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.veltiara-rag-chat__icon {
	display: block;
	flex-shrink: 0;
}

/* Round "×" close button (accessible name: "Bezárás"). */
button.veltiara-rag-chat__close {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	min-width: 40px;
	min-height: 40px;
	max-width: none;
	padding: 0;
	border: 1px solid rgba(246, 243, 238, 0.45);
	border-radius: 50%;
	background: transparent;
	color: #f6f3ee;
	line-height: 1;
	white-space: nowrap;
}

h2.veltiara-rag-chat__title {
	min-width: 0;
	/* Always one line; ellipsis only as a last resort on tiny screens. */
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* While the chat sheet is open, floating corner badges must not cover it. */
html.veltiara-rag-chat-is-open #google-merchantwidget-iframe-wrapper,
html.veltiara-rag-chat-is-open #veltiara-referral-badge {
	display: none !important;
}

button.veltiara-rag-chat__close:hover,
button.veltiara-rag-chat__close:focus-visible {
	background: #c6a15a;
	border-color: #c6a15a;
	color: #1a140c;
}

.veltiara-rag-chat__log {
	display: flex;
	flex-direction: column;
	flex: 1 1 auto;
	min-height: 0;
	overflow: auto;
	overflow-anchor: none;
	scrollbar-width: thin;
	scrollbar-color: rgba(198, 161, 90, 0.65) transparent;
}

.veltiara-rag-chat__log::-webkit-scrollbar {
	width: 6px;
}

.veltiara-rag-chat__log::-webkit-scrollbar-thumb {
	border-radius: 3px;
	background: rgba(198, 161, 90, 0.65);
}

/* Answer area wrapper: holds the "more below" fade and arrow button. */
.veltiara-rag-chat__log-wrap {
	position: relative;
	display: flex;
	flex-direction: column;
	/* Grows with the answers up to the panel limit, then the log scrolls. */
	flex: 1 1 auto;
	min-height: 3rem;
	margin-bottom: 0.75rem;
}

.veltiara-rag-chat__log-wrap.has-more::after {
	content: '';
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 2.75rem;
	background: linear-gradient(rgba(16, 20, 28, 0), #10141c);
	pointer-events: none;
}

button.veltiara-rag-chat__more {
	position: absolute;
	left: 50%;
	bottom: 4px;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	min-height: 36px;
	padding: 0;
	transform: translateX(-50%);
	border: 1px solid #c6a15a;
	border-radius: 50%;
	background: #10141c;
	color: #ecc45c;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
	cursor: pointer;
}

button.veltiara-rag-chat__more[hidden] {
	display: none;
}

button.veltiara-rag-chat__more:hover,
button.veltiara-rag-chat__more:focus-visible {
	background: #c6a15a;
	color: #1a140c;
}

.veltiara-rag-chat__log > * {
	flex-shrink: 0;
}

.veltiara-rag-chat__message {
	margin: 0 0 0.75rem;
	white-space: pre-wrap;
	color: #f6f3ee;
}

.veltiara-rag-chat__message--user {
	align-self: flex-end;
	max-width: 85%;
	margin-left: 2rem;
	padding: 0.55rem 0.75rem;
	border-radius: 12px 12px 4px 12px;
	background: rgba(198, 161, 90, 0.16);
}

.veltiara-rag-chat__log a,
.veltiara-rag-chat__log a:visited,
.veltiara-rag-chat__citations a,
.veltiara-rag-chat__citations a:visited {
	color: #ecc45c;
}

.veltiara-rag-chat__log a:hover,
.veltiara-rag-chat__log a:focus-visible,
.veltiara-rag-chat__citations a:hover,
.veltiara-rag-chat__citations a:focus-visible {
	color: #f6d98a;
}

.veltiara-rag-chat__pending {
	color: #f6f3ee;
}

.veltiara-rag-chat__spinner {
	display: inline-block;
	width: 0.9rem;
	height: 0.9rem;
	margin-left: 0.45rem;
	vertical-align: -0.15em;
	border: 2px solid rgba(236, 196, 92, 0.35);
	border-top-color: #ecc45c;
	border-radius: 50%;
	animation: veltiara-rag-chat-spin 0.8s linear infinite;
}

@keyframes veltiara-rag-chat-spin {
	to {
		transform: rotate(360deg);
	}
}

@media (prefers-reduced-motion: reduce) {
	.veltiara-rag-chat__spinner {
		animation: none;
		border-color: #ecc45c;
	}
}

.veltiara-rag-chat__source-gap {
	display: block;
	height: 0.7rem;
}

.veltiara-rag-chat__source-lead {
	margin: 0.9rem 0 0.35rem;
	color: #f6f3ee;
}

.veltiara-rag-chat__citations {
	margin: 0 0 0.75rem;
	padding-left: 1.1rem;
}

.veltiara-rag-chat__form {
	display: flex;
	flex-shrink: 0;
	flex-direction: column;
	gap: 0.4rem;
	position: relative;
	z-index: 1;
	background: #10141c;
}

.veltiara-rag-chat__label {
	font-size: 0.9rem;
}

textarea.veltiara-rag-chat__input,
textarea.veltiara-rag-chat__input:focus {
	width: 100%;
	box-sizing: border-box;
	font: inherit;
	padding: 0.6rem 0.7rem;
	border: 1px solid rgba(246, 243, 238, 0.28);
	border-radius: 10px;
	color: #f6f3ee;
	-webkit-text-fill-color: #f6f3ee;
	caret-color: #f6f3ee;
	background-color: #0c1018;
}

/* Two-line question field (usually one sentence): leaves room for the answer. */
textarea.veltiara-rag-chat__input,
textarea.veltiara-rag-chat__input:focus {
	min-height: 0;
	height: auto;
	line-height: 1.4;
	padding: 0.5rem 0.7rem;
	resize: none;
}

.veltiara-rag-chat__input::placeholder {
	color: rgba(246, 243, 238, 0.55);
}

.veltiara-rag-chat__turnstile {
	min-height: 0;
}

/* Question field + round send button on one row. */
.veltiara-rag-chat__compose {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.veltiara-rag-chat__compose textarea.veltiara-rag-chat__input {
	flex: 1 1 auto;
	width: auto;
	min-width: 0;
}

/* Round send button (accessible name: "Beküld"). */
.veltiara-rag-chat__submit {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	min-height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: #c6a15a;
	color: #1a140c;
}

.veltiara-rag-chat__submit.is-busy .veltiara-rag-chat__icon {
	opacity: 0.45;
}

.veltiara-rag-chat__submit:hover,
.veltiara-rag-chat__submit:focus-visible {
	background: #d4b56e;
	color: #1a140c;
}

/* Empty field: muted, clearly inactive send button. */
.veltiara-rag-chat__submit:disabled,
.veltiara-rag-chat__submit:disabled:hover {
	background: rgba(246, 243, 238, 0.14);
	color: rgba(246, 243, 238, 0.45);
	cursor: not-allowed;
}

/* Waiting for the answer: keeps the gold colour, dimmed. */
.veltiara-rag-chat__submit.is-busy:disabled {
	background: #c6a15a;
	color: #1a140c;
	opacity: 0.6;
	cursor: progress;
}

/* Page without a header launcher: the chat opens only from the AI card. */
.veltiara-rag-chat--headless {
	margin: 0;
}

.veltiara-rag-chat--headless .veltiara-rag-chat__open {
	display: none;
}

/*
 * Hero headline next to the AI card: the Kadence heading is sized for a
 * full-width row (70px), which breaks words in a half-width column. Size it
 * from its own column width (container query), so "TERMÉSZETES" always fits.
 * Only applies to the row that holds the AI card.
 */
.kb-row-layout-wrap:has(.veltiara-rag-hero) .kt-inside-inner-col:has(> h1.wp-block-kadence-advancedheading) {
	container-type: inline-size;
}

.kb-row-layout-wrap:has(.veltiara-rag-hero) h1.wp-block-kadence-advancedheading {
	font-size: clamp(26px, 10.5cqi, 46px);
	letter-spacing: 0.1em;
	line-height: 1.2;
}

/*
 * Phone: the hero row is 100vh tall and vertically centred. With the AI card
 * stacked under the headline the content is taller than the screen, so the
 * centring pushed the headline up under the transparent header. Let the row
 * grow with its content and start below the header instead; the collection
 * button stays on one line.
 */
@media (max-width: 767px) {
	.kb-row-layout-wrap:has(.veltiara-rag-hero) > .kt-row-column-wrap {
		min-height: 0;
		padding-top: 112px;
		padding-bottom: 48px;
		gap: 32px;
	}

	.kb-row-layout-wrap:has(.veltiara-rag-hero) .wp-block-kadence-singlebtn.kb-button {
		padding: 14px 22px;
		font-size: 13px;
		letter-spacing: 2.5px;
		line-height: 1.4;
	}
}

/*
 * Homepage AI card ("B" variant). Sits in the hero next to (desktop) or
 * under (mobile) the collection CTA; the buttons open the page's chat.
 */
.veltiara-rag-hero {
	display: flex;
	flex-direction: column;
	gap: 10px;
	width: 100%;
	max-width: 34rem;
	margin: 0 auto;
	padding: 16px;
	box-sizing: border-box;
	border: 1px solid rgba(198, 161, 90, 0.4);
	border-radius: 16px;
	background: rgba(16, 20, 28, 0.78);
	color: #f6f3ee;
	text-align: left;
	color-scheme: dark;
}

.veltiara-rag-hero__head {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 4px 12px;
	margin-bottom: 2px;
}

h2.veltiara-rag-hero__title {
	margin: 0;
	font-family: Cormorant, Georgia, serif;
	font-style: italic;
	font-weight: 600;
	font-size: 22px;
	line-height: 1.25;
	letter-spacing: 0;
	text-transform: none;
	color: #ecc45c;
}

.veltiara-rag-hero__keywords {
	font-size: 11px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: rgba(246, 243, 238, 0.75);
}

button.veltiara-rag-hero__question,
button.veltiara-rag-hero__own {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	width: 100%;
	min-height: 48px;
	margin: 0;
	box-sizing: border-box;
	font: inherit;
	font-size: 15px;
	line-height: 1.35;
	letter-spacing: normal;
	text-align: left;
	text-transform: none;
	cursor: pointer;
}

button.veltiara-rag-hero__question {
	padding: 10px 14px;
	border: 1px solid rgba(246, 243, 238, 0.18);
	border-radius: 12px;
	background: rgba(246, 243, 238, 0.04);
	color: #f6f3ee;
}

button.veltiara-rag-hero__question .veltiara-rag-hero__icon {
	flex-shrink: 0;
	color: #c6a15a;
}

button.veltiara-rag-hero__question:hover,
button.veltiara-rag-hero__question:focus-visible {
	border-color: #c6a15a;
	background: rgba(198, 161, 90, 0.12);
	color: #f6f3ee;
}

button.veltiara-rag-hero__own {
	margin-top: 4px;
	padding: 6px 6px 6px 18px;
	border: 1px solid rgba(198, 161, 90, 0.7);
	border-radius: 999px;
	background: #0c1018;
	color: rgba(246, 243, 238, 0.75);
	cursor: text;
}

button.veltiara-rag-hero__own:hover,
button.veltiara-rag-hero__own:focus-visible {
	border-color: #ecc45c;
	background: #0c1018;
	color: #f6f3ee;
}

.veltiara-rag-hero__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: #c6a15a;
	color: #1a140c;
}

button.veltiara-rag-hero__question:focus-visible,
button.veltiara-rag-hero__own:focus-visible {
	outline: 2px solid #ecc45c;
	outline-offset: 2px;
}

@media (min-width: 1025px) {
	.veltiara-rag-hero {
		padding: 28px;
		border-radius: 20px;
		gap: 12px;
	}

	h2.veltiara-rag-hero__title {
		font-size: 28px;
	}

	button.veltiara-rag-hero__question,
	button.veltiara-rag-hero__own {
		min-height: 52px;
		font-size: 16px;
	}
}

@media (min-width: 720px) {
	/*
	 * Desktop: fixed-height card, so the window does not jump in size as the
	 * first answer streams in. The answer log fills the space and scrolls.
	 */
	.veltiara-rag-chat__panel {
		height: min(85vh, 52rem);
	}
}

@media (max-width: 719px) {
	/*
	 * Mobile: the sheet is anchored to the TOP and limited to the upper ~65%
	 * of the screen. Some Android browsers overlay the on-screen keyboard
	 * without shrinking any viewport, so a bottom sheet would sit behind it.
	 * In the upper half, the textarea stays visible above the keyboard.
	 */
	.veltiara-rag-chat__dialog.is-open {
		align-items: flex-start;
		padding: 0;
	}

	.veltiara-rag-chat__panel {
		width: 100%;
		/* --veltiara-rag-vv-height: visual viewport height set by rag-chat.js
		   while open (shrinks when the on-screen keyboard is up). */
		/* Default 60% of the screen; never taller than the visible area. */
		height: min(60vh, var(--veltiara-rag-vv-height, 100vh));
		max-height: min(65vh, var(--veltiara-rag-vv-height, 100vh));
		border-radius: 0 0 16px 16px;
		padding: calc(0.85rem + env(safe-area-inset-top)) 1rem 0.85rem;
		/* Safety net: never clip the form on very short screens; scroll instead. */
		overflow-y: auto;
	}

}
