/**
 * Glossary Tooltips — стили терминов и popup.
 * Красочный дизайн, подсветка кода, ссылки на другие термины.
 */

/* Термин в тексте — подчёркнут пунктиром, курсор pointer */
.entry-content .glossary-term,
.dekanpro-entry .glossary-term {
	cursor: pointer;
	text-decoration: underline;
	text-decoration-style: dotted;
	text-underline-offset: 2px;
	color: inherit;
	transition: color 0.2s, background-color 0.2s;
}

.entry-content .glossary-term:hover,
.dekanpro-entry .glossary-term:hover {
	color: var(--dekanpro-primary, #6366f1);
}

.entry-content .glossary-term:focus,
.dekanpro-entry .glossary-term:focus {
	outline: 2px solid var(--dekanpro-primary, #6366f1);
	outline-offset: 2px;
}

.entry-content .glossary-term-active,
.dekanpro-entry .glossary-term-active {
	color: var(--dekanpro-primary, #6366f1);
	background-color: rgba(99, 102, 241, 0.12);
}

/* ===== Popup — красочный дизайн ===== */
.glossary-popup {
	position: fixed;
	z-index: 999999;
	max-width: 420px;
	max-height: 85vh;
	overflow-y: auto;
	padding: 1.5rem 1.75rem;
	background: linear-gradient(145deg, #ffffff 0%, #f8fafc 50%, #f1f5f9 100%);
	border-radius: 1rem;
	box-shadow:
		0 25px 50px -12px rgba(0, 0, 0, 0.2),
		0 0 0 1px rgba(99, 102, 241, 0.08),
		inset 0 1px 0 rgba(255, 255, 255, 0.9);
	font-size: 16px;
	line-height: 1.6;
	animation: glossary-popup-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes glossary-popup-in {
	from {
		opacity: 0;
		transform: translateY(-10px) scale(0.97);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Кнопка закрытия — переопределяем стили темы (button с градиентом) */
.glossary-popup .glossary-popup-close::before {
	content: none !important;
}

.glossary-popup .glossary-popup-close {
	position: absolute;
	top: 0.75rem;
	right: 0.75rem;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0 !important;
	border: 1px solid rgba(100, 116, 139, 0.2) !important;
	border-radius: 0.5rem !important;
	background: #fff !important;
	background-image: none !important;
	color: #64748b !important;
	font-weight: inherit !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	cursor: pointer;
	transition: color 0.2s, background 0.2s, border-color 0.2s, transform 0.15s !important;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

.glossary-popup .glossary-popup-close svg {
	display: block;
	flex-shrink: 0;
}

.glossary-popup .glossary-popup-close:hover {
	color: #dc2626 !important;
	background: #fef2f2 !important;
	background-image: none !important;
	border-color: rgba(220, 38, 38, 0.3) !important;
	transform: none !important;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
}

.glossary-popup .glossary-popup-close:focus {
	outline: 2px solid var(--dekanpro-primary, #6366f1);
	outline-offset: 2px;
}

.glossary-popup .glossary-popup-close:active {
	transform: scale(0.95);
}

/* Заголовок термина */
.glossary-popup-term {
	margin: 0 2rem 1rem 0;
	padding: 0.5rem 0.75rem;
	font-size: 1.15rem;
	font-weight: 700;
	color: #1e293b;
	background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(124, 58, 237, 0.1));
	border-left: 4px solid #6366f1;
	border-radius: 0 0.5rem 0.5rem 0;
}

/* Секции */
.glossary-popup-section {
	margin-bottom: 1.25rem;
}

.glossary-popup-section:last-child {
	margin-bottom: 0;
}

/* Метки секций — цветные */
.glossary-popup-label {
	margin: 0 0 0.5rem;
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	opacity: 0.9;
}

.glossary-popup-label-def {
	color: #6366f1;
}

.glossary-popup-label-examples {
	color: #059669;
}

.glossary-popup-label-cases {
	color: #d97706;
}

/* Текст и параграфы */
.glossary-popup-text {
	margin: 0 0 0.5rem;
	color: #334155;
}

.glossary-popup-text:last-child {
	margin-bottom: 0;
}

/* Ссылки на другие термины — подсветка */
.glossary-popup-ref {
	display: inline;
	padding: 0.1em 0.35em;
	margin: 0 0.05em;
	background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(124, 58, 237, 0.15));
	color: #4f46e5;
	border-radius: 0.35rem;
	cursor: pointer;
	text-decoration: underline;
	text-decoration-style: dotted;
	text-underline-offset: 2px;
	transition: background 0.15s, color 0.15s;
}

.glossary-popup-ref:hover {
	background: linear-gradient(135deg, rgba(99, 102, 241, 0.35), rgba(124, 58, 237, 0.3));
	color: #4338ca;
}

/* Блоки кода в попапе — как в статьях */
.glossary-popup-pre {
	background: linear-gradient(135deg, #1a1b26 0%, #24283b 100%) !important;
	border-radius: 0.75rem !important;
	padding: 1rem 1.25rem !important;
	margin: 0.5rem 0 !important;
	overflow-x: auto;
	position: relative;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
	border: 1px solid rgba(255, 255, 255, 0.06);
	font-size: 12px !important;
	line-height: 1.5 !important;
}

.glossary-popup-pre::before {
	content: '';
	position: absolute;
	top: 3px;
  	left: 6px;
	width: 8px;
	height: 8px;
	background: #ff5f56;
	border-radius: 50%;
	box-shadow: 14px 0 0 #ffbd2e, 28px 0 0 #27ca40;
}

.glossary-popup-pre code {
	background: transparent !important;
	color: #c9d1d9 !important;
	font-family: 'SF Mono', 'Monaco', 'Consolas', 'Liberation Mono', monospace !important;
	font-size: inherit !important;
	white-space: pre !important;
}

/* Списки */
.glossary-popup-section ul {
	margin: 0.25rem 0 0;
	padding-left: 1.25rem;
}

.glossary-popup-section li {
	margin-bottom: 0.4rem;
	color: #475569;
}

.glossary-popup-section li:last-child {
	margin-bottom: 0;
}

/* Мобильная версия — окно на всю ширину экрана */
@media screen and (max-width: 768px) {
	.glossary-popup {
		left: 0.5rem !important;
		right: 0.5rem !important;
		width: auto !important;
		max-width: none !important;
	}
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
	body.dekanpro-dark-mode .glossary-popup,
	.dark-mode .glossary-popup {
		background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
		box-shadow:
			0 25px 50px -12px rgba(0, 0, 0, 0.5),
			0 0 0 1px rgba(148, 163, 184, 0.1);
	}

	body.dekanpro-dark-mode .glossary-popup-term,
	.dark-mode .glossary-popup .glossary-popup-term {
		color: #f1f5f9;
		background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(124, 58, 237, 0.2));
		border-left-color: #818cf8;
	}

	body.dekanpro-dark-mode .glossary-popup .glossary-popup-close,
	.dark-mode .glossary-popup .glossary-popup-close {
		background: rgba(30, 41, 59, 0.9) !important;
		background-image: none !important;
		border-color: rgba(148, 163, 184, 0.25) !important;
		color: #94a3b8 !important;
	}

	body.dekanpro-dark-mode .glossary-popup .glossary-popup-close:hover,
	.dark-mode .glossary-popup .glossary-popup-close:hover {
		background: rgba(220, 38, 38, 0.25) !important;
		background-image: none !important;
		border-color: rgba(248, 113, 113, 0.4) !important;
		color: #f87171 !important;
	}

	body.dekanpro-dark-mode .glossary-popup-label-def,
	.dark-mode .glossary-popup .glossary-popup-label-def {
		color: #818cf8;
	}

	body.dekanpro-dark-mode .glossary-popup-label-examples,
	.dark-mode .glossary-popup .glossary-popup-label-examples {
		color: #34d399;
	}

	body.dekanpro-dark-mode .glossary-popup-label-cases,
	.dark-mode .glossary-popup .glossary-popup-label-cases {
		color: #fbbf24;
	}

	body.dekanpro-dark-mode .glossary-popup-text,
	body.dekanpro-dark-mode .glossary-popup-section li,
	.dark-mode .glossary-popup .glossary-popup-text,
	.dark-mode .glossary-popup .glossary-popup-section li {
		color: #cbd5e1;
	}

	body.dekanpro-dark-mode .glossary-popup-ref,
	.dark-mode .glossary-popup .glossary-popup-ref {
		background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(124, 58, 237, 0.25));
		color: #a5b4fc;
	}

	body.dekanpro-dark-mode .glossary-popup-ref:hover,
	.dark-mode .glossary-popup .glossary-popup-ref:hover {
		background: linear-gradient(135deg, rgba(99, 102, 241, 0.45), rgba(124, 58, 237, 0.4));
		color: #c7d2fe;
	}
}
