/* ==========================================================================
   PK Notifications — Enhanced Comment Threads (Hybrid Mode: Dark & Light)
   Compatible with WPCommunity, PK Notifications (.pk-cm-*), pk-comment-edit
   ========================================================================== */

/* Compact Nesting & Safe Depth Cap (matches site rules & works standalone) */
body.pk-threads-enabled .comment-list .comment > .comment {
	padding-left: 24px;
}

body.pk-threads-enabled .comment-list .comment > .comment > .comment > .comment > .comment > .comment .comment {
	padding-left: 0;
}

body.pk-threads-enabled .comment-list .comment > .comment > .comment > .comment > .comment > .comment .comment > .comment-branch {
	display: none;
}

/* Hide vertical branch lines by default so they don't distract while reading */
body.pk-threads-enabled:not(.pk-threads-show-lines) .comment-list .comment-branch {
	display: none;
}

/* Optional Interactive Tree Lines (only when enabled in settings) */
body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch {
	width: 20px;
	border-left: none;
	opacity: 1;
	cursor: pointer;
	transition: none;
}

body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::before {
	content: "";
	position: absolute;
	top: 0;
	bottom: 0;
	left: 7px;
	width: 2px;
	border-radius: 2px;
	background-color: rgba(255, 255, 255, .14);
	transition: background-color .16s ease;
}

body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::after {
	content: "";
	position: absolute;
	top: 16px;
	left: 9px;
	width: 9px;
	height: 2px;
	border-radius: 0 2px 2px 0;
	background-color: rgba(255, 255, 255, .14);
	pointer-events: none;
	transition: background-color .16s ease, top .2s ease;
}

body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment.pk-cm-is-unread > .comment-branch::after {
	top: 28px;
}

body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch:hover::before,
body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch:hover::after {
	background-color: var(--wpsc-primary-color, #3276ff);
}

html[theme="light"] body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::before,
html[theme="light"] body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::after {
	background-color: rgba(17, 31, 58, .13);
}

html[theme="light"] body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch:hover::before,
html[theme="light"] body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch:hover::after {
	background-color: var(--wpsc-primary-color, #3276ff);
}

/* Subtle separation for flattened deep replies (never touches .comment-body border-left) */
body.pk-threads-enabled .comment.pk-th-is-deep {
	margin-top: 20px;
	padding-top: 14px;
	border-top: 1px solid rgba(255, 255, 255, .07);
}

html[theme="light"] body.pk-threads-enabled .comment.pk-th-is-deep {
	border-top-color: rgba(17, 31, 58, .08);
}

/* Temporarily reveal a filtered-out parent comment when jumping to it */
.comment-list.pk-cm-filter-unread .comment.pk-th-force-visible {
	display: block !important;
}

.comment-list.pk-cm-filter-unread .comment.pk-th-force-visible:not(.pk-cm-is-unread) > .comment-body {
	opacity: .85;
}

/* Reply-To Context Block (placed cleanly between .comment-header and .comment-content) */
.pk-th-reply-wrap {
	margin: 8px 0 2px;
	min-width: 0;
}

.pk-th-reply-link {
	text-decoration: none !important;
	color: var(--wpsc-text-light-color, rgba(222, 222, 222, .72));
	font-size: 12.5px;
	line-height: 1.4;
	cursor: pointer;
	transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

.pk-th-reply-link:focus-visible {
	outline: 2px solid var(--wpsc-primary-color, #3276ff);
	outline-offset: 2px;
}

.pk-th-reply-link__arrow {
	flex-shrink: 0;
	color: var(--wpsc-link-color, #8ac0f5);
	font-size: 13px;
	line-height: 1;
}

html[theme="light"] .pk-th-reply-link__arrow {
	color: #1b55f2;
}

.pk-th-reply-link__author {
	color: var(--wpsc-link-color, #8ac0f5);
	font-weight: 600;
}

html[theme="light"] .pk-th-reply-link__author {
	color: #1b55f2;
}

/* Mode 1: Compact Reply Pill (adjacent reply within indent depth) */
.pk-th-reply-link--compact {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	max-width: 100%;
	padding: 2px 9px 2px 7px;
	border-radius: 999px;
	background-color: rgba(50, 118, 255, .10);
	border: 1px solid rgba(50, 118, 255, .20);
}

.pk-th-reply-link--compact:hover {
	background-color: rgba(50, 118, 255, .20);
	border-color: rgba(50, 118, 255, .45);
	color: var(--wpsc-text-color, #e3e3e3);
}

.pk-th-reply-link--compact .pk-th-reply-link__author {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

html[theme="light"] .pk-th-reply-link--compact {
	background-color: rgba(50, 118, 255, .07);
	border-color: rgba(27, 85, 242, .20);
	color: rgba(17, 31, 58, .72);
}

html[theme="light"] .pk-th-reply-link--compact:hover {
	background-color: rgba(50, 118, 255, .14);
	border-color: rgba(27, 85, 242, .42);
	color: #111f3a;
}

/* Mode 2: Smart 1-Line Mini-Quote (detached reply or flattened deep reply) */
.pk-th-reply-link--quote {
	display: flex;
	align-items: center;
	gap: 6px;
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
	padding: 6px 10px;
	border-radius: 6px;
	border: 1px solid rgba(255, 255, 255, .08);
	border-left: 2px solid var(--wpsc-primary-color, #3276ff);
	background-color: rgba(255, 255, 255, .045);
}

.pk-th-reply-link--quote:hover {
	background-color: rgba(50, 118, 255, .13);
	border-color: rgba(50, 118, 255, .32);
	border-left-color: var(--wpsc-primary-color, #3276ff);
	color: var(--wpsc-text-color, #e3e3e3);
}

html[theme="light"] .pk-th-reply-link--quote {
	background-color: rgba(17, 31, 58, .045);
	border-color: rgba(17, 31, 58, .09);
	border-left-color: #1b55f2;
	color: rgba(17, 31, 58, .72);
}

html[theme="light"] .pk-th-reply-link--quote:hover {
	background-color: rgba(50, 118, 255, .10);
	border-color: rgba(27, 85, 242, .28);
	border-left-color: #1b55f2;
	color: #111f3a;
}

.pk-th-reply-link__line {
	min-width: 0;
	flex: 1;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
}

.pk-th-reply-link__sep {
	color: var(--wpsc-link-color, #8ac0f5);
	font-weight: 600;
}

html[theme="light"] .pk-th-reply-link__sep {
	color: #1b55f2;
}

/* Jump Target Highlight Pulse (no layout shift, compatible with .pk-cm-is-unread) */
.comment-body.pk-th-flash {
	border-radius: 8px;
	animation: pkThFlash 2s ease-out;
}

@keyframes pkThFlash {
	0% {
		box-shadow: 0 0 0 3px rgba(50, 118, 255, .60), inset 0 0 0 999px rgba(50, 118, 255, .12);
	}
	45% {
		box-shadow: 0 0 0 2px rgba(50, 118, 255, .42), inset 0 0 0 999px rgba(50, 118, 255, .08);
	}
	100% {
		box-shadow: 0 0 0 0 rgba(50, 118, 255, 0), inset 0 0 0 999px rgba(50, 118, 255, 0);
	}
}

/* Desktop Hover Preview Popover */
.pk-th-preview {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 999880;
	width: 340px;
	max-width: calc(100vw - 24px);
	padding: 10px 12px;
	border-radius: 10px;
	border: 1px solid var(--wpsc-border-color, rgba(255, 255, 255, .20));
	border-left: 3px solid var(--wpsc-primary-color, #3276ff);
	background-color: var(--wpsc-white-bg, #1b1a26);
	color: var(--wpsc-text-color, #e3e3e3);
	box-shadow: 0 12px 32px rgba(0, 0, 0, .42);
	pointer-events: none;
	opacity: 0;
	transform: translateY(4px);
	transition: opacity .14s ease, transform .14s ease;
	box-sizing: border-box;
}

.pk-th-preview.is-visible {
	opacity: 1;
	transform: translateY(0);
}

html[theme="light"] .pk-th-preview {
	background-color: var(--wpsc-white-bg, #ffffff);
	color: var(--wpsc-text-color, #111f3a);
	border-color: rgba(17, 31, 58, .16);
	border-left-color: #1b55f2;
	box-shadow: 0 10px 28px rgba(17, 31, 58, .16);
}

.pk-th-preview__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 8px;
	margin-bottom: 5px;
	font-size: 12px;
}

.pk-th-preview__author {
	font-weight: 700;
	color: var(--wpsc-text-color, #e3e3e3);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

html[theme="light"] .pk-th-preview__author {
	color: #111f3a;
}

.pk-th-preview__date {
	flex-shrink: 0;
	font-size: 11.5px;
	color: var(--wpsc-text-light-color, rgba(222, 222, 222, .62));
}

.pk-th-preview__text {
	font-size: 13px;
	line-height: 1.45;
	color: var(--wpsc-text-light-color, rgba(222, 222, 222, .85));
	display: -webkit-box;
	-webkit-line-clamp: 4;
	-webkit-box-orient: vertical;
	overflow: hidden;
	word-break: break-word;
}

html[theme="light"] .pk-th-preview__text {
	color: rgba(17, 31, 58, .80);
}

@media (hover: none) {
	.pk-th-preview {
		display: none !important;
	}
}

/* Floating "← Вернуться к ответу" Pill (avoids .pk-cm-float-nav & toasts) */
.pk-th-return {
	position: fixed;
	left: 50%;
	bottom: 20px;
	transform: translateX(-50%);
	z-index: 999860;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 6px 4px 12px;
	border-radius: 999px;
	background-color: var(--wpsc-white-bg, #1b1a26);
	color: var(--wpsc-text-color, #e3e3e3);
	border: 1px solid rgba(50, 118, 255, .45);
	box-shadow: 0 10px 28px rgba(0, 0, 0, .40);
	max-width: calc(100vw - 24px);
	white-space: nowrap;
	transition: opacity .18s ease, transform .18s ease, bottom .18s ease;
}

.pk-th-return.is-hidden {
	opacity: 0;
	pointer-events: none;
	transform: translate(-50%, 10px);
}

.pk-th-return.is-above-nav {
	bottom: 70px;
}

html[theme="light"] .pk-th-return {
	background-color: var(--wpsc-white-bg, #ffffff);
	color: #111f3a;
	box-shadow: 0 8px 24px rgba(17, 31, 58, .18);
}

.pk-th-return__btn,
.pk-th-return__btn:hover,
.pk-th-return__btn:focus,
.pk-th-return__close,
.pk-th-return__close:hover,
.pk-th-return__close:focus {
	background-image: none;
	font-family: inherit;
	box-shadow: none;
}

.pk-th-return__btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 4px 6px 4px 0;
	border: none;
	background: transparent;
	color: var(--wpsc-link-color, #8ac0f5);
	font-size: 13px;
	font-weight: 600;
	line-height: 1.3;
	cursor: pointer;
}

.pk-th-return__btn:hover,
.pk-th-return__btn:focus-visible {
	color: var(--wpsc-link-hover-color, #ffffff);
	outline: none;
}

html[theme="light"] .pk-th-return__btn {
	color: #1b55f2;
}

html[theme="light"] .pk-th-return__btn:hover,
html[theme="light"] .pk-th-return__btn:focus-visible {
	color: #123eb8;
}

.pk-th-return__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 24px;
	height: 24px;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: transparent;
	color: var(--wpsc-text-light-color, rgba(222, 222, 222, .65));
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	transition: background-color .15s ease, color .15s ease;
}

.pk-th-return__close:hover,
.pk-th-return__close:focus-visible {
	background-color: var(--wpsc-highlight-color, rgba(255, 255, 255, .12));
	color: var(--wpsc-text-color, #e3e3e3);
	outline: none;
}

html[theme="light"] .pk-th-return__close {
	color: rgba(17, 31, 58, .55);
}

html[theme="light"] .pk-th-return__close:hover {
	background-color: rgba(17, 31, 58, .08);
	color: #111f3a;
}

/* Mobile Adjustments */
@media (max-width: 767px) {
	body.pk-threads-enabled .comment-list .comment > .comment {
		padding-left: 16px;
	}

	body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch {
		width: 14px;
	}

	body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::before {
		left: 4px;
	}

	body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment-branch::after {
		left: 6px;
		top: 16px;
		width: 6px;
		height: 2px;
	}

	body.pk-threads-enabled.pk-threads-show-lines .comment-list .comment.pk-cm-is-unread > .comment-branch::after {
		top: 28px;
	}

	body.pk-threads-enabled .comment-list .comment > .comment > .comment > .comment .comment {
		padding-left: 0;
	}

	body.pk-threads-enabled .comment-list .comment > .comment > .comment > .comment .comment > .comment-branch {
		display: none;
	}

	.pk-th-reply-link {
		font-size: 12px;
	}

	.pk-th-reply-link--quote {
		padding: 5px 8px;
	}
}

@media (max-width: 768px) {
	.pk-th-return {
		bottom: 76px;
	}

	.pk-th-return.is-above-nav {
		bottom: 126px;
	}
}
