.cm-ai-widget {
    --cm-ai-accent: #0b63f6;
    --cm-ai-accent-strong: #064ec6;
    --cm-ai-highlight: #f7b500;
    --cm-ai-surface: #ffffff;
    --cm-ai-surface-soft: #f4f7fb;
    --cm-ai-text: #12213a;
    --cm-ai-muted: #61708a;
    --cm-ai-border: #dbe3ee;
    --cm-ai-shadow: 0 18px 48px rgba(16, 31, 56, .22);
    position: fixed;
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 1090;
    font-family: inherit;
    color: var(--cm-ai-text);
}

.cm-ai-widget[hidden],
.cm-ai-panel[hidden],
.cm-ai-typing[hidden] {
    display: none !important;
}

.cm-ai-trigger {
    width: 58px;
    height: 58px;
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--cm-ai-accent);
    color: #ffffff;
    box-shadow: 0 12px 28px rgba(11, 99, 246, .34);
    cursor: pointer;
    transition: background-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.cm-ai-trigger:hover,
.cm-ai-trigger:focus-visible {
    background: var(--cm-ai-accent-strong);
    box-shadow: 0 15px 32px rgba(11, 99, 246, .42);
    transform: translateY(-2px);
    outline: none;
}

.cm-ai-trigger .material-icons {
    font-size: 27px;
}

.cm-ai-trigger-close {
    display: none;
}

.cm-ai-widget.is-open .cm-ai-trigger-open {
    display: none;
}

.cm-ai-widget.is-open .cm-ai-trigger-close {
    display: inline-block;
}

.cm-ai-widget.is-open .cm-ai-trigger {
    display: none;
}

.cm-ai-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: min(378px, calc(100vw - 32px));
    height: min(570px, calc(100vh - 118px));
    min-height: 430px;
    border: 1px solid var(--cm-ai-border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--cm-ai-surface);
    box-shadow: var(--cm-ai-shadow);
}

.cm-ai-widget.is-open .cm-ai-panel {
    bottom: 0;
}

.cm-ai-header {
    min-height: 68px;
    padding: 12px 12px 12px 15px;
    border-bottom: 1px solid var(--cm-ai-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #172235;
    color: #ffffff;
}

.cm-ai-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cm-ai-heading > div {
    min-width: 0;
}

.cm-ai-heading strong,
.cm-ai-heading span:not(.material-icons) {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cm-ai-heading strong {
    font-size: 1rem;
    line-height: 1.25;
}

.cm-ai-heading span:not(.material-icons) {
    margin-top: 2px;
    color: rgba(255, 255, 255, .72);
    font-size: .76rem;
    line-height: 1.2;
}

.cm-ai-mark {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
    background: var(--cm-ai-highlight);
    color: #172235;
    font-size: 20px;
}

.cm-ai-icon-button,
.cm-ai-send {
    border: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.cm-ai-icon-button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex: 0 0 38px;
    background: rgba(255, 255, 255, .09);
    color: #ffffff;
}

.cm-ai-icon-button:hover,
.cm-ai-icon-button:focus-visible {
    background: rgba(255, 255, 255, .18);
    outline: none;
}

.cm-ai-icon-button .material-icons {
    font-size: 21px;
}

.cm-ai-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--cm-ai-surface-soft);
    scrollbar-width: thin;
}

.cm-ai-message {
    width: fit-content;
    max-width: 88%;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--cm-ai-border);
    border-radius: 8px;
    background: var(--cm-ai-surface);
    color: var(--cm-ai-text);
    box-shadow: 0 3px 10px rgba(22, 34, 53, .06);
}

.cm-ai-message-user {
    margin-left: auto;
    border-color: var(--cm-ai-accent);
    background: var(--cm-ai-accent);
    color: #ffffff;
}

.cm-ai-message-system {
    width: 100%;
    max-width: 100%;
    border-style: dashed;
    background: transparent;
    color: var(--cm-ai-muted);
    box-shadow: none;
    text-align: center;
}

.cm-ai-message-error {
    border-color: #efb7b7;
    background: #fff3f3;
    color: #8b2020;
}

.cm-ai-message-label {
    margin-bottom: 4px;
    color: var(--cm-ai-muted);
    font-size: .69rem;
    font-weight: 800;
    line-height: 1.2;
    text-transform: uppercase;
}

.cm-ai-message-user .cm-ai-message-label {
    color: rgba(255, 255, 255, .74);
}

.cm-ai-message-text {
    font-size: .91rem;
    line-height: 1.48;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.cm-ai-section-link {
    width: 100%;
    margin-top: 9px;
    padding: 8px 0 0;
    border: 0;
    border-top: 1px solid var(--cm-ai-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: transparent;
    color: var(--cm-ai-accent-strong);
    font-size: .82rem;
    font-weight: 800;
    text-align: left;
    cursor: pointer;
}

.cm-ai-section-link:hover,
.cm-ai-section-link:focus-visible {
    color: var(--cm-ai-accent);
    outline: none;
}

.cm-ai-section-link .material-icons {
    flex: 0 0 auto;
    font-size: 18px;
}

.cm-ai-handoff-button {
    width: 100%;
    min-height: 38px;
    margin-top: 10px;
    padding: 8px 10px;
    border: 1px solid #0f766e;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    background: #ffffff;
    color: #0f625c;
    font: inherit;
    font-size: .82rem;
    font-weight: 800;
    cursor: pointer;
}

.cm-ai-handoff-button:hover,
.cm-ai-handoff-button:focus-visible {
    background: #e9f8f5;
    outline: none;
}

.cm-ai-handoff-button:disabled {
    cursor: wait;
    opacity: .6;
}

.cm-ai-handoff-button .material-icons {
    font-size: 19px;
}

.cm-ai-widget.is-human-mode .cm-ai-mark {
    background: #50d5c6;
}

.cm-ai-typing {
    padding: 8px 16px 4px;
    background: var(--cm-ai-surface-soft);
}

.cm-ai-typing > span:not(.sr-only) {
    width: 6px;
    height: 6px;
    margin-right: 3px;
    border-radius: 50%;
    display: inline-block;
    background: var(--cm-ai-muted);
    animation: cm-ai-pulse 1.1s infinite ease-in-out;
}

.cm-ai-typing > span:nth-child(2) {
    animation-delay: .14s;
}

.cm-ai-typing > span:nth-child(3) {
    animation-delay: .28s;
}

@keyframes cm-ai-pulse {
    0%, 60%, 100% { opacity: .32; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.cm-ai-composer {
    padding: 10px;
    border-top: 1px solid var(--cm-ai-border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px;
    align-items: end;
    gap: 8px;
    background: var(--cm-ai-surface);
}

.cm-ai-composer textarea {
    width: 100%;
    min-height: 42px;
    max-height: 112px;
    padding: 10px 11px;
    border: 1px solid var(--cm-ai-border);
    border-radius: 6px;
    resize: none;
    overflow-y: auto;
    background: var(--cm-ai-surface);
    color: var(--cm-ai-text);
    font: inherit;
    font-size: .9rem;
    line-height: 1.4;
}

.cm-ai-composer textarea:focus {
    border-color: var(--cm-ai-accent);
    box-shadow: 0 0 0 3px rgba(11, 99, 246, .12);
    outline: none;
}

.cm-ai-send {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    background: var(--cm-ai-accent);
    color: #ffffff;
}

.cm-ai-send:hover,
.cm-ai-send:focus-visible {
    background: var(--cm-ai-accent-strong);
    outline: none;
}

.cm-ai-send:disabled,
.cm-ai-composer textarea:disabled {
    cursor: wait;
    opacity: .62;
}

.cm-ai-send .material-icons {
    font-size: 20px;
}

.cm-ai-note {
    margin: 0;
    padding: 0 12px 10px;
    background: var(--cm-ai-surface);
    color: var(--cm-ai-muted);
    font-size: .67rem;
    line-height: 1.35;
    text-align: center;
}

@media (prefers-color-scheme: dark) {
    .cm-ai-widget {
        --cm-ai-surface: #172235;
        --cm-ai-surface-soft: #0f1827;
        --cm-ai-text: #eef4ff;
        --cm-ai-muted: #a7b4c8;
        --cm-ai-border: #34435a;
        --cm-ai-shadow: 0 20px 54px rgba(0, 0, 0, .5);
    }

    .cm-ai-message-error {
        border-color: #824747;
        background: #3a2025;
        color: #ffd6d6;
    }

    .cm-ai-handoff-button {
        background: #172235;
        color: #7be0d5;
    }
}

[data-theme="dark"] .cm-ai-widget,
body.dark .cm-ai-widget,
body.dark-mode .cm-ai-widget {
    --cm-ai-surface: #172235;
    --cm-ai-surface-soft: #0f1827;
    --cm-ai-text: #eef4ff;
    --cm-ai-muted: #a7b4c8;
    --cm-ai-border: #34435a;
    --cm-ai-shadow: 0 20px 54px rgba(0, 0, 0, .5);
}

[data-theme="dark"] .cm-ai-handoff-button,
body.dark .cm-ai-handoff-button,
body.dark-mode .cm-ai-handoff-button {
    background: #172235;
    color: #7be0d5;
}

@media (max-width: 575.98px) {
    .cm-ai-widget {
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    .cm-ai-panel {
        position: fixed;
        right: 10px;
        bottom: max(10px, env(safe-area-inset-bottom));
        left: 10px;
        width: auto;
        height: min(700px, calc(100vh - 20px));
        height: min(700px, calc(100dvh - 20px));
        min-height: 380px;
    }

    .cm-ai-composer textarea {
        font-size: 16px;
    }

    .cm-ai-trigger {
        width: 54px;
        height: 54px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cm-ai-trigger,
    .cm-ai-typing > span:not(.sr-only) {
        transition: none;
        animation: none;
    }
}
