/**
 * Doctor Banoo chat widget. Uses the theme's colour variables when they exist and the brand values
 * otherwise, so it looks right under any theme.
 */

.drb-chat {
	--c-green: var(--wp--preset--color--green-action, #2fa184);
	--c-ink: var(--wp--preset--color--green-ink, #1f5d4c);
	--c-soft: var(--wp--preset--color--green-bg, #e8f7f0);
	--c-pink: var(--wp--preset--color--brand-pink, #f58fae);
	--c-cream: var(--wp--preset--color--cream, #fdf7f0);
	--c-white: var(--wp--preset--color--white, #fffcfd);
	--c-line: var(--wp--preset--color--line, #efe9eb);
	--c-muted: var(--wp--preset--color--text-muted, #5e6b65);
	--c-text: var(--wp--preset--color--text, #1b2420);
	position: fixed;
	inset-block-end: 20px;
	inset-inline-end: 20px;
	z-index: 70;
	font-family: inherit;
	direction: rtl;
}

.drb-chat *,
.drb-chat *::before,
.drb-chat *::after {
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent;
}

.drb-chat :focus:not(:focus-visible) {
	outline: none;
}

.drb-chat svg {
	inline-size: 22px;
	block-size: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.drb-chat__toggle {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-block-size: 52px;
	padding: 0 18px;
	border: 0;
	border-radius: 999px;
	background: var(--c-ink);
	color: #fff;
	font: inherit;
	font-weight: 600;
	box-shadow: 0 10px 28px rgba(27, 36, 32, 0.22);
	cursor: pointer;
	transition: transform 200ms ease-out, background-color 200ms ease-out;
}

.drb-chat__toggle:hover {
	background: var(--c-green);
}

.drb-chat.is-open .drb-chat__toggle {
	transform: scale(0.92);
}

@media (max-width: 899px) {
	.drb-chat__toggle {
		inline-size: 52px;
		padding: 0;
		justify-content: center;
	}

	.drb-chat__toggle-label {
		position: absolute;
		inline-size: 1px;
		block-size: 1px;
		overflow: hidden;
		clip: rect(0 0 0 0);
	}
}

.drb-chat__dot {
	position: absolute;
	inset-block-start: 4px;
	inset-inline-start: 4px;
	inline-size: 12px;
	block-size: 12px;
	border: 2px solid #fff;
	border-radius: 50%;
	background: var(--c-pink);
}

.drb-chat__panel {
	position: absolute;
	inset-block-end: 64px;
	inset-inline-end: 0;
	display: flex;
	flex-direction: column;
	inline-size: min(380px, calc(100vw - 24px));
	block-size: min(560px, calc(100dvh - 140px));
	overflow: hidden;
	border-radius: 22px;
	background: var(--c-white);
	color: var(--c-text);
	box-shadow: 0 24px 60px rgba(27, 36, 32, 0.24);
	animation: drb-chat-in 200ms ease-out;
}

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

/* Only on a phone: the page behind the sheet dims, and a tap on it closes the sheet. */

.drb-chat__scrim {
	display: none;
}

@media (max-width: 899px) {
	.drb-has-tabbar .drb-chat__scrim {
		position: fixed;
		inset: 0;
		display: block;
		background: rgba(27, 36, 32, 0.32);
		animation: drb-chat-fade 200ms ease-out;
	}

	.drb-has-tabbar .drb-chat__scrim[hidden] {
		display: none;
	}
}

@keyframes drb-chat-fade {
	from {
		opacity: 0;
	}
}

@keyframes drb-chat-in {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
}

/* The face of the widget: an avatar, a softer head, ready-made questions, the writing dots, and
   the short invitation that appears on its own. */

.drb-chat__avatar {
	display: grid;
	place-items: center;
	flex: 0 0 auto;
	inline-size: 38px;
	block-size: 38px;
	border-radius: 50%;
	background: var(--c-white);
	color: var(--c-pink);
	box-shadow: 0 2px 6px rgba(27, 36, 32, 0.12);
}

.drb-chat__avatar svg {
	inline-size: 20px;
	block-size: 20px;
	fill: currentColor;
	stroke: none;
}

.drb-chat__starters {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.drb-chat__starter {
	padding: 6px 12px;
	border: 1px solid var(--c-line);
	border-radius: 999px;
	background: var(--c-cream);
	font: inherit;
	font-size: 13px;
	color: var(--c-ink);
	cursor: pointer;
	transition: border-color 180ms ease-out, background-color 180ms ease-out;
}

.drb-chat__starter:hover {
	border-color: var(--c-green);
	background: var(--c-soft);
}

.drb-chat__typing {
	display: flex;
	align-items: center;
	align-self: flex-start;
	gap: 8px;
	padding: 10px 14px;
	border-radius: 16px;
	border-end-start-radius: 6px;
	background: var(--c-soft);
}

.drb-chat__dots {
	display: flex;
	gap: 5px;
}

.drb-chat__typingtext {
	color: var(--c-ink);
	font-size: 13px;
}

.drb-chat__typing[hidden] {
	display: none;
}

.drb-chat__dots span {
	inline-size: 6px;
	block-size: 6px;
	border-radius: 50%;
	background: var(--c-green);
	animation: drb-chat-dots 1.4s ease-in-out infinite;
}

.drb-chat__dots span:nth-child(2) {
	animation-delay: 200ms;
}

.drb-chat__dots span:nth-child(3) {
	animation-delay: 400ms;
}

@keyframes drb-chat-dots {
	0%,
	60%,
	100% {
		opacity: 0.35;
		transform: translateY(0);
	}

	30% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

/* The invitation */

.drb-chat__nudge {
	position: absolute;
	inset-block-end: 68px;
	inset-inline-end: 0;
	display: flex;
	align-items: stretch;
	gap: 2px;
	max-inline-size: min(300px, calc(100vw - 32px));
	padding: 4px;
	border: 1px solid var(--c-line);
	border-radius: 20px;
	background: linear-gradient(135deg, var(--c-white), #ffeef4);
	box-shadow: 0 14px 34px rgba(27, 36, 32, 0.2);
	opacity: 0;
	transform: translateY(10px) scale(0.96);
	transform-origin: 100% 100%;
	transition: opacity 240ms ease-out, transform 240ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.drb-chat__nudge.is-in {
	opacity: 1;
	transform: none;
}

.drb-chat__nudgebody {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border: 0;
	border-radius: 16px;
	background: transparent;
	font: inherit;
	font-size: 14px;
	line-height: 1.6;
	color: var(--c-text);
	text-align: start;
	cursor: pointer;
}

.drb-chat__nudgemark {
	display: grid;
	place-items: center;
	flex: 0 0 auto;
	inline-size: 36px;
	block-size: 36px;
	border-radius: 50%;
	background: var(--c-ink);
	color: #fff;
}

.drb-chat__nudgeclose {
	align-self: flex-start;
	padding: 6px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--c-muted);
	cursor: pointer;
}

.drb-chat__nudgeclose svg {
	inline-size: 16px;
	block-size: 16px;
}

/* Whatever opens the chat gives a small wave while the invitation is up. */

.is-nudging .drb-icon,
.drb-chat__toggle.is-nudging svg {
	animation: drb-chat-wave 1.1s ease-in-out 3;
}

@keyframes drb-chat-wave {
	0%,
	100% {
		transform: rotate(0);
	}

	20% {
		transform: rotate(-12deg);
	}

	40% {
		transform: rotate(10deg);
	}

	60% {
		transform: rotate(-6deg);
	}
}

@media (max-width: 899px) {
	.drb-has-tabbar .drb-chat__nudge {
		inset-block-end: calc(var(--drb-tabbar-height, 64px) + env(safe-area-inset-bottom, 0px) + 26px);
		inset-inline: 12px auto;
		max-inline-size: calc(100vw - 24px);
	}
}

.drb-chat__head {
	display: flex;
	align-items: center;
	gap: 10px;
	justify-content: space-between;
	gap: 8px;
	padding: 14px 16px;
	background: var(--c-ink);
	color: #fff;
}

.drb-chat__head div {
	display: grid;
	line-height: 1.5;
}

.drb-chat__status {
	font-size: 12px;
	opacity: 0.85;
}

.drb-chat__status.is-online::before {
	content: "";
	display: inline-block;
	inline-size: 8px;
	block-size: 8px;
	margin-inline-end: 6px;
	border-radius: 50%;
	background: #6dc9a8;
}

.drb-chat__close {
	display: grid;
	place-items: center;
	inline-size: 36px;
	block-size: 36px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
}

.drb-chat__body {
	flex: 1;
	padding: 14px;
	overflow-y: auto;
	background: var(--c-cream);
}

.drb-chat__intro {
	margin: 0 0 10px;
	padding: 9px 12px;
	border-radius: 14px;
	background: var(--c-white);
	font-size: 14px;
	line-height: 1.8;
}

.drb-chat__log {
	display: grid;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.drb-chat__msg {
	display: grid;
	max-inline-size: 85%;
	padding: 8px 12px 4px;
	border-radius: 16px;
	background: var(--c-white);
	font-size: 15px;
	line-height: 1.8;
}

.drb-chat__msg p {
	margin: 0;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.drb-chat__msg time {
	justify-self: end;
	color: var(--c-muted);
	font-size: 11px;
}

/* The visitor's own messages on the start side, the team's on the end side. */
.drb-chat__msg--visitor {
	justify-self: start;
	border-start-start-radius: 4px;
	background: var(--c-soft);
}

.drb-chat__msg--team {
	justify-self: end;
	border-start-end-radius: 4px;
}

.drb-chat__msg--system {
	justify-self: center;
	max-inline-size: 95%;
	background: transparent;
	color: var(--c-muted);
	font-size: 13px;
	text-align: center;
}

.drb-chat__who {
	color: var(--c-ink);
	font-size: 12px;
	font-weight: 700;
}

.drb-chat__startform {
	display: grid;
	gap: 10px;
}

.drb-chat__row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

/* The button that starts the conversation never leaves the screen, whatever the form does. */
.drb-chat__start {
	position: sticky;
	inset-block-end: -14px;
	z-index: 2;
	margin-block-start: 2px;
	box-shadow: 0 -10px 16px var(--c-cream);
}

.drb-chat__field {
	display: grid;
	gap: 4px;
	font-size: 13px;
	font-weight: 600;
}

.drb-chat__field input,
.drb-chat__field textarea,
.drb-chat__input {
	inline-size: 100%;
	padding: 10px 12px;
	border: 1px solid var(--c-line);
	border-radius: 12px;
	background: var(--c-white);
	color: var(--c-text);
	font: inherit;
	font-size: 16px;
	font-weight: 400;
}

.drb-chat__field input:focus,
.drb-chat__field textarea:focus,
.drb-chat__input:focus {
	outline: 2px solid var(--c-soft);
	border-color: var(--c-green);
}

.drb-chat__trap {
	position: absolute;
	inline-size: 1px;
	block-size: 1px;
	opacity: 0;
	pointer-events: none;
}

.drb-chat__error {
	margin: 0;
	color: var(--c-ink);
	font-size: 13px;
}

.drb-chat__start {
	min-block-size: 46px;
	border: 0;
	border-radius: 12px;
	background: var(--c-green);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

.drb-chat__start:disabled {
	opacity: 0.6;
}

.drb-chat__composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-block-start: 1px solid var(--c-line);
	background: var(--c-white);
}

.drb-chat__composer[hidden] {
	display: none;
}

.drb-chat__input {
	flex: 1;
	max-block-size: 120px;
	resize: none;
	border-radius: 20px;
}

.drb-chat__send {
	display: grid;
	flex: 0 0 auto;
	place-items: center;
	inline-size: 44px;
	block-size: 44px;
	border: 0;
	border-radius: 50%;
	background: var(--c-green);
	color: #fff;
	cursor: pointer;
}

.drb-chat__note {
	margin: 0;
	padding: 6px 14px 10px;
	background: var(--c-white);
	color: var(--c-muted);
	font-size: 11px;
	line-height: 1.7;
	text-align: center;
}

/* On a phone the theme's tab bar carries the chat, so the bubble in the corner would only cover
   the page. The panel becomes a sheet that rises from the bottom edge and stops above the tabs. */

@media (max-width: 899px) {
	.drb-has-tabbar .drb-chat__toggle {
		display: none;
	}

	body.drb-has-tabbar.drb-chat-open {
		overflow: hidden;
	}

	.drb-has-tabbar .drb-chat {
		inset-block-end: 0;
		inset-inline: 0;
	}

	.drb-has-tabbar .drb-chat__panel {
		position: fixed;
		inset-block-end: calc(var(--drb-tabbar-height, 64px) + env(safe-area-inset-bottom, 0px));
		inset-inline: 0;
		inline-size: 100%;
		max-block-size: calc(100dvh - var(--drb-tabbar-height, 64px) - env(safe-area-inset-bottom, 0px) - 12px);
		block-size: 86dvh;
		border-start-start-radius: 26px;
		border-start-end-radius: 26px;
		border-end-start-radius: 0;
		border-end-end-radius: 0;
		box-shadow: 0 -18px 50px rgba(27, 36, 32, 0.22);
		animation: drb-chat-up 260ms cubic-bezier(0.2, 0.7, 0.2, 1);
	}

	/* A handle at the top, so it reads as a sheet that came up rather than a page that appeared. */
	.drb-has-tabbar .drb-chat__panel::before {
		content: "";
		position: absolute;
		inset-block-start: 8px;
		inset-inline-start: 50%;
		inline-size: 40px;
		block-size: 4px;
		margin-inline-start: -20px;
		border-radius: 999px;
		background: var(--c-line);
	}

	.drb-has-tabbar .drb-chat__head {
		padding-block-start: 18px;
	}
}

@keyframes drb-chat-up {
	from {
		transform: translateY(100%);
	}
}

@media (max-width: 599px) {
	body:not(.drb-has-tabbar) .drb-chat.is-open {
		inset: 0;
	}

	body:not(.drb-has-tabbar) .drb-chat.is-open .drb-chat__panel {
		position: fixed;
		inset: 0;
		inline-size: 100%;
		block-size: 100dvh;
		border-radius: 0;
	}

	body:not(.drb-has-tabbar) .drb-chat.is-open .drb-chat__toggle {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.drb-chat__panel {
		animation: none !important;
	}
}
