/* =========================================================================
   v37: post_detail.css — «страница поста» (пост + комментарии).
   Общий оверлей для ленты (/feed) и профилей (/profile, /profile/user).

   Поведение:
   - ПК (>900px): модалка по центру. Если у поста есть изображение —
     раскладка «картинка слева, комментарии справа»
     (.post-detail-modal--split); текстовый пост — одноколоночная модалка.
     Форма комментария прижата к низу модалки (как композер в чате).
   - Телефон (≤899px): пост открывается на весь экран (не модалка),
     шапка и поле ввода комментария прилипают к краям экрана.

   v37: форма отправки комментария redesign — как форма отправки сообщений
   в чате: круглая кнопка-скрепка слева, поле-«пилюля» по центру,
   справа микрофон, который при вводе текста превращается в кнопку
   отправки (анимация свапа как в чате).
   ========================================================================= */

/* --- База оверлея (раньше в feed.css) --- */
.post-detail-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,.55);
    display: flex; align-items: flex-start; justify-content: center;
    overflow-y: auto; padding: 20px;
}
.post-detail-overlay[hidden] { display: none; }
.post-detail-modal {
    background: var(--surface, #161616); color: var(--text, #fff);
    border-radius: 16px; max-width: 560px; width: 100%;
    margin: auto; box-shadow: 0 8px 32px rgba(0,0,0,.4);
    overflow: hidden;
}
.post-detail-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 18px; border-bottom: 1px solid rgba(255,255,255,.08);
    background: var(--surface, #161616);
}
.post-detail-header h3 { margin: 0; font-size: 17px; font-weight: 700; }
.post-detail-close {
    border: 0; background: transparent; color: var(--muted, #8899aa);
    font-size: 24px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.post-detail-close:hover { color: var(--text, #fff); }
.post-detail-body { padding: 14px 18px; }
.post-detail-body .post-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-detail-body .post-author { font-weight: 700; color: var(--text, #fff); text-decoration: none; }
.post-detail-body .post-time { font-size: 12px; color: var(--muted, #8899aa); }
.post-detail-body .post-content { font-size: 15px; line-height: 1.45; margin-bottom: 10px; white-space: pre-wrap; word-break: break-word; }
.post-detail-body .post-image-wrap { margin: 8px 0; border-radius: 12px; overflow: hidden; }
.post-detail-body .post-image { width: 100%; border-radius: 12px; }
.post-detail-body .post-actions { display: flex; gap: 16px; padding: 8px 0; font-size: 13px; color: var(--muted, #8899aa); }
.post-detail-body .post-actions .post-like-btn { display: inline-flex; align-items: center; gap: 5px; }
.post-detail-body .post-actions .post-view-count { display: inline-flex; align-items: center; gap: 5px; }
.post-detail-body .empty { color: var(--muted, #8899aa); }

/* --- Комментарии: секция = колонка (список сверху, форма снизу) --- */
.post-detail-comments-section {
    padding: 0 18px 18px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.comments-list { display: flex; flex-direction: column; gap: 2px; }
.comments-loading { color: var(--muted, #8899aa); font-size: 13px; padding: 8px 0; text-align: center; }

/* --- v37: форма комментария — как композер чата --- */
.comment-form-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.comment-composer-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.comment-composer-tool {
    width: 40px; height: 40px; min-width: 40px; flex: 0 0 auto;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.06);
    color: var(--text, #fff);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0;
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.comment-composer-tool:hover { background: rgba(255,255,255,.12); }
.comment-composer-tool:active { transform: scale(.94); }
.comment-composer-tool img {
    width: 19px; height: 19px; display: block;
    filter: brightness(0) invert(1);
    opacity: .85;
}
.comment-composer-input {
    flex: 1; min-width: 0;
    resize: none;
    min-height: 42px; max-height: 140px; height: 42px;
    padding: 10px 16px;
    border-radius: 21px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(0,0,0,.22);
    color: var(--text, #fff);
    font: inherit; font-size: 14.5px; line-height: 1.4;
    outline: none;
    overflow-x: hidden; overflow-y: auto;
    word-break: break-word; overflow-wrap: anywhere;
    box-sizing: border-box;
    transition: border-color .15s ease, background .15s ease;
}
.comment-composer-input:focus { border-color: var(--accent, #8b7cf7); }
.comment-composer-input::placeholder { color: var(--muted, #8899aa); opacity: .85; }
/* Правый слот: микрофон ↔ отправка (как composer-primary-slot в чате) */
.comment-composer-primary {
    position: relative;
    width: 40px; height: 40px; flex: 0 0 40px;
}
.comment-composer-primary .comment-composer-tool,
.comment-composer-primary .comment-composer-send {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    margin: 0;
    transition: opacity .22s ease, transform .34s cubic-bezier(.34,1.45,.64,1);
}
.comment-composer-send {
    border: 0;
    border-radius: 50%;
    background: var(--accent, #8b7cf7);
    color: #fff;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0;
}
.comment-composer-send img {
    width: 18px; height: 18px; display: block;
    filter: brightness(0) invert(1);
}
.comment-composer-send:hover { opacity: .9; }
.comment-composer-send:disabled { opacity: .5; cursor: not-allowed; }
/* Свап как в чате: пусто → микрофон; есть текст → отправка */
.comment-form-wrap:not(.composer-has-text) .comment-composer-send {
    opacity: 0;
    transform: scale(.68) rotate(18deg);
    pointer-events: none;
}
.comment-form-wrap:not(.composer-has-text) .comment-composer-mic { z-index: 2; }
.comment-form-wrap.composer-has-text .comment-composer-mic {
    opacity: 0;
    transform: scale(.68) rotate(-18deg);
    pointer-events: none;
}
.comment-form-wrap.composer-has-text .comment-composer-send { z-index: 2; }

/* v37: превью ответа — пилюля с акцентной плашкой */
.comment-reply-preview {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(139,124,247,.14);
    border-left: 3px solid var(--accent, #8b7cf7);
    font-size: 13px;
    color: var(--text, #fff);
}
.comment-reply-preview__icon { color: var(--accent, #8b7cf7); font-weight: 700; }
.comment-reply-preview__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comment-reply-preview__cancel {
    border: 0; background: transparent; color: var(--muted, #8899aa);
    font-size: 14px; cursor: pointer; line-height: 1; padding: 2px 4px;
}
.comment-reply-preview__cancel:hover { color: var(--text, #fff); }

.comment-error { color: #e0245e; font-size: 13px; margin: 0; }

/* --- Ветки ответов (v37: свёрнуты по умолчанию) --- */
.comment-thread {
    margin-left: 28px;
    padding-left: 8px;
    border-left: 2px solid rgba(127,127,127,.18);
    display: flex; flex-direction: column; gap: 2px;
}
.comment-thread[hidden] { display: none; }
.comment-thread-toggle {
    display: inline-flex; align-items: center; gap: 4px;
    border: 0; background: transparent; cursor: pointer;
    color: var(--accent, #8b7cf7);
    font-size: 12.5px; font-weight: 600;
    padding: 2px 8px; border-radius: 8px;
    transition: background .15s ease;
}
.comment-thread-toggle:hover { background: rgba(139,124,247,.12); }
.comment-thread-toggle__chev { font-size: 11px; line-height: 1; }
.comment-replies-note { font-size: 12px; color: var(--muted, #8899aa); }

/* --- Элементы комментария --- */
.comment-item { padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
.comment-item:last-child { border-bottom: 0; }
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.avatar-xs { width: 28px; height: 28px; border-radius: 50%; font-size: 13px; }
.avatar-xs.has-image img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.comment-author { font-weight: 700; font-size: 14px; color: var(--text, #fff); text-decoration: none; }
.comment-author:hover { text-decoration: underline; }
.comment-time { font-size: 12px; color: var(--muted, #8899aa); }
.comment-text { font-size: 14px; line-height: 1.4; margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.comment-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.comment-like-btn, .comment-dislike-btn {
    display: inline-flex; align-items: center; gap: 4px;
    border: 0; background: transparent; cursor: pointer;
    color: var(--muted, #8899aa); padding: 2px 6px; border-radius: 6px;
    font-size: 13px; transition: color .15s;
}
.comment-like-btn:hover { color: #e0245e; }
.comment-like-btn.is-liked { color: #ef4444; }
.comment-dislike-btn:hover { color: #8899aa; }
.comment-dislike-btn.is-disliked { color: #6b7280; }
.comment-like-count { font-weight: 600; min-width: 12px; text-align: center; }
.comment-reply-btn {
    border: 0; background: transparent; cursor: pointer;
    color: var(--muted, #8899aa); padding: 2px 6px; border-radius: 6px;
    font-size: 13px; transition: color .15s;
}
.comment-reply-btn:hover { color: var(--accent, #8b7cf7); }

/* --- v37: тост о недоступных действиях (скрепка/микрофон) --- */
.comment-action-toast {
    position: fixed;
    left: 50%; bottom: 96px;
    transform: translateX(-50%) translateY(8px);
    background: rgba(22,22,28,.94);
    color: #fff;
    font-size: 13.5px; font-weight: 600;
    padding: 10px 18px;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,.35);
    z-index: 10001;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
    max-width: min(86vw, 420px);
    text-align: center;
}
.comment-action-toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =========================================================================
   ПК (≥900px): форма прижата к низу модалки; список прокручивается
   ========================================================================= */
@media (min-width: 900px) {
    /* Одноколоночная модалка: шапка / пост / комментарии — колонка */
    .post-detail-modal {
        display: flex;
        flex-direction: column;
        max-height: calc(100dvh - 48px);
    }
    .post-detail-header { flex: 0 0 auto; }
    .post-detail-body {
        flex: 0 1 auto;
        min-height: 120px;
        overflow-y: auto;
    }
    .post-detail-comments-section {
        flex: 1 1 auto;
        min-height: 170px;
        padding-bottom: 14px;
    }
    .comments-list,
    .comments-loading {
        flex: 1 1 auto;
        overflow-y: auto;
        min-height: 0;
    }
    .comment-form-wrap {
        flex: 0 0 auto;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 1px solid rgba(255,255,255,.08);
    }

    /* Сплит: пост с изображением — картинка слева, комментарии справа */
    .post-detail-modal.post-detail-modal--split {
        max-width: 1100px;
        display: grid;
        grid-template-columns: minmax(0, 11fr) minmax(0, 9fr);
        grid-template-rows: auto minmax(0, 1fr);
        grid-template-areas:
            "header header"
            "body comments";
        max-height: calc(100dvh - 48px);
    }
    .post-detail-modal--split .post-detail-header { grid-area: header; }
    .post-detail-modal--split .post-detail-body {
        grid-area: body;
        overflow-y: auto;
        min-height: 0;
        border-right: 1px solid rgba(255,255,255,.08);
        padding-bottom: 22px;
    }
    .post-detail-modal--split .post-detail-body .post-image-wrap {
        margin: 10px 0;
        border-radius: 14px;
        background: rgba(0,0,0,.25);
        display: flex;
        justify-content: center;
    }
    .post-detail-modal--split .post-detail-body .post-image {
        width: 100%;
        max-height: calc(100dvh - 260px);
        object-fit: contain;
        border-radius: 14px;
    }
    .post-detail-modal--split .post-detail-comments-section {
        grid-area: comments;
        overflow: hidden;
        padding: 0 18px 14px;
    }
    /* Список комментариев прокручивается, форма ответа прижата к низу колонки */
    .post-detail-modal--split .comments-list,
    .post-detail-modal--split .comments-loading {
        flex: 1 1 auto;
        overflow-y: auto;
        min-height: 0;
        padding-right: 6px;
    }
    .post-detail-modal--split .comment-form-wrap {
        flex: 0 0 auto;
        margin: 12px 0 0;
        padding-top: 12px;
        border-top: 1px solid rgba(255,255,255,.08);
    }
}

/* =========================================================================
   Телефон (≤899px): пост на весь экран (не модалка), форма прилипает к низу
   ========================================================================= */
@media (max-width: 899px) {
    .post-detail-overlay {
        padding: 0;
        align-items: stretch;
        background: var(--surface, #161616);
        overflow-y: auto;
    }
    .post-detail-modal {
        max-width: 100%;
        width: 100%;
        min-height: 100%;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }
    .post-detail-header {
        position: sticky;
        top: 0;
        z-index: 5;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        border-bottom: 1px solid rgba(255,255,255,.08);
    }
    .post-detail-body { padding-top: 12px; }
    .post-detail-comments-section {
        flex: 1 0 auto;
        padding-bottom: 0;
    }
    /* Список в общем потоке страницы; при коротком контенте список растягивается,
       прижимая форму к нижнему краю; при длинном — форма прилипает (sticky) */
    .comments-list,
    .comments-loading { flex: 1 1 auto; }
    .comment-form-wrap {
        position: sticky;
        bottom: 0;
        z-index: 5;
        background: var(--surface, #161616);
        margin-top: 0;
        padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid rgba(255,255,255,.08);
    }
    .comment-composer-tool { width: 42px; height: 42px; min-width: 42px; }
    .comment-composer-primary { width: 46px; height: 46px; flex: 0 0 46px; }
    .comment-composer-input { min-height: 42px; height: 42px; border-radius: 22px; }
    .comment-composer-row { gap: 10px; }
}

/* Светлая тема (посты открываются и на светлых страницах) */
body[data-theme="light"] .comment-composer-tool {
    background: rgba(0,0,0,.05);
    border-color: rgba(0,0,0,.14);
}
body[data-theme="light"] .comment-composer-tool:hover { background: rgba(0,0,0,.1); }
body[data-theme="light"] .comment-composer-tool img { filter: brightness(0) saturate(100%); }
body[data-theme="light"] .comment-composer-send img { filter: brightness(0) invert(1); }
body[data-theme="light"] .comment-composer-input {
    background: #fff;
    border-color: rgba(0,0,0,.14);
    color: #111827;
}
body[data-theme="light"] .comment-reply-preview { background: rgba(139,124,247,.1); }
body[data-theme="light"] .comment-action-toast { background: rgba(245,245,248,.97); color: #111827; }

/* Лёгкая анимация появления (не мешает reduced-motion) */
@media (prefers-reduced-motion: no-preference) {
    .post-detail-overlay:not([hidden]) .post-detail-modal {
        animation: postDetailIn .18s ease;
    }
    @keyframes postDetailIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: none; }
    }
}
