/**
 * CloudRebuild live chat widget.
 *
 * Reuses the theme's design tokens where they exist, with fallbacks so the
 * widget still looks right if the plugin is active under another theme.
 */

.crc {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 99999;
	font-family: var( --cr-font-body, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif );
}

/* ---------------------------------------------------------------- Bubble */

.crc__bubble {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	color: #fff;
	background: var( --cr-brand-grad, linear-gradient( 135deg, #3b82f6 0%, #1d4ed8 100% ) );
	box-shadow: 0 6px 20px rgba( 37, 99, 235, 0.35 );
	cursor: pointer;
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.crc__bubble:hover {
	transform: translateY( -2px );
	box-shadow: 0 10px 26px rgba( 37, 99, 235, 0.42 );
}

.crc__bubble:focus-visible {
	outline: 3px solid var( --cr-brand-500, #3b82f6 );
	outline-offset: 3px;
}

.crc.is-open .crc__bubble {
	transform: scale( 0.92 );
}

/* Unread count, for replies that land while the panel is shut. */
.crc__badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	border-radius: 10px;
	background: var( --cr-danger-500, #ef4444 );
	color: #fff;
	font-size: 12px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
}

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

.crc__panel {
	position: absolute;
	right: 0;
	bottom: 72px;
	display: flex;
	flex-direction: column;
	width: 370px;
	max-width: calc( 100vw - 32px );
	height: 520px;
	max-height: calc( 100vh - 120px );
	overflow: hidden;
	border: 1px solid var( --cr-border, rgba( 15, 23, 42, 0.08 ) );
	border-radius: 16px;
	background: var( --cr-card-bg, #fff );
	box-shadow: 0 24px 60px rgba( 15, 23, 42, 0.18 );
}

.crc__panel[hidden] {
	display: none;
}

.crc__head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 14px 14px 16px;
	border-bottom: 1px solid var( --cr-border-soft, rgba( 15, 23, 42, 0.05 ) );
	background: var( --cr-bg-soft, #f8fafc );
}

.crc__title {
	flex: 1;
	font-family: var( --cr-font-display, inherit );
	font-size: 15px;
	font-weight: 600;
	color: var( --cr-fg, #0f172a );
}

/* Connection dot. Colour is the only difference between states, so each
   one also changes the adjacent label text — never colour alone. */
.crc__status {
	width: 9px;
	height: 9px;
	flex: 0 0 9px;
	border-radius: 50%;
	background: var( --cr-fg-muted, #64748b );
}

.crc__status.is-bot,
.crc__status.is-connecting {
	background: var( --cr-amber-500, #f59e0b );
}

.crc__status.is-live {
	background: var( --cr-success-500, #10b981 );
	box-shadow: 0 0 0 3px var( --cr-success-50, #d1fae5 );
}

.crc__status.is-offline {
	background: var( --cr-danger-500, #ef4444 );
}

.crc__status.is-ended {
	background: var( --cr-fg-muted, #64748b );
}

.crc__x {
	display: flex;
	padding: 4px;
	border: 0;
	border-radius: 6px;
	background: none;
	color: var( --cr-fg-muted, #64748b );
	cursor: pointer;
}

.crc__x:hover {
	background: var( --cr-border-soft, rgba( 15, 23, 42, 0.05 ) );
	color: var( --cr-fg, #0f172a );
}

/* ------------------------------------------------------------ Transcript */

.crc__log {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

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

.crc__who {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: var( --cr-fg-muted, #64748b );
}

.crc__bubbleText {
	padding: 9px 13px;
	border-radius: 14px;
	font-size: 14px;
	line-height: 1.5;
	/* Bot prompts contain deliberate line breaks; agent text may contain
	   long URLs that would otherwise widen the panel. */
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.crc__msg--bot .crc__bubbleText,
.crc__msg--agent .crc__bubbleText {
	border-bottom-left-radius: 4px;
	background: var( --cr-bg-soft, #f1f5f9 );
	color: var( --cr-fg, #0f172a );
}

.crc__msg--agent .crc__who {
	color: var( --cr-success-700, #047857 );
}

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

.crc__msg--visitor .crc__bubbleText {
	border-bottom-right-radius: 4px;
	background: var( --cr-brand-600, #2563eb );
	color: #fff;
}

/* System notices are the widget talking about itself — handoff, timeout,
   closure — so they read as neither party. */
.crc__msg--system {
	align-self: center;
	max-width: 100%;
	text-align: center;
}

.crc__msg--system .crc__bubbleText {
	background: var( --cr-brand-50, #eff6ff );
	color: var( --cr-brand-700, #1d4ed8 );
	font-size: 13px;
}

/* -------------------------------------------------------------- Typing */

.crc__typing {
	display: flex;
	gap: 4px;
	padding: 0 20px 10px;
}

.crc__typing[hidden] {
	display: none;
}

.crc__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var( --cr-fg-muted, #94a3b8 );
	animation: crc-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes crc-bounce {
	0%, 60%, 100% { transform: translateY( 0 ); opacity: 0.45; }
	30%           { transform: translateY( -4px ); opacity: 1; }
}

/* --------------------------------------------------------------- Composer */

.crc__form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px 12px;
	border-top: 1px solid var( --cr-border-soft, rgba( 15, 23, 42, 0.05 ) );
}

.crc__form.is-disabled {
	opacity: 0.55;
	pointer-events: none;
}

.crc__input {
	flex: 1;
	max-height: 120px;
	padding: 9px 12px;
	border: 1px solid var( --cr-border, rgba( 15, 23, 42, 0.12 ) );
	border-radius: 10px;
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	resize: none;
}

.crc__input:focus {
	border-color: var( --cr-brand-500, #3b82f6 );
	outline: 2px solid var( --cr-brand-100, #dbeafe );
	outline-offset: 0;
}

.crc__skip {
	padding: 9px 12px;
	border: 1px solid var( --cr-border, rgba( 15, 23, 42, 0.12 ) );
	border-radius: 10px;
	background: none;
	color: var( --cr-fg-muted, #64748b );
	font-size: 13px;
	cursor: pointer;
}

.crc__skip:hover {
	color: var( --cr-fg, #0f172a );
	border-color: var( --cr-fg-muted, #64748b );
}

.crc__skip[hidden] {
	display: none;
}

.crc__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	flex: 0 0 38px;
	border: 0;
	border-radius: 10px;
	background: var( --cr-brand-600, #2563eb );
	color: #fff;
	cursor: pointer;
}

.crc__send:hover {
	background: var( --cr-brand-700, #1d4ed8 );
}

/* ----------------------------------------------------------- Small screens */

@media ( max-width: 480px ) {
	.crc {
		right: 16px;
		bottom: 16px;
	}

	.crc__panel {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		max-width: 100%;
		height: 100%;
		max-height: 100%;
		border: 0;
		border-radius: 0;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.crc__bubble,
	.crc__typing span {
		transition: none;
		animation: none;
	}
}

/* "End chat", offered in the header only once a human is connected. */
.crc__end {
	padding: 4px 9px;
	border: 1px solid var( --cr-border, rgba( 15, 23, 42, 0.12 ) );
	border-radius: 7px;
	background: none;
	color: var( --cr-fg-muted, #64748b );
	font-family: inherit;
	font-size: 12px;
	cursor: pointer;
}

.crc__end:hover {
	border-color: var( --cr-danger-500, #ef4444 );
	color: var( --cr-danger-600, #dc2626 );
}

.crc__end[hidden] {
	display: none;
}
