/* ========================================
   Private Messages — DM Chat UI
   Consistent with community chat styling
   ======================================== */

/* ========== Section Container ========== */
.community-messages-section {
    flex: 1;
    display: none;
    min-height: 0;
}

.community-messages-section.active {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* ========== PM Container ========== */
.pm-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: var(--spacing-md);
    gap: 12px;
}

/* ========== Section Titles ========== */
.pm-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 8px;
    padding: 0 4px;
}

/* ========== Empty State ========== */
.pm-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}

.pm-empty-icon {
    font-size: 2rem;
}

.pm-empty-state p {
    margin: 0;
    font-size: 0.9rem;
    max-width: 280px;
}

/* ========== Pending Requests ========== */
.pm-pending-section {
    background: var(--surface);
    border-radius: 12px;
    padding: 12px;
    border: 1px solid var(--border);
}

.pm-pending-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
}

.pm-pending-item + .pm-pending-item {
    border-top: 1px solid var(--border);
}

.pm-pending-info {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

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

.pm-pending-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pm-pending-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.pm-pending-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* ========== Buttons ========== */
.pm-btn {
    padding: 6px 14px;
    border-radius: 8px;
    border: none;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.pm-btn:active {
    transform: scale(0.96);
}

.pm-btn--accept {
    background: #22c55e;
    color: #fff;
}

.pm-btn--accept:hover {
    background: #16a34a;
}

.pm-btn--reject {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.pm-btn--reject:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ========== Connections List ========== */
.pm-connections-list {
    display: flex;
    flex-direction: column;
}

.pm-connection-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.pm-connection-item:hover {
    background: var(--surface);
}

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

.pm-connection-name {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pm-connection-arrow {
    font-size: 1.2rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* ========== Unread Badge on Connection Items ========== */
.pm-unread-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: #fff;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
    animation: pm-unread-appear 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes pm-unread-appear {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ========== Chat Area ========== */
.pm-chat-area {
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.pm-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--chat-header-bg, #1a1f2e);
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pm-back-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.pm-back-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.pm-chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.pm-chat-header-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    border-radius: 8px;
    padding: 4px 6px;
    transition: background 0.15s ease;
}

.pm-chat-header-profile:hover {
    background: rgba(255, 255, 255, 0.08);
}

.pm-chat-header-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    flex: 1;
}

.pm-clickable-avatar {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.pm-clickable-avatar:hover {
    opacity: 0.8;
}

.pm-disconnect-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #888);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    margin-left: auto;
    transition: background 0.15s ease, color 0.15s ease;
}

.pm-disconnect-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error, #ef4444);
}

/* ========== Chat Messages ========== */
.pm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-gutter: stable;
}

.pm-message {
    display: flex;
    justify-content: flex-start;
    max-width: 80%;
}

.pm-message--own {
    align-self: flex-end;
    justify-content: flex-end;
}

.pm-message-bubble {
    background: var(--bubble-other, #1e293b);
    border-radius: 16px;
    border-top-left-radius: 4px;
    padding: 8px 12px;
    max-width: 100%;
    word-break: break-word;
}

.pm-message--own .pm-message-bubble {
    background: var(--bubble-own, #0ea5e9);
    border-radius: 16px;
    border-top-right-radius: 4px;
}

.pm-message-text {
    font-size: 0.9rem;
    line-height: 1.4;
    color: var(--text-primary);
}

.pm-message-time {
    display: block;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.45);
    text-align: right;
    margin-top: 2px;
}

.pm-message--own .pm-message-time {
    color: rgba(255, 255, 255, 0.6);
}

/* ========== Message Footer ========== */
.pm-message-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    justify-content: flex-end;
}

/* ========== Message Edit Feature ========== */

/* Pencil button — hidden until bubble hover */
.pm-message-edit-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0 2px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.45);
    transition: color 0.15s ease, transform 0.15s ease;
    flex-shrink: 0;
}

.pm-message-bubble:hover .pm-message-edit-btn {
    display: inline-flex;
    align-items: center;
}

.pm-message-edit-btn:hover {
    color: rgba(255, 255, 255, 0.9);
    transform: scale(1.15);
}

/* "edited" label */
.pm-message-edited-label {
    font-size: 0.6rem;
    opacity: 0.5;
    font-style: italic;
    flex-shrink: 0;
}

.pm-message--own .pm-message-edited-label {
    color: rgba(255, 255, 255, 0.65);
}

/* Editing state */
.pm-message-bubble--editing {
    outline: 2px solid rgba(14, 165, 233, 0.45);
    border-radius: 12px;
}

/* Inline edit textarea */
.pm-message-edit-input {
    width: 100%;
    min-width: 160px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(14, 165, 233, 0.55);
    border-radius: 8px;
    color: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 6px 10px;
    resize: none;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}

/* Save / Cancel action row */
.pm-message-edit-actions {
    display: flex;
    gap: 6px;
    margin-right: auto;
}

.pm-message-edit-save,
.pm-message-edit-cancel {
    padding: 2px 10px;
    border-radius: 12px;
    border: none;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.pm-message-edit-save {
    background: rgba(255, 255, 255, 0.9);
    color: #0a0e17;
}

.pm-message-edit-cancel {
    background: rgba(255, 255, 255, 0.15);
    color: inherit;
}

.pm-message-edit-save:hover,
.pm-message-edit-cancel:hover {
    opacity: 0.8;
}

/* ========== Chat Input ========== */
.pm-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--chat-input-bg, #1a1f2e);
    border-top: 1px solid var(--border);
    border-radius: 0 0 12px 12px;
    flex-shrink: 0;
}

.pm-chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 8px 16px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.pm-chat-input:focus {
    border-color: var(--primary-color);
}

.pm-chat-input::placeholder {
    color: var(--text-muted);
}

.pm-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color, #0ea5e9);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
}

.pm-send-btn:hover {
    background: #0284c7;
}

.pm-send-btn:active {
    transform: scale(0.92);
}

/* ========== Connect Button (User Profile) ========== */
.user-profile-connect-btn {
    padding: 8px 18px;
    border-radius: 8px;
    border: 1px solid var(--primary-color, #0ea5e9);
    background: transparent;
    color: var(--primary-color, #0ea5e9);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.user-profile-connect-btn:hover:not(:disabled) {
    background: var(--primary-color, #0ea5e9);
    color: #fff;
}

.user-profile-connect-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.user-profile-connect-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

.user-profile-connect-btn--connected {
    border-color: #22c55e;
    color: #22c55e;
}

.user-profile-connect-btn--pending {
    border-color: #f59e0b;
    color: #f59e0b;
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
    .pm-container {
        padding: var(--spacing-sm);
    }

    .pm-message {
        max-width: 90%;
    }

    .pm-pending-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .pm-pending-actions {
        align-self: flex-end;
    }
}
