/**
 * SiteStaffr Fixed Position Widget Styles
 *
 * Styles for the floating voice widget ([sitestaffr_widget] shortcode).
 * Includes 5 widget states: idle, listening, thinking, speaking, error.
 *
 * @package    SiteStaffr
 * @since      0.11.76
 */

/* ===========================
   WIDGET CONTAINER
   =========================== */

.sitestaffr-widget {
	position: fixed;
	z-index: 999999;
	display: flex;
	flex-direction: column;
	align-items: center;
}

/* Position variants */
.sitestaffr-widget.position-bottom-right {
	bottom: 20px;
	right: 20px;
}

.sitestaffr-widget.position-bottom-left {
	bottom: 20px;
	left: 20px;
}

/* Raise widget when tooltip is below to prevent clipping */
.sitestaffr-widget.sitestaffr-tooltip--bottom.position-bottom-right,
.sitestaffr-widget.sitestaffr-tooltip--bottom.position-bottom-left {
	bottom: 50px;
}

/* Mobile responsive - reduce spacing */
@media (max-width: 768px) {
	.sitestaffr-widget.position-bottom-right {
		bottom: 15px;
		right: 15px;
	}

	.sitestaffr-widget.position-bottom-left {
		bottom: 15px;
		left: 15px;
	}
}

/* ===========================
   WIDGET BUTTON
   =========================== */

.sitestaffr-widget-button {
	position: relative;
	width: var(--widget-size, 60px);
	height: var(--widget-size, 60px);
	border-radius: var(--widget-border-radius, 20px 20px 20px 0px);
	border: var(--widget-border-width, 0) var(--widget-border-style, none) var(--widget-border-color, transparent);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	transition: all 0.3s ease;
	padding: 0;
	outline: none;
}

/* Color properties use ID selector for Elementor specificity */
#sitestaffr-widget .sitestaffr-widget-button {
	background-color: var(--widget-bg-color, #0073aa);
	color: var(--widget-icon-color, #ffffff);
}

.sitestaffr-widget-button:hover {
	transform: scale(1.05);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Hover colors — idle state only (listening/speaking/thinking states have fixed colors) */
#sitestaffr-widget:not(.state-listening):not(.state-thinking):not(.state-speaking):not(.state-searching):not(.state-error) .sitestaffr-widget-button:hover {
	background-color: var(--widget-hover-bg-color, var(--widget-bg-color));
	color: var(--widget-hover-icon-color, var(--widget-icon-color));
}

#sitestaffr-widget:not(.state-listening):not(.state-thinking):not(.state-speaking):not(.state-searching):not(.state-error) .sitestaffr-widget-button:hover svg {
	color: var(--widget-hover-icon-color, var(--widget-icon-color));
}

.sitestaffr-widget-button:active {
	transform: scale(0.98);
}

.sitestaffr-widget-button:focus {
	outline: 2px solid var(--widget-bg-color, #0073aa);
	outline-offset: 2px;
}

/* Ensure touch targets are at least 44px */
@media (max-width: 768px) {
	.sitestaffr-widget-button {
		min-width: 44px;
		min-height: 44px;
	}
}

/* ===========================
   ICONS
   =========================== */

.sitestaffr-icon {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: var(--widget-icon-size, 24px);
	height: var(--widget-icon-size, 24px);
	opacity: 0;
	transition: opacity 0.3s ease;
}

/* Show phone icon by default (idle state) */
.sitestaffr-widget:not(.state-connecting):not(.state-listening):not(.state-thinking):not(.state-speaking):not(.state-searching):not(.state-error) .sitestaffr-icon-phone {
	opacity: 1;
}

/* Show microphone icon ONLY when listening */
.sitestaffr-widget.state-listening .sitestaffr-icon-microphone {
	opacity: 1;
}

/* Show spinner when connecting or thinking */
.sitestaffr-widget.state-connecting .sitestaffr-icon-spinner,
.sitestaffr-widget.state-thinking .sitestaffr-icon-spinner,
.sitestaffr-widget.state-searching .sitestaffr-icon-spinner {
	opacity: 1;
	animation: sitestaffr-spin 1s linear infinite;
}

/* Show soundwave when speaking */
.sitestaffr-widget.state-speaking .sitestaffr-icon-soundwave {
	opacity: 1;
}

/* Show phone icon when error (fallback) */
.sitestaffr-widget.state-error .sitestaffr-icon-phone {
	opacity: 1;
}

/* ===========================
   SOUNDWAVE ANIMATION
   =========================== */

.sitestaffr-icon-soundwave {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 3px;
}

.sitestaffr-icon-soundwave span {
	width: 3px;
	background-color: currentColor;
	border-radius: 2px;
	animation: sitestaffr-soundwave 1s ease-in-out infinite;
}

.sitestaffr-icon-soundwave span:nth-child(1) {
	height: 8px;
	animation-delay: 0s;
}

.sitestaffr-icon-soundwave span:nth-child(2) {
	height: 14px;
	animation-delay: 0.2s;
}

.sitestaffr-icon-soundwave span:nth-child(3) {
	height: 10px;
	animation-delay: 0.4s;
}

@keyframes sitestaffr-soundwave {
	0%, 100% {
		transform: scaleY(1);
	}
	50% {
		transform: scaleY(1.5);
	}
}

/* ===========================
   SPINNER ANIMATION
   =========================== */

@keyframes sitestaffr-spin {
	from {
		transform: translate(-50%, -50%) rotate(0deg);
	}
	to {
		transform: translate(-50%, -50%) rotate(360deg);
	}
}

/* ===========================
   PULSE ANIMATION (LISTENING STATE)
   =========================== */

.sitestaffr-pulse-ring {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: var(--widget-size, 60px);
	height: var(--widget-size, 60px);
	border-radius: var(--widget-border-radius, 20px 20px 20px 0px);
	border: 2px solid #e74c3c;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
}

.sitestaffr-widget.state-listening .sitestaffr-pulse-ring {
	opacity: 1;
	animation: sitestaffr-pulse 1.5s ease-out infinite;
}

@keyframes sitestaffr-pulse {
	0% {
		transform: translate(-50%, -50%) scale(1);
		opacity: 0.8;
	}
	100% {
		transform: translate(-50%, -50%) scale(1.5);
		opacity: 0;
	}
}

/* ===========================
   STATUS TOOLTIP
   =========================== */

.sitestaffr-widget-tooltip {
	position: absolute;
	bottom: calc(100% + 10px);
	left: 50%;
	transform: translateX(-50%);
	background-color: rgba(0, 0, 0, 0.85);
	color: #ffffff;
	padding: 8px 12px;
	border-radius: 6px;
	font-size: 13px;
	font-weight: 500;
	white-space: nowrap;
	max-width: min(350px, calc(100vw - 24px));
	text-align: center;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
	z-index: 10;
}

.sitestaffr-widget-tooltip::after {
	content: '';
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	border: 6px solid transparent;
	border-top-color: rgba(0, 0, 0, 0.85);
}

/* Keep tooltip inside viewport for edge-pinned widget positions */
.sitestaffr-widget.position-bottom-right .sitestaffr-widget-tooltip {
	left: auto;
	right: 0;
	transform: none;
	text-align: left;
}

.sitestaffr-widget.position-bottom-right .sitestaffr-widget-tooltip::after {
	left: auto;
	right: calc((var(--widget-size, 60px) / 2) - 6px);
	transform: none;
}

.sitestaffr-widget.position-bottom-left .sitestaffr-widget-tooltip {
	left: 0;
	right: auto;
	transform: none;
	text-align: left;
}

.sitestaffr-widget.position-bottom-left .sitestaffr-widget-tooltip::after {
	left: calc((var(--widget-size, 60px) / 2) - 6px);
	transform: none;
}

/* Show tooltip on hover (idle state only) */
.sitestaffr-widget:not(.state-connecting):not(.state-listening):not(.state-thinking):not(.state-speaking):not(.state-searching):not(.state-error) .sitestaffr-widget-button:hover + .sitestaffr-widget-tooltip {
	opacity: 1;
}

/* Tooltip below widget */
.sitestaffr-widget.sitestaffr-tooltip--bottom .sitestaffr-widget-tooltip {
	bottom: auto;
	top: calc(100% + 10px);
}

.sitestaffr-widget.sitestaffr-tooltip--bottom .sitestaffr-widget-tooltip::after {
	top: auto;
	bottom: 100%;
	border-top-color: transparent;
	border-bottom-color: rgba(0, 0, 0, 0.85);
}

/* Persistent tooltip — always visible when enabled */
.sitestaffr-widget.sitestaffr-tooltip--persistent .sitestaffr-widget-tooltip {
	opacity: 1;
	visibility: visible;
}

/* Show tooltip while the voice session is establishing */
.sitestaffr-widget.state-connecting .sitestaffr-widget-tooltip {
	opacity: 1;
}

/* Show tooltip during knowledge search with contextual text */
.sitestaffr-widget.state-searching .sitestaffr-widget-tooltip {
	opacity: 1;
	font-style: italic;
}

/* Update tooltip text based on state */
.sitestaffr-widget.state-listening .sitestaffr-tooltip-text::before {
	content: attr(data-listening-text);
}

.sitestaffr-widget.state-thinking .sitestaffr-tooltip-text::before {
	content: attr(data-thinking-text);
}

.sitestaffr-widget.state-speaking .sitestaffr-tooltip-text::before {
	content: attr(data-speaking-text);
}

.sitestaffr-widget.state-error .sitestaffr-tooltip-text::before {
	content: attr(data-error-text);
}

/* ===========================
   STATE COLORS
   =========================== */

/* Listening state - always red button with white icon, no border */
.sitestaffr-widget.state-listening .sitestaffr-widget-button {
	background-color: #e74c3c !important;
	border-color: transparent !important;
}

.sitestaffr-widget.state-listening .sitestaffr-widget-button svg {
	stroke: #ffffff !important;
	fill: none !important;
}

/* Error state - red button with shake */
.sitestaffr-widget.state-error .sitestaffr-widget-button {
	background-color: #e74c3c;
	animation: sitestaffr-shake 0.5s ease;
}

@keyframes sitestaffr-shake {
	0%, 100% {
		transform: translateX(0);
	}
	25% {
		transform: translateX(-5px);
	}
	75% {
		transform: translateX(5px);
	}
}

/* ===========================
   ACCESSIBILITY
   =========================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
	.sitestaffr-widget-button {
		border: 2px solid currentColor;
	}
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
	.sitestaffr-widget-button,
	.sitestaffr-icon,
	.sitestaffr-pulse-ring,
	.sitestaffr-widget-tooltip {
		transition: none;
		animation: none;
	}
}

/* ===========================
   MOBILE OPTIMIZATIONS
   =========================== */

@media (max-width: 768px) {
	.sitestaffr-widget-tooltip {
		font-size: 12px;
		padding: 6px 10px;
	}
}

/* ===========================
   MIC PERMISSION OVERLAY
   =========================== */

/* Mic permission overlay — shown during getUserMedia() browser prompt */
.sitestaffr-mic-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.75);
	z-index: 999998; /* Below browser permission prompt, above everything else */
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0;
	transition: opacity 0.25s ease;
	pointer-events: none;
}

.sitestaffr-mic-overlay.is-visible {
	opacity: 1;
	pointer-events: auto;
}

.sitestaffr-mic-overlay-text {
	color: #fff;
	font-size: 18px;
	font-weight: 500;
	text-align: center;
	max-width: 400px;
	line-height: 1.5;
	padding: 0 24px;
}

.sitestaffr-mic-retry-btn {
	display: inline-block;
	background: #1FB6CC;
	color: #fff;
	border: none;
	padding: 10px 24px;
	border-radius: 6px;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease;
}

.sitestaffr-mic-retry-btn:hover {
	background: #00838F;
}

.sitestaffr-mic-dismiss-btn {
	display: inline-block;
	background: none;
	border: none;
	color: rgba(255, 255, 255, 0.7);
	font-size: 14px;
	cursor: pointer;
	padding: 6px 12px;
	margin-top: 4px;
	transition: color 0.15s ease;
}

.sitestaffr-mic-dismiss-btn:hover {
	color: #fff;
}
