/*
 * On-site chat widget (web-chat-widget.js's own docblock explains why
 * this is its own small anchored panel rather than the .yp-drawer
 * primitive global.css already defines). z-index sits above the sticky
 * header (900) but below .yp-drawer (1000) on purpose — if a customer
 * opens the cart/search drawer while this is open, its backdrop should
 * naturally cover the widget rather than fight it for the top layer.
 */

.yp-chat-widget {
	position: fixed;
	right: var(--wp--preset--spacing--sm);
	bottom: var(--wp--preset--spacing--sm);
	z-index: 950;
}

.yp-chat-fab {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	border: none;
	background: var(--wp--custom--gradient-brand);
	color: var(--wp--preset--color--white);
	box-shadow: var(--wp--custom--shadow-elevation--high);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 150ms ease;
}

.yp-chat-fab:hover {
	transform: scale(1.05);
}

.yp-chat-fab svg,
.yp-chat-fab__icon-open {
	position: absolute;
	transition: opacity 120ms ease, transform 120ms ease;
}

.yp-chat-fab svg {
	width: 24px;
	height: 24px;
}

/* The mascot's own face — direct request, giving the launcher a real
   face instead of a generic chat-bubble icon. Filled to the edges of
   the circular button (object-fit: cover crops rather than letterboxes
   the source image's slightly-taller-than-square canvas) and nudged up
   a couple pixels since the mascot's own head sits above center in its
   source art — centering the crop as-is would push the face down
   toward the antenna/body instead of framing it. */
.yp-chat-fab__icon-open {
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: cover;
	object-position: center -4px;
}

.yp-chat-fab__icon-close {
	opacity: 0;
	transform: scale(0.7);
}

.yp-chat-widget.is-open .yp-chat-fab__icon-open {
	opacity: 0;
	transform: scale(0.7);
}

.yp-chat-widget.is-open .yp-chat-fab__icon-close {
	opacity: 1;
	transform: scale(1);
}

.yp-chat-panel {
	position: absolute;
	right: 0;
	bottom: calc(56px + var(--wp--preset--spacing--xs));
	width: min(360px, calc(100vw - 2 * var(--wp--preset--spacing--sm)));
	height: min(520px, calc(100vh - 140px));
	background: var(--wp--preset--color--white);
	border-radius: var(--wp--custom--radius--card);
	box-shadow: var(--wp--custom--shadow-elevation--high);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* The [hidden] attribute's UA default (display: none) has lower specificity
 * than the class rule above and loses to it, so the panel stays visible —
 * and toggling `panel.hidden` in JS has no visual effect — without this. */
.yp-chat-panel[hidden] {
	display: none;
}

.yp-chat-panel__header {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.9rem 1rem;
	background: var(--wp--custom--gradient-navy);
	color: var(--wp--preset--color--warm-white);
	font-family: var(--wp--preset--font-family--heading);
	font-weight: 700;
}

.yp-chat-panel__header .yp-icon-button {
	width: 1.85rem;
	height: 1.85rem;
	background: transparent;
	border-color: rgba(255, 255, 255, 0.3);
	color: var(--wp--preset--color--warm-white) !important;
}

.yp-chat-panel__title {
	display: flex;
	align-items: center;
	gap: 0.55rem;
}

.yp-chat-panel__avatar {
	width: 1.85rem;
	height: 1.85rem;
	border-radius: 50%;
	object-fit: cover;
	object-position: center -1px;
	background: rgba(255, 255, 255, 0.15);
	flex-shrink: 0;
}

.yp-chat-panel__body {
	flex: 1;
	overflow-y: auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	background: var(--wp--preset--color--warm-white);
}

/**
 * A message row pairs a bubble with its avatar (bot only — a user
 * message has nothing to show next to it, so its row is just the
 * bubble) — direct request, giving bot replies a real face instead of
 * a plain bubble under a text-only header. `max-width` moved here from
 * the bubble itself so it constrains the row (avatar + bubble
 * together) against the panel width; the bubble's own `min-width: 0`
 * is what actually lets its text wrap instead of overflowing once it's
 * a flex child rather than the width-constrained element directly.
 */
.yp-chat-message-row {
	display: flex;
	align-items: flex-end;
	gap: 0.4rem;
	max-width: 85%;
}

.yp-chat-message-row--bot {
	align-self: flex-start;
}

.yp-chat-message-row--user {
	align-self: flex-end;
	justify-content: flex-end;
}

.yp-chat-message__avatar {
	width: 22px;
	height: 22px;
	border-radius: 50%;
	object-fit: cover;
	object-position: center -1px;
	background: var(--wp--preset--color--light-gray);
	flex-shrink: 0;
}

.yp-chat-message {
	min-width: 0;
	padding: 0.55rem 0.8rem;
	border-radius: var(--wp--custom--radius--input);
	font-size: 0.88rem;
	line-height: 1.45;
	word-wrap: break-word;
}

.yp-chat-message a {
	color: inherit;
	text-decoration: underline;
}

.yp-chat-message--bot {
	background: var(--wp--preset--color--white);
	border: 1px solid var(--wp--preset--color--light-gray);
	color: var(--wp--preset--color--near-black);
	border-bottom-left-radius: 4px;
}

.yp-chat-message--user {
	background: var(--wp--preset--color--near-black);
	color: var(--wp--preset--color--warm-white);
	border-bottom-right-radius: 4px;
}

.yp-chat-message--typing {
	color: var(--wp--preset--color--charcoal);
	font-weight: 700;
	letter-spacing: 0.1em;
}

.yp-chat-panel__form {
	flex-shrink: 0;
	display: flex;
	gap: 0.5rem;
	padding: 0.75rem;
	border-top: 1px solid var(--wp--preset--color--light-gray);
	background: var(--wp--preset--color--white);
}

.yp-chat-panel__form input {
	flex: 1;
	min-width: 0;
	font-family: var(--wp--preset--font-family--body);
	font-size: 0.88rem;
	padding: 0.6rem 0.8rem;
	border: 1.5px solid var(--wp--preset--color--light-gray);
	border-radius: var(--wp--custom--radius--input);
	background: var(--wp--preset--color--warm-white);
	color: var(--wp--preset--color--near-black);
}

.yp-chat-panel__form input:focus {
	outline: none;
	border-color: var(--wp--preset--color--near-black);
}

.yp-chat-panel__form button {
	width: 2.6rem;
	flex-shrink: 0;
	border: none;
	border-radius: var(--wp--custom--radius--control);
	background: var(--wp--preset--color--near-black);
	color: var(--wp--preset--color--warm-white);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.yp-chat-panel__form button svg {
	width: 16px;
	height: 16px;
}

@media (max-width: 480px) {
	.yp-chat-widget {
		right: var(--wp--preset--spacing--xs);
		bottom: var(--wp--preset--spacing--xs);
	}

	.yp-chat-panel {
		width: calc(100vw - 2 * var(--wp--preset--spacing--xs));
	}
}
