:root { 
    --saa-color-primary: #F29057; 
    --saa-color-secondary: #055159; 
    --saa-bg-user: #055159; 
    --saa-bg-bot: #f1f0f0; 
    --saa-color-text-user: #ffffff; 
    --saa-color-text-bot: #333333;
    
    /* Dynamic Offsets */
    --saa-offset-side: 25px;
    --saa-offset-bottom: 25px;
    --saa-mob-safe: 0px; 
}

#saa-chat-toggle { 
    position: fixed; 
    bottom: var(--saa-offset-bottom); 
    right: var(--saa-offset-side); /* Default Right */
    width: 60px; height: 60px; 
    background-color: var(--saa-color-primary); 
    color: #fff;
    border-radius: 12px;
    cursor: pointer; z-index: 99999; 
    display: flex; align-items: center; justify-content: center; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.2); 
    transition: transform 0.3s;
}
#saa-chat-toggle:hover { transform: scale(1.05); }
#saa-chat-toggle svg { width: 32px; height: 32px; }

#saa-chat-box { 
    position: fixed; 
    bottom: calc(var(--saa-offset-bottom) + 80px); 
    right: var(--saa-offset-side); /* Default Right */
    width: 360px; height: 550px; 
    background: #fff; border-radius: 15px; display: none; flex-direction: column; 
    z-index: 99999; overflow: hidden; direction: rtl; 
    box-shadow: 0 5px 30px rgba(0,0,0,0.15); border: 1px solid #e5e5e5; 
}

/* Telegram Style Header */
.saa-chat-header { 
    background: var(--saa-color-secondary); 
    color: #fff; 
    padding: 15px; 
    display: flex; justify-content: space-between; align-items: center; 
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    background-color: rgba(5, 81, 89, 0.95); /* Adjust based on secondary color */
}

.saa-close-btn { cursor: pointer; font-size: 24px; }

.saa-chat-body { 
    flex: 1; padding: 15px; overflow-y: auto; background: #fff; 
    display: flex; flex-direction: column; 
}

.saa-messages-container { display: flex; flex-direction: column; gap: 5px; }

/* Chat Bubbles */
.saa-message { 
    max-width: 80%; padding: 10px 14px; border-radius: 18px; font-size: 14px; word-wrap: break-word; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.saa-message.user { 
    background-color: var(--saa-bg-user); color: var(--saa-color-text-user); 
    align-self: flex-start; 
    border-bottom-right-radius: 4px; /* Asymmetric look */
}
.saa-message.bot { 
    background-color: var(--saa-bg-bot); color: var(--saa-color-text-bot); 
    align-self: flex-end; 
    border-bottom-left-radius: 4px; /* Asymmetric look */
}

/* Hide admin debug info in frontend */
.saa-admin-debug { display: none !important; }

.saa-tree-options { 
    display: flex; flex-direction: column; gap: 8px; margin-top: 5px; align-items: flex-end; 
}
.saa-tree-btn { 
    background: #fff; border: 1px solid var(--saa-color-secondary); 
    color: var(--saa-color-secondary); padding: 8px 16px; border-radius: 20px; 
    cursor: pointer; transition: 0.2s; 
}
.saa-tree-btn:hover { 
    background: var(--saa-color-secondary); color: #fff; 
}

/* Modern Input Bar */
.saa-chat-footer { 
    padding: 10px; border-top: 1px solid #eee; display: flex; gap: 10px; background: #fff; 
    align-items: flex-end;
}
#saa-input { 
    flex: 1; border: 1px solid #ddd; border-radius: 20px; padding: 12px 15px; 
    resize: none; font-family: inherit; font-size: 14px;
    max-height: 100px;
    background: #f5f5f5;
}
#saa-input:focus { border-color: var(--saa-color-primary); outline: none; background: #fff; }

#saa-send { 
    background: var(--saa-color-primary); color: #fff; border: none; 
    width: 45px; height: 45px; border-radius: 50%; cursor: pointer; 
    flex-shrink: 0;
    transition: transform 0.2s;
}
#saa-send:active { transform: scale(0.9); }

.saa-typing { 
    display: none; align-self: flex-end; margin-top: 5px; 
    background: var(--saa-bg-bot); padding: 5px 10px; border-radius: 10px; 
}
.saa-typing span { 
    display: inline-block; width: 6px; height: 6px; background: #aaa; 
    border-radius: 50%; margin: 0 2px; animation: saaTyping 1.4s infinite; 
}
@keyframes saaTyping { 0%, 100% {transform: scale(0);} 50% {transform: scale(1);} }

/* Sidebar Mode (Desktop Only) */
@media(min-width: 481px) {
    .saa-mode-sidebar #saa-chat-box {
        top: 0 !important;
        bottom: 0 !important;
        width: 380px !important;
        height: 100vh !important;
        border-radius: 0 !important;
        box-shadow: -5px 0 20px rgba(0,0,0,0.1);
        /* Left/Right Border handled by PHP inline styles */
    }
}

/* Embedded Mode */
.saa-embedded-wrap {
    width: 100%;
    height: 600px;
    position: relative;
    border: 1px solid #eee;
    border-radius: 10px;
    overflow: hidden;
}
.saa-embedded-wrap #saa-chat-box {
    position: absolute !important;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    box-shadow: none;
    display: flex !important;
}
.saa-embedded-wrap #saa-chat-toggle { display: none !important; }

/* Mobile Titles */
.saa-title-mobile { display: none; }

/* Mobile Mode (Telegram Feel - Always Active & Overrides Sidebar) */
@media(max-width:480px){ 
    .saa-mobile-app #saa-chat-box {
        position: fixed !important;
        inset: 0 !important;
        width: auto !important; 
        height: 100dvh !important; 
        border-radius: 0 !important;
        margin: 0 !important;
        z-index: 2147483647 !important; 
        /* Safe area handling */
        padding-bottom: max(env(safe-area-inset-bottom), var(--saa-mob-safe, 0px));
        left: 0 !important; right: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
    .saa-mobile-app #saa-chat-toggle {
        z-index: 2147483647 !important;
    }
    .saa-mobile-app .saa-chat-body {
        overscroll-behavior: contain;
    }
    .saa-mobile-app .saa-chat-header {
        padding-top: max(15px, env(safe-area-inset-top));
    }
    /* Switch Titles on Mobile */
    .saa-mobile-app .saa-title-desktop { display: none; }
    .saa-mobile-app .saa-title-mobile { display: inline; }
}

/* ==========================================================================
SMART ACTION BUTTONS (Inline Buttons)
   ========================================================================== */

/* ظرف نگه‌دارنده تمام دکمه‌های استخراج شده در زیر پیام ربات */
.saa-action-btns-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(0,0,0,0.08); /* خط جداکننده محو */
}

/* استایل گرافیکی دکمه شیشه‌ای */
.saa-action-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #ffffff;
    color: var(--saa-color-secondary) !important;
    text-decoration: none !important;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

/* جلوگیری از به هم ریختگی در صورت طولانی بودن نام دکمه */
.saa-action-btn span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: 8px; /* فاصله بین متن و آیکون در حالت RTL */
}

/* افکت Hover (هاور) برای احساس تعامل */
.saa-action-btn:hover {
    background-color: var(--saa-color-secondary);
    color: #ffffff !important;
    border-color: var(--saa-color-secondary);
    transform: translateY(-1px); /* افکت بالا آمدن ملایم */
    box-shadow: 0 3px 6px rgba(0,0,0,0.1);
}

/* تغییر رنگ آیکون هنگام Hover */
.saa-action-btn:hover svg {
    stroke: #ffffff;
}
