/**
 * CodeJack Chat — widget styles.
 * Everything is scoped under .cjchat-root and driven by CSS custom
 * properties so the host theme cannot bleed in and admin can retheme
 * without touching this file.
 */

:root {
	--cjchat-accent: #7c5cff;
	--cjchat-surface: #14141c;
	--cjchat-text: #f4f4f8;
	--cjchat-radius: 16px;
	--cjchat-font: inherit;
}

.cjchat-root,
.cjchat-root * {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
	font-family: var(--cjchat-font);
	line-height: 1.45;
	letter-spacing: normal;
	text-transform: none;
	text-shadow: none;
	-webkit-font-smoothing: antialiased;
}

.cjchat-root {
	position: fixed;
	z-index: 2147483000;
	inset: auto 20px 20px auto;
	font-size: 15px;
	color: var(--cjchat-text);
	color-scheme: dark;
}

/* Launcher bubble */
.cjchat-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--cjchat-accent);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
	position: relative;
}

.cjchat-launcher svg {
	width: 26px;
	height: 26px;
}

.cjchat-launcher::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: var(--cjchat-accent);
	opacity: 0.6;
	animation: cjchat-pulse 2.4s ease-out infinite;
}

@media (prefers-reduced-motion: reduce) {
	.cjchat-launcher::before {
		animation: none;
		display: none;
	}
}

@keyframes cjchat-pulse {
	0% { transform: scale(1); opacity: 0.5; }
	100% { transform: scale(1.6); opacity: 0; }
}

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

/* Panel */
.cjchat-panel {
	position: absolute;
	bottom: 76px;
	right: 0;
	width: 380px;
	max-width: calc(100vw - 40px);
	height: 600px;
	max-height: calc(100vh - 120px);
	background: var(--cjchat-surface);
	background: color-mix(in srgb, var(--cjchat-surface) 88%, transparent);
	backdrop-filter: blur(18px);
	-webkit-backdrop-filter: blur(18px);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: var(--cjchat-radius);
	box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.cjchat-panel[hidden] {
	display: none;
}

.cjchat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 14px 16px;
	border-bottom: 1px solid rgba(255, 255, 255, 0.08);
	flex-shrink: 0;
}

.cjchat-header-title {
	font-weight: 600;
	font-size: 15px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.cjchat-header-actions {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-shrink: 0;
}

.cjchat-icon-btn {
	background: rgba(255, 255, 255, 0.08);
	border: none;
	color: var(--cjchat-text);
	width: 32px;
	height: 32px;
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cjchat-icon-btn:hover {
	background: rgba(255, 255, 255, 0.16);
}

.cjchat-icon-btn:focus-visible,
.cjchat-launcher:focus-visible,
.cjchat-send:focus-visible,
.cjchat-chip:focus-visible,
.cjchat-input textarea:focus-visible,
.cjchat-gate-form input:focus-visible,
.cjchat-gate-form select:focus-visible,
.cjchat-gate-submit:focus-visible {
	outline: 2px solid var(--cjchat-accent);
	outline-offset: 2px;
}

.cjchat-whatsapp-btn {
	background: #25d366;
	color: #06210f;
	font-size: 12px;
	font-weight: 600;
	border: none;
	border-radius: 999px;
	padding: 6px 12px;
	cursor: pointer;
	display: flex;
	align-items: center;
	gap: 4px;
	white-space: nowrap;
}

.cjchat-whatsapp-btn:hover {
	filter: brightness(1.08);
}

/* Chat body wrapper: swapped out for .cjchat-gate while the pre-chat form is active */
.cjchat-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 0;
}

.cjchat-body[hidden] {
	display: none;
}

/* Message list */
.cjchat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.cjchat-msg {
	max-width: 88%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 14px;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.cjchat-msg p {
	margin: 0 0 6px;
}
.cjchat-msg p:last-child { margin-bottom: 0; }
.cjchat-msg ul,
.cjchat-msg ol {
	margin: 0 0 6px 18px;
}
.cjchat-msg a {
	color: var(--cjchat-accent);
	text-decoration: underline;
}
.cjchat-msg code {
	background: rgba(255, 255, 255, 0.12);
	padding: 1px 5px;
	border-radius: 4px;
	font-size: 13px;
}

.cjchat-msg-user {
	align-self: flex-end;
	background: var(--cjchat-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.cjchat-msg-assistant {
	align-self: flex-start;
	background: rgba(255, 255, 255, 0.06);
	border-bottom-left-radius: 4px;
}

.cjchat-typing {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 10px 14px;
	background: rgba(255, 255, 255, 0.06);
	border-radius: 14px;
}

.cjchat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--cjchat-text);
	opacity: 0.6;
	animation: cjchat-bounce 1.2s infinite ease-in-out;
}
.cjchat-typing span:nth-child(2) { animation-delay: 0.15s; }
.cjchat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes cjchat-bounce {
	0%, 80%, 100% { transform: translateY(0); }
	40% { transform: translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
	.cjchat-typing span { animation: none; opacity: 0.9; }
}

/* Suggested prompt chips */
.cjchat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 0 16px 12px;
	flex-shrink: 0;
}

.cjchat-chip {
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(255, 255, 255, 0.12);
	color: var(--cjchat-text);
	border-radius: 999px;
	padding: 7px 12px;
	font-size: 13px;
	cursor: pointer;
	text-align: left;
}

.cjchat-chip:hover {
	background: rgba(255, 255, 255, 0.14);
}

/* Pre-chat gate: replaces the chat body until the visitor submits their details */
.cjchat-gate {
	flex: 1;
	overflow-y: auto;
	padding: 20px 16px;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.cjchat-gate[hidden] {
	display: none;
}

.cjchat-gate-intro {
	font-size: 14px;
	opacity: 0.85;
	margin-bottom: 16px;
}

.cjchat-gate-form {
	display: flex;
	flex-direction: column;
}

.cjchat-gate-label {
	font-size: 12px;
	font-weight: 600;
	opacity: 0.8;
	margin: 12px 0 6px;
}

.cjchat-gate-label:first-of-type {
	margin-top: 0;
}

.cjchat-gate-form input[type="text"],
.cjchat-gate-form input[type="email"],
.cjchat-gate-form input[type="tel"],
.cjchat-gate-form select {
	width: 100%;
	padding: 10px 12px;
	border-radius: 8px;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(0, 0, 0, 0.25);
	color: var(--cjchat-text);
	font-size: 14px;
	appearance: none;
	-webkit-appearance: none;
}

.cjchat-gate-form select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23f4f4f8'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5' stroke='%23f4f4f8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 10px center;
	padding-right: 32px;
}

/* Browser autofill (name/email) forces its own background + black text,
   ignoring a plain `color` rule — this is the standard workaround. */
.cjchat-gate-form input:-webkit-autofill,
.cjchat-gate-form input:-webkit-autofill:hover,
.cjchat-gate-form input:-webkit-autofill:focus {
	-webkit-text-fill-color: var(--cjchat-text);
	caret-color: var(--cjchat-text);
	-webkit-box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.25) inset;
	box-shadow: 0 0 0 1000px rgba(0, 0, 0, 0.25) inset;
	transition: background-color 9999s ease-in-out 0s;
}

.cjchat-gate-form input[type="text"] + input[type="text"] {
	margin-top: 8px;
}

.cjchat-gate-form select ~ input[type="text"] {
	margin-top: 8px;
}

.cjchat-consent {
	display: flex;
	align-items: flex-start;
	gap: 6px;
	font-size: 12px;
	opacity: 0.85;
	margin: 14px 0 4px;
}

.cjchat-gate-error {
	font-size: 12px;
	color: #ff8a8a;
	margin-top: 8px;
}

.cjchat-gate-submit {
	margin-top: 16px;
	background: var(--cjchat-accent);
	color: #fff;
	border: none;
	border-radius: 8px;
	padding: 11px 14px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}

.cjchat-gate-submit:disabled {
	opacity: 0.6;
	cursor: default;
}

/* Input row */
.cjchat-input {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid rgba(255, 255, 255, 0.08);
	flex-shrink: 0;
	padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.cjchat-input textarea {
	flex: 1;
	resize: none;
	max-height: 120px;
	min-height: 40px;
	padding: 10px 12px;
	border-radius: 12px;
	border: 1px solid rgba(255, 255, 255, 0.14);
	background: rgba(0, 0, 0, 0.25);
	color: var(--cjchat-text);
	font-size: 14px;
}

.cjchat-send {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: var(--cjchat-accent);
	color: #fff;
	border: none;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cjchat-send:disabled {
	opacity: 0.5;
	cursor: default;
}

.cjchat-notice {
	margin: 0 16px 12px;
	padding: 10px 12px;
	font-size: 13px;
	border-radius: 10px;
	background: rgba(255, 255, 255, 0.08);
	flex-shrink: 0;
}

/* Mobile: full-screen sheet */
@media (max-width: 640px) {
	.cjchat-root {
		inset: auto 12px 12px auto;
	}

	.cjchat-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		border-radius: 0;
	}

	.cjchat-header {
		padding-top: calc(14px + env(safe-area-inset-top));
	}

	.cjchat-input {
		padding-bottom: calc(12px + env(safe-area-inset-bottom));
	}
}
