.ai-chat-root {
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    z-index: 9998;
    font-family: inherit;
    direction: rtl;
}

.ai-chat-root--open .ai-chat-fab {
    box-shadow: 0 8px 26px color-mix(in srgb, var(--site-accent, #f7858d) 45%, transparent);
}

.ai-chat-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 3.25rem;
    padding: 0.55rem 1rem 0.55rem 0.75rem;
    border: none;
    border-radius: 999px;
    background: var(--site-accent, #f7858d);
    color: #fff !important;
    box-shadow: 0 6px 20px color-mix(in srgb, var(--site-accent, #f7858d) 40%, transparent);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.ai-chat-fab:hover,
.ai-chat-fab:focus {
    transform: translateY(-2px);
    background: var(--site-accent-hover, color-mix(in srgb, var(--site-accent, #f7858d) 85%, #000));
    box-shadow: 0 8px 24px color-mix(in srgb, var(--site-accent, #f7858d) 50%, transparent);
    outline: none;
    color: #fff !important;
}

.ai-chat-fab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    flex: 0 0 2.1rem;
}

.ai-chat-fab-icon .mdi {
    font-size: 1.35rem;
    line-height: 1;
    color: #fff !important;
}

.ai-chat-fab-label {
    white-space: nowrap;
    color: #fff !important;
}

.ai-chat-panel {
    position: absolute;
    bottom: calc(100% + 0.75rem);
    left: 0;
    width: min(360px, calc(100vw - 2rem));
    max-height: min(520px, calc(100vh - 6rem));
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.ai-chat-panel[hidden] {
    display: none !important;
}

.ai-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    background: var(--site-accent, #f7858d);
    color: #fff;
}

.ai-chat-header strong {
    display: block;
    font-size: 0.95rem;
}

.ai-chat-quick-prompts {
    display: flex;
    gap: 0.4rem;
    padding: 0.65rem 0.75rem 0.25rem;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ai-chat-quick-prompts button {
    flex: 0 0 auto;
    border: 1px solid color-mix(in srgb, var(--site-accent, #f7858d) 24%, transparent);
    background: color-mix(in srgb, var(--site-accent, #f7858d) 8%, #fff);
    color: #555;
    border-radius: 999px;
    padding: 0.35rem 0.65rem;
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

.ai-chat-quick-prompts button:hover,
.ai-chat-quick-prompts button:focus {
    border-color: var(--site-accent, #f7858d);
    color: var(--site-accent, #f7858d);
    outline: none;
}

.ai-chat-audience-notice {
    display: block;
    margin-top: 0.25rem;
    opacity: 0.92;
    font-size: 0.72rem;
    line-height: 1.5;
}

.ai-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    background: #fafafa;
    min-height: 180px;
    max-height: 280px;
}

.ai-chat-msg {
    margin-bottom: 0.65rem;
    display: flex;
}

.ai-chat-msg--user {
    justify-content: flex-start;
}

.ai-chat-msg--assistant {
    justify-content: flex-end;
}

.ai-chat-bubble {
    max-width: 88%;
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-chat-msg--user .ai-chat-bubble {
    background: var(--site-accent, #f7858d);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-chat-msg--assistant .ai-chat-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #eee;
    border-bottom-left-radius: 4px;
}

.ai-chat-msg--typing .ai-chat-bubble {
    opacity: 0.7;
    font-style: italic;
}

.ai-chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.65rem;
    border-top: 1px solid #eee;
    background: #fff;
    align-items: flex-end;
}

.ai-chat-form textarea {
    flex: 1;
    resize: none;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 0.5rem 0.65rem;
    font-family: inherit;
    font-size: 0.85rem;
    min-height: 2.5rem;
    max-height: 8.25rem;
    overflow-y: auto;
}

.ai-chat-form textarea:focus {
    outline: none;
    border-color: var(--site-accent, #f7858d);
}

.ai-chat-send {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    border-radius: 50%;
    background: var(--site-accent, #f7858d);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.ai-chat-footnote {
    margin: 0;
    padding: 0.35rem 0.75rem 0.65rem;
    font-size: 0.68rem;
    color: #888;
    background: #fff;
}

/* موبایل: بالای نوار پایین PWA، بدون تداخل با دکمه رفتن به بالا */
@media (max-width: 768px) {
    .ai-chat-root {
        left: 0.75rem;
        right: auto;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }

    .ai-chat-fab {
        width: 3.35rem;
        min-width: 3.35rem;
        height: 3.35rem;
        min-height: 3.35rem;
        padding: 0;
        border-radius: 50%;
    }

    .ai-chat-fab-label {
        display: none;
    }

    .ai-chat-fab-icon {
        width: 100%;
        height: 100%;
        background: transparent;
    }

    .ai-chat-fab-icon .mdi {
        font-size: 1.7rem;
    }

    .ai-chat-panel {
        position: fixed;
        left: 0.5rem;
        right: 0.5rem;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        width: auto;
        max-height: calc(100vh - 7.5rem);
        z-index: 9999;
    }

    .ai-chat-messages {
        max-height: min(240px, 38vh);
    }
}

@media (max-width: 380px) {
    .ai-chat-root {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }
}

@media print {
    .ai-chat-root,
    .ai-chat-fab,
    .ai-chat-panel {
        display: none !important;
        visibility: hidden !important;
    }
}
/* Evidence is rendered as safe links rather than model-generated HTML. */
.ai-chat-sources { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.ai-chat-sources a { background:#f3efff; color:#4c1d95; border-radius:12px; padding:6px 10px; font-size:12px; min-height:36px; }
