/* The quote screens (layouts/field). These used to be two <style> blocks in
   the page, which the Content-Security-Policy refuses (walkthrough, 7 Oct:
   Scope & price set off style-src reports), so they live here.

   What anything sticky inside the field layout has to clear: the field bar is
   pinned at the top (64px and its 2px rule, the desk's own height) plus
   whatever the notch takes. :where() carries no specificity, so the View as
   strip's own :root value (shared/_view_as_banner) still wins under it. */
:where(html.kf-field-layout) {
  --kf-sticky-top: calc(4rem + 2px + env(safe-area-inset-top));
}

/* "Add a line" (documents/_catalog_picker), pinned under whatever bar sits
   above it: the desk's or the quote screens'. Was a style="" attribute, which
   the Content-Security-Policy refuses (walkthrough, 7 Oct). */
[data-kf-sticky-picker] {
  top: var(--kf-sticky-top, 0px);
}

/* The hidden companion inputs must never occupy a pane. Name the two panes
   as well, so bookkeeping added later cannot push a quote into the sidebar. */
@media (min-width: 48rem) {
  .kf-quote-builder {
    grid-template-areas: "picker lines";
  }

  .kf-quote-builder > [data-quote-builder-pane="picker"] {
    grid-area: picker;
  }

  .kf-quote-builder > [data-quote-builder-pane="lines"] {
    grid-area: lines;
  }
}

/* THE QUOTE FIRST ON A PHONE (sweep 2, T8): on the Scope & price step the lines
   the customer signs come before "+ Add a line" (a fold, documents/_line_items_fields
   picker_below). The picker stays first in the page's source so an iPad's grid
   areas above are unchanged; only the phone's one column is reordered. */
@media (max-width: 47.99rem) {
  .kf-quote-builder[data-picker-below] {
    display: flex;
    flex-direction: column;
  }

  .kf-quote-builder[data-picker-below] > [data-quote-builder-pane="lines"] {
    order: 1;
    margin-top: 0;
  }

  .kf-quote-builder[data-picker-below] > [data-quote-builder-pane="picker"] {
    order: 2;
    margin-top: 1rem;
  }
}

/* A wide viewport does not guarantee a wide quote: the picker, page padding
   and other composer layouts all take space. Keep the name above labeled
   figures until this card itself has room for a readable table. Browsers
   without container queries keep that usable stacked layout. */
.kf-quote-lines {
  container: quote-lines / inline-size;
}

.kf-quote-line-headings {
  display: none;
}

.kf-quote-line-figures > label {
  min-width: 0;
}

@container quote-lines (min-width: 28rem) {
  .kf-quote-line-figures {
    grid-template-columns: 4.5rem 5.5rem 6.5rem minmax(0, 1fr);
  }

  .kf-quote-line-amount {
    grid-column: auto;
    display: block;
    text-align: right;
  }

  .kf-quote-line-amount .kf-quote-figure-label {
    display: block;
    margin-bottom: .25rem;
  }

  .kf-quote-line-amount [data-role="amount"] {
    display: inline-block;
    min-height: 2.75rem;
    padding-top: .625rem;
  }
}

@container quote-lines (min-width: 44rem) {
  .kf-quote-line-headings {
    display: flex;
    gap: .75rem;
  }

  .kf-quote-lines .quote-line {
    flex-wrap: nowrap;
  }

  .kf-quote-line-item {
    flex: 1 1 0%;
  }

  /* A line of the rep's own (and a note) is words before it is figures: its box
     spans the whole line instead of the strip the figures leave beside them, so
     a long description is not cut off while it is typed. The figures and the
     menu sit under it. */
  .kf-quote-lines .quote-line[data-kind="custom"],
  .kf-quote-lines .quote-line[data-kind="note"] {
    flex-wrap: wrap;
  }

  .kf-quote-lines .quote-line[data-kind="custom"] .kf-quote-line-item,
  .kf-quote-lines .quote-line[data-kind="note"] .kf-quote-line-item {
    flex: 1 1 100%;
  }

  /* The figures keep their columns under the headings, at the right. */
  .kf-quote-lines .quote-line[data-kind="custom"] .kf-quote-line-figures {
    margin-left: auto;
  }

  .kf-quote-line-figures {
    order: 2;
    flex-basis: auto;
    grid-template-columns: 5rem 6rem 7rem 7rem;
  }

  .kf-quote-lines .kf-line-menu {
    order: 3;
  }

  .kf-quote-figure-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  .kf-quote-line-amount {
    padding-top: .625rem;
  }

  .kf-quote-line-amount [data-role="amount"] {
    min-height: 0;
    padding-top: 0;
  }
}

/* ===========================================================================
   SCOPE & PRICE, TWO COLUMNS (the 3 Nov pick, quote step 3 "B"). The lines at
   the left; at the right ONE short card that stays in view while the page
   scrolls (the total, the discount, the margin line, Back and Save & review)
   with Price check, Payments and Notes under it. From 1180px wide that is two
   columns; from an upright iPad it is one column (the totals under the lines,
   the pinned bar below); on a phone each line folds to one row.
   documents/_line_items_fields (two_column: true), field/_step_scope.
   =========================================================================== */
.kf-b {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.kf-b-main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

/* Narrow: the rail steps out of the way, so the totals card and the cards follow the lines in order. */
.kf-b-rail {
  display: contents;
}

.kf-wide-only {
  display: none;
}

.kf-b-lines {
  display: flex;
  flex-direction: column;
}

/* The order inside the lines card: the title, then the search bar and chips from an iPad up; on a phone the
   lines first and "+ Add a line" under the last one. */
.kf-b-order-title { order: 1; }
.kf-b-order-headings { order: 3; }
.kf-b-order-rows { order: 4; }
.kf-b-order-picker { order: 5; }
.kf-b-order-notes { order: 6; }

@media (min-width: 48rem) {
  .kf-b-order-picker { order: 2; }
}

@media (min-width: 73.75rem) {
  .kf-b {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 21rem;
    column-gap: 1.5rem;
    align-items: stretch;
  }

  .kf-b > .kf-b-main { grid-column: 1; }

  .kf-b > .kf-b-rail {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
  }

  .kf-wide-only { display: flex; }

  /* The pinned card is about 350px tall, so it fits a laptop screen with Save & review in view; the cards under
     it scroll up beneath it. The wrapper paints the page's own colour so they do not show through. */
  .kf-b-pin-wrap {
    position: sticky;
    top: calc(var(--kf-sticky-top, 4rem) - 0.5rem);
    z-index: 5;
    margin: -1.5rem 0;
    padding: 1.5rem 0;
    background: var(--color-page);
  }

  .kf-b-pin { box-shadow: var(--shadow-lift); }

  /* Back and Save & review live in the pinned card here, so the bottom bar steps aside, and the page does not
     keep the room it reserved for it. */
  .kf-bar-not-wide { display: none; }
  main:has(.kf-b) { padding-bottom: 3rem; }
}

.kf-b-pin-head {
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem 0;
}

.kf-b-pin-actions {
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-line);
}

/* THE MARGIN, ONE LINE: yellow while a cost is missing, a quiet one once it is worked out; a tap opens the Costs
   sheet (gross_margins/_quote, costs-sheet). */
.kf-margin-line {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  border: 0;
  border-top: 1px solid var(--color-line);
  background: transparent;
  color: var(--color-ink);
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.375rem;
  text-align: left;
}

button.kf-margin-line {
  min-height: var(--spacing-tap);
  cursor: pointer;
}

.kf-margin-line-warn {
  border-top-color: #ecd9a0;
  border-bottom: 1px solid #ecd9a0;
  background: var(--color-warn-soft);
  color: var(--color-warn);
}

.kf-margin-line-bad { color: var(--color-bad-ink); }
.kf-margin-icon { flex: none; margin-top: 0.125rem; }
.kf-margin-words { min-width: 0; }
.kf-margin-go { color: var(--color-accent-strong); font-weight: 600; }

/* THE DRAWING CHECK, ONE LINE (takeoffs/_scope_box): a pill, the drawing's own numbers, and Details. */
.kf-strip-summary {
  padding: 0.75rem 1rem;
  list-style: none;
  cursor: pointer;
}

.kf-strip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  min-height: 2rem;
}

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

@media (min-width: 40rem) {
  .kf-strip-summary { padding-left: 1.25rem; padding-right: 1.25rem; }
}

.kf-strip-warn > .kf-strip-summary {
  border-radius: var(--radius-ui) var(--radius-ui) 0 0;
  background: var(--color-warn-soft);
}

.kf-strip:not([open]) > .kf-strip-summary { border-radius: var(--radius-ui); }

.kf-strip-figures {
  display: flex;
  flex: 1 1 12rem;
  flex-wrap: wrap;
  gap: 0.125rem 0.5rem;
  min-width: 0;
  font-size: 0.9375rem;
  color: var(--color-muted);
}

.kf-strip-figures b { font-weight: 600; color: var(--color-ink); }
.kf-strip-dot { color: var(--color-line-strong); }

.kf-strip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
  min-height: var(--spacing-tap);
  font-weight: 600;
  color: var(--color-accent-strong);
}

.kf-when-open { display: none; }
.kf-strip[open] .kf-when-open { display: inline; }
.kf-strip[open] .kf-when-closed { display: none; }
.kf-strip[open] .kf-strip-chevron { transform: rotate(180deg); }

.kf-strip-body {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--color-line);
}

@media (min-width: 40rem) {
  .kf-strip-body { padding-left: 1.25rem; padding-right: 1.25rem; }
}

.kf-strip-note { padding: 0 1rem 0.75rem; }
.kf-strip-confirm { padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--color-line); }

@media (min-width: 40rem) {
  .kf-strip-note { padding-left: 1.25rem; padding-right: 1.25rem; }
  .kf-strip-confirm { padding-left: 1.25rem; padding-right: 1.25rem; }
}

.kf-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.375rem;
  white-space: nowrap;
}

.kf-pill svg { width: 0.875rem; height: 0.875rem; flex: none; }
.kf-pill-good { background: var(--color-good-soft); color: var(--color-good-ink); }
.kf-pill-warn { background: #f59e0b; color: var(--color-ink); }

/* PAYMENTS AND NOTES ON A PHONE fold to one row each (what they say, and a chevron); from an iPad up they are the
   cards they were, and the row is just the card's title. */
.kf-fold-summary {
  padding: 0.5rem 1rem;
  list-style: none;
  cursor: pointer;
}

.kf-fold-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.5rem;
}

.kf-fold-summary::-webkit-details-marker { display: none; }
.kf-fold-name { flex: 1 1 auto; min-width: 0; }
.kf-fold-value { min-width: 0; font-size: 0.9375rem; color: var(--color-muted); text-align: right; }
.kf-fold-chevron { flex: none; }
.kf-fold[open] > .kf-fold-summary .kf-fold-chevron { transform: rotate(90deg); }
.kf-fold-body { padding: 0 1rem 1rem; }

@media (min-width: 48rem) {
  .kf-fold-summary { padding: 1rem 1.25rem 0; pointer-events: none; cursor: default; }
  .kf-fold-row { min-height: 0; }
  .kf-fold-value, .kf-fold-chevron { display: none; }
  .kf-fold-body { padding: 0.75rem 1.25rem 1.25rem; }
}

.kf-pay-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.875rem 0 0;
  padding: 0;
  list-style: none;
}

.kf-pay-rows[hidden] { display: none; }

.kf-pay-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9375rem;
  color: var(--color-ink);
}

.kf-pay-n {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
  font-size: 0.75rem;
  font-weight: 600;
}

/* A CATALOG LINE ON A PHONE: one row (name, quantity x price, amount and a chevron) that opens to edit. */
.kf-line-fold { display: none; }

@media (max-width: 47.99rem) {
  .quote-line[data-fold] .kf-quote-line-item { flex: 1 1 0%; }

  .quote-line[data-fold] .kf-line-fold {
    order: 2;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: var(--spacing-tap);
    padding: 0 0.25rem;
    border: 0;
    background: none;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }

  .quote-line[data-fold]:not([data-open]) .kf-quote-line-figures,
  .quote-line[data-fold]:not([data-open]) .kf-line-menu,
  .quote-line[data-fold]:not([data-open]) [data-line-note] {
    display: none;
  }

  .quote-line[data-fold][data-open] .kf-fold-chevron { transform: rotate(180deg); }
  .quote-line[data-fold] .kf-line-menu { order: 4; margin-left: auto; }
  .quote-line[data-fold] .kf-menu-note { display: none; }
}

@media (min-width: 48rem) {
  .kf-line-summary { display: none; }

  /* "Add a note" is in the line's ... menu; the line's own note shows only once it has one. */
  .kf-b .quote-line:not([data-has-note]) [data-line-note] > summary { display: none; }
}
