/* =========================================================
   ویجت پشتیبانی شناور
   مارک‌آپ: part/support-widget.php · منطق: js/support-widget.js
   راهنما: docs/support-widget-guide.md
   ========================================================= */

/* جعبهٔ ویجت دقیقاً به اندازهٔ دکمه است؛ تولتیپ و پنجره absolute هستند
   تا ظاهر شدنشان جای دکمه را جابه‌جا نکند */
.support-widget {
    position: fixed;
    bottom: 22px;
    z-index: 1045; /* بالاتر از اوورلای منو (1035) و پایین‌تر از مودال‌ها (1055) */
    display: inline-flex;
    font-family: inherit;
    direction: rtl;
}

.support-widget--left { left: 22px; }
.support-widget--right { right: 22px; }

/* ---------- دکمهٔ شناور ---------- */
.support-widget__fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 52px;
    min-width: 52px;
    padding: 0 1.15rem;
    border: 0;
    border-radius: 999px;
    background: #c21a1a;
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(194, 26, 26, 0.35);
    transition: gap 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                padding 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.2s ease,
                box-shadow 0.2s ease;
}

.support-widget__fab:hover {
    background: #a81616;
    box-shadow: 0 14px 32px rgba(194, 26, 26, 0.45);
}

.support-widget__fab-icon {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: block;
}

/* مورف کشویی: عرض متن جمع می‌شود تا دکمهٔ قرصی به دایره تبدیل شود */
.support-widget__fab-label {
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease;
}

.support-widget__fab.is-compact {
    padding: 0;
    gap: 0;
}

.support-widget__fab.is-compact .support-widget__fab-label {
    max-width: 0;
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .support-widget__fab,
    .support-widget__fab-label {
        transition: none;
    }
}

/* ---------- تولتیپ جلب توجه ---------- */
/* absolute است تا دکمه را جابه‌جا نکند؛ مقدار left و --arrow-x را
   جاوااسکریپت بر اساس فاصله تا دیوارهٔ مرورگر تنظیم می‌کند */
.support-widget__tooltip {
    position: absolute;
    bottom: calc(100% + 14px);
    left: 0;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.support-widget__tooltip.is-visible {
    display: block;
    opacity: 1;
    animation: support-tooltip-float 2.2s ease-in-out infinite;
}

/* فلش باریک رو به پایین، دقیقاً روی مرکز دکمهٔ پشتیبانی
   (عرض ۱۲px، ارتفاع ۸px تا کشیده و نازک دیده شود) */
.support-widget__tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: var(--arrow-x, 26px);
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 6px 0;
    border-color: transparent;
}

/* حالت باریک: یک خط، بدون دکمهٔ بستن
   عمداً overflow:hidden ندارد تا فلش ::after زیر بالن بریده نشود */
.support-widget__tooltip.is-pill {
    background: #2b2b2b;
    color: #fff;
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    max-width: calc(100vw - 44px);
    white-space: nowrap;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.support-widget__tooltip.is-pill .support-widget__tooltip-text {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.support-widget__tooltip.is-pill::after {
    border-top-color: #2b2b2b;
}

/* حالت حبابی: پیام چندخطی معرفی دستیار، با دکمهٔ بستن */
.support-widget__tooltip.is-bubble {
    background: #fff;
    color: #222;
    border-radius: 16px;
    padding: 1rem 1.1rem;
    width: 270px;
    max-width: calc(100vw - 44px);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 2;
    text-align: right;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
    pointer-events: auto;
}

.support-widget__tooltip.is-bubble::after {
    border-top-color: #fff;
    filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.1));
}

.support-widget__narges-flower {
    display: inline-block;
    width: 1.15em;
    height: 1.15em;
    vertical-align: -0.2em;
    margin: 0 0.15em;
    object-fit: contain;
}

/* PNG گل نرگس — خوانا ولی inline (~2.4em ≈ ۳۴px با فونت ۰٫۸۸rem) */
.support-widget__narges-flower--png {
    width: 2.4em;
    height: 2.4em;
    vertical-align: -0.55em;
    margin: 0 0.1em;
    border-radius: 50%;
    object-fit: cover;
    transform: none;
    transform-origin: center;
}

.support-widget__narges-flower--svg {
    width: 1.15em;
    height: 1.15em;
    vertical-align: -0.2em;
    object-fit: contain;
}

.support-widget__tooltip-close {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: #efefef;
    color: #666;
    font-size: 0.95rem;
    line-height: 0;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: background 0.2s ease, color 0.2s ease;
}

.support-widget__tooltip-close:hover {
    background: #e2e2e2;
    color: #c21a1a;
}

@keyframes support-tooltip-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}

@media (prefers-reduced-motion: reduce) {
    .support-widget__tooltip.is-visible {
        animation: none;
        transform: none;
    }
}

/* ---------- پنجرهٔ پشتیبانی ---------- */
.support-widget__panel {
    position: absolute;
    bottom: calc(100% + 12px);
    width: 360px;
    max-width: calc(100vw - 32px);
    max-height: min(560px, calc(100vh - 120px));
    display: none;
    flex-direction: column;
    overflow: hidden;
    background: #f4f5f7;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.support-widget--left .support-widget__panel { left: 0; }
.support-widget--right .support-widget__panel { right: 0; }

.support-widget.is-open .support-widget__panel {
    display: flex;
    animation: support-panel-in 0.2s ease;
}

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

.support-widget__head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.85rem 1rem;
    background: #f4f5f7;
}

/* هدر برندشده برای واریانت دستیار */
.support-widget__head--brand {
    background: #c21a1a;
    padding: 1rem;
}

.support-widget__head-avatar {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #c21a1a;
    font-size: 1.4rem;
    line-height: 0;
}

.support-widget__head-text {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.support-widget__head-title {
    font-weight: 800;
    font-size: 0.95rem;
    color: #222;
}

.support-widget__head-subtitle {
    font-size: 0.75rem;
    font-weight: 500;
    color: #777;
}

.support-widget__head--brand .support-widget__head-title,
.support-widget__head--brand .support-widget__head-subtitle {
    color: #fff;
}

.support-widget__head--brand .support-widget__head-subtitle {
    opacity: 0.85;
}

.support-widget__back,
.support-widget__close {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    padding: 0.25rem;
    line-height: 0;
    font-size: 1.4rem;
    color: #666;
    cursor: pointer;
    transition: color 0.2s ease;
}

.support-widget__back:hover,
.support-widget__close:hover {
    color: #c21a1a;
}

.support-widget__head--brand .support-widget__back,
.support-widget__head--brand .support-widget__close {
    color: rgba(255, 255, 255, 0.9);
}

.support-widget__head--brand .support-widget__back:hover,
.support-widget__head--brand .support-widget__close:hover {
    color: #fff;
}

/* بدنهٔ اسکرول‌شونده */
.support-widget__body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 1rem 1rem;
    /* فایرفاکس: اسکرول‌بار باریک، هم‌رنگ نوار اسکرول سفارشی صفحه */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.22) transparent;
}

/* واریانت‌هایی که عنصر چسبیده به لبهٔ پایین دارند (مثل نوار چت) */
.support-widget__body--flush {
    padding-bottom: 0;
}

.support-widget__body::-webkit-scrollbar {
    width: 6px;
}

.support-widget__body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 999px;
}

/* ---------- اسکلت لودینگ ---------- */
.support-widget__skeleton {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 1rem 0;
}

.support-widget__skeleton-art,
.support-widget__skeleton-line {
    display: block;
    border-radius: 8px;
    background: linear-gradient(90deg, #e6e8eb 25%, #f2f3f5 37%, #e6e8eb 63%);
    background-size: 400% 100%;
    animation: support-skeleton 1.3s ease infinite;
}

.support-widget__skeleton-art {
    width: 110px;
    height: 90px;
    border-radius: 14px;
    margin-bottom: 6px;
}

.support-widget__skeleton-line {
    width: 100%;
    height: 44px;
}

.support-widget__skeleton-line--title {
    width: 60%;
    height: 18px;
    margin-bottom: 6px;
}

@keyframes support-skeleton {
    0%   { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@media (prefers-reduced-motion: reduce) {
    .support-widget__skeleton-art,
    .support-widget__skeleton-line {
        animation: none;
    }
}

/* ---------- مودال «به‌زودی» ---------- */
.support-soon[hidden] {
    display: none;
}

.support-soon {
    position: fixed;
    inset: 0;
    z-index: 1060; /* بالاتر از خود ویجت */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.support-soon__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: support-soon-fade 0.2s ease;
}

.support-soon__box {
    position: relative;
    width: 360px;
    max-width: 100%;
    background: #fff;
    border-radius: 16px;
    padding: 1.75rem 1.5rem 1.5rem;
    text-align: center;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.3);
    animation: support-soon-in 0.22s ease;
}

@keyframes support-soon-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes support-soon-in {
    from { opacity: 0; transform: translateY(12px) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

.support-soon__close {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    border: 0;
    background: transparent;
    padding: 0.25rem;
    line-height: 0;
    font-size: 1.3rem;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
}

.support-soon__close:hover {
    color: #c21a1a;
}

.support-soon__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    border-radius: 50%;
    background: rgba(194, 26, 26, 0.1);
    color: #c21a1a;
    font-size: 2rem;
    line-height: 0;
}

.support-soon__title {
    margin: 0 0 0.6rem;
    font-weight: 800;
    font-size: 1.05rem;
    color: #222;
}

.support-soon__text {
    margin: 0 0 1.25rem;
    font-size: 0.88rem;
    line-height: 2;
    color: #666;
}

.support-soon__btn {
    width: 100%;
    border: 0;
    border-radius: 10px;
    background: #c21a1a;
    color: #fff;
    padding: 0.7rem 1rem;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.support-soon__btn:hover {
    background: #a81616;
}

/* ---------- کارت دعوت به دستیار هوش مصنوعی ---------- */
.support-cta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border: 1px solid rgba(194, 26, 26, 0.2);
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(194, 26, 26, 0.07), rgba(194, 26, 26, 0.02));
    font-family: inherit;
    text-align: right;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.support-cta:hover {
    border-color: rgba(194, 26, 26, 0.45);
    box-shadow: 0 10px 24px rgba(194, 26, 26, 0.12);
}

.support-cta__icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #c21a1a;
    color: #fff;
    font-size: 1.3rem;
    line-height: 0;
}

.support-cta__body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.support-cta__title {
    font-weight: 800;
    font-size: 0.9rem;
    color: #222;
}

.support-cta__text {
    font-size: 0.78rem;
    color: #777;
}

.support-cta__arrow {
    flex: 0 0 auto;
    font-size: 1.2rem;
    color: #c21a1a;
    transition: transform 0.2s ease;
}

.support-cta:hover .support-cta__arrow {
    transform: translateX(-3px);
}

/* ---------- گفتگو با دستیار ---------- */
.support-chat__messages {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 0.5rem 0;
}

.support-chat__row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.support-chat__row--user {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

.support-chat__avatar {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #c21a1a;
    color: #fff;
    font-size: 1rem;
    line-height: 0;
}

.support-chat__bubble {
    max-width: 82%;
    background: #fff;
    border-radius: 14px 14px 14px 4px;
    padding: 0.75rem 0.9rem;
    font-size: 0.86rem;
    line-height: 2;
    color: #333;
}

.support-chat__bubble--user {
    max-width: 82%;
    background: #c21a1a;
    color: #fff;
    border-radius: 14px 14px 4px 14px;
}

/* سه نقطهٔ «در حال تایپ» */
.support-chat__typing {
    display: flex;
    align-items: center;
    gap: 4px;
}

.support-chat__typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #bbb;
    animation: support-typing 1s infinite ease-in-out;
}

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

@keyframes support-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* نوار نوشتن پیام: چسبیده به پایین بدنهٔ اسکرول‌شونده */
.support-chat__composer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    margin: 0.5rem -1rem 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.support-chat__composer.is-locked {
    opacity: 0.6;
}

.support-chat__input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 999px;
    padding: 0.6rem 1rem;
    font-family: inherit;
    font-size: 0.86rem;
    color: #333;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.support-chat__input:focus {
    border-color: rgba(194, 26, 26, 0.45);
    box-shadow: 0 0 0 3px rgba(194, 26, 26, 0.1);
}

.support-chat__send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: #c21a1a;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.support-chat__send:disabled {
    background: #c9ccd2;
    cursor: not-allowed;
}

.support-chat__send:not(:disabled):hover {
    background: #a81616;
}

/* فرم مشخصات کاربر مهمان، داخل حباب گفتگو */
.support-lead {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-width: 220px;
}

.support-lead__hint {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    margin: 0 0 0.25rem;
    font-size: 0.8rem;
    line-height: 1.9;
    color: #666;
}

.support-lead__hint i {
    font-size: 1rem;
    line-height: 1.9;
    color: #999;
}

.support-lead__field {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 0.6rem 0.85rem;
    font-family: inherit;
    font-size: 0.85rem;
    color: #333;
    background: #fff;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.support-lead__field:focus {
    border-color: rgba(194, 26, 26, 0.45);
    box-shadow: 0 0 0 3px rgba(194, 26, 26, 0.1);
}

.support-lead__submit {
    border: 0;
    border-radius: 10px;
    background: #c21a1a;
    color: #fff;
    padding: 0.6rem 1rem;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.support-lead__submit:hover {
    background: #a81616;
}

/* ---------- اجزای مشترک واریانت‌ها ---------- */
.support-empty {
    text-align: center;
    padding: 0.5rem 0 1.25rem;
}

.support-empty__title {
    font-weight: 800;
    font-size: 0.95rem;
    color: #222;
    margin: 0 0 1rem;
}

.support-empty__art {
    width: 120px;
    height: auto;
    margin: 0 auto;
    display: block;
}

.support-section__title {
    font-weight: 800;
    font-size: 0.95rem;
    color: #222;
    margin: 0 0 0.75rem;
    text-align: center;
}

/* لیست کارتی موضوعات */
.support-list {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}

.support-list__link {
    display: block;
    width: 100%;
    padding: 0.9rem 1rem;
    border: 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    background: transparent;
    color: #3b6fd4;
    font-family: inherit;
    font-size: 0.88rem;
    text-align: right;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.support-list__item:last-child .support-list__link {
    border-bottom: 0;
}

.support-list__link:hover {
    background: #f7f8fa;
}

.support-list__link--alert {
    color: #c21a1a;
    font-weight: 700;
}

/* کانال‌های تماس (واریانت contact) */
.support-channels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}

.support-channel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.9rem 0.5rem;
    background: #fff;
    border-radius: 12px;
    color: #333;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
    transition: box-shadow 0.2s ease, color 0.2s ease;
}

.support-channel:hover {
    color: #c21a1a;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

.support-channel i {
    font-size: 1.6rem;
    line-height: 1;
    color: #c21a1a;
}

.support-note {
    margin: 0.9rem 0 0;
    font-size: 0.8rem;
    line-height: 1.9;
    color: #777;
    text-align: center;
}

.support-note--start {
    margin: 0 0 0.25rem;
    text-align: right;
}

/* فرم تیکت (واریانت ticket) */
.support-form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: #fff;
    border-radius: 12px;
    padding: 1rem;
}

.support-form__field {
    width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    font-family: inherit;
    font-size: 0.88rem;
    color: #333;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.support-form__field:focus {
    border-color: rgba(194, 26, 26, 0.45);
    box-shadow: 0 0 0 3px rgba(194, 26, 26, 0.1);
}

textarea.support-form__field {
    min-height: 96px;
    resize: vertical;
}

.support-form__submit {
    border: 0;
    border-radius: 10px;
    background: #c21a1a;
    color: #fff;
    padding: 0.7rem 1rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease;
}

.support-form__submit:hover {
    background: #a81616;
}

/* پیام خطای بارگذاری */
.support-error {
    text-align: center;
    padding: 1.5rem 0;
    color: #777;
    font-size: 0.88rem;
}

.support-error__retry {
    margin-top: 0.75rem;
    border: 0;
    background: transparent;
    color: #c21a1a;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

/* ---------- موبایل ---------- */
@media (max-width: 575.98px) {
    .support-widget {
        bottom: 16px;
    }

    .support-widget--left { left: 16px; }
    .support-widget--right { right: 16px; }

    .support-widget__panel {
        width: calc(100vw - 32px);
        max-height: calc(100vh - 140px);
    }
}
