/* Thinking-state options for peter-assistant, built from the GenAI4FFD logo.

   Plain SVG + CSS, no animation library. config.toml's custom_css loads this file
   into the app; section 10 binds the chosen options to the Chainlit fork's
   hooks, with no script (#73, #123). index.html in this folder shows every
   option.

   All classes start with gx-. State goes in data-state (avatars, panel rows)
   or data-busy (buttons); thinking-ui.js has small helpers to switch them.

   Sections
     1. Shared keyframes
     2. Pixel exhaust          large, start screen / first reply
     3. Blueprint build        large, long tools
     4. Small avatars          4a logo, cluster, glyph  4b matrix  4c halo
                               4d waiting state for all of them
     5. Pixel dots             typing indicator
     6. Status line            shimmer label + elapsed time
     7. Progress panel         plan items and ingestion stages (AgentTodos)
     8. Send / stop button
     9. Jump to latest         scroll-down button
    10. Chainlit bindings      what the app uses, on Chainlit's markup

   Variables (set them on a parent, e.g. :root)
     --gx-cut          background behind the logo pixels; their outline takes it
     --gx-muted        inactive text, tracks and outlines
     --gx-petrol       petrol blue; lighten it on dark backgrounds
     --gx-accent       accent pink: send button and the waiting state
     --gx-accent-busy  send button while an answer streams
     --gx-size         width of a small avatar
     --gx-wait         how long a prompt waits for the user (halo countdown)
     --gx-track        empty part of a stage bar
     --gx-jump-bg, --gx-jump-fg, --gx-jump-line   jump button colours

   Colours: petrol #005578, teal #008198, yellow #F8B92C, orange #F28925
   (from the logo); error red #E24B4A.

   Every section has a prefers-reduced-motion fallback: movement stops and
   at most a slow fade (gx-calm) remains. */


/* ==== 1. Shared keyframes ===================================================
   Used by several sections below; keep them when deleting a section. */
@keyframes gx-calm { 50% { opacity: .45; } }
@keyframes gx-pop { from { opacity: .4; transform: scale(.4); } to { opacity: 1; transform: scale(1); } }
@keyframes gx-spin { to { transform: rotate(360deg); } }
@keyframes gx-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-2px); }
  40% { transform: translateX(2px); }
  60% { transform: translateX(-1.5px); }
  80% { transform: translateX(1px); }
}


/* ==== 2. Pixel exhaust ======================================================
   The chimney sends its pixels up. Large (about 250 px); for the start screen
   or the wait for the first reply. Loops, so it also works as a plain SVG file.
   Markup  .gx-exhaust > svg with the logo paths, plus
           .gx-px     the four logo pixels (style --i: 0-3, staggers them)
           .gx-ember  loose pixels (style --dx, --dy, --r: where they fly)
           .gx-heat   a band that rises through the tower (inside a clip-path)
   States  none */
.gx-exhaust svg { display: block; width: 100%; height: auto; overflow: visible; }
.gx-exhaust .gx-px {
  stroke: var(--gx-cut, #fff); stroke-width: .75;
  transform-box: fill-box; transform-origin: 50% 100%;
  animation: gx-ex-breathe 1.4s ease-in-out infinite;
  animation-delay: calc(var(--i) * .14s);
}
.gx-exhaust .gx-ember {
  transform-box: fill-box; transform-origin: center; opacity: 0;
  animation: gx-ex-ember 2.8s cubic-bezier(.25, .6, .35, 1) infinite;
}
.gx-exhaust .gx-heat { opacity: 0; animation: gx-ex-heat 1.4s ease-in infinite; }
@keyframes gx-ex-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.06); }
}
@keyframes gx-ex-ember {
  0% { opacity: 0; transform: translate(0, 0) rotate(0) scale(.3); }
  12% { opacity: 1; transform: translate(0, -6px) rotate(0) scale(1); }
  60% { opacity: .85; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--r)) scale(.45); }
}
@keyframes gx-ex-heat {
  0% { opacity: 0; transform: translateY(0); }
  15%, 85% { opacity: .45; }
  100% { opacity: 0; transform: translateY(-100px); }
}
@media (prefers-reduced-motion: reduce) {
  .gx-exhaust .gx-ember, .gx-exhaust .gx-heat { animation: none; opacity: 0; }
  .gx-exhaust .gx-px { animation: gx-calm 2.4s ease-in-out infinite; }
}


/* ==== 3. Blueprint build ====================================================
   The hall draws itself as a floor plan on grid paper, fills in, then gets
   its pixels. Large (about 270 px); for long tools like model generation.
   Markup  .gx-build > svg with
           .gx-grid             the grid paper (a pattern + mask in <defs>)
           .gx-line             outlines, pathLength="1" (style --i staggers them)
           .gx-line.gx-solid    parts that fill in after drawing
           .gx-px               the four logo pixels
           The <defs> ids must be unique when several are on one page.
   States  none */
.gx-build svg { display: block; width: 100%; height: auto; overflow: visible; }
.gx-build .gx-grid { opacity: .26; }
.gx-build .gx-line {
  stroke-dasharray: 1; stroke-dashoffset: 1; stroke-linejoin: round;
  animation: gx-bp-draw 5.2s cubic-bezier(.65, 0, .35, 1) infinite;
  animation-delay: calc(var(--i) * .14s);
}
.gx-build .gx-line.gx-solid {
  fill-opacity: 0;
  animation: gx-bp-draw 5.2s cubic-bezier(.65, 0, .35, 1) infinite, gx-bp-fill 5.2s ease infinite;
  animation-delay: calc(var(--i) * .14s);
}
.gx-build .gx-px {
  stroke: var(--gx-cut, #fff); stroke-width: .75;
  transform-box: fill-box; transform-origin: center; opacity: 0;
  animation: gx-bp-pop 5.2s ease-out infinite;
  animation-delay: calc(var(--i) * .09s);
}
@keyframes gx-bp-draw {
  0% { stroke-dashoffset: 1; opacity: 1; }
  30%, 88% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}
@keyframes gx-bp-fill {
  0%, 26% { fill-opacity: 0; }
  44%, 100% { fill-opacity: 1; }
}
@keyframes gx-bp-pop {
  0%, 48% { opacity: 0; transform: scale(0); }
  55% { opacity: 1; transform: scale(1.2); }
  61%, 88% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.7); }
}
@media (prefers-reduced-motion: reduce) {
  .gx-build .gx-line, .gx-build .gx-line.gx-solid { animation: none; stroke-dashoffset: 0; fill-opacity: 1; }
  .gx-build .gx-px { opacity: 1; animation: gx-calm 2.4s ease-in-out infinite; }
}


/* ==== 4. Small avatars ======================================================
   The icon in front of each chat row, drawn for 16-32 px (--gx-size).
   All four versions share the states in data-state:
     idle, thinking, working, waiting (4d), done, error
   Chainlit draws its avatar as <img>, which can loop one animation but not
   change state; switching states needs a custom_js script. */

/* ---- 4a. Current logo, pixel cluster, chimney glyph ----
   Markup  span.gx-avatar[.gx-avatar--cluster | .gx-avatar--glyph] > svg >
           g.gx-px-group > .gx-px (style --i staggers them)
           .gx-avatar alone is the current logo, kept for comparison.
   Uses    gx-pop, gx-shake, gx-calm */
.gx-avatar { display: inline-block; width: var(--gx-size, 24px); line-height: 0; vertical-align: middle; }
.gx-avatar svg { display: block; width: 100%; height: auto; overflow: visible; }
.gx-avatar .gx-px { stroke: var(--gx-cut, #fff); stroke-width: .75; transform-box: fill-box; transform-origin: center; transition: fill .25s; }
.gx-avatar .gx-px-group { transform-box: fill-box; transform-origin: center; }
.gx-avatar .gx-petrol { fill: var(--gx-petrol, #005578); }
.gx-avatar--cluster .gx-px { stroke-width: 1.8; }
.gx-avatar--glyph .gx-px { stroke-width: .6; }
.gx-avatar[data-state="thinking"] .gx-px {
  animation: gx-av-wave 1.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * .15s);
}
.gx-avatar[data-state="working"] .gx-px-group { animation: gx-av-turn 2.4s cubic-bezier(.7, 0, .3, 1) infinite; }
.gx-avatar[data-state="done"] .gx-px {
  animation: gx-pop .5s cubic-bezier(.3, 1.5, .5, 1) both;
  animation-delay: calc(var(--i) * .06s);
}
.gx-avatar[data-state="error"] { animation: gx-shake .45s ease-in-out; }
.gx-avatar[data-state="error"] .gx-px { fill: #E24B4A; }
@keyframes gx-av-wave {
  0%, 100% { opacity: .3; transform: scale(.55); }
  40% { opacity: 1; transform: scale(1.12); }
  60% { opacity: 1; transform: scale(1); }
}
@keyframes gx-av-turn {
  0%, 12% { transform: rotate(0); }
  25%, 37% { transform: rotate(90deg); }
  50%, 62% { transform: rotate(180deg); }
  75%, 87% { transform: rotate(270deg); }
  100% { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .gx-avatar .gx-px, .gx-avatar .gx-px-group, .gx-avatar[data-state] { animation: none !important; }
  .gx-avatar[data-state="thinking"] .gx-px-group,
  .gx-avatar[data-state="working"] .gx-px-group { animation: gx-calm 1.8s ease-in-out infinite !important; }
}

/* ---- 4b. Pixel matrix ----
   The logo rebuilt from nine cells; while working, an orange cell travels
   around the edge.
   Markup  span.gx-matrix > svg > nine rect.gx-cell (style --d staggers them),
           .gx-off for empty cells, .gx-ring for outlined ones, .gx-petrol /
           .gx-petrol-ring for the petrol ones, and one rect.gx-shuttle.
   Uses    gx-pop, gx-shake, gx-calm */
.gx-matrix { display: inline-block; width: var(--gx-size, 24px); line-height: 0; vertical-align: middle; color: var(--gx-muted, #85847e); }
.gx-matrix svg { display: block; width: 100%; height: auto; overflow: visible; }
.gx-matrix .gx-cell { transform-box: fill-box; transform-origin: center; transition: fill .25s, stroke .25s; }
.gx-matrix .gx-off { fill: currentColor; opacity: .12; }
.gx-matrix .gx-ring { fill: none; stroke-width: 1.4; }
.gx-matrix .gx-petrol { fill: var(--gx-petrol, #005578); }
.gx-matrix .gx-petrol-ring { stroke: var(--gx-petrol, #005578); }
.gx-matrix .gx-shuttle { opacity: 0; fill: #F28925; stroke: var(--gx-cut, #fff); stroke-width: 1; }
.gx-matrix[data-state="thinking"] .gx-cell:not(.gx-off) {
  animation: gx-mx-wave 1.3s ease-in-out infinite;
  animation-delay: calc(var(--d) * .13s);
}
.gx-matrix[data-state="thinking"] .gx-off {
  fill: #F28925;
  animation: gx-mx-spark 1.3s ease-in-out infinite;
  animation-delay: calc(var(--d) * .13s);
}
.gx-matrix[data-state="working"] .gx-shuttle { opacity: 1; animation: gx-mx-conveyor 2.4s ease-in-out infinite; }
.gx-matrix[data-state="done"] .gx-cell:not(.gx-off) {
  animation: gx-pop .45s cubic-bezier(.3, 1.5, .5, 1) both;
  animation-delay: calc(var(--d) * .05s);
}
.gx-matrix[data-state="error"] { animation: gx-shake .45s ease-in-out; }
.gx-matrix[data-state="error"] .gx-cell:not(.gx-off):not(.gx-ring) { fill: #E24B4A; }
.gx-matrix[data-state="error"] .gx-ring { stroke: #E24B4A; }
@keyframes gx-mx-wave { 0%, 100% { opacity: .35; transform: scale(.8); } 45% { opacity: 1; transform: scale(1); } }
@keyframes gx-mx-spark { 0%, 100% { opacity: .06; } 45% { opacity: .7; } }
@keyframes gx-mx-conveyor {
  0%, 100% { transform: translate(0, 0); }
  12.5% { transform: translate(8.75px, 0); }
  25% { transform: translate(17.5px, 0); }
  37.5% { transform: translate(17.5px, 8.75px); }
  50% { transform: translate(17.5px, 17.5px); }
  62.5% { transform: translate(8.75px, 17.5px); }
  75% { transform: translate(0, 17.5px); }
  87.5% { transform: translate(0, 8.75px); }
}
@media (prefers-reduced-motion: reduce) {
  .gx-matrix .gx-cell, .gx-matrix .gx-shuttle, .gx-matrix[data-state] { animation: none !important; }
  .gx-matrix[data-state="working"] .gx-shuttle { opacity: 0; }
  .gx-matrix[data-state="thinking"] svg, .gx-matrix[data-state="working"] svg { animation: gx-calm 1.8s ease-in-out infinite; }
}

/* ---- 4c. Halo ----
   The pixel cluster stays still; a thin ring around it shows the state.
   Thinking: one orange arc circles. Working: the four logo colours circle,
   like the send button's ring. Done: the ring closes once in teal and fades.
   Markup  span.gx-halo > svg with
           circle.gx-halo-track            faint full ring
           g.gx-halo-spin > four circle.gx-halo-arc.gx-halo-a0 … a3
                                           (pathLength="100"; stroke-dashoffset
                                           0, -25, -50, -75 set in the markup)
           g.gx-halo-mark > svg > the four .gx-px of the cluster
   Uses    gx-spin, gx-pop, gx-shake, gx-calm */
.gx-halo { display: inline-block; width: var(--gx-size, 24px); line-height: 0; vertical-align: middle; }
.gx-halo > svg { display: block; width: 100%; height: auto; overflow: visible; }
.gx-halo .gx-px { stroke: var(--gx-cut, #fff); stroke-width: 2.4; transform-box: fill-box; transform-origin: center; }
.gx-halo .gx-halo-mark { transform-box: fill-box; transform-origin: center; }
.gx-halo .gx-halo-spin { transform-box: view-box; transform-origin: 50% 50%; }
.gx-halo .gx-halo-track { fill: none; stroke: var(--gx-muted, #85847e); stroke-width: 1.5; opacity: 0; transition: opacity .3s; }
.gx-halo .gx-halo-arc { fill: none; stroke-width: 1.5; stroke-linecap: round; opacity: 0; transition: opacity .25s; }
.gx-halo .gx-halo-a0 { stroke: var(--gx-petrol, #005578); }
.gx-halo[data-state="thinking"] .gx-halo-track { opacity: .2; }
.gx-halo[data-state="thinking"] .gx-halo-a3 { opacity: 1; stroke-dasharray: 26 74; }
.gx-halo[data-state="thinking"] .gx-halo-spin { animation: gx-spin 1.1s linear infinite; }
.gx-halo[data-state="working"] .gx-halo-arc { opacity: 1; stroke-dasharray: 19 81; }
.gx-halo[data-state="working"] .gx-halo-spin { animation: gx-spin 1.6s linear infinite; }
.gx-halo[data-state="done"] .gx-halo-a1 { stroke-dasharray: 100; animation: gx-ha-close 1s ease-out both; }
.gx-halo[data-state="done"] .gx-halo-mark { animation: gx-pop .5s cubic-bezier(.3, 1.5, .5, 1) both; }
.gx-halo[data-state="error"] { animation: gx-shake .45s ease-in-out; }
.gx-halo[data-state="error"] .gx-halo-a0 { opacity: 1; stroke: #E24B4A; stroke-dasharray: 100 0; }
@keyframes gx-ha-close {
  0% { opacity: 1; stroke-dashoffset: 100; }
  45% { opacity: 1; stroke-dashoffset: 0; }
  100% { opacity: 0; stroke-dashoffset: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .gx-halo .gx-halo-spin, .gx-halo .gx-halo-mark, .gx-halo[data-state] { animation: none !important; }
  .gx-halo[data-state="thinking"] .gx-halo-arc, .gx-halo[data-state="working"] .gx-halo-arc { animation: gx-calm 1.8s ease-in-out infinite; }
}

/* ---- 4d. Waiting for the user (all avatars) ----
   When the agent asks something (ask_user, request_ingestion_confirmation):
   the pixels hold still and one pulses in the accent pink. On the halo the
   ring empties over --gx-wait, the time the prompt stays open (300 s in the
   app). Under the prompt, .gx-wait shows the time left.
   Markup  data-state="waiting" on any avatar above;
           span.gx-wait > span (label) + span.gx-wait-time (filled by
           GxThinkingUI.startCountdown)
   Uses    gx-calm */
.gx-avatar[data-state="waiting"] .gx-px,
.gx-halo[data-state="waiting"] .gx-px { opacity: .55; transition: opacity .25s, fill .25s; }
.gx-avatar[data-state="waiting"] .gx-px-group > :first-child,
.gx-halo[data-state="waiting"] .gx-halo-mark svg > :first-child,
.gx-matrix[data-state="waiting"] .gx-cell:nth-of-type(3) {
  opacity: 1; fill: var(--gx-accent, #D81B60);
  animation: gx-wt-pulse 1.6s ease-in-out infinite;
}
.gx-halo[data-state="waiting"] .gx-halo-track { opacity: .2; }
.gx-halo[data-state="waiting"] .gx-halo-a0 {
  opacity: 1; stroke: var(--gx-accent, #D81B60); stroke-dasharray: 100;
  animation: gx-wt-count var(--gx-wait, 300s) linear forwards;
}
.gx-wait { display: inline-flex; align-items: baseline; gap: 8px; font-size: .9em; }
.gx-wait-time { color: var(--gx-muted, #85847e); font-variant-numeric: tabular-nums; }
@keyframes gx-wt-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(.8); } }
@keyframes gx-wt-count { from { stroke-dashoffset: 0; } to { stroke-dashoffset: 100; } }
@media (prefers-reduced-motion: reduce) {
  .gx-avatar[data-state="waiting"] .gx-px-group > :first-child,
  .gx-halo[data-state="waiting"] .gx-halo-mark svg > :first-child,
  .gx-matrix[data-state="waiting"] .gx-cell:nth-of-type(3) { animation: gx-calm 1.8s ease-in-out infinite !important; }
}


/* ==== 5. Pixel dots =========================================================
   Four squares in the logo colours hop in turn; a typing indicator for the
   gap between sending and the first token. Sized in em: set font-size.
   Markup  span.gx-dots > four <i>
   States  none (also used inside the jump button, section 9) */
.gx-dots { display: inline-flex; align-items: center; gap: .24em; height: 1em; vertical-align: middle; }
.gx-dots i {
  display: block; width: .44em; height: .44em; border-radius: .1em; background: #F28925;
  animation: gx-dt-hop 1.3s cubic-bezier(.45, 0, .55, 1) infinite;
  animation-delay: calc(var(--i) * .13s);
}
.gx-dots i:nth-child(1) { --i: 0; background: var(--gx-petrol, #005578); }
.gx-dots i:nth-child(2) { --i: 1; background: #008198; }
.gx-dots i:nth-child(3) { --i: 2; background: #F8B92C; }
.gx-dots i:nth-child(4) { --i: 3; background: #F28925; }
@keyframes gx-dt-hop {
  0%, 55%, 100% { transform: translateY(0) rotate(0); opacity: .5; }
  25% { transform: translateY(-.42em) rotate(45deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .gx-dots i { animation: gx-calm 1.8s ease-in-out infinite; animation-delay: calc(var(--i) * .2s); }
}


/* ==== 6. Status line ========================================================
   A label that shimmers in the logo's yellow and orange, with elapsed time.
   .gx-shimmer also works on its own, on any running step label.
   Markup  div.gx-status > span.gx-status-label.gx-shimmer + span.gx-status-time
           (both filled by GxThinkingUI.startStatus)
   States  none; .is-swapping on the label while it changes text */
.gx-status { display: inline-flex; align-items: center; gap: 10px; }
.gx-shimmer {
  color: transparent;
  background: linear-gradient(100deg, var(--gx-muted, #85847e) 0 40%, #F8B92C 47%, #F28925 53%, var(--gx-muted, #85847e) 60% 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  animation: gx-st-shimmer 2.2s linear infinite;
}
.gx-status-label { display: inline-block; transition: opacity .18s, transform .18s; }
.gx-status-label.is-swapping { opacity: 0; transform: translateY(-4px); }
.gx-status-time { color: var(--gx-muted, #85847e); font-size: .85em; font-variant-numeric: tabular-nums; }
@keyframes gx-st-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .gx-shimmer { animation: none; background: none; color: var(--gx-muted, #85847e); }
}


/* ==== 7. Progress panel =====================================================
   A restyle of AgentTodos.jsx: status marks for the plan and a bar per
   ingestion stage, driven by the n / total the panel already receives.
   Markup  div.gx-panel > div.gx-panel-head + ul, with
           li.gx-todo  > span.gx-check + text                     (plan item)
           li.gx-stage > span.gx-check + span.gx-stage-title
                         + span.gx-stage-meta + span.gx-bar > span.gx-bar-fill
           A stage's progress is --p (0 to 1); .gx-stage--bare hides the bar
           for stages without counts. GxThinkingUI.setStage fills a row.
   States  data-state on .gx-check, .gx-todo and .gx-stage:
           pending (default), working, done, error
   Uses    gx-calm */
.gx-panel { display: grid; gap: 12px; font-size: 13px; line-height: 1.45; }
.gx-panel-head { color: var(--gx-muted, #85847e); font-size: 12px; font-weight: 500; margin-bottom: 6px; }
.gx-panel ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.gx-todo { display: flex; align-items: flex-start; gap: 8px; }
.gx-todo .gx-check { margin-top: 3px; }
.gx-todo[data-state="done"] { color: var(--gx-muted, #85847e); }

/* the status mark: an outlined square that fills, checks or turns red */
.gx-check {
  position: relative; display: inline-block; flex: none; width: 12px; height: 12px; border-radius: 3px;
  box-shadow: inset 0 0 0 1.5px var(--gx-muted, #85847e); transition: background .25s, box-shadow .25s;
}
.gx-check::after { content: ""; position: absolute; }
.gx-check[data-state="working"] { box-shadow: inset 0 0 0 1.5px #F28925; }
.gx-check[data-state="working"]::after {
  inset: 3px; border-radius: 1.5px; background: #F28925;
  animation: gx-ck-fill 1.4s ease-in-out infinite;
}
.gx-check[data-state="done"] { box-shadow: none; background: #008198; }
.gx-check[data-state="done"]::after {
  left: 4.2px; top: 1.8px; width: 3.4px; height: 6.4px;
  border: solid #fff; border-width: 0 1.6px 1.6px 0; transform: rotate(45deg);
  animation: gx-ck-pop .35s cubic-bezier(.3, 1.5, .5, 1) both;
}
.gx-check[data-state="error"] { box-shadow: none; background: #E24B4A; }
.gx-check[data-state="error"]::after { left: 3px; right: 3px; top: 5.2px; height: 1.6px; border-radius: 1px; background: #fff; }
@keyframes gx-ck-fill { 0%, 100% { opacity: .55; transform: scale(.4); } 50% { opacity: 1; transform: scale(1); } }
@keyframes gx-ck-pop { from { opacity: 0; transform: rotate(45deg) scale(.4); } to { opacity: 1; transform: rotate(45deg) scale(1); } }

/* a stage row: mark, title, meta text, and the bar underneath */
.gx-stage { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; column-gap: 8px; row-gap: 5px; }
.gx-stage-meta { color: var(--gx-muted, #85847e); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.gx-bar {
  grid-column: 2 / -1; position: relative; height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--gx-track, rgba(128, 128, 128, .22));
}
.gx-bar-fill {
  position: absolute; inset: 0; background: #008198; border-radius: 2px;
  transform-origin: left center; transform: scaleX(var(--p, 0));
  transition: transform .5s cubic-bezier(.3, 0, .2, 1), background .25s;
}
.gx-stage[data-state="working"] .gx-bar::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .35), transparent);
  animation: gx-bar-sheen 2s ease-in-out infinite;
}
.gx-stage[data-state="error"] .gx-bar-fill { background: #E24B4A; }
.gx-stage--bare .gx-bar { display: none; }
@keyframes gx-bar-sheen { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
@media (prefers-reduced-motion: reduce) {
  .gx-check[data-state="working"]::after { animation: gx-calm 1.8s ease-in-out infinite; transform: scale(.7); }
  .gx-stage[data-state="working"] .gx-bar::after { animation: none; display: none; }
  .gx-bar-fill { transition: none; }
}


/* ==== 8. Send / stop button =================================================
   While an answer streams, the send button turns into a stop button inside a
   ring of the four logo colours.
   Markup  button.gx-send > span.gx-send-ring
                          + svg.gx-send-icon > .gx-send-arrow + .gx-send-stop
   States  data-busy="true" | "false" (GxThinkingUI.setBusy)
   Uses    gx-spin */
.gx-send {
  position: relative; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--gx-accent, #D81B60); color: #fff;
  transition: background .2s, transform .15s;
}
.gx-send:active { transform: scale(.94); }
.gx-send:focus-visible { outline: 2px solid var(--gx-accent, #D81B60); outline-offset: 7px; }
.gx-send-icon { width: 20px; height: 20px; overflow: visible; }
.gx-send-arrow, .gx-send-stop {
  transform-box: fill-box; transform-origin: center;
  transition: opacity .2s, transform .28s cubic-bezier(.3, 1.4, .5, 1);
}
.gx-send-stop { opacity: 0; transform: scale(.3); }
.gx-send-ring {
  position: absolute; inset: -5px; border-radius: 50%;
  background: conic-gradient(#005578 0 21%, transparent 0 25%, #008198 0 46%, transparent 0 50%,
                             #F8B92C 0 71%, transparent 0 75%, #F28925 0 96%, transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  opacity: 0; transform: scale(.85); transition: opacity .25s, transform .3s;
}
.gx-send[data-busy="true"] { background: var(--gx-accent-busy, #A3154A); }
.gx-send[data-busy="true"] .gx-send-arrow { opacity: 0; transform: translateY(-6px) scale(.6); }
.gx-send[data-busy="true"] .gx-send-stop { opacity: 1; transform: scale(1); }
.gx-send[data-busy="true"] .gx-send-ring { opacity: 1; animation: gx-spin 1.6s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .gx-send[data-busy="true"] .gx-send-ring { animation: none; transform: none; }
}


/* ==== 9. Jump to latest =====================================================
   Restyles the round scroll-down button Chainlit shows when you scroll up in
   the chat. While the agent still works below, the arrow gives way to the
   pixel dots; once the turn has ended it is a plain arrow.
   Markup  button.gx-jump > svg.gx-jump-arrow + span.gx-dots (section 5)
           hidden while the chat is at the bottom
   States  data-busy="true" | "false" */
.gx-jump {
  width: 36px; height: 36px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: var(--gx-jump-bg, Canvas); color: var(--gx-jump-fg, CanvasText);
  border: 1px solid var(--gx-jump-line, rgba(128, 128, 128, .3));
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  animation: gx-jp-in .2s ease-out; transition: transform .15s;
}
.gx-jump[hidden] { display: none; }
.gx-jump:active { transform: scale(.94); }
.gx-jump > * { grid-area: 1 / 1; transition: opacity .2s, transform .25s; }
.gx-jump-arrow { width: 18px; height: 18px; }
.gx-jump .gx-dots { font-size: 10px; opacity: 0; transform: scale(.6); }
.gx-jump[data-busy="true"] .gx-jump-arrow { opacity: 0; transform: translateY(4px) scale(.6); }
.gx-jump[data-busy="true"] .gx-dots { opacity: 1; transform: none; }
@keyframes gx-jp-in { from { opacity: 0; transform: translateY(6px); } }


/* ==== 10. Chainlit bindings =================================================
   How the app uses the sections above in Chainlit's own markup (#73), on
   hooks the Chainlit fork provides (#123): data-avatar-state and
   data-running-step on each row's avatar, the avatar SVG drawn inline
   (ui.inline_svg_avatars in .chainlit/config.toml), the running step's
   timer (ui.step_timer), four <i> in the loading cursor and in the
   scroll-down button's .scroll-busy. No script.
   Colours follow Chainlit's theme tokens; the dark petrol from the footer of
   index.html applies under Chainlit's .dark class. */
:root {
  --gx-cut: hsl(var(--background));
  --gx-muted: hsl(var(--muted-foreground));
  --gx-accent: hsl(var(--primary));
}
.dark { --gx-petrol: #2C86AE; }

/* Row avatar (4a): the pixel cluster (public/avatars/peter.svg, inline).
   The row's state: thinking while its answer streams or the Nachdenken /
   Thinking step runs (i18n "thinking.label"), working while another step
   runs or a BlueprintCard (data-gx-building) is live, waiting while an ask
   card (data-gx-waiting) is open, done once it has ended. */
.inline-svg-avatar .gx-px {
  stroke: var(--gx-cut); stroke-width: 1.8;
  transform-box: fill-box; transform-origin: center; transition: fill .25s, opacity .25s;
}
.inline-svg-avatar .gx-px-group { transform-box: fill-box; transform-origin: center; }
[data-avatar-state="done"] .inline-svg-avatar .gx-px {
  animation: gx-pop .5s cubic-bezier(.3, 1.5, .5, 1) both;
  animation-delay: calc(var(--i) * .06s);
}
[data-avatar-state="running"] .inline-svg-avatar .gx-px-group,
.ai-message:has([data-gx-building="true"]) > [data-avatar-state] .inline-svg-avatar .gx-px-group {
  animation: gx-av-turn 2.4s cubic-bezier(.7, 0, .3, 1) infinite;
}
[data-avatar-state="streaming"] .inline-svg-avatar .gx-px,
[data-running-step="Nachdenken"] .inline-svg-avatar .gx-px,
[data-running-step="Thinking"] .inline-svg-avatar .gx-px {
  animation: gx-av-wave 1.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * .15s);
}
[data-running-step="Nachdenken"] .inline-svg-avatar .gx-px-group,
[data-running-step="Thinking"] .inline-svg-avatar .gx-px-group { animation: none; }
/* A live BlueprintCard means working, whatever the row's step. */
.ai-message:has([data-gx-building="true"]) > [data-avatar-state] .inline-svg-avatar .gx-px { animation: none; }
/* Waiting (4d) wins over the others. */
.ai-message:has([data-gx-waiting="true"]) > [data-avatar-state] .inline-svg-avatar .gx-px-group { animation: none; }
.ai-message:has([data-gx-waiting="true"]) > [data-avatar-state] .inline-svg-avatar .gx-px { animation: none; opacity: .55; }
.ai-message:has([data-gx-waiting="true"]) > [data-avatar-state] .inline-svg-avatar .gx-px-group > :first-child {
  opacity: 1; fill: var(--gx-accent, #D81B60);
  animation: gx-wt-pulse 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .inline-svg-avatar .gx-px, .inline-svg-avatar .gx-px-group { animation: none !important; }
  [data-avatar-state="running"] .inline-svg-avatar .gx-px-group,
  [data-avatar-state="streaming"] .inline-svg-avatar .gx-px-group { animation: gx-calm 1.8s ease-in-out infinite !important; }
}

/* Running step label (6): the brand shimmer instead of Chainlit's grey one;
   the fork's timer after it keeps the muted colour. */
.loading-shimmer {
  background: linear-gradient(100deg, var(--gx-muted) 0 40%, #F8B92C 47%, #F28925 53%, var(--gx-muted) 60% 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text;
  animation: gx-st-shimmer 2.2s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .loading-shimmer { animation: none; background: none; -webkit-text-fill-color: var(--gx-muted); }
}

/* Loading cursor and scroll-down button (5, 9): the pixel dots, from the
   four <i> the fork puts in them. */
.loading-cursor {
  display: inline-flex; align-items: center; gap: .24em; height: 1em; width: auto;
  background: none; border-radius: 0; animation: none;
  -webkit-mask-image: none; mask-image: none; vertical-align: middle;
}
.loading-cursor > i, #scroll-down-button > .scroll-busy > i {
  display: block; width: .44em; height: .44em; border-radius: .1em; background: #F28925;
  animation: gx-dt-hop 1.3s cubic-bezier(.45, 0, .55, 1) infinite;
  animation-delay: calc(var(--i) * .13s);
}
.loading-cursor > i:nth-child(1), #scroll-down-button > .scroll-busy > i:nth-child(1) { --i: 0; background: var(--gx-petrol, #005578); }
.loading-cursor > i:nth-child(2), #scroll-down-button > .scroll-busy > i:nth-child(2) { --i: 1; background: #008198; }
.loading-cursor > i:nth-child(3), #scroll-down-button > .scroll-busy > i:nth-child(3) { --i: 2; background: #F8B92C; }
.loading-cursor > i:nth-child(4), #scroll-down-button > .scroll-busy > i:nth-child(4) { --i: 3; background: #F28925; }
@media (prefers-reduced-motion: reduce) {
  .loading-cursor > i, #scroll-down-button > .scroll-busy > i { animation: gx-calm 1.8s ease-in-out infinite; animation-delay: calc(var(--i) * .2s); }
}
#scroll-down-button > svg { transition: opacity .2s, transform .25s; }
#scroll-down-button > .scroll-busy {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: .24em;
  font-size: 8px; opacity: 0; transform: scale(.6); transition: opacity .2s, transform .25s;
}
#scroll-down-button[data-busy="true"] > svg { opacity: 0; transform: translateY(4px) scale(.6); }
#scroll-down-button[data-busy="true"] > .scroll-busy { opacity: 1; transform: none; }

/* Stop button (8): the ring in the logo colours while the answer streams. */
#stop-button { position: relative; overflow: visible; }
#stop-button::before {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(#005578 0 21%, transparent 0 25%, #008198 0 46%, transparent 0 50%,
                             #F8B92C 0 71%, transparent 0 75%, #F28925 0 96%, transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2.5px));
  animation: gx-spin 1.6s linear infinite;
}
@media (prefers-reduced-motion: reduce) { #stop-button::before { animation: none; } }

/* Blueprint card (3) for long tools, BlueprintCard.jsx (#78). */
.gx-build-card {
  display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 20px; align-items: center;
  margin: 4px 0; padding: 14px 18px; border: 1px solid hsl(var(--border)); border-radius: 14px;
}
.gx-build-title { font-weight: 600; font-size: 15px; }
.gx-build-step { font-size: 14.5px; margin-top: 2px; }
.gx-build-meta { font-size: 13px; color: var(--gx-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .gx-build-card { grid-template-columns: 96px minmax(0, 1fr); gap: 14px; } }

/* Progress panel (7), AgentTodos.jsx: a finished run's panel stays as a
   record, so its marks and bars stop moving. */
[data-agent-todos][data-active="false"] .gx-check::after,
[data-agent-todos][data-active="false"] .gx-bar::after { animation: none; }

/* Chat scroller (#106, #107): Chainlit's .custom-scrollbar look (thin,
   muted thumb, no track) at the right edge of the chat. The gutter is
   always reserved: while an answer streams, Chainlit sizes a spacer under
   the last user message to just fill the view, so the content keeps
   crossing the overflow threshold; a scrollbar that came and went changed
   the width, re-wrapped the text and flickered. */
.relative.flex-col.flex-grow.overflow-y-auto > .flex-col.flex-grow.overflow-y-auto {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--muted-foreground) / .3) transparent;
}
.relative.flex-col.flex-grow.overflow-y-auto > .flex-col.flex-grow.overflow-y-auto::-webkit-scrollbar { width: 4px; }
.relative.flex-col.flex-grow.overflow-y-auto > .flex-col.flex-grow.overflow-y-auto::-webkit-scrollbar-track { background: transparent; }
.relative.flex-col.flex-grow.overflow-y-auto > .flex-col.flex-grow.overflow-y-auto::-webkit-scrollbar-thumb {
  background-color: hsl(var(--muted-foreground) / .3); border-radius: 2px;
}
