/* ============================================================================
   YEMMA — THE SAMPLE CREDIT, FOUND
   Where the bag is added up: the note in the checkout's address step, its
   compact twin above the bag page's total, the line under the drawer's
   subtotal, and the summary row the credit prints as. Drawn by
   `Swatches\CreditCheckout`; the row's label is `SwatchCredit::label()`.

   Loaded on every front page, because the drawer is on every front page and a
   rug added over AJAX can bring the credit into it without a reload. So it is
   small, and it styles nothing but its own blocks.

   Every colour is a theme token. Two are mixed rather than used neat, and the
   reason is contrast, not taste: --muted on --bone-2 is 3.5:1 and --ok is
   4.2:1, both short of what an 11px label or a figure needs. The mixes keep the
   hue and reach 5:1. A browser without color-mix() falls back to the neat
   token, which is the theme's own choice everywhere else.
   ========================================================================== */

.crednote,
.credline,
.credrow {
  --cred-quiet: var(--muted);
  --cred-found: var(--ok);
}

/* Behind @supports and not as a second declaration: a custom property is never
   rejected when it is parsed, so the second line would always win — and in a
   browser that cannot mix, the colour would then be dropped, not fall back. */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  .crednote,
  .credline,
  .credrow {
    --cred-quiet: color-mix(in srgb, var(--muted) 60%, var(--ink-3));
    --cred-found: color-mix(in srgb, var(--ok) 85%, var(--ink));
  }
}

/* ------------------------------------------------------------- THE NOTE --- */
/* The checkout's, under the billing fields. A brass rule on the alternate
   ground — the shop's own way of saying something it wants read, the way
   `.wait__moved` and the thank-you page's gateway box do — and never an alert:
   nothing here is wrong. */
.crednote {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .9rem;
  margin-top: 1.4rem;
  padding: 1rem 1.15rem 1rem 1rem;
  background: var(--bone-2);
  border-left: 2px solid var(--brass);
  font-size: .88rem;
  line-height: 1.6;
  color: var(--ink-3);
}

/* Still printed when there is nothing to say — a fragment must exist to be
   replaced — and taking no room at all. */
.crednote--none { display: none; }

.crednote__seal {
  display: block;
  width: 34px;
  height: 34px;
  color: var(--brass);
}
.crednote__seal svg { display: block; width: 100%; height: 100%; }

.crednote__t { margin: 0; max-width: 62ch; }

/* The greeting, in the voice of the headings. */
.crednote__hi {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 500;
  font-size: 1.14em;
  color: var(--ink);
}

/* The money, in the serif every figure in this shop is set in — a size up,
   because Cormorant's small x-height reads a size down beside Jost, and with
   lining figures, because its old-style ones sink below a sans sentence and
   "$ 20.00" read smaller than the "$ 3,000.00" set beside it. */
.crednote__fig,
.crednote__gap {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.14em;
  font-variant-numeric: lining-nums;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

/* Found money wears the colour every discount here wears. */
.crednote--ok .crednote__fig { color: var(--cred-found); }

/* What is left to spend is the one figure worth reaching for. */
.crednote__gap { color: var(--clay); }

/* Arriving. `is-new` is given by the theme's checkout script, and only when the
   note says something different from what the page showed before — never on
   the refresh WooCommerce runs as the page loads, which replaces every fragment
   whether it changed or not. The note slides up; the seal is pressed on. */
@keyframes crednote-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@keyframes crednote-stamp {
  0%   { opacity: 0; transform: scale(1.4) rotate(-18deg); }
  55%  { opacity: 1; transform: scale(.92) rotate(3deg); }
  100% { opacity: 1; transform: none; }
}

.crednote.is-new { animation: crednote-in .55s var(--ease-out) both; }
.crednote.is-new .crednote__seal { animation: crednote-stamp .75s var(--ease-out) .15s both; }

/* The compact twin, above the bag page's total: the near miss only. */
.crednote--compact {
  gap: .7rem;
  margin: .5rem 0 .5rem;
  padding: .75rem .85rem .75rem .8rem;
  font-size: 12px;
  line-height: 1.55;
}
.crednote--compact .crednote__seal { width: 24px; height: 24px; }

/* ---------------------------------------------------------- THE DRAWER --- */
/* Under the subtotal, in the drawer's own figures. The drawer foot is already
   on the alternate ground, so the near miss keeps the rule and drops the
   ground rather than vanishing into it. */
.credline--ok {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 .5rem;
}

.credline__l {
  display: inline-flex;
  align-items: center;
  gap: .6em;
  font-size: 11px;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--cred-quiet);
}

/* The seal's lozenge, small: the same mark as the summary row. */
.credline__l::before {
  content: "";
  flex: none;
  width: 6px;
  height: 6px;
  border: 1px solid var(--brass);
  transform: rotate(45deg);
}

.credline__fig {
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1;
  color: var(--cred-found);
  white-space: nowrap;
}

.credline--below {
  margin: .45rem 0 .9rem;
  padding: .1rem 0 .1rem .75rem;
  border-left: 2px solid var(--brass);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-3);
}

.credline--below .credline__fig,
.credline__gap {
  font-family: var(--serif);
  font-size: 1.2em;
  font-weight: 500;
  font-variant-numeric: lining-nums;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

.credline__gap { color: var(--clay); }

/* ------------------------------------------------------ THE SUMMARY ROW --- */
/* `SwatchCredit::label()` prints the name and, under it, where it came from.
   One rule for both summaries — the bag page's `.sum__row` and the checkout's
   review table — so the row reads the same on the way to paying as in the bag.
   A grid, so the second line sits under the words rather than under the mark. */
.credrow {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: .55em;
  align-items: baseline;
}

.credrow::before {
  content: "";
  align-self: center;
  width: 6px;
  height: 6px;
  border: 1px solid var(--brass);
  transform: rotate(45deg);
}

/* Two classes, because the bag's own `.sum__row small` is one class and an
   element, and sets the colour this sheet needs to darken. */
.credrow .credrow__sub {
  grid-column: 2;
  display: block;
  margin-top: .15rem;
  font-family: var(--sans);
  font-size: 10.5px;
  line-height: 1.45;
  letter-spacing: .02em;
  text-transform: none;
  color: var(--cred-quiet);
}

/* The figure never breaks from its minus sign. */
.cart-discount--credit td { white-space: nowrap; }

/* The bag page's figure, in the colour every discount here wears. bag.css
   inks `.sum__row span:first-child` for the row's label, and the price
   WooCommerce prints inside the figure's `.free` is a first child too — so
   the credit showed its minus sign in green and "$ 20.00" in ink. Found by
   its label, because the bag's rows carry no class; a browser without :has()
   keeps the theme's colour, as every other coupon there does. */
.sum__row:has(.credrow) .free .woocommerce-Price-amount { color: inherit; }

/* ---------------------------------------------------------------- MOTION -- */
@media (prefers-reduced-motion: reduce) {
  .crednote.is-new,
  .crednote.is-new .crednote__seal { animation: none; }
}

/* Under the email field, inside the address step's two-column grid: the note
   spans both columns, and while it is empty it gives back the grid's row gap so
   the form does not open a hole between the email and the name. */
.cform > .crednote-live { grid-column: 1 / -1; }
.cform > .crednote-live:has(.crednote--none) { margin-top: -1.1rem; }
