/* ==========================================================================
   Pretzel RAG — Chat styles
   ========================================================================== */

/* Override WordPress block editor layout constraints.
   When the shortcode is inside a Group block with is-layout-constrained,
   WP injects max-width + margin:auto !important on child elements.
   These rules ensure the chat controls its own layout.              */

.prag-chat {
	max-width: 950px !important;
	margin-left: auto !important;
	margin-right: auto !important;
	width: 100%;
	box-sizing: border-box;
	padding-left: 0;
	padding-right: 0;
}

.prag-chat > * {
	max-width: none !important;
	margin-left: 0 !important;
	margin-right: 0 !important;
}

/* Heading
   ========================================================================== */

.prag-chat__heading {
	font-family: var(--wp--preset--font-family--outfit, 'Outfit', sans-serif);
	font-weight: 700;
	font-size: var(--wp--preset--font-size--h-2, 36px);
	line-height: var(--wp--custom--typography--heading-line-height, 1.2);
	color: var(--wp--preset--color--black, #000000);
	margin: 0 0 var(--wp--preset--spacing--30, 1.25rem);
}

.prag-chat__description {
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif);
	font-size: var(--wp--preset--font-size--medium, 18px);
	line-height: 1.5;
	color: var(--wp--preset--color--black, #000000);
	margin: 0 0 var(--wp--preset--spacing--40, 1.5rem);
	max-width: 80ch;
}

/* Chat panel — wraps messages + input
   ========================================================================== */

.prag-chat__panel {
	display: flex;
	flex-direction: column;
}

.prag-chat__panel--active {
	border: none;
	border-radius: 0;
	padding: 0;
	background: transparent;
	flex: 1;
	min-height: 0;
}

.prag-chat__panel--active .prag-chat__messages {
	padding-bottom: 1rem;
}

.prag-chat__panel--active .prag-chat__input-area {
	flex-shrink: 0;
}

/* Overlay modal (desktop)
   ========================================================================== */

.prag-chat__overlay {
	position: fixed;
	inset: 0;
	z-index: 999999;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 0.35s ease;
	overflow: hidden;
}

.prag-chat__overlay--visible {
	opacity: 1;
}

.prag-chat__overlay-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.5);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}

.prag-chat__overlay-modal {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 90%;
	max-width: 700px;
	min-height: 60vh;
	max-height: 80vh;
	background: #faf8f5;
	border-radius: 1rem;
	box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
	overflow: hidden;
	transform: scale(0.4);
	transform-origin: center center;
	transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
	            box-shadow 0.45s ease;
}

.prag-chat__overlay--visible .prag-chat__overlay-modal {
	transform: scale(1);
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
}

.prag-chat__overlay--closing .prag-chat__overlay-modal {
	transform: scale(0.4);
	transition: transform 0.3s cubic-bezier(0.55, 0, 1, 0.45);
}

.prag-chat__overlay-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 1rem 1.25rem;
	border-bottom: 1px solid rgba(0, 0, 0, 0.06);
	flex-shrink: 0;
}

.prag-chat__overlay-title {
	font-family: var(--wp--preset--font-family--outfit, 'Outfit', sans-serif);
	font-weight: 700;
	font-size: 1rem;
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__overlay-close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	border: none;
	border-radius: 0.5rem;
	background: transparent;
	color: var(--wp--preset--color--dark-grey, #565656);
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
	padding: 0;
}

.prag-chat__overlay-close:hover {
	background: rgba(0, 0, 0, 0.06);
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__overlay-modal .prag-chat__panel {
	flex: 1;
	min-height: 0;
	padding: 1rem 1.25rem;
	display: flex;
	flex-direction: column;
}

.prag-chat__overlay-modal .prag-chat__messages {
	max-height: none;
	flex: 1 1 0;
	overflow-y: auto;
	min-height: 0;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-ms-overflow-style: none;
	touch-action: pan-y;
	overscroll-behavior: contain;
}

.prag-chat__overlay-modal .prag-chat__messages::-webkit-scrollbar {
	display: none;
}

.prag-chat__overlay-modal > .prag-chat__suggestions {
	padding: 0.25rem 1.25rem 0.75rem;
	flex-shrink: 0;
	touch-action: pan-x;
}

.prag-chat__overlay-footer {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	padding: 0.75rem 1.25rem;
	border-top: 1px solid rgba(0, 0, 0, 0.06);
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif);
	font-size: 0.75rem;
	color: var(--wp--preset--color--dark-grey, #7a7a7a);
	flex-shrink: 0;
}

.prag-chat__pretzel-icon {
	width: 1rem;
	height: 0.6875rem;
	color: var(--wp--preset--color--marigold, #ffbe21);
	flex-shrink: 0;
}

.prag-chat__pretzel-name {
	font-weight: 700;
	color: var(--wp--preset--color--black, #000000);
}

/* Takeover — full-screen chat view (mobile)
   ========================================================================== */

.prag-chat__takeover {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	height: 100dvh;
	overflow: hidden;
	overscroll-behavior: none;
	touch-action: none;
	background: var(--chat-bg, #faf8f5);
	transform: translateY(100%);
	visibility: hidden;
	transition: transform var(--chat-transition, 320ms cubic-bezier(0.4, 0, 0.2, 1)),
	            visibility 0s linear 320ms;
}

.prag-chat__takeover.is-open {
	transform: translateY(0);
	visibility: visible;
	transition: transform var(--chat-transition, 320ms cubic-bezier(0.4, 0, 0.2, 1)),
	            visibility 0s linear 0s;
}

/* Takeover header */

.prag-chat__takeover-header {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	border-bottom: 1px solid rgba(0, 0, 0, 0.06);
	flex-shrink: 0;
}

.prag-chat__takeover-back {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2rem;
	height: 2rem;
	border: none;
	border-radius: 0.5rem;
	background: transparent;
	color: var(--wp--preset--color--dark-grey, #565656);
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
	padding: 0;
	flex-shrink: 0;
}

.prag-chat__takeover-back:hover {
	background: rgba(0, 0, 0, 0.06);
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__takeover-title {
	font-family: var(--wp--preset--font-family--outfit, 'Outfit', sans-serif);
	font-weight: 700;
	font-size: 1rem;
	color: var(--wp--preset--color--black, #000000);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	min-width: 0;
}

/* Panel inside takeover */

.prag-chat__takeover .prag-chat__panel {
	flex: 1;
	min-height: 0;
	padding: 1rem 1.25rem;
}

.prag-chat__takeover .prag-chat__messages {
	max-height: none;
	flex: 1 1 0;
	overflow-y: auto;
	min-height: 0;
	scroll-behavior: smooth;
	scrollbar-width: none;
	-ms-overflow-style: none;
	overscroll-behavior: contain;
	touch-action: pan-y;
}

.prag-chat__takeover .prag-chat__messages::-webkit-scrollbar {
	display: none;
}

.prag-chat__takeover .prag-chat__messages:empty {
	display: flex;
}

.prag-chat__takeover .prag-chat__input-area {
	flex-shrink: 0;
	height: auto;
	margin-top: 0.75rem;
	touch-action: manipulation;
}

.prag-chat__takeover .prag-chat__send {
	top: 50%;
	bottom: auto;
	transform: translateY(-50%);
}

.prag-chat__takeover .prag-chat__input,
.prag-chat__takeover .prag-chat__input:focus {
	height: auto !important;
	min-height: 2.75rem;
	max-height: 120px;
	overflow-y: auto;
	padding: 0.625rem 3.5rem 0.625rem 1rem !important;
	font-size: 16px !important;
	line-height: 1.5 !important;
}

/* Suggestions toggle + popover (inside takeover input area) */

.prag-chat__suggestions-toggle {
	display: none;
}

.prag-chat__suggestions-popover {
	display: none;
}

.prag-chat__takeover .prag-chat__suggestions-toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	position: absolute;
	top: 50%;
	transform: translateY(-50%);
	right: 3rem;
	width: 2.25rem;
	height: 2.25rem;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--wp--preset--color--dark-grey, #7a7a7a);
	cursor: pointer;
	padding: 0;
	transition: background 0.15s, color 0.15s;
}

.prag-chat__suggestions-popover--visible ~ .prag-chat__suggestions-toggle {
	background: rgba(255, 196, 37, 0.3);
	color: #000000;
}

.prag-chat__takeover .prag-chat__suggestions-popover {
	display: none;
	position: absolute;
	bottom: 100%;
	right: 0;
	width: max-content;
	max-width: 85%;
	padding: 0.375rem;
	margin-bottom: 0.5rem;
	background: #fff5d6;
	border: 1px solid #FFC425;
	border-radius: 0.75rem;
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
	flex-direction: column;
	gap: 0.25rem;
	z-index: 10;
}

.prag-chat__takeover .prag-chat__suggestions-popover::before,
.prag-chat__takeover .prag-chat__suggestions-popover::after {
	content: '';
	position: absolute;
	right: calc(3rem + 1.125rem - 8px);
	border-left: 8px solid transparent;
	border-right: 8px solid transparent;
}

.prag-chat__takeover .prag-chat__suggestions-popover::before {
	bottom: -9px;
	border-top: 9px solid #FFC425;
}

.prag-chat__takeover .prag-chat__suggestions-popover::after {
	bottom: -7px;
	border-top: 8px solid #fff5d6;
}

.prag-chat__takeover .prag-chat__suggestions-popover--visible {
	display: flex;
}

.prag-chat__takeover .prag-chat__suggestions-popover .prag-chat__suggestion {
	text-align: left;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	color: #000000 !important;
	border: none;
	border-radius: 0.5rem;
	padding: 0.75rem;
	font-size: 0.8125rem;
	background: #ffffff;
	min-height: 2.75rem;
	box-sizing: border-box;
}

.prag-chat__takeover .prag-chat__suggestions-popover .prag-chat__suggestion:active {
	background: rgba(255, 196, 37, 0.15);
}

/* Input area
   ========================================================================== */

.prag-chat__input-area {
	position: relative;
	background: var(--wp--preset--color--white, #ffffff);
	border-radius: var(--wp--custom--border--radius, 0.625rem);
	height: 5.5rem;
}

.prag-chat__input,
.prag-chat__input:invalid,
.prag-chat__input:valid,
.prag-chat__input:focus {
	display: block;
	width: 100% !important;
	height: 100% !important;
	padding: 1.25rem 3.5rem 1.25rem 1.5rem;
	margin: 0 !important;
	border: none !important;
	border-radius: inherit;
	background: transparent !important;
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif) !important;
	font-size: 0.875rem !important;
	color: var(--wp--preset--color--black, #000000) !important;
	outline: none !important;
	box-shadow: none !important;
	line-height: 1.5;
	box-sizing: border-box;
	text-indent: 0 !important;
	letter-spacing: normal !important;
	resize: none;
}

.prag-chat__input::placeholder {
	color: var(--wp--preset--color--dark-grey, #565656);
	font-family: inherit;
	font-size: inherit;
	opacity: 1;
}

.prag-chat__input--thinking::placeholder {
	animation: prag-pulse-placeholder 1.5s ease-in-out infinite;
}

@keyframes prag-pulse-placeholder {
	0%, 100% { opacity: 0.3; }
	50% { opacity: 1; }
}

form.prag-chat__input-area button.prag-chat__send,
.prag-chat__send {
	position: absolute;
	bottom: 0.625rem;
	right: 0.75rem;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	border: none;
	border-radius: 50%;
	background: var(--wp--preset--color--black, #000000);
	color: var(--wp--preset--color--white, #ffffff);
	cursor: pointer;
	transition: opacity 0.3s;
	flex-shrink: 0;
	padding: 0;
	font-size: inherit;
}

.prag-chat__send:hover {
	opacity: 0.75;
}

form.prag-chat__input-area button.prag-chat__send:disabled,
.prag-chat__send:disabled {
	background: var(--wp--preset--color--stone, #dedede);
	cursor: not-allowed;
	opacity: 1;
}

/* Messages area
   ========================================================================== */

.prag-chat__messages {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	scroll-behavior: smooth;
}

.prag-chat__messages:empty {
	display: none;
}

/* Message bubbles
   ========================================================================== */

.prag-chat__bubble {
	max-width: 85%;
	padding: 0.75rem 1rem;
	border-radius: var(--wp--custom--border--radius, 0.625rem);
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif);
	font-size: 0.9375rem;
	line-height: 1.5;
	word-wrap: break-word;
}

.prag-chat__bubble--user {
	align-self: flex-end;
	background: var(--wp--preset--color--marigold, #ffbe21);
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__bubble--bot {
	align-self: flex-start;
	background: var(--wp--preset--color--butter, #ffe7ae);
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__bubble--bot a {
	color: var(--wp--preset--color--black, #000000);
	text-decoration: underline;
}

.prag-chat__bubble--bot a:hover {
	opacity: 0.7;
}

.prag-chat__bubble--bot p {
	margin: 0 0 0.5rem;
}

.prag-chat__bubble--bot p:last-child {
	margin-bottom: 0;
}

/* Typing indicator
   ========================================================================== */

.prag-chat__typing {
	align-self: flex-start;
	background: var(--wp--preset--color--butter, #ffe7ae);
	border-radius: var(--wp--custom--border--radius, 0.625rem);
	padding: 0.75rem 1rem;
	display: flex;
	align-items: center;
	justify-content: center;
}

.prag-chat__typing-icon {
	width: 1rem;
	height: 1.5rem;
	animation: prag-drop-bounce 0.8s infinite ease-in-out;
}

@keyframes prag-drop-bounce {
	0%, 100% { transform: translateY(0); }
	50%      { transform: translateY(-0.4rem); }
}

/* Sources (inside bot bubble)
   ========================================================================== */

.prag-chat__sources-divider {
	border: none;
	border-top: 1px solid rgba(0, 0, 0, 0.1);
	margin: 0.75rem 0 0.5rem;
}

.prag-chat__sources {
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif);
	font-size: 0.8125rem;
	padding-bottom: 0.5rem;
}

.prag-chat__sources summary {
	list-style: none !important;
}

.prag-chat__sources summary::-webkit-details-marker {
	display: none !important;
}

/* Override any theme-injected toggle icons on summary */
.prag-chat__sources summary::before,
.prag-chat__sources summary::after,
.prag-chat__sources-summary::before,
.prag-chat__sources-summary::after {
	display: none !important;
	content: none !important;
}

.prag-chat__sources-summary {
	display: inline-flex;
	align-items: center;
	gap: 0.375rem;
	color: var(--wp--preset--color--dark-grey, #565656);
	font-size: 0.75rem;
	font-weight: 600;
	cursor: pointer;
	transition: color 0.2s;
	user-select: none;
	padding: 0.25rem 0.625rem;
	border-radius: 1rem;
	border: 1px solid rgba(0, 0, 0, 0.12);
	background: transparent;
}

.prag-chat__sources-summary:hover {
	color: var(--wp--preset--color--black, #000000);
	background: rgba(0, 0, 0, 0.04);
}

.prag-chat__sources-icon {
	width: 0.875rem;
	height: 0.875rem;
	flex-shrink: 0;
}

.prag-chat__sources-chevron {
	width: 0.75rem;
	height: 0.75rem;
	flex-shrink: 0;
	transition: transform 0.2s;
}

.prag-chat__sources[open] .prag-chat__sources-chevron {
	transform: rotate(180deg);
}

.prag-chat__sources-list {
	margin-top: 0.5rem;
	display: flex;
	flex-direction: column;
	gap: 0.375rem;
}

.prag-chat__source-item {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	padding: 0.5rem 0.625rem;
	border-radius: 0.5rem;
	background: rgba(255, 196, 37, 0.08);
	border: 1px solid rgba(255, 196, 37, 0.15);
}

.prag-chat__source-num {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 1.25rem;
	height: 1.25rem;
	border-radius: 50%;
	background: var(--wp--preset--color--marigold, #ffbe21);
	color: var(--wp--preset--color--black, #000000);
	font-size: 0.625rem;
	font-weight: 700;
	flex-shrink: 0;
	line-height: 1;
}

.prag-chat__source-body {
	display: flex;
	flex-direction: column;
	gap: 0.125rem;
	min-width: 0;
}

.prag-chat__source-doc {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	font-weight: 600;
	color: var(--wp--preset--color--black, #000000);
	font-size: 0.8125rem;
	line-height: 1.3;
	word-break: break-word;
}

.prag-chat__source-file-icon {
	width: 0.875rem;
	height: 0.875rem;
	flex-shrink: 0;
	color: var(--wp--preset--color--dark-grey, #565656);
}

.prag-chat__source-excerpt {
	color: var(--wp--preset--color--dark-grey, #565656);
	font-size: 0.75rem;
	line-height: 1.4;
}

/* Inline suggestions (pill buttons inside overlay modal)
   ========================================================================== */

.prag-chat__suggestions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	padding-top: 0.75rem;
	flex-shrink: 0;
}

/* Starter questions
   ========================================================================== */

.prag-chat__starters {
	margin-bottom: var(--wp--preset--spacing--40, 1.5rem);
	text-align: center;
}

.prag-chat__starters-label {
	font-family: var(--wp--preset--font-family--outfit, 'Outfit', sans-serif);
	font-size: var(--wp--preset--font-size--small, 16px);
	font-weight: 700;
	text-transform: uppercase;
	color: var(--wp--preset--color--black, #000000);
	margin: 0 0 2rem;
}

.prag-chat__starters-row {
	display: flex;
	gap: 1rem;
	justify-content: center;
}

.prag-chat__starter-chip {
	flex: 1 1 0;
	padding: 1rem 2rem;
	border: 1px solid #FFC425;
	border-radius: var(--wp--custom--border--radius, 0.625rem);
	background: rgba(255, 196, 37, 0.3);
	font-family: var(--wp--preset--font-family--inter);
	font-size: 0.9375rem;
	color: #000000 !important;
	text-decoration: none !important;
	cursor: pointer;
	transition: all 0.3s;
	text-align: center;
	line-height: 1.4;
}

.prag-chat__starter-chip:hover,
.prag-chat__starter-chip:focus-visible {
	background: var(--wp--preset--color--marigold, #ffbe21);
	border-color: var(--wp--preset--color--marigold, #ffbe21);
	outline: none;
}

.prag-chat__starter-chip--used {
	opacity: 0.5;
	border-style: dashed;
}

/* Suggestion pills
   ========================================================================== */

.prag-chat__suggestion {
	padding: 0.4rem 0.875rem;
	border: 1px solid var(--wp--preset--color--stone, #dedede);
	border-radius: 999px;
	background: transparent;
	font-family: var(--wp--preset--font-family--inter, 'Inter', sans-serif);
	font-size: 0.8125rem;
	color: var(--wp--preset--color--dark-grey, #7a7a7a);
	cursor: pointer;
	transition: border-color 0.2s, color 0.2s;
	line-height: 1.4;
}

.prag-chat__suggestion:hover:not(:disabled) {
	border-color: #FFC425;
	color: var(--wp--preset--color--black, #000000);
}

.prag-chat__suggestion:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.prag-chat__suggestion--used {
	opacity: 0.5;
	border-style: dashed;
}

/* Error message
   ========================================================================== */

.prag-chat__error {
	align-self: center;
	margin-top: 1rem;
	padding: 0.625rem 1rem;
	background: #fce9ee;
	color: #a00330;
	border-radius: var(--wp--custom--border--radius, 0.625rem);
	font-size: 0.875rem;
	text-align: center;
}

.prag-chat__retry {
	display: inline-block;
	margin-top: 0.375rem;
	padding: 0.25rem 0.75rem;
	border: 1px solid #a00330;
	border-radius: 4px;
	background: transparent;
	color: #a00330;
	font-size: 0.8125rem;
	cursor: pointer;
}

.prag-chat__retry:hover {
	background: #a00330;
	color: #ffffff;
}

/* Responsive
   ========================================================================== */

@media (max-width: 600px) {
	.prag-chat {
		padding-left: 1rem !important;
		padding-right: 1rem !important;
	}

	.prag-chat__starters-row {
		flex-direction: column;
		align-items: center;
	}

	.prag-chat__starter-chip {
		max-width: 100%;
		width: 100%;
		padding: 0.75rem 1rem;
		font-size: 0.875rem;
	}

	.prag-chat__input-area {
		height: 2.75rem;
		border-radius: 0.625rem;
	}

	.prag-chat__input,
	.prag-chat__input:invalid,
	.prag-chat__input:valid,
	.prag-chat__input:focus {
		padding: 0.625rem 3.5rem 0.625rem 1rem !important;
		font-size: 16px !important;
		line-height: 1.5 !important;
	}

	.prag-chat__send {
		width: 1.75rem;
		height: 1.75rem;
		top: 50%;
		bottom: auto;
		transform: translateY(-50%);
		right: 0.5rem;
	}

	.prag-chat__takeover .prag-chat__panel {
		padding: 0.75rem;
	}

}
