/* Chat widget — един вертикален скрол, без хоризонтален overflow. */
.kts-chat-root,
.kts-chat-root *,
.kts-chat-root *::before,
.kts-chat-root *::after {
	box-sizing: border-box;
}

.kts-chat-root {
	position: fixed;
	right: 1rem;
	bottom: 1rem;
	z-index: 99990;
	font-family: inherit;
	max-width: calc(100vw - 1rem);
}

.kts-chat-toggle {
	border: 1px solid #102E46;
	background: #102E46;
	color: #fff;
	padding: 0.7rem 1.15rem;
	cursor: pointer;
	border-radius: 999px;
	position: relative;
	font-weight: 600;
	box-shadow: 0 8px 24px rgba(16, 46, 70, 0.25);
}

.kts-chat-badge {
	position: absolute;
	top: -6px;
	right: -6px;
	background: #b33;
	color: #fff;
	border-radius: 999px;
	font-size: 0.7rem;
	min-width: 1.1rem;
	padding: 0.1rem 0.3rem;
	text-align: center;
}

.kts-chat-panel {
	/* По-голям usable viewport за дълги готови отговори */
	width: min(420px, calc(100vw - 1.5rem));
	height: min(720px, calc(100dvh - 1.5rem));
	max-height: calc(100dvh - 1.5rem);
	background: #F7F6F2;
	border: 1px solid rgba(16, 24, 32, 0.16);
	border-radius: 8px;
	box-shadow: 0 12px 36px rgba(16, 24, 32, 0.16);
	display: flex;
	flex-direction: column;
	margin-bottom: 0.5rem;
	overflow: hidden; /* без панелен скрол — само .kts-chat-scroll */
}

.kts-chat-panel[hidden] {
	display: none !important;
}

.kts-chat-root.is-open .kts-chat-toggle {
	display: none !important;
}

.kts-chat-root.is-open .kts-chat-panel {
	margin-bottom: 0;
}

.kts-chat-head {
	flex: 0 0 auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0.65rem 0.75rem;
	border-bottom: 1px solid #d9d2c8;
	background: #fff;
}

.kts-chat-head button {
	border: 0;
	background: transparent;
	cursor: pointer;
	font-size: 1.1rem;
	line-height: 1;
	padding: 0.15rem 0.35rem;
}

/* Единствената зона със скрол: съобщения + chips заедно */
.kts-chat-scroll {
	flex: 1 1 auto;
	min-height: 0;
	overflow-x: hidden;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	background: #fff;
}

.kts-chat-body {
	padding: 0.75rem;
	overflow: visible; /* без nested scrollbar */
}

.kts-chat-msg {
	margin-bottom: 0.65rem;
	font-size: 0.95rem;
	line-height: 1.45;
	max-width: 100%;
}

.kts-chat-msg time {
	display: block;
	font-size: 0.75rem;
	opacity: 0.7;
	margin-top: 0.15rem;
	overflow-wrap: anywhere;
}

.kts-chat-msg.customer {
	text-align: right;
}

.kts-chat-msg .bubble {
	display: inline-block;
	padding: 0.5rem 0.7rem;
	background: #ebe6df;
	border-radius: 2px;
	max-width: 100%;
	width: fit-content;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	word-break: break-word;
	text-align: left;
}

.kts-chat-msg.customer .bubble {
	background: #102E46;
	color: #fff;
}

.kts-chat-msg.assistant .bubble {
	background: #ebe6df;
}

.kts-chat-msg.operator .bubble {
	background: #e8eef4;
	border-left: 3px solid #A27A43;
}

.kts-chat-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	padding: 0.35rem 0.75rem 0.75rem;
	overflow: visible; /* без втори скрол */
	border-top: 1px solid rgba(16, 24, 32, 0.06);
	background: #fff;
}

.kts-chat-chip {
	border: 1px solid rgba(16, 46, 70, 0.28);
	background: #F7F6F2;
	color: #102E46;
	border-radius: 999px;
	padding: 0.4rem 0.75rem;
	font-size: 0.8rem;
	line-height: 1.25;
	cursor: pointer;
	text-align: left;
	max-width: 100%;
	overflow-wrap: anywhere;
	word-break: break-word;
	white-space: normal;
}

.kts-chat-chip:hover,
.kts-chat-chip:focus-visible {
	background: #102E46;
	color: #fff;
	outline: none;
}

.kts-chat-chip.is-operator {
	border-color: #A27A43;
	color: #A27A43;
	font-weight: 600;
}

.kts-chat-chip.is-operator:hover {
	background: #A27A43;
	color: #fff;
}

.kts-chat-sticky {
	flex: 0 0 auto;
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	padding: 0.4rem 0.65rem;
	background: #fff;
	border-top: 1px solid rgba(16, 24, 32, 0.08);
}

.kts-chat-sticky-btn {
	border: 1px solid rgba(16, 46, 70, 0.35);
	background: #fff;
	color: #102E46;
	border-radius: 2px;
	padding: 0.4rem 0.65rem;
	font-size: 0.8rem;
	cursor: pointer;
	font-weight: 600;
	flex: 1 1 auto;
	min-width: calc(50% - 0.2rem);
}

.kts-chat-sticky-btn:hover,
.kts-chat-sticky-btn:focus {
	background: #102E46;
	color: #fff;
	outline: none;
}

.kts-chat-sticky-btn.is-secondary {
	font-weight: 500;
	border-style: dashed;
}

.kts-chat-sticky-hint {
	margin: 0;
	font-size: 0.78rem;
	opacity: 0.85;
	width: 100%;
}

.kts-chat-foot {
	flex: 0 0 auto;
	padding: 0.5rem 0.65rem 0.65rem;
	border-top: 1px solid #d9d2c8;
	background: #f7f5f2;
	overflow: hidden;
}

.kts-chat-foot textarea,
.kts-chat-foot input[type="text"],
.kts-chat-foot input[type="email"] {
	display: block;
	width: 100%;
	max-width: 100%;
	margin-bottom: 0.35rem;
	font: inherit;
	resize: vertical;
	min-width: 0;
}

.kts-chat-foot textarea {
	max-height: 6.5rem;
	min-height: 2.6rem;
	resize: none; /* предотвратява раздуване и хоризонтален drag */
}

.kts-chat-foot button#kts-chat-send {
	width: 100%;
	border: 1px solid #102E46;
	background: #102E46;
	color: #fff;
	padding: 0.55rem;
	cursor: pointer;
	border-radius: 2px;
	font-weight: 600;
}

.kts-chat-note {
	font-size: 0.72rem;
	line-height: 1.35;
	margin: 0 0 0.4rem;
	opacity: 0.85;
	overflow-wrap: anywhere;
}

/* Скрит honeypot — иначе заема място и чупи layout */
.kts-chat-honeypot {
	position: absolute !important;
	left: -10000px !important;
	top: auto !important;
	width: 1px !important;
	height: 1px !important;
	opacity: 0 !important;
	overflow: hidden !important;
	pointer-events: none !important;
	margin: 0 !important;
	padding: 0 !important;
	border: 0 !important;
}

/* Mobile / тесен екран — почти пълен екран */
@media (max-width: 560px) {
	.kts-chat-root {
		right: 0;
		left: 0;
		bottom: 0;
		max-width: 100vw;
	}

	.kts-chat-root.is-open {
		top: 0;
		inset: 0;
	}

	.kts-chat-panel {
		width: 100vw;
		height: 100dvh;
		max-height: 100dvh;
		border-radius: 0;
		margin: 0;
		border-left: 0;
		border-right: 0;
		border-bottom: 0;
	}

	.kts-chat-msg {
		font-size: 0.98rem;
		line-height: 1.5;
	}

	.kts-chat-chip {
		font-size: 0.82rem;
		padding: 0.45rem 0.8rem;
		flex: 1 1 100%;
	}

	.kts-chat-sticky-btn {
		min-width: calc(50% - 0.2rem);
		font-size: 0.82rem;
	}

	.kts-chat-toggle {
		margin: 0.5rem;
	}
}

/* Consent банер отворен — вдигаме чата над него (само когато панелът е затворен). */
body:has(#kts-consent-root:not([hidden])) .kts-chat-root:not(.is-open) {
	bottom: min(36vh, 270px);
	z-index: 100010;
}

@media (max-width: 560px) {
	body:has(#kts-consent-root:not([hidden])) .kts-chat-root:not(.is-open) {
		bottom: min(38vh, 280px);
		right: 0.5rem;
		left: auto;
	}

	/* Отворен чат над consent — пълен екран без изместване */
	body:has(#kts-consent-root:not([hidden])) .kts-chat-root.is-open {
		inset: 0;
		bottom: 0;
		z-index: 100020;
	}
}
