/* ============================================================
   دستیار پشتیبانی هوشمند — دکمهٔ شناور + پنجرهٔ گفت‌وگو (v3.3.2)
   رنگ‌بندی صورتی هماهنگ با قالب گالری نیلوفر — راست‌به‌چپ
   ============================================================ */

/* ---------- دکمهٔ شناور (پایین-چپ) ---------- */
.ai-chat-fab {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #db2777, #be185d);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 28px -6px rgba(219, 39, 119, 0.55);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-fab:hover,
.ai-chat-fab:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px -6px rgba(219, 39, 119, 0.6);
}

.ai-chat-fab-icon {
    display: inline-flex;
    width: 20px;
    height: 20px;
}

.ai-chat-fab-icon svg {
    width: 100%;
    height: 100%;
}

.ai-chat-fab-label {
    white-space: nowrap;
}

/* نقطهٔ سبز «آنلاین» گوشهٔ دکمه */
.ai-chat-online-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #22c55e;
    border: 2.5px solid #fff;
    animation: ai-dot-pulse 2.4s ease-in-out infinite;
}

@keyframes ai-dot-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
    50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ---------- پنجرهٔ گفت‌وگو ---------- */
.ai-chat-panel {
    position: fixed;
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    left: 20px;
    z-index: 1201;
    display: flex;
    flex-direction: column;
    width: 372px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: calc(100vh - 120px - env(safe-area-inset-bottom, 0px));
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 24px 60px -12px rgba(80, 20, 50, 0.35), 0 0 0 1px rgba(219, 39, 119, 0.12);
    font-size: 14px;
    animation: ai-panel-in 0.22s ease;
}

@keyframes ai-panel-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- ترمیم v3.3.2: ویژگی hidden باید بر display فائق باشد ----------
   قانون display:flex بالا ویژگی hidden را خنثی می‌کرد؛ نتیجه:
   پنجرهٔ گفت‌وگو از همان بارگذاری صفحه باز بود و با دکمهٔ بستن (✕)
   هرگز بسته نمی‌شد. این قانون ترمیم می‌کند. */
.ai-chat-panel[hidden] { display: none !important; }

/* ---------- سربرگ ---------- */
.ai-chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #db2777, #9d174d);
    color: #fff;
    flex-shrink: 0;
}

.ai-chat-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
}

.ai-chat-avatar svg {
    width: 22px;
    height: 22px;
}

.ai-chat-title {
    display: flex;
    flex-direction: column;
    line-height: 1.4;
    flex: 1;
    min-width: 0;
}

.ai-chat-title strong {
    font-size: 14.5px;
    font-weight: 800;
}

.ai-chat-status {
    font-size: 11.5px;
    opacity: 0.85;
}

.ai-chat-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.ai-chat-close:hover { background: rgba(255, 255, 255, 0.3); }

.ai-chat-close svg { width: 16px; height: 16px; }

/* ---------- پیام‌ها ---------- */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 6px;
    background: #fdf7f9;
    scroll-behavior: smooth;
}

/* اسکرول‌بار ظریف */
.ai-chat-messages::-webkit-scrollbar { width: 6px; }
.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #f3c6dc;
    border-radius: 3px;
}

.ai-msg {
    display: flex;
    margin-bottom: 10px;
    animation: ai-msg-in 0.18s ease;
}

@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* پیام دستیار — سمت راست (ابتدای خط در چیدمان راست‌به‌چپ) */
.ai-msg.ai {
    justify-content: flex-start;
}

/* پیام کاربر — سمت چپ */
.ai-msg.user {
    justify-content: flex-end;
}

.ai-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    line-height: 1.9;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg.ai .ai-bubble {
    background: #fff;
    color: #3d1a2b;
    border: 1px solid #f6dbe7;
    border-start-start-radius: 4px;
}

.ai-msg.user .ai-bubble {
    background: linear-gradient(135deg, #db2777, #be185d);
    color: #fff;
    border-start-end-radius: 4px;
}

/* حباب خطا */
.ai-msg.ai .ai-bubble.ai-bubble-error {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}

/* حباب خوش‌آمد */
.ai-msg.ai .ai-bubble.ai-bubble-greet {
    background: #fdf0f6;
    border-color: #f9d5e7;
}

/* ---------- نشانگر تایپ (سه‌نقطه) ---------- */
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #db2777;
    opacity: 0.4;
    animation: ai-typing-bounce 1.2s infinite;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- پیشنهادهای آماده ---------- */
.ai-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px 4px;
    background: #fdf7f9;
    flex-shrink: 0;
}

.ai-chat-chip {
    border: 1px solid #f6c9dd;
    background: #fff;
    color: #be185d;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.ai-chat-chip:hover,
.ai-chat-chip:focus-visible {
    background: #db2777;
    color: #fff;
}

/* ---------- فرم ارسال ---------- */
.ai-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #f6dbe7;
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    border: 1.5px solid #f3d3e3;
    border-radius: 12px;
    background: #fdf7f9;
    font-family: inherit;
    font-size: 13.5px;
    color: #3d1a2b;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.ai-chat-input:focus {
    border-color: #db2777;
    background: #fff;
}

.ai-chat-input:disabled { opacity: 0.6; }

.ai-chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #db2777, #be185d);
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    flex-shrink: 0;
}

.ai-chat-send svg { width: 18px; height: 18px; transform: scaleX(-1); }

.ai-chat-send:hover { transform: translateY(-1px); }

.ai-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

/* ---------- پانوشت ---------- */
.ai-chat-foot {
    padding: 6px 12px 8px;
    font-size: 10.5px;
    color: #b98da1;
    text-align: center;
    background: #fff;
    flex-shrink: 0;
}

/* ---------- موبایل ---------- */
@media (max-width: 560px) {
    .ai-chat-fab {
        left: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        padding: 11px 15px;
        font-size: 13px;
    }

    .ai-chat-panel {
        left: 10px;
        right: 10px;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-width: none;
        height: auto;
        max-height: calc(100vh - 100px - env(safe-area-inset-bottom, 0px));
        border-radius: 16px;
    }

    .ai-bubble { max-width: 88%; }
}
