/* =========================================================
   RivaChat - Frontend Chat Widget
   Modern Glass UI
   RTL / Persian
========================================================= */


/* =========================================================
   1. ROOT WIDGET
========================================================= */

#rivachat-chat-widget {
    display: none;
    position: fixed;
    z-index: 999999;

    font-family: 'IRANSans', 'Tahoma', 'Segoe UI', sans-serif;
    direction: rtl;

    --rc-primary: #2563eb;
    --rc-primary-dark: #1d4ed8;

    --rc-glass-bg: rgba(255, 255, 255, 0.84);
    --rc-glass-border: rgba(255, 255, 255, 0.58);

    --rc-radius: 20px;

    pointer-events: none;
}


/* فقط عناصر قابل کلیک ویجت فعال باشند */

#rivachat-chat-widget .rivachat-chat-button,
#rivachat-chat-widget .rivachat-chat-popup {
    pointer-events: auto;
}


/* =========================================================
   2. FLOATING CHAT BUTTON
========================================================= */

#rivachat-chat-widget .rivachat-chat-button {
    width: 60px;
    height: 60px;

    border-radius: 50%;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;

    position: relative;

    box-shadow:
        0 8px 20px rgba(0, 0, 0, 0.25);

    transition:
        transform 0.25s cubic-bezier(.34, 1.56, .64, 1),
        box-shadow 0.2s ease;
}


#rivachat-chat-widget .rivachat-chat-button:hover {
    transform: scale(1.06);

    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.30);
}


#rivachat-chat-widget .rivachat-chat-button:active {
    transform: scale(0.96);
}


/* =========================================================
   3. PULSE ANIMATION
========================================================= */

#rivachat-chat-widget .rivachat-pulse-ring {
    position: absolute;
    inset: 0;

    border-radius: 50%;

    box-shadow:
        0 0 0 0 rgba(255, 255, 255, 0.45);

    animation:
        rivachat-pulse 2.6s ease-out infinite;

    pointer-events: none;
}


@keyframes rivachat-pulse {

    0% {
        box-shadow:
            0 0 0 0 rgba(255, 255, 255, 0.45);
    }

    70% {
        box-shadow:
            0 0 0 14px rgba(255, 255, 255, 0);
    }

    100% {
        box-shadow:
            0 0 0 0 rgba(255, 255, 255, 0);
    }

}


/* =========================================================
   4. CHAT / CLOSE ICON ANIMATION
========================================================= */

#rivachat-chat-widget .rivachat-chat-icon,
#rivachat-chat-widget .rivachat-close-icon {
    position: absolute;

    transition:
        transform 0.28s ease,
        opacity 0.2s ease;
}


#rivachat-chat-widget .rivachat-chat-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}


#rivachat-chat-widget .rivachat-close-icon {
    opacity: 0;
    transform: scale(0.4) rotate(-90deg);
}


#rivachat-chat-widget.open .rivachat-chat-icon {
    opacity: 0;
    transform: scale(0.4) rotate(90deg);
}


#rivachat-chat-widget.open .rivachat-close-icon {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}


#rivachat-chat-widget.open .rivachat-pulse-ring {
    display: none;
}


/* =========================================================
   5. UNREAD BADGE
========================================================= */

#rivachat-chat-widget .rivachat-unread-badge {
    position: absolute;

    top: -4px;
    left: -4px;

    min-width: 20px;
    height: 20px;

    padding: 0 4px;

    box-sizing: border-box;

    display: flex;
    align-items: center;
    justify-content: center;

    background: #e53935;
    color: #fff;

    border-radius: 50%;

    font-size: 11px;
    font-weight: 700;

    box-shadow:
        0 0 0 2px #fff;

    animation:
        rivachat-badge-pop 0.3s ease;
}


@keyframes rivachat-badge-pop {

    0% {
        transform: scale(0);
    }

    70% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }

}


/* =========================================================
   6. SYSTEM NOTICE
========================================================= */

#rivachat-chat-widget .rivachat-system-notice {
    background: #fff3cd;
    color: #664d03;

    border: 1px solid #ffe69c;
    border-radius: 12px;

    padding: 8px 12px;

    margin: 6px auto;

    font-size: 0.8rem;

    align-self: center;

    text-align: center;

    max-width: 90%;

    box-sizing: border-box;
}


/* =========================================================
   7. TYPING INDICATOR
========================================================= */

#rivachat-chat-widget .rivachat-typing-indicator {
    font-size: 0.75rem;
    color: #94a3b8;

    padding:
        0 15px 6px;

    min-height: 16px;
}


/* =========================================================
   8. NAME PROMPT
========================================================= */

#rivachat-chat-widget .rivachat-name-prompt {
    background: #fff;

    border: 1px solid #e2e8f0;
    border-radius: 14px;

    padding: 12px 14px;
    margin: 8px 0;

    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.05);

    align-self: stretch;

    box-sizing: border-box;
}


#rivachat-chat-widget .rivachat-name-prompt-text {
    font-size: 13px;
    color: #334155;

    margin-bottom: 8px;
}


#rivachat-chat-widget .rivachat-name-prompt-row {
    display: flex;
    align-items: center;

    gap: 6px;

    margin-bottom: 6px;
}


#rivachat-chat-widget .rivachat-name-prompt-row input {
    flex: 1;

    border: 1.5px solid #e2e8f0;
    border-radius: 10px;

    padding: 7px 10px;

    font-size: 13px;

    direction: rtl;

    outline: none;

    font-family: inherit;

    box-sizing: border-box;
}


#rivachat-chat-widget .rivachat-name-prompt-row button {
    all: unset;

    box-sizing: border-box;

    background: #2271b1;
    color: #fff;

    padding: 7px 14px;

    border-radius: 10px;

    font-size: 12.5px;

    cursor: pointer;

    white-space: nowrap;
}


#rivachat-chat-widget .rivachat-name-prompt #rivachat-name-skip {
    all: unset;

    box-sizing: border-box;

    display: block;

    width: 100%;

    text-align: center;

    font-size: 11.5px;

    color: #94a3b8;

    cursor: pointer;

    padding: 4px;
}


#rivachat-chat-widget .rivachat-name-prompt #rivachat-name-skip:hover {
    color: #64748b;
    text-decoration: underline;
}


/* =========================================================
   9. CHAT POPUP
========================================================= */

#rivachat-chat-widget .rivachat-chat-popup {
    position: absolute;

    bottom: 80px;
    right: 0;

    width: 360px;

    max-height: 70vh;
    min-height: 380px;

    height: auto;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    background: var(--rc-glass-bg);

    backdrop-filter:
        blur(18px) saturate(180%);

    -webkit-backdrop-filter:
        blur(18px) saturate(180%);

    border:
        1px solid var(--rc-glass-border);

    border-radius:
        var(--rc-radius);

    box-shadow:
        0 24px 60px rgba(15, 23, 42, 0.18),
        0 8px 24px rgba(15, 23, 42, 0.08);

    opacity: 0;
    visibility: hidden;

    transform:
        translateY(16px) scale(0.98);

    transform-origin:
        bottom left;

    transition:
        opacity 0.25s ease,
        transform 0.25s cubic-bezier(.2, .9, .3, 1),
        visibility 0.25s ease;

    box-sizing: border-box;
}


#rivachat-chat-widget.open .rivachat-chat-popup {
    opacity: 1;
    visibility: visible;

    transform:
        translateY(0) scale(1);
}


/* =========================================================
   10. CHAT HEADER
========================================================= */

#rivachat-chat-widget .rivachat-chat-header {
    padding: 14px 18px;

    color: #fff;

    background:
        linear-gradient(
            135deg,
            #1d4ed8,
            #2563eb
        );

    display: flex;
    align-items: center;

    gap: 12px;

    flex-shrink: 0;

    border-radius:
        var(--rc-radius)
        var(--rc-radius)
        0
        0;

    box-sizing: border-box;
}


#rivachat-chat-widget .rivachat-chat-header-avatar {
    width: 38px;
    height: 38px;

    border-radius: 50%;

    background:
        rgba(255, 255, 255, 0.18);

    display: flex;
    align-items: center;
    justify-content: center;

    flex-shrink: 0;
}


#rivachat-chat-widget .rivachat-chat-header-text {
    display: flex;
    flex-direction: column;

    flex: 1;

    min-width: 0;
}


#rivachat-chat-widget .rivachat-chat-title {
    font-weight: 700;

    font-size: 14.5px;

    line-height: 1.3;
}


#rivachat-chat-widget .rivachat-chat-subtitle {
    font-size: 11.5px;

    opacity: 0.85;

    display: flex;
    align-items: center;

    gap: 5px;

    margin-top: 2px;
}


#rivachat-chat-widget .rivachat-status-dot {
    width: 7px;
    height: 7px;

    border-radius: 50%;

    background: #4ade80;

    box-shadow:
        0 0 0 2px rgba(255, 255, 255, 0.3);

    flex-shrink: 0;
}


/* =========================================================
   11. CLOSE BUTTON
========================================================= */

#rivachat-chat-widget .rivachat-chat-close {
    all: unset;

    box-sizing: border-box;

    width: 30px !important;
    height: 30px !important;

    min-width: 30px;
    min-height: 30px;

    border-radius: 50% !important;

    background:
        rgba(255, 255, 255, 0.16) !important;

    border:
        none !important;

    color: #fff;

    cursor: pointer;

    font-size: 15px;

    flex-shrink: 0;

    display: flex !important;
    align-items: center;
    justify-content: center;

    transition:
        background 0.15s ease,
        transform 0.15s ease;
}


#rivachat-chat-widget .rivachat-chat-close:hover {
    background:
        rgba(255, 255, 255, 0.30) !important;

    transform: scale(1.05);
}


/* =========================================================
   12. MESSAGES CONTAINER
========================================================= */

/*
   نکته مهم:
   direction را روی کانتینر پیام‌ها LTR کرده‌ایم تا
   flex-start / flex-end بدون تأثیر RTL رفتار استاندارد داشته باشند.
   خود پیام‌ها دوباره RTL هستند.
*/

#rivachat-chat-widget .rivachat-chat-messages {
    flex: 1;

    min-height: 0;

    padding: 16px;

    overflow-y: auto;

    background:
        radial-gradient(
            circle at top right,
            rgba(37, 99, 235, 0.06),
            transparent 34%
        ),
        rgba(248, 250, 252, 0.72);

    display: flex;
    flex-direction: column;

    /*
       بسیار مهم برای درست شدن سمت پیام‌ها
    */
    direction: ltr;

    scrollbar-width: thin;

    box-sizing: border-box;
}


#rivachat-chat-widget .rivachat-chat-messages::-webkit-scrollbar {
    width: 6px;
}


#rivachat-chat-widget .rivachat-chat-messages::-webkit-scrollbar-thumb {
    background: #d1d5db;

    border-radius: 10px;
}


#rivachat-chat-widget .rivachat-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}


/* =========================================================
   13. MESSAGE WRAPPER
========================================================= */

#rivachat-chat-widget .message {
    width: 100%;
    max-width: 100%;

    display: flex;
    flex-direction: column;

    margin-bottom: 10px;

    clear: both;

    direction: rtl;

    animation:
        rivachat-msg-in 0.2s ease;

    box-sizing: border-box;
}


@keyframes rivachat-msg-in {

    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }

}


/* =========================================================
   14. USER MESSAGE → RIGHT
========================================================= */

#rivachat-chat-widget .message.admin {
    align-self: flex-end;

    align-items: flex-end;

    text-align: right;
}


/* =========================================================
   15. ADMIN MESSAGE → LEFT
========================================================= */

#rivachat-chat-widget .message.user {
    align-self: flex-start;

    align-items: flex-start;

    text-align: left;
}


/* =========================================================
   16. MESSAGE BUBBLE
========================================================= */

#rivachat-chat-widget .message .bubble {
    display: inline-block;

    width: fit-content;

    max-width: 78%;

    box-sizing: border-box;

    padding: 9px 14px;

    border-radius: 16px;

    word-wrap: break-word;
    overflow-wrap: break-word;

    line-height: 1.55;

    font-size: 13.5px;

    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04);
}


/* =========================================================
   17. USER BUBBLE
========================================================= */

#rivachat-chat-widget .message.admin .bubble {
    background:
        linear-gradient(
            135deg,
            #2563eb,
            #1d4ed8
        ) !important;

    color: #fff !important;

    border:
        none !important;

    border-radius:
        16px 16px 4px 16px !important;
}


/* =========================================================
   18. ADMIN BUBBLE
========================================================= */

#rivachat-chat-widget .message.user .bubble {
    background:
        rgba(241, 245, 249, 0.92) !important;

    color: #1e293b !important;

    border:
        1px solid rgba(226, 232, 240, 0.9) !important;

    border-radius:
        16px 16px 16px 4px !important;
}


/* =========================================================
   19. MESSAGE TIME
========================================================= */

#rivachat-chat-widget .message-time {
    display: block;
    margin-top: 5px;
    font-size: 10px;
    line-height: 1.4;
    color: #94a3b8;
    direction: rtl;
    opacity: .9;
}

#rivachat-chat-widget .message-text {
    display: block;
}


#rivachat-chat-widget .message.admin .message-time {
    align-self: flex-end;

    text-align: right;
}


#rivachat-chat-widget .message.user .message-time {
    align-self: flex-start;

    text-align: left;
}


/* =========================================================
   20. INPUT AREA
========================================================= */

#rivachat-chat-widget .rivachat-chat-input-area {
    display: flex;

    align-items: flex-end;

    gap: 8px;

    padding: 12px;

    background:
        rgba(255, 255, 255, 0.72) !important;

    border-top:
        1px solid rgba(226, 232, 240, 0.72) !important;

    backdrop-filter:
        blur(14px);

    -webkit-backdrop-filter:
        blur(14px);

    flex-shrink: 0;

    box-sizing: border-box;
}


/* =========================================================
   21. TEXTAREA
========================================================= */

#rivachat-chat-widget .rivachat-chat-input-area textarea {
    flex: 1;

    width: 100%;

    min-width: 0;

    min-height: 36px !important;

    height: 36px !important;

    max-height: 100px !important;

    box-sizing: border-box;

    border:
        1.5px solid #e2e8f0;

    border-radius:
        14px !important;

    padding:
        8px 12px !important;

    resize: none;

    font-family: inherit;

    direction: rtl;

    font-size: 14px;

    line-height: 1.5;

    overflow-y: hidden;

    outline: none;

    background:
        rgba(255, 255, 255, 0.85) !important;

    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        background 0.15s ease,
        height 0.1s ease;
}


#rivachat-chat-widget .rivachat-chat-input-area textarea:focus {
    border-color:
        #2563eb !important;

    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.14) !important;

    background:
        #fff !important;
}


/* =========================================================
   22. SEND BUTTON
========================================================= */

#rivachat-chat-widget .rivachat-chat-send {
    all: unset;

    box-sizing: border-box;

    width: 40px !important;
    height: 40px !important;

    min-width: 40px;
    min-height: 40px;

    border:
        none !important;

    border-radius:
        50% !important;

    background:
        linear-gradient(
            135deg,
            #2563eb,
            #1d4ed8
        ) !important;

    color: #fff;

    cursor: pointer;

    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    flex-shrink: 0;

    padding: 0 !important;
    margin: 0;

    line-height: 0;

    box-shadow:
        0 7px 18px rgba(37, 99, 235, 0.24);

    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        opacity 0.15s ease;
}


#rivachat-chat-widget .rivachat-chat-send:hover {
    transform: translateY(-1px);

    box-shadow:
        0 9px 22px rgba(37, 99, 235, 0.30);
}


#rivachat-chat-widget .rivachat-chat-send:active {
    transform: scale(0.92);
}


#rivachat-chat-widget .rivachat-chat-send:disabled {
    opacity: 0.6;

    cursor: default;

    transform: none;
}


#rivachat-chat-widget .rivachat-chat-send svg {
    width: 18px;
    height: 18px;

    display: block;

    pointer-events: none;
}


/* =========================================================
   23. CONTACT FORM
========================================================= */

#rivachat-chat-widget .rivachat-contact-form {
    width: 100%;

    box-sizing: border-box;

    padding: 24px 18px;

    margin: auto 0;

    text-align: center;

    color: #0f172a;
}


#rivachat-chat-widget .rivachat-contact-icon {
    width: 54px;
    height: 54px;

    margin:
        0 auto 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 16px;

    background:
        linear-gradient(
            135deg,
            rgba(37, 99, 235, 0.12),
            rgba(29, 78, 216, 0.08)
        );

    font-size: 25px;
}


#rivachat-chat-widget .rivachat-contact-title {
    font-size: 17px;

    font-weight: 800;

    margin-bottom: 7px;
}


#rivachat-chat-widget .rivachat-contact-text {
    font-size: 12.5px;

    line-height: 1.8;

    color: #64748b;

    margin-bottom: 18px;
}


#rivachat-chat-widget .rivachat-contact-form label {
    display: block;

    text-align: right;

    font-size: 11.5px;

    font-weight: 700;

    color: #475569;

    margin:
        10px 2px 5px;
}


#rivachat-chat-widget .rivachat-contact-form input {
    width: 100%;

    height: 42px;

    box-sizing: border-box;

    border:
        1px solid rgba(203, 213, 225, 0.9);

    border-radius: 12px;

    background:
        rgba(255, 255, 255, 0.78);

    padding:
        0 12px;

    font-family: inherit;

    font-size: 13px;

    color: #0f172a;

    outline: none;

    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background 0.2s ease;
}


#rivachat-chat-widget .rivachat-contact-form input:focus {
    border-color:
        #2563eb;

    box-shadow:
        0 0 0 3px rgba(37, 99, 235, 0.12);

    background:
        #fff;
}


#rivachat-chat-widget .rivachat-contact-form input::placeholder {
    color: #94a3b8;
}


/* =========================================================
   24. CONTACT SUBMIT
========================================================= */

#rivachat-chat-widget #rivachat-contact-submit {
    width: 100%;

    min-height: 42px;

    margin-top: 15px;

    border: 0;

    border-radius: 12px;

    background:
        linear-gradient(
            135deg,
            #2563eb,
            #1d4ed8
        );

    color: #fff;

    font-family: inherit;

    font-size: 13px;

    font-weight: 700;

    cursor: pointer;

    box-shadow:
        0 8px 20px rgba(37, 99, 235, 0.22);

    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
}


#rivachat-chat-widget #rivachat-contact-submit:hover {
    transform: translateY(-1px);
}


#rivachat-chat-widget #rivachat-contact-submit:disabled {
    opacity: 0.65;

    cursor: wait;
}


/* =========================================================
   25. CONTACT ERROR
========================================================= */

#rivachat-chat-widget .rivachat-contact-error {
    min-height: 18px;

    margin-top: 8px;

    color: #dc2626;

    font-size: 11.5px;

    line-height: 1.5;
}


/* =========================================================
   26. MOBILE
========================================================= */

@media (max-width: 480px) {

    #rivachat-chat-widget .rivachat-chat-popup {
        position: fixed !important;

        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;

        width: 100% !important;
        height: 100% !important;

        max-height: 100% !important;

        min-height: 0 !important;

        border-radius: 0 !important;

        transform:
            translateY(100%) !important;

        visibility: visible !important;

        opacity: 1 !important;
    }


    #rivachat-chat-widget.open .rivachat-chat-popup {
        transform:
            translateY(0) !important;
    }


    #rivachat-chat-widget .rivachat-chat-header {
        padding-top:
            max(16px, env(safe-area-inset-top));
    }


    #rivachat-chat-widget .rivachat-chat-button {
        width: 56px;
        height: 56px;
    }


    #rivachat-chat-widget .rivachat-chat-messages {
        padding: 14px;
    }


    #rivachat-chat-widget .message .bubble {
        max-width: 82%;
    }


    #rivachat-chat-widget .rivachat-contact-form {
        padding: 20px 18px;
    }

}


/* =========================================================
   27. VERY SMALL SCREENS
========================================================= */

@media (max-width: 360px) {

    #rivachat-chat-widget .rivachat-chat-messages {
        padding: 12px;
    }


    #rivachat-chat-widget .rivachat-chat-input-area {
        padding: 10px;
        gap: 6px;
    }


    #rivachat-chat-widget .rivachat-chat-send {
        width: 38px !important;
        height: 38px !important;

        min-width: 38px;
        min-height: 38px;
    }


    #rivachat-chat-widget .message .bubble {
        max-width: 86%;

        font-size: 13px;
    }

}