/* Thread Popup Overlay */
.thread-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5); z-index: 1000;
    padding: 0; backdrop-filter: blur(2px);
    align-items: center; justify-content: center; overflow: hidden;
}
.thread-overlay.open { display: flex; }

/* Modal */
.thread-modal {
    background: var(--color-surface); border-radius: var(--radius-md);
    width: 100%; max-width: 700px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    position: relative; animation: modalSlideIn 0.2s ease;
    height: 100%; max-height: 85vh; 
    display: flex; flex-direction: column; overflow: hidden;
    margin: 0;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.thread-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--color-border);
    background: var(--color-surface); z-index: 10; flex-shrink: 0;
}
.thread-header-title { font-size: 1.125rem; font-weight: 600; color: var(--color-text); }

.thread-action-btn, .thread-close-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; background: none; border: none;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--color-text-muted);
    transition: background 0.15s, color 0.15s;
}
.thread-action-btn:hover, .thread-close-btn:hover { background: var(--color-hover); color: var(--color-text); }
.thread-action-btn svg, .thread-close-btn svg { width: 22px; height: 22px; }

/* Main Body Layout */
.thread-body { 
    display: flex; flex-direction: column; flex: 1; 
    overflow: hidden; padding: 0; position: relative;
}

/* Scrollable Content Area */
.thread-content-scroll {
    flex: 1; overflow-y: auto; padding: 20px;
}

/* Post Layout */
.thread-post { margin-bottom: 20px; }
.thread-post .post-header { 
    display: flex; align-items: flex-start; gap: 12px; 
    margin-bottom: 12px; 
}
.thread-post .post-meta { flex: 1; min-width: 0; }
.thread-post .menu-container { flex-shrink: 0; }

.thread-post .post-content { margin-bottom: 16px; }
.thread-post .post-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.thread-post .post-attachment { border-radius: var(--radius-sm); overflow: hidden; max-width: 100%; }
.thread-post .post-attachment img { max-width: 100%; max-height: 400px; object-fit: contain; display: block; }

/* Avatars */
.post-avatar, .thread-comment-avatar, .thread-reactor-avatar, .user-list-avatar {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* Reactions */
.thread-reactions {
    display: flex; align-items: center; gap: 12px; padding: 12px 0;
    border-top: 1px solid var(--color-border); border-bottom: 1px solid var(--color-border);
    margin-bottom: 20px; position: relative;
}
.thread-reaction-btn {
    display: flex; align-items: center; gap: 6px; padding: 8px 16px;
    border-radius: var(--radius-full); border: 1px solid var(--color-border);
    background: var(--color-surface); color: var(--color-text-muted);
    font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: all 0.15s;
}
.thread-reaction-btn:hover { background: var(--color-hover); color: var(--color-text); }
.thread-reaction-btn.active { background: var(--color-primary-light); color: var(--color-primary); border-color: var(--color-primary); }
.thread-reaction-btn.disabled { opacity: 0.7; cursor: default; }
.thread-reaction-btn.disabled:hover { background: var(--color-surface); color: var(--color-text-muted); }
.thread-reaction-btn svg { width: 18px; height: 18px; }
.thread-reaction-count { font-weight: 600; }

.thread-reactors { position: relative; cursor: pointer; }
.reactors-row { display: flex; align-items: center; gap: 4px; }

.thread-reactor-avatar {
    width: 24px; height: 24px; border-radius: 50%;
    border: 2px solid var(--color-surface);
    margin-left: -8px; overflow: hidden; display: flex; align-items: center;
    justify-content: center; font-size: 0.625rem; font-weight: 600;
    text-decoration: none;
}
.thread-reactor-avatar:first-child { margin-left: 0; }
.thread-reactor-avatar img { width: 100%; height: 100%; object-fit: cover; }
.thread-reactor-more { font-size: 0.75rem; color: var(--color-text-muted); margin-left: 4px; }

/* User List Tooltip (PORTAL VERSION) */
.user-list-tooltip-portal {
    display: none; position: fixed;
    background: var(--color-surface); border: 1px solid var(--color-border);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15); border-radius: var(--radius-md);
    width: 260px; max-height: 300px; overflow-y: auto; z-index: 2000;
    padding: 8px; flex-direction: column; gap: 4px;
}
.user-list-item {
    display: flex; align-items: center; gap: 10px; padding: 6px;
    border-radius: 6px; text-decoration: none; color: var(--color-text);
}
.user-list-item:hover { background: var(--color-hover); }
.user-list-avatar {
    width: 24px; height: 24px; border-radius: 50%;
    overflow: hidden; flex-shrink: 0; display: flex; align-items: center;
    justify-content: center; font-size: 0.625rem; font-weight: 600;
}
.user-list-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-list-name { font-size: 0.813rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Comments */
.thread-comments-header { font-size: 0.875rem; font-weight: 600; color: var(--color-text); margin-bottom: 16px; }
.thread-comments-list { display: flex; flex-direction: column; gap: 16px; }
.thread-comment { display: flex; gap: 12px; }
.thread-comment.reply { margin-left: 44px; }
.thread-comment-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600; color: var(--color-text-muted); }
.thread-comment.reply .thread-comment-avatar { width: 28px; height: 28px; }
.thread-comment-avatar a { width: 100%; height: 100%; display: block; }
.thread-comment-avatar img { width: 100%; height: 100%; object-fit: cover; }
.thread-comment-body { flex: 1; min-width: 0; }
.thread-comment-bubble { background: var(--color-bg); border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 4px; }
.thread-comment-author { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.thread-comment-name { font-size: 0.813rem; font-weight: 600; color: var(--color-text); }
.thread-comment-content { font-size: 0.875rem; color: var(--color-text); line-height: 1.5; white-space: pre-wrap; }

.thread-comment-action-row { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.thread-comment-meta { font-size: 0.75rem; color: var(--color-text-muted); }
.thread-comment-action {
    background: none; border: none; padding: 0; font-size: 0.75rem;
    font-weight: 600; color: var(--color-text-muted); cursor: pointer; transition: color 0.1s;
}
.thread-comment-action:hover { color: var(--color-text); }
.thread-comment-action.active { color: var(--color-primary); }

/* Footer (Main Input) */
.thread-footer {
    flex-shrink: 0; background: var(--color-surface);
    border-top: 1px solid var(--color-border); z-index: 20;
}
.thread-comment-input-wrapper { display: flex; gap: 12px; padding: 16px 20px; align-items: center; }

/* Inline Reply Form */
.thread-inline-reply { 
    margin-top: 12px; margin-bottom: 12px;
    margin-left: 48px; /* Indent for nesting */
    display: flex; flex-direction: column; gap: 4px;
}

.thread-inline-row {
    display: flex; align-items: center; gap: 8px; width: 100%;
}

.thread-inline-footer {
    display: flex; justify-content: flex-start;
}

.thread-comment-input {
    flex: 1; padding: 0 14px; height: 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full); font-size: 0.875rem; font-family: var(--font-family);
    background: var(--color-bg); color: var(--color-text); outline: none; transition: border-color 0.15s;
    width: 100%;
}
.thread-comment-input:focus { border-color: var(--color-primary); }
.thread-comment-input::placeholder { color: var(--color-text-muted); }

.thread-comment-buttons { display: flex; align-items: center; gap: 8px; }

/* Submit Button */
.thread-comment-submit {
    display: flex; align-items: center; justify-content: center;
    border: none; border-radius: var(--radius-full); cursor: pointer; transition: background 0.15s;
    background: var(--color-primary); color: #fff;
    height: 40px; padding: 0 20px; font-size: 0.875rem; font-weight: 600;
    flex-shrink: 0; width: auto; margin: 0;
}

.thread-comment-submit:hover { background: var(--color-primary-hover); }
.thread-comment-submit:disabled { background: var(--color-border); cursor: not-allowed; }

/* Cancel Text Link */
.thread-cancel-link {
    font-size: 0.75rem; font-weight: 500;
    color: var(--color-text-muted); cursor: pointer;
    padding: 4px 0; display: inline-block;
}
.thread-cancel-link:hover { color: var(--color-text); text-decoration: underline; }

/* Auth CTA */
.auth-cta {
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    padding: 24px; background: var(--color-bg); 
    text-align: center;
}
.auth-cta p { font-size: 0.938rem; color: var(--color-text-muted); }

/* Menus */
.menu-container { position: relative; display: inline-flex; }
.menu-trigger {
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 4px; color: var(--color-text-muted);
    cursor: pointer; background: transparent; border: none;
}
.menu-trigger:hover { background: var(--color-hover); color: var(--color-text); }
.menu-dropdown {
    display: none; position: absolute; right: 0; top: 100%;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    min-width: 160px; z-index: 100; padding: 4px; flex-direction: column; gap: 2px;
}
.menu-container.open .menu-dropdown { display: flex; }
.menu-item {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px;
    font-size: 0.813rem; color: var(--color-text); text-decoration: none;
    border-radius: 4px; transition: background 0.15s; background: none;
    border: none; width: 100%; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--color-hover); }
.menu-item.danger { color: #ef4444; }
.menu-item.danger:hover { background: #fef2f2; }

/* Loading */
.thread-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; color: var(--color-text-muted); }
.thread-loading-spinner {
    width: 32px; height: 32px; border: 3px solid var(--color-border);
    border-top-color: var(--color-primary); border-radius: 50%;
    animation: spin 0.8s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.thread-error { text-align: center; padding: 48px 24px; color: var(--color-text-muted); }
.thread-no-comments { text-align: center; padding: 24px; color: var(--color-text-muted); font-size: 0.875rem; }

/* --- Custom Dialogs (Confirm / Edit) --- */
/* High z-index to sit on top of thread overlay */
.thread-dialog-overlay {
    display: flex; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6); z-index: 2000;
    align-items: center; justify-content: center;
    backdrop-filter: blur(2px); animation: dialogFadeIn 0.15s ease;
}

.thread-dialog-box {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    width: 90%; max-width: 400px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    display: flex; flex-direction: column; gap: 16px;
    animation: dialogScaleIn 0.15s ease;
    border: 1px solid var(--color-border);
}
.thread-dialog-box.edit-mode { max-width: 500px; }

.thread-dialog-header { display: flex; flex-direction: column; gap: 4px; }
.thread-dialog-title { font-size: 1.125rem; font-weight: 600; color: var(--color-text); }
.thread-dialog-msg { font-size: 0.938rem; color: var(--color-text-muted); line-height: 1.5; }

/* Dialog Inputs */
.thread-dialog-textarea {
    width: 100%; min-height: 120px;
    padding: 12px; border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg); color: var(--color-text);
    font-family: inherit; font-size: 0.938rem; resize: vertical;
    outline: none; transition: border-color 0.15s;
}
.thread-dialog-textarea:focus { border-color: var(--color-primary); }

/* Dialog Buttons */
.thread-dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }

.thread-btn {
    padding: 8px 16px; border-radius: var(--radius-full);
    font-size: 0.875rem; font-weight: 600; cursor: pointer;
    border: none; transition: all 0.15s;
}
.thread-btn-cancel { background: transparent; color: var(--color-text-muted); }
.thread-btn-cancel:hover { background: var(--color-hover); color: var(--color-text); }

.thread-btn-confirm { background: var(--color-primary); color: #fff; }
.thread-btn-confirm:hover { background: var(--color-primary-hover); }

.thread-btn-danger { background: #ef4444; color: #fff; }
.thread-btn-danger:hover { background: #dc2626; }

@keyframes dialogFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialogScaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }