/**
 * STSPC WhatsApp Live Chat - Frontend Styles
 *
 * @package STSPC\WhatsApp
 */

/* =========================================================
   CSS Custom Properties
   ========================================================= */
:root {
	--stspc-wa-green: #25D366;
	--stspc-wa-dark-green: #128C7E;
	--stspc-wa-light-green: #DCF8C6;
	--stspc-wa-header-bg: #5c2468; /* fallback — overridden by inline style from settings */
	--stspc-wa-header-text: #ffffff;
	--stspc-wa-chat-bg: #E5DDD5;
	--stspc-wa-bubble-bg: #ffffff;
	--stspc-wa-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
	--stspc-wa-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
	--stspc-wa-radius: 16px;
	--stspc-wa-btn-radius: 50%;
	--stspc-wa-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	--stspc-wa-z-button: 999999;
	--stspc-wa-z-popup: 1000000;
}

/* =========================================================
   Widget Container
   ========================================================= */
.stspc-wa-widget {
	position: fixed;
	bottom: 24px;
	z-index: var(--stspc-wa-z-button);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 14px;
	line-height: 1.5;
	box-sizing: border-box;
	direction: ltr;
	transition: bottom 0.35s ease;
}

.stspc-wa-widget *,
.stspc-wa-widget *::before,
.stspc-wa-widget *::after {
	box-sizing: border-box;
}

.stspc-wa-bottom-right {
	right: 24px;
}

.stspc-wa-bottom-left {
	left: 24px;
}

/* =========================================================
   Floating Button
   ========================================================= */
.stspc-wa-button {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	border: none;
	border-radius: var(--stspc-wa-btn-radius);
	color: #ffffff;
	cursor: pointer;
	box-shadow: var(--stspc-wa-shadow);
	transition: transform var(--stspc-wa-transition),
	            box-shadow var(--stspc-wa-transition),
	            background-color var(--stspc-wa-transition);
	outline: none;
	-webkit-tap-highlight-color: transparent;
}

.stspc-wa-button:hover {
	transform: scale(1.08);
	box-shadow: var(--stspc-wa-shadow-lg);
}

.stspc-wa-button:focus-visible {
	outline: 3px solid #4A90D9;
	outline-offset: 3px;
}

.stspc-wa-button:active {
	transform: scale(0.96);
}

/* Icon inside button */
.stspc-wa-icon {
	display: block;
	fill: currentColor;
}

/* Text-with-icon style */
.stspc-wa-icon-text-with-icon {
	border-radius: 28px;
	padding: 0 20px;
	gap: 8px;
}

.stspc-wa-btn-text {
	font-size: 14px;
	font-weight: 600;
	white-space: nowrap;
}

/* Sizes */
.stspc-wa-size-small {
	width: 50px;
	height: 50px;
}

.stspc-wa-size-medium {
	width: 60px;
	height: 60px;
}

.stspc-wa-size-large {
	width: 70px;
	height: 70px;
}

.stspc-wa-icon-text-with-icon.stspc-wa-size-small,
.stspc-wa-icon-text-with-icon.stspc-wa-size-medium,
.stspc-wa-icon-text-with-icon.stspc-wa-size-large {
	width: auto;
	height: auto;
	padding: 12px 24px;
}

.stspc-wa-icon-text-with-icon .stspc-wa-icon {
	width: 22px;
	height: 22px;
}

/* =========================================================
   Tooltip
   ========================================================= */
.stspc-wa-tooltip {
	position: absolute;
	bottom: calc(100% + 10px);
	left: 50%;
	transform: translateX(-50%) translateY(4px);
	background: #333;
	color: #fff;
	padding: 6px 12px;
	border-radius: 6px;
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

.stspc-wa-tooltip::after {
	content: "";
	position: absolute;
	top: 100%;
	left: 50%;
	transform: translateX(-50%);
	border: 5px solid transparent;
	border-top-color: #333;
}

.stspc-wa-button:hover .stspc-wa-tooltip {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}

/* Bottom-left: tooltip alignment */
.stspc-wa-bottom-left .stspc-wa-tooltip {
	left: 0;
	transform: translateX(0) translateY(4px);
}

.stspc-wa-bottom-left .stspc-wa-tooltip::after {
	left: 20px;
	transform: none;
}

.stspc-wa-bottom-left .stspc-wa-button:hover .stspc-wa-tooltip {
	transform: translateX(0) translateY(0);
}

/* =========================================================
   Animations
   ========================================================= */
/* Pulse — keyframes generated dynamically in widget render to match button colour */

.stspc-wa-anim-pulse {
	animation: stspc-wa-pulse 2s infinite;
}

.stspc-wa-anim-pulse:hover {
	animation: none;
}

/* Bounce */
@keyframes stspc-wa-bounce {
	0%, 20%, 50%, 80%, 100% {
		transform: translateY(0);
	}
	40% {
		transform: translateY(-8px);
	}
	60% {
		transform: translateY(-4px);
	}
}

.stspc-wa-anim-bounce {
	animation: stspc-wa-bounce 2.5s infinite;
}

.stspc-wa-anim-bounce:hover {
	animation: none;
}

/* =========================================================
   Chat Popup
   ========================================================= */
.stspc-wa-popup {
	position: absolute;
	bottom: calc(100% + 16px);
	width: 370px;
	max-height: 520px;
	background: #fff;
	border-radius: var(--stspc-wa-radius);
	box-shadow: var(--stspc-wa-shadow-lg);
	overflow: hidden;
	display: flex;
	flex-direction: column;
	z-index: var(--stspc-wa-z-popup);
	opacity: 0;
	transform: translateY(20px) scale(0.95);
	pointer-events: none;
	transition: opacity var(--stspc-wa-transition),
	            transform var(--stspc-wa-transition);
}

.stspc-wa-bottom-right .stspc-wa-popup {
	right: 0;
}

.stspc-wa-bottom-left .stspc-wa-popup {
	left: 0;
}

.stspc-wa-popup.stspc-wa-popup-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Header */
.stspc-wa-popup-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	background: var(--stspc-wa-header-bg);
	color: var(--stspc-wa-header-text);
}

.stspc-wa-popup-header-info {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.stspc-wa-popup-header-title {
	font-size: 16px;
	font-weight: 700;
}

.stspc-wa-popup-header-subtitle {
	font-size: 12px;
	opacity: 0.85;
}

.stspc-wa-popup-close {
	background: none;
	border: none;
	color: var(--stspc-wa-header-text);
	font-size: 24px;
	cursor: pointer;
	padding: 0 4px;
	line-height: 1;
	opacity: 0.8;
	transition: opacity 0.2s;
	border-radius: 4px;
}

.stspc-wa-popup-close:hover {
	opacity: 1;
}

.stspc-wa-popup-close:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

/* Body */
.stspc-wa-popup-body {
	flex: 1;
	overflow-y: auto;
	padding: 20px;
	background: var(--stspc-wa-chat-bg);
	background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 10c1 0 2 1 2 2s-1 2-2 2-2-1-2-2 1-2 2-2' fill='%23c8c3ba' fill-opacity='.08'/%3E%3C/svg%3E");
}

/* Agent */
.stspc-wa-agent {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 16px;
}

.stspc-wa-agent-avatar {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	overflow: hidden;
}

.stspc-wa-agent-avatar svg {
	display: block;
}

.stspc-wa-agent-info {
	display: flex;
	flex-direction: column;
}

.stspc-wa-agent-name {
	font-weight: 600;
	font-size: 14px;
	color: #111;
}

.stspc-wa-agent-status {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12px;
	color: #666;
}

.stspc-wa-status-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
}

.stspc-wa-status-online {
	background: var(--stspc-wa-green);
}

.stspc-wa-status-offline {
	background: #999;
}

/* Message Bubble */
.stspc-wa-message-bubble {
	background: var(--stspc-wa-bubble-bg);
	padding: 12px 16px;
	border-radius: 0 12px 12px 12px;
	margin-bottom: 16px;
	font-size: 14px;
	line-height: 1.6;
	color: #333;
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
	position: relative;
}

.stspc-wa-message-bubble::before {
	content: "";
	position: absolute;
	top: 0;
	left: -8px;
	border-width: 0 8px 8px 0;
	border-style: solid;
	border-color: transparent var(--stspc-wa-bubble-bg) transparent transparent;
}

/* Quick Reply Templates */
.stspc-wa-templates {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.stspc-wa-template-btn {
	display: block;
	width: 100%;
	text-align: left;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 20px;
	padding: 10px 16px;
	font-size: 13px;
	color: var(--stspc-wa-header-bg);
	cursor: pointer;
	transition: background 0.2s, border-color 0.2s, transform 0.15s;
	font-family: inherit;
}

.stspc-wa-template-btn:hover {
	background: color-mix(in srgb, var(--stspc-wa-header-bg) 10%, #fff);
	border-color: var(--stspc-wa-header-bg);
	transform: translateX(4px);
}

.stspc-wa-template-btn:focus-visible {
	outline: 2px solid var(--stspc-wa-header-bg);
	outline-offset: 2px;
}

/* Footer / Input */
.stspc-wa-popup-footer {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 16px;
	background: #fff;
	border-top: 1px solid #e5e5e5;
}

.stspc-wa-message-input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 20px;
	padding: 10px 16px;
	font-size: 14px;
	font-family: inherit;
	outline: none;
	transition: border-color 0.2s;
}

.stspc-wa-message-input:focus {
	border-color: var(--stspc-wa-header-bg);
}

.stspc-wa-send-btn {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--stspc-wa-header-bg);
	border: none;
	border-radius: 50%;
	color: #fff;
	cursor: pointer;
	transition: background 0.2s, transform 0.15s;
}

.stspc-wa-send-btn:hover {
	background: color-mix(in srgb, var(--stspc-wa-header-bg) 80%, #000);
	transform: scale(1.08);
}

.stspc-wa-send-btn:focus-visible {
	outline: 3px solid #4A90D9;
	outline-offset: 2px;
}

.stspc-wa-send-btn:active {
	transform: scale(0.94);
}

/* =========================================================
   Mobile Responsive
   ========================================================= */
@media (max-width: 480px) {
	.stspc-wa-widget {
		bottom: 16px;
	}

	.stspc-wa-bottom-right {
		right: 16px;
	}

	.stspc-wa-bottom-left {
		left: 16px;
	}

	.stspc-wa-popup {
		width: calc(100vw - 32px);
		max-height: 70vh;
	}

	.stspc-wa-bottom-right .stspc-wa-popup {
		right: -8px;
	}

	.stspc-wa-bottom-left .stspc-wa-popup {
		left: -8px;
	}
}

/* =========================================================
   Print: hide widget
   ========================================================= */
@media print {
	.stspc-wa-widget {
		display: none !important;
	}
}

/* =========================================================
   Reduced Motion
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
	.stspc-wa-button,
	.stspc-wa-popup,
	.stspc-wa-tooltip,
	.stspc-wa-template-btn,
	.stspc-wa-send-btn {
		transition-duration: 0.01ms !important;
	}

	.stspc-wa-anim-pulse,
	.stspc-wa-anim-bounce {
		animation: none !important;
	}
}

/* =========================================================
   Hidden utility (JS controlled visibility)
   ========================================================= */
.stspc-wa-hidden {
	display: none !important;
}
