/* =====================================================
   🎨 Modern Professional Chat Widget CSS
   ===================================================== */

/* --- General Container --- */
#mlc-chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Sahel', 'Vazir', 'Tahoma', sans-serif;
}

/* --- Chat Button (دکمه چت) --- */
#mlc-chat-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 65px;
    height: 65px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: none;
    border: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

#mlc-chat-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

#mlc-chat-button:hover {
    transform: scale(1.05);
    box-shadow: none;
}

#mlc-chat-button:hover::before {
    opacity: 1;
}

#mlc-chat-button img {
    width: 65px;
    height: 75px;
    filter: brightness(0) invert(1);
    position: relative;
    z-index: 1;
}

#mlc-chat-button.mlc-hidden {
    display: none;
}

/* Unread Badge on Chat Button */
.mlc-unread-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    font-size: 11px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.6);
    border: 2px solid white;
    padding: 0 6px;
    animation: badgePulse 2s infinite;
    z-index: 2;
}

@keyframes badgePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(239, 68, 68, 0.6);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.8);
    }
}

/* Pulse animation removed for cleaner look */

/* --- Chat Window (پنجره چت) --- */
#mlc-chat-window {
    width: 380px;
    max-width: 90vw;
    height: 550px;
    max-height: 85vh;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Sahel', 'Vazir', sans-serif;
    direction: rtl;
    animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Chat Header (هدر چت) --- */
.mlc-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    position: relative;
    overflow: hidden;
}

.mlc-chat-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: headerShine 3s linear infinite;
}

@keyframes headerShine {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    100% {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

.mlc-admin-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    margin-left: 12px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    position: relative;
    z-index: 1;
}

.mlc-admin-name {
    font-weight: 600;
    flex-grow: 1;
    margin-right: 10px;
    font-size: 16px;
    position: relative;
    z-index: 1;
}

.mlc-admin-status {
    font-size: 0.75em;
    padding: 4px 10px;
    border-radius: 12px;
    margin-left: 10px;
    font-weight: 500;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(5px);
}

.mlc-admin-status.online {
    background-color: rgba(40, 167, 69, 0.9);
    box-shadow: 0 0 12px rgba(40, 167, 69, 0.5);
    animation: statusPulse 2s infinite;
}

.mlc-admin-status.offline {
    background-color: rgba(108, 117, 125, 0.8);
}

@keyframes statusPulse {
    0%, 100% {
        box-shadow: 0 0 12px rgba(40, 167, 69, 0.5);
    }
    50% {
        box-shadow: 0 0 20px rgba(40, 167, 69, 0.8);
    }
}

.mlc-close-chat {
    background: rgba(239, 68, 68, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    margin-right: auto;
    position: relative;
    z-index: 1;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.mlc-close-chat:hover {
    background: rgba(220, 38, 38, 1);
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.6);
}

/* --- Chat Messages Area (منطقه پیام‌ها) --- */
.mlc-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: linear-gradient(to bottom, #f8f9fa 0%, #ffffff 100%);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.mlc-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.mlc-chat-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
}

.mlc-chat-messages::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* --- Individual Messages (پیام‌ها) --- */
.mlc-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    margin-bottom: 8px;
    word-wrap: break-word;
    position: relative;
    animation: messageSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

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

/* Admin/Bot Messages (پیام‌های ادمین/ربات) - سمت راست */
.mlc-message.mlc-admin-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.mlc-message.mlc-admin-message .mlc-message-link,
.mlc-message.mlc-admin-message a {
    color: #fde68a !important;
    text-decoration: underline;
    font-weight: 600;
    transition: color 0.2s;
}

.mlc-message.mlc-admin-message .mlc-message-link:hover,
.mlc-message.mlc-admin-message a:hover {
    color: #fef3c7 !important;
}

/* Visitor Messages (پیام‌های بازدیدکننده) - سمت چپ */
.mlc-message.mlc-visitor-message {
    background: linear-gradient(135deg, #e0e7ff 0%, #f0f4ff 100%);
    color: #1e293b;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(102, 126, 234, 0.2);
}

.mlc-message.mlc-visitor-message .mlc-message-link,
.mlc-message.mlc-visitor-message a {
    color: #667eea !important;
    text-decoration: underline;
    font-weight: 600;
    transition: color 0.2s;
}

.mlc-message.mlc-visitor-message .mlc-message-link:hover,
.mlc-message.mlc-visitor-message a:hover {
    color: #764ba2 !important;
}

/* System/Welcome Messages (پیام‌های سیستم) */
.mlc-message.mlc-system-message,
.mlc-message.mlc-welcome-message {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    align-self: center;
    text-align: center;
    border-radius: 18px;
    font-size: 0.9em;
    padding: 10px 16px;
    border: 1px solid rgba(146, 64, 14, 0.2);
}

/* Message Time (زمان پیام) */
.mlc-message-time {
    font-size: 0.7em;
    opacity: 0.7;
    display: block;
    margin-top: 6px;
    text-align: left;
}

.mlc-visitor-message .mlc-message-time {
    text-align: right;
}

/* Typing Indicator (نشانگر تایپ) */
.mlc-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 18px;
    max-width: 60px;
    align-self: flex-start;
    border-bottom-right-radius: 4px;
}

.mlc-typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.8);
    animation: typing 1.4s infinite;
}

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

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

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

/* --- Chat Ended Message (پیام پایان چت) --- */
.mlc-chat-ended-message {
    text-align: center;
    padding: 20px;
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-radius: 12px;
    margin: 10px;
}

#mlc-start-new-chat {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#mlc-start-new-chat:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
}

/* --- Chat Input Area (منطقه ورودی) --- */
.mlc-chat-input-area {
    display: flex;
    padding: 15px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    gap: 10px;
    align-items: flex-end;
}

#mlc-chat-input {
    flex: 1;
    border: 2px solid #e9ecef;
    border-radius: 20px;
    padding: 12px 18px;
    font-size: 14px;
    resize: none;
    font-family: inherit;
    max-height: 100px;
    min-height: 44px;
    transition: all 0.3s;
    background: white;
}

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

#mlc-send-message {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

#mlc-send-message:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.5);
}

#mlc-send-message:active {
    transform: translateY(0);
}

#mlc-end-chat {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s;
    line-height: 1.3;
    text-align: center;
}

#mlc-end-chat:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* --- Responsive Design (طراحی واکنش‌گرا) --- */
@media (max-width: 768px) {
    #mlc-chat-widget-container {
        right: 10px;
        bottom: 10px;
    }
    
    #mlc-chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-width: calc(100vw - 20px);
        max-height: calc(100vh - 100px);
        border-radius: 12px;
    }
    
    #mlc-chat-button {
        width: 55px;
        height: 55px;
        box-shadow: none;
        border: none;
    }
    
    .mlc-unread-badge {
        top: -4px;
        right: -4px;
        min-width: 20px;
        height: 20px;
        font-size: 10px;
        border-radius: 10px;
    }
    
    .mlc-chat-header {
        padding: 14px 16px;
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
    }
    
    .mlc-admin-avatar {
        width: 38px;
        height: 38px;
        margin-left: 10px;
    }
    
    .mlc-admin-name {
        font-size: 14px;
    }
    
    .mlc-chat-messages {
        padding: 15px;
        gap: 10px;
    }
    
    .mlc-message {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 14px;
    }
    
    .mlc-chat-input-area {
        padding: 12px;
        gap: 8px;
    }
    
    #mlc-chat-input {
        padding: 10px 14px;
        font-size: 14px;
        min-height: 40px;
    }
    
    #mlc-send-message {
        padding: 10px 18px;
        font-size: 13px;
    }
    
    #mlc-end-chat {
        padding: 7px 12px;
        font-size: 11px;
    }
}

/* --- Link Styling in Messages --- */
.mlc-message a {
    color: inherit;
    text-decoration: underline;
    font-weight: 500;
    transition: opacity 0.2s;
}

.mlc-message a:hover {
    opacity: 0.8;
}

/* --- Accessibility --- */
*:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
