/* Enhanced Comment Section Styling */

/* Comment container */
.comments-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.comments-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #28a745, #20c997, #17a2b8);
}

/* Comment form styling */
.comment-form-container {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 1.5rem;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.comment-form-container:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.comment-form-container h5 {
    color: #2c3e50;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.comment-form .form-control {
    border-radius: 0.75rem;
    border: 2px solid #e9ecef;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
    background-color: #fff;
}

.comment-form .form-control:focus {
    border-color: #28a745;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);
    background-color: #fff;
}

.comment-form .form-control:hover {
    border-color: #20c997;
}

.comment-form .btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    border: none;
    border-radius: 0.75rem;
    padding: 0.75rem 2rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.comment-form .btn-success:hover {
    background: linear-gradient(135deg, #20c997 0%, #17a2b8 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(40, 167, 69, 0.3);
}

/* Individual comment styling */
.comment-item {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.comment-item:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
    border-color: #20c997;
}

.comment-item.comment-reply {
    margin-left: 2.5rem;
    border-left: 4px solid #28a745;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    position: relative;
}

.comment-item.comment-reply::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 1.5rem;
    width: 1.2rem;
    height: 2px;
    background: #28a745;
    z-index: 1;
}

.comment-item.comment-reply .comment-content {
    border-left: 3px solid #20c997;
    padding-left: 1rem;
    background: rgba(32, 201, 151, 0.05);
}

/* Second level indentation - deeper nesting */
.comment-item.comment-reply.comment-reply {
    margin-left: 5rem;
}

.comment-item.comment-reply.comment-reply::before {
    left: -1.8rem;
    width: 1.5rem;
}

/* Third level indentation - even deeper */
.comment-item.comment-reply.comment-reply.comment-reply {
    margin-left: 7.5rem;
}

.comment-item.comment-reply.comment-reply.comment-reply::before {
    left: -2.1rem;
    width: 1.8rem;
}

/* Comment header */
.comment-header {
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
}

/* Comment author */
.comment-author {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.comment-avatar img,
.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #20c997;
    object-fit: cover;
    transition: all 0.3s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.comment-avatar img:hover,
.avatar-placeholder:hover {
    border-color: #17a2b8;
    transform: scale(1.05);
}

.avatar-placeholder {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
}

/* Comment content */
.comment-content {
    line-height: 1.6;
    color: #495057;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    padding: 0.75rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 20%);
    border-radius: 0.5rem;
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
}

.comment-item:hover .comment-content {
    background: linear-gradient(135deg, #e9ecef 0%, #f8f9fa 20%);
    border-color: #20c997;
}

/* Reply form container */
.reply-form-container {
    margin-top: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 0.5rem;
    border-left: 3px solid #28a745;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    display: none; /* Hidden by default */
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.reply-form-container.show {
    display: block !important; /* Show when .show class is added */
    opacity: 1;
    transform: translateY(0);
    z-index: 10; /* Ensure it's above other elements */
    position: relative;
}

.reply-form .form-control {
    font-size: 0.875rem;
    border-radius: 0.5rem;
    border: 1px solid #dee2e6;
    background-color: #fff;
}

.reply-form .form-control:focus {
    border-color: #20c997;
    box-shadow: 0 0 0 0.2rem rgba(32, 201, 151, 0.25);
}

.reply-form .btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    border: none;
}

.reply-form .btn-success:hover {
    background: linear-gradient(135deg, #20c997 0%, #17a2b8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

/* Comment actions button styles */
.comment-actions .btn {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.comment-actions .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Nested replies - Enhanced threading system */
.comment-replies {
    margin-top: 1.5rem;
    padding-left: 2rem;
    position: relative;
}

.comment-replies::before {
    content: '';
    position: absolute;
    left: 1rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, #28a745, #20c997, #17a2b8);
    opacity: 0.3;
}

.comment-replies .comment-item {
    margin-bottom: 1rem;
    margin-top: 0;
    position: relative;
}

.comment-replies .comment-item::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 1.5rem;
    width: 1rem;
    height: 2px;
    background: #28a745;
}

/* Second level indentation for threaded discussions */
.comment-item.comment-reply.comment-reply {
    margin-left: 5rem;
}

.comment-item.comment-reply.comment-reply::before {
    left: -1.8rem;
    width: 1.3rem;
}

/* Third level and beyond */
.comment-item.comment-reply.comment-reply.comment-reply {
    margin-left: 7.5rem;
}

.comment-item.comment-reply.comment-reply.comment-reply::before {
    left: -2.1rem;
    width: 1.6rem;
}

/* Enhanced indentation system for main thread comments (all after first) */
.comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item) {
    margin-left: 2.5rem;
    border-left: 4px solid #28a745;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    position: relative;
}

.comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item)::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 1.5rem;
    width: 1.2rem;
    height: 2px;
    background: #28a745;
    z-index: 1;
}

.comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item) .comment-content {
    border-left: 3px solid #20c997;
    padding-left: 1rem;
    background: rgba(32, 201, 151, 0.05);
}

/* Empty state */
.comments-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 0.75rem;
    border: 2px dashed #dee2e6;
    margin: 1.5rem 0;
}

.comments-empty .fas {
    font-size: 3rem;
    color: #6c757d;
    opacity: 0.7;
    margin-bottom: 1rem;
}

.comments-empty p {
    color: #6c757d;
    font-size: 1rem;
    margin-top: 1rem;
    font-weight: 500;
}

/* Responsive design */
@media (max-width: 768px) {
    .comments-section {
        padding: 1.25rem;
        margin: 0 -15px;
        border-radius: 0;
        min-width: 100% !important;
    }

    .comment-item {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .comment-item.comment-reply {
        margin-left: 1.25rem;
    }

    .comment-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
    }

    .comment-actions {
        align-self: flex-end;
        margin-top: 0.25rem;
    }

    .comment-avatar img,
    .avatar-placeholder {
        width: 35px;
        height: 35px;
    }

    .comment-content {
        font-size: 0.875rem;
        padding: 0.625rem;
    }

    .reply-form-container {
        padding: 0.75rem;
        margin-left: -0.75rem;
        margin-right: -0.75rem;
    }

    .comment-replies {
        padding-left: 0.75rem;
    }

    .comment-form-container {
        padding: 1.25rem;
        margin-bottom: 1.25rem;
    }
}

/* Animations */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Safety text wrapping for long words/URLs */
.comment-content {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

/* Mobile responsiveness improvements for threaded comments */
@media (max-width: 768px) {
    /* Reduce connector lines and indentation */
    .comment-replies { padding-left: 0.5rem; }
    .comment-replies::before { display: none; }

    .comment-item.comment-reply { margin-left: 0.75rem; border-left-width: 3px; }
    .comment-item.comment-reply::before { left: -1rem; width: 0.75rem; }

    .comment-item.comment-reply.comment-reply { margin-left: 1.25rem; }
    .comment-item.comment-reply.comment-reply::before { left: -1.2rem; width: 0.9rem; }

    .comment-item.comment-reply.comment-reply.comment-reply { margin-left: 1.75rem; }
    .comment-item.comment-reply.comment-reply.comment-reply::before { left: -1.3rem; width: 1rem; }

    /* Reduce main thread offset for subsequent top-level comments */
    .comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item) {
        margin-left: 0.75rem;
        border-left-width: 3px;
    }
    .comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item)::before {
        left: -1rem;
        width: 0.75rem;
    }
}

@media (max-width: 576px) {
    /* On very small screens, remove indentation entirely to prevent overflow */
    .comment-item.comment-reply,
    .comment-item.comment-reply.comment-reply,
    .comment-item.comment-reply.comment-reply.comment-reply,
    .comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item) {
        margin-left: 0;
        border-left: none;
    }

    .comment-item.comment-reply::before,
    .comment-item.comment-reply.comment-reply::before,
    .comment-item.comment-reply.comment-reply.comment-reply::before,
    .comments-list .comment-item:nth-child(n+2):not(.comment-replies .comment-item)::before,
    .comment-replies::before {
        display: none;
    }

    .comment-actions { align-self: stretch; width: 100%; }
}