/* Small, reusable, page-agnostic UI controls — not tied to any one feature area.
   (Split out of layout.css.) */

/* Pill-shaped search input-group (Figma list-screen chrome, first used by the Customers
   list toolbar — reusable by any search box, not list-specific). */
.cp-pill-search {
  & > :first-child {
    border-top-left-radius: 50rem;
    border-bottom-left-radius: 50rem;
  }

  & > :last-child {
    border-top-right-radius: 50rem;
    border-bottom-right-radius: 50rem;
  }
}

/* A link styled as a button stays a link inside a disabled fieldset. The fieldset
   leaves links working (a locked work order relies on that for Duplicate WO,
   Cancel Changes and Delete, see app/views/pages/work-order/form.js), but
   Bootstrap's `fieldset:disabled .btn` dims every .btn and turns off its pointer
   events, so a live link would look and act dead. Pointing the disabled colors
   back at the normal ones (and the hover ones on hover) undoes that without
   restating any variant's colors. */
fieldset:disabled a.btn {
  --bs-btn-disabled-color: var(--bs-btn-color);
  --bs-btn-disabled-bg: var(--bs-btn-bg);
  --bs-btn-disabled-border-color: var(--bs-btn-border-color);
  --bs-btn-disabled-opacity: 1;

  pointer-events: auto;

  &:hover {
    --bs-btn-disabled-color: var(--bs-btn-hover-color);
    --bs-btn-disabled-bg: var(--bs-btn-hover-bg);
    --bs-btn-disabled-border-color: var(--bs-btn-hover-border-color);
  }
}

/* Tab strip mounted on a card's black header: inactive tabs are light-on-dark, the active tab
   lifts out in the card-body color. Pair with a card-header carrying `p-0`. Reusable by any
   card that puts nav-tabs in its header (currently the customer detail page's Orders/Invoices
   tabs). */
.cp-card-tabs {
  border-bottom: 0;
  padding: .25rem .5rem 0;

  & .nav-link {
    color: var(--cp-on-dark-muted);
    border: 0;
    font-size: .875rem;
  }

  & .nav-link:hover { color: var(--cp-on-dark); }

  & .nav-link.active {
    color: var(--bs-body-color);
    background: var(--bs-body-bg);
    border-radius: var(--bs-border-radius) var(--bs-border-radius) 0 0;
  }
}

/* Key/value rows for a detail-page card body (Sales Info, Customer History, etc. — pair
   with a zero-padded `card-body p-0`). Each row supplies its own padding so the divider
   between rows bleeds all the way to the card's edges, and no divider after the
   last row. Reusable by any future
   entity-detail page that wants the same label:value card body. */
.cp-detail-dl {
  & > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .4rem .75rem;
    border-bottom: var(--bs-border-width) solid var(--bs-border-color);

    &:last-child { border-bottom: 0; }
  }
}

/* Line-item remove button: a uniform filled-red circular minus (Figma table chrome).
   Pair with Bootstrap's own .btn.btn-danger and a bi-dash-lg icon.

   border-radius:50% alone isn't enough for a true circle on a Bootstrap button,
   the pill-shaped --bs-btn-border-radius from theme.css's .btn rule and
   the button's own padding both fight a perfect circle unless width/height are
   pinned and padding zeroed here too. */

/* The grid cells a line-item row puts its remove button (.cp-line-remove) and its
   price (.cp-line-price-cell, see pages/work-order-cards.css) in. Each takes a small
   control's height and centres what it holds, so it lines up with the inputs beside
   it whether the row aligns its items to the start (line item rows) or the end
   (print rows, whose controls carry labels above them).

   Aligning the button or the price itself cannot do this: it would pin to one edge
   or the other, leaving a 1.25rem circle sitting 5px off centre against a 31px
   control. Centring the cell against the whole row instead puts it level with a
   print's labels and fields together, below the one and above the other.

   font-size and the height formula are Bootstrap's own for .form-control-sm,
   reproduced for the same reason .cp-token-select above reproduces them: the
   1.5em term is only the right number when the em matches. */
.cp-line-remove-cell,
.cp-line-price-cell {
  align-items: center;
  display: flex;
  font-size: .875rem;
  min-height: calc(1.5em + .5rem + calc(var(--bs-border-width) * 2));
}

.cp-line-remove {
  align-items: center;
  border-radius: 50% !important;
  display: inline-flex;
  flex: 0 0 auto;
  height: 1.25rem;
  justify-content: center;
  line-height: 1;
  min-width: 1.25rem;
  padding: 0;
  width: 1.25rem;
}

/* Horizontal form row (Figma "form-item/horizontal"): the label sits beside its control in a
   fixed column rather than above it, so a stack of them reads as one aligned form. Ported from
   the design prototype's .cp-hrow / .cp-hlabel / .cp-subrow rules; first used by the work order
   form's Materials & Services card, but page-agnostic.

   The label column is a hard 88px in both directions. Letting it shrink would misalign the
   controls, which is the only thing this layout exists to do.

   TODO: rename this family once the design prototype stops being the UI source of truth. The h
   is for horizontal, meaning the label sits beside its control rather than above it, which is
   ordinary forms vocabulary (Bootstrap 3 shipped .form-horizontal for the same thing) but reads
   as "horizontal row" and so as redundant, since every row is horizontal. Keeping the
   prototype's names is worth that while cards are still being ported from it and our markup can
   be diffed against theirs. After that, something like .cp-inline-label-row / .cp-inline-label
   carries the meaning without the convention. */
.cp-hrow {
  display: flex;
  align-items: center;
  gap: .5rem;

  /* min-width:0 so a long <option> label can't force the select past its share of the row.
     Flex refuses to shrink an item below its content width without it. */
  & > .form-select,
  & > .form-control {
    flex: 1 1 auto;
    min-width: 0;
  }
}

.cp-hlabel {
  flex: 0 0 88px;
  width: 88px;
  margin-bottom: 0;
}

/* Sub-item rows (Board Color under Mounting, Fitting's spacer fields) indent under their
   parent's control column: the 88px label plus .cp-hrow's own .5rem gap. */
.cp-subrow {
  margin-left: 6rem;
}

/* Vendor Keywords badge (Figma Vendor Detail shows each keyword as a badge) —
   quiet enough to sit in a dense list row, using theme border/body tokens so
   it holds up in dark mode too. Pair with Bootstrap's own `.badge`. */
.cp-kw-badge {
  font-weight: 500;
  color: var(--bs-body-color);
  background: var(--bs-tertiary-bg);
  border: var(--bs-border-width) solid var(--bs-border-color);
}

/* The narrow stepper variant for an inchesField sharing a line-item row (the mat layer's Size).
   Two buttons abreast overflow that row and wrap it onto three lines, so + goes over - in one
   column, the way the prototype's fracCtl does with its `stacked` argument. Half-height buttons,
   so the pair still measures the same as the input beside them. */
.cp-inches-stack {
  display: flex;
  flex-direction: column;

  /* The pair splits the height of the input beside it rather than each button
     claiming a full control's worth, which would make this cell half again as
     tall as every other cell in the row and stretch the whole row with it. */
  & .btn {
    --bs-btn-padding-y: 0;
    --bs-btn-padding-x: 0.25rem;
    --bs-btn-font-size: 0.7rem;

    flex: 1 1 0;
    min-height: 0;
    line-height: 1;

    /* Square, like the side-by-side pair. theme.css gives .btn a pill-shaped
       --bs-btn-border-radius, and Bootstrap rounds the first and last child of
       a .btn-group-vertical, so without this the two buttons come out as a
       lozenge sitting inside a square-cornered input group. */
    border-radius: 0;
  }
}

/* Segmented toggle (reactive-components/segmented-toggle.js): a row of
   mutually-exclusive buttons where the active one gets the --bs-primary
   accent instead of Bootstrap's default outline-secondary gray. First used
   by the work order form's Measurements card (Uniform/Split, Fit-to), but
   page-agnostic — any `.btn-group` wrapping segmentedToggle's buttons picks
   this up. The --cp-seg-track/--cp-seg-track-hover tokens it references live
   in theme.css alongside this app's other hand-authored --cp-* tokens.

   No border: even a border-color held constant across rest/hover still
   visibly shifted, since :hover also raises this button's z-index above its
   neighbor (Bootstrap's own .btn-group > .btn:hover rule), changing which
   button's overlapping edge wins. Background alone can't produce that
   artifact.

   No overlap margin either. Bootstrap's .btn-group negative-margins each
   button left to collapse borders, but with no border here there's nothing
   to collapse - the leftover overlap just let a hovered button (raised
   above its neighbor by that same z-index bump) bleed its background a
   couple pixels into the next segment. Selector shape mirrors Bootstrap's
   own .btn-group rule to win the specificity tie via source order (this
   file loads after bootstrap.min.css, see head.js). */
.cp-seg-toggle .btn {
  background: var(--cp-seg-track);
  border: 0;
  color: var(--bs-body-color);
}

.cp-seg-toggle .btn:hover {
  background: var(--cp-seg-track-hover);
  color: var(--bs-body-color);
}

/* Bootstrap's own focus ring silently fails to render here: it deep-refers
   to --bs-btn-focus-shadow-rgb, which only variant classes (.btn-primary,
   .btn-outline-*, etc) define, and these are plain .btn with no variant.
   Reuses the site's standard orange focus ring (see theme.css's
   .form-control:focus block). :focus-visible, not :focus, to match
   Bootstrap's own buttons (no ring on mouse click, only keyboard nav) -
   z-index comes from Bootstrap's .btn-group > .btn:focus rule already. */
.cp-seg-toggle .btn:focus-visible {
  box-shadow: 0 0 0 .25rem rgb(199 82 45 / 30%);
}

.cp-seg-toggle .btn.active {
  background: var(--bs-primary);
  color: var(--cp-on-dark);
}

.cp-seg-toggle > :not(.btn-check:first-child) + .btn {
  margin-left: 0;
}

/* Token select (reactive-components/lib/searchable-select.js): the customer
   and line-item product pickers. A div dressed as a form field, holding the
   selected record as a removable token plus a borderless input for typing.
   The point is that a bound record must not look like typed text, which is
   all the old plain input could convey.

   Not built from .form-control: that class hard-sets a fixed `height` on its
   -sm variant, which a token cannot fit inside. The handful of declarations
   below reproduce what .form-control-sm would have given us, at auto height.

   Square corners match this app's --bs-border-radius-sm of 0. */
.cp-token-select {
  display: flex;
  align-items: center;
  gap: .25rem;

  /* Same reason .cp-token-input below carries it. A flex item's min-width
     defaults to auto, which floors it at its content's width, and the content
     here is a long placeholder ("Search mat code or board name…") or a token.
     In a line-item row that floor is wider than the share of the row this
     control gets, and since .row wraps, the cells after it drop onto a second
     line rather than the control getting narrower. */
  min-width: 0;

  /* Bootstrap's own .form-control-sm height formula, reproduced so this box
     lines up with the plain inputs beside it in a line-item row. */
  min-height: calc(1.5em + .5rem + calc(var(--bs-border-width) * 2));

  /* Half of .form-control's horizontal padding, not the full .5rem it would
     otherwise borrow. The token inside carries its own padding, so the two
     stack up and read as a wide gap between the pill and the frame around it,
     which is space a line-item row cannot spare. */
  padding: .25rem;
  font-size: .875rem;
  background: var(--bs-body-bg);
  border: var(--bs-border-width) solid var(--bs-border-color);
  cursor: text;
}

/* :focus-within, not :focus. The box is a div, so it never takes focus
   itself; the ring has to follow the input nested inside it. Values match
   theme.css's .form-control:focus so this reads as the same control. */
.cp-token-select:focus-within {
  border-color: #e3a996;
  box-shadow: 0 0 0 .25rem rgb(199 82 45 / 30%);
}

.cp-token-select.is-invalid {
  border-color: var(--bs-form-invalid-border-color);
}

/* The input is never removed from the DOM, only collapsed to a sliver once a
   token is present. It has to stay focusable for Backspace-to-clear and for
   click-to-retype; display:none or visibility:hidden would take that away.
   Width 1px rather than 0 because a zero-width input is not reliably
   focusable across browsers. */
.cp-token-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  background: transparent;
  border: 0;
  outline: 0;
}

.cp-token-select.is-filled .cp-token-input {
  flex: 0 0 1px;
  width: 1px;
}

/* The chosen record as plain text in the field, the way the prototype shows a
   picked mat or frame ("MAT-4PLY-WHT — Smooth White 4-Ply" sitting in an
   ordinary input). This used to be a chip (tertiary fill, hairline border,
   rounded) so a bound record would not read as typed text; the design review
   asked for the prototype's look instead. The element and its class stay, so
   the picker's behaviour and every selector the e2e specs use are unchanged.

   line-height is tight on purpose. The text has to fit inside the line box an
   empty control already reserves, or picking a record would make the control
   taller than its empty neighbours and knock every line-item row out of
   alignment. The horizontal padding lines the text up with where the empty
   field's placeholder starts. */
.cp-token {
  display: inline-flex;
  align-items: center;
  gap: .25rem;

  /* min-width lets the token shrink below its content once the input
     re-expands beside it during a search; without it flex refuses to
     shrink a flex item past its content and the label never truncates. */
  min-width: 0;
  max-width: 100%;
  padding: 0 .25rem;
  font-weight: 400;
  line-height: 1.25;
}

/* Truncate rather than wrap: a product label runs long ("M-1234 - Gold leaf
   2in ornate carved"), and wrapping would make each line-item row a
   different height. The full text rides along in a title attribute. */
.cp-token-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Deliberately quieter than the row-delete button next to it in a line-item
   row (.btn-outline-danger): this clears a field, that removes a whole row,
   and confusing the two is expensive. Shrunk from .btn-close's default 1em
   box, and its focus ring retuned because Bootstrap hardcodes that one to
   blue via --bs-btn-close-focus-shadow and theme.css never retunes it. */
.cp-token-remove {
  --bs-btn-close-focus-shadow: 0 0 0 .25rem rgb(199 82 45 / 30%);

  flex: 0 0 auto;
  width: .375em;
  height: .375em;
  padding: .1875em;

  /* Hidden until the field is hovered or focused, since the prototype's picked
     mat and frame fields show no clear control at all. Kept rather than
     removed: without it, clearing a field takes Backspace in an empty input,
     which nobody would guess. opacity rather than display so it stays in the
     tab order and keeps its place in the row's layout. */
  opacity: 0;
}

.cp-token-select:is(:hover, :focus-within) .cp-token-remove {
  opacity: 1;
}

/* The dropdown hangs directly off the bottom edge of the control, so a top
   radius would round it away from that edge and read as a detached card.
   Square on top, barely rounded at the bottom: the theme's 12px
   --bs-border-radius is far too round at this size. Bootstrap's
   .list-group-item corners inherit from the list, so setting it here is
   enough. */
.cp-token-dropdown {
  z-index: 1000;
  overflow-y: auto;

  /* Roughly eight rows at .cp-token-dropdown .list-group-item's px-2 py-1
     density, past which the list is long enough to want scrolling rather
     than to keep growing down the page. */
  max-height: 240px;
  border-radius: 0 0 .25rem .25rem;

  /* Same two-layer recipe as theme.css's .card (a tight contact shadow plus
     a wider ambient one), pushed a little deeper: this floats over page
     content rather than sitting on the canvas, so it has to read as clearly
     detached. Bootstrap's .shadow-sm was too faint to separate the list from
     the card behind it, and is !important, so it's dropped at the call site
     rather than overridden here. */
  box-shadow: 0 2px 4px rgb(0 0 0 / 8%), 0 8px 20px rgb(0 0 0 / 14%);

  /* Bootstrap gives .list-group-item-action a hover background but leaves the
     cursor as text, which reads as unclickable on a picker row. */
  & .list-group-item {
    cursor: pointer;
  }
}

/* Order Status timeline: dots on a connecting line, one per mainline stop.
   Ported from the design prototype's .cp-ostep rules, with the abbreviations
   spelled out. Only estimate / in_process / complete are stops; On Hold and
   Cancelled are off-line states that paint the track instead (see
   reactive-components/work-orders/status-cards.js). */
.cp-status-track {
  display: flex;
  justify-content: space-between;

  & .cp-status-stop {
    position: relative;
    flex: 1 1 0;
    text-align: center;
  }

  /* The connecting line. Drawn per stop rather than as one element behind
     them, so each segment can be colored by the state of the stop it leads
     into. Spans from the previous dot's center to this one's; top offsets it
     to the dot's vertical middle.

     z-index puts it behind the dots. Without it the line wins regardless of
     source order: it is positioned and the dot is not, and positioned
     elements paint in a later stage than a static sibling's content. That
     was invisible while both were the same gray, and obvious the moment a
     reached dot turned orange against a gray line. */
  & .cp-status-stop:not(:first-child)::before {
    position: absolute;
    z-index: 0;
    top: 6px;
    right: 50%;
    left: -50%;
    height: 2px;
    background: var(--bs-border-color);
    content: "";
  }

  & .cp-status-stop-dot {
    /* position + z-index, so the dot sits above the line above. */
    position: relative;
    z-index: 1;
    display: block;

    /* Centered in the flex column that the label sits below. */
    width: 14px;
    height: 14px;
    margin: 0 auto;
    border: 2px solid var(--bs-border-color);
    border-radius: 50%;
    background: var(--bs-border-color);
  }

  & .cp-status-stop-label {
    display: block;
    margin-top: .35rem;
    color: var(--bs-secondary-color);
    font-size: .6875rem;
    line-height: 1.1;
  }

  & .is-done .cp-status-stop-dot,
  & .is-current .cp-status-stop-dot {
    border-color: var(--bs-primary);
    background: var(--bs-primary);
  }

  & .is-done::before,
  & .is-current::before {
    background: var(--bs-primary);
  }

  & .is-current .cp-status-stop-label {
    color: var(--bs-primary);
    font-weight: 600;
  }
}

/* Held: the order stopped where it is, so the reached track turns amber
   rather than reading as still progressing. */
.cp-status-track.is-held {
  & .is-done .cp-status-stop-dot,
  & .is-current .cp-status-stop-dot,
  & .is-done::before,
  & .is-current::before {
    border-color: var(--bs-warning);
    background: var(--bs-warning);
  }

  & .is-current .cp-status-stop-label {
    color: var(--bs-warning-text-emphasis);
  }
}

/* Cancelled has no position on the line (it can be cancelled from either
   Estimate or In Process and we don't record which), so the whole track dims
   and no stop is marked current. A deleted order is shown the same way. */
.cp-status-track.is-cancelled,
.cp-status-track.is-deleted {
  opacity: .5;
}

/* Marks a control the app hasn't really built yet: the user types a value the
   finished system will compute for them. Currently the work order form's price
   inputs, which are a manual stub until Price Codes pricing exists (see
   LineItem.price in the model). `grep -rn cp-provisional-field` is the
   inventory of what's still fake on screen, alongside `grep -rn "TODO:"`.

   Bright blue precisely because nothing else in the theme is: primary and links
   are terracotta, focus rings orange, invalid red, --bs-info a pale cyan. An
   off-palette color can't be read as a brand state the user is meant to decode,
   so it registers as scaffolding. Delete the rule and its call sites together
   when the real pricing lands.

   One class, so Bootstrap's own `.form-control.is-invalid` still wins the
   border color: a validation error stays red, and only the 2px width carries
   over. Never the only signal that a field is provisional, since color alone
   says nothing to a screen reader; the marked controls carry a `title` too.

   TODO: this rule is meant to be deleted, not inherited. The last call site to
   lose its marking takes the class with it: delete this block, the
   PROVISIONAL_PRICE_TITLE it pairs with (reactive-components/work-order/form/
   lib/provisional-price.js) and the "marks every price input as provisional"
   guard in test/routes/work-order-form-rendering.test.js in the same change.
   A styled-but-unused class is how a temporary marker becomes permanent. */
.cp-provisional-field {
  border: 2px solid #0d6efd;
}

/* The cone flagging something whose contents are not finished, so a client walkthrough does not
   read it as done. See components/under-construction-icon.js.

   Brand orange, which is cone-coloured, and the one hue that holds up in both places this is
   used. It started as --bs-warning, chosen against a black card header where a pale amber pops;
   on the dashboard's light page that same amber is barely there. Not --bs-danger, which carries
   enough contrast but reads as something broken rather than something unbuilt. The trade is at
   the black end: orange on black is ~3.3:1 against amber's ~15:1, which still clears the 3:1
   WCAG asks of a graphical object, and the cone supplements the hover text rather than being
   the only carrier of the message.

   TODO: demo scaffolding, delete on the way out. `grep -rn underConstructionIcon` is the list of
   things currently flagged: the dashboard's unwired figures and the work order form's Print WO
   button (no template to print yet); when the last one is finished, this rule and the component
   go together. Unlike .cp-provisional-field above, which marks a field the app will eventually
   compute, this marks something nobody has built yet, so it should have the shortest life of
   the two.

   Two classes rather than one, because theme.css's `.card-header .bi` paints every icon in a
   header with the light ink and would otherwise win at 0,2,0. This ties it and takes the tie on
   source order, widgets.css being loaded after theme.css. Written as .bi rather than
   .card-header so the colour holds wherever the cone is used. */
.bi.cp-under-construction {
  color: var(--bs-primary);
}

/* A dialog that holds one height whatever its body is showing, rather than sizing to it.
   For a modal whose contents change length while the user works: the Find Code search
   regrew the dialog on every keystroke, which moved the filters out from under the cursor
   typing into them. Pair with Bootstrap's .modal-dialog-scrollable, which already makes the
   dialog full height and gives .modal-content the max-height this turns into a height, and
   which is what puts the overflow on the body so a long list scrolls inside. */
.cp-modal-fill-height .modal-content {
  height: 100%;
}

/* Bootstrap's own dialog widths step 300 / 500 / 800px (.modal-sm / default /
   .modal-lg). Clear/Restart WO needed something between the first two, so
   this is ours: 1.5x .modal-sm. */
.cp-modal-md {
  --bs-modal-width: 450px;
}

/* A button whose only job is opening a Bootstrap dropdown menu (data-bs-toggle="dropdown"),
   as opposed to one that acts directly: it reads as one more control in a row of selects and
   filters rather than as something that does a thing on click and does it harder on hover, so
   it skips the outline variant's hover/active colour inversion and gets the same lighter
   border every .form-select and .form-control already carry. Layer onto whichever .btn-*
   variant the toggle already uses; this only touches the custom properties Bootstrap's own
   .btn/.dropdown-toggle rules key off of. */
.cp-dropdown-toggle {
  --bs-btn-border-color: var(--bs-border-color);
  --bs-btn-hover-bg: var(--bs-btn-bg);
  --bs-btn-hover-border-color: var(--bs-border-color);
  --bs-btn-hover-color: var(--bs-btn-color);
  --bs-btn-active-bg: var(--bs-btn-bg);
  --bs-btn-active-border-color: var(--bs-border-color);
  --bs-btn-active-color: var(--bs-btn-color);
}
