/*
 * card.css -- the rewards card sheet.
 *
 * Follows the prefs/rating bottom-sheet pattern and takes every colour from
 * base.css tokens, with ONE deliberate exception documented at .cd-face: the
 * card face itself is theme-independent. That is not palette drift, it is the
 * point -- see the comment there before "fixing" it to use --surface.
 */

.cd-backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}

.cd-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92%;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}

.cd-close {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.cd-title {
  margin: 0 var(--tap) 2px 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}

.cd-brands {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- the card face ----------
 * INTENTIONALLY not themed. This is a surface a scanner reads and a surface you
 * read digits off in a dim car at night, so it is white with near-black digits
 * in BOTH light and dark mode. There is no web API for screen brightness, so a
 * full-width maximum-contrast panel is the real equivalent -- and rendering it
 * dark to "respect the theme" would make the one job it has harder. Hardcoded
 * rather than tokenised because a token would re-theme it, which is the bug.
 */
.cd-face {
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 14px 14px;
  text-align: center;
}

.cd-digits {
  display: block;
  width: 100%;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: #101317;
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas,
    'Liberation Mono', monospace;
  font-size: clamp(24px, 8vw, 38px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  line-height: 1.25;
  word-break: break-all;
  cursor: pointer;
}

.cd-copyhint {
  margin: 8px 0 0;
  font-size: 12px;
  color: #5b6470; /* fixed: lives on the always-white face, not on --surface */
}

.cd-copyhint.is-flash {
  color: var(--tier-great);
  font-weight: 600;
}

/* ---------- barcode ----------
 * Lives inside the always-white .cd-face, below the digits: the digits are the
 * pump (no scanner there), the barcode is the register inside.
 */
.cd-barcode:not(:empty) {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.cd-barcode-svg {
  display: block;
  width: 100%;
  /* Tall enough for a counter scanner to get a clean read at arm's length. */
  height: 72px;
}

.cd-bc-fail {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: #8a3a33; /* fixed: sits on the always-white face, not on --surface */
}

.cd-fmt {
  margin: 12px 2px 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

/* ---------- actions ---------- */
.cd-actions,
.cd-formactions {
  display: flex;
  gap: var(--gap);
  margin-top: 18px;
}

.cd-btn {
  flex: 1;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.cd-btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.cd-btn--danger {
  color: var(--tier-poor);
  border-color: var(--tier-poor);
  background: var(--tier-poor-soft);
}

/* ---------- scanning ---------- */
.cd-scanbtn {
  width: 100%;
  min-height: var(--tap);
  margin-bottom: 4px;
}

/* "or type it in" rule -- a divider, not a heading */
.cd-or {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 12px;
  color: var(--text-faint);
}
.cd-or::before,
.cd-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.cd-scan {
  position: relative;
  width: 100%;
  /* A loyalty barcode is wide and short; a letterbox frame matches how the card
     is actually held and keeps the bars filling the sensor width. */
  aspect-ratio: 5 / 3;
  overflow: hidden;
  border-radius: var(--radius);
  background: #000; /* fixed: this is a camera viewport, not a themed surface */
}

.cd-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Aiming guide. Purely decorative -- detection uses the whole frame, so this
   must never imply the barcode has to sit exactly inside it. */
.cd-reticle {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 30%;
  bottom: 30%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 6px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.28);
}

.cd-scanmsg {
  margin: 12px 2px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
}

@media (prefers-reduced-motion: reduce) {
  .cd-reticle { transition: none; }
}

/* ---------- entry form ---------- */
.cd-form {
  margin: 0;
}

.cd-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.cd-input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  /* 16px minimum or iOS Safari zooms the viewport on focus. */
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.cd-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.cd-input.is-bad {
  border-color: var(--tier-poor);
}

.cd-hint {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

.cd-privacy {
  margin: 10px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--tier-great);
}

/* ---------- the station-detail entry point ----------
 * Both card entry points live in THIS file rather than beside their host
 * components, so the whole feature is reviewable and removable in one place --
 * same reason .pf-rw-card is here. The one rule that reaches back into another
 * component is the flex layout below: rewards.css owns .ps-dt-rewards--member
 * as a plain text line, and this turns it into a row with the button on the
 * right. card.css is loaded AFTER rewards.css in index.html, so this wins
 * deterministically -- keep that order if you reorder the <link> tags.
 */
.ps-dt-rewards--member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.ps-dt-rewards-earn {
  min-width: 0; /* let a long program name shrink rather than shove the button */
}

.ps-dt-card {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--brand);
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

/* Nothing stored yet: present but quieter than "Show card", which is the one
   you actually reach for at a counter. */
.ps-dt-card.is-empty {
  background: transparent;
  color: var(--brand);
}

/* ---------- backup block (prefs) ---------- */
.pf-bk {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.pf-bk-title {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.pf-bk-state {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
}

.pf-bk-msg {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tier-great);
}
.pf-bk-msg.is-bad { color: var(--tier-poor); }

.pf-bk-actions {
  display: flex;
  gap: var(--gap);
}

.pf-bk-btn {
  flex: 1;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.pf-bk-btn--go {
  width: 100%;
  flex: none;
  margin-top: 10px;
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.pf-bk-panel[hidden] { display: none; }

.pf-bk-panel {
  margin-top: 12px;
}

.pf-bk-warn {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--tier-ok);
}

.pf-bk-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.pf-bk-text {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  /* 16px minimum or iOS Safari zooms the viewport on focus. */
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.4;
  resize: vertical;
}

.pf-bk-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

/* ---------- the prefs-row entry point ---------- */
.pf-rw-card {
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}

.pf-rw-card.is-empty {
  color: var(--text-dim);
  font-weight: 500;
}
