/*
 * CIBR Chat Bot - (c) 2026 Cesar Barboza - devcibr.com
 * Software propietario. Prohibida su copia, distribucion o
 * comercializacion sin autorizacion del titular (Ley 11.723).
 * Licencia: ver el archivo LICENSE.
 */

/* =========================================
   CIBR CHAT BOT - WIDGET

   Colores: se cambian aca o, el principal,
   desde el panel (Configuracion > Color).
   Todo esta dentro de .chatbot para no
   afectar al resto del sitio.
========================================= */

.chatbot {
    --cb-primary: #8b5cf6;                      /* botones, mensajes del visitante */
    --cb-accent: #14b8a6;                       /* "conectado", agente, chat en vivo */
    --cb-bg: #0a0f1e;                           /* fondo de la ventana */
    --cb-bg-input: #030712;                     /* fondo de los campos */
    --cb-card: rgba(15, 23, 42, 0.55);          /* burbujas del bot */
    --cb-border: rgba(148, 163, 184, 0.12);
    --cb-border-strong: rgba(148, 163, 184, 0.25);
    --cb-text: #f8fafc;
    --cb-text-muted: #94a3b8;
    --cb-build: "dev";                          /* identificador de la copia */

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9000;

    color: var(--cb-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
}

/* Proteccion contra estilos generales del sitio */
.chatbot *,
.chatbot *::before,
.chatbot *::after {
    box-sizing: border-box;
}

.chatbot p {
    margin: 0;
}

.chatbot button,
.chatbot input,
.chatbot textarea {
    font: inherit;
    letter-spacing: normal;
    text-transform: none;
}


/* =========================================
   BOTON FLOTANTE
========================================= */

.chatbot-toggle {
    width: 58px;
    height: 58px;

    display: grid;
    place-items: center;

    border: none;
    border-radius: 50%;

    background: linear-gradient(135deg, var(--cb-primary), var(--cb-accent));
    color: #ffffff;

    cursor: pointer;

    box-shadow:
        0 10px 30px color-mix(in srgb, var(--cb-primary) 40%, transparent);

    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-toggle:hover {
    transform: translateY(-2px);
    box-shadow:
        0 14px 36px color-mix(in srgb, var(--cb-primary) 55%, transparent);
}

.chatbot-toggle:focus-visible,
.chatbot button:focus-visible,
.chatbot textarea:focus-visible,
.chatbot input:focus-visible {
    outline: 2px solid var(--cb-primary);
    outline-offset: 2px;
}

.chatbot svg {
    width: 24px;
    height: 24px;

    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chatbot-toggle {
    position: relative;
}

.chatbot-unread {
    position: absolute;
    top: -2px;
    right: -2px;

    min-width: 20px;
    height: 20px;
    padding: 0 5px;

    display: grid;
    place-items: center;

    border-radius: 999px;
    border: 2px solid var(--cb-bg-input);

    background: #ef4444;
    color: #ffffff;

    font-size: 11px;
    font-weight: 700;
}

.chatbot-unread[hidden] {
    display: none;
}

.chatbot-icon-close,
.chatbot.is-open .chatbot-icon-open {
    display: none;
}

.chatbot.is-open .chatbot-icon-close {
    display: block;
}


/* =========================================
   VENTANA
========================================= */

.chatbot-panel {
    position: absolute;
    right: 0;
    bottom: 74px;

    width: 360px;
    height: 520px;
    max-height: calc(100vh - 120px);

    display: flex;
    flex-direction: column;

    background: var(--cb-bg);
    border: 1px solid var(--cb-border-strong);
    border-radius: 18px;

    overflow: hidden;

    box-shadow:
        0 24px 70px rgba(0, 0, 0, 0.55);

    animation: chatbot-in 0.2s ease;
}

.chatbot-panel[hidden] {
    display: none;
}

@keyframes chatbot-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
}


/* =========================================
   CABECERA
========================================= */

.chatbot-header {
    display: flex;
    align-items: center;
    gap: 12px;

    padding: 14px 16px;

    border-bottom: 1px solid var(--cb-border);
    background: color-mix(in srgb, var(--cb-primary) 8%, transparent);
}

.chatbot-header div {
    flex: 1;
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.chatbot-header strong {
    font-size: 15px;
    color: var(--cb-text);
}

.chatbot-header small {
    font-size: 12px;
    color: var(--cb-text-muted);
}

/* Avatar: punto verde del bot o inicial/foto del agente */

.chatbot-avatar {
    flex-shrink: 0;

    width: 10px;
    height: 10px;
    border-radius: 50%;

    background: var(--cb-accent) center / cover no-repeat;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--cb-accent) 20%, transparent);
}

.chatbot.is-live .chatbot-avatar {
    width: 36px;
    height: 36px;

    display: grid;
    place-items: center;

    background-color: var(--cb-primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--cb-accent) 60%, transparent);

    color: #ffffff;
    font-weight: 700;
}

.chatbot-close {
    display: grid;
    place-items: center;

    width: 32px;
    height: 32px;

    border: none;
    border-radius: 8px;

    background: transparent;
    color: var(--cb-text-muted);

    cursor: pointer;
}

.chatbot-close:hover {
    background: rgba(148, 163, 184, 0.12);
    color: var(--cb-text);
}

.chatbot-close svg {
    width: 18px;
    height: 18px;
}


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

.chatbot-messages {
    flex: 1;
    overflow-y: auto;

    display: flex;
    flex-direction: column;
    gap: 10px;

    padding: 16px;

    scroll-behavior: smooth;
}

.chatbot-msg {
    max-width: 82%;
    padding: 10px 14px;

    border-radius: 14px;

    font-size: 14px;
    line-height: 1.5;

    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chatbot-msg--bot,
.chatbot-msg--agent {
    align-self: flex-start;

    background: var(--cb-card);
    border: 1px solid var(--cb-border);
    border-bottom-left-radius: 4px;

    color: var(--cb-text);
}

.chatbot-msg--agent {
    border-color: color-mix(in srgb, var(--cb-accent) 35%, transparent);
}

.chatbot-msg small {
    display: block;
    margin-bottom: 2px;

    color: var(--cb-accent);
    font-size: 11px;
    font-weight: 600;
}

.chatbot-msg--visitor {
    align-self: flex-end;

    background: var(--cb-primary);
    border-bottom-right-radius: 4px;

    color: #ffffff;
}

.chatbot-msg--failed {
    opacity: 0.55;
}

.chatbot-msg--error {
    align-self: center;
    max-width: 100%;

    padding: 6px 12px;

    background: #32151b;
    border: 1px solid #672631;

    color: #ff9ba8;
    font-size: 13px;
}


/* Indicador "escribiendo" */

.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 14px;
}

.chatbot-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;

    background: var(--cb-text-muted);

    animation: chatbot-dot 1.2s infinite ease-in-out;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbot-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}


/* Formulario de email dentro del chat */

.chatbot-email {
    align-self: flex-start;

    display: flex;
    gap: 8px;

    width: 90%;
}

.chatbot-email input {
    flex: 1;
    min-width: 0;
}


/* =========================================
   BARRA "HABLAR CON UNA PERSONA"
========================================= */

.chatbot-bar {
    padding: 8px 12px 0;
    border-top: 1px solid var(--cb-border);
}

.chatbot-bar[hidden] {
    display: none;
}

.chatbot-live-btn {
    width: 100%;
    padding: 8px 12px;

    background: color-mix(in srgb, var(--cb-accent) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--cb-accent) 35%, transparent);
    border-radius: 10px;

    color: var(--cb-accent);
    font-size: 13px;
    font-weight: 600;

    cursor: pointer;
}

.chatbot-live-btn:hover {
    background: color-mix(in srgb, var(--cb-accent) 18%, transparent);
}

.chatbot-live-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

.chatbot.is-live .chatbot-live-btn {
    background: transparent;
    border-color: var(--cb-border-strong);
    color: var(--cb-text-muted);
    font-weight: 400;
}


/* Nombre + email antes de hablar con una persona */

.chatbot-contact {
    white-space: normal;
    display: flex;
    flex-direction: column;
    gap: 8px;

    width: 90%;
    max-width: 90%;
}

.chatbot-contact p {
    margin: 0 0 2px;
}

.chatbot-contact input {
    width: 100%;
    padding: 9px 11px;

    background: var(--cb-bg-input);
    color: var(--cb-text);

    border: 1px solid #303047;
    border-radius: 10px;

    font: inherit;
    font-size: 14px;
}

.chatbot-contact input:focus {
    outline: none;
    border-color: var(--cb-primary);
}

.chatbot-contact-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.chatbot-contact-actions button {
    padding: 7px 14px;

    border: none;
    border-radius: 10px;

    background: var(--cb-primary);
    color: #ffffff;

    font: inherit;
    font-size: 14px;
    font-weight: 600;

    cursor: pointer;
}

.chatbot-contact-actions .chatbot-contact-cancel {
    background: transparent;
    color: var(--cb-text-muted);
    font-weight: 400;
}

.chatbot-contact-actions button:disabled {
    opacity: 0.5;
    cursor: wait;
}


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

.chatbot-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;

    padding: 12px;

    border-top: 1px solid var(--cb-border);
}

/* Firma del desarrollador, debajo del campo de texto */
.chatbot-credit {
    padding: 0 12px 9px;
    margin-top: -4px;

    color: var(--cb-text-muted);
    font-size: 11px;
    line-height: 1.3;
    text-align: center;

    opacity: 0.75;
}

.chatbot-credit a {
    color: inherit;
    font-weight: 600;
    text-decoration: none;
}

.chatbot-credit a:hover {
    color: var(--cb-text);
    text-decoration: underline;
}

.chatbot-form textarea,
.chatbot-email input {
    padding: 10px 12px;

    background: var(--cb-bg-input);
    color: var(--cb-text);

    border: 1px solid #303047;
    border-radius: 10px;

    font: inherit;
    font-size: 14px;
}

.chatbot-form textarea {
    flex: 1;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

.chatbot-form textarea:focus,
.chatbot-email input:focus {
    outline: none;
    border-color: var(--cb-primary);
}

.chatbot-form button,
.chatbot-email button {
    flex-shrink: 0;

    border: none;
    border-radius: 10px;

    background: var(--cb-primary);
    color: #ffffff;

    cursor: pointer;
}

.chatbot-form button {
    display: grid;
    place-items: center;

    width: 42px;
    height: 42px;
}

.chatbot-form button svg {
    width: 18px;
    height: 18px;
}

.chatbot-email button {
    padding: 0 14px;
    font-size: 14px;
    font-weight: 600;
}

.chatbot-form button:disabled,
.chatbot-email button:disabled {
    opacity: 0.5;
    cursor: wait;
}

.chatbot-form button:not(:disabled):hover,
.chatbot-email button:not(:disabled):hover {
    opacity: 0.9;
}


/* Solo lectores de pantalla */

.chatbot-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}


/* =========================================
   MOVIL
========================================= */

@media (max-width: 480px) {

    .chatbot {
        right: 16px;
        bottom: 16px;
    }

    .chatbot-panel {
        position: fixed;
        inset: auto 16px 86px 16px;

        width: auto;
        height: calc(100vh - 110px);
        height: calc(100dvh - 110px);
        max-height: none;
    }
}

@media (prefers-reduced-motion: reduce) {

    .chatbot-panel,
    .chatbot-typing span,
    .chatbot-toggle {
        animation: none;
        transition: none;
    }
}
