/* Work order form, card internals: the line-item stacks, their row cells and the Find Code
   modal. The page shell around them (the column grid, the scrolling) is work-order-layout.css. */

/* Every line item's price, wherever it renders (mat layers, mat designs, frame layers,
   printing, materials & services): a dark, square-cornered "tag". */
.cp-line-price.form-control-plaintext {
  width: auto;
  margin-inline-start: auto;
}

/* The cell priceCell() puts a price in, sized and centred like the remove button's cell (see
   .cp-line-remove-cell in widgets.css). Packed to the end, so a price wider than a narrow cell
   ($33.48 in a Frames row's col-2) spills out to the left, into the gap before it, rather than
   across the remove button after it. */
.cp-line-price-cell {
  justify-content: flex-end;
}

.cp-line-price.form-control-plaintext.cp-line-price-priced {
  /* .form-control-plaintext's own line-height: 1.5 (21px against this text's 14px) left more
     empty line-box above the digits than below, off-center in a box this tight; 1 plus
     centering the line box itself (rather than trusting text-align/vertical-align to land it
     inside that leftover space) is what actually centers it. display: flex still blockifies to
     plain flex here (being a flex item forces that), so this doesn't change how the box itself
     is pushed within its row (the rule above).
     min-height: 0 clears .form-control-sm's own min-height (~31px, sized for a real input):
     without it the padding/line-height trims above did nothing visible, since that floor kept
     forcing the box back to 31px regardless, with the centering only pushing the text around
     inside space that was never trimmed. */
  display: flex;
  align-items: center;
  min-height: 0;
  line-height: 1;
  padding-block: .3rem;
  padding-inline: .6rem;
  background-color: var(--bs-dark);
  color: var(--cp-on-dark);

  /* Square, not .form-control-sm's own border-radius: var(--bs-border-radius-sm) (still in
     play here, and left rounding it otherwise). */
  border-radius: 0;
}

/* Prices outside the card, the prototype's per-line prices (Order/New, mockup 34:385): each line
   item's tag hangs off its card's right edge, level with its row, in a gutter beside the card.

   The gutter is the line-items column's own right padding (.cp-priced-col, set by scrollColumn()
   for that column alone), not a separate track. The columns scroll, and a scroll container clips
   whatever lies outside its box, so a tag drawn past the column's edge would be cut off. Inside
   the padding it is still within the column. The prototype does it the same way and for the same
   reason.

   Only once the main pair is split (the same 1000px the column widths switch at in
   work-order-layout.css). Below that the line-items column shares its track with Art and
   Measurements, and a 110px gutter would come out of cards that cannot spare it, so the tags stay
   inside their rows as before.

   Each tag is positioned across against the row holding it. The left offset walks from the row's
   right edge out to the card's: the card body's 1rem padding and the card's border, less the
   half-gutter a Bootstrap .row (Mats, Frames) already extends past the padding. A .cp-hrow
   (Materials & Services) or .cp-mat-design-row has no gutter, so the variable falls back to zero
   there. A row left off that list is no containing block, and its tag is measured from something
   wider further out.

   Down, it stays where it would be in the row: no top, so the tag keeps its static position,
   centred in its .cp-line-price-cell (or its .cp-hrow) the same way it is below 1000px. Centring
   it on the row instead put a print's price level with its labels and fields together, and a
   Mat Design's price, whose grid row is neither a .row nor a .cp-hrow, against the whole mat
   section. */
@container cp-wo-cards (width >= 1000px) {
  .cp-priced-col {
    padding-right: 110px;

    & .card-body :is(.row, .cp-hrow, .cp-mat-design-row):has(.cp-line-price) {
      position: relative;
    }

    /* The cell the tag used to fill, in a .row, collapses so the remove button sits straight
       after the last control, as it does in the prototype. */
    & .card-body .row > :has(> .cp-line-price) {
      flex: 0 0 0;
      width: 0;
      padding: 0;
    }

    & .cp-line-price.form-control-plaintext {
      position: absolute;
      left: calc(100% + 1rem + var(--bs-border-width) - var(--bs-gutter-x, 0px) * .5);
      z-index: 2;
    }

    /* The prototype's tag: a fixed 104px wide and the height of the inputs beside it, so every
       price on the card lines up into one column of black boxes. */
    & .cp-line-price.form-control-plaintext.cp-line-price-priced {
      justify-content: flex-end;
      width: 104px;
      min-height: calc(1.5em + .5rem + calc(var(--bs-border-width) * 2));
    }
  }
}

/* A product picker with its Find Code magnifier attached to its right edge, the prototype's
   input-group-sm around a field and a .btn-light (.mat-find-link on a mat row, the
   .find-code-btn on #frame-add). Not Bootstrap's own .input-group, which styles only
   .form-control children and leaves .cp-token-select's div with its own corners and a
   doubled border where the two meet.

   This replaced a bare orange glyph sitting loose beside the picker. The design review asked
   for the prototype's attached button instead.

   The button's height is .cp-token-select's, so the two read as one control, and its corners
   are square to meet the field's, which theme.css's rounded .btn would otherwise give it. */
.cp-search-group {
  display: flex;
  align-items: stretch;

  & > :first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  & > .btn {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    min-height: calc(1.5em + .5rem + calc(var(--bs-border-width) * 2));
    margin-left: calc(var(--bs-border-width) * -1);
    padding: 0 .6rem;
    font-size: .875rem;
    line-height: 1;
    border-radius: 0;
  }
}

/* A select narrow enough that Bootstrap's chevron crowds out the value. It
   reserves 2.25rem on the right for the arrow, which on the mat layer row's
   Cut cell leaves too little for even a two-letter value: SB renders as S.
   Tighten the reserve and pull the chevron in to match. */
.cp-narrow-select.form-select {
  padding-right: 1.4rem;
  background-position: right .3rem center;
}

/* The cell holding a short measurement in a line-item row: the mat layer's Size,
   the frame layer's Width. A fixed width rather than a grid column, because the
   twelfths either side of what one needs are both wrong: col-3 leaves it half
   empty while the product picker beside it truncates, and col-2 clips the value
   itself. What is left over goes to the picker, which is the cell that can
   always use more. */
.cp-inches-cell {
  flex: 0 0 auto;
  width: 64px;

  /* Tighter than .form-control's .5rem. At this width the default padding is
     the difference between showing 1 3/4 and showing 1 3, and a measurement
     that reads as the wrong number is worse than a cramped one. */
  & .form-control {
    padding-right: .3rem;
    padding-left: .3rem;
  }
}

/* The cell holding a product picker: a mat layer's board, a frame layer's code. It refuses to go
   below its content's width without this, because a flex item's min-width defaults to auto, and
   the content is a long product label or a long placeholder, wider than the share of the row left
   once the measurement, price and remove button have taken theirs.

   What that looks like depends on which way the parent gives. A .row wraps, so the mat card drops
   its later cells onto a second line; the frame band does not wrap, so it pushed the width field
   out of the band instead, by 12px at 1200px wide and 154px at 860px. Both are the same cell
   refusing to shrink, and both stop here: the picker is the one that gives, and the pill inside it
   truncates, which .cp-token-label is already set up to do. */
.cp-picker-cell {
  min-width: 0;
}

/* The Mats card's Mat Design list: a heading row with a column of rows under it.
   The tracks are declared once, here, and both the headings and every row take them
   through subgrid. That is the whole point of the grid: the prototype aligns its
   heading to its rows by giving two separate Bootstrap .rows matching .col classes,
   which holds only as long as nobody edits one of them.

   1fr for the design select so the row fills the card, then a fixed Qty, a fixed
   price, and the remove button's own width. Price is 80px, not the plain text's old 64px:
   .cp-line-price (work-order-cards.css, above) pads its text into a pill, which needs the
   extra room. */
.cp-mat-designs {
  display: grid;
  grid-template-columns: 1fr 72px 80px auto;
  gap: .25rem .5rem;
  align-items: center;
  margin-bottom: .5rem;

  & > * {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
    align-items: center;
  }

  /* A row's validation messages sit under the whole row rather than in the
     design column, since more than one cell can be at fault. */
  & .invalid-feedback {
    grid-column: 1 / -1;
  }
}

/* The mat stack's line-art gutter: one notched board per layer, stepped right and down so they
   overlap, drawn to the left of the rows rather than as a panel behind them. Ported from the
   design prototype's .mat-nest-gutter. The SVG's width and height are set inline by
   reactive-components/work-order/form/lib/mat-nest-gutter.js, which measures the rows:
   the stack is taller than they are, so it hangs below the last one.
 */
.cp-mat-layers {
  position: relative;

  & .cp-mat-nest {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    pointer-events: none;

    & svg {
      display: block;
    }

    /* White board, gray edge, square corners. Literal values rather than Bootstrap's surface
       tokens: these are the designer's mat-viz component colors, not the app's card chrome, and
       reading --bs-body-bg here would make the boards vanish against the card in dark mode. */
    & path {
      fill: #fff;
      stroke: #c4c8cb;
      stroke-width: 1;
    }

    /* The component's Label/Small. */
    & text {
      font-size: 9.5px;
      font-weight: 600;
      fill: var(--bs-body-color);
    }
  }
}

/* The frame stack drawn as a nested cross-section: one panel per layer, each running from the top
   of the list to the bottom of its own row, so the last (outermost) moulding visibly contains what
   is built inside it. Geometry comes from the painter
   (reactive-components/work-order/form/lib/frame-nest-panels.js), which measures the rows; this
   only says what a panel looks like and which way the layers stack.

   The list is the positioning context, and the panels sit behind the rows rather than around them,
   because a row cannot both be a grid cell in the form and a box wrapping the rows after it. */
.cp-frame-layers {
  position: relative;
}

.cp-frame-nest {
  position: absolute;
  inset: 0;
  z-index: 0;

  /* The panels are a drawing. Clicks belong to the row on top of them. */
  pointer-events: none;
}

.cp-frame-nest-panel {
  position: absolute;
  top: 0;
  background: var(--bs-body-bg);
  border: var(--bs-border-width) solid var(--bs-border-color);
}

.cp-frame-layer {
  position: relative;
  z-index: 1;
}

/* A row showing search results outranks the rows under it. Every row is positioned so it paints
   above the nest panels, which puts them all on one level, and on one level the last row in the
   document wins: a lower row's controls drew over the results of the row above, through them.

   Keyed on the dropdown being open rather than on :focus-within, because the open dropdown is the
   thing that needs the room. They part company for the 150ms the list stays up after blur, which is
   long enough to see a result vanish behind the row below it. */
.cp-frame-layer:has(.cp-token-dropdown:not(.d-none)) {
  z-index: 2;
}

/* The part of a row a panel wraps: the picker and its width. The padding keeps them off the panel's
   edges on all four sides, so a layer reads as a band of moulding with the controls sitting inside
   it rather than as controls with a line drawn round them. margin-left is the indent, set by the
   painter.

   The horizontal 1rem is the painter's step (FRAME_NEST_STEP in lib/frame-nest.js), as in the
   prototype's .frame-visual, so the gap from one panel's edge to the next equals the gap from the
   innermost panel's edge to its own fields. Change one and the other has to follow. */
.cp-frame-visual {
  min-width: 0;
  padding: .5rem 1rem;
}

/* A frame layer that holds a moulding shows its code as bare text on the band, with no field
   outline, the prototype's read-only .layer-name. The outline comes back on hover and focus,
   so the field still shows it can be searched again. */
.cp-frame-visual .cp-token-select.is-filled:not(:hover, :focus-within) {
  background: transparent;
  border-color: transparent;
}

/* The frame layer's width field. Marker class on the inchesField wrapper, which
   also carries .cp-inches-cell for the shared 64px-wide layout. See widthField()
   in reactive-components/work-order/form/lib/frame-width.js for the component.
   The read-only span styling that used to live here was removed when the width
   went back to an editable field; see the comment above widthField for why. */
