﻿/* ============================================================
   chat-widget.css — سیستم چت پشتیبانی (UserArea)
   Olympic Co
   ============================================================ */

:root {
    --chat-primary: #005be8;
    --chat-primary-dark: #0000db;
    --chat-bg: #fff;
    --chat-radius: 16px;
    --chat-shadow: 0 4px 18px rgba(26, 39, 232, 0.45);
}

/* ─── Toggle Button ─────────────────────────────────────── */

/* انیمیشن ورود از سمت راست */
@keyframes chat-slide-in {
    from { transform: translateX(120px); opacity: 0; }
    to   { transform: translateX(0);     opacity: 1; }
}

/* ضربان ملایم برای جلب توجه */
@keyframes chat-pulse {
    0%,100% { box-shadow: var(--chat-shadow); }
    50%      { box-shadow: 0 0 0 10px rgba(0,91,232,0.15), var(--chat-shadow); }
}

.chat-toggle-btn {
    position: fixed;
    bottom: 28px;
    bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.25s ease, transform 0.25s ease;
}

/* مرحله ۱: ورود از راست */
.chat-toggle-btn.chat-btn-entering {
    display: flex;
    animation: chat-slide-in 0.55s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

/* مرحله ۲: ثابت — بعد از ورود، فقط نمایش بدون animation */
.chat-toggle-btn.chat-btn-visible {
    display: flex;
    animation: none;
}

/* مرحله ۳: ضربان — روی visible اضافه میشه، تا ابد ادامه داره */
.chat-toggle-btn.chat-btn-visible.chat-btn-pulse {
    animation: chat-pulse 2.2s ease-in-out infinite;
}

.chat-toggle-btn:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.08);
}

/* ─── Label پشتیبانی آنلاین ──────────────────────────────── */
.chat-label-tooltip {
    position: fixed;
    bottom: 96px;
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
    right: 10px;
    background: var(--chat-primary);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 9997;
    box-shadow: 0 2px 8px rgba(0,91,232,0.3);
    /* همیشه block — visibility و opacity کنترل میکنن */
    display: block;
    opacity: 0;
    visibility: hidden;
    transform: translateY(6px);
    transition: opacity 0.35s ease, transform 0.35s ease, visibility 0.35s;
}

/* دُم label */
.chat-label-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 22px;
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: var(--chat-primary) transparent transparent;
}

.chat-label-tooltip.label-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ─── Badge ─────────────────────────────────────────────── */
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53935;
    color: #fff;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    line-height: 1;
}

/* ─── Chat Box ───────────────────────────────────────────── */
.chat-box {
    position: fixed;
    bottom: 100px;
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    right: 28px;
    width: 380px;
    height: 520px;
    max-height: 580px;
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.25s ease;
    direction: rtl;
    box-sizing: border-box;
}
.chat-box.open {
    display: flex;
}

/* ─── Header ─────────────────────────────────────────────── */
.chat-header {
    background: var(--chat-primary);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
}
.chat-header-actions button {
    background: none;
    border: none;
    color: rgba(255,255,255,0.85);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 0.15s;
}
.chat-header-actions button:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

/* ─── Body ───────────────────────────────────────────────── */
.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8f9fa;
    min-height: 0;
}
.chat-body::-webkit-scrollbar { width: 4px; }
.chat-body::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ─── Welcome / FAQ Screen ───────────────────────────────── */
.chat-welcome {
    text-align: center;
    padding: 20px 10px;
}
.chat-welcome .chat-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}
.chat-welcome h5 { font-weight: 700; margin-bottom: 6px; font-size: 16px; }
.chat-welcome p  { color: #666; font-size: 13px; margin-bottom: 18px; }

.chat-faq-item {
    background: #fff;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: right;
}
    .chat-faq-item:hover {
        border-color: var(--chat-primary);
        background: #f3f3ff;
    }
.chat-faq-item .faq-q {
    font-weight: 600;
    font-size: 13px;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-faq-item .faq-a {
    display: none;
    margin-top: 8px;
    font-size: 12px;
    color: #555;
    line-height: 1.6;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}
.chat-faq-item.open .faq-a { display: block; }
.chat-faq-item.open .faq-q i { transform: rotate(90deg); }
.chat-faq-item .faq-q i { transition: transform 0.2s; }

.chat-start-btn {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
    transition: background 0.2s;
}
.chat-start-btn:hover { background: var(--chat-primary-dark); }

/* ─── Login Screen ───────────────────────────────────────── */
.chat-login-screen {
    padding: 20px;
    text-align: center;
}
.chat-login-screen p { font-size: 13px; color: #555; margin-bottom: 16px; }

/* ─── Profile Screen ─────────────────────────────────────── */
.chat-profile-screen {
    padding: 20px;
}
.chat-profile-screen .form-control {
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 10px;
    padding: 10px 12px;
}
.chat-profile-screen label { font-size: 13px; font-weight: 600; margin-bottom: 4px; }

/* ─── Messages ───────────────────────────────────────────── */
.chat-msg {
    display: flex;
    margin-bottom: 12px;
}
.chat-msg.user  { justify-content: flex-start; }
.chat-msg.admin { justify-content: flex-end; }

.chat-msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.55;
    position: relative;
    word-break: break-word;
}
.chat-msg.user  .chat-msg-bubble { background: #fff; border: 1px solid #e9ecef; border-radius: 0 14px 14px 14px; color: #333; }
.chat-msg.admin .chat-msg-bubble { background: var(--chat-primary); color: #fff; border-radius: 14px 0 14px 14px; }

.chat-msg-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.6;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-msg.admin .chat-msg-time { justify-content: flex-end; }

.chat-date-separator {
    text-align: center;
    margin: 12px 0 8px;
    position: relative;
    font-size: 11px;
    color: #888;
}
.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: #ddd;
}
.chat-date-separator::before { right: 0; }
.chat-date-separator::after  { left: 0; }
.chat-date-separator span {
    background: #fff;
    padding: 0 8px;
    position: relative;
    z-index: 1;
}

.seen-icon   { color: #4fc3f7; font-size: 11px; }
.unseen-icon { opacity: 0.5;   font-size: 11px; }

/* ─── File Preview in Message ────────────────────────────── */
.chat-file-msg img {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    display: block;
    margin-top: 6px;
    cursor: pointer;
}
.chat-file-msg a {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: inherit;
    text-decoration: none;
    margin-top: 4px;
}

/* ─── Product Mention ────────────────────────────────────── */
.chat-product-mention {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 11px;
    margin-top: 6px;
    text-decoration: none;
    color: inherit;
}
.chat-msg.user .chat-product-mention {
    background: #fff3f0;
    border-color: var(--chat-primary);
    color: var(--chat-primary);
}

/* ─── Mention Tag (محصول انتخاب‌شده) ───────────────────── */
.chat-mention-tag-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #fff3f0;
    border: 1px solid #ffcdd2;
    border-radius: 8px;
    font-size: 12px;
    color: #c62828;
    margin-bottom: 6px;
    direction: rtl;
}

/* هر تگ جداگانه */
.chat-mention-tag-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffebee;
    border: 1px solid #ffcdd2;
    border-radius: 20px;
    padding: 2px 8px 2px 4px;
    font-size: 11px;
    color: #c62828;
    font-weight: 600;
    white-space: nowrap;
}
.chat-mention-tag-item i { color: #e8431a; font-size: 11px; }
.chat-mention-tag-item .tag-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.chat-mention-tag-bar .tag-remove {
    background: none;
    border: none;
    color: #c62828;
    border-radius: 50%;
    width: 18px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 10px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    padding: 0;
}
.chat-mention-tag-bar .tag-remove:hover { background: #e53935; color: #fff; border-radius: 50%; }

/* ─── Input Area ─────────────────────────────────────────── */
.chat-input-area {
    border-top: 1px solid #e9ecef;
    background: #fff;
    padding: 10px 12px;
    flex-shrink: 0;
    position: relative;
}
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-input-row textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    resize: none;
    max-height: 80px;
    min-height: 38px;
    line-height: 1.4;
    font-family: inherit;
    overflow-y: auto;
    direction: rtl;
}
.chat-input-row textarea:focus { outline: none; border-color: var(--chat-primary); }
.chat-input-actions { display: flex; gap: 2px; }
.chat-input-actions button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    color: #888;
    border-radius: 50%;
}
.chat-input-actions button:hover { color: var(--chat-primary); background: #f5f5f5; }
.chat-send-btn {
    background: var(--chat-primary) !important;
    color: #fff !important;
    border-radius: 50% !important;
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px !important;
    flex-shrink: 0; border: none; cursor: pointer;
    transition: opacity 0.2s;
}
.chat-send-btn:hover { opacity: 0.85; }

/* ─── File Preview Bar ───────────────────────────────────── */
.chat-file-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: #f9f9f9;
    border-radius: 8px;
    font-size: 12px;
    margin-bottom: 6px;
}
.chat-file-preview.show { display: flex; }
.chat-file-preview .remove-file { background: none; border: none; color: #e53935; cursor: pointer; }

/* ─── Mention Dropdown ───────────────────────────────────── */
.chat-mention-dropdown {
    position: absolute; bottom: 100%; left: 0; right: 0;
    background: #fff; border: 1px solid #ddd; border-radius: 10px;
    max-height: 200px; overflow-y: auto;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.1); z-index: 10; display: none;
}
.chat-mention-dropdown.open { display: block; }
.chat-mention-item {
    padding: 10px 14px; cursor: pointer; font-size: 13px;
    display: flex; align-items: center; gap: 8px;
    border-bottom: 1px solid #f5f5f5;
}
.chat-mention-item:hover { background: #f0f7ff; }
.chat-mention-item i { color: var(--chat-primary); }

/* ─── Emoji Picker ───────────────────────────────────────── */
#chat-emoji-picker {
    position: absolute; bottom: 100%; right: 0;
    background: #fff; border: 1px solid #ddd; border-radius: 10px;
    padding: 8px; box-shadow: 0 -4px 16px rgba(0,0,0,0.1);
    z-index: 11; width: 200px; text-align: center; display: none;
}

/* ─── Typing Indicator ───────────────────────────────────── */
.chat-typing {
    display: flex; align-items: center; gap: 4px;
    padding: 8px 14px; font-size: 12px; color: #888;
}
.chat-typing .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #aaa; animation: typing 1.2s infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* ─── Closed Banner ──────────────────────────────────────── */
.chat-closed-banner {
    background: #fff3e0; border: 1px solid #ffcc80;
    border-radius: 8px; padding: 10px 14px;
    font-size: 12px; color: #e65100; text-align: center; margin: 8px;
}

/* ─── Mention Hint Bar ───────────────────────────────────── */
@keyframes hint-slide-down {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes hint-glow {
    0%,100% { box-shadow: 0 0 0 0 rgba(0,91,232,0); }
    50%      { box-shadow: 0 0 0 4px rgba(0,91,232,0.18); }
}
@keyframes hint-shrink {
    from { max-height: 80px; opacity: 1; padding: 8px 12px; }
    to   { max-height: 28px; opacity: 1; padding: 4px 10px; }
}

.chat-mention-hint {
    display: none;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #eef3ff 0%, #f0f7ff 100%);
    border: 1.5px solid #b3cdfb;
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 7px;
    font-size: 12px;
    color: #1a4aad;
    direction: rtl;
    animation: hint-slide-down 0.4s cubic-bezier(0.34,1.56,0.64,1) forwards,
               hint-glow 2s ease-in-out 0.5s infinite;
    position: relative;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease, opacity 0.3s ease;
    max-height: 80px;
}
.chat-mention-hint.hint-visible { display: flex; }
/* حالت کوچک‌شده — فقط آیکون و مثال کوچک */
.chat-mention-hint.hint-mini {
    animation: hint-shrink 0.4s ease forwards;
    max-height: 28px;
    padding: 4px 10px;
    gap: 6px;
    cursor: pointer;
}
.chat-mention-hint.hint-mini .hint-text,
.chat-mention-hint.hint-mini .hint-close { display: none; }
.chat-mention-hint.hint-mini .hint-icon {
    width: 20px; height: 20px; font-size: 11px;
}
.chat-mention-hint.hint-mini .hint-example {
    font-size: 11px; padding: 1px 6px;
    animation: none;
}
.chat-mention-hint .hint-icon {
    font-size: 18px;
    background: var(--chat-primary);
    color: #fff;
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: width 0.3s, height 0.3s, font-size 0.3s;
}
.chat-mention-hint .hint-text { flex: 1; line-height: 1.5; }
.chat-mention-hint .hint-text strong { display: block; font-size: 12.5px; margin-bottom: 2px; }
.chat-mention-hint .hint-text span   { color: #4a6fa5; font-size: 11px; }
.chat-mention-hint .hint-example {
    background: var(--chat-primary);
    color: #fff;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    animation: hint-glow 1.5s ease-in-out infinite;
    transition: font-size 0.3s, padding 0.3s;
}
.chat-mention-hint .hint-close {
    background: none; border: none; color: #aaa;
    cursor: pointer; padding: 0; font-size: 14px;
    position: absolute; left: 8px; top: 8px;
    line-height: 1;
}
.chat-mention-hint .hint-close:hover { color: #e53935; }

/* ─── دکمه منشن محصول در لیست فروشگاه ──────────────────── */
.product-mention-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f0f7ff;
    color: var(--chat-primary);
    border: 1.5px solid #b3cdfb;
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 6px;
    white-space: nowrap;
}
.product-mention-btn:hover:not(:disabled) {
    background: var(--chat-primary);
    color: #fff;
    border-color: var(--chat-primary);
    transform: scale(1.04);
}
.product-mention-btn:disabled,
.product-mention-btn.mentioned {
    background: #e8f5e9;
    color: #388e3c;
    border-color: #a5d6a7;
    cursor: default;
    transform: none;
}
.product-mention-btn i { font-size: 12px; }

/* ─── Drag Handle (فقط موبایل نمایش داده می‌شود) ─────────── */
.chat-drag-handle { display: none; }
.chat-overlay     { display: none; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 991px) {
    .chat-toggle-btn    { bottom: 24px; right: 20px; left: auto; }
    .chat-label-tooltip { bottom: 92px; right: 8px; left: auto; }
    .chat-box           { bottom: 90px; left: 12px; right: 12px; width: auto; }
}

/* ══════════════════════════════════════════════════════════
   موبایل — Bottom Sheet اپلیکیشنی
   ══════════════════════════════════════════════════════════ */
/* sheet animations — فقط برای حالت‌های بدون touch استفاده می‌شوند */
@keyframes sheet-slide-up {
    from { transform: translateY(100%); opacity: 0.6; }
    to   { transform: translateY(0);    opacity: 1;   }
}
@keyframes sheet-slide-down {
    from { transform: translateY(var(--sheet-drag-offset, 0px)); }
    to   { transform: translateY(110%); }
}

@media (max-width: 600px) {

    /* ── دکمه toggle ── */
    .chat-toggle-btn {
        bottom: 20px;
        right: 20px;
        left: auto;
        width: 56px;
        height: 56px;
        font-size: 22px;
        /* بالای navbar احتمالی مرورگر */
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
    .chat-label-tooltip {
        bottom: calc(86px + env(safe-area-inset-bottom, 0px));
        right: 6px;
        left: auto;
        font-size: 11px;
    }

    /* ── overlay تیره پشت sheet ── */
    .chat-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9990;
        opacity: 0;
        transition: opacity 0.38s ease;
        /* برای fade هنگام drag */
        will-change: opacity;
    }
    .chat-overlay.active {
        display: block;
        opacity: 1;
    }
    .chat-overlay.no-transition {
        transition: none !important;
    }

    /* ── chat box → bottom sheet ── */
    .chat-box {
        position: fixed;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: 92dvh !important;
        max-height: 92dvh !important;
        border-radius: 20px 20px 0 0 !important;
        z-index: 9995;
        display: flex !important;
        transform: translateY(100%);
        /* transition برای open/close بدون drag */
        transition: transform 0.42s cubic-bezier(0.32, 0.72, 0, 1),
                    visibility 0s linear 0.42s;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        will-change: transform;
        visibility: hidden;
        /* اسکرول داخل sheet نباید body رو scroll کنه */
        overscroll-behavior: contain;
    }
    /* حین drag — transition رو خاموش کن */
    .chat-box.dragging {
        transition: none !important;
    }
    .chat-box.open {
        transform: translateY(0) !important;
        visibility: visible;
        transition: transform 0.42s cubic-bezier(0.32, 0.72, 0, 1),
                    visibility 0s linear 0s;
    }
    /* closing — فقط وقتی drag نیست */
    .chat-box.closing {
        transform: translateY(110%) !important;
        visibility: visible;
        transition: transform 0.34s cubic-bezier(0.4, 0, 1, 1),
                    visibility 0s linear 0.34s;
    }

    /* ── drag handle بالای sheet ── */
    .chat-drag-handle {
        display: flex !important;
        justify-content: center;
        align-items: center;
        padding: 10px 0 4px;
        flex-shrink: 0;
        cursor: grab;
        background: var(--chat-primary);
        border-radius: 20px 20px 0 0;
        touch-action: none;
    }
    .chat-drag-handle:active { cursor: grabbing; }
    .chat-drag-handle-bar {
        width: 44px;
        height: 5px;
        background: rgba(255,255,255,0.55);
        border-radius: 6px;
        pointer-events: none;
    }

    /* ── header موبایل — کمی فشرده‌تر ── */
    .chat-header {
        border-radius: 0 !important;
        padding: 10px 16px;
    }

    /* ── body کامل‌تر ── */
    .chat-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* ── input area — کمی بزرگ‌تر برای انگشت ── */
    .chat-input-row textarea {
        font-size: 16px !important; /* جلوگیری از zoom روی iOS */
        min-height: 42px;
    }
    .chat-send-btn { width: 42px !important; height: 42px !important; }
    .chat-input-area { padding: 10px 10px; }
}

/* خیلی کوچک (320px) */
@media (max-width: 360px) {
    .chat-box { height: 96dvh !important; max-height: 96dvh !important; }
}
