/* ========================================
   BeautyExpert Widget — BeautyTheShop
   Posición: bottom-right (estándar UX ecommerce)
   iOS/Safari: evitar ancho en vw sobre el viewport completo + zoom si el input < 16px.
   ======================================== */

.cb-toggle,
.cb-panel {
    box-sizing: border-box;
}

/* Botón flotante */
.cb-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(26, 26, 46, 0.4);
    z-index: 10001;
    font-size: 26px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    outline: none;
}
.cb-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(26, 26, 46, 0.55);
}
.cb-toggle .cb-icon-close { display: none; }
.cb-toggle.cb-open .cb-icon-chat { display: none; }
.cb-toggle.cb-open .cb-icon-close { display: inline; }
.cb-toggle .cb-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #e74c3c;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    line-height: 20px;
    text-align: center;
    font-weight: 700;
    display: none;
}

/* Panel de chat */
.cb-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 400px;
    max-width: calc(100% - 48px);
    max-height: 560px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
    z-index: 10000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}
.cb-panel.cb-visible {
    display: flex;
    animation: cbSlideUp 0.25s ease-out;
}
@keyframes cbSlideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Header */
.cb-header {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.cb-header-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #1a1a2e;
    font-size: 18px;
    flex-shrink: 0;
}
.cb-header-info {
    flex: 1;
    min-width: 0;
}
.cb-header-title {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cb-header-subtitle {
    font-size: 11px;
    opacity: 0.75;
    margin-top: 1px;
}
.cb-header-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ecc71;
    margin-right: 4px;
    vertical-align: middle;
}
.cb-header-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.15s;
    line-height: 1;
}
.cb-header-close:hover { color: #fff; }

/* Mensajes */
.cb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    max-height: 340px;
    min-height: 200px;
    background: #f8f9fc;
}
.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* Burbujas de sugerencias */
.cb-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.cb-suggestion {
    background: #fff;
    border: 1.5px solid #e0e3eb;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 12.5px;
    color: #1a1a2e;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.3;
}
.cb-suggestion:hover {
    background: #1a1a2e;
    color: #fff;
    border-color: #1a1a2e;
}

/* Mensaje individual */
.cb-msg {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
}
.cb-msg-user {
    align-items: flex-end;
}
.cb-msg-assistant {
    align-items: flex-start;
}
.cb-msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    word-wrap: break-word;
    font-size: 13.5px;
    line-height: 1.5;
}
.cb-msg-user .cb-msg-bubble {
    background: #1a1a2e;
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}
.cb-msg-assistant .cb-msg-bubble {
    background: #fff;
    color: #2c2c2c;
    border-radius: 16px 16px 16px 4px;
    border: 1px solid #e8e8ee;
}
.cb-msg-assistant .cb-msg-bubble a {
    color: #1a1a2e !important;
    font-weight: 600;
    text-decoration: underline !important;
}
.cb-msg-assistant .cb-msg-bubble a:hover {
    color: #2d2d5e !important;
}
.cb-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 3px;
    padding: 0 4px;
}

/* Productos */
.cb-products-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.cb-product-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 10px;
    background: #fff;
    transition: box-shadow 0.15s;
}
.cb-product-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.cb-product-img {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: 6px;
    background: #f5f5f5;
    flex-shrink: 0;
}
.cb-product-info {
    flex: 1;
    min-width: 0;
}
.cb-product-brand {
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
}
.cb-product-name {
    font-size: 12px;
    font-weight: 600;
    color: #1a1a2e;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}
.cb-product-price {
    font-size: 13px;
    font-weight: 700;
    color: #1a1a2e;
    display: block;
    margin-top: 2px;
}
.cb-product-price-old {
    font-size: 11px;
    color: #999;
    text-decoration: line-through;
    margin-left: 6px;
    font-weight: 400;
}
.cb-product-btn {
    display: inline-block;
    padding: 5px 10px;
    font-size: 11px;
    background: #fff !important;
    color: #1a1a2e !important;
    border: 1.5px solid #1a1a2e !important;
    border-radius: 6px;
    text-decoration: none !important;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s;
}
.cb-product-btn:hover,
.cb-product-btn:visited,
.cb-product-btn:active,
.cb-product-btn:focus {
    background: #f0f0f5 !important;
    color: #1a1a2e !important;
    text-decoration: none !important;
    border-color: #1a1a2e !important;
}

/* Tracking card */
.cb-tracking-card {
    border: 1px solid #e0e3eb;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 8px;
    background: #fff;
}
.cb-tracking-header {
    background: #f0f2f8;
    padding: 10px 14px;
    font-weight: 700;
    font-size: 13px;
    border-bottom: 1px solid #e0e3eb;
    color: #1a1a2e;
}
.cb-tracking-body { padding: 10px 14px; }
.cb-tracking-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 12.5px;
}
.cb-tracking-row .cb-label { color: #666; }
.cb-tracking-row .cb-value { font-weight: 600; color: #1a1a2e; }
.cb-tracking-btn {
    display: block;
    text-align: center;
    margin: 8px 14px 14px;
    padding: 8px;
    background: #fff !important;
    color: #1a1a2e !important;
    border: 2px solid #1a1a2e !important;
    border-radius: 8px;
    text-decoration: none !important;
    font-size: 12.5px;
    font-weight: 600;
    transition: all 0.15s;
}
.cb-tracking-btn:hover,
.cb-tracking-btn:visited,
.cb-tracking-btn:active,
.cb-tracking-btn:focus {
    background: #f0f0f5 !important;
    color: #1a1a2e !important;
    text-decoration: none !important;
    border-color: #1a1a2e !important;
}

/* Typing indicator */
.cb-typing {
    padding: 6px 16px 10px;
    display: none;
    align-items: center;
    gap: 3px;
    background: #f8f9fc;
}
.cb-typing.cb-visible { display: flex; }
.cb-typing-dot {
    width: 7px;
    height: 7px;
    background: #b0b3be;
    border-radius: 50%;
    animation: cbBounce 1.4s infinite;
}
.cb-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.cb-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cbBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-5px); }
}

/* Input area */
.cb-input-area {
    padding: 12px 14px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    background: #fff;
    flex-shrink: 0;
}
.cb-input {
    flex: 1;
    border: 1.5px solid #e0e3eb;
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 13.5px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s;
    background: #f8f9fc;
}
.cb-input:focus {
    border-color: #1a1a2e;
    background: #fff;
}
.cb-input::placeholder { color: #aaa; }
.cb-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #1a1a2e;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}
.cb-send:hover { background: #2d2d5e; }
.cb-send:active { transform: scale(0.95); }
.cb-send:disabled { background: #ccc; cursor: not-allowed; }
.cb-toggle,
.cb-send {
    touch-action: manipulation;
}

/* Powered by */
.cb-powered {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: #bbb;
    background: #fff;
    border-top: 1px solid #f0f0f0;
}

/* Evita scroll horizontal del documento cuando el teclado iOS redimensiona el layout */
html.cb-widget-open,
html.cb-widget-open body {
    overflow: hidden;
    overscroll-behavior: none;
}

/* Agent join notification */
.cb-agent-join {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
    padding: 0 12px;
}
.cb-agent-join-line {
    flex: 1;
    height: 1px;
    background: #d5d5d5;
}
.cb-agent-join-text {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
    font-weight: 500;
    background: #f0f7ff;
    padding: 3px 10px;
    border-radius: 10px;
    border: 1px solid #d0e3f7;
}

/* Agent messages */
.cb-msg-agent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    padding: 0 12px;
}
.cb-agent-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e8f0fe;
    border: 1.5px solid #4a90d9;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 14px;
}
.cb-agent-content {
    max-width: calc(100% - 44px);
}
.cb-agent-name {
    display: block;
    font-size: 10px;
    font-weight: 600;
    color: #4a90d9;
    margin-bottom: 2px;
    padding-left: 4px;
}
.cb-msg-agent .cb-msg-bubble {
    background: #e8f0fe !important;
    color: #1a1a2e;
    border: 1px solid #d0e3f7;
    border-radius: 2px 12px 12px 12px;
    padding: 8px 14px;
    font-size: 13px;
    line-height: 1.45;
}
.cb-msg-agent .cb-msg-time {
    display: block;
    font-size: 10px;
    color: #aaa;
    margin-top: 2px;
    padding-left: 4px;
}

/* Mobile: pantalla completa (Safari iOS: vw del layout suele desbordar el ancho útil) */
@media (max-width: 480px) {
    .cb-panel {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        min-height: 100%;
        min-height: -webkit-fill-available;
        min-height: 100dvh;
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        overscroll-behavior: contain;
    }

    .cb-messages {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
    }

    .cb-toggle {
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        right: calc(16px + env(safe-area-inset-right, 0px));
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    /* El FAB con icono X comparte esquina con "enviar": ocultar si el panel ya tiene cierre en cabecera */
    .cb-toggle.cb-open {
        display: none;
    }

    .cb-input {
        font-size: 16px;
    }
}
