/* The help chat: the "Help" tab in the corner and the panel it opens
 * (assets/help-chat.js builds the markup).
 *
 * WHY A FILE OF ITS OWN. The chat goes on two kinds of page: the members
 * pages, written by Functions (functions/_lib/page.js links this beside
 * members.css), and the owner's guide, a static page with its own look
 * (guide/index.html links this and nothing else of the members area). So this
 * file brings everything the chat needs and touches nothing else on the page:
 *  - its colours and type, as custom properties set on the chat's own two
 *    elements (.chat-tab and .chat), never on :root, so a page's own tokens
 *    are left as they are (the guide's are mostly the same values anyway);
 *  - its two faces (the same files every page here uses, so nothing is
 *    downloaded twice);
 *  - the few resets a host page could otherwise leak in: box sizing, the
 *    [hidden] attribute (the panel and the tab are flex boxes, which would
 *    otherwise show while hidden), the visually-hidden labels, the focus ring.
 * Like members.css it is a plain file from this site: the Content-Security-
 * Policy allows it by style-src 'self', with no hash. tools/stage.sh ships it
 * BY NAME, beside members.css and help-chat.js.
 *
 * CONTRAST. Every text colour against every background it sits on is at least
 * 4.5:1, measured by tools/widget-check.mjs: the lowest is the soft text on
 * the raised, switched-off Send button, 5.5:1.
 */

@font-face { font-family: "Gloock"; src: url("/assets/gloock-latin.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Libre Franklin"; src: url("/assets/libre-franklin-latin.woff2") format("woff2"); font-weight: 400 600; font-style: normal; font-display: swap; }

/* The chat's tokens: the marketing page's colours, on the chat alone. */
.chat-tab, .chat {
  --canvas: #0A0C11;      /* the box you type in */
  --surface: #121318;     /* the mark beside "Help" */
  --panel: #0E1015;       /* the panel, a step off any page */
  --bubble: #1A1C22;      /* the assistant's messages */
  --raise: #1E2026;       /* a control that is switched off */
  --ink: #D9D6D0;         /* text: 13.1:1 on the panel */
  --soft: #9A958C;        /* times, notes: 6.4:1 on the panel, 5.7:1 on a bubble */
  --accent: #F7F4EC;      /* the tab, Send, and the member's own messages */
  --accent-ink: #0B0E13;  /* text on the accent: 17.6:1 */
  --line: rgba(217, 214, 208, 0.14);
  --line-firm: rgba(217, 214, 208, 0.30);
  --attention: #E8877E;   /* an answer arrived while the chat was closed */
  --display: "Gloock", Georgia, serif;
  --text: "Libre Franklin", "Helvetica Neue", Arial, sans-serif;
  --t-xs: 0.8125rem;      /* 13px: times, the status line, fine print */
  --t-sm: 0.9375rem;      /* 15px: messages, buttons */
  --t-base: 1.0625rem;    /* 17px */
  box-sizing: border-box; text-align: left; text-transform: none;
}
.chat *, .chat *::before, .chat *::after, .chat-tab * { box-sizing: border-box; }
.chat[hidden], .chat-tab[hidden], .chat [hidden], .chat-tab [hidden] { display: none !important; }
.chat { color: var(--ink); font: 400 var(--t-base)/1.6 var(--text); }
/* Read by screen readers, not shown ("You asked:", the box's label). */
.chat .vh { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.chat :focus-visible, .chat-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* =====================================================================
   A tab in the corner opens a panel: a header, the conversation as
   bubbles (the member's on the right in the accent, the assistant's on the
   left), and a composer at the foot. 400 x 640 on a wide screen; the whole
   screen on a phone.
   ===================================================================== */
/* The tab is a quiet control, the panel's own colour with a firm hairline and
   the bubble mark in cream: the cream slab it was out-shouted every page's
   own main button (Pay, Sign in with Google, Ask in the help chat) from the
   corner, and read as a plugin's launcher rather than part of the page. */
.chat-tab {
  position: fixed; z-index: 60;
  right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 0.55rem; min-height: 48px; padding: 0 1.15rem 0 0.95rem; margin: 0;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line-firm); border-radius: 0;
  font: 600 0.9375rem/1 var(--text); letter-spacing: normal; cursor: pointer;
  /* No shadow, here or on the panel: a hairline with a wide black shadow is the
     floating-widget look (impeccable flags it, "gpt-thin-border-wide-shadow"),
     and on this canvas the shadow barely showed (black on #0A0C11). Both are
     edged by their hairline, as every other box on these pages is. */
  transition: border-color 180ms ease, background-color 180ms ease, transform 140ms cubic-bezier(0.23, 1, 0.32, 1), opacity 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-tab svg { color: var(--accent); }
/* Hover looks only where a pointer hovers: on a touch screen :hover stays on
   the last thing tapped (a common question stayed lit after it was sent, and
   Send stayed dimmed). There the press (:active) is the feedback. */
@media (hover: hover) { .chat-tab:hover { border-color: var(--ink); background: #15171C; } }
.chat-tab:active { transform: translateY(1px); }
/* On a phone, where it sits over the very lines being read, the mark alone:
   48 x 48 instead of 106 x 52. Its name stays "Help" for a screen reader. */
@media (max-width: 40rem) {
  .chat-tab { width: 48px; padding: 0; justify-content: center; }
  .chat-tab__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* Stepped aside while one of the page's own controls is under it (help-chat.js,
   "Out of the way"): down and out of sight, back when the corner is clear. A
   keyboard can still reach it, and focused it shows. */
.chat-tab--aside { transform: translateY(calc(100% + 2rem)); opacity: 0; pointer-events: none;
  transition: transform 260ms cubic-bezier(0.23, 1, 0.32, 1), opacity 200ms ease; }
.chat-tab--aside:focus-visible { transform: none; opacity: 1; pointer-events: auto; }
/* Room at the end of any page that has the tab, so its last line (the
   guide's footer link sits in that very corner on a wide screen) scrolls
   clear of it. Only while the tab is there: without script, no tab, no room. */
body:has(> .chat-tab)::after { content: ""; display: block; height: 84px; }
/* While the panel stands open beside the page (a wide screen), as much room as
   the panel is tall, so the page's last controls can scroll up clear of it
   (help-chat.js, "Beside the page"). */
html.chat-beside body:has(> .chat-tab)::after { height: calc(min(640px, 100dvh - 2rem) + 2rem); }
.chat-tab svg { flex: none; }
.chat-tab__dot {
  position: absolute; top: -6px; right: -6px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--attention); box-shadow: 0 0 0 3px var(--canvas);
}

.chat {
  position: fixed; z-index: 70; right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  width: min(400px, calc(100vw - 2rem)); height: min(640px, calc(100dvh - 2rem));
  background: var(--panel); border: 1px solid var(--line-firm);
}
.chat:focus { outline: none; }
/* It arrives rather than appears: 160ms of opacity, nothing that moves its box
   (its edges are measured the moment it opens). Closing is instant. */
.chat { transition: opacity 160ms ease; }
@starting-style { .chat { opacity: 0; } }
/* Nothing to type into (signed out, sign-in not switched on): the panel is as
   tall as what it says, not 640px of empty panel under one sentence. */
.chat:has(> .chat__foot[hidden]) { height: auto; max-height: min(640px, calc(100dvh - 2rem)); }
.chat:has(> .chat__foot[hidden]) .chat__log { flex: 0 1 auto; padding-block: 1.25rem; }
/* A phone, upright or sideways (the same query as PHONE in help-chat.js): the
   whole screen. help-chat.js sizes it to the visible area while a keyboard is up. */
@media (max-width: 639.98px), (max-height: 499.98px) {
  .chat { inset: 0; width: auto; height: 100dvh; border: 0; box-shadow: none; }
  /* The whole screen on a phone either way; the sentence then sits in the
     middle of it, not under the header with the screen empty below. */
  .chat:has(> .chat__foot[hidden]) { height: 100dvh; max-height: none; }
  .chat:has(> .chat__foot[hidden]) .chat__log { flex: 1; justify-content: center; }
}
/* While the chat covers a phone's screen, the page under it holds still. */
html.chat-locked, html.chat-locked body { overflow: hidden; }

.chat__head { display: flex; align-items: center; gap: 0.8rem; padding: 0.7rem 0.6rem 0.7rem 1rem; border-bottom: 1px solid var(--line); }
/* The assistant's mark: the tab's speech bubble (inline SVG in currentColor),
   so the panel and the tab that opened it say the same thing. Unframed: a
   40px hairline box round it was an avatar tile, the one framed icon on the
   site, and the most plugin-like thing left in the panel. */
.chat__mark { flex: none; display: grid; place-items: center; width: 24px; height: 40px; color: var(--ink); }
.chat__who { min-width: 0; }
.chat__name { margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.35rem; line-height: 1.1; letter-spacing: -0.005em; color: var(--ink); }
.chat__sub { margin: 0.1rem 0 0; max-width: none; font-size: var(--t-xs); color: var(--soft); line-height: 1.3; }
.chat__close {
  flex: none; margin-left: auto; width: 44px; height: 44px; padding: 0; display: grid; place-items: center;
  background: transparent; color: var(--ink); border: 1px solid transparent; border-radius: 0; cursor: pointer;
}
.chat__close:hover { border-color: var(--line-firm); }

.chat__log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 0.85rem; padding: 1rem 1rem 1.1rem;
  /* What scrolls under the header, or down past the composer, fades out over
     its last 14px instead of being cut by the rule (a question half cut by the
     composer's rule read as a rendering fault). Both fades sit inside the log's
     padding (1rem and 1.1rem), so nothing at rest is dimmed. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.chat__log:focus-visible { outline-offset: -3px; }
.chat__notice { margin: 0 0 0.15rem; padding: 0 0 0.35rem; border-bottom: 1px solid var(--line); font-size: var(--t-xs); line-height: 1.5; color: var(--soft); }
.chat__notice p { margin: 0; max-width: none; }
.chat__notice summary {
  display: inline-flex; align-items: center; gap: 0.45rem; min-height: 44px; cursor: pointer; list-style: none;
  color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-firm); text-underline-offset: 0.2em;
}
.chat__notice summary::-webkit-details-marker { display: none; }
.chat__notice details[open] summary, .chat__notice summary:hover { text-decoration-color: var(--ink); }
.chat__notice details p { margin: 0 0 0.6rem; }
.chat__day { align-self: center; margin: 0.25rem 0 0; font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.04em; color: var(--soft); }

/* Square, like every other box on these pages. The member's words are a
   cream block on the right; the assistant's are the members page's own
   answer (.answer in members.css): a step darker than the panel, with a rule
   down the left. Rounded 14px bubbles (and 10px notes) were the chat's own
   shape language, and the part that read as a plugin. */
.msg { display: flex; flex-direction: column; gap: 0.3rem; max-width: 86%; }
.msg--me { align-self: flex-end; align-items: flex-end; }
.msg--bot { align-self: flex-start; align-items: flex-start; }
.msg__bubble { padding: 0.65rem 0.9rem; font-size: var(--t-sm); line-height: 1.55; overflow-wrap: anywhere; border-radius: 0; }
/* clip: a pasted pile of combining marks (three letters under 300 accents)
   drew a column of them about 100px above and below its bubble, over the
   messages round it (measured). Each paragraph keeps its marks to itself; the
   bubble's buttons (Try again) are not inside a paragraph, so their focus
   rings are not cut. */
.msg__bubble p { margin: 0 0 0.6rem; max-width: none; overflow: clip; overflow-clip-margin: 0.35em; }
.msg__bubble p:last-child { margin-bottom: 0; }
.msg--me .msg__bubble { background: var(--accent); color: var(--accent-ink); white-space: pre-wrap; }
.msg--bot .msg__bubble { background: var(--canvas); color: var(--ink); border-left: 2px solid var(--line-firm); padding-left: 0.85rem; }
.msg__time { padding: 0; font-size: var(--t-xs); color: var(--soft); }
/* What the chat itself says: a state, a refusal, a failure. Centred, framed by a hairline. */
.msg--sys { align-self: center; align-items: center; max-width: 92%; text-align: center; }
.msg--sys .msg__bubble { background: transparent; color: var(--ink); border: 1px solid var(--line-firm); padding: 0.85rem 1.1rem; }
/* Alone in a panel sized to it (signed out, sign-in not switched on), the note
   needs no frame: a hairline box 20px inside the panel's own read as a card in
   a card. */
.chat:has(> .chat__foot[hidden]) .msg--sys .msg__bubble { border-color: transparent; padding: 0.35rem 0.5rem; }
.msg__acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin-top: 0.7rem; }
.msg__btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 1rem;
  background: transparent; color: var(--ink); border: 1px solid var(--line-firm); border-radius: 0;
  font: inherit; font-size: var(--t-sm); font-weight: 600; text-decoration: none; cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease, filter 180ms ease, transform 140ms cubic-bezier(0.23, 1, 0.32, 1);
}
@media (hover: hover) { .msg__btn:hover { border-color: var(--ink); background: rgba(247, 244, 236, 0.06); } }
.msg__btn:active { transform: translateY(1px); background: rgba(247, 244, 236, 0.1); }
.msg__btn--main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
@media (hover: hover) { .msg__btn--main:hover { background: var(--accent); filter: brightness(0.93); } }
.msg__btn--main:active { background: var(--accent); filter: brightness(0.88); }

/* Waiting: three dots that rise in turn. With reduced motion, the word instead. */
.dots { display: inline-flex; align-items: center; gap: 5px; height: 1.4rem; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--soft); animation: chat-dot 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-dot { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.thinking__word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Suggestions while the conversation is empty: common questions, answered free. */
/* One even column of questions, every one the full width (ragged right edges,
   one box per its own text, read as a heap of tags). */
.chips { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; }
.chips__k { margin: 0.25rem 0 0; font-size: var(--t-xs); color: var(--soft); }
.chip {
  min-height: 44px; padding: 0.55rem 0.9rem; text-align: left;
  background: transparent; color: var(--ink); border: 1px solid var(--line-firm); border-radius: 0;
  font: inherit; font-size: var(--t-sm); line-height: 1.4; cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease, transform 140ms cubic-bezier(0.23, 1, 0.32, 1);
}
@media (hover: hover) { .chip:hover { border-color: var(--ink); background: rgba(247, 244, 236, 0.06); } }
.chip:active { transform: translateY(1px); background: rgba(247, 244, 236, 0.1); }

.chat__foot { padding: 0.75rem 1rem calc(0.7rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat__form { display: flex; align-items: flex-end; gap: 0.5rem; margin: 0; }
.chat__input {
  /* One line to start; three at most (3 x 1.5em, the padding and the border), then it scrolls. */
  flex: 1; min-width: 0; min-height: 46px; max-height: calc(4.5em + 1.2rem + 2px); padding: 0.6rem 0.75rem; margin: 0;
  resize: none; overflow-y: auto; background: var(--canvas); color: var(--ink);
  border: 1px solid var(--line-firm); border-radius: 0; font: inherit; font-size: 1rem; line-height: 1.5;
}
.chat__input::placeholder { color: var(--soft); opacity: 1; }
/* As every box you type in on these pages: the edge firms under the mouse. */
.chat__input:hover:not(:disabled):not(:focus) { border-color: rgba(217, 214, 208, 0.5); }
/* The members pages' one focus for a box you type in (members.css): the edge
   turns cream at 2px, with no second ring 3px outside it. */
.chat__input:focus, .chat .chat__input:focus-visible {
  border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); outline: 2px solid transparent; outline-offset: -2px;
}
.chat__send {
  flex: none; min-height: 46px; min-width: 68px; padding: 0 1rem;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 0;
  font: 600 var(--t-sm)/1 var(--text); cursor: pointer;
  transition: filter 180ms ease, transform 140ms cubic-bezier(0.23, 1, 0.32, 1);
}
/* Hover darkens the cream (brightness above 1 has no room to show on it:
   measured), and a press darkens it further. */
@media (hover: hover) { .chat__send:hover { filter: brightness(0.93); } }
.chat__send:active:not(:disabled) { transform: translateY(1px); filter: brightness(0.88); }
.chat__close { transition: border-color 180ms ease, background-color 180ms ease; }
.chat__close:hover { background: rgba(247, 244, 236, 0.06); }
.chat__close:active { background: rgba(247, 244, 236, 0.1); }
.chat__send, .msg__btn, .chip, .chat__close { -webkit-tap-highlight-color: transparent; }
/* Switched off (waiting for an answer, or not taking questions): the same
   shapes in the raised colour, still readable (5.5:1), never faded out. */
.chat__send:disabled, .chat__input:disabled, .chat__input[readonly] { background: var(--raise); color: var(--soft); border-color: var(--line); cursor: not-allowed; filter: none; }
.chat__meta { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; min-height: 1.2rem; margin-top: 0.4rem; }
.chat__status, .chat__count { margin: 0; max-width: none; font-size: var(--t-xs); line-height: 1.4; color: var(--soft); }
.chat__count { flex: none; }
.chat__count--near { color: var(--ink); font-weight: 600; }

/* Held sideways there is little height to share: the header drops its second
   line and its padding, and the status line steps out while the box is in
   use, so the conversation keeps some room above a keyboard. After the rules
   it narrows, so it wins. */
@media (max-height: 499.98px) {
  .chat__head { padding-block: 0; }
  .chat__mark { display: none; }
  .chat__sub { display: none; }
  .chat__foot { padding-top: 0.45rem; padding-bottom: calc(0.45rem + env(safe-area-inset-bottom)); }
  .chat__foot:focus-within .chat__meta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-tab, .chat, .chat * { transition: none !important; scroll-behavior: auto !important; }
  .dots { display: none; }
  .thinking__word { position: static; width: auto; height: auto; overflow: visible; clip-path: none; white-space: normal; color: var(--soft); }
}

/* On paper the tab is a fixed box printed over the page (it sat on the members
   page's help card, measured in Chrome's print), and the panel is a
   conversation nobody asked to print. */
@media print {
  .chat-tab, .chat { display: none !important; }
}
