/**
 * CaliBoyz AI Support — Widget styles
 * Optimized for desktop & mobile
 */

:root {
	--cbas-primary: #1a472a;
	--cbas-accent: #c9a227;
	--cbas-primary-dark: #0f2d1a;
	--cbas-bg: #ffffff;
	--cbas-surface: #f7f9f8;
	--cbas-border: rgba(26, 71, 42, 0.12);
	--cbas-text: #1a1f1c;
	--cbas-text-muted: #5c6b62;
	--cbas-shadow: 0 12px 40px rgba(15, 45, 26, 0.18);
	--cbas-radius: 18px;
	--cbas-z: 2147483000;
	--cbas-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

.cbas-root {
	position: fixed;
	right: max(16px, env(safe-area-inset-right));
	bottom: max(16px, env(safe-area-inset-bottom));
	z-index: var(--cbas-z);
	font-family: var(--cbas-font);
	font-size: 15px;
	line-height: 1.45;
	color: var(--cbas-text);
	pointer-events: none;
}

.cbas-root * {
	box-sizing: border-box;
}

.cbas-root .cbas-launcher,
.cbas-root .cbas-panel,
.cbas-root .cbas-teaser,
.cbas-root .cbas-backdrop {
	pointer-events: auto;
}

/* Launcher FAB */
.cbas-launcher {
	position: relative;
	width: 60px;
	height: 60px;
	border: none;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--cbas-primary) 0%, var(--cbas-primary-dark) 100%);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--cbas-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.25s ease, box-shadow 0.25s ease;
	-webkit-tap-highlight-color: transparent;
}

.cbas-launcher:hover {
	transform: scale(1.05);
	box-shadow: 0 16px 48px rgba(15, 45, 26, 0.28);
}

.cbas-launcher:active {
	transform: scale(0.97);
}

.cbas-launcher-label {
	position: absolute;
	right: calc(100% + 10px);
	white-space: nowrap;
	background: #fff;
	color: var(--cbas-primary);
	font-size: 13px;
	font-weight: 600;
	padding: 8px 14px;
	border-radius: 999px;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
	border: 1px solid var(--cbas-border);
	opacity: 0;
	transform: translateX(8px);
	transition: opacity 0.2s, transform 0.2s;
	pointer-events: none;
}

.cbas-launcher:hover .cbas-launcher-label,
.cbas-root.cbas-teaser-visible .cbas-launcher-label {
	opacity: 1;
	transform: translateX(0);
}

/* Teaser bubble */
.cbas-teaser {
	position: absolute;
	right: 0;
	bottom: 76px;
	width: min(280px, calc(100vw - 32px));
	background: #fff;
	border: 1px solid var(--cbas-border);
	border-radius: 16px;
	padding: 14px 16px 12px;
	box-shadow: var(--cbas-shadow);
	animation: cbas-teaser-in 0.35s ease;
}

.cbas-teaser[hidden] {
	display: none !important;
}

@keyframes cbas-teaser-in {
	from { opacity: 0; transform: translateY(10px) scale(0.96); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

.cbas-teaser-close {
	position: absolute;
	top: 6px;
	right: 8px;
	border: none;
	background: transparent;
	font-size: 20px;
	line-height: 1;
	color: var(--cbas-text-muted);
	cursor: pointer;
	padding: 4px;
}

.cbas-teaser-text {
	margin: 0 0 10px;
	font-size: 14px;
	line-height: 1.4;
	padding-right: 16px;
}

.cbas-teaser-open {
	border: none;
	background: var(--cbas-primary);
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	padding: 8px 14px;
	border-radius: 999px;
	cursor: pointer;
	font-family: inherit;
	width: 100%;
}

.cbas-teaser-open:hover {
	background: var(--cbas-primary-dark);
}

/* Mobile backdrop */
.cbas-backdrop {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.45);
	z-index: 0;
}

body.cbas-chat-open .cbas-backdrop {
	display: none;
}

.cbas-launcher {
	z-index: 2;
}

.cbas-panel {
	z-index: 3;
}

.cbas-teaser {
	z-index: 2;
}

.cbas-launcher-icon {
	position: absolute;
	width: 26px;
	height: 26px;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.cbas-launcher-icon--close {
	opacity: 0;
	transform: rotate(-90deg) scale(0.8);
}

.cbas-root.is-open .cbas-launcher-icon--chat {
	opacity: 0;
	transform: rotate(90deg) scale(0.8);
}

.cbas-root.is-open .cbas-launcher-icon--close {
	opacity: 1;
	transform: rotate(0) scale(1);
}

.cbas-launcher-pulse {
	position: absolute;
	inset: -4px;
	border-radius: 50%;
	border: 2px solid var(--cbas-accent);
	opacity: 0;
	animation: cbas-pulse 2.5s ease-out infinite;
	pointer-events: none;
}

.cbas-root:not(.is-open):not(.cbas-has-interacted) .cbas-launcher-pulse {
	opacity: 1;
}

@keyframes cbas-pulse {
	0% { transform: scale(1); opacity: 0.6; }
	100% { transform: scale(1.35); opacity: 0; }
}

/* Panel */
.cbas-panel {
	position: absolute;
	right: 0;
	bottom: 76px;
	width: min(400px, calc(100vw - 32px - env(safe-area-inset-left) - env(safe-area-inset-right)));
	height: min(620px, calc(100dvh - 120px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
	max-height: calc(100dvh - 100px);
	background: var(--cbas-bg);
	border-radius: var(--cbas-radius);
	box-shadow: var(--cbas-shadow);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--cbas-border);
	opacity: 0;
	transform: translateY(16px) scale(0.96);
	transition: opacity 0.28s ease, transform 0.28s ease;
}

.cbas-root.is-open .cbas-panel {
	opacity: 1;
	transform: translateY(0) scale(1);
}

.cbas-panel[hidden] {
	display: none !important;
}

/* Header */
.cbas-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--cbas-primary) 0%, var(--cbas-primary-dark) 100%);
	color: #fff;
	flex-shrink: 0;
}

.cbas-header-info {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.cbas-avatar {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.15);
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}

.cbas-avatar svg {
	width: 22px;
	height: 22px;
	color: var(--cbas-accent);
}

.cbas-agent-name {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.cbas-status {
	margin: 2px 0 0;
	font-size: 12px;
	opacity: 0.85;
	display: flex;
	align-items: center;
	gap: 6px;
}

.cbas-status-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #4ade80;
	box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

.cbas-header-actions {
	display: flex;
	gap: 4px;
	flex-shrink: 0;
}

.cbas-icon-btn {
	width: 34px;
	height: 34px;
	border: none;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
}

.cbas-icon-btn:hover {
	background: rgba(255, 255, 255, 0.22);
}

.cbas-icon-btn svg {
	width: 18px;
	height: 18px;
}

/* Messages */
.cbas-messages {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: var(--cbas-surface);
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
}

.cbas-message {
	max-width: 88%;
	animation: cbas-msg-in 0.3s ease;
}

@keyframes cbas-msg-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: translateY(0); }
}

.cbas-message--user {
	align-self: flex-end;
}

.cbas-message--assistant {
	align-self: flex-start;
}

.cbas-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}

.cbas-message--user .cbas-bubble {
	background: var(--cbas-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.cbas-message--assistant .cbas-bubble {
	background: #fff;
	color: var(--cbas-text);
	border: 1px solid var(--cbas-border);
	border-bottom-left-radius: 4px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.cbas-bubble p {
	margin: 0 0 0.5em;
}

.cbas-bubble p:last-child {
	margin-bottom: 0;
}

.cbas-bubble a {
	color: var(--cbas-primary);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.cbas-message--user .cbas-bubble a {
	color: var(--cbas-accent);
}

/* Typing indicator */
.cbas-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 12px 16px;
	background: #fff;
	border: 1px solid var(--cbas-border);
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	width: fit-content;
}

.cbas-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cbas-text-muted);
	animation: cbas-dot 1.2s infinite ease-in-out;
}

.cbas-typing span:nth-child(2) { animation-delay: 0.15s; }
.cbas-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cbas-dot {
	0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
	40% { transform: scale(1); opacity: 1; }
}

/* Product cards */
.cbas-products {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-top: 10px;
}

.cbas-product-card {
	display: flex;
	gap: 10px;
	padding: 10px;
	background: var(--cbas-surface);
	border: 1px solid var(--cbas-border);
	border-radius: 12px;
	text-decoration: none;
	color: inherit;
	transition: border-color 0.15s, transform 0.15s;
}

.cbas-product-card:hover {
	border-color: var(--cbas-accent);
	transform: translateY(-1px);
}

.cbas-product-img {
	width: 56px;
	height: 56px;
	border-radius: 8px;
	object-fit: cover;
	background: #e8ece9;
	flex-shrink: 0;
}

.cbas-product-img--placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
}

.cbas-product-info {
	min-width: 0;
	flex: 1;
}

.cbas-product-name {
	font-weight: 600;
	font-size: 13px;
	line-height: 1.3;
	margin: 0 0 4px;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.cbas-product-price {
	font-size: 13px;
	color: var(--cbas-primary);
	font-weight: 600;
	margin: 0;
}

.cbas-product-badge {
	display: inline-block;
	font-size: 10px;
	font-weight: 700;
	text-transform: uppercase;
	padding: 2px 6px;
	border-radius: 4px;
	background: var(--cbas-accent);
	color: #1a1f1c;
	margin-left: 6px;
	vertical-align: middle;
}

.cbas-product-oos {
	font-size: 11px;
	color: #b91c1c;
	margin-top: 2px;
}

.cbas-product-cta {
	display: inline-block;
	margin-top: 6px;
	font-size: 12px;
	font-weight: 600;
	color: var(--cbas-primary);
}

/* Quick prompts */
.cbas-quick-prompts {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	padding: 0 16px 10px;
	background: var(--cbas-surface);
	flex-shrink: 0;
}

.cbas-quick-prompts:empty {
	display: none;
	padding: 0;
}

.cbas-quick-btn {
	border: 1px solid var(--cbas-border);
	background: #fff;
	color: var(--cbas-primary);
	font-size: 12px;
	padding: 6px 12px;
	border-radius: 20px;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s;
	white-space: nowrap;
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	font-family: inherit;
}

.cbas-quick-btn:hover {
	background: rgba(26, 71, 42, 0.06);
	border-color: var(--cbas-primary);
}

/* Input area */
.cbas-input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid var(--cbas-border);
	background: #fff;
	flex-shrink: 0;
}

.cbas-input {
	flex: 1;
	border: 1px solid var(--cbas-border);
	border-radius: 12px;
	padding: 10px 14px;
	font-family: inherit;
	font-size: 15px;
	line-height: 1.4;
	resize: none;
	max-height: 120px;
	min-height: 42px;
	outline: none;
	transition: border-color 0.15s, box-shadow 0.15s;
	background: var(--cbas-surface);
}

.cbas-input:focus {
	border-color: var(--cbas-primary);
	box-shadow: 0 0 0 3px rgba(26, 71, 42, 0.12);
}

.cbas-send {
	width: 42px;
	height: 42px;
	border: none;
	border-radius: 12px;
	background: var(--cbas-primary);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background 0.15s, opacity 0.15s;
}

.cbas-send:not(:disabled):hover {
	background: var(--cbas-primary-dark);
}

.cbas-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.cbas-send svg {
	width: 20px;
	height: 20px;
}

/* Footer */
.cbas-footer {
	text-align: center;
	padding: 6px;
	font-size: 10px;
	color: var(--cbas-text-muted);
	background: #fff;
	border-top: 1px solid var(--cbas-border);
	flex-shrink: 0;
}

/* Mobile fullscreen mode */
@media (max-width: 480px) {
	.cbas-panel {
		position: fixed;
		right: max(0px, env(safe-area-inset-right));
		left: max(0px, env(safe-area-inset-left));
		bottom: max(0px, env(safe-area-inset-bottom));
		width: auto;
		height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
		max-height: none;
		border-radius: var(--cbas-radius) var(--cbas-radius) 0 0;
	}

	.cbas-root.is-open .cbas-launcher {
		opacity: 0;
		pointer-events: none;
		transform: scale(0.8);
	}

	body.cbas-chat-open .cbas-backdrop {
		display: block;
	}

	.cbas-message {
		max-width: 92%;
	}

	.cbas-quick-prompts {
		flex-wrap: nowrap;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
		padding-bottom: 12px;
	}

	.cbas-quick-prompts::-webkit-scrollbar {
		display: none;
	}

	.cbas-quick-btn {
		flex-shrink: 0;
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.cbas-panel,
	.cbas-launcher,
	.cbas-launcher-icon,
	.cbas-message,
	.cbas-launcher-pulse {
		animation: none !important;
		transition: none !important;
	}
}

/* Screen reader only */
.cbas-root .screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	word-wrap: normal !important;
}
