/* ===== КОММЕНТАРИИ ПОД ПОСТАМИ ===== */
.comments-section {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    margin-top: 12px;
    padding: 12px 4px 0;
    border-top: 1px solid var(--border-card, rgba(124, 92, 252, 0.22));
    overflow-x: clip;
    overflow-wrap: anywhere;
    word-wrap: break-word;
    isolation: isolate;
    contain: style;
}

.comments-wrapper {
    position: relative;
    min-width: 0;
    max-width: 100%;
}

.comments-list,
.popup-comments-list {
    min-width: 0;
    max-width: 100%;
}

.comments-preview {
    position: relative;
    overflow: hidden;
    max-height: 200px;
    transition: max-height 0.4s ease;
}

.comments-section[data-open="false"] .comments-preview:not(.expanded) {
    max-height: 0;
}

.comments-section[data-open="false"] .comments-fade {
    opacity: 0;
}

.comments-preview.expanded {
    max-height: 600px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-card, rgba(124, 92, 252, 0.22)) transparent;
}

.comments-list .comment-item,
.popup-comments-list .comment-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "author date"
        "text text";
    column-gap: 10px;
    row-gap: 2px;
    box-sizing: border-box;
    min-width: 0;
    padding: 10px 0;
    min-height: 44px;
    border-bottom: 1px solid var(--border-card, rgba(124, 92, 252, 0.22));
    overflow-wrap: anywhere;
    word-wrap: break-word;
    word-break: break-word;
}

.comments-list .comment-item:last-child,
.popup-comments-list .comment-item:last-child {
    border-bottom: none;
}

.comment-author {
    grid-area: author;
    min-width: 0;
    font-weight: 600;
    color: var(--accent-primary, #7c5cfc);
    font-size: 13px;
    line-height: 1.3;
}

.comment-author a {
    display: grid;
    align-items: center;
    box-sizing: border-box;
    max-width: 100%;
    min-width: 44px;
    min-height: 44px;
    padding: 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--accent-primary, #7c5cfc);
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.comment-author a:visited {
    color: var(--accent-primary, #7c5cfc);
}

.comment-author a:hover {
    text-decoration: underline;
}

.comment-author a:focus:not(:focus-visible) {
    outline: none;
}

.comment-author a:focus-visible {
    outline: 2px solid var(--accent-primary, #7c5cfc);
    outline-offset: 2px;
    text-decoration: none;
}

.comment-author:focus-visible {
    outline: 2px solid var(--accent-primary, #7c5cfc);
    outline-offset: 2px;
}

.comment-text {
    grid-area: text;
    color: var(--text-primary);
    font-size: 14px;
    margin: 2px 0 0;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-word;
    background: transparent;
}

.comment-sticker {
    display: block;
    width: 96px;
    height: 96px;
    max-width: 100%;
    object-fit: contain;
    object-position: center;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    outline: none;
    margin: 4px 0;
    pointer-events: none;
}

.comment-sticker:not([src]),
.comment-sticker[src=""],
.comment-sticker[src="/uploads/stickers//.webp"] {
    display: none;
}

.comment-text:has(.comment-sticker) {
    background: transparent;
    line-height: 0;
    margin: 4px 0 0;
}

[data-theme="light"] .comment-sticker,
[data-theme="light"] .comment-text:has(.comment-sticker) {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.comment-date {
    grid-area: date;
    align-self: start;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.3;
    white-space: nowrap;
}

.comment-date time {
    color: inherit;
    font-size: inherit;
}

.no-comments {
    color: var(--text-muted, #8b90a0);
    font-size: 13px;
    padding: 10px 0;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.comments-fade {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(to bottom, transparent, var(--bg-card, #161b27));
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.comments-fade.hidden {
    opacity: 0;
}

.comments-toggle-btn {
    display: block;
    width: 100%;
    padding: 6px 0;
    margin-top: 6px;
    min-height: 44px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: color 0.3s ease, background 0.3s ease;
    text-align: center;
    border-radius: 8px;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.comments-toggle-btn:hover {
    color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 8%, transparent);
}

.comments-toggle-btn:active {
    background: color-mix(in srgb, var(--accent-primary) 12%, transparent);
}

.comments-toggle-btn:focus:not(:focus-visible) {
    outline: none;
}

.comments-toggle-btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.comments-toggle-btn .icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.comments-toggle-btn .icon.rotated {
    transform: rotate(180deg);
}

/* ===== ФОРМА КОММЕНТАРИЯ ===== */
.comment-form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.comment-form input[type="text"] {
    flex: 1 1 160px;
    min-width: 0;
    padding: 8px 14px;
    min-height: 44px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 20px;
    color: var(--text-input);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.comment-form input[type="text"]:focus {
    border-color: var(--accent-primary);
}

.comment-form input[type="text"]:focus:not(:focus-visible) {
    outline: none;
}

.comment-form input[type="text"]:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.comment-form input[type="text"]::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
    font-size: 13px;
}

.comment-form button {
    padding: 6px 16px;
    min-height: 44px;
    min-width: 44px;
    flex-shrink: 0;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 20px;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    font-size: 13px;
    font-family: inherit;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.comment-form button:hover:not(:disabled) {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.comment-form button:focus:not(:focus-visible) {
    outline: none;
}

.comment-form button:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.comment-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .comment-form input[type="text"] {
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .comment-date {
        white-space: normal;
        text-align: right;
    }
}

@media (prefers-reduced-motion: reduce) {
    .comments-preview,
    .comments-fade,
    .comments-toggle-btn,
    .comments-toggle-btn .icon,
    .comment-form input[type="text"],
    .comment-form button {
        transition: none;
    }
}

@supports not (overflow-x: clip) {
    .comments-section {
        overflow-x: hidden;
    }
}

@media (forced-colors: active) {
    .comment-author a:focus-visible,
    .comments-toggle-btn:focus-visible,
    .comment-form input[type="text"]:focus-visible,
    .comment-form button:focus-visible,
    .comments-section:not(:has(.comment-form)) .comments-list:empty:focus-visible::before,
    .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus-visible::before,
    .comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error):focus-visible::before,
    .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item):focus-visible::after,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty:focus-visible::before,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error):focus-visible::before,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error):focus-visible::before {
        outline: 2px solid CanvasText;
        outline-offset: 2px;
    }

    .comment-form input[type="text"],
    .comment-form button {
        border: 1px solid ButtonText;
    }

    .comments-fade {
        background: none;
    }

    /* Пустой тред «Напишите первым»: muted var может исчезнуть на contrast canvas */
    .comments-list:empty::before,
    .popup-comments-list:empty::before,
    .no-comments:not(#photo-popup-error)::before,
    .comments-list .no-comments:not(#photo-popup-error)::before,
    .popup-comments-list .no-comments:not(#photo-popup-error)::before,
    .photo-popup-content .no-comments:not(#photo-popup-error)::before,
    .photo-popup-content .comments-section .no-comments:not(#photo-popup-error)::before {
        color: CanvasText;
        forced-color-adjust: none;
    }

    /* Гостевое «Войдите»: LinkText после CanvasText, иначе contrast снова CanvasText */
    .comments-section:not(:has(.comment-form)) .comments-list:empty::before,
    .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
    .comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error)::before,
    .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty::before,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error)::before,
    .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
        color: LinkText;
        forced-color-adjust: none;
    }

    /* guest-note «Пока нет»: CanvasText после LinkText (.comments-section без :not(guest-note)) */
    .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty::before,
    .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
    .photo-popup-content:has(.guest-note) .popup-comments-list:empty::before,
    .photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
        color: CanvasText;
        forced-color-adjust: none;
    }

    .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty:focus-visible::before,
    .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus-visible::before,
    .photo-popup-content:has(.guest-note) .popup-comments-list:empty:focus-visible::before,
    .photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error):focus-visible::before {
        outline: none;
    }

    #photo-popup-error.no-comments,
    .no-comments#photo-popup-error,
    .photo-popup-content #photo-popup-error.no-comments,
    .photo-popup-content .no-comments#photo-popup-error {
        color: CanvasText;
        forced-color-adjust: none;
    }
}

.comments-section[hidden],
.comments-wrapper[hidden],
.comment-form[hidden],
.comment-item[hidden] {
    display: none !important;
}

.comments-section[aria-busy="true"] {
    pointer-events: none;
    opacity: 0.72;
}

.comments-list .comment-item,
.popup-comments-list .comment-item {
    content-visibility: auto;
    contain-intrinsic-size: auto 44px;
}

.comments-list:empty + .comments-fade,
.comments-list:has(.no-comments) + .comments-fade {
    display: none;
}

.comment-sticker[src="undefined"],
.comment-sticker[src="null"],
.comment-sticker[src="about:blank"] {
    display: none;
}

.comment-text {
    color: var(--text-primary, #e8eefc);
}

.comment-date {
    color: var(--text-muted, #8b90a0);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.comments-preview.expanded {
    scrollbar-gutter: stable;
}

.comment-form {
    touch-action: manipulation;
}

.comment-form input[type="text"],
.comment-form button {
    box-sizing: border-box;
}

.comment-form input[type="text"] {
    background: var(--bg-input, #121826);
    border-color: var(--border-input, rgba(124, 92, 252, 0.28));
    color: var(--text-input, #e8eefc);
}

.comment-form input[type="text"]::placeholder {
    color: var(--text-muted, #8b90a0);
}

.comment-form button {
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-input, #121826);
    border-color: var(--border-input, rgba(124, 92, 252, 0.28));
    color: var(--text-muted, #8b90a0);
}

.comment-form input[type="text"]:focus,
.comment-form input[type="text"]:focus-visible,
.comment-form button:focus-visible,
.comments-toggle-btn:focus-visible,
.comment-form button:hover:not(:disabled) {
    border-color: var(--accent-primary, #7c5cfc);
}

.comment-form input[type="text"]:focus-visible,
.comment-form button:focus-visible,
.comments-toggle-btn:focus-visible {
    outline: 2px solid var(--accent-primary, #7c5cfc);
}

.comment-form input[type="text"]:invalid:not(:placeholder-shown):not(:focus) {
    border-color: #e35d6a;
}

@supports not (selector(:has(*))) {
    .comment-text .comment-sticker {
        background: transparent;
        line-height: 0;
    }
}

@supports not (color-mix(in srgb, black 8%, transparent)) {
    .comments-toggle-btn:hover {
        background: rgba(124, 92, 252, 0.08);
    }

    .comments-toggle-btn:active {
        background: rgba(124, 92, 252, 0.12);
    }
}

@media (prefers-reduced-transparency: reduce) {
    .comments-fade {
        background: var(--bg-card, #161b27);
    }
}

/* RGBA-стикер без карточки/свечения; поле комментария не уезжает под клавиатуру */
img.comment-sticker,
.popup-comments-list img.comment-sticker,
.photo-popup-content img.comment-sticker,
.comment-sticker {
    background: none;
    background-color: transparent;
    background-image: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    outline: none;
    filter: none;
    -webkit-filter: none;
    overflow: visible;
    isolation: isolate;
    mix-blend-mode: normal;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    clip-path: none;
    -webkit-clip-path: none;
    mask: none;
    -webkit-mask: none;
}

img.comment-sticker::before,
img.comment-sticker::after,
.comment-sticker::before,
.comment-sticker::after {
    content: none;
    display: none;
    background: none;
    box-shadow: none;
}

.comment-text:has(.comment-sticker),
.comment-item:has(.comment-sticker),
.popup-comments-list .comment-text:has(.comment-sticker),
.popup-comments-list .comment-item:has(.comment-sticker),
.photo-popup-content .comment-text:has(.comment-sticker),
.photo-popup-content .comment-item:has(.comment-sticker) {
    background: none;
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
    filter: none;
    overflow: visible;
}

[data-theme="light"] img.comment-sticker,
[data-theme="light"] .comment-sticker,
[data-theme="light"] .comment-text:has(.comment-sticker),
[data-theme="light"] .comment-item:has(.comment-sticker) {
    background: none;
    background-color: transparent;
    box-shadow: none;
    filter: none;
    -webkit-filter: none;
}

.comment-form {
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px), env(keyboard-inset-bottom, 0px));
}

.comment-form input[type="text"] {
    scroll-margin-bottom: max(24px, env(keyboard-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
    scroll-margin-top: 12px;
}

.comments-section:has(.comment-form:focus-within) {
    scroll-padding-bottom: max(72px, env(keyboard-inset-bottom, 0px));
}

@media (max-width: 768px) {
    .comment-form:focus-within {
        position: sticky;
        bottom: env(keyboard-inset-bottom, 0px);
        z-index: 4;
        box-sizing: border-box;
        padding-top: 8px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px), env(keyboard-inset-bottom, 0px));
        background: var(--bg-card, #161b27);
        background-clip: padding-box;
    }

    .comment-form input[type="text"]:focus {
        scroll-margin-bottom: max(64px, env(keyboard-inset-bottom, 0px));
    }
}

@media (prefers-reduced-transparency: reduce) {
    img.comment-sticker,
    .comment-sticker {
        filter: none;
        -webkit-filter: none;
        opacity: 1;
        background: transparent;
    }
}

/* Пустой тред: «Напишите первым» вместо дыры / старого «нет комментариев» */
.comments-list:empty::before,
.popup-comments-list:empty::before {
    content: "Напишите первым";
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding: 12px 0;
    color: var(--text-muted, #8b90a0);
    font-size: 13px;
    line-height: 1.45;
    font-weight: 500;
}

.no-comments,
.comments-list .no-comments,
.popup-comments-list .no-comments,
.photo-popup-content .no-comments,
.photo-popup-content .comments-section .no-comments {
    font-size: 0;
    line-height: 0;
    color: transparent;
}

.no-comments::before,
.comments-list .no-comments::before,
.popup-comments-list .no-comments::before,
.photo-popup-content .no-comments::before,
.photo-popup-content .comments-section .no-comments::before {
    content: "Напишите первым";
    font-size: 13px;
    line-height: 1.45;
    font-weight: 500;
    color: var(--text-muted, #8b90a0);
}

/* Поле комментария над нижней панелью навигатора, не под ней */
@media (max-width: 768px) {
    .comments-section {
        --comments-dock: calc(80px + env(safe-area-inset-bottom, 0px) + var(--music-player-h, 0px));
        scroll-padding-bottom: calc(var(--comments-dock) + 8px);
    }

    .comments-section[data-open="true"] > .comment-form,
    .comments-section:focus-within > .comment-form {
        position: sticky;
        bottom: max(var(--comments-dock), env(keyboard-inset-bottom, 0px));
        z-index: 8;
        box-sizing: border-box;
        margin-bottom: 0;
        padding-top: 8px;
        padding-bottom: 8px;
        background: var(--bg-card, #161b27);
        background-clip: padding-box;
        border-top: 1px solid var(--border-card, rgba(124, 92, 252, 0.22));
    }

    .comments-section[data-open="true"] > .comment-form input[type="text"],
    .comments-section:focus-within > .comment-form input[type="text"] {
        scroll-margin-bottom: calc(var(--comments-dock) + 8px);
    }

    /* Раскрытый тред не уезжает под навигатор: скролл внутри, поле остаётся в кадре */
    .comments-section[data-open="true"] .comments-preview.expanded,
    .comments-section:focus-within .comments-preview.expanded {
        max-height: min(600px, calc(100dvh - var(--comments-dock, 80px) - 168px));
        overscroll-behavior: contain;
    }

    .comments-section[data-open="true"],
    .comments-section:focus-within {
        scroll-margin-bottom: calc(var(--comments-dock, 80px) + 64px);
    }

    /* Гость без sticky-формы: «Войдите» не уезжает под dock/навигатор */
    .comments-section[data-open="true"]:not(:has(.comment-form)) {
        padding-bottom: calc(var(--comments-dock) + 8px);
    }

    .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
    .comments-section[data-open="true"]:not(:has(.comment-form)) .comments-list:empty::before,
    .comments-section[data-open="true"]:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before {
        scroll-margin-bottom: calc(var(--comments-dock) + 8px);
    }
}

@supports not (height: 100dvh) {
    @media (max-width: 768px) {
        .comments-section[data-open="true"] .comments-preview.expanded,
        .comments-section:focus-within .comments-preview.expanded {
            max-height: min(600px, calc(100vh - var(--comments-dock, 80px) - 168px));
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    .comments-section[data-open="true"] > .comment-form,
    .comments-section:focus-within > .comment-form {
        transition: none;
    }
}

/* Светлая тема: поле не чёрная полоса (#121826 / sticky #161b27) */
[data-theme="light"] .comment-form,
html[data-theme="light"] .comment-form {
    color-scheme: light;
    background: var(--bg-card, #ffffff);
}

[data-theme="light"] .comment-form input[type="text"],
html[data-theme="light"] .comment-form input[type="text"] {
    color-scheme: light;
    background: var(--bg-input, #f3f4f6);
    background-color: var(--bg-input, #f3f4f6);
    border-color: var(--border-input, rgba(0, 0, 0, 0.08));
    color: var(--text-input, #111827);
    -webkit-text-fill-color: var(--text-input, #111827);
    caret-color: var(--text-input, #111827);
}

[data-theme="light"] .comment-form input[type="text"]::placeholder,
html[data-theme="light"] .comment-form input[type="text"]::placeholder {
    color: var(--text-muted, #6b7280);
    opacity: 1;
    -webkit-text-fill-color: var(--text-muted, #6b7280);
}

[data-theme="light"] .comment-form button,
html[data-theme="light"] .comment-form button {
    color-scheme: light;
    background: var(--bg-input, #f3f4f6);
    background-color: var(--bg-input, #f3f4f6);
    border-color: var(--border-input, rgba(0, 0, 0, 0.08));
    color: var(--text-muted, #6b7280);
}

[data-theme="light"] .comment-form button:hover:not(:disabled),
html[data-theme="light"] .comment-form button:hover:not(:disabled) {
    background: var(--accent-primary, #7c5cfc);
    border-color: var(--accent-primary, #7c5cfc);
    color: #fff;
}

/* Тёмная тема: color-scheme:dark — UA/autofill на sticky #121826 не оставляют светлые контролы */
.comment-form,
[data-theme="dark"] .comment-form,
html[data-theme="dark"] .comment-form {
    color-scheme: dark;
}

.comment-form input[type="text"],
.comment-form button,
[data-theme="dark"] .comment-form input[type="text"],
[data-theme="dark"] .comment-form button,
html[data-theme="dark"] .comment-form input[type="text"],
html[data-theme="dark"] .comment-form button {
    color-scheme: dark;
}

/* Тёмная тема: Chrome autofill не должен заливать sticky-поле жёлтым/белым */
.comment-form input[type="text"]:-webkit-autofill,
.comment-form input[type="text"]:-webkit-autofill:hover,
.comment-form input[type="text"]:-webkit-autofill:focus,
[data-theme="dark"] .comment-form input[type="text"]:-webkit-autofill,
html[data-theme="dark"] .comment-form input[type="text"]:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-input, #121826) inset;
    box-shadow: inset 0 0 0 1000px var(--bg-input, #121826);
    -webkit-text-fill-color: var(--text-input, #e8eefc);
    caret-color: var(--text-input, #e8eefc);
}

[data-theme="light"] .comment-form input[type="text"]:-webkit-autofill,
[data-theme="light"] .comment-form input[type="text"]:-webkit-autofill:hover,
[data-theme="light"] .comment-form input[type="text"]:-webkit-autofill:focus,
html[data-theme="light"] .comment-form input[type="text"]:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--bg-input, #f3f4f6) inset;
    box-shadow: inset 0 0 0 1000px var(--bg-input, #f3f4f6);
    -webkit-text-fill-color: var(--text-input, #111827);
    caret-color: var(--text-input, #111827);
}

[data-theme="light"] .comments-fade,
html[data-theme="light"] .comments-fade {
    background: linear-gradient(to bottom, transparent, var(--bg-card, #ffffff));
}

@media (prefers-reduced-transparency: reduce) {
    [data-theme="light"] .comments-fade,
    html[data-theme="light"] .comments-fade {
        background: var(--bg-card, #ffffff);
    }
}

@media (max-width: 768px) {
    [data-theme="light"] .comment-form:focus-within,
    [data-theme="light"] .comments-section[data-open="true"] > .comment-form,
    [data-theme="light"] .comments-section:focus-within > .comment-form,
    html[data-theme="light"] .comment-form:focus-within,
    html[data-theme="light"] .comments-section[data-open="true"] > .comment-form,
    html[data-theme="light"] .comments-section:focus-within > .comment-form {
        background: var(--bg-card, #ffffff);
        background-clip: padding-box;
        border-top-color: var(--border-card, rgba(0, 0, 0, 0.08));
    }
}

/* Гость без формы: touch-action на хосте (движки часто игнорят на ::before/::after) */
.comments-section:not(:has(.comment-form)) .comments-list:empty,
.comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error),
.comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error),
.comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item),
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error),
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Гость без формы: пустой тред — «Войдите» акцентом (ссылка входа), не muted пустота */
.comments-section:not(:has(.comment-form)) .comments-list:empty::before,
.comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
.comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error)::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error)::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
    content: "Войдите";
    color: var(--accent-primary, #7c5cfc);
    font-size: 13px;
    line-height: 1.45;
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.comments-section:not(:has(.comment-form)) .comments-list:empty:hover::before,
.comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):hover::before,
.comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error):hover::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty:hover::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error):hover::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error):hover::before {
    text-decoration: underline;
}

.comments-section:not(:has(.comment-form)) .comments-list:empty:focus:not(:focus-visible)::before,
.comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus:not(:focus-visible)::before,
.comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error):focus:not(:focus-visible)::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty:focus:not(:focus-visible)::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error):focus:not(:focus-visible)::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error):focus:not(:focus-visible)::before {
    outline: none;
}

.comments-section:not(:has(.comment-form)) .comments-list:empty:focus-visible::before,
.comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus-visible::before,
.comments-section:not(:has(.comment-form)) .comments-list .no-comments:not(#photo-popup-error):focus-visible::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty:focus-visible::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error):focus-visible::before,
.photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list .no-comments:not(#photo-popup-error):focus-visible::before {
    outline: 2px solid var(--accent-primary, #7c5cfc);
    outline-offset: 2px;
    text-decoration: none;
}

/* Гость: «Войдите» под списком только при открытом треде (не висит под collapse) */
.comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after {
    content: "Войдите";
    display: block;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    padding: 12px 0;
    color: var(--accent-primary, #7c5cfc);
    font-size: 13px;
    line-height: 1.45;
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.comments-section[data-open="false"]:not(:has(.comment-form)):has(.comment-item)::after {
    content: none;
    display: none;
    padding: 0;
}

.comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item):hover::after {
    text-decoration: underline;
}

.comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item):focus:not(:focus-visible)::after {
    outline: none;
}

.comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item):focus-visible::after {
    outline: 2px solid var(--accent-primary, #7c5cfc);
    outline-offset: 2px;
    text-decoration: none;
}

/* Попап: форма в compose — не дублировать «Войдите»; пустой тред — «Напишите первым» */
.photo-popup-content:has(.comment-form) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty::before,
.photo-popup-content:has(.comment-form) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
.photo-popup-content:has(.comment-form) .popup-comments-list:empty::before,
.photo-popup-content:has(.comment-form) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
    content: "Напишите первым";
    color: var(--text-muted, #8b90a0);
    font-weight: 500;
    cursor: default;
    text-decoration: none;
    touch-action: auto;
}

/* Попап-гость (.guest-note): писать нельзя — muted «Пока нет», не призыв писать */
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error),
.photo-popup-content:has(.guest-note) .popup-comments-list:empty,
.photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error) {
    touch-action: auto;
    -webkit-tap-highlight-color: transparent;
    cursor: default !important;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty::before,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
.photo-popup-content:has(.guest-note) .popup-comments-list:empty::before,
.photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
    content: "Пока нет комментариев";
    color: var(--text-muted, #8b90a0);
    font-weight: 500;
    cursor: default !important;
    text-decoration: none;
    touch-action: auto;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: none;
}

.photo-popup-content:has(.comment-form) .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
.photo-popup-content:has(.comment-form) .comments-section:not(:has(.comment-form)):has(.comment-item)::after,
.photo-popup-content:has(.guest-note) .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)):has(.comment-item)::after {
    content: none;
    display: none;
}

.photo-popup-content:has(.guest-note) .popup-comments-list:empty:hover::before,
.photo-popup-content:has(.guest-note) .no-comments:not(#photo-popup-error):hover::before,
.photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error):hover::before {
    text-decoration: none;
}

/* guest-note: «Пока нет» неинтерактивно — без outline акцента Войдите */
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty:focus-visible::before,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus-visible::before,
.photo-popup-content:has(.guest-note) .popup-comments-list:empty:focus-visible::before,
.photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error):focus-visible::before,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty:focus::before,
.photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error):focus::before,
.photo-popup-content:has(.guest-note) .popup-comments-list:empty:focus::before,
.photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error):focus::before {
    outline: none;
}

/* Ошибка фотопопапа: читаемый текст, без подписи пустого треда */
#photo-popup-error.no-comments,
.no-comments#photo-popup-error,
.photo-popup-content #photo-popup-error.no-comments,
.photo-popup-content .no-comments#photo-popup-error {
    font-size: 16px;
    line-height: 1.45;
    font-weight: 500;
    color: var(--text-primary, #fff);
}

#photo-popup-error.no-comments::before,
.no-comments#photo-popup-error::before,
.photo-popup-content #photo-popup-error.no-comments::before,
.photo-popup-content .no-comments#photo-popup-error::before {
    content: none !important;
    display: none !important;
}

[data-theme="light"] .comments-section:not(:has(.comment-form)) .comments-list:empty::before,
[data-theme="light"] .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
[data-theme="light"] .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
html[data-theme="light"] .comments-section:not(:has(.comment-form)) .comments-list:empty::before,
html[data-theme="light"] .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
html[data-theme="light"] .comments-section[data-open="true"]:not(:has(.comment-form)):has(.comment-item)::after,
[data-theme="light"] .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty::before,
[data-theme="light"] .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error)::before,
html[data-theme="light"] .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .popup-comments-list:empty::before,
html[data-theme="light"] .photo-popup-content:not(:has(.comment-form)):not(:has(.guest-note)) .no-comments:not(#photo-popup-error)::before {
    color: var(--accent-primary, #7c5cfc);
}

/* light: guest-note «Пока нет» — muted после accent Войдите */
[data-theme="light"] .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty::before,
[data-theme="light"] .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
[data-theme="light"] .photo-popup-content:has(.guest-note) .popup-comments-list:empty::before,
[data-theme="light"] .photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error)::before,
html[data-theme="light"] .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .popup-comments-list:empty::before,
html[data-theme="light"] .photo-popup-content:has(.guest-note) .comments-section:not(:has(.comment-form)) .no-comments:not(#photo-popup-error)::before,
html[data-theme="light"] .photo-popup-content:has(.guest-note) .popup-comments-list:empty::before,
html[data-theme="light"] .photo-popup-content:has(.guest-note) .popup-comments-list .no-comments:not(#photo-popup-error)::before {
    color: var(--text-muted, #6b7280);
}

[data-theme="light"] #photo-popup-error.no-comments,
[data-theme="light"] .no-comments#photo-popup-error,
html[data-theme="light"] #photo-popup-error.no-comments,
html[data-theme="light"] .no-comments#photo-popup-error {
    color: var(--text-primary, #111827);
}
