/**
 * FLOSC Companion Widget (v1.6.1)
 * ================================
 * Floating chat widget for non-app WordPress pages.
 * Pattern: FAB trigger → expandable chat container → FLOSC iframe.
 * Styled via FLOSC CSS custom properties.
 * Reference: mesolitica/nous-chat-widget
 */

/* ─── Container ──────────────────────────────── */
.flosc-companion {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.flosc-companion.flosc-companion--left {
    right: auto;
    left: 24px;
}

/* ─── FAB Trigger ────────────────────────────── */
.flosc-companion-fab {
    width: var(--flosc-companion-launcher-size, 60px);
    height: var(--flosc-companion-launcher-size, 60px);
    border-radius: 50%;
    background: var(--flosc-accent, #2563eb);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 22px -6px rgba(0, 0, 0, 0.30);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.35s ease;
    /* Gentle "breathing" glow to invite engagement (disabled under reduced-motion). */
    animation: flosc-companion-breathe 4.5s ease-in-out infinite;
}

.flosc-companion-fab:hover {
    transform: scale(1.1);
}

/* Pause the breathing while the panel is open or when motion is reduced. */
.flosc-companion.is-open .flosc-companion-fab,
.flosc-companion.flosc-companion--motion-reduce .flosc-companion-fab {
    animation: none;
}

.flosc-companion.flosc-companion--motion-reduce .flosc-companion-fab,
.flosc-companion.flosc-companion--motion-reduce .flosc-companion-window,
.flosc-companion.flosc-companion--motion-reduce .flosc-companion-fab svg {
    transition: none !important;
}

.flosc-companion.flosc-companion--motion-reduce .flosc-companion-fab:hover {
    transform: none;
}

.flosc-companion.flosc-companion--motion-full .flosc-companion-fab {
    transition-duration: 0.4s;
}

.flosc-companion.flosc-companion--motion-full .flosc-companion-window {
    transition-duration: 0.35s;
}

.flosc-companion-fab svg {
    width: calc(var(--flosc-companion-launcher-size, 60px) * 0.46);
    height: calc(var(--flosc-companion-launcher-size, 60px) * 0.46);
    fill: currentColor;
    transition: transform 0.3s ease;
}

.flosc-companion.is-open .flosc-companion-fab svg {
    transform: rotate(180deg);
}

/* ─── Chat Window (soft-glass surface) ───────── */
.flosc-companion-window {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: var(--flosc-companion-width, 380px);
    height: var(--flosc-companion-height, 560px);
    border-radius: 18px;
    overflow: hidden;
    background: var(--flosc-bg, #ffffff);
    box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.40),
                0 0 0 1px rgba(0, 0, 0, 0.05);
    -webkit-backdrop-filter: blur(20px) saturate(1.15);
    backdrop-filter: blur(20px) saturate(1.15);
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.flosc-companion.flosc-companion--left .flosc-companion-window {
    right: auto;
    left: 0;
}

.flosc-companion.is-open .flosc-companion-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ─── Header (accent gradient with hairline) ─── */
.flosc-companion-header {
    background: var(--flosc-accent, #2563eb);
    background: linear-gradient(135deg, var(--flosc-accent, #2563eb),
                color-mix(in srgb, var(--flosc-accent, #2563eb) 80%, #000));
    color: #ffffff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.flosc-companion-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.flosc-companion-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.flosc-companion-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.flosc-companion-title {
    font-size: 15px;
    font-weight: 600;
}

.flosc-companion-subtitle {
    font-size: 12px;
    opacity: 0.8;
}

.flosc-companion-close {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s ease;
}

.flosc-companion-close:hover {
    opacity: 1;
    transform: translateY(1px);
}

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

.flosc-companion-fullscreen {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
    opacity: 0.85;
    line-height: 1;
    transition: opacity 0.2s;
}

.flosc-companion-fullscreen:hover {
    opacity: 1;
}

.flosc-companion.is-fullscreen .flosc-companion-window {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    bottom: 0;
    left: 0;
    right: auto;
}

.flosc-companion.is-fullscreen .flosc-companion-fab {
    display: none;
}

/* ─── Iframe Body ────────────────────────────── */
.flosc-companion-body {
    width: 100%;
    height: calc(100% - 68px);
    border: none;
}

/* ─── Mobile Responsive ──────────────────────── */
@media (max-width: 640px) {
    .flosc-companion:not(.flosc-companion--mobile-panel) .flosc-companion-window {
        width: 100vw;
        height: 100vh;
        bottom: 0;
        right: 0;
        border-radius: 0;
        position: fixed;
    }

    .flosc-companion:not(.flosc-companion--mobile-panel).is-open .flosc-companion-fab {
        display: none;
    }

    .flosc-companion.flosc-companion--mobile-panel .flosc-companion-window {
        width: min(var(--flosc-companion-width, 380px), calc(100vw - 24px));
        height: min(var(--flosc-companion-height, 560px), 80vh);
    }
}

/* ─── Notification Badge ─────────────────────── */
.flosc-companion-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #dc2626;
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
}

.flosc-companion-badge:empty {
    display: none;
}

.flosc-message--bot {
    background: #f1f5f9;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.flosc-message--user {
    background: var(--flosc-accent, #2563eb);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.flosc-launcher {
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { box-shadow: 0 10px 30px -10px rgba(99, 102, 241, 0.5); }
    50% { box-shadow: 0 15px 40px -8px rgba(99, 102, 241, 0.7); }
}

/* ─── Breathing launcher keyframes ───────────── */
@keyframes flosc-companion-breathe {
    0%, 100% { box-shadow: 0 8px 22px -6px rgba(0, 0, 0, 0.30); }
    50%      { box-shadow: 0 14px 36px -6px rgba(0, 0, 0, 0.42); }
}

/* ─── Accessibility: visible keyboard focus + OS reduced-motion ─── */
.flosc-companion-fab:focus-visible,
.flosc-companion-close:focus-visible,
.flosc-companion-fullscreen:focus-visible,
.flosc-companion-window a:focus-visible,
.flosc-companion-window button:focus-visible {
    outline: 2px solid var(--flosc-accent, #2563eb);
    outline-offset: 2px;
    border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
    .flosc-companion,
    .flosc-companion * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
