/* =========================================================================
   Alocart Chatbot Widget — self-contained styles (RTL / Persian, no deps)
   Theming is driven by CSS custom properties set at runtime from the
   chatbot settings API. Light/dark are handled via [data-acb-theme].
   ========================================================================= */

.acb-root,
.acb-root * {
    box-sizing: border-box;
}

.acb-root {
    /* Brand (overridden at runtime) */
    --acb-primary: #e74266;
    --acb-secondary: #20b69e;

    /* Light theme surface tokens (default) */
    --acb-bg: #ffffff;
    --acb-bg-soft: #f4f5f7;
    --acb-text: #1f2430;
    --acb-text-soft: #6b7280;
    --acb-border: #e6e8ee;
    --acb-bot-bg: #f4f5f7;
    --acb-bot-text: #1f2430;
    --acb-shadow: 0 12px 40px rgba(20, 20, 40, 0.18);

    --acb-radius: 16px;
    --acb-radius-sm: 12px;
    --acb-font: 'iranyekan', 'Vazirmatn', 'IRANSans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;

    position: fixed;
    z-index: 2147483000;
    direction: rtl;
    font-family: var(--acb-font);
    line-height: 1.75;
}

.acb-root[data-acb-theme="dark"] {
    --acb-bg: #1b1e27;
    --acb-bg-soft: #242833;
    --acb-text: #eef0f5;
    --acb-text-soft: #a2a8b6;
    --acb-border: #333846;
    --acb-bot-bg: #242833;
    --acb-bot-text: #eef0f5;
    --acb-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* Position */
.acb-root.acb-pos-right { right: 24px; bottom: 24px; }
.acb-root.acb-pos-left  { left: 24px;  bottom: 24px; }

/* ---------- Launcher bubble ---------- */
.acb-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--acb-primary);
    color: #fff;
    box-shadow: var(--acb-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .18s ease, box-shadow .18s ease;
}
.acb-launcher:hover { transform: scale(1.06); }
.acb-launcher svg { width: 28px; height: 28px; }
.acb-launcher .acb-badge {
    position: absolute;
    top: -2px; inset-inline-end: -2px;
    background: var(--acb-secondary);
    color: #fff;
    font-size: 11px;
    min-width: 18px; height: 18px;
    border-radius: 9px;
    display: none;
    align-items: center; justify-content: center;
    padding: 0 5px;
}

/* ---------- Chat window ---------- */
.acb-window {
    position: absolute;
    bottom: 76px;
    /* Physical anchoring (not logical) so the panel hugs the launcher in RTL. */
    right: 0;
    left: auto;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: var(--acb-bg);
    border-radius: var(--acb-radius);
    box-shadow: var(--acb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(12px) scale(.98);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.acb-root.acb-pos-left .acb-window { right: auto; left: 0; }
.acb-root.acb-open .acb-window { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.acb-root.acb-open .acb-launcher { transform: scale(.9); }

/* Header */
.acb-header {
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-secondary));
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.acb-header-titles { flex: 1; min-width: 0; }
.acb-header-titles h3 { margin: 0; font-size: 16px; font-weight: 700; }
.acb-header-titles p { margin: 2px 0 0; font-size: 12px; opacity: .9; }
.acb-header-btn {
    background: rgba(255, 255, 255, .18);
    border: none; color: #fff; cursor: pointer;
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s ease;
}
.acb-header-btn:hover { background: rgba(255, 255, 255, .32); }
.acb-header-btn svg { width: 18px; height: 18px; }

/* Messages */
.acb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--acb-bg);
    scrollbar-width: thin;
}
.acb-messages::-webkit-scrollbar { width: 7px; }
.acb-messages::-webkit-scrollbar-thumb { background: var(--acb-border); border-radius: 4px; }

.acb-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: var(--acb-radius-sm);
    font-size: 14px;
    word-wrap: break-word;
    white-space: normal;
    animation: acb-in .18s ease;
}
@keyframes acb-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.acb-msg-bot  { align-self: flex-start; background: var(--acb-bot-bg); color: var(--acb-bot-text); border-bottom-right-radius: 4px; }
.acb-msg-user { align-self: flex-end;  background: var(--acb-primary); color: #fff; border-bottom-left-radius: 4px; }

/* Markdown bits inside messages */
.acb-msg p { margin: 0 0 8px; }
.acb-msg p:last-child { margin-bottom: 0; }
.acb-msg a { color: inherit; text-decoration: underline; font-weight: 600; }
.acb-msg-bot a { color: var(--acb-primary); }
.acb-msg ul, .acb-msg ol { margin: 6px 0; padding-inline-start: 20px; }
.acb-msg li { margin: 2px 0; }
.acb-msg code { background: rgba(127, 127, 127, .18); padding: 1px 5px; border-radius: 5px; font-size: 13px; direction: ltr; display: inline-block; }
.acb-msg pre { background: rgba(127, 127, 127, .14); padding: 10px; border-radius: 8px; overflow-x: auto; direction: ltr; }
.acb-msg strong { font-weight: 700; }

/* Inline images inside bot messages */
.acb-msg img { max-width: 100%; border-radius: 8px; }

/* Product card (rendered when a bot message pairs an image with a link) */
.acb-product {
    display: flex;
    align-items: stretch;
    gap: 0;
    margin: 8px 0 2px;
    border: 1px solid var(--acb-border);
    border-radius: 16px;
    overflow: hidden;
    background: var(--acb-bg);
    text-decoration: none;
    color: var(--acb-text);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .10);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.acb-product:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(0, 0, 0, .18);
    border-color: var(--acb-primary);
}
.acb-product-thumb {
    flex: 0 0 92px;
    width: 92px;
    background: var(--acb-bg-soft);
    position: relative;
    overflow: hidden;
}
.acb-product-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}
.acb-product-body {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    padding: 12px 14px;
    min-width: 0;
}
.acb-product-title {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.acb-product-cta {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12.5px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--acb-primary), var(--acb-secondary));
    padding: 5px 12px;
    border-radius: 999px;
}

/* Typing indicator */
.acb-typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: var(--acb-bot-bg); border-radius: var(--acb-radius-sm); }
.acb-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--acb-text-soft); animation: acb-blink 1.2s infinite ease-in-out; }
.acb-typing span:nth-child(2) { animation-delay: .2s; }
.acb-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes acb-blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* Suggested questions */
.acb-suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.acb-chip {
    background: var(--acb-bg-soft);
    color: var(--acb-text);
    border: 1px solid var(--acb-border);
    border-radius: 999px;
    padding: 7px 13px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s ease;
}
.acb-chip:hover { border-color: var(--acb-primary); color: var(--acb-primary); }

/* Input */
.acb-input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--acb-border);
    background: var(--acb-bg);
}
.acb-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--acb-border);
    background: var(--acb-bg-soft);
    color: var(--acb-text);
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    max-height: 110px;
    line-height: 1.6;
    outline: none;
    transition: border-color .15s ease;
}
.acb-input textarea:focus { border-color: var(--acb-primary); }
.acb-input textarea::placeholder { color: var(--acb-text-soft); }
.acb-send {
    background: var(--acb-primary);
    border: none;
    color: #fff;
    width: 42px; height: 42px;
    border-radius: 12px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    transition: opacity .15s ease, transform .15s ease;
}
.acb-send:hover { transform: translateY(-1px); }
.acb-send:disabled { opacity: .5; cursor: default; transform: none; }
.acb-send svg { width: 20px; height: 20px; }

.acb-footer { text-align: center; font-size: 11px; color: var(--acb-text-soft); padding: 0 0 8px; background: var(--acb-bg); }
.acb-footer a { color: var(--acb-text-soft); text-decoration: none; }

@media (max-width: 480px) {
    /* لانچر بالای منوی پایینِ موبایلِ قالب (app-navbar-menu ~۵۶px) بنشیند
       تا رویش نیفتد؛ safe-area برای آیفون هم لحاظ می‌شود. */
    .acb-root.acb-pos-right, .acb-root.acb-pos-left { right: 12px; left: auto; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
    .acb-root.acb-pos-left { right: auto; left: 12px; }
    .acb-window { width: calc(100vw - 24px); height: calc(100vh - 150px); bottom: 74px; }
}
