.wf-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    border: 0;
    padding: 0;
    white-space: nowrap;
    clip-path: inset(50%);
    clip: rect(0 0 0 0);
    overflow: hidden;
}

:root {
    --wf-chat-bg: #ffffff;
    --wf-chat-surface: #ffffff;
    --wf-chat-surface-alt: #f7f9fc;
    --wf-chat-text: #0f172a;
    --wf-chat-text-strong: #0b1220;
    --wf-chat-muted: #475569;
    --wf-chat-line: #e2e8f0;
    --wf-chat-line-strong: #cbd5e1;
    --wf-chat-primary: #0f3d91;
    --wf-chat-primary-strong: #0a2f75;
    --wf-chat-primary-soft: #eef2ff;
    --wf-chat-accent: #0e7490;
    --wf-chat-user-bg: #0f3d91;
    --wf-chat-user-text: #ffffff;
    --wf-chat-shadow: -18px 0 60px rgba(15, 23, 42, 0.22);
}

/* Trigger stays anchored to bottom-right of viewport */
.wf-ai-chat {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1100;
    font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
}

.wf-ai-chat__trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(130deg, var(--wf-chat-accent), var(--wf-chat-primary));
    color: #fff;
    box-shadow: 0 16px 38px rgba(15, 61, 145, 0.34);
    padding: 0.78rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.015em;
    cursor: pointer;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.wf-ai-chat__trigger:hover,
.wf-ai-chat__trigger:focus {
    transform: translateY(-1px);
    box-shadow: 0 20px 44px rgba(15, 61, 145, 0.42);
    outline: none;
}

.wf-ai-chat__trigger-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: #9df5d8;
    box-shadow: 0 0 0 0 rgba(157, 245, 216, 0.55);
    animation: wfPulse 1.8s infinite;
}

.wf-ai-chat__unread {
    display: inline-grid;
    place-items: center;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.3rem;
    border: 2px solid #ffffff;
    border-radius: 999px;
    background: #dc2626;
    color: #ffffff;
    font-size: 0.72rem;
    line-height: 1;
}

.wf-ai-chat__unread[hidden],
.wf-ai-chat__reply-alert[hidden],
.wf-ai-chat__notice[hidden],
.wf-ai-chat__plans[hidden] {
    display: none !important;
}

.wf-ai-chat__trigger.has-unread {
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.18), 0 16px 38px rgba(15, 61, 145, 0.34);
}

.wf-ai-chat__reply-alert {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.65rem);
    width: min(20rem, calc(100vw - 2rem));
    border: 1px solid #bfdbfe;
    border-radius: 0.65rem;
    background: #ffffff;
    color: #0f172a;
    padding: 0.75rem 0.85rem;
    box-shadow: 0 14px 35px rgba(15, 23, 42, 0.2);
    text-align: left;
    cursor: pointer;
}

.wf-ai-chat__reply-alert strong,
.wf-ai-chat__reply-alert span {
    display: block;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

.wf-ai-chat__reply-alert span {
    margin-top: 0.2rem;
    color: #475569 !important;
    -webkit-text-fill-color: #475569 !important;
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@keyframes wfPulse {
    0% { box-shadow: 0 0 0 0 rgba(157, 245, 216, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(157, 245, 216, 0); }
    100% { box-shadow: 0 0 0 0 rgba(157, 245, 216, 0); }
}

/* -------- Offcanvas backdrop -------- */
.wf-ai-chat__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1190;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}

.wf-ai-chat__backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* -------- Offcanvas panel (right-to-left slide-in) -------- */
.wf-ai-chat__panel {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    height: min(44rem, calc(100dvh - 2rem));
    width: min(26rem, calc(100vw - 2rem));
    background: var(--wf-chat-surface);
    color: var(--wf-chat-text);
    border-left: 1px solid var(--wf-chat-line);
    box-shadow: var(--wf-chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: 1200;
    transform: translateX(calc(100% + 2rem));
    transition: transform 0.36s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    margin: 0;
    border-radius: 0.75rem;
    opacity: 1;
}

/* Neutralize the HTML5 hidden attribute so we can animate the transform */
.wf-ai-chat__panel[hidden] {
    display: flex !important;
    transform: translateX(calc(100% + 2rem));
    pointer-events: none;
}

.wf-ai-chat__panel:not([hidden]) {
    transform: translateX(0);
    pointer-events: auto;
}

.wf-ai-chat__header {
    background: var(--wf-chat-surface);
    color: var(--wf-chat-text-strong);
    padding: 0.9rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    border-bottom: 1px solid var(--wf-chat-line);
    flex-shrink: 0;
}

.wf-ai-chat__notice {
    margin: 0.7rem 1rem 0;
    border: 1px solid #86efac;
    border-radius: 0.6rem;
    background: #f0fdf4;
    color: #14532d;
    padding: 0.65rem 0.7rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: 0.55rem;
    flex-shrink: 0;
}

.wf-ai-chat__notice.is-pending {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
}

.wf-ai-chat__notice.is-error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.wf-ai-chat__notice-icon {
    display: grid;
    place-items: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: #15803d;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    font-size: 0.75rem;
    font-weight: 800;
}

.wf-ai-chat__notice.is-pending .wf-ai-chat__notice-icon {
    background: #1d4ed8;
}

.wf-ai-chat__notice.is-error .wf-ai-chat__notice-icon {
    background: #b91c1c;
}

.wf-ai-chat__notice > span:not(.wf-ai-chat__notice-icon),
.wf-ai-chat__notice > span:not(.wf-ai-chat__notice-icon) strong,
.wf-ai-chat__notice > span:not(.wf-ai-chat__notice-icon) span {
    color: inherit !important;
    -webkit-text-fill-color: currentColor !important;
}

.wf-ai-chat__notice strong,
.wf-ai-chat__notice span span {
    display: block;
}

.wf-ai-chat__notice span span {
    margin-top: 0.12rem;
    font-size: 0.76rem;
    line-height: 1.35;
}

.wf-ai-chat__notice button {
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

.wf-ai-chat__header h3 {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 700;
    letter-spacing: 0.005em;
    color: #111827 !important;
}

.wf-ai-chat__header p {
    margin: 0.32rem 0 0;
    font-size: 0.82rem;
    color: #334155 !important;
    line-height: 1.4;
}

.wf-ai-chat__live-status {
    margin-top: 0.62rem;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border: 1px solid #dbe3ef;
    border-radius: 999px;
    background: #f8fafc;
    color: #1f2937;
    font-size: 0.76rem;
    font-weight: 700;
    padding: 0.28rem 0.56rem;
}

.wf-ai-chat__live-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #94a3b8;
}

.wf-ai-chat__live-status.is-waiting {
    border-color: #f5d7a1;
    background: #fff9eb;
    color: #7c4a03;
}

.wf-ai-chat__live-status.is-waiting .wf-ai-chat__live-dot {
    background: #f59e0b;
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45);
    animation: wfLivePulse 1.5s infinite;
}

.wf-ai-chat__live-status.is-connected {
    border-color: #bfe9cf;
    background: #effcf4;
    color: #14532d;
}

.wf-ai-chat__live-status.is-connected .wf-ai-chat__live-dot {
    background: #16a34a;
}

@keyframes wfLivePulse {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.wf-ai-chat__close {
    border: 1px solid var(--wf-chat-line-strong);
    border-radius: 0.5rem;
    background: var(--wf-chat-surface-alt);
    color: var(--wf-chat-text);
    width: 2.1rem;
    height: 2.1rem;
    font-size: 1.36rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.wf-ai-chat__close:hover,
.wf-ai-chat__close:focus {
    background: var(--wf-chat-primary-soft);
    border-color: var(--wf-chat-primary);
    outline: none;
}

/* Messages area grows to fill remaining space */
.wf-ai-chat__messages {
    min-height: 0;
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.72rem;
    background: var(--wf-chat-surface);
    opacity: 1 !important;
}

.wf-ai-msg {
    max-width: 88%;
    background: linear-gradient(130deg, var(--wf-chat-accent), var(--wf-chat-primary));
    border-radius: 0.9rem;
    padding: 0.72rem 0.88rem;
    font-size: 0.93rem;
    line-height: 1.55;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    opacity: 1 !important;
}

.wf-ai-msg p {
    margin: 0;
    white-space: pre-wrap;
    color: inherit !important;
    font-weight: 500;
    opacity: 1 !important;
}

.wf-ai-msg__link {
    display: inline-block;
    margin-top: 0.55rem;
    border-radius: 0.5rem;
    background: var(--wf-chat-primary);
    color: #ffffff !important;
    padding: 0.5rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    -webkit-text-fill-color: #ffffff !important;
}

.wf-ai-msg__link:hover,
.wf-ai-msg__link:focus {
    background: var(--wf-chat-primary-strong);
    color: #ffffff !important;
    text-decoration: none;
    outline: none;
}

.wf-ai-msg--assistant {
    background: #ffffff !important;
    border: 1px solid #d9e1ec !important;
    color: #0b0b0b !important;
    align-self: flex-start;
    border-bottom-left-radius: 0.3rem;
}

#wfAiChatPanel .wf-ai-msg--assistant,
#wfAiChatPanel .wf-ai-msg--assistant p * {
    color: #000 !important;
    opacity: 1 !important;
    -webkit-text-fill-color: #000 !important;
}
.wf-ai-msg--user {
    background: var(--wf-chat-user-bg);
    border: 1px solid var(--wf-chat-user-bg);
    color: var(--wf-chat-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 0.3rem;
}

.wf-ai-msg--user p {
    color: var(--wf-chat-user-text);
}

.wf-ai-chat__actions {
    padding: 0.6rem 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--wf-chat-surface);
    border-top: 1px solid var(--wf-chat-line);
    flex-shrink: 0;
}

.wf-ai-chat__actions button {
    border: 1px solid var(--wf-chat-line-strong);
    background: var(--wf-chat-surface);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--wf-chat-text-strong);
    padding: 0.52rem 0.92rem;
    letter-spacing: 0.008em;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.wf-ai-chat__actions button:hover,
.wf-ai-chat__actions button:focus {
    background: var(--wf-chat-primary-soft);
    border-color: var(--wf-chat-primary);
    color: var(--wf-chat-primary);
    outline: none;
}

.wf-ai-chat__composer {
    border-top: 1px solid var(--wf-chat-line);
    padding: 0.75rem 1rem;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.55rem;
    background: var(--wf-chat-surface);
    flex-shrink: 0;
}

.wf-ai-chat__composer textarea,
.wf-ai-chat__lead textarea,
.wf-ai-chat__lead input,
.wf-ai-chat__lead select {
    width: 100%;
    border: 1px solid var(--wf-chat-line-strong);
    border-radius: 0.55rem;
    font-size: 0.93rem;
    color: #0f172a !important; 
    padding: 0.58rem 0.68rem;
    resize: vertical;
    background: var(--wf-chat-surface);
    line-height: 1.45;
}

.wf-ai-chat__composer textarea::placeholder,
.wf-ai-chat__lead textarea::placeholder,
.wf-ai-chat__lead input::placeholder {
    color: #64748b !important;
}

.wf-ai-chat__composer textarea:focus,
.wf-ai-chat__lead textarea:focus,
.wf-ai-chat__lead input:focus,
.wf-ai-chat__lead select:focus {
    outline: none;
    border-color: var(--wf-chat-primary);
    box-shadow: 0 0 0 3px rgba(15, 61, 145, 0.15);
}

.wf-ai-chat__composer button,
.wf-ai-chat__lead-actions button {
    border: 0;
    border-radius: 0.55rem;
    background: var(--wf-chat-primary);
    color: #fff;
    font-size: 0.86rem;
    font-weight: 700;
    padding: 0.6rem 1rem;
    min-height: 2.4rem;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.16s ease;
}

.wf-ai-chat__composer button:hover,
.wf-ai-chat__lead-actions button:hover {
    background: var(--wf-chat-primary-strong);
    transform: translateY(-1px);
}

/* Forms are dedicated panel views, not content stacked below the conversation. */
.wf-ai-chat__lead {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem;
    background: var(--wf-chat-surface);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.wf-ai-chat__lead h4 {
    font-size: 1.02rem;
    margin: 0 0 0.75rem;
    color: var(--wf-chat-text-strong);
    letter-spacing: 0.01em;
}

.wf-ai-chat__form-heading p {
    margin: -0.35rem 0 0.85rem;
    color: var(--wf-chat-muted);
    font-size: 0.82rem;
    line-height: 1.4;
}

.wf-ai-chat__lead-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

.wf-ai-chat__lead label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--wf-chat-text);
    margin-bottom: 0.6rem;
}

.wf-ai-chat__lead-inline {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.5rem;
}

.wf-checkbox {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--wf-chat-text);
}

.wf-checkbox input {
    width: auto;
    margin-top: 0.2rem;
}

.wf-ai-chat__lead-actions {
    margin-top: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.wf-ai-chat__secondary {
    background: var(--wf-chat-surface) !important;
    color: var(--wf-chat-text-strong) !important;
    border: 1px solid var(--wf-chat-line-strong) !important;
}

.wf-ai-chat__secondary:hover {
    background: var(--wf-chat-primary-soft) !important;
    border-color: var(--wf-chat-primary) !important;
    color: var(--wf-chat-primary) !important;
}

.wf-ai-chat__lead[hidden] {
    display: none !important;
}

.wf-ai-chat__plans {
    flex: 1 1 auto;
    min-height: 0;
    padding: 1rem;
    overflow-y: auto;
    background: #ffffff;
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

.wf-ai-chat__plans-heading > span {
    color: #0e7490 !important;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
}

.wf-ai-chat__plans-heading h4 {
    margin: 0.2rem 0 0;
    color: #0f172a !important;
    font-size: 1.08rem;
}

.wf-ai-chat__plans-heading p,
.wf-ai-chat__plans-empty {
    margin: 0.3rem 0 0.85rem;
    color: #475569 !important;
    font-size: 0.82rem;
}

.wf-ai-chat__plan-list {
    display: grid;
    gap: 0.55rem;
}

.wf-ai-chat__plan {
    border: 1px solid #dbe3ef;
    border-radius: 0.55rem;
    background: #ffffff;
    padding: 0.72rem;
}

.wf-ai-chat__plan strong,
.wf-ai-chat__plan p,
.wf-ai-chat__plan span {
    color: #0f172a !important;
    -webkit-text-fill-color: #0f172a !important;
}

.wf-ai-chat__plan p {
    margin: 0.2rem 0 0;
    color: #475569 !important;
    -webkit-text-fill-color: #475569 !important;
    font-size: 0.76rem;
    line-height: 1.35;
}

.wf-ai-chat__plan-action {
    margin-top: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.wf-ai-chat__plan-action span {
    font-size: 0.78rem;
    font-weight: 800;
}

.wf-ai-chat__plan-action a {
    border-radius: 0.45rem;
    background: var(--wf-chat-primary);
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    padding: 0.46rem 0.65rem;
    font-size: 0.76rem;
    font-weight: 800;
    text-decoration: none;
}

.wf-ai-chat__plan-actions {
    margin-top: 0.75rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
}

.wf-ai-chat__plan-actions button {
    min-height: 2.4rem;
    border: 0;
    border-radius: 0.55rem;
    background: var(--wf-chat-primary);
    color: #ffffff;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}

.wf-ai-chat__panel.is-form-view .wf-ai-chat__messages,
.wf-ai-chat__panel.is-form-view .wf-ai-chat__actions,
.wf-ai-chat__panel.is-form-view .wf-ai-chat__composer,
.wf-ai-chat__panel.is-form-view .wf-ai-chat__footer,
.wf-ai-chat__panel.is-plans-view .wf-ai-chat__messages,
.wf-ai-chat__panel.is-plans-view .wf-ai-chat__actions,
.wf-ai-chat__panel.is-plans-view .wf-ai-chat__composer,
.wf-ai-chat__panel.is-plans-view .wf-ai-chat__footer {
    display: none;
}

.wf-ai-chat__lead[aria-busy="true"] {
    cursor: progress;
}

.wf-ai-chat__lead[aria-busy="true"] button[type="submit"] {
    opacity: 0.82;
}

.wf-ai-chat__footer {
    border-top: 1px solid var(--wf-chat-line);
    padding: 0.7rem 1.15rem 0.85rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    background: var(--wf-chat-surface);
    flex-shrink: 0;
}

.wf-ai-chat__footer a {
    font-size: 0.582rem;
    font-weight: 700;
    color: var(--wf-chat-primary);
    text-decoration: none;
    border-bottom: 1px dashed transparent;
    transition: color 0.18s ease, border-color 0.18s ease;
}

.wf-ai-chat,
.wf-ai-chat * {
    text-shadow: none !important;
}

#wfAiChatPanel,
#wfAiChatPanel .wf-ai-chat__messages,
#wfAiChatPanel .wf-ai-msg,
#wfAiChatPanel .wf-ai-msg--assistant,
#wfAiChatPanel .wf-ai-msg--assistant p,
#wfAiChatPanel .wf-ai-chat__header,
#wfAiChatPanel .wf-ai-chat__header h3,
#wfAiChatPanel .wf-ai-chat__header p,
#wfAiChatPanel .wf-ai-chat__composer textarea,
#wfAiChatPanel .wf-ai-chat__composer textarea::placeholder {
    filter: none !important;
    opacity: 1 !important;
}

#wfAiChatPanel .wf-ai-msg--assistant p {
    color: #0b0b0b !important;
    -webkit-text-fill-color: #000 !important;
}

.wf-ai-chat__footer a:hover,
.wf-ai-chat__footer a:focus {
    color: var(--wf-chat-primary-strong);
    border-color: var(--wf-chat-primary-strong);
}

.wf-ai-chat__messages::-webkit-scrollbar,
.wf-ai-chat__lead::-webkit-scrollbar {
    width: 10px;
}

.wf-ai-chat__messages::-webkit-scrollbar-track,
.wf-ai-chat__lead::-webkit-scrollbar-track {
    background: transparent;
}

.wf-ai-chat__messages::-webkit-scrollbar-thumb,
.wf-ai-chat__lead::-webkit-scrollbar-thumb {
    background: var(--wf-chat-line-strong);
    border: 2px solid transparent;
    border-radius: 99px;
    background-clip: content-box;
}

@media (max-width: 767px) {
    .wf-ai-chat {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .wf-ai-chat__panel {
        top: 0;
        right: 0;
        bottom: 0;
        height: 100dvh;
        width: 100vw;
        border-radius: 0;
    }

    body.wf-ai-chat-open {
        overflow: hidden;
    }

    .wf-ai-chat__lead-grid {
        grid-template-columns: 1fr;
    }

    .wf-ai-chat__composer {
        grid-template-columns: 1fr;
    }

    .wf-ai-chat__composer button {
        width: 100%;
    }

    .wf-ai-chat__footer {
        gap: 0.85rem;
        flex-wrap: wrap;
    }
}
