/**
 * Chat UI Styles - WhatsApp-like messaging interface
 */

/* ============================================================================
   Chat Icon in Header
   ============================================================================ */

.chat-icon-container {
    display: inline-block;
    position: relative;
    margin-right: 10px;
}

.chat-icon-btn {
    position: relative;
    color: var(--bs-body-color);
    font-size: 1.5rem;
    padding: 0.25rem 0.5rem;
    text-decoration: none;
}

.chat-icon-btn:hover {
    color: var(--bs-primary);
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #dc3545;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* ============================================================================
   Chat Page
   ============================================================================ */

.chat-page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.chat-page-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #ddd;
}

.chat-page-header h2 {
    margin: 0;
    font-size: 28px;
    color: #333;
}

/* ============================================================================
   Chat Container (Two-Column Layout)
   ============================================================================ */

.chat-container {
    display: flex;
    height: 70vh;
    min-height: 500px;
    max-height: 700px;
    background-color: #f0f2f5;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   Left Panel: Conversations List
   ============================================================================ */

.chat-conversations-panel {
    width: 350px;
    min-width: 350px;
    border-right: 1px solid #e0e0e0;
    background-color: white;
    display: flex;
    flex-direction: column;
}

.chat-conversations-header {
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f8f9fa;
}

.chat-conversations-header h6 {
    margin: 0;
    font-weight: 600;
}

.chat-conversations-list {
    flex: 1;
    overflow-y: auto;
}

.chat-conversation-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
}

.chat-conversation-item:hover {
    background-color: #f5f5f5;
}

.chat-conversation-item.active {
    background-color: #e9ecef;
}

.conversation-avatar {
    margin-right: 12px;
    color: #999;
}

.conversation-content {
    flex: 1;
    min-width: 0; /* For text-overflow */
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.conversation-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.conversation-time {
    font-size: 0.75rem;
    color: #999;
}

.conversation-preview {
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-item .badge {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
}

/* ============================================================================
   Right Panel: Message Thread
   ============================================================================ */

.chat-messages-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #e5ddd5; /* WhatsApp-like background */
    position: relative;
}

.chat-no-conversation-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background-color: #f8f9fa;
}

.chat-no-conversation-selected i {
    margin-bottom: 15px;
    opacity: 0.3;
}

.chat-thread {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-thread-header {
    padding: 12px 20px;
    background-color: #f0f2f5;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-thread-user-info strong {
    font-size: 1rem;
}

.chat-thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(0, 0, 0, 0.02) 10px,
        rgba(0, 0, 0, 0.02) 20px
    );
}

.chat-thread-input {
    padding: 15px 20px;
    background-color: #f0f2f5;
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
}

.chat-input-textarea {
    resize: none;
    border-radius: 20px;
    padding: 10px 15px;
    max-height: 100px;
}

.chat-send-btn {
    min-width: 45px;
    height: 45px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================================
   Messages
   ============================================================================ */

.chat-message {
    display: flex;
    margin-bottom: 12px;
    animation: slideIn 0.2s ease-out;
}

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

.message-mine {
    justify-content: flex-end;
}

.message-theirs {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
}

.message-mine .message-bubble {
    background-color: #dcf8c6; /* WhatsApp green */
    border-bottom-right-radius: 2px;
}

.message-theirs .message-bubble {
    background-color: white;
    border-bottom-left-radius: 2px;
}

.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 0.95rem;
    line-height: 1.4;
    margin-bottom: 4px;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 0.7rem;
    color: #666;
    margin-top: 2px;
}

.message-time {
    font-size: 0.7rem;
}

.message-status {
    font-size: 0.8rem;
    color: #999;
}

.message-mine .message-status {
    color: #4a9eff; /* Blue checkmarks when read */
}

/* ============================================================================
   Scrollbar Styling
   ============================================================================ */

.chat-conversations-list::-webkit-scrollbar,
.chat-thread-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-conversations-list::-webkit-scrollbar-track,
.chat-thread-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-conversations-list::-webkit-scrollbar-thumb,
.chat-thread-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-conversations-list::-webkit-scrollbar-thumb:hover,
.chat-thread-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ============================================================================
   Responsive Design
   ============================================================================ */

@media (max-width: 768px) {
    .chat-conversations-panel {
        width: 100%;
        min-width: 100%;
    }

    .chat-messages-panel {
        display: none; /* Hide on mobile by default */
    }

    .chat-container.conversation-selected .chat-conversations-panel {
        display: none;
    }

    .chat-container.conversation-selected .chat-messages-panel {
        display: flex;
    }

    .message-bubble {
        max-width: 80%;
    }
}

/* ============================================================================
   Loading States
   ============================================================================ */

.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #999;
}

.chat-loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ============================================================================
   Empty States
   ============================================================================ */

.chat-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #999;
    text-align: center;
}

.chat-empty-state i {
    font-size: 3rem;
    margin-bottom: 15px;
    opacity: 0.3;
}

.chat-empty-state p {
    margin: 0;
    font-size: 0.95rem;
}

/* ============================================================================
   Invitation Messages
   ============================================================================ */

.chat-message-system {
    justify-content: center;
}

.message-bubble-invitation {
    background-color: #fff3cd !important;
    border: 1px solid #ffc107;
    border-radius: 8px !important;
    max-width: 400px;
    text-align: center;
    padding: 15px;
}

.invitation-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

