/* ==========================================================================
   Chatbot IA — Maison Kenzoshiro | Widget front
   Theming via custom properties injectées par le plugin :
   --kzc-primary, --kzc-button, --kzc-msg-bg, --kzc-font-size
   ========================================================================== */

.kzc-widget {
	--kzc-primary: #111827;
	--kzc-button: #2563EB;
	--kzc-msg-bg: #F3F4F6;
	--kzc-font-size: 14.5px;
	--kzc-radius: 16px;
	--kzc-shadow: 0 12px 40px rgba(17, 24, 39, 0.18);

	position: fixed;
	bottom: 24px;
	z-index: 999999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: var(--kzc-font-size);
	line-height: 1.45;
	color: #1f2937;
}

.kzc-pos-right { right: 24px; }
.kzc-pos-left  { left: 24px; }

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

/* Un element marque [hidden] doit toujours rester cache, meme si une
   regle plus bas lui donne display:flex/block (panneau, formulaire lead,
   message proactif). Sinon ils s'affichent en permanence sur le front. */
.kzc-widget [hidden] { display: none !important; }

html.kzc-page-locked,
body.kzc-page-locked {
	overflow: hidden !important;
	touch-action: none;
}

body.kzc-page-locked {
	position: fixed;
	left: 0;
	right: 0;
	width: 100%;
}

/* ── Bulle de lancement ────────────────────────────────────────────────── */

.kzc-launcher {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 64px;
	height: 58px;
	border: none;
	border-radius: 14px;
	background: var(--kzc-button);
	color: #fff;
	cursor: pointer;
	box-shadow: var(--kzc-shadow);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	margin-left: auto;
}

.kzc-pos-left .kzc-launcher { margin-left: 0; margin-right: auto; }

.kzc-launcher:hover { transform: scale(1.06); }
.kzc-launcher:focus-visible { outline: 3px solid rgba(37, 99, 235, 0.4); outline-offset: 2px; }
.kzc-launcher svg { color: #fff; }

.kzc-launcher-close { display: none; }
.kzc-widget.kzc-open .kzc-launcher-icon { display: none; }
.kzc-widget.kzc-open .kzc-launcher-close { display: block; }
.kzc-widget.kzc-open .kzc-launcher { display: none; }

/* ── Message proactif ──────────────────────────────────────────────────── */

.kzc-proactive {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	max-width: 280px;
	margin-bottom: 12px;
	padding: 12px 14px;
	background: #fff;
	border-radius: 14px;
	box-shadow: var(--kzc-shadow);
	animation: kzc-pop 0.35s ease both;
}

.kzc-proactive-close {
	flex: none;
	border: none;
	background: transparent;
	font-size: 18px;
	line-height: 1;
	color: #9ca3af;
	cursor: pointer;
	padding: 0;
}

/* ── Panneau ───────────────────────────────────────────────────────────── */

.kzc-panel {
	position: absolute;
	bottom: 0;
	width: 370px;
	max-width: calc(100vw - 32px);
	height: 600px;
	max-height: calc(100vh - 120px);
	display: flex;
	flex-direction: column;
	background: #fff;
	border-radius: 0;
	box-shadow: var(--kzc-shadow);
	overflow: hidden;
	transform-origin: bottom right;
	animation: kzc-pop 0.28s cubic-bezier(0.21, 1.02, 0.73, 1) both;
}

.kzc-pos-right .kzc-panel { right: 0; }
.kzc-pos-left  .kzc-panel { left: 0; transform-origin: bottom left; }

@keyframes kzc-pop {
	from { opacity: 0; transform: translateY(12px) scale(0.96); }
	to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.kzc-panel, .kzc-proactive { animation: none; }
	.kzc-launcher { transition: none; }
}

/* ── Header ────────────────────────────────────────────────────────────── */

.kzc-header {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	gap: 8px;
	padding: 18px 44px 14px;
	background: var(--kzc-primary);
	color: #fff;
}

.kzc-logo {
	width: 56px;
	height: 56px;
	border-radius: 50%;
	object-fit: cover;
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 26px;
}

.kzc-header-title {
	font-weight: 600;
	font-size: 1.05em;
}

.kzc-header-close {
	position: absolute;
	top: 10px;
	right: 10px;
	width: 32px !important;
	min-width: 32px !important;
	max-width: 32px !important;
	height: 32px !important;
	min-height: 32px !important;
	max-height: 32px !important;
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	padding: 0 !important;
	border: none !important;
	border-radius: 0 !important;
	background: transparent !important;
	color: var(--kzc-button) !important;
	cursor: pointer;
	line-height: 1 !important;
	box-shadow: none !important;
}

.kzc-header-close:hover {
	background: transparent !important;
	color: #F47A3D !important;
}

.kzc-header-close svg {
	display: block;
	margin: auto;
	flex: none;
	width: 22px;
	height: 22px;
}

/* ── Messages ──────────────────────────────────────────────────────────── */

.kzc-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 14px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: #fff;
}

.kzc-widget.kzc-lead-open .kzc-messages {
	display: none;
}

.kzc-widget.kzc-lead-open .kzc-composer {
	display: none;
}

.kzc-msg {
	max-width: 82%;
	padding: 10px 13px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-wrap: break-word;
}

.kzc-msg-bot {
	align-self: flex-start;
	background: var(--kzc-msg-bg);
	border-bottom-left-radius: 4px;
}

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

.kzc-msg a { color: var(--kzc-button); text-decoration: underline; }
.kzc-msg-user a { color: #fff; }

.kzc-typing {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 12px 14px;
	background: var(--kzc-msg-bg);
	border-radius: 14px;
	border-bottom-left-radius: 4px;
}

.kzc-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #9ca3af;
	animation: kzc-blink 1.2s infinite ease-in-out;
}

.kzc-typing span:nth-child(2) { animation-delay: 0.15s; }
.kzc-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes kzc-blink {
	0%, 80%, 100% { opacity: 0.3; }
	40% { opacity: 1; }
}

/* ── Formulaire de lead ────────────────────────────────────────────────── */

.kzc-lead-form {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 18px 18px 0;
	border-top: none;
	background: #fafafa;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.kzc-lead-title {
	font-weight: 600;
	text-align: center;
	margin-bottom: 8px;
}

.kzc-lead-intro {
	margin: -2px 0 4px;
	color: #4b5563;
	font-size: 13px;
	line-height: 1.35;
	text-align: center;
}

.kzc-lead-error {
	padding: 9px 10px;
	border: 1px solid #fecaca;
	border-radius: 10px;
	background: #fef2f2;
	color: #991b1b;
	font-size: 13px;
	line-height: 1.35;
}

.kzc-lead-form input,
.kzc-lead-form textarea {
	width: 100%;
	padding: 11px 12px;
	border: 1px solid #d1d5db;
	border-radius: 10px;
	font: inherit;
	background: #fff;
	font-size: 15px;
	line-height: 1.35;
}

.kzc-lead-form textarea {
	min-height: 96px;
	resize: vertical;
}

.kzc-lead-form input:focus,
.kzc-lead-form textarea:focus,
.kzc-input input:focus {
	outline: 2px solid var(--kzc-button);
	outline-offset: 0;
	border-color: transparent;
}

.kzc-consent {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	font-size: 12px;
	line-height: 1.35;
	color: #4b5563;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	padding: 10px;
}

.kzc-consent input {
	margin-top: 2px;
	flex: none;
	width: 16px !important;
	height: 16px !important;
	min-width: 16px !important;
	accent-color: var(--kzc-button);
}

.kzc-consent span {
	display: block;
	min-width: 0;
	color: #374151;
	-webkit-text-fill-color: #374151;
}

.kzc-lead-actions {
	display: flex;
	gap: 8px;
	justify-content: flex-end;
	position: sticky;
	bottom: 0;
	margin: 4px -18px 0;
	padding: 12px 18px 14px;
	background: #fafafa;
	border-top: 1px solid #e5e7eb;
}

.kzc-btn {
	border: none;
	border-radius: 10px;
	padding: 10px 18px;
	background: var(--kzc-button);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	min-height: 42px;
}

.kzc-btn:disabled { opacity: 0.6; cursor: default; }

.kzc-btn-ghost {
	background: transparent;
	color: #6b7280;
}

/* ── Zone de saisie ────────────────────────────────────────────────────── */

.kzc-composer {
	border-top: 1px solid #e5e7eb;
	background: #fff;
}

.kzc-clear-chat {
	display: inline-block;
	width: auto;
	margin: 7px 14px 0;
	padding: 0;
	border: none;
	background: transparent;
	color: #6b7280;
	font: inherit;
	font-size: 11.5px;
	line-height: 1.2;
	text-align: left;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.kzc-clear-chat:hover { color: var(--kzc-button); }

.kzc-input {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 14px 12px;
	background: #fff;
}

.kzc-input input {
	flex: 1;
	height: 44px;
	padding: 0 16px;
	border: 1px solid #d1d5db;
	border-radius: 999px;
	font: inherit;
	font-size: 13.5px;
	box-sizing: border-box;
}

/* Le texte tapé doit toujours rester lisible, même si le thème du site
   impose ses propres styles de formulaire (couleur, dark mode, etc.). */
.kzc-input input,
.kzc-lead-form input,
.kzc-lead-form textarea {
	color: #111827 !important;
	background: #fff !important;
	-webkit-text-fill-color: #111827;
	caret-color: #111827;
}

.kzc-input input::placeholder,
.kzc-lead-form input::placeholder,
.kzc-lead-form textarea::placeholder {
	color: #9ca3af;
	opacity: 1;
}

.kzc-send {
	flex: none;
	width: 44px !important;
	min-width: 44px !important;
	max-width: 44px !important;
	height: 44px !important;
	min-height: 44px !important;
	max-height: 44px !important;
	display: inline-flex !important;
	align-items: center;
	justify-content: center;
	padding: 0 !important;
	border: none !important;
	border-radius: 50% !important;
	background: var(--kzc-button) !important;
	color: #fff !important;
	cursor: pointer;
	line-height: 1 !important;
}

.kzc-send svg {
	display: block;
	margin: auto;
	flex: none;
	transform: none;
}

.kzc-send:disabled { opacity: 0.6; cursor: default; }

/* ── Responsive mobile / tablette ──────────────────────────────────────── */

@media (max-width: 640px) {
	.kzc-widget { bottom: 16px; }
	.kzc-pos-right { right: 16px; }
	.kzc-pos-left { left: 16px; }

	/* Chat plein écran : plus lisible et plus simple à fermer sur mobile
	   qu'un petit panneau flottant. La croix du header sert à fermer. */
	.kzc-panel {
		position: fixed;
		inset: 0;
		width: 100vw;
		height: 100dvh;
		min-height: 100dvh;
		max-width: none;
		max-height: none;
		border-radius: 0;
	}

	/* La bulle de lancement est masquée pendant que le chat plein écran
	   est ouvert : elle serait de toute façon recouverte par le panneau. */
	.kzc-widget.kzc-open .kzc-launcher { display: none; }

	.kzc-header { padding-top: 22px; }
}


/* ── Mode aperçu admin (live preview) ──────────────────────────────────── */

.kzc-widget.kzc-preview {
	position: relative;
	bottom: auto;
	right: auto;
	left: auto;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	justify-content: flex-start;
}

.kzc-widget.kzc-preview.kzc-pos-left { align-items: flex-start; }

/* Dans l'apercu, le panneau est montre en entier au-dessus de la bulle,
   sans etre rogne : hauteur maitrisee + espace avant le launcher. */
.kzc-widget.kzc-preview .kzc-panel {
	position: relative;
	bottom: auto;
	height: 460px;
	max-height: none;
	margin-bottom: 22px;
	animation: none;
}

.kzc-widget.kzc-preview .kzc-proactive { margin-bottom: 14px; }
