.demo-chat-root {
    --demo-chat-accent: #6366f1;
    --demo-chat-accent-dark: #4f46e5;
    --demo-chat-bg: #ffffff;
    --demo-chat-text: #111827;
    --demo-chat-muted: #6b7280;
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
    z-index: 2147483000;
    position: relative;
}

.demo-chat-toggle {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1.125rem;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--demo-chat-accent), var(--demo-chat-accent-dark));
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 12px 32px rgba(79, 70, 229, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 2147483001;
}

.demo-chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 36px rgba(79, 70, 229, 0.42);
}

.demo-chat-toggle.demo-chat-toggle-pulse {
    animation: demo-chat-pulse 2s ease-in-out infinite;
}

@keyframes demo-chat-pulse {
    0%, 100% {
        box-shadow: 0 12px 32px rgba(79, 70, 229, 0.35);
    }
    50% {
        box-shadow: 0 12px 32px rgba(79, 70, 229, 0.35), 0 0 0 8px rgba(99, 102, 241, 0.18);
    }
}

.demo-chat-toggle.is-open {
    opacity: 0;
    pointer-events: none;
}

.demo-chat-toggle svg {
    width: 22px;
    height: 22px;
}

.demo-chat-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    width: min(390px, calc(100vw - 1.5rem));
    height: min(620px, calc(100vh - 2rem));
    background: var(--demo-chat-bg);
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 2147483002;
    border: 1px solid rgba(15, 23, 42, 0.08);
}

.demo-chat-panel.hidden {
    display: none;
}

.demo-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.875rem;
    background: linear-gradient(135deg, var(--demo-chat-accent), var(--demo-chat-accent-dark));
    color: #fff;
}

.demo-chat-header-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.demo-chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.18);
}

.demo-chat-title {
    font-size: 1rem;
    font-weight: 700;
}

.demo-chat-subtitle {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-top: 0.125rem;
}

.demo-chat-close {
    background: rgba(255, 255, 255, 0.16);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.demo-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.demo-chat-msg {
    padding: 0.75rem 0.875rem;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-break: break-word;
}

.demo-chat-msg-row {
    display: flex;
    gap: 0.5rem;
    max-width: 92%;
}

.demo-chat-msg-row-assistant {
    align-self: flex-start;
    align-items: flex-end;
}

.demo-chat-msg-row-user {
    align-self: flex-end;
    justify-content: flex-end;
}

.demo-chat-msg-row-user .demo-chat-msg {
    max-width: 100%;
}

.demo-chat-msg-row-assistant .demo-chat-msg {
    max-width: calc(100% - 2.5rem);
}

.demo-chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.demo-chat-msg-assistant {
    background: #fff;
    color: var(--demo-chat-text);
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.demo-chat-msg-user {
    background: var(--demo-chat-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.demo-chat-loading-row {
    align-self: flex-start;
    align-items: flex-end;
}

.demo-chat-loading {
    padding: 0.625rem 0.875rem;
    background: #fff;
    border-radius: 14px;
    color: var(--demo-chat-muted);
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 4px;
}

.demo-chat-loading.demo-chat-loading-dots-only {
    min-width: 2.5rem;
    text-align: center;
}

.demo-chat-loading-dots {
    display: inline-flex;
    margin-left: 1px;
}

.demo-chat-loading-dots span {
    animation: demo-chat-loading-dot 1.2s ease-in-out infinite;
    opacity: 0.2;
}

.demo-chat-loading-dots span:nth-child(1) {
    animation-delay: 0s;
}

.demo-chat-loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.demo-chat-loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes demo-chat-loading-dot {
    0%,
    60%,
    100% {
        opacity: 0.2;
        transform: translateY(0);
    }

    30% {
        opacity: 1;
        transform: translateY(-2px);
    }
}

.demo-chat-version-row {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 0.65rem;
}

.demo-chat-version-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--demo-chat-muted);
}

.demo-chat-version-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.demo-chat-version-btn {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
    line-height: 1.2;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.demo-chat-version-btn:hover:not(:disabled) {
    border-color: var(--demo-chat-accent);
    color: var(--demo-chat-accent);
}

.demo-chat-version-btn.is-active {
    background: var(--demo-chat-accent);
    border-color: var(--demo-chat-accent);
    color: #fff;
    cursor: default;
}

.demo-chat-version-btn:disabled:not(.is-active) {
    opacity: 0.55;
    cursor: not-allowed;
}

.demo-chat-footer {
    padding: 0.75rem;
    border-top: 1px solid #e5e7eb;
    background: #fff;
}

.demo-chat-undo-row {
    margin-bottom: 0.625rem;
}

.demo-chat-undo-row.hidden {
    display: none;
}

.demo-chat-undo-btn {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid #fca5a5;
    background: #fef2f2;
    color: #b91c1c;
    border-radius: 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
}

.demo-chat-undo-btn:hover {
    background: #fee2e2;
}

.demo-chat-undo-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.demo-chat-input-row {
    display: flex;
    gap: 0.5rem;
}

.demo-chat-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
}

.demo-chat-input:focus {
    outline: none;
    border-color: var(--demo-chat-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.demo-chat-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 10px;
    background: var(--demo-chat-accent);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.demo-chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.demo-chat-send svg {
    width: 18px;
    height: 18px;
}

.demo-chat-order {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.demo-chat-order.hidden {
    display: none;
}

.demo-chat-order-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--demo-chat-text);
    margin-bottom: 0.25rem;
}

.demo-chat-order label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--demo-chat-muted);
}

.demo-chat-order input,
.demo-chat-order textarea {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 0.5rem 0.625rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--demo-chat-text);
}

.demo-chat-order-submit {
    margin-top: 0.375rem;
    padding: 0.75rem;
    border: none;
    border-radius: 10px;
    background: var(--demo-chat-accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.demo-chat-order-back {
    padding: 0.625rem;
    border: none;
    background: transparent;
    color: var(--demo-chat-muted);
    cursor: pointer;
    font-size: 0.8125rem;
}

@media (max-width: 480px) {
    .demo-chat-toggle-label {
        display: none;
    }

    .demo-chat-panel {
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
    }
}
