/*
 * Custom Chat Assistant - widget styles.
 * Every rule is scoped under #cca-root and every class uses the cca- prefix,
 * so the widget does not leak into (or get broken by) the active theme.
 */

#cca-root {
	--cca-primary: #2563eb;
	--cca-primary-text: #ffffff;
	--cca-header: #1e293b;
	--cca-header-text: #ffffff;
	--cca-radius: 16px;
	--cca-width: 380px;
	--cca-height: 600px;
	--cca-bg: #ffffff;
	--cca-surface: #f1f5f9;
	--cca-text: #0f172a;
	--cca-muted: #64748b;
	--cca-border: #e2e8f0;
	--cca-edge-x: 43px; /* jarak dari sisi kiri/kanan layar */
	--cca-edge-y: 95px; /* jarak dari bawah layar */
	--cca-effect: #60a5fa; /* warna gelombang/glow efek tombol (v0.9.2) */
	--cca-primary-hover: #1d4ed8; /* warna tombol saat hover (v0.9.2) */

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
	color: var(--cca-text);
	-webkit-text-size-adjust: 100%;
}

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

/* Neutralise aggressive theme button/input styles. */
#cca-root button,
#cca-root input {
	font: inherit;
	margin: 0;
	text-transform: none;
	letter-spacing: normal;
	text-shadow: none;
	-webkit-appearance: none;
	appearance: none;
}

#cca-root button {
	cursor: pointer;
	min-height: 0;
	line-height: 1;
}

#cca-root svg {
	display: block;
	flex: none;
}

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

#cca-root .cca-launcher {
	position: fixed;
	bottom: min(var(--cca-edge-y), calc(100vh - 76px));
	z-index: 999990;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 60px;
	height: 60px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--cca-primary);
	color: var(--cca-primary-text);
	box-shadow: 0 6px 20px rgba(15, 23, 42, 0.28);
	overflow: visible; /* v0.9.2: gelombang efek keluar dari tombol; cegah tema memotongnya */
	transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

#cca-root .cca-launcher:hover {
	transform: translateY(-2px);
	background: var(--cca-primary-hover);
	box-shadow: 0 10px 26px rgba(15, 23, 42, 0.32);
}

#cca-root .cca-launcher:active {
	transform: translateY(0) scale(0.96);
}

#cca-root .cca-launcher:focus-visible,
#cca-root .cca-iconbtn:focus-visible,
#cca-root .cca-chip:focus-visible,
#cca-root .cca-send:focus-visible {
	outline: 3px solid var(--cca-primary);
	outline-offset: 2px;
}

#cca-root.cca-btn-rounded .cca-launcher {
	border-radius: 18px;
}

#cca-root.cca-btn-pill .cca-launcher {
	width: auto;
	min-width: 60px;
	padding: 0 22px 0 18px;
	border-radius: 999px;
}

#cca-root .cca-launcher__label {
	font-weight: 600;
	font-size: 15px;
	white-space: nowrap;
}

#cca-root .cca-launcher__icon--close {
	display: none;
}

#cca-root.is-open .cca-launcher__icon--chat {
	display: none;
}

#cca-root.is-open .cca-launcher__icon--close {
	display: inline-flex;
}

#cca-root.is-open .cca-launcher__label {
	display: none;
}

#cca-root.is-open.cca-btn-pill .cca-launcher {
	padding: 0;
	width: 60px;
	border-radius: 50%;
}

#cca-root.cca-pos-right .cca-launcher {
	right: min(var(--cca-edge-x), calc(100vw - 76px));
}

#cca-root.cca-pos-left .cca-launcher {
	left: min(var(--cca-edge-x), calc(100vw - 76px));
}

/* ---------- Effect tombol (v0.9.2) ----------
 * Dipilih dari Pengaturan > Tampilan > Effect; kelas cca-fx-* ada di #cca-root.
 * Hanya transform/opacity (dan properti `scale`/`translate`, agar tidak bentrok dengan
 * transform hover) sehingga ringan. Gelombang memakai pseudo-element tombol: tidak
 * menambah elemen/ukuran layout, tidak memicu scroll. Berhenti saat chat terbuka.
 */

#cca-root {
	--cca-fx-scale: 1.55;
}

#cca-root.cca-btn-pill {
	--cca-fx-scale: 1.22; /* tombol pil lebar: gelombang lebih kecil agar tetap rapi */
}

#cca-root.cca-fx-soft-pulse:not(.is-open) .cca-launcher::before,
#cca-root.cca-fx-ripple:not(.is-open) .cca-launcher::before,
#cca-root.cca-fx-ripple:not(.is-open) .cca-launcher::after,
#cca-root.cca-fx-glow:not(.is-open) .cca-launcher::before {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	border-radius: inherit;
	border: 3px solid var(--cca-effect);
	opacity: 0;
	pointer-events: none;
	animation: cca-fx-wave 2s ease-out infinite;
}

/* 1. Pulse (bawaan): gelombang PENUH berwarna di belakang tombol, membesar 2x lalu memudar,
 * 1 detik; lapisan kedua lebih transparan dengan jeda 0,4 detik (sama dengan animate-ping).
 * Gelombang ::before/::after ada di lapisan z-index -1, sedangkan warna tombol dipindah ke
 * <span class="cca-launcher__bg"> supaya gelombang benar-benar berada DI BELAKANG tombol.
 * Jika HTML lama dari cache belum punya span itu (:has tidak cocok), tombol tetap solid seperti biasa.
 */
#cca-root {
	--cca-fx-ping-scale: 2;
}

#cca-root.cca-btn-pill {
	--cca-fx-ping-scale: 1.3; /* tombol pil lebar: gelombang lebih kecil agar tetap rapi */
}

#cca-root .cca-launcher__bg {
	display: none;
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher:has(> .cca-launcher__bg) {
	background: transparent;
	box-shadow: none;
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher:has(> .cca-launcher__bg) > .cca-launcher__bg {
	display: block;
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	border-radius: inherit;
	background: var(--cca-primary);
	box-shadow: 0 6px 20px rgba(15, 23, 42, 0.28);
	pointer-events: none;
	transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher:has(> .cca-launcher__bg):hover > .cca-launcher__bg {
	background: var(--cca-primary-hover);
	box-shadow: 0 10px 26px rgba(15, 23, 42, 0.32);
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher:has(> .cca-launcher__bg) > .cca-launcher__icon,
#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher:has(> .cca-launcher__bg) > .cca-launcher__label {
	position: relative; /* di atas span latar */
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher::before,
#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher::after {
	content: "";
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
	z-index: -1;
	border-radius: inherit;
	background: var(--cca-effect);
	opacity: 0;
	pointer-events: none;
	animation: cca-fx-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher::before {
	--cca-wave-o: 0.6;
}

#cca-root.cca-fx-pulse:not(.is-open) .cca-launcher::after {
	--cca-wave-o: 0.3;
	animation-delay: 0.4s;
}

/* 2. Soft Pulse: 1 gelombang, lebih lambat dan lebih transparan. */
#cca-root.cca-fx-soft-pulse:not(.is-open) .cca-launcher::before {
	animation: cca-fx-wave-soft 2.4s ease-out infinite;
}

/* 3. Ripple: riak lebih lebar, tipis, dan lebih lambat; dua lapisan berjarak merata. */
#cca-root.cca-fx-ripple:not(.is-open) .cca-launcher::before,
#cca-root.cca-fx-ripple:not(.is-open) .cca-launcher::after {
	border-width: 2px;
	animation: cca-fx-ripple 2.8s ease-out infinite;
}

#cca-root.cca-fx-ripple:not(.is-open) .cca-launcher::after {
	animation-delay: 1.4s;
}

/* 4. Breathing: tombol membesar 1.00 -> 1.06 -> 1.00. */
#cca-root.cca-fx-breathing:not(.is-open) .cca-launcher {
	animation: cca-fx-breathe 2.8s ease-in-out infinite;
}

/* 5. Glow: cahaya lembut di sekeliling tombol, membesar-mengecil perlahan. */
#cca-root.cca-fx-glow:not(.is-open) .cca-launcher::before {
	border: 0;
	box-shadow: 0 0 14px 3px var(--cca-effect);
	animation: cca-fx-glow 3s ease-in-out infinite;
}

/* 6. Bounce: naik sedikit lalu kembali (kecil, bukan gaya game). */
#cca-root.cca-fx-bounce:not(.is-open) .cca-launcher {
	animation: cca-fx-bounce 2.4s ease-out infinite;
}

/* 7. Float: melayang naik-turun sangat pelan. */
#cca-root.cca-fx-float:not(.is-open) .cca-launcher {
	animation: cca-fx-float 3.6s ease-in-out infinite;
}

/* 8. No Effect (cca-fx-none): tanpa aturan animasi otomatis. Hover/klik tetap berlaku. */

@keyframes cca-fx-ping {
	0%         { transform: scale(1); opacity: var(--cca-wave-o, 0.6); }
	75%, 100%  { transform: scale(var(--cca-fx-ping-scale, 2)); opacity: 0; }
}

@keyframes cca-fx-wave {
	0%   { transform: scale(1); opacity: 0.75; }
	100% { transform: scale(var(--cca-fx-scale)); opacity: 0; }
}

@keyframes cca-fx-wave-soft {
	0%   { transform: scale(1); opacity: 0.45; }
	100% { transform: scale(1.4); opacity: 0; }
}

@keyframes cca-fx-ripple {
	0%   { transform: scale(1); opacity: 0.6; }
	100% { transform: scale(calc(var(--cca-fx-scale) + 0.4)); opacity: 0; }
}

@keyframes cca-fx-breathe {
	0%, 100% { scale: 1; }
	50%      { scale: 1.06; }
}

@keyframes cca-fx-glow {
	0%, 100% { transform: scale(1); opacity: 0.35; }
	50%      { transform: scale(1.1); opacity: 0.8; }
}

@keyframes cca-fx-bounce {
	0%, 40%, 70%, 100% { translate: 0 0; }
	20%                { translate: 0 -4px; }
	55%                { translate: 0 -2px; }
}

@keyframes cca-fx-float {
	0%, 100% { translate: 0 0; }
	50%      { translate: 0 -4px; }
}

/* ---------- Window ---------- */

#cca-root .cca-window {
	position: fixed;
	bottom: calc(var(--cca-edge-y) + 74px);
	z-index: 999991;
	display: flex;
	flex-direction: column;
	width: min(var(--cca-width), calc(100vw - var(--cca-edge-x) - 16px));
	height: max(280px, min(var(--cca-height), calc(100vh - var(--cca-edge-y) - 100px)));
	overflow: hidden;
	background: var(--cca-bg);
	border-radius: var(--cca-radius);
	box-shadow: 0 16px 48px rgba(15, 23, 42, 0.24), 0 2px 8px rgba(15, 23, 42, 0.08);
	opacity: 0;
	visibility: hidden;
	transform: translateY(16px) scale(0.97);
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}

@supports (height: 100dvh) {
	#cca-root .cca-window {
		height: max(280px, min(var(--cca-height), calc(100dvh - var(--cca-edge-y) - 100px)));
	}
}

#cca-root.cca-pos-right .cca-window {
	right: var(--cca-edge-x);
	transform-origin: bottom right;
}

#cca-root.cca-pos-left .cca-window {
	left: var(--cca-edge-x);
	transform-origin: bottom left;
}

#cca-root.is-open .cca-window {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

/* ---------- Header ---------- */

#cca-root .cca-header {
	display: flex;
	align-items: center;
	gap: 10px;
	flex: none;
	padding: 14px 12px 14px 16px;
	background: var(--cca-header);
	color: var(--cca-header-text);
}

#cca-root .cca-header__avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 38px;
	height: 38px;
	overflow: hidden;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.16);
}

#cca-root .cca-header__avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

#cca-root .cca-header__info {
	flex: 1;
	min-width: 0;
}

#cca-root .cca-header__name {
	font-size: 16px;
	font-weight: 600;
	line-height: 1.25;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

#cca-root .cca-header__status {
	font-size: 12.5px;
	line-height: 1.3;
	opacity: 0.75;
}

#cca-root .cca-iconbtn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 36px;
	height: 36px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	opacity: 0.8;
	transition: background 0.15s ease, opacity 0.15s ease;
}

#cca-root .cca-iconbtn:hover {
	background: rgba(255, 255, 255, 0.16);
	opacity: 1;
}

/* ---------- Messages ---------- */

#cca-root .cca-messages {
	display: flex;
	flex: 1;
	flex-direction: column;
	gap: 10px;
	min-height: 0;
	padding: 16px 14px 10px;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	background: var(--cca-bg);
}

#cca-root .cca-msg {
	display: flex;
	gap: 8px;
	max-width: 88%;
	animation: cca-in 0.25s ease both;
}

#cca-root .cca-msg--bot {
	align-self: flex-start;
}

#cca-root .cca-msg--user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

#cca-root .cca-msg__avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
	align-self: flex-end;
	width: 28px;
	height: 28px;
	overflow: hidden;
	border-radius: 50%;
	background: var(--cca-header);
	color: var(--cca-header-text);
}

#cca-root .cca-msg__avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

#cca-root .cca-msg__body {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

#cca-root .cca-msg--user .cca-msg__body {
	align-items: flex-end;
}

#cca-root .cca-bubble {
	padding: 10px 14px;
	border-radius: 18px;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
	word-break: normal;
}

#cca-root .cca-msg--bot .cca-bubble {
	background: var(--cca-surface);
	color: var(--cca-text);
	border-bottom-left-radius: 6px;
}

#cca-root .cca-msg--user .cca-bubble {
	background: var(--cca-primary);
	color: var(--cca-primary-text);
	border-bottom-right-radius: 6px;
}

#cca-root .cca-time {
	margin-top: 3px;
	padding: 0 4px;
	font-size: 11.5px;
	color: var(--cca-muted);
}

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

#cca-root .cca-typing__bubble {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	align-self: flex-start;
	padding: 13px 16px;
	border-radius: 18px;
	border-bottom-left-radius: 6px;
	background: var(--cca-surface);
}

#cca-root .cca-typing__dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--cca-muted);
	animation: cca-bounce 1.2s infinite ease-in-out;
}

#cca-root .cca-typing__dot:nth-child(2) {
	animation-delay: 0.15s;
}

#cca-root .cca-typing__dot:nth-child(3) {
	animation-delay: 0.3s;
}

#cca-root .cca-typing__label {
	margin-top: 3px;
	padding: 0 4px;
	font-size: 12px;
	color: var(--cca-muted);
}

/* ---------- Auto WhatsApp redirect countdown ---------- */

#cca-root .cca-wa-countdown {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	flex-shrink: 0;
	gap: 6px 12px;
	margin: 2px 0 4px 36px;
	padding: 10px 12px;
	border-radius: 12px;
	background: var(--cca-surface);
	color: var(--cca-text, inherit);
	font-size: 13px;
	line-height: 1.35;
	animation: cca-in 0.25s ease both;
}

#cca-root .cca-wa-countdown__text {
	flex: 1 1 100%;
}

#cca-root .cca-wa-countdown__actions {
	display: inline-flex;
	gap: 14px;
}

#cca-root .cca-wa-countdown__now,
#cca-root .cca-wa-countdown__cancel {
	border: none;
	background: none;
	padding: 0;
	color: var(--cca-primary);
	font-size: 13px;
	font-weight: 600;
	text-decoration: underline;
	cursor: pointer;
}

#cca-root .cca-wa-countdown__bar {
	flex: 1 1 100%;
	height: 3px;
	border-radius: 3px;
	background: rgba(127, 127, 127, 0.25);
	overflow: hidden;
}

#cca-root .cca-wa-countdown__bar > i {
	display: block;
	height: 100%;
	background: var(--cca-primary);
	transition: width 1s linear;
}

/* ---------- Quick replies ---------- */

#cca-root .cca-replies {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding: 2px 0 4px 36px;
	animation: cca-in 0.25s ease both;
}

#cca-root .cca-chip {
	padding: 9px 15px;
	border: 1.5px solid var(--cca-primary);
	border-radius: 999px;
	background: var(--cca-bg);
	color: var(--cca-primary);
	font-size: 14px;
	font-weight: 500;
	line-height: 1.2;
	text-align: left;
	transition: background 0.15s ease, color 0.15s ease;
}

#cca-root .cca-chip:hover {
	background: var(--cca-primary);
	color: var(--cca-primary-text);
}

#cca-root .cca-chip--cta {
	background: var(--cca-primary);
	color: var(--cca-primary-text);
}

#cca-root .cca-chip--cta:hover {
	opacity: 0.88;
}

/* ---------- Input ---------- */

#cca-root .cca-form {
	display: flex;
	flex: none;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
	border-top: 1px solid var(--cca-border);
	background: var(--cca-bg);
}

#cca-root .cca-input {
	flex: 1;
	min-width: 0;
	height: 44px;
	padding: 0 16px;
	border: 1px solid var(--cca-border);
	border-radius: 999px;
	background: #f8fafc;
	color: var(--cca-text);
	font-size: 16px; /* 16px stops iOS from zooming the page on focus. */
	box-shadow: none;
}

#cca-root .cca-input:focus {
	border-color: var(--cca-primary);
	outline: 2px solid var(--cca-primary);
	outline-offset: 0;
	background: #ffffff;
}

#cca-root .cca-input::placeholder {
	color: var(--cca-muted);
	opacity: 1;
}

#cca-root .cca-send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--cca-primary);
	color: var(--cca-primary-text);
	transition: opacity 0.15s ease, transform 0.15s ease;
}

#cca-root .cca-send:hover {
	transform: scale(1.05);
}

#cca-root.is-busy .cca-send {
	opacity: 0.45;
	pointer-events: none;
}

/* ---------- Animations ---------- */

@keyframes cca-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: none;
	}
}

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

/* ---------- Mobile: full screen ---------- */

@media (max-width: 480px) {
	#cca-root .cca-window {
		top: var(--cca-vt, 0px);
		right: 0;
		bottom: auto;
		left: 0;
		width: 100%;
		height: 100vh;
		height: 100dvh;
		height: var(--cca-vh, 100dvh);
		border-radius: 0;
		transform-origin: bottom center;
	}

	#cca-root.cca-pos-right .cca-window,
	#cca-root.cca-pos-left .cca-window {
		right: 0;
		left: 0;
	}

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

	#cca-root .cca-msg {
		max-width: 92%;
	}
}

html.cca-no-scroll {
	overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
	#cca-root *,
	#cca-root *::before,
	#cca-root *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}

	/* v0.9.2: tanpa animasi otomatis bagi pengguna yang meminta reduced motion. */
	#cca-root .cca-launcher,
	#cca-root .cca-launcher::before,
	#cca-root .cca-launcher::after {
		animation: none !important;
	}

	#cca-root .cca-launcher::before,
	#cca-root .cca-launcher::after {
		display: none !important;
	}
}
