/**
 * SG Attractions redemption terminal.
 *
 * A scanner-first counter UI layered on Bootstrap 5.3. Designed for handhelds
 * held at arm's length under bright light: large tap targets, high contrast,
 * unmistakable result states. Yellow and green come straight from the SG
 * Attractions logo; the logo's blue is deepened to a dark navy so large
 * surfaces (app bar, primary buttons) stay calm behind the yellow mark.
 */

:root {
  /* Brand */
  --brand-blue: #131347;
  --brand-blue-800: #0e0e36;
  --brand-blue-900: #0a0a28;
  --brand-blue-050: #ecedf5;
  --brand-yellow: #fdcd00;
  --brand-green: #004503;

  /* Neutrals */
  --canvas: #eef0f6;
  --surface: #ffffff;
  --surface-muted: #f7f8fc;
  --line: #e2e6ef;
  --ink: #14161f;
  --muted: #5b6478;

  /* Semantic */
  --ok: #0f7a3d;
  --ok-bg: #e6f5ec;
  --warn: #b26a00;
  --warn-bg: #fdf3e0;
  --danger: #b3261e;
  --danger-bg: #fdeceb;
  --info-bg: var(--brand-blue-050);

  --radius-card: 18px;
  --radius-control: 12px;
  --shadow-card: 0 10px 30px rgba(20, 22, 31, 0.08);
  --tap: 48px;
}

/* ---------------------------------------------------------------- shell -- */

body {
  min-height: 100dvh;
  color: var(--ink);
  background-color: var(--canvas);
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(19, 19, 71, 0.10) 0%, rgba(19, 19, 71, 0) 60%);
  background-repeat: no-repeat;
  -webkit-text-size-adjust: 100%;
}

.page-main {
  padding-bottom: 2rem;
}

/* App bar -------------------------------------------------------------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: linear-gradient(100deg, var(--brand-blue) 0%, var(--brand-blue-900) 100%);
  box-shadow: 0 2px 12px rgba(19, 19, 71, 0.32);
  padding-top: env(safe-area-inset-top);
}

.app-bar__inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 60px;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.app-bar__brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand-logo {
  display: block;
  height: 30px;
  width: auto;
  max-width: 55vw;
}

.app-bar__title {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  padding-left: 0.75rem;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
  white-space: nowrap;
}

.app-bar__spacer {
  flex: 1 1 auto;
}

.app-bar__count {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.1;
  text-align: right;
}

.app-bar__count strong {
  color: var(--brand-yellow);
  font-size: 1.05rem;
  font-weight: 800;
}

.app-bar__user {
  min-height: 40px;
  border-radius: 999px;
  padding: 0.35rem 0.9rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.3);
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-bar__user:hover,
.app-bar__user:focus,
.app-bar__user.show {
  color: var(--brand-blue);
  background: var(--brand-yellow);
  border-color: var(--brand-yellow);
}

@media (max-width: 575.98px) {
  .app-bar__title {
    display: none;
  }

  .brand-logo {
    height: 26px;
  }
}

/* Cards ---------------------------------------------------------------- */

.terminal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  overflow: hidden;
}

.terminal-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--brand-yellow);
}

@media (max-width: 575.98px) {
  .terminal-card {
    padding: 1.15rem;
  }
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.section-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.15rem 0 0;
}

/* ------------------------------------------------------------- controls -- */

.btn-terminal {
  min-height: 56px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: var(--radius-control);
  padding-inline: 1.25rem;
}

.btn-brand,
.btn-brand:visited {
  color: #fff;
  background: var(--brand-blue);
  border: 1px solid var(--brand-blue);
}

.btn-brand:hover,
.btn-brand:focus {
  color: #fff;
  background: var(--brand-blue-800);
  border-color: var(--brand-blue-800);
}

.btn-brand:active {
  color: #fff;
  background: var(--brand-blue-900);
}

.btn-redeem,
.btn-redeem:visited {
  color: #fff;
  background: var(--ok);
  border: 1px solid var(--ok);
}

.btn-redeem:hover,
.btn-redeem:focus {
  color: #fff;
  background: #0c6633;
  border-color: #0c6633;
}

.btn-quiet,
.btn-quiet:visited {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
}

.btn-quiet:hover,
.btn-quiet:focus {
  background: var(--surface-muted);
  border-color: #cfd5e4;
  color: var(--ink);
}

.btn,
.form-control,
.form-select {
  border-radius: var(--radius-control);
}

.btn:focus-visible,
.form-control:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(19, 19, 71, 0.55);
  outline-offset: 2px;
  box-shadow: none;
}

.app-bar .btn:focus-visible,
.app-bar a:focus-visible {
  outline: 3px solid var(--brand-yellow);
  outline-offset: 2px;
}

.form-control:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 0.2rem rgba(19, 19, 71, 0.15);
}

.form-control-lg {
  min-height: 54px;
}

/* Big code field ------------------------------------------------------- */

.code-field {
  position: relative;
}

.code-field .form-control {
  height: 60px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
  padding-right: 3rem;
  padding-left: 3rem;
  background: var(--surface-muted);
  border: 2px solid var(--line);
}

.code-field .form-control:focus {
  background: var(--surface);
}

.code-field .form-control::placeholder {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  color: #97a0b5;
}

.code-field .js-clear-code {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: none;
}

.code-field .js-clear-code:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

/* "or" divider --------------------------------------------------------- */

.divider-or {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 1.25rem 0 1rem;
}

.divider-or::before,
.divider-or::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--line);
}

/* -------------------------------------------------------------- scanner -- */

.scanner {
  position: relative;
  border-radius: var(--radius-card);
  background: #0d0f1a;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner #canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner__hint {
  position: absolute;
  inset: auto 0 0 0;
  padding: 0.6rem 0.9rem;
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.85rem;
  text-align: center;
  background: linear-gradient(180deg, rgba(13, 15, 26, 0) 0%, rgba(13, 15, 26, 0.85) 100%);
}

/* Framing brackets — purely decorative, drawn over the video. */
.scanner__frame {
  position: absolute;
  inset: 12%;
  pointer-events: none;
}

.scanner__frame span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 4px solid var(--brand-yellow);
  border-radius: 6px;
}

.scanner__frame span:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.scanner__frame span:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.scanner__frame span:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.scanner__frame span:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; }

#loadingMessage {
  color: rgba(255, 255, 255, 0.8);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.95rem;
}

#output {
  margin-top: 0.75rem;
}

/* -------------------------------------------------------------- voucher -- */

.voucher-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
}

.voucher-head__title {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0;
}

.voucher-head__sub {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0.2rem 0 0;
}

.voucher-code {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.2rem 0.6rem;
  border-radius: 8px;
  background: var(--brand-blue-050);
  color: var(--brand-blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  word-break: break-all;
}

.voucher-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--surface-muted);
}

.voucher-row:last-child {
  border-bottom: 0;
}

.voucher-row .label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  flex: 0 0 auto;
}

.voucher-row .value {
  text-align: right;
  font-weight: 600;
}

/* Remaining / total — the number staff act on. */
.counter-tile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 5px solid var(--brand-yellow);
  border-radius: var(--radius-control);
  background: var(--surface-muted);
}

.counter-tile__label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.counter-tile__value {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.counter-tile__value small {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

/* Status pills --------------------------------------------------------- */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-purchased { background: var(--brand-blue-050); color: var(--brand-blue); }
.status-used      { background: var(--ok-bg); color: var(--ok); }
.status-expired,
.status-partially_redeemed_expired { background: var(--danger-bg); color: var(--danger); }
.status-flexi_unused { background: var(--warn-bg); color: var(--warn); }

/* ---------------------------------------------------------- subtickets -- */

.subticket-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.child-ticket-summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 0.9rem 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.child-ticket-summary:hover {
  border-color: #c7cee0;
  box-shadow: 0 4px 14px rgba(20, 22, 31, 0.07);
}

.child-ticket-summary__body {
  flex: 1 1 auto;
  min-width: 0;
}

.child-ticket-summary__title {
  font-weight: 700;
  line-height: 1.3;
}

.child-ticket-summary__sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.child-ticket-summary__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.45rem;
}

.qty-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.child-ticket-summary button[name="select"] {
  flex: 0 0 auto;
  min-height: var(--tap);
  min-width: 92px;
  font-weight: 700;
  border-radius: var(--radius-control);
}

/* ------------------------------------------------- subticket confirm --- */

/* Names what the next tap will redeem, above the item's own details. */
.confirm-callout {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand-blue-800);
  background: var(--surface-muted);
  animation: fade-in 0.15s ease-out;
}

.confirm-callout__eyebrow {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-blue-800);
}

.confirm-callout__hint {
  font-size: 0.875rem;
  color: var(--muted);
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ actions --- */

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 1.75rem -1.5rem -1.5rem;
  padding: 0.9rem 1.5rem calc(0.9rem + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

/* Secondary action beside the primary one, so neither can end up underneath the
   sticky bar. The primary takes whatever width is left. */
.action-bar--split {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
}

.action-bar--split .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-bar--split .btn-quiet {
  flex: 0 0 auto;
  padding-inline: 1.15rem;
}

.action-bar--split .btn-redeem {
  flex: 1 1 auto;
}

/* Nothing to redeem: the back button is the only control, so it takes the bar. */
.action-bar--split .btn-quiet:only-of-type {
  flex: 1 1 auto;
}

@media (max-width: 575.98px) {
  .action-bar {
    margin: 1.75rem -1.15rem -1.15rem;
    padding-inline: 1.15rem;
  }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.25rem 0;
}

/* inline-flex so the label sits centred in a button taller than its text — an
   <a class="btn"> is inline-block and would otherwise ride the top edge. */
.form-actions .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding-inline: 1.15rem;
  font-weight: 700;
}

/* --------------------------------------------------------------- flash --- */

.flash-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
  line-height: 1.4;
  box-shadow: var(--shadow-card);
}

.flash-alert__icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
}

.flash-alert__body {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
}

/* Bootstrap pins .alert-dismissible .btn-close absolutely and reserves 3rem of
   padding for it. This alert is a flex row, so the button is a normal item in
   it: small glyph, round hover target, aligned with the first line of text. */
.flash-alert.alert-dismissible {
  padding-right: 1rem;
}

.flash-alert .btn-close {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  width: 1.6rem;
  height: 1.6rem;
  margin: -0.1rem -0.25rem 0 0;
  padding: 0;
  border-radius: 50%;
  background-size: 0.6rem 0.6rem;
  opacity: 0.45;
  transition: opacity 0.15s ease, background-color 0.15s ease;
}

/* Keeps the glyph small but the tap area near the 44px the rest of the terminal
   uses — the visible circle stays 26px, the hit box is ~40px. */
.flash-alert .btn-close::after {
  content: "";
  position: absolute;
  inset: -0.45rem;
}

.flash-alert .btn-close:hover {
  opacity: 0.9;
  background-color: rgba(0, 0, 0, 0.06);
}

.flash-alert .btn-close:focus-visible {
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(19, 19, 71, 0.18);
}

/* Support reference: the trace id of this refusal's debug.log entry. */
.flash-alert__ref {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  opacity: 0.9;
}

.flash-alert__ref-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: inherit;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 6px;
  padding: 0.1rem 0.45rem;
  /* One tap selects the whole id — staff read it out or paste it into a report. */
  user-select: all;
  -webkit-user-select: all;
}

.flash-alert__ref-hint {
  opacity: 0.75;
}

@media (max-width: 480px) {
  .flash-alert__ref-hint {
    display: none;
  }
}

.flash-alert.alert-success { background: var(--ok-bg); border-color: rgba(15, 122, 61, 0.25); color: #0a4f28; }
.flash-alert.alert-danger  { background: var(--danger-bg); border-color: rgba(179, 38, 30, 0.25); color: #8c1c16; }
.flash-alert.alert-warning { background: var(--warn-bg); border-color: rgba(178, 106, 0, 0.25); color: #7c4a00; }
.flash-alert.alert-info    { background: var(--info-bg); border-color: rgba(19, 19, 71, 0.2); color: var(--brand-blue-800); }

/* --------------------------------------------------------------- login --- */

.auth-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 1rem calc(2rem + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 70% at 50% 0%, #23236b 0%, var(--brand-blue) 45%, var(--brand-blue-900) 100%);
}

.auth-shell__brand {
  margin-bottom: 1.75rem;
}

.auth-shell__brand .brand-logo {
  height: 46px;
  max-width: 78vw;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-shell__foot {
  margin-top: 1.5rem;
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.82rem;
  text-align: center;
}

/* --------------------------------------------------------------- error --- */

.error-shell {
  max-width: 620px;
  margin: 0 auto;
  padding: 3rem 1rem;
}

.error-shell h1,
.error-shell h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.error-shell .error {
  color: var(--danger);
}

/* ------------------------------------------------------------- utility --- */

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