/* ==================== ENHANCED MESSAGING SYSTEM STYLES ==================== */

/* Driver Messaging System */
.enhanced-messaging-system {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95) 0%, rgba(30, 41, 59, 0.90) 100%);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 20px;
    padding: 0;
    margin-bottom: 3rem; /* Increased spacing from routes section */
    margin-top: 2rem; /* Add top margin for better separation */
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow-y: auto; /* Allow vertical scrolling */
    overflow-x: hidden; /* Hide horizontal scrollbar */
    transition: all 0.3s ease;
    display: block !important; /* Force visibility */
    visibility: visible !important; /* Force visibility */
    min-height: 400px; /* Adequate min-height for content */
    max-height: 600px; /* Sufficient max-height for scrolling */
    z-index: 10; /* Ensure proper layering */
}

/* Ensure proper spacing after messaging system */
.enhanced-messaging-system + h3,
.enhanced-messaging-system + * {
    margin-top: 2rem !important;
    clear: both; /* Prevent float conflicts */
}

/* Fix any potential route list conflicts */
.driver-route-list {
    clear: both;
    margin-top: 2rem !important;
    z-index: 5;
    position: relative;
}

.enhanced-messaging-system::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.8), transparent);
    animation: shimmer 2s linear infinite;
}

/* Messaging Header */
.messaging-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.05);
}

.messaging-title {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #e2e8f0;
}

.messaging-title i {
    color: #3b82f6;
    font-size: 1.25rem;
}

.messaging-title h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.message-count {
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    animation: messagePulse 2s infinite;
}

.messaging-action-btn {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    color: #3b82f6;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.messaging-action-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: scale(1.05);
}

/* Messaging Content */
.messaging-content {
    padding: 1.5rem 2rem 2rem;
    max-height: 400px;
    transition: max-height 0.3s ease;
}

.messaging-content.collapsed {
    max-height: 0;
    padding: 0 2rem;
    overflow: hidden;
}

/* Status Indicator */
.messaging-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 12px;
    color: #e2e8f0;
}

.status-indicator.online {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    animation: messagePulse 2s infinite;
}

.status-indicator.offline {
    background: #ef4444;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #3b82f6;
    font-size: 0.875rem;
    margin-left: auto;
}

.typing-dots {
    display: flex;
    gap: 2px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: #3b82f6;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

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

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

/* Messages Container */
.messages-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    min-height: 200px;
    max-height: 250px; /* Reduced to leave more space for input */
    overflow-y: auto;
    padding: 1rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(59, 130, 246, 0.1);
    flex-shrink: 0; /* Prevent shrinking */
}

.welcome-message {
    text-align: center;
    color: #94a3b8;
    padding: 2rem 1rem;
}

.welcome-message i {
    font-size: 2rem;
    color: #3b82f6;
    margin-bottom: 1rem;
}

.welcome-message p {
    margin: 0.5rem 0;
    font-size: 0.875rem;
}

/* Message Bubbles */
.message-bubble {
    margin: 1rem 0;
    animation: slideIn 0.3s ease;
}

.message-bubble.sent {
    text-align: right;
}

.message-bubble.received {
    text-align: left;
}

.message-content {
    display: inline-block;
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 20px;
    color: white;
    font-size: 0.875rem;
    line-height: 1.4;
    position: relative;
}

.message-bubble.sent .message-content {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    border-bottom-right-radius: 8px;
}

.message-bubble.received .message-content {
    background: linear-gradient(135deg, rgba(75, 85, 99, 0.8) 0%, rgba(55, 65, 81, 0.9) 100%);
    border-bottom-left-radius: 8px;
}

.message-time {
    font-size: 0.75rem;
    color: #94a3b8;
    margin: 0.25rem 0.5rem 0;
}

.message-status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: #94a3b8;
    margin-left: 0.5rem;
}

/* Message Input */
.message-input-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

#driverMessageInput {
    flex: 1;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    color: #e2e8f0;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.3s ease;
}

#driverMessageInput:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: rgba(15, 23, 42, 0.95);
}

.message-input-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.emoji-btn, .send-btn {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 10px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #3b82f6;
}

.emoji-btn {
    font-size: 1.25rem;
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
}

.send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover, .emoji-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: scale(1.1);
}

/* Message Tools */
.message-tools {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.tool-btn {
    background: rgba(75, 85, 99, 0.3);
    border: 1px solid rgba(75, 85, 99, 0.5);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #e2e8f0;
    font-size: 0.875rem;
}

.tool-btn.emergency {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    color: #fca5a5;
}

.tool-btn:hover {
    background: rgba(75, 85, 99, 0.5);
    transform: translateY(-2px);
}

.tool-btn.emergency:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Quick Replies */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.quick-reply-btn {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #3b82f6;
    font-size: 0.8rem;
    white-space: nowrap;
}

.quick-reply-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: translateY(-1px);
}

/* Management Messaging System */
.management-messaging-system {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.95) 0%, rgba(30, 41, 59, 0.90) 100%);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 16px;
    padding: 1.5rem;
    margin: 1.5rem 0;
    backdrop-filter: blur(15px);
}

/* Communication Header */
.communication-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(34, 197, 94, 0.2);
}

.driver-online-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #e2e8f0;
}

.driver-online-status small {
    color: #94a3b8;
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.communication-actions {
    display: flex;
    gap: 1rem;
}

.comm-action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.25rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.875rem;
    font-weight: 500;
}

.comm-action-btn.call {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
}

.comm-action-btn.video {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
}

.comm-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

/* Admin Messages Container */
.admin-messages-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    min-height: 250px;
    max-height: 350px;
    overflow-y: auto;
    padding: 1rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.messages-history {
    height: 100%;
}

.no-messages-state {
    text-align: center;
    color: #94a3b8;
    padding: 3rem 1rem;
}

.no-messages-state i {
    font-size: 3rem;
    color: #34d399;
    margin-bottom: 1rem;
}

/* Admin Message Input */
.admin-message-input-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.admin-message-input-wrapper {
    margin-bottom: 1rem;
}

#adminMessageInput {
    width: 100%;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 10px;
    padding: 1rem;
    color: #e2e8f0;
    font-size: 0.875rem;
    resize: vertical;
    min-height: 80px;
    outline: none;
    font-family: inherit;
    transition: all 0.3s ease;
}

#adminMessageInput:focus {
    border-color: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
    background: rgba(15, 23, 42, 0.95);
}

.admin-message-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.admin-tool-btn {
    background: rgba(75, 85, 99, 0.3);
    border: 1px solid rgba(75, 85, 99, 0.5);
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #e2e8f0;
}

.admin-tool-btn.priority {
    background: rgba(251, 191, 36, 0.2);
    border-color: rgba(251, 191, 36, 0.5);
    color: #fbbf24;
}

.admin-tool-btn:hover {
    background: rgba(75, 85, 99, 0.5);
    transform: scale(1.1);
}

.admin-tool-btn.priority:hover {
    background: rgba(251, 191, 36, 0.3);
}

.admin-send-btn {
    background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.5rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.admin-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.admin-send-btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(34, 197, 94, 0.3);
}

/* Admin Quick Messages */
.admin-quick-messages {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.admin-quick-btn {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #22c55e;
    font-size: 0.8rem;
    white-space: nowrap;
}

.admin-quick-btn:hover {
    background: rgba(34, 197, 94, 0.2);
    transform: translateY(-1px);
}

/* Message Statistics */
.message-statistics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(34, 197, 94, 0.2);
}

.message-statistics .stat-item {
    text-align: center;
    color: #e2e8f0;
}

.message-statistics .stat-item i {
    color: #22c55e;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.message-statistics .stat-item span {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: #22c55e;
}

.message-statistics .stat-item label {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 0.25rem;
}

/* Enhanced Call Button */
.enhanced-call-btn {
    position: relative;
    background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
    border: none;
    color: white;
    transition: all 0.3s ease;
}

.enhanced-call-btn:hover {
    background: linear-gradient(135deg, #16a34a 0%, #14532d 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(34, 197, 94, 0.4);
}

.enhanced-call-btn small {
    display: block;
    font-size: 0.7rem;
    opacity: 0.8;
    margin-top: 2px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .messaging-header {
        padding: 1rem;
    }
    
    .messaging-content {
        padding: 1rem;
    }
    
    .message-input-wrapper {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .communication-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .comm-action-btn {
        width: 100%;
        justify-content: center;
    }
    
    .message-statistics {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .admin-quick-messages {
        flex-direction: column;
    }
    
    .admin-quick-btn {
        text-align: center;
    }
}

/* Animations */
@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(200%); }
}

@keyframes slideIn {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes messagePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Scrollbar Styling for Message Containers */
.messages-container::-webkit-scrollbar,
.admin-messages-container::-webkit-scrollbar,
.enhanced-messaging-system::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track,
.admin-messages-container::-webkit-scrollbar-track,
.enhanced-messaging-system::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb,
.admin-messages-container::-webkit-scrollbar-thumb,
.enhanced-messaging-system::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.5);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.admin-messages-container::-webkit-scrollbar-thumb:hover,
.enhanced-messaging-system::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.7);
    background-clip: padding-box;
}
