/* CRM Section Styles */

body {
    font-family: 'Inter', sans-serif;
}


/* CRM Layout */
.crm-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 20px;
    height: calc(100vh - 160px);
    max-width: 1800px;
    margin: 0 auto;
}

/* Conversations List Panel */
.conversations-panel {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.conversations-header {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
    background: #f8f9ff;
}

.conversations-header h2 {
    margin: 0 0 16px 0;
    font-size: 24px;
    font-weight: 700;
    color: #333;
}

/* Search and Filter */
.conversations-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: 10px 40px 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
}

.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.filter-container {
    display: flex;
    gap: 8px;
}

.filter-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #667eea;
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s ease;
}

.conversation-item:hover {
    background: #f8f9ff;
}

.conversation-item.active {
    background: #e3f2fd !important;
    border-left: 4px solid #667eea;
}

.conversation-item.unread {
    background: #fff8f0;
}

.conversation-item.active.unread {
    background: #e3f2fd !important;
}

.conversation-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    margin-right: 12px;
    flex-shrink: 0;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

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

.conversation-name {
    font-weight: 600;
    font-size: 15px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
}

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

.conversation-item.unread .conversation-preview {
    color: #333;
    font-weight: 500;
}

.conversation-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.unread-badge {
    background: #667eea;
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
}

.conversation-tags {
    display: flex;
    gap: 4px;
}

.tag-chip {
    font-size: 11px;
    padding: 2px 8px;
    background: #f0f0f0;
    border-radius: 12px;
    color: #666;
}

/* Chat Panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

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

.chat-contact-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
}

.chat-details h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.chat-phone {
    font-size: 13px;
    color: #666;
    margin-top: 2px;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    padding: 8px 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: #e0e0e0;
}

.action-btn i {
    margin-right: 4px;
}

/* Messages Area */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    background: #f9fafb;
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: fadeIn 0.3s ease;
    clear: both;
    width: 100%;
}

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

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

.message-bubble {
    max-width: 65%;
    min-width: 80px;
    padding: 10px 14px;
    border-radius: 16px;
    position: relative;
    display: block;
    word-wrap: break-word;
    width: fit-content;
}

.message.incoming .message-bubble {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
    color: #1f2937;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    margin-right: auto;
}

.message.outgoing .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    border: none;
    margin-left: auto;
}

.message-text {
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.incoming .message-text {
    color: #1f2937;
}

.message.outgoing .message-text {
    color: #ffffff;
}

.message-media {
    margin-bottom: 8px;
    max-width: 100%;
}

.message-media img {
    max-width: 100%;
    max-height: 400px;
    width: auto;
    height: auto;
    border-radius: 12px;
    display: block;
    cursor: pointer;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.message-media img:hover {
    transform: scale(1.02);
}

.message-media video {
    max-width: 100%;
    max-height: 400px;
    border-radius: 12px;
    display: block;
}

.message-media audio {
    width: 100%;
    max-width: 300px;
    height: 40px;
}

.message-media a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    transition: all 0.2s ease;
}

.message.outgoing .message-media a {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.message-media a:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.message.outgoing .message-media a:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message-media a i {
    font-size: 20px;
}

/* Reaction Messages */
.message-reaction {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 60px;
}

.reaction-emoji {
    font-size: 48px;
    line-height: 1;
    animation: reactionPop 0.3s ease;
}

@keyframes reactionPop {
    0% {
        transform: scale(0);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Stickers */
.sticker-image img {
    max-width: 200px !important;
    max-height: 200px !important;
    width: auto !important;
    height: auto !important;
}

/* Location Messages */
.message-location {
    width: 100%;
    max-width: 350px;
}

.message-location a {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.02);
    transition: all 0.2s ease;
}

.message.outgoing .message-location a {
    background: rgba(255, 255, 255, 0.1);
}

.message-location a:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.location-map {
    width: 100%;
    height: 200px;
    background: #f3f4f6;
    position: relative;
}

.location-info {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
}

.message.outgoing .location-info {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.location-info i {
    font-size: 24px;
    color: #667eea;
}

.message.outgoing .location-info i {
    color: white;
}

.location-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
}

.location-address {
    font-size: 12px;
    opacity: 0.7;
}

/* Contact Messages */
.message-contacts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 300px;
}

.contact-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: white;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.message.outgoing .contact-card {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.contact-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    flex-shrink: 0;
}

.message.outgoing .contact-avatar {
    background: rgba(255, 255, 255, 0.3);
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-phone {
    font-size: 12px;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Media Error State */
.media-error {
    padding: 20px;
    text-align: center;
    background: rgba(239, 68, 68, 0.1);
    border: 1px dashed rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    color: #dc2626;
    font-size: 13px;
}

.media-error i {
    font-size: 24px;
    margin-bottom: 8px;
    display: block;
}

.message.outgoing .media-error {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    color: white;
}

/* Media messages should have less padding */
.message-bubble:has(.message-media),
.message-bubble:has(.message-location),
.message-bubble:has(.message-contacts),
.message-bubble:has(.message-reaction) {
    padding: 4px;
    max-width: 70%;
}

.message-bubble:has(.message-reaction) {
    max-width: auto;
    min-width: auto;
}

.message-bubble:has(.message-media) .message-text:empty,
.message-bubble:has(.message-location) .message-text:empty,
.message-bubble:has(.message-contacts) .message-text:empty,
.message-bubble:has(.message-reaction) .message-text:empty {
    display: none;
}

.message-bubble:has(.message-media) .message-text,
.message-bubble:has(.message-location) .message-text,
.message-bubble:has(.message-contacts) .message-text {
    padding: 8px 10px 4px 10px;
}

.message-bubble:has(.message-media) .message-time,
.message-bubble:has(.message-location) .message-time,
.message-bubble:has(.message-contacts) .message-time,
.message-bubble:has(.message-reaction) .message-time {
    padding: 4px 10px 6px 10px;
}

.message-time {
    font-size: 10px;
    margin-top: 6px;
    opacity: 0.7;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 4px;
}

.message.incoming .message-time {
    color: #9ca3af;
}

.message.outgoing .message-time {
    text-align: right;
    color: rgba(255, 255, 255, 0.9);
    justify-content: flex-end;
}

.message-status {
    font-size: 11px;
    margin-left: 4px;
}

.message-status.delivered::after {
    content: "✓✓";
}

.message-status.read::after {
    content: "✓✓";
    color: #4caf50;
}

/* Date Divider */
.date-divider {
    text-align: center;
    margin: 24px 0 16px 0;
}

.date-divider span {
    background: #f3f4f6;
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 11px;
    color: #6b7280;
    font-weight: 500;
    text-transform: capitalize;
}

/* Chat Input */
.chat-input-container {
    padding: 20px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.attachment-btn {
    padding: 10px;
    background: #f3f4f6;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    resize: none;
    font-family: 'Inter', sans-serif;
    transition: all 0.2s ease;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input::placeholder {
    color: #9ca3af;
}

.send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-btn:active {
    transform: translateY(0);
}

.send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
}

.empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 20px;
    margin: 0 0 8px 0;
    color: #666;
}

.empty-state p {
    font-size: 14px;
    color: #999;
}

/* Loading States */
.loading-conversations {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #999;
}

.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .crm-container {
        grid-template-columns: 1fr;
        height: auto;
    }

    .conversations-panel {
        height: 300px;
    }

    .chat-panel {
        height: calc(100vh - 500px);
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    main {
        padding: 15px;
    }

    .crm-container {
        gap: 15px;
    }

    .conversations-header h2 {
        font-size: 20px;
    }

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

    .chat-input-wrapper {
        gap: 8px;
    }

    .attachment-btn {
        padding: 8px;
    }

    .send-btn {
        padding: 8px 16px;
    }
}

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

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

.conversations-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}


