/* =========================================
   ویجت چت شناور - استایل‌های عمومی
   ========================================= */

.chat-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 9999;
    font-family: 'Vazirmatn', sans-serif;
}

/* =========================================
   دکمه چت با انیمیشن ترکیبی قوی
   ========================================= */
.chat-toggle {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: linear-gradient(135deg, #240046, #6200ea);
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* انیمیشن ترکیبی: حرکت + چرخش + تپش + موج */
    animation: 
        dance 1.8s ease-in-out infinite,
        wave 2.5s ease-in-out infinite,
        pulseShadow 3s ease-in-out infinite;
    
    transition: transform 0.2s;
}

/* هاور دستی برای زمانی که کاربر نگه می‌دارد */
.chat-toggle:hover {
    animation-play-state: paused;
    transform: scale(1.15) rotate(5deg);
    box-shadow: 0 8px 30px rgba(98, 0, 234, 0.7);
}

/* =========================================
   انیمیشن رقص (بالا و پایین + چرخش)
   ========================================= */
@keyframes dance {
    0%   { transform: translateY(0) rotate(0deg) scale(1); }
    15%  { transform: translateY(-12px) rotate(6deg) scale(1.06); }
    30%  { transform: translateY(0) rotate(-4deg) scale(1); }
    45%  { transform: translateY(-8px) rotate(4deg) scale(1.04); }
    60%  { transform: translateY(0) rotate(-2deg) scale(1); }
    75%  { transform: translateY(-6px) rotate(2deg) scale(1.02); }
    100% { transform: translateY(0) rotate(0deg) scale(1); }
}

/* =========================================
   انیمیشن موج (حلقه‌های نور)
   ========================================= */
@keyframes wave {
    0% {
        box-shadow: 0 0 0 0 rgba(98, 0, 234, 0.6);
    }
    40% {
        box-shadow: 0 0 0 25px rgba(98, 0, 234, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(98, 0, 234, 0);
    }
}

/* =========================================
   انیمیشن تپش سایه (برای تنوع)
   ========================================= */
@keyframes pulseShadow {
    0%, 100% {
        box-shadow: 0 6px 20px rgba(98, 0, 234, 0.4);
    }
    50% {
        box-shadow: 0 10px 35px rgba(98, 0, 234, 0.7);
    }
}

/* =========================================
   آیکون‌های دکمه (چت / بستن)
   ========================================= */
.chat-toggle .fa-comment-dots {
    display: block;
}
.chat-toggle .fa-times {
    display: none;
}
.chat-widget.open .chat-toggle .fa-comment-dots {
    display: none;
}
.chat-widget.open .chat-toggle .fa-times {
    display: block;
}

/* وقتی چت باز است، انیمیشن متوقف شود */
.chat-widget.open .chat-toggle {
    animation-play-state: paused;
}

/* =========================================
   پنل چت
   ========================================= */
.chat-panel {
    position: absolute;
    bottom: 85px;
    right: 0;
    width: 380px;
    max-width: 90vw;
    height: 500px;
    max-height: 70vh;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    direction: rtl;
    text-align: right;
    border: 1px solid #e9ecef;
}

.chat-widget.open .chat-panel {
    display: flex;
}

/* =========================================
   هدر چت
   ========================================= */
.chat-header {
    background: linear-gradient(135deg, #240046, #6200ea);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}
.chat-header .close-chat {
    background: none;
    border: none;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
}

/* =========================================
   پیام‌ها
   ========================================= */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.chat-message.user {
    align-self: flex-end;
    background: #6200ea;
    color: white;
    border-bottom-left-radius: 4px;
}

.chat-message.bot {
    align-self: flex-start;
    background: white;
    color: #333;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.chat-message.bot .citation {
    font-size: 0.8rem;
    color: #6200ea;
    margin-top: 8px;
    border-top: 1px solid #e0e0e0;
    padding-top: 6px;
}

.chat-message .handoff-badge {
    margin-top: 10px;
    background: #ff9800;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    display: inline-block;
}

/* =========================================
   ورودی و دکمه ارسال
   ========================================= */
.chat-input-area {
    display: flex;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e9ecef;
    gap: 8px;
}

.chat-input-area input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 30px;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: border 0.2s;
}

.chat-input-area input:focus {
    border-color: #6200ea;
}

.chat-input-area button {
    background: #6200ea;
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-area button:hover:not(:disabled) {
    background: #4a00b0;
    transform: scale(1.05);
}

.chat-input-area button:disabled {
    background: #aaa;
    cursor: not-allowed;
}

/* =========================================
   موبایل
   ========================================= */
@media (max-width: 768px) {
    .chat-panel {
        width: 95vw;
        height: 60vh;
        bottom: 75px;
        right: 0;
    }

    .chat-toggle {
        width: 55px;
        height: 55px;
        font-size: 24px;
    }

    /* در موبایل انیمیشن را کمی ملایم‌تر کنیم */
    .chat-toggle {
        animation: 
            dance 2.2s ease-in-out infinite,
            wave 3s ease-in-out infinite,
            pulseShadow 3.5s ease-in-out infinite;
    }
}

/* =========================================
   اسپینر (حالت بارگذاری)
   ========================================= */
.loading-message {
    background: white !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08) !important;
    padding: 12px 20px !important;
    border-radius: 16px !important;
    border-bottom-right-radius: 4px !important;
    display: flex;
    align-items: center;
    min-height: 45px;
}

.typing-indicator {
    display: flex;
    gap: 6px;
    align-items: center;
}

.typing-indicator span {
    width: 10px;
    height: 10px;
    background: #6200ea;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* =========================================
   یادداشت دستی (جایگزین دکمه کارشناس)
   ========================================= */
.handoff-note {
    margin-top: 10px;
    padding: 8px 12px;
    background: #fff3cd;
    color: #856404;
    border-radius: 8px;
    font-size: 0.85rem;
    border-right: 3px solid #ffc107;
}