/**
 * Universal Comments System Styles
 * Mobile-first, cross-platform design
 * Separated from engagement.css for modularity
 */

/* ============== CSS VARIABLES ============== */
:root {
    --comment-primary: #ff6b00;
    --comment-primary-light: #fff8f0;
    --comment-primary-dark: #e55a00;
    --comment-text: #1f2937;
    --comment-text-muted: #6b7280;
    --comment-border: #e5e7eb;
    --comment-bg: #ffffff;
    --comment-radius: 12px;
    --comment-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ============== COMMENTS SECTION ============== */
.comments-section {
    background: var(--comment-bg);
    border-radius: var(--comment-radius);
    padding: 1rem;
    margin-top: 1rem;
    transition: all 0.3s ease;
}

/* Expanded state - for mobile overlay */
@media (max-width: 768px) {
    .comments-section.comments-expanded {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        border-radius: 0;
        overflow-y: auto;
        padding: 1rem;
        padding-top: 3rem;
        background: var(--comment-bg);
    }
    
    .comments-section.comments-expanded::before {
        content: '×';
        position: fixed;
        top: 0.75rem;
        right: 1rem;
        font-size: 2rem;
        color: var(--comment-text-muted);
        cursor: pointer;
        z-index: 1001;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--comment-bg);
        border-radius: 50%;
        box-shadow: var(--comment-shadow);
    }
}

/* ============== COMMENT ITEM ============== */
.comment-item {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--comment-border);
}

.comment-item:last-child {
    border-bottom: none;
}

.comment-flex {
    display: flex;
    gap: 0.75rem;
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

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

.comment-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.25rem;
}

.comment-author {
    font-weight: 600;
    color: var(--comment-text);
    font-size: 0.9rem;
}

.comment-time {
    font-size: 0.75rem;
    color: var(--comment-text-muted);
}

.reply-indicator {
    font-size: 0.7rem;
    color: var(--comment-primary);
}

.comment-text {
    margin: 0.5rem 0;
    color: var(--comment-text);
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

/* ============== NESTED REPLIES ============== */
.comment-item.reply-item {
    margin-left: 0.5rem;
    padding-left: 0.75rem;
    border-left: 3px solid var(--comment-primary);
    background: var(--comment-primary-light);
    border-radius: 0 var(--comment-radius) var(--comment-radius) 0;
    margin-top: 0.5rem;
}

.comment-item.reply-level-1 { border-left-color: #ff6b00; }
.comment-item.reply-level-2 { border-left-color: #ff8533; margin-left: 0.25rem; }
.comment-item.reply-level-3 { border-left-color: #ffa366; margin-left: 0.25rem; }

.replies-container {
    margin-top: 0.5rem;
}

/* Mobile: Less nesting indentation */
@media (max-width: 480px) {
    .comment-item.reply-item {
        margin-left: 0.25rem;
        padding-left: 0.5rem;
    }
    
    .comment-avatar {
        width: 32px;
        height: 32px;
    }
    
    .comment-item.reply-level-2 .comment-avatar,
    .comment-item.reply-level-3 .comment-avatar {
        width: 28px;
        height: 28px;
    }
}

/* ============== COMMENT ACTIONS ============== */
.comment-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.comment-action-btn {
    background: transparent;
    border: none;
    color: var(--comment-text-muted);
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    text-decoration: none !important;
    min-height: 32px;
}

/* Reaction buttons - remove underline */
.reaction-btn {
    background: transparent;
    border: none;
    color: var(--comment-text-muted);
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex !important;
    align-items: center;
    gap: 0.25rem;
    text-decoration: none !important;
    min-height: 32px;
    visibility: visible !important;
    opacity: 1 !important;
}

.reaction-btn:hover {
    color: var(--comment-primary);
    background: var(--comment-primary-light);
    text-decoration: none !important;
}

.reaction-btn.active {
    color: var(--comment-primary);
    font-weight: 600;
    text-decoration: none !important;
}

/* Comment action bar styling */
.comment-action-bar {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Override Bootstrap btn-link underlines */
.comment-like-btn,
.reply-btn,
.emoji-picker-btn,
.btn.btn-link {
    text-decoration: none !important;
    color: var(--comment-text-muted) !important;
    display: inline-flex !important;
    visibility: visible !important;
}

/* Force visibility of all comment elements including emoji button */
.comment-card .comment-header,
.comment-card .comment-header *,
.comment-card .comment-action-bar,
.comment-card .comment-action-bar *,
.comment-card .dropdown,
.comment-card .dropdown *,
.comment-card .reaction-btn,
.comment-card .btn-outline-secondary,
.comment-card .emoji-picker-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.comment-card .comment-action-bar,
.comment-card .reaction-btn,
.comment-card .btn-outline-secondary,
.comment-card .emoji-picker-btn {
    display: inline-flex !important;
}

/* Special handling for newly added comments */
.comment-card.newly-added-comment,
.comment-card.newly-added-comment * {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
}

.comment-card.newly-added-comment .comment-action-bar,
.comment-card.newly-added-comment .reaction-btn,
.comment-card.newly-added-comment .btn-outline-secondary,
.comment-card.newly-added-comment .emoji-picker-btn {
    display: inline-flex !important;
}

.comment-like-btn:hover,
.reply-btn:hover,
.emoji-picker-btn:hover,
.btn.btn-link:hover {
    text-decoration: none !important;
    color: var(--comment-primary) !important;
    background-color: var(--comment-primary-light) !important;
}

.comment-like-btn.active,
.reply-btn.active,
.emoji-picker-btn.active {
    color: var(--comment-primary) !important;
    text-decoration: none !important;
}

.comment-action-btn:hover {
    color: var(--comment-primary);
    background: var(--comment-primary-light);
}

.comment-action-btn.active,
.comment-action-btn.liked {
    color: var(--comment-primary);
}

/* Touch-friendly on mobile */
@media (max-width: 768px) {
    .comment-action-btn {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
    }
}

/* ============== COMMENT IMAGES ============== */
.comment-image {
    max-width: 200px;
    max-height: 150px;
    width: auto;
    height: auto;
    object-fit: cover;
    border-radius: 8px;
    margin: 0.5rem 0;
    border: 3px solid var(--comment-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: block;
}

.comment-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(255, 107, 0, 0.3);
}

.comment-gif {
    max-width: 180px;
    max-height: 140px;
    border-radius: 8px;
    margin: 0.5rem 0;
    border: 3px solid var(--comment-primary);
    display: block;
}

/* Mobile: Smaller images */
@media (max-width: 480px) {
    .comment-image {
        max-width: 150px;
        max-height: 120px;
    }
    
    .comment-gif {
        max-width: 140px;
        max-height: 110px;
    }
}

/* ============== REACTIONS ============== */
.comment-reactions {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    margin: 0.25rem 0;
}

.reaction-badge {
    background: var(--comment-primary-light);
    border: 1px solid var(--comment-primary);
    border-radius: 12px;
    padding: 0.15rem 0.5rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reaction-badge:hover {
    background: var(--comment-primary);
    color: white;
}

/* ============== EMOJI PICKER ============== */
.emoji-picker-popup {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 2px solid var(--comment-primary);
    border-radius: var(--comment-radius);
    padding: 0.5rem;
    box-shadow: 0 4px 16px rgba(255, 107, 0, 0.3);
    z-index: 1050;
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    max-width: 260px;
    min-width: 200px;
}

/* Ensure emoji picker button has relative positioning */
.emoji-picker-btn,
[data-emoji-comment] {
    position: relative;
}

.emoji-btn {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    padding: 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1;
}

.emoji-btn:hover {
    background: var(--comment-primary-light);
    transform: scale(1.2);
}

.insert-emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    padding: 0.5rem;
    background: white;
    border: 2px solid var(--comment-primary);
    border-radius: var(--comment-radius);
    max-width: 300px;
}

.emoji-insert-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    padding: 0.25rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.emoji-insert-btn:hover {
    background: var(--comment-primary-light);
    transform: scale(1.15);
}

/* Mobile emoji picker */
@media (max-width: 480px) {
    .emoji-picker-popup,
    .insert-emoji-grid {
        max-width: calc(100vw - 2rem);
        left: 0;
        transform: none;
        right: auto;
    }
}

/* ============== GIF PICKER ============== */
.gif-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none; /* Hidden by default - only show when active */
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.gif-picker-overlay.active {
    display: flex; /* Only show when active class is present */
}

.gif-picker-modal {
    background: white;
    border-radius: var(--comment-radius);
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.gif-picker-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--comment-border);
}

.gif-search-input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--comment-border);
    border-radius: 8px;
    font-size: 1rem;
}

.gif-search-input:focus {
    outline: none;
    border-color: var(--comment-primary);
}

.gif-picker-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--comment-text-muted);
    padding: 0.5rem;
}

.gif-results {
    padding: 0.5rem;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
    max-height: 50vh;
}

.gif-result {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.gif-result:hover {
    transform: scale(1.05);
    border-color: var(--comment-primary);
}

/* Mobile GIF picker */
@media (max-width: 480px) {
    .gif-picker-modal {
        max-height: 90vh;
        border-radius: var(--comment-radius) var(--comment-radius) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: none;
    }
    
    .gif-results {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============== REPLY FORM ============== */
.inline-reply-form {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--comment-primary-light);
    border-radius: var(--comment-radius);
    border: 2px solid var(--comment-primary);
}

.reply-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--comment-border);
    border-radius: 8px;
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
    font-size: 0.95rem;
}

.reply-textarea:focus {
    outline: none;
    border-color: var(--comment-primary);
}

.reply-form-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.reply-attachments {
    display: flex;
    gap: 0.25rem;
}

.reply-action-btn {
    background: white;
    border: 2px solid var(--comment-primary);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--comment-primary);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.reply-action-btn:hover {
    background: var(--comment-primary);
    color: white;
}

.reply-form-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-cancel {
    background: transparent;
    border: 2px solid var(--comment-border);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--comment-text-muted);
}

.btn-submit {
    background: var(--comment-primary);
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: white;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-submit:hover {
    background: var(--comment-primary-dark);
}

.btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Mobile reply form */
@media (max-width: 480px) {
    .reply-form-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .reply-attachments,
    .reply-form-actions {
        justify-content: center;
    }
}

/* ============== ATTACHMENT PREVIEW ============== */
.attachment-preview,
.attachment-preview-container {
    margin: 0.5rem 0;
}

.attachment-preview {
    position: relative;
    display: inline-block;
    padding: 0.25rem;
    background: var(--comment-primary-light);
    border: 2px dashed var(--comment-primary);
    border-radius: 8px;
}

.attachment-preview img {
    max-width: 100px;
    max-height: 80px;
    border-radius: 6px;
    display: block;
}

.remove-attachment {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--comment-primary);
    color: white;
    border: 2px solid white;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.remove-attachment:hover {
    background: var(--comment-primary-dark);
}

/* ============== MAIN COMMENT FORM ============== */
#comment-form {
    background: var(--comment-bg);
    border: 1px solid var(--comment-border);
    border-radius: var(--comment-radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

#comment-form textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--comment-border);
    border-radius: 8px;
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

#comment-form textarea:focus {
    outline: none;
    border-color: var(--comment-primary);
}

.comment-emoji-picker-container {
    margin-bottom: 0.5rem;
}

.comment-attachments {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.emoji-btn,
.gif-btn,
.image-btn {
    background: var(--comment-primary-light);
    border: 2px solid var(--comment-primary);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--comment-primary);
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    text-decoration: none !important;
}

.emoji-btn:hover,
.gif-btn:hover,
.image-btn:hover {
    background: var(--comment-primary);
    color: white;
}

.submit-comment-btn {
    background: var(--comment-primary) !important;
    border-color: var(--comment-primary) !important;
}

.submit-comment-btn:hover {
    background: var(--comment-primary-dark) !important;
}

/* Mobile comment form */
@media (max-width: 480px) {
    #comment-form {
        padding: 0.75rem;
    }
    
    .comment-attachments {
        justify-content: center;
        margin-bottom: 0.5rem;
    }
}

/* ============== NO COMMENTS MESSAGE ============== */
.no-comments-message {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--comment-text-muted);
    font-style: italic;
    background: #f9fafb;
    border-radius: var(--comment-radius);
    border: 2px dashed var(--comment-border);
}

/* ============== TOAST NOTIFICATIONS ============== */
.comment-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--comment-text);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--comment-radius);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 10001;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
}

.comment-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.comment-toast-success {
    background: #10b981;
}

.comment-toast-error {
    background: #ef4444;
}

/* Mobile toast */
@media (max-width: 768px) {
    .comment-toast {
        bottom: 80px;
        left: 1rem;
        right: 1rem;
        transform: translateY(100px);
        max-width: none;
    }
    
    .comment-toast.show {
        transform: translateY(0);
    }
}

/* ============== IMAGE LIGHTBOX ============== */
.comment-image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: none; /* Hidden by default - only show when active */
    align-items: center;
    justify-content: center;
    z-index: 10002;
    cursor: zoom-out;
    padding: 1rem;
}

.comment-image-lightbox.active {
    display: flex; /* Only show when active class is present */
}

.comment-image-lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    border: 4px solid var(--comment-primary);
}

/* ============== COMMENT-ITEM STRUCTURE (FALLBACK) ============== */
/* Special handling for comment-item structure (fallback) */
.comment-item .comment-action-bar,
.comment-item .reaction-btn,
.comment-item .btn-outline-secondary,
.comment-item .emoji-picker-btn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.comment-item .comment-action-bar *,
.comment-item .reaction-btn *,
.comment-item .btn-outline-secondary *,
.comment-item .emoji-picker-btn * {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Force visibility of emoji button in all comment structures */
.comment-card .emoji-picker-btn,
.comment-item .emoji-picker-btn {
    display: inline-flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    margin-left: 8px;
}

.comment-item .comment-flex {
    display: flex !important;
    gap: 0.75rem;
}

.comment-item .comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.comment-item .comment-content {
    flex: 1;
}

.comment-item .comment-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.comment-item .comment-text {
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

