/* /sema-chat/assets/css/chat-widget.css */
/* 🔥 VERSIÓN FINAL - FUNCIONAL EN MÓVIL Y ESCRITORIO */

/* =============================================
   CONTENEDOR PRINCIPAL
============================================= */
#sema-chat-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* =============================================
   POSICIÓN DEL WIDGET
============================================= */
#sema-chat-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

#sema-chat-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* =============================================
   TEASER - GLOBO QUE LLAMA LA ATENCIÓN
============================================= */
.chat-teaser {
    position: absolute;
    bottom: 10px;
    max-width: 230px;
    background: white;
    color: #1a1a2e;
    padding: 12px 30px 12px 16px;
    border-radius: 16px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
    font-size: 13px;
    line-height: 1.4;
    cursor: pointer;
    z-index: 9998;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-teaser.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#sema-chat-widget.open .chat-teaser {
    display: none !important;
}

#sema-chat-widget.bottom-right .chat-teaser {
    right: 72px;
}

#sema-chat-widget.bottom-left .chat-teaser {
    left: 72px;
}

.chat-teaser::after {
    content: '';
    position: absolute;
    bottom: 22px;
    width: 0;
    height: 0;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
}

#sema-chat-widget.bottom-right .chat-teaser::after {
    right: -7px;
    border-left: 7px solid white;
}

#sema-chat-widget.bottom-left .chat-teaser::after {
    left: -7px;
    border-right: 7px solid white;
}

.chat-teaser-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 11px;
    cursor: pointer;
    padding: 6px;
    line-height: 1;
}

.chat-teaser-text {
    padding-right: 2px;
}

/* =============================================
   BOTÓN FLOTANTE
============================================= */
.chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--chat-color, #667eea);
    color: white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.chat-toggle:hover {
    transform: scale(1.05);
}

.chat-toggle .close-icon {
    display: none;
}

.chat-toggle.active .chat-icon {
    display: none;
}

.chat-toggle.active .close-icon {
    display: inline;
}

.chat-toggle .chat-icon svg {
    width: 28px;
    height: 28px;
    display: block;
    stroke: white;
}

/* =============================================
   VENTANA DEL CHAT
============================================= */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.chat-window.open {
    display: flex;
}

/* =============================================
   HEADER DEL CHAT
============================================= */
.chat-header {
    padding: 15px 20px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 70px;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    font-size: 24px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-title {
    font-weight: 600;
    font-size: 16px;
}

.chat-status {
    font-size: 12px;
    opacity: 0.9;
}

.chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    min-width: 44px;
    min-height: 44px;
}

/* =============================================
   BARRA DE CARRITO
============================================= */
.chat-cart-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: #f0f4ff;
    border-bottom: 1px solid #e9ecef;
    color: #1a1a2e;
    text-decoration: none;
    font-size: 13px;
    flex-shrink: 0;
}

.chat-cart-bar.visible {
    display: flex;
}

.chat-cart-icon {
    font-size: 15px;
}

.chat-cart-text {
    font-weight: 600;
}

/* =============================================
   MENSAJES
============================================= */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
}

.message {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.message.bot {
    align-items: flex-start;
}

.message.user {
    align-items: flex-end;
    margin-left: auto;
}

.message-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.bot .message-content {
    background: white;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.message.user .message-content {
    background: var(--chat-color, #667eea);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

/* =============================================
   TARJETAS DE PRODUCTO
============================================= */
.product-cards {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    margin: -4px 0 12px;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.product-card {
    flex: 0 0 auto;
    width: 150px;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.product-card-image {
    width: 100%;
    height: 100px;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.product-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.product-card-image .placeholder {
    font-size: 28px;
}

.product-card-body {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.product-card-name {
    font-size: 12px;
    font-weight: 600;
    color: #1a1a2e;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-card-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--chat-color, #667eea);
}

.product-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.product-card-view-btn,
.product-card-add-btn {
    flex: 1;
    border: none;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 4px;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
}

.product-card-view-btn {
    background: #f0f0f5;
    color: #1a1a2e;
}

.product-card-add-btn {
    background: var(--chat-color, #667eea);
    color: white;
}

.product-card-add-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.product-card-add-btn.added {
    background: #25D366;
}

.product-card.out-of-stock .product-card-add-btn {
    display: none;
}

.product-card-stock-note {
    font-size: 10px;
    color: #c0392b;
    font-weight: 600;
}

/* =============================================
   CATEGORÍAS SUGERIDAS
============================================= */
.category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: -4px 0 12px;
}

.category-chip {
    background: #f0f0f5;
    color: #1a1a2e;
    border: none;
    border-radius: 14px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

/* =============================================
   INPUT Y ACCIONES
============================================= */
.chat-input-area {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

#sema-chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e9ecef;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
}

#sema-chat-input:focus {
    border-color: var(--chat-color, #667eea);
}

.chat-send-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 50% !important;
    border: none !important;
    color: white !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    line-height: 0 !important;
}

.chat-send-btn svg {
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    stroke: currentColor !important;
    fill: none !important;
    flex-shrink: 0 !important;
    pointer-events: none !important;
}

.chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-actions {
    padding: 10px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-shrink: 0;
}

.chat-whatsapp-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: #25D366;
    color: white;
    width: 100%;
    max-width: 250px;
}

.chat-footer {
    text-align: center;
    padding: 8px;
    background: #f8f9fa;
    font-size: 11px;
    color: #999;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.chat-footer small {
    font-size: 11px;
    color: #999;
}

.chat-footer small a {
    color: var(--chat-color, #667eea);
    font-weight: 600;
    text-decoration: none;
}

.chat-footer small a:hover {
    text-decoration: underline;
}

/* =============================================
   🔥 MÓVIL - PANTALLA COMPLETA
============================================= */
@media (max-width: 768px) {
    
    /* BOTÓN FLOTANTE - SIEMPRE VISIBLE */
    #sema-chat-widget .chat-toggle {
        display: flex !important;
        position: fixed !important;
        bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(20px + env(safe-area-inset-right, 0px)) !important;
        z-index: 999999998 !important;
        width: 56px !important;
        height: 56px !important;
        font-size: 24px !important;
        background: var(--chat-color, #667eea) !important;
        color: white !important;
        border: none !important;
        border-radius: 50% !important;
        cursor: pointer !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* OCULTAR BOTÓN CUANDO EL CHAT ESTÁ ABIERTO */
    #sema-chat-widget.open .chat-toggle {
        display: none !important;
    }
    
    /* VENTANA DEL CHAT - PANTALLA COMPLETA */
    /* top/left/right/bottom:0 es la base (funciona en todos lados).
       100dvh es una mejora progresiva para navegadores que la soportan,
       evitando el clásico problema de "100vh" con la barra de
       direcciones dinámica de Chrome/Safari mobile. */
    #sema-chat-widget .chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: white !important;
        z-index: 999999999 !important;
        display: none !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }
    
    #sema-chat-widget.open .chat-window {
        display: flex !important;
    }
    
    /* HEADER COMPACTO (+ respeta el notch) */
    .chat-header {
        padding: 12px 16px !important;
        padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
        min-height: 56px !important;
        flex-shrink: 0 !important;
    }
    
    .chat-avatar {
        width: 32px !important;
        height: 32px !important;
        font-size: 16px !important;
    }
    
    .chat-title {
        font-size: 15px !important;
    }
    
    .chat-status {
        font-size: 11px !important;
    }
    
    /* MENSAJES - TODO EL ESPACIO */
    .chat-messages {
        flex: 1 1 auto !important;
        padding: 12px 16px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        background: #f8f9fa !important;
        min-height: 0 !important;
    }
    
    /* INPUT FIJO ABAJO (+ respeta el home indicator en iPhone) */
    .chat-input-area {
        padding: 10px 16px !important;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        flex-shrink: 0 !important;
        background: white !important;
        border-top: 1px solid #e9ecef !important;
    }
    
    #sema-chat-input {
        font-size: 16px !important;
        padding: 10px 14px !important;
        border-radius: 20px !important;
    }
    
    .chat-send-btn {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .chat-send-btn svg {
        width: 18px !important;
        height: 18px !important;
    }
    
    /* WHATSAPP - SIEMPRE VISIBLE */
    .chat-actions {
        padding: 8px 16px !important;
        flex-shrink: 0 !important;
        background: #f8f9fa !important;
        border-top: 1px solid #e9ecef !important;
    }
    
    .chat-whatsapp-btn {
        max-width: 100% !important;
        font-size: 14px !important;
        padding: 10px 16px !important;
        border-radius: 25px !important;
        font-weight: 600 !important;
    }
    
    .chat-footer {
        flex-shrink: 0 !important;
        padding: 4px 0 !important;
        font-size: 10px !important;
        background: #f8f9fa !important;
        border-top: 1px solid #e9ecef !important;
    }
    
    .chat-footer small {
        font-size: 10px !important;
    }
    
    /* TEASER - que no se corte en pantallas chicas */
    .chat-teaser {
        max-width: calc(100vw - 100px) !important;
        font-size: 12px !important;
    }
    
    /* OVERLAY DE ENLACE - respeta el notch en pantalla completa */
    .chat-link-overlay-header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    }
}

/* =============================================
   OVERLAY DE ENLACE - VISTA PREVIA EMBEBIDA
   Evita que el usuario "pierda" el chat al tocar
   un link: el producto se carga adentro del chat
   en vez de navegar afuera.
============================================= */
.chat-link-overlay {
    position: absolute;
    inset: 0;
    background: white;
    display: none;
    flex-direction: column;
    z-index: 20;
}

.chat-link-overlay.open {
    display: flex;
}

.chat-link-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #e9ecef;
    background: white;
    flex-shrink: 0;
}

.chat-link-back {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #1a1a2e;
    padding: 8px 10px;
    border-radius: 8px;
    min-height: 40px;
}

.chat-link-back:hover {
    background: #f8f9fa;
}

.chat-link-external {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #666;
    flex-shrink: 0;
}

.chat-link-external:hover {
    background: #f8f9fa;
}

.chat-link-overlay-body {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #f8f9fa;
}

.chat-link-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: white;
}

.chat-link-loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
}

.chat-link-overlay.loading .chat-link-loading {
    display: flex;
}

.chat-link-overlay.loading .chat-link-iframe {
    visibility: hidden;
}

.chat-link-fallback {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    background: #f8f9fa;
}

.chat-link-fallback p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

.chat-link-fallback-btn {
    display: inline-block;
    padding: 10px 22px;
    border-radius: 20px;
    background: var(--chat-color, #667eea);
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.chat-link-overlay.failed .chat-link-fallback {
    display: flex;
}

.chat-link-overlay.failed .chat-link-iframe {
    display: none;
}

/* =============================================
   SCROLLBAR
============================================= */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 10px;
}

/* =============================================
   TYPING INDICATOR
============================================= */
@keyframes typing {
    0%, 60%, 100% { opacity: 0.2; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1.2); }
}

.typing-dot {
    display: inline-block;
    font-size: 24px;
    margin: 0 2px;
    color: #999;
    animation: typing 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }