/* ======================================================
   assets/css/pages/chatbot-widget.css
   CHATBOT WIDGET PÚBLICO — C4 SYSTEM
   ======================================================

   RESPONSABILIDAD:
   - Estilos visuales del chatbot público
   - Botón flotante
   - Panel de conversación
   - Header premium con avatar técnico
   - Mensajes usuario / bot / sistema
   - Typing animation
   - Opciones dinámicas
   - Input de texto
   - Resumen visual final
   - Botones finales WhatsApp / reiniciar
   - Responsive móvil

   IMPORTANTE:
   - Compatible con el chatbot.js mejorado
   - Mantiene compatibilidad con clases antiguas
   - No depende de librerías externas
   - Pensado para estética tech/profesional C4 SYSTEM
====================================================== */


/* ======================================================
   VARIABLES LOCALES DEL WIDGET
====================================================== */

.c4-chatbot-root {
    --c4-chat-primary: #2563eb;
    --c4-chat-primary-dark: #1d4ed8;
    --c4-chat-primary-soft: rgba(37, 99, 235, .12);

    --c4-chat-dark: #0f172a;
    --c4-chat-dark-2: #111827;

    --c4-chat-text: #111827;
    --c4-chat-muted: #6b7280;
    --c4-chat-border: rgba(15, 23, 42, .12);

    --c4-chat-bg: #f8fafc;
    --c4-chat-white: #ffffff;

    --c4-chat-success: #16a34a;
    --c4-chat-success-dark: #15803d;

    --c4-chat-radius-panel: 24px;
    --c4-chat-radius-bubble: 17px;

    --c4-chat-shadow-panel: 0 28px 80px rgba(15, 23, 42, .34);
    --c4-chat-shadow-soft: 0 12px 35px rgba(15, 23, 42, .14);
    --c4-chat-shadow-bubble: 0 5px 16px rgba(15, 23, 42, .08);

    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 9999;
    font-family: inherit;
}


/* ======================================================
   BOTÓN FLOTANTE (ESTILO WHATSAPP PREMIUM)
====================================================== */

.c4-chatbot-toggle {
    position: relative;
    width: 60px; /* Ajustado a un tamaño estándar perfecto */
    height: 60px;
    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: none;
    border-radius: 50%; /* Asegura una esfera perfecta */
    padding: 0;

    background: #25D366;
    color: #ffffff;

    cursor: pointer;

    /* Sombra suave y realista idéntica a la muestra */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 
                0 12px 24px rgba(37, 211, 102, 0.25);

    transition:
        transform .2s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow .2s ease,
        filter .2s ease;
}

.c4-chatbot-toggle:hover {
    transform: scale(1.05) translateY(-2px); /* Un ligero escalado premium */
    filter: brightness(1.03);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18), 
                0 16px 32px rgba(37, 211, 102, 0.35);
}

.c4-chatbot-toggle:active {
    transform: scale(0.98) translateY(0);
}

/* Contenedor del Icono SVG */
.c4-chatbot-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    line-height: 1;
    z-index: 2;
}

.c4-chatbot-toggle-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.c4-chatbot-toggle-text {
    display: none;
}

/* El pulso verde de notificación lo movemos a la esquina superior derecha */
.c4-chatbot-toggle-pulse {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ef4444; /* Cambiado a rojo técnico de alerta para que resalte sobre el verde */
    border: 2px solid #25D366; /* Match con el fondo */
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: c4ChatPulse 2s infinite;
    z-index: 3;
}


/* ======================================================
   PANEL PRINCIPAL
====================================================== */
.c4-chatbot-panel {
    position: absolute;
    right: 0;
    bottom: 72px;

    width: 355px;
    max-width: calc(100vw - 32px);

    height: 520px;
    max-height: calc(100vh - 90px);

    display: none;
    flex-direction: column;

    overflow: hidden;

    padding: 0 !important;
    margin: 0 !important;
    gap: 0;

    box-sizing: border-box;

    background: #f8fafc;

    border-radius: var(--c4-chat-radius-panel);

    border: 1px solid var(--c4-chat-border);

    box-shadow: var(--c4-chat-shadow-panel);

    transform-origin: bottom right;
}

.c4-chatbot-root.is-open .c4-chatbot-panel {
    display: flex;
    animation: c4ChatPanelIn .22s ease-out both;
}

/* ======================================================
   HEADER PREMIUM
====================================================== */

/* ======================================================
   HEADER ESTILO WHATSAPP REALISTA
====================================================== */

.c4-chatbot-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;

    padding: 12px 16px; /* Un poco más compacto */

    margin: 0;
    border-radius: 0;

    /* Cambiado al verde corporativo de WhatsApp Web */
    background: #008069; 
    color: #ffffff;

    overflow: hidden;
    flex-shrink: 0;
}

/* Quitamos el círculo decorativo de fondo azul para máxima fidelidad */
.c4-chatbot-header::after {
    display: none;
}

.c4-chatbot-header::after {
    content: "";
    position: absolute;
    inset: auto -40px -60px auto;
    width: 160px;
    height: 160px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    pointer-events: none;
}

.c4-chatbot-header-agent {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* ======================================================
   AVATARES INTEGRADOS CON LA ESTÉTICA VERDE
====================================================== */

.c4-chatbot-header-avatar,
.c4-chatbot-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 50%;
    color: #ffffff;
    
    /* Cambiado de degradado azul a un verde sólido que destaca */
    background: #128c7e; 
    
    /* Ajustamos la sombra para que sea más limpia */
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.c4-chatbot-header-avatar {
    width: 40px;
    height: 40px;
}

.c4-chatbot-avatar {
    width: 32px;
    height: 32px;
    margin-top: 2px;
}

/* Forzamos que si hay SVGs internos dentro de los avatares se escalen bien */
.c4-chatbot-header-avatar svg,
.c4-chatbot-avatar svg {
    width: 55%;
    height: 55%;
    fill: currentColor;
}

.c4-chatbot-header strong {
    display: block;
    font-size: 15px;
    line-height: 1.15;
    letter-spacing: .01em;
}

.c4-chatbot-header span {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    opacity: .88;
}

.c4-chatbot-status {
    display: inline-flex !important;
    align-items: center;
    gap: 6px;
    line-height: 1.25;
}

.c4-chatbot-status i {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .16);
}

.c4-chatbot-header .c4-chatbot-location {
    display: block;
    margin-top: 5px;
    padding: 3px 7px;
    border: 1px solid rgba(255, 255, 255, .38);
    border-radius: 999px;
    background: rgba(255, 255, 255, .14);
    color: #ffffff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1.2;
    opacity: 1;
    white-space: nowrap;
}

.c4-chatbot-close {
    position: relative;
    z-index: 3;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: #ffffff;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
    transition:
        background .16s ease,
        transform .16s ease;
}

.c4-chatbot-close:hover {
    background: rgba(255,255,255,.25);
    transform: rotate(4deg);
}


/* ======================================================
   BODY / ÁREA DE MENSAJES
====================================================== */

/* ======================================================
   BODY / ÁREA DE MENSAJES
====================================================== */

.c4-chatbot-body {
    flex: 1;
    min-height: 0;
    padding: 16px 14px;
    overflow-y: auto;
    
    /* El emblemático fondo beige texturizado de WhatsApp */
    background-color: #efeae2;
    /* Opcional: Si quieres añadir el patrón de WhatsApp, descomenta la línea de abajo:
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: auto;
    opacity: 0.99; */

    scroll-behavior: smooth;
}

.c4-chatbot-body::-webkit-scrollbar {
    width: 8px;
}

.c4-chatbot-body::-webkit-scrollbar-track {
    background: transparent;
}

.c4-chatbot-body::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, .35);
    border-radius: 999px;
}

.c4-chatbot-body::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, .52);
}


/* ======================================================
   MENSAJES
====================================================== */

.c4-chatbot-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 13px;
    animation: c4ChatMessageIn .22s ease-out both;
}



.c4-chatbot-msg-bot {
    justify-content: flex-start;
}

.c4-chatbot-msg-user {
    justify-content: flex-end;
}

.c4-chatbot-msg-system {
    justify-content: center;
}

.c4-chatbot-msg-content {
    max-width: 82%;
    display: flex;
    flex-direction: column;
}

.c4-chatbot-msg-user .c4-chatbot-msg-content {
    align-items: flex-end;
}

.c4-chatbot-msg-bot .c4-chatbot-msg-content {
    align-items: flex-start;
}

.c4-chatbot-msg-system .c4-chatbot-msg-content {
    max-width: 92%;
    align-items: center;
}

/* ======================================================
   BURBUJAS DE MENSAJE REALISTAS
====================================================== */

.c4-chatbot-bubble {
    padding: 8px 12px;
    border-radius: 8px; /* WhatsApp usa esquinas menos redondeadas en los mensajes */
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 1px 0.5px rgba(11,20,26,.13); /* Sombra sutil de mensaje */
    word-break: break-word;
    white-space: pre-wrap;
}

/* Burbuja del Bot (Mensaje Recibido - Blanco) */
.c4-chatbot-msg-bot .c4-chatbot-bubble {
    background: #ffffff;
    color: #111b21; /* Texto casi negro de WhatsApp */
    border: none;
    border-top-left-radius: 0px; /* Simula la esquina de mensaje de WhatsApp */
}

/* Burbuja del Usuario (Mensaje Enviado - Verde Claro) */
.c4-chatbot-msg-user .c4-chatbot-bubble {
    background: #d9fdd3; 
    color: #111b21;
    border: none;
    border-top-right-radius: 0px; /* Simula la esquina de mensaje de WhatsApp */
}

/* Meta datos (Hora del mensaje) */
.c4-chatbot-msg-meta {
    margin-top: 2px;
    font-size: 11px;
    color: #667781; /* Color gris de WhatsApp */
    text-align: right; /* WhatsApp alinea la hora a la derecha dentro/debajo */
}

.c4-chatbot-msg-system .c4-chatbot-bubble {
    background: rgba(15, 23, 42, .06);
    color: #475569;
    border: 1px solid rgba(15, 23, 42, .06);
    text-align: center;
    font-size: 12.5px;
    box-shadow: none;
}



.c4-chatbot-msg-user .c4-chatbot-msg-meta {
    padding-right: 4px;
}

.c4-chatbot-msg-bot .c4-chatbot-msg-meta {
    padding-left: 4px;
}


/* ======================================================
   TYPING INDICATOR
====================================================== */

.c4-chatbot-typing-row {
    align-items: flex-start;
}

.c4-chatbot-typing {
    min-width: 148px;
}

.c4-chatbot-typing-label {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 8px;
}

.c4-chatbot-typing-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.c4-chatbot-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2563eb;
    animation: c4TypingBounce 1.4s infinite ease-in-out;
}

.c4-chatbot-typing-dots span:nth-child(2) {
    animation-delay: .2s;
}

.c4-chatbot-typing-dots span:nth-child(3) {
    animation-delay: .4s;
}


/* ======================================================
   OPCIONES DINÁMICAS
====================================================== */

.c4-chatbot-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0 15px 38px;
    animation: c4ChatMessageIn .22s ease-out both;
}

.c4-chatbot-option {
    position: relative;
    width: 100%;
    border: 1px solid rgba(37, 99, 235, .24);
    border-radius: 14px;
    padding: 12px 14px;
    background:
        linear-gradient(180deg, #ffffff, #f8fafc);
    color: #1e3a8a;
    font-weight: 850;
    text-align: left;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
    transition:
        background .18s ease,
        border-color .18s ease,
        transform .18s ease,
        box-shadow .18s ease;
}

.c4-chatbot-option::after {
    content: "›";
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #2563eb;
    font-size: 20px;
    opacity: .65;
}

.c4-chatbot-option:hover {
    background: #eff6ff;
    border-color: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(37, 99, 235, .12);
}

.c4-chatbot-option:active {
    transform: translateY(0);
}


/* ======================================================
   INPUT
====================================================== */

/* ======================================================
   INPUT INFERIOR
====================================================== */

.c4-chatbot-input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #f0f2f5; /* Fondo gris de la barra de herramientas de WA */
    border-top: 1px solid #e9edef;
}

.c4-chatbot-input {
    flex: 1;
    min-width: 0;
    border: none;
    border-radius: 8px; /* Esquinas más suaves */
    padding: 9px 12px;
    font-size: 15px;
    outline: none;
    color: #111b21;
    background: #ffffff;
    box-shadow: 0 1px 1px rgba(0,0,0,.05);
}

/* Botón enviar (Lo podemos mantener azul C4 o cambiarlo al verde de WA) */
.c4-chatbot-send {
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #00a884; /* Verde de acción de WhatsApp */
    color: #ffffff;
    font-weight: bold;
    cursor: pointer;
    box-shadow: none;
    transition: transform .1s ease;
}

.c4-chatbot-send:hover {
    background: #008f70;
    transform: scale(1.05);
    box-shadow: none;
}

.c4-chatbot-input::placeholder {
    color: #9ca3af;
}

.c4-chatbot-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}



.c4-chatbot-send:active {
    transform: translateY(0);
}

.c4-chatbot-send:disabled,
.c4-chatbot-input:disabled {
    opacity: .55;
    cursor: not-allowed;
}


/* ======================================================
   RESUMEN FINAL
====================================================== */

.c4-chatbot-summary-card {
    margin: 10px 0 14px 38px;
    border-radius: 18px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid rgba(37, 99, 235, .16);
    box-shadow:
        0 16px 36px rgba(15, 23, 42, .10),
        0 0 0 1px rgba(255, 255, 255, .60) inset;
    animation: c4ChatMessageIn .24s ease-out both;
}

.c4-chatbot-summary-title {
    padding: 14px 15px;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, .16), transparent 36%),
        linear-gradient(135deg, #f8fafc, #eff6ff);
    border-bottom: 1px solid rgba(37, 99, 235, .12);
}

.c4-chatbot-summary-title span {
    display: block;
    color: #0f172a;
    font-size: 14px;
    font-weight: 950;
}

.c4-chatbot-summary-title small {
    display: block;
    margin-top: 3px;
    color: #64748b;
    font-size: 11.5px;
}

.c4-chatbot-summary-list {
    padding: 10px 13px 12px;
}

.c4-chatbot-summary-row {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px dashed rgba(148, 163, 184, .45);
}

.c4-chatbot-summary-row:last-child {
    border-bottom: none;
}

.c4-chatbot-summary-label {
    color: #64748b;
    font-size: 12px;
    font-weight: 750;
}

.c4-chatbot-summary-value {
    color: #111827;
    font-size: 12.8px;
    font-weight: 900;
    line-height: 1.35;
}

/* ======================================================
   TICKET TÉCNICO FINAL
====================================================== */

.c4-chatbot-ticket {
    margin: 12px 0 14px 38px;
    overflow: hidden;
    border-radius: 18px;
    background: #ffffff;
    border: 1px solid rgba(37, 99, 235, .18);
    box-shadow:
        0 16px 38px rgba(15, 23, 42, .12),
        0 0 0 1px rgba(255, 255, 255, .65) inset;
    animation: c4ChatMessageIn .24s ease-out both;
}

.c4-chatbot-ticket-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 15px;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, .18), transparent 38%),
        linear-gradient(135deg, #f8fafc, #eff6ff);
    border-bottom: 1px solid rgba(37, 99, 235, .12);
}

.c4-chatbot-ticket-label {
    display: block;
    margin-bottom: 3px;
    color: #64748b;
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.c4-chatbot-ticket-head strong {
    display: block;
    color: #0f172a;
    font-size: 14px;
    font-weight: 950;
}

.c4-chatbot-ticket-status {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 6px 9px;
    font-size: 10.5px;
    font-weight: 950;
    line-height: 1;
    white-space: nowrap;
}

.c4-chatbot-ticket-status.is-qualified {
    background: rgba(22, 163, 74, .12);
    color: #15803d;
    border: 1px solid rgba(22, 163, 74, .22);
}

.c4-chatbot-ticket-status.is-not-qualified {
    background: rgba(239, 68, 68, .10);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, .20);
}

.c4-chatbot-ticket-body {
    padding: 10px 14px 11px;
}

.c4-chatbot-ticket-row {
    display: grid;
    grid-template-columns: 106px minmax(0, 1fr);
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px dashed rgba(148, 163, 184, .42);
}

.c4-chatbot-ticket-row:last-child {
    border-bottom: none;
}

.c4-chatbot-ticket-row-label {
    color: #64748b;
    font-size: 12px;
    font-weight: 800;
}

.c4-chatbot-ticket-row-value {
    color: #111827;
    font-size: 12.8px;
    font-weight: 900;
    line-height: 1.35;
}

.c4-chatbot-ticket-note {
    padding: 12px 14px;
    background: rgba(15, 23, 42, .035);
    border-top: 1px solid rgba(148, 163, 184, .22);
    color: #475569;
    font-size: 12px;
    line-height: 1.4;
}

/* ======================================================
   ACCIONES FINALES
====================================================== */

.c4-chatbot-final-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0 4px 38px;
    animation: c4ChatMessageIn .24s ease-out both;
}

.c4-chatbot-whatsapp,
.c4-chatbot-restart {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 950;
    text-decoration: none;
    cursor: pointer;
    min-height: 44px;
    transition:
        background .16s ease,
        transform .16s ease,
        box-shadow .16s ease,
        border-color .16s ease;
}

.c4-chatbot-whatsapp {
    background:
        radial-gradient(circle at top left, rgba(255,255,255,.20), transparent 28%),
        linear-gradient(135deg, #16a34a, #15803d);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, .18);
    box-shadow: 0 14px 30px rgba(22, 163, 74, .24);
}

.c4-chatbot-whatsapp::before {
    content: "✓";
    margin-right: 8px;
    font-weight: 950;
}

.c4-chatbot-whatsapp:hover {
    background:
        radial-gradient(circle at top left, rgba(255,255,255,.22), transparent 28%),
        linear-gradient(135deg, #15803d, #166534);
    transform: translateY(-1px);
    box-shadow: 0 17px 34px rgba(22, 163, 74, .30);
}

.c4-chatbot-restart {
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
}

.c4-chatbot-restart:hover {
    background: #f3f4f6;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}


/* ======================================================
   ESTADOS DE ACCESIBILIDAD
====================================================== */

.c4-chatbot-toggle:focus-visible,
.c4-chatbot-close:focus-visible,
.c4-chatbot-option:focus-visible,
.c4-chatbot-send:focus-visible,
.c4-chatbot-input:focus-visible,
.c4-chatbot-whatsapp:focus-visible,
.c4-chatbot-restart:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .30);
    outline-offset: 2px;
}


/* ======================================================
   RESPONSIVE TABLET / MÓVIL
====================================================== */

@media (max-width: 640px) {
    .c4-chatbot-toggle-text {
        display: none;
    }

    .c4-chatbot-toggle {
        width: 58px;
        height: 58px;
        justify-content: center;
        padding: 0;
    }

    .c4-chatbot-toggle-pulse {
        top: 8px;
        left: 10px;
    }

    .c4-chatbot-panel {
        right: 0 !important;
        bottom: 72px !important;
        width: calc(100vw - 28px) !important;
        height: min(540px, calc(100vh - 150px)) !important;
        max-height: calc(100vh - 150px) !important;
        border-radius: 20px;
    }
}

/* ======================================================
   FIX DEFINITIVO MÓVIL — CHATBOT FLOTANTE REAL
====================================================== */

.c4-chatbot-root {
    position: fixed !important;
    right: 18px !important;
    bottom: 18px !important;
    z-index: 2147483647 !important;
    pointer-events: auto !important;
}

.c4-chatbot-toggle,
.c4-chatbot-panel {
    z-index: 2147483647 !important;
}

@media (max-width: 768px) {
    .c4-chatbot-root {
        right: 18px !important;
        bottom: 18px !important;
    }

    body.chat-abierto .boton-whatsapp {
        display: none !important;
    }
}

@media (max-width: 380px) {
    .c4-chatbot-root {
        right: 14px !important;
        bottom: 14px !important;
    }

    .c4-chatbot-panel {
        right: -6px !important;
        width: calc(100vw - 18px) !important;
    }
}
