/**
 * Chat widget.
 *
 * Uses the theme's design tokens where they exist, with the DAStek values as
 * fallbacks so the widget still looks right if the plugin is ever used under a
 * different theme.
 */

.dk-chat {
	--dkc-primary: var(--dk-primary, #30c7b5);
	--dkc-primary-dark: var(--dk-primary-dark, #00ac97);
	--dkc-ink: var(--dk-ink, #14261c);
	--dkc-body: var(--dk-body, #4f5655);
	--dkc-white: var(--dk-white, #ffffff);
	--dkc-surface: var(--dk-surface-alt, #f6f7f8);
	--dkc-border: var(--dk-border, #e6e6e6);
	--dkc-font: var(--dk-font-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
	--dkc-heading: var(--dk-font-heading, var(--dkc-font));

	position: fixed;
	z-index: 9999;
	right: 1.25rem;
	bottom: 1.25rem;
	font-family: var(--dkc-font);
}

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

.dk-chat__launcher {
	display: flex;
	width: 56px;
	height: 56px;
	align-items: center;
	justify-content: center;
	margin-left: auto;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--dkc-primary);
	box-shadow: 0 8px 24px rgba(20, 38, 28, 0.28);
	color: var(--dkc-white);
	cursor: pointer;
	transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
}

.dk-chat__launcher:hover,
.dk-chat__launcher:focus-visible {
	background: var(--dkc-primary-dark);
	transform: translateY(-2px);
}

.dk-chat__launcher:focus-visible {
	outline: 3px solid var(--dkc-ink);
	outline-offset: 3px;
}

.dk-chat__launcher svg {
	display: block;
	fill: currentColor;
}

/* The icon swaps to a cross while the panel is open. */
.dk-chat__launcher-close {
	display: none;
}

.dk-chat.is-open .dk-chat__launcher-icon {
	display: none;
}

.dk-chat.is-open .dk-chat__launcher-close {
	display: block;
}

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

.dk-chat__panel {
	display: flex;
	overflow: hidden;
	width: min(23rem, calc(100vw - 2.5rem));
	height: min(30rem, calc(100vh - 8rem));
	flex-direction: column;
	margin-bottom: 0.875rem;
	background: var(--dkc-white);
	border: 1px solid var(--dkc-border);
	border-radius: 4px;
	box-shadow: 0 18px 48px rgba(20, 38, 28, 0.22);
}

.dk-chat__panel[hidden] {
	display: none;
}

.dk-chat__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.875rem 1rem;
	background: var(--dkc-ink);
	color: var(--dkc-white);
	gap: 0.5rem;
}

.dk-chat__title {
	margin: 0;
	color: var(--dkc-white);
	font-family: var(--dkc-heading);
	font-size: 16px;
	font-weight: 700;
	line-height: 1.3;
}

.dk-chat__close {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0.25rem;
	border: 0;
	background: none;
	color: inherit;
	cursor: pointer;
	opacity: 0.8;
}

.dk-chat__close:hover,
.dk-chat__close:focus-visible {
	opacity: 1;
}

.dk-chat__close svg {
	display: block;
	fill: currentColor;
}

/* -------------------------------------------------------------------------
 * Message log
 * ---------------------------------------------------------------------- */

.dk-chat__log {
	overflow-y: auto;
	flex: 1;
	padding: 1rem;
	background: var(--dkc-surface);
	overscroll-behavior: contain;
}

.dk-chat__log:focus-visible {
	outline: 2px solid var(--dkc-primary);
	outline-offset: -2px;
}

.dk-chat__msg {
	max-width: 85%;
	margin-bottom: 0.75rem;
	padding: 0.625rem 0.875rem;
	border-radius: 4px;
	font-size: 14px;
	line-height: 1.6;
}

.dk-chat__msg p {
	margin: 0 0 0.5rem;
}

.dk-chat__msg p:last-child {
	margin-bottom: 0;
}

.dk-chat__msg--bot {
	background: var(--dkc-white);
	border: 1px solid var(--dkc-border);
	color: var(--dkc-body);
}

.dk-chat__msg--user {
	margin-left: auto;
	background: var(--dkc-primary);
	color: var(--dkc-white);
}

.dk-chat__msg a {
	color: var(--dkc-primary-dark);
	text-decoration: underline;
	word-break: break-word;
}

.dk-chat__msg--user a {
	color: var(--dkc-white);
}

.dk-chat__msg--error {
	background: #fdf3f3;
	border-color: #e6c4c4;
	color: #8a2b2b;
}

/* Three dots while a reply is on its way. */
.dk-chat__typing {
	display: flex;
	width: fit-content;
	align-items: center;
	gap: 4px;
}

.dk-chat__typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--dkc-body);
	animation: dk-chat-bounce 1.2s infinite ease-in-out;
}

.dk-chat__typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.dk-chat__typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes dk-chat-bounce {
	0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-3px); }
}

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

.dk-chat__form {
	display: flex;
	align-items: flex-end;
	padding: 0.75rem;
	background: var(--dkc-white);
	border-top: 1px solid var(--dkc-border);
	gap: 0.5rem;
}

.dk-chat__input {
	max-height: 7rem;
	flex: 1;
	padding: 0.5rem 0.625rem;
	border: 1px solid var(--dkc-border);
	border-radius: 3px;
	color: var(--dkc-ink);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.5;
	resize: none;
}

.dk-chat__input:focus-visible {
	border-color: var(--dkc-primary);
	outline: 2px solid var(--dkc-primary);
	outline-offset: -1px;
}

.dk-chat__send {
	display: flex;
	width: 38px;
	height: 38px;
	flex: none;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 3px;
	background: var(--dkc-primary);
	color: var(--dkc-white);
	cursor: pointer;
	transition: background-color 0.2s ease-in-out;
}

.dk-chat__send:hover:not(:disabled),
.dk-chat__send:focus-visible {
	background: var(--dkc-primary-dark);
}

.dk-chat__send:disabled {
	cursor: not-allowed;
	opacity: 0.5;
}

.dk-chat__send svg {
	display: block;
	fill: currentColor;
}

.dk-chat__note {
	margin: 0;
	padding: 0 0.75rem 0.625rem;
	background: var(--dkc-white);
	color: var(--dkc-body);
	font-size: 11px;
	line-height: 1.4;
	text-align: center;
}

/* -------------------------------------------------------------------------
 * Small screens — the panel takes the viewport rather than floating in it
 * ---------------------------------------------------------------------- */

@media (max-width: 480px) {
	.dk-chat {
		right: 1rem;
		bottom: 1rem;
	}

	.dk-chat__panel {
		position: fixed;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 78vh;
		height: 78dvh;
		margin: 0;
		border-width: 1px 0 0;
		border-radius: 0;
	}
}

/* -------------------------------------------------------------------------
 * Respect a reduced-motion preference
 * ---------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.dk-chat__launcher,
	.dk-chat__send {
		transition: none;
	}

	.dk-chat__launcher:hover,
	.dk-chat__launcher:focus-visible {
		transform: none;
	}

	.dk-chat__typing span {
		animation: none;
		opacity: 0.6;
	}
}

/*
 * The theme provides .screen-reader-text, but the widget must stay accessible
 * under any theme, so the class is defined here too.
 */
.dk-chat .screen-reader-text {
	position: absolute !important;
	overflow: hidden;
	width: 1px;
	height: 1px;
	clip-path: inset(50%);
	white-space: nowrap;
}
