/**
 * BetAsistenteContacto — estilos del asistente (front-end).
 *
 * Variables inyectadas en línea desde PHP:
 * --bac-primary, --bac-on-primary, --bac-surface, --bac-radius,
 * --bac-size, --bac-z, --bac-offx, --bac-offy
 *
 * @package BetAsistenteContacto
 */

#bac-root,
#bac-root * {
    box-sizing: border-box;
}

#bac-root {
    --bac-text: #111827;
    --bac-muted: #6b7280;
    --bac-line: rgba(17, 24, 39, 0.1);
    --bac-bot: #f3f4f6;
    --bac-user: var(--bac-primary);
    --bac-user-text: var(--bac-on-primary);
    --bac-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
    --bac-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    position: fixed;
    z-index: var(--bac-z, 999990);
    font-family: var(--bac-font);
    font-size: 15px;
    line-height: 1.45;
    color: var(--bac-text, #111827);
    color-scheme: light;
    -webkit-font-smoothing: antialiased;
}

#bac-root.bac-pos-bottom-right {
    right: var(--bac-offx, 20px);
    bottom: var(--bac-offy, 20px);
    left: auto;
    top: auto;
}

#bac-root.bac-pos-bottom-left {
    left: var(--bac-offx, 20px);
    bottom: var(--bac-offy, 20px);
    right: auto;
    top: auto;
}

#bac-root.bac-dark-dark,
#bac-root.bac-dark-auto {
    /* Los valores de modo oscuro automático se aplican más abajo con media query. */
}

#bac-root.bac-dark-dark {
    /* !important: gana a la paleta que PHP inyecta en el atributo style. */
    --bac-text: #f9fafb !important;
    --bac-muted: #9ca3af !important;
    --bac-line: rgba(255, 255, 255, 0.12) !important;
    --bac-bot: #1f2937 !important;
    --bac-surface: #111827 !important;
    --bac-shadow: 0 18px 45px rgba(0, 0, 0, 0.55) !important;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    #bac-root.bac-dark-auto {
        /* !important: gana a la paleta que PHP inyecta en el atributo style. */
        --bac-text: #f9fafb !important;
        --bac-muted: #9ca3af !important;
        --bac-line: rgba(255, 255, 255, 0.12) !important;
        --bac-bot: #1f2937 !important;
        --bac-surface: #111827 !important;
        --bac-shadow: 0 18px 45px rgba(0, 0, 0, 0.55) !important;
        color-scheme: dark;
    }
}

/* Aislamiento del tema: dentro del asistente cada texto hereda la paleta
   del panel, salvo que una regla propia del widget indique otro color. */
#bac-root .bac-panel *,
#bac-root .bac-bubble *,
#bac-root .bac-greeting * {
    color: inherit;
}

/* ── Burbuja ─────────────────────────────────────────────── */

#bac-root .bac-bubble {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--bac-size, 60px);
    height: var(--bac-size, 60px);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--bac-primary);
    color: var(--bac-on-primary);
    font-size: calc(var(--bac-size, 60px) * 0.45);
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.25);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    overflow: visible;
    -webkit-appearance: none;
    appearance: none;
}

#bac-root .bac-bubble:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.3);
}

#bac-root .bac-bubble:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.45);
    outline-offset: 3px;
}

#bac-root .bac-bubble-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

#bac-root .bac-bubble-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#bac-root .bac-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--bac-surface, #fff);
}

/* ── Animaciones ─────────────────────────────────────────── */

#bac-root.bac-anim-pop .bac-bubble {
    animation: bac-pop-in 0.35s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}

#bac-root.bac-anim-slide .bac-bubble {
    animation: bac-slide-in 0.4s ease both;
}

@keyframes bac-pop-in {
    from {
        transform: scale(0.6);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes bac-slide-in {
    from {
        transform: translateY(24px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ── Panel ───────────────────────────────────────────────── */

#bac-root .bac-panel {
    position: absolute;
    bottom: calc(var(--bac-size, 60px) + 14px);
    width: 360px;
    max-width: calc(100vw - 32px);
    max-height: min(560px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--bac-surface, #fff);
    color: var(--bac-text, #111827);
    border-radius: calc(var(--bac-radius, 16px) + 4px);
    box-shadow: var(--bac-shadow);
    border: 1px solid var(--bac-line);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.22s ease, visibility 0.22s;
    pointer-events: none;
}

#bac-root.bac-pos-bottom-left .bac-panel {
    left: 0;
    right: auto;
    transform-origin: bottom left;
}

#bac-root.bac-pos-bottom-right .bac-panel {
    right: 0;
    left: auto;
}

#bac-root.bac-open .bac-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#bac-root.bac-anim-none .bac-panel,
#bac-root.bac-anim-none .bac-bubble {
    animation: none;
    transition: none;
}

/* Cabecera */

#bac-root .bac-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bac-primary);
    color: var(--bac-on-primary);
    flex: 0 0 auto;
}

#bac-root .bac-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    background: color-mix(in srgb, var(--bac-on-primary) 20%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    overflow: hidden;
    flex: 0 0 auto;
}

#bac-root .bac-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

#bac-root .bac-head-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
}

#bac-root .bac-head-text strong {
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#bac-root .bac-head-text span {
    font-size: 12px;
    opacity: 0.85;
}

#bac-root .bac-close {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 22px;
    line-height: 1;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0.85;
    transition: background 0.15s ease;
    padding: 0;
}

#bac-root .bac-close:hover {
    background: rgba(255, 255, 255, 0.18);
    background: color-mix(in srgb, var(--bac-on-primary) 18%, transparent);
    opacity: 1;
}

/* Registro de mensajes */

#bac-root .bac-log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bac-surface);
    color: var(--bac-text, #111827);
    scrollbar-width: thin;
    scrollbar-color: var(--bac-muted) transparent;
    min-height: 120px;
}

#bac-root .bac-msg {
    display: flex;
    max-width: 100%;
}

#bac-root .bac-msg-bot {
    justify-content: flex-start;
}

#bac-root .bac-msg-user {
    justify-content: flex-end;
}

#bac-root .bac-msg-text {
    max-width: 84%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

#bac-root .bac-msg-bot .bac-msg-text {
    background: var(--bac-bot);
    color: var(--bac-text, #111827);
    border-bottom-left-radius: 5px;
}

#bac-root .bac-msg-user .bac-msg-text {
    background: var(--bac-user);
    color: var(--bac-user-text);
    border-bottom-right-radius: 5px;
}

#bac-root .bac-typing {
    gap: 4px;
    padding: 10px 12px;
    background: var(--bac-bot);
    border-radius: 14px;
    border-bottom-left-radius: 5px;
    width: auto;
    align-self: flex-start;
}

#bac-root .bac-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bac-muted);
    display: inline-block;
    animation: bac-blink 1.2s infinite ease-in-out;
}

#bac-root .bac-dot:nth-child(2) {
    animation-delay: 0.15s;
}

#bac-root .bac-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bac-blink {
    0%, 80%, 100% {
        opacity: 0.25;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

/* Acciones */

#bac-root .bac-actions {
    flex: 0 0 auto;
    padding: 0 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 48%;
    overflow-y: auto;
    background: var(--bac-surface);
    color: var(--bac-text, #111827);
}

#bac-root .bac-actions:empty {
    display: none;
}

#bac-root .bac-choices,
#bac-root .bac-links,
#bac-root .bac-end {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#bac-root .bac-choice,
#bac-root .bac-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--bac-line);
    border-radius: 10px;
    background: transparent;
    color: var(--bac-text, #111827);
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

#bac-root .bac-choice:hover,
#bac-root .bac-link:hover {
    border-color: var(--bac-primary);
    background: rgba(37, 99, 235, 0.06);
    background: color-mix(in srgb, var(--bac-primary) 12%, transparent);
    transform: translateX(2px);
}

#bac-root .bac-link-icon {
    flex: 0 0 auto;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
}

#bac-root .bac-link-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

#bac-root .bac-link-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

#bac-root .bac-more,
#bac-root .bac-restart {
    align-self: flex-start;
    border: 0;
    background: transparent;
    color: var(--bac-muted);
    font-size: 12.5px;
    font-family: inherit;
    text-decoration: underline;
    cursor: pointer;
    padding: 2px 0;
}

#bac-root .bac-more:hover,
#bac-root .bac-restart:hover {
    color: var(--bac-primary);
}

#bac-root .bac-restart-row {
    display: flex;
    justify-content: flex-start;
}

#bac-root .bac-cta {
    width: 100%;
    padding: 10px 14px;
    border: 0;
    border-radius: 10px;
    background: var(--bac-primary);
    color: var(--bac-on-primary);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: filter 0.15s ease;
}

#bac-root .bac-cta:hover {
    filter: brightness(1.06);
}

/* Formulario de prospecto */

#bac-root .bac-lead {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 2px 0;
}

#bac-root .bac-lead-title {
    margin: 0 0 2px;
    font-weight: 700;
    font-size: 14px;
    color: var(--bac-text, #111827);
}

#bac-root .bac-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    color: var(--bac-muted);
}

#bac-root .bac-field input,
#bac-root .bac-field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--bac-line);
    border-radius: 9px;
    background: transparent;
    color: var(--bac-text, #111827);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

#bac-root .bac-field input::placeholder,
#bac-root .bac-field textarea::placeholder,
#bac-root .bac-input::placeholder {
    color: var(--bac-muted);
    opacity: 1;
}

#bac-root .bac-field input:focus,
#bac-root .bac-field textarea:focus {
    outline: none;
    border-color: var(--bac-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#bac-root .bac-consent {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    font-size: 11.5px;
    color: var(--bac-muted);
    line-height: 1.35;
}

#bac-root .bac-consent input {
    margin-top: 2px;
    flex: 0 0 auto;
}

#bac-root .bac-hp {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#bac-root .bac-lead-submit {
    margin-top: 2px;
    padding: 9px 14px;
    border: 0;
    border-radius: 10px;
    background: var(--bac-primary);
    color: var(--bac-on-primary);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

#bac-root .bac-lead-submit[disabled] {
    opacity: 0.6;
    cursor: progress;
}

/* Campo de escritura */

#bac-root .bac-form {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 10px 14px 12px;
    border-top: 1px solid var(--bac-line);
    background: var(--bac-surface);
    color: var(--bac-text, #111827);
}

#bac-root .bac-form[hidden] {
    display: none;
}

#bac-root .bac-input {
    flex: 1 1 auto;
    padding: 9px 12px;
    border: 1px solid var(--bac-line);
    border-radius: 20px;
    background: transparent;
    color: var(--bac-text, #111827);
    font-family: inherit;
    font-size: 14px;
}

#bac-root .bac-input:focus {
    outline: none;
    border-color: var(--bac-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#bac-root .bac-send {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--bac-primary);
    color: var(--bac-on-primary);
    font-size: 15px;
    cursor: pointer;
    line-height: 1;
}

#bac-root .bac-send:hover {
    filter: brightness(1.06);
}

/* Pie */

#bac-root .bac-foot {
    flex: 0 0 auto;
    text-align: center;
    font-size: 10.5px;
    color: var(--bac-muted);
    padding: 0 0 7px;
    background: var(--bac-surface);
}

#bac-root .bac-foot:empty {
    display: none;
}

/* ── Globo de saludo ─────────────────────────────────────── */

#bac-root .bac-greeting {
    position: absolute;
    bottom: calc(var(--bac-size, 60px) + 12px);
    width: 230px;
    padding: 10px 30px 10px 13px;
    background: var(--bac-surface, #fff);
    border: 1px solid var(--bac-line);
    border-radius: 14px;
    box-shadow: var(--bac-shadow);
    font-size: 13.5px;
    color: var(--bac-text, #111827);
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#bac-root .bac-greeting[hidden] {
    display: none;
}

#bac-root .bac-greeting.is-visible {
    opacity: 1;
    transform: translateY(0);
}

#bac-root.bac-pos-bottom-right .bac-greeting {
    right: 0;
}

#bac-root.bac-pos-bottom-left .bac-greeting {
    left: 0;
}

#bac-root .bac-greeting-close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--bac-muted);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

#bac-root .bac-greeting-close:hover {
    background: var(--bac-bot);
}

/* ── Botón en línea (shortcode / Elementor) ──────────────── */

#bac-root.bac-inline-mode .bac-bubble {
    display: none;
}

.bac-inline-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 18px;
    border: 0;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s ease, transform 0.12s ease;
}

.bac-inline-trigger:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.bac-inline-trigger:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.4);
    outline-offset: 2px;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 480px) {
    #bac-root {
        font-size: 14px;
    }

    #bac-root .bac-panel {
        position: fixed;
        left: 8px !important;
        right: 8px !important;
        bottom: calc(var(--bac-size, 60px) + 18px) !important;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 120px);
        border-radius: 16px;
        transform-origin: bottom center;
    }

    #bac-root .bac-actions {
        max-height: 42%;
    }

    #bac-root .bac-greeting {
        width: 190px;
        font-size: 13px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #bac-root .bac-bubble,
    #bac-root .bac-panel,
    #bac-root .bac-greeting,
    #bac-root .bac-choice,
    #bac-root .bac-link {
        animation: none !important;
        transition: none !important;
    }

    #bac-root .bac-dot {
        animation: none;
        opacity: 0.6;
    }
}
