/**
 * PEWIK AI Chatbot - Bright & Accessible Design
 * Kolor przewodni: #2a3342 (ciemny granatowy)
 * Zaprojektowane z myślą o dostępności (WCAG 2.1 AA)
 */

/* ===========================================
   Główny kontener
   =========================================== */
#pewik-chatbot-container {
	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 9999;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ===========================================
   Przycisk otwierania chatbota
   =========================================== */
#pewik-chatbot-button {
	width: 64px;
	height: 64px;
	border-radius: 50%;
	background: #2a3342;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(42, 51, 66, 0.35), 0 2px 8px rgba(0, 0, 0, 0.1);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	border: 3px solid #ffffff;
	position: relative;
	overflow: hidden;
	z-index: 9999;
}

#pewik-chatbot-button::before {
	content: '';
	position: absolute;
	width: 100%;
	height: 100%;
	background: #3d4a5c;
	opacity: 0;
	transition: opacity 0.3s;
}

#pewik-chatbot-button:hover {
	transform: scale(1.08);
	box-shadow: 0 12px 32px rgba(42, 51, 66, 0.45), 0 4px 12px rgba(0, 0, 0, 0.15);
}

#pewik-chatbot-button:hover::before {
	opacity: 1;
}

#pewik-chatbot-button svg {
	position: relative;
	z-index: 1;
	filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

#pewik-chatbot-button.active {
	transform: scale(0.92);
}

/* ===========================================
   Dymek z nazwą chatbota
   =========================================== */
#pewik-chatbot-label {
	position: absolute;
	right: 35px;
	bottom: 34px;
	height: 59px;
	width: 120px;

	/* Zmiana 1: Używamy gradientu, aby wyciąć róg */
	/* circle at 100% 100% oznacza środek koła w prawym dolnym rogu */
	/* transparent 22px to promień wycięcia */
	background: radial-gradient(circle at 100% 100%, transparent 35px, #ffffff 35.5px);

	padding: 0 24px;

	/* Zmiana 2: Prawy dolny róg ustawiamy na 0, reszta zaokrąglona */
	border-radius: 22px 22px 0 22px;

	/* Zmiana 3: box-shadow nie zadziała na wycięciu, używamy drop-shadow */
	/* Łączymy dwa cienie w jeden filtr */
	filter: drop-shadow(0 4px 20px rgba(0, 0, 0, 0.12)) drop-shadow(0 2px 8px rgba(0, 0, 0, 0.08));

	font-size: 15px;
	font-weight: 600;
	color: #2a3342;
	white-space: nowrap;
	display: flex;
	align-items: center;
	animation: labelAppear 0.4s cubic-bezier(0.4, 0, 0.2, 1);
	z-index: 9998;
}


@keyframes labelAppear {
	from {
		opacity: 0;
		transform: translateX(10px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

/* Animacja pulsowania */
@keyframes pulse {
	0%,
	100% {
		transform: scale(1);
		box-shadow: 0 8px 24px rgba(42, 51, 66, 0.35), 0 2px 8px rgba(0, 0, 0, 0.1);
	}
	50% {
		transform: scale(1.05);
		box-shadow: 0 12px 32px rgba(42, 51, 66, 0.5), 0 4px 12px rgba(0, 0, 0, 0.15);
	}
}

#pewik-chatbot-button.pulse-animation {
	animation: pulse 2.5s infinite;
}

/* ===========================================
   Okno chatbota
   =========================================== */
#pewik-chatbot-window {
	position: absolute;
	bottom: 88px;
	right: 0;
	width: 420px;
	max-width: calc(100vw - 48px);
	height: 640px;
	max-height: calc(100vh - 140px);
	background: #ffffff;
	border-radius: 24px;
	box-shadow: 0 24px 80px rgba(0, 0, 0, 0.12), 0 8px 32px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
	border: 1px solid rgba(42, 51, 66, 0.15);
}

@keyframes slideUp {
	from {
		opacity: 0;
		transform: translateY(30px) scale(0.95);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Animacja pulsującej poświaty dla #ai */
@keyframes glowPulse {
	0%,
	100% {
		box-shadow: 0 24px 80px rgba(0, 0, 0, 0.12), 0 8px 32px rgba(0, 0, 0, 0.08), 0 0 20px rgba(42, 51, 66, 0.4),
			0 0 40px rgba(42, 51, 66, 0.2);
	}
	50% {
		box-shadow: 0 24px 80px rgba(0, 0, 0, 0.12), 0 8px 32px rgba(0, 0, 0, 0.08), 0 0 40px rgba(42, 51, 66, 0.6),
			0 0 80px rgba(42, 51, 66, 0.4), 0 0 120px rgba(42, 51, 66, 0.2);
	}
}

#pewik-chatbot-window.glow-attention {
	animation: glowPulse 2s ease-in-out infinite;
	border: 2px solid rgba(42, 51, 66, 0.5);
}

#pewik-chatbot-window.glow-attention #pewik-chatbot-header {
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08), inset 0 -2px 20px rgba(255, 255, 255, 0.1);
}

/* ===========================================
   Nagłówek chatbota - #2a3342
   =========================================== */
#pewik-chatbot-header {
	background: #2a3342;
	color: white;
	padding: 24px 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

#pewik-chatbot-header h3 {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
	letter-spacing: -0.3px;
	color: #ffffff;
	text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.chatbot-header-title {
	display: flex;
	align-items: center;
	gap: 8px;
}

.chatbot-info-icon {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	cursor: help;
	color: rgba(255, 255, 255, 0.7);
	transition: color 0.2s ease;
}

.chatbot-info-icon:hover {
	color: #ffffff;
}

.chatbot-info-icon svg {
	width: 18px;
	height: 18px;
}

.chatbot-tooltip {
	position: absolute;
	left: 50%;
	top: calc(100% + 10px);
	transform: translateX(-50%);
	background: #1a232f;
	color: #ffffff;
	padding: 12px 14px;
	border-radius: 10px;
	font-size: 12px;
	font-weight: 400;
	line-height: 1.5;
	width: 240px;
	text-align: left;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.2s ease, visibility 0.2s ease;
	z-index: 10000;
	pointer-events: none;
}

.chatbot-tooltip::before {
	content: '';
	position: absolute;
	bottom: 100%;
	left: 50%;
	transform: translateX(-50%);
	border: 6px solid transparent;
	border-bottom-color: #1a232f;
}

.chatbot-info-icon:hover .chatbot-tooltip {
	opacity: 1;
	visibility: visible;
}

.chatbot-header-actions {
	display: flex;
	gap: 8px;
	align-items: center;
}

#pewik-chatbot-reset,
#pewik-chatbot-close {
	background: rgba(255, 255, 255, 0.15);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 2px solid rgba(255, 255, 255, 0.2);
	color: white;
	cursor: pointer;
	padding: 0;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	line-height: 1;
	flex-shrink: 0;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#pewik-chatbot-reset svg,
#pewik-chatbot-close svg {
	width: 20px;
	height: 20px;
	stroke-width: 2.5;
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#pewik-chatbot-reset:hover,
#pewik-chatbot-close:hover {
	background: rgba(255, 255, 255, 0.3);
	border-color: rgba(255, 255, 255, 0.4);
	transform: scale(1.1);
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#pewik-chatbot-reset:active,
#pewik-chatbot-close:active {
	transform: scale(0.95);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

#pewik-chatbot-reset:hover svg {
	transform: rotate(-360deg);
}

#pewik-chatbot-close:hover svg {
	transform: rotate(90deg);
}

/* ===========================================
   Obszar wiadomości
   =========================================== */
#pewik-chatbot-messages {
	flex: 1;
	overflow-y: auto;
	padding: 24px;
	background: linear-gradient(to bottom, #f8fafb 0%, #ffffff 100%);
	scroll-behavior: smooth;
}

/* Scrollbar */
#pewik-chatbot-messages::-webkit-scrollbar {
	width: 8px;
}

#pewik-chatbot-messages::-webkit-scrollbar-track {
	background: rgba(42, 51, 66, 0.05);
	border-radius: 4px;
}

#pewik-chatbot-messages::-webkit-scrollbar-thumb {
	background: rgba(42, 51, 66, 0.4);
	border-radius: 4px;
	transition: background 0.2s;
}

#pewik-chatbot-messages::-webkit-scrollbar-thumb:hover {
	background: rgba(42, 51, 66, 0.6);
}

/* ===========================================
   Wiadomości
   =========================================== */
.message {
	margin-bottom: 18px;
	padding: 14px 18px;
	border-radius: 18px;
	max-width: 85%;
	word-wrap: break-word;
	line-height: 1.6;
	position: relative;
	animation: fadeInSlide 0.3s ease-out;
	font-size: 15px;
}

@keyframes fadeInSlide {
	from {
		opacity: 0;
		transform: translateY(12px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Default link styles for user messages */
.user-message a {
	color: #2a3342;
	text-decoration: underline;
	font-weight: 600;
	text-underline-offset: 2px;
}

.user-message a:hover {
	color: #1a232f;
	text-decoration-thickness: 2px;
}

/* Pastel link styles for bot messages */
.bot-message a {
	color: #a78bfa;
	text-decoration: underline;
	font-weight: 600;
	text-underline-offset: 2px;
	transition: all 0.2s ease;
}

.bot-message a:visited {
	color: #a78bfa;
}

.bot-message a:hover {
	color: #8b5cf6;
	text-decoration-thickness: 2px;
}

.message code {
	background: rgba(42, 51, 66, 0.08);
	padding: 3px 8px;
	border-radius: 6px;
	font-size: 0.92em;
	font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
	color: #2a3342;
	border: 1px solid rgba(42, 51, 66, 0.15);
}

.message strong {
	font-weight: 700;
	color: inherit;
}

/* Wiadomość użytkownika - #2a3342 */
.user-message {
	background: #2a3342;
	color: #ffffff;
	margin-left: auto;
	border-bottom-right-radius: 6px;
	box-shadow: 0 4px 12px rgba(42, 51, 66, 0.25);
	font-weight: 500;
}

/* Wiadomość bota */
.bot-message {
	background: #ffffff;
	color: #1a202c;
	border-bottom-left-radius: 6px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
	border: 2px solid rgba(42, 51, 66, 0.12);
}

/* Wiadomość powitalna */
.initial-message {
	background: linear-gradient(135deg, #e8edf3 0%, #dfe5ed 100%);
	border: 2px solid #2a3342;
	font-weight: 500;
	color: #1a202c;
	box-shadow: 0 4px 12px rgba(42, 51, 66, 0.15);
}

/* Wiadomość błędu */
.error-message {
	background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
	border: 2px solid #f87171;
	color: #991b1b;
	font-weight: 500;
}

/* ===========================================
   Wskaźnik pisania
   =========================================== */
.typing-indicator {
	background: #ffffff !important;
	border: 2px solid rgba(42, 51, 66, 0.12) !important;
	opacity: 1 !important;
	color: #64748b;
	font-weight: 500;
}

.typing-dots {
	display: inline-flex;
	gap: 5px;
	align-items: center;
}

.typing-dots span {
	animation: typingDot 1.4s infinite;
	font-size: 28px;
	line-height: 0;
	color: #2a3342;
}

.typing-dots span:nth-child(2) {
	animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes typingDot {
	0%,
	60%,
	100% {
		opacity: 0.25;
		transform: translateY(0);
	}
	30% {
		opacity: 1;
		transform: translateY(-10px);
	}
}

/* ===========================================
   Cytowania
   =========================================== */
.citation-indicator {
	margin-top: 10px;
	padding-top: 10px;
	border-top: 2px solid rgba(42, 51, 66, 0.15);
	font-size: 13px;
	color: #2a3342;
	font-weight: 600;
}

/* ===========================================
   Przycisk retry
   =========================================== */
.retry-button {
	margin: 12px 0;
	padding: 12px 20px;
	background: #2a3342;
	color: white;
	border: none;
	border-radius: 14px;
	cursor: pointer;
	font-size: 15px;
	font-weight: 700;
	transition: all 0.25s;
	box-shadow: 0 4px 12px rgba(42, 51, 66, 0.3);
	width: auto;
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

.retry-button:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 16px rgba(42, 51, 66, 0.4);
	background: #3d4a5c;
}

/* ===========================================
   Pole wprowadzania
   =========================================== */
#pewik-chatbot-input-container {
	padding: 20px;
	background: #ffffff;
	border-top: 2px solid rgba(42, 51, 66, 0.1);
	display: flex;
	gap: 12px;
	align-items: center;
	box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
}

#pewik-chatbot-input {
	flex: 1;
	padding: 14px 20px;
	border: 2px solid #e0e7ff;
	border-radius: 28px;
	font-size: 15px;
	outline: none;
	transition: all 0.25s;
	font-family: inherit;
	background: #f8fafb;
	color: #1a202c;
	font-weight: 500;
}

#pewik-chatbot-input::placeholder {
	color: #94a3b8;
	font-weight: 400;
}

#pewik-chatbot-input:focus {
	border-color: #2a3342;
	background: #ffffff;
	box-shadow: 0 0 0 4px rgba(42, 51, 66, 0.12);
	transform: scale(1.01);
}

#pewik-chatbot-input:disabled {
	background: #f1f5f9;
	cursor: not-allowed;
	opacity: 0.7;
}

#pewik-chatbot-send {
	background: #2a3342;
	color: white;
	border: none;
	padding: 14px;
	width: 52px;
	height: 52px;
	border-radius: 50%;
	cursor: pointer;
	transition: all 0.25s;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 12px rgba(42, 51, 66, 0.3);
}

#pewik-chatbot-send:hover:not(:disabled) {
	transform: scale(1.1) rotate(15deg);
	box-shadow: 0 6px 16px rgba(42, 51, 66, 0.4);
	background: #3d4a5c;
}

#pewik-chatbot-send:active:not(:disabled) {
	transform: scale(0.95);
}

#pewik-chatbot-send:disabled {
	opacity: 0.4;
	cursor: not-allowed;
	transform: none !important;
}

/* ========================================
   PRZYCISKI OCENY
   ======================================== */

.message-rating {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-top: 12px;
	padding-top: 10px;
	border-top: 1px solid rgba(0, 0, 0, 0.05);
	animation: fadeInRating 0.3s ease-out;
}

.rating-label {
	font-size: 12px;
	color: #666;
	margin-right: auto;
}

.rating-btn {
	background: white;
	border: 1px solid #e0e0e0;
	border-radius: 50%;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: all 0.2s;
	color: #666;
	padding: 0;
}

.rating-btn:hover:not(:disabled) {
	transform: scale(1.1);
	border-color: #2a3342;
	color: #2a3342;
	box-shadow: 0 2px 8px rgba(42, 51, 66, 0.2);
}

.rating-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.rating-btn.thumbs-up:hover:not(:disabled) {
	border-color: #46b450;
	color: #46b450;
	box-shadow: 0 2px 8px rgba(70, 180, 80, 0.2);
}

.rating-btn.thumbs-down:hover:not(:disabled) {
	border-color: #dc3232;
	color: #dc3232;
	box-shadow: 0 2px 8px rgba(220, 50, 50, 0.2);
}

.rating-success {
	color: #46b450;
	font-size: 12px;
	font-weight: 600;
}

.rating-error {
	color: #dc3232;
	font-size: 12px;
	font-weight: 600;
}

@keyframes fadeInRating {
	from {
		opacity: 0;
		transform: translateY(5px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ===========================================
   Responsywność - Mobile
   =========================================== */
@media (max-width: 768px) {
	#pewik-chatbot-container {
		bottom: 12px;
		right: 12px;
	}

	#pewik-chatbot-button {
		width: 60px;
		height: 60px;
	}

	#pewik-chatbot-window {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 84px;
		width: 100%;
		height: calc(100vh - 100px);
		max-height: none;
		max-width: none;
		border-radius: 24px 24px 0 0;
	}

	.message {
		max-width: 88%;
		font-size: 14px;
	}

	#pewik-chatbot-input {
		font-size: 16px;
	}
}

/* Bardzo małe ekrany */
@media (max-width: 380px) {
	#pewik-chatbot-header {
		padding: 18px 16px;
	}

	#pewik-chatbot-header h3 {
		font-size: 15px;
	}

	.chatbot-tooltip {
		left: 0;
		transform: translateX(0);
		width: 200px;
	}

	.chatbot-tooltip::before {
		left: 12px;
		transform: none;
	}

	.chatbot-header-actions {
		gap: 6px;
	}

	#pewik-chatbot-reset,
	#pewik-chatbot-close {
		width: 32px;
		height: 32px;
	}

	#pewik-chatbot-reset svg,
	#pewik-chatbot-close svg {
		width: 18px;
		height: 18px;
	}

	#pewik-chatbot-input {
		padding: 12px 16px;
	}

	#pewik-chatbot-send {
		width: 48px;
		height: 48px;
	}
}

/* ===========================================
   Accessibility - Wysoki kontrast
   =========================================== */
#pewik-chatbot-button:focus-visible,
#pewik-chatbot-send:focus-visible,
#pewik-chatbot-reset:focus-visible,
#pewik-chatbot-close:focus-visible,
#pewik-chatbot-input:focus-visible,
.retry-button:focus-visible {
	outline: 4px solid #2a3342;
	outline-offset: 3px;
}

@media (prefers-contrast: high) {
	.bot-message {
		border-width: 3px;
		border-color: #2a3342;
	}

	.user-message {
		background: #1a232f;
	}

	#pewik-chatbot-input {
		border-width: 3px;
	}
}

/* Redukcja ruchu */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}

/* ===========================================
   Dodatkowe ulepszenia wizualne
   =========================================== */
@keyframes messageAppear {
	from {
		opacity: 0;
		transform: translateY(15px) scale(0.97);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

.message {
	animation: messageAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bot-message:hover {
	border-color: rgba(42, 51, 66, 0.25);
	box-shadow: 0 4px 12px rgba(42, 51, 66, 0.1);
}

.message a {
	display: inline-flex;
	align-items: center;
	gap: 4px;
}

.message a[target='_blank']::after {
	content: '↗';
	font-size: 0.85em;
	opacity: 0.7;
}

/* =====================================================
   DISCLAIMER POD INPUTEM
   ===================================================== */
#pewik-chatbot-disclaimer {
	padding: 8px 16px 12px 16px;
	font-size: 11px;
	color: #6b7280;
	text-align: center;
	line-height: 1.4;
	background: #f9fafb;
	border-top: 1px solid #e5e7eb;
	border-radius: 0 0 16px 16px;
}

#pewik-chatbot-disclaimer a {
	color: #0066cc;
	text-decoration: none;
	font-weight: 500;
}

#pewik-chatbot-disclaimer a:hover {
	text-decoration: underline;
}
