.floating-widget {
    position: fixed;
    inset: auto 2rem 2rem auto;
    z-index: var(--z-popover);
    display: grid;
    gap: 1rem;
    justify-items: end;
}

.floating-widget__launcher {
    width: 3.75rem;
    height: 3.75rem;
    border-radius: var(--radius-full);
    border: none;
    background: var(--theme-gradient-accent);
    color: var(--theme-text-inverse);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.floating-widget__launcher:focus-visible {
    outline: 3px solid rgba(var(--theme-primary-rgb), 0.4);
    outline-offset: 3px;
}

.floating-widget__launcher:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
}

.floating-widget__launcher svg {
    width: 1.75rem;
    height: 1.75rem;
    fill: currentColor;
}

.floating-widget__window {
    width: min(24rem, calc(100vw - 2.5rem));
    border-radius: var(--radius-2xl);
    background: var(--theme-bg-primary);
    border: 1px solid var(--theme-border-light);
    box-shadow: var(--shadow-2xl);
    overflow: hidden;
    display: none;
    flex-direction: column;
    transition: opacity var(--transition-base), transform var(--transition-base);
    opacity: 0;
    transform: translateY(1rem);
}

.floating-widget__window.is-open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.floating-widget__header {
    background: var(--theme-gradient-primary);
    color: var(--theme-text-inverse);
    padding: 1rem 1.25rem;
    font-weight: var(--font-weight-semibold);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.floating-widget__header-title {
    margin: 0;
    font-size: var(--font-size-lg);
}

.floating-widget__header-status {
    font-size: var(--font-size-xs);
    opacity: 0.8;
}

.floating-widget__body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 22rem;
    overflow-y: auto;
    background: var(--theme-bg-secondary);
}

.floating-widget__message {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.floating-widget__message--ai {
    flex-direction: row;
}

.floating-widget__message--user {
    flex-direction: row-reverse;
}

.floating-widget__avatar {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-full);
    background: rgba(var(--theme-primary-rgb), 0.15);
    color: var(--theme-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--font-weight-semibold);
    font-size: 0.875rem;
}

.floating-widget__bubble {
    background: var(--theme-bg-primary);
    border: 1px solid var(--theme-border-light);
    border-radius: var(--radius-xl);
    padding: 0.85rem 1rem;
    color: var(--theme-text-primary);
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
    position: relative;
    max-width: 80%;
}

.floating-widget__message--ai .floating-widget__bubble {
    background: rgba(var(--theme-primary-rgb), 0.08);
}

.floating-widget__bubble time {
    display: block;
    font-size: var(--font-size-xs);
    margin-top: 0.5rem;
    color: var(--theme-text-muted);
}

.floating-widget__input {
    padding: 1rem 1.25rem;
    background: var(--theme-bg-primary);
    border-top: 1px solid var(--theme-border-light);
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.floating-widget__input input {
    flex: 1;
    border: 1px solid var(--theme-border-light);
    border-radius: var(--radius-lg);
    padding: 0.75rem 1rem;
    background: var(--theme-bg-secondary);
    color: var(--theme-text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.floating-widget__input input:focus {
    outline: none;
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(var(--theme-primary-rgb), 0.15);
    background: var(--theme-bg-primary);
}

.floating-widget__send {
    border: none;
    border-radius: var(--radius-lg);
    padding: 0.75rem 1.25rem;
    background: var(--theme-gradient-primary);
    color: var(--theme-text-inverse);
    font-weight: var(--font-weight-semibold);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.floating-widget__send:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.floating-widget__send svg {
    width: 1rem;
    height: 1rem;
    fill: currentColor;
}

@media (max-width: 640px) {
    .floating-widget {
        inset: auto 1rem 1rem auto;
    }

    .floating-widget__launcher {
        width: 3.25rem;
        height: 3.25rem;
    }

    .floating-widget__window {
        width: min(20rem, calc(100vw - 1.5rem));
    }
}
