/* Styles for the LLM and AI-engineering widgets (js/widgets/set-ai.js).
   Every class is prefixed w-<widget name>-; colours come from the theme variables in app.css. */

/* Small print: what is illustrative, and how the toy differs from the real thing. */
.w-sampling-fine, .w-tokenizer-fine, .w-embedding-space-fine, .w-chunking-fine, .w-context-window-fine {
  font-size: 12.5px; color: var(--muted);
}

/* ---------------------------------------------------------------- sampling */
.w-sampling-prompt { margin: 14px 0 10px; font: 15px/1.6 var(--mono); color: var(--text); overflow-wrap: anywhere; }
.w-sampling-next {
  display: inline-block; padding: 0 8px; border-radius: 6px; font-weight: 650; color: var(--accent);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.w-sampling-next.w-sampling-empty { color: var(--muted); background: transparent; border: 1px dashed var(--border-2); }
.w-sampling-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.w-sampling-table caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.w-sampling-col-token { width: 98px; }
.w-sampling-col-raw { width: 64px; }
.w-sampling-col-final { width: 92px; }
.w-sampling-col-count { width: 58px; }
.w-sampling-table th, .w-sampling-table td { padding: 3px 6px; text-align: left; vertical-align: middle; font-weight: 500; }
.w-sampling-table thead th { font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.w-sampling-token {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); color: var(--text);
  border-left: 3px solid transparent;
}
.w-sampling-table .w-sampling-num { text-align: right; white-space: nowrap; font-family: var(--mono); font-size: 12.5px; color: var(--text-2); }
.w-sampling-track {
  position: relative; height: 18px; border-radius: 4px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--border);
}
.w-sampling-track i { position: absolute; left: 0; display: block; transition: width .15s ease; }
.w-sampling-gain { top: 0; height: 11px; background: color-mix(in srgb, var(--accent) 38%, transparent); }
.w-sampling-raw { top: 0; height: 11px; background: var(--accent); }
.w-sampling-share { bottom: 0; height: 4px; background: var(--info); }
.w-sampling-cut .w-sampling-token { color: var(--muted); text-decoration: line-through; }
.w-sampling-cut .w-sampling-num { color: var(--muted); }
.w-sampling-cut .w-sampling-raw { background: var(--border-2); }
.w-sampling-latest .w-sampling-token { border-left-color: var(--info); }
.w-sampling-key-raw { --wc: var(--accent); }
.w-sampling-key-gain { --wc: color-mix(in srgb, var(--accent) 38%, transparent); }
.w-sampling-key-share { --wc: var(--info); }
.w-sampling-key-cut { --wc: var(--border-2); }
.w-sampling-knobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.w-sampling-knobs .w-label { min-width: 88px; }
.w-sampling-knobs .w-slider { flex: 1; width: auto; min-width: 0; }
.w-sampling-recent { margin: 10px 0 0; min-height: 2.9em; font-size: 12.5px; line-height: 1.45; color: var(--muted); }

/* ---------------------------------------------------------------- tokenizer */
.w-tokenizer-text { display: block; width: 100%; min-height: 60px; resize: vertical; line-height: 1.5; }
.w-tokenizer-knob { flex: 1 1 300px; }
.w-tokenizer-knob .w-slider { flex: 1; width: auto; min-width: 120px; }
.w-tokenizer-split { margin-top: 12px; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.w-tokenizer-stage {
  padding: 10px; max-height: 330px; overflow-y: auto; background: var(--code-bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.w-tokenizer-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px 3px; }
.w-tokenizer-chip {
  display: inline-flex; flex-direction: column; align-items: center; min-width: 20px; padding: 2px 5px 1px; border-radius: 6px;
  background: color-mix(in srgb, var(--wc) 20%, transparent); border: 1px solid color-mix(in srgb, var(--wc) 60%, transparent);
}
.w-tokenizer-piece { font: 13.5px/1.35 var(--mono); color: var(--text); white-space: pre; }
.w-tokenizer-id { font: 9.5px/1.25 var(--mono); color: var(--muted); }
.w-tokenizer-mark { color: var(--muted); font-weight: 700; }
.w-tokenizer-empty { font-size: 13px; font-style: italic; color: var(--muted); }
.w-tokenizer-key { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.w-tokenizer-heading {
  margin-bottom: 7px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.w-tokenizer-merges { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-tokenizer-merge { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 6px; align-items: baseline; }
.w-tokenizer-rank { font: 11px var(--mono); color: var(--muted); }
.w-tokenizer-rule { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.w-tokenizer-rule code {
  padding: 1px 4px; border-radius: 4px; font: 12.5px var(--mono); white-space: pre; color: var(--text); background: var(--surface-3);
}
.w-tokenizer-newest .w-tokenizer-rule code:last-child { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.w-tokenizer-seen { grid-column: 2; font-size: 11px; color: var(--muted); }
.w-tokenizer-corpus { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.w-tokenizer-corpus summary { width: fit-content; cursor: pointer; }
.w-tokenizer-corpus p { margin: 8px 0 0; white-space: pre-line; line-height: 1.55; color: var(--text-2); }

/* ---------------------------------------------------------------- attention */
.w-attention .w-svg { touch-action: auto; }
.w-attention-flag {
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.w-attention-flag strong { color: var(--accent); }
.w-attention-toggle { cursor: pointer; font-weight: 600; }
.w-attention-toggle input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }
.w-attention-stage { margin-top: 12px; padding: 6px 6px 8px; }
.w-attention-arcs { height: 92px; }
.w-attention-arc { fill: none; stroke: var(--accent); stroke-linecap: round; vector-effect: non-scaling-stroke; }
.w-attention-tokens, .w-attention-weights { display: grid; }
.w-attention-token {
  min-width: 0; margin: 0 2px; padding: 5px 0 8px; border-radius: 7px; border: 1px solid var(--border-2); color: var(--text);
  font: 600 12.5px var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  /* The bar along the bottom is as wide as this token's share of the selected token's attention. */
  background: linear-gradient(var(--accent), var(--accent)) left bottom / calc(var(--w, 0) * 100%) 4px no-repeat, var(--surface-2);
}
.w-attention-token.w-attention-on { border-color: var(--info); box-shadow: 0 0 0 2px var(--info); }
.w-attention-token.w-attention-masked { opacity: .42; text-decoration: line-through; }
.w-attention-weights span { padding-top: 6px; text-align: center; font: 600 11.5px var(--mono); color: var(--text-2); }
.w-attention-weights .w-attention-masked { color: var(--muted); }
.w-attention-split { margin-top: 12px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.w-attention-map text { font-size: 11.5px; }
.w-svg .w-attention-axis { font-size: 10px; }
.w-svg .w-attention-sum { font-family: var(--mono); font-size: 11px; }
.w-attention-row { cursor: pointer; }
.w-attention-cell { fill: var(--surface-2); stroke: var(--border); }
.w-attention-blank { fill: none; stroke: var(--border); stroke-dasharray: 2 3; }
.w-attention-slash { stroke: var(--border-2); stroke-width: 1.5; }
.w-attention-rowmark { fill: none; stroke: var(--info); stroke-width: 2; pointer-events: none; }
.w-attention-heading { margin-bottom: 8px; font-size: 13.5px; font-weight: 650; color: var(--text); }
.w-attention-rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.w-attention-rank li { display: grid; grid-template-columns: minmax(0, 1fr) 48px 36px; gap: 6px; align-items: center; font-size: 12.5px; }
.w-attention-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.w-attention-bar { height: 8px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.w-attention-bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.w-attention-share { text-align: right; font: 600 12px var(--mono); color: var(--text); }
.w-attention-total { margin: 10px 0 0; font-size: 12.5px; color: var(--text-2); }
.w-attention-about { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------- embedding-space */
.w-embedding-space .w-svg { touch-action: auto; }
.w-embedding-space-map, .w-embedding-space .w-panel { margin-top: 12px; }
.w-embedding-space-input { width: 132px; }
.w-embedding-space-hint { min-width: 98px; font-size: 12.5px; color: var(--bad); }
.w-embedding-space-word { cursor: pointer; }
.w-embedding-space-word text { fill: var(--text-2); font-size: 12px; }
.w-embedding-space-dim { opacity: .5; }
.w-embedding-space-lit text, .w-embedding-space-focus text { fill: var(--text); font-weight: 700; }
.w-embedding-space-focus .w-fill { stroke: var(--text); stroke-width: 2.5; }
.w-embedding-space-hit { fill: transparent; }
.w-svg .w-embedding-space-origin { font-size: 10px; }
.w-embedding-space-reach {
  fill: color-mix(in srgb, var(--accent) 9%, transparent); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 4;
}
.w-embedding-space-link { fill: none; stroke: var(--border-2); stroke-width: 1.2; }
.w-embedding-space-link.w-embedding-space-strong { stroke: var(--accent); stroke-width: 1.8; }
.w-embedding-space-arrow { fill: none; stroke: var(--info); stroke-width: 2.5; }
.w-embedding-space-arrow.w-embedding-space-copy { stroke: var(--accent); stroke-dasharray: 7 4; }
.w-embedding-space-head-step { fill: var(--info); }
.w-embedding-space-head-copy { fill: var(--accent); }
.w-embedding-space-result { fill: none; stroke: var(--accent); stroke-width: 2; }
.w-embedding-space-heading { margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.w-embedding-space-results {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 2px 22px; counter-reset: rank;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.w-embedding-space-results li { display: flex; align-items: center; gap: 6px; font-size: 13px; counter-increment: rank; }
.w-embedding-space-results li::before { content: counter(rank) "."; min-width: 16px; font: 12px var(--mono); color: var(--muted); }
.w-embedding-space-results .btn { padding: 3px 8px; color: var(--text); }
.w-embedding-space-answer .btn { color: var(--accent); }
.w-embedding-space-score { margin-left: auto; font: 12px var(--mono); color: var(--text-2); white-space: nowrap; }

/* ---------------------------------------------------------------- chunking */
.w-chunking-asked { margin: 12px 0 8px; font-size: 13.5px; color: var(--text-2); }
.w-chunking-asked strong { color: var(--text); }
.w-chunking-terms { font-size: 12.5px; color: var(--muted); }
.w-chunking-doc {
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--code-bg);
  font-size: 13.5px; line-height: 2; color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere;
}
.w-chunking-run { padding: 3px 0; }
.w-chunking-even { background: color-mix(in srgb, var(--info) 20%, transparent); }
.w-chunking-odd { background: color-mix(in srgb, var(--violet) 27%, transparent); }
.w-chunking-overlap {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--info) 34%, transparent) 0 4px,
    color-mix(in srgb, var(--violet) 34%, transparent) 4px 8px);
}
.w-chunking-run.w-chunking-miss { color: var(--muted); }
.w-chunking-run.w-chunking-hit { color: var(--text); background: color-mix(in srgb, var(--accent) 27%, transparent); }
.w-chunking-run.w-chunking-answer {
  text-decoration: underline; text-decoration-color: var(--ok); text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.w-chunking-run.w-chunking-term { font-weight: 700; color: var(--text); }
.w-chunking-tag {
  display: inline-block; margin: 0 3px 0 1px; padding: 2px 4px; border-radius: 4px; vertical-align: 1px; white-space: nowrap;
  font: 700 10px/1.1 var(--mono); color: var(--text-2); background: var(--surface-3); border: 1px solid var(--border-2);
}
.w-chunking-tag b { margin-left: 4px; font-weight: 500; color: var(--muted); }
.w-chunking-tag.w-chunking-hit { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.w-chunking-tag.w-chunking-hit b { color: inherit; }
.w-chunking-key-even { --wc: color-mix(in srgb, var(--info) 42%, transparent); }
.w-chunking-key-odd { --wc: color-mix(in srgb, var(--violet) 46%, transparent); }
.w-chunking-key-overlap {
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--info) 60%, transparent) 0 3px,
    color-mix(in srgb, var(--violet) 60%, transparent) 3px 6px);
}
.w-chunking-key-hit { --wc: color-mix(in srgb, var(--accent) 55%, transparent); }
.w-chunking-key-answer { height: 8px; border-radius: 0; background: none; border-bottom: 2px solid var(--ok); }
.w-chunking .w-panel { margin-top: 12px; }
.w-chunking-heading { margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.w-chunking-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: rank; }
.w-chunking-results li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 13px; counter-increment: rank; }
.w-chunking-results li::before { content: "#" counter(rank); font: 12px var(--mono); color: var(--muted); }
.w-chunking-results .w-chunking-tag { margin: 0; vertical-align: baseline; }
.w-chunking-score { font: 600 12.5px var(--mono); color: var(--text); }
.w-chunking-why { color: var(--text-2); }
.w-chunking-none { margin: 0; font-size: 13px; color: var(--muted); }
.w-chunking-ok .w-stat-value { color: var(--ok); }
.w-chunking-bad .w-stat-value { color: var(--bad); }

/* ---------------------------------------------------------------- context-window */
/* Dark label text for the series colours, which are the same in both themes. */
.w-context-window { --w-context-window-ink: #10141d; }
.w-context-window-bar { position: relative; margin: 30px 0 28px; }
.w-context-window-track {
  display: flex; height: 34px; border-radius: 7px; overflow: hidden; background: var(--code-bg); border: 1px solid var(--border-2);
}
.w-context-window-seg, .w-context-window-free {
  flex: 0 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap;
}
.w-context-window-seg { min-width: 2px; background: var(--wc); box-shadow: inset -1px 0 0 var(--surface); }
.w-context-window-seg span { font-size: 11px; font-weight: 700; color: var(--w-context-window-ink); }
.w-context-window-free span { font-size: 11px; color: var(--muted); }
/* Hatching marks tokens that are reserved or condensed rather than sent as written. */
.w-context-window-output, .w-context-window-summary {
  background: repeating-linear-gradient(135deg, var(--wc) 0 6px, color-mix(in srgb, var(--wc) 62%, var(--code-bg)) 6px 12px);
}
.w-context-window-limit { position: absolute; top: -5px; bottom: -5px; border-left: 2px solid var(--text); }
.w-context-window-limit span {
  position: absolute; right: -1px; bottom: 100%; padding-bottom: 2px; white-space: nowrap;
  font-size: 11px; font-weight: 600; color: var(--text-2);
}
.w-context-window-limit.w-context-window-start span { right: auto; left: -1px; }
.w-context-window-over {
  position: absolute; top: 1px; right: 1px; bottom: 1px; border-radius: 0 6px 6px 0; pointer-events: none;
  background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--bad) 60%, transparent) 0 5px, transparent 5px 10px);
}
.w-context-window-over span {
  position: absolute; top: 100%; right: 0; padding-top: 6px; white-space: nowrap; font-size: 11px; font-weight: 700; color: var(--bad);
}
.w-context-window-cached {
  position: absolute; top: 100%; left: 0; min-width: 6px; height: 7px; margin-top: 3px;
  border: 2px solid var(--ok); border-top: 0; border-radius: 0 0 4px 4px;
}
.w-context-window-cached span {
  position: absolute; top: 100%; left: 0; padding-top: 1px; white-space: nowrap; font-size: 11px; font-weight: 700; color: var(--ok);
}
.w-context-window-status { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.w-context-window .w-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.w-context-window .w-stat { min-width: 0; }
.w-context-window-is-over .w-context-window-track { border-color: var(--bad); }
.w-context-window-is-over .w-context-window-status { color: var(--bad); }
.w-context-window-split { margin-top: 12px; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.w-context-window-side { display: grid; gap: 12px; }
.w-context-window-heading {
  margin-bottom: 8px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.w-context-window-knobs { display: grid; gap: 8px; }
.w-context-window-knobs .w-control { gap: 8px; }
.w-context-window-knobs .w-swatch { flex: none; }
.w-context-window-knobs .w-label { flex: 1; min-width: 0; white-space: normal; font-size: 12.5px; line-height: 1.25; }
.w-context-window-knobs .w-slider { flex: none; width: 110px; }
.w-context-window-knobs .w-value { min-width: 52px; text-align: right; }
.w-context-window-sum { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); }
.w-context-window-toggle {
  display: flex; align-items: flex-start; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--text-2); cursor: pointer;
}
.w-context-window-toggle input { flex: none; width: 15px; height: 15px; margin: 3px 0 0; accent-color: var(--accent); }
.w-context-window-toggle span { font-weight: 600; }
.w-context-window-toggle small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.w-context-window-prices { display: grid; gap: 6px; }
.w-context-window-field {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 76px; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2);
}
.w-context-window-unit { font-family: var(--mono); color: var(--muted); }
.w-context-window-price { width: 76px; padding: 4px 8px; text-align: right; }
.w-context-window-order {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--text-2);
}
