/* ============================================================
   KOHA-IA — koha-widget.css
   Basado en MetaRagIA design system
   ============================================================ */

:root {
    --c-bg: #F4F6FB;
    --c-surface: #FFFFFF;
    --c-border: #D9E2F0;
    --c-border-soft: #E8EEF8;
    --c-text: #1A1A18;
    --c-text-muted: #8A8A84;
    --c-accent: #4A90D9;
    --c-accent-dark: #2F6FB5;
    --c-accent-soft: #EBF3FC;
    --c-online: #22C55E;
    --toolbar-bg: #5B9BD5;
    --font-sans: system-ui, 'DM Sans', sans-serif;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .06);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .08);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, .10);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, .13);
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-full: 9999px;
    --chat--color--primary: #4A90D9;
    --chat--color--primary-shade-50: #2F6FB5;
    --chat--color--primary--shade-100: #1E5A9C;
    --chat--color--secondary: #4A90D9;
    --chat--color-white: #ffffff;
    --chat--color-light: #F4F6FB;
    --chat--color-light-shade-50: #D9E2F0;
    --chat--color-dark: #1A1A18;
    --chat--font-family: system-ui, 'DM Sans', sans-serif;
    --chat--border-radius: 10px;
    --chat--transition-duration: .2s;
    --chat--spacing: 1rem;
    --chat--window--width: 400px;
    --chat--window--height: 600px;
    --chat--window--border: 1px solid #D9E2F0;
    --chat--window--border-radius: 16px;
    --chat--window--bottom: 24px;
    --chat--window--right: 24px;
    --chat--window--z-index: 9999;
    --chat--header--background: #5B9BD5;
    --chat--header--color: #ffffff;
    --chat--header--border-top: none;
    --chat--header--border-bottom: none;
    --chat--heading--font-size: 16px;
    --chat--subtitle--font-size: 12px;
    --chat--message--font-size: 14px;
    --chat--message--border-radius: 10px;
    --chat--message--bot--background: #FFFFFF;
    --chat--message--bot--color: #1A1A18;
    --chat--message--user--background: #4A90D9;
    --chat--message--user--color: #ffffff;
    --chat--body--background: #F4F6FB;
    --chat--toggle--size: 60px;
    --chat--toggle--width: 60px;
    --chat--toggle--height: 60px;
    --chat--toggle--border-radius: 9999px;
    --chat--toggle--background: transparent;
    --chat--toggle--hover--background: transparent;
    --chat--toggle--active--background: transparent;
    --chat--toggle--color: transparent;
    --chat--input--border: 1px solid #D9E2F0;
    --chat--input--border-radius: 6px;
    --chat--input--background: #ffffff;
    --chat--input--border-active: 1px solid #4A90D9;
    --chat--input--send--button--color: #4A90D9;
    --chat--footer--background: #ffffff;
    --chat--footer--color: #1A1A18;
    --chat--button--border-radius: 6px;
    --chat--button--background: #4A90D9;
    --chat--button--hover--background: #2F6FB5;
}

#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;
}

.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(--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(--shadow-lg) !important;
}

.chat-window-toggle svg {
    display: none !important;
}

.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 {
    margin-top: 0 !important;
    text-align: left;
    color: #5B9BD5 !important;
    font-size: .9rem !important;
    font-weight: 800 !important;
    font-family: var(--font-sans) !important;
}

.chat-window:not(.chat-window-toggle) {
    box-shadow: var(--shadow-lg) !important;
}

.chat-header-gif {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-right: 6px;
}

.chat-ctrl-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.chat-ctrl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, .30);
    background: rgba(255, 255, 255, .15);
    color: #ffffff;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .12s;
    flex-shrink: 0;
    padding: 0;
}

.chat-ctrl-btn:hover {
    background: rgba(255, 255, 255, .30);
    border-color: rgba(255, 255, 255, .55);
    transform: scale(1.08);
}

.chat-ctrl-btn:active {
    transform: scale(.96);
    background: rgba(255, 255, 255, .40);
}

.chat-ctrl-btn svg {
    width: 12px;
    height: 12px;
    stroke: #ffffff;
    flex-shrink: 0;
    pointer-events: none;
    display: block;
}

.chat-status-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border-soft);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    color: var(--c-text-muted);
    flex-shrink: 0;
}

.chat-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-online);
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, .25);
    animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 2px rgba(34, 197, 94, .25);
    }

    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, .10);
    }
}

.chat-status-text {
    color: darkslategrey;
    font-weight: 600;
    letter-spacing: .01em;
}

.typewriter-cursor {
    display: inline-block;
    animation: blink .7s step-end infinite;
    color: #5B9BD5;
    font-weight: 300;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

.chat-messages-list .chat-message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-messages-list .chat-message-row.row-bot {
    flex-direction: row;
}

.chat-messages-list .chat-message-row.row-user {
    flex-direction: row-reverse;
}

.chat-messages-list .chat-message-row>.chat-message {
    margin-top: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: 0 !important;
}

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background-color: #4A90D9;
    background-repeat: no-repeat;
    background-position: center;
    flex-shrink: 0;
    align-self: flex-end;
}

.chat-msg-avatar.avatar-bot {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 8V4H8'/%3E%3Crect width='16' height='12' x='4' y='8' rx='2'/%3E%3Cpath d='M2 14h2'/%3E%3Cpath d='M20 14h2'/%3E%3Cpath d='M15 13v2'/%3E%3Cpath d='M9 13v2'/%3E%3C/svg%3E");
    background-size: 16px 16px;
}

.chat-msg-avatar.avatar-user {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='5'/%3E%3Cpath d='M20 21a8 8 0 0 0-16 0'/%3E%3C/svg%3E");
    background-size: 16px 16px;
}

#flipia-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 4px 4px;
    width: 100%;
    animation: suggestions-fadein .35s ease;
}

@keyframes suggestions-fadein {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#flipia-suggestions.suggestions-hide {
    animation: suggestions-fadeout .3s ease forwards;
}

@keyframes suggestions-fadeout {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(6px);
    }
}

.suggestions-label {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    color: var(--c-text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 0 2px;
    margin-bottom: 2px;
}

.suggestion-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: var(--c-surface);
    border: 1.5px solid var(--c-border);
    border-radius: var(--r-md);
    padding: 10px 14px;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--c-text);
    text-align: left;
    transition: background .18s, border-color .18s, color .18s, transform .12s;
    box-shadow: var(--shadow-xs);
    line-height: 1.3;
}

.suggestion-btn:hover {
    background: var(--c-accent-soft);
    border-color: var(--c-accent);
    color: var(--c-accent-dark);
    transform: translateX(2px);
}

.suggestion-icon {
    font-size: 16px;
    flex-shrink: 0;
    line-height: 1;
}

.suggestion-text {
    flex: 1;
}

#flipia-mic-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin-left: 10px;
    border-radius: var(--r-sm);
    background: transparent;
    border: 1.5px solid var(--c-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, border-color .2s, color .2s;
    color: var(--c-text-muted);
    position: static !important;
}

#flipia-mic-btn:hover {
    background: var(--c-accent-soft);
    border-color: var(--c-accent);
    color: var(--c-accent);
}

#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;
}

#flipia-mic-btn.unsupported {
    opacity: 0.4;
    cursor: not-allowed;
}

@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);
    }
}

#flipia-mic-toast {
    position: fixed;
    bottom: 180px;
    right: 45px;
    z-index: 10001;
    background: var(--c-accent);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--r-full);
    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;
}

#flipia-greeting-bubble {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 10002;
    background: #5B9BD5;
    color: #ffffff;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    padding: 10px 14px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: var(--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;
}

/* Evitar que el textarea del chat sea redimensionable */
#koha-ia-chat textarea,
#koha-ia-chat [class*="chat-input"] textarea,
#koha-ia-chat .chat-inputs textarea {
    resize: none !important;
}

@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;
    }

    .chat-msg-avatar {
        width: 24px;
        height: 24px;
        min-width: 24px;
    }

    .suggestion-btn {
        font-size: 12px;
        padding: 9px 12px;
    }
}