#ai-chat-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 65px;
    height: 65px;
    background: #ffffff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    transition: 0.2s ease;
    z-index: 9999999;
}

#ai-chat-bubble img {
    width: 42px;
    height: 42px;
    object-fit: contain;
}

#ai-chat-bubble:hover {
    transform: scale(1.10);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
}

/* Hover effect */
#ai-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

#ai-chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 330px;
    height: 430px;
    background: white;
    border-radius: 12px;
    border: 1px solid #ddd;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999999;
}

#ai-chat-header {
    background: #2271b1;
    padding: 12px;
    text-align: center;
    color: white;
    font-weight: bold;
}

#ai-chat-messages {
    flex: 1;
    height: calc(430px - 120px);
    padding: 10px;
    overflow-y: auto;
    overflow-x: hidden;
    display: block;
    scroll-behavior: smooth;
}

.ai-msg-user {
    background: #d6ecff;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 8px;
    text-align: right !important;
    direction: rtl;
}

.ai-msg-bot {
    background: #f1f1f1;
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 8px;
    text-align: right !important;
    direction: rtl;
}

#ai-chat-input-area {
    display: flex;
    flex-direction: row-reverse;
    /* Important: keep the desired input/button order */
    gap: 5px;
    padding: 10px;
    border-top: 1px solid #ddd;
}

#ai-chat-input {
    flex: 1;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #aaa;
}

#ai-chat-send {
    padding: 8px 12px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Font */
/* Local Vazirmatn font (self-hosted) */
@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url("../fonts/vazirmatn/Vazirmatn-Light.woff2") format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/vazirmatn/Vazirmatn-Regular.woff2") format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/vazirmatn/Vazirmatn-Medium.woff2") format('woff2');
}

@font-face {
    font-family: 'Vazirmatn';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/vazirmatn/Vazirmatn-Bold.woff2") format('woff2');
}

#ai-chat-window,
#ai-chat-header,
#ai-chat-messages,
#ai-chat-input,
#ai-chat-send {
    font-family: 'Vazirmatn', sans-serif !important;
}

/* Message input (RTL) */
#ai-chat-input {
    flex: 1;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #aaa;
    text-align: right !important;
    direction: rtl;
    font-size: 14px;
    font-family: 'Vazirmatn', sans-serif !important;
}

/* Placeholder (RTL) */
#ai-chat-input::placeholder {
    text-align: right;
    direction: rtl;
    color: #777;
    font-family: 'Vazirmatn', sans-serif !important;
}

/* Send button */
#ai-chat-send {
    padding: 10px 14px;
    background: #2271b1;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-family: 'Vazirmatn', sans-serif !important;
}

/* Message bubble styling */
.ai-msg-user {
    background: #2271b1;
    color: white;
    padding: 10px 14px;
    border-radius: 14px 14px 0 14px;
    margin-bottom: 8px;
    text-align: right !important;
    direction: rtl;
    max-width: 85%;
    margin-left: auto !important;
    margin-right: 0 !important;
}

.ai-msg-bot {
    background: #ffffff;
    border: 1px solid #2271b1;
    color: #333;
    padding: 10px 14px;
    border-radius: 14px 14px 14px 0;
    margin-bottom: 8px;
    text-align: right !important;
    direction: rtl;
    max-width: 85%;
}

/* =========================================================
   AI_CA_FORCE_LAYOUT (stable RTL/LTR)
   - Send button ALWAYS on the LEFT of the input
   - User message on the RIGHT, Bot message on the LEFT
   ========================================================= */
#ai-chat-window #ai-chat-input-area {
    display: flex !important;
    flex-direction: row-reverse !important;
    /* input then button => button goes left */
    direction: ltr !important;
    align-items: center !important;
}

#ai-chat-window #ai-chat-send {
    order: 1 !important;
}

#ai-chat-window #ai-chat-input {
    order: 2 !important;
    direction: rtl !important;
    text-align: right !important;
}

#ai-chat-window #ai-chat-messages {
    display: flex !important;
    flex-direction: column !important;
}

#ai-chat-window #ai-chat-messages .ai-msg-user {
    align-self: flex-end !important;
    margin-left: auto !important;
    margin-right: 0 !important;
}

#ai-chat-window #ai-chat-messages .ai-msg-bot {
    align-self: flex-start !important;
    margin-right: auto !important;
    margin-left: 0 !important;
}

/* =========================================================
   AI_CA_FORCE_SEND_LEFT (stable across themes/RTL/LTR)
   - Ensures SEND button stays on the LEFT of the input
   - Works whether input id is #ai-chat-input or #ai-chat-txt
   ========================================================= */
#ai-chat-window #ai-chat-input-area {
    display: flex !important;
    flex-direction: row !important;
    /* respect RTL for ordering */
    direction: rtl !important;
    /* first element on RIGHT, second on LEFT */
    align-items: center !important;
    gap: 5px !important;
}

#ai-chat-window #ai-chat-input,
#ai-chat-window #ai-chat-txt {
    flex: 1 1 auto !important;
    order: 1 !important;
    /* keep input first (right side) */
    direction: rtl !important;
    text-align: right !important;
}

#ai-chat-window #ai-chat-send {
    flex: 0 0 auto !important;
    order: 2 !important;
    /* keep button second (left side) */
}

/* =========================================================
   AI_CA_LINK_STYLES
   - Make chatbot links clearly visible (blue + bold)
   ========================================================= */
#ai-chat-window #ai-chat-messages a,
#ai-chat-window #ai-chat-messages a:visited {
    color: #1d4ed8 !important;
    font-weight: 800 !important;
    text-decoration: underline !important;
    cursor: pointer !important;
}

#ai-chat-window #ai-chat-messages a:hover {
    opacity: 0.9 !important;
}