/**
 * Botão flutuante e painel do chat.
 *
 * As cores vêm de custom properties escritas pelo plugin a partir das
 * configurações (Katd4_Config::css_inline). Os valores abaixo são só o
 * fallback de quem nunca abriu a tela de configurações.
 *
 * z-index acima de 10: a barra de topo do tema usa 10 e passaria por cima.
 * Desktop: 450px de largura x 80% da altura, ancorado sobre o botão.
 * Smartphone: tela inteira.
 */

#katd4-root {
	--katd4-principal: #128c7e;
	--katd4-principal-texto: #ffffff;
	--katd4-fundo: #ece5dd;
	--katd4-bot: #ffffff;
	--katd4-bot-texto: #111111;
	--katd4-visitante: #d9fdd3;
	--katd4-visitante-texto: #111111;
}

.katd4-botao,
.katd4-painel {
	z-index: 100000;
	font-family: inherit;
	box-sizing: border-box;
}

.katd4-botao *,
.katd4-painel * {
	box-sizing: border-box;
}

/* -- botão flutuante: círculo grande, só o balão --------------------------- */

.katd4-botao {
	position: fixed;
	right: 24px;
	bottom: 24px;
	width: 68px;
	height: 68px;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var( --katd4-principal );
	color: var( --katd4-principal-texto );
	cursor: pointer;
	box-shadow: 0 6px 20px rgba( 0, 0, 0, 0.28 );
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.katd4-botao:hover {
	transform: scale( 1.06 );
	box-shadow: 0 10px 28px rgba( 0, 0, 0, 0.34 );
}

.katd4-botao:focus-visible {
	outline: 3px solid var( --katd4-principal );
	outline-offset: 3px;
}

.katd4-botao svg {
	width: 34px;
	height: 34px;
	display: block;
	fill: currentColor;
}

.katd4-aberto .katd4-botao {
	display: none;
}

/* -- painel --------------------------------------------------------------- */

.katd4-painel {
	position: fixed;
	right: 24px;
	bottom: 24px;
	width: 450px;
	height: 80vh;
	max-height: 80vh;
	display: flex;
	flex-direction: column;
	background: var( --katd4-fundo );
	border-radius: 14px;
	overflow: hidden;
	box-shadow: 0 12px 40px rgba( 0, 0, 0, 0.32 );
}

.katd4-painel[hidden] {
	display: none;
}

.katd4-topo {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 14px;
	background: var( --katd4-principal );
	color: var( --katd4-principal-texto );
	flex: 0 0 auto;
}

.katd4-topo-avatar {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	object-fit: cover;
}

.katd4-topo-titulo {
	flex: 1 1 auto;
	font-weight: 600;
	font-size: 15px;
}

.katd4-acao {
	border: 0;
	background: rgba( 255, 255, 255, 0.18 );
	color: inherit;
	border-radius: 6px;
	padding: 5px 10px;
	font-size: 13px;
	cursor: pointer;
}

.katd4-acao:hover {
	background: rgba( 255, 255, 255, 0.32 );
}

/* -- conversa ------------------------------------------------------------- */

.katd4-corpo {
	flex: 1 1 auto;
	overflow-y: auto;
	scroll-behavior: smooth;
	padding: 14px;
	background: var( --katd4-fundo );
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.katd4-bolha {
	max-width: 85%;
	padding: 9px 12px;
	border-radius: 12px;
	font-size: 14.5px;
	line-height: 1.45;
	white-space: pre-wrap;
	word-wrap: break-word;
	animation: katd4-surge 0.18s ease-out;
}

@keyframes katd4-surge {
	from {
		opacity: 0;
		transform: translateY( 4px );
	}
	to {
		opacity: 1;
		transform: none;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.katd4-bolha,
	.katd4-botao,
	.katd4-opcoes,
	.katd4-opcao,
	.katd4-whatsapp {
		animation: none;
		transition: none;
	}

	.katd4-opcao:hover,
	.katd4-opcao:active {
		transform: none;
	}

	.katd4-corpo {
		scroll-behavior: auto;
	}
}

.katd4-bolha--bot {
	align-self: flex-start;
	background: var( --katd4-bot );
	color: var( --katd4-bot-texto );
	border-top-left-radius: 3px;
}

.katd4-bolha--visitante {
	align-self: flex-end;
	background: var( --katd4-visitante );
	color: var( --katd4-visitante-texto );
	border-top-right-radius: 3px;
}

/* -- opções: no fluxo, abaixo das bolhas do bot, à esquerda --------------- */

.katd4-opcoes {
	align-self: flex-start;
	max-width: 92%;
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 6px;
	margin: 2px 0 4px;
	animation: katd4-surge 0.18s ease-out;
}

.katd4-opcao {
	max-width: 100%;
	text-align: left;
	padding: 10px 16px;
	border: 0;
	border-radius: 999px;
	background: var( --katd4-principal );
	color: var( --katd4-principal-texto );
	font-size: 14px;
	font-weight: 500;
	line-height: 1.35;
	cursor: pointer;
	box-shadow: 0 1px 2px rgba( 0, 0, 0, 0.14 );
	transition: filter 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

/*
 * Com o botão já preenchido, o hover não pode ser "encher de cor". O feedback
 * vem da elevação, que funciona sobre qualquer cor escolhida no painel; o
 * brilho ajuda nas cores médias e é inofensivo nos extremos.
 */
.katd4-opcao:hover {
	filter: brightness( 1.08 );
	box-shadow: 0 3px 10px rgba( 0, 0, 0, 0.24 );
	transform: translateY( -1px );
}

.katd4-opcao:active {
	filter: brightness( 0.94 );
	box-shadow: 0 1px 2px rgba( 0, 0, 0, 0.18 );
	transform: translateY( 0 );
}

/*
 * O anel de foco não pode ser da cor principal: seria a cor do próprio botão.
 * Usa o tom que contrasta com o balão do bot, que é o vizinho mais próximo.
 */
.katd4-opcao:focus-visible {
	outline: 3px solid var( --katd4-bot-texto );
	outline-offset: 2px;
}

/* WhatsApp é ação da conversa, então mora no fluxo junto com as opções */
.katd4-whatsapp {
	align-self: flex-start;
	display: inline-block;
	padding: 11px 18px;
	border-radius: 999px;
	background: var( --katd4-principal );
	color: var( --katd4-principal-texto );
	font-size: 14.5px;
	font-weight: 600;
	text-decoration: none;
	animation: katd4-surge 0.18s ease-out;
}

/* -- rodapé: só o que se digita ------------------------------------------ */

.katd4-rodape {
	flex: 0 0 auto;
	padding: 10px;
	background: #f6f6f6;
	border-top: 1px solid #e2e2e2;
}

.katd4-rodape:empty {
	display: none;
}

.katd4-form {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
}

.katd4-campo {
	flex: 1 1 60%;
	min-width: 0;
	padding: 10px;
	border: 1px solid #ccc;
	border-radius: 8px;
	font-size: 15px;
	background: #fff;
	color: #111;
}

.katd4-campo:focus {
	outline: 2px solid var( --katd4-principal );
	outline-offset: -1px;
	border-color: var( --katd4-principal );
}

.katd4-enviar {
	padding: 10px 16px;
	border: 0;
	border-radius: 8px;
	background: var( --katd4-principal );
	color: var( --katd4-principal-texto );
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
}

.katd4-pular {
	background: #ddd;
	color: #333;
}

/* -- smartphone: tela inteira -------------------------------------------- */

@media ( max-width: 640px ) {
	.katd4-painel {
		right: 0;
		bottom: 0;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		max-height: none;
		border-radius: 0;
	}

	.katd4-botao {
		right: 16px;
		bottom: 16px;
		width: 62px;
		height: 62px;
	}

	.katd4-campo {
		font-size: 16px; /* evita o zoom automático do iOS ao focar */
	}
}
