/* ---------------------------------------------------------------------------
   The deal card
   ---------------------------------------------------------------------------
   A deal on the company drawer's Deals tab, read in a glance
   (design/deal-card.md, built in app/deals.js "The deal card"): the band
   across the top, the heading (name and description; value with the stage
   under it), the working fortnight, Details, and Candid's move as the
   board's card foot. The card is a .dealitem container (pipeline.css); its
   sizes come from the drawer type scale (drawer-type-scale.css), so these
   rules lay things out and colour them.
   --------------------------------------------------------------------------- */

/* The band: full width over the card's top edge, its corners the card's. */
.dealband {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  margin: calc(-1 * var(--pad-box)) calc(-1 * var(--pad-box)) 0;
  min-height: 48px; box-sizing: border-box; padding: 12px var(--pad-box); border-radius: var(--r-box) var(--r-box) 0 0;
  --tone: var(--muted);
  background: color-mix(in srgb, var(--tone) 12%, var(--card));
  color: color-mix(in srgb, var(--tone) 72%, var(--ink));
}
.dealband.is-warn { --tone: #B7791F }
.dealband.is-bad { --tone: var(--bad) }
.dealband.is-plan { --tone: var(--teal) }
/* Teal is light, so its words take more ink to stay over 4.5:1. */
.dealband.is-plan { color: color-mix(in srgb, var(--teal) 50%, var(--ink)) }
.dealband.is-won { --tone: var(--good) }
.dealband.is-lost, .dealband.is-none { background: var(--page); color: var(--muted) }
.dealband > .ms { font-size: 20px; color: inherit; flex: 0 0 auto }
.dealband__face { width: 24px; height: 24px; flex: 0 0 24px; font-size: 10px }
.drawer__body .dealband .dealband__lead { color: inherit; flex: 0 0 auto }
.drawer__body .dealband__tail {
  margin-left: auto; min-width: 0; color: inherit; text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dealband__late { color: var(--bad) }
/* On a narrow card the band's detail takes its own line, up to two, so
   the step that is waiting is read whole rather than cut off. */
@container (max-width: 440px) {
  .dealband { flex-wrap: wrap; row-gap: 2px }
  .drawer__body .dealband__tail {
    flex: 1 0 100%; margin-left: 34px; text-align: left; white-space: normal;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-wrap: pretty;
  }
}

/* The heading: what it is on the left, its worth and stage on the right. */
.dealhead { display: flex; align-items: flex-start; gap: 16px; min-width: 0 }
.dealhead__what { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px }
.dealhead__worth { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; position: relative }
/* On a narrow card the name keeps at least half the row; a long stage
   (Lost · and its reason) is cut short rather than squeezing it. */
@container (max-width: 440px) {
  .dealhead__what { flex-basis: 50% }
  .dealhead__worth { max-width: 50% }
  .dealhead__worth :is(.stagepick, .stagepick__anchor, .stagepick__btn) { max-width: 100%; flex-shrink: 1; min-width: 0 }
  .dealhead__worth .stagepick__btn > span { overflow: hidden; text-overflow: ellipsis }
}
/* Writing in place in the heading: nothing round it moves. The value and
   stage keep their side, and each field takes the type of the words it
   replaces and sits so they stay where they were. The box here is compact
   (1px padding, a field the height of its line, a smaller tick and cross)
   so its edge hugs the words rather than crossing the line under them: 10px
   to the left is its edge, padding and the field's own (1 + 1 + 8), and what
   height it adds is hung above and below it, so the parts round it hold still. */
.dealhead .infield { --in-pad: 2px; --in-h: 26px; width: 100% }
/* The phone's 44px field minimum is the box's here, not the line's. */
.dealhead .infield .input { min-height: 0 }
.dealhead .dealfix--name > .infield { margin-top: -3px; margin-bottom: -7px }
.dealhead .dealfix--name .infield .input { font-size: var(--dr-section, 17px); font-weight: 600; letter-spacing: -.015em }
.dealhead .dealnote > .infield { flex: 0 0 auto; margin-top: -4px; margin-bottom: -2px }
.dealhead .dealnote > .infield .input { font-size: var(--dr-body, 14px); line-height: 1.6 }
/* The value's field floats over the place the figure held (deals.js keeps
   that place its size), anchored to the right edge and opening leftwards
   over the name's spare room, so the stage under it never moves. */
.dealhead .dealfix--value { position: relative; flex-wrap: nowrap }
.dealhead .dealfix--value > .infield { --in-h: 28px; position: absolute; top: 0; right: 8px; z-index: 2; margin: 0; width: min(220px, 100cqw) }
.dealhead .dealfix--value .infield .input { font-size: 24px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums }
/* On a narrow card the left half is too thin to write in, so the name and
   description fields span the whole heading, raised over the value and stage
   on the low layer (as a floating composer is), and the value's field opens
   leftwards over the name rather than off the card. The height a touch field
   adds over the line is hung below it, so the parts under it still hold. */
@container (max-width: 440px) {
  .dealhead :is(.dealfix--name, .dealnote) > .infield { position: relative; z-index: 2 }
  .dealhead :is(.dealfix--name, .dealnote) > .infield { flex: 0 0 auto; width: 100cqw }
  .dealhead :is(.dealfix--name, .dealnote, .dealfix--value) > .infield:focus-within {
    box-shadow: inset 0 0 0 .5px var(--field-focus), var(--shadow-low);
  }
}
.dealhead__what .dealnote__go, .dealhead__what .dealnote__add { text-align: left }
/* The stage as text with its chevron, no box; a grey wash on hover. It
   hangs into the padding by its own inset so its words end on the edge. */
.dealhead__worth .stagepick__btn {
  height: 32px; padding: 0 4px 0 8px; margin-right: -4px; gap: 6px;
  border: 0; border-radius: var(--r-btn-sm); background: none; color: var(--text);
}
.dealhead__worth :is(.stagepick, .stagepick__anchor, .stagepick__btn) { flex: 0 0 auto; max-width: none }
.dealhead__worth .stagepick__btn > span { overflow: visible }
/* Candid's move is said in the card's foot, so not again beside the stage. */
.dealhead__worth .stagepick > :not(.stagepick__anchor) { display: none }
.dealhead__worth .stagepick__btn:hover:not(:disabled), .dealhead__worth .stagepick__btn[aria-expanded="true"] { background: var(--btn-wash) }
.dealhead__worth .stagepick__btn:disabled { padding-right: 8px }
.dealhead__worth .stagepick__chev.ms { color: var(--muted); opacity: 1 }
@media (pointer: coarse) { .dealhead__worth .stagepick__btn { height: 44px } }
.dealhead__worth .stagemenu { right: 0; left: auto }

/* The fortnight: a column per day, letter over square over what is on it. */
.dealdays {
  list-style: none; margin: 0; padding: 0; display: grid; grid-auto-flow: column;
  grid-auto-columns: minmax(40px, 1fr); gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.dealdays::-webkit-scrollbar { display: none }
.dealdays:focus-visible { outline: 2px solid var(--teal); outline-offset: 4px; border-radius: var(--r-btn-sm) }
/* Each day said whole to a screen reader, hidden from the eye. */
.dealdays__say { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0 }
.dealdays__day { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; text-align: center }
.drawer__body .dealdays__wd { line-height: 1 }
.dealdays__sq {
  position: relative; width: 100%; height: 32px; display: grid; place-items: center;
  border-radius: var(--r-btn-sm); background: var(--page); color: var(--muted);
  font-size: var(--dr-label); font-weight: 500; font-variant-numeric: tabular-nums;
}
.dealdays__more { position: absolute; top: 3px; right: 4px; font-size: 10px; line-height: 1; font-weight: 600 }
.drawer__body .dealdays__ev { display: flex; flex-direction: column; align-items: center; gap: 2px; white-space: nowrap; line-height: 1.2 }
.dealdays__ev .ms { font-size: 16px; color: inherit }
/* What each day holds, by colour: today ink, the close amber, Candid's
   plans teal, the renewal outlined, anything gone by red. */
.dealdays__day.is-close .dealdays__sq { background: color-mix(in srgb, #B7791F 16%, var(--card)); color: #7A4E00 }
.drawer__body .dealdays__day.is-close .dealdays__ev { color: #8A5A00 }
.dealdays__day:is(.is-next, .is-meet) .dealdays__sq { background: color-mix(in srgb, var(--teal) 16%, var(--card)); color: color-mix(in srgb, var(--teal) 45%, var(--ink)) }
.drawer__body .dealdays__day:is(.is-next, .is-meet) .dealdays__ev { color: color-mix(in srgb, var(--teal) 55%, var(--ink)) }
.dealdays__day.is-renew .dealdays__sq { background: none; box-shadow: inset 0 0 0 1.5px var(--text); color: var(--text) }
.drawer__body .dealdays__day.is-renew .dealdays__ev { color: var(--text) }
.dealdays__day.is-late .dealdays__sq { background: color-mix(in srgb, var(--bad) 14%, var(--card)); color: var(--bad) }
.drawer__body .dealdays__day.is-late .dealdays__ev { color: var(--bad) }
/* Today is the ink square; on a day with something on it, ringed in its colour. */
.dealdays__day.is-today .dealdays__sq { background: var(--ink); color: var(--on-ink, #fff); box-shadow: none }
.drawer__body .dealdays__day.is-today.is-today .dealdays__ev:not(:has(.ms)) { color: var(--text) }
.dealdays__day.is-today.is-close .dealdays__sq { outline: 2px solid #B7791F; outline-offset: 1px }
.dealdays__day.is-today:is(.is-next, .is-meet) .dealdays__sq { outline: 2px solid var(--teal); outline-offset: 1px }
/* A square before today or past the fortnight stands a little apart. */
.dealdays__day.is-before { margin-right: 6px }
.dealdays__day.is-after { margin-left: 6px }

/* Candid's move: the board's card foot (.dealcard__moved, pipeline.css),
   full width across the card's bottom edge, tinted in the stage it came
   from, with Undo. */
.dealmoved {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 2px 10px;
  margin: 0 calc(-1 * var(--pad-box)) calc(-1 * var(--pad-box));
  padding: 12px var(--pad-box); border-radius: 0 0 var(--r-box) var(--r-box);
  background: color-mix(in srgb, var(--from, var(--line)) 11%, var(--card));
  border-top: 1px solid color-mix(in srgb, var(--from, var(--ink)) 22%, transparent);
}
.dealmoved > .ms { font-size: 16px; color: color-mix(in srgb, var(--from, var(--muted)) 75%, var(--ink)) }
.drawer__body .dealmoved__what { color: var(--muted); min-width: 0 }
.dealmoved__what b { font-weight: var(--weight-strong); color: color-mix(in srgb, var(--from, var(--ink)) 70%, var(--ink)) }
.drawer__body .dealmoved__why { grid-column: 2 / -1; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.dealmoved__undo {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 8px; margin-right: -8px;
  border: 0; border-radius: var(--r-btn-sm); background: none; color: var(--text); font: inherit; font-size: var(--dr-label); font-weight: 500; cursor: pointer;
}
.dealmoved__undo .ms { font-size: 17px }
.dealmoved__undo:hover { background: color-mix(in srgb, var(--from, var(--ink)) 14%, transparent); color: var(--coral) }
.dealmoved__undo:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px }
@media (pointer: coarse) { .dealmoved__undo { height: 44px } }

/* A Details part written in place (deals.js "held"): it keeps the size it
   had as a fact, and its field (or its list's button) floats over it, raised
   on the low layer, wide enough to write in and opening leftwards on the
   card's right half, so the grid round it never reflows. */
:is(.dealmeta, .dealterm) > .dealfix.is-held { position: relative; grid-column: auto; flex-wrap: nowrap }
:is(.dealmeta, .dealterm) > .dealfix.is-held > :is(.infield, .selbtn) {
  position: absolute; top: 50%; left: 8px; z-index: 2; transform: translateY(-50%);
  width: max(100%, 260px); max-width: none; margin: 0; box-shadow: var(--shadow-low);
}
/* A date needs only its own width and the tick and cross. */
:is(.dealmeta, .dealterm) > .dealfix.is-held > .infield:has(> .input[type="date"]:only-of-type) { width: max-content; min-width: 100% }
/* Its edge on the card's content edge: the part hangs 8px into the padding for its wash. */
:is(.dealmeta, .dealterm) > .dealfix.is-held-end > :is(.infield, .selbtn) { left: auto; right: 8px }
:is(.dealmeta, .dealterm) > .dealfix.is-held > .infield:focus-within { box-shadow: inset 0 0 0 .5px var(--field-focus), var(--shadow-low) }
:is(.dealmeta, .dealterm) > .dealfix.is-held > .infield__err { position: absolute; top: calc(50% + 26px); left: 8px; z-index: 2; width: max-content; padding: 2px 6px; border-radius: 6px; background: var(--card) }

/* The next step on a narrow card: its words take the whole first line of
   the box and the date and the tick and cross wrap under them; the row keeps
   its height (deals.js), so the box floats over what is under it, raised. */
@container (max-width: 440px) {
  .dealstep:has(.dealfix--next-step) { align-items: flex-start }
  .dealstep .dealfix--next-step > .infield { position: relative; z-index: 2; flex-wrap: wrap; row-gap: 0; box-shadow: var(--shadow-low) }
  .dealstep .dealfix--next-step > .infield:focus-within { box-shadow: inset 0 0 0 .5px var(--field-focus), var(--shadow-low) }
  .dealstep .dealfix--next-step > .infield > .input:first-child { flex: 1 1 100% }
  .dealstep .dealfix--next-step > .infield > .input[type="date"] { flex: 1 1 auto; border-left: 0 }
}
