/* Modern Chat Widget Styles */

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Chat Button */
.chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.3s ease;
    position: relative;
}

.chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.chat-button-active {
    transform: scale(0.95);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.chat-button i {
    font-size: 26px;
}

/* Unread Badge */
.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 12px;
    min-width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.5);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chat Container */
.chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s ease;
}

.chat-container.chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

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

.chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 16px;
}

.chat-header i {
    font-size: 20px;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    transition: opacity 0.2s;
}

.chat-close:hover {
    opacity: 0.8;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8f9fa;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* Welcome Message */
.chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.chat-welcome-icon {
    font-size: 48px;
    color: #667eea;
    margin-bottom: 16px;
    display: block;
}

/* Chat Messages */
.chat-message {
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease;
}

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

.chat-message-user {
    align-items: flex-end;
}

.chat-message-support {
    align-items: flex-start;
}

.chat-message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: break-word; /* Ensures very long words break */
    overflow-wrap: break-word; /* Modern browsers */
    position: relative;
    min-width: 0; /* Allows proper flex shrinking */
}

.chat-message-user .chat-message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message-support .chat-message-bubble {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.chat-message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

/* Chat Error */
.chat-error {
    background: #ffe0e0;
    color: #d32f2f;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Chat Input */
.chat-input-container {
    padding: 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 16px 16px;
    display: flex;
    gap: 12px;
}

.chat-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input:focus {
    border-color: #667eea;
}

.chat-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.chat-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-send:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .chat-container {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .chat-container.chat-open {
        position: fixed;
        top: 0;
        left: 0;
    }
    
    .chat-header {
        border-radius: 0;
    }
    
    .chat-input-container {
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 16px);
    }
    
    .chat-button {
        bottom: env(safe-area-inset-bottom, 20px);
    }
}

/* File Attachment Styles */
.chat-attach {
    background: none;
    border: none;
    color: #667eea;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
}

.chat-attach:hover {
    background: rgba(102, 126, 234, 0.1);
    color: #764ba2;
}

.chat-attach:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-attach i {
    font-size: 16px;
}

/* File Attachment Preview */
.chat-attachment-preview {
    padding: 10px 15px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.attachment-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    font-size: 13px;
}

.attachment-name {
    flex: 1;
    color: #333;
    display: flex;
    align-items: center;
    gap: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0; /* Allows flex item to shrink smaller than content */
}

.attachment-name i {
    color: #667eea;
}

.attachment-size {
    color: #666;
    font-size: 12px;
}

.attachment-remove {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.attachment-remove:hover {
    background: #f0f0f0;
    color: #666;
}

/* File input hidden */
.chat-file-input {
    display: none !important;
}

/* Message with attachments */
.chat-message-attachment {
    margin: 8px 0;
    padding: 8px 12px;
    background: #f0f4ff;
    border: 1px solid #d4e4ff;
    border-radius: 8px;
    font-size: 13px;
}

.chat-message-attachment i {
    color: #667eea;
    margin-right: 5px;
}

.attachment-download {
    background: none;
    border: none;
    color: #667eea;
    text-decoration: underline;
    cursor: pointer;
    font-size: 13px;
}

.attachment-download:hover {
    color: #764ba2;
}

/* Long filename handling in messages */
.filename-long {
    display: inline-block;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    cursor: help;
    position: relative;
}

.filename-long:hover::after {
    content: attr(data-full-name);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: normal;
    word-break: break-word;
    max-width: 300px;
    z-index: 10001;
    pointer-events: none;
    opacity: 1;
    animation: tooltipFadeIn 0.2s ease;
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(5px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Improved attachment info layout */
.attachment-info {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    font-size: 13px;
    min-width: 0; /* Important for flex children */
}

/* Ensure attachment name text can truncate properly */
.attachment-name span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}