/**
 * Bakery AI Chatbot Widget Stylesheet
 *
 * CRITICAL DEFENSE: High-specificity selectors and !important declarations
 * protect all interactive <button> and <input> elements from being overridden
 * by Astra's aggressive global theme button skins.
 *
 * FIX: the original :root block here redefined --bakery-primary,
 * --bakery-secondary, --bakery-accent, --bakery-bg, --bakery-surface,
 * --bakery-text, --bakery-text-muted, and --bakery-border with different
 * hardcoded values than bakery-core's real tokens (e.g. --bakery-primary
 * was #92400e here vs. the real #78350f). Since :root rules are global and
 * this stylesheet loads after bakery-core's, it would have silently
 * overridden the site's actual brand color preset everywhere, not just
 * inside this widget — undoing the theming system already verified live.
 * Fixed: this widget's own :root now only holds non-brand, namespaced
 * tokens (radius/shadow, prefixed --bch- to avoid any future collision);
 * every color below references the real var(--bakery-*) tokens directly,
 * with a safe fallback for the rare case bakery-core isn't active.
 */
:root {
	--bch-shadow: 0 12px 36px -4px rgba(69, 26, 3, 0.18), 0 4px 12px -2px rgba(69, 26, 3, 0.08);
	--bch-radius-lg: 20px;
	--bch-radius-md: 12px;
	--bch-radius-sm: 8px;
}

#bakery-ai-chatbot-container.bakery-ai-chatbot-wrap {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 999990;
	direction: ltr;
	pointer-events: none;
}

/* Defensive Astra Theme Override for Floating Launcher Button */
body #bakery-ai-chatbot-container button#bakery-ai-chatbot-launcher,
button#bakery-ai-chatbot-launcher.bakery-ai-chatbot-launcher {
	pointer-events: auto !important;
	position: relative !important;
	display: flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 60px !important;
	height: 60px !important;
	border-radius: 50% !important;
	background: var(--bakery-primary, #78350f) !important;
	background-color: var(--bakery-primary, #78350f) !important;
	color: #ffffff !important;
	border: 2px solid #ffffff !important;
	box-shadow: 0 8px 24px rgba(120, 53, 15, 0.35) !important;
	cursor: pointer !important;
	padding: 0 !important;
	margin: 0 !important;
	transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s ease !important;
}

body #bakery-ai-chatbot-container button#bakery-ai-chatbot-launcher:hover {
	background: var(--bakery-primary-hover, var(--bakery-accent, #b45309)) !important;
	transform: scale(1.06) translateY(-2px) !important;
}

.bakery-ai-launcher-icon {
	display: flex;
	align-items: center;
	justify-content: center;
}

.bakery-ai-launcher-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 999px;
	background: var(--bakery-danger, #b91c1c);
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	line-height: 18px;
	text-align: center;
	border: 2px solid #fff;
}

.bakery-ai-launcher-badge[hidden] {
	display: none;
}

.bakery-ai-chatbot-window {
	pointer-events: auto;
	position: absolute;
	bottom: 74px;
	right: 0;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: 560px;
	background: var(--bakery-surface, #ffffff);
	border-radius: var(--bch-radius-lg, 20px);
	box-shadow: var(--bch-shadow);
	border: 1px solid var(--bakery-border, #e7e5e4);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: scale(0.92) translateY(18px);
	transform-origin: bottom right;
	transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
	visibility: hidden;
}

.bakery-ai-chatbot-window.is-open {
	opacity: 1;
	transform: scale(1) translateY(0);
	visibility: visible;
}

@media (max-width: 480px) {
	.bakery-ai-chatbot-window {
		width: calc(100vw - 24px);
		height: min(560px, calc(100vh - 100px));
		bottom: 70px;
		right: -12px;
	}
}

/* --- Header --- */
.bakery-ai-chatbot-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 14px 16px;
	background: var(--bakery-primary, #78350f);
	color: #ffffff;
	flex-shrink: 0;
}

.bakery-ai-header-left {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.bakery-ai-header-avatar {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.18);
	color: #ffffff;
	flex-shrink: 0;
}

.bakery-ai-online-dot {
	position: absolute;
	bottom: -1px;
	right: -1px;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #22c55e;
	border: 2px solid var(--bakery-primary, #78350f);
}

.bakery-ai-header-meta {
	min-width: 0;
}

.bakery-ai-header-title {
	margin: 0;
	font-size: 14px;
	font-weight: 700;
	color: #ffffff;
	line-height: 1.3;
}

.bakery-ai-header-subtitle {
	margin: 0;
	font-size: 11.5px;
	color: rgba(255, 255, 255, 0.75);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

body #bakery-ai-chatbot-container button.bakery-ai-chatbot-close-btn {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 30px !important;
	height: 30px !important;
	padding: 0 !important;
	background: rgba(255, 255, 255, 0.12) !important;
	border: none !important;
	border-radius: 50% !important;
	color: #ffffff !important;
	cursor: pointer !important;
	flex-shrink: 0;
}

body #bakery-ai-chatbot-container button.bakery-ai-chatbot-close-btn:hover {
	background: rgba(255, 255, 255, 0.24) !important;
}

/* --- Messages body --- */
.bakery-ai-messages-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--bakery-bg, #fefbf6);
}

.bakery-ai-msg-group {
	display: flex;
	flex-direction: column;
	max-width: 86%;
}

.bakery-ai-msg-group.bot {
	align-self: flex-start;
}

.bakery-ai-msg-group.user {
	align-self: flex-end;
	align-items: flex-end;
}

.bakery-ai-msg-bubble {
	padding: 10px 13px;
	border-radius: var(--bch-radius-md, 12px);
	font-size: 13.5px;
	line-height: 1.5;
}

.bakery-ai-msg-bubble p {
	margin: 0 0 6px;
}

.bakery-ai-msg-bubble p:last-child {
	margin-bottom: 0;
}

.bakery-ai-msg-bubble.bot {
	background: var(--bakery-surface, #ffffff);
	color: var(--bakery-text, #292524);
	border: 1px solid var(--bakery-border, #e7e5e4);
	border-bottom-left-radius: 4px;
}

.bakery-ai-msg-bubble.user {
	background: var(--bakery-primary, #78350f);
	color: #ffffff;
	border-bottom-right-radius: 4px;
}

.bakery-ai-msg-bubble.error {
	background: #fef2f2;
	color: var(--bakery-danger, #b91c1c);
	border: 1px solid #fecaca;
}

/* Suggested Action Buttons Insulated from Astra */
body #bakery-ai-chatbot-container button.bakery-ai-action-btn,
button.bakery-ai-action-btn {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	gap: 6px !important;
	width: 100% !important;
	margin-top: 8px !important;
	padding: 8px 14px !important;
	background: var(--bakery-accent, #b45309) !important;
	color: #ffffff !important;
	border: none !important;
	border-radius: var(--bch-radius-sm, 8px) !important;
	font-size: 12.5px !important;
	font-weight: 600 !important;
	cursor: pointer !important;
	box-shadow: 0 2px 4px rgba(217, 119, 6, 0.25) !important;
}

body #bakery-ai-chatbot-container button.bakery-ai-action-btn:hover {
	background: var(--bakery-primary, #78350f) !important;
	transform: translateY(-1px) !important;
}

body #bakery-ai-chatbot-container button.bakery-ai-action-btn:disabled {
	opacity: 0.7 !important;
	cursor: default !important;
	transform: none !important;
}

/* --- Quick prompts --- */
.bakery-ai-quick-prompts {
	margin-top: 4px;
}

.bakery-ai-quick-title {
	display: block;
	margin-bottom: 6px;
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--bakery-muted, #78716c);
}

.bakery-ai-quick-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

body #bakery-ai-chatbot-container button.bakery-ai-quick-pill {
	display: inline-flex !important;
	align-items: center !important;
	padding: 6px 11px !important;
	background: var(--bakery-surface, #ffffff) !important;
	border: 1px solid var(--bakery-border, #e7e5e4) !important;
	border-radius: 999px !important;
	color: var(--bakery-primary, #78350f) !important;
	font-size: 12px !important;
	font-weight: 600 !important;
	cursor: pointer !important;
}

body #bakery-ai-chatbot-container button.bakery-ai-quick-pill:hover {
	background: var(--bakery-subtle, #f5f5f4) !important;
}

/* --- Typing indicator --- */
.bakery-ai-typing-indicator {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 16px;
	flex-shrink: 0;
}

.bakery-ai-typing-dots {
	display: flex;
	gap: 3px;
}

.bakery-ai-typing-dots span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--bakery-muted, #78716c);
	animation: bakery-ai-bounce 1.2s infinite ease-in-out;
}

.bakery-ai-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.bakery-ai-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bakery-ai-bounce {
	0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
	30% { transform: translateY(-4px); opacity: 1; }
}

.bakery-ai-typing-text {
	font-size: 11.5px;
	color: var(--bakery-muted, #78716c);
}

/* --- Footer / input row --- */
.bakery-ai-chatbot-footer {
	flex-shrink: 0;
	border-top: 1px solid var(--bakery-border, #e7e5e4);
	padding: 10px 12px;
	background: var(--bakery-surface, #ffffff);
}

.bakery-ai-input-wrap {
	display: flex;
	align-items: center;
	gap: 8px;
}

body #bakery-ai-chatbot-container input.bakery-ai-chat-input {
	flex: 1 !important;
	min-width: 0 !important;
	padding: 9px 12px !important;
	background: var(--bakery-subtle, #f5f5f4) !important;
	border: 1px solid var(--bakery-border, #e7e5e4) !important;
	border-radius: var(--bch-radius-sm, 8px) !important;
	color: var(--bakery-text, #292524) !important;
	font-size: 13px !important;
}

body #bakery-ai-chatbot-container input.bakery-ai-chat-input:focus {
	outline: none !important;
	border-color: var(--bakery-primary, #78350f) !important;
}

body #bakery-ai-chatbot-container button.bakery-ai-chat-send-btn {
	display: inline-flex !important;
	align-items: center !important;
	justify-content: center !important;
	width: 36px !important;
	height: 36px !important;
	padding: 0 !important;
	background: var(--bakery-primary, #78350f) !important;
	border: none !important;
	border-radius: 50% !important;
	color: #ffffff !important;
	cursor: pointer !important;
	flex-shrink: 0;
}

body #bakery-ai-chatbot-container button.bakery-ai-chat-send-btn:hover {
	background: var(--bakery-accent, #b45309) !important;
}

body #bakery-ai-chatbot-container button.bakery-ai-chat-send-btn:disabled {
	opacity: 0.6 !important;
	cursor: default !important;
}

.bakery-ai-footer-note {
	display: flex;
	align-items: center;
	gap: 5px;
	margin-top: 6px;
	font-size: 10.5px;
	color: var(--bakery-muted, #78716c);
}