/* ============================================= */
/* COMMENT SYSTEM - MAIN OVERLAY & CONTAINER */
/* ============================================= */

/* Main overlay that covers entire screen */
.comment-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 1050;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Main comment popup container */
.comment-popup-container {
    width: 100%;
    max-width: 800px;
    height: 100%;
    background: white;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    animation: commentPopupSlideInMobile 0.35s ease-out;
    position: relative;
    overflow: hidden;
}

/* ============================================= */
/* DESKTOP SPECIFIC STYLES */
/* ============================================= */

@media (min-width: 769px) {
    /* Desktop overlay with padding and centered alignment */
    .comment-popup-overlay {
        padding: 1rem;
        align-items: center;
    }
    
    /* Desktop container with rounded corners and shadow */
    .comment-popup-container {
        height: 85vh;
        max-height: 700px;
        border-radius: 20px;
        box-shadow: 0 25px 80px rgba(0, 0, 0, 0.4);
        animation: commentPopupSlideIn 0.4s ease-out;
    }
}

/* ============================================= */
/* HEADER SECTION */
/* ============================================= */

/* Comment popup header with title and close button */
.comment-popup-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background: #fff;
    position: relative;
    z-index: 20;
}

/* Header title styling */
.comment-popup-header h4 {
    margin: 0;
    color: #1a1a1a;
    font-weight: 700;
    font-size: 1.25rem;
}

/* Close button styling */
.close-comment-popup {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin: -0.5rem;
    color: #666;
    transition: all 0.2s ease;
}

.close-comment-popup:hover {
    color: #333;
    transform: scale(1.1);
}

/* ============================================= */
/* MAIN BODY & COMMENTS LIST - SCROLL FIXED */
/* ============================================= */

/* Main body container - FIXED FOR SCROLL */
.comment-popup-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* CRITICAL FOR SCROLL */
    overflow: hidden;
}

/* Comments list container with scrolling - FIXED */
.comments-list-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    min-height: 0; /* CRITICAL FOR SCROLL */
    position: relative;
    padding-bottom: 100px;
}

/* Comments list wrapper */
.comments-list {
    min-height: min-content;
}

/* ============================================= */
/* STICKY COMMENT FORM SECTION - MOBILE FIXED */
/* ============================================= */

/* Sticky comment form at bottom */
.comment-form-sticky {
    flex-shrink: 0;
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #f0f0f0;
    background: rgba(255, 255, 255, 0.95);
    position: sticky;
    bottom: 0;
    z-index: 15;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
}

/* Sticky comment form wrapper */
.sticky-comment-form {
    background: #fff;
    padding: 1rem;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid #e8ecef;
}

/* Comment form buttons container - FIXED ALIGNMENT */
.comment-actions.mt-2 {
    margin-top: 0.75rem !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding: 0 0.25rem !important;
}

/* Submit comment button - FIXED ALIGNMENT */
.submit-comment {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.4rem !important;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
    min-height: 36px !important;
}

/* Cancel button - FIXED ALIGNMENT */
.cancel-comment {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
    min-height: 36px !important;
}

/* Icon alignment in form buttons - FIXED */
.submit-comment i,
.cancel-comment i {
    margin-right: 0.3rem !important;
    font-size: 0.8rem !important;
    line-height: 1 !important;
    vertical-align: middle !important;
}

/* ============================================= */
/* INPUT FIELDS STYLING */
/* ============================================= */

/* Comment and reply input fields */
.comment-input, .reply-input {
    border-radius: 20px;
    padding: 12px 16px;
    border: 1.5px solid #e8ecef;
    resize: none;
    transition: all 0.3s ease;
    font-size: 15px;
    line-height: 1.4;
    background: #fff;
}

/* Input focus states */
.comment-input:focus, .reply-input:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    outline: none;
    background: #fff;
}

/* ============================================= */
/* COMMENT & REPLY ITEMS - COMPACT MODERN */
/* ============================================= */

/* Individual comment item - COMPACT */
.comment-item {
    animation: slideInUp 0.3s ease;
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 12px;
    transition: all 0.2s ease;
    position: relative;
}

.comment-item:hover {
    background-color: #f8f9fa;
}

/* Remove container borders - use subtle divider */
.comment-item:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 3.5rem;
    right: 0.75rem;
    height: 1px;
    background: #f0f0f0;
}

/* Main comment content styling - COMPACT */
.comment-content {
    background: transparent;
    border-radius: 0;
    padding: 0;
    border-left: none;
    transition: all 0.2s ease;
}

.comment-content:hover {
    border-left-color: transparent;
    background-color: transparent !important;
    transform: none;
}

/* Reply item - COMPACT */
.reply-item {
    animation: slideInUp 0.3s ease;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background-color 0.2s ease;
}

.reply-item:hover {
    background-color: #f8f9fa;
}

/* Reply content styling - COMPACT */
.reply-content {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    margin-bottom: 0;
    transition: all 0.2s ease;
}

.reply-content:hover {
    border-color: transparent;
    background-color: transparent;
}

/* ============================================= */
/* ACTION BUTTONS STYLING - LIKE COUNTS FIXED */
/* ============================================= */

/* Action buttons container */
.comment-actions, .reply-actions {
    animation: fadeIn 0.3s ease;
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 0.5rem;
}

/* Like button with COUNT VISIBLE - MOBILE FIXED */
.like-comment-btn {
    text-decoration: none !important;
    border: none !important;
    background: none !important;
    transition: all 0.3s ease;
    padding: 0.3rem 0.6rem !important;
    font-size: 0.8rem !important;
    color: #666 !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.3rem !important;
    min-width: auto !important;
}

/* Like button active state */
.like-comment-btn.text-danger {
    color: #dc3545 !important;
}

.like-comment-btn:hover {
    transform: scale(1.05);
    background: rgba(0, 0, 0, 0.05) !important;
}

/* Like count visibility - FIXED FOR MOBILE & DESKTOP */
.like-comment-btn .fa-heart {
    font-size: 0.8rem !important;
    flex-shrink: 0;
}

.like-comment-btn span:not(.small-icon) {
    display: inline-block !important;
    font-size: 0.75rem;
    font-weight: 600;
    color: inherit;
    flex-shrink: 0;
}

/* General button hover effects */
.comment-btn, .reply-btn {
    transition: all 0.2s ease;
    position: relative;
}

.comment-btn:hover, .reply-btn:hover {
    transform: translateY(-1px);
}

/* Delete button specific styling */
.delete-comment-btn {
    transition: all 0.3s ease;
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem !important;
    border-radius: 8px;
    border: 1px solid #dc3545 !important;
    background: rgba(220, 53, 69, 0.1) !important;
    color: #dc3545 !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.3rem !important;
}

.delete-comment-btn:hover {
    background-color: #dc3545 !important;
    color: white !important;
    transform: scale(1.05);
}

/* Reply button styling */
.reply-btn {
    padding: 0.25rem 0.6rem !important;
    font-size: 0.75rem;
    border-radius: 8px;
    border: 1px solid #007bff !important;
    background: rgba(0, 123, 255, 0.1) !important;
    color: #007bff !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.3rem !important;
}

.reply-btn:hover {
    background: #007bff !important;
    color: white !important;
}

/* ============================================= */
/* REPLIES SECTION - COMPACT */
/* ============================================= */

/* Replies container with expand/collapse */
.replies-container {
    border-left: 2px solid #e9ecef;
    padding-left: 0.75rem;
    margin-left: 0.75rem;
    margin-top: 0.5rem;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
}

.replies-container.expanded {
    max-height: 2000px;
    padding-top: 0.5rem;
}

/* Expand/Collapse toggle button */
.replies-toggle-btn {
    background: rgba(0, 123, 255, 0.1);
    border: none;
    color: #007bff;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    margin: 0.5rem 0;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.replies-toggle-btn:hover {
    background-color: rgba(0, 123, 255, 0.2);
    color: #0056b3;
}

.replies-toggle-btn .fas {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
}

.replies-toggle-btn.expanded .fas {
    transform: rotate(180deg);
}

/* Reply count badge */
.reply-count-badge {
    background: #007bff;
    color: white;
    border-radius: 10px;
    padding: 0.1rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Reply form container */
.reply-form-container {
    animation: slideInDown 0.3s ease;
    background: #f8f9fa;
    padding: 0.75rem;
    border-radius: 8px;
    margin-top: 0.5rem;
    border: 1px solid #e8ecef;
}

/* Reply form buttons */
.reply-actions.mt-2 {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    margin-top: 0.5rem !important;
}

.submit-reply, .cancel-reply {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 0.3rem !important;
    padding: 0.4rem 0.8rem !important;
    font-size: 0.8rem !important;
}

/* ============================================= */
/* COMMENT COUNT BADGE */
/* ============================================= */

/* Comment count display badge */
.comment-count {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border-radius: 12px;
    padding: 3px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
    min-width: 20px;
    text-align: center;
}

/* ============================================= */
/* ANIMATIONS & TRANSITIONS */
/* ============================================= */

/* Mobile popup slide-in animation */
@keyframes commentPopupSlideInMobile {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Desktop popup slide-in animation */
@keyframes commentPopupSlideIn {
    from {
        opacity: 0;
        transform: translateY(50px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Fade in animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Slide up animation */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Slide down animation */
@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================= */
/* MOBILE RESPONSIVE DESIGN - ALL ISSUES FIXED */
/* ============================================= */

@media (max-width: 768px) {
    /* Mobile overlay adjustments */
    .comment-popup-overlay {
        padding: 0;
        align-items: flex-start;
    }
    
    /* Mobile container full screen */
    .comment-popup-container {
        height: 100vh;
        border-radius: 0;
        max-width: none;
        margin-top: 0;
    }
    
    /* Mobile header with safe area support */
    .comment-popup-header {
        padding: 1rem 1.25rem;
        padding-top: max(1rem, env(safe-area-inset-top, 1rem));
        border-radius: 0;
        background: linear-gradient(135deg, #fff 0%, #f8f9fa 100%);
        border-bottom: 1px solid #e8ecef;
    }
    
    /* Mobile comments list with SCROLL FIXED */
    .comments-list-container {
        padding: 1rem 1.25rem;
        padding-bottom: 180px; /* Reduced for better scroll */
        height: calc(100vh - 140px); /* Fixed height for scroll */
        flex: 1;
        min-height: 0;
    }
    
    /* Mobile replies container adjustments */
    .replies-container {
        margin-left: 0.5rem;
        padding-left: 0.75rem;
    }
    
    /* Mobile form styling */
    .sticky-comment-form {
        padding: 0.75rem;
        border-radius: 12px;
        box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
        border: 1px solid #e0e0e0;
    }
    
    /* Mobile input optimization */
    .comment-input, .reply-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 14px 16px;
        border-radius: 25px;
    }
    
    /* Mobile sticky form positioning */
    .comment-form-sticky {
        padding: 1rem 1.25rem;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        background: rgba(248, 249, 250, 0.95);
        border-top: 1px solid #e9ecef;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
    }
    
    /* MOBILE FORM BUTTONS - FIXED ALIGNMENT */
    .comment-actions.mt-2 {
        margin-top: 0.5rem !important;
        gap: 0.4rem !important;
        padding: 0 !important;
    }
    
    .submit-comment, .cancel-comment {
        padding: 0.5rem 0.8rem !important;
        font-size: 0.8rem !important;
        min-height: 38px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0.3rem !important;
    }
    
    .submit-comment i, .cancel-comment i {
        margin-right: 0.2rem !important;
        font-size: 0.75rem !important;
    }
    
    /* MOBILE ACTION BUTTONS - LIKE COUNTS VISIBLE */
    .comment-actions .btn-sm .d-none.d-sm-inline,
    .reply-actions .btn-sm .d-none.d-sm-inline {
        display: none !important;
    }
    
    .comment-actions .btn-sm,
    .reply-actions .btn-sm {
        padding: 0.4rem 0.5rem !important;
        min-width: 36px;
        height: 32px;
        justify-content: center;
    }
    
    .comment-actions .btn-sm i,
    .reply-actions .btn-sm i {
        margin-right: 0 !important;
    }
    
    /* LIKE BUTTON MOBILE - COUNTS VISIBLE */
    .like-comment-btn {
        padding: 0.4rem 0.5rem !important;
        min-width: 50px !important;
        height: 32px;
        justify-content: center;
        gap: 0.2rem !important;
    }
    
    .like-comment-btn span:not(.small-icon) {
        display: inline-block !important; /* SHOW COUNTS ON MOBILE */
        font-size: 0.7rem !important;
        font-weight: 600;
    }
    
    /* Better touch targets for mobile */
    .like-comment-btn, .reply-btn, .delete-comment-btn {
        min-height: 36px;
        min-width: 36px;
    }
    
    /* Mobile keyboard handling */
    .keyboard-open .comment-form-sticky {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
    }
    
    .keyboard-open .comments-list-container {
        padding-bottom: 220px; /* Extra space when keyboard is open */
    }
    
    /* More compact comment items on mobile */
    .comment-item {
        margin-bottom: 0.75rem;
        padding: 0.6rem;
    }
    
    .comment-item:not(:last-child)::after {
        left: 3rem;
        right: 0.5rem;
        bottom: -0.4rem;
    }
    
    /* Mobile avatar sizes */
    .comment-item .rounded-circle {
        width: 36px !important;
        height: 36px !important;
    }
    
    .reply-item .rounded-circle {
        width: 30px !important;
        height: 30px !important;
    }
}

/* ============================================= */
/* SCROLLBAR STYLING */
/* ============================================= */

/* Custom scrollbar for comments list */
.comments-list-container::-webkit-scrollbar {
    width: 6px;
}

.comments-list-container::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 10px;
}

.comments-list-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 10px;
}

.comments-list-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ============================================= */
/* AVATAR & IMAGE STYLING */
/* ============================================= */

/* Circular avatar images */
.rounded-circle {
    object-fit: cover;
    flex-shrink: 0;
}

/* Comment avatar size */
.comment-item .rounded-circle {
    width: 40px !important;
    height: 40px !important;
}

/* Reply avatar size */
.reply-item .rounded-circle {
    width: 32px !important;
    height: 32px !important;
}

/* ============================================= */
/* LOADING & EMPTY STATES */
/* ============================================= */

/* Loading spinner */
.spinner-border {
    width: 1.5rem;
    height: 1.5rem;
}

/* Empty state styling */
.text-center.py-4 {
    padding: 3rem 1rem !important;
}

/* ============================================= */
/* TEXT & CONTENT STYLING */
/* ============================================= */

/* Comment text styling */
.comment-content p {
    margin: 0.25rem 0 0.5rem 0;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #333;
    word-wrap: break-word;
}

/* Reply text styling */
.reply-content p {
    margin: 0.15rem 0 0.3rem 0;
    font-size: 0.85rem;
    line-height: 1.3;
    color: #333;
    word-wrap: break-word;
}

/* Username styling */
.comment-content h6 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    color: #1a1a1a;
}

.reply-content h6 {
    font-size: 0.85rem;
    font-weight: 600;
    margin: 0;
    color: #1a1a1a;
}

/* Time text */
.text-muted {
    font-size: 0.75rem;
    color: #666;
}

/* ============================================= */
/* ICON SIZE FIXES */
/* ============================================= */

/* Small icon sizing for all action buttons */
.small-icon {
    font-size: 0.75rem !important;
}

/* Button size consistency */
.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.2;
}

/* Icon alignment in buttons */
.btn-sm i {
    vertical-align: middle !important;
    line-height: 1 !important;
}