/*
 * Mira — zwevende chatwidget.
 *
 * Stond als inline <style> in templates/components/floating_chat.html. Verplaatst
 * naar een eigen bestand zodat de Content Security Policy geen 'unsafe-inline'
 * meer hoeft toe te staan voor stylesheets.
 *
 * Onderaan staan de toestandsklassen die Alpine's x-show en x-transition
 * vervangen: de widget zet .is-expanded en .is-open op de root, de rest is CSS.
 */

/* =======================================================================
   FLOATING CHAT WIDGET — Mira popup
   Works on both light and dark theme pages.
   ======================================================================= */

/* Container — bottom-right fixed */
.floating-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* =======================================================================
   FAB — Floating Action Button (avatar → pill expansion)
   ======================================================================= */
.mira-fab {
    position: relative;
    display: flex;
    align-items: center;
}

.mira-fab__btn {
    display: flex;
    align-items: center;
    gap: 0;
    height: 88px;
    border-radius: 44px;
    border: 3px solid #059669;
    background: #fff;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 24px rgba(5, 150, 105, 0.2);
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    color: #059669;
    width: 88px;
}

/* Expanded state — pill shape */
.floating-chat-widget.is-expanded .mira-fab__btn {
    width: auto;
    padding-right: 40px;
    gap: 12px;
    box-shadow: 0 8px 40px rgba(5, 150, 105, 0.25);
}

.mira-fab__btn:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 32px rgba(5, 150, 105, 0.3);
}

/* Avatar circle — vult exact de binnenruimte van .mira-fab__btn (88px knop - 2x3px rand) */
.mira-fab__avatar {
    width: 82px;
    height: 82px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.mira-fab__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Close icon (when chat open) */
.mira-fab__close-icon {
    margin: auto;
}

/* Text label inside pill */
.mira-fab__text {
    font-size: 0.875rem;
    color: #1c1917;
    white-space: nowrap;
    line-height: 1.4;
    font-family: inherit;
}

.mira-fab__text strong {
    color: #059669;
    font-weight: 600;
}

/* Pulse ring around avatar */
.mira-fab__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #059669;
    animation: miraFabPulse 2.5s ease-in-out infinite;
    pointer-events: none;
}

/* Close/dismiss button (top-right of pill) */
.mira-fab__close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #e7e5e4;
    background: #fff;
    cursor: pointer;
    font-size: 0.875rem;
    color: #78716c;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 5;
    line-height: 1;
    padding: 0;
}

.mira-fab__close:hover {
    background: #f5f5f4;
    color: #1c1917;
    border-color: #78716c;
}

/* =======================================================================
   CHAT WINDOW
   ======================================================================= */
.floating-chat__window {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    width: 420px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 16px 64px rgba(28, 25, 23, 0.15);
    border: 1px solid #e7e5e4;
    display: flex;
    flex-direction: column;
    font-family: inherit;
}

/* Chat header */
.floating-chat__header {
    background: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid #e7e5e4;
    border-radius: 16px 16px 0 0;
    overflow: visible;
    position: relative;
}

.floating-chat__header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.floating-chat__header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #059669;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-radius 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s ease;
    transform-origin: center center;
    position: relative;
    z-index: 1;
}

.floating-chat__header-avatar:hover {
    transform: scale(4);
    z-index: 500;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

.floating-chat__header-name {
    font-weight: 600;
    color: #1c1917;
    font-size: 0.875rem;
    margin: 0;
}

.floating-chat__header-role {
    font-size: 0.75rem;
    color: #059669;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.floating-chat__header-role::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #059669;
    display: inline-block;
    animation: miraFabDotPulse 1.5s ease-in-out infinite;
}

.floating-chat__header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.floating-chat__header-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #f5f5f4;
    border: none;
    cursor: pointer;
    color: #78716c;
    padding: 4px;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-chat__header-btn:hover {
    background: #e7e5e4;
    color: #1c1917;
}

/* Chat messages area */
.floating-chat__messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #fafaf9;
}

.floating-chat__msg {
    margin-bottom: 16px;
}

.floating-chat__msg-author {
    font-size: 0.75rem;
    font-weight: 600;
    color: #059669;
    margin: 0 0 4px 0;
}

.floating-chat__msg-text {
    font-size: 0.875rem;
    line-height: 1.6;
    margin: 0;
    color: #1c1917;
}

/* Chat message bubbles */
.floating-mira-bubble {
    background: #fff;
    border: 1px solid #e7e5e4;
    border-radius: 12px 12px 12px 2px;
    padding: 12px 16px;
    max-width: 320px;
}

.floating-user-bubble {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 12px 12px 2px 12px;
    padding: 12px 16px;
    max-width: 320px;
    margin-left: auto;
}

.floating-user-bubble .floating-chat__msg-author {
    color: #1c1917;
}

.floating-message-animation {
    animation: miraFabFadeInUp 0.3s ease-out;
}

/* Suggestions */
.floating-chat__suggestions {
    margin-bottom: 16px;
}

.floating-chat__suggestions-label {
    font-size: 0.75rem;
    color: #78716c;
    margin: 0 0 8px 0;
}

.floating-chat__suggestion-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 1px solid #e7e5e4;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.8125rem;
    color: #1c1917;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    margin-bottom: 6px;
    font-family: inherit;
}

.floating-chat__suggestion-btn:hover {
    background: #f5f5f4;
    border-color: #059669;
}

/* Chat input area */
.floating-chat__input-area {
    padding: 16px;
    border-top: 1px solid #e7e5e4;
    background: #fff;
    flex-shrink: 0;
    border-radius: 0 0 16px 16px;
}

.floating-chat__form {
    display: flex;
    gap: 8px;
}

.floating-chat-widget .floating-chat__input,
.floating-chat-widget form input.floating-chat__input {
    flex: 1;
    background: #f5f5f4;
    color: #1c1917;
    border: 1px solid #e7e5e4;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.floating-chat-widget .floating-chat__input::placeholder,
.floating-chat-widget form input.floating-chat__input::placeholder {
    color: #a8a29e;
}

.floating-chat-widget .floating-chat__input:focus,
.floating-chat-widget form input.floating-chat__input:focus {
    border-color: #78716c;
    background: #fff;
}

.floating-chat__send-btn {
    background: #1c1917;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
    white-space: nowrap;
}

.floating-chat__send-btn:hover {
    background: #1e3a5f;
}

/* Typing indicator */
.floating-chat__typing {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 0.75rem;
    color: #78716c;
}

.floating-chat__typing-dots {
    display: flex;
    gap: 3px;
}

.floating-chat__typing-dots span {
    width: 6px;
    height: 6px;
    background: #a8a29e;
    border-radius: 50%;
    animation: miraFabBounce 1.2s ease-in-out infinite;
}

.floating-chat__typing-dots span:nth-child(2) { animation-delay: 0.1s; }
.floating-chat__typing-dots span:nth-child(3) { animation-delay: 0.2s; }

/* =======================================================================
   ANIMATIONS
   ======================================================================= */
@keyframes miraFabPulse {
    0%, 100% { opacity: 0; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.15); }
}

@keyframes miraFabDotPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

@keyframes miraFabFadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes miraFabBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* =======================================================================
   RESPONSIVE
   ======================================================================= */

/* Tablet and smaller */
@media (max-width: 768px) {
    .floating-chat__header-avatar:hover {
        transform: scale(2.5);
    }
}

/* Mobile */
@media (max-width: 480px) {
    .floating-chat-widget {
        bottom: 16px;
        right: 16px;
    }

    /* FAB — smaller on mobile */
    .mira-fab__btn {
        width: 68px;
        height: 68px;
        border-radius: 34px;
    }

    .mira-fab__avatar {
        width: 62px;
        height: 62px;
    }

    .floating-chat-widget.is-expanded .mira-fab__btn {
        max-width: calc(100vw - 48px);
    }

    .mira-fab__text {
        font-size: 0.8125rem;
    }

    /* Chat window — reasonable mobile size */
    .floating-chat__window {
        width: calc(100vw - 16px);
        right: -8px;
        height: auto;
        max-height: calc(100vh - 140px);
        min-height: 360px;
        border-radius: 16px;
    }

    /* Compact header on mobile */
    .floating-chat__header {
        padding: 12px 16px;
    }

    .floating-chat__header-avatar {
        width: 38px;
        height: 38px;
    }

    /* Disable extreme scale on mobile — touch triggers hover and it stays */
    .floating-chat__header-avatar:hover {
        transform: scale(1.8);
    }

    /* Smaller messages area */
    .floating-chat__messages {
        padding: 12px;
        max-height: 50vh;
    }

    .floating-mira-bubble,
    .floating-user-bubble {
        max-width: 85%;
    }

    /* Compact input on mobile */
    .floating-chat__input-area {
        padding: 12px;
    }

    .floating-chat__send-btn span {
        display: none;
    }

    .floating-chat__send-btn {
        padding: 10px 12px;
    }

    .floating-chat__suggestion-btn {
        font-size: 0.75rem;
        padding: 6px 10px;
    }
}

/* =======================================================================
   TOESTANDEN — vervangt Alpine's x-show en x-transition

   De widget zet twee klassen op de root: .is-open zolang het chatvenster
   openstaat, en .is-expanded zolang de knop als pil met tekst getoond wordt.
   Die twee sluiten elkaar uit; de widget zet .is-expanded niet terwijl de
   chat open is.

   De selectoren staan bewust op de root en niet op het element zelf: zowel
   .mira-fab__close als .floating-chat__window krijgen hierboven display:flex,
   en een [hidden]-attribuut uit de UA-stylesheet verliest daarvan.
   ======================================================================= */

/* --- Chatvenster: fade + lift, zoals de Alpine-transitie deed --- */
.floating-chat__window {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.floating-chat-widget:not(.is-open) .floating-chat__window {
    opacity: 0;
    visibility: hidden;
    transform: translateY(1rem) scale(0.95);
    /* visibility pas ná de fade omklappen, anders verdwijnt hij abrupt */
    transition: opacity 0.2s ease-in, transform 0.2s ease-in, visibility 0s linear 0.2s;
}

/* --- Avatar en sluitkruis wisselen elkaar af in de knop --- */
.floating-chat-widget.is-open .mira-fab__avatar,
.floating-chat-widget:not(.is-open) .mira-fab__close-icon {
    display: none;
}

/* --- Pulsering: alleen bij de kale avatar --- */
.floating-chat-widget.is-open .mira-fab__pulse,
.floating-chat-widget.is-expanded .mira-fab__pulse {
    display: none;
}

/* --- Pil-tekst en wegklik-knop: alleen in uitgeklapte toestand --- */
.mira-fab__text {
    opacity: 1;
    transition: opacity 0.3s ease-out 0.15s;
}

.mira-fab__close {
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.2s ease-out 0.3s, transform 0.2s ease-out 0.3s;
}

.floating-chat-widget:not(.is-expanded) .mira-fab__text {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease-in, visibility 0s linear 0.15s;
}

.floating-chat-widget:not(.is-expanded) .mira-fab__close {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.75);
    transition: opacity 0.15s ease-in, transform 0.15s ease-in, visibility 0s linear 0.15s;
}

/* Wie liever geen beweging ziet, krijgt het zonder overgang. */
@media (prefers-reduced-motion: reduce) {
    .floating-chat__window,
    .mira-fab__text,
    .mira-fab__close,
    .floating-chat-widget:not(.is-open) .floating-chat__window,
    .floating-chat-widget:not(.is-expanded) .mira-fab__text,
    .floating-chat-widget:not(.is-expanded) .mira-fab__close {
        transition: none;
    }
}
