/* ====== Reset ====== */
#smart-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

#smart-chat-widget button {
    font-family: inherit;
    box-sizing: border-box;
}

#smart-chat-widget #chat-close-btn {
    appearance: none;
    -webkit-appearance: none;

    margin: 0;
    padding: 0;

    width: 36px;
    height: 36px;

    min-width: 36px;
    min-height: 36px;

    max-width: 36px;
    max-height: 36px;

    border: none;
    outline: none;

    background: rgba(255,255,255,0.12);

    color: #ffffff;

    display: flex;
    align-items: center;
    justify-content: center;

    line-height: 1;
    font-size: 18px;

    flex: 0 0 36px;

    cursor: pointer;
}

/* ====== ویجت اصلی ====== */
#smart-chat-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 999999;
    font-family: 'IRANSans', 'Vazir', 'Tahoma', Arial, sans-serif;
    direction: rtl;

    /* مهم: خود container نباید کلیک‌های سایت را بگیرد */
    pointer-events: none;
}

#chat-toggle,
#chat-toggle-btn {
    pointer-events: auto;
}

#smart-chat-widget #chat-box {
    order: 1;
}

#smart-chat-widget #chat-toggle {
    order: 2;
}
/* ====== دکمه باز کردن چت (آیکون زیبا) ====== */
#chat-toggle-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: linear-gradient(145deg, #4CAF50, #1B5E20);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 32px;
    box-shadow: 
        0 8px 32px rgba(76, 175, 80, 0.45),
        inset 0 -4px 0 rgba(0,0,0,0.15);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    user-select: none;
}

#chat-toggle-btn::after {
    content: '';
    position: absolute;
    font-size: 34px;
}

#chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 12px 48px rgba(76, 175, 80, 0.55);
}

#chat-toggle-btn:active {
    transform: scale(0.92);
}

/* نقطه اعلان */
#chat-toggle-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f44336;
    color: white;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: pulse 2s infinite;
    box-shadow: 0 2px 8px rgba(244, 67, 54, 0.4);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ====== باکس چت (کاملاً ثابت و حرفه‌ای) ====== */
#chat-box {
    width: 420px;
    height: 580px;
    max-height: 85vh;

    background: #ffffff;
    border-radius: 28px;

    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.25),
        0 4px 20px rgba(0, 0, 0, 0.08);

    display: flex;
    flex-direction: column;

    overflow: hidden;
    margin-bottom: 18px;

    border: 1px solid rgba(255,255,255,0.1);

    opacity: 0;
    visibility: hidden;
    transform: translateY(40px) scale(0.92);

    pointer-events: none;

    transition:
        opacity 0.3s ease,
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0.3s;
}

#chat-box.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ====== هدر ====== */
#chat-header {
    background: linear-gradient(135deg, #1a237e, #0d47a1);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 64px;
    border-radius: 28px 28px 0 0;
    position: relative;
    z-index: 2;
}

#chat-header .chat-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 15px;
}

#chat-header .chat-title .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

#chat-header .chat-status {
    font-size: 11px;
    opacity: 0.8;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 6px;
}

#chat-header .chat-status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    display: inline-block;
    animation: blink 1.4s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

#chat-close-btn {
    background: rgba(255,255,255,0.12);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-close-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: rotate(90deg);
}

/* ====== پیام‌ها (اسکرول‌دار) ====== */
#chat-messages {
    flex: 1 1 0;
    min-height: 0;

    padding: 16px 18px 8px 18px;

    overflow-y: auto;
    overflow-x: hidden;

    background: #f0f2f5;
    direction: rtl;

    display: flex;
    flex-direction: column;

    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#chat-messages::-webkit-scrollbar {
    width: 8px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #c1c7cd;
    border-radius: 10px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0a6ac;
}

/* ====== پیام‌ها ====== */
.chat-message {
    margin-bottom: 10px;
    padding: 10px 16px;
    border-radius: 18px;
    max-width: 88%;
    word-wrap: break-word;
    line-height: 2;
    font-size: 14px;
    animation: messageIn 0.3s ease-out;
    clear: both;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.chat-message.bot {
    background: #ffffff;
    color: #1a1a2e;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    float: right;
    clear: both;
    align-self: flex-start;
}

.chat-message.user {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: white;
    border-bottom-left-radius: 6px;
    float: left;
    clear: both;
    align-self: flex-end;
}

.chat-message.bot a {
    color: #1a237e;
    text-decoration: underline;
}

.chat-message.bot button,
.chat-message.bot .chat-add-btn {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
    color: white;
    border: none;
    padding: 6px 18px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    margin-top: 8px;
    transition: 0.3s;
    font-family: inherit;
}

.chat-message.bot button:hover,
.chat-message.bot .chat-add-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.35);
}

/* ====== تایپینگ ====== */
.typing {
    display: flex;
    gap: 5px;
    padding: 12px 18px;
    background: #ffffff;
    border-radius: 18px;
    border-bottom-right-radius: 6px;
    width: fit-content;
    float: right;
    clear: both;
    align-self: flex-start;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.typing span {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4CAF50;
    animation: typingDot 1.4s infinite;
}

.typing span:nth-child(1) { animation-delay: 0s; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-8px); }
}

/* ====== دکمه‌های سریع ====== */
#chat-actions {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    background: #ffffff;
    border-top: 1px solid #e8ecf1;
    flex-wrap: wrap;
    flex-shrink: 0;
    min-height: 50px;
    align-items: center;
}

.quick-btn {
    background: #f0f2f5;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    color: #555;
    transition: 0.3s;
    font-family: inherit;
    font-weight: 500;
}

.quick-btn:hover {
    background: #4CAF50;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
}

/* ====== ورودی ====== */
#chat-input-area {
    display: flex;
    padding: 10px 16px 14px 16px;
    background: #ffffff;
    border-top: 1px solid #e8ecf1;
    gap: 10px;
    flex-shrink: 0;
    min-height: 60px;
    align-items: center;
}

#chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid #e8ecf1;
    border-radius: 30px;
    outline: none;
    font-size: 14px;
    transition: 0.3s;
    direction: rtl;
    font-family: inherit;
    background: #f8f9fa;
    min-width: 0;
}

#chat-input:focus {
    border-color: #4CAF50;
    background: white;
    box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.1);
}

#chat-input::placeholder {
    color: #b0b8c0;
}

#chat-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4CAF50, #1B5E20);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 20px;
    transition: 0.3s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
}

#chat-send-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 24px rgba(76, 175, 80, 0.4);
}

#chat-send-btn:active {
    transform: scale(0.92);
}

/* ====== ریسپانسیو ====== */
@media (max-width: 576px) {
    #smart-chat-widget {
        bottom: 10px;
        right: 10px;
        left: 10px;

         pointer-events: none;
    }

    #chat-toggle,
    #chat-toggle-btn {
    pointer-events: auto;
}

    #chat-box {
        width: 100%;
        height: min(90vh, 680px);
        max-height: calc(100vh - 20px);

        border-radius: 20px;
        margin-bottom: 10px;
    }

    #chat-header {
        border-radius: 20px 20px 0 0;
        min-height: 56px;
        padding: 12px 16px;
    }

    #chat-toggle-btn {
        width: 58px;
        height: 58px;
    }

    #chat-messages {
        min-height: 0;
        padding: 12px 14px;
    }
}

/* ====== دارک مود ====== */
@media (prefers-color-scheme: dark) {
    #chat-box {
        background: #1a1a2e;
        border-color: rgba(255,255,255,0.05);
    }
    
    #chat-messages {
        background: #16162a;
    }
    
    .chat-message.bot {
        background: #2a2a44;
        color: #e8e8f0;
    }
    
    #chat-input {
        background: #2a2a44;
        border-color: #3a3a5a;
        color: white;
    }
    
    #chat-input::placeholder {
        color: #6a6a8a;
    }
    
    #chat-actions {
        background: #1a1a2e;
        border-color: #2a2a44;
    }
    
    .quick-btn {
        background: #2a2a44;
        color: #b0b0c8;
    }
    
    .quick-btn:hover {
        background: #4CAF50;
        color: white;
    }
    
    #chat-input-area {
        background: #1a1a2e;
        border-color: #2a2a44;
    }
}

/* موقعیت صحیح آیکن چت */
/* ===== موقعیت مستقل آیکن چت ===== */

#smart-chat-widget {
    position: fixed !important;
    right: 20px !important;
    bottom: 20px !important;
    left: auto !important;
    width: 420px !important;
}

#smart-chat-widget #chat-toggle {
    position: absolute !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 68px !important;
    height: 68px !important;
}

#smart-chat-widget #chat-toggle-btn {
    position: absolute !important;
    right: 0 !important;
    bottom: 0 !important;
}

@media (max-width: 576px) {

    /* خود کانتینر فقط فضای آیکن را اشغال کند */
    #smart-chat-widget {
        position: fixed;
        right: 10px;
        bottom: 10px;
        left: auto;

        width: 58px;
        height: 58px;

        pointer-events: none;
    }

    /* آیکن قابل کلیک باشد */
    #chat-toggle-btn {
        width: 58px;
        height: 58px;
        pointer-events: auto;
    }

    /*
     * پنجره چت مستقل از اندازه کانتینر باشد
     * و کل عرض صفحه را نپوشاند
     */
    #chat-box {
    position: fixed;

    right: 10px;
    bottom: 78px;
    left: 10px;

    width: auto;

    height: calc(100dvh - 110px);
    max-height: calc(100dvh - 110px);

    margin: 0;

    border-radius: 20px;

    pointer-events: none;
}

    #chat-box.is-open {
        pointer-events: auto;
    }

    #chat-header {
        border-radius: 20px 20px 0 0;
        min-height: 56px;
        padding: 12px 16px;
    }

    #chat-messages {
        min-height: 0;
        padding: 12px 14px;
    }
}