@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@300;400;500&family=Outfit:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --brand: #0a0a0a;
    --accent: #6c47ff;
    --accent-light: #8b6dff;
    --surface: #ffffff;
    --surface-2: #f5f4ff;
    --surface-3: #ede9ff;
    --border: rgba(108, 71, 255, 0.15);
    --text: #0a0a0a;
    --text-muted: #6b7280;
    --bubble-user: #6c47ff;
    --bubble-ai: #f0eeff;
    --radius: 18px;
    --shadow: 0 20px 60px rgba(108, 71, 255, 0.18);
}

/* ── Floating Button ── */
#storebrain-floating-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9998;
    box-shadow: 0 8px 30px rgba(108, 71, 255, 0.45);
    transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease;
}
#storebrain-floating-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(108, 71, 255, 0.55);
}
#storebrain-floating-button svg { width: 26px; height: 26px; fill: #fff; }
#storebrain-floating-button .sb-badge {
    position: absolute;
    top: -3px; right: -3px;
    width: 14px; height: 14px;
    background: #ff4d6d;
    border-radius: 50%;
    border: 2px solid #fff;
    display: none;
}
#storebrain-floating-button.has-notification .sb-badge { display: block; }

/* ── Widget Container ── */
#storebrain-widget-container {
    position: fixed;
    bottom: 96px; right: 24px;
    width: 380px;
    z-index: 9999;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(.34,1.56,.64,1);
    transform-origin: bottom right;
}
#storebrain-widget-container.storebrain-hidden {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
    pointer-events: none;
}
#storebrain-widget-container:not(.storebrain-hidden) {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* ── Chat Shell ── */
#storebrain-chat-container {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 560px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    font-family: 'DM Sans', sans-serif;
}

/* ══════════════════════════════════════════
   HEADER — NEW DESIGN
   ══════════════════════════════════════════ */
#storebrain-widget-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 68px;
    background: #0f0f13;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
#storebrain-widget-header::before {
    content: '';
    position: absolute;
    top: -40px; left: -20px;
    width: 160px; height: 160px;
    background: radial-gradient(circle, rgba(108,71,255,0.28) 0%, transparent 70%);
    animation: headerGlow 4s ease-in-out infinite alternate;
    pointer-events: none;
}
#storebrain-widget-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        90deg, transparent, transparent 40px,
        rgba(255,255,255,0.012) 40px, rgba(255,255,255,0.012) 41px
    );
    pointer-events: none;
}
@keyframes headerGlow {
    0%   { transform: translate(0,0) scale(1); opacity: 0.7; }
    100% { transform: translate(20px,10px) scale(1.2); opacity: 1; }
}
.sb-header-avatar {
    position: relative;
    width: 42px; height: 42px;
    flex-shrink: 0;
    z-index: 1;
}
.sb-avatar-ring {
    position: absolute;
    inset: -3px;
    border-radius: 14px;
    background: conic-gradient(from 0deg, #6c47ff, #a78bfa, #38bdf8, #6c47ff);
    animation: spin 4s linear infinite;
    opacity: 0.85;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sb-avatar-inner {
    position: absolute;
    inset: 2px;
    background: #1a1a24;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.sb-header-info {
    flex: 1;
    z-index: 1;
    min-width: 0;
}
.sb-header-name {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 15px;
    color: #ffffff;
    letter-spacing: 0.01em;
    line-height: 1;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sb-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: rgba(255,255,255,0.45);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.sb-status-dot {
    width: 6px; height: 6px;
    background: #22c55e;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 6px #22c55e;
    animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px #22c55e; }
    50%       { opacity: 0.6; box-shadow: 0 0 14px #22c55e; }
}
#storebrain-close-btn {
    width: 32px; height: 32px;
    border-radius: 9px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    font-size: 20px;
    line-height: 1;
    padding: 0;
    z-index: 1;
    font-family: sans-serif;
}
#storebrain-close-btn:hover {
    background: rgba(239,68,68,0.15);
    color: #f87171;
    border-color: rgba(239,68,68,0.25);
}
/* ══ END HEADER ══ */

/* ── Messages ── */
#storebrain-messages {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fafafa;
    scroll-behavior: smooth;
}
#storebrain-messages::-webkit-scrollbar { width: 4px; }
#storebrain-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ── Message Bubbles ── */
.storebrain-message {
    max-width: 82%;
    animation: msgIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.sb-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
}
.storebrain-message.customer { align-self: flex-end; }
.storebrain-message.customer .sb-bubble {
    background: var(--bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(108, 71, 255, 0.25);
}
.storebrain-message.assistant { align-self: flex-start; }
.storebrain-message.assistant .sb-bubble {
    background: var(--bubble-ai);
    color: var(--text);
    border-bottom-left-radius: 4px;
}
.sb-timestamp {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}
.storebrain-message.customer .sb-timestamp { text-align: right; }

/* ── Typing Indicator ── */
.sb-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: var(--bubble-ai);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}
.sb-typing span {
    width: 7px; height: 7px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.2s infinite;
    opacity: 0.4;
}
.sb-typing span:nth-child(2) { animation-delay: 0.2s; }
.sb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-4px); opacity: 1; }
}

/* ── Product Card ── */
.sb-product-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    max-width: 260px;
    margin-top: 8px;
    box-shadow: 0 4px 20px rgba(108,71,255,0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: msgIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
.sb-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(108,71,255,0.14);
}
.sb-product-img {
    width: 100%; height: 140px;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
}
.sb-product-img img { width: 100%; height: 100%; object-fit: cover; }
.sb-product-body { padding: 12px 14px; }
.sb-product-name {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    margin-bottom: 4px;
    line-height: 1.3;
}
.sb-product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
    font-family: 'Syne', sans-serif;
}
.sb-product-stock {
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 10px;
}
.sb-product-stock.in-stock { background: #dcfce7; color: #16a34a; }
.sb-product-stock.out-stock { background: #fee2e2; color: #dc2626; }
.sb-add-cart-btn {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
    font-family: 'DM Sans', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.sb-add-cart-btn:hover { background: var(--accent-light); transform: translateY(-1px); }
.sb-add-cart-btn:active { transform: scale(0.97); }
.sb-add-cart-btn.added { background: #16a34a; }
.sb-view-btn {
    width: 100%;
    padding: 8px;
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 6px;
    transition: background 0.2s;
    font-family: 'DM Sans', sans-serif;
}
.sb-view-btn:hover { background: var(--surface-2); }

/* ── Input Area ── */
#storebrain-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--surface);
    border-top: 1px solid rgba(0,0,0,0.06);
}
#storebrain-message-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    font-family: 'DM Sans', sans-serif;
    background: var(--surface-2);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}
#storebrain-message-input:focus { border-color: var(--accent); background: #fff; }
#storebrain-message-input::placeholder { color: var(--text-muted); }
#storebrain-send-btn {
    width: 42px; height: 42px;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}
#storebrain-send-btn,#storebrain-floating-button{
    padding: 0;
}
#storebrain-send-btn:hover { background: var(--accent-light); transform: scale(1.05); }
#storebrain-send-btn:active { transform: scale(0.95); }
#storebrain-send-btn:disabled { background: #d1d5db; cursor: not-allowed; transform: none; }
#storebrain-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Welcome ── */
.sb-welcome { text-align: center; padding: 20px 10px; }
.sb-welcome-icon { font-size: 40px; margin-bottom: 10px; }
.sb-welcome h3 {
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    margin-bottom: 6px;
}
.sb-welcome p { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ── Toast ── */
.sb-toast {
    position: fixed;
    bottom: 100px; right: 24px;
    background: var(--brand);
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-family: 'DM Sans', sans-serif;
    z-index: 10000;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}
.sb-toast.show { opacity: 1; transform: translateY(0); }

/* ── Mobile ── */
@media (max-width: 480px) {
    #storebrain-widget-container { right: 0; left: 0; bottom: 0; width: 100%; }
    #storebrain-chat-container { border-radius: 20px 20px 0 0; height: 75vh; }
}

/* ══════════════════════════════════════════
   PRODUCT TABLE — جدول المنتجات
   ══════════════════════════════════════════ */

.sb-product-table-container {
    width: 100%;
    overflow-x: auto;
    margin-top: 10px;
}

.sb-product-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 12px;
    overflow: hidden;
    font-size: 13px;
}

.sb-product-table thead {
    background: linear-gradient(135deg, #6c47ff 0%, #8b6dff 100%);
    color: #fff;
}

.sb-product-table thead th {
    padding: 12px 10px;
    text-align: right;
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}

.sb-product-table tbody tr {
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s;
}

.sb-product-table tbody tr:hover {
    background: #f8f9ff;
}

.sb-product-table tbody tr:last-child {
    border-bottom: none;
}

.sb-product-table tbody td {
    padding: 12px 10px;
    vertical-align: middle;
}

.sb-table-product-name {
    font-weight: 600;
    color: var(--text);
    font-size: 13px;
    line-height: 1.4;
}

.sb-table-product-price {
    font-weight: 700;
    color: var(--accent);
    font-size: 14px;
    font-family: 'Syne', sans-serif;
}

.sb-table-stock {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.sb-table-stock.in-stock {
    background: #dcfce7;
    color: #16a34a;
}

.sb-table-stock.out-stock {
    background: #fee2e2;
    color: #dc2626;
}

.sb-table-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.sb-btn-cart,
.sb-btn-view {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    white-space: nowrap;
}

.sb-btn-cart {
    background: linear-gradient(135deg, #6c47ff 0%, #8b6dff 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(108, 71, 255, 0.25);
}

.sb-btn-cart:hover {
    background: linear-gradient(135deg, #7c5cff 0%, #9c7dff 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(108, 71, 255, 0.35);
}

.sb-btn-cart:active {
    transform: translateY(0);
}

.sb-btn-cart.added {
    background: linear-gradient(135deg, #16a34a 0%, #22c55e 100%);
}

.sb-btn-cart:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.sb-btn-view {
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--border);
}

.sb-btn-view:hover {
    background: var(--surface-2);
    border-color: var(--accent);
}

/* Responsive table for mobile */
@media (max-width: 480px) {
    .sb-product-table {
        font-size: 12px;
    }

    .sb-product-table thead th,
    .sb-product-table tbody td {
        padding: 8px 6px;
    }

    .sb-table-product-name {
        font-size: 12px;
    }

    .sb-table-product-price {
        font-size: 13px;
    }

    .sb-btn-cart,
    .sb-btn-view {
        padding: 5px 8px;
        font-size: 11px;
    }
}

/* ══════════════════════════════════════════
   PROACTIVE MESSAGES — رسائل استباقية
   ══════════════════════════════════════════ */

#sb-proactive-bubble {
    position: fixed;
    bottom: 92px;
    right: 24px;
    max-width: 260px;
    background: #ffffff;
    border-radius: 16px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 8px 30px rgba(108, 71, 255, 0.18), 0 2px 8px rgba(0,0,0,0.08);
    border: 1.5px solid rgba(108, 71, 255, 0.12);
    padding: 14px 36px 14px 16px;
    z-index: 9997;
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px) scale(0.95);
    transition: opacity 0.3s cubic-bezier(.34,1.56,.64,1),
                transform 0.3s cubic-bezier(.34,1.56,.64,1);
    font-family: 'DM Sans', sans-serif;
}

#sb-proactive-bubble.sb-proactive-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

#sb-proactive-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 20px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 0px solid transparent;
    border-top: 8px solid #ffffff;
    filter: drop-shadow(0 2px 2px rgba(108,71,255,0.1));
}

.sb-proactive-content {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.sb-proactive-text {
    font-size: 13.5px;
    font-weight: 600;
    color: #0a0a0a;
    margin: 0;
    line-height: 1.4;
}

.sb-proactive-sub {
    font-size: 11.5px;
    color: #6b7280;
    margin: 0;
    line-height: 1.3;
}

.sb-proactive-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 18px;
    cursor: pointer;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
    padding: 0;
}

.sb-proactive-close:hover {
    background: #f3f4f6;
    color: #374151;
}

/* نبضة على الـ floating button عند وجود رسالة */
#storebrain-floating-button.has-notification {
    animation: btnPulse 2s ease-in-out infinite;
}

@keyframes btnPulse {
    0%, 100% { box-shadow: 0 8px 30px rgba(108, 71, 255, 0.45); }
    50%       { box-shadow: 0 8px 40px rgba(108, 71, 255, 0.7), 0 0 0 8px rgba(108,71,255,0.1); }
}

@media (max-width: 480px) {
    #sb-proactive-bubble {
        right: 12px;
        bottom: 86px;
        max-width: calc(100vw - 90px);
    }
}