/* SiteTech chat widget. Scoped under #st-chat-root so it cannot collide with home.css (the
   cinematic home page) or shared.css (the subpages). Colours come from tokens.css only. */

#st-chat-root, #st-chat-root * {
    box-sizing: border-box;
    font-family: 'Geist', system-ui, Arial, sans-serif;
}

/* --st-kb and --st-vvh are set by chatbot.js while a keyboard (or any other overlay) covers the
   lower part of the layout viewport: how many px are covered, and the height still visible.
   Unset, every calc below resolves to the original sizing. */
#st-chat-root {
    --st-safe: env(safe-area-inset-bottom, 0px);
    position: fixed;
    right: 24px;
    bottom: calc(24px + var(--st-kb, 0px));
    z-index: 500;
}
#st-chat-root.st-kb-open { --st-safe: 0px; }     /* the home indicator is behind the keyboard */

/* The launcher is the site's own near-black with a hairline, not the --cyan accent (Albert, 10 Oct 2026, with the new
   Wes palette): his silver hat and skin compute to 1.11:1 and 1.02:1 against cyan. The accent stays on the AI tag, the
   visitor's bubbles and the focus ring. */
#st-chat-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--bg-raised);
    color: var(--fg-title);
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 24px rgba(0,0,0,0.4);
    transition: transform 0.2s;
}
#st-chat-toggle:hover { transform: scale(1.06); }
#st-chat-toggle:focus-visible,
#st-chat-send:focus-visible,
#st-chat-panel a:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
#st-chat-toggle .st-chat-close-icon { display: none; font-size: 28px; line-height: 1; }
/* Wes fills the button: 48 px is exactly two screen pixels per drawing pixel at 1x and a whole number at 2x and 3x.
   The tag sits inside the button's 56 px square, so the button's footprint and clearances are unchanged. The
   toggle itself stays unpositioned (see the bar under the open panel below); only this inner box is. */
#st-chat-toggle .st-chat-open-icon { position: relative; display: block; width: 48px; height: 48px; }
#st-chat-toggle .st-chat-aitag {
    position: absolute;
    right: -2px;
    bottom: -2px;
    padding: 1px 5px;
    border-radius: 8px;
    border: 1px solid var(--cyan);
    background: var(--bg);
    color: var(--fg);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    line-height: 1.3;
}
#st-chat-root.open #st-chat-toggle .st-chat-open-icon { display: none; }
#st-chat-root.open #st-chat-toggle .st-chat-close-icon { display: block; }

/* Closed means not focusable and not announced: visibility, not opacity alone. */
#st-chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: min(360px, calc(100vw - 48px));
    height: min(500px, calc(var(--st-vvh, 100vh) - 140px));
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}
#st-chat-root.open #st-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s;
}

#st-chat-header {
    touch-action: none;                /* a drag on the header is never a page scroll */
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-soft);
}
#st-chat-header .st-chat-titlerow { display: flex; align-items: center; gap: 8px; }
#st-chat-header .st-chat-title {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--fg-title);
}
#st-chat-header .st-chat-head { display: flex; align-items: center; gap: 10px; }
#st-chat-header .st-chat-who { min-width: 0; }
#st-chat-header .st-chat-subtitle {
    margin-top: 2px;
    font-size: 12px;
    color: var(--fg-muted);
}
#st-chat-header .st-chat-badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 7px;
    border-radius: 10px;
    background: var(--blue-dim);
    color: var(--fg-title);
}
#st-chat-header .st-chat-notice {
    margin: 6px 0 0;
    font-size: 12px;
    line-height: 1.45;
    color: var(--fg-muted);
}
#st-chat-header .st-chat-notice a { color: var(--cyan); }

/* Wes, the pixel mascot (drawn by chatbot.js from the same runs as assets/wes.svg). Square pixels, no animation. */
.st-wes { display: block; flex: none; shape-rendering: crispEdges; image-rendering: pixelated; }
.st-wes .wK { fill: var(--wes-ink); }
.st-wes .wY { fill: var(--wes-hat); }
.st-wes .wO { fill: var(--wes-hat-shade); }
.st-wes .wS { fill: var(--wes-skin); }
.st-wes .wW { fill: var(--wes-white); }
.st-wes .wB { fill: var(--wes-shirt); }
.st-wes .wb { fill: var(--wes-shirt-shade); }
.st-wes .wH { fill: var(--wes-headset); }
.st-wes .wM { fill: var(--wes-metal); }
.st-chat-row { display: flex; align-items: flex-start; gap: 8px; align-self: flex-start; max-width: 100%; }
.st-chat-row > .st-wes { margin-top: 2px; }
.st-chat-row > .st-chat-msg { max-width: calc(100% - 32px); min-width: 0; }

#st-chat-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;      /* a scroll that reaches the end stays in the panel */
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.st-chat-msg {
    max-width: 88%;
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.st-chat-msg a { color: inherit; text-decoration: underline; }
.st-chat-msg.user {
    align-self: flex-end;
    background: var(--cyan);
    color: var(--bg);
    border-bottom-right-radius: 3px;
}
.st-chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-well);
    color: var(--fg-soft);
    border: 1px solid var(--border-soft);
    border-bottom-left-radius: 3px;
}
.st-chat-msg.error {
    align-self: flex-start;
    background: var(--error-bg);
    color: var(--error-fg);
    border: 1px solid var(--border);
}
.st-chat-msg.typing { align-self: flex-start; color: var(--fg-dim); font-style: italic; }

#st-chat-form {
    touch-action: none;
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-soft);
}
#st-chat-input {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    background: var(--bg-well);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 9px 14px;
    color: var(--fg);
    font-size: 16px;                   /* 16px stops iOS Safari zooming the page on focus */
}
#st-chat-input::placeholder { color: var(--fg-dim); opacity: 1; }   /* the browser default is 3.99:1 on --bg-well */
#st-chat-input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
#st-chat-send {
    min-height: 44px;
    min-width: 44px;
    background: var(--fg);
    color: var(--bg);
    border: none;
    border-radius: 22px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
#st-chat-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 480px) {
    #st-chat-root { right: 16px; bottom: calc(16px + var(--st-safe) + var(--st-kb, 0px)); }
    #st-chat-panel { width: calc(100vw - 32px); }
    /* A solid bar under the panel and the toggle while it is open, so no page content (the home
       hero's copy) shows in the strip between the panel's bottom edge and the screen edge. Its
       top edge is the panel's bottom edge: root bottom + 72px = 88px + safe area + keyboard.
       z-index -1 keeps it under the toggle: the toggle is not positioned, so without it this fixed
       bar painted over the close button and only a hovered toggle (its scale transform) rose above it. */
    #st-chat-root.open::before {
        content: "";
        position: fixed;
        z-index: -1;
        left: 0;
        right: 0;
        bottom: var(--st-kb, 0px);
        height: calc(88px + var(--st-safe));
        background: var(--bg-deep);
        border-top: 1px solid var(--border);
    }
    /* No visualViewport API: keep the panel at the top of the screen, above any keyboard. */
    #st-chat-root.st-no-vv #st-chat-panel { position: fixed; top: 8px; bottom: auto; right: 16px; height: min(420px, 46vh); }
    #st-chat-root.st-no-vv.open::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    #st-chat-toggle, #st-chat-panel, #st-chat-root.open #st-chat-panel { transition: none; }
    #st-chat-toggle:hover { transform: none; }
    #st-chat-panel { transform: none; }
    #st-chat-root.open #st-chat-panel { transform: none; }
}
