/* ==========================================================================
   IBRCartChat Widget Styles
   ========================================================================== */

:root {
    --ibr-primary: #1E3A8A;
    --ibr-accent: #10B981;
    --ibr-font-size: 15px;
    --ibr-bg: #ffffff;
    --ibr-text: #1f2937;
    --ibr-border: #e5e7eb;
    --ibr-radius: 12px;
}

#ibrcartchat-root {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    direction: ltr;
}

#ibrcartchat-root.ibr-rtl {
    direction: rtl;
}

/* زر الفتح (Launcher) */
.ibr-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--ibr-primary);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ibr-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.ibr-button.ibr-pulse {
    animation: ibr-pulse-anim 2s infinite;
}

@keyframes ibr-pulse-anim {
    0% { box-shadow: 0 0 0 0 rgba(30, 58, 138, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(30, 58, 138, 0); }
    100% { box-shadow: 0 0 0 0 rgba(30, 58, 138, 0); }
}

/* نافذة الشات */
.ibr-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 100px);
    background: var(--ibr-bg);
    border-radius: var(--ibr-radius);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
    border: 1px solid var(--ibr-border);
}

.ibr-window.ibr-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* رأس النافذة (Header) */
.ibr-header {
    background: var(--ibr-primary);
    color: white;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ibr-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ibr-header-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ibr-title {
    font-weight: bold;
    font-size: 15px;
}

.ibr-status {
    font-size: 11px;
    color: #a7f3d0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ibr-actions {
    display: flex;
    gap: 8px;
}

.ibr-icon-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 18px;
    opacity: 0.8;
    padding: 4px;
}

.ibr-icon-btn:hover {
    opacity: 1;
}

/* منطقة الرسائل */
.ibr-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* فقاعات الرسائل (Bubbles) */
.ibr-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.ibr-user {
    align-self: flex-end;
    align-items: flex-end;
}

.ibr-assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.ibr-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: var(--ibr-font-size) !important; /* ربط حجم الخط هنا */
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.ibr-user .ibr-bubble {
    background: var(--ibr-primary);
    color: white;
    border-bottom-right-radius: 2px;
}

.ibr-assistant .ibr-bubble {
    background: white;
    color: var(--ibr-text);
    border: 1px solid var(--ibr-border);
    border-bottom-left-radius: 2px;
}

/* تنسيقات Markdown المتقدمة (الخطوات والجداول) */
.ibr-bubble ol {
    list-style: none;
    padding-right: 0;
    margin: 15px 0;
    counter-reset: step-counter;
}

.ibr-rtl .ibr-bubble ol {
    padding-right: 0;
    padding-left: 0;
}

.ibr-bubble ol li {
    position: relative;
    padding-right: 40px;
    margin-bottom: 20px;
    counter-increment: step-counter;
    line-height: 1.6;
}

.ibr-rtl .ibr-bubble ol li {
    padding-right: 40px;
    padding-left: 0;
}

.ibr-bubble ol li::before {
    content: counter(step-counter);
    position: absolute;
    right: 0;
    top: 0;
    width: 28px;
    height: 28px;
    background: var(--ibr-primary);
    color: #fff;
    border-radius: 50%;
    text-align: center;
    line-height: 28px;
    font-weight: bold;
    font-size: 13px;
    z-index: 2;
}

/* السهم الواصل */
.ibr-bubble ol li::after {
    content: '↓';
    position: absolute;
    right: 8px;
    top: 26px;
    color: var(--ibr-accent);
    font-size: 16px;
    font-weight: bold;
    z-index: 1;
}

.ibr-bubble ol li:last-child::after {
    display: none;
}

/* الجداول */
.ibr-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 13px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
}

.ibr-bubble th, .ibr-bubble td {
    padding: 8px 10px;
    border: 1px solid var(--ibr-border);
    text-align: right;
}

.ibr-rtl .ibr-bubble th, .ibr-rtl .ibr-bubble td {
    text-align: right;
}

.ibr-bubble th {
    background-color: #f3f4f6;
    font-weight: bold;
}

/* الأقتباسات (Blockquotes) */
.ibr-bubble blockquote {
    border-left: 4px solid var(--ibr-accent);
    background: #f0fdf4;
    margin: 10px 0;
    padding: 8px 12px;
    color: #065f46;
    font-size: 13px;
    border-radius: 4px;
}

.ibr-rtl .ibr-bubble blockquote {
    border-left: none;
    border-right: 4px solid var(--ibr-accent);
}

/* بطاقات المنتجات */
.ibr-products {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    max-width: 100%;
}

.ibr-product-card {
    background: white;
    border: 1px solid var(--ibr-border);
    border-radius: 8px;
    padding: 8px;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ibr-product-thumb {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
}

.ibr-product-title {
    font-weight: bold;
    font-size: 12px;
    line-height: 1.2;
}

.ibr-product-price {
    color: var(--ibr-accent);
    font-weight: bold;
    font-size: 12px;
}

.ibr-product-add {
    background: var(--ibr-primary);
    color: white;
    padding: 6px;
    border-radius: 4px;
    font-size: 11px;
}

/* حقل الإدخال */
.ibr-input-area {
    padding: 12px;
    background: white;
    border-top: 1px solid var(--ibr-border);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ibr-input {
    flex: 1;
    border: 1px solid var(--ibr-border);
    border-radius: 20px;
    padding: 10px 15px;
    font-size: var(--ibr-font-size) !important; /* ربط حجم الخط هنا */
    font-family: inherit;
    resize: none;
    max-height: 100px;
    outline: none;
    line-height: 1.4;
}

.ibr-input:focus {
    border-color: var(--ibr-accent);
}

.ibr-send-btn {
    background: var(--ibr-accent);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ibr-send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

/* الفوتر */
.ibr-footer {
    padding: 8px 15px;
    background: white;
    border-top: 1px solid var(--ibr-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ibr-social-bar {
    display: flex;
    gap: 8px;
}

.ibr-social-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
}

.ibr-social-icon svg {
    width: 14px;
    height: 14px;
}

.ibr-powered-by {
    font-size: 10px;
    color: #9ca3af;
}

/* مؤشر الكتابة */
.ibr-typing .ibr-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
}

.ibr-typing span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: ibr-bounce 1.4s infinite ease-in-out both;
}

.ibr-typing span:nth-child(1) { animation-delay: -0.32s; }
.ibr-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes ibr-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* شريط الترقية في النسخة المجانية */
.ibr-upgrade-banner a {
    color: #059669 !important;
    text-decoration: none !important;
}
.ibr-upgrade-banner a:hover {
    text-decoration: underline !important;
}

/* استجابة للجوال */
@media (max-width: 480px) {
    .ibr-window {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
}


/* ==========================================================
   FULLSCREEN MODE (التكبير على كامل الشاشة)
   ========================================================== */
.ibr-window.ibr-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    z-index: 9999999 !important;
    transform: none !important;
}

.ibr-window.ibr-fullscreen .ibr-messages {
    padding: 25px max(15px, calc((100vw - 900px) / 2)) !important;
}

.ibr-window.ibr-fullscreen .ibr-input-area {
    padding: 15px max(15px, calc((100vw - 900px) / 2)) !important;
}

.ibr-window.ibr-fullscreen .ibr-message {
    max-width: 75% !important;
}

.ibr-window.ibr-fullscreen .ibr-bubble {
    font-size: calc(var(--ibr-font-size) + 1px) !important;
    padding: 12px 18px !important;
}

.ibr-window.ibr-fullscreen .ibr-button {
    display: none !important;
}

/* أيقونة الزر تتغير حسب الحالة */
.ibr-icon-btn.ibr-max-btn svg {
    transition: transform 0.3s;
}

.ibr-window.ibr-fullscreen .ibr-icon-btn.ibr-max-btn svg {
    transform: rotate(180deg);
}

/* منع تمرير الصفحة خلف الشات المكبر */
body.ibr-fullscreen-open {
    overflow: hidden !important;
}

@media (max-width: 768px) {
    .ibr-window.ibr-fullscreen .ibr-message {
        max-width: 90% !important;
    }
}

.ibr-image-preview img {
    max-width: 100%;
    border-radius: 6px;
    border: 2px solid #10B981;
}
.ibr-icon-btn.ibr-upload-btn:hover {
    color: var(--ibr-primary) !important;
    transform: scale(1.1);
}
.ibr-chat-image {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 8px;
    display: block;
    transition: transform 0.2s;
}
.ibr-chat-image:hover {
    transform: scale(1.02);
    cursor: pointer;
}
/* ============================================================
   FULLSCREEN — MESSAGE BUBBLES (20% margins on each side)
   ============================================================
   Bubble width: ~60% of the window
   Left margin:  20%
   Right margin: 20%
   ============================================================ */

/* Container padding — leave room so margins are consistent */
.ibr-window.ibr-fullscreen .ibr-messages {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.ibr-window.ibr-fullscreen .ibr-message {
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 30% !important;
    box-sizing: border-box !important;
}

/* ---- Assistant bubble: 60% wide, aligned left within the padded area ---- */
.ibr-window.ibr-fullscreen .ibr-message.ibr-assistant {
    justify-content: flex-start !important;
}
.ibr-window.ibr-fullscreen .ibr-message.ibr-assistant .ibr-bubble {
    max-width: 100% !important;
    width: auto !important;
}

/* ---- User bubble: 60% wide, aligned right within the padded area ---- */
.ibr-window.ibr-fullscreen .ibr-message.ibr-user {
    justify-content: flex-end !important;
}
.ibr-window.ibr-fullscreen .ibr-message.ibr-user .ibr-bubble {
    max-width: 100% !important;
    width: auto !important;
}

/* ---- Carousel & suggestions: follow the same 20% margin ---- */
.ibr-window.ibr-fullscreen .ibr-carousel {
    width: 100% !important;
    max-width: 100% !important;
}

.ibr-window.ibr-fullscreen .ibr-suggestions {
    max-width: 100% !important;
}

/* ---- Mobile: reduce margins (20% too much on small screens) ---- */
@media (max-width: 768px) {
    .ibr-window.ibr-fullscreen .ibr-message {
        padding: 0 8% !important;
    }
}