/**
 * JSE AI Chat Widget Stylesheet
 *
 * Designed with a premium dark glassmorphic theme, smooth micro-animations,
 * and HSL-based harmonious color palettes.
 *
 * @since 1.0.0
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
	--jse-chat-font: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	--jse-chat-primary-gradient: linear-gradient(135deg, hsl(1.8, 89.92%, 60.98%) 0%, hsl(0, 5.34%, 25.69%) 100%);
	--jse-chat-bg-glass: rgba(18, 18, 30, 0.85);
	--jse-chat-border-glass: rgba(255, 255, 255, 0.08);
	--jse-chat-text-main: hsl(220, 15%, 90%);
	--jse-chat-text-muted: hsl(220, 10%, 65%);
	--jse-chat-bubble-user: linear-gradient(135deg, hsl(1.94, 100%, 42.55%) 0%, hsl(200, 5.34%, 25.69%) 100%);
	--jse-chat-bubble-bot: rgba(255, 255, 255, 0.05);
	--jse-chat-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
	--jse-chat-radius-large: 18px;
	--jse-chat-radius-medium: 12px;
	--jse-chat-radius-bubble: 16px;
}

/* Container */
#jse-chat-widget {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 999999;
	font-family: var(--jse-chat-font);
	display: flex;
	flex-direction: column;
	align-items: flex-end;
}

/* Launcher Button */
#jse-chat-launcher {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	background: var(--jse-chat-primary-gradient);
	color: #ffffff;
	border: none;
	cursor: pointer;
	box-shadow: var(--jse-chat-shadow);
	display: flex;
	justify-content: center;
	align-items: center;
	transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
	outline: none;
	padding: 0;
	margin: 0;
}

#jse-chat-launcher:hover {
	transform: scale(1.1) rotate(5deg);
	box-shadow: 0 15px 45px rgba(255, 80, 80, 0.25);
}

#jse-chat-launcher:active {
	transform: scale(0.95);
}

#jse-chat-launcher svg {
	transition: transform 0.3s ease;
}

	/* Window — hidden by default, only shown when chat is open */
	#jse-chat-window {
		display: none;
		width: 380px;
		height: 520px;
		background: var(--jse-chat-bg-glass);
		backdrop-filter: blur(16px);
		-webkit-backdrop-filter: blur(16px);
		border: 1px solid var(--jse-chat-border-glass);
		border-radius: var(--jse-chat-radius-large);
		box-shadow: var(--jse-chat-shadow);
		margin-bottom: 20px;
		flex-direction: column;
		overflow: hidden;
		opacity: 0;
		transform: translateY(20px) scale(0.95);
		pointer-events: none;
		transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
	}

	#jse-chat-widget.jse-chat-open #jse-chat-window {
		display: flex;
		opacity: 1;
		transform: translateY(0) scale(1);
		pointer-events: auto;
	}

/* Header */
.jse-chat-header {
	padding: 16px 20px;
	background: rgba(255, 255, 255, 0.02);
	border-bottom: 1px solid var(--jse-chat-border-glass);
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.jse-chat-header-info {
	display: flex;
	flex-direction: column;
}

.jse-chat-header-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--jse-chat-text-main);
	letter-spacing: 0.5px;
}

.jse-chat-header-status {
	font-size: 11px;
	color: hsl(145, 80%, 45%);
	display: flex;
	align-items: center;
	gap: 6px;
	margin-top: 2px;
}

.jse-chat-header-status::before {
	content: '';
	display: inline-block;
	width: 6px;
	height: 6px;
	background-color: currentColor;
	border-radius: 50%;
	box-shadow: 0 0 8px currentColor;
}

#jse-chat-clear {
	background: transparent;
	border: none;
	color: var(--jse-chat-text-muted);
	cursor: pointer;
	padding: 6px;
	border-radius: 50%;
	transition: background-color 0.2s ease, color 0.2s ease;
	display: flex;
	justify-content: center;
	align-items: center;
}

#jse-chat-clear:hover {
	background-color: rgba(255, 255, 255, 0.05);
	color: hsl(0, 80%, 65%);
}

/* Messages Area */
#jse-chat-messages {
	flex: 1;
	padding: 20px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 16px;
	scroll-behavior: smooth;
}

/* Scrollbar */
#jse-chat-messages::-webkit-scrollbar {
	width: 5px;
}

#jse-chat-messages::-webkit-scrollbar-track {
	background: transparent;
}

#jse-chat-messages::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.1);
	border-radius: 10px;
}

#jse-chat-messages::-webkit-scrollbar-thumb:hover {
	background: rgba(255, 255, 255, 0.2);
}

/* Bubbles */
.jse-chat-msg {
	display: flex;
	max-width: 85%;
	animation: jseChatFadeIn 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

.jse-chat-msg-user {
	align-self: flex-end;
	flex-direction: row-reverse;
}

.jse-chat-msg-bot {
	align-self: flex-start;
}

.jse-chat-bubble {
	padding: 12px 16px;
	font-size: 14px;
	line-height: 1.5;
	border-radius: var(--jse-chat-radius-bubble);
	word-break: break-word;
}

.jse-chat-msg-user .jse-chat-bubble {
	background: var(--jse-chat-bubble-user);
	color: #ffffff;
	border-bottom-right-radius: 4px;
	box-shadow: 0 4px 15px rgba(80, 80, 255, 0.2);
}

.jse-chat-msg-bot .jse-chat-bubble {
	background: var(--jse-chat-bubble-bot);
	color: var(--jse-chat-text-main);
	border-bottom-left-radius: 4px;
	border: 1px solid var(--jse-chat-border-glass);
}

/* Bubble Content Helpers */
.jse-chat-bubble p {
	margin: 0 0 12px 0;
}
.jse-chat-bubble p:last-child {
	margin-bottom: 0;
}

.jse-chat-bubble h1,
.jse-chat-bubble h2,
.jse-chat-bubble h3,
.jse-chat-bubble h4,
.jse-chat-bubble h5,
.jse-chat-bubble h6 {
	color: #ffffff;
	font-weight: 600;
	margin: 16px 0 8px 0;
	line-height: 1.3;
}
.jse-chat-bubble h1:first-child,
.jse-chat-bubble h2:first-child,
.jse-chat-bubble h3:first-child,
.jse-chat-bubble h4:first-child,
.jse-chat-bubble h5:first-child,
.jse-chat-bubble h6:first-child {
	margin-top: 0;
}
.jse-chat-bubble h1 { font-size: 1.4em; }
.jse-chat-bubble h2 { font-size: 1.3em; }
.jse-chat-bubble h3 { font-size: 1.2em; }
.jse-chat-bubble h4 { font-size: 1.15em; }
.jse-chat-bubble h5 { font-size: 1.05em; }
.jse-chat-bubble h6 { font-size: 1em; }

.jse-chat-bubble ul, .jse-chat-bubble ol {
	margin: 0 0 12px 0;
	padding-left: 20px;
}
.jse-chat-bubble ul {
	list-style-type: disc;
}
.jse-chat-bubble ol {
	list-style-type: decimal;
}
.jse-chat-bubble ul:last-child, .jse-chat-bubble ol:last-child {
	margin-bottom: 0;
}

.jse-chat-bubble li {
	margin-bottom: 6px;
}
.jse-chat-bubble li:last-child {
	margin-bottom: 0;
}

.jse-chat-bubble strong {
	color: #ffffff;
	font-weight: 600;
}

.jse-chat-bubble blockquote {
	margin: 12px 0;
	padding-left: 12px;
	border-left: 3px solid var(--jse-chat-border-glass);
	color: var(--jse-chat-text-muted);
	font-style: italic;
}

.jse-chat-bubble hr {
	border: 0;
	height: 1px;
	background: var(--jse-chat-border-glass);
	margin: 16px 0;
}

.jse-chat-bubble table {
	border-collapse: collapse;
	width: 100%;
	margin: 12px 0;
}

.jse-chat-bubble th,
.jse-chat-bubble td {
	border: 1px solid var(--jse-chat-border-glass);
	padding: 6px 10px;
	text-align: left;
	font-size: 13px;
}

.jse-chat-bubble th {
	background: rgba(255, 255, 255, 0.05);
	color: #ffffff;
	font-weight: 600;
}

.jse-chat-bubble code {
	background: rgba(0, 0, 0, 0.3);
	padding: 2px 5px;
	border-radius: 4px;
	font-family: monospace;
	font-size: 12px;
	color: hsl(45, 100%, 75%);
}

.jse-chat-bubble pre {
	background: rgba(0, 0, 0, 0.4);
	padding: 10px;
	border-radius: 6px;
	overflow-x: auto;
	margin: 8px 0;
}

.jse-chat-bubble pre code {
	background: transparent;
	padding: 0;
	color: inherit;
}

/* Typing Indicator */
.jse-chat-typing-dots {
	display: flex;
	gap: 4px;
	padding: 6px 10px;
	align-items: center;
	height: 20px;
}

.jse-chat-typing-dot {
	width: 6px;
	height: 6px;
	background-color: var(--jse-chat-text-muted);
	border-radius: 50%;
	animation: jseChatTyping 1.4s infinite ease-in-out both;
}

.jse-chat-typing-dot:nth-child(1) {
	animation-delay: -0.32s;
}

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

/* Input Area */
.jse-chat-input-area {
	padding: 16px 20px;
	border-top: 1px solid var(--jse-chat-border-glass);
	display: flex;
	gap: 12px;
	align-items: flex-end;
	background: rgba(0, 0, 0, 0.1);
}

#jse-chat-input {
	flex: 1;
	background: rgba(255, 255, 255, 0.04) !important;
	border: 1px solid var(--jse-chat-border-glass);
	border-radius: var(--jse-chat-radius-medium);
	padding: 12px;
	color: var(--jse-chat-text-main);
	font-family: var(--jse-chat-font);
	font-size: 14px;
	resize: none;
	max-height: 100px;
	outline: none;
	box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
	transition: border-color 0.2s ease, background-color 0.2s ease;
}

#jse-chat-input:focus {
	border-color: hsl(235, 75%, 60%);
	background-color: rgba(255, 255, 255, 0.06);
}

#jse-chat-send {
	background: var(--jse-chat-primary-gradient);
	color: #ffffff;
	border: none;
	width: 42px;
	height: 42px;
	border-radius: var(--jse-chat-radius-medium);
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
	flex-shrink: 0;
	box-shadow: 0 4px 10px rgba(80, 80, 255, 0.25);
  padding: unset;
}

#jse-chat-send:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 15px rgba(80, 80, 255, 0.35);
}

#jse-chat-send:active {
	transform: translateY(0);
}

#jse-chat-send svg {
	margin-left: 2px;
}

/* Animations */
@keyframes jseChatFadeIn {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

@keyframes jseChatTyping {
	0%, 80%, 100% {
		transform: scale(0);
		opacity: 0.3;
	}
	40% {
		transform: scale(1);
		opacity: 1;
	}
}

/* Responsive */
/* Header Actions styling */
.jse-chat-header-actions {
	display: flex;
	align-items: center;
	gap: 8px;
}

#jse-chat-toggle-size {
	background: transparent;
	border: none;
	color: var(--jse-chat-text-muted);
	cursor: pointer;
	padding: 6px;
	border-radius: 50%;
	transition: background-color 0.2s ease, color 0.2s ease;
	display: flex;
	justify-content: center;
	align-items: center;
}

#jse-chat-toggle-size:hover {
	background-color: rgba(255, 255, 255, 0.05);
	color: var(--jse-chat-text-main);
}

/* Link Preview Card */
.jse-link-preview-card {
	align-self: flex-start;
	width: 100%;
	max-width: 320px;
	background: rgba(255, 255, 255, 0.03);
	border: 1px solid var(--jse-chat-border-glass);
	border-radius: var(--jse-chat-radius-medium);
	margin-top: -8px;
	margin-bottom: 8px;
	overflow: hidden;
	transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
	animation: jseChatFadeIn 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

.jse-link-preview-card:hover {
	background: rgba(255, 255, 255, 0.07);
	transform: translateY(-2px);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.jse-link-preview-link {
	display: flex;
	text-decoration: none !important;
	color: inherit !important;
	width: 100%;
}

.jse-link-preview-image {
	width: 90px;
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	flex-shrink: 0;
	border-right: 1px solid var(--jse-chat-border-glass);
}

.jse-link-preview-content {
	padding: 10px 12px;
	display: flex;
	flex-direction: column;
	gap: 4px;
	flex: 1;
	min-width: 0; /* Ensures text ellipsis works */
}

.jse-link-preview-title {
	font-size: 13px;
	font-weight: 600;
	color: var(--jse-chat-text-main);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.jse-link-preview-desc {
	font-size: 11px;
	color: var(--jse-chat-text-muted);
	margin: 0 !important;
	line-height: 1.4;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}

.jse-link-preview-domain {
	font-size: 9px;
	color: var(--jse-chat-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.5px;
	margin-top: 2px;
}

/* Shimmer Loading State */
.jse-link-preview-loading {
	height: 68px;
	background: rgba(255, 255, 255, 0.01);
}

.jse-link-preview-shimmer {
	width: 100%;
	height: 100%;
	background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
	background-size: 200% 100%;
	animation: jseShimmer 1.5s infinite;
}

@keyframes jseShimmer {
	0% { background-position: 200% 0; }
	100% { background-position: -200% 0; }
}

/* Drawer Mode Layout Overrides */
#jse-chat-widget.jse-chat-open.jse-chat-drawer {
	top: 0;
	bottom: 0;
	right: 0;
	height: 100vh;
	width: 450px;
	bottom: 0 !important;
}

.jse-chat-open.jse-chat-drawer #jse-chat-window {
	width: 100%;
	height: 100%;
	border-radius: 0;
	margin-bottom: 0;
	border-top: none;
	border-right: none;
	border-bottom: none;
}

/* Position launcher outside drawer on desktop */
@media (min-width: 481px) {
	#jse-chat-widget.jse-chat-open.jse-chat-drawer #jse-chat-launcher {
		position: absolute;
		left: -76px;
		top: 24px;
		bottom: auto;
		right: auto;
		z-index: 1000001;
	}
}

/* Responsive */
@media (max-width: 480px) {
	#jse-chat-widget {
		bottom: 12px;
		right: 12px;
		left: 12px;
	}

	#jse-chat-window {
		width: 100%;
		height: calc(100vh - 110px);
		max-height: 600px;
	}

	#jse-chat-launcher {
		width: 54px;
		height: 54px;
	}

	/* Drawer takes full width on small screens */
	#jse-chat-widget.jse-chat-open.jse-chat-drawer {
		left: 0;
		width: 100%;
	}

	/* Position close button inside header top-left on mobile */
	#jse-chat-widget.jse-chat-open.jse-chat-drawer #jse-chat-launcher {
		position: absolute;
		left: 16px;
		top: 16px;
		bottom: auto;
		right: auto;
		width: 38px;
		height: 38px;
		z-index: 1000001;
		background: rgba(255, 255, 255, 0.08);
		border: 1px solid var(--jse-chat-border-glass);
	}

	#jse-chat-widget.jse-chat-open.jse-chat-drawer #jse-chat-launcher svg {
		width: 20px;
		height: 20px;
	}

	#jse-chat-widget.jse-chat-open.jse-chat-drawer .jse-chat-header-info {
		margin-left: 48px;
	}
}

/* Mic and Speak Buttons */
.jse-chat-mic-btn {
	background: rgba(255, 255, 255, 0.06);
	color: var(--jse-chat-text-main);
	border: 1px solid var(--jse-chat-border-glass);
	width: 42px;
	height: 42px;
	border-radius: var(--jse-chat-radius-medium);
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
	transition: background-color 0.2s ease, transform 0.2s ease;
	flex-shrink: 0;
	padding: 0;
	margin: 0;
}

.jse-chat-mic-btn:hover {
	background: rgba(255, 255, 255, 0.1);
	transform: translateY(-2px);
}

.jse-chat-mic-btn.jse-chat-mic-recording {
	background: #d63638 !important;
	color: #ffffff !important;
	animation: jseChatPulse 1.5s infinite;
}

.jse-chat-speak-btn {
	height: fit-content;
	background: transparent;
	border: none;
	color: rgba(255, 255, 255, 0.4);
	cursor: pointer;
	padding: 4px;
	margin-left: 8px;
	border-radius: 50%;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	vertical-align: middle;
	transition: color 0.2s ease, background-color 0.2s ease;
}

.jse-chat-speak-btn:hover {
	color: var(--jse-chat-text-main);
	background-color: rgba(255, 255, 255, 0.1);
}

.jse-chat-speak-btn.jse-chat-speaking {
	color: #50c8ff !important;
	animation: jseChatPulse 1.5s infinite;
}

@keyframes jseChatPulse {
	0% {
		opacity: 1;
	}
	50% {
		opacity: 0.6;
	}
	100% {
		opacity: 1;
	}
}

/* System Notices */
.jse-chat-msg-system {
	align-self: center !important;
	margin: 8px 0;
	width: 100%;
	justify-content: center;
	max-width: 100% !important;
}

.jse-chat-system-notice {
	background: rgba(214, 54, 56, 0.1);
	border: 1px solid rgba(214, 54, 56, 0.25);
	color: #ff9999;
	padding: 8px 14px;
	border-radius: var(--jse-chat-radius-medium);
	font-size: 12px;
	text-align: center;
	max-width: 85%;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	animation: jseChatFadeIn 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

/* Speed Button */
.jse-chat-speed-btn {
	background: rgba(255, 255, 255, 0.08);
	color: var(--jse-chat-text-main);
	border: 1px solid var(--jse-chat-border-glass);
	padding: 2px 6px;
	font-size: 11px;
	border-radius: 4px;
	cursor: pointer;
	font-weight: 600;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	height: 24px;
	transition: background-color 0.2s ease, border-color 0.2s ease;
	user-select: none;
}

.jse-chat-speed-btn:hover {
	background: rgba(255, 255, 255, 0.15);
	border-color: rgba(255, 255, 255, 0.3);
}

.jse-chat-speed-btn:active {
	background: rgba(255, 255, 255, 0.2);
}
