/* ===========================
   ORBYT CHATBOT — Resilient Orbit widget
   Launcher bottom-left (back-to-top owns bottom-right)
   =========================== */

.orbit-launcher {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-full);
    background: transparent;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    /* above the cookie banner (9999) so the robot is visible on first paint */
    z-index: 10000;
    cursor: pointer;
    filter: drop-shadow(0 6px 18px rgba(0, 212, 255, 0.35));
    /* hidden until chatbot.js starts the spawn sequence (post-loader) */
    opacity: 0;
    visibility: hidden;
    transition: transform var(--transition-base) var(--ease-bounce),
                filter var(--transition-fast),
                opacity var(--transition-base),
                visibility var(--transition-base);
}

.orbit-launcher.is-ready {
    opacity: 1;
    visibility: visible;
}

.orbit-launcher:hover {
    transform: perspective(300px) rotateX(10deg) rotateY(-12deg) scale(1.1);
    filter: drop-shadow(0 10px 26px rgba(0, 212, 255, 0.55));
}

.orbit-launcher:active {
    transform: scale(0.94);
}

.orbit-launcher:focus-visible {
    /* two-tone ring: navy holds >=3:1 on light surfaces, yellow on dark */
    outline: 3px solid var(--color-navy);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px var(--color-yellow);
}

.orbit-launcher svg {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
}

/* ── Transformer ARC mark ──
   One SVG of persistent parts. data-tf="1..4" on the launcher / avatar picks
   the state; every robot part is the flip-reveal destination of a badge part,
   so the pieces visibly travel, swing and flip between forms:
     apex(+eyes) → monitor head   A legs → arms   swoosh → collapses under the
     expanding torso   disc shell → cracks, slides away, leaves the open ring
   Delays inside a state rule stagger arrivals when ENTERING that state. */
.tf-logo {
    display: block;
}

.orbit-launcher .tf-logo {
    animation: tf-bob 5.5s ease-in-out infinite;
}

@keyframes tf-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}

/* satellite on the ring — slow quiet revolution while the badge is at rest */
.tf-orbiter {
    transform-box: view-box;
    transform-origin: 50% 50%;
    animation: tf-orbit 16s linear infinite;
    transition: opacity 0.25s ease;
}

[data-tf="3"] .tf-orbiter,
[data-tf="4"] .tf-orbiter {
    opacity: 0;
}

@keyframes tf-orbit {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* shared motion defaults — arrivals bounce, departures cut sharper */
.tf-shell-l,
.tf-shell-r,
.tf-swoosh,
.tf-torso,
.tf-arm-l,
.tf-arm-r,
.tf-leg-l,
.tf-leg-r,
.tf-apex,
.tf-head {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    transition: transform 0.34s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.3s ease,
                visibility 0.34s;
}

/* ══ state 1 (default): the three A-pieces + swoosh assemble the badge;
      robot parts wait collapsed (zero-size — nothing can ghost) ══ */
.tf-torso {
    transform-origin: 50% 55%;
    transform: scaleY(0);
}

.tf-arm-l {
    transform-origin: 100% 12%;
    transform: scaleX(0);
}

.tf-arm-r {
    transform-origin: 0% 12%;
    transform: scaleX(0);
}

.tf-head {
    transform-origin: 50% 100%;
    transform: scaleY(0);
}

.tf-leg-l { transform-origin: 85% 8%; }
.tf-leg-r { transform-origin: 15% 8%; }

.tf-eyes {
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* energy core: covered by the closed shell at rest, revealed by the crack */
.tf-core {
    transition: opacity 0.25s ease;
}

[data-tf="4"] .tf-core { opacity: 0; }

/* ══ state 2: eyes ignite, the pieces loosen — a breath before unfolding ══ */
[data-tf="2"] .tf-eyes,
[data-tf="3"] .tf-eyes {
    opacity: 1;
}

/* apex grows upward from its base — taller, pointier A, no gap */
[data-tf="2"] .tf-apex {
    transform-origin: 50% 100%;
    transform: scaleY(1.08);
}

[data-tf="2"] .tf-leg-l { transform: rotate(-1.5deg); }
[data-tf="2"] .tf-leg-r { transform: rotate(1.5deg); }

/* ══ state 3: shell cracks, apex rises as proto-head (eyes riding it),
      legs swing out as limbs, swoosh starts its sweep ══ */
[data-tf="3"] .tf-shell-l { transform: translateX(-2.5px); }
[data-tf="3"] .tf-shell-r { transform: translateX(2.5px); }

[data-tf="3"] .tf-leg-l {
    transform: translate(-4px, -1px) rotate(20deg);
    transition-delay: 0.08s;
}

[data-tf="3"] .tf-leg-r {
    transform: translate(4px, -1px) rotate(-20deg);
    transition-delay: 0.08s;
}

[data-tf="3"] .tf-apex {
    transform: translate(-4px, -16px);
    transition-delay: 0.14s;
}

/* torso core already growing behind the spread limbs */
[data-tf="3"] .tf-torso {
    transform-origin: 50% 60%;
    transform: scaleY(0.45);
    transition-delay: 0.18s;
}

[data-tf="3"] .tf-swoosh {
    transform: translateY(5px) rotate(9deg) scale(0.85);
    transition-delay: 0.1s;
}

/* ══ state 4: flip-reveals — each badge piece collapses flat exactly where
      its robot counterpart expands a beat later ══ */
[data-tf="4"] .tf-shell-l {
    transform: translateX(-13px);
    opacity: 0;
    visibility: hidden;
    transition-delay: 0.05s;
}

[data-tf="4"] .tf-shell-r {
    transform: translateX(13px);
    opacity: 0;
    visibility: hidden;
    transition-delay: 0.05s;
}

[data-tf="4"] .tf-apex {
    /* same head-slot position as state 3, flattening in place */
    transform: translate(-4px, -19px) scale(1.1, 0);
    transition-duration: 0.26s;
    transition-timing-function: ease-in;
}

[data-tf="4"] .tf-head {
    transform: scaleY(1);
    transition-delay: 0.3s;
}

[data-tf="4"] .tf-leg-l {
    transform: translate(-15px, 0) rotate(60deg) scale(0.5, 0);
    transition-duration: 0.3s;
    transition-timing-function: ease-in;
}

[data-tf="4"] .tf-leg-r {
    transform: translate(15px, 0) rotate(-60deg) scale(0.5, 0);
    transition-duration: 0.3s;
    transition-timing-function: ease-in;
}

[data-tf="4"] .tf-arm-l,
[data-tf="4"] .tf-arm-r {
    transform: scaleX(1);
    transition-delay: 0.3s;
}

[data-tf="4"] .tf-swoosh {
    transform: translateY(11px) scaleY(0);
    transition-duration: 0.3s;
    transition-timing-function: ease-in;
    transition-delay: 0.08s;
}

[data-tf="4"] .tf-torso {
    transform: scaleY(1);
    transition-delay: 0.22s;
}
.orbit-launcher__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 14px;
    height: 14px;
    border-radius: var(--radius-full);
    background: var(--color-coral);
    border: 2px solid var(--color-navy);
    animation: orbit-pulse 2.4s ease-in-out infinite;
}

@keyframes orbit-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.25); }
}

/* ── "Chat with Orbyt" pill label (shown by chatbot.js on early visits) ── */
.orbit-launcher__pill {
    position: absolute;
    left: calc(100% + 0.75rem);
    top: 50%;
    transform: translateY(-50%) translateX(-6px);
    white-space: nowrap;
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    font-weight: var(--font-semibold);
    color: var(--color-navy);
    background: var(--color-white);
    border: var(--border-medium) solid var(--color-navy);
    border-radius: var(--radius-full);
    padding: 0.4rem 0.875rem;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base) var(--ease-bounce),
                transform var(--transition-base) var(--ease-bounce),
                visibility var(--transition-base);
}

.orbit-launcher__pill.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(0);
}

/* ── Panel ── */
.orbit-panel {
    position: fixed;
    bottom: 6rem;
    left: 2rem;
    width: min(380px, calc(100vw - 2rem));
    max-height: min(560px, calc(100dvh - 8rem));
    display: flex;
    flex-direction: column;
    background: var(--color-white);
    border: var(--border-thick) solid var(--color-navy);
    border-radius: var(--radius-lg);
    box-shadow: 8px 8px 0 rgba(10, 37, 64, 0.9),
                0 20px 60px rgba(10, 37, 64, 0.25);
    z-index: 10001; /* one above the launcher, both above the cookie banner */
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.98);
    transition: opacity var(--transition-base) var(--ease-bounce),
                transform var(--transition-base) var(--ease-bounce),
                visibility var(--transition-base);
}

.orbit-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ── Header ── */
.orbit-panel__header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--color-navy);
    color: var(--color-white);
    border-bottom: var(--border-thick) solid var(--color-teal);
    flex-shrink: 0;
}

.orbit-panel__avatar {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(0, 212, 255, 0.35));
}

.orbit-panel__avatar svg {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-full);
}

.orbit-panel__title {
    font-family: var(--font-display);
    font-size: var(--fs-body);
    font-weight: var(--font-bold);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.orbit-panel__subtitle {
    font-size: var(--fs-xs);
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.3;
}

.orbit-panel__close {
    margin-left: auto;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background var(--transition-fast);
}

.orbit-panel__close:hover {
    color: var(--color-white);
    background: rgba(255, 255, 255, 0.1);
}

.orbit-panel__close:focus-visible {
    outline: 2px solid var(--color-teal);
    outline-offset: 2px;
}

.orbit-panel__close svg {
    width: 18px;
    height: 18px;
}

/* ── Messages ── */
.orbit-panel__messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--color-off-white, #f8fafc);
    min-height: 180px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.orbit-msg {
    max-width: 85%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-md);
    font-size: var(--fs-sm);
    line-height: var(--leading-relaxed);
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.orbit-msg--bot {
    align-self: flex-start;
    background: var(--color-white);
    color: var(--color-text);
    border: var(--border-medium) solid var(--color-border, #e2e8f0);
    border-left: var(--border-thick) solid var(--color-teal);
}

.orbit-msg--user {
    align-self: flex-end;
    background: var(--color-navy);
    color: var(--color-white);
    border: var(--border-medium) solid var(--color-navy);
}

.orbit-msg--error {
    align-self: flex-start;
    background: var(--color-coral-subtle);
    border: var(--border-medium) solid var(--color-coral);
    color: var(--color-text);
}

.orbit-msg a {
    color: var(--color-on-light-teal, #006B82); /* 6.1:1 — message links must pass AA normal text */
    text-decoration: underline;
    text-underline-offset: 2px;
}

.orbit-msg--user a {
    color: var(--color-teal);
}

/* Typing indicator */
.orbit-typing {
    align-self: flex-start;
    display: flex;
    gap: 5px;
    padding: 0.75rem 0.875rem;
    background: var(--color-white);
    border: var(--border-medium) solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-md);
}

.orbit-typing span {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--color-teal);
    animation: orbit-typing 1.2s ease-in-out infinite;
}

.orbit-typing span:nth-child(2) { animation-delay: 0.15s; }
.orbit-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes orbit-typing {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* Quick suggestion chips (first open) */
.orbit-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-self: flex-start;
}

.orbit-chip {
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    font-weight: var(--font-semibold);
    padding: 0.375rem 0.75rem;
    background: var(--color-white);
    color: var(--color-navy);
    border: var(--border-medium) solid var(--color-navy);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background var(--transition-fast),
                color var(--transition-fast),
                transform var(--transition-base) var(--ease-bounce);
}

.orbit-chip:hover {
    background: var(--color-teal);
    border-color: var(--color-teal);
    color: var(--color-navy);
    transform: scale(1.05);
}

/* ── Turnstile host (first open) ── */
.orbit-panel__gate {
    padding: 0.75rem 1rem;
    border-top: var(--border-medium) solid var(--color-border, #e2e8f0);
    background: var(--color-white);
    flex-shrink: 0;
}

.orbit-panel__gate-note {
    font-size: var(--fs-xs);
    color: var(--color-text-secondary);
    margin: 0 0 0.5rem;
}

.orbit-panel__gate[hidden] {
    display: none;
}

/* ── Input row ── */
.orbit-panel__form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--color-white);
    border-top: var(--border-medium) solid var(--color-border, #e2e8f0);
    flex-shrink: 0;
}

.orbit-panel__input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.625rem 0.875rem;
    font: inherit;
    font-size: 1rem; /* never below 16px — iOS zooms focused inputs under 16px */
    color: var(--color-text);
    background: var(--color-off-white, #f8fafc);
    border: var(--border-medium) solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-md);
    resize: none;
    max-height: 96px;
    line-height: 1.4;
}

.orbit-panel__input:focus {
    outline: none;
    border-color: var(--color-teal);
    box-shadow: 0 0 0 3px var(--color-teal-subtle);
}

.orbit-panel__send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    align-self: flex-end;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-teal);
    color: var(--color-navy);
    border: var(--border-medium) solid var(--color-navy);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast),
                transform var(--transition-base) var(--ease-bounce);
}

.orbit-panel__send:hover:not(:disabled) {
    background: var(--color-yellow);
    transform: scale(1.06);
}

.orbit-panel__send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.orbit-panel__send:focus-visible {
    outline: 2px solid var(--color-navy);
    outline-offset: 2px;
}

.orbit-panel__send svg {
    width: 18px;
    height: 18px;
}

/* ── Footer ── */
.orbit-panel__footer {
    padding: 0.375rem 0.75rem;
    font-size: 10px;
    text-align: center;
    color: var(--color-text-secondary);
    background: var(--color-white);
    border-top: 1px solid var(--color-border, #e2e8f0);
    flex-shrink: 0;
}

/* ── Mobile ── */
@media (max-width: 767px) {
    .orbit-launcher {
        bottom: var(--space-6);
        left: var(--space-4);
        width: 50px;
        height: 50px;
    }

    .orbit-panel {
        left: var(--space-3);
        right: var(--space-3);
        bottom: 5rem;
        width: auto;
        max-height: min(70dvh, 520px);
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .orbit-launcher,
    .orbit-panel,
    .orbit-chip,
    .orbit-panel__send,
    .orbit-launcher__pill,
    .tf-shell-l,
    .tf-shell-r,
    .tf-swoosh,
    .tf-torso,
    .tf-arm-l,
    .tf-arm-r,
    .tf-leg-l,
    .tf-leg-r,
    .tf-apex,
    .tf-eyes,
    .tf-head {
        transition: none;
    }

    .orbit-launcher__badge,
    .orbit-typing span,
    .orbit-launcher .tf-logo,
    .tf-orbiter {
        animation: none;
    }

    .orbit-launcher:hover {
        transform: scale(1.05);
    }
}
