/**
 * MPO Chatbot – Frontend Widget Styles
 *
 * BEM methodology. CSS custom properties for theming.
 * All selectors are scoped under .mpo-chatbot to prevent
 * theme / page-builder CSS from overriding widget styles.
 *
 * @package MPO_Chatbot
 */

/* =========================================================================
   Custom properties (scoped to the widget root, not :root)
   ========================================================================= */
.mpo-chatbot {
	--mpo-primary: #0073aa;
	--mpo-secondary: #23282d;
	--mpo-right: 20px;
	--mpo-left: auto;
	--mpo-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	--mpo-radius: 12px;
	--mpo-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
	--mpo-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================================================
   Element reset – prevent theme / page-builder leakage
   Scoped to .mpo-chatbot so nothing outside is affected.
   ========================================================================= */
.mpo-chatbot,
.mpo-chatbot *,
.mpo-chatbot *::before,
.mpo-chatbot *::after {
	box-sizing: border-box !important;
	text-transform: none !important;
	letter-spacing: normal !important;
	text-decoration: none !important;
	text-indent: 0 !important;
	text-shadow: none !important;
	float: none !important;
	word-spacing: normal !important;
}

.mpo-chatbot div,
.mpo-chatbot span,
.mpo-chatbot p,
.mpo-chatbot a,
.mpo-chatbot img,
.mpo-chatbot form,
.mpo-chatbot label,
.mpo-chatbot input,
.mpo-chatbot button,
.mpo-chatbot svg,
.mpo-chatbot ul,
.mpo-chatbot ol,
.mpo-chatbot li {
	margin: 0;
	padding: 0;
	border: 0;
	outline: 0;
	font-size: 100%;
	font-weight: normal;
	font-style: normal;
	vertical-align: baseline;
	background: transparent;
	color: inherit;
	line-height: inherit;
	font-family: inherit;
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	list-style: none;
	min-width: 0;
	min-height: 0;
	max-width: none;
	max-height: none;
}

.mpo-chatbot button {
	cursor: pointer;
}

.mpo-chatbot img,
.mpo-chatbot svg {
	display: inline-block;
	max-width: 100%;
	height: auto;
}

/* =========================================================================
   Toggle button (FAB)
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__toggle {
	position: fixed;
	bottom: 20px;
	right: var(--mpo-right);
	left: var(--mpo-left);
	z-index: 999998;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--mpo-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--mpo-shadow);
	transition: transform var(--mpo-transition), opacity var(--mpo-transition);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	line-height: 0;
}

.mpo-chatbot .mpo-chatbot__toggle:hover {
	transform: scale(1.08);
}

.mpo-chatbot .mpo-chatbot__toggle:focus-visible {
	outline: 2px solid var(--mpo-primary);
	outline-offset: 3px;
}

.mpo-chatbot .mpo-chatbot__toggle svg {
	width: 24px;
	height: 24px;
	fill: currentColor;
	stroke: none;
}

.mpo-chatbot .mpo-chatbot__toggle .mpo-icon-close {
	display: none;
}

/* Custom toggle icon (uploaded image) */
.mpo-chatbot .mpo-chatbot__toggle .mpo-icon-custom {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	object-fit: cover;
}

.mpo-chatbot.mpo-chatbot--open .mpo-chatbot__toggle .mpo-icon-chat,
.mpo-chatbot.mpo-chatbot--open .mpo-chatbot__toggle .mpo-icon-custom {
	display: none;
}

.mpo-chatbot.mpo-chatbot--open .mpo-chatbot__toggle .mpo-icon-close {
	display: block;
}

/* =========================================================================
   Chat window
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__window {
	position: fixed;
	bottom: 88px;
	right: var(--mpo-right);
	left: var(--mpo-left);
	z-index: 999999;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 520px;
	max-height: calc(100vh - 120px);
	border-radius: var(--mpo-radius);
	background: #fff;
	color: #1d2327;
	box-shadow: var(--mpo-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	font-family: var(--mpo-font);
	font-size: 14px;
	line-height: 1.5;
	opacity: 0;
	visibility: hidden;
	transform: translateY(16px) scale(0.96);
	transition: opacity var(--mpo-transition), transform var(--mpo-transition), visibility var(--mpo-transition);
}

.mpo-chatbot.mpo-chatbot--open .mpo-chatbot__window {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

/* Inline variant (shortcode / block) */
.mpo-chatbot .mpo-chatbot__window--inline {
	position: relative;
	bottom: auto;
	right: auto;
	left: auto;
	width: 100%;
	height: 100%;
	max-width: none;
	max-height: none;
	opacity: 1;
	visibility: visible;
	transform: none;
	border: 1px solid #ddd;
}

/* =========================================================================
   Header
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	background: var(--mpo-primary);
	color: #fff;
	flex-shrink: 0;
	border: none;
	border-radius: 0;
}

.mpo-chatbot .mpo-chatbot__header-info {
	display: flex;
	align-items: center;
	gap: 10px;
}

.mpo-chatbot .mpo-chatbot__header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
}

.mpo-chatbot .mpo-chatbot__avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	border: none;
}

.mpo-chatbot .mpo-chatbot__bot-name {
	font-weight: 600;
	font-size: 15px;
	color: #fff;
}

.mpo-chatbot .mpo-chatbot__close {
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	line-height: 0;
}

.mpo-chatbot .mpo-chatbot__close:hover,
.mpo-chatbot .mpo-chatbot__new-chat:hover {
	background: rgba(255, 255, 255, 0.2);
}

.mpo-chatbot .mpo-chatbot__close svg,
.mpo-chatbot .mpo-chatbot__new-chat svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
}

.mpo-chatbot .mpo-chatbot__new-chat {
	background: none;
	border: none;
	color: #fff;
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	line-height: 0;
	opacity: 0.85;
	transition: opacity 0.15s;
}

.mpo-chatbot .mpo-chatbot__new-chat:hover {
	opacity: 1;
}

/* =========================================================================
   Messages area
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	scroll-behavior: smooth;
	background: #fff;
}

/* Scrollbar styling */
.mpo-chatbot .mpo-chatbot__messages::-webkit-scrollbar {
	width: 6px;
}

.mpo-chatbot .mpo-chatbot__messages::-webkit-scrollbar-thumb {
	background: #ccc;
	border-radius: 3px;
}

/* Single message */
.mpo-chatbot .mpo-chatbot__message {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: var(--mpo-radius);
	word-wrap: break-word;
	overflow-wrap: break-word;
	animation: mpo-fadeIn 0.2s ease;
	border: none;
	flex-shrink: 0;
	height: auto;
}

@keyframes mpo-fadeIn {
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* Bot message */
.mpo-chatbot .mpo-chatbot__message--bot {
	align-self: flex-start;
	background: #f0f0f0;
	color: #1d2327;
	border-bottom-left-radius: 4px;
}

/* User message */
.mpo-chatbot .mpo-chatbot__message--user {
	align-self: flex-end;
	background: var(--mpo-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

/* Typing indicator */
.mpo-chatbot .mpo-chatbot__typing {
	display: none;
	align-self: flex-start;
	padding: 10px 18px;
	background: #f0f0f0;
	border-radius: var(--mpo-radius);
	border-bottom-left-radius: 4px;
}

.mpo-chatbot .mpo-chatbot__typing--visible {
	display: flex;
}

.mpo-chatbot .mpo-chatbot__typing-dot {
	width: 7px;
	height: 7px;
	margin: 0 2px;
	background: #999;
	border-radius: 50%;
	display: inline-block;
	animation: mpo-bounce 1.4s infinite both;
}

.mpo-chatbot .mpo-chatbot__typing-dot:nth-child(2) { animation-delay: 0.16s; }
.mpo-chatbot .mpo-chatbot__typing-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes mpo-bounce {
	0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
	40%           { transform: scale(1);   opacity: 1; }
}

/* =========================================================================
   Suggested questions
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__suggested {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 16px 8px;
	flex-shrink: 0;
	background: #fff;
}

.mpo-chatbot .mpo-chatbot__suggested:empty {
	display: none;
}

.mpo-chatbot .mpo-chatbot__chip {
	display: inline-block;
	padding: 6px 12px;
	font-size: 13px;
	line-height: 1.3;
	border: 1px solid var(--mpo-primary);
	border-radius: 16px;
	background: #fff;
	color: var(--mpo-primary);
	cursor: pointer;
	transition: background var(--mpo-transition), color var(--mpo-transition);
	font-family: var(--mpo-font);
}

.mpo-chatbot .mpo-chatbot__chip:hover,
.mpo-chatbot .mpo-chatbot__chip:focus {
	background: var(--mpo-primary);
	color: #fff;
}

/* =========================================================================
   Input form
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__form {
	display: flex;
	align-items: center;
	padding: 10px 12px;
	border-top: 1px solid #e0e0e0;
	background: #fafafa;
	flex-shrink: 0;
	margin: 0;
	border-bottom: none;
	border-left: none;
	border-right: none;
}

.mpo-chatbot .mpo-chatbot__input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 20px;
	padding: 8px 14px;
	font-size: 14px;
	font-family: var(--mpo-font);
	outline: none;
	transition: border-color var(--mpo-transition);
	background: #fff;
	color: #1d2327;
	height: auto;
	width: auto;
	min-height: 0;
	max-height: none;
	box-shadow: none;
	line-height: 1.5;
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
}

.mpo-chatbot .mpo-chatbot__input::placeholder {
	color: #999;
	opacity: 1;
}

.mpo-chatbot .mpo-chatbot__input:focus {
	border-color: var(--mpo-primary);
	box-shadow: none;
	outline: none;
}

.mpo-chatbot .mpo-chatbot__send {
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	margin-left: 8px;
	border: none;
	border-radius: 50%;
	background: var(--mpo-primary);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	transition: opacity var(--mpo-transition);
	line-height: 0;
}

.mpo-chatbot .mpo-chatbot__send:hover {
	opacity: 0.85;
	background: var(--mpo-primary);
}

.mpo-chatbot .mpo-chatbot__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.mpo-chatbot .mpo-chatbot__send svg {
	width: 18px;
	height: 18px;
	fill: none;
	stroke: currentColor;
}

/* =========================================================================
   Markdown styles inside bot messages
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-heading {
	margin: 8px 0 4px;
	font-weight: 600 !important;
	line-height: 1.3;
	color: #1d2327;
}

.mpo-chatbot .mpo-chatbot__message--bot h3.mpo-md-heading { font-size: 16px; }
.mpo-chatbot .mpo-chatbot__message--bot h4.mpo-md-heading { font-size: 15px; }
.mpo-chatbot .mpo-chatbot__message--bot h5.mpo-md-heading { font-size: 14px; }
.mpo-chatbot .mpo-chatbot__message--bot h6.mpo-md-heading { font-size: 13px; }

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-list {
	margin: 6px 0;
	padding-left: 20px !important;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-list li {
	margin-bottom: 2px;
	line-height: 1.5;
}

.mpo-chatbot .mpo-chatbot__message--bot ul.mpo-md-list li {
	list-style: disc !important;
}

.mpo-chatbot .mpo-chatbot__message--bot ol.mpo-md-list li {
	list-style: decimal !important;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-inline {
	background: #e4e4e7;
	color: #b91c1c;
	padding: 1px 5px;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
	font-size: 12px;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-pre {
	background: #1e1e2e;
	color: #cdd6f4;
	padding: 10px 12px;
	border-radius: 8px;
	margin: 8px 0;
	overflow-x: auto;
	font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
	font-size: 12px;
	line-height: 1.5;
	white-space: pre;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-pre .mpo-md-code {
	background: none;
	color: inherit;
	padding: 0;
	font-size: inherit;
	font-family: inherit;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-link {
	color: var(--mpo-primary) !important;
	text-decoration: underline !important;
	font-weight: 500 !important;
}

.mpo-chatbot .mpo-chatbot__message--bot .mpo-md-link:hover {
	opacity: 0.8;
}

/* =========================================================================
   Message feedback buttons (thumbs up / down)
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__feedback {
	display: flex;
	gap: 4px;
	margin-top: 6px;
	justify-content: flex-start;
}

.mpo-chatbot .mpo-chatbot__feedback-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	border: 1px solid #ddd;
	border-radius: 6px;
	background: #fff;
	color: #999;
	cursor: pointer;
	padding: 0;
	transition: all 0.15s ease;
	line-height: 0;
}

.mpo-chatbot .mpo-chatbot__feedback-btn:hover {
	border-color: var(--mpo-primary);
	color: var(--mpo-primary);
	background: rgba(0, 115, 170, 0.05);
}

.mpo-chatbot .mpo-chatbot__feedback-btn:disabled {
	cursor: default;
}

.mpo-chatbot .mpo-chatbot__feedback-btn--active {
	border-color: var(--mpo-primary);
	color: var(--mpo-primary);
	background: rgba(0, 115, 170, 0.1);
}

.mpo-chatbot .mpo-chatbot__feedback-btn--active[data-feedback="negative"] {
	border-color: #b91c1c;
	color: #b91c1c;
	background: rgba(185, 28, 28, 0.1);
}

.mpo-chatbot .mpo-chatbot__feedback-btn svg {
	width: 14px;
	height: 14px;
	fill: none;
	stroke: currentColor;
}

.mpo-chatbot .mpo-chatbot__feedback-thanks {
	font-size: 11px;
	color: #999;
	align-self: center;
	margin-left: 4px;
	animation: mpo-fade-in 0.2s ease;
}

/* =========================================================================
   Streaming cursor
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__message--streaming::after {
	content: '▍';
	display: inline;
	animation: mpo-blink 0.7s steps(2) infinite;
	color: var(--mpo-primary, #2563eb);
	font-weight: bold;
}

@keyframes mpo-blink {
	0% { opacity: 1; }
	50% { opacity: 0; }
}

/* =========================================================================
   Error state
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__message--error {
	background: #fef2f2;
	color: #b91c1c;
	border: 1px solid #fecaca;
	font-size: 13px;
}

/* Bot message with product cards – use full width */
.mpo-chatbot .mpo-chatbot__message--bot:has(.mpo-product-grid) {
	max-width: 95%;
}

/* =========================================================================
   Product cards
   ========================================================================= */
.mpo-chatbot .mpo-product-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 8px;
	margin: 8px 0 4px;
	width: 100%;
}

.mpo-chatbot .mpo-product-grid .mpo-product-card:only-child {
	grid-column: 1 / -1;
}

.mpo-chatbot .mpo-product-card {
	background: #fff;
	border: 1px solid #e2e2e2;
	border-radius: 10px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	transition: box-shadow 0.2s ease, transform 0.2s ease;
	text-decoration: none !important;
	color: inherit !important;
	cursor: pointer;
}

.mpo-chatbot .mpo-product-card:hover {
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	transform: translateY(-2px);
}

.mpo-chatbot .mpo-product-card__image {
	width: 100%;
	aspect-ratio: 4 / 3;
	overflow: hidden;
	background: #f5f5f5;
}

.mpo-chatbot .mpo-product-card__image img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.mpo-chatbot .mpo-product-card__body {
	padding: 10px;
	display: flex;
	flex-direction: column;
	flex: 1;
}

.mpo-chatbot .mpo-product-card__title {
	font-size: 13px;
	font-weight: 600 !important;
	margin: 0 0 4px;
	color: #1a1a1a;
	line-height: 1.3;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.mpo-chatbot .mpo-product-card__desc {
	font-size: 11px;
	color: #666;
	margin: 0 0 8px;
	line-height: 1.4;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	flex: 1;
}

.mpo-chatbot .mpo-product-card__price {
	font-size: 14px;
	font-weight: 700 !important;
	color: var(--mpo-primary);
	margin-bottom: 0;
	display: block;
	margin-top: auto;
}

/* =========================================================================
   Powered-by footer (optional)
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__footer {
	text-align: center;
	padding: 4px 0;
	font-size: 11px;
	color: #999;
	background: #fafafa;
	border-top: 1px solid #e0e0e0;
}

/* =========================================================================
   Mobile responsiveness
   ========================================================================= */
@media (max-width: 480px) {
	.mpo-chatbot .mpo-chatbot__window {
		width: calc(100vw - 16px);
		height: calc(100vh - 100px);
		bottom: 78px;
		right: 8px !important;
		left: 8px !important;
		border-radius: 10px;
	}

	.mpo-chatbot .mpo-chatbot__toggle {
		width: 50px;
		height: 50px;
		bottom: 16px;
	}

	.mpo-chatbot .mpo-product-grid {
		grid-template-columns: 1fr;
	}
}

/* =========================================================================
   Attention bubble (above toggle)
   ========================================================================= */
.mpo-chatbot .mpo-chatbot__attention {
	position: fixed;
	bottom: 88px;
	right: var(--mpo-right);
	left: var(--mpo-left);
	z-index: 999998;
	display: none;
	align-items: center;
	gap: 6px;
	max-width: 260px;
	padding: 10px 14px;
	background: #fff;
	color: #1d2327;
	font-family: var(--mpo-font);
	font-size: 13px;
	line-height: 1.4;
	border-radius: 10px;
	box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
	animation: mpo-attention-in 0.5s ease forwards;
	transform-origin: bottom center;
}

/* Position the tail / pointer toward the toggle button */
.mpo-chatbot .mpo-chatbot__attention::after {
	content: '';
	position: absolute;
	bottom: -8px;
	right: 20px;
	width: 0;
	height: 0;
	border-left: 8px solid transparent;
	border-right: 8px solid transparent;
	border-top: 8px solid #fff;
}

.mpo-chatbot .mpo-chatbot__attention--visible {
	display: flex;
}

.mpo-chatbot .mpo-chatbot__attention-text {
	flex: 1;
}

.mpo-chatbot .mpo-chatbot__attention-close {
	flex-shrink: 0;
	width: 20px;
	height: 20px;
	border: none;
	background: none;
	color: #999;
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
}

.mpo-chatbot .mpo-chatbot__attention-close:hover {
	color: #333;
	background: #f0f0f0;
}

/* Subtle pulsing glow on the toggle while attention bubble is visible */
.mpo-chatbot--attention .mpo-chatbot__toggle {
	animation: mpo-pulse 2s ease-in-out infinite;
}

@keyframes mpo-attention-in {
	0%   { opacity: 0; transform: translateY(8px) scale(0.9); }
	100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes mpo-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(var(--mpo-primary-rgb, 0, 115, 170), 0.5); }
	50%      { box-shadow: 0 0 0 10px rgba(var(--mpo-primary-rgb, 0, 115, 170), 0); }
}

/* Hide attention bubble when chat is open */
.mpo-chatbot.mpo-chatbot--open .mpo-chatbot__attention {
	display: none !important;
}

/* Left-position: move the pointer */
.mpo-chatbot .mpo-chatbot__attention[data-position="left"]::after {
	right: auto;
	left: 20px;
}

/* Mobile */
@media (max-width: 480px) {
	.mpo-chatbot .mpo-chatbot__attention {
		bottom: 78px;
		right: 8px;
		max-width: calc(100vw - 80px);
	}
}

/* =========================================================================
   Screen-reader only helper
   ========================================================================= */
.mpo-chatbot .mpo-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* =========================================================================
   Reduced motion
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
	.mpo-chatbot .mpo-chatbot__window,
	.mpo-chatbot .mpo-chatbot__toggle,
	.mpo-chatbot .mpo-chatbot__message,
	.mpo-chatbot .mpo-chatbot__chip,
	.mpo-chatbot .mpo-chatbot__typing-dot {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}
