/* ============================================================================
   Receipt printer — the styles for js/receipt-printer.js

   Ported from Kokonut UI's receipt-printer (MIT, @dorianbaffier). The original
   draws on Tailwind's zinc palette; here every colour is a token from
   tokens.css, so the printer is metal, paper and ink like everything else on
   the site rather than a grey widget dropped into it.

   Two numbers are the component's, not the design system's, and they cannot be
   tokenised without breaking the physics in the script:

     288 × 480   the card  (h-[30rem] w-72 in the original)
     224         the paper (w-56), and SLOT_Y 64 for the slot

   Everything else — radius, rules, type, easing — is the house scale.
   ========================================================================= */

.rp {
  /* Serrated edges: the bottom was torn off the last receipt, and the top
     gets the same edge once this one is torn. Both are conic gradients used as
     masks, which is how the original does it and why it needs no image. */
  --rp-tooth: 8px;
  --rp-edge-top: conic-gradient(
      from 135deg at 50% 0,
      #0000,
      #000 1deg 89deg,
      #0000 90deg
    )
    50% 0 / var(--rp-tooth) calc(var(--rp-tooth) / 2) repeat-x;
  --rp-edge-bottom: conic-gradient(
      from -45deg at 50% 100%,
      #0000,
      #000 1deg 89deg,
      #0000 90deg
    )
    50% 100% / var(--rp-tooth) calc(var(--rp-tooth) / 2) repeat-x;
  --rp-mask-resting: var(--rp-edge-bottom),
    linear-gradient(#000 0 0) 0 0 / 100% calc(100% - var(--rp-tooth) / 2)
      no-repeat;
  --rp-mask-torn: var(--rp-edge-top), var(--rp-edge-bottom),
    linear-gradient(#000 0 0) 0 calc(var(--rp-tooth) / 2) / 100%
      calc(100% - var(--rp-tooth)) no-repeat;

  position: relative;
  width: 288px;
  height: 480px;
  overflow: hidden;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-lg);
  background: var(--mist);
  color: var(--ink);
  font-family: var(--font-text);
  -webkit-user-select: none;
  user-select: none;
}

/* The sheet, clipped at the slot until it's torn free. */
.rp__stage {
  position: absolute;
  inset: 64px 0 0 0;
  overflow: hidden;
}

.rp--torn .rp__stage {
  overflow: visible;
}

.rp__paper {
  position: absolute;
  top: 0;
  left: 50%;
  width: 224px;
  margin-left: -112px;
  background: var(--shell);
  /* Lifted off the ground, not floating on haze: one contact shadow, one
     soft one, both tinted with the ink rather than black. */
  box-shadow: 0 1px 2px rgba(41, 39, 36, 0.06),
    0 8px 24px -12px rgba(41, 39, 36, 0.25);
  transform-origin: 0 0;
  /* Inside the printer until the first frame places it, so first paint does
     not flash a full receipt. */
  transform: translate3d(0, -100%, 0);
  -webkit-mask: var(--rp-mask-resting);
  mask: var(--rp-mask-resting);
  touch-action: none;
  will-change: transform;
}

.rp--torn .rp__paper {
  -webkit-mask: var(--rp-mask-torn);
  mask: var(--rp-mask-torn);
}

.rp--hanging .rp__paper {
  cursor: grab;
}

.rp--hanging .rp__paper:active,
.rp--held .rp__paper {
  cursor: grabbing;
}

/* Gone for good once torn: the next print starts from a clean sheet. */
.rp--idle.rp--torn .rp__paper {
  visibility: hidden;
}

/* Perforation along the slot, where the sheet tears off. */
.rp__perf {
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  height: 0;
  border-top: 2px dotted var(--alu);
  pointer-events: none;
}

/* ── the slip ─────────────────────────────────────────────────────────────*/

.rp__slip {
  padding: 24px 20px 32px;
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  line-height: 15px; /* = LINE in the script: one feed step, one text line */
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.rp__merchant {
  margin: 0;
  text-align: center;
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
}

.rp__meta {
  margin: 0;
  text-align: center;
  color: var(--ink-muted);
}

.rp__stamp {
  width: max-content;
  margin: 8px auto 0;
  padding: 3px 8px;
  border: 1px solid var(--ink-muted);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--t-micro);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transform: rotate(-4deg);
}

.rp__rule {
  margin: 7px 0;
  overflow: hidden;
  white-space: nowrap;
  color: var(--alu);
}

.rp__row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
}

.rp__row--quiet {
  color: var(--ink-muted);
}

.rp__row--total {
  margin-top: 4px;
  font-size: var(--t-caption);
  font-weight: 500;
  color: var(--ink);
}

/* Three lines keep the product name readable in the 184px of slip available
   here. The sheet is measured after layout, so a taller slip just feeds for a
   few more steps. */
.rp__name {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
}

.rp__num {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.rp__barcode {
  display: flex;
  justify-content: center;
  gap: 1px;
  height: 36px;
  margin-top: 16px;
}

.rp__bar {
  display: block;
  height: 100%;
  background: var(--graphite);
}

.rp__bar--gap {
  background: transparent;
}

.rp__thanks {
  margin: 12px 0 0;
  text-align: center;
  color: var(--ink-muted);
}

/* ── the housing ──────────────────────────────────────────────────────────*/

.rp__housing {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 2;
  height: 64px;
  border-bottom: 1px solid var(--rule-soft);
  background: var(--shell);
  will-change: transform;
}

.rp__housing-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  padding: 16px 20px 0;
}

.rp__housing-merchant {
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.rp__status {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

/* The slot the paper comes out of. */
.rp__slot {
  position: absolute;
  right: 32px;
  bottom: 8px;
  left: 32px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--graphite);
}

/* ── controls ─────────────────────────────────────────────────────────────*/

.rp__actions {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  padding: 20px;
  opacity: 1;
  transition: opacity var(--d-base) var(--ease-out);
}

.rp:not(.rp--idle) .rp__actions {
  opacity: 0;
  pointer-events: none;
}

.rp__print {
  padding: 8px 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--graphite);
  color: var(--on-dark);
  font-family: var(--font-text);
  font-size: var(--t-sm);
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease);
}

.rp__print:hover {
  background: var(--ink);
}

.rp__print:focus-visible {
  outline: 2px solid var(--sage-deep);
  outline-offset: 2px;
}

.rp__print:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Keyboard only, and only while there is paper to tear: it sits in the tab
   order for exactly the phase in which it does something. */
.rp__tear {
  position: absolute;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: 4;
  padding: 6px 12px;
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-pill);
  background: var(--shell);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--t-micro);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity var(--d-fast) var(--ease),
    transform var(--d-fast) var(--ease);
}

.rp__tear:focus-visible {
  opacity: 1;
  pointer-events: auto;
  transform: none;
  outline: 2px solid var(--sage-deep);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .rp__actions,
  .rp__tear,
  .rp__print {
    transition: none;
  }
}
