/**
 * SiteStaffr Chat Panel Styles
 *
 * Styles for the text chat panel and landing card used by
 * [sitestaffr_widget] and [sitestaffr_button] shortcodes.
 *
 * @package    SiteStaffr
 * @since      1.5.0
 */

/* ===========================
   CSS VARIABLES
   =========================== */

.sitestaffr-chat-panel,
.sitestaffr-landing-card {
	--chat-primary: var(--widget-bg-color, #1FB6CC);
	--chat-primary-hover: var(--widget-hover-bg-color, #17A2B8);
	--chat-text-on-primary: var(--widget-icon-color, #ffffff);
	--chat-bg: #ffffff;
	--chat-border: #e5e7eb;
	--chat-text: #1f2937;
	--chat-text-muted: #6b7280;
	--chat-visitor-bg: #1FB6CC;
	--chat-visitor-text: #ffffff;
	--chat-assistant-bg: #f3f4f6;
	--chat-assistant-text: #1f2937;
	--chat-input-bg: #ffffff;
	--chat-input-border: #d1d5db;
	--chat-input-focus: var(--chat-primary);
	--chat-radius: 12px;
	--chat-panel-width: 380px;
	--chat-panel-height: 520px;
}

/* ===========================
   LANDING CARD (both mode)
   =========================== */

.sitestaffr-landing-card {
	position: fixed;
	z-index: 999998;
	width: var(--chat-panel-width);
	background: var(--chat-bg);
	border-radius: var(--chat-radius);
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.95);
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.sitestaffr-landing-card.is-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.sitestaffr-landing-card-header {
	padding: 20px 20px 12px;
	text-align: center;
}

.sitestaffr-landing-card-header h3 {
	margin: 0 0 4px;
	font-size: 17px;
	font-weight: 600;
	color: var(--chat-text);
}

.sitestaffr-landing-card-header p {
	margin: 0;
	font-size: 13px;
	color: var(--chat-text-muted);
}

.sitestaffr-landing-card-tiles {
	display: flex;
	gap: 12px;
	padding: 8px 20px 20px;
}

.sitestaffr-landing-tile {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding: 20px 12px;
	background: #f9fafb;
	border: 2px solid var(--chat-border);
	border-radius: 10px;
	cursor: pointer;
	transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
	text-align: center;
}

.sitestaffr-landing-tile:hover {
	border-color: var(--chat-primary);
	background: #f0fdfa;
	transform: translateY(-1px);
}

.sitestaffr-landing-tile:active {
	transform: translateY(0);
}

.sitestaffr-landing-tile-icon {
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--chat-primary);
	border-radius: 10px;
	color: var(--chat-text-on-primary);
}

.sitestaffr-landing-tile-icon svg {
	width: 22px;
	height: 22px;
	stroke: currentColor;
	fill: none;
}

.sitestaffr-landing-tile-label {
	font-size: 14px;
	font-weight: 600;
	color: var(--chat-text);
}

.sitestaffr-landing-tile-desc {
	font-size: 12px;
	color: var(--chat-text-muted);
	line-height: 1.3;
}

/* ===========================
   CHAT PANEL
   =========================== */

.sitestaffr-chat-panel {
	position: fixed;
	z-index: 999998;
	width: var(--chat-panel-width);
	height: var(--chat-panel-height);
	max-height: calc(100vh - 120px);
	background: var(--chat-bg);
	border-radius: var(--chat-radius);
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.95);
	transition: opacity 0.2s ease, transform 0.2s ease;
	pointer-events: none;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.sitestaffr-chat-panel.is-open {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

/* Positioning — set by JS based on widget position */
.sitestaffr-chat-panel.position-bottom-right,
.sitestaffr-landing-card.position-bottom-right {
	bottom: 90px;
	right: 20px;
}

.sitestaffr-chat-panel.position-bottom-left,
.sitestaffr-landing-card.position-bottom-left {
	bottom: 90px;
	left: 20px;
}

/* Raise panels when widget is raised for below-widget tooltip */
.sitestaffr-chat-panel.sitestaffr-tooltip--bottom.position-bottom-right,
.sitestaffr-landing-card.sitestaffr-tooltip--bottom.position-bottom-right {
	bottom: 120px;
	right: 20px;
}

.sitestaffr-chat-panel.sitestaffr-tooltip--bottom.position-bottom-left,
.sitestaffr-landing-card.sitestaffr-tooltip--bottom.position-bottom-left {
	bottom: 120px;
	left: 20px;
}


/* ===========================
   CHAT HEADER
   =========================== */

.sitestaffr-chat-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	background: var(--chat-primary);
	color: var(--chat-text-on-primary);
	flex-shrink: 0;
}

.sitestaffr-chat-header-title {
	font-size: 15px;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	margin: 0;
}

.sitestaffr-chat-header-actions {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
}

.sitestaffr-chat-header-btn {
	background: none;
	border: none;
	color: var(--chat-text-on-primary);
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	display: flex;
	align-items: center;
	justify-content: center;
	opacity: 0.8;
	transition: opacity 0.15s ease;
}

.sitestaffr-chat-header-btn:hover {
	opacity: 1;
}

.sitestaffr-chat-header-btn svg {
	width: 18px;
	height: 18px;
}

.sitestaffr-chat-mute-btn.is-muted {
	opacity: 0.5;
}

/* ===========================
   MESSAGES AREA
   =========================== */

.sitestaffr-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	scroll-behavior: smooth;
}

/* Scrollbar styling */
.sitestaffr-chat-messages::-webkit-scrollbar {
	width: 5px;
}

.sitestaffr-chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

.sitestaffr-chat-messages::-webkit-scrollbar-thumb {
	background: #d1d5db;
	border-radius: 3px;
}

/* ===========================
   MESSAGE BUBBLES
   =========================== */

.sitestaffr-chat-message {
	max-width: 80%;
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 14px;
	line-height: 1.5;
	word-wrap: break-word;
	overflow-wrap: break-word;
	animation: sitestaffr-msg-in 0.2s ease;
}

.sitestaffr-chat-message--visitor {
	align-self: flex-end;
	background: var(--chat-visitor-bg);
	color: var(--chat-visitor-text);
	border-bottom-right-radius: 4px;
}

.sitestaffr-chat-message--assistant {
	align-self: flex-start;
	background: var(--chat-assistant-bg);
	color: var(--chat-assistant-text);
	border-bottom-left-radius: 4px;
}

/* Markdown rendering inside assistant bubbles */
.sitestaffr-chat-message--assistant p {
	margin: 0 0 0.4em;
}
.sitestaffr-chat-message--assistant p:last-child {
	margin-bottom: 0;
}
.sitestaffr-chat-message--assistant ul,
.sitestaffr-chat-message--assistant ol {
	margin: 0.4em 0;
	padding-left: 1.4em;
}
.sitestaffr-chat-message--assistant li {
	margin-bottom: 0.3em;
}
.sitestaffr-chat-message--assistant li:last-child {
	margin-bottom: 0;
}
.sitestaffr-chat-message--assistant strong {
	font-weight: 600;
}
.sitestaffr-chat-message--assistant code {
	background: rgba(0, 0, 0, 0.06);
	padding: 0.1em 0.3em;
	border-radius: 3px;
	font-size: 0.9em;
}

.sitestaffr-chat-message--streaming {
	/* No extra styles needed — content arrives progressively */
}

@keyframes sitestaffr-msg-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ===========================
   TYPING INDICATOR
   =========================== */

.sitestaffr-chat-typing {
	align-self: flex-start;
	display: none;
	align-items: center;
	gap: 4px;
	padding: 12px 16px;
	background: var(--chat-assistant-bg);
	border-radius: 16px;
	border-bottom-left-radius: 4px;
}

.sitestaffr-chat-typing.is-visible {
	display: flex;
}

.sitestaffr-chat-typing-dot {
	width: 7px;
	height: 7px;
	background: #9ca3af;
	border-radius: 50%;
	animation: sitestaffr-typing-bounce 1.2s ease-in-out infinite;
}

.sitestaffr-chat-typing-dot:nth-child(2) {
	animation-delay: 0.15s;
}

.sitestaffr-chat-typing-dot:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes sitestaffr-typing-bounce {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.4;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* ===========================
   CHARACTER COUNT
   =========================== */

.sitestaffr-chat-char-count {
	font-size: 11px;
	color: #9ca3af;
	text-align: right;
	padding: 0 16px 2px;
	flex-shrink: 0;
	display: none;
}

.sitestaffr-chat-char-count.is-visible {
	display: block;
}

.sitestaffr-chat-char-count.near-limit {
	color: #ef4444;
}

/* ===========================
   INPUT AREA
   =========================== */

.sitestaffr-chat-input-area {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 16px 16px;
	border-top: 1px solid var(--chat-border);
	flex-shrink: 0;
	background: var(--chat-bg);
}

.sitestaffr-chat-input-wrapper {
	flex: 1;
	position: relative;
}

.sitestaffr-chat-textarea {
	width: 100%;
	min-height: 40px;
	max-height: 100px;
	padding: 10px 12px;
	border: 1px solid var(--chat-input-border);
	border-radius: 20px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.4;
	resize: none;
	outline: none;
	transition: border-color 0.15s ease;
	box-sizing: border-box;
	color: var(--chat-text);
	background: var(--chat-input-bg);
}

.sitestaffr-chat-textarea:focus {
	border-color: var(--chat-input-focus);
}

.sitestaffr-chat-textarea::placeholder {
	color: #9ca3af;
}

.sitestaffr-chat-panel .sitestaffr-chat-send-btn {
	width: 40px;
	height: 40px;
	border: none;
	border-radius: 50%;
	background: var(--chat-primary);
	color: var(--chat-text-on-primary);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	padding: 0;
	margin: 0;
	line-height: 1;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.sitestaffr-chat-panel .sitestaffr-chat-send-btn:hover {
	background: var(--chat-primary-hover);
}

.sitestaffr-chat-panel .sitestaffr-chat-send-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

.sitestaffr-chat-panel .sitestaffr-chat-send-btn svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
	stroke: none;
	display: block;
}

/* ===========================
   NOTICE (inactivity, error)
   =========================== */

.sitestaffr-chat-notice {
	text-align: center;
	padding: 8px 16px;
	font-size: 12px;
	color: var(--chat-text-muted);
	font-style: italic;
}

/* ===========================
   PANEL-OPEN STATE
   =========================== */

.sitestaffr-widget.panel-open .sitestaffr-widget-tooltip {
	display: none;
}

/* On mobile fullscreen, hide the floating widget button so it doesn't overlap */
@media (max-width: 480px) {
	.sitestaffr-widget.panel-open .sitestaffr-widget-button {
		display: none;
	}
}

/* ===========================
   LANDING CARD CLOSE BUTTON
   =========================== */

.sitestaffr-landing-card-close {
	display: none;
	position: absolute;
	top: 12px;
	right: 12px;
	background: none;
	border: none;
	color: var(--chat-text-muted);
	cursor: pointer;
	padding: 4px;
	border-radius: 4px;
	align-items: center;
	justify-content: center;
	opacity: 0.8;
	transition: opacity 0.15s ease;
	z-index: 1;
}

.sitestaffr-landing-card-close:hover {
	opacity: 1;
}

.sitestaffr-landing-card-close svg {
	width: 18px;
	height: 18px;
}

@media (max-width: 480px) {
	.sitestaffr-chat-panel,
	.sitestaffr-landing-card {
		top: 0 !important;
		left: 0 !important;
		right: 0 !important;
		bottom: 0 !important;
		width: auto !important;
		height: auto !important;
		max-height: none !important;
		border-radius: 0;
	}

	.sitestaffr-landing-card {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.sitestaffr-landing-card-close {
		display: flex;
	}

	.sitestaffr-landing-card-tiles {
		flex-direction: column;
	}
}

/* ===========================
   CONTACT FORM FALLBACK
   =========================== */

.sitestaffr-contact-form {
	padding: 16px;
	border-top: 1px solid var(--chat-border);
}

.sitestaffr-contact-form-intro {
	margin: 0 0 12px;
	font-size: 14px;
	color: var(--chat-text);
	line-height: 1.4;
}

.sitestaffr-contact-form-fields {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.sitestaffr-contact-input,
.sitestaffr-contact-textarea {
	width: 100%;
	padding: 10px 12px;
	border: 1px solid var(--chat-input-border);
	border-radius: 8px;
	font-size: 14px;
	font-family: inherit;
	color: var(--chat-text);
	background: var(--chat-input-bg);
	box-sizing: border-box;
	transition: border-color 0.15s ease;
}

.sitestaffr-contact-input:focus,
.sitestaffr-contact-textarea:focus {
	outline: none;
	border-color: var(--chat-input-focus);
}

.sitestaffr-contact-textarea {
	resize: vertical;
	min-height: 60px;
}

.sitestaffr-contact-submit {
	padding: 10px 16px;
	background: var(--chat-primary);
	color: var(--chat-text-on-primary);
	border: none;
	border-radius: 8px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease;
}

.sitestaffr-contact-submit:hover {
	background: var(--chat-primary-hover);
}

.sitestaffr-contact-submit:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.sitestaffr-contact-form-success {
	margin: 0;
	padding: 20px 0;
	text-align: center;
	font-size: 14px;
	color: var(--chat-text);
	line-height: 1.4;
}

/* System message bubble (mic recovery, etc.) */
.sitestaffr-chat-bubble--system {
	background: #f0f4f8;
	color: #475569;
	font-size: 13px;
	line-height: 1.5;
	padding: 10px 14px;
	border-radius: 12px;
	margin: 8px 12px;
	text-align: center;
}
