/*
 * The Help chat (Round 2 item 9; cards 171, 172; owner Oct 2 #38). Enqueued
 * only while the `chatbot` switch is on (ChatbotRenderer), and linked by the
 * /support/ page for its in-page copy; every rule is scoped to a class only
 * the plugin prints.
 *
 * STACKING WITH THE SUBMIT LISTING BUTTON (§8H, card 157)
 * -------------------------------------------------------
 * feed-chrome.css pins .ys-submit-fab at bottom 16px, --ys-fab-size tall, on
 * the front page (body.ys-has-fab), and reserved --ys-chat-clearance for a
 * chat bubble above it. Here:
 *
 *   - the bubble is 56px; with the FAB on the page it sits 12px above it:
 *       bottom: calc(16px + safe-area + var(--ys-fab-size) + 12px)
 *   - --ys-chat-clearance becomes 56px + 12px, which feed-chrome.css already
 *     adds to the body's bottom padding, so the footer clears both buttons;
 *   - on a page without the FAB the bubble takes the FAB's spot and the body
 *     gets its own clearance;
 *   - the browse-wall nudge (browse-wall.css), which sits where the bubble
 *     now is, is lifted above the bubble.
 *
 * #10301f is the FAB's green, so the two read as one stack.
 *
 * THE OPEN PANEL (owner, Oct 2 #38)
 * ---------------------------------
 * It stacks above everything the site pins to the screen -- the theme's fixed
 * header, the WP admin bar (99999), the announcement banner (100000), the
 * business-ad popup (100001), the Submit FAB and the bubble -- so its header
 * bar and X are never covered: --ys-chat-z.
 *
 *   computer  a floating panel bottom right, 380 x 600, shorter only when the
 *             window is;
 *   phone     (max-width: 640px, chatbot.js PHONE_QUERY) the whole screen:
 *             100dvh (100vh before it), then the visual viewport's height
 *             from chatbot.js (--ys-chat-vv-h) so the text box sits above
 *             the keyboard; safe-area insets top and bottom; the bubble is
 *             hidden and the page behind does not scroll (html.ys-chat-locked).
 *   /support/ (.ys-chatbot--inline) the panel sits in the page, a card 560px
 *             tall, with no bubble and no X.
 *
 * Header bar #237C30 is the site green's darker step (#2E9E3D family), dark
 * enough for white text. Greens only, everywhere in the widget; the one red
 * is the Rejected tag on a listing, which is a problem to fix.
 */

:root {
	--ys-chat-bubble: 56px;
	--ys-chat-gap: 12px;
	--ys-chat-green: #10301f;
	--ys-chat-brand: #2E9E3D;
	--ys-chat-brand-dark: #237C30;
	--ys-chat-tint: #EEF7EF;
	--ys-chat-line: #B9DDBF;
	--ys-chat-z: 100010;
}

body.ys-has-chatbot {
	--ys-chat-clearance: calc(var(--ys-chat-bubble) + var(--ys-chat-gap));
}

body.ys-has-chatbot:not(.ys-has-fab) {
	padding-bottom: calc(var(--ys-chat-bubble) + 24px);
}

.ys-chatbot {
	--ys-chat-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	font-family: inherit;
}

body.ys-has-fab .ys-chatbot {
	--ys-chat-bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--ys-fab-size, 56px) + var(--ys-chat-gap));
}

body.ys-has-fab.ys-has-chatbot .ys-browse-nudge {
	bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--ys-fab-size, 56px) + var(--ys-chat-gap) + var(--ys-chat-clearance));
}

.ys-chatbot[hidden],
.ys-chatbot [hidden] {
	display: none !important;
}

/* ------------------------------------------------------------------ bubble */

.ys-chatbot__bubble {
	position: fixed;
	right: calc(16px + env(safe-area-inset-right, 0px));
	bottom: var(--ys-chat-bottom);
	z-index: 901;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--ys-chat-bubble);
	height: var(--ys-chat-bubble);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--ys-chat-green);
	color: #fff;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
	cursor: pointer;
}

.ys-chatbot__bubble:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 6px var(--ys-chat-green);
}

/*
 * R4-68 (Nov 2): on the post-a-listing form (submit-wizard.js puts
 * html.ys-form-open on the page) the bubble sat on the right end of Next,
 * Pay and Submit and on the name and email boxes. On a phone or a narrow
 * window it is not drawn there: the form is the one page where every control
 * runs to the right edge. The chat is still one tap away from the form's own
 * "Still not working? Get in touch" line (the wizard clicks the bubble's
 * button for her), and an open chat keeps its bubble rules. Every other page
 * is unchanged.
 */
@media (max-width: 991px) {
	html.ys-form-open .ys-chatbot:not(.is-open) .ys-chatbot__bubble {
		display: none;
	}
}

/* ------------------------------------------------------------------- panel */

.ys-chatbot__panel {
	position: fixed;
	right: calc(16px + env(safe-area-inset-right, 0px));
	bottom: calc(var(--ys-chat-bottom) + var(--ys-chat-bubble) + var(--ys-chat-gap));
	z-index: var(--ys-chat-z);
	display: flex;
	flex-direction: column;
	width: min(380px, calc(100vw - 32px));
	height: min(600px, calc(100vh - var(--ys-chat-bottom) - var(--ys-chat-bubble) - 40px));
	height: min(600px, calc(100dvh - var(--ys-chat-bottom) - var(--ys-chat-bubble) - 40px));
	background: #fff;
	color: #1c2a21;
	border: 1px solid #e1e8e2;
	border-radius: 16px;
	box-shadow: 0 12px 36px rgba(0, 0, 0, .22);
	overflow: hidden;
}

.ys-chatbot__head {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 8px 10px 14px;
	background: var(--ys-chat-brand-dark);
	color: #fff;
}

.ys-chatbot__avatar {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: #fff;
	color: var(--ys-chat-brand-dark);
	font-size: 11px;
	font-weight: 700;
}

/* R4-31: the site logo (the Today's Posts mark's 512px file) laid over the
   "YAD" letters, whole in the circle (contain: never cropped or stretched).
   The logo is opaque white, so the letters only show if it is missing. */
.ys-chatbot__avatar--logo {
	position: relative;
	overflow: hidden;
}

.ys-chatbot__logo {
	position: absolute;
	inset: 0;
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 50%;
	object-fit: contain;
	-webkit-user-drag: none;
}

.ys-chatbot__heading {
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
}

.ys-chatbot__title {
	font-size: 16px;
	font-weight: 600;
	line-height: 1.2;
}

.ys-chatbot__who {
	font-size: 12px;
	line-height: 1.3;
	color: #E0FFDF;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ys-chatbot__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #fff;
	cursor: pointer;
}

.ys-chatbot__close:hover {
	background: rgba(255, 255, 255, .14);
}

.ys-chatbot__close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: -2px;
}

/* The scrolling middle: the conversation, then the step's buttons. */
.ys-chatbot__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	padding: 14px 14px 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.ys-chatbot__log {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.ys-chatbot__msg {
	max-width: 86%;
	padding: 10px 14px;
	border-radius: 18px;
	font-size: 14.5px;
	line-height: 1.45;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
}

.ys-chatbot__msg--assistant {
	align-self: flex-start;
	background: #f3f3f3;
	border-top-left-radius: 6px;
}

.ys-chatbot__msg--user {
	align-self: flex-end;
	background: var(--ys-chat-brand-dark);
	color: #fff;
	border-top-right-radius: 6px;
}

.ys-chatbot__msg--note {
	align-self: stretch;
	max-width: none;
	background: var(--ys-chat-tint);
	color: #1F6B2C;
	font-size: 13px;
}

.ys-chatbot__msg--pending {
	opacity: .6;
	font-style: italic;
}

/* The listing the person picked, on their side. */
.ys-chatbot__pick {
	align-self: flex-end;
	display: flex;
	align-items: center;
	gap: 10px;
	max-width: 86%;
	padding: 8px 12px;
	border: 1.5px solid var(--ys-chat-brand-dark);
	border-radius: 18px;
	border-top-right-radius: 6px;
	background: var(--ys-chat-tint);
}

.ys-chatbot__pick-body,
.ys-chatbot__card-body {
	display: flex;
	flex-direction: column;
	min-width: 0;
	gap: 3px;
}

.ys-chatbot__pick-caption,
.ys-chatbot__card-caption {
	font-size: 14.5px;
	font-weight: 600;
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.ys-chatbot__pick-sub {
	font-size: 12px;
	color: #435248;
}

/* What we have on it: from the listing's own record. */
.ys-chatbot__facts {
	display: flex;
	flex-direction: column;
	gap: 6px;
	white-space: normal;
}

.ys-chatbot__facts-head {
	font-weight: 600;
}

.ys-chatbot__facts-num {
	font-weight: 400;
	color: #52645a;
}

.ys-chatbot__tag {
	display: inline-block;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	background: #eceff0;
	color: #4a5558;
}

.ys-chatbot__tag.is-live {
	background: var(--ys-chat-tint);
	color: var(--ys-chat-brand-dark);
}

.ys-chatbot__tag.is-red {
	background: #fdeaea;
	color: #a12a2a;
}

/* ----------------------------------------------------------------- buttons */

.ys-chatbot__options {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 8px;
	margin-top: 2px;
}

.ys-chatbot__opt {
	max-width: 100%;
	font: inherit;
	line-height: 1.25;
	text-align: left;
	cursor: pointer;
}

.ys-chatbot__opt--chip {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 9px 15px;
	border: 1.5px solid var(--ys-chat-brand-dark);
	border-radius: 999px;
	background: #fff;
	color: #1f6a2b;
	font-size: 14.5px;
}

.ys-chatbot__opt--chip:hover {
	background: var(--ys-chat-tint);
}

.ys-chatbot__lock {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 12.5px;
	color: #52645a;
}

.ys-chatbot__opt--ghost {
	padding: 9px 15px;
	border: 1.5px solid #d6dfd8;
	border-radius: 999px;
	background: #fff;
	color: #435248;
	font-size: 14.5px;
}

.ys-chatbot__opt--primary,
.ys-chatbot__opt--outline {
	align-self: stretch;
	min-height: 46px;
	padding: 10px 16px;
	border-radius: 999px;
	font-size: 15px;
	font-weight: 700;
	text-align: center;
}

.ys-chatbot__opt--primary {
	border: 0;
	background: var(--ys-chat-brand);
	color: #fff;
}

.ys-chatbot__opt--primary:hover {
	background: #25843A;
}

.ys-chatbot__opt--outline {
	border: 2px solid var(--ys-chat-brand-dark);
	background: #fff;
	color: #1f6a2b;
}

.ys-chatbot__opt--listing {
	align-self: stretch;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 12px;
	border: 1px solid #d6dfd8;
	border-radius: 16px;
	background: #fff;
	color: #1c2a21;
}

.ys-chatbot__opt--listing:hover {
	border-color: var(--ys-chat-line);
	background: #fbfdfb;
}

.ys-chatbot__card-sub {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 12px;
	color: #52645a;
}

.ys-chatbot__thumb {
	flex: 0 0 auto;
	display: block;
	width: 44px;
	height: 44px;
	border-radius: 12px;
	background: #e4ebe5;
	overflow: hidden;
}

.ys-chatbot__thumb img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ys-chatbot__opt-label {
	margin: 6px 0 0;
	font-size: 12px;
	letter-spacing: .04em;
	text-transform: uppercase;
	color: #52645a;
}

.ys-chatbot__opt:focus-visible {
	outline: 2px solid var(--ys-chat-brand);
	outline-offset: 2px;
}

.ys-chatbot__botcheck {
	margin-top: 4px;
}

/* -------------------------------------------------------------------- form */

.ys-chatbot__form {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	border-top: 1px solid #e3e9e4;
	background: #fff;
}

.ys-chatbot__input {
	flex: 1 1 auto;
	min-width: 0;
	height: 42px;
	padding: 0 16px;
	border: 1px solid #d6dfd8;
	border-radius: 999px;
	font: inherit;
	font-size: 15px;
}

.ys-chatbot__input:focus {
	outline: 2px solid var(--ys-chat-brand);
	outline-offset: -1px;
}

.ys-chatbot__send {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--ys-chat-brand-dark);
	color: #fff;
	cursor: pointer;
}

.ys-chatbot__send[disabled] {
	opacity: .4;
	cursor: default;
}

/* -------------------------------------------------- /support/: in the page */

.ys-chatbot--inline .ys-chatbot__panel {
	position: relative;
	right: auto;
	bottom: auto;
	z-index: auto;
	width: 100%;
	height: 560px;
	max-height: calc(100vh - 160px);
	max-height: calc(100dvh - 160px);
	min-height: 420px;
	border-radius: 20px;
	box-shadow: 0 1px 2px rgba(20, 29, 27, .05);
}

/* ------------------------------------------------- phone: the whole screen */

html.ys-chat-locked,
html.ys-chat-locked body {
	overflow: hidden !important;
	overscroll-behavior: none;
}

@media (max-width: 640px) {
	.ys-chatbot:not(.ys-chatbot--inline) .ys-chatbot__panel {
		top: 0;
		right: 0;
		bottom: auto;
		left: 0;
		width: 100%;
		height: 100vh;
		height: 100dvh;
		max-height: none;
		border: 0;
		border-radius: 0;
		box-shadow: none;
	}

	/* The visual viewport, once chatbot.js has measured it: above the keyboard. */
	.ys-chatbot.has-vv .ys-chatbot__panel {
		top: var(--ys-chat-vv-top, 0px);
		height: var(--ys-chat-vv-h, 100dvh);
	}

	.ys-chatbot:not(.ys-chatbot--inline) .ys-chatbot__head {
		padding-top: calc(10px + env(safe-area-inset-top, 0px));
		padding-right: calc(8px + env(safe-area-inset-right, 0px));
		padding-left: calc(14px + env(safe-area-inset-left, 0px));
	}

	.ys-chatbot__title {
		font-size: 17px;
	}

	.ys-chatbot:not(.ys-chatbot--inline) .ys-chatbot__form {
		padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
		padding-right: calc(12px + env(safe-area-inset-right, 0px));
		padding-left: calc(12px + env(safe-area-inset-left, 0px));
	}

	/* 16px: iOS does not zoom the page into a box this size. */
	.ys-chatbot__input {
		font-size: 16px;
		height: 46px;
	}

	.ys-chatbot__send {
		width: 46px;
		height: 46px;
	}

	.ys-chatbot.is-open .ys-chatbot__bubble {
		display: none;
	}
}
