/* New Modern Chat UI */
#chat-floating-button {
	position: fixed;
	bottom: 30px;
	right: 30px;
	width: 60px;
	height: 60px;
	background: linear-gradient(135deg, #667eea, #764ba2);
	color: white;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 24px;
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
	cursor: pointer;
	z-index: 999;
	transition: all 0.3s ease;
}
#chat-floating-button:hover {
	transform: scale(1.1);
	box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
}

#chat-popup-overlay {
	position: fixed;
	inset: 0;
	background-color: rgba(0, 0, 0, 0.3);
	z-index: 1000;
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.3s ease;
	backdrop-filter: blur(4px);
}

#chat-popup-overlay.open {
	opacity: 1;
	visibility: visible;
}

#chat-popup-card {
	position: fixed;
	top: 50%;
	left: 50%;
	width: 80vw;
	height: 90vh;
	max-width: 1400px;
	background-color: #f7f9fc;
	border-radius: 20px;
	box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	z-index: 1001;
	transform: translate(-50%, -50%) scale(0.95);
	opacity: 0;
	visibility: hidden;
	transition: transform 0.3s ease, opacity 0.3s ease, visibility 0s 0.3s;
}

#chat-popup-overlay.open #chat-popup-card {
	transform: translate(-50%, -50%) scale(1);
	opacity: 1;
	visibility: visible;
}

.chat-container {
	display: flex;
	height: 100%;
	position: relative;
}

.chat-user-list {
	width: 25%;
	min-width: 280px;
	background-color: #ffffff;
	border-right: 1px solid #e5e7eb;
	display: flex;
	flex-direction: column;
	transition: transform 0.3s ease, margin-left 0.3s ease;
}

.chat-user-list-header {
    padding: 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.chat-user-list-header h3 { color: #1f2937; }

.chat-user-list-body {
    overflow-y: auto;
    flex-grow: 1;
}
.chat-user {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #f3f4f6;
}
.chat-user.selected { background-color: #eef2ff; }
.chat-user:hover { background-color: #f9fafb; }

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    font-size: 1.2rem;
    color: white;
    margin-right: 1rem;
    position: relative;
    flex-shrink: 0;
}
.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background-color: #10b981;
    border-radius: 50%;
    border: 2px solid white;
}
.user-info { flex-grow: 1; overflow: hidden; }
.user-name { font-weight: 600; color: #111827; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-last-active { font-size: 0.8rem; color: #6b7280; }

.unread-badge {
    background-color: #6366f1;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 12px;
}
.user-meta { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.75rem; color: #9ca3af; margin-left: auto;}

.chat-conversation-area {
    width: 75%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #f5f7fa, #eef2ff);
}

.conversation-header {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ffffff;
    flex-shrink: 0;
}
#chat-with-user-name { color: #1f2937; }
#close-chat-popup {
    background: #d32f2f;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    font-size: 2.0rem;
    line-height: 0;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#close-chat-popup:hover {
    background: #c12b2b;
    transform: scale(1.1);
}
#chat-mobile-menu-btn { display: none; background: none; border: none; font-size: 1.25rem; cursor: pointer; color: #6b7280; }

.conversation-body {
    flex-grow: 1;
    padding: 1rem 1.5rem;
    overflow-y: auto;
}
.chat-bubble {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 1rem;
    max-width: 100%;
}
.chat-bubble.sent {
    flex-direction: row-reverse;
}
.chat-bubble-content-wrapper {
    max-width: 65%;
    padding: 0.75rem 1.25rem;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.5;
    position: relative;
}
.chat-bubble.sent .chat-bubble-content-wrapper {
    background: linear-gradient(to right, #6366f1, #8b5cf6);
    color: white;
    border-bottom-right-radius: 5px;
}
.chat-bubble.received .chat-bubble-content-wrapper {
    background-color: #ffffff;
    color: #374151;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 5px;
}

.chat-bubble-meta { font-size: 0.7rem; margin-top: 5px; text-align: right; opacity: 0.8;}
.sent .chat-bubble-meta { color: #d1d5db; }
.received .chat-bubble-meta { color: #9ca3af; }

.conversation-input {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e5e7eb;
    background-color: #ffffff;
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-shrink: 0;
}
#chat-message-input {
    flex-grow: 1;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    padding: 0.75rem 1.25rem;
    resize: none;
    max-height: 120px;
    background-color: #f9fafb;
}
#chat-send-btn {
    background: #6366f1;
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
}
#chat-send-btn:hover { background-color: #4f46e5; }

#chat-attachment-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9ca3af;
    padding: 0.5rem;
    position: relative;
}
#attachment-popover {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}
#attachment-popover.visible {
    opacity: 1;
    visibility: visible;
}
.attachment-option {
    background: none; border: none; text-align: left; padding: 0.5rem 1rem; cursor: pointer; border-radius: 4px;
}
.attachment-option:hover { background-color: #f3f4f6; }


/* Edit/Delete options menu */
.chat-bubble-options {
    position: relative;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
    align-self: center;
}
.chat-bubble:hover .chat-bubble-options {
    opacity: 1;
}
.chat-bubble-options-btn {
    background: none; border: none; font-size: 1.2rem; color: #9ca3af; cursor: pointer; padding: 8px;
}
.chat-bubble-options-menu {
    position: absolute; bottom: 100%; right: 0;
    background: white; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    z-index: 10; overflow: hidden; width: 100px;
}
.chat-bubble.sent .chat-bubble-options-menu {
    left: auto;
    right: 100%;
    margin-right: 5px;
}
.chat-bubble-options-menu button {
    display: block; width: 100%; text-align: left; padding: 8px 12px; font-size: 14px;
    background: none; border: none; cursor: pointer;
}
.chat-bubble-options-menu button:hover { background-color: #f3f4f6; }

/* Edit mode */
.chat-edit-textarea {
    width: 100%; padding: 8px; border: 1px solid #c7d2fe; border-radius: 8px; resize: none;
    background-color: #eef2ff; color: #374151; margin-bottom: 8px;
    font-family: inherit; font-size: inherit; line-height: inherit;
}
.chat-edit-actions { text-align: right; }
.chat-edit-save {
    background-color: #4f46e5; color: white; border: none; cursor: pointer;
    padding: 4px 12px; border-radius: 6px; font-size: 0.8rem; font-weight: 600;
}

/* Pre-loader for uploads and history */
.chat-loader { display: flex; justify-content: center; align-items: center; padding: 40px 20px; }
.chat-loader div { width: 10px; height: 10px; background-color: #6366f1; border-radius: 50%; margin: 0 5px; animation: chat-loader-bounce 1.4s infinite ease-in-out both; }
.chat-loader div:nth-child(1) { animation-delay: -0.32s; }
.chat-loader div:nth-child(2) { animation-delay: -0.16s; }
@keyframes chat-loader-bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }
.chat-loader.small div { width: 5px; height: 5px; }

.chat-upload-preloader { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; opacity: 0.8; padding: 0.75rem 1.25rem; }

/* Document/Image Viewer Modal */
#chat-viewer-modal {
    position: fixed; inset: 0; background-color: rgba(0,0,0,0.7);
    z-index: 2000; display: none; flex-direction: column;
    opacity: 0; transition: opacity 0.3s;
}
#chat-viewer-modal.open { display: flex; opacity: 1; }
#chat-viewer-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem; background: #1f2937; color: white; flex-shrink: 0;
}
#chat-viewer-filename { font-weight: 600; }
#chat-viewer-close-btn {
    width: 48px; height: 48px; border-radius: 50%;
    background-color: #d32f2f; color: white; border: none;
    font-size: 1.5rem; line-height: 1; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
}
#chat-viewer-close-btn:hover { transform: scale(1.1); }
#chat-viewer-content { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 1rem; overflow: auto; }
#chat-viewer-content img, #chat-viewer-content iframe {
    max-width: 100%; max-height: 100%; border: none; border-radius: 8px;
    width: 90%; height: 100%;
}
.unsupported-file-preview { text-align: center; color: white; }
.unsupported-file-preview i { font-size: 5rem; }
.unsupported-file-preview .button-download {
    display: inline-block; background: #6366f1; color: white; padding: 10px 20px;
    border-radius: 8px; margin-top: 1rem; text-decoration: none;
}
.attachment-image { cursor: pointer; }
.attachment-file { cursor: pointer; }
.attachment-info { display: flex; align-items: center; gap: 0.75rem; }
.attachment-name { font-weight: 600; }

/* Custom Confirmation Modal */
.chat-confirm-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 3000;
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.chat-confirm-modal {
    background: white; padding: 2rem; border-radius: 12px; text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2); max-width: 400px;
}
.chat-confirm-modal p { font-size: 1.1rem; margin-bottom: 1.5rem; color: #374151; }
.chat-confirm-actions { display: flex; justify-content: center; gap: 1rem; }
.chat-confirm-actions button {
    padding: 10px 25px; border-radius: 8px; border: none; cursor: pointer;
    font-weight: 600; transition: background-color 0.2s;
}
.chat-confirm-actions .btn-cancel { background-color: #e5e7eb; color: #374151; }
.chat-confirm-actions .btn-cancel:hover { background-color: #d1d5db; }
.chat-confirm-actions .btn-confirm { background-color: #ef4444; color: white; }
.chat-confirm-actions .btn-confirm:hover { background-color: #dc2626; }

/* Responsive Styles for Mobile */
@media (max-width: 768px) {
    #chat-popup-card {
        width: 100%; height: 100%; top: 0; left: 0; transform: none; border-radius: 0; box-shadow: none;
    }
    #chat-popup-overlay.open #chat-popup-card {
         transform: none;
    }
    .chat-user-list {
        position: absolute;
        top: 0; left: 0; bottom: 0;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        z-index: 20;
        border-right: 1px solid #e5e7eb;
    }
    .chat-container.mobile-user-list-active .chat-user-list {
        transform: translateX(0);
    }
    .chat-conversation-area {
        width: 100%;
    }
    #chat-mobile-menu-btn {
        display: block;
    }
}



