/* dig2pay checkout card.
 * Mobile-first, one accent colour, system fonts only, no remote assets.
 * Palettes are resolved per theme here; a merchant token overrides exactly one
 * custom property through the CSSOM (theme.js), so no inline style is needed. */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  /* light palette (default) */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #111827;
  --muted: #556070;
  --accent: #2454d6;
  --accent-contrast: #ffffff;
  --danger: #b42318;
  --success: #067647;
  --warning: #8a5a00;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 6%);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --text: #e6edf3;
  --muted: #9aa7b5;
  --accent: #7aa2ff;
  --accent-contrast: #0b1020;
  --danger: #ff8a7a;
  --success: #56d38b;
  --warning: #e3b341;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

/* Before the script resolves the theme (or when it cannot run) follow the OS. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #9aa7b5;
    --accent: #7aa2ff;
    --accent-contrast: #0b1020;
    --danger: #ff8a7a;
    --success: #56d38b;
    --warning: #e3b341;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

:root {
  --line: color-mix(in srgb, var(--text) 14%, var(--bg));
  --line-soft: color-mix(in srgb, var(--text) 9%, var(--surface));
  --well: color-mix(in srgb, var(--text) 5%, var(--surface));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

#sheet {
  max-width: 28rem;
  margin: 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.noscript {
  text-align: center;
  color: var(--muted);
}

/* ---- card ---------------------------------------------------------------- */

.card {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.demo {
  margin: 0;
  padding: 10px 12px;
  border: 1px dashed var(--warning);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warning) 10%, var(--surface));
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
}

/* ---- header: amount first ----------------------------------------------- */

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.head-main {
  min-width: 0;
}

.amount {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 0;
  font-weight: 700;
}

.amount-num {
  font-size: 2.25rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.amount-asset {
  color: var(--muted);
  font-size: 1.0625rem;
  font-weight: 600;
}

.amount-net {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.timer {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.timer-text {
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- network chips ------------------------------------------------------- */

.pay {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.chip-asset {
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.2;
}

.chip-net {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
}

.chip[aria-checked="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--accent);
}

.chip:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
}

.chip:focus-visible,
.btn:focus-visible,
.link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.warn {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--warning);
  border-radius: 4px var(--radius-sm) var(--radius-sm) 4px;
  background: color-mix(in srgb, var(--warning) 9%, var(--surface));
  color: var(--text);
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* ---- QR: always black on white for scan reliability ---------------------- */

.qr {
  width: 220px;
  height: 220px;
  margin: 0 auto;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

/* ---- address + copy ------------------------------------------------------ */

.addr {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.addr-text {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--well);
  font: 500 0.875rem/1.5 var(--font-mono);
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
}

.addr-short {
  display: none;
}

.addr-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 650;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:active {
  transform: translateY(1px);
}

.btn[data-copied] {
  background: var(--surface);
  color: var(--accent);
}

.btn-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.link {
  display: none;
  align-self: center;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Narrow: middle-ellipsis address with a tap to expand. The full text stays in
 * the accessibility tree (visually clipped) while the short form is shown. */
@media (max-width: 379px) {
  .addr[data-expanded="false"] .addr-full {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .addr[data-expanded="false"] .addr-short {
    display: inline;
  }

  .link {
    display: inline-flex;
    align-items: center;
  }
}

@media (min-width: 380px) {
  body {
    padding: 20px 16px;
  }

  .card {
    padding: 24px 22px;
  }

  .addr-actions {
    flex-direction: row;
  }

  .btn {
    flex: 1;
  }
}

/* ---- top-level return ---------------------------------------------------- */

.return {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.return[hidden],
.return-line[hidden] {
  display: none;
}

.return-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ---- status -------------------------------------------------------------- */

.status {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.status-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.status-icon {
  display: none;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.card[data-state="processing"] .status-dot,
.card[data-state="partial"] .status-dot {
  background: var(--warning);
}

.card[data-state="loading"] .status-dot {
  background: var(--muted);
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}

.progress-bar {
  display: block;
  width: calc(var(--p, 0) * 1%);
  height: 100%;
  border-radius: inherit;
  background: var(--warning);
}

/* Result states: paid, expired, invalid. */
.card[data-state="paid"] .status,
.card[data-state="expired"] .status,
.card[data-state="invalid"] .status {
  align-items: center;
  padding: 8px 0 4px;
  border-top: 0;
  text-align: center;
}

.card[data-state="paid"] .status-line,
.card[data-state="expired"] .status-line,
.card[data-state="invalid"] .status-line {
  flex-direction: column;
  gap: 14px;
  font-size: 1.25rem;
  line-height: 1.25;
}

.card[data-state="paid"] .status-dot,
.card[data-state="expired"] .status-dot,
.card[data-state="invalid"] .status-dot {
  display: none;
}

.card[data-state="paid"] .status-icon--ok,
.card[data-state="expired"] .status-icon--warn,
.card[data-state="invalid"] .status-icon--bad {
  display: block;
  width: 64px;
  height: 64px;
  padding: 16px;
  border-radius: 50%;
}

.card[data-state="paid"] .status-icon--ok {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 14%, var(--surface));
}

.card[data-state="expired"] .status-icon--warn {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
}

.card[data-state="invalid"] .status-icon--bad {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
}

.card[data-state="paid"] .head {
  justify-content: center;
  text-align: center;
}

.card[data-state="paid"] .amount {
  justify-content: center;
}

/* ---- loading skeleton ---------------------------------------------------- */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sk {
  display: block;
  border-radius: var(--radius-sm);
  background: var(--well);
}

.sk-a {
  width: 45%;
  height: 40px;
}

.sk-b {
  width: 100%;
  height: 44px;
}

.sk-c {
  width: 220px;
  max-width: 100%;
  height: 220px;
  margin: 0 auto;
}

/* ---- motion: state changes only, never decorative ------------------------ */

@media (prefers-reduced-motion: no-preference) {
  .chip,
  .btn,
  .progress-bar {
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, width 0.4s ease;
  }

  .card[data-state="new"] .status-dot {
    animation: pulse 2s ease-in-out infinite;
  }

  .card[data-state="processing"] .status-dot,
  .card[data-state="partial"] .status-dot {
    animation: pulse 1.2s ease-in-out infinite;
  }

  .card[data-state="paid"] .status-line,
  .card[data-state="expired"] .status-line,
  .card[data-state="invalid"] .status-line,
  .card[data-state="processing"] .status-text,
  .card[data-state="partial"] .status-text {
    animation: rise 0.32s ease-out both;
  }

  .card[data-state="paid"] .status-icon--ok path {
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: draw 0.45s 0.15s ease-out forwards;
  }

  .sk {
    animation: shimmer 1.6s ease-in-out infinite;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes shimmer {
  50% {
    opacity: 0.55;
  }
}

@media (forced-colors: active) {
  .chip[aria-checked="true"] {
    outline: 2px solid Highlight;
  }
}
