/**
 * comments.css — Shared comment styles
 * Used by post-detail, video-modal comments panel, and any future comment channel.
 * Import this wherever comment.html / comments-panel.html are used.
 */

/* ============================================================
   CMT-THREAD  (Twitter / X threaded comment item)
   comment.html uses these classes
   ============================================================ */

.cmt-thread {
    display: grid;
    grid-template-columns: 36px 1fr;
    column-gap: 10px;
    padding: 10px 12px 4px;
    position: relative;
    transition: background 0.15s;
}

.cmt-thread:hover {
    background: var(--bg-hover, rgba(0,0,0,0.04));
}

.cmt-thread.cmt-reply {
    padding-left: 24px;
    grid-template-columns: 30px 1fr;
    border-left: 2.5px solid var(--border-light, #e0e0e0);
    margin-left: 18px;
    border-radius: 0 0 0 6px;
    background: var(--bg-hover, rgba(0,0,0,0.02));
}

.cmt-thread.cmt-reply:last-child {
    border-radius: 0 0 6px 6px;
    margin-bottom: 6px;
}

.cmt-thread.cmt-reply .cmt-avatar {
    width: 28px;
    height: 28px;
}

/* Panel context: stronger reply differentiation */
.comments-panel .cmt-thread.cmt-reply {
    border-left-color: var(--primary, #1d9bf0);
    border-left-width: 2px;
    background: rgba(29, 155, 240, 0.04);
    margin-left: 20px;
    padding-top: 8px;
    padding-bottom: 4px;
}

/* Replies section container inside panel */
.comments-panel .cmt-replies {
    border-left: 2px solid var(--border-light, #e8e8e8);
    margin-left: 18px;
    padding-left: 0;
    position: relative;
}

/* "View N replies" / collapse toggle */
.cmt-replies-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary, #1d9bf0);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px 4px 0;
    margin-left: 46px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.cmt-replies-toggle:hover {
    background: rgba(29,155,240,0.07);
}

.cmt-replies-toggle i {
    font-size: 0.875rem;
    transition: transform 0.2s;
}

.cmt-replies-toggle.expanded i {
    transform: rotate(180deg);
}

/* Collapse animation for replies */
.cmt-replies-list {
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cmt-replies-list.collapsed {
    max-height: 0 !important;
}

/* Left column: avatar + vertical connector */
.cmt-left {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.cmt-avatar-wrap {
    display: block;
    text-decoration: none;
    flex-shrink: 0;
}

.cmt-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--border-light, #e0e0e0);
    background: var(--bg-secondary);
    display: block;
}

/* Vertical thread line connecting parent to replies */
.cmt-vline {
    flex: 1;
    width: 2px;
    background: var(--border-light, #e0e0e0);
    margin: 4px auto 0;
    border-radius: 1px;
    min-height: 16px;
}

/* Right column: all content */
.cmt-body {
    flex: 1;
    min-width: 0;
    padding-bottom: 8px;
}

/* Header row: name, handle, time, menu */
.cmt-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
    margin-bottom: 2px;
}

.cmt-meta-row {
    display: flex;
    align-items: baseline;
    gap: 5px;
    flex-wrap: wrap;
    min-width: 0;
}

.cmt-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    transition: color 0.15s;
}

a.cmt-name:hover {
    color: var(--primary);
    text-decoration: underline;
}

.cmt-handle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.cmt-sep {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.cmt-time {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* "Replying to @user" label */
.cmt-replying-to {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.cmt-replying-to a {
    color: var(--primary);
    text-decoration: none;
}

.cmt-replying-to a:hover {
    text-decoration: underline;
}

/* Comment text */
.cmt-text {
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    margin: 0 0 6px;
}

.cmt-text p {
    margin: 0 0 4px;
}

.cmt-text p:last-child {
    margin-bottom: 0;
}

/* ── Action row (like, reply, share) ──────────────── */
.cmt-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

.cmt-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 20px;
    transition: color 0.15s, background 0.15s;
    line-height: 1;
    text-decoration: none;
}

.cmt-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.cmt-btn i {
    font-size: 1rem;
}

.cmt-btn.cmt-like:hover {
    color: #1d9bf0;
    background: rgba(29, 155, 240, 0.08);
}

.cmt-btn.cmt-like.liked,
.cmt-btn.cmt-like.liked:hover {
    color: #1d9bf0;
}

/* ── Three-dot menu ─────────────────────────────────── */
.cmt-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.cmt-menu-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    font-size: 1rem;
}

.cmt-menu-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.cmt-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    min-width: 180px;
    z-index: 1100;
    display: none;
    overflow: hidden;
    animation: dropdownIn 0.15s ease;
}

.cmt-dropdown.open {
    display: block;
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.cmt-drop-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}

.cmt-drop-item:hover {
    background: var(--bg-hover, rgba(0,0,0,0.05));
}

.cmt-drop-item.danger {
    color: var(--danger, #dc3545);
}

.cmt-drop-item.danger:hover {
    background: rgba(220, 53, 69, 0.08);
}

.cmt-drop-item i {
    font-size: 1rem;
    width: 18px;
}

/* ── Nested replies container ──────────────────────── */
.cmt-replies {
    padding-left: 0;
    grid-column: 1 / -1; /* span full grid width so replies don't collapse into avatar column */
}

/* Highlight when being replied to */
.cmt-thread.reply-target > .cmt-body {
    background: rgba(29, 155, 240, 0.06);
    border-radius: 8px;
    padding: 4px 8px 4px;
}

.cmt-thread.reply-target > .cmt-left .cmt-avatar {
    outline: 2px solid var(--primary, #1d9bf0);
    outline-offset: 1px;
}

/* Flash highlight for freshly-inserted comment */
@keyframes highlightComment {
    0%   { background: rgba(29, 155, 240, 0.18); }
    100% { background: transparent; }
}

@keyframes cmt-flash {
    0%   { background: rgba(29, 155, 240, 0.2); }
    100% { background: transparent; }
}

.cmt-flash-highlight {
    animation: cmt-flash 2s ease forwards;
}

/* ── Media grid inside comment ───────────────────────
   X-style: attachments never span the full desktop column.
   Single media keeps its intrinsic aspect ratio (no crop/stretch);
   multi-media uses a compact cropped grid. */
.cmt-images-grid {
    margin: 8px 0;
    border-radius: 12px;
    overflow: hidden;
    max-width: min(380px, 100%);
}

.cmt-grid-single {
    display: inline-block;
    max-width: min(340px, 100%);
    overflow: visible;
}

.cmt-grid-single .cmt-grid-item {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    border: 1px solid var(--border-light, rgba(0, 0, 0, 0.08));
    cursor: pointer;
    background: var(--bg-secondary, #f2f2f2);
}

.cmt-grid-single .cmt-grid-item img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 320px;
    object-fit: contain;
    transition: transform 0.2s;
}

/* Videos keep a stable 16:9 frame (the element needs box dimensions). */
.cmt-grid-single .cmt-grid-item video {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 320px;
    object-fit: cover;
    transition: transform 0.2s;
}

.cmt-grid-single .cmt-grid-item:hover img,
.cmt-grid-single .cmt-grid-item:hover video {
    transform: scale(1.03);
}

.cmt-play-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: rgba(255,255,255,0.9);
    pointer-events: none;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* ============================================================
   COMMENT INPUT BAR  (shared, used in panel + post-detail)
   ============================================================ */

.comment-input-area {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    padding: 8px 12px;
}

.comment-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
    margin: 0;
}

.comment-input-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    cursor: pointer;
    transition: opacity 0.2s, outline 0.2s;
    margin-bottom: 4px;
    border: 1.5px solid var(--border-light);
}

.comment-input-avatar:hover {
    opacity: 0.8;
}

.comment-input-avatar.anonymous-active {
    outline: 2px solid var(--primary, #1d9bf0);
    outline-offset: 2px;
    opacity: 0.85;
}

/* WhatsApp-style pill */
.comment-input-pill {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-end;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 22px;
    padding: 5px 6px 5px 10px;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.comment-input-pill:focus-within {
    border-color: var(--primary, #1d9bf0);
    background: var(--bg-primary);
    box-shadow: 0 0 0 2px rgba(29,155,240,0.12);
}

.comment-textarea-detail {
    flex: 1;
    min-height: 22px;
    max-height: 120px;
    padding: 2px 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9375rem;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.45;
    overflow-y: auto;
}

.comment-textarea-detail::placeholder {
    color: var(--text-tertiary);
}

/* icon buttons inside the pill */
.attach-media-btn-inner,
.cmt-icon-btn-inner {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    font-size: 1rem;
    padding: 0;
    margin-right: 2px;
    margin-bottom: 1px;
}

.attach-media-btn-inner:hover,
.cmt-icon-btn-inner:hover {
    color: var(--primary, #1d9bf0);
    background: rgba(29,155,240,0.1);
}

/* Anon active state */
.cmt-icon-btn-inner.anon-active {
    color: var(--primary, #1d9bf0);
}

.submit-comment-pill-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary, #1d9bf0);
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 0.8125rem;
    margin-left: 4px;
}

.submit-comment-pill-btn:hover {
    background: var(--primary-hover, #1a8cd8);
    transform: scale(1.08);
}

.submit-comment-pill-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
    transform: none;
}

/* Media preview strip */
.comment-media-preview {
    display: flex;
    gap: 6px;
    padding: 6px 12px 2px;
    flex-wrap: wrap;
    max-height: 120px;
    overflow-y: auto;
}

.comment-media-preview-item {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-light);
    flex-shrink: 0;
}

.comment-media-preview-item img,
.comment-media-preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.comment-media-remove-btn {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(0,0,0,0.65);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    line-height: 1;
    padding: 0;
    transition: background 0.15s;
}

.comment-media-remove-btn:hover {
    background: var(--danger, #dc3545);
}

/* ── Reply context indicator pill ──────────────────── */
.reply-context-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    animation: slideDown 0.15s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.reply-context-indicator strong {
    color: var(--text-primary);
}

.cancel-reply-x {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    font-size: 1rem;
}

.cancel-reply-x:hover {
    color: var(--danger, #dc3545);
}

/* ============================================================
   COMMENTS LIST WRAPPER
   ============================================================ */

.comments-list-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.12) transparent;
}

.comments-list-wrapper::-webkit-scrollbar {
    width: 5px;
}

.comments-list-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.14);
    border-radius: 3px;
}

/* No-comment state */
.no-comments-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-tertiary);
    min-height: 200px;
}

.no-comments-detail i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.35;
}

.no-comments-detail p {
    font-size: 0.9rem;
    margin: 0;
}

/* ============================================================
   COMMENTS PANEL  (slide-up bottom sheet used in video modal)
   ============================================================ */

.comments-panel {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    height: 70vh;
    height: 70dvh; /* dynamic viewport height — shrinks when soft keyboard opens */
    min-height: 340px;
    background: var(--bg-primary);
    border-radius: 20px 20px 0 0;
    z-index: 10010;
    display: flex;
    flex-direction: column;
    transition: bottom 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.22);
    overflow: hidden;
}

.comments-panel.open {
    bottom: 0;
    /* JS (visualViewport listener) overrides this when keyboard is open */
}

/* Keep comment input always visible above keyboard */
.comments-panel .comment-input-area {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--bg-primary);
    padding-bottom: env(safe-area-inset-bottom, 0);
    border-top: 1px solid var(--border-light);
}

/* Drag handle pill */
.panel-drag-handle {
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    padding: 10px 0 0;
    cursor: grab;
}

.panel-drag-handle span {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color, rgba(0,0,0,0.15));
}

/* Panel header */
.panel-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 10px;
    border-bottom: 1px solid var(--border-light);
}

.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.panel-header .panel-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-left: 6px;
    font-weight: 500;
}

.panel-close-btn {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.25rem;
    transition: background 0.15s;
}

.panel-close-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Panel backdrop overlay */
.comments-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 10009;
    display: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.comments-panel-backdrop.open {
    display: block;
}

/* ============================================================
   GALLERY LIGHTBOX  (for comment media)
   ============================================================ */

#cmtGalleryModal {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 20000;
    display: none;
}

#cmtGalleryModal.open {
    display: block;
}

.cmt-gallery-inner {
    position: relative;
    width: 100%;
    height: 100%;
}

.cmt-gallery-scroller {
    height: 100%;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.cmt-gallery-slide {
    height: 100%;
    min-height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 56px 12px 24px;
    box-sizing: border-box;
}

.cmt-gallery-slide img,
.cmt-gallery-slide video {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
}

.cmt-gallery-counter {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255,255,255,0.85);
    font-size: 0.875rem;
    z-index: 2;
    background: rgba(0,0,0,0.35);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.cmt-gallery-close {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.85;
    z-index: 2;
}

.cmt-gallery-close:hover { opacity: 1; }
