/* Parking payment page — mobile-first, built for a one-handed pass in a lot. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #131a26;
  --muted: #5c6675;
  --border: #dde3ec;
  --border-strong: #c3ccda;
  --accent: #1d4ed8;
  --accent-press: #1740b0;
  --accent-tint: #eaf0ff;
  --danger: #c0271c;
  --danger-tint: #fdeceb;
  --success: #0f7a55;
  --success-tint: #e6f5ef;
  --radius: 14px;
  --radius-lg: 18px;
  /* Page gutter, shared so the full-bleed pay bar lines up exactly. */
  --gutter: max(1rem, env(safe-area-inset-left), env(safe-area-inset-right));
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 10px 28px rgb(16 24 40 / 0.07);
  --pad: 1.125rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d111a;
    --surface: #161c27;
    --surface-2: #1d2430;
    --text: #eef1f6;
    --muted: #9aa5b4;
    --border: #2c3542;
    --border-strong: #3d4857;
    --accent: #2563eb;
    --accent-press: #1d4ed8;
    --accent-tint: #16233d;
    --danger: #ff8478;
    --danger-tint: #2c1614;
    --success: #34d399;
    --success-tint: #10261f;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.35), 0 10px 28px rgb(0 0 0 / 0.35);
  }
}

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

/* Several toggled elements set display themselves; [hidden] must still win. */
[hidden] { display: none !important; }

html {
  /* Never let a stray wide element sideways-scroll a checkout. */
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

a { color: var(--accent); }

.page {
  max-width: 27rem;
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.125rem 0.5rem;
}

.brand { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}

.brand-name {
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--success-tint);
  color: var(--success);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

/* ------------------------------------------------------------------ hero */

.hero {
  padding: 1.375rem var(--pad) 1.25rem;
  margin-bottom: 0.875rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.hero-eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero-amount {
  margin: 0.3rem 0 0.45rem;
  font-size: 2.75rem;
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
}

.hero-cur { font-size: 0.55em; font-weight: 650; vertical-align: 0.42em; margin-right: 0.06em; }
.hero-code {
  margin-left: 0.35rem;
  color: var(--muted);
  font-size: 0.28em;
  font-weight: 650;
  letter-spacing: 0.06em;
  vertical-align: 0.72em;
}

.hero-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
}

/* ----------------------------------------------------------------- groups */

.group {
  padding: 1rem var(--pad) 0.375rem;
  margin-bottom: 0.875rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.group-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.875rem;
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.005em;
}

.step {
  display: grid;
  place-items: center;
  width: 1.375rem;
  height: 1.375rem;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ----------------------------------------------------------------- fields */

.field { margin-bottom: 0.875rem; scroll-margin: 5rem 0 8rem; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.005em;
}

input {
  width: 100%;
  min-height: 3rem;
  padding: 0.7rem 0.85rem;
  font: inherit;
  /* 16px minimum stops iOS Safari zooming the page on focus. */
  font-size: max(16px, 1rem);
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder { color: var(--muted); opacity: 0.55; }

input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* Plate reads like a plate: wide, uppercase, evenly spaced. */
.plate-input {
  font-weight: 650;
  font-size: max(18px, 1.125rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.plate-input::placeholder { letter-spacing: 0.14em; font-weight: 500; }

/* CVV stays type=text so iOS honours inputmode=numeric; mask it visually. */
input.masked { -webkit-text-security: disc; text-security: disc; }

.input-affix { position: relative; }
.input-affix input { padding-right: 3.5rem; }

.brand-badge {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 1.5rem;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}
.brand-badge.on { opacity: 1; }
.brand-badge svg { display: block; width: 100%; height: 100%; }

.hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.755rem;
  line-height: 1.4;
}

.error {
  margin: 0;
  max-height: 0;
  overflow: hidden;
  color: var(--danger);
  font-size: 0.78rem;
  line-height: 1.4;
  transition: max-height 0.15s ease-out;
}

.field.invalid input {
  border-color: var(--danger);
  background: var(--danger-tint);
}
.field.invalid input:focus {
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--danger) 20%, transparent);
}
.field.invalid .hint { display: none; }
.field.invalid .error { max-height: 4rem; margin-top: 0.35rem; }

.field.valid input { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); }

/* "?" affordance next to the CVV label — small dot, 44px hit area. */
.help {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.05rem;
  height: 1.05rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font: 700 0.68rem/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.help::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}
.help:hover { background: var(--border-strong); }

/* Returning-parker banner */
.remembered {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  margin: -0.25rem 0 0.875rem;
  color: var(--muted);
  font-size: 0.78rem;
}
.remembered button {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  text-decoration: underline;
  cursor: pointer;
}

/* ----------------------------------------------------------------- alerts */

.alert {
  margin: 0 0 0.875rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--danger-tint);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  color: var(--danger);
  font-size: 0.86rem;
  line-height: 1.45;
}
.alert a { color: inherit; }

/* --------------------------------------------------------------- pay bar */

.paybar {
  position: sticky;
  /* -1px so an IntersectionObserver can tell "pinned" from "reached its place". */
  bottom: -1px;
  z-index: 5;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0.75rem var(--gutter) calc(0.625rem + 1px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: box-shadow 0.2s, border-color 0.2s;
  border-top: 1px solid transparent;
}

.paybar.stuck {
  border-top-color: var(--border);
  box-shadow: 0 -8px 24px -12px rgb(16 24 40 / 0.25);
}

#pay-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 3.5rem;
  padding: 0 3rem;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font: 700 1.0625rem/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.08s;
}

#pay-btn:hover { background: var(--accent-press); }
#pay-btn:active { transform: scale(0.985); }
#pay-btn:disabled { cursor: default; opacity: 0.9; }
#pay-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-spinner {
  position: absolute;
  right: 1.125rem;
  top: 50%;
  width: 1.15rem;
  height: 1.15rem;
  margin-top: -0.575rem;
  border: 2.5px solid rgb(255 255 255 / 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  opacity: 0;
  animation: spin 0.7s linear infinite;
}
#pay-btn.loading .btn-spinner { opacity: 1; }

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

.trust {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.755rem;
}

/* Extra context below the fold — never competes with the button. */
.reassure {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.775rem;
  line-height: 1.55;
  text-align: center;
}

/* ---------------------------------------------------------------- receipt */

.receipt {
  padding: 2rem var(--pad) 1.5rem;
  margin-top: 0.5rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.check {
  display: grid;
  place-items: center;
  width: 3.75rem;
  height: 3.75rem;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: var(--success-tint);
  color: var(--success);
}

.check-path {
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
  animation: draw 0.45s 0.1s ease-out forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.receipt h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 720;
  letter-spacing: -0.02em;
}

.receipt-lede {
  margin: 0 0 1.375rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.receipt-rows {
  margin: 0 0 1.25rem;
  padding: 0.25rem 0.9rem;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: left;
}

.receipt-rows > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.receipt-rows > div:last-child { border-bottom: 0; }

.receipt-rows dt {
  flex: none;
  color: var(--muted);
  font-size: 0.8rem;
}
.receipt-rows dd {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  letter-spacing: 0.02em;
}
.strong { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.06em; }

.receipt-tip {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.ghost-btn {
  width: 100%;
  min-height: 2.875rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: 650 0.9375rem/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.ghost-btn:hover { background: var(--surface-2); }

/* ----------------------------------------------------------------- footer */

.pagefoot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.25rem 0 calc(1.25rem + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.78rem;
}
.pagefoot a { padding: 0.375rem 0.25rem; color: var(--muted); text-decoration: none; }
.pagefoot a:hover { text-decoration: underline; }

/* ------------------------------------------------------------- CVV sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(9 12 20 / 0.45);
  animation: fade 0.15s ease-out;
}

.sheet-panel {
  width: min(27rem, 100%);
  padding: 1.375rem var(--pad) calc(1.125rem + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  animation: rise 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet-panel h2 { margin: 0 0 0.6rem; font-size: 1.0625rem; font-weight: 700; }
.sheet-panel p { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.875rem; line-height: 1.5; }
.sheet-panel strong { color: var(--text); }

#cvv-sheet-close {
  width: 100%;
  min-height: 2.875rem;
  margin-top: 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: 650 0.9375rem/1 inherit;
  cursor: pointer;
}

/* One focus ring for every control, so nothing falls back to the UA default. */
.help:focus-visible,
.ghost-btn:focus-visible,
.remembered button:focus-visible,
#cvv-sheet-close:focus-visible,
.pagefoot a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }

/* ---------------------------------------------------------------- tablet+ */

@media (min-width: 30rem) {
  .page { padding-top: 1.5rem; }
  .hero { padding: 1.75rem var(--pad) 1.5rem; }
  .hero-amount { font-size: 3rem; }
}

/* Very narrow phones (SE and below): stop the 2-up row from cramping. */
@media (max-width: 20.5rem) {
  .row { grid-template-columns: 1fr; gap: 0; }
  .hero-amount { font-size: 2.375rem; }
}

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

@media (prefers-contrast: more) {
  input { border-color: var(--border-strong); }
  .hint, .trust, .reassure { color: var(--text); }
}
