/* Chat History - Messenger Style */
.history-item-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-surface);
    border-radius: 16px;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.history-item-card:hover {
    background: var(--bg-surface-hover);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.15);
}

.history-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.history-avatar-img {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary-color);
}

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

.history-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.history-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.history-preview {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-view-btn {
    background: var(--primary-color);
    border: none;
    border-radius: 12px;
    padding: 0.75rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.history-view-btn:hover {
    background: #45a049;
    transform: scale(1.05);
}

/* Modal Header Actions */
.messenger-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.header-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.add-friend-history-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary-color);
    border: none;
    border-radius: 12px;
    padding: 0.625rem 1rem;
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.add-friend-history-btn:hover:not(:disabled) {
    background: #45a049;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.add-friend-history-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.add-friend-history-btn svg {
    flex-shrink: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Mobile: Hide avatar in chat history modal header to save space */
@media (max-width: 768px) {
    .chat-history-modal .dev-avatar-container {
        display: none !important;
    }

    .chat-history-modal .header-info {
        gap: 0 !important;
    }

    .chat-history-modal .header-text {
        margin-left: 0 !important;
    }

    .chat-history-modal .messenger-header {
        padding: 1rem;
    }

    .chat-history-modal .add-friend-history-btn span {
        display: none;
    }

    .chat-history-modal .add-friend-history-btn {
        padding: 0.5rem;
        min-width: auto;
    }
}

/* Message Alignment - Messenger Style */
.message-wrapper {
    display: flex;
    flex-direction: column;
    margin-bottom: 0.5rem;
    max-width: 70%;
}

.message-wrapper.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message-wrapper.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message-wrapper .message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 18px;
    word-wrap: break-word;
    max-width: 100%;
    font-size: 0.95rem;
    line-height: 1.4;
}

.message-wrapper.sent .message-bubble {
    background-color: var(--chat-bubble-me);
    color: var(--chat-text-me);
    border-bottom-right-radius: 4px;
}

.message-wrapper.received .message-bubble {
    background-color: var(--chat-bubble-them);
    color: var(--chat-text-them);
    border-bottom-left-radius: 4px;
}

.message-timestamp {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    opacity: 0.7;
    padding: 0 0.5rem;
}

.date-separator {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 1rem 0;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    align-self: center;
    max-width: 200px;
}

#chatMessagesContainer {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    gap: 0.25rem;
    overflow-y: auto;
    max-height: 60vh;
}

/* Modal Overlay Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: 16px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.messenger-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    /* Important for flex container scrolling */
}

/* Scrollbar styling for message container */
#chatMessagesContainer::-webkit-scrollbar,
.messenger-body::-webkit-scrollbar {
    width: 8px;
}

#chatMessagesContainer::-webkit-scrollbar-track,
.messenger-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

#chatMessagesContainer::-webkit-scrollbar-thumb,
.messenger-body::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
}

#chatMessagesContainer::-webkit-scrollbar-thumb:hover,
.messenger-body::-webkit-scrollbar-thumb:hover {
    background: #45a049;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .modal-content {
        max-height: 90vh;
        margin: 0;
        border-radius: 12px;
    }

    #chatMessagesContainer {
        max-height: calc(90vh - 100px);
    }
}