/*
 * FHIR Lab's own styles, on top of the shared "Night clinic" core (tokens,
 * base, components, pages, labs): the textarea-over-highlight editor, token
 * colours for JSON / HTTP / FHIRPath, the JSON tree, the REST console, the
 * FHIR blocks, the three labs (message flow, claim anatomy, search builder)
 * and a few page pieces. Colours come only from tokens.css, so both themes
 * follow. Code is always left-to-right, inside pages that may be right-to-left.
 */

/* ---------------------------------------------------------------- icons */

/* A default size for icons; zero specificity, so every contextual rule (.btn svg …) wins. */
:where(svg.icon) {
  width: 1.1em;
  height: 1.1em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
}

/* ---------------------------------------------------------------- brand mark and footer */

.brand-mark .brand-mark-rules {
  opacity: 0.75;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark-pulse {
  fill: none;
  stroke: url(#brand-gradient);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.foot-notes {
  flex: 1 1 100%;
  font-size: var(--fs-xs);
  color: var(--ink-3);
}

.foot-notes > summary {
  width: fit-content;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
}

.foot-notes > summary:hover {
  color: var(--accent);
}

.foot-notes ul {
  display: grid;
  gap: 6px;
  margin: var(--s-2) 0 0;
  padding-inline-start: 1.2em;
  line-height: 1.7;
}

/* ---------------------------------------------------------------- code editor */

.code-editor {
  --editor-min-lines: 4;
  --editor-max-lines: 18;
  --editor-line: 1.65;
  --editor-pad-y: 10px;
  --editor-pad-x: 14px;
  position: relative;
  /* Long lines scroll inside the editor; they never widen the grid or flex row around it. */
  contain: inline-size;
  min-width: 0;
  direction: ltr;
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--code-surface);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: var(--editor-line);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}

.code-editor:focus-within {
  border-color: var(--teal);
  box-shadow: var(--focus-ring);
}

.code-editor.has-error {
  border-color: color-mix(in srgb, var(--bad) 60%, var(--rule));
}

.code-editor-scroll {
  display: flex;
  align-items: stretch;
  min-height: calc(var(--editor-min-lines) * var(--editor-line) * 1em + 2 * var(--editor-pad-y));
  max-height: calc(var(--editor-max-lines) * var(--editor-line) * 1em + 2 * var(--editor-pad-y));
  overflow: auto;
  border-radius: inherit;
  overscroll-behavior: contain;
}

.code-editor-gutter {
  position: sticky;
  left: 0;
  z-index: 2;
  display: flex;
  flex: none;
  flex-direction: column;
  min-width: 2.9em;
  padding: var(--editor-pad-y) 8px var(--editor-pad-y) 6px;
  border-right: 1px solid var(--rule);
  background: var(--code-gutter);
  color: var(--ink-3);
  font-size: 0.8em;
  line-height: calc(var(--editor-line) / 0.8);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.code-editor-layer {
  position: relative;
  flex: 1 0 auto;
  min-width: 0;
}

.code-editor-highlight,
.code-editor-input {
  display: block;
  margin: 0;
  padding: var(--editor-pad-y) var(--editor-pad-x);
  border: 0;
  font: inherit;
  line-height: inherit;
  letter-spacing: normal;
  word-spacing: normal;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  text-align: left;
}

.code-editor-highlight {
  min-height: calc(var(--editor-min-lines) * var(--editor-line) * 1em + 2 * var(--editor-pad-y));
  color: var(--syn-variable);
  pointer-events: none;
}

/* The textarea lies exactly over the highlighted copy: its own text is invisible, its caret and selection are not. */
.code-editor-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  outline: none;
  -webkit-text-fill-color: transparent;
}

.code-editor-input::selection {
  background: var(--selection);
  -webkit-text-fill-color: transparent;
}

.code-editor-input::placeholder {
  color: var(--ink-3);
  -webkit-text-fill-color: var(--ink-3);
}

.code-editor-input[readonly] {
  caret-color: transparent;
}

.code-editor-error {
  position: absolute;
  inset-inline: 0;
  top: calc(var(--editor-pad-y) + (var(--error-line, 1) - 1) * var(--editor-line) * 1em);
  height: calc(var(--editor-line) * 1em);
  z-index: 0;
  border-left: 3px solid var(--bad);
  background: var(--bad-soft);
  pointer-events: none;
}

.code-editor.is-single {
  --editor-min-lines: 1;
  --editor-max-lines: 1;
}

.code-editor.is-single .code-editor-scroll {
  overflow-y: hidden;
  scrollbar-width: thin;
}

/* ---------------------------------------------------------------- token colours */

.tok-key,
.tok-param,
.tok-header,
.tok-method,
.tok-keyword {
  color: var(--syn-keyword);
}

.tok-method,
.tok-keyword,
.tok-type {
  font-weight: 650;
}

.tok-string,
.tok-value {
  color: var(--syn-string);
}

.tok-number,
.tok-prefix,
.tok-operation {
  color: var(--syn-number);
}

.tok-prefix {
  font-weight: 700;
}

.tok-literal,
.tok-type,
.tok-function,
.tok-modifier {
  color: var(--syn-function);
}

.tok-punct,
.tok-operator {
  color: var(--syn-operator);
}

.tok-path {
  color: var(--syn-variable);
}

.tok-variable {
  color: var(--syn-number);
  font-style: italic;
}

.tok-error {
  color: var(--bad);
  text-decoration: underline wavy var(--bad);
  text-decoration-skip-ink: none;
  text-underline-offset: 3px;
}

.code-static .syntax-token {
  border-radius: 3px;
  transition: background var(--dur-fast), box-shadow var(--dur-fast);
}

.lab-code {
  padding: 8px 12px;
  font-size: 0.84rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- JSON tree */

.json-tree {
  position: relative;
  contain: inline-size;
  min-width: 0;
  max-height: 36rem;
  overflow: auto;
  padding: 10px 12px 10px 1.5em;
  direction: ltr;
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--code-surface);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.7;
  color: var(--syn-variable);
}

.jt-row,
.jt-summary {
  white-space: pre;
}

.jt-summary {
  display: block;
  position: relative;
  padding-left: 1.1em;
  margin-left: -1.1em;
  cursor: pointer;
  list-style: none;
  border-radius: 4px;
}

.jt-summary::-webkit-details-marker {
  display: none;
}

.jt-summary::before {
  content: "";
  position: absolute;
  left: 0.2em;
  top: 0.62em;
  width: 0.45em;
  height: 0.45em;
  background: var(--ink-3);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
  transition: rotate var(--dur-fast);
}

.jt-node[open] > .jt-summary::before {
  rotate: 90deg;
}

.jt-summary:hover {
  background: var(--surface-2);
}

.jt-summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.jt-node[open] > .jt-summary .jt-collapsed,
.jt-node[open] > .jt-summary .jt-count {
  display: none;
}

.jt-collapsed {
  color: var(--ink-3);
}

.jt-count {
  margin-left: 0.6em;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink-3);
  font-family: var(--font-body);
  font-size: 0.72rem;
}

.jt-children {
  margin-left: 0.3em;
  padding-left: 1.2em;
  border-left: 1px dashed var(--rule-strong);
}

.jt-key {
  color: var(--syn-keyword);
}

.jt-index {
  color: var(--ink-3);
}

.jt-string {
  color: var(--syn-string);
}

.jt-number {
  color: var(--syn-number);
}

.jt-literal,
.jt-null {
  color: var(--syn-function);
}

.jt-null {
  font-style: italic;
}

.jt-punct {
  color: var(--syn-operator);
}

.jt-key.has-note,
.jt-index.has-note {
  text-decoration: underline dotted var(--teal);
  text-underline-offset: 4px;
  cursor: help;
  border-radius: 3px;
}

.jt-key.has-note:hover,
.jt-key.has-note:focus-visible,
.jt-index.has-note:hover,
.jt-index.has-note:focus-visible {
  background: var(--highlight-wash);
  outline: none;
}

.jt-tip {
  position: absolute;
  z-index: 5;
  width: min(300px, calc(100% - 16px));
  padding: 10px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  line-height: 1.7;
  white-space: normal;
  pointer-events: none;
}

:root[dir="rtl"] .jt-tip {
  direction: rtl;
  text-align: right;
}

.jt-tip-meta {
  margin-top: 6px;
  direction: ltr;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- shared pieces */

.display-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 0;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-3);
}

.display-label svg {
  width: 14px;
  height: 14px;
}

.result-waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.result-waiting::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--rule-strong);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: fhir-spin 0.9s linear infinite;
}

@keyframes fhir-spin {
  to {
    rotate: 360deg;
  }
}

.trace-counter {
  margin-inline-start: auto;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* "Educational simulation": on every answer the nphies simulator writes. */
.sim-badge {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 6px 12px;
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--rule));
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--ink-2);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

.sim-badge svg {
  margin-top: 0.2em;
  color: var(--warn);
}

.page-head .sim-badge {
  margin-top: var(--s-3);
}

.quiz-explain .feedback-title.is-ok {
  color: var(--ok);
}

.quiz-explain .feedback-title.is-bad {
  color: var(--bad);
}

/* ---------------------------------------------------------------- REST console */

.rest-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}

.rest-method,
.rest-url {
  min-height: 36px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--code-surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.rest-method {
  flex: none;
  padding: 4px 8px;
  font-weight: 700;
  color: var(--syn-keyword);
  cursor: pointer;
}

.rest-base {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--ink-3);
}

.rest-url {
  flex: 1 1 14rem;
  min-width: 10rem;
  padding: 4px 10px;
}

.rest-method:focus-visible,
.rest-url:focus-visible,
.rest-headers-field:focus-visible {
  outline: none;
  border-color: var(--teal);
  box-shadow: var(--focus-ring);
}

.rest-url[readonly],
.rest-method:disabled {
  color: var(--ink-2);
  cursor: default;
}

.rest-send {
  flex: none;
}

.rest-headers-box {
  padding: 6px 12px;
  border-bottom: 1px solid var(--rule);
  font-size: var(--fs-xs);
}

.rest-headers-box > summary {
  width: fit-content;
  cursor: pointer;
  color: var(--ink-3);
  font-weight: 600;
}

.rest-headers-field {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--code-surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
  resize: vertical;
}

.rest-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--rule);
}

.rest-body .display-label {
  padding-inline: 0;
}

.rest-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 8px 12px;
  border-inline-start: 4px solid var(--ok);
  background: var(--ok-soft);
}

.rest-status.is-3xx {
  border-inline-start-color: var(--teal);
  background: var(--teal-soft);
}

.rest-status.is-4xx {
  border-inline-start-color: var(--warn);
  background: var(--warn-soft);
}

.rest-status.is-5xx {
  border-inline-start-color: var(--bad);
  background: var(--bad-soft);
}

.rest-code {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ok);
}

.rest-status.is-3xx .rest-code {
  color: var(--teal);
}

.rest-status.is-4xx .rest-code {
  color: var(--warn);
}

.rest-status.is-5xx .rest-code {
  color: var(--bad);
}

.rest-meaning {
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.rest-status .spacer {
  flex: 1;
}

.rest-time {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--ink-3);
}

.rest-result > .sim-badge,
.rest-result > .rest-hint {
  margin: 8px 12px 0;
}

.rest-hint {
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.rest-summary {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr);
  align-items: baseline;
  gap: 4px 12px;
  margin: 8px 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--fs-sm);
}

.rest-summary-row {
  display: contents;
}

.rest-summary-label {
  font-weight: 600;
  color: var(--ink-3);
}

.rest-summary code {
  justify-self: start;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--syn-keyword);
}

.rest-summary-meaning {
  color: var(--ink-2);
}

.rest-summary-note {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding-top: 6px;
  border-top: 1px dashed var(--rule);
  text-align: left;
  font-size: var(--fs-xs);
  font-style: italic;
  color: var(--ink-2);
}

.rest-issues-wrap {
  margin-top: 4px;
}

.rest-issues {
  display: grid;
  gap: 6px;
  margin: 6px 0 0;
  padding: 0 12px 10px;
  list-style: none;
}

.rest-issue {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding: 6px 10px;
  border-inline-start: 3px solid var(--ink-3);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: var(--fs-sm);
}

.rest-issue.is-error,
.rest-issue.is-fatal {
  border-inline-start-color: var(--bad);
  background: var(--bad-soft);
}

.rest-issue.is-warning {
  border-inline-start-color: var(--warn);
  background: var(--warn-soft);
}

.rest-issue.is-information {
  border-inline-start-color: var(--teal);
  background: var(--teal-soft);
}

.rest-issue-path {
  padding: 0 6px;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  line-height: 1.8;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.rest-issue-path:hover,
.rest-issue-path:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.rest-result > .result-meta {
  margin-top: 6px;
  border-top: 1px solid var(--rule);
}

.rest-panels {
  padding: 0 12px 12px;
}

.rest-panels > .json-tree,
.rest-panels > .code-static {
  max-height: 32rem;
}

.rest-raw {
  overflow: auto;
}

.rest-headers th {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--syn-keyword);
}

.rest-headers td {
  font-family: var(--font-mono);
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- json, fhirpath and resource blocks */

.json-block > .code-editor {
  border-end-start-radius: 0;
  border-end-end-radius: 0;
}

.json-bar {
  border: 1px solid var(--rule);
  border-top: 0;
  border-end-start-radius: var(--r-md);
  border-end-end-radius: var(--r-md);
}

.json-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
}

.json-status.is-ok {
  color: var(--ok);
}

.json-status.is-bad {
  color: var(--bad);
}

.json-status svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.4;
}

.json-issues:empty {
  display: none;
}

.json-issues .rest-issues {
  padding: 0;
}

.json-explain {
  padding: 10px 14px;
  border-inline-start: 3px solid var(--bad);
  border-radius: var(--r-sm);
  background: var(--bad-soft);
  font-size: var(--fs-sm);
}

.fp-editor {
  padding: 10px 12px;
  border-bottom: 1px solid var(--rule);
}

.fp-result {
  border-bottom: 1px solid var(--rule);
}

.fp-message {
  font-size: var(--fs-sm);
}

.fp-message.is-bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.fp-message.is-info {
  color: var(--ink-2);
}

.fp-values {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0 12px 12px;
  padding-inline-start: calc(12px + 1.6em);
  direction: ltr;
  text-align: left;
}

.fp-values > li::marker {
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.fp-value {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--code-surface);
  color: var(--syn-string);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.fp-resource {
  padding: 8px 12px 12px;
  font-size: var(--fs-sm);
}

.fp-resource > summary {
  width: fit-content;
  margin-bottom: 6px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
}

.fp-resource > .expected-caption {
  margin-top: 8px;
}

.resource-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-inline-start: auto;
  font-size: var(--fs-2xs);
  color: var(--ink-3);
}

.resource-body {
  padding: 10px 12px 12px;
}

.resource-body > .json-tree {
  max-height: 40rem;
}

/* ---------------------------------------------------------------- message-flow lab */

.flow-lanes,
.flow-track {
  --flow-gap: var(--s-3);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: var(--flow-gap);
}

.flow-lane {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 2px;
  padding: 10px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: center;
}

.flow-lane-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 4px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}

.lane-1 .flow-lane-icon {
  background: var(--brand-gradient);
  color: var(--on-btn);
}

.lane-2 .flow-lane-icon {
  background: var(--teal-soft);
  color: var(--teal);
}

.flow-lane-icon svg {
  width: 20px;
  height: 20px;
}

.flow-lane-title {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.flow-lane-sub {
  font-size: var(--fs-2xs);
  color: var(--ink-3);
}

.flow-queue {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 6px;
  width: 100%;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--rule);
  font-size: var(--fs-2xs);
  color: var(--ink-3);
}

.flow-queue-count {
  min-width: 1.8em;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.flow-queue-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.flow-queue-chips:empty {
  display: none;
}

.flow-queue-chip {
  padding: 0 6px;
  border-radius: 6px;
  background: var(--warn-soft);
  color: var(--warn);
  font-family: var(--font-mono);
  font-size: 0.66rem;
}

.flow-steps {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.flow-step {
  display: grid;
  gap: 4px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--rule);
}

.flow-step.is-new {
  animation: flow-in 420ms var(--ease) both;
}

@keyframes flow-in {
  from {
    opacity: 0;
    translate: 0 6px;
  }
}

.flow-track {
  align-items: center;
  min-height: 34px;
}

/* The event chip sits above the arrow's line, so a long event name never hides the line on a phone. */
.flow-arrow {
  --flow-line-bottom: 6px;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 6px;
  min-height: 42px;
  padding-bottom: 16px;
  color: var(--accent);
}

.flow-arrow.is-back {
  color: var(--teal);
}

/* An arrow runs from the centre of one lane to the centre of another. */
.flow-arrow.span-0-1 {
  grid-column: 1 / 3;
  --flow-inset: calc(25% - var(--flow-gap) / 4);
}

.flow-arrow.span-1-2 {
  grid-column: 2 / 4;
  --flow-inset: calc(25% - var(--flow-gap) / 4);
}

.flow-arrow.span-0-2 {
  grid-column: 1 / 4;
  --flow-inset: calc(100% / 6 - var(--flow-gap) / 3);
}

.flow-arrow::before {
  content: "";
  position: absolute;
  inset-inline: var(--flow-inset);
  bottom: var(--flow-line-bottom);
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

/* The head: 11px tall, centred on the 2px line. */
.flow-arrow::after {
  content: "";
  position: absolute;
  bottom: calc(var(--flow-line-bottom) - 4.5px);
  width: 11px;
  height: 11px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.flow-arrow.is-forward::after {
  inset-inline-end: calc(var(--flow-inset) - 2px);
}

.flow-arrow.is-back::after {
  inset-inline-start: calc(var(--flow-inset) - 2px);
  scale: -1 1;
}

:root[dir="rtl"] .flow-arrow.is-forward::after {
  scale: -1 1;
}

:root[dir="rtl"] .flow-arrow.is-back::after {
  scale: 1 1;
}

.flow-arrow.is-waiting {
  color: var(--warn);
}

.flow-arrow.is-waiting::before {
  background: repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 11px);
}

.flow-chip {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 0 8px;
  border: 1px solid currentColor;
  border-radius: var(--r-pill);
  background: var(--surface);
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.8;
  white-space: nowrap;
}

.flow-wait {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--warn-soft);
  font-size: var(--fs-2xs);
  font-weight: 600;
}

.flow-caption {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.flow-detail {
  display: grid;
  gap: 6px;
}

.flow-detail:empty {
  display: none;
}

.flow-detail .rest-summary {
  margin: 0;
}

.flow-json > summary {
  width: fit-content;
  cursor: pointer;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-3);
}

.flow-json > .json-tree {
  margin-top: 6px;
}

.flow-status {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.flow-status:empty {
  display: none;
}

/* ---------------------------------------------------------------- claim-anatomy lab */

.anatomy-map {
  display: grid;
  gap: var(--s-2);
}

.anatomy-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
}

.anatomy-group-title {
  min-width: 7.5em;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--ink-2);
}

.anatomy-tile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-xs);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}

/* The element name is the tile's label, not a chip inside a chip. */
.anatomy-tile code {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: inherit;
}

.anatomy-tile:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.anatomy-tile:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.anatomy-tile[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.anatomy-tile.is-missing {
  border-style: dashed;
  background: transparent;
  color: var(--ink-3);
}

.anatomy-count {
  font-size: 0.68rem;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.anatomy-detail {
  display: grid;
  gap: var(--s-2);
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
}

.anatomy-detail .display-label {
  padding: 4px 0 0;
}

.anatomy-title {
  justify-self: start;
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  color: var(--accent);
}

.anatomy-rules {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.anatomy-rules > li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: var(--fs-sm);
}

/* ---------------------------------------------------------------- search-builder lab */

.sb-label {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.sb-type {
  width: auto;
  min-width: 13rem;
  direction: ltr;
  font-family: var(--font-mono);
}

.sb-chips {
  display: grid;
  gap: 6px;
}

.sb-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  direction: ltr;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
}

.sb-name,
.sb-modifier,
.sb-prefix {
  min-height: 32px;
  padding: 3px 8px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  background: var(--code-surface);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  cursor: pointer;
}

.sb-name {
  font-weight: 700;
  color: var(--syn-keyword);
}

.sb-modifier {
  color: var(--syn-function);
}

.sb-prefix {
  color: var(--syn-number);
}

.sb-value.field-input {
  flex: 1 1 10rem;
  width: auto;
  min-width: 8rem;
  min-height: 32px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.sb-remove {
  margin-inline-start: auto;
}

.sb-url .code-static {
  font-size: 0.84rem;
}

.sb-results {
  display: grid;
  gap: 6px;
}

.sb-results > .result-meta {
  padding-inline: 0;
}

.sb-table td:first-child {
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- pages */

.level.is-planned {
  border-style: dashed;
  background: transparent;
}

.level.is-planned .level-number {
  background: transparent;
  border-style: dashed;
  color: var(--ink-3);
}

.level.is-planned .level-title {
  color: var(--ink-2);
}

.plan-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.plan-topics > li {
  padding: 1px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: var(--fs-xs);
  color: var(--ink-2);
}

.path-more {
  justify-content: center;
  margin-top: var(--s-4);
}

.home-notice {
  margin-block: var(--s-6) 0;
}

/* The console's raw JSON view has long lines: keep the sandbox page's main column at the page width on a phone.
   (The rail, history and fenced-code fixes live in the shared core.) */
.playground-main {
  grid-template-columns: minmax(0, 1fr);
}

.rest-console {
  min-width: 0;
}

.rail-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.inventory {
  display: grid;
  gap: 4px;
}

.inventory-type {
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
}

.inventory-type > summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  cursor: pointer;
  font-size: var(--fs-sm);
}

.inventory-type > summary code {
  font-family: var(--font-mono);
  font-weight: 700;
}

.inventory-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0 6px 6px;
  list-style: none;
}

.inventory-item {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: var(--fs-xs);
  text-align: start;
  cursor: pointer;
}

.inventory-item:hover,
.inventory-item:focus-visible {
  background: var(--highlight-wash);
  outline: none;
}

.inventory-item code {
  flex: none;
  font-family: var(--font-mono);
  color: var(--accent);
}

.inventory-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-2);
}

.certificate.is-locked {
  filter: grayscale(0.85);
  opacity: 0.75;
}

/* ---------------------------------------------------------------- small screens and motion */

@media (max-width: 640px) {
  .rest-base {
    display: none;
  }

  .rest-summary {
    grid-template-columns: max-content minmax(0, 1fr);
  }

  .rest-summary-meaning {
    grid-column: 1 / -1;
    margin-top: -2px;
    font-size: var(--fs-xs);
  }

  .flow-lanes,
  .flow-track {
    --flow-gap: 6px;
  }

  .flow-lane {
    padding: 8px 4px;
  }

  .flow-lane-sub {
    display: none;
  }

  .flow-chip {
    padding: 0 5px;
    font-size: 0.62rem;
  }

  .anatomy-group-title {
    flex-basis: 100%;
  }

  .resource-legend {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flow-step.is-new {
    animation: none;
  }

  .result-waiting::before {
    animation-duration: 3s;
  }

  .jt-summary::before {
    transition: none;
  }
}
