/**
 * AI Chat for WooCommerce widget. Everything is scoped to #aicw so theme styles don't leak in or out.
 * The three brand colours come from AI Chat › Settings as an inline style on #aicw; the darker
 * shades are mixed from them.
 */

#aicw {
	--aicw-primary: #2b6cb0;
	--aicw-header: #1f2937;
	--aicw-accent: #16a34a;
	--aicw-primary-dark: color-mix(in srgb, var(--aicw-primary) 82%, #000);
	--aicw-primary-tint: color-mix(in srgb, var(--aicw-primary) 8%, #fff);
	--aicw-accent-dark: color-mix(in srgb, var(--aicw-accent) 80%, #000);
	--aicw-text: #1f2937;
	--aicw-text-2: #4b5563;
	--aicw-grey: #f3f4f6;
	--aicw-line: #e0e3e7;
	--aicw-muted: #6b7280;
	--aicw-white: #fff;
	--aicw-radius: 14px;
	--aicw-shadow: 0 12px 40px rgba(20, 30, 32, 0.22), 0 2px 8px rgba(20, 30, 32, 0.12);

	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99990;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.45;
	color: var(--aicw-text);
	-webkit-font-smoothing: antialiased;
}

#aicw *,
#aicw *::before,
#aicw *::after {
	box-sizing: border-box;
}

#aicw button,
#aicw input,
#aicw textarea {
	font: inherit;
	color: inherit;
	letter-spacing: normal;
	text-transform: none;
	margin: 0;
}

#aicw .aicw-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

#aicw [hidden] {
	display: none !important;
}

/* Launcher ---------------------------------------------------------------------------------- */

#aicw .aicw-launcher {
	display: flex;
	align-items: center;
	gap: 8px;
	height: 52px;
	padding: 0 20px 0 16px;
	border: 0;
	border-radius: 26px;
	background: var(--aicw-primary);
	color: var(--aicw-white);
	font-weight: 600;
	font-size: 16px;
	box-shadow: var(--aicw-shadow);
	cursor: pointer;
	transition: background-color 0.15s ease, transform 0.15s ease;
}

#aicw .aicw-launcher:hover {
	background: var(--aicw-primary-dark);
	transform: translateY(-1px);
}

#aicw .aicw-launcher:focus-visible,
#aicw button:focus-visible,
#aicw a:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--aicw-primary) 45%, transparent);
	outline-offset: 2px;
}

#aicw .aicw-launcher-icon .aicw-dot {
	fill: var(--aicw-primary);
}

#aicw .aicw-launcher-icon {
	width: 24px;
	height: 24px;
	color: var(--aicw-white);
}

#aicw .aicw-launcher {
	position: relative;
}

#aicw[data-unread="true"] .aicw-launcher::after {
	content: "";
	position: absolute;
	top: -2px;
	right: -2px;
	width: 14px;
	height: 14px;
	border: 2px solid var(--aicw-white);
	border-radius: 50%;
	background: var(--aicw-accent);
}

#aicw[data-open="true"] .aicw-launcher {
	display: none;
}

/* Panel -------------------------------------------------------------------------------------- */

#aicw .aicw-panel {
	position: absolute;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	width: 390px;
	height: min(640px, calc(100vh - 40px));
	background: var(--aicw-white);
	border-radius: var(--aicw-radius);
	box-shadow: var(--aicw-shadow);
	overflow: hidden;
	animation: aicw-in 0.18s ease-out;
}

@keyframes aicw-in {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

#aicw .aicw-head {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 12px 10px 12px 16px;
	background: var(--aicw-header);
	color: var(--aicw-white);
}

#aicw .aicw-head-text {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

#aicw .aicw-title {
	font-size: 16px;
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

#aicw .aicw-subtitle {
	font-size: 12px;
	opacity: 0.8;
}

#aicw[data-team-online="true"] .aicw-team-state::before {
	content: "";
	display: inline-block;
	width: 7px;
	height: 7px;
	margin-right: 5px;
	border-radius: 50%;
	background: var(--aicw-accent);
	vertical-align: 1px;
}

#aicw .aicw-human {
	flex: none;
	padding: 6px 10px;
	border: 1px solid rgba(255, 255, 255, 0.45);
	border-radius: 16px;
	background: transparent;
	color: var(--aicw-white);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
}

#aicw .aicw-human:hover {
	background: rgba(255, 255, 255, 0.12);
}

#aicw .aicw-icon-btn {
	flex: none;
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--aicw-white);
	cursor: pointer;
}

#aicw .aicw-icon-btn:hover {
	background: rgba(255, 255, 255, 0.12);
}

#aicw .aicw-icon-btn svg {
	width: 20px;
	height: 20px;
}

/* Messages ----------------------------------------------------------------------------------- */

#aicw .aicw-log {
	flex: 1;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 14px 8px;
	background: var(--aicw-grey);
}

#aicw .aicw-msg {
	display: flex;
	flex-direction: column;
	margin: 0 0 10px;
}

#aicw .aicw-bubble {
	max-width: 88%;
	padding: 10px 13px;
	border-radius: 14px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

#aicw .aicw-msg--assistant .aicw-bubble,
#aicw .aicw-msg--staff .aicw-bubble {
	align-self: flex-start;
	background: var(--aicw-white);
	border: 1px solid var(--aicw-line);
	border-bottom-left-radius: 4px;
}

#aicw .aicw-msg--staff .aicw-bubble {
	background: color-mix(in srgb, var(--aicw-accent) 8%, #fff);
	border-color: color-mix(in srgb, var(--aicw-accent) 45%, #fff);
}

#aicw .aicw-msg--customer .aicw-bubble {
	align-self: flex-end;
	background: var(--aicw-header);
	color: var(--aicw-white);
	border-bottom-right-radius: 4px;
	white-space: pre-wrap;
}

#aicw .aicw-who {
	margin: 0 0 3px 4px;
	font-size: 12px;
	font-weight: 600;
	color: var(--aicw-accent-dark);
}

#aicw .aicw-bubble p {
	margin: 0 0 8px;
	font-size: inherit;
	line-height: inherit;
}

#aicw .aicw-bubble p:last-child,
#aicw .aicw-bubble ul:last-child,
#aicw .aicw-bubble ol:last-child {
	margin-bottom: 0;
}

#aicw .aicw-bubble ul,
#aicw .aicw-bubble ol {
	margin: 0 0 8px;
	padding-left: 20px;
}

#aicw .aicw-bubble li {
	margin: 0 0 3px;
	list-style: inherit;
}

#aicw .aicw-bubble ul li {
	list-style-type: disc;
}

#aicw .aicw-bubble ol li {
	list-style-type: decimal;
}

#aicw .aicw-bubble a {
	color: var(--aicw-primary-dark);
	text-decoration: underline;
	text-underline-offset: 2px;
}

#aicw .aicw-msg--customer .aicw-bubble a {
	color: var(--aicw-white);
}

#aicw .aicw-bubble strong {
	font-weight: 700;
}

#aicw .aicw-note {
	margin: 4px 12px 12px;
	font-size: 13px;
	text-align: center;
	color: var(--aicw-muted);
}

/* Typing and tool status */

#aicw .aicw-typing {
	display: flex;
	gap: 4px;
	padding: 4px 0;
}

#aicw .aicw-bubble p + .aicw-typing,
#aicw .aicw-bubble ul + .aicw-typing {
	display: none;
}

#aicw .aicw-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--aicw-muted);
	opacity: 0.4;
	animation: aicw-dot 1.2s infinite ease-in-out;
}

#aicw .aicw-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

#aicw .aicw-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes aicw-dot {
	0%, 80%, 100% {
		opacity: 0.3;
		transform: none;
	}
	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

#aicw .aicw-working {
	margin-top: 6px;
	font-size: 13px;
	font-style: italic;
	color: var(--aicw-muted);
}

#aicw .aicw-bubble > .aicw-working:first-child {
	margin-top: 0;
}

/* Suggestions */

#aicw .aicw-suggestions {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 6px;
	margin: 2px 0 12px;
}

#aicw .aicw-chip {
	padding: 7px 12px;
	border: 1px solid var(--aicw-primary);
	border-radius: 16px;
	background: var(--aicw-white);
	color: var(--aicw-primary-dark);
	font-size: 14px;
	text-align: left;
	cursor: pointer;
}

#aicw .aicw-chip:hover {
	background: var(--aicw-primary-tint);
}

/* Product cards */

#aicw .aicw-cards {
	display: flex;
	gap: 8px;
	margin: -2px 0 12px;
	padding-bottom: 4px;
	overflow-x: auto;
	scroll-snap-type: x mandatory;
}

#aicw .aicw-card {
	flex: 0 0 150px;
	display: flex;
	flex-direction: column;
	background: var(--aicw-white);
	border: 1px solid var(--aicw-line);
	border-radius: 10px;
	overflow: hidden;
	color: var(--aicw-text);
	text-decoration: none;
	scroll-snap-align: start;
	transition: border-color 0.15s ease;
}

#aicw .aicw-card:hover {
	border-color: var(--aicw-primary);
}

#aicw .aicw-card img {
	display: block;
	width: 100%;
	height: 100px;
	object-fit: cover;
	background: var(--aicw-grey);
}

#aicw .aicw-card-body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 8px 9px 9px;
	font-size: 12.5px;
}

#aicw .aicw-card-name {
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
	overflow: hidden;
	font-weight: 600;
	line-height: 1.3;
}

#aicw .aicw-card-price {
	margin-top: 3px;
	font-weight: 700;
	color: var(--aicw-text);
}

#aicw .aicw-card-per,
#aicw .aicw-card-stock {
	color: var(--aicw-muted);
}

#aicw .aicw-card-stock.is-in {
	color: var(--aicw-accent-dark);
}

/* Handover form */

/* Square top corners keep the coloured top edge a straight line. */
#aicw .aicw-handover {
	margin: 0 0 12px;
	padding: 14px;
	background: var(--aicw-white);
	border: 1px solid var(--aicw-line);
	border-top: 3px solid var(--aicw-primary);
	border-radius: 0 0 6px 6px;
}

#aicw .aicw-handover-title {
	margin: 0 0 4px;
	font-weight: 700;
}

#aicw .aicw-handover-text {
	margin: 0 0 10px;
	font-size: 13.5px;
	color: var(--aicw-text-2);
}

#aicw .aicw-handover-text a {
	color: var(--aicw-primary-dark);
}

#aicw .aicw-handover label {
	display: block;
	margin: 0 0 8px;
	font-size: 13px;
	font-weight: 600;
}

#aicw .aicw-handover label span {
	font-weight: 400;
	color: var(--aicw-muted);
}

#aicw .aicw-handover input,
#aicw .aicw-handover textarea {
	display: block;
	width: 100%;
	margin-top: 3px;
	padding: 8px 10px;
	border: 1px solid var(--aicw-line);
	border-radius: 8px;
	background: var(--aicw-white);
	font-size: 15px;
	font-weight: 400;
	box-shadow: none;
}

#aicw .aicw-handover input:focus,
#aicw .aicw-handover textarea:focus {
	outline: none;
	border-color: var(--aicw-header);
	box-shadow: 0 0 0 2px rgba(54, 66, 69, 0.15);
}

#aicw .aicw-handover-error {
	margin: 0 0 8px;
	font-size: 13px;
	color: var(--aicw-primary-dark);
}

#aicw .aicw-handover-actions {
	display: flex;
	align-items: center;
	gap: 12px;
}

#aicw .aicw-details-privacy {
	margin: 10px 0 0;
	font-size: 12px;
	color: var(--aicw-muted);
}

#aicw .aicw-details-privacy a {
	color: inherit;
}

#aicw .aicw-button {
	padding: 9px 16px;
	border: 0;
	border-radius: 8px;
	background: var(--aicw-accent);
	color: var(--aicw-white);
	font-weight: 700;
	cursor: pointer;
}

#aicw .aicw-button:hover {
	background: var(--aicw-accent-dark);
}

#aicw .aicw-button:disabled {
	opacity: 0.6;
	cursor: default;
}

#aicw .aicw-link {
	padding: 0;
	border: 0;
	background: none;
	color: var(--aicw-muted);
	text-decoration: underline;
	cursor: pointer;
}

#aicw .aicw-ended {
	display: flex;
	justify-content: center;
	margin: 4px 0 12px;
}

/* Compose ------------------------------------------------------------------------------------ */

#aicw .aicw-compose {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 10px 6px 14px;
	border-top: 1px solid var(--aicw-line);
	background: var(--aicw-white);
}

#aicw .aicw-compose textarea {
	flex: 1;
	min-height: 40px;
	max-height: 120px;
	padding: 9px 0;
	border: 0;
	background: transparent;
	resize: none;
	font-size: 15px;
	line-height: 1.4;
	box-shadow: none;
	outline: none;
}

#aicw .aicw-send {
	flex: none;
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--aicw-primary);
	color: var(--aicw-white);
	cursor: pointer;
}

#aicw .aicw-send:hover {
	background: var(--aicw-primary-dark);
}

#aicw .aicw-send:disabled {
	background: var(--aicw-line);
	cursor: default;
}

#aicw .aicw-send svg {
	width: 18px;
	height: 18px;
}

#aicw .aicw-foot {
	margin: 0;
	padding: 0 14px 10px;
	background: var(--aicw-white);
	font-size: 11px;
	line-height: 1.35;
	color: var(--aicw-muted);
}

#aicw .aicw-foot a {
	color: inherit;
}

/* Phones: full screen ------------------------------------------------------------------------ */

@media (max-width: 600px) {
	#aicw {
		right: 12px;
		bottom: 12px;
	}

	#aicw .aicw-launcher {
		height: 50px;
		padding: 0 14px;
	}

	#aicw .aicw-launcher-label {
		display: none;
	}

	#aicw[data-open="true"] {
		inset: 0;
	}

	#aicw .aicw-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		height: 100dvh;
		border-radius: 0;
	}

	#aicw .aicw-human {
		padding: 5px 8px;
		font-size: 12px;
	}

	#aicw .aicw-compose textarea {
		font-size: 16px; /* stops iOS zooming in */
	}
}

@media (prefers-reduced-motion: reduce) {
	#aicw .aicw-panel,
	#aicw .aicw-typing span {
		animation: none;
	}
}

@media print {
	#aicw {
		display: none;
	}
}
