.ai-handoff {
    --ai-menu-bg: #ffffff;
    --ai-menu-soft: #f2f4f6;
    --ai-menu-text: #191c1e;
    --ai-menu-muted: #5d6b7a;
    --ai-menu-line: rgba(25, 28, 30, 0.13);
    position: relative;
    z-index: 30;
    width: max-content;
    max-width: 100%;
    margin: -0.7rem auto 1.8rem;
    color: var(--ai-menu-text);
    text-align: left;
}

html.dark .ai-handoff {
    --ai-menu-bg: #1a1f24;
    --ai-menu-soft: #151a1e;
    --ai-menu-text: #f0f2f5;
    --ai-menu-muted: #9aa8b8;
    --ai-menu-line: rgba(255, 255, 255, 0.12);
}

.ai-handoff__buttons {
    display: inline-flex;
    min-height: 42px;
    border: 1px solid var(--ai-menu-line);
    border-radius: 11px;
    background: color-mix(in srgb, var(--ai-menu-bg) 94%, transparent);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

.ai-handoff button {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.ai-handoff__primary {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 42px;
    padding: 0.55rem 0.9rem;
    font-size: 0.88rem;
    font-weight: 650;
}

.ai-handoff__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    min-height: 42px;
    border-left: 1px solid var(--ai-menu-line) !important;
    color: var(--ai-menu-muted) !important;
}

.ai-handoff__primary:hover,
.ai-handoff__toggle:hover,
.ai-handoff__item:hover,
.ai-handoff__item:focus-visible {
    background: var(--ai-menu-soft);
}

.ai-handoff button:focus-visible {
    outline: 2px solid var(--primary, #22c55e);
    outline-offset: -2px;
}

.ai-handoff__toggle svg {
    width: 15px;
    height: 15px;
    transition: transform 0.18s ease;
}

.ai-handoff__toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.ai-handoff__provider-icon {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--ai-menu-line);
    border-radius: 8px;
    background: var(--ai-menu-soft);
    color: var(--ai-menu-text);
}

.ai-handoff__provider-icon img {
    display: block;
    width: 20px;
    height: 20px;
    object-fit: contain;
}

[data-ai-provider="chatgpt"] .ai-handoff__provider-icon,
[data-ai-provider="grok"] .ai-handoff__provider-icon {
    border-color: rgba(255, 255, 255, 0.12);
    background: #0d0d0d;
}

.ai-handoff__action-icon svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.ai-handoff__primary .ai-handoff__provider-icon {
    width: 23px;
    height: 23px;
    border: 0;
    background: #0d0d0d;
}

.ai-handoff__menu {
    position: absolute;
    top: calc(100% + 0.55rem);
    left: 50%;
    width: min(370px, calc(100vw - 2rem));
    padding: 0.45rem;
    border: 1px solid var(--ai-menu-line);
    border-radius: 14px;
    background: var(--ai-menu-bg);
    box-shadow: 0 22px 65px rgba(0, 0, 0, 0.22);
    transform: translateX(-50%);
}

.ai-handoff__menu[hidden] {
    display: none;
}

.ai-handoff__item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-height: 54px;
    padding: 0.5rem 0.6rem;
    border-radius: 9px;
    text-align: left;
}

.ai-handoff__item-copy {
    min-width: 0;
}

.ai-handoff__item-title,
.ai-handoff__item-description {
    display: block;
}

.ai-handoff__item-title {
    color: var(--ai-menu-text);
    font-size: 0.88rem;
    font-weight: 680;
    line-height: 1.25;
}

.ai-handoff__item-description {
    margin-top: 0.12rem;
    color: var(--ai-menu-muted);
    font-size: 0.73rem;
    line-height: 1.3;
}

.ai-handoff__external {
    color: var(--ai-menu-muted);
    font-size: 0.88rem;
}

.ai-handoff__separator {
    height: 1px;
    margin: 0.35rem 0.45rem;
    background: var(--ai-menu-line);
}

.ai-handoff__status {
    position: absolute;
    top: calc(100% + 0.45rem);
    left: 50%;
    width: max-content;
    max-width: calc(100vw - 2rem);
    padding: 0.35rem 0.65rem;
    border: 1px solid var(--ai-menu-line);
    border-radius: 999px;
    background: var(--ai-menu-bg);
    color: var(--ai-menu-muted);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
    font-size: 0.72rem;
    transform: translateX(-50%);
}

.ai-handoff__status:empty {
    display: none;
}

@media (max-width: 520px) {
    .ai-handoff {
        margin-bottom: 1.5rem;
    }

    .ai-handoff__menu {
        position: fixed;
        top: auto;
        right: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        left: 0.75rem;
        width: auto;
        max-height: min(78vh, 590px);
        overflow-y: auto;
        transform: none;
    }

    .ai-handoff__status {
        position: fixed;
        top: auto;
        bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-handoff__toggle svg {
        transition: none;
    }
}
