/* Customer Live Chat - front-end widget.
   Scoped under #clc-root so it cannot leak into the theme. */

#clc-root {
	--clc-accent: #c9962c;
	--clc-accent-ink: #100e0c;
	--clc-surface: #ffffff;
	--clc-ink: #16130f;
	--clc-muted: #6b6357;
	--clc-line: #e4ded2;
	--clc-bubble: #f3efe7;
	--clc-radius: 16px;

	position: fixed;
	bottom: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
}

#clc-root.clc-right { right: 24px; }
#clc-root.clc-left  { left: 24px; }

#clc-root *,
#clc-root *::before,
#clc-root *::after { box-sizing: border-box; }

/* Every panel below sets an explicit display, which is an author style and so
   beats the user agent's [hidden]{display:none}. Without this the panel, the
   composer and the typing dots are all visible before the chat has started. */
#clc-root [hidden] { display: none !important; }

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

/* ---- launcher ------------------------------------------------------- */

.clc-launcher {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	min-height: 52px;
	padding: 0 20px 0 16px;
	border: none;
	border-radius: 999px;
	background: var(--clc-accent);
	color: var(--clc-accent-ink);
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
	transition: transform 160ms ease, box-shadow 160ms ease;
	position: relative;
}

.clc-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28); }
.clc-launcher:focus-visible { outline: 3px solid var(--clc-accent); outline-offset: 3px; }

.clc-launcher-icon svg { width: 24px; height: 24px; fill: currentColor; display: block; }

.clc-badge {
	position: absolute;
	top: -4px;
	inset-inline-end: -4px;
	min-width: 20px; height: 20px;
	padding: 0 5px;
	border-radius: 999px;
	background: #c0392b;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
	border: 2px solid #fff;
}

#clc-root.clc-open .clc-launcher { display: none; }

/* ---- panel ---------------------------------------------------------- */

.clc-panel {
	display: flex;
	flex-direction: column;
	width: min(370px, calc(100vw - 32px));
	height: min(560px, calc(100vh - 120px));
	background: var(--clc-surface);
	color: var(--clc-ink);
	border: 1px solid var(--clc-line);
	border-radius: var(--clc-radius);
	overflow: hidden;
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.26);
}

.clc-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 14px 14px 18px;
	background: var(--clc-accent);
	color: var(--clc-accent-ink);
	flex: none;
}

.clc-title { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.25; }

.clc-status { margin: 2px 0 0; font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 6px; }
.clc-status::before {
	content: ""; width: 7px; height: 7px; border-radius: 50%;
	background: currentColor; opacity: 0.45;
}
.clc-status.is-online::before { background: #1f9d55; opacity: 1; }

.clc-close {
	flex: none;
	width: 40px; height: 40px;
	display: grid; place-items: center;
	background: rgba(0, 0, 0, 0.08);
	border: none; border-radius: 50%;
	color: inherit; cursor: pointer;
}
.clc-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.clc-close:hover { background: rgba(0, 0, 0, 0.16); }
.clc-close:focus-visible { outline: 3px solid var(--clc-accent-ink); outline-offset: -3px; }

.clc-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.clc-notice {
	flex: none;
	margin: 0;
	padding: 9px 16px;
	background: #fdf3d7;
	color: #6b4e0b;
	font-size: 13px;
	border-bottom: 1px solid #f0e2b8;
}
.clc-notice.is-error { background: #fdecea; color: #8a2018; border-bottom-color: #f5c9c4; }

/* ---- pre-chat form -------------------------------------------------- */

.clc-prechat { padding: 18px; overflow-y: auto; }
.clc-intro { margin: 0 0 16px; font-size: 15px; color: var(--clc-ink); }

.clc-label { display: block; margin: 0 0 5px; font-size: 12.5px; font-weight: 600; color: var(--clc-muted); }

.clc-prechat input {
	width: 100%;
	min-height: 46px;
	margin: 0 0 14px;
	padding: 10px 13px;
	font: inherit;
	color: var(--clc-ink);
	background: #fff;
	border: 1px solid var(--clc-line);
	border-radius: 10px;
}
.clc-prechat input:focus-visible { outline: 2px solid var(--clc-accent); outline-offset: 1px; border-color: var(--clc-accent); }

.clc-primary {
	width: 100%;
	min-height: 48px;
	border: none;
	border-radius: 999px;
	background: var(--clc-accent);
	color: var(--clc-accent-ink);
	font: inherit; font-weight: 700;
	cursor: pointer;
}
.clc-primary:hover { filter: brightness(1.06); }
.clc-primary:focus-visible { outline: 3px solid var(--clc-accent); outline-offset: 2px; }
.clc-primary[disabled] { opacity: 0.6; cursor: default; }

.clc-error { margin: -6px 0 12px; color: #9b2c20; font-size: 13px; }

/* ---- thread --------------------------------------------------------- */

.clc-thread {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	background: #fbfaf7;
	overscroll-behavior: contain;
}

.clc-msg { display: flex; flex-direction: column; max-width: 84%; }
.clc-msg-who { font-size: 11px; letter-spacing: 0.03em; text-transform: uppercase; color: var(--clc-muted); margin-bottom: 3px; }

.clc-msg-body {
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14.5px;
	line-height: 1.5;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	word-break: break-word;
}

.clc-msg-time { font-size: 11px; color: #9a9182; margin-top: 4px; }

.clc-msg.is-customer { align-self: flex-end; align-items: flex-end; }
.clc-msg.is-customer .clc-msg-body {
	background: var(--clc-accent);
	color: var(--clc-accent-ink);
	border-bottom-right-radius: 5px;
}

.clc-msg.is-agent .clc-msg-body,
.clc-msg.is-system .clc-msg-body {
	background: var(--clc-surface);
	border: 1px solid var(--clc-line);
	border-bottom-left-radius: 5px;
}

.clc-msg.is-system { align-self: center; max-width: 92%; }
.clc-msg.is-system .clc-msg-body { background: var(--clc-bubble); border-style: dashed; color: var(--clc-muted); font-size: 14px; }
.clc-msg.is-system .clc-msg-who { display: none; }

.clc-msg.is-pending .clc-msg-body { opacity: 0.55; }
.clc-msg.is-failed .clc-msg-body { background: #fdecea; color: #8a2018; cursor: pointer; }

/* ---- typing --------------------------------------------------------- */

.clc-typing {
	flex: none;
	margin: 0;
	padding: 6px 18px 10px;
	display: flex;
	gap: 4px;
	align-items: center;
}
.clc-typing span {
	width: 7px; height: 7px; border-radius: 50%;
	background: #b8afa0;
	animation: clc-bounce 1.2s infinite ease-in-out;
}
.clc-typing span:nth-child(2) { animation-delay: 0.15s; }
.clc-typing span:nth-child(3) { animation-delay: 0.3s; }

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

/* ---- composer ------------------------------------------------------- */

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

.clc-compose textarea {
	flex: 1 1 auto;
	min-width: 0;
	min-height: 44px;
	max-height: 120px;
	padding: 11px 13px;
	font: inherit;
	font-size: 16px;            /* 16px stops iOS zooming the page on focus */
	line-height: 1.4;
	color: var(--clc-ink);
	background: #fff;
	border: 1px solid var(--clc-line);
	border-radius: 12px;
	resize: none;
	overflow-y: auto;
}
.clc-compose textarea:focus-visible { outline: 2px solid var(--clc-accent); outline-offset: 1px; border-color: var(--clc-accent); }

.clc-send {
	flex: none;
	width: 46px; height: 46px;
	display: grid; place-items: center;
	border: none; border-radius: 50%;
	background: var(--clc-accent);
	color: var(--clc-accent-ink);
	cursor: pointer;
}
.clc-send svg { width: 20px; height: 20px; fill: currentColor; }
.clc-send:hover { filter: brightness(1.06); }
.clc-send:focus-visible { outline: 3px solid var(--clc-accent); outline-offset: 2px; }
.clc-send[disabled] { opacity: 0.5; cursor: default; }

/* ---- mobile --------------------------------------------------------- */

@media (max-width: 600px) {
	#clc-root { bottom: 16px; }
	#clc-root.clc-right { right: 16px; }
	#clc-root.clc-left  { left: 16px; }

	.clc-launcher-text { display: none; }
	.clc-launcher { padding: 0; width: 56px; height: 56px; justify-content: center; }

	/* Full-height sheet. dvh tracks the visual viewport, so the composer stays
	   above the on-screen keyboard instead of being pushed out of reach. */
	#clc-root.clc-open {
		inset: 0;
		bottom: 0;
		right: 0;
		left: 0;
	}
	#clc-root.clc-open .clc-panel {
		width: 100vw;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		border: none;
		border-radius: 0;
	}
	.clc-close { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
	.clc-launcher { transition: none; }
	.clc-typing span { animation: none; }
}
