/* =========================================================================
   GRAVIQUEST, ASK GRAVITAS
   A floating assistant, on every page. Built on the same tokens as everything
   else, so it inherits both themes without a single hard-coded colour.

   Two deliberate departures from the usual e-commerce widget:
   it does not open itself, and it does not nag. A bubble that pops up
   unasked on a reading site interrupts the one thing the site is for.
   ========================================================================= */

.gchat {
  --gchat-edge: clamp(1rem, 3vw, 1.75rem);
  /* A page with its own bottom chrome (the workspace's status bar, or its
     rail on a phone) sets --gchat-bottom to clear it; the panel's ceiling
     below is computed from the same figure, so the two cannot disagree. */
  position: fixed; right: var(--gchat-edge); bottom: calc(var(--gchat-bottom, var(--gchat-edge)) + var(--gchat-keyboard, 0px));
  z-index: var(--g-z-overlay);
  font-family: var(--g-font); line-height: 0;
}

/* ---- Launcher -----------------------------------------------------------
   One control, one job: open. It used to morph into an X while the panel was
   also showing a close button in its header, two ways to shut the same thing,
   six inches apart, which makes a reader stop and choose. Now the launcher
   simply gets out of the way, and the panel's own close is the only close.
   It stays in the layout while hidden, because the panel is anchored to it. */
/* At rest a circle holding the mark. Under the pointer, or with keyboard
   focus, the name unrolls to its left and the circle becomes the pill it
   used to be all the time. The padding is what makes the resting shape a
   circle: (3.25 - 1.5) / 2 either side of a 1.5rem mark and a zero-width
   label. Only a click opens the panel (chat.js). */
.gchat__btn {
  display: inline-flex; align-items: center;
  height: 3.25rem; padding: 0 0.875rem;
  border-radius: var(--g-radius-pill);
  border: 1px solid var(--g-solid-bg);
  background: var(--g-solid-bg); color: var(--g-solid-fg);
  font-size: var(--g-fs-small); font-weight: var(--g-w-semibold); line-height: 1;
  cursor: pointer; box-shadow: var(--g-shadow), var(--g-glow-md);
  transform-origin: 100% 100%;
  transition: transform var(--g-dur) var(--g-ease-orbit),
              opacity 160ms var(--g-ease-orbit),
              box-shadow var(--g-dur) var(--g-ease-orbit),
              visibility 0s linear 0s;
}
.gchat__btn:hover { transform: translateY(-2px); }
.gchat__btn .gchat__spark { width: 1.5rem; height: 1.5rem; display: block; flex: none; }
/* The width animates through a 0fr → 1fr grid track rather than max-width,
   so it runs to the text's real width in any language and at any font size
   instead of to a guessed ceiling. The text fades a beat behind the width on
   the way out and a beat after it on the way in, so letters are never seen
   being cut by the edge. */
.gchat__label {
  display: grid; grid-template-columns: 0fr; overflow: hidden;
  transition: grid-template-columns 260ms var(--g-ease-orbit),
              margin-left 260ms var(--g-ease-orbit);
}
.gchat__label > span {
  min-width: 0; white-space: nowrap; opacity: 0;
  transition: opacity 120ms var(--g-ease-orbit);
}
.gchat__btn:hover .gchat__label,
.gchat__btn:focus-visible .gchat__label {
  grid-template-columns: 1fr; margin-left: 0.55rem;
}
.gchat__btn:hover .gchat__label > span,
.gchat__btn:focus-visible .gchat__label > span {
  opacity: 1; transition: opacity 180ms var(--g-ease-orbit) 90ms;
}
@media (prefers-reduced-motion: reduce) {
  .gchat__label, .gchat__label > span { transition: none; }
}
/* visibility has to be named in the transition list, not just given a delay in
   `transition-delay`, a delay on a property that isn't being transitioned is
   ignored, and the button would snap out of existence mid-fade. */
.gchat.is-open .gchat__btn {
  opacity: 0; transform: scale(0.85); visibility: hidden;
  transition: transform 160ms var(--g-ease-orbit),
              opacity 160ms var(--g-ease-orbit),
              visibility 0s linear 160ms;
}

/* ---- Panel --------------------------------------------------------------
   Absolutely positioned above the launcher rather than stacked with it, so
   the panel can animate on both edges. `display: none` was why closing had no
   animation at all: it is not an animatable property, so the panel vanished on
   the frame the class came off. Visibility is, if you delay it past the fade. */
.gchat__panel {
  /* Anchored to the bottom of the widget, not above the launcher. Sitting it
     above left the launcher's own height as a band of nothing under the panel -
     and since the launcher hides while the panel is open, that band was empty.
     The panel simply takes the space instead. */
  position: absolute; right: 0; bottom: 0;
  display: flex; flex-direction: column; line-height: var(--g-lh-body);
  width: min(23.5rem, calc(100vw - 2rem));
  /* The ceiling is the sticky header, not the top of the viewport. A flat
     `100dvh - 4rem` put the panel's top 3rem down on a short phone screen,
     inside a header 4.5rem tall, so the two drew over each other. Now the
     panel stops a gap below the measured header (--g-header-h, site.css),
     whatever the viewport. The fallback covers pages without site.css. */
  --gchat-ceiling: calc(var(--g-header-h, 4.5rem) + var(--gchat-bottom, var(--gchat-edge)) + 0.75rem);
  height: min(34rem, calc(100vh - var(--gchat-ceiling)));
  height: min(34rem, calc(100dvh - var(--gchat-ceiling)));
  height: min(34rem, calc(var(--gchat-viewport, 100dvh) - var(--gchat-ceiling)));
  background: var(--g-surface-raised);
  border: 1px solid var(--g-border);
  border-radius: var(--g-radius-lg);
  box-shadow: var(--g-shadow), var(--g-glow-lg);
  overflow: hidden;

  /* Closed state. The origin is the launcher's corner, so it grows out of the
     button it came from and collapses back into it. */
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(8px) scale(0.96);
  transform-origin: 100% 100%;
  transition: opacity 170ms var(--g-ease-orbit),
              transform 220ms var(--g-ease-orbit),
              visibility 0s linear 220ms;
}
.gchat.is-open .gchat__panel {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: none;
  transition: opacity 200ms var(--g-ease-orbit),
              transform 280ms var(--g-ease-orbit),
              visibility 0s linear 0s;
}

/* ---- Panel header -------------------------------------------------------
   Was: a bordered circle holding the mark like a profile picture, a title, and
   a mono uppercase strapline reading "FIND YOUR WAY AROUND", which said the
   same thing as the note at the foot of the panel, one line below the name and
   in the loudest treatment in the widget. A logo does not need a container to
   be a logo, and the honesty line only needs saying once. What is left is a
   lockup and a minimize. The rule under it is the tab strip's, not its own. */
.gchat__head {
  display: flex; align-items: center; gap: 0.6rem;
  /* Right padding only keeps a long title clear of the minimize, which is
     positioned against the panel's corner rather than laid out in this row. */
  padding: 0.75rem calc(var(--g-space-md) + 1.9rem) 0.4rem var(--g-space-md);
  background: var(--g-surface);
  flex: none;
}
.gchat__brand { display: inline-flex; align-items: center; gap: 0.55rem; min-width: 0; }
.gchat__brand .gchat__mark { width: 1.15rem; height: 1.15rem; flex: none; }
.gchat__title {
  font-size: var(--g-fs-body); font-weight: var(--g-w-semibold);
  letter-spacing: -0.01em; line-height: 1.2; color: var(--g-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* The + is part of the name, and the brand sets it apart everywhere else. */
.gchat__plus { color: var(--g-accent); }
/* Concentric with the panel's top-right corner. A circle this close to a
   rounded corner reads as wrong unless the two curves are parallel, which
   means one centre: the corner arc's centre sits radius-lg in from both outer
   edges, so the circle's centre goes there too, and the gap between the two
   outlines is the same all the way round the bend (outer radius = inner
   radius + inset). As a flex item it was 12px from the top and 5px from the
   side, two different insets against one curve. The -1px is the panel's
   border, since the offsets are measured from inside it. The same centre also
   lands within a pixel of the new-tab + under it. */
.gchat__min {
  position: absolute;
  top: calc(var(--g-radius-lg) - 1px - 0.95rem);
  right: calc(var(--g-radius-lg) - 1px - 0.95rem);
  width: 1.9rem; height: 1.9rem; border-radius: 50%;
  display: grid; place-items: center;
  background: none; border: 1px solid transparent; cursor: pointer;
  color: var(--g-text-subtle);
  transition: color var(--g-dur) var(--g-ease-orbit),
              background-color var(--g-dur) var(--g-ease-orbit),
              border-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__min:hover {
  color: var(--g-text); border-color: var(--g-border);
  background: rgb(var(--g-tint) / 0.08);
}
.gchat__min svg { width: 1rem; height: 1rem; display: block; }

/* ---- Conversation tabs --------------------------------------------------
   Underlined rather than filled, like the workspace dock's tabs, so the strip
   reads as navigation inside the panel and not as a row of more buttons. The
   strip scrolls sideways instead of wrapping: a second row of tabs would take
   the height the conversation needs. The close on a tab only shows on the
   active one or under the pointer, because eight crosses in a row are noise. */
.gchat__tabbar {
  display: flex; align-items: stretch; flex: none;
  border-bottom: 1px solid var(--g-hairline);
  background: var(--g-surface);
}
.gchat__tabs {
  position: relative; flex: 1; min-width: 0;
  display: flex; overflow-x: auto; scrollbar-width: none;
  padding-left: calc(var(--g-space-md) - 0.8rem);
}
.gchat__tabs::-webkit-scrollbar { display: none; }
/* The strip is draggable once it overflows (chat.js). The fades mark the
   side that has more tabs past it; a mask rather than an overlay, so it
   works on any surface colour and never sits over a tab's close button. */
.gchat__tabs.has-before, .gchat__tabs.has-after { cursor: grab; }
.gchat__tabs.is-dragging { cursor: grabbing; user-select: none; }
.gchat__tabs.is-dragging .gchat__tab-btn { cursor: grabbing; }
.gchat__tabs.has-after {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 2rem), transparent);
}
.gchat__tabs.has-before {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 2rem), transparent);
          mask-image: linear-gradient(to left, #000 calc(100% - 2rem), transparent);
}
.gchat__tabs.has-before.has-after {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 2rem, #000 calc(100% - 2rem), transparent);
          mask-image: linear-gradient(to right, transparent, #000 2rem, #000 calc(100% - 2rem), transparent);
}
.gchat__tab {
  display: flex; align-items: center; flex: none; max-width: 10.5rem;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: border-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__tab.is-active { border-bottom-color: var(--g-accent); }
.gchat__tab-btn {
  display: flex; align-items: center; gap: 0.4rem; min-width: 0;
  font: inherit; font-size: var(--g-fs-caption); line-height: 1.2;
  color: var(--g-text-subtle); background: none; border: 0; cursor: pointer;
  padding: 0.6rem 0.3rem 0.55rem 0.8rem;
  transition: color var(--g-dur) var(--g-ease-orbit);
}
.gchat__tab-btn:last-child { padding-right: 0.8rem; }
.gchat__tab-btn:hover, .gchat__tab.is-active .gchat__tab-btn { color: var(--g-text); }
.gchat__tab-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A reply that landed in a tab the reader was not looking at. */
.gchat__dot {
  flex: none; width: 0.4rem; height: 0.4rem; border-radius: 50%;
  background: var(--g-accent);
}
.gchat__tab-x {
  flex: none; width: 1.3rem; height: 1.3rem; margin-right: 0.35rem;
  display: grid; place-items: center; border-radius: 50%;
  background: none; border: 0; cursor: pointer; color: var(--g-text-subtle);
  opacity: 0;
  transition: opacity var(--g-dur) var(--g-ease-orbit),
              color var(--g-dur) var(--g-ease-orbit),
              background-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__tab:hover .gchat__tab-x,
.gchat__tab.is-active .gchat__tab-x,
.gchat__tab-x:focus-visible { opacity: 1; }
@media (hover: none) { .gchat__tab-x { opacity: 1; } }
.gchat__tab-x:hover { color: var(--g-text); background: rgb(var(--g-tint) / 0.08); }
.gchat__tab-x svg { width: 0.65rem; height: 0.65rem; display: block; }
.gchat__new {
  flex: none; width: 2.5rem;
  display: grid; place-items: center;
  background: none; border: 0; border-left: 1px solid var(--g-hairline);
  color: var(--g-text-subtle); cursor: pointer;
  transition: color var(--g-dur) var(--g-ease-orbit),
              background-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__new:hover { color: var(--g-text); background: rgb(var(--g-tint) / 0.06); }
.gchat__new[disabled] { opacity: 0.35; cursor: default; background: none; }
.gchat__new svg { width: 1rem; height: 1rem; display: block; }

.gchat__log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--g-space-md);
  display: flex; flex-direction: column; gap: var(--g-space-sm);
  scrollbar-width: thin;
}

.gchat__msg { flex: none; min-width: 0; max-width: 92%; overflow-wrap: anywhere; font-size: var(--g-fs-small); line-height: 1.55; }
.gchat__msg p { white-space: pre-line; }
.gchat__msg p { margin: 0 0 .5rem; }
.gchat__msg p:last-child { margin-bottom: 0; }
.gchat__msg--bot {
  align-self: flex-start; color: var(--g-text-muted);
  background: var(--g-surface-sunken);
  border: 1px solid var(--g-hairline);
  border-radius: var(--g-radius) var(--g-radius) var(--g-radius) var(--g-radius-sm);
  padding: .65rem .85rem;
}
.gchat__msg--me {
  align-self: flex-end; color: var(--g-solid-fg);
  background: var(--g-solid-bg);
  border-radius: var(--g-radius) var(--g-radius) var(--g-radius-sm) var(--g-radius);
  padding: .65rem .85rem;
}
.gchat__msg a { color: var(--g-text); text-decoration-color: var(--g-accent); }

/* Links the assistant offers are destinations, so they look like the site's
   own controls rather than blue text inside a chat bubble.
   A source is labelled with its title, and in the workspace a title is
   whatever someone typed for a task or a key result, often a full sentence
   ("Prioritize Revenue experiments and record Continue / Change / Stop
   decisions"). Allowed to wrap, that sentence filled a pill radius three
   lines tall and became a lumpy oval. A pill is one line, so the label is
   held to one line and cut with an ellipsis; chat.js puts the whole title
   in the tooltip. */
.gchat__links { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; min-width: 0; }
.gchat__link {
  display: inline-block; max-width: 100%; box-sizing: border-box;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: var(--g-fs-caption); font-weight: var(--g-w-medium);
  color: var(--g-text); text-decoration: none;
  border: 1px solid var(--g-border); border-radius: var(--g-radius-pill);
  padding: .25rem .7rem;
  transition: border-color var(--g-dur) var(--g-ease-orbit),
              background-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__link:hover { border-color: var(--g-border-strong); background: rgb(var(--g-tint) / .08); }
/* Actions (the workspace's "Save as task") sit in the same row and look the
   same, minus the underline a link would get from a button reset. */
.gchat__action { font-family: inherit; background: none; cursor: pointer; line-height: inherit; }
.gchat__action[disabled] { cursor: default; opacity: .6; }

.gchat__typing { display: flex; gap: .25rem; padding: .8rem .85rem; }
.gchat__typing i {
  width: .38rem; height: .38rem; border-radius: 50%;
  background: var(--g-text-subtle); animation: gchat-blink 1.1s infinite;
}
.gchat__typing i:nth-child(2) { animation-delay: .18s; }
.gchat__typing i:nth-child(3) { animation-delay: .36s; }
@keyframes gchat-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ---- Suggested openers --------------------------------------------------
   A blank chat box is a small exam. Three concrete questions show what the
   thing is for and cost one tap instead of a sentence. */
.gchat__chips {
  display: flex; flex-wrap: wrap; gap: .35rem; flex: none;
  padding: 0 var(--g-space-md) var(--g-space-sm);
}
.gchat__chip {
  font: inherit; font-size: var(--g-fs-caption); color: var(--g-text-muted);
  background: transparent; border: 1px dashed var(--g-border);
  border-radius: var(--g-radius-pill); padding: .28rem .7rem; cursor: pointer;
  transition: color var(--g-dur) var(--g-ease-orbit), border-color var(--g-dur) var(--g-ease-orbit);
}
.gchat__chip:hover { color: var(--g-text); border-color: var(--g-border-strong); }

.gchat__form {
  display: flex; gap: .4rem; align-items: flex-end; flex: none;
  padding: var(--g-space-sm) var(--g-space-md) .55rem;
  border-top: 1px solid var(--g-hairline);
  background: var(--g-surface);
}
.gchat__input {
  flex: 1; min-width: 0; font: inherit; font-size: max(1rem, var(--g-fs-small));
  color: var(--g-text); background: var(--g-surface-sunken);
  border: 1px solid var(--g-border); border-radius: var(--g-radius);
  padding: .55rem .7rem; resize: none; max-height: 6rem; line-height: 1.45;
}
.gchat__input::placeholder { color: var(--g-text-subtle); }
.gchat__input:focus-visible {
  outline: none; border-color: var(--g-accent);
  box-shadow: 0 0 0 3px rgb(var(--g-tint) / .18);
}
.gchat__send {
  flex: none; width: 2.3rem; height: 2.3rem; border-radius: var(--g-radius);
  border: 1px solid var(--g-solid-bg); background: var(--g-solid-bg);
  color: var(--g-solid-fg); cursor: pointer; display: grid; place-items: center;
}
.gchat__send svg { width: 1rem; height: 1rem; }
.gchat__send[disabled] { opacity: .4; cursor: default; }

/* The only place the widget explains itself, now the header does not. It sits
   under the input rather than over the conversation, where it is available
   without being read twice. */
.gchat__foot {
  margin: 0; flex: none;
  padding: 0 var(--g-space-md) .8rem;
  font-family: var(--g-font-mono); font-size: .65rem; letter-spacing: .06em;
  line-height: 1.5; color: var(--g-text-subtle); background: var(--g-surface);
}

/* The hero's orbit is a drag target on touch and the launcher is fixed over
   the page. They never overlap on desktop, but on a short phone in landscape
   the button can land on the canvas, so it gets out of the way while a drag
   is in progress. */
.gchat.is-dragging-hero { opacity: .25; pointer-events: none; }
