/* ============================================================================
   COMMENTS SYSTEM - ENHANCED WITH REDDIT-STYLE THREADING
   ============================================================================ */

:root {
    --thread-line-color: #cbd5e0;
    --thread-line-hover: #667eea;
    --thread-line-width: 2px;
    --comment-spacing: 12px;
    --avatar-size: 40px;
    --indent-size: 30px;
}

/* ============================================================================
   COMMENT THREAD STRUCTURE
   ============================================================================ */

.comment-thread {
    position: relative;
    margin-bottom: var(--comment-spacing);
}

/* Top-level comments have more spacing */
.comment-thread.top-level {
    padding: 16px 0;
    border-bottom: 1px solid #e2e8f0;
}

.comment-thread.top-level:last-child {
    border-bottom: none;
}

.comment-main {
    display: flex;
    gap: 12px;
    position: relative;
}

/* ============================================================================
   LEFT COLUMN - AVATAR AND THREADING LINES
   ============================================================================ */

.comment-left-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    width: var(--avatar-size);
    position: relative;
}

/* Avatar styles */
.avatar {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-placeholder {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================================================
   REDDIT-STYLE VERTICAL THREADING LINE
   ============================================================================ */

.thread-line-vertical {
    position: absolute;
    top: calc(var(--avatar-size) + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: var(--thread-line-width);
    bottom: 0;
    background: var(--thread-line-color);
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 1;
}

/* Hide thread line when replies are hidden */
.comment-thread:has(> .replies-container.is-hidden) > .comment-main > .comment-left-col > .thread-line-vertical {
    display: none;
}

/* Hover effect on thread line */
.thread-line-vertical:hover {
    background: var(--thread-line-hover);
    width: 4px;
}

/* When line is clicked, briefly highlight */
.thread-line-vertical:active {
    background: var(--thread-line-hover);
    width: 4px;
}

/* ============================================================================
   HORIZONTAL CONNECTOR (Reddit-style elbow)
   ============================================================================ */

/* Add connector line from parent to child */
.replies-container > .comment-thread::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--indent-size) + var(--avatar-size) / 2);
    top: calc(var(--avatar-size) / 2);
    width: calc(var(--indent-size) - var(--avatar-size) / 2 - 12px);
    height: var(--thread-line-width);
    background: var(--thread-line-color);
}

/* ============================================================================
   CONTENT AREA
   ============================================================================ */

.comment-content {
    flex: 1;
    min-width: 0;
}

.comment-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.author-name {
    font-weight: 600;
  
    text-decoration: none;
    font-size: 14px;
}

.author-name:hover {
    text-decoration: underline;
}

.timestamp {
    font-size: 12px;
    color: #718096;
}

.comment-body {
  
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 8px;
    word-wrap: break-word;
}

/* ============================================================================
   COMMENT ACTIONS
   ============================================================================ */

.comment-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 8px;
}

.action-btn {
    background: none;
    border: none;
    color: #718096;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.action-btn:hover {
    background: #f7fafc;
    color: #2d3748;
}

/* ============================================================================
   YOUTUBE-STYLE TOGGLE REPLIES BUTTON
   ============================================================================ */

.toggle-replies-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: #667eea;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 12px;
    margin-top: 8px;
    border-radius: 18px;
    transition: all 0.2s;
}

.toggle-replies-btn:hover {
    background: rgba(102, 126, 234, 0.1);
}

.toggle-replies-btn .chevron-icon {
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.toggle-replies-btn.expanded .chevron-icon {
    transform: rotate(180deg);
}

.toggle-text {
    font-size: 13px;
}

/* ============================================================================
   REPLIES CONTAINER
   ============================================================================ */

.replies-container {
    margin-top: var(--comment-spacing);
    padding-left: var(--indent-size);
    transition: all 0.3s ease;
    overflow: hidden;
}

/* Hidden state for replies */
.replies-container.is-hidden {
    max-height: 0;
    margin-top: 0;
    opacity: 0;
    pointer-events: none;
}

/* Show state */
.replies-container:not(.is-hidden) {
    max-height: none;
    opacity: 1;
}

/* ============================================================================
   DEPTH-SPECIFIC STYLING
   ============================================================================ */

/* Level 0 - Root comments (no special indent) */
.comment-thread[data-depth="0"] {
    padding-left: 0;
}

/* Level 1 - First replies */
.comment-thread[data-depth="1"] {
    /* Inherits indent from replies-container */
}

/* Level 2+ - Deep replies (flattened) */
.comment-thread[data-depth="2"] {
    /* Stays at same indent as level 1 */
}

/* Level 3+ - Maximum depth, all further replies stay here */
.comment-thread[data-depth="3"] {
    /* Stays at same indent as level 2 */
}

/* At depth 3+, remove the vertical line since we're at max depth */
.comment-thread[data-depth="3"] .thread-line-vertical {
    display: none;
}

/* Depth 4+ removes padding to show replies are flattened */
.replies-container[data-depth="4"],
.replies-container[data-depth="5"],
.replies-container[data-depth="6"] {
    padding-left: 0;
}

/* Reply-to indicator for flattened replies */
.reply-to {
    font-size: 12px;
    font-style: italic;
    margin-bottom: 6px;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border-left: 2px solid #cbd5e0;
    border-radius: 4px;
    display: inline-block;
}

/* ============================================================================
   PARENT HIGHLIGHT EFFECT
   ============================================================================ */

.comment-thread.parent-highlighted {
    position: relative;
}

.comment-thread.parent-highlighted::after {
    content: '';
    position: absolute;
    top: -8px;
    left: -12px;
    right: -12px;
    bottom: -8px;
    background: rgba(102, 126, 234, 0.08);
    pointer-events: none;
    animation: highlightFade 2s ease-out;
    z-index: -1;
}

@keyframes highlightFade {
    0% {
        background: rgba(102, 126, 234, 0.15);
    }
    100% {
        background: rgba(102, 126, 234, 0.08);
    }
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    :root {
        --avatar-size: 32px;
        --indent-size: 32px;
    }
    
    .replies-container {
        padding-left: var(--indent-size);
    }
    
    .comment-main {
        gap: 8px;
    }
    
    .toggle-replies-btn {
        font-size: 12px;
        padding: 6px 10px;
    }
    
    .action-btn {
        font-size: 11px;
        padding: 3px 6px;
    }
    
    .comment-body {
        font-size: 13px;
    }
    /* Depth 4+ removes padding to show replies are flattened */
        .replies-container[data-depth="4"],
        .replies-container[data-depth="5"],
        .replies-container[data-depth="6"] {
            padding-left: 0;
        }
}

/* ============================================================================
   COMMENT STATES
   ============================================================================ */

/* Deleted comments */
.comment-thread.deleted {
    opacity: 0.6;
}

.comment-thread.deleted .comment-body {
    font-style: italic;
    color: #a0aec0;
}

/* Highlighted from URL */
.comment-thread.highlighted {
    animation: highlightPulse 1s ease-out;
}

@keyframes highlightPulse {
    0%, 100% {
        background: transparent;
    }
    50% {
        background: rgba(102, 126, 234, 0.1);
    }
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */

.replies-container.loading {
    opacity: 0.5;
    pointer-events: none;
}

.loading-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #718096;
    gap: 8px;
}

.loading-spinner i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */



/* High contrast mode support */
@media (prefers-contrast: high) {
    .thread-line-vertical {
        background: #000;
    }
    
    .toggle-replies-btn {
        border: 1px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .thread-line-vertical,
    .toggle-replies-btn,
    .replies-container,
    .chevron-icon {
        transition: none;
    }
    
    .comment-thread.parent-highlighted::after,
    .comment-thread.highlighted {
        animation: none;
    }
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    .thread-line-vertical,
    .toggle-replies-btn,
    .comment-actions {
        display: none;
    }
    
    .replies-container.is-hidden {
        max-height: none;
        opacity: 1;
        display: block;
    }
}

/* ============================================================================
   ACTION MENU (3 DOTS DROPDOWN)
   ============================================================================ */

.action-menu-wrapper {
    position: relative;
    display: inline-block;
    margin-left: auto;
}

.action-menu-btn {
    background: none;
    border: none;
    color: #718096;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 16px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

.action-menu-btn:hover {
    background: #f7fafc;
    color: #2d3748;
}

.action-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 150px;
    z-index: 1000;
    display: none;
    margin-top: 4px;
}

.action-menu.active {
    display: block;
    animation: menuFadeIn 0.2s ease-out;
}

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

.action-menu-item {
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #2d3748;
    transition: background 0.2s;
}

.action-menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.action-menu-item:last-child {
    border-radius: 0 0 8px 8px;
}

.action-menu-item:hover {
    background: #f7fafc;
}

.action-menu-item i {
    font-size: 14px;
}

.action-menu-item.delete-btn {
    color: #f56565;
}

.action-menu-item.delete-btn:hover {
    background: #fff5f5;
}

/* ============================================================================
   REPLY FORM
   ============================================================================ */

.reply-form-container {
    margin: 12px 0 0 28px;
    padding: 12px;
    background: var(--bg-secondary);

}

.reply-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reply-input-group {
    width: 100%;
}

.reply-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s;
}

.reply-textarea:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.reply-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-reply,
.btn-cancel {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-reply {
    background: #667eea;
    color: white;
}

.btn-reply:hover {
    background: #5568d3;
}

.btn-reply:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

.btn-cancel {
    background: #e2e8f0;
    color: #2d3748;
}

.btn-cancel:hover {
    background: #cbd5e0;
}

/* ============================================================================
   EDIT FORM
   ============================================================================ */

.edit-comment-form {
    margin-top: 8px;
    padding: 12px;
    background: #fffaf0;
    border-radius: 6px;
    border-left: 3px solid #ed8936;
}

.edit-textarea {
    width: 100%;
    min-height: 100px;
    padding: 10px 12px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 10px;
}

.edit-textarea:focus {
    outline: none;
    border-color: #ed8936;
    box-shadow: 0 0 0 3px rgba(237, 137, 54, 0.1);
}

.edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-save {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: #ed8936;
    color: white;
    transition: all 0.2s;
}

.btn-save:hover {
    background: #dd6b20;
}

.btn-save:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

/* ============================================================================
   EDITED BADGE
   ============================================================================ */

.edited-badge {
    font-size: 11px;
    color: #718096;
    font-style: italic;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.edited-badge i {
    font-size: 10px;
}

/* ============================================================================
   MOBILE RESPONSIVE FOR NEW ELEMENTS
   ============================================================================ */

@media (max-width: 768px) {
    .reply-form-container {
        margin-left: 40px;
        padding: 10px;
    }
    
    .action-menu {
        min-width: 130px;
    }
    
    .action-menu-item {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .edit-comment-form {
        padding: 10px;
    }
}

/* ============================================================================
   CAPTCHA STYLES
   ============================================================================ */

.captcha-section {
    margin: 12px 0;
}

.captcha-section.compact {
    margin: 10px 0;
}

.captcha-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 8px;
}

.captcha-field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.captcha-refresh {
    background: none;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    padding: 6px;
    cursor: pointer;
    color: #718096;
    transition: all 0.2s;
}

.captcha-refresh:hover {
    background: #f7fafc;
    border-color: #a0aec0;
}

