/* ==========================================================================
   mikr.app — the transactional pages: checkout.html and upgrade.html.
   Loaded after tokens.css and base.css. Names no colour and no spacing value.

   These two pages are the "Transactional" family in design.md: a brand bar,
   no menu, no footer. They follow the reader's stored theme like every other
   page but carry no switch of their own.

   The payment form is a Stripe iframe and follows neither theme — its colours
   come from the Stripe Dashboard. It is a white card today, so the payment
   side here is a plain ground in both themes and lets that card be the card.

   Class names here are load-bearing. Each page's script creates elements with
   .option, .option-title, .option-sub, .option-price, .btn, .status, .loading
   and .spinner, and toggles .open, .show, .error and .hidden. Renaming any of
   them drops behaviour silently.
   ========================================================================== */

/* ---------- the bar. Static, not the site's fixed nav: these pages are one
     task each, and a bar that follows the reader is a bar that offers exits. */
.pay-bar {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.pay-bar__inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-md); min-height: var(--nav-h);
}
.pay-back {
  display: inline-flex; align-items: center; gap: var(--space-3xs);
  color: var(--ink-2); font-size: var(--text-base);
  transition: color var(--dur-short) var(--ease-out);
}
.pay-back:hover { color: var(--ink); text-decoration: none; }
.pay-back svg { width: 16px; height: 16px; }

/* ---------- checkout: summary and payment form, side by side ---------- */
.pay-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  max-width: 1100px; margin-inline: auto;
  min-height: calc(100vh - var(--nav-h));
}
.pay-summary { padding: var(--space-xl) var(--space-lg); }
/* The payment side is its own ground, and it runs to the edge of the window:
   the pseudo-element carries the same background past the grid's max-width so
   the panel does not end in a stripe of body colour. body has overflow-x:clip,
   so the 100vw cannot open a scrollbar. */
.pay-form {
  position: relative;
  padding: var(--space-xl) var(--space-lg);
  background: var(--paper-2);
  border-left: 1px solid var(--rule);
}
.pay-form::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 100%; width: 100vw;
  background: var(--paper-2);
}
.pay-summary__title {
  text-transform: uppercase;
  margin-bottom: var(--space-lg);
}

.product {
  display: flex; gap: var(--space-sm); align-items: center;
  margin-bottom: var(--space-md);
}
.product__mark {
  width: 2.75rem; height: 2.75rem; flex: 0 0 auto;
  border-radius: var(--radius-control);
  display: grid; place-items: center;
  background: var(--accent-fill); color: var(--accent-ink);
}
.product__mark svg { width: 24px; height: 24px; }
.product__name { display: block; font-size: var(--text-md); font-weight: 600; letter-spacing: -0.02em; }
.product__tier { display: block; color: var(--ink-2); }
.product__desc {
  color: var(--ink-2); max-width: 54ch;
  margin-bottom: var(--space-md);
}

.includes { list-style: none; margin-bottom: var(--space-lg); }
.includes li {
  display: flex; align-items: flex-start; gap: var(--space-2xs);
  padding-block: var(--space-3xs);
}
.includes svg { flex: 0 0 auto; width: 16px; height: 16px; color: var(--ok); margin-top: 0.22em; }

/* ---------- discount ---------- */
.discount { padding-top: var(--space-md); border-top: 1px solid var(--rule); }
.discount-toggle {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: var(--text-sm); color: var(--ink-2);
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px;
  transition: color var(--dur-short) var(--ease-out);
}
.discount-toggle:hover { color: var(--ink); }

.discount-form { display: none; gap: var(--space-2xs); margin-top: var(--space-2xs); }
.discount-form.open { display: flex; }
.discount-form input {
  flex: 1 1 auto; min-width: 0;
  font-family: var(--font-mono); font-size: var(--text-sm); text-transform: uppercase;
  color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: var(--radius-control);
  padding: var(--space-2xs) var(--space-xs);
}
.discount-form input::placeholder { color: var(--ink-3); }
.discount-form input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--rule-2); }
.discount-form .btn { flex: 0 0 auto; font-size: var(--text-base); }

.discount-status { margin-top: var(--space-2xs); font-size: var(--text-sm); min-height: 1.4em; color: var(--ink-2); }
.discount-status.error { color: var(--danger); }

.discount-applied {
  display: none; align-items: center; justify-content: space-between;
  gap: var(--space-xs); margin-top: var(--space-2xs);
  padding: var(--space-2xs) var(--space-xs);
  font-size: var(--text-sm); color: var(--ok);
  border: 1px solid color-mix(in oklch, var(--ok) 40%, transparent);
  border-radius: var(--radius-control);
  background: color-mix(in oklch, var(--ok) 12%, transparent);
}
.discount-applied.show { display: flex; }
.discount-applied .remove-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: var(--text-xs); color: var(--ink-2);
  text-decoration: underline; text-underline-offset: 3px;
}
.discount-applied .remove-link:hover { color: var(--danger); }

/* ---------- a note, not a state: neutral by the alerts decision in design.md,
     where an accent panel is reserved for things a reader can click. ---------- */
.pay-note {
  display: flex; gap: var(--space-2xs);
  margin-top: var(--space-md); padding: var(--space-xs);
  font-size: var(--text-sm); color: var(--ink-2);
  background: var(--paper-2);
  border: 1px solid var(--rule); border-left: 2px solid var(--rule-2);
  border-radius: var(--radius-control);
}
.pay-note svg { flex: 0 0 auto; width: 16px; height: 16px; color: var(--ink-2); margin-top: 0.22em; }
.pay-note strong { color: var(--ink); font-weight: 600; }

/* ---------- the money. The rows are shown and hidden by the hidden attribute,
     so the attribute selector below has to outrank the class that lays them
     out: an author display value beats the browser's own [hidden] rule. ---------- */
.pay-lines { margin-top: var(--space-md); padding-top: var(--space-md); border-top: 1px solid var(--rule); }
.pay-line {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-sm); padding-block: var(--space-3xs);
  color: var(--ink-2); font-size: var(--text-base);
}
.pay-line[hidden] { display: none; }
.pay-line .amount { color: var(--ink); font-variant-numeric: tabular-nums; }
.pay-line--sub .amount { color: var(--ink-3); text-decoration: line-through; }
.pay-line--off, .pay-line--off .amount { color: var(--ok); }
.pay-line--total {
  margin-top: var(--space-2xs); padding-top: var(--space-2xs);
  border-top: 1px solid var(--rule);
  color: var(--ink); font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.02em;
}
.pay-line--total .amount { font-weight: 700; }

.pay-meta {
  display: flex; align-items: flex-start; gap: var(--space-2xs);
  margin-top: var(--space-md); font-size: var(--text-xs); color: var(--ink-2); line-height: 1.55;
}
.pay-meta svg { flex: 0 0 auto; width: 14px; height: 14px; margin-top: 0.2em; }
.pay-meta a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; }
.pay-meta a:hover { color: var(--ink); }

.error-msg {
  display: none;
  margin-top: var(--space-md); padding: var(--space-xs);
  font-size: var(--text-sm); color: var(--danger);
  border: 1px solid color-mix(in oklch, var(--danger) 40%, transparent);
  border-radius: var(--radius-control);
  background: color-mix(in oklch, var(--danger) 10%, transparent);
}

/* ---------- where Stripe mounts ---------- */
#checkout { width: 100%; min-height: 25rem; }
.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-sm); height: 18.75rem;
  color: var(--ink-2); font-size: var(--text-base);
}
.spinner {
  width: 2rem; height: 2rem; border-radius: 50%;
  border: 3px solid var(--rule); border-top-color: var(--accent);
  animation: pay-spin 0.8s linear infinite;
}
@keyframes pay-spin { to { transform: rotate(360deg); } }
/* base.css clamps every animation to 1ms under reduced motion, which would
   leave a frozen ring on the page. Drop the ring instead; the words stay. */
@media (prefers-reduced-motion: reduce) { .spinner { display: none; } }

/* ==========================================================================
   upgrade.html — one column, three phases in the same card slot
   ========================================================================== */
.pay-column { max-width: 38rem; margin-inline: auto; padding-block: var(--space-xl) var(--space-2xl); }
.pay-column h1 { font-size: var(--text-xl); margin-bottom: var(--space-2xs); }
.pay-column .lede { margin-bottom: var(--space-lg); }

.card {
  background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: var(--radius-card);
  padding: var(--space-md);
}
.hidden { display: none !important; }

.field-label { display: block; font-size: var(--text-sm); color: var(--ink-2); margin-bottom: var(--space-2xs); }
textarea#token {
  width: 100%; min-height: 6rem; resize: vertical;
  font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.5;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--radius-control);
  padding: var(--space-2xs) var(--space-xs);
  word-break: break-all;
}
textarea#token::placeholder { color: var(--ink-3); }
textarea#token:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--rule-2); }

/* The script builds buttons with class="btn" alone, so inside a card .btn has
   to read as the primary control. .btn.secondary follows, and wins by order. */
.card .btn { background: var(--accent-fill); color: var(--accent-ink); justify-content: center; }
.card .btn:hover:not(:disabled) { background: var(--accent-fill-2); text-decoration: none; }
.card > .btn { width: 100%; margin-top: var(--space-sm); }
.card .btn.secondary {
  background: transparent; color: var(--ink); border-color: var(--rule-2);
}
.card .btn.secondary:hover:not(:disabled) { background: var(--hover); border-color: var(--ink-2); }

.status { margin-top: var(--space-2xs); font-size: var(--text-sm); min-height: 1.4em; color: var(--ink-2); }
.status.error { color: var(--danger); }

.current { color: var(--ink-2); margin-bottom: var(--space-sm); }
.current b { color: var(--ink); font-weight: 600; }

.option {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-sm); margin-bottom: var(--space-2xs);
  padding: var(--space-xs); border: 1px solid var(--rule); border-radius: var(--radius-control);
}
.option-title { font-weight: 600; color: var(--ink); }
.option-sub { font-size: var(--text-sm); color: var(--ink-2); margin-top: var(--space-3xs); }
/* min-width, because the script emits the price and the button as siblings in
   one flex row: without a floor the three prices land at three x positions. */
.option-price {
  font-size: var(--text-md); font-weight: 700; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  min-width: 4rem; text-align: right;
}
.option .btn { font-size: var(--text-base); padding: var(--space-2xs) var(--space-sm); min-height: 2.5rem; }

/* ---------- narrow screens ---------- */
@media (max-width: 62rem) {
  .pay-grid { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .pay-form { border-left: 0; border-top: 1px solid var(--rule); }
  .pay-form::after { content: none; }
}
@media (max-width: 40rem) {
  .pay-summary, .pay-form { padding: var(--space-lg) 0; }
  .pay-summary { padding-inline: var(--gutter); }
  .pay-form { padding-inline: var(--gutter); }
  .pay-grid { max-width: none; }
  .option { flex-direction: column; align-items: stretch; }
  .option .btn { width: 100%; }
  .pay-brand .brand__name { font-size: var(--text-sm); }
}
