/* Receipt-printer checkout overlay.
   Motion adapted from the dqnamo receipt-printer experiment
   (https://www.dqnamo.com/experiments/receipt-printer). */

.rp-overlay {
  position: fixed;
  inset: 0;
  z-index: 94;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px 12px 20px;
  box-sizing: border-box;
  overflow-y: auto;
}
.rp-overlay.is-open { display: flex; }
.rp-overlay[hidden] { display: none !important; }

.rp-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.rp-root {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  isolation: isolate;
  margin: auto;
}

/* —— Machine body: dark charcoal device, not a toast card —— */
.rp-machine {
  position: relative;
  isolation: isolate;
  width: 100%;
  overflow: hidden;
  border-radius: 1.5rem;
  border: 1px solid #1a1d24;
  background:
    linear-gradient(180deg, #2a2e36 0%, #1b1e25 42%, #14161c 100%);
  padding: 0.7rem 0.75rem 2rem;
  box-shadow:
    0 24px 40px -18px rgba(0, 0, 0, 0.72),
    0 8px 16px -10px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -1px 0 rgba(0, 0, 0, 0.55);
}

.rp-machine::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  opacity: 0.22;
  mix-blend-mode: overlay;
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,0.035) 2px, rgba(255,255,255,0.035) 3px),
    repeating-linear-gradient(90deg, transparent, transparent 3px, rgba(0,0,0,0.1) 3px, rgba(0,0,0,0.1) 4px);
}

.rp-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.5rem;
  padding: 0 0.15rem 0.55rem;
}

.rp-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.rp-header-mark {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  object-fit: contain;
}

.rp-header-name {
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: #e8edf4;
  line-height: 1;
}

.rp-home {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: #c8cdd6;
  font-family: Inter, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
}
.rp-home:hover { background: rgba(255, 255, 255, 0.09); color: #f1f5f9; }
.rp-home:focus-visible {
  outline: 2px solid var(--gold-hi, #c9a558);
  outline-offset: 2px;
}

/* Recessed black POS screen — plan + total live here */
.rp-screen {
  position: relative;
  z-index: 10;
  isolation: isolate;
  overflow: hidden;
  border-radius: 0.75rem;
  border: 1px solid #050608;
  background: #07080b;
  padding: 0.95rem 1rem 0.85rem;
  color: #e8edf4;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 0 0 1px rgba(0, 0, 0, 0.55),
    inset 0 18px 28px rgba(0, 0, 0, 0.35);
}
.rp-screen::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  border-radius: inherit;
  box-shadow: inset 0 0 28px 6px rgba(0, 0, 0, 0.55);
}

.rp-screen-body {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 1.05rem;
}

.rp-screen-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rp-screen-plan { min-width: 0; }
.rp-screen-name {
  font-family: Inter, system-ui, sans-serif;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: #f4f7fb;
}
.rp-screen-period {
  margin-top: 3px;
  font-size: 11.5px;
  font-weight: 500;
  color: #8b93a1;
  line-height: 1.25;
}

.rp-screen-sum { text-align: right; flex-shrink: 0; }
.rp-screen-sum-label {
  font-size: 11px;
  font-weight: 550;
  color: #8b93a1;
  line-height: 1.2;
}
.rp-screen-sum-amt {
  margin-top: 2px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
  line-height: 1.15;
}

.rp-status {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding-top: 0.15rem;
}

.rp-indicator {
  position: relative;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.rp-indicator > * {
  grid-column: 1;
  grid-row: 1;
}

.rp-spin {
  color: #94a3b8;
  animation: rp-spin 0.8s linear infinite;
}
.rp-check {
  color: #34d399;
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 0.16s cubic-bezier(0.23, 1, 0.32, 1), transform 0.16s cubic-bezier(0.23, 1, 0.32, 1);
}
.rp-root[data-stage="complete"] .rp-spin { display: none; }
.rp-root[data-stage="complete"] .rp-check {
  opacity: 1;
  transform: scale(1);
}

.rp-status-text {
  min-width: 0;
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rp-root[data-stage="complete"] .rp-status-text { color: #d5dbe6; }

/* Slot lip + mouth */
.rp-slot {
  position: absolute;
  left: 1.5rem;
  right: 1.5rem;
  bottom: 0.75rem;
  z-index: 40;
  height: 8px;
  border-radius: 0.25rem;
  border: 1px solid #050608;
  background: #050608;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.75),
    0 1px 0 rgba(255, 255, 255, 0.07);
}
.rp-slot::before {
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  top: -3px;
  height: 3px;
  border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.1), rgba(0,0,0,0.45));
}

.rp-output {
  position: relative;
  z-index: 50;
  margin-top: -1rem;
  height: 36rem;
  width: calc(80% + 3rem);
  max-width: 100%;
  overflow: hidden;
  padding: 0 1.5rem;
  box-sizing: border-box;
}

.rp-slot-shadow {
  pointer-events: none;
  position: absolute;
  left: 1.5rem;
  right: 1.5rem;
  top: -4px;
  z-index: 20;
  height: 8px;
  background: rgba(2, 6, 23, 0.55);
  filter: blur(6px);
  opacity: 0;
}
.rp-root[data-stage="printing"] .rp-slot-shadow,
.rp-root[data-stage="complete"] .rp-slot-shadow { opacity: 1; }

.rp-feed {
  position: relative;
  isolation: isolate;
  opacity: 0;
  transform: translateY(calc(-100% + 2px));
}
.rp-feed::before {
  content: "";
  pointer-events: none;
  position: absolute;
  left: 0.75rem;
  right: 0.75rem;
  top: 0.75rem;
  bottom: 1rem;
  z-index: 0;
  border-radius: 2px;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.28);
}
.rp-feed::after {
  content: "";
  pointer-events: none;
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 0;
  z-index: 0;
  height: 12px;
  transform: translateY(6px);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.1);
  filter: blur(12px);
}

.rp-root[data-stage="printing"] .rp-feed {
  opacity: 1;
  animation: rp-feed 1.75s linear forwards;
}
.rp-root[data-stage="complete"] .rp-feed {
  opacity: 1;
  transform: translateY(0);
}

/* Stepped paper feed — same keyframes / times as the dqnamo experiment. */
@keyframes rp-feed {
  0%    { transform: translateY(calc(-100% + 2px)); }
  7.5%  { transform: translateY(-91%); }
  10.5% { transform: translateY(-91%); }
  18%   { transform: translateY(-81%); }
  21%   { transform: translateY(-81%); }
  28.5% { transform: translateY(-70%); }
  31.5% { transform: translateY(-70%); }
  39%   { transform: translateY(-58%); }
  42%   { transform: translateY(-58%); }
  49.5% { transform: translateY(-45%); }
  52.5% { transform: translateY(-45%); }
  60%   { transform: translateY(-32%); }
  63%   { transform: translateY(-32%); }
  70.5% { transform: translateY(-20%); }
  73.5% { transform: translateY(-20%); }
  81%   { transform: translateY(-10%); }
  84%   { transform: translateY(-10%); }
  91.5% { transform: translateY(-3%); }
  94.5% { transform: translateY(-3%); }
  100%  { transform: translateY(0%); }
}

@keyframes rp-spin { to { transform: rotate(360deg); } }

/* White / off-white thermal slip — not cream-gold */
.rp-paper {
  position: relative;
  z-index: 10;
  min-height: 22rem;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(20, 16, 12, 0.028) 0 1px,
      transparent 1px 3px
    ),
    #f7f4ee;
  color: #1a1a1a;
  padding: 1.6rem 1.15rem 2.15rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 11.5px;
  line-height: 1.4;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.rp-mark {
  display: block;
  width: 64px;
  height: 64px;
  margin: 0 auto;
  object-fit: contain;
}

.rp-rule {
  border: 0;
  height: 0;
  border-top: 1px dotted rgba(26, 26, 26, 0.55);
  margin: 10px 0;
}

.rp-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0;
}
.rp-k {
  color: #6b6b6b;
  font-weight: 400;
  font-size: 11px;
}
.rp-v {
  color: #111;
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rp-row.is-plan .rp-k,
.rp-row.is-plan .rp-v {
  color: #111;
  font-weight: 700;
  font-size: 12px;
}
.rp-row.is-total {
  margin: 6px 0;
  font-size: 15.5px;
  letter-spacing: 0.02em;
}
.rp-row.is-total .rp-k,
.rp-row.is-total .rp-v {
  font-weight: 800;
  text-transform: uppercase;
  color: #0a0a0a;
  font-size: 15.5px;
}

.rp-sub {
  color: #7a7a7a;
  margin: 1px 0 2px;
  font-size: 10.5px;
  font-weight: 400;
}

.rp-fallback {
  font-weight: 700;
  color: #111;
  letter-spacing: 0.01em;
}

.rp-barcode {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 2px;
}

.rp-barcode-caption {
  display: block;
  text-align: center;
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #6b6b6b;
}

.rp-done {
  margin-top: 10px;
  appearance: none;
  border: 1px solid rgba(181, 143, 74, 0.5);
  background: var(--gold, #b58f4a);
  color: #0b1220;
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: -0.01em;
  border-radius: 12px;
  padding: 10px 18px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.22s ease, transform 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}
.rp-root[data-stage="complete"] .rp-done {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.rp-done:hover { background: var(--gold-hi, #c9a558); }
.rp-done:focus-visible {
  outline: 2px solid var(--gold-hi, #c9a558);
  outline-offset: 3px;
}

[data-theme="light"] .rp-backdrop { background: rgba(15, 23, 42, 0.5); }

@media (prefers-reduced-motion: reduce) {
  .rp-spin { animation: none; }
  .rp-feed,
  .rp-root[data-stage="printing"] .rp-feed,
  .rp-root[data-stage="complete"] .rp-feed {
    animation: none !important;
    opacity: 1;
    transform: translateY(0);
  }
  .rp-check,
  .rp-done { transition: none; }
}

@media (max-height: 780px) {
  .rp-output { height: 30rem; }
  .rp-paper { min-height: 18rem; padding: 1.25rem 1rem 1.85rem; }
}
@media (max-height: 640px) {
  .rp-output { height: 26rem; }
  .rp-screen { padding: 0.75rem 0.85rem 0.7rem; }
  .rp-screen-body { gap: 0.7rem; }
  .rp-screen-name { font-size: 14px; }
  .rp-screen-sum-amt { font-size: 16px; }
}
