/*!
 * eJouets Chatbot Pro — Premium UI
 * Style: Modern SaaS (Shopify Inbox / Intercom inspired)
 * Mobile-first, glassmorphism, soft shadows, smooth motion.
 */

:root {
    /* Brand palette */
    --ejcbp-grad-start:  #6366f1;   /* indigo */
    --ejcbp-grad-mid:    #8b5cf6;   /* violet */
    --ejcbp-grad-end:    #ec4899;   /* pink */
    --ejcbp-primary:     #6366f1;
    --ejcbp-primary-700: #4f46e5;

    /* Neutrals */
    --ejcbp-bg:          #ffffff;
    --ejcbp-bg-soft:     #f8fafc;
    --ejcbp-bg-bubble:   #f1f5f9;
    --ejcbp-text:        #0f172a;
    --ejcbp-text-muted:  #64748b;
    --ejcbp-text-soft:   #94a3b8;
    --ejcbp-border:      #e2e8f0;
    --ejcbp-border-soft: #f1f5f9;

    /* States */
    --ejcbp-success:     #10b981;
    --ejcbp-warning:     #f59e0b;
    --ejcbp-danger:      #ef4444;

    /* Effects */
    --ejcbp-radius-lg:   18px;
    --ejcbp-radius-md:   14px;
    --ejcbp-radius-sm:   10px;
    --ejcbp-shadow-1:    0 4px 12px -2px rgba(15, 23, 42, .08), 0 2px 4px -1px rgba(15, 23, 42, .04);
    --ejcbp-shadow-2:    0 12px 32px -8px rgba(15, 23, 42, .18), 0 4px 12px -2px rgba(15, 23, 42, .08);
    --ejcbp-shadow-3:    0 24px 64px -16px rgba(99, 102, 241, .35), 0 8px 24px -4px rgba(15, 23, 42, .12);

    --ejcbp-font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ejcbp-font-head:   'Poppins', var(--ejcbp-font);
    --ejcbp-z:           2147483600;
}

/* ========================================================================
   ROOT
   ======================================================================== */
.ejcbp,
.ejcbp * {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.ejcbp {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: var(--ejcbp-z);
    font-family: var(--ejcbp-font);
    font-size: 14px;
    color: var(--ejcbp-text);
    line-height: 1.5;
}

/* ========================================================================
   LAUNCHER
   ======================================================================== */
.ejcbp-launcher {
    position: relative;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, var(--ejcbp-grad-start) 0%, var(--ejcbp-grad-mid) 50%, var(--ejcbp-grad-end) 100%);
    box-shadow: var(--ejcbp-shadow-3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .25s ease, box-shadow .25s ease;
    outline: none;
    padding: 0;
}
.ejcbp-launcher:hover  { transform: translateY(-2px) scale(1.04); }
.ejcbp-launcher:active { transform: translateY(0) scale(.98); }

.ejcbp-launcher-icon,
.ejcbp-launcher-close {
    position: absolute;
    width: 26px;
    height: 26px;
    transition: opacity .2s ease, transform .2s ease;
}
.ejcbp-launcher-close { opacity: 0; transform: rotate(-90deg); }
.ejcbp.is-open .ejcbp-launcher-icon  { opacity: 0; transform: rotate(90deg); }
.ejcbp.is-open .ejcbp-launcher-close { opacity: 1; transform: rotate(0); }

.ejcbp-launcher-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-grad-end));
    opacity: .35;
    z-index: -1;
    animation: ejcbp-pulse-ring 2.4s ease-out infinite;
}
@keyframes ejcbp-pulse-ring {
    0%   { transform: scale(.85); opacity: .5; }
    70%  { transform: scale(1.4);  opacity: 0;   }
    100% { transform: scale(1.4);  opacity: 0;   }
}

/* ========================================================================
   WINDOW
   ======================================================================== */
.ejcbp-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 384px;
    max-width: calc(100vw - 24px);
    height: min(640px, calc(100vh - 110px));
    background: var(--ejcbp-bg);
    border-radius: var(--ejcbp-radius-lg);
    box-shadow: var(--ejcbp-shadow-2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--ejcbp-border-soft);
    transform: translateY(20px) scale(.97);
    opacity: 0;
    transition: transform .26s cubic-bezier(.16,1,.3,1), opacity .2s ease;
    pointer-events: none;
}
.ejcbp.is-open .ejcbp-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.ejcbp-window[hidden] { display: flex !important; }

/* ========================================================================
   HEADER
   ======================================================================== */
.ejcbp-header {
    position: relative;
    padding: 18px 16px 22px;
    color: #fff;
    background: linear-gradient(135deg, var(--ejcbp-grad-start) 0%, var(--ejcbp-grad-mid) 60%, var(--ejcbp-grad-end) 130%);
    overflow: hidden;
    flex-shrink: 0;
}
.ejcbp-header-glow {
    position: absolute;
    inset: -40%;
    background:
        radial-gradient(circle at 20% 30%, rgba(255,255,255,.25), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(255,255,255,.18), transparent 50%);
    pointer-events: none;
}
.ejcbp-header-content {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ejcbp-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, .3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ejcbp-avatar-emoji { font-size: 22px; line-height: 1; }
.ejcbp-status-dot {
    position: absolute;
    bottom: 1px; right: 1px;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: var(--ejcbp-success);
    border: 2px solid #fff;
}

.ejcbp-header-text { flex: 1; min-width: 0; }
.ejcbp-title {
    font-family: var(--ejcbp-font-head);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -.01em;
}
.ejcbp-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: .92;
    margin-top: 2px;
}
.ejcbp-status-pulse {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, .7);
    animation: ejcbp-pulse-dot 2s ease-out infinite;
}
@keyframes ejcbp-pulse-dot {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, .7); }
    70%  { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.ejcbp-header-actions { display: flex; gap: 4px; }
.ejcbp-icon-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 0;
    background: transparent;
    color: rgba(255,255,255,.85);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s ease, color .15s ease;
}
.ejcbp-icon-btn svg { width: 16px; height: 16px; }
.ejcbp-icon-btn:hover {
    background: rgba(255, 255, 255, .15);
    color: #fff;
}

/* ========================================================================
   BODY / MESSAGES
   ======================================================================== */
.ejcbp-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        linear-gradient(180deg, var(--ejcbp-bg-soft) 0%, var(--ejcbp-bg) 100%);
}

.ejcbp-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px 8px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--ejcbp-border) transparent;
}
.ejcbp-messages::-webkit-scrollbar { width: 6px; }
.ejcbp-messages::-webkit-scrollbar-thumb { background: var(--ejcbp-border); border-radius: 3px; }

/* Message bubble */
.ejcbp-msg {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    align-items: flex-end;
    animation: ejcbp-msg-in .32s cubic-bezier(.16,1,.3,1) both;
}
@keyframes ejcbp-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ejcbp-msg-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-grad-end));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
}
.ejcbp-msg-content { max-width: 78%; }
.ejcbp-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    background: var(--ejcbp-bg-bubble);
    color: var(--ejcbp-text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.ejcbp-bubble strong { font-weight: 600; color: var(--ejcbp-text); }
.ejcbp-bubble em     { font-style: normal; color: var(--ejcbp-primary); font-weight: 500; }

.ejcbp-msg.bot   .ejcbp-bubble { border-bottom-left-radius: 6px; }
.ejcbp-msg.user                  { flex-direction: row-reverse; }
.ejcbp-msg.user .ejcbp-msg-avatar {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    color: var(--ejcbp-text-muted);
}
.ejcbp-msg.user .ejcbp-bubble {
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-primary-700));
    color: #fff;
    border-bottom-right-radius: 6px;
}
.ejcbp-msg.user .ejcbp-bubble strong { color: #fff; }

.ejcbp-msg-meta {
    font-size: 11px;
    color: var(--ejcbp-text-soft);
    margin-top: 4px;
    padding: 0 4px;
}
.ejcbp-msg.user .ejcbp-msg-meta { text-align: right; }

/* Typing indicator */
.ejcbp-typing { display: flex; gap: 4px; padding: 6px 0; }
.ejcbp-typing span {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--ejcbp-text-soft);
    animation: ejcbp-typing-bounce 1.2s ease-in-out infinite;
}
.ejcbp-typing span:nth-child(2) { animation-delay: .15s; }
.ejcbp-typing span:nth-child(3) { animation-delay: .3s;  }
@keyframes ejcbp-typing-bounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: .4; }
    30%          { transform: translateY(-5px); opacity: 1;  }
}

/* ========================================================================
   QUICK ACTIONS (dynamic buttons after first message)
   ======================================================================== */
.ejcbp-quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 4px 16px 16px;
}
.ejcbp-action-btn {
    position: relative;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--ejcbp-border);
    background: #fff;
    color: var(--ejcbp-text);
    font: 500 13px var(--ejcbp-font);
    cursor: pointer;
    text-align: left;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    animation: ejcbp-action-in .35s cubic-bezier(.16,1,.3,1) both;
    line-height: 1.3;
}
.ejcbp-action-btn:nth-child(1) { animation-delay: .02s; }
.ejcbp-action-btn:nth-child(2) { animation-delay: .06s; }
.ejcbp-action-btn:nth-child(3) { animation-delay: .10s; }
.ejcbp-action-btn:nth-child(4) { animation-delay: .14s; }
.ejcbp-action-btn:nth-child(5) { animation-delay: .18s; }
.ejcbp-action-btn:nth-child(6) { animation-delay: .22s; }
.ejcbp-action-btn:nth-child(7) { animation-delay: .26s; }
.ejcbp-action-btn:nth-child(8) { animation-delay: .30s; }
.ejcbp-action-btn:nth-child(9) { animation-delay: .34s; }
@keyframes ejcbp-action-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ejcbp-action-btn:hover {
    transform: translateY(-1px);
    border-color: transparent;
    box-shadow:
        0 4px 12px -2px rgba(99, 102, 241, .2),
        inset 0 0 0 1px transparent;
    background-image:
        linear-gradient(#fff, #fff),
        linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-grad-end));
    background-origin: border-box;
    background-clip: padding-box, border-box;
    border: 1px solid transparent;
}
.ejcbp-action-btn:active { transform: translateY(0); }

/* Single column for short button lists (inline / yes-no) */
.ejcbp-msg .ejcbp-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.ejcbp-msg .ejcbp-action-row .ejcbp-action-btn {
    padding: 7px 12px;
    font-size: 12.5px;
    border-radius: 999px;
    flex: 0 1 auto;
}

/* ========================================================================
   CARDS (product, tracking, summary)
   ======================================================================== */
.ejcbp-card {
    background: #fff;
    border: 1px solid var(--ejcbp-border);
    border-radius: var(--ejcbp-radius-md);
    padding: 12px;
    margin-top: 8px;
    box-shadow: var(--ejcbp-shadow-1);
    animation: ejcbp-msg-in .35s cubic-bezier(.16,1,.3,1) both;
}

/* Product card */
.ejcbp-product {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.ejcbp-product-img {
    width: 64px; height: 64px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--ejcbp-bg-soft);
    border: 1px solid var(--ejcbp-border-soft);
}
.ejcbp-product-info { flex: 1; min-width: 0; }
.ejcbp-product-name {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--ejcbp-text);
    margin-bottom: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.ejcbp-product-price {
    font-weight: 700;
    font-size: 14px;
    color: var(--ejcbp-primary);
    margin-bottom: 6px;
}
.ejcbp-product-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ejcbp-mini-btn {
    padding: 5px 10px;
    border-radius: 999px;
    font: 500 11.5px var(--ejcbp-font);
    border: 1px solid var(--ejcbp-border);
    background: #fff;
    color: var(--ejcbp-text);
    cursor: pointer;
    transition: all .15s ease;
}
.ejcbp-mini-btn:hover {
    border-color: var(--ejcbp-primary);
    color: var(--ejcbp-primary);
}
.ejcbp-mini-btn.is-primary {
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-primary-700));
    color: #fff;
    border-color: transparent;
}
.ejcbp-mini-btn.is-primary:hover {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px -2px rgba(99, 102, 241, .4);
}

/* Tracking card */
.ejcbp-tracking-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ejcbp-border-soft);
}
.ejcbp-tracking-num {
    font-family: var(--ejcbp-font-head);
    font-weight: 600;
    font-size: 14px;
}
.ejcbp-tracking-num small { color: var(--ejcbp-text-muted); font-weight: 500; font-size: 11px; }
.ejcbp-status-badge {
    padding: 4px 10px;
    border-radius: 999px;
    font: 600 11px var(--ejcbp-font);
    background: rgba(99, 102, 241, .1);
    color: var(--ejcbp-primary);
}
.ejcbp-status-badge.is-cancel { background: rgba(239, 68, 68, .1); color: var(--ejcbp-danger); }
.ejcbp-status-badge.is-done   { background: rgba(16, 185, 129, .1); color: var(--ejcbp-success); }

/* Timeline */
.ejcbp-timeline {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    position: relative;
}
.ejcbp-timeline::before {
    content: '';
    position: absolute;
    top: 9px; left: 12px; right: 12px;
    height: 2px;
    background: var(--ejcbp-border);
    z-index: 0;
}
.ejcbp-timeline-fill {
    position: absolute;
    top: 9px; left: 12px;
    height: 2px;
    background: linear-gradient(90deg, var(--ejcbp-grad-start), var(--ejcbp-grad-end));
    transition: width .5s ease;
    z-index: 1;
}
.ejcbp-timeline-step {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--ejcbp-text-muted);
    flex: 1;
}
.ejcbp-timeline-dot {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--ejcbp-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ejcbp-text-soft);
    font-size: 10px;
    transition: all .3s ease;
}
.ejcbp-timeline-step.is-done .ejcbp-timeline-dot {
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-grad-end));
    border-color: transparent;
    color: #fff;
}
.ejcbp-timeline-step.is-done .ejcbp-timeline-label { color: var(--ejcbp-text); font-weight: 500; }

.ejcbp-tracking-meta {
    margin-top: 10px;
    font-size: 12px;
    color: var(--ejcbp-text-muted);
}
.ejcbp-tracking-meta strong { color: var(--ejcbp-text); }
.ejcbp-tracking-items {
    margin-top: 8px;
    font-size: 12px;
}
.ejcbp-tracking-items li {
    padding: 4px 0;
    border-top: 1px solid var(--ejcbp-border-soft);
    display: flex; justify-content: space-between;
}
.ejcbp-tracking-items li:first-child { border-top: 0; }

/* Order summary card */
.ejcbp-summary-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    font-size: 13px;
    border-top: 1px solid var(--ejcbp-border-soft);
}
.ejcbp-summary-row:first-child { border-top: 0; }
.ejcbp-summary-row .lbl { color: var(--ejcbp-text-muted); }
.ejcbp-summary-row .val { color: var(--ejcbp-text); font-weight: 500; text-align: right; }
.ejcbp-summary-total {
    margin-top: 8px;
    padding-top: 10px;
    border-top: 2px solid var(--ejcbp-border);
    font-weight: 700;
    font-size: 15px;
    color: var(--ejcbp-primary);
    display: flex;
    justify-content: space-between;
}

/* ========================================================================
   FOOTER / INPUT
   ======================================================================== */
.ejcbp-footer {
    padding: 10px 12px 8px;
    background: #fff;
    border-top: 1px solid var(--ejcbp-border-soft);
    flex-shrink: 0;
}
.ejcbp-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ejcbp-bg-soft);
    border: 1px solid var(--ejcbp-border);
    border-radius: 22px;
    padding: 4px 4px 4px 14px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ejcbp-input-wrap:focus-within {
    border-color: var(--ejcbp-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .14);
    background: #fff;
}
.ejcbp-input {
    flex: 1;
    border: 0;
    background: transparent;
    color: var(--ejcbp-text);
    font: 14px var(--ejcbp-font);
    resize: none;
    outline: none;
    padding: 8px 0;
    max-height: 96px;
    line-height: 1.4;
}
.ejcbp-input::placeholder { color: var(--ejcbp-text-soft); }

.ejcbp-send {
    width: 34px; height: 34px;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, var(--ejcbp-grad-start), var(--ejcbp-primary-700));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform .15s ease, opacity .15s ease;
    padding: 0;
}
.ejcbp-send:hover:not(:disabled)  { transform: scale(1.06); }
.ejcbp-send:active:not(:disabled) { transform: scale(.95); }
.ejcbp-send:disabled { opacity: .4; cursor: not-allowed; }
.ejcbp-send svg { width: 15px; height: 15px; }

.ejcbp-poweredby {
    text-align: center;
    font-size: 10.5px;
    color: var(--ejcbp-text-soft);
    margin-top: 6px;
    letter-spacing: .01em;
}

/* ========================================================================
   MOBILE
   ======================================================================== */
@media (max-width: 480px) {
    .ejcbp { bottom: 16px; right: 16px; }
    .ejcbp.is-open .ejcbp-window {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        bottom: 0;
        right: 0;
    }
    .ejcbp.is-open .ejcbp-launcher { display: none; }
    .ejcbp-header { padding-top: max(18px, env(safe-area-inset-top)); }
    .ejcbp-footer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ejcbp *,
    .ejcbp *::before,
    .ejcbp *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
