/*
 * Design language: the public gate page is styled as a printed receipt —
 * this page's actual job is to appear right after a customer's visit,
 * tap/scan in hand, so the metaphor is mechanically true rather than
 * decorative. One ink colour + one stamp accent, no per-platform rainbow —
 * a real receipt doesn't colour-code its line items. Courier Prime carries
 * the "printed" personality; IBM Plex Sans (plus the system CJK stack, since
 * neither web font covers Chinese) does the reading work.
 */
:root {
  --surface: #e8e2d2;      /* ambient counter/table the receipt sits on */
  --paper: #fbf8f1;        /* the receipt itself */
  --paper-dark: #f2ecdd;   /* recessed paper areas (rows, inputs) */
  --ink: #241f18;
  --ink-soft: #8c8271;
  --line: #d8cdb2;         /* perforation + dotted rules */
  --stamp: #b23a2e;        /* primary ink-stamp accent */
  --stamp-ink: #fff9ef;
  --verified: #3c6e4a;     /* secondary stamp, e.g. confirmations */
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-paper: 0 18px 40px -12px rgba(36, 31, 24, 0.35);

  --font-display: "Courier Prime", ui-monospace, "PingFang SC", "Noto Sans SC", monospace;
  --font-body: "IBM Plex Sans", "PingFang SC", "Noto Sans SC", -apple-system, sans-serif;

  /* Admin panel reuses the same system, expressed quietly (no perforation/
     stamp theatrics — see public/assets/css/admin.css). */
  --bg: var(--surface);
  --card-bg: var(--paper);
  --accent: var(--stamp);
  --accent-ink: var(--stamp-ink);
  --radius: var(--radius-md);
  --shadow: 0 6px 20px -8px rgba(36, 31, 24, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--surface);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- bilingual toggle: see lib/Helpers.php::i18n() ---------- */
.i18n[lang] { display: none; }
html[data-lang="en"] .i18n[lang="en"] { display: revert; }
html[data-lang="zh"] .i18n[lang="zh"] { display: revert; }

/* ---------- generic ---------- */
.btn {
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.7rem 1rem;
}
.btn-primary { background: var(--stamp); color: var(--stamp-ink); }
.btn:focus-visible, a:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 2px;
}

/* ---------- stub pages (home / not-found) ---------- */
.stub-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: var(--font-body);
  background: var(--surface);
}
.stub-card {
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-paper);
  padding: 2.5rem;
  max-width: 420px;
  text-align: center;
}
.stub-card h1 { margin-top: 0; font-family: var(--font-display); }
.stub-card .btn { display: inline-block; text-decoration: none; margin-top: 1rem; }

/* ---------- gate page: the receipt ---------- */
.gate-page {
  min-height: 100vh;
  padding: 2.5rem 1rem 4rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,0.5), transparent 60%),
    var(--surface);
}

.receipt {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--paper);
  box-shadow: var(--shadow-paper);
  padding: 2.25rem 1.5rem 1.75rem;
  animation: print-in 0.55s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes print-in {
  from { opacity: 0; transform: translateY(-18px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Perforated edge — a row of "punched" circles matching the ambient
   surface colour, so the paper reads as torn from a roll. */
.receipt::before,
.receipt::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 14px;
  background-image: radial-gradient(circle at 7px 7px, var(--surface) 7px, transparent 7.5px);
  background-size: 20px 14px;
  background-repeat: repeat-x;
}
.receipt::before { top: -7px; }
.receipt::after { bottom: -7px; }

.lang-toggle {
  position: absolute;
  top: 1.1rem;
  right: 1.25rem;
  z-index: 2;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}
.lang-toggle:hover { color: var(--ink); border-color: var(--ink-soft); }

.barcode {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  height: 22px;
  margin: 0 auto 0.6rem;
  width: fit-content;
}
.barcode span { display: block; width: 2px; background: var(--ink); }

.gate-header { text-align: center; margin-bottom: 0.5rem; }
.gate-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}
.gate-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
}
.gate-eyebrow {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0.35rem 0 1.4rem;
}

.receipt-rule {
  border: none;
  border-top: 2px dashed var(--line);
  margin: 0 0 0.25rem;
}

/* ---------- itemized link list ---------- */
.line-items { list-style: none; margin: 0; padding: 0; }
.line-item { border-bottom: 1px dotted var(--line); }
.line-item:last-child { border-bottom: none; }

.line-item-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  padding: 0.85rem 0;
}
.line-item-btn:hover .line-item-name,
.line-item-btn:hover .line-item-arrow { color: var(--stamp); }

.line-item-icon {
  flex: none;
  width: 22px;
  height: 22px;
  color: var(--ink);
}
.line-item-icon svg { width: 100%; height: 100%; }

.line-item-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
}

.line-item-leader {
  flex: 1;
  border-bottom: 1px dotted var(--line);
  height: 0;
  min-width: 0.75rem;
  margin: 0 0 0.35em;
}

.line-item-cta {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.line-item-arrow { font-size: 0.95rem; }

.gate-footer {
  text-align: center;
  margin-top: 1.6rem;
  padding-top: 1.1rem;
}
.gate-footer-thanks {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.empty-state { text-align: center; color: var(--ink-soft); padding: 1rem 0; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(36, 31, 24, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay[hidden] { display: none; }

.overlay-sheet {
  background: var(--paper);
  width: 100%;
  max-width: 420px;
  border-radius: 20px 20px 0 0;
  padding: 1.5rem 1.4rem calc(1.5rem + env(safe-area-inset-bottom));
  max-height: 85vh;
  overflow-y: auto;
  border-top: 2px dashed var(--line);
}
.overlay-sheet--center {
  border-radius: var(--radius-lg);
  border-top: none;
  margin-bottom: auto;
  margin-top: auto;
  text-align: center;
}
.overlay-sheet h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.lang-options { display: flex; gap: 0.75rem; justify-content: center; margin-top: 1rem; }
.lang-option {
  flex: 1;
  padding: 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--paper-dark);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.lang-option:hover { border-color: var(--stamp); color: var(--stamp); }

.overlay-sheet-header { display: flex; align-items: center; justify-content: space-between; }
.overlay-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
  padding: 0.25rem 0.5rem;
}
.overlay-hint { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 1rem; }

.copy-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  background: var(--paper-dark);
}
.copy-text { margin: 0 0 0.6rem; font-size: 0.88rem; line-height: 1.5; }
.btn-copy {
  background: var(--stamp);
  color: var(--stamp-ink);
  font-size: 0.85rem;
  padding: 0.45rem 1.1rem;
}
.btn-copy.is-copied { background: var(--verified); }
.copy-btn-label--copied { display: none; }
.btn-copy.is-copied .copy-btn-label--default { display: none; }
.btn-copy.is-copied .copy-btn-label--copied { display: inline; }

@media (min-width: 560px) {
  .overlay { align-items: center; }
  .overlay-sheet { border-radius: var(--radius-lg); border-top: none; }
}
