/* Store Assistant — mobile-first. Colours come from CSS variables set inline by PHP. */

.sa-chat {
	--sa-gap: 16px;
	position: fixed;
	bottom: var(--sa-gap);
	z-index: 99990;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.45;
}
.sa-chat.sa-pos-right { right: var(--sa-gap); }
.sa-chat.sa-pos-left { left: var(--sa-gap); }
.sa-chat *,
.sa-chat *::before,
.sa-chat *::after { box-sizing: border-box; }
.sa-chat [hidden] { display: none !important; }

/* Bubble */
.sa-bubble {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--sa-bubble);
	color: var(--sa-bubble-text);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
	cursor: pointer;
	transition: transform 0.15s ease;
}
.sa-bubble:hover { transform: scale(1.05); }
.sa-bubble:focus-visible,
.sa-chat button:focus-visible,
.sa-link:focus-visible,
.sa-input:focus-visible {
	outline: 2px solid var(--sa-bubble);
	outline-offset: 2px;
}
.sa-chat.is-open .sa-bubble { display: none; }

/* Panel: full width, anchored to the bottom on phones */
.sa-panel {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 85vh;
	height: 85dvh;
	max-height: 520px;
	background: #ffffff;
	border: 0;
	border-radius: 16px 16px 0 0;
	box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
	overflow: hidden;
}

.sa-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 12px 12px 16px;
	background: var(--sa-header);
	color: var(--sa-header-text);
}
.sa-avatar {
	flex: 0 0 36px;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	object-fit: cover;
}
.sa-initials {
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.22);
	font-weight: 700;
	font-size: 14px;
}
.sa-title {
	flex: 1 1 auto;
	min-width: 0;
	font-weight: 700;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.sa-clear,
.sa-close {
	padding: 4px;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	cursor: pointer;
}
.sa-clear { font-size: 13px; text-decoration: underline; }
.sa-close { display: flex; }

/* Messages */
.sa-messages {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	overscroll-behavior: contain;
}
.sa-msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
}
.sa-msg--user { align-self: flex-end; align-items: flex-end; }
.sa-msg--assistant { align-self: flex-start; align-items: flex-start; }
.sa-text {
	padding: 9px 13px;
	border-radius: 16px;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}
.sa-msg--user .sa-text {
	background: var(--sa-user);
	color: var(--sa-user-text);
	border-bottom-right-radius: 4px;
}
.sa-msg--assistant .sa-text {
	background: var(--sa-assistant);
	color: var(--sa-assistant-text);
	border-bottom-left-radius: 4px;
}
.sa-msg--error .sa-text { opacity: 0.85; font-style: italic; }

.sa-links {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-top: 6px;
}
.sa-link {
	display: inline-block;
	padding: 6px 12px;
	border: 0;
	border-radius: 999px;
	background: var(--sa-user);
	color: #ffffff;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
}
.sa-link:hover,
.sa-link:focus { color: #ffffff; text-decoration: none; filter: brightness(0.93); }

/* Typing dots */
.sa-typing {
	flex-direction: row;
	gap: 4px;
	padding: 12px 14px;
	border-radius: 16px;
	background: var(--sa-assistant);
}
.sa-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--sa-assistant-text);
	opacity: 0.4;
	animation: sa-dot 1.2s infinite ease-in-out;
}
.sa-typing span:nth-child(2) { animation-delay: 0.15s; }
.sa-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sa-dot {
	0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
	40% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
	.sa-typing span { animation: none; opacity: 0.7; }
	.sa-bubble { transition: none; }
}

/* Input row */
.sa-input-row {
	display: flex;
	gap: 8px;
	margin: 0;
	padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
	background: #ffffff;
	box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.06);
}
.sa-input {
	flex: 1 1 auto;
	min-width: 0;
	height: 42px;
	margin: 0;
	padding: 0 14px;
	border: 0;
	border-radius: 999px;
	background: #f3f3f3;
	color: #1d2327;
	font: inherit;
	font-size: 16px; /* Prevents iOS zoom on focus. */
	box-shadow: none;
}
.sa-send {
	flex: 0 0 42px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--sa-bubble);
	color: var(--sa-bubble-text);
	cursor: pointer;
}
.sa-send:disabled { opacity: 0.55; cursor: default; }

/* Desktop */
@media (min-width: 480px) {
	.sa-chat { --sa-gap: 20px; }
	.sa-panel {
		position: absolute;
		left: auto;
		right: 0;
		bottom: 0;
		width: 360px;
		height: 520px;
		max-height: calc(100vh - 40px);
		border-radius: 16px;
		box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
	}
	.sa-pos-left .sa-panel { left: 0; right: auto; }
	.sa-input { font-size: 15px; }
}
