/* Custom Chat Interface Styles */
.chat-container {
    display: flex;
    height: 100%;
    background: #ffffff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
}

.dark .chat-container {
    background: #1f2937;
}

/* Sidebar Styles */
.chat-sidebar {
    width: 20rem;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

.dark .chat-sidebar {
    border-right-color: #374151;
}

.chat-sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
}

.dark .chat-sidebar-header {
    border-bottom-color: #374151;
}

.chat-sidebar-title {
    font-size: 1.125rem;
    font-weight: 500;
    color: #111827;
    margin-bottom: 0.5rem;
}

.dark .chat-sidebar-title {
    color: #ffffff;
}

.chat-search-input {
    width: 100%;
    border-radius: 0.375rem;
    border: 1px solid #d1d5db;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background: #ffffff;
    color: #111827;
}

.dark .chat-search-input {
    border-color: #374151;
    background: #111827;
    color: #ffffff;
}

.chat-search-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px #3b82f6;
    border-color: #3b82f6;
}

/* Contact List */
.chat-contacts-list {
    overflow-y: auto;
    flex: 1;
    height: calc(100% - 5rem);
}

.contact-item {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
}

.dark .contact-item {
    border-bottom-color: #374151;
}

.contact-item:hover {
    background-color: #f9fafb;
}

.dark .contact-item:hover {
    background-color: #374151;
}

.contact-item.active {
    background-color: #f3f4f6;
}

.dark .contact-item.active {
    background-color: #374151;
}

.contact-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 500;
    color: #6b7280;
    flex-shrink: 0;
}

.dark .contact-avatar {
    background: #4b5563;
    color: #d1d5db;
}

.contact-info {
    flex: 1;
    min-width: 0;
    margin-left: 0.75rem;
}

.contact-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dark .contact-name {
    color: #ffffff;
}

.contact-phone {
    font-size: 0.75rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.25rem;
}

.dark .contact-phone {
    color: #9ca3af;
}

.contact-ad-badge {
    font-size: 0.75rem;
    color: #3b82f6;
    float: right;
}

/* Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-empty-state {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
}

.dark .chat-empty-state {
    color: #9ca3af;
}

/* Chat Header */
.chat-header {
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dark .chat-header {
    border-bottom-color: #374151;
}

.chat-header-info {
    display: flex;
    align-items: center;
}

.chat-header-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 500;
    color: #6b7280;
    flex-shrink: 0;
    margin-right: 0.75rem;
}

.dark .chat-header-avatar {
    background: #4b5563;
    color: #d1d5db;
}

.chat-header-details {
    display: flex;
    flex-direction: column;
}

.chat-header-name {
    font-size: 1.125rem;
    font-weight: 500;
    color: #111827;
}

.dark .chat-header-name {
    color: #ffffff;
}

.chat-header-contact {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

.dark .chat-header-contact {
    color: #9ca3af;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 500px;
}

.dark .chat-messages {
    background: #1f2937;
}

.chat-messages-empty {
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
    padding: 2rem;
}

.dark .chat-messages-empty {
    color: #ffffff;
}

/* Message Bubbles */
.message-wrapper {
    display: flex;
    margin-bottom: 0.5rem;
}

.message-wrapper.inbound {
    justify-content: flex-start;
}

.message-wrapper.outbound {
    justify-content: flex-end;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    max-width: 70%;
    word-wrap: break-word;
    position: relative;
}

.message-bubble.inbound {
    background: #f3f4f6;
    color: #374151;
    border-bottom-left-radius: 0.375rem;
}

.dark .message-bubble.inbound {
    background: #374151;
    color: #ffffff;
}

.message-bubble.outbound {
    background: #3b82f6;
    color: #ffffff;
    border-bottom-right-radius: 0.375rem;
}

.dark .message-bubble.outbound {
    background: #2563eb;
}

/* Message Media */
.message-image {
    max-width: 100%;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    display: block;
}

.message-caption {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.5rem;
}

.dark .message-caption {
    color: #9ca3af;
}

.message-contact-card {
    padding: 0.5rem;
    border-radius: 0.375rem;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 0.5rem;
}

.dark .message-contact-card {
    background: rgba(0, 0, 0, 0.2);
}

.message-contact-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: inherit;
}

.message-contact-phone {
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.8;
}

.message-location-link {
    display: flex;
    align-items: center;
    color: inherit;
    text-decoration: none;
    margin-top: 0.5rem;
}

.message-location-icon {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
}

.message-timestamp {
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.7;
    margin-top: 0.25rem;
    display: block;
}

.message-status {
    font-size: 0.75rem;
    color: inherit;
    opacity: 0.7;
    margin-left: 0.5rem;
}

.message-reaction {
    font-size: 0.875rem;
    margin-left: 0.5rem;
}

.message-ad-badge {
    font-size: 0.75rem;
    color: #3b82f6;
    font-weight: 500;
}

.message-download-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: inherit;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.message-download-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message-save-contact-btn {
    background: #3b82f6;
    color: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    border: none;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.dark .message-save-contact-btn {
    background: #2563eb;
}

.message-save-contact-btn:hover {
    background: #2563eb;
}

.dark .message-save-contact-btn:hover {
    background: #1d4ed8;
}

/* Chat Input */
.chat-input-area {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.dark .chat-input-area {
    border-top-color: #374151;
    background: #1f2937;
}

.chat-input-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    border-radius: 0.375rem;
    border: 1px solid #d1d5db;
    padding: 0.75rem 1rem;
    background: #ffffff;
    color: #111827;
}

.dark .chat-input {
    border-color: #374151;
    background: #111827;
    color: #ffffff;
}

.chat-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px #3b82f6;
    border-color: #3b82f6;
}

/* Channel Filter */
.channel-filter {
    margin-bottom: 1.5rem;
}

.channel-select {
    width: 100%;
    border-radius: 0.375rem;
    border: 1px solid #d1d5db;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    background: #ffffff;
    color: #111827;
    margin-bottom: 1rem;
}

.dark .channel-select {
    border-color: #374151;
    background: #111827;
    color: #ffffff;
}

/* Utility Classes for the Chat */
.chat-flex {
    display: flex;
}

.chat-flex-col {
    flex-direction: column;
}

.chat-h-full {
    height: 100%;
}

.chat-w-80 {
    width: 20rem;
}

.chat-flex-1 {
    flex: 1;
}

.chat-items-center {
    align-items: center;
}

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

.chat-space-x-3 > * + * {
    margin-left: 0.75rem;
}

.chat-space-y-4 > * + * {
    margin-top: 1rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-sidebar {
        width: 100%;
        max-width: 16rem;
    }

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

    .chat-container {
        flex-direction: column;
        height: auto;
    }

    .chat-messages {
        height: 50vh;
    }
}

@media (max-width: 640px) {
    .contact-item {
        padding: 0.75rem;
    }

    .chat-header {
        padding: 0.75rem;
    }

    .chat-input-area {
        padding: 0.75rem;
    }

    .message-bubble {
        max-width: 90%;
        padding: 0.5rem 0.75rem;
    }
}

/* Scrollbar Styling */
.chat-contacts-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-contacts-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.dark .chat-contacts-list::-webkit-scrollbar-track,
.dark .chat-messages::-webkit-scrollbar-track {
    background: #1e293b;
}

.chat-contacts-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.dark .chat-contacts-list::-webkit-scrollbar-thumb,
.dark .chat-messages::-webkit-scrollbar-thumb {
    background: #475569;
}

.chat-contacts-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark .chat-contacts-list::-webkit-scrollbar-thumb:hover,
.dark .chat-messages::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Animation for better UX */
.contact-item {
    transition: all 0.2s ease-in-out;
}

.message-bubble {
    animation: fadeInUp 0.3s ease-out;
}

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

/* Fix for message text alignment */
.message-bubble p {
    margin: 0;
    line-height: 1.4;
}

.message-bubble small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Fix for location links */
.message-location-link:hover {
    opacity: 0.8;
}

/* Fix for contact items spacing */
.contact-item .contact-info {
    overflow: hidden;
}

/* Ensure proper text wrapping in messages */
.message-bubble {
    word-break: break-word;
    overflow-wrap: break-word;
}

#load-more-messages {
    text-align: center;
    margin-bottom: 1rem;
    cursor: pointer;
    color: #3b82f6;
    font-size: 0.875rem;
}
