/*
 * CadUnlock AI Chat — storefront widget styles.
 * Brand: navy primary (#0b1f3a) + orange accent (#f5821f). Colours can be overridden by
 * the plugin settings through the --cuchat-primary / --cuchat-accent custom properties.
 * Text placed on the accent colour always uses the primary colour to keep WCAG AA contrast.
 */

.cuchat,
.cuchat *,
.cuchat *::before,
.cuchat *::after {
	box-sizing: border-box;
}

.cuchat {
	--cuchat-primary: #0b1f3a;
	--cuchat-accent: #f5821f;
	--cuchat-accent-strong: #dc751c;
	--cuchat-surface: #fff;
	--cuchat-surface-alt: #f4f6fa;
	--cuchat-bubble-agent: #eaeff6;
	--cuchat-bubble-visitor: #fdebd9;
	--cuchat-text: #0b1f3a;
	--cuchat-muted: #4b5a70;
	--cuchat-border: #d9dfe8;
	--cuchat-success: #15703a;
	--cuchat-warning: #b26a00;
	--cuchat-danger: #b42318;
	--cuchat-radius: 18px;
	--cuchat-shadow: 0 18px 48px rgba(11, 31, 58, 0.28), 0 2px 8px rgba(11, 31, 58, 0.14);
	--cuchat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	--cuchat-z: 99999;

	position: fixed;
	bottom: max(20px, env(safe-area-inset-bottom));
	z-index: var(--cuchat-z);
	font-family: var(--cuchat-font);
	font-size: 15px;
	line-height: 1.45;
	color: var(--cuchat-text);
	direction: ltr;
	text-align: left;
	-webkit-font-smoothing: antialiased;
}

@supports (color: color-mix(in srgb, red 50%, white)) {
	.cuchat {
		--cuchat-bubble-visitor: color-mix(in srgb, var(--cuchat-accent) 16%, white);
		--cuchat-bubble-agent: color-mix(in srgb, var(--cuchat-primary) 9%, white);
		--cuchat-accent-strong: color-mix(in srgb, var(--cuchat-accent) 90%, black);
	}
}

.cuchat--right {
	right: max(20px, env(safe-area-inset-right));
}

.cuchat--left {
	left: max(20px, env(safe-area-inset-left));
}

.cuchat__sr-only {
	position: absolute !important;
	width: 1px !important;
	height: 1px !important;
	padding: 0 !important;
	margin: -1px !important;
	overflow: hidden !important;
	clip: rect(0, 0, 0, 0) !important;
	clip-path: inset(50%) !important;
	white-space: nowrap !important;
	border: 0 !important;
}

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

.cuchat__launcher {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 10px;
	min-height: 56px;
	padding: 0 20px 0 16px;
	margin: 0;
	border: 0;
	border-radius: 999px;
	background: var(--cuchat-primary);
	color: #fff;
	font: 600 15px/1 var(--cuchat-font);
	letter-spacing: 0.01em;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(11, 31, 58, 0.32);
	transition: transform 160ms ease, box-shadow 160ms ease;
	-webkit-appearance: none;
	appearance: none;
	text-decoration: none;
}

.cuchat__launcher:hover {
	transform: translateY(-1px);
	box-shadow: 0 14px 32px rgba(11, 31, 58, 0.36);
}

.cuchat__launcher:focus {
	outline: none;
}

.cuchat__launcher:focus-visible {
	outline: 3px solid var(--cuchat-accent);
	outline-offset: 3px;
}

.cuchat__launcher-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	color: var(--cuchat-accent);
}

.cuchat__launcher-icon svg {
	display: block;
}

.cuchat__launcher-icon--close {
	display: none;
	color: #fff;
}

.cuchat--open .cuchat__launcher-icon--open {
	display: none;
}

.cuchat--open .cuchat__launcher-icon--close {
	display: inline-flex;
}

.cuchat--open .cuchat__launcher-label {
	display: none;
}

.cuchat__badge {
	position: absolute;
	top: -6px;
	right: -4px;
	min-width: 24px;
	height: 24px;
	padding: 0 7px;
	border-radius: 12px;
	background: var(--cuchat-accent);
	color: var(--cuchat-primary);
	font: 700 13px/24px var(--cuchat-font);
	text-align: center;
	box-shadow: 0 0 0 2px #fff;
}

.cuchat__badge[hidden] {
	display: none;
}

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

.cuchat__panel {
	position: absolute;
	bottom: 72px;
	display: flex;
	flex-direction: column;
	width: 384px;
	max-width: calc(100vw - 32px);
	height: min(640px, calc(100vh - 120px));
	height: min(640px, calc(100dvh - 120px));
	overflow: hidden;
	border-radius: var(--cuchat-radius);
	background: var(--cuchat-surface);
	box-shadow: var(--cuchat-shadow);
	transform-origin: bottom right;
	animation: cuchat-pop 180ms ease-out;
}

.cuchat--left .cuchat__panel {
	left: 0;
	transform-origin: bottom left;
}

.cuchat--right .cuchat__panel {
	right: 0;
}

.cuchat__panel[hidden] {
	display: none;
}

.cuchat__panel:focus {
	outline: none;
}

@keyframes cuchat-pop {
	from {
		opacity: 0;
		transform: translateY(12px) scale(0.98);
	}

	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Header */

.cuchat__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 12px 14px 16px;
	background: var(--cuchat-primary);
	color: #fff;
}

.cuchat__brand {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

.cuchat__mark {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 40px;
	height: 40px;
	border-radius: 12px;
	background: var(--cuchat-accent);
	color: var(--cuchat-primary);
}

.cuchat__brand-text {
	min-width: 0;
}

.cuchat__title {
	margin: 0;
	padding: 0;
	font: 700 16px/1.25 var(--cuchat-font);
	color: #fff;
	letter-spacing: 0.005em;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.cuchat__status {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 3px 0 0;
	font-size: 13px;
	line-height: 1.2;
	color: rgba(255, 255, 255, 0.92);
}

.cuchat__status-dot {
	display: inline-block;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: #9aa6b8;
	box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.cuchat__status[data-mode="human"] .cuchat__status-dot {
	background: #3ddc84;
}

.cuchat__status[data-mode="ai"] .cuchat__status-dot {
	background: var(--cuchat-accent);
}

.cuchat__status[data-mode="offline"] .cuchat__status-dot {
	background: #9aa6b8;
}

.cuchat__header-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: 0 0 auto;
}

.cuchat__iconbtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 10px;
	background: transparent;
	color: #fff;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.cuchat__iconbtn:hover {
	background: rgba(255, 255, 255, 0.12);
}

.cuchat__iconbtn:focus {
	outline: none;
}

.cuchat__iconbtn:focus-visible {
	outline: 3px solid #fff;
	outline-offset: -3px;
}

.cuchat__menu-wrap {
	position: relative;
}

.cuchat__menu {
	position: absolute;
	top: calc(100% + 4px);
	right: 0;
	z-index: 2;
	min-width: 240px;
	margin: 0;
	padding: 6px;
	list-style: none;
	border-radius: 12px;
	background: var(--cuchat-surface);
	color: var(--cuchat-text);
	box-shadow: 0 12px 32px rgba(11, 31, 58, 0.24);
	border: 1px solid var(--cuchat-border);
}

.cuchat__menu[hidden] {
	display: none;
}

.cuchat__menu li {
	margin: 0;
	padding: 0;
}

.cuchat__menu-item {
	display: block;
	width: 100%;
	padding: 10px 12px;
	margin: 0;
	border: 0;
	border-radius: 8px;
	background: transparent;
	color: var(--cuchat-text);
	font: 500 14px/1.3 var(--cuchat-font);
	text-align: left;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.cuchat__menu-item:hover {
	background: var(--cuchat-surface-alt);
}

.cuchat__menu-item:focus {
	outline: none;
}

.cuchat__menu-item:focus-visible {
	outline: 3px solid var(--cuchat-primary);
	outline-offset: -3px;
}

/* Notice bar */

.cuchat__notice {
	padding: 10px 16px;
	background: #fff4e5;
	color: #7a4a00;
	font-size: 13.5px;
	border-bottom: 1px solid #f3d9b1;
}

.cuchat__notice[hidden] {
	display: none;
}

.cuchat__notice--error {
	background: #fdecea;
	color: #8a1c14;
	border-bottom-color: #f5c6c2;
}

.cuchat__notice--info {
	background: var(--cuchat-surface-alt);
	color: var(--cuchat-muted);
	border-bottom-color: var(--cuchat-border);
}

/* Messages */

.cuchat__messages {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px 14px;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: var(--cuchat-surface);
	scroll-behavior: smooth;
}

.cuchat__messages:focus {
	outline: none;
}

.cuchat__messages:focus-visible {
	outline: 3px solid var(--cuchat-primary);
	outline-offset: -3px;
}

.cuchat__msg {
	display: flex;
	flex-direction: column;
	max-width: 86%;
	gap: 3px;
}

.cuchat__msg--visitor {
	align-self: flex-end;
	align-items: flex-end;
}

.cuchat__msg--agent,
.cuchat__msg--ai {
	align-self: flex-start;
	align-items: flex-start;
}

.cuchat__msg-sender {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 0 4px;
	font-size: 12px;
	font-weight: 600;
	color: var(--cuchat-muted);
}

.cuchat__msg--visitor .cuchat__msg-sender {
	display: none;
}

.cuchat__ai-tag {
	display: inline-block;
	padding: 1px 6px;
	border-radius: 6px;
	background: var(--cuchat-bubble-visitor);
	color: var(--cuchat-primary);
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	border: 1px solid var(--cuchat-accent);
}

.cuchat__msg-body {
	padding: 10px 14px;
	border-radius: 16px;
	background: var(--cuchat-bubble-agent);
	color: var(--cuchat-text);
	font-size: 15px;
	line-height: 1.45;
	white-space: pre-wrap;
	overflow-wrap: break-word;
	overflow-wrap: anywhere;
}

.cuchat__msg--agent .cuchat__msg-body,
.cuchat__msg--ai .cuchat__msg-body {
	border-bottom-left-radius: 6px;
}

.cuchat__msg--visitor .cuchat__msg-body {
	background: var(--cuchat-bubble-visitor);
	border-bottom-right-radius: 6px;
}

.cuchat__msg-body a {
	color: var(--cuchat-primary);
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.cuchat__msg-body a:focus-visible {
	outline: 2px solid var(--cuchat-primary);
	outline-offset: 2px;
}

.cuchat__msg-time {
	padding: 0 4px;
	font-size: 11.5px;
	color: var(--cuchat-muted);
}

.cuchat__msg--system {
	align-self: center;
	align-items: center;
	max-width: 100%;
	text-align: center;
}

.cuchat__msg--system .cuchat__msg-sender {
	display: none;
}

.cuchat__msg--system .cuchat__msg-body {
	padding: 8px 12px;
	border-radius: 10px;
	background: var(--cuchat-surface-alt);
	color: var(--cuchat-muted);
	font-size: 13.5px;
	border: 1px dashed var(--cuchat-border);
}

.cuchat__msg--pending .cuchat__msg-body {
	opacity: 0.7;
}

.cuchat__msg--failed .cuchat__msg-body {
	outline: 2px solid var(--cuchat-danger);
}

.cuchat__msg-retry {
	padding: 0;
	margin: 0;
	border: 0;
	background: none;
	color: var(--cuchat-danger);
	font: 600 12px/1.2 var(--cuchat-font);
	text-decoration: underline;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

/* Typing indicator */

.cuchat__typing {
	align-self: flex-start;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 12px 14px;
	border-radius: 16px;
	border-bottom-left-radius: 6px;
	background: var(--cuchat-bubble-agent);
}

.cuchat__typing[hidden] {
	display: none;
}

.cuchat__typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cuchat-muted);
	animation: cuchat-blink 1.2s infinite ease-in-out;
}

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

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

@keyframes cuchat-blink {
	0%,
	80%,
	100% {
		opacity: 0.25;
		transform: translateY(0);
	}

	40% {
		opacity: 1;
		transform: translateY(-2px);
	}
}

/* Details (email) form */

.cuchat__details {
	padding: 12px 14px;
	border-top: 1px solid var(--cuchat-border);
	background: var(--cuchat-surface-alt);
}

.cuchat__details[hidden] {
	display: none;
}

.cuchat__details-text {
	margin: 0 0 8px;
	font-size: 13.5px;
	color: var(--cuchat-muted);
}

.cuchat__details-row {
	display: flex;
	gap: 8px;
	margin-top: 8px;
}

.cuchat__input {
	width: 100%;
	min-height: 42px;
	padding: 8px 12px;
	margin: 0;
	border: 1px solid var(--cuchat-border);
	border-radius: 10px;
	background: #fff;
	color: var(--cuchat-text);
	font: 400 16px/1.3 var(--cuchat-font);
	-webkit-appearance: none;
	appearance: none;
	box-shadow: none;
}

.cuchat__input:focus {
	outline: 2px solid var(--cuchat-primary);
	outline-offset: 0;
	border-color: var(--cuchat-primary);
}

.cuchat__btn {
	flex: 0 0 auto;
	min-height: 42px;
	padding: 0 16px;
	margin: 0;
	border: 0;
	border-radius: 10px;
	background: var(--cuchat-accent);
	color: var(--cuchat-primary);
	font: 700 14px/1 var(--cuchat-font);
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.cuchat__btn:hover {
	background: var(--cuchat-accent-strong);
	color: var(--cuchat-primary);
}

.cuchat__btn:focus {
	outline: none;
}

.cuchat__btn:focus-visible {
	outline: 3px solid var(--cuchat-primary);
	outline-offset: 2px;
}

.cuchat__details-feedback {
	margin: 6px 0 0;
	min-height: 1em;
	font-size: 13px;
	color: var(--cuchat-success);
}

.cuchat__details-feedback.is-error {
	color: var(--cuchat-danger);
}

/* Composer */

.cuchat__composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--cuchat-border);
	background: var(--cuchat-surface);
}

.cuchat__textarea {
	flex: 1 1 auto;
	width: 100%;
	max-height: 140px;
	min-height: 44px;
	padding: 11px 14px;
	margin: 0;
	border: 1px solid var(--cuchat-border);
	border-radius: 14px;
	background: var(--cuchat-surface-alt);
	color: var(--cuchat-text);
	font: 400 16px/1.35 var(--cuchat-font);
	resize: none;
	overflow-y: auto;
	-webkit-appearance: none;
	appearance: none;
	box-shadow: none;
}

.cuchat__textarea::placeholder {
	color: #5a687f;
	opacity: 1;
}

.cuchat__textarea:focus {
	outline: 2px solid var(--cuchat-primary);
	outline-offset: 0;
	border-color: var(--cuchat-primary);
	background: #fff;
}

.cuchat__textarea:disabled {
	opacity: 0.6;
}

.cuchat__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 46px;
	height: 46px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 14px;
	background: var(--cuchat-accent);
	color: var(--cuchat-primary);
	cursor: pointer;
	transition: background-color 120ms ease, color 120ms ease;
	-webkit-appearance: none;
	appearance: none;
}

.cuchat__send:hover {
	background: var(--cuchat-accent-strong);
	color: var(--cuchat-primary);
}

.cuchat__send:disabled {
	cursor: default;
	opacity: 0.55;
}

.cuchat__send:focus {
	outline: none;
}

.cuchat__send:focus-visible {
	outline: 3px solid var(--cuchat-primary);
	outline-offset: 2px;
}

.cuchat__footnote {
	margin: 0;
	padding: 6px 14px 10px;
	font-size: 11.5px;
	line-height: 1.35;
	color: var(--cuchat-muted);
	text-align: center;
	background: var(--cuchat-surface);
}

.cuchat__footnote[hidden] {
	display: none;
}

/* ------------------------------------------------------------------ */
/* Responsive                                                           */
/* ------------------------------------------------------------------ */

@media (max-width: 640px) {
	.cuchat__launcher {
		min-height: 58px;
		padding: 0 15px;
	}

	.cuchat__launcher-label {
		display: none;
	}

	.cuchat--open .cuchat__launcher {
		display: none;
	}

	.cuchat__panel {
		position: fixed;
		inset: 0;
		width: auto;
		max-width: none;
		height: 100vh;
		height: 100dvh;
		border-radius: 0;
		animation: cuchat-slide 200ms ease-out;
	}

	.cuchat__header {
		padding-top: max(14px, env(safe-area-inset-top));
	}

	.cuchat__composer {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
	}

	.cuchat__footnote {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
	}

	.cuchat__msg {
		max-width: 90%;
	}
}

@keyframes cuchat-slide {
	from {
		opacity: 0;
		transform: translateY(24px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@media (max-height: 520px) and (min-width: 641px) {
	.cuchat__panel {
		height: calc(100vh - 100px);
		height: calc(100dvh - 100px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.cuchat__panel,
	.cuchat__launcher,
	.cuchat__typing span,
	.cuchat__send {
		animation: none !important;
		transition: none !important;
	}

	.cuchat__messages {
		scroll-behavior: auto;
	}
}

@media (forced-colors: active) {
	.cuchat__launcher,
	.cuchat__send,
	.cuchat__btn,
	.cuchat__iconbtn {
		border: 1px solid ButtonText;
	}

	.cuchat__msg-body {
		border: 1px solid CanvasText;
	}
}

@media print {
	.cuchat {
		display: none !important;
	}
}
