/* ── i4life Chatbot — Frontend Widget ─────────────────────── */

/* ── Reset de seguridad: aislar el widget del CSS del tema ── */

/* Box-sizing normalizado dentro del widget */
#i4cb-root * { box-sizing: border-box; }
#i4cb-window * { box-sizing: border-box !important; }

/* Reset de botones SOLO dentro de la ventana de chat
   (NO afecta a #i4cb-toggle que es hijo directo de #i4cb-root) */
#i4cb-window button {
    all: unset;
    box-sizing: border-box !important;
    cursor: pointer !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Reset de inputs y textareas dentro del widget */
#i4cb-window input,
#i4cb-window textarea {
    all: unset;
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: block !important;
    width: 100% !important;
}

/* Forzar herencia de color en SVGs para que temas WP no los anulen */
#i4cb-root svg path { fill: currentColor !important; }
#i4cb-send svg,
#i4cb-toggle svg { display: block; flex-shrink: 0; }

/* Botón flotante */
#i4cb-toggle {
    position: fixed;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;           /* evita que el avatar se salga del círculo */
    padding: 0;                 /* sin relleno para que la imagen llene el botón */
    box-shadow: 0 4px 20px rgba(0,0,0,.25);
    z-index: 999998;
    transition: transform .2s, box-shadow .2s;
}
#i4cb-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 24px rgba(0,0,0,.3); }
/* Estado abierto: hover rota la X 90° en lugar de escalar */
#i4cb-toggle.i4cb-toggle-open { transition: transform .25s ease, box-shadow .2s; }
#i4cb-toggle.i4cb-toggle-open:hover { transform: rotate(90deg); box-shadow: 0 6px 24px rgba(0,0,0,.3); }

/* Ventana de chat */
#i4cb-window {
    position: fixed;
    width: 360px;
    max-height: 520px;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,.18);
    z-index: 999997;
    background: #fff;
    flex-direction: column;
    overflow: hidden;
    animation: i4cb-pop .2s ease;
}
@keyframes i4cb-pop {
    from { opacity:0; transform:translateY(12px) scale(.97); }
    to   { opacity:1; transform:translateY(0) scale(1); }
}

/* Cabecera */
#i4cb-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    flex-shrink: 0;
}

/* Mensajes */
#i4cb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#i4cb-messages::-webkit-scrollbar { width: 4px; }
#i4cb-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* Burbujas */
.i4cb-bubble { display: flex; max-width: 85%; align-items: flex-end; gap: 6px; }
.i4cb-bubble-user      { align-self: flex-end; }
.i4cb-bubble-assistant { align-self: flex-start; }

/* Avatar del bot junto a las burbujas del asistente */
.i4cb-bubble-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    align-self: flex-end;
}
.i4cb-bubble-avatar-default {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--i4cb-primary, #4f46e5);
    opacity: .2;
    flex-shrink: 0;
}

.i4cb-bubble-inner {
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
}
.i4cb-bubble-user .i4cb-bubble-inner {
    background: var(--i4cb-primary, #4f46e5);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.i4cb-bubble-assistant .i4cb-bubble-inner {
    background: #f1f0f5;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.i4cb-typing-indicator .i4cb-bubble-inner {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 16px;
}
.i4cb-typing-indicator span {
    width: 7px; height: 7px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    animation: i4cb-bounce 1.2s infinite ease-in-out;
}
.i4cb-typing-indicator span:nth-child(2) { animation-delay: .2s; }
.i4cb-typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes i4cb-bounce {
    0%,80%,100% { transform: scale(1); opacity:.5; }
    40%          { transform: scale(1.4); opacity:1; }
}

/* Sugerencias */
#i4cb-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 12px 8px;
}
.i4cb-suggestion {
    background: #f1f0f5 !important;
    border: 1px solid #e0dff0 !important;
    border-radius: 20px !important;
    padding: 5px 12px !important;
    font-size: 12px !important;
    cursor: pointer !important;
    color: #333 !important;
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap !important;
    display: inline-flex !important;
    line-height: 1.4 !important;
}
/* La píldora SUGGEST (fill) puede ser una frase larga — permitir salto de línea */
.i4cb-suggestion-fill {
    white-space: normal !important;
    text-align: left !important;
    border-radius: 12px !important;
    width: 100% !important;
    display: block !important;
    padding: 7px 14px !important;
}
.i4cb-suggestion:hover { background: #e5e5f5 !important; }

/* Input */
#i4cb-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
    flex-shrink: 0;
}
#i4cb-input {
    flex: 1 !important;
    resize: none !important;
    border: 1px solid #ddd !important;
    border-radius: 12px !important;
    padding: 9px 12px !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    outline: none !important;
    font-family: inherit !important;
    min-height: 38px !important;
    max-height: 120px !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
    background: #fff !important;
    color: #1a1a2e !important;
    transition: border-color .15s;
    display: block !important;
    width: auto !important;
    margin: 0 !important;
    box-shadow: none !important;
}
#i4cb-input:focus { border-color: var(--i4cb-primary, #4f46e5) !important; box-shadow: none !important; outline: none !important; }
/* Ocultar scrollbar del textarea (el JS gestiona el alto automático) */
#i4cb-input                             { scrollbar-width: none; }  /* Firefox */
#i4cb-input::-webkit-scrollbar         { display: none; }           /* Chrome/Safari */

#i4cb-send {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    border: none !important;
    border-radius: 50% !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;
    text-decoration: none !important;
    transition: opacity .15s, transform .15s, box-shadow .15s;
    box-shadow: 0 2px 8px rgba(0,0,0,.2) !important;
    outline: none !important;
}
#i4cb-send:hover { opacity: .9 !important; transform: scale(1.08) !important; box-shadow: 0 3px 12px rgba(0,0,0,.25) !important; }
#i4cb-send:active { transform: scale(.96) !important; }
#i4cb-send:disabled { opacity: .35 !important; cursor: not-allowed !important; transform: none !important; box-shadow: none !important; }
#i4cb-send:focus { outline: none !important; box-shadow: 0 0 0 3px rgba(79,70,229,.35) !important; }

/* Footer */
#i4cb-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px 8px;
    background: #fafafa;
    flex-shrink: 0;
    border-top: 1px solid #f0f0f0;
}
.i4cb-footer-brand {
    font-size: 10px;
    color: #bbb;
}
.i4cb-footer-link {
    color: #bbb;
    text-decoration: none;
    font-weight: 600;
}
.i4cb-footer-link:hover {
    color: #888;
    text-decoration: underline;
}

/* Escalación inline — mini-formulario de contacto */
.i4cb-escalation-card {
    margin: 4px 12px 8px;
    padding: 14px 16px;
    background: #fff8f0;
    border: 1px solid #fde8c8;
    border-radius: 12px;
}
.i4cb-esc-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: #92400e;
}
.i4cb-esc-sub {
    margin: 0 0 10px;
    font-size: 12px;
    color: #b45309;
    line-height: 1.4;
}
.i4cb-esc-fields {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 10px;
}
.i4cb-esc-name,
.i4cb-esc-email,
.i4cb-esc-phone,
.i4cb-esc-msg {
    width: 100% !important;
    box-sizing: border-box !important;
    border: 1px solid #fcd34d !important;
    border-radius: 7px !important;
    padding: 7px 10px !important;
    font-size: 13px !important;
    font-family: inherit !important;
    background: #fffbf5 !important;
    color: #1f2937 !important;
    outline: none !important;
    transition: border-color .15s;
    resize: none !important;
    display: block !important;
    margin: 0 !important;
}
.i4cb-esc-name:focus,
.i4cb-esc-email:focus,
.i4cb-esc-phone:focus,
.i4cb-esc-msg:focus  { border-color: #f59e0b !important; }
.i4cb-esc-name.i4cb-esc-error,
.i4cb-esc-email.i4cb-esc-error,
.i4cb-esc-phone.i4cb-esc-error { border-color: #ef4444 !important; }
.i4cb-esc-errmsg {
    font-size: 12px;
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 6px 9px;
    margin-bottom: 8px;
    line-height: 1.4;
}
.i4cb-esc-submit {
    background: #f59e0b !important;
    color: #fff !important;
    border: none !important;
    border-radius: 7px !important;
    padding: 8px 16px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    font-family: inherit !important;
    transition: background .15s;
    width: 100% !important;
    display: block !important;
    text-align: center !important;
    box-sizing: border-box !important;
}
.i4cb-esc-submit:hover    { background: #d97706 !important; }
.i4cb-esc-submit:disabled { opacity: .6 !important; cursor: not-allowed !important; }
.i4cb-esc-ok {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #166534;
    text-align: center;
    padding: 4px 0;
}

/* ── Demo CTA button ────────────────────────────────────────── */
.i4cb-demo-cta {
    display: block;
    margin: 8px 12px 4px 12px;
    padding: 11px 20px;
    background: var(--i4cb-primary, #4f46e5);
    color: #fff !important;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    border-radius: 10px;
    text-decoration: none !important;
    box-shadow: 0 2px 8px rgba(79,70,229,.35);
    transition: filter .15s, box-shadow .15s;
    cursor: pointer;
}
.i4cb-demo-cta:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 14px rgba(79,70,229,.45);
    color: #fff !important;
}

/* Burbuja proactiva — posición siempre gestionada por JS vía setAttribute */
#i4cb-proactive {
    position: fixed;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,.18);
    padding: 10px 14px;
    font-size: 14px;
    max-width: 220px;
    cursor: pointer;
    z-index: 999998;
    animation: i4cb-pop .2s ease;
    color: #1a1a2e;
    line-height: 1.4;
}

/* Separador de historial */
.i4cb-history-sep {
    text-align: center;
    font-size: 10px;
    color: #aaa;
    padding: 4px 0;
    position: relative;
}
.i4cb-history-sep::before,
.i4cb-history-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: #e8e8e8;
}
.i4cb-history-sep::before { left: 0; }
.i4cb-history-sep::after  { right: 0; }

/* Burbujas de historial (ligeramente atenuadas) */
.i4cb-bubble-history .i4cb-bubble-inner { opacity: .75; }

/* Links dentro de burbujas */
.i4cb-bubble-inner a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}
.i4cb-bubble-user .i4cb-bubble-inner a { color: rgba(255,255,255,.9); }

/* Píldoras de enlace "→ Más información" en respuestas del asistente */
.i4cb-bubble-assistant .i4cb-link-pill {
    display: inline-flex !important;
    align-items: center !important;
    background: var(--i4cb-primary, #4f46e5) !important;
    color: #fff !important;
    text-decoration: none !important;
    border-radius: 20px !important;
    padding: 3px 12px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    margin: 4px 4px 2px 0 !important;
    transition: opacity .15s;
    word-break: normal !important;
    white-space: nowrap !important;
    vertical-align: middle !important;
}
.i4cb-bubble-assistant .i4cb-link-pill:hover { opacity: .82 !important; }

/* ── Formulario de captura de leads (inline) ────────────────── */
.i4cb-lead-card {
    background: #f8f9fe;
    border: 1px solid #dde1f5;
    border-radius: 12px;
    padding: 14px 16px;
    margin: 8px 12px;
    box-shadow: 0 1px 6px rgba(79,70,229,.08);
}
.i4cb-lead-msg {
    margin: 0 0 10px;
    font-size: 13px;
    color: #374151;
    line-height: 1.45;
}
.i4cb-lead-input {
    display: block !important;
    width: 100% !important;
    box-sizing: border-box !important;
    border: 1px solid #d1d5db !important;
    border-radius: 7px !important;
    padding: 7px 10px !important;
    font-size: 13px !important;
    color: #111827 !important;
    background: #fff !important;
    margin-bottom: 7px !important;
    outline: none !important;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit !important;
}
.i4cb-lead-input:focus {
    border-color: #4f46e5 !important;
    box-shadow: 0 0 0 2px rgba(79,70,229,.15) !important;
}
.i4cb-lead-input-error {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 2px rgba(239,68,68,.15) !important;
}
.i4cb-lead-error {
    color: #dc2626;
    font-size: 12px;
    margin-bottom: 6px;
    padding: 6px 8px;
    background: #fef2f2;
    border-radius: 5px;
    border: 1px solid #fecaca;
    line-height: 1.4;
}
.i4cb-lead-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}
.i4cb-lead-submit {
    flex: 1 !important;
    padding: 8px 14px !important;
    background: #4f46e5 !important;
    color: #fff !important;
    border: none !important;
    border-radius: 7px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: background .15s;
    font-family: inherit !important;
}
.i4cb-lead-submit:hover { background: #4338ca !important; }
.i4cb-lead-skip {
    background: transparent !important;
    border: none !important;
    font-size: 12px !important;
    color: #9ca3af !important;
    cursor: pointer !important;
    padding: 4px 6px !important;
    text-decoration: underline !important;
    font-family: inherit !important;
}
.i4cb-lead-skip:hover { color: #6b7280 !important; }

/* Responsive */
@media (max-width: 480px) {
    #i4cb-window {
        width: calc(100vw - 20px);
        right: 10px !important;
        left: 10px !important;
        bottom: 80px;
    }
}
