/*
 * The extraction pack's screens: the extraction plan editor (listing and detail profiles), the
 * browser action plan editor, the element picker (also shown inside the source wizard's sheet)
 * and the plan card on the source form. Moved verbatim from application.css (E13T16).
 * Every token these rules name is defined in the `:root` block of application.css,
 * which both layouts link before this file; the only custom properties set here are the editor's
 * own `--plan-*` ones.
 */

.plan-state {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--theme-foreground-medium-contrast);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-regular);
}

.plan-state__dot {
  width: var(--size-half);
  height: var(--size-half);
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  background: currentColor;
}

.plan-state--published .plan-state__dot {
  background: var(--theme-foreground-success);
}

.plan-state--missing .plan-state__dot {
  background: var(--theme-foreground-caution);
}

.plan-state--invalid .plan-state__dot {
  background: var(--theme-foreground-error);
}

/* Shared with the browser action plan editor's trace table, which draws its own rows out of
   these three. Anything the extraction editor changes about them is scoped under .plan-step or
   .plan-step__readout below, so restyling one screen cannot move the other. */
.plan-step__operation { font-weight: var(--font-weight-medium); }
.plan-step__value-text { display: block; overflow-wrap: anywhere; font-size: var(--font-size-10); }
.plan-step__badge { font-size: var(--font-size-10); }
.plan-step__badge--stopped { color: var(--theme-foreground-error); font-weight: var(--font-weight-medium); }
.plan-pipeline__add { display: flex; gap: var(--size-1x); align-items: center; }
/* Only the browser action editor draws .plan-arg and .plan-rule. In a narrow rule a step's
   arguments go under its head rather than beside it, and an input is 12rem wide but never wider
   than its column. It was a 12rem minimum, which WebKit's own 238px default for these inputs
   exceeded, and that pushed the page to 433px in a 390px viewport. */
.plan-rule .plan-step { flex-wrap: wrap; }
.plan-arg { display: flex; flex-direction: column; font-size: var(--font-size-10); gap: var(--size-half); min-width: 0; }
.plan-arg__input { width: 12rem; max-width: 100%; }

.plan-arg input[type="text"],
.plan-arg input[type="number"],
.plan-arg select,
.plan-pipeline__add select {
  min-height: var(--size-5x);
  padding: 0 var(--size-inset);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius-sm);
  background: var(--theme-background-container);
  color: var(--theme-foreground-high-contrast);
  font-family: inherit;
  font-size: var(--font-size-30);
}

.plan-arg input[type="text"]:focus-visible,
.plan-arg input[type="number"]:focus-visible,
.plan-arg select:focus-visible,
.plan-pipeline__add select:focus-visible {
  outline: 2px solid var(--theme-accent);
  outline-offset: 0;
  border-color: var(--theme-accent);
}

.plan-arg input[type="checkbox"] {
  position: relative;
  width: calc(var(--size-half) * 4.5);
  height: calc(var(--size-half) * 4.5);
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--theme-border-high-contrast);
  border-radius: var(--radius-sm);
  background: var(--theme-background-container);
  cursor: pointer;
}

.plan-arg input[type="checkbox"]:checked {
  border-color: var(--theme-foreground-high-contrast);
  background: var(--theme-foreground-high-contrast);
}

.plan-arg input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid var(--theme-foreground-inverse);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ------------------------------------------------ extraction plan editor (E3T33 redesign) -- */

/* One vocabulary of state for the whole screen, in the same three words the step readouts use.
   `stopped` is the only red badge, so a broken chain is the thing the eye lands on. */
.plan-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--size-half);
  padding: 0;
  border-radius: 0;
  background: none;
  color: var(--theme-foreground-medium-contrast);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-regular);
  white-space: nowrap;
}

.plan-badge::before {
  content: "";
  width: var(--size-half);
  height: var(--size-half);
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  background: var(--theme-border-high-contrast);
}


.plan-badge--complete::before { background: var(--theme-foreground-success); }
.plan-badge--partial::before { background: var(--theme-foreground-caution); }
.plan-badge--stopped::before { background: var(--theme-foreground-error); }

.plan-coverage--complete { --plan-state: var(--theme-foreground-success); }
.plan-coverage--partial { --plan-state: var(--theme-foreground-caution); }
.plan-coverage--stopped { --plan-state: var(--theme-foreground-error); }

/* The bar is an svg because its length is a number the server computed, and a presentation
   attribute carries a number without an inline style; the offers chart is drawn the same way. */
.plan-bar {
  display: block;
  width: 5.25rem;
  height: 0.375rem;
  flex: 0 0 auto;
}

.plan-bar__track { fill: var(--theme-border-low-contrast); }
.plan-bar__fill { fill: var(--plan-state, var(--theme-foreground-low-contrast)); }

/* -------------------------------------------------------------------------------- header -- */

/* The hand editor is drawn as a small flow on a canvas: the stored page it starts from, the item
   locator under it and each field branching off a trunk. These are the few measures the
   connectors share, so a line always lands on the middle of a card's header. */
.plan-editor {
  --plan-line: var(--theme-border-high-contrast);
  --plan-chain-gap: var(--size-3x);
  --plan-branch: var(--size-5x);
  --plan-anchor: 1.75rem;
}

.plan-editor__header {
  position: sticky;
  top: var(--topbar-height);
  z-index: 5;
  padding: var(--size-inset) 0;
  background: var(--theme-background-base);
  border-bottom: 1px solid var(--theme-border-low-contrast);
}

.plan-editor__masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--size-3x);
  flex-wrap: wrap;
}

.plan-editor__identity {
  display: flex;
  flex-direction: column;
  gap: var(--size-half);
  min-width: 0;
}

.plan-editor__breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  font-size: var(--font-size-20);
  font-weight: var(--font-weight-regular);
  text-transform: none;
  color: var(--theme-foreground-low-contrast);
}

.plan-editor__crumb { color: inherit; }
.plan-editor__crumb--feed { font-family: var(--font-mono); text-transform: none; }
.plan-editor__crumb--current { color: var(--theme-foreground-high-contrast); }

.plan-editor__crumb-arrow {
  width: 0.85rem;
  height: 0.85rem;
  color: var(--theme-foreground-low-contrast);
}

.plan-editor__heading {
  margin: 0;
  font-size: var(--font-size-50);
  font-weight: var(--font-weight-medium);
}

.plan-editor__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--size-1x);
}

.plan-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--size-1x);
  min-height: 2.25rem;
  padding: 0 var(--size-inset);
  border-radius: var(--radius-full);
  background: var(--theme-background-container-alt);
}

.plan-chip__icon {
  width: 0.95rem;
  height: 0.95rem;
  color: var(--theme-foreground-low-contrast);
}

.plan-chip__text {
  font-family: var(--font-mono);
  font-size: var(--font-size-10);
  color: var(--theme-foreground-medium-contrast);
}

.plan-editor__tabs { margin-top: var(--size-inset); }

/* The profile tabs are one segmented control: the grey track of .tabs, with the current segment
   lifted white. */
.plan-editor__tabs {
  display: inline-flex;
  align-items: center;
  gap: var(--size-half);
  padding: var(--size-half);
  border-radius: var(--radius);
  background: var(--theme-background-container-alt);
}

.plan-editor__tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--size-1x);
  min-height: var(--size-4x);
  padding: 0 var(--size-inset);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--theme-foreground-medium-contrast);
  font-size: var(--font-size-20);
  font-weight: var(--font-weight-medium);
  transition: background var(--duration-colour) var(--bezier), color var(--duration-colour) var(--bezier);
}

.plan-editor__tab:hover { color: var(--theme-foreground-high-contrast); }

.plan-editor__tab-saved {
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-regular);
  color: var(--theme-foreground-low-contrast);
  overflow-wrap: anywhere;
}

.plan-editor__tab--current {
  background: var(--theme-background-container);
  color: var(--theme-foreground-high-contrast);
  box-shadow: var(--shadow-segment);
}

/* ------------------------------------------------------------------------------ workspace -- */

/* The stored page is the main area and the Fields panel sits beside it; what a fetch would store
   and the hand editor run under both. Under 768px the three stack. */
.plan-editor__workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22.5rem;
  align-items: start;
  gap: var(--size-2x);
  padding: var(--size-2x) 0 var(--size-4x);
}

.plan-editor__workspace > * { min-width: 0; }

.plan-editor .plan-result,
.plan-editor__form { grid-column: 1 / -1; }

/* The canvas, inside "Edit the steps by hand". The dots are the one texture on the screen and
   they belong to it: the chain on top of them is a diagram, and a diagram is drawn on a board. */
.plan-editor__canvas {
  display: flex;
  flex-direction: column;
  gap: var(--size-3x);
  padding: var(--size-3x);
  border-radius: var(--radius-xl);
  background-color: var(--theme-background-container-alt);
  background-image: radial-gradient(circle, var(--theme-border-high-contrast) 1px, transparent 1.3px);
  background-size: 18px 18px;
}

/* Every card on the canvas is a node: white, lifted by a shadow and not outlined, because the
   grey board already draws the edge a border would. */
.plan-editor__canvas .panel {
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-node);
}

.plan-editor__chain {
  display: flex;
  flex-direction: column;
  gap: var(--plan-chain-gap);
}

.plan-canvas__start {
  position: relative;
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: var(--size-1x);
  min-height: 2rem;
  padding: 0 var(--size-inset);
  border-radius: var(--radius-full);
  background: var(--theme-background-accent);
  color: var(--theme-foreground-inverse);
  font-size: var(--font-size-20);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-md);
}

.plan-canvas__start-icon { width: 0.95rem; height: 0.95rem; }

/* The trunk leaves the start pill at the same x every branch below hangs from. */
.plan-canvas__start::after {
  content: "";
  position: absolute;
  top: 100%;
  left: calc(var(--plan-branch) / 2 - 1px);
  width: 2px;
  height: var(--plan-chain-gap);
  background: var(--plan-line);
}

@media (max-width: 767px) {
  .plan-editor__workspace { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .plan-editor { --plan-branch: var(--size-3x); --plan-chain-gap: var(--size-2x); }
  .plan-editor__canvas { padding: var(--size-inset); border-radius: var(--radius-lg); }
  .plan-chip { padding: var(--size-half) var(--size-inset); border-radius: var(--radius-lg); }
  .plan-pipeline__operation { flex: 1 1 auto; min-width: 0; }
  /* Two equal tabs across the full width, each with its saved line on a row of its own, so a
     phone never scrolls sideways to read who saved the other profile. */
  .plan-editor__tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plan-editor__tab { flex-wrap: wrap; min-width: 0; padding: var(--size-half) var(--size-1x); }
  .plan-editor__tab-saved { flex-basis: 100%; text-align: center; }
}

/* ----------------------------------------------------------------------- pipeline as card -- */

.plan-pipeline {
  position: relative;
  padding: 0;
}

/* A field is read out of each item the locator found, so its card hangs off the locator's trunk
   rather than following it: an elbow from the trunk into the middle of its header, and a trunk
   segment on down to the next field. */
.plan-pipeline--field { margin-left: var(--plan-branch); }

.plan-pipeline--field::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--plan-chain-gap));
  left: calc(-1 * var(--plan-branch) / 2 - 1px);
  width: calc(var(--plan-branch) / 2 + 1px);
  height: calc(var(--plan-chain-gap) + var(--plan-anchor) + 1px);
  border-left: 2px solid var(--plan-line);
  border-bottom: 2px solid var(--plan-line);
  border-bottom-left-radius: var(--radius-lg);
}

.plan-pipeline--field:has(+ .plan-pipeline--field)::after {
  content: "";
  position: absolute;
  top: var(--plan-anchor);
  bottom: 0;
  left: calc(-1 * var(--plan-branch) / 2 - 1px);
  width: 2px;
  background: var(--plan-line);
}

.plan-pipeline__header {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
  border-bottom: 1px solid var(--theme-border-low-contrast);
}

.plan-pipeline__icon {
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  padding: 0.45rem;
  border-radius: var(--radius);
  background: var(--theme-background-accent-subtle);
  color: var(--theme-accent);
}

.plan-pipeline--field .plan-pipeline__icon {
  background: var(--theme-background-container-alt);
  color: var(--theme-foreground-medium-contrast);
}

.plan-pipeline__title {
  margin: 0;
  font-size: var(--font-size-30);
  font-weight: var(--font-weight-medium);
}

.plan-pipeline__title--field {
  font-family: var(--font-mono);
  font-size: var(--font-size-20);
  font-weight: var(--font-weight-medium);
}

.plan-pipeline__kind {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-coverage {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  margin-left: auto;
}

.plan-pipeline .plan-pipeline__empty {
  margin: 0;
  padding: var(--size-2x) var(--size-2x);
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-pipeline__steps {
  list-style: none;
  margin: 0;
  padding: var(--size-1x) 0;
}

.plan-pipeline__add {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
  border-top: 1px solid var(--theme-border-low-contrast);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: var(--theme-background-container-alt);
}

.plan-pipeline__operation {
  width: 14rem;
  max-width: 100%;
  min-height: 2.15rem;
  padding: var(--size-half) var(--size-1x);
  border-radius: var(--radius);
  font-size: var(--font-size-10);
}

.plan-pipeline__add-button {
  white-space: nowrap;
  border: 1px dashed var(--theme-border-high-contrast);
  background: var(--theme-background-container);
  color: var(--theme-foreground-medium-contrast);
}

.plan-pipeline__add-button:hover {
  background: var(--theme-background-container-alt);
  color: var(--theme-accent);
}

.plan-pipeline__add-icon {
  width: 0.85rem;
  height: 0.85rem;
}

/* ------------------------------------------------------------------- one step on the rail -- */

.plan-step {
  display: flex;
  gap: var(--size-inset);
  padding: var(--size-1x) var(--size-2x);
  margin: 0;
}

.plan-step__rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  padding-top: var(--size-half);
}

.plan-step__number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-full);
  background: var(--theme-background-container-alt);
  color: var(--theme-foreground-low-contrast);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-medium);
}

.plan-step__rail-line {
  width: 2px;
  flex: 1 1 auto;
  min-height: 1rem;
  margin-top: var(--size-half);
  background: var(--theme-border-low-contrast);
}

/* Same reason as the card tint: the colour of the rail is what the recompute just said, and the
   only element carrying that answer is the readout the recompute replaced. */
.plan-step:has(.plan-step__readout--complete) .plan-step__number { background: var(--theme-background-success-subtle); color: var(--theme-foreground-success); }
.plan-step:has(.plan-step__readout--partial) .plan-step__number { background: var(--theme-background-caution-subtle); color: var(--theme-foreground-caution); }
.plan-step:has(.plan-step__readout--stopped) .plan-step__number { background: var(--theme-background-error-subtle); color: var(--theme-foreground-error); }

.plan-step__body {
  flex: 1 1 auto;
  min-width: 0;
}

.plan-step__head {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  flex-wrap: wrap;
  justify-content: flex-start;
}

.plan-step .plan-step__operation {
  padding: var(--size-half) var(--size-1x);
  border-radius: var(--radius);
  background: var(--theme-background-container-alt);
  color: var(--theme-foreground-high-contrast);
  font-family: var(--font-mono);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-medium);
}

.plan-step__arguments {
  display: flex;
  flex: 1 1 14rem;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--size-1x);
  min-width: 0;
  margin: 0;
}

.plan-step__no-arguments {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-step__buttons {
  display: flex;
  gap: var(--size-1x);
  margin-left: auto;
}

.plan-step__icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius);
  background: var(--theme-background-container);
  color: var(--theme-foreground-medium-contrast);
  cursor: pointer;
}

.plan-step__icon-button:hover {
  background: var(--theme-background-accent-subtle);
  border-color: var(--theme-border-high-contrast);
  color: var(--theme-accent);
}

.plan-step__remove:hover {
  background: var(--theme-background-error-subtle);
  border-color: var(--theme-foreground-error);
  color: var(--theme-foreground-error);
}

.plan-step__button-icon {
  width: 1rem;
  height: 1rem;
}

/* -------------------------------------------------------------- one argument, in the line -- */

.plan-step-arg {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  min-width: 0;
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-step-arg--wide { flex: 1 1 13rem; }

/* Collapsed it is a chip in the line; opened it takes the line, because what it opens onto is a
   list of selectors rather than a word. */
.plan-step-arg--stowed { flex: 0 0 auto; display: block; }
.plan-step-arg--stowed[open] { flex: 1 0 100%; }

.plan-step-arg__stow {
  padding: var(--size-half) var(--size-1x);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius);
  color: var(--theme-foreground-low-contrast);
  font-size: var(--font-size-10);
  cursor: pointer;
}

.plan-step-arg--stowed[open] .plan-step-arg__stow { margin-bottom: var(--size-half); }

.plan-step-arg__name {
  white-space: nowrap;
}

.plan-step-arg__input {
  min-height: 2.35rem;
  padding: var(--size-half) var(--size-inset);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--font-size-20);
}

.plan-step-arg__input--narrow { width: 5.5rem; min-width: 0; }
textarea.plan-step-arg__input { min-height: 3.5rem; }
/* An argument with a declared domain is a select, and a select already sizes to the longest of
   its handful of words, so it takes its own width rather than the 13rem a free-text input claims. */
select.plan-step-arg__input { width: auto; }

/* A boolean argument as a chip rather than a bare checkbox: the box itself is what submits, so
   it stays in the form and is only taken out of sight, and the chip it drives says the argument
   name whether it is on or off. */
.plan-step-arg--toggle { cursor: pointer; }

.plan-step-arg__check {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.plan-step-arg__toggle-face {
  display: inline-flex;
  align-items: center;
  gap: var(--size-1x);
  height: 2.35rem;
  padding: 0 var(--size-inset);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius);
  background: var(--theme-background-container);
  color: var(--theme-foreground-low-contrast);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-medium);
}

.plan-step-arg__toggle-icon {
  width: 0.85rem;
  height: 0.85rem;
  opacity: 0.25;
}

.plan-step-arg__check:checked + .plan-step-arg__toggle-face {
  border-color: transparent;
  background: var(--theme-background-accent-subtle);
  color: var(--theme-accent);
}

.plan-step-arg__check:checked + .plan-step-arg__toggle-face .plan-step-arg__toggle-icon { opacity: 1; }

/* The box that carries the focus is out of sight, so the chip it drives wears the ring: the same
   2px accent outline everything else interactive gets. */
.plan-step-arg__check:focus-visible + .plan-step-arg__toggle-face {
  outline: 2px solid var(--theme-accent);
  outline-offset: 2px;
  border-color: var(--theme-accent);
}

/* ------------------------------------------------------- the value the step just produced -- */

/* The state colour sits on the readout, not on the step, because the readout is what the live
   recompute replaces; on the step it would keep the first answer's colour for ever. */
.plan-step__readout {
  margin-top: var(--size-1x);
  padding: var(--size-1x) var(--size-inset);
  border-radius: var(--radius);
  background: var(--theme-background-container-alt);
}

.plan-step__readout--partial { background: var(--theme-background-caution-subtle); }
.plan-step__readout--stopped { background: var(--theme-background-error-subtle); }
.plan-step__readout--complete .plan-step__badge { color: var(--theme-foreground-success); }
.plan-step__readout--partial .plan-step__badge { color: var(--theme-foreground-caution); }

.plan-step__readout .plan-step__value-text {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-medium-contrast);
}

.plan-step__state { margin: var(--size-half) 0 0; }

.plan-step__readout .plan-step__badge {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-step__readout .plan-step__badge--stopped {
  color: var(--theme-foreground-error);
  font-weight: var(--font-weight-medium);
}

/* ------------------------------------- the empty state a profile with no plan opens on -- */

.plan-editor__empty {
  display: flex;
  flex-direction: column;
  gap: var(--size-2x);
  max-width: 44rem;
  margin: var(--size-5x) auto;
  padding-bottom: var(--size-4x);
}

.plan-empty {
  padding: var(--size-5x) var(--size-4x);
  text-align: center;
}

.plan-empty__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: var(--radius-full);
  background: var(--theme-background-caution-subtle);
  color: var(--theme-foreground-caution);
}

.plan-empty__icon { width: 1.5rem; height: 1.5rem; }

.plan-empty__title {
  margin: var(--size-2x) 0 var(--size-1x);
  font-size: var(--font-size-40);
  font-weight: var(--font-weight-medium);
}

.plan-empty__body {
  margin: 0 auto var(--size-3x);
  max-width: 28rem;
  font-size: var(--font-size-20);
  line-height: 1.6;
  color: var(--theme-foreground-low-contrast);
}

.plan-empty__actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--size-1x);
}

/* ------------------------------------------------------- the result, and the picker -- */

/* The browser action editor's right pane: one card holding what one paid render reported. */
.plan-right {
  display: flex;
  flex-direction: column;
  gap: var(--size-inset);
  min-width: 0;
  padding: var(--size-inset);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius-xl);
  background: var(--theme-background-container);
}

.plan-picker {
  background: var(--theme-background-container);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.plan-picker { border: 1px solid var(--theme-border-low-contrast); }

.plan-result__warning,
.plan-result__reasons,
.plan-result__reason {
  margin: 0 0 var(--size-inset);
  padding: var(--size-inset);
  border-radius: var(--radius);
  font-size: var(--font-size-10);
}

.plan-result__warning { background: var(--theme-background-caution-subtle); }
.plan-result__reasons,
.plan-result > .plan-result__reason { background: var(--theme-background-error-subtle); }

.plan-result__warning { color: var(--theme-foreground-caution); }
.plan-result__reasons { list-style: none; }
.plan-result__reasons .plan-result__reason { margin: 0; padding: var(--size-half) 0; }
.plan-result__reason { color: var(--theme-foreground-error); }

/* The editor's three panels. The picker inside the page panel is flush with it, so the stored page
   reads as the panel's own body rather than a box inside a box. */
.plan-editor .plan-page,
.plan-editor .plan-fields,
.plan-editor .plan-result { padding: 0; overflow: hidden; }

.plan-editor .plan-picker { border: 0; border-radius: 0; }
.plan-editor .plan-picker__frame { height: min(38rem, 70vh); }

.plan-editor .plan-page__chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
  border-bottom: 1px solid var(--theme-border-low-contrast);
}

.plan-editor .plan-page__chips-label,
.plan-editor .plan-page__by-hand {
  margin: 0;
  font-size: var(--font-size-20);
  color: var(--theme-foreground-medium-contrast);
}

.plan-editor .plan-page__by-hand { padding: var(--size-2x); }

.plan-editor .plan-page__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--size-1x);
  min-height: 2.25rem;
  min-width: 0;
  padding: 0 var(--size-inset);
  border: 0;
  border-radius: var(--radius-full);
  background: var(--theme-background-container-alt);
  font: inherit;
  font-size: var(--font-size-20);
  color: inherit;
  overflow-wrap: anywhere;
}

.plan-editor button.plan-page__chip { cursor: pointer; }
.plan-editor button.plan-page__chip:disabled { cursor: default; }

/* The field being marked: the next click in a card writes its steps. */
.plan-editor .plan-page__chip[aria-pressed="true"] {
  background: var(--theme-background-accent-subtle);
  color: var(--theme-accent);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px var(--theme-accent);
}

.plan-editor .plan-page__skip { display: block; padding: var(--size-1x) var(--size-2x); }
.plan-editor .plan-page__skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* "+ New field": a dashed chip that opens, in the flow of the chip bar rather than floating over
   the page, the names an item stores and the plan does not have yet. */
.plan-editor .plan-page__new[open] { flex-basis: 100%; }

.plan-editor .plan-page__new-toggle {
  width: fit-content;
  box-shadow: inset 0 0 0 1px var(--theme-border-low-contrast);
  background: transparent;
  cursor: pointer;
  list-style: none;
}

.plan-editor .plan-page__new-toggle::-webkit-details-marker { display: none; }

.plan-editor .plan-page__new-menu {
  display: flex;
  flex-wrap: wrap;
  gap: var(--size-1x);
  margin: var(--size-1x) 0 0;
  padding: 0;
  list-style: none;
}

.plan-editor .plan-page__new-choice {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 2.25rem;
  padding: var(--size-half) var(--size-inset);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius-sm);
  background: var(--theme-background-container);
  font: inherit;
  font-size: var(--font-size-20);
  color: inherit;
  cursor: pointer;
}

.plan-editor .plan-page__new-note {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-editor .plan-fields__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
}

.plan-editor .plan-fields__title,
.plan-editor .plan-result__title {
  margin: 0;
  font-size: var(--font-size-40);
  font-weight: var(--font-weight-medium);
}

/* Every field reached every item: the panel turns the success wash, the one place on the screen
   that says "this plan works" in a single glance. The server decides it
   (PlanEditor::Preview#complete?), inside #plan-fields, so the recompute redraws it. */
.plan-editor .plan-fields--complete { background: var(--theme-background-success-subtle); }

.plan-editor .plan-field {
  display: flex;
  flex-direction: column;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
  border-top: 1px solid var(--theme-border-low-contrast);
}

.plan-editor .plan-field__head { display: flex; align-items: center; gap: var(--size-1x); }

.plan-editor .plan-field__name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: var(--font-weight-medium);
  overflow-wrap: anywhere;
}

.plan-editor .plan-field__samples {
  display: flex;
  flex-direction: column;
  gap: var(--size-half);
  margin: 0;
  padding: var(--size-1x) var(--size-inset);
  list-style: none;
  border-radius: var(--radius);
  background: var(--theme-background-container-alt);
  font-size: var(--font-size-10);
}

/* One line per sample, as the mockup's readout: a value is recognised by its start, and a long
   one (a whole card's markup) would otherwise push every other field off the screen. */
.plan-editor .plan-field__sample { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-editor .plan-field__selector {
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

/* The "reads" choice under the selector: the plan-arg select's look, at the panel's small size. */
.plan-editor .plan-field__reads {
  display: flex;
  align-items: center;
  gap: var(--size-1x);
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

/* What a field says about itself under the selector: how many variants it reads, and for a partial
   field where to click to add the one it misses. */
.plan-editor .plan-field__note {
  margin: 0;
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

.plan-editor .plan-field__note--hint {
  padding: var(--size-half) var(--size-1x);
  border-radius: var(--radius-sm);
  background: var(--theme-background-caution-subtle);
  color: var(--theme-foreground-high-contrast);
}

.plan-editor .plan-field__reads-select {
  min-height: var(--size-4x);
  padding: 0 var(--size-1x);
  border: 1px solid var(--theme-border-low-contrast);
  border-radius: var(--radius-sm);
  background: var(--theme-background-container);
  color: var(--theme-foreground-high-contrast);
}

.plan-editor .plan-result__warning,
.plan-editor .plan-result__reasons,
.plan-editor .plan-result > .plan-result__reason { margin: var(--size-2x) var(--size-2x) 0; }

.plan-editor .plan-result__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--size-1x) var(--size-inset);
  padding: var(--size-2x) var(--size-2x) var(--size-inset);
}

.plan-editor .plan-result__note {
  font-size: var(--font-size-10);
  color: var(--theme-foreground-low-contrast);
}

/* The table scrolls inside its own box, so a phone never scrolls the page sideways. */
.plan-editor .plan-result__scroll { overflow-x: auto; padding: 0 var(--size-2x) var(--size-2x); }

.plan-editor .plan-result__table { width: 100%; border-collapse: collapse; }

.plan-editor .plan-result__table th,
.plan-editor .plan-result__table td {
  max-width: 20rem;
  padding: var(--size-1x) var(--size-inset);
  border-bottom: 1px solid var(--theme-border-low-contrast);
  text-align: left;
  vertical-align: top;
  font-size: var(--font-size-20);
  /* One line per item, as the mockup's table: the full value is in the cell's title. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-editor .plan-result__table th {
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-medium);
  color: var(--theme-foreground-low-contrast);
}

.plan-editor .plan-result__table td { min-width: 8rem; }
.plan-editor .plan-result__table th:first-child,
.plan-editor .plan-result__table .plan-result__number { width: 1%; min-width: 0; color: var(--theme-foreground-low-contrast); }
.plan-editor .plan-result__cell--missing { color: var(--theme-foreground-error); font-size: var(--font-size-10); }

.plan-editor .plan-hand { border-top: 1px solid var(--theme-border-low-contrast); }

.plan-editor .plan-hand__summary {
  padding: var(--size-inset) 0;
  color: var(--theme-accent);
  font-size: var(--font-size-20);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

.plan-picker__banner {
  display: flex;
  align-items: flex-start;
  gap: var(--size-1x);
  padding: var(--size-inset) var(--size-2x);
  border-bottom: 1px solid var(--theme-border-low-contrast);
  background: var(--theme-background-container-alt);
}

.plan-picker__banner-icon { width: 0.95rem; height: 0.95rem; flex: 0 0 auto; color: var(--theme-accent); }

.plan-picker__status,
.plan-picker__empty,
.plan-picker__warning {
  margin: 0;
  font-size: var(--font-size-10);
  color: var(--theme-foreground-medium-contrast);
}

.plan-picker__warning { padding: var(--size-2x) var(--size-2x); color: var(--theme-foreground-caution); }
.plan-picker__empty { padding: var(--size-1x) 0; }
.plan-picker__form { margin: 0; }

.plan-picker__frame {
  display: block;
  width: 100%;
  height: 22rem;
  border: 0;
  border-bottom: 1px solid var(--theme-border-low-contrast);
  background: var(--theme-background-container);
}

.plan-picker__candidates { padding: var(--size-inset) var(--size-2x); }

.plan-picker__group {
  margin: var(--size-1x) 0 var(--size-half);
  font-size: var(--font-size-10);
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  color: var(--theme-foreground-low-contrast);
}

.plan-candidate-list { list-style: none; padding: 0; margin: 0; }

.plan-candidate {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--size-1x);
  padding: var(--size-1x) 0;
  border-top: 1px solid var(--theme-border-low-contrast);
  font-size: var(--font-size-10);
}

.plan-candidate:first-child { border-top: 0; }

.plan-candidate__selector {
  flex: 1 1 100%;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-weight: var(--font-weight-medium);
  color: var(--theme-foreground-high-contrast);
}

.plan-candidate__reason { color: var(--theme-foreground-low-contrast); }
.plan-candidate__pair { margin-left: auto; color: var(--theme-foreground-medium-contrast); }

/* Browser action plan editor (E1T26): the same two pane shell, with the rules on the left and
   one paid render's trace on the right. The cost block is styled to be read rather than
   skipped, because a person who does not see what a run spends clicks it again. */
.plan-rule { border: 1px solid var(--theme-border-low-contrast); border-radius: var(--radius); padding: var(--size-1x) var(--size-inset); margin: var(--size-1x) 0; background: var(--theme-background-container, var(--theme-background-container)); }
.plan-rule[draggable="true"] { cursor: grab; }
.plan-rule__handle { color: var(--theme-foreground-low-contrast); margin-right: var(--size-half); }
.plan-cost {
  margin: var(--size-3x) 0;
  padding: 0 0 0 var(--size-inset);
  border: 0;
  border-left: 2px solid var(--theme-foreground-caution);
  background: none;
}
.plan-cost__title { font-size: var(--font-size-20); font-weight: var(--font-weight-medium); margin: 0 0 var(--size-half); }
.plan-cost__list { font-size: var(--font-size-10); margin: 0; padding-left: var(--size-2x); }
.plan-refusal {
  padding: 0 0 0 var(--size-inset);
  border-left: 2px solid var(--theme-foreground-error);
  background: none;
  font-size: var(--font-size-10);
}
.plan-partial { border-left: 3px solid var(--theme-foreground-caution); background: var(--theme-background-caution-subtle); padding: var(--size-1x) var(--size-inset); font-size: var(--font-size-20); }
.plan-snapshot-link { font-size: var(--font-size-10); margin: var(--size-1x) 0; }
.plan-trace { width: 100%; border-collapse: collapse; font-size: var(--font-size-10); }
.plan-trace th { font-weight: var(--font-weight-medium); }
.plan-trace th, .plan-trace td { text-align: left; vertical-align: top; padding: var(--size-half); border-bottom: 1px solid var(--theme-border-low-contrast); }
.plan-trace__rule { font-size: var(--font-size-10); color: var(--theme-foreground-medium-contrast); margin-left: var(--size-half); }
.plan-trace__shot { width: 12rem; max-width: 100%; border-radius: var(--radius-sm); }
