/* =====================================================================
   AI CHAT WIDGET — استایل مستقل و قابل استفاده در هر پروژه‌ای
   فقط کافیه این فایل + ai-chat-widget.js رو به پروژه اضافه کنی.
   رنگ‌ها از طریق CSS variable ها قابل تغییرن (روی #aichat-root ست کن).
   ===================================================================== */

#aichat-root {
    --aichat-primary: #2B5278;
    --aichat-primary-dark: #1f3c59;
    --aichat-accent: #2563eb;
    --aichat-accent-dark: #1d4ed8;
    --aichat-bubble-user: #306091;
    --aichat-bubble-bot: #eef1f4;
    --aichat-text-bot: #1e293b;
    --aichat-bg: #ffffff;
    --aichat-header-bg: #334155;
    --aichat-border: #e2e8f0;
    --aichat-danger: #ef4444;
    --aichat-radius: 16px;
    direction: rtl;
    font-family: inherit;
}

#aichat-root * {
    box-sizing: border-box;
}

/* ---------- دکمه شناور ---------- */
.aichat-toggle {
    position: fixed;
    bottom: 30px;
    right: 22px;
    z-index: 700; /* زیر مدال رزرو (9000) و استوری‌ویوور (9200) تا وقتی اونا بازن، این المان دیده و کلیک‌پذیر نباشه */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 0;
    background: var(--aichat-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 26px rgba(0, 0, 0, .28);
    cursor: pointer;
    transition: transform .2s ease, background .2s ease;
}

.aichat-toggle:hover {
    transform: scale(1.08);
    background: var(--aichat-primary-dark);
}

.aichat-toggle svg {
    width: 28px;
    height: 28px;
}

/* آیکون سفارشی (ai-chatting.png) به‌صورت پیش‌فرض مشکیه؛ چون پس‌زمینه‌ی
   دکمه آبیه، با filter تبدیلش می‌کنیم به سفید (بدون نیاز به نسخه‌ی جدا). */
.aichat-toggle__icon {
    width: 32px;
    height: 32px;
    object-fit: contain;
    filter: brightness(0) invert(1);
    pointer-events: none;
}

.aichat-toggle.aichat-is-wiggling {
    animation: aichat-wiggle 1.2s ease-in-out;
}

@keyframes aichat-wiggle {
    0%, 100% { transform: translateX(0) rotate(0); }
    10%, 30%, 50%, 70% { transform: translateX(-8px) rotate(-4deg); }
    20%, 40%, 60%, 80% { transform: translateX(8px) rotate(4deg); }
    90% { transform: translateX(0) rotate(0); }
}

/* لرزش ریز و دوره‌ای برای یادآوری وجود دکمه چت (هر ۵ ثانیه، خیلی ملایم) */
.aichat-toggle.aichat-is-nudging {
    animation: aichat-nudge .5s ease-in-out;
}

@keyframes aichat-nudge {
    0%, 100% { transform: translateX(0) rotate(0); }
    25% { transform: translateX(-3px) rotate(-2deg); }
    50% { transform: translateX(3px) rotate(2deg); }
    75% { transform: translateX(-2px) rotate(-1deg); }
}

.aichat-toggle__badge {
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--aichat-danger);
    border: 2px solid #fff;
    display: none;
    animation: aichat-pulse-red 1.5s infinite ease-in-out;
}

.aichat-toggle__badge.aichat-is-visible {
    display: block;
}

@keyframes aichat-pulse-red {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: .75; }
}

.aichat-toggle__prompt {
    position: fixed;
    z-index: 700; /* زیر مدال رزرو (9000) و استوری‌ویوور (9200) تا وقتی اونا بازن، این المان دیده و کلیک‌پذیر نباشه */
    bottom: 96px;
    right: 22px;
    background: #1e293b;
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    border-radius: 8px;
    padding: 7px 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
    opacity: 0;
    transform: translateY(10px) scale(.9);
    pointer-events: none;
    transition: opacity .3s ease, transform .3s ease;
}

.aichat-toggle__prompt.aichat-is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ---------- پنجره چت ---------- */
.aichat-window {
    position: fixed;
    z-index: 700; /* زیر مدال رزرو (9000) و استوری‌ویوور (9200) تا وقتی اونا بازن، این المان دیده و کلیک‌پذیر نباشه */
    inset: 0;
    width: 100vw;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}

@media (min-width: 768px) {
    .aichat-window {
        inset: auto;
        bottom: 100px;
        right: 22px;
        top: auto;
        left: auto;
        width: 380px;
        height: 580px;
        border-radius: var(--aichat-radius);
        border: 1px solid var(--aichat-border);
    }
}

.aichat-window[hidden] {
    display: none;
}

.aichat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--aichat-header-bg);
    color: #fff;
    padding: 14px 16px;
}

.aichat-header__title {
    font-size: 15px;
    font-weight: 700;
}

.aichat-header__close {
    border: 0;
    background: var(--aichat-danger);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.aichat-header__close svg {
    width: 18px;
    height: 18px;
}

.aichat-body {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.aichat-msg {
    max-width: 82%;
    display: flex;
    flex-direction: column;
}

.aichat-msg--user {
    align-self: flex-end;
    align-items: flex-end;
}

.aichat-msg--ai {
    align-self: flex-start;
    align-items: flex-start;
}

.aichat-msg__bubble {
    border-radius: 14px;
    padding: 10px 13px;
    font-size: 13px;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
}

.aichat-msg--user .aichat-msg__bubble {
    background: var(--aichat-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.aichat-msg--ai .aichat-msg__bubble {
    background: var(--aichat-bubble-bot);
    color: var(--aichat-text-bot);
    border-bottom-left-radius: 4px;
}

.aichat-msg--error .aichat-msg__bubble {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    font-weight: 600;
}

.aichat-msg__bubble strong {
    font-weight: 700;
    color: #b91c1c;
}

.aichat-msg__bubble a {
    color: #2563eb;
    text-decoration: underline;
}

.aichat-msg__time {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 3px;
}

.aichat-loading {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 4px;
    align-self: flex-start;
}

.aichat-loading span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: aichat-bounce 1.1s infinite ease-in-out both;
}

.aichat-loading span:nth-child(1) { animation-delay: -0.28s; }
.aichat-loading span:nth-child(2) { animation-delay: -0.14s; }

@keyframes aichat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: .5; }
    40% { transform: scale(1); opacity: 1; }
}

.aichat-footer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px;
    background: #f8fafc;
    border-top: 1px solid var(--aichat-border);
}

.aichat-input {
    flex: 1;
    resize: none;
    min-height: 46px;
    max-height: 120px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 12px 14px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    color: #1e293b;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.aichat-input:focus {
    border-color: var(--aichat-accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .18);
}

.aichat-input:disabled {
    background: #e2e8f0;
    opacity: .7;
    cursor: not-allowed;
}

.aichat-send {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 0;
    color: #fff;
    background: var(--aichat-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    transition: background .15s ease, transform .15s ease;
}

.aichat-send:hover:not(:disabled) {
    background: var(--aichat-accent-dark);
    transform: scale(1.05);
}

.aichat-send:disabled {
    cursor: not-allowed;
    background: #94a3b8;
}

.aichat-send svg {
    width: 20px;
    height: 20px;
}

/* اسکرول‌بار باریک برای بدنه چت */
.aichat-body::-webkit-scrollbar {
    width: 6px;
}

.aichat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}