/* Enhanced Chat System Styles - Scoped to #chatApp */

#chatApp {
    /* CSS Custom Properties */
    --primary-color: #561792;
    --primary-dark: #5f0c85;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --purple-color: #8b5cf6;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --bg-white: #ffffff;
    --bg-gray-50: #f9fafb;
    --bg-gray-100: #f3f4f6;
    --bg-gray-900: #111827;
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;

    /* Base Chat App Styles */
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 600px;
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-light);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
}

#chatApp *,
#chatApp *::before,
#chatApp *::after {
    box-sizing: border-box;
}

#chatApp.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

#chatApp.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    z-index: 1001;
}

/* Chat Header */
#chatApp .chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

#chatApp .header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

#chatApp .avatar {
    position: relative;
    width: 44px;
    height: 44px;
}

#chatApp .avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-light);
}

#chatApp .status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success-color);
    border: 2px solid var(--bg-white);
    border-radius: 50%;
}

#chatApp .user-info .name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
    margin: 0 0 2px 0;
}

#chatApp .user-info .status {
    font-size: 0.75rem;
    color: var(--success-color);
    font-weight: 500;
    margin: 0;
}

#chatApp .header-actions {
    display: flex;
    gap: 4px;
}

#chatApp .action-btn.back-btn{
    background: var(--bg-gray-100);
    color: var(--text-secondary);
}
#chatApp .action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-light);
    font-size: 0.875rem;
    text-decoration: none;
}

#chatApp .action-btn:hover {
    background: var(--bg-gray-100);
    color: var(--text-secondary);
}

#chatApp .back-btn:hover {
    background: var(--primary-color);
    color: var(--bg-white);
}

#chatApp .fullscreen-btn:hover {
    background: var(--primary-color);
    color: var(--bg-white);
}

#chatApp .close-btn:hover {
    background: #fee2e2;
    color: #dc2626;
}

/* Chat Container */
#chatApp .chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Services View */
#chatApp .services-view {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-gray-50);
}

#chatApp .services-header {
    padding: 24px 20px 16px;
    text-align: center;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
}

#chatApp .services-header h3 {
    margin: 0 0 4px 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

#chatApp .services-header p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#chatApp .services-list {
    padding: 16px;
}

#chatApp .service-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

#chatApp .service-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-color);
}

#chatApp .service-item:active {
    transform: translateY(0);
}

#chatApp .service-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-white);
    font-size: 1.125rem;
    flex-shrink: 0;
}

#chatApp .service-info {
    flex: 1;
    min-width: 0;
}

#chatApp .service-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

#chatApp .service-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.3;
}

#chatApp .service-time {
    font-size: 0.75rem;
    color: var(--text-light);
    white-space: nowrap;
    margin-left: 8px;
}

#chatApp .service-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#chatApp .last-message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chatApp .service-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chatApp .days-left {
    font-size: 0.75rem;
    font-weight: 600;
}

#chatApp .unread-badge {
    background: #ef4444;
    color: var(--bg-white);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
}

/* Chat View */
#chatApp .chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#chatApp .chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-gray-50);
    scroll-behavior: smooth;
}

#chatApp .chat-body::-webkit-scrollbar {
    width: 4px;
}

#chatApp .chat-body::-webkit-scrollbar-track {
    background: transparent;
}

#chatApp .chat-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

#chatApp .chat-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Welcome Message */
#chatApp .welcome-message {
    text-align: center;
    padding: 32px 20px;
    margin-bottom: 20px;
}

#chatApp .welcome-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-white);
    font-size: 1.25rem;
}

#chatApp .welcome-message p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
    line-height: 1.5;
}

/* Message Groups */
#chatApp .message-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
}

#chatApp .message-group.sender {
    align-items: flex-end;
}

#chatApp .message-group.receiver {
    align-items: flex-start;
}

#chatApp .message-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

#chatApp .message-group.sender .message-bubble {
    background: var(--primary-color);
    color: var(--bg-white);
    border-bottom-right-radius: var(--radius-sm);
}

#chatApp .message-group.receiver .message-bubble {
    background: var(--bg-white);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: var(--radius-sm);
}

#chatApp .message-content {
    font-size: 0.875rem;
    line-height: 1.4;
    margin-bottom: 4px;
}

#chatApp .message-time {
    font-size: 0.75rem;
    opacity: 0.7;
    text-align: right;
    margin-top: 4px;
}

#chatApp .message-group.receiver .message-time {
    color: var(--text-light);
}

#chatApp .message-media {
    margin-bottom: 8px;
}

#chatApp .message-media img {
    width: 100%;
    max-width: 240px;
    height: auto;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.2s ease;
}

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

/* Typing Indicator */
#chatApp .typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-sm);
    max-width: 80%;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
}

#chatApp .typing-dots {
    display: flex;
    gap: 4px;
}

#chatApp .typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-light);
    border-radius: 50%;
    animation: typingDots 1.4s infinite;
}

#chatApp .typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

#chatApp .typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDots {
    0%, 60%, 100% { transform: scale(0.8); opacity: 0.5; }
    30% { transform: scale(1); opacity: 1; }
}

#chatApp .typing-text {
    font-size: 0.75rem;
    color: var(--text-light);
    font-style: italic;
}

/* Loading Indicator */
#chatApp .chat-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

#chatApp .loader-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
}

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

/* Chat Input */
#chatApp .chat-input-container {
    background: var(--bg-white);
    border-top: 1px solid var(--border-light);
    padding: 16px 20px;
    position: sticky;
    bottom: 0;
}

#chatApp .chat-input-form {
    display: flex;
    align-items: center;
    gap: 12px;
}

#chatApp .input-actions {
    display: flex;
    align-items: center;
}

#chatApp .attach-btn {
    width: 40px;
    height: 40px;
    color: var(--text-light);
    font-size: 1.1rem;
}

#chatApp .attach-btn:hover {
    color: var(--primary-color);
    background: var(--bg-gray-100);
}

#chatApp .input-wrapper {
    flex: 1;
    position: relative;
}

#chatApp .image-preview {
    position: relative;
    margin-bottom: 8px;
    display: inline-block;
}

#chatApp .image-preview img {
    max-width: 120px;
    max-height: 120px;
    border-radius: var(--radius-md);
    object-fit: cover;
    border: 1px solid var(--border-light);
}

#chatApp .remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #dc2626;
    color: var(--bg-white);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    box-shadow: var(--shadow-sm);
}

#chatApp #chat_input {
    width: 100%;
    min-height: 40px;
    max-height: 120px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--bg-white);
}

#chatApp #chat_input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#chatApp #chat_input::placeholder {
    color: var(--text-light);
}

#chatApp #chat_input:disabled {
    background: var(--bg-gray-100);
    color: var(--text-light);
    cursor: not-allowed;
}

#chatApp .send-btn {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: var(--bg-white);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    box-shadow: var(--shadow-sm);
}

#chatApp .send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

#chatApp .send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    background: var(--border-color);
}

/* Service Colors */
#chatApp .service-item[data-service-color="#561792"] .service-icon {
    background: #561792;
}

#chatApp .service-item[data-service-color="#10b981"] .service-icon {
    background: #10b981;
}

#chatApp .service-item[data-service-color="#f59e0b"] .service-icon {
    background: #f59e0b;
}

#chatApp .service-item[data-service-color="#8b5cf6"] .service-icon {
    background: #8b5cf6;
}

/* Animations */
#chatApp .service-item {
    animation: fadeInUp 0.3s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

#chatApp .service-item:nth-child(1) { animation-delay: 0.1s; }
#chatApp .service-item:nth-child(2) { animation-delay: 0.2s; }
#chatApp .service-item:nth-child(3) { animation-delay: 0.3s; }
#chatApp .service-item:nth-child(4) { animation-delay: 0.4s; }

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

/* View Transitions */
#chatApp .services-view,
#chatApp .chat-view {
    transition: all 0.3s ease;
}

#chatApp .services-view.slide-out {
    transform: translateX(-100%);
    opacity: 0;
}

#chatApp .chat-view.slide-in {
    transform: translateX(0);
    opacity: 1;
}


/* Message Dropdown Styles */
#chatApp .message-bubble {
    position: relative;
}

#chatApp .message-dropdown {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
}

#chatApp .dropdown-btn {
    background: rgba(0, 0, 0, 0.1);
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    font-size: 10px;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

#chatApp .dropdown-btn:hover {
    background: rgba(0, 0, 0, 0.2);
    color: white;
}

#chatApp .message-group.sender:hover .dropdown-btn {
    opacity: 1;
}

#chatApp .dropdown-menu {
    position: absolute;
    top: 100%;
    padding: 0 !important;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 140px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
    transition: all 0.2s ease;
    margin-top: 4px;
}

#chatApp .dropdown-menu.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#chatApp .dropdown-option {
    width: 100%;
    padding: 7px 7px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 12px;
    color: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease;
}

#chatApp .dropdown-option:hover {
    background: #f8fafc;
}

#chatApp .dropdown-option:first-child {
    border-top-left-radius: 7px;
    border-top-right-radius: 7px;
}

#chatApp .dropdown-option:last-child {
    border-bottom-left-radius: 7px;
    border-bottom-right-radius: 7px;
}

#chatApp .dropdown-option.delete-option {
    color: #df0000;
}

#chatApp .dropdown-option.delete-option:hover {
    background: rgba(239, 68, 68, 0.1);
}

#chatApp .dropdown-option i {
    font-size: 11px;
    width: 14px;
    opacity: 0.7;
}

/* Ensure message content has proper spacing for dropdown */
#chatApp .message-group.sender .message-bubble {
    padding-right: 36px; /* Make space for dropdown button */
}


/* Mobile Responsive */
@media (max-width: 768px) {
    #chatApp {
        width: 100vw;
        height: 800px;
        max-height: calc(83vh);
        bottom: 12px;
        right: 0;
    }
    
    #chatApp .chat-body {
        padding: 16px;
    }
    
    #chatApp .chat-input-container {
        padding: 12px 16px;
    }
    
    #chatApp .message-bubble {
        max-width: 85%;
    }
    
    #chatApp .services-list {
        padding: 12px;
    }
    
    #chatApp .service-item {
        padding: 12px;
    }
    
    #chatApp .service-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    #chatApp .service-name {
        font-size: 0.9rem;
    }
    
    #chatApp .last-message {
        font-size: 0.75rem;
    }
}