/**
 * Polaris Rambot — footer assistant. Token-driven (brand accent re-tints the
 * dismiss control). Ported from the Ramtech partner-portal bot.
 */

.polaris-rambot {
	position: fixed;
	bottom: var(--polaris-rambot-offset-bottom, 20px);
	display: flex;
	/* Anchor to the bottom so the avatar never moves when the (variable-height)
	   bubble appears/disappears — the bubble grows upward instead of shifting it. */
	align-items: flex-end;
	gap: 12px;
	z-index: 9998;
	opacity: 0;
	transform: translateY(12px);
	transition: opacity .3s ease, transform .3s ease;
	pointer-events: none;
	font-family: var(--polaris-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}
.polaris-rambot--right { right: var(--polaris-rambot-offset-side, 20px); flex-direction: row; }
.polaris-rambot--left { left: var(--polaris-rambot-offset-side, 20px); flex-direction: row-reverse; }
.polaris-rambot.is-visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.polaris-rambot[hidden] { display: none; }

.polaris-rambot__avatar {
	position: relative;
	box-sizing: border-box;
	flex: 0 0 auto;
	width: var(--polaris-rambot-avatar-size, 64px);
	height: var(--polaris-rambot-avatar-size, 64px);
	border-radius: var(--polaris-radius-pill, 999px);
	background: var(--polaris-surface, #fff);
	border: 5px solid #fff;
	box-shadow: var(--polaris-shadow, 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1));
}
/* The image is rounded on its own so the corner badge is NOT clipped by the wrap. */
.polaris-rambot__avatar img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: var(--polaris-radius-pill, 999px); }

.polaris-rambot__bubble {
	position: relative;
	width: var(--polaris-rambot-bubble-width, 260px);
	max-width: calc(100vw - 32px);
	padding: 12px 14px;
	background: var(--polaris-surface, #fff);
	color: var(--polaris-ink, #1f2733);
	border: 1px solid var(--polaris-line, #e3e8ef);
	border-radius: 14px;
	box-shadow: var(--polaris-shadow, 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1));
	font-size: var(--polaris-rambot-font-size, 13px);
	line-height: 1.45;
	opacity: 0;
	transform: translateY(6px) scale(.96);
	transition: opacity .25s ease, transform .25s ease;
}
.polaris-rambot--right .polaris-rambot__bubble { transform-origin: bottom right; }
.polaris-rambot--left .polaris-rambot__bubble { transform-origin: bottom left; }
.polaris-rambot__bubble[hidden] { display: none; }
.polaris-rambot.is-speaking .polaris-rambot__bubble { opacity: 1; transform: translateY(0) scale(1); }

.polaris-rambot__bubble::after {
	content: '';
	position: absolute;
	top: 50%;
	width: 12px;
	height: 12px;
	background: var(--polaris-surface, #fff);
}
.polaris-rambot--right .polaris-rambot__bubble::after {
	right: -7px;
	border-right: 1px solid var(--polaris-line, #e3e8ef);
	border-bottom: 1px solid var(--polaris-line, #e3e8ef);
	transform: translateY(-50%) rotate(-45deg);
}
.polaris-rambot--left .polaris-rambot__bubble::after {
	left: -7px;
	border-left: 1px solid var(--polaris-line, #e3e8ef);
	border-bottom: 1px solid var(--polaris-line, #e3e8ef);
	transform: translateY(-50%) rotate(45deg);
}

@media (max-width: 600px) {
	.polaris-rambot { gap: 8px; }
	.polaris-rambot__bubble {
		max-width: calc(100vw - var(--polaris-rambot-avatar-size, 64px) - var(--polaris-rambot-offset-side, 20px) - 24px);
		padding: 10px 12px;
	}
}
@media (prefers-reduced-motion: reduce) {
	.polaris-rambot, .polaris-rambot__bubble { transition: none; }
}

/* ----- Concierge chat (Phase 2): notification badge + chat panel ----- */

.polaris-rambot__badge {
	position: absolute;
	top: -5px;
	right: -5px;
	min-width: 22px;
	height: 22px;
	padding: 0 6px;
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 12px;
	font-weight: 700;
	line-height: 1;
	color: #fff;
	background: var(--polaris-rambot-badge, #ef4444);
	border: 2px solid #fff;
	border-radius: var(--polaris-radius-pill, 999px);
	box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
	z-index: 3;
	transform-origin: center bottom;
	animation: polaris-rambot-badge-bounce 1s ease-in-out infinite;
}
.polaris-rambot__badge[hidden] { display: none; }
.polaris-rambot--left .polaris-rambot__badge { right: auto; left: -5px; }

@keyframes polaris-rambot-badge-bounce {
	0%, 100% { transform: translateY(0); }
	30%      { transform: translateY(-5px); }
	50%      { transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
	.polaris-rambot__badge { animation: none; }
}

/* Stand-out message bubble (vs the normal grey tip bubble) */
.polaris-rambot.is-message .polaris-rambot__bubble {
	border: 1px solid var(--polaris-rambot-badge, #ef4444);
	box-shadow: 0 6px 22px rgba(0, 0, 0, .14), 0 0 0 3px color-mix(in srgb, var(--polaris-rambot-badge, #ef4444) 16%, transparent);
}
.polaris-rambot__notif { font-weight: 600; }

/* Chat panel — anchored above the avatar */
.polaris-rambot__chat {
	position: absolute;
	bottom: calc(var(--polaris-rambot-avatar-size, 56px) + 14px);
	width: min(320px, calc(100vw - 32px));
	height: min(440px, 64vh);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--polaris-surface, #fff);
	border: 1px solid var(--polaris-line, #e3e8ef);
	border-radius: 12px;
	box-shadow: 0 18px 50px rgba(16, 24, 40, .16);
	z-index: 3;
}
.polaris-rambot--right .polaris-rambot__chat { right: 0; }
.polaris-rambot--left .polaris-rambot__chat { left: 0; }
.polaris-rambot__chat[hidden] { display: none; }

.polaris-rambot__chat-head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	background: var(--polaris-surface, #fff);
	color: var(--polaris-ink, #1f2733);
	border-bottom: 1px solid var(--polaris-line, #e3e8ef);
}
.polaris-rambot__chat-pic {
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font: 700 13px/1 var(--polaris-font, inherit);
	background: var(--polaris-line, #e3e8ef);
	border-radius: var(--polaris-radius-pill, 999px);
	overflow: hidden;
}
.polaris-rambot__chat-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.polaris-rambot__chat-x {
	margin-inline-start: 6px;
	width: 34px;
	height: 34px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: var(--polaris-ink, #4b5675);
	background: var(--polaris-surface, #fff) !important;
	border: 1px solid var(--polaris-line, #e3e8ef) !important;
	border-radius: 8px !important;
	padding: 0 !important;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.polaris-rambot__chat-x svg { width: 15px; height: 15px; }
.polaris-rambot__chat-x:hover { background: color-mix(in srgb, var(--polaris-ink, #1f2733) 6%, #fff); border-color: color-mix(in srgb, var(--polaris-ink, #1f2733) 18%, #fff); }

.polaris-rambot__chat-name {
	margin-inline-start: 4px;
	font: 600 13px/1.2 var(--polaris-font, inherit);
	color: var(--polaris-ink, #1f2733);
	white-space: nowrap;
}
.polaris-rambot__chat-end {
	margin-inline-start: auto;
	flex: 0 0 auto;
	white-space: nowrap;
	height: 34px;
	padding: 0 12px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font: 600 12px/1 var(--polaris-font, inherit);
	color: #ef4444;
	background: rgba(239, 68, 68, .1);
	border: 1px solid rgba(239, 68, 68, .28);
	border-radius: 8px;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease;
}
.polaris-rambot__chat-end:hover { background: rgba(239, 68, 68, .18); border-color: rgba(239, 68, 68, .4); }

/* In-chat close confirmation (a message-style prompt, not a browser dialog). */
.polaris-rambot__confirm {
	align-self: stretch;
	margin-top: 4px;
	padding: 12px 13px;
	border-radius: 12px;
	background: var(--polaris-surface, #fff);
	border: 1px solid var(--polaris-line, #e3e8ef);
	box-shadow: 0 2px 10px rgba(16, 24, 40, .08);
}
.polaris-rambot__confirm p {
	margin: 0 0 10px;
	font-size: 13px;
	line-height: 1.4;
	color: var(--polaris-ink, #1f2733);
}
.polaris-rambot__confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.polaris-rambot__confirm button {
	font: 600 11.5px/1 var(--polaris-font, inherit);
	padding: 5px 10px !important;
	border-radius: 8px !important;
	cursor: pointer;
	text-transform: none;
	min-width: 0;
	box-shadow: none;
	transition: filter .15s ease, background .15s ease;
}
.polaris-rambot__confirm button[data-cancel] {
	background: var(--polaris-surface, #fff) !important;
	color: var(--polaris-ink, #4b5675) !important;
	border: 1px solid var(--polaris-line, #e3e8ef) !important;
}
.polaris-rambot__confirm button[data-cancel]:hover { background: color-mix(in srgb, var(--polaris-ink, #1f2733) 6%, #fff) !important; }
.polaris-rambot__confirm button[data-confirm] {
	background: #ef4444 !important;
	color: #fff !important;
	border: 0 !important;
}
.polaris-rambot__confirm button[data-confirm]:hover { filter: brightness(1.05); }

.polaris-rambot__chat-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	background: color-mix(in srgb, var(--polaris-ink, #1f2733) 3%, #fff);
}
.polaris-rambot__chat-empty {
	margin: auto;
	font-size: 13px;
	color: color-mix(in srgb, var(--polaris-ink, #1f2733) 55%, transparent);
	text-align: center;
}
.polaris-rambot__msg {
	max-width: 82%;
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 8px 11px;
	border-radius: 13px;
	font-size: 13px;
	line-height: 1.4;
}
.polaris-rambot__msg.is-them {
	align-self: flex-start;
	background: var(--polaris-surface, #fff);
	color: var(--polaris-ink, #1f2733);
	border: 1px solid var(--polaris-line, rgba(0, 0, 0, .08));
	border-bottom-left-radius: 4px;
}
.polaris-rambot__msg.is-mine {
	align-self: flex-end;
	background: var(--polaris-accent, #2d6cdf);
	color: #fff;
	border-bottom-right-radius: 4px;
}
.polaris-rambot__msg-time { font-size: 10px; opacity: .65; }
.polaris-rambot__msg.is-mine .polaris-rambot__msg-time { text-align: right; }

.polaris-rambot__chat-form {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px;
	border-top: 1px solid var(--polaris-line, rgba(0, 0, 0, .08));
	background: var(--polaris-surface, #fff);
}
.polaris-rambot__chat-form textarea {
	flex: 1 1 auto;
	resize: none;
	max-height: 96px;
	padding: 9px 12px;
	font: 13px/1.4 var(--polaris-font, inherit);
	color: var(--polaris-ink, #1f2733);
	background: var(--polaris-surface, #fff);
	border: 1px solid var(--polaris-line, #dbdfe9);
	border-radius: 8px;
	transition: border-color .15s ease, box-shadow .15s ease;
}
.polaris-rambot__chat-form textarea:focus {
	outline: none;
	border-color: var(--polaris-accent, #2d6cdf);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--polaris-accent, #2d6cdf) 14%, transparent);
}
/* Rambot renders in the theme (outside #polaris-ui), so neutralise the host
   theme's global <button> styling (pill radius, min-width, transforms). */
.polaris-rambot__chat-send,
.polaris-rambot__chat-x {
	font-family: inherit;
	text-transform: none;
	letter-spacing: normal;
	min-width: 0;
	box-shadow: none;
	line-height: 1;
}
.polaris-rambot__chat-send {
	flex: 0 0 auto;
	width: 38px !important;
	height: 38px !important;
	padding: 0 !important;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	color: #fff !important;
	background: var(--polaris-accent, #2d6cdf) !important;
	border: 0 !important;
	border-radius: 8px !important;
	cursor: pointer;
	transition: filter .15s ease;
}
.polaris-rambot__chat-send svg { width: 16px; height: 16px; }
.polaris-rambot__chat-send i { font-size: 16px; line-height: 1; }
.polaris-rambot__chat-send:hover { filter: brightness(1.05); }

@media (max-width: 480px) {
	.polaris-rambot__chat { width: calc(100vw - 28px); height: min(70vh, 460px); }
}
