/**
 * Inline Comments Styles
 * 
 * Requirements: 4.3, 4.4
 */

/* Paragraph wrapper for positioning */
.inline-comment-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
    padding-right: 48px; /* Space for indicator on desktop */
}

/* Comment indicator button */
.inline-comment-indicator {
    position: absolute;
    right: -40px;
    top: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
}

.inline-comment-wrapper:hover .inline-comment-indicator {
    opacity: 1;
}

.inline-comment-indicator:hover {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--primary, #3b82f6);
}

.inline-comment-indicator.has-comments {
    opacity: 1;
    background: var(--primary-light, #dbeafe);
    color: var(--primary, #3b82f6);
}

.inline-comment-indicator .comment-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--primary, #3b82f6);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}

/* Comment panel */
.inline-comment-panel {
    position: absolute;
    right: -360px;
    top: 0;
    width: 300px;
    background: white;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    z-index: 100;
    animation: slideIn 0.2s ease;
}

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

.comment-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.comment-panel-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #111827);
}

.close-panel {
    background: none;
    border: none;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-panel:hover {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-primary, #111827);
}

.comment-panel-body {
    max-height: 500px;
    overflow-y: auto;
}

/* Comments list */
.comments-list {
    padding: 1rem;
}

.no-comments {
    color: var(--text-muted, #6b7280);
    font-size: 0.875rem;
    text-align: center;
    padding: 2rem 1rem;
}

/* Comment item */
.comment-item {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

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

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

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

.comment-header .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comment-header .avatar.avatar--sm {
    width: 32px;
    height: 32px;
}

.comment-header .avatar__placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light, #dbeafe);
    color: var(--primary, #3b82f6);
    font-weight: 600;
    font-size: 0.875rem;
}

.comment-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.comment-author {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary, #111827);
}

.comment-date {
    font-size: 0.75rem;
    color: var(--text-muted, #6b7280);
}

.comment-content {
    font-size: 0.875rem;
    color: var(--text-secondary, #374151);
    line-height: 1.5;
    margin-bottom: 0.5rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

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

.comment-actions button {
    background: none;
    border: none;
    color: var(--text-muted, #6b7280);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s ease;
}

.comment-actions button:hover {
    color: var(--primary, #3b82f6);
}

.comment-actions .btn-delete:hover {
    color: var(--danger, #ef4444);
}

/* Nested replies */
.comment-replies {
    margin-top: 0.75rem;
    margin-left: 2.5rem;
    padding-left: 0.75rem;
    border-left: 2px solid var(--border, #e5e7eb);
}

.comment-reply {
    margin-bottom: 0.75rem;
}

.comment-reply:last-child {
    margin-bottom: 0;
}

.comment-reply .comment-avatar {
    width: 28px;
    height: 28px;
}

.comment-reply .avatar {
    width: 32px;
    height: 32px;
}

/* Comment form */
.comment-form {
    padding: 1rem;
    border-top: 1px solid var(--border, #e5e7eb);
    display: flex;
    gap: 0.75rem;
}

.comment-form__avatar {
    flex-shrink: 0;
}

.comment-form__avatar .avatar {
    width: 40px;
    height: 40px;
}

.comment-form__input {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.comment-input,
.reply-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.2s ease;
}

.comment-input:focus,
.reply-input:focus {
    outline: none;
    border-color: var(--primary, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.comment-form__actions,
.reply-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.comment-form__actions button,
.reply-form-actions button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-cancel-reply {
    background: transparent;
    color: var(--text-secondary, #374151);
}

.btn-cancel-reply:hover {
    background: var(--bg-secondary, #f3f4f6);
}

.btn-submit,
.btn-submit-reply {
    background: var(--primary, #3b82f6);
    color: white;
}

.btn-submit:hover,
.btn-submit-reply:hover {
    background: var(--primary-dark, #2563eb);
}

.btn-submit:disabled,
.btn-submit-reply:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Reply form */
.reply-form {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-secondary, #f9fafb);
    border-radius: 6px;
    display: flex;
    gap: 0.75rem;
}

.reply-form .comment-form__avatar .avatar {
    width: 32px;
    height: 32px;
}

.reply-form .reply-input {
    background: white;
}

/* Mobile responsive */
@media (max-width: 1024px) {
    .inline-comment-wrapper {
        padding-right: 44px; /* Adjust for tablet */
    }
    
    .inline-comment-indicator {
        right: -36px;
    }

    .inline-comment-panel {
        position: fixed;
        right: 0;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        animation: slideUp 0.3s ease;
        z-index: 1001;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .comment-panel-body {
        max-height: calc(70vh - 60px);
    }
}

@media (max-width: 768px) {
    /* Fix wrapper to not break mobile layout */
    .inline-comment-wrapper {
        position: relative;
        margin-right: 0;
        margin-bottom: 1.5rem;
        padding-right: 0; /* Remove desktop padding */
        display: flex;
        align-items: flex-start;
        gap: 8px;
        min-height: 44px; /* Minimum height for touch target */
    }

    /* Make indicator inline and touch-friendly */
    .inline-comment-indicator {
        position: relative;
        display: inline-flex;
        flex-shrink: 0;
        right: auto;
        top: 2px;
        margin-left: 0;
        opacity: 1;
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    /* Paragraph takes remaining space and can grow */
    .inline-comment-wrapper > p {
        flex: 1;
        margin: 0;
        min-height: 0; /* Allow paragraph to be smaller than 44px if needed */
    }

    /* Panel positioning for mobile */
    .inline-comment-panel {
        position: fixed;
        right: 0;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        max-height: 80vh;
        border-radius: 16px 16px 0 0;
        z-index: 1001;
    }

    .comment-replies {
        margin-left: 1rem;
        padding-left: 0.5rem;
    }

    /* Adjust comment form for mobile */
    .comment-form {
        padding: 0.75rem;
    }

    .comment-form__avatar .avatar {
        width: 32px;
        height: 32px;
    }

    /* Smaller avatars on mobile */
    .comment-header .avatar {
        width: 32px;
        height: 32px;
    }

    /* Better spacing for mobile */
    .comments-list {
        padding: 0.75rem;
    }

    .comment-item {
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
    }
}

/* Dark mode support */
[data-theme="dark"] .inline-comment-panel {
    background: var(--bg-primary-dark, #1f2937);
    border-color: var(--border-dark, #374151);
}

[data-theme="dark"] .comment-panel-header {
    border-bottom-color: var(--border-dark, #374151);
}

[data-theme="dark"] .comment-form {
    border-top-color: var(--border-dark, #374151);
}

[data-theme="dark"] .comment-input,
[data-theme="dark"] .reply-input {
    background: var(--bg-secondary-dark, #111827);
    border-color: var(--border-dark, #374151);
    color: var(--text-primary-dark, #f9fafb);
}

[data-theme="dark"] .reply-form {
    background: var(--bg-secondary-dark, #111827);
}

[data-theme="dark"] .reply-form .reply-input {
    background: var(--bg-primary-dark, #1f2937);
}
