/* ==========================================================================
   Spider Digitizing — chat popup
   --------------------------------------------------------------------------
   A guided-help panel, not a live-chat box. Built on the site's own tokens
   (--as-clr-pr-1 ember on the near-black ground) rather than a generic
   "support blue", because a widget in someone else's brand colours reads as an
   embedded third party.

   Design rules this file follows, and why:

   - The launcher is the only thing visible on a resting page. Everything else
     exists solely while the panel is open, so the closed cost is one 56px
     button that is `display:none` until chat.js proves it works.
   - Ember is used for exactly two things: the primary action and the state a
     visitor can act on. It is never decoration. On the dark ground it clears
     AA at --as-clr-pr-1; the label sits on near-black, so the *text* is white
     and the ember is the fill, which inverts the usual failure.
   - z-index 3000 puts it above the sticky header (50), the mobile drawer
     (1000) and the command palette (1100) is never open at the same time.
   - Nothing here depends on a webfont, and nothing here is load-bearing for
     layout — the widget is position:fixed and out of flow, so it cannot cause
     reflow or a layout shift on the page behind it.
   ========================================================================== */

/* libo's widget tokens, verbatim, with gold mapped to our ember. Read straight
   off libo/assets/css/brand.css so the widget is the same object on both
   sites, not merely "inspired by" it:
     --brand-bg #0a0a0a -> our near-black ground
     --brand-surface #161616
     --brand-gold #d4af37 / gold-dark #b8941f -> ember #fd3f00 / #c02f00
     --brand-border rgba(255,255,255,.08) / strong .15
     --brand-radius-lg 16px, --brand-text-muted #9a9a9a, --brand-success #22c55e */
.sp-chat {
    --sp-bg: #050505;
    --sp-bg-raised: #111111;
    --sp-surface: #161616;
    --sp-accent: #fd3f00;
    --sp-accent-dark: #c02f00;
    --sp-accent-gradient: linear-gradient(145deg, var(--sp-accent), var(--sp-accent-dark));
    --sp-border: rgba(255, 255, 255, 0.08);
    --sp-border-strong: rgba(255, 255, 255, 0.15);
    --sp-radius-lg: 16px;
    --sp-muted: #9a9a9a;
    --sp-success: #22c55e;
}

.sp-chat,
.sp-chat * { box-sizing: border-box; }

.sp-chat {
    position: fixed;
    inset: 0;
    z-index: 3000;
    pointer-events: none;
    font-family: var(--as-font-1, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}

.sp-chat > * { pointer-events: auto; }

/* --------------------------------------------------------------- launcher */

.sp-chat__launcher {
    position: fixed;
    right: 1.6rem;
    bottom: 1.4rem;
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 1.1rem 0.7rem 0.85rem;
    border: 1px solid var(--sp-border-strong);
    border-radius: 100px;
    background: var(--sp-accent-gradient);
    /* Dark text on the ember fill, exactly as libo runs dark text on its gold.
       White-on-ember is the thing that made ours read as a generic red button
       rather than as the same widget. */
    color: #0a0a0a;
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;

    /* Fail closed. chat.js adds .is-ready to <html>; until then there is no
       launcher, so a blocked or broken script leaves no dead button behind. */
    display: none;
}

.is-ready .sp-chat__launcher { display: inline-flex; }

.sp-chat__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
}

.sp-chat__launcher:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 3px;
}

/* One-time attention pulse, gated on localStorage in chat.js so it is shown
   once per visitor rather than on every page view. */
.sp-chat__launcher.is-new::after {
    content: "";
    position: absolute;
    inset: -3px;
    border: 2px solid var(--sp-accent);
    border-radius: 100px;
    animation: spChatPulse 2.6s ease-out 2;
    pointer-events: none;
}

@keyframes spChatPulse {
    0% { opacity: 0.6; transform: scale(1); }
    70%, 100% { opacity: 0; transform: scale(1.16); }
}

.sp-chat__launcher-txt { white-space: nowrap; }

/* The unread dot. aria-hidden: the launcher already carries an aria-label, and
   a decorative dot announced as content is noise. */
.sp-chat__dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #0a0a0a;
    box-shadow: 0 0 0 2px var(--sp-accent);
    opacity: 0;
    transform: scale(0.4);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.sp-chat__launcher.is-new .sp-chat__dot { opacity: 1; transform: scale(1); }

/* ------------------------------------------------------------------ panel */

.sp-chat__panel {
    position: fixed;
    right: 1.6rem;
    bottom: 5.6rem;
    width: 372px;
    max-width: calc(100vw - 2rem);
    height: 560px;
    max-height: calc(100vh - 9rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--sp-bg-raised);
    border: 1px solid var(--sp-border-strong);
    border-radius: var(--sp-radius-lg);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.sp-chat__panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* A warm ember wash at the top of the panel, so the widget reads as ours the
   moment it opens. Two stops only — a gradient with more would band on the
   dark ground. */


/* ------------------------------------------------------------------- head */

.sp-chat__head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 1rem 1.1rem;
    border-bottom: 1px solid var(--sp-border);
    background: linear-gradient(135deg, rgba(253, 63, 0, 0.12), transparent 70%), var(--sp-surface);
    flex: 0 0 auto;
}

.sp-chat__avatar {
    position: relative;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--sp-border-strong);
    color: var(--sp-accent);
    flex: 0 0 auto;
}

/* The presence dot. Purely decorative - aria-hidden on the avatar already. */
.sp-chat__avatar::after {
    content: "";
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--sp-success);
    border: 2px solid var(--sp-surface);
}

.sp-chat__id { display: flex; flex-direction: column; min-width: 0; flex: 1; }

.sp-chat__id strong {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    line-height: 1.25;
}

.sp-chat__id span {
    font-size: 0.75rem;
    color: #8b8b93;
    line-height: 1.3;
}

.sp-chat__back,
.sp-chat__close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.03);
    color: #9a9aa2;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.sp-chat__back:hover,
.sp-chat__close:hover {
    background: rgba(253, 63, 0, 0.14);
    border-color: rgba(253, 63, 0, 0.34);
    color: var(--sp-accent);
}

.sp-chat__back:focus-visible,
.sp-chat__close:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

.sp-chat__back[hidden] { display: none; }

/* ------------------------------------------------------------------ crumb */

.sp-chat__crumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.72rem;
    color: #7c7c84;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.22s ease, opacity 0.22s ease, padding 0.22s ease;
    flex: 0 0 auto;
}

.sp-chat__crumb.is-on {
    max-height: 44px;
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    opacity: 1;
}

.sp-chat__crumb b { color: #b9b9c0; font-weight: 600; }

/* ----------------------------------------------------------------- thread */

.sp-chat__thread {
    position: relative;
    flex: 1 1 auto;
    /* min-height: 0 is the whole fix for "the wheel scrolls the page instead of
       the thread". A flex item defaults to min-height:auto, which means it will
       NOT shrink below its content height. So the thread grew to fit every
       bubble, never became a scroll container at all, and the page underneath
       took the wheel. libo has had this line all along. */
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* Stop a touch drag on the thread from pulling the page with it once the
       thread hits either end. contain handles the wheel; this handles the
       finger. */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 1.1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.sp-chat__thread::-webkit-scrollbar { width: 6px; }
.sp-chat__thread::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16);
    border-radius: 3px;
}

/* ---------------------------------------------------------------- bubbles */

.sp-chat__msg {
    max-width: 86%;
    padding: 0.6rem 0.8rem;
    font-size: 0.855rem;
    line-height: 1.6;
    border-radius: 14px;
    overflow-wrap: anywhere;
}

.sp-chat__msg strong { color: #fff; font-weight: 700; }

.sp-chat__msg--bot {
    align-self: flex-start;
    background: var(--sp-surface);
    border: 1px solid var(--sp-border);
    border-bottom-left-radius: 5px;
    color: #d9d9de;
}

.sp-chat__msg--user {
    align-self: flex-end;
    background: rgba(253, 63, 0, 0.16);
    border: 1px solid rgba(253, 63, 0, 0.32);
    border-bottom-right-radius: 5px;
    color: #fff;
    font-weight: 600;
}

/* The typewriter reveal. Set by JS: opacity 0 and a hair of rise, then
   animated in by keyframes. Under reduced-motion chat.js skips the reveal and
   sets these directly, so the class being absent is never a stuck state. */
.sp-chat__msg--enter { opacity: 0; animation: spChatIn 0.22s ease forwards; }

@keyframes spChatIn {
    to { opacity: 1; transform: translateY(0); }
}

.sp-chat__msg--enter { transform: translateY(5px); }

/* ------------------------------------------------------------ typing dots */

.sp-chat__typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 0.8rem 0.9rem;
    border-radius: 14px;
    border-bottom-left-radius: 5px;
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.09);
}

.sp-chat__typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #8b8b93;
    animation: spChatBlink 1.3s ease-in-out infinite;
}

.sp-chat__typing i:nth-child(2) { animation-delay: 0.18s; }
.sp-chat__typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes spChatBlink {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* The blinking caret at the end of a reveal. */
.sp-chat__caret {
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin: 0 0 -0.14em 1px;
    background: var(--sp-accent);
    animation: spChatCaret 1s steps(1, end) infinite;
}

@keyframes spChatCaret {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

/* ---------------------------------------------------------- topic chooser */

.sp-chat__intro {
    align-self: flex-start;
    max-width: 100%;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #d9d9de;
}

.sp-chat__topics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.15rem;
}

.sp-chat__topic {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
    padding: 0.8rem 0.85rem;
    text-align: left;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 12px;
    color: #e6e6ea;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.sp-chat__topic:hover {
    background: rgba(253, 63, 0, 0.1);
    border-color: rgba(253, 63, 0, 0.32);
    transform: translateY(-1px);
}

.sp-chat__topic:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

.sp-chat__topic-ico { color: var(--sp-accent); }

.sp-chat__topic-label { font-size: 0.86rem; font-weight: 650; color: #fff; }

/* ------------------------------------------------------------------ chips */

.sp-chat__chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.sp-chat__chip {
    padding: 0.42rem 0.78rem;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.05);
    color: #d9d9de;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.sp-chat__chip:hover {
    background: rgba(253, 63, 0, 0.14);
    border-color: rgba(253, 63, 0, 0.4);
    color: #fff;
}

.sp-chat__chip:focus-visible {
    outline: 2px solid var(--sp-accent);
    outline-offset: 2px;
}

.sp-chat__chip--back { border-style: dashed; }

/* ------------------------------------------------------- the money table */

.sp-chat__rows {
    width: 100%;
    margin-top: 0.65rem;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.sp-chat__rows th {
    text-align: left;
    padding: 0.42rem 0.6rem 0.42rem 0;
    font-weight: 500;
    color: #a5a5ad;
    border-bottom: 1px solid rgba(255, 255, 255, 0.11);
    vertical-align: top;
}

.sp-chat__rows td {
    text-align: right;
    padding: 0.42rem 0 0.42rem 0.6rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.11);
    vertical-align: top;
    font-variant-numeric: tabular-nums;
}

.sp-chat__rows tr:last-child th,
.sp-chat__rows tr:last-child td { border-bottom: 0; }

/* -------------------------------------------------------------------- CTA */

.sp-chat__cta {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.75rem;
    padding: 0.6rem 1rem;
    border-radius: 9px;
    background: var(--sp-accent);
    color: #fff;
    font-size: 0.83rem;
    font-weight: 700;
    text-decoration: none;
    transition: background 0.16s ease, transform 0.16s ease;
}

.sp-chat__cta:hover { background: #ff5a22; transform: translateY(-1px); }

.sp-chat__cta:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* The "talk to a human" answer gets the emphasis: it is the branch the
   scripted tree cannot serve, and a visitor who wants a person should not
   have to hunt for the link. */
.sp-chat__msg--human {
    border-color: rgba(253, 63, 0, 0.4);
    background: rgba(253, 63, 0, 0.07);
}

.sp-chat__note {
    align-self: flex-start;
    max-width: 92%;
    margin-top: 0.2rem;
    padding: 0.55rem 0.75rem;
    border-left: 2px solid rgba(253, 63, 0, 0.5);
    background: rgba(253, 63, 0, 0.06);
    font-size: 0.78rem;
    line-height: 1.55;
    color: #c9c9d0;
}

/* -------------------------------------------------------------------- foot */

.sp-chat__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 1.1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(0, 0, 0, 0.4);
    flex: 0 0 auto;
}

.sp-chat__foot-links { display: flex; gap: 1rem; }

.sp-chat__foot-links a {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.76rem;
    color: #9a9aa2;
    text-decoration: none;
    transition: color 0.16s ease;
}

.sp-chat__foot-links a:hover { color: var(--sp-accent); }
.sp-chat__foot-links a:focus-visible { outline: 2px solid var(--sp-accent); outline-offset: 2px; }

.sp-chat__foot-note { font-size: 0.7rem; color: #6c6c74; }

/* --------------------------------------------------------------- no-JS link */

.sp-chat-nojs {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 3000;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.7rem 1.05rem;
    border-radius: 100px;
    background: var(--sp-accent);
    color: #fff;
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* ------------------------------------------------------------- breakpoints */

@media (max-width: 900px) {
    /* Below this the panel is taller than the viewport is useful, so shorten it
       rather than let the footer and header eat the thread. */
    .sp-chat__panel { height: min(520px, calc(100vh - 8.5rem)); }
}

/* Phone: the panel becomes a full-screen sheet. A 384px panel plus a launcher
   on a 390px phone leaves a 6px sliver of page, which looks broken rather than
   intentional. */
@media (max-width: 560px) {
    .sp-chat__launcher {
        right: 1rem;
        bottom: 1rem;
        width: 56px;
        height: 56px;
        padding: 0;
        justify-content: center;
        border-radius: 50%;
    }

    .sp-chat__launcher-txt { display: none; }

    .sp-chat__panel {
        right: 0;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        border: 0;
        border-radius: 0;
        transform: translateY(100%);
    }

    .sp-chat__panel.is-open { transform: translateY(0); }

    .sp-chat__topics { grid-template-columns: 1fr; }
    .sp-chat__msg { max-width: 92%; }

    .sp-chat__foot {
        justify-content: center;
        padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
    }

    .sp-chat__foot-note { display: none; }
}

/* Coarse pointers get 44px targets, not 32px. */
@media (pointer: coarse) {
    .sp-chat__back,
    .sp-chat__close { width: 40px; height: 40px; }
}

/* Short landscape phones: 600px of panel on a 380px-tall viewport is a letter
   box. Cap by height instead. */
@media (min-width: 561px) and (max-height: 620px) {
    .sp-chat__panel { height: calc(100vh - 7.5rem); }
}

/* --------------------------------------------------------------- a11y prefs */

@media (prefers-reduced-motion: reduce) {
    .sp-chat__panel,
    .sp-chat__launcher,
    .sp-chat__dot,
    .sp-chat__crumb,
    .sp-chat__msg--enter,
    .sp-chat__topic,
    .sp-chat__chip,
    .sp-chat__cta { transition-duration: 0.01ms !important; animation: none !important; }

    .sp-chat__launcher.is-new::after { display: none; }
    .sp-chat__msg--enter { opacity: 1; transform: none; }
    .sp-chat__typing i { animation: none; opacity: 0.7; }
    .sp-chat__caret { display: none; }
}

@media (prefers-contrast: more) {
    .sp-chat__panel { border-color: var(--sp-accent); }
    .sp-chat__msg--bot { border-color: rgba(255, 255, 255, 0.32); }
    .sp-chat__foot-links a { color: #d5d5dc; }
}