/* ===========================================
   TENSI+ CHAT WIDGET - ESTILOS
   Diseño por Bruno Ramon - AutoNex
   =========================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&display=swap');

:root {
    --bg-white: #FFFFFF;
    --bg-light: #F5F5F5;
    --bg-input: #F9F9F9;
    --text-dark: #1A1A1A;
    --text-body: #374151;
    --text-muted: #6B7280;
    --text-light: #9CA3AF;
    --border: #E8E8E8;
    --border-light: #F0F0F0;
    --tensi-blue: #189CD9;
    --tensi-blue-light: rgba(24, 156, 217, 0.15);
    --user-bubble: #F0F0F0;
    --send-btn-bg: #E8E8E8;
    --send-btn-icon: #6B7280;
}

/* Contenedor del trigger con bocadillo */
.chat-trigger-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Bocadillo de bienvenida */
.chat-bubble-message {
    background: var(--bg-white);
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    max-width: 240px;
    opacity: 1;
    transform: translateY(0);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-bubble-message p {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
    line-height: 1.4;
    margin: 0;
}

.chat-bubble-message.hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

/* Botón flotante del chat */
.chat-trigger {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tensi-blue);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(24, 156, 217, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    position: relative;
}

.chat-trigger:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px rgba(24, 156, 217, 0.45);
}

.chat-trigger svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Anillo de pulso sutil */
.chat-trigger::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -4px;
    right: -4px;
    bottom: -4px;
    border-radius: 50%;
    border: 2px solid var(--tensi-blue);
    opacity: 0;
    animation: gentlePulse 3s ease-in-out infinite;
}

@keyframes gentlePulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.4;
    }
}

.chat-trigger.no-pulse::before {
    animation: none;
    opacity: 0;
}

/* Contenedor principal del chat */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--bg-white);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1),
                0 8px 25px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100000;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

.chat-widget.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header del chat */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light);
}

.chat-header-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-clear,
.chat-minimize {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.chat-clear:hover,
.chat-minimize:hover {
    background: var(--bg-light);
}

.chat-clear svg,
.chat-minimize svg {
    width: 18px;
    height: 18px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-minimize svg {
    width: 20px;
    height: 20px;
}

/* Contenido del chat */
.chat-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px 32px;
    display: flex;
    flex-direction: column;
}

.chat-content.no-scroll {
    overflow: hidden;
}

/* Pantalla de bienvenida */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding-top: 16px;
}

/* Logo Tensi+ */
.chat-logo {
    width: 56px;
    height: 70px;
    margin-bottom: 20px;
    animation: floatIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-logo svg {
    width: 100%;
    height: 100%;
}

@keyframes floatIn {
    from {
        opacity: 0;
        transform: translateY(-15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-greeting {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 0 6px 0;
    animation: fadeUp 0.5s ease 0.1s both;
}

.chat-subtitle {
    font-size: 15px;
    color: var(--text-muted);
    margin: 0 0 32px 0;
    animation: fadeUp 0.5s ease 0.2s both;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Opciones rápidas */
.quick-options {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.quick-option {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 0;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
    border-top: 1px solid var(--border-light);
    transition: all 0.2s ease;
    animation: fadeUp 0.5s ease calc(0.3s + var(--delay, 0s)) both;
}

.quick-option:last-child {
    border-bottom: 1px solid var(--border-light);
}

.quick-option:hover {
    background: var(--bg-light);
    margin: 0 -24px;
    padding-left: 24px;
    padding-right: 24px;
}

.quick-option-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quick-option-icon svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-dark);
    stroke-width: 2.5;
    fill: none;
}

.quick-option-text {
    flex: 1;
    font-size: 15px;
    font-weight: 400;
    color: var(--text-dark);
}

/* Mensajes del chat */
.chat-messages {
    display: none;
    flex-direction: column;
    gap: 16px;
}

.chat-messages.active {
    display: flex;
}

.chat-welcome.hidden {
    display: none;
}

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: var(--text-dark);
    border-bottom-right-radius: 6px;
}

.message.bot {
    align-self: flex-start;
    background: var(--tensi-blue-light);
    color: var(--text-body);
    border-bottom-left-radius: 6px;
}

/* Indicador de escritura */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--tensi-blue);
    opacity: 0.6;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* Footer con input */
.chat-footer {
    padding: 16px 20px 20px;
    background: var(--bg-white);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-input);
    border-radius: 24px;
    padding: 6px 6px 6px 20px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    min-height: 54px;
}

.chat-input-wrapper:focus-within {
    border-color: #D1D5DB;
    background: var(--bg-white);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.03);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-dark);
    outline: none;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    line-height: 1.5;
    padding: 11px 0;
    overflow-y: hidden;
}

.chat-input::placeholder {
    color: var(--text-light);
}

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* Botón enviar */
.chat-send {
    width: 42px;
    height: 42px;
    border: none;
    background: var(--send-btn-bg);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send:hover {
    background: #DCDCDC;
}

.chat-send:active {
    transform: scale(0.95);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send svg {
    width: 20px;
    height: 20px;
    stroke: var(--send-btn-icon);
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chat-disclaimer {
    text-align: center;
    font-size: 12px;
    color: var(--text-light);
    margin: 12px 0 0 0;
}

/* Cards de producto */
.tensi-product-card {
    background: var(--bg-white);
    border-radius: 12px;
    padding: 14px;
    margin-top: 10px;
    display: flex;
    gap: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-light);
    transition: all 0.2s ease;
    align-items: flex-start;
    overflow: hidden;
}

.tensi-product-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.tensi-product-image {
    width: 70px;
    height: 70px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-light);
    flex-shrink: 0;
}

.tensi-product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-width: 0;
    min-height: 70px;
}

.tensi-product-name {
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 0 8px 0;
    font-size: 13px;
    line-height: 1.35;
    word-wrap: break-word;
}

.tensi-product-price-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    margin-top: auto;
    flex-wrap: wrap;
}

.tensi-product-price {
    color: var(--tensi-blue);
    font-weight: 700;
    font-size: 14px;
    margin: 0;
}

.tensi-product-link {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s;
    flex-shrink: 0;
}

.tensi-product-link:hover {
    background: var(--tensi-blue);
    border-color: var(--tensi-blue);
}

.tensi-product-link svg {
    width: 14px;
    height: 14px;
    fill: var(--text-muted);
}

.tensi-product-link:hover svg {
    fill: white;
}

/* Acciones del producto (botones) */
.tensi-product-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

/* Botón añadir al carrito */
.tensi-add-to-cart {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 5px 8px;
    background: var(--tensi-blue);
    color: white;
    border: none;
    border-radius: 5px;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    height: 26px;
}

.tensi-add-to-cart:hover {
    background: #1589c0;
    transform: scale(1.02);
}

.tensi-add-to-cart:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.tensi-add-to-cart.loading {
    pointer-events: none;
}

.tensi-add-to-cart svg {
    width: 12px;
    height: 12px;
    fill: white;
}

/* Upselling message */
.upselling-message {
    padding: 16px !important;
}

.upselling-title {
    font-weight: 600;
    color: var(--text-dark);
    margin: 0 0 12px 0;
    font-size: 14px;
}

/* Grid de productos upselling */
.tensi-upsell-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.tensi-upsell-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-white);
    border-radius: 10px;
    border: 1px solid var(--border-light);
}

.tensi-upsell-image {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    background: var(--bg-light);
    flex-shrink: 0;
}

.tensi-upsell-info {
    flex: 1;
    min-width: 0;
}

.tensi-upsell-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dark);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tensi-upsell-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--tensi-blue);
    margin: 2px 0 0 0;
}

.tensi-upsell-add {
    padding: 6px 10px;
    background: var(--bg-light);
    color: var(--text-dark);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.tensi-upsell-add:hover {
    background: var(--tensi-blue);
    color: white;
    border-color: var(--tensi-blue);
}

.tensi-upsell-add:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.tensi-upsell-add.added {
    background: #10B981;
    color: white;
    border-color: #10B981;
}

/* Enlace ver carrito */
.tensi-view-cart {
    display: inline-block;
    padding: 10px 16px;
    background: var(--text-dark);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    text-align: center;
}

.tensi-view-cart:hover {
    background: #333;
    transform: translateY(-1px);
}

/* Scrollbar personalizada */
.chat-content::-webkit-scrollbar {
    width: 5px;
}

.chat-content::-webkit-scrollbar-track {
    background: transparent;
}

.chat-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.chat-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

/* Responsive */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .chat-widget.open {
        border-radius: 0;
    }

    .chat-trigger-container {
        bottom: 16px;
        right: 16px;
    }

    .chat-trigger {
        width: 56px;
        height: 56px;
    }

    .chat-bubble-message {
        max-width: 200px;
    }

    .chat-content {
        padding: 20px 20px 32px;
    }

    .chat-logo {
        width: 48px;
        height: 60px;
    }

    .chat-greeting {
        font-size: 20px;
    }

    .quick-option:hover {
        margin: 0 -20px;
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* Enlaces PDF en mensajes */
.tensi-pdf-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--tensi-blue);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    margin-top: 8px;
}

.tensi-pdf-link:hover {
    background: #1589c0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(24, 156, 217, 0.3);
}

.tensi-pdf-link svg {
    flex-shrink: 0;
}

/* Enlaces de texto normales en mensajes */
.tensi-text-link {
    color: var(--tensi-blue);
    text-decoration: underline;
    word-break: break-all;
}

.tensi-text-link:hover {
    color: #1589c0;
}
