/* Chat System Styles */

.chat-container {
    height: calc(100vh - 120px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.chat-sidebar {
    background: #f8f9fa;
    border-right: 1px solid #e9ecef;
    height: 100%;
    overflow-y: auto;
}

.chat-main {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chat-header {
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
}

.chat-input {
    background: #fff;
    border-top: 1px solid #e9ecef;
    padding: 15px 20px;
}

.conversation-item {
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    transition: background-color 0.2s;
}

.conversation-item:hover {
    background: #e9ecef;
}

.conversation-item.active {
    background: #007bff;
    color: white;
}

.message-bubble {
    max-width: 70%;
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
}

.message-sent {
    background: #007bff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message-received {
    background: #e9ecef;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.75em;
    opacity: 0.7;
    margin-top: 4px;
}

.message-status {
    font-size: 0.7em;
    margin-top: 2px;
}

.typing-indicator {
    padding: 10px 15px;
    font-style: italic;
    color: #495057;
    align-self: flex-start;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.online-indicator {
    width: 10px;
    height: 10px;
    background: #28a745;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.offline-indicator {
    width: 10px;
    height: 10px;
    background: #495057;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.online-status {
    color: #28a745;
    font-size: 0.9em;
}

.offline-status {
    color: #495057;
    font-size: 0.9em;
}

.typing-status {
    color: #0084ff;
    font-size: 0.9em;
    font-style: italic;
}

.search-box {
    padding: 15px;
    border-bottom: 1px solid #e9ecef;
}

.search-result-item:hover {
    background: #f8f9fa;
}

.empty-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #495057;
    text-align: center;
}

.file-message {
    display: flex;
    align-items: center;
    padding: 10px;
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
    margin-top: 5px;
}

.file-icon {
    font-size: 1.5em;
    margin-right: 10px;
}

.emoji-picker {
    position: fixed; /* JS will reposition precisely near the emoji button */
    bottom: 90px;
    right: 20px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: none;
    z-index: 1000;
    max-height: 260px;
    overflow-y: auto;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.emoji-item {
    padding: 5px;
    cursor: pointer;
    border-radius: 4px;
    text-align: center;
    font-size: 1.2em;
}

.emoji-item:hover {
    background: #f0f0f0;
}

.back-button {
    color: #007bff;
    text-decoration: none;
    margin-right: 15px;
}

.back-button:hover {
    color: #0056b3;
}

.file-upload-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    margin: 10px 0;
    transition: border-color 0.2s;
}

.file-upload-area.dragover {
    border-color: #007bff;
    background: #f8f9ff;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 80px);
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .chat-sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .chat-sidebar.show {
        transform: translateX(0);
    }
    
    .back-button {
        display: inline-block !important;
    }
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar,
.chat-sidebar::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-sidebar::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-sidebar::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animation for new messages */
.message-bubble {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Status indicators */
.connection-status {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

/* Unread message badge */
.unread-badge {
    font-size: 0.7em;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pagination Loading Indicators */
#loadingMoreIndicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    margin: 10px auto;
    max-width: 250px;
    animation: fadeIn 0.3s ease-in;
}

#loadingMoreIndicator .spinner-border {
    width: 1.2rem;
    height: 1.2rem;
    border-width: 2px;
}

#noMoreMessagesIndicator {
    text-align: center;
    padding: 10px;
    color: #495057;
    font-size: 0.875rem;
    font-style: italic;
    animation: fadeIn 0.3s ease-in;
}

/* Smooth message appearance */
.message-bubble {
    animation: messageSlideIn 0.2s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Ensure smooth scrolling */
.chat-messages {
    scroll-behavior: smooth;
}

/* Date separator styling */
.chat-date-separator {
    text-align: center;
    margin: 20px 0;
    position: relative;
    animation: fadeIn 0.3s ease-in;
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #e0e0e0;
}

.chat-date-separator::before {
    left: 0;
}

.chat-date-separator::after {
    right: 0;
}

/* Messages spacer - invisible element for pagination anchor */
.messages-spacer {
    height: 1px;
    visibility: hidden;
}
