/*
 * Kreaktiv Chatbot widget styles.
 * Mobile-first: below 640px the panel becomes a full-height sheet with
 * safe-area padding, which is what makes the installed app feel native.
 */

#kcb-root {
	--kcb-accent: #1f6feb;
	--kcb-bg: #ffffff;
	--kcb-surface: #f4f5f7;
	--kcb-text: #16181d;
	--kcb-muted: #5b6472;
	--kcb-border: #e3e6ea;
	--kcb-radius: 14px;
	--kcb-shadow: 0 12px 40px rgba(15, 20, 30, 0.18);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: var(--kcb-text);
}

/*
 * An author-level `display` declaration outranks the browser's built-in
 * [hidden] rule, so hiding .kcb-log (display:flex) with the hidden attribute
 * alone does nothing - the welcome screen and the conversation would then be
 * drawn on top of each other. State it explicitly.
 */
#kcb-root [hidden],
body.kcb-standalone [hidden] {
	display: none !important;
}

@media (prefers-color-scheme: dark) {
	#kcb-root,
	body.kcb-standalone {
		--kcb-bg: #16181d;
		--kcb-surface: #22262e;
		--kcb-text: #f2f4f7;
		--kcb-muted: #a4adba;
		--kcb-border: #333a45;
		--kcb-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
	}
}

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

.kcb-launcher {
	position: fixed;
	bottom: calc(20px + env(safe-area-inset-bottom));
	inset-inline-end: 20px;
	z-index: 99998;
	width: 58px;
	height: 58px;
	border: 0;
	border-radius: 50%;
	background: var(--kcb-accent);
	color: #fff;
	box-shadow: var(--kcb-shadow);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: transform 0.15s ease;
}

.kcb-launcher:hover { transform: scale(1.05); }
.kcb-launcher:focus-visible { outline: 3px solid var(--kcb-accent); outline-offset: 3px; }

#kcb-root.kcb-pos-left .kcb-launcher { inset-inline-end: auto; inset-inline-start: 20px; }

/* Hint bubble beside the launcher, dismissed on first open. */

.kcb-bubble-hint {
	position: fixed;
	bottom: calc(30px + env(safe-area-inset-bottom));
	inset-inline-end: 90px;
	z-index: 99997;
	max-width: 220px;
	padding: 10px 14px;
	border: 1px solid var(--kcb-border);
	border-radius: 12px;
	background: var(--kcb-bg);
	color: var(--kcb-text);
	font: inherit;
	font-size: 13.5px;
	text-align: start;
	box-shadow: var(--kcb-shadow);
	cursor: pointer;
	animation: kcb-fade-in 0.4s ease 1.2s both;
}

#kcb-root.kcb-pos-left .kcb-bubble-hint { inset-inline-end: auto; inset-inline-start: 90px; }

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

@media (prefers-reduced-motion: reduce) {
	.kcb-bubble-hint { animation: none; }
}

/* ------------------------------------------------------------------- Panel */

#kcb-root.kcb-floating .kcb-panel {
	position: fixed;
	bottom: calc(88px + env(safe-area-inset-bottom));
	inset-inline-end: 20px;
	z-index: 99999;
	width: 390px;
	max-width: calc(100vw - 40px);
	height: 560px;
	max-height: calc(100vh - 130px);
	background: var(--kcb-bg);
	border: 1px solid var(--kcb-border);
	border-radius: var(--kcb-radius);
	box-shadow: var(--kcb-shadow);
	display: none;
	flex-direction: column;
	overflow: hidden;
}

#kcb-root.kcb-pos-left .kcb-panel { inset-inline-end: auto; inset-inline-start: 20px; }
#kcb-root.kcb-floating .kcb-panel.is-open { display: flex; }

#kcb-root.kcb-embedded .kcb-panel {
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 480px;
	background: var(--kcb-bg);
	border: 1px solid var(--kcb-border);
	border-radius: var(--kcb-radius);
	overflow: hidden;
}

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

.kcb-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: var(--kcb-accent);
	color: #fff;
	flex: 0 0 auto;
}

.kcb-header-title { font-weight: 600; font-size: 15px; }

.kcb-close {
	border: 0;
	background: transparent;
	color: #fff;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
	padding: 0 4px;
	opacity: 0.85;
}

.kcb-close:hover { opacity: 1; }

/* ------------------------------------------------------------ Welcome view */

.kcb-welcome {
	flex: 1 1 auto;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
	background: var(--kcb-bg);
}

.kcb-welcome-headline {
	margin: 0 0 8px;
	font-size: 19px;
	line-height: 1.3;
	font-weight: 700;
	color: var(--kcb-text);
}

.kcb-welcome-sub {
	margin: 0 0 18px;
	color: var(--kcb-muted);
	font-size: 14px;
}

.kcb-welcome-back {
	display: block;
	width: 100%;
	margin-bottom: 18px;
	padding: 11px 14px;
	border: 1px solid var(--kcb-border);
	border-radius: 10px;
	background: var(--kcb-surface);
	color: var(--kcb-text);
	font: inherit;
	font-weight: 600;
	font-size: 14px;
	cursor: pointer;
}

.kcb-welcome-form { display: flex; flex-direction: column; gap: 14px; }

.kcb-field { display: flex; flex-direction: column; gap: 5px; }

.kcb-field-label { font-size: 13px; font-weight: 600; color: var(--kcb-text); }

.kcb-field-input {
	width: 100%;
	box-sizing: border-box;
	padding: 11px 12px;
	border: 1px solid var(--kcb-border);
	border-radius: 10px;
	/* 16px keeps iOS Safari from zooming the viewport on focus. */
	font-size: 16px;
	font-family: inherit;
	background: var(--kcb-bg);
	color: var(--kcb-text);
}

.kcb-field-input:focus { outline: 2px solid var(--kcb-accent); outline-offset: -1px; }

.kcb-consent {
	display: flex;
	align-items: flex-start;
	gap: 9px;
	font-size: 12.5px;
	line-height: 1.45;
	color: var(--kcb-muted);
	cursor: pointer;
}

.kcb-consent input { margin-top: 2px; flex: 0 0 auto; width: 16px; height: 16px; }
.kcb-consent a { color: var(--kcb-accent); }

.kcb-welcome-error {
	margin: 0;
	padding: 9px 11px;
	border-radius: 8px;
	background: rgba(215, 38, 61, 0.1);
	color: #b3182f;
	font-size: 13px;
}

.kcb-welcome-submit {
	padding: 13px 16px;
	border: 0;
	border-radius: 10px;
	background: var(--kcb-accent);
	color: #fff;
	font: inherit;
	font-weight: 600;
	font-size: 15px;
	cursor: pointer;
}

.kcb-welcome-submit:disabled { opacity: 0.6; cursor: default; }

.kcb-welcome-skip {
	display: block;
	width: 100%;
	margin-top: 12px;
	padding: 6px;
	border: 0;
	background: none;
	color: var(--kcb-muted);
	font: inherit;
	font-size: 13px;
	text-decoration: underline;
	cursor: pointer;
}

.kcb-channels {
	margin-top: 24px;
	padding-top: 18px;
	border-top: 1px solid var(--kcb-border);
}

.kcb-channels-title {
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--kcb-muted);
	margin-bottom: 9px;
}

.kcb-channel {
	display: block;
	padding: 10px 12px;
	margin-bottom: 7px;
	border: 1px solid var(--kcb-border);
	border-radius: 9px;
	color: var(--kcb-text);
	text-decoration: none;
	font-size: 14px;
}

.kcb-channel::before { margin-inline-end: 8px; }
.kcb-channel-email::before { content: "✉"; }
.kcb-channel-phone::before { content: "☎"; }
.kcb-channel:hover { border-color: var(--kcb-accent); }

/* --------------------------------------------------------------- Transcript */

.kcb-log {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	background: var(--kcb-bg);
}

.kcb-msg { display: flex; }
.kcb-msg-user { justify-content: flex-end; }

.kcb-bubble {
	max-width: 85%;
	padding: 10px 13px;
	border-radius: 14px;
	background: var(--kcb-surface);
	white-space: normal;
	overflow-wrap: anywhere;
}

.kcb-msg-user .kcb-bubble {
	background: var(--kcb-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.kcb-msg-assistant .kcb-bubble { border-bottom-left-radius: 4px; }

.kcb-link { color: var(--kcb-accent); text-decoration: underline; }
.kcb-msg-user .kcb-link { color: #fff; }

.kcb-link-cart {
	display: inline-block;
	margin-top: 8px;
	padding: 9px 15px;
	border-radius: 8px;
	background: var(--kcb-accent);
	color: #fff !important;
	font-weight: 600;
	text-decoration: none;
}

.kcb-link-cart:hover { filter: brightness(1.08); }

/* Typing indicator */

.kcb-typing { display: flex; gap: 4px; align-items: center; padding: 14px 15px; }

.kcb-typing span {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--kcb-muted);
	animation: kcb-bounce 1.2s infinite ease-in-out;
}

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

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

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

/* ----------------------------------------------------------------- Composer */

.kcb-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid var(--kcb-border);
	background: var(--kcb-bg);
	flex: 0 0 auto;
}

.kcb-input {
	flex: 1 1 auto;
	resize: none;
	border: 1px solid var(--kcb-border);
	border-radius: 10px;
	padding: 10px 12px;
	/* 16px keeps iOS Safari from zooming the viewport on focus. */
	font-size: 16px;
	font-family: inherit;
	line-height: 1.4;
	max-height: 120px;
	background: var(--kcb-bg);
	color: var(--kcb-text);
}

.kcb-input:focus { outline: 2px solid var(--kcb-accent); outline-offset: -1px; }

.kcb-send {
	flex: 0 0 auto;
	width: 42px;
	height: 42px;
	border: 0;
	border-radius: 10px;
	background: var(--kcb-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.kcb-send:disabled { opacity: 0.5; cursor: default; }

.kcb-footer {
	padding: 7px 14px calc(9px + env(safe-area-inset-bottom));
	font-size: 11px;
	color: var(--kcb-muted);
	text-align: center;
	background: var(--kcb-bg);
	flex: 0 0 auto;
}

/* ------------------------------------------------------------------- Mobile */

@media (max-width: 640px) {
	#kcb-root.kcb-floating .kcb-panel {
		inset: 0;
		width: 100%;
		max-width: none;
		height: 100dvh;
		max-height: none;
		border: 0;
		border-radius: 0;
	}

	#kcb-root.kcb-floating .kcb-panel.is-open ~ .kcb-launcher { display: none; }

	.kcb-header { padding-top: calc(14px + env(safe-area-inset-top)); }

	body.kcb-open { overflow: hidden; }
}

@media (max-width: 480px) {
	/* Not enough width beside the launcher for a readable hint. */
	.kcb-bubble-hint { display: none; }
}

/* -------------------------------------------------------- Standalone / PWA */

body.kcb-standalone {
	--kcb-bg: #ffffff;
	--kcb-surface: #f4f5f7;
	--kcb-text: #16181d;
	--kcb-muted: #5b6472;
	--kcb-border: #e3e6ea;
	margin: 0;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	background: var(--kcb-bg);
	color: var(--kcb-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.kcb-standalone .kcb-app-main,
body.kcb-standalone #kcb-root {
	flex: 1 1 auto;
	display: flex;
	min-height: 0;
}

body.kcb-standalone #kcb-root.kcb-embedded .kcb-panel {
	flex: 1 1 auto;
	border: 0;
	border-radius: 0;
	min-height: 0;
}

.kcb-app-nav {
	display: flex;
	gap: 4px;
	padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
	background: var(--kcb-surface);
	border-bottom: 1px solid var(--kcb-border);
	flex: 0 0 auto;
}

.kcb-app-nav a {
	flex: 1 1 0;
	text-align: center;
	padding: 9px 12px;
	border-radius: 9px;
	color: var(--kcb-muted);
	text-decoration: none;
	font-weight: 600;
	font-size: 14px;
}

.kcb-app-nav a.is-active { background: var(--kcb-bg); color: var(--kcb-text); }

.kcb-badge {
	display: inline-block;
	min-width: 19px;
	padding: 1px 6px;
	margin-inline-start: 5px;
	border-radius: 10px;
	background: #d7263d;
	color: #fff;
	font-size: 12px;
}

/* -------------------------------------------------------------- Alarm view */

.kcb-alarms {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
}

.kcb-alarms h1 { font-size: 19px; margin: 0 0 14px; }
.kcb-alarms-empty { color: var(--kcb-muted); }
.kcb-alarm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.kcb-alarm {
	border: 1px solid var(--kcb-border);
	border-inline-start: 4px solid var(--kcb-muted);
	border-radius: 11px;
	padding: 13px 14px;
	background: var(--kcb-surface);
}

.kcb-alarm-critical { border-inline-start-color: #d7263d; }
.kcb-alarm-warning { border-inline-start-color: #e08600; }
.kcb-alarm-notice { border-inline-start-color: #1f6feb; }

.kcb-alarm-title { font-weight: 600; margin-bottom: 3px; }
.kcb-alarm-sku { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--kcb-muted); }
.kcb-alarm-prices { margin: 9px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kcb-alarm-observed { font-size: 17px; font-weight: 700; color: #d7263d; }
.kcb-alarm-arrow { color: var(--kcb-muted); }
.kcb-alarm-expected { font-size: 17px; font-weight: 700; color: #1a7f4b; }
.kcb-alarm-msg { font-size: 13px; color: var(--kcb-muted); }

.kcb-alarm-actions { display: flex; gap: 8px; margin-top: 12px; }

.kcb-alarm-edit,
.kcb-alarm-resolve {
	flex: 1 1 0;
	text-align: center;
	padding: 9px 12px;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	text-decoration: none;
	border: 1px solid var(--kcb-border);
}

.kcb-alarm-edit { background: var(--kcb-accent, #1f6feb); color: #fff; border-color: transparent; }
.kcb-alarm-resolve { background: var(--kcb-bg); color: var(--kcb-text); }
.kcb-alarm-resolve:disabled { opacity: 0.5; }
