/* ================================================
   PAPER COMMENTS SYSTEM STYLES
   Nested comment threads with Markdown support
   ================================================ */

/* ================================================
   COMMENT OVERLAY
   ================================================ */
#comment-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
    backdrop-filter: blur(4px);
}

#comment-overlay.show {
    display: flex;
}

/* ================================================
   COMMENT CARD (Main Container)
   ================================================ */
.comment-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 1100px;
    width: 95%;
    height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ================================================
   COMMENT CARD HEADER
   ================================================ */
.comment-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-gray);
}

.comment-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    line-height: 1;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
}

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

/* ================================================
   PAPER INFO SECTION
   ================================================ */
.comment-paper-info {
    flex: 1;
    padding-right: 16px;
}

#comment-paper-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    line-height: 1.4;
}

#comment-paper-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

#comment-paper-meta .badge {
    font-size: 11px;
    padding: 3px 8px;
}

.comment-author {
    font-size: 13px;
    color: var(--text-secondary);
}

#comment-paper-links {
    display: flex;
    gap: 8px;
}

#comment-paper-links .paper-link {
    font-size: 12px;
    padding: 4px 10px;
}

/* ================================================
   COMMENT FORM (Main Input)
   ================================================ */
.comment-form-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-white);
    flex-shrink: 0;
}

.comment-form-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.comment-textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    transition: all 0.2s;
    background: var(--bg-white);
    color: var(--text-primary);
}

.comment-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

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

.comment-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.char-count {
    font-size: 12px;
    color: var(--text-muted);
}

.comment-form-buttons {
    display: flex;
    gap: 8px;
}

.comment-submit-btn {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.comment-cancel-btn {
    padding: 8px 16px;
    background: var(--bg-gray);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.comment-cancel-btn:hover {
    background: var(--border-light);
}

/* ================================================
   MESSAGE DISPLAY
   ================================================ */
.comment-message {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
    display: none;
}

.comment-message.success {
    background: #F0FDF4;
    color: #16A34A;
    border: 1px solid #BBF7D0;
    display: block;
}

.comment-message.error {
    background: #FEF2F2;
    color: #DC2626;
    border: 1px solid #FECACA;
    display: block;
}

/* ================================================
   COMMENT BODY (Unified Scrollable Container)
   ================================================ */
.comment-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.comment-body::-webkit-scrollbar {
    width: 8px;
}

.comment-body::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 4px;
}

.comment-body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.comment-body::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ================================================
   COMMENTS CONTAINER
   ================================================ */
.comments-section {
    padding: 20px 24px;
    background: var(--bg-gray);
    flex: 1;
}

.comments-section h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#comments-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Loading State */
.comments-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.comments-loading .loading-spinner {
    margin: 0 auto 16px;
}

/* No Comments State */
.no-comments {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    background: var(--bg-gray);
    border-radius: var(--radius-md);
}

/* ================================================
   COMMENT NODE (Individual Comment)
   ================================================ */
.comment-node {
    position: relative;
    padding: 16px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.comment-node:hover {
    border-color: var(--border);
}

/* Nesting Indentation */
.comment-node.depth-0 {
    margin-left: 0;
}

.comment-node.depth-1 {
    margin-left: 24px;
    border-left: 3px solid var(--primary-light);
}

.comment-node.depth-2 {
    margin-left: 48px;
    border-left: 3px solid #A78BFA;
}

.comment-node.depth-3 {
    margin-left: 72px;
    border-left: 3px solid #C4B5FD;
}

.comment-node.depth-4 {
    margin-left: 96px;
    border-left: 3px solid #DDD6FE;
}

/* Comment Header */
.comment-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.comment-author-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
}

.comment-date {
    font-size: 12px;
    color: var(--text-muted);
}

/* Comment Content */
.comment-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
}

.comment-content.deleted {
    color: var(--text-muted);
    font-style: italic;
}

/* Markdown Styles */
.comment-content strong {
    font-weight: 600;
}

.comment-content em {
    font-style: italic;
}

.comment-content del {
    text-decoration: line-through;
    opacity: 0.7;
}

.comment-content code {
    background: var(--bg-gray);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
}

.comment-content .code-block {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    overflow-x: auto;
    margin: 8px 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.comment-content a {
    color: var(--primary);
    text-decoration: none;
}

.comment-content a:hover {
    text-decoration: underline;
}

/* Headers in comments */
.comment-content .comment-h1 {
    font-size: 1.4em;
    font-weight: 700;
    color: var(--text-primary);
    margin: 16px 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.comment-content .comment-h2 {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--text-primary);
    margin: 12px 0 6px 0;
}

.comment-content .comment-h3 {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 10px 0 4px 0;
}

/* Math expressions */
.comment-content .math-inline {
    font-family: 'Times New Roman', 'Cambria Math', serif;
    font-style: italic;
    background: var(--primary-bg);
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--primary-dark);
}

.comment-content .math-block {
    display: block;
    font-family: 'Times New Roman', 'Cambria Math', serif;
    font-style: italic;
    font-size: 1.1em;
    text-align: center;
    background: var(--primary-bg);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin: 8px 0;
    color: var(--primary-dark);
    border-left: 3px solid var(--primary);
}

/* Lists in comments */
.comment-content .comment-ul,
.comment-content .comment-ol {
    margin: 8px 0;
    padding-left: 24px;
}

.comment-content .comment-li,
.comment-content .comment-oli {
    margin: 4px 0;
}

/* Blockquotes */
.comment-content .comment-quote {
    margin: 8px 0;
    padding: 8px 16px;
    background: var(--bg-gray);
    border-left: 3px solid var(--primary-light);
    color: var(--text-secondary);
    font-style: italic;
}

/* Horizontal rule */
.comment-content .comment-hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}

/* Comment Actions */
.comment-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-light);
}

.comment-action-btn {
    background: none;
    border: none;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

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

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

.comment-action-btn.edit-btn {
    color: var(--text-secondary);
}

.comment-action-btn.edit-btn:hover {
    background: var(--bg-gray);
    color: var(--text-primary);
}

.comment-action-btn.delete-btn {
    color: #DC2626;
}

.comment-action-btn.delete-btn:hover {
    background: #FEF2F2;
}

/* Comment Children Container */
.comment-children {
    margin-top: 8px;
}

/* ================================================
   INLINE FORMS (Reply/Edit)
   ================================================ */
.reply-form-container,
.edit-form-container {
    margin-top: 12px;
}

.inline-comment-form {
    background: var(--bg-gray);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.inline-comment-form .comment-textarea {
    min-height: 60px;
}

/* ================================================
   COMMENT BUTTON (In Paper Cards)
   ================================================ */
.comment-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-gray);
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.comment-btn:hover {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.comment-btn .comment-icon {
    font-size: 14px;
}

/* ================================================
   RESPONSIVE DESIGN
   ================================================ */
@media (max-width: 768px) {
    #comment-overlay {
        padding: 20px 10px;
    }

    .comment-card {
        max-height: calc(100vh - 40px);
    }

    .comment-card-header {
        padding: 16px;
        flex-direction: column;
        gap: 12px;
    }

    .comment-close-btn {
        position: absolute;
        top: 12px;
        right: 12px;
    }

    .comment-paper-info {
        padding-right: 40px;
    }

    #comment-paper-title {
        font-size: 16px;
    }

    .comment-form-section {
        padding: 16px;
    }

    .comments-section {
        padding: 16px;
    }

    /* Reduce nesting on mobile */
    .comment-node.depth-1,
    .comment-node.depth-2,
    .comment-node.depth-3,
    .comment-node.depth-4 {
        margin-left: 16px;
    }

    .comment-form-footer {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .comment-form-buttons {
        width: 100%;
    }

    .comment-form-buttons button {
        flex: 1;
    }
}

@media (max-width: 480px) {
    #comment-paper-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .comment-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .comment-actions {
        flex-wrap: wrap;
    }
}
