/*
 * S&J Leathers - AI chat widget
 * Floating assistant for the landing page
 */

.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.syj-chat {
	--syj-chat-z: 9000;
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: var(--syj-chat-z);
	font-family: var(--font-family-body, 'Inter', sans-serif);
}

.syj-chat__toggle {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	border: none;
	border-radius: 50%;
	background: var(--color-secondary, #b49463);
	color: var(--color-text-light, #fff);
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(26, 26, 26, 0.18);
	transition: transform var(--transition-base, 0.3s ease),
		background-color var(--transition-base, 0.3s ease);
}

.syj-chat__toggle:hover {
	background: var(--color-secondary-hover, #9e7f53);
	transform: translateY(-2px);
}

.syj-chat__toggle:focus-visible {
	outline: 2px solid var(--color-primary, #1a1a1a);
	outline-offset: 3px;
}

.syj-chat__toggle-icon {
	width: 24px;
	height: 24px;
}

.syj-chat__panel {
	position: absolute;
	right: 0;
	bottom: calc(100% + 12px);
	display: flex;
	flex-direction: column;
	width: min(360px, calc(100vw - 40px));
	max-height: min(520px, calc(100vh - 120px));
	background: #fff;
	border: 1px solid var(--color-border, #e0e0e0);
	border-radius: var(--radius-lg, 12px);
	box-shadow: 0 16px 40px rgba(26, 26, 26, 0.16);
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px) scale(0.98);
	transition: opacity var(--transition-base, 0.3s ease),
		transform var(--transition-base, 0.3s ease),
		visibility var(--transition-base, 0.3s ease);
}

.syj-chat--open .syj-chat__panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

.syj-chat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 18px;
	background: var(--color-bg-cream, #f9f7f2);
	border-bottom: 1px solid var(--color-border-light, #e5e5e5);
}

.syj-chat__title {
	margin: 0;
	font-family: var(--font-family-heading, 'Playfair Display', serif);
	font-size: 1.125rem;
	font-weight: 600;
	color: var(--color-primary, #1a1a1a);
}

.syj-chat__subtitle {
	margin: 4px 0 0;
	font-size: 0.8125rem;
	color: var(--color-text-muted, #6b7280);
}

.syj-chat__header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex-shrink: 0;
}

.syj-chat__expand,
.syj-chat__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border: none;
	border-radius: var(--radius-sm, 4px);
	background: transparent;
	color: var(--color-text-muted, #6b7280);
	cursor: pointer;
}

.syj-chat__header-icon {
	width: 18px;
	height: 18px;
}

.syj-chat__expand:hover,
.syj-chat__close:hover {
	background: rgba(26, 26, 26, 0.06);
	color: var(--color-primary, #1a1a1a);
}

.syj-chat__expand:focus-visible,
.syj-chat__close:focus-visible {
	outline: 2px solid var(--color-primary, #1a1a1a);
	outline-offset: 2px;
}

.syj-chat__close {
	font-size: 1.5rem;
	line-height: 1;
}

.syj-chat--expanded .syj-chat__panel {
	position: fixed;
	right: 20px;
	bottom: 20px;
	top: 20px;
	width: min(520px, calc(100vw - 40px));
	max-height: none;
	height: auto;
}

.syj-chat--expanded .syj-chat__messages {
	max-height: none;
	flex: 1;
	min-height: 0;
}

.syj-chat--expanded .syj-chat__product-image {
	max-width: 280px;
}

.syj-chat__messages {
	flex: 1;
	min-height: 220px;
	max-height: 320px;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #fff;
}

.syj-chat__message {
	max-width: 88%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 0.9375rem;
	line-height: 1.5;
	word-break: break-word;
}

.syj-chat__message--assistant {
	align-self: flex-start;
	background: var(--color-bg-cream, #f9f7f2);
	color: var(--color-text-dark, #333);
	border-bottom-left-radius: 4px;
}

.syj-chat__message--formatted {
	max-width: 92%;
}

.syj-chat__message--formatted p {
	margin: 0 0 0.65rem;
}

.syj-chat__message--formatted p:last-child {
	margin-bottom: 0;
}

.syj-chat__message--formatted strong {
	display: block;
	margin: 0.35rem 0 0.25rem;
	font-family: var(--font-family-heading, 'Playfair Display', serif);
	font-size: 0.98rem;
	font-weight: 600;
	color: var(--color-primary, #1a1a1a);
}

.syj-chat__message--formatted p:first-child strong {
	margin-top: 0;
}

.syj-chat__message--formatted ul,
.syj-chat__message--formatted ol {
	margin: 0 0 0.75rem;
	padding-left: 1.15rem;
}

.syj-chat__message--formatted li {
	margin: 0.2rem 0;
}

.syj-chat__message--formatted li strong {
	display: inline;
	font-family: inherit;
	font-size: inherit;
}

.syj-chat__message--formatted a {
	color: var(--color-secondary-hover, #9e7f53);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.syj-chat__message--formatted a:hover {
	color: var(--color-primary, #1a1a1a);
}

.syj-chat__product-media {
	margin: 0 0 0.5rem;
}

.syj-chat__product-image {
	display: block;
	width: 100%;
	max-width: 220px;
	height: auto;
	border-radius: var(--radius-md, 8px);
	border: 1px solid var(--color-border-light, #e5e5e5);
	background: #fff;
}

.syj-chat__product-link {
	font-weight: 600;
}

.syj-chat__intro {
	margin-bottom: 0.5rem;
}

.syj-chat__intro p:last-child {
	margin-bottom: 0;
}

.syj-chat__product-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin-top: 0.35rem;
}

.syj-chat__product-row {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	padding: 10px;
	border: 1px solid var(--color-border-light, #e5e5e5);
	border-radius: var(--radius-md, 8px);
	background: #fff;
}

.syj-chat__product-row-media-link,
.syj-chat__product-row-media-wrap {
	flex: 0 0 96px;
}

.syj-chat__product-row-media-link {
	display: block;
	border-radius: var(--radius-md, 8px);
	overflow: hidden;
}

.syj-chat__product-row-image {
	display: block;
	width: 96px;
	height: 72px;
	object-fit: cover;
	border-radius: var(--radius-md, 8px);
	border: 1px solid var(--color-border-light, #e5e5e5);
	background: var(--color-bg-cream, #f9f7f2);
}

.syj-chat__product-row-details {
	flex: 1;
	min-width: 0;
}

.syj-chat__product-row-title {
	margin: 0 0 0.35rem;
	font-family: var(--font-family-heading, 'Playfair Display', serif);
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1.3;
	color: var(--color-primary, #1a1a1a);
}

.syj-chat__product-row-copy p {
	margin: 0 0 0.45rem;
	font-size: 0.85rem;
}

.syj-chat__product-row-copy ul {
	margin: 0;
	padding-left: 1rem;
	font-size: 0.84rem;
}

.syj-chat__product-row-copy li {
	margin: 0.15rem 0;
}

.syj-chat__product-row-meta {
	margin: 0 0 0.25rem;
	font-size: 0.84rem;
	color: var(--color-text-dark, #333);
}

.syj-chat__product-row-cta {
	display: inline-block;
	margin-top: 0.45rem;
	font-size: 0.82rem;
	font-weight: 600;
	color: var(--color-secondary-hover, #9e7f53);
	text-decoration: underline;
	text-underline-offset: 2px;
}

.syj-chat__product-row-cta:hover {
	color: var(--color-primary, #1a1a1a);
}

.syj-chat--expanded .syj-chat__product-row-image {
	width: 120px;
	height: 90px;
}

.syj-chat--expanded .syj-chat__product-row-media-link,
.syj-chat--expanded .syj-chat__product-row-media-wrap {
	flex-basis: 120px;
}

.syj-chat__message--user {
	align-self: flex-end;
	background: var(--color-primary, #1a1a1a);
	color: var(--color-text-light, #fff);
	border-bottom-right-radius: 4px;
}

.syj-chat__message--error {
	align-self: stretch;
	background: #fef2f2;
	color: #991b1b;
	border: 1px solid #fecaca;
}

.syj-chat__typing {
	align-self: flex-start;
	padding: 10px 14px;
	background: var(--color-bg-cream, #f9f7f2);
	border-radius: 14px;
	color: var(--color-text-muted, #6b7280);
	font-size: 0.875rem;
}

.syj-chat__form {
	display: flex;
	gap: 8px;
	padding: 12px;
	border-top: 1px solid var(--color-border-light, #e5e5e5);
	background: #fff;
}

.syj-chat__input {
	flex: 1;
	min-width: 0;
	padding: 10px 12px;
	border: 1px solid var(--color-border, #e0e0e0);
	border-radius: var(--radius-md, 8px);
	font: inherit;
	color: var(--color-text-dark, #333);
}

.syj-chat__input:focus {
	outline: none;
	border-color: var(--color-secondary, #b49463);
	box-shadow: 0 0 0 3px rgba(180, 148, 99, 0.2);
}

.syj-chat__send {
	flex-shrink: 0;
	padding: 10px 16px;
	border: none;
	border-radius: var(--radius-md, 8px);
	background: var(--color-secondary, #b49463);
	color: var(--color-text-light, #fff);
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	cursor: pointer;
}

.syj-chat__send:hover:not(:disabled) {
	background: var(--color-secondary-hover, #9e7f53);
}

.syj-chat__send:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.syj-chat__send:focus-visible {
	outline: 2px solid var(--color-primary, #1a1a1a);
	outline-offset: 2px;
}

@media (max-width: 480px) {
	.syj-chat {
		right: 12px;
		bottom: 12px;
	}

	.syj-chat__panel {
		width: calc(100vw - 24px);
	}

	.syj-chat--expanded .syj-chat__panel {
		inset: 12px;
		width: auto;
		right: 12px;
		left: 12px;
		top: 12px;
		bottom: 12px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.syj-chat__toggle,
	.syj-chat__panel {
		transition: none;
	}
}
