/* ==========================================================================
   CHECKOUT PAGE & POS RECEIPT PRINTER MOTION UI
   ========================================================================== */

:root {
  --bg-viewport: #09090b;
  --card-bg: #121215;
  --card-border: rgba(255, 255, 255, 0.08);
  --card-surface: #18191d;

  --chassis-top: #1f2024;
  --chassis-bottom: #141517;
  --screen-bg: #070709;
  --screen-border: rgba(255, 255, 255, 0.05);

  --text-white: #ffffff;
  --text-dim: #9ca3af;
  --text-muted: #6b7280;
  --accent-emerald: #10b981;
  --accent-indigo: #6366f1;

  /* Premium Off-White Thermal Paper */
  --paper-top: #fafafc;
  --paper-mid: #f3f3f6;
  --paper-bottom: #ebecee;
  --paper-ink: #141416;
  --paper-ink-muted: #56565c;
  --paper-line: rgba(0, 0, 0, 0.14);

  --checkout-width: 480px;
  --machine-width: 450px;
  --paper-width: 390px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-viewport);
  color: var(--text-white);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start; /* Positions near the top to give ample downward space for extruded paper */
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

.font-mono {
  font-family: "Space Mono", "SF Mono", Menlo, monospace;
}

/* Background Atmosphere */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(140px);
  z-index: 0;
}

.glow-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15), transparent 70%);
  top: -120px;
  left: 50%;
  transform: translateX(-50%);
}

.glow-2 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.1), transparent 70%);
  bottom: -60px;
  right: 15%;
}

.grid-overlay {
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 1;
}

.viewport-container {
  position: relative;
  z-index: 5;
  width: 100%;
  max-width: 600px;
  padding: 40px 16px 120px; /* Sits nicely near top with scroll room at bottom */
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ==========================================================================
   VIEW 1: CHECKOUT FORM STYLES
   ========================================================================== */
.checkout-view {
  width: 100%;
  max-width: var(--checkout-width);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.checkout-view.hidden {
  opacity: 0;
  transform: translateY(-20px) scale(0.96);
  pointer-events: none;
  position: absolute;
}

.checkout-card {
  background: linear-gradient(175deg, #18191d 0%, #111215 100%);
  border: 1px solid var(--card-border);
  border-radius: 26px;
  padding: 24px 24px 28px;
  box-shadow: 
    0 30px 60px -15px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
}

.checkout-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #37383f, #212226);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.secure-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  color: #34d399;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.section-block {
  margin-bottom: 20px;
}

.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* Order Summary Box */
.order-summary-box {
  background: #0d0d10;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 16px;
}

.order-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.order-item-row:last-of-type {
  margin-bottom: 0;
}

.item-name {
  font-size: 0.86rem;
  font-weight: 600;
  color: #f3f4f6;
}

.item-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.item-val {
  font-size: 0.88rem;
  font-weight: 700;
  font-family: 'Space Mono', monospace;
  color: #f9fafb;
}

.summary-divider {
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
  margin: 12px 0;
}

.calc-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.calc-line.promo {
  color: #34d399;
}

.total-due-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.due-label {
  font-weight: 700;
  font-size: 0.9rem;
}

.due-price {
  font-size: 1.15rem;
  font-weight: 800;
  color: #ffffff;
}

/* Inputs & Form */
.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.input-grid.double-col {
  margin-top: 10px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.input-field.full-width {
  grid-column: span 2;
}

.input-field label {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--text-dim);
}

.input-field input {
  background: #0d0d10;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: #ffffff;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-field input:focus {
  border-color: rgba(99, 102, 241, 0.6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.card-input-box {
  background: #0d0d10;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 14px;
}

.card-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.card-input-wrap input {
  width: 100%;
  padding-right: 60px;
  font-family: 'Space Mono', monospace;
  letter-spacing: 0.04em;
}

.visa-badge {
  position: absolute;
  right: 10px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  color: #93c5fd;
  letter-spacing: 0.05em;
}

/* Pay Submit Button */
.btn-pay-submit {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #ffffff, #e2e8f0);
  color: #000000;
  border: none;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(255, 255, 255, 0.25);
  transition: all 0.2s ease;
  margin-top: 24px;
  font-family: inherit;
}

.btn-pay-submit:hover {
  background: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 6px 25px rgba(255, 255, 255, 0.35);
}

.btn-pay-submit:active {
  transform: scale(0.98);
}

/* ==========================================================================
   VIEW 2: PRINTER CONFIRMATION STYLES
   ========================================================================== */
.printer-view {
  width: 100%;
  max-width: var(--machine-width);
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.printer-view.hidden {
  opacity: 0;
  transform: translateY(25px) scale(0.96);
  pointer-events: none;
  position: absolute;
}

.printer-stage-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.pos-machine {
  position: relative;
  width: 100%;
  max-width: var(--machine-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.9);
  border-radius: 28px;
}

/* 1. TOP FRONT HOUSING (Layer 30) */
.machine-front-top {
  position: relative;
  z-index: 30;
  width: 100%;
  background: linear-gradient(180deg, var(--chassis-top) 0%, #16171a 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1.5px solid #000000;
  border-radius: 28px 28px 0 0;
  padding: 20px 18px 14px;
}

.machine-front-top::before {
  content: '';
  position: absolute;
  top: 0;
  left: 40px;
  right: 40px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
}

.machine-screen-card {
  background: var(--screen-bg);
  border: 1px solid var(--screen-border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5) inset;
}

.screen-main-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.plan-info {
  display: flex;
  flex-direction: column;
}

.plan-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.plan-subtitle {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.total-info {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.total-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-bottom: 2px;
}

.total-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.screen-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.status-icon-box {
  position: relative;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-circle {
  width: 16px;
  height: 16px;
  border: 2.2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

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

.check-circle {
  position: absolute;
  color: var(--accent-emerald);
  transform: scale(0);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.status-msg {
  font-size: 0.86rem;
  font-weight: 500;
  color: #c7c7cc;
  transition: color 0.3s ease;
}

.screen-status-row[data-state="idle"] .status-icon-box {
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 16px;
  height: 16px;
}

.screen-status-row[data-state="processing"] .spinner-circle,
.screen-status-row[data-state="printing"] .spinner-circle {
  display: block;
}

.screen-status-row[data-state="processing"] .status-msg,
.screen-status-row[data-state="printing"] .status-msg {
  color: #ffffff;
}

.screen-status-row[data-state="completed"] .check-circle {
  transform: scale(1);
  opacity: 1;
}

.screen-status-row[data-state="completed"] .status-msg {
  color: #ffffff;
}

/* 2. BOTTOM FRONT BASE */
.machine-front-bottom {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 16px;
  background: linear-gradient(180deg, #101113 0%, var(--chassis-bottom) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top: none;
  border-radius: 0 0 28px 28px;
}

/* 3. THERMAL RECEIPT VIEWPORT (Strictly Masked from the Slot Line) */
.receipt-track-wrapper {
  position: absolute;
  /* Dynamically pinned right at the bottom edge of machine-front-top */
  top: 154px;
  left: 50%;
  transform: translateX(-50%);
  width: var(--paper-width);
  max-width: 95%;
  height: 600px;
  z-index: 25;
  clip-path: polygon(0 0, 100% 0, 100% 2000px, 0 2000px);
  -webkit-clip-path: polygon(0 0, 100% 0, 100% 2000px, 0 2000px);
  overflow: visible;
  filter: drop-shadow(0 25px 25px rgba(0, 0, 0, 0.65)) drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35));
}

.receipt-track-wrapper::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.35) 50%, transparent 100%);
  pointer-events: none;
  z-index: 28;
}

.thermal-receipt {
  position: relative;
  width: 100%;
  background: linear-gradient(180deg, var(--paper-top) 0%, var(--paper-mid) 60%, var(--paper-bottom) 100%);
  color: var(--paper-ink);
  transform: translateY(-100%);
  opacity: 0;
  will-change: transform, opacity;
  border-left: 1px solid rgba(0, 0, 0, 0.06);
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  padding-bottom: 2px;
}

.thermal-receipt::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: 
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.015) 1px, transparent 1px),
    repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0, 0, 0, 0.01) 3px, rgba(0, 0, 0, 0.01) 4px);
  background-size: 8px 8px, 100% 4px;
  pointer-events: none;
  opacity: 0.8;
  z-index: 1;
}

.thermal-receipt::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, 
    rgba(0, 0, 0, 0.03) 0%, 
    transparent 6%, 
    transparent 94%, 
    rgba(0, 0, 0, 0.03) 100%
  );
  pointer-events: none;
  z-index: 1;
}

.thermal-receipt.state-hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.thermal-receipt.state-printing {
  opacity: 1;
  pointer-events: auto;
}

.thermal-receipt.state-completed {
  opacity: 1;
  transform: translateY(0);
}

/* Serrated Tooth Edges */
.serrated-edge {
  position: relative;
  width: 100%;
  height: 8px;
  z-index: 5;
  background-repeat: repeat-x;
  background-size: 10px 8px;
}

.serrated-edge.top-edge {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 8'%3E%3Cpolygon points='0,8 5,0 10,8' fill='%23fafafc'/%3E%3C/svg%3E");
  margin-bottom: -2px;
}

.serrated-edge.bottom-edge {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 8'%3E%3Cpolygon points='0,0 5,8 10,0' fill='%23ebecee'/%3E%3C/svg%3E");
  margin-top: 0px;
}

.receipt-content {
  position: relative;
  z-index: 2;
  padding: 14px 22px 14px;
}

.receipt-header {
  text-align: center;
  margin-bottom: 12px;
}

.receipt-logo-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.8px solid var(--paper-ink);
  margin-bottom: 6px;
  color: var(--paper-ink);
}

.receipt-store-title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.receipt-store-desc {
  font-size: 0.72rem;
  color: var(--paper-ink-muted);
}

.receipt-rule {
  margin: 12px 0;
}

.receipt-rule.dashed {
  border-bottom: 1px dashed var(--paper-line);
}

.receipt-rule.solid {
  border-bottom: 1.5px solid var(--paper-ink);
  margin: 8px 0;
}

/* Metadata */
.receipt-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.76rem;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  color: var(--paper-ink-muted);
}

.meta-line span:last-child {
  color: var(--paper-ink);
  font-weight: 700;
  font-size: 0.82rem;
}

/* Line Items */
.receipt-lines {
  font-size: 0.8rem;
}

.line-head {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: var(--paper-ink-muted);
  margin-bottom: 8px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.line-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.line-name {
  font-weight: 700;
  color: var(--paper-ink);
  font-size: 0.84rem;
}

.line-note {
  font-size: 0.7rem;
  color: var(--paper-ink-muted);
}

.line-entry .font-mono {
  font-size: 0.92rem;
  font-weight: 700;
}

/* Calculations */
.receipt-math {
  font-size: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.math-row {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.82rem;
}

.math-row .font-mono {
  font-size: 0.9rem;
}

.math-row.promo {
  color: #059669;
}

.grand-total {
  font-size: 1rem;
  font-weight: 800;
  margin-top: 6px;
}

.grand-price {
  font-size: 1.25rem !important;
  font-weight: 800;
}

/* Footer / Barcode */
.receipt-end {
  text-align: center;
  margin-top: 12px;
}

.barcode-graphic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.barcode-svg {
  width: 80%;
  height: 34px;
}

.barcode-digits {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  color: var(--paper-ink-muted);
}

.receipt-gratitude {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.receipt-footnote {
  font-size: 0.64rem;
  color: var(--paper-ink-muted);
}

/* Responsive */
@media (max-width: 520px) {
  :root {
    --checkout-width: 100%;
    --machine-width: 100%;
    --paper-width: 90%;
  }

  .viewport-container {
    padding: 24px 12px 140px;
  }

  .checkout-card {
    padding: 18px 16px;
  }

  .input-grid {
    grid-template-columns: 1fr;
  }

  .input-field.full-width {
    grid-column: span 1;
  }

  .machine-front-top {
    padding: 16px 14px 12px;
    border-radius: 22px 22px 0 0;
  }

  .machine-screen-card {
    padding: 16px;
    border-radius: 14px;
  }
}
