/* Features: Ticket Research stage (#ai-assist in features.dc.html).
   One press on a ticket in four movements: Gather (the sources arrive and
   stream into the model), Write (the plan streams in under its progress line),
   Cite (each step lights the sources it rests on, joined by a thread) and
   Search (a web query loses the name, address, ticket number and host name
   before it crosses the network line). js/features-research.js drives the
   states below and draws the threads, the model and the line on the canvas.
   Without the script, or before it mounts, the markup is the finished
   picture: every source in, the plan written, the query already cleaned.
   Colours come from the page's --stage-* variables, so it follows the theme. */

.rsx { container: rsx / inline-size; position: relative; margin: 0; min-width: 0; border: 1px solid rgba(var(--stage-ink), .1); border-radius: 14px; background: var(--stage-bg); color: var(--stage-text); overflow: hidden; isolation: isolate; -webkit-tap-highlight-color: transparent; box-shadow: 0 40px 110px -70px color-mix(in srgb, var(--stage-teal) 55%, transparent); }
.rsx::before { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: radial-gradient(circle at 1px 1px, rgba(var(--stage-ink), .1) 1px, transparent 0); background-size: 22px 22px; -webkit-mask-image: radial-gradient(70% 62% at 50% 46%, #000 0%, transparent 82%); mask-image: radial-gradient(70% 62% at 50% 46%, #000 0%, transparent 82%); }
.rsx__canvas { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
.rsx__shade { position: absolute; inset: 0; z-index: 0; pointer-events: none; background: radial-gradient(130% 100% at 50% 40%, transparent 55%, rgba(var(--stage-shade), .6) 100%); }

/* Caption and the ticket being researched */
.rsx__top { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px 32px; padding: 24px 28px 0; }
.rsx__captions { flex: 1 1 300px; min-width: 0; display: grid; }
.rsx__caption { grid-area: 1 / 1; margin: 0; max-width: 34ch; font: 400 15px/1.5 var(--f-sans); letter-spacing: -.005em; color: rgba(var(--stage-ink), .86); text-wrap: pretty; transition: opacity .8s ease, transform 1s cubic-bezier(.2, .7, .2, 1); }
.rsx__caption:not(:first-child) { opacity: 0; }
.rsx.is-live .rsx__caption { opacity: 0; transform: translateY(8px); transition-delay: 0s; }
.rsx.is-live .rsx__caption.is-on { opacity: 1; transform: none; transition-delay: .3s; }

.rsx__ticket { flex: none; display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; height: 38px; padding: 0 5px 0 12px; box-sizing: border-box; border: 1px solid rgba(var(--stage-ink), .14); border-radius: 9px; background: var(--stage-bg); }
.rsx__ticket b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 13px/1 var(--f-sans); letter-spacing: -.005em; }
.rsx__num { flex: none; font: 400 11px/1 var(--f-mono); color: var(--stage-faint); }
.rsx__go { flex: none; display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px 0 6px; box-sizing: border-box; border-radius: 6px; background: color-mix(in srgb, var(--stage-teal) 15%, transparent); color: var(--stage-teal); font: 500 12px/1 var(--f-sans); transition: transform .16s ease, background-color .2s ease, box-shadow .5s ease; }
.rsx__go kbd { display: grid; place-items: center; width: 17px; height: 17px; box-sizing: border-box; border: 1px solid color-mix(in srgb, var(--stage-teal) 45%, transparent); border-radius: 4px; font: 500 11px/1 var(--f-mono); }
.rsx__go.is-pressed { transform: scale(.93); background: color-mix(in srgb, var(--stage-teal) 30%, transparent); box-shadow: 0 0 0 7px color-mix(in srgb, var(--stage-teal) 10%, transparent); }

/* Sources, the model, the plan */
.rsx__body { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 290px) minmax(120px, 1fr) minmax(0, 400px); align-items: center; gap: 0 24px; padding: 28px 28px 18px; }

.rsx__sources { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rsx-src { --k: var(--stage-teal); display: grid; grid-template-columns: 24px minmax(0, 1fr); align-items: center; gap: 6px 11px; padding: 10px 12px; border: 1px solid rgba(var(--stage-ink), .1); border-radius: 9px; background: linear-gradient(rgba(var(--stage-ink), .025), rgba(var(--stage-ink), .025)), var(--stage-bg); cursor: default; transition: opacity .45s ease, transform .6s cubic-bezier(.2, .7, .2, 1), border-color .3s ease, background-color .3s ease; }
.rsx-src[data-kind='linked'] { --k: var(--stage-blue); }
.rsx-src[data-kind='article'] { --k: var(--stage-violet); }
.rsx-src[data-kind='file'] { --k: var(--stage-text); }
.rsx-src__n { grid-row: span 2; display: grid; place-items: center; width: 24px; height: 24px; box-sizing: border-box; border: 1px solid color-mix(in srgb, var(--k) 50%, transparent); border-radius: 6px; font: 500 11px/1 var(--f-mono); color: var(--k); transition: background-color .3s ease, color .3s ease; }
.rsx-src__meta { display: flex; gap: 8px; min-width: 0; font: 400 11px/1 var(--f-mono); color: var(--stage-faint); white-space: nowrap; }
.rsx-src__meta span:first-child { color: var(--k); }
.rsx-src b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 13px/1.2 var(--f-sans); letter-spacing: -.005em; }
.rsx-src.is-lit { border-color: color-mix(in srgb, var(--k) 55%, transparent); background: linear-gradient(color-mix(in srgb, var(--k) 10%, transparent), color-mix(in srgb, var(--k) 10%, transparent)), var(--stage-bg); }
.rsx-src.is-lit .rsx-src__n { background: var(--k); color: var(--stage-bg); }
.rsx-src.is-dim { opacity: .36; }
.rsx.is-live .rsx-src:not(.is-in) { opacity: 0; transform: translateX(-14px); }

.rsx__core { align-self: stretch; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; }
.rsx__orb { width: 112px; height: 112px; box-sizing: border-box; border: 1px solid color-mix(in srgb, var(--stage-teal) 40%, transparent); border-radius: 50%; box-shadow: inset 0 0 0 22px var(--stage-bg), inset 0 0 0 23px color-mix(in srgb, var(--stage-teal) 30%, transparent); }
.rsx.is-drawn .rsx__orb { border-color: transparent; box-shadow: none; }
.rsx__model { margin: 16px 0 0; text-align: center; font: 500 12px/1.3 var(--f-sans); white-space: nowrap; }
.rsx__model small { display: block; margin-top: 3px; font: 400 11px/1.3 var(--f-mono); color: var(--stage-teal); }

.rsx__plan { min-width: 0; padding: 16px 18px 12px; border: 1px solid rgba(var(--stage-ink), .14); border-radius: 12px; background: linear-gradient(rgba(var(--stage-ink), .035), rgba(var(--stage-ink), .02)), var(--stage-bg); }
.rsx__head { margin: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font: 500 14px/1 var(--f-sans); letter-spacing: -.01em; }
.rsx__head span { font: 400 11px/1 var(--f-mono); color: var(--stage-faint); }
.rsx__pipe { margin: 12px 0 0; padding: 0 0 12px; list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; border-bottom: 1px solid rgba(var(--stage-ink), .1); font: 400 11px/1 var(--f-mono); color: var(--stage-faint); }
.rsx__pipe li { display: flex; align-items: center; gap: 6px; transition: color .3s ease; }
.rsx__pipe li::before { content: ''; flex: none; width: 8px; height: 8px; box-sizing: border-box; border: 1px solid var(--stage-teal); border-radius: 50%; background: var(--stage-teal); }
.rsx.is-live .rsx__pipe li:not(.is-done)::before { border-color: rgba(var(--stage-ink), .3); background: transparent; }
.rsx.is-live .rsx__pipe li.is-on { color: var(--stage-text); }
.rsx.is-live .rsx__pipe li.is-on::before { border-color: var(--stage-teal); border-top-color: transparent; animation: rsx-spin .7s linear infinite; }

.rsx__label { margin: 13px 0 6px; font: 400 11px/1 var(--f-mono); letter-spacing: .02em; color: var(--stage-faint); }
.rsx__glance { margin: 0; min-height: 2.9em; font: 400 13px/1.45 var(--f-sans); color: rgba(var(--stage-ink), .9); text-wrap: pretty; }
.rsx__lines { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.rsx-line { display: flex; align-items: center; gap: 10px; height: 32px; margin: 0 -8px; padding: 0 6px 0 8px; border-radius: 7px; cursor: default; transition: background-color .3s ease, opacity .4s ease; }
.rsx-line__box { flex: none; width: 13px; height: 13px; box-sizing: border-box; border: 1px solid rgba(var(--stage-ink), .3); border-radius: 4px; }
.rsx__lines--ask .rsx-line__box { border-radius: 50%; }
.rsx-line__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 400 13px/1.2 var(--f-sans); color: rgba(var(--stage-ink), .9); }
.rsx-line__refs { flex: none; display: flex; gap: 3px; }
.rsx-line__refs b { --k: var(--stage-teal); display: grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; background: rgba(var(--stage-ink), .07); font: 500 11px/1 var(--f-mono); color: var(--stage-faint); transition: opacity .3s ease, transform .4s cubic-bezier(.3, 1.6, .5, 1), background-color .3s ease, color .3s ease; }
.rsx-line__refs b[data-k='linked'] { --k: var(--stage-blue); }
.rsx-line__refs b[data-k='article'] { --k: var(--stage-violet); }
.rsx-line__refs b[data-k='file'] { --k: var(--stage-text); }
.rsx-line__refs b + b { transition-delay: .07s; }
.rsx-line.is-lit { background: color-mix(in srgb, var(--stage-teal) 10%, transparent); }
.rsx-line.is-lit .rsx-line__box { border-color: var(--stage-teal); }
.rsx-line.is-lit .rsx-line__refs b { background: color-mix(in srgb, var(--k) 22%, transparent); color: var(--k); }
.rsx-line.is-dim { opacity: .38; }
.rsx.is-live .rsx-line:not(.is-done) .rsx-line__refs b { opacity: 0; transform: scale(.5); }

/* Streaming: skeleton bars before a line starts, a caret while it types. */
.rsx-line.is-empty .rsx-line__text::after, .rsx__glance.is-empty::before, .rsx__glance.is-empty::after { content: ''; display: block; height: 6px; border-radius: 3px; background: rgba(var(--stage-ink), .1); animation: rsx-pulse 1.6s ease-in-out infinite; }
.rsx-line.is-empty .rsx-line__text::after { width: var(--sk, 72%); }
.rsx-line:nth-child(2) { --sk: 86%; }
.rsx-line:nth-child(3) { --sk: 60%; }
.rsx__glance.is-empty::before { width: 94%; margin: 6px 0 9px; }
.rsx__glance.is-empty::after { width: 58%; }
.rsx-line.is-typing .rsx-line__text::after, .rsx__glance.is-typing::after { content: ''; display: inline-block; width: 1px; height: 1.05em; margin-left: 2px; vertical-align: -2px; background: var(--stage-teal); }

/* The network line: a query leaves only once it is clean. */
.rsx__edge { position: relative; z-index: 1; height: 104px; margin: 0 28px; }
.rsx__edge::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dashed rgba(var(--stage-ink), .24); }
.rsx.is-drawn .rsx__edge::before { border-color: transparent; }
.rsx__net, .rsx__web { position: absolute; left: 0; margin: 0; font: 400 11px/1 var(--f-mono); color: var(--stage-faint); }
.rsx__net { bottom: calc(50% + 9px); }
.rsx__web { top: calc(50% + 9px); }
.rsx__query, .rsx__sent { position: absolute; left: 50%; margin: 0; display: flex; align-items: center; max-width: calc(100% - 200px); height: 32px; padding: 0 12px; box-sizing: border-box; border-radius: 8px; overflow: hidden; white-space: nowrap; font: 400 12px/1 var(--f-mono); transform: translateX(-50%); transition: opacity .4s ease, transform .6s cubic-bezier(.2, .7, .2, 1); }
.rsx__query { bottom: calc(50% + 12px); gap: 6px; border: 1px solid rgba(var(--stage-ink), .14); background: var(--stage-bg); color: rgba(var(--stage-ink), .9); }
.rsx__sent { top: calc(50% + 12px); gap: 10px; border: 1px solid color-mix(in srgb, var(--stage-violet) 45%, transparent); background: linear-gradient(color-mix(in srgb, var(--stage-violet) 10%, transparent), color-mix(in srgb, var(--stage-violet) 10%, transparent)), var(--stage-bg); }
.rsx__query > span:first-child, .rsx__sent > span:first-child { flex: none; font-family: var(--f-sans); font-weight: 500; }
.rsx__query > span:first-child { margin-right: 4px; color: var(--stage-faint); }
.rsx__sent > span:first-child { color: var(--stage-violet); }
.rsx.is-live .rsx__query:not(.is-in), .rsx.is-live .rsx__sent:not(.is-in) { opacity: 0; transform: translate(-50%, 6px); }

.rsx-tok { flex: none; display: inline-block; max-width: 24ch; overflow: hidden; padding: 4px 3px; border-radius: 4px; transition: max-width .55s cubic-bezier(.6, 0, .2, 1), opacity .35s ease, margin .55s cubic-bezier(.6, 0, .2, 1), padding .55s cubic-bezier(.6, 0, .2, 1), background-color .25s ease, color .25s ease, text-decoration-color .25s ease; }
.rsx-tok--cut { max-width: 0; margin: 0 -3px; padding: 4px 0; opacity: 0; }
.rsx.is-live .rsx-tok--cut { max-width: 24ch; margin: 0; padding: 4px 3px; opacity: 1; text-decoration: line-through; text-decoration-color: transparent; }
.rsx.is-live .rsx-tok--cut.is-cut { background: color-mix(in srgb, var(--stage-violet) 22%, transparent); color: var(--stage-violet); text-decoration-color: currentColor; text-decoration-thickness: 1.5px; }
.rsx.is-live .rsx-tok--cut.is-gone { max-width: 0; margin: 0 -3px; padding: 4px 0; opacity: 0; }

/* Movements */
.rsx__rail { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; margin: 0 28px; }
.rsx__tab { all: unset; --h: var(--stage-teal); box-sizing: border-box; position: relative; min-width: 0; display: flex; align-items: baseline; gap: 9px; padding: 15px 0 19px; cursor: pointer; color: var(--stage-faint); transition: color .3s ease; }
.rsx__tab:nth-child(3) { --h: var(--stage-blue); }
.rsx__tab:nth-child(4) { --h: var(--stage-violet); }
.rsx__tab[aria-pressed='true'], .rsx__tab:hover { color: var(--stage-text); }
.rsx__tab:focus-visible { outline: 1px solid var(--h); outline-offset: -2px; }
.rsx__track { position: absolute; top: 0; left: 0; right: 0; height: 1px; overflow: hidden; background: rgba(var(--stage-ink), .18); }
.rsx__bar { display: block; height: 100%; background: var(--h); transform: scaleX(0); transform-origin: left; }
.rsx__idx { font: 400 11px/1 var(--f-mono); color: var(--h); }
.rsx__tab > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 13px/1 var(--f-sans); letter-spacing: -.005em; }

.rsx.is-still *, .rsx.is-still *::before, .rsx.is-still *::after { animation: none !important; transition: none !important; }

@keyframes rsx-spin { to { transform: rotate(1turn); } }
@keyframes rsx-pulse { 50% { opacity: .45; } }

/* Narrow stages: the sources become a row of chips over the plan, and the model steps aside. */
@container rsx (max-width: 759px) {
  .rsx__top { flex-direction: column; padding: 20px 18px 0; }
  .rsx__captions { flex: none; width: 100%; }
  .rsx__caption { font-size: 14px; }
  .rsx__ticket b { font-size: 12px; }
  .rsx__body { grid-template-columns: minmax(0, 1fr); padding: 18px 18px 6px; }
  .rsx__sources { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .rsx-src { grid-template-columns: auto auto; gap: 8px; padding: 5px 9px 5px 5px; }
  .rsx-src__n { grid-row: auto; width: 20px; height: 20px; }
  .rsx-src__meta span + span, .rsx-src b { display: none; }
  .rsx.is-live .rsx-src:not(.is-in) { transform: translateY(-6px); }
  .rsx__core { display: none; }
  .rsx__plan { margin-top: 30px; padding: 14px 14px 10px; }
  .rsx__edge { height: 96px; margin: 0 18px; }
  .rsx__query, .rsx__sent { max-width: calc(100% - 96px); left: auto; right: 0; transform: none; font-size: 11px; padding: 0 10px; }
  .rsx.is-live .rsx__query:not(.is-in), .rsx.is-live .rsx__sent:not(.is-in) { transform: translateY(6px); }
  .rsx__rail { gap: 0 10px; margin: 0 18px; }
  .rsx__idx { display: none; }
}
