/* ============================================================
   KOHA-IA — koha-widget.css
   Estilos del widget embebible para Koha
   ============================================================ */

/* Variables --chat-- se inyectan inline desde koha-widget.js para garantizar precedencia sobre N8N CSS */

/* ── Contenedor del chat ──────────────────────────────────────── */
#koha-ia-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
}

body:not(.koha-widget-ready) #koha-ia-chat {
    opacity: 0;
    pointer-events: none;
}

body.koha-widget-ready #koha-ia-chat {
    opacity: 1;
    pointer-events: auto;
    transition: opacity .3s ease;
}

/* ── Toggle button GIF ───────────────────────────────────────── */
.chat-window-toggle {
    width: 64px !important;
    height: 64px !important;
    min-width: 64px !important;
    min-height: 64px !important;
    border-radius: 50% !important;
    border: none !important;
    padding: 0 !important;
    cursor: pointer !important;
    background-color: transparent !important;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
    box-shadow: var(--koha-shadow-md) !important;
    transition: transform .2s ease, box-shadow .2s ease !important;
    overflow: visible !important;
}

.chat-window-toggle:hover {
    transform: scale(1.08) !important;
    box-shadow: var(--koha-shadow-lg) !important;
}

.chat-window-toggle svg {
    display: none !important;
}

/* ── Typing indicator ────────────────────────────────────────── */
.chat-message-typing .chat-message-typing__dot {
    display: none !important;
}

.chat-message-typing-body {
    display: flex !important;
    align-items: center !important;
    gap: 3px !important;
}

.chat-message-typing-body>*,
.chat-message-typing-body span,
.chat-message-typing-body div {
    width: 4px !important;
    height: 4px !important;
    min-width: 4px !important;
    min-height: 4px !important;
    max-width: 4px !important;
    max-height: 4px !important;
    border-radius: 100% !important;
}

.chat-message.chat-message-from-bot.chat-message-typing {
    min-width: 280px !important;
    width: 280px !important;
    padding: 10px 14px !important;
    display: flex !important;
    align-items: center;
    justify-content: flex-end !important;
    flex-direction: row-reverse;
    gap: 8px;
}

.flipia-typing-label,
.koha-typing-label {
    margin-top: 0 !important;
    text-align: left;
    color: #8A8A84 !important;
    font-size: .8rem !important;
}

/* ── Sombra ventana flotante ─────────────────────────────────── */
.chat-window:not(.chat-window-toggle) {
    box-shadow: var(--koha-shadow-lg) !important;
}

/* ── Botón micrófono ─────────────────────────────────────────── */
#flipia-mic-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin-left: 10px;
    border-radius: 6px;
    background: transparent;
    border: 1.5px solid #D9E2F0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, border-color .2s, color .2s;
    color: #8A8A84;
    position: static !important;
}

#flipia-mic-btn:hover {
    background: #EBF3FC;
    border-color: #4A90D9;
    color: #4A90D9;
}

#flipia-mic-btn.recording {
    background: #FEE2E2;
    border-color: #EF4444;
    color: #EF4444;
    animation: mic-pulse 1.2s ease-in-out infinite;
}

#flipia-mic-btn svg {
    width: 16px;
    height: 16px;
    pointer-events: none;
}

@keyframes mic-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, .35);
    }

    50% {
        box-shadow: 0 0 0 5px rgba(239, 68, 68, .0);
    }
}

/* ── Toast del micrófono ─────────────────────────────────────── */
#flipia-mic-toast {
    position: fixed;
    bottom: 180px;
    right: 45px;
    z-index: 10001;
    background: #4A90D9;
    color: #fff;
    font-family: system-ui, sans-serif;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 9999px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .2s, transform .2s;
    pointer-events: none;
    white-space: nowrap;
}

#flipia-mic-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

body:not(.koha-widget-ready) #flipia-mic-toast {
    display: none;
}

/* ── Burbuja de saludo ───────────────────────────────────────── */
#flipia-greeting-bubble {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 10002;
    background: #5B9BD5;
    color: #ffffff;
    font-family: system-ui, sans-serif;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--koha-shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(6px) scale(.97);
    transition: opacity .25s ease, transform .25s ease;
    pointer-events: none;
}

#flipia-greeting-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 18px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-top: 8px solid #5B9BD5;
}

#flipia-greeting-bubble.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

#flipia-greeting-bubble .bubble-close {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .25);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    line-height: 1;
    padding: 0;
    transition: background .15s;
}

#flipia-greeting-bubble .bubble-close:hover {
    background: rgba(255, 255, 255, .4);
}

body:not(.koha-widget-ready) #flipia-greeting-bubble {
    display: none;
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
    #koha-ia-chat {
        bottom: 16px;
        right: 16px;
    }

    .n8n-chat__window,
    [class*="chat-window"],
    [class*="chatWindow"] {
        width: calc(100vw - 32px) !important;
        max-height: 87vh !important;
    }

    #flipia-mic-toast {
        right: 30px;
        bottom: 160px;
    }

    #flipia-greeting-bubble {
        right: 16px;
        bottom: 88px;
        font-size: 12px;
    }
}