/* SellBot Chat Widget — Professional UX/UI */

:root {
    --sb-primary: #0a0a0a;
    --sb-primary-hover: #000000;
    --sb-primary-light: #f4f4f5;
    --sb-secondary: #a1a1aa;
    --sb-bg: #ffffff;
    --sb-bg-chat: #fafafa;
    --sb-text: #0a0a0a;
    --sb-text-muted: #737373;
    --sb-border: #e5e5e5;
    --sb-border-soft: #f0f0f0;
    --sb-radius: 20px;
    --sb-radius-sm: 14px;
    --sb-radius-input: 12px;
    --sb-radius-btn: 10px;
    --sb-radius-pill: 999px;
    --sb-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.06);
    --sb-shadow-fab: 0 14px 32px -10px rgba(0, 0, 0, 0.45);
    --sb-transition: cubic-bezier(0.4, 0, 0.2, 1);
    --sb-font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    --sb-font-display: 'Inter Tight', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --sb-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Reset del contenedor */
.sb-container,
.sb-container * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

.sb-container.sb-position-left {
    right: auto;
    left: 24px;
}

/* ═══════════ FAB (Floating Action Button) ═══════════ */
.sb-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--sb-primary);
    box-shadow: var(--sb-shadow-fab);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.3s var(--sb-transition), box-shadow 0.3s var(--sb-transition);
    outline: none;
}

.sb-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

.sb-fab:active {
    transform: scale(0.95);
}

.sb-fab img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.sb-fab-icon {
    width: 28px;
    height: 28px;
    fill: #fff;
    transition: transform 0.3s var(--sb-transition), opacity 0.3s var(--sb-transition);
}

.sb-fab-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.sb-container.sb-open .sb-fab-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.sb-container.sb-open .sb-fab-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse animation */
.sb-fab::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--sb-primary);
    opacity: 0;
    animation: sb-pulse 3s var(--sb-transition) infinite;
    z-index: -1;
}

.sb-container.sb-open .sb-fab::before {
    animation: none;
}

@keyframes sb-pulse {
    0%, 100% { opacity: 0; transform: scale(1); }
    50% { opacity: 0.15; transform: scale(1.25); }
}

/* Notification badge */
.sb-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    border-radius: 999px;
    border: 2px solid #fff;
    display: none;
}

.sb-fab-badge.sb-show {
    display: block;
    animation: sb-bounce-in 0.4s var(--sb-transition);
}

/* ═══════════ Chat Panel ═══════════ */
.sb-panel {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: min(380px, calc(100vw - 32px));
    max-width: calc(100vw - 32px);
    max-height: 700px;
    height: calc(100vh - 120px);
    background: var(--sb-bg);
    border-radius: var(--sb-radius);
    box-shadow: var(--sb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s var(--sb-transition),
                opacity 0.35s var(--sb-transition);
    transform-origin: bottom right;
    border: 1px solid var(--sb-border-soft);
}

.sb-position-left .sb-panel {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.sb-container.sb-open .sb-panel {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

/* ═══════════ Header ═══════════ */
.sb-header {
    padding: 14px 16px;
    background: var(--sb-header-bg, var(--sb-bg));
    color: var(--sb-text);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--sb-border-soft);
}

.sb-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--sb-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.sb-header-avatar svg {
    fill: #fff;
}

.sb-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sb-header-info {
    flex: 1;
    min-width: 0;
}

.sb-header-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: var(--sb-text);
    font-family: var(--sb-font-display);
    letter-spacing: -0.01em;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.sb-header-title::after {
    content: '';
    width: 7px;
    height: 7px;
    background: #22c55e;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.22);
    flex-shrink: 0;
}

.sb-header-status {
    font-size: 11px;
    color: var(--sb-text-muted);
    margin-top: 2px;
    letter-spacing: -0.005em;
}

.sb-header-close {
    width: 30px;
    height: 30px;
    border: 1px solid var(--sb-border);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    flex-shrink: 0;
    color: var(--sb-text-muted);
}

.sb-header-close:hover {
    background: var(--sb-primary-light);
    color: var(--sb-text);
}

.sb-header-close svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
}

/* ═══════════ Messages Area ═══════════ */
.sb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--sb-bg-chat);
    scroll-behavior: smooth;
}

.sb-messages::-webkit-scrollbar {
    width: 5px;
}

.sb-messages::-webkit-scrollbar-track {
    background: transparent;
}

.sb-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
}

/* Message bubbles */
.sb-message {
    display: flex;
    gap: 8px;
    max-width: 96%;
    animation: sb-slide-up 0.3s var(--sb-transition);
}

.sb-message > div {
    min-width: 0;
}

.sb-message-bot {
    align-self: flex-start;
}

.sb-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.sb-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    margin-top: 4px;
}

.sb-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sb-message-user .sb-message-avatar {
    display: none;
}

.sb-bubble {
    padding: 10px 14px;
    border-radius: var(--sb-radius-sm);
    font-size: 13.5px;
    line-height: 1.5;
    letter-spacing: -0.005em;
    word-break: break-word;
}

.sb-message-bot .sb-bubble {
    background: var(--sb-bot-bubble-bg, var(--sb-bg));
    color: var(--sb-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--sb-border-soft);
}

.sb-message-user .sb-bubble {
    background: var(--sb-user-bubble-bg, var(--sb-primary));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sb-message-user .sb-bubble a {
    color: #fff;
    text-decoration: underline;
}

.sb-bubble ul {
    margin: 6px 0 2px;
    padding-left: 20px;
}
.sb-bubble li { margin: 2px 0; }
.sb-bubble strong { font-weight: 600; }
.sb-bubble em { font-style: italic; }
.sb-bubble code {
    background: rgba(0,0,0,0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
}
.sb-bubble a {
    color: var(--sb-primary);
    text-decoration: underline;
    word-break: break-all;
}

/* ═══════════ Product Cards ═══════════ */
.sb-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0 4px;
    width: 100%;
}

.sb-product-card {
    display: flex;
    flex-direction: row;
    background: var(--sb-bg);
    border-radius: var(--sb-radius-sm);
    overflow: hidden;
    border: 1px solid var(--sb-border);
    transition: transform 0.2s var(--sb-transition), box-shadow 0.2s var(--sb-transition);
    text-decoration: none;
    color: inherit;
    width: 100%;
}

.sb-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sb-product-image {
    width: 72px;
    min-width: 72px;
    height: auto;
    min-height: 72px;
    overflow: hidden;
    background: #f1f5f9;
    position: relative;
}

.sb-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s var(--sb-transition);
}

.sb-product-card:hover .sb-product-image img {
    transform: scale(1.05);
}

.sb-product-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: #ef4444;
    color: #fff;
}

.sb-product-info {
    padding: 8px 10px;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.sb-product-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--sb-text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.sb-product-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--sb-primary);
}

.sb-product-price del {
    color: var(--sb-text-muted);
    font-weight: 400;
    font-size: 12px;
    margin-left: 4px;
}

.sb-product-stock {
    font-size: 11px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.sb-product-stock.sb-instock {
    color: #059669;
}

.sb-product-stock.sb-outofstock {
    color: #dc2626;
}

.sb-product-stock::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.sb-product-link {
    display: none;
}

/* Add to cart button */
.sb-add-to-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--sb-cart-btn-bg, var(--sb-primary));
    border: none;
    border-left: 1px solid var(--sb-border);
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
    min-width: 70px;
    font-family: var(--sb-font);
}

.sb-add-to-cart:hover {
    background: var(--sb-primary-hover);
}

.sb-add-to-cart:disabled {
    opacity: 0.7;
    cursor: wait;
}

.sb-add-to-cart.sb-added {
    background: #059669;
    cursor: default;
}

.sb-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: sb-spin 0.6s linear infinite;
}

@keyframes sb-spin {
    to { transform: rotate(360deg); }
}

/* Variants badge */
.sb-badge-variants {
    background: var(--sb-primary);
    top: auto;
    bottom: 8px;
    font-size: 10px;
}

/* Auto-popup proactivo */
.sb-auto-popup {
    position: absolute;
    bottom: 76px;
    right: 0;
    background: var(--sb-bg);
    color: var(--sb-text);
    padding: 12px 16px;
    border-radius: var(--sb-radius-sm);
    box-shadow: var(--sb-shadow);
    border: 1px solid var(--sb-border-soft);
    font-size: 13px;
    line-height: 1.45;
    width: 260px;
    max-width: calc(100vw - 48px);
    white-space: normal;
    cursor: pointer;
    transform: scale(0.85) translateY(10px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s var(--sb-transition), opacity 0.3s var(--sb-transition);
}

.sb-position-left .sb-auto-popup {
    right: auto;
    left: 0;
}

.sb-auto-popup.sb-show {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
    animation: sb-slide-up 0.3s var(--sb-transition);
}

.sb-auto-popup:hover {
    border-color: var(--sb-primary);
}

/* Product card skeleton loading */
.sb-product-skeleton {
    display: flex;
    flex-direction: row;
    border-radius: var(--sb-radius-sm);
    overflow: hidden;
    border: 1px solid var(--sb-border);
    background: var(--sb-bg);
    width: 100%;
}

.sb-skeleton-image {
    width: 72px;
    min-width: 72px;
    height: 72px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: sb-shimmer 1.5s infinite;
}

.sb-skeleton-text {
    margin: 10px 12px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 200% 100%;
    animation: sb-shimmer 1.5s infinite;
}

.sb-skeleton-text:last-child {
    width: 60%;
    margin-bottom: 12px;
}

@keyframes sb-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══════════ Typing Indicator ═══════════ */
.sb-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 16px;
    background: var(--sb-bg);
    border-radius: var(--sb-radius-sm);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--sb-border-soft);
    gap: 6px;
    align-items: center;
    animation: sb-slide-up 0.3s var(--sb-transition);
    flex-wrap: wrap;
}

.sb-typing.sb-show {
    display: flex;
}

.sb-typing-text {
    font-size: 12px;
    color: var(--sb-text-muted);
    margin-left: 4px;
    transition: opacity 0.2s;
}

.sb-typing-dot {
    width: 7px;
    height: 7px;
    background: var(--sb-secondary);
    border-radius: 50%;
    animation: sb-typing-bounce 1.4s infinite;
}

.sb-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.sb-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes sb-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ═══════════ Suggestion Chips ═══════════ */
.sb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.sb-chip {
    padding: 8px 14px;
    border-radius: var(--sb-radius-pill);
    font-size: 13px;
    font-weight: 500;
    background: var(--sb-bg);
    color: var(--sb-text);
    border: 1px solid var(--sb-border);
    cursor: pointer;
    transition: all 0.2s var(--sb-transition);
    white-space: nowrap;
    line-height: 1.3;
    font-family: var(--sb-font);
}

.sb-chip:hover {
    background: var(--sb-primary-light);
    border-color: #d4d4d8;
    transform: translateY(-1px);
}

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

/* ═══════════ Input Area ═══════════ */
.sb-input-area {
    padding: 10px 12px 12px;
    background: var(--sb-footer-bg, var(--sb-bg));
    border-top: 1px solid var(--sb-border-soft);
    flex-shrink: 0;
}

.sb-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    background: var(--sb-bg-chat);
    border: 1px solid var(--sb-border);
    border-radius: var(--sb-radius-input);
    padding: 4px 4px 4px 14px;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.sb-input-wrap:focus-within {
    border-color: var(--sb-text-muted);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.04);
}

.sb-input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 8px 0;
    font-size: 13.5px;
    font-family: var(--sb-font);
    color: var(--sb-text);
    resize: none;
    max-height: 100px;
    min-height: 22px;
    line-height: 1.5;
    letter-spacing: -0.005em;
    outline: none;
}

.sb-input::placeholder {
    color: var(--sb-text-muted);
}

.sb-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--sb-send-btn-bg, var(--sb-primary));
    border-radius: var(--sb-radius-btn);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
    align-self: flex-end;
    color: #fff;
}

.sb-send-btn:hover {
    background: var(--sb-primary-hover);
    transform: scale(1.05);
}

.sb-send-btn:active {
    transform: scale(0.95);
}

.sb-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.sb-send-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ═══════════ Powered by ═══════════ */
.sb-powered {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: var(--sb-text-muted);
    background: var(--sb-footer-bg, var(--sb-bg));
    border-top: 1px solid var(--sb-border-soft);
    flex-shrink: 0;
}

.sb-powered a {
    color: inherit;
    text-decoration: underline;
}

.sb-powered a:hover {
    color: var(--sb-primary);
}

/* ═══════════ Error message ═══════════ */
.sb-error {
    padding: 8px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 13px;
    text-align: center;
}

/* ═══════════ Animations ═══════════ */
@keyframes sb-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sb-bounce-in {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ═══════════ Mobile Responsive ═══════════ */
@media (max-width: 600px) {
    .sb-container {
        bottom: 16px;
        right: 16px;
    }

    .sb-container.sb-position-left {
        left: 16px;
    }

    /* Anclar el panel al viewport para evitar que se salga de pantalla
       sumando offsets del contenedor. */
    .sb-panel {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 88px;
        top: 12px;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        transform-origin: bottom right;
    }

    .sb-position-left .sb-panel {
        transform-origin: bottom left;
    }

    .sb-fab {
        width: 54px;
        height: 54px;
    }

    .sb-auto-popup {
        max-width: calc(100vw - 48px);
    }

    .sb-message {
        max-width: 97%;
    }
}


/* ═══════════ Contact fallback buttons ═══════════ */

.sb-fallback-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.sb-fallback-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--sb-radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--sb-font);
    text-decoration: none;
    transition: opacity 0.2s var(--sb-transition), transform 0.15s var(--sb-transition);
    cursor: pointer;
    line-height: 1.2;
}

.sb-fallback-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
}

.sb-fallback-btn svg {
    flex-shrink: 0;
}

.sb-fallback-wa {
    background: #25d366;
    color: #fff;
}

.sb-fallback-mail {
    background: var(--sb-primary);
    color: #fff;
}

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