/* ==========================================================================
   دستیار هوشمند Qwen - استایل ویجت چت
   ========================================================================== */

:root {
    --qca-primary: #6366f1;
    --qca-secondary: #8b5cf6;
    --qca-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --qca-bot-bubble: #f1f5f9;
    --qca-bot-text: #1e293b;
    --qca-radius: 22px;
    --qca-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    --qca-shadow-lg: 0 24px 70px rgba(15, 23, 42, 0.28);
    --qca-z: 99999;
    --qca-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Vazirmatn, IRANSans, sans-serif;
}

* {
    box-sizing: border-box;
}

/* دکمه شناور باز کردن */
#qca-widget .qca-fab {
    position: fixed;
    bottom: 28px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--qca-gradient);
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--qca-z);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    animation: qca-pulse 2.5s infinite;
}

#qca-widget.qca-pos-right .qca-fab { right: 28px; }
#qca-widget.qca-pos-left  .qca-fab { left: 28px; }

#qca-widget .qca-fab:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.55);
}

#qca-widget .qca-fab svg {
    width: 30px;
    height: 30px;
    color: #fff;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#qca-widget .qca-fab .qca-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    font-family: var(--qca-font);
    animation: none;
}

#qca-widget .qca-fab.is-hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}

@keyframes qca-pulse {
    0%   { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0.4); }
    70%  { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 18px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 8px 24px rgba(99, 102, 241, 0.45), 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* پنل چت */
#qca-widget .qca-panel {
    position: fixed;
    bottom: 104px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--qca-radius);
    box-shadow: var(--qca-shadow-lg);
    z-index: var(--qca-z);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(24px) scale(0.96);
    transform-origin: bottom;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.3s;
}

#qca-widget.qca-pos-right .qca-panel { right: 28px; transform-origin: bottom right; }
#qca-widget.qca-pos-left  .qca-panel { left: 28px; transform-origin: bottom left; }

#qca-widget .qca-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* هدر پنل */
#qca-widget .qca-panel-header {
    background: var(--qca-gradient);
    padding: 18px 18px 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    flex-shrink: 0;
}

#qca-widget .qca-panel-header::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 80% 20%, rgba(255,255,255,0.18), transparent 60%);
    pointer-events: none;
}

#qca-widget .qca-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.35);
    position: relative;
}

#qca-widget .qca-avatar svg {
    width: 26px;
    height: 26px;
    color: #fff;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

#qca-widget .qca-avatar .qca-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid #fff;
}

#qca-widget .qca-header-info {
    flex: 1;
    min-width: 0;
}

#qca-widget .qca-header-info h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    font-family: var(--qca-font);
    line-height: 1.3;
}

#qca-widget .qca-header-info .qca-status-text {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: var(--qca-font);
}

#qca-widget .qca-status-text .qca-status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 6px #4ade80;
}

#qca-widget .qca-header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

#qca-widget .qca-icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    padding: 0;
}

#qca-widget .qca-icon-btn:hover { background: rgba(255, 255, 255, 0.32); }

#qca-widget .qca-icon-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* بدنه پیام‌ها */
#qca-widget .qca-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background:
        linear-gradient(180deg, #fafbff 0%, #fff 100%);
    scroll-behavior: smooth;
}

#qca-widget .qca-messages::-webkit-scrollbar { width: 6px; }
#qca-widget .qca-messages::-webkit-scrollbar-track { background: transparent; }
#qca-widget .qca-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* پیام */
#qca-widget .qca-message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: qca-msg-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

#qca-widget .qca-msg-bot {
    align-self: flex-start;
}

#qca-widget .qca-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

#qca-widget .qca-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-family: var(--qca-font);
}

#qca-widget .qca-msg-bot .qca-msg-avatar {
    background: var(--qca-gradient);
    color: #fff;
}

#qca-widget .qca-msg-user .qca-msg-avatar {
    background: #e2e8f0;
    color: #475569;
}

#qca-widget .qca-msg-bubble {
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.65;
    font-family: var(--qca-font);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#qca-widget .qca-msg-bot .qca-msg-bubble {
    background: var(--qca-bot-bubble);
    color: var(--qca-bot-text);
    border-bottom-left-radius: 5px;
}

#qca-widget .qca-msg-user .qca-msg-bubble {
    background: var(--qca-gradient);
    color: #fff;
    border-bottom-right-radius: 5px;
}

/* محتوای مارک‌داون داخل حباب */
#qca-widget .qca-msg-bubble p { margin: 0 0 8px; }
#qca-widget .qca-msg-bubble p:last-child { margin-bottom: 0; }
#qca-widget .qca-msg-bubble ul,
#qca-widget .qca-msg-bubble ol { margin: 6px 0; padding-right: 20px; }
#qca-widget .qca-msg-bubble li { margin: 3px 0; }
#qca-widget .qca-msg-bubble strong { font-weight: 700; }
#qca-widget .qca-msg-bubble em { font-style: italic; }
#qca-widget .qca-msg-bubble code {
    background: rgba(0,0,0,0.08);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 13px;
    font-family: "Courier New", monospace;
    direction: ltr;
}
#qca-widget .qca-msg-bubble pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 8px 0;
    direction: ltr;
}
#qca-widget .qca-msg-bubble pre code { background: none; padding: 0; color: inherit; }
#qca-widget .qca-msg-bubble a { color: inherit; text-decoration: underline; }
#qca-widget .qca-msg-user .qca-msg-bubble a { color: #fff; }

#qca-widget .qca-msg-time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
    font-family: var(--qca-font);
}

/* اندیکاتور تایپ */
#qca-widget .qca-typing {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 13px 16px;
    background: var(--qca-bot-bubble);
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    width: fit-content;
}

#qca-widget .qca-typing span {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: qca-typing-bounce 1.4s infinite;
}

#qca-widget .qca-typing span:nth-child(2) { animation-delay: 0.2s; }
#qca-widget .qca-typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* بخش پیام‌رسان‌ها */
#qca-widget .qca-social-section {
    padding: 4px 16px 14px;
    background: #fff;
    flex-shrink: 0;
}

#qca-widget .qca-social-title {
    font-size: 12px;
    color: #64748b;
    text-align: center;
    margin: 0 0 10px;
    font-family: var(--qca-font);
    font-weight: 500;
}

#qca-widget .qca-social-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

#qca-widget .qca-social-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 4px;
    border-radius: 14px;
    text-decoration: none;
    background: #f8fafc;
    border: 1px solid #eef2f7;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    font-family: var(--qca-font);
}

#qca-widget .qca-social-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

#qca-widget .qca-social-btn svg {
    width: 26px;
    height: 26px;
}

#qca-widget .qca-social-btn span {
    font-size: 11px;
    font-weight: 600;
    color: #475569;
}

#qca-widget .qca-social-btn.qca-telegram:hover { background: #e8f4fd; }
#qca-widget .qca-social-btn.qca-whatsapp:hover { background: #e9fbf0; }
#qca-widget .qca-social-btn.qca-bale:hover     { background: #fff4e6; }
#qca-widget .qca-social-btn.qca-discord:hover  { background: #eef0fb; }

/* ناحیه ورودی */
#qca-widget .qca-input-area {
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #eef2f7;
    flex-shrink: 0;
}

#qca-widget .qca-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f1f5f9;
    border-radius: 18px;
    padding: 6px 6px 6px 14px;
    border: 2px solid transparent;
    transition: border-color 0.2s ease, background 0.2s ease;
}

#qca-widget .qca-input-wrap:focus-within {
    border-color: var(--qca-primary);
    background: #fff;
}

#qca-widget .qca-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 14px;
    line-height: 1.5;
    font-family: var(--qca-font);
    max-height: 100px;
    min-height: 24px;
    padding: 6px 0;
    color: #1e293b;
}

#qca-widget .qca-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--qca-gradient);
    border: none;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#qca-widget .qca-send-btn:hover { transform: scale(1.08); }
#qca-widget .qca-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
#qca-widget .qca-send-btn svg {
    width: 20px; height: 20px;
    fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

#qca-widget .qca-footer {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #94a3b8;
    background: #fff;
    font-family: var(--qca-font);
}

/* پیام خطا داخل چت */
#qca-widget .qca-error-bubble {
    background: #fef2f2 !important;
    color: #b91c1c !important;
    border: 1px solid #fecaca;
}

/* بک‌دراپ موبایل */
#qca-widget .qca-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(2px);
    z-index: calc(var(--qca-z) - 1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#qca-widget .qca-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

/* پاسخگو - موبایل */
@media (max-width: 480px) {
    #qca-widget .qca-panel {
        bottom: 0;
        right: 0 !important;
        left: 0 !important;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    #qca-widget .qca-panel.is-open {
        transform: translateY(0) scale(1);
    }
}

/* RTL: مارک‌داون و جهت */
html[dir="rtl"] #qca-widget,
#qca-widget {
    direction: rtl;
}

#qca-widget .qca-msg-bubble code,
#qca-widget .qca-msg-bubble pre,
#qca-widget .qca-input-wrap {
    direction: ltr;
}

#qca-widget .qca-msg-bubble {
    direction: rtl;
}
