/* The trace demo: a sample invoice drawn as a coupon (DESIGN.md, the Ticket
   Wallet). The hero shows it with the first line open; the demo section lets
   a visitor open each line and void it. */

/* The section itself, its heading and its intro come from .section,
   .section-heading and .prose in styles.css; here they take the how-it-works
   section's scale. */
#trace-demo {
  max-width: 1280px;
  padding: 72px var(--gutter) 96px;
}

#trace-demo .section-heading {
  margin-bottom: 20px;
  font: var(--section-title);
  letter-spacing: 0;
  text-transform: none;
}

.demo-intro {
  margin-bottom: var(--gutter);
}

.demo-note {
  margin: 0 0 var(--gutter);
  max-width: 60ch;
  color: var(--ink-2);
  font: var(--body-sm);
}

/* The hero's coupon sits in a grid cell, which must be allowed to shrink. */
.hero-coupon {
  min-width: 0;
}

.demo .button {
  margin-top: 0;
}

.demo-step {
  margin: 0 0 var(--gutter);
}

.demo-caption {
  margin: 0 0 var(--row);
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.demo-controls {
  margin-top: var(--gutter);
}

.demo-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The sheet: the invoice, with the credit note beside it once voided. */
.demo-sheet {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--gutter);
  max-width: 1100px;
  min-width: 0;
}

.invoice {
  position: relative;
  z-index: 1;
  flex: 1 1 520px;
  min-width: 0;
  padding-bottom: 6px;
  background: var(--coupon);
  outline: 1.5px solid var(--ink);
  outline-offset: -1.5px;
  box-shadow: var(--sheet-3);
}

.invoice::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -7px;
  left: 0;
  height: 7px;
  background: radial-gradient(circle at 7px 0, transparent 4px, var(--coupon) 4.5px) repeat-x 0 0 / 14px 7px;
}

/* Coupon leg: a 54px ink block with the client's initials, the title and
   sub-line, and a status cell at the right edge. */
.coupon-head {
  display: flex;
  align-items: stretch;
  border-bottom: 1.5px solid var(--ink);
}

.initials {
  display: grid;
  place-items: center;
  width: 64px;
  background: var(--ink);
  color: var(--dock);
  font: 700 24px / 1 "Barlow Condensed", sans-serif;
  letter-spacing: 0.04em;
}

.head-text {
  flex: 1;
  min-width: 0;
  padding: 11px var(--cell);
}

.client {
  margin: 0;
  font: 700 22px / 1.15 "Barlow Condensed", sans-serif;
  letter-spacing: 0;
}

.sub {
  margin: 2px 0 0;
  color: var(--ink-2);
  font: var(--body-sm);
}

.status {
  display: grid;
  place-items: center;
  padding: 0 var(--cell);
  border-left: 1px solid var(--hair);
  background: var(--copy);
  color: var(--carbon);
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

[data-state="void"] .status {
  background: var(--coupon);
  color: var(--ink-2);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--row) var(--cell);
  align-items: baseline;
  margin: 0;
  padding: 12px var(--cell);
  border-bottom: 1px solid var(--hair);
}

.invoice-number {
  font: var(--figure);
  font-size: 15px;
  color: var(--carbon);
  white-space: nowrap;
}

.sample-label {
  padding: 3px 8px 2px;
  background: var(--ink);
  color: var(--coupon);
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* Stamps are bordered boxes set at a slight counter-clockwise tilt. */
.stamp-issued,
.stamp-void {
  position: absolute;
  top: 74px;
  right: var(--cell);
  text-transform: uppercase;
}

.stamp-issued {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 14px 6px;
  border: 3px solid var(--carbon);
  background: var(--stamp-ground);
  color: var(--carbon);
  font: var(--stamp);
  font-size: 32px;
  letter-spacing: 0.16em;
  transform: rotate(-6deg);
}

.stamp-number {
  font: var(--figure);
  font-size: 13px;
  letter-spacing: 0;
}

.stamp-void {
  padding: 1px 9px 0;
  border: 2.5px solid var(--void);
  color: var(--void);
  font: var(--stamp);
  letter-spacing: 0.16em;
  transform: rotate(-7deg);
}

.void-reason {
  margin: 0;
  padding: 10px var(--cell) 0;
  color: var(--void);
  font: var(--body-sm);
}

/* The moves (DESIGN.md, "Motion"): the stamp lands, the credit note slides out
   from behind the invoice, the figures tick over when the currency changes and
   a line opens with the hero's unfold and fresh. demo.js marks the stage for
   the length of each, so a re-render for another reason replays nothing. They
   exist only when the visitor allows motion; without it each step simply shows
   its result. (unfold and fresh are the hero's keyframes, in styles.css.) */
@media (prefers-reduced-motion: no-preference) {
  @keyframes stamp-land {
    from {
      transform: rotate(-14deg) scale(1.6);
      filter: blur(2px);
    }

    to {
      transform: rotate(-7deg) scale(1);
      filter: blur(0);
    }
  }

  @keyframes credit-out {
    from {
      transform: translateX(-44px);
    }

    to {
      transform: none;
    }
  }

  @keyframes tick {
    from {
      transform: translateY(-8px);
    }

    to {
      transform: none;
    }
  }

  .demo-live.voiding .stamp-void {
    animation: stamp-land 320ms var(--ease-stamp) 60ms both;
  }

  .demo-live.voiding .carbon-copy {
    animation: credit-out 300ms var(--out-expo) 200ms both;
  }

  .demo-live.tick .lines .net {
    animation: tick 220ms var(--out-quart) both;
  }

  .demo-live.tick .lines tbody tr:nth-child(2) .net {
    animation-delay: 50ms;
  }

  .demo-live.tick .lines tbody tr:nth-child(3) .net {
    animation-delay: 100ms;
  }

  .demo-live.tick .lines tfoot .net {
    animation-delay: 160ms;
  }

  .demo-live [data-line].just-opened {
    animation: fresh 240ms linear both;
  }

  .demo-live [data-line].just-opened details[open] ul {
    animation: unfold 240ms var(--out-quart) both;
  }
}

/* The lines. */
.lines {
  width: 100%;
  border-collapse: collapse;
}

.lines th {
  padding: 10px var(--cell);
  border-bottom: 1.5px solid var(--ink);
  color: var(--ink-2);
  font: var(--label);
  letter-spacing: 0.09em;
  text-align: left;
  text-transform: uppercase;
}

.lines td,
.lines tfoot th {
  padding: 13px var(--cell);
  border-bottom: 1px solid var(--hair);
  vertical-align: top;
  text-align: left;
}

.lines .n {
  text-align: right;
}

.lines .net {
  color: var(--carbon);
  font: var(--figure);
  white-space: nowrap;
}

.lines .charge {
  font: var(--title);
}

.lines .working {
  color: var(--ink-2);
}

.lines tfoot th {
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.lines tfoot .net {
  font: var(--figure-total);
}

.lines tfoot th,
.lines tfoot td {
  border-bottom: 0;
}

/* A voided invoice keeps its rows: text in ink-2, amounts struck through. */
[data-state="void"] .lines td {
  color: var(--ink-2);
}

[data-state="void"] .lines .net {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

/* "Where this came from": a native disclosure under the charge name. */
.trace {
  margin-top: 4px;
  font: var(--body-sm);
}

.trace summary {
  display: inline-block;
  cursor: pointer;
  transition: background-color 120ms linear;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.trace summary:hover {
  background: var(--fresh);
}

.trace ul {
  margin: 8px 0 0;
  padding: 0 0 0 var(--cell);
}

.trace li {
  color: var(--ink);
}

/* The line the visitor has opened is filled with fresh, as in the hero. */
.demo-live [data-line]:has(details[open]) {
  background: var(--fresh);
}

/* The credit note: a carbon copy, lavender with a fine dot texture. */
.carbon-copy {
  position: relative;
  flex: 0 1 260px;
  min-width: 0;
  background-color: var(--copy);
  background-image: radial-gradient(var(--carbon-dot) 0.8px, transparent 1px);
  background-size: 6px 6px;
  border: 1.5px solid var(--carbon);
  box-shadow: var(--sheet-2);
  color: var(--carbon);
}

.carbon-copy p {
  margin: 0;
  padding: 14px var(--cell);
  border-bottom: 1px dashed var(--carbon);
}

.carbon-copy p:last-child {
  border-bottom: 0;
}

.carbon-copy .label {
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.carbon-copy .credit-note-number {
  font: var(--figure);
  font-size: 22px;
}

.carbon-copy .credit-note-amount {
  font: var(--figure);
  font-size: 22px;
  white-space: nowrap;
}

.carbon-copy .note {
  color: var(--ink);
  font: var(--body-sm);
}

@media (max-width: 760px) {
  /* The stamps move into the flow. */
  .stamp-issued,
  .stamp-void {
    position: static;
    display: inline-flex;
    margin: var(--cell);
  }

  .stamp-issued {
    font-size: 22px;
  }

  .lines td,
  .lines tfoot th,
  .lines th {
    padding: 12px;
  }

  .head-text {
    padding: 11px 12px;
  }

  .status {
    padding: 0 10px;
  }

  .meta {
    padding: 12px;
  }
}

/* Room beside the invoice number for the stamp. */
@media (min-width: 761px) {
  .meta {
    min-height: 96px;
    align-items: flex-start;
  }

  .stamp-issued,
  .stamp-void {
    top: 80px;
  }
}

/* On a phone each line is two rows: charge and net, then the working. */
@media (max-width: 760px) {
  .lines thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .lines,
  .lines tbody,
  .lines tfoot {
    display: block;
  }

  .lines tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "charge net"
      "working working";
    border-bottom: 1px solid var(--hair);
  }

  .lines tfoot tr {
    border-bottom: 0;
  }

  .lines tr > :nth-child(1) {
    grid-area: charge;
  }

  .lines tr > :nth-child(2) {
    grid-area: working;
    padding-top: 0;
  }

  .lines tr > :nth-child(3) {
    grid-area: net;
  }

  .lines td,
  .lines tfoot th {
    border-bottom: 0;
  }

  .lines tfoot .net {
    font-size: 22px;
  }
}

/* The currency switch: three radios drawn as one segmented control. The real
   radios stay in the page (visually hidden, still focusable) so the arrow
   keys, the tab stop and the screen reader's group all come for free. */
.currency-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--row) var(--cell);
  margin: 0 0 var(--gutter);
  padding: 0;
  border: 0;
  min-width: 0;
}

.currency-switch legend {
  float: left;
  margin: 0 var(--cell) 0 0;
  padding: 0;
  font: var(--label);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.currency-options {
  display: inline-flex;
  border: 1.5px solid var(--ink);
  background: var(--coupon);
}

.currency-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 44px;
  padding: 0 var(--cell);
  font: var(--control);
  font-size: 18px;
  cursor: pointer;
  transition:
    background-color 120ms linear,
    color 120ms linear;
}

.currency-option + .currency-option {
  border-left: 1.5px solid var(--ink);
}

.currency-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* The chosen option is filled with ink; the label is the focus target. */
.currency-option:has(input:checked) {
  background: var(--ink);
  color: var(--on-ink);
}

.currency-option:has(input:focus-visible) {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--dock);
}

.currency-note {
  margin: 0;
  color: var(--ink-2);
  font: var(--body-sm);
}
