.nimble-ai-chat {
    --nimble-ai-chat-accent: var(--accent, #2563eb);
    --nimble-ai-chat-accent-hover: var(--accent-hover, #1d4ed8);
    --nimble-ai-chat-surface: #ffffff;
    --nimble-ai-chat-surface-muted: #f3f4f6;
    --nimble-ai-chat-text: #111827;
    --nimble-ai-chat-text-muted: #5b6472;
    --nimble-ai-chat-border: #d9dee7;
    --nimble-ai-chat-danger: #b42318;
    --nimble-ai-chat-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
    --nimble-ai-chat-base-bottom: clamp(1rem, 3vw, 2rem);
    position: fixed;
    right: clamp(1rem, 3vw, 2rem);
    bottom: var(--nimble-ai-chat-base-bottom);
    z-index: 2147483000;
    color: var(--nimble-ai-chat-text);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    transition: bottom 180ms ease;
}

.nimble-ai-chat--back-to-top-visible {
    bottom: calc(var(--nimble-ai-chat-base-bottom) + 4rem);
}

.nimble-ai-chat,
.nimble-ai-chat *,
.nimble-ai-chat *::before,
.nimble-ai-chat *::after {
    box-sizing: border-box;
}

.nimble-ai-chat__toggle {
    display: inline-flex;
    min-width: 3.5rem;
    min-height: 3.5rem;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.85rem 1rem;
    border: 0;
    border-radius: 999px;
    background: var(--nimble-ai-chat-accent);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.24);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    transition:
        background-color 160ms ease,
        box-shadow 160ms ease,
        transform 160ms ease;
}

.nimble-ai-chat__toggle:hover {
    background: var(--nimble-ai-chat-accent-hover);
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.28);
    transform: translateY(-1px);
}

.nimble-ai-chat__toggle-icon,
.nimble-ai-chat__icon-button svg,
.nimble-ai-chat__send svg {
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.nimble-ai-chat__panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.8rem);
    display: flex;
    width: min(24rem, calc(100vw - 2rem));
    height: min(38rem, calc(100dvh - 7rem));
    min-height: 25rem;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--nimble-ai-chat-border);
    border-radius: 1rem;
    background: var(--nimble-ai-chat-surface);
    box-shadow: var(--nimble-ai-chat-shadow);
    color: var(--nimble-ai-chat-text);
    animation: nimble-ai-chat-panel-in 180ms ease-out;
}

.nimble-ai-chat__panel[hidden] {
    display: none !important;
}

.nimble-ai-chat__header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3.75rem;
    padding: 0.75rem 0.8rem 0.75rem 1rem;
    border-bottom: 1px solid var(--nimble-ai-chat-border);
    background: var(--nimble-ai-chat-surface);
}

.nimble-ai-chat__title {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: inherit;
    font: inherit;
    font-size: 1rem;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nimble-ai-chat__header-actions {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.nimble-ai-chat__icon-button {
    display: inline-flex;
    width: 2.5rem;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 0.65rem;
    background: transparent;
    color: var(--nimble-ai-chat-text-muted);
    cursor: pointer;
    transition:
        background-color 150ms ease,
        color 150ms ease;
}

.nimble-ai-chat__icon-button:hover {
    background: var(--nimble-ai-chat-surface-muted);
    color: var(--nimble-ai-chat-text);
}

.nimble-ai-chat__icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.nimble-ai-chat__messages {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 0;
    margin: 0;
    padding: 1rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.nimble-ai-chat__message {
    display: flex;
    max-width: 88%;
    flex-direction: column;
    gap: 0.22rem;
    margin: 0;
}

.nimble-ai-chat__message--assistant {
    align-self: flex-start;
}

.nimble-ai-chat__message--user {
    align-self: flex-end;
}

.nimble-ai-chat__speaker {
    padding: 0 0.3rem;
    color: var(--nimble-ai-chat-text-muted);
    font-size: 0.72rem;
    font-weight: 700;
}

.nimble-ai-chat__message--user .nimble-ai-chat__speaker {
    align-self: flex-end;
}

.nimble-ai-chat__message-text {
    margin: 0;
    padding: 0.7rem 0.85rem;
    border-radius: 0.9rem 0.9rem 0.9rem 0.25rem;
    background: var(--nimble-ai-chat-surface-muted);
    color: var(--nimble-ai-chat-text);
    font-size: 0.92rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.nimble-ai-chat__message--user .nimble-ai-chat__message-text {
    border-radius: 0.9rem 0.9rem 0.25rem 0.9rem;
    background: var(--nimble-ai-chat-accent);
    color: #ffffff;
}

.nimble-ai-chat__status {
    flex: 0 0 auto;
    min-height: 1.7rem;
    margin: 0;
    padding: 0.2rem 1rem;
    color: var(--nimble-ai-chat-text-muted);
    font-size: 0.76rem;
    line-height: 1.3;
}

.nimble-ai-chat__status--error {
    color: var(--nimble-ai-chat-danger);
    font-weight: 650;
}

.nimble-ai-chat__form {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--nimble-ai-chat-border);
    background: var(--nimble-ai-chat-surface);
}

.nimble-ai-chat__input {
    display: block;
    width: 100%;
    min-height: 2.75rem;
    max-height: 8rem;
    resize: vertical;
    padding: 0.66rem 0.75rem;
    border: 1px solid var(--nimble-ai-chat-border);
    border-radius: 0.72rem;
    outline: 0;
    background: var(--nimble-ai-chat-surface);
    color: var(--nimble-ai-chat-text);
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.35;
    transition:
        border-color 150ms ease,
        box-shadow 150ms ease;
}

.nimble-ai-chat__input::placeholder {
    color: var(--nimble-ai-chat-text-muted);
    opacity: 0.9;
}

.nimble-ai-chat__input:disabled {
    cursor: wait;
    opacity: 0.65;
}

.nimble-ai-chat__send {
    display: inline-flex;
    min-width: 2.75rem;
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.65rem 0.75rem;
    border: 0;
    border-radius: 0.72rem;
    background: var(--nimble-ai-chat-accent);
    color: #ffffff;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 750;
    transition:
        background-color 150ms ease,
        opacity 150ms ease;
}

.nimble-ai-chat__send:hover {
    background: var(--nimble-ai-chat-accent-hover);
}

.nimble-ai-chat__send:disabled {
    cursor: wait;
    opacity: 0.6;
}

.nimble-ai-chat__toggle:focus-visible,
.nimble-ai-chat__icon-button:focus-visible,
.nimble-ai-chat__input:focus-visible,
.nimble-ai-chat__send:focus-visible {
    outline: 3px solid var(--nimble-ai-chat-accent);
    outline: 3px solid color-mix(in srgb, var(--nimble-ai-chat-accent) 45%, #ffffff);
    outline-offset: 2px;
}

.nimble-ai-chat__input:focus-visible {
    border-color: var(--nimble-ai-chat-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--nimble-ai-chat-accent) 18%, transparent);
}

.nimble-ai-chat__sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

@keyframes nimble-ai-chat-panel-in {
    from {
        opacity: 0;
        transform: translateY(0.5rem) scale(0.98);
    }

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

@media (prefers-color-scheme: dark) {
    .nimble-ai-chat {
        --nimble-ai-chat-surface: #171b24;
        --nimble-ai-chat-surface-muted: #252b37;
        --nimble-ai-chat-text: #f3f4f6;
        --nimble-ai-chat-text-muted: #aeb6c4;
        --nimble-ai-chat-border: #343c4a;
        --nimble-ai-chat-danger: #fda29b;
        --nimble-ai-chat-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
    }
}

html[data-theme-mode="dark"] .nimble-ai-chat,
html.theme-dark .nimble-ai-chat {
    --nimble-ai-chat-surface: #171b24;
    --nimble-ai-chat-surface-muted: #252b37;
    --nimble-ai-chat-text: #f3f4f6;
    --nimble-ai-chat-text-muted: #aeb6c4;
    --nimble-ai-chat-border: #343c4a;
    --nimble-ai-chat-danger: #fda29b;
    --nimble-ai-chat-shadow: 0 24px 60px rgba(0, 0, 0, 0.48);
}

@media (max-width: 35rem) {
    .nimble-ai-chat {
        --nimble-ai-chat-base-bottom: 0.75rem;
        right: 0.75rem;
    }

    .nimble-ai-chat__toggle {
        width: 3.5rem;
        padding: 0.85rem;
    }

    .nimble-ai-chat__toggle-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .nimble-ai-chat__panel {
        position: fixed;
        right: 0.75rem;
        bottom: 5rem;
        left: 0.75rem;
        width: auto;
        height: min(38rem, calc(100dvh - 6rem));
        min-height: min(25rem, calc(100dvh - 6rem));
    }

    .nimble-ai-chat__send-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .nimble-ai-chat,
    .nimble-ai-chat *,
    .nimble-ai-chat *::before,
    .nimble-ai-chat *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
