* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

/* Customer Chat Styles */
.chat-container {
    max-width: 400px;
    margin: 50px auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    height: auto; 
    display: flex;
    flex-direction: column;
    max-height: 100vh; 
}

.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-close-chat {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-close-chat:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.chat-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    font-size: 14px;
}

.status-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ff4757;
    margin-right: 8px;
}

.status-indicator.online::before {
    background: #2ed573;
}

/* Start Chat Form */
.chat-start-form {
    padding: 30px;
}

.chat-start-form h4 {
    margin-bottom: 20px;
    color: #2c3e50;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s;
}

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

/* Chat Window */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Important for flex child to respect parent height */
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #fafbfc;
    min-height: 400px;
    max-height: 500px;
    height: 500px;
}

.message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-end;
}

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

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

.message.system {
    justify-content: center;
    text-align: center;
}

.message.system p {
    background: #e8ecef;
    color: #666;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.customer .message-bubble {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.agent .message-bubble {
    background: #e8ecef;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: -5px;
}

/* Customer message timestamp - left aligned */
.message.customer .message-time {
    text-align: left;
    color: rgba(15, 14, 14, 0.8);
}

/* Agent message timestamp - right aligned */
.message.agent .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 20px 10px;
    display: flex;
    align-items: center;
}

.typing-indicator span {
    height: 8px;
    width: 8px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
    animation: typing 1.4s infinite;
}

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

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

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

/* Chat Input */
.chat-input-area {
    padding: 5px;
    background: white;
    border-top: 1px solid #e1e8ed;
    flex-shrink: 0; /* Prevent input area from shrinking */
}

#messageForm {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e1e8ed;
    border-radius: 25px;
    font-size: 15px;
    outline: none;
    transition: all 0.3s;
}

#messageInput:focus {
    border-color: #667eea;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-send {
    background: #667eea;
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
}

.btn-send:hover {
    background: #5a67d8;
}

/* Admin Dashboard Styles */
.admin-dashboard {
    min-height: 100vh;
    background: #f5f7fa;
}

.dashboard-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.dashboard-header h2 {
    font-size: 24px;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

.btn-home {
    background: rgba(52, 152, 219, 0.8);
    color: white;
    padding: 8px 20px;
    font-size: 14px;
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.3s ease;
}

.btn-home:hover {
    background: rgba(52, 152, 219, 1);
}

.btn-logout {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 20px;
    font-size: 14px;
}

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

.dashboard-content {
    display: flex;
    height: calc(100vh - 80px);
    max-height: calc(100vh - 80px); /* Ensure it doesn't exceed viewport */
    overflow: hidden; /* Prevent overflow */
}

/* Sessions Panel */
.sessions-panel {
    width: 350px;
    background: white;
    border-right: 1px solid #e1e8ed;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 80px);
}

.panel-section {
    border-bottom: 1px solid #e1e8ed;
}

.panel-section h3 {
    padding: 20px;
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.count {
    background: #667eea;
    color: white;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 12px;
}

.sessions-list {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.session-item {
    padding: 15px;
    margin-bottom: 10px;
    background: #f8f9fa;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-item:hover {
    background: #e8ecef;
    transform: translateX(5px);
}

.session-item.active {
    background: #e3e8ff;
    border-left: 4px solid #667eea;
}

.session-info strong {
    display: block;
    margin-bottom: 4px;
    color: #2c3e50;
}

.session-info small {
    display: block;
    color: #666;
    font-size: 13px;
    margin-bottom: 2px;
}

.btn-accept {
    background: #2ed573;
    color: white;
    padding: 8px 16px;
    font-size: 14px;
}

.btn-accept:hover {
    background: #26d764;
}

.unread-badge {
    background: #ff4757;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    max-height: calc(100vh - 120px); /* Fixed height for admin */
    min-height: 0; /* Important for flex child */
}

.chat-panel .chat-header {
    padding: 20px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-close-chat {
    background: #ff4757;
    color: white;
    padding: 8px 20px;
    font-size: 14px;
}

.btn-close-chat:hover {
    background: #ff3838;
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        margin: 0;
        max-width: 100%;
        height: auto;
        min-height: 100vh;
        border-radius: 0;
        max-height: none;
    }
    
    .messages-container {
        min-height: 200px;
        max-height: 60vh;
    }
    
    .dashboard-content {
        flex-direction: column;
    }
    
    .sessions-panel {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid #e1e8ed;
    }
    
    .chat-panel {
        height: 60%;
    }
}

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

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

.messages-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Chat Interface */
#chatInterface {
    position: relative;
    height: 100%;
}

/* Chat Closed Message */
.chat-closed-message {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.closed-overlay {
    text-align: center;
    padding: 40px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.1);
    max-width: 350px;
}

.closed-content h3 {
    color: #e74c3c;
    margin-bottom: 15px;
    font-size: 18px;
}

.closed-content p {
    color: #666;
    margin-bottom: 10px;
    font-size: 14px;
}

.start-new-chat-btn {
    margin-top: 20px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.start-new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}



/* Canned Responses Modal */
.canned-responses-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    margin: 5% auto;
    background: white;
    border-radius: 12px;
    padding: 0;
    max-width: 800px;
    width: 100%;
    max-height: 80%;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

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

.modal-header h3 {
    margin: 0;
    color: #333;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.modal-body {
    padding: 20px;
    max-height: 600px;
    overflow-y: auto;
}

.canned-response-item {
    padding: 15px;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.canned-response-item:hover {
    background: #f8f9fa;
    border-color: #667eea;
}

.canned-response-item strong {
    display: block;
    margin-bottom: 5px;
    color: #333;
}

.canned-response-item p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Rating Modal */
.rating-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.rating-stars {
    text-align: center;
    margin: 20px 0;
}

.star {
    font-size: 30px;
    color: #ddd;
    cursor: pointer;
    transition: color 0.2s;
    margin: 0 2px;
}

.star:hover,
.star.selected {
    color: #ffc107;
}

#ratingFeedback {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin: 15px 0;
    min-height: 80px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.modal-actions button:first-child {
    background: #6c757d;
    color: white;
}

.modal-actions button:last-child {
    background: #667eea;
    color: white;
}



/* Agent Status Indicators */
.agent-status {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.agent-status.available {
    background: #d4edda;
    color: #155724;
}

.agent-status.busy {
    background: #f8d7da;
    color: #721c24;
}

.agent-status.away {
    background: #fff3cd;
    color: #856404;
}

.agent-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.agent-status.available::before {
    background: #28a745;
}

.agent-status.busy::before {
    background: #dc3545;
}

.agent-status.away::before {
    background: #ffc107;
}

/* Enhanced Typing Indicator */
.typing-indicator-enhanced {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: #f8f9fa;
    border-radius: 15px;
    margin: 5px 0;
    font-size: 13px;
    color: #666;
}

.typing-dots {
    display: flex;
    margin-left: 8px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: #999;
    border-radius: 50%;
    margin: 0 1px;
    animation: typing-bounce 1.4s infinite;
}

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

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

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

/* Message Read Receipts */
.message-status {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
}

.message-status.sent::after {
    content: '✓';
}

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

.message-status.read::after {
    content: '✓✓';
    color: #667eea;
}



/* Transfer Modal */
.transfer-modal .modal-body {
    padding: 20px;
}

/* Mobile Improvements */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    
    .canned-responses-modal .modal-body {
        max-height: 60vh;
    }
}

/* Loading States */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.message-sending {
    opacity: 0.7;
}

.message-sending::after {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 1px solid currentColor;
    border-top: 1px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.quick-action-btn {
    padding: 6px 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-action-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 10px;
    right: 10px;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    z-index: 1000;
}

.connection-status.connected {
    background: #d4edda;
    color: #155724;
}

.connection-status.disconnected {
    background: #f8d7da;
    color: #721c24;
}

.connection-status.reconnecting {
    background: #fff3cd;
    color: #856404;
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.quick-action-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 20px;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.quick-action-btn:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Quick Actions Toolbar (Customer) */
.quick-actions-toolbar {
    padding: 0px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    padding: 12px 20px;
    flex-shrink: 0;
}

.quick-actions-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-actions-buttons .quick-action-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: capitalize;
}

.quick-actions-buttons .quick-action-btn:hover {
    background: #5a6fd8;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.quick-actions-buttons .quick-action-btn:active {
    transform: translateY(0);
}

/* Show quick actions button in chat input area */
.show-quick-actions-btn {
    background: #17a2b8;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s;
}

.show-quick-actions-btn:hover {
    background: #138496;
}
