/* ============ Chatbot Widget ============ */
#alijm-ai-chatbot {
    position: fixed;
    bottom: 50px;
    z-index: 999999;
    font-family: Tahoma, Arial, sans-serif;
    direction: rtl;
}

.alijm-ai-chatbot-right { right: 10px; }
.alijm-ai-chatbot-left  { left: 10px; }

#alijm-ai-chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--alijm-ai-color, #2271b1);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

#alijm-ai-chatbot-toggle:hover {
    transform: scale(1.1);
}

/* ============ پنجره چت - دسکتاپ ============ */
#alijm-ai-chatbot-window {
    display: none;
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    overflow: hidden;
    flex-direction: column;
}

.alijm-ai-chatbot-left #alijm-ai-chatbot-window {
    right: auto;
    left: 0;
}

#alijm-ai-chatbot.open #alijm-ai-chatbot-window {
    display: flex;
}

.alijm-ai-chatbot-header {
    background: var(--alijm-ai-color, #2271b1);
    color: #fff;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.alijm-ai-chatbot-title {
    font-weight: bold;
    font-size: 15px;
}

#alijm-ai-chatbot-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

#alijm-ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background: #f8f9fa;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.alijm-ai-msg {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.alijm-ai-msg-user {
    margin-right: auto;
    align-items: flex-end;
    margin-left: 0;
}

.alijm-ai-msg-assistant {
    margin-left: auto;
    align-items: flex-start;
    margin-right: 0;
}

.alijm-ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 12px;
    line-height: 1.6;
    word-wrap: break-word;
}

.alijm-ai-msg-user .alijm-ai-msg-bubble {
    background: var(--alijm-ai-color, #2271b1);
    color: #fff;
    border-bottom-right-radius: 3px;
}

.alijm-ai-msg-assistant .alijm-ai-msg-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 3px;
}

.alijm-ai-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 3px;
    padding: 0 5px;
}

#alijm-ai-chatbot-typing {
    padding: 10px 20px;
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

#alijm-ai-chatbot-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    animation: alijm-ai-typing 1.4s infinite;
}

#alijm-ai-chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
#alijm-ai-chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes alijm-ai-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-5px); }
}

.alijm-ai-chatbot-input-wrap {
    padding: 10px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    background: #fff;
    align-items: flex-end;
    flex-shrink: 0;
}

#alijm-ai-chatbot-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 16px; /* ⚡ 16px برای جلوگیری از zoom در iOS */
    resize: none;
    max-height: 100px;
    outline: none;
    line-height: 1.5;
}

#alijm-ai-chatbot-input:focus {
    border-color: var(--alijm-ai-color, #2271b1);
}

#alijm-ai-chatbot-send {
    background: var(--alijm-ai-color, #2271b1);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

#alijm-ai-chatbot-send:hover { opacity: 0.9; }

#alijm-ai-chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.alijm-ai-chatbot-footer {
    padding: 6px;
    text-align: center;
    font-size: 10px;
    color: #999;
    background: #fafafa;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

/* ==========================================================================
   📱 پنجره چت در موبایل - Full Screen با پشتیبانی از کیبورد
   ========================================================================== */
@media (max-width: 768px) {
    #alijm-ai-chatbot {
        bottom: 60px;
    }

    #alijm-ai-chatbot.open {
        /* کانتینر تمام صفحه رو پر می‌کنه (برای overlay/backdrop) */
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
    }

    #alijm-ai-chatbot.open #alijm-ai-chatbot-window {
        /* 📌 پنجره چت با ۸۰٪ عرض و ارتفاع کامل */
        position: fixed;
        top: 0;
        bottom: 0;
        width: 80vw !important;              /* ۸۰٪ عرض */
        max-width: 80vw !important;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;

        /* پیش‌فرض: از visualViewport تنظیم میشه (توسط JS) */
        --alijm-vh: 100dvh;
        height: var(--alijm-vh);
    }

    /* 📌 پنجره در سمت راست (وقتی چت‌بات راست است) */
    .alijm-ai-chatbot-right.open #alijm-ai-chatbot-window {
        right: 0 !important;
        left: auto !important;
    }

    /* 📌 پنجره در سمت چپ (وقتی چت‌بات چپ است) */
    .alijm-ai-chatbot-left.open #alijm-ai-chatbot-window {
        left: 0 !important;
        right: auto !important;
    }

    /* 📌 backdrop تیره پشت پنجره (۲۰٪ باقی مانده) */
    #alijm-ai-chatbot.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);

        animation: alijm-backdrop-fade-in 0.3s ease;
    }

    @keyframes alijm-backdrop-fade-in {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    /* مخفی کردن toggle وقتی پنجره باز است */
    #alijm-ai-chatbot.open #alijm-ai-chatbot-toggle {
        display: none;
    }

    /* هدر */
    .alijm-ai-chatbot-header {
        padding: 12px 15px;
        padding-top: calc(12px + env(safe-area-inset-top, 0));
    }

    .alijm-ai-chatbot-title {
        font-size: 14px;
    }

    #alijm-ai-chatbot-messages {
        padding: 12px;
    }

    .alijm-ai-msg {
        max-width: 90%;
    }

    .alijm-ai-msg-bubble {
        font-size: 14px;
        padding: 9px 12px;
    }

    .alijm-ai-chatbot-input-wrap {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
    }

    #alijm-ai-chatbot-input {
        font-size: 16px; /* ⚡ ضروری برای iOS */
        padding: 8px 12px;
    }

    #alijm-ai-chatbot-send {
        width: 38px;
        height: 38px;
    }

    .alijm-ai-chatbot-footer {
        padding: 4px;
        font-size: 9px;
        padding-bottom: calc(4px + env(safe-area-inset-bottom, 0));
    }
}

/* موبایل کوچک */
@media (max-width: 380px) {
    #alijm-ai-chatbot.open #alijm-ai-chatbot-window {
        width: 85vw !important;
        max-width: 85vw !important;
    }

    #alijm-ai-chatbot-toggle {
        width: 50px;
        height: 50px;
    }

    .alijm-ai-chatbot-header {
        padding: 10px 12px;
    }

    .alijm-ai-chatbot-title {
        font-size: 13px;
    }
}

/* Landscape */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    #alijm-ai-chatbot.open #alijm-ai-chatbot-window {
        width: 60vw !important;
        max-width: 60vw !important;
        height: 100vh;
        height: 100dvh;
    }
}

/* ==========================================================================
   📱 موبایل کوچک (تا 380 پیکسل)
   ========================================================================== */
@media (max-width: 380px) {
    #alijm-ai-chatbot-toggle {
        width: 50px;
        height: 50px;
    }

    .alijm-ai-chatbot-header {
        padding: 10px 12px;
    }

    .alijm-ai-chatbot-title {
        font-size: 13px;
    }

    #alijm-ai-chatbot-input {
        padding: 7px 10px;
    }
}

/* ==========================================================================
   💻 حالت landscape (افقی) در موبایل
   ========================================================================== */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    #alijm-ai-chatbot.open #alijm-ai-chatbot-window {
        height: 100vh;
        height: 100dvh;
    }

    .alijm-ai-chatbot-header {
        padding: 8px 15px;
    }

    #alijm-ai-chatbot-messages {
        padding: 10px;
    }

    .alijm-ai-chatbot-input-wrap {
        padding: 6px 10px;
    }
}

/* ============ استایل لینک‌ها در پیام‌های چت‌بات ============ */
.alijm-ai-msg-bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-word;
    font-weight: 600;
}

.alijm-ai-msg-assistant .alijm-ai-msg-bubble a {
    color: var(--alijm-ai-color, #2271b1);
}

.alijm-ai-msg-assistant .alijm-ai-msg-bubble a:hover {
    opacity: 0.8;
    text-decoration: none;
}

.alijm-ai-msg-user .alijm-ai-msg-bubble a {
    color: #fff;
    text-decoration: underline;
}

/* استایل لیست‌ها */
.alijm-ai-msg-bubble ul,
.alijm-ai-msg-bubble ol {
    margin: 8px 15px 8px 0;
    padding-right: 20px;
}

.alijm-ai-msg-bubble li {
    margin-bottom: 4px;
    line-height: 1.6;
}

.alijm-ai-msg-bubble strong,
.alijm-ai-msg-bubble b {
    font-weight: 700;
}

.alijm-ai-msg-bubble em,
.alijm-ai-msg-bubble i {
    font-style: italic;
}

.alijm-ai-msg-bubble code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
}

.alijm-ai-msg-user .alijm-ai-msg-bubble code {
    background: rgba(255,255,255,0.25);
}

.alijm-ai-msg-bubble h3,
.alijm-ai-msg-bubble h4 {
    margin: 10px 0 5px 0;
    font-weight: 700;
    font-size: 1.05em;
}

.alijm-ai-msg-bubble p {
    margin: 0 0 8px 0;
}

.alijm-ai-msg-bubble p:last-child {
    margin-bottom: 0;
}