/* Menomentis — paying (the brand book's Paying): the pay button and the plan
   sheet (src/editor/Plans.js), and what the credits went on — the bars of
   the past hour, week and month and the card over an answer's figure
   (src/editor/Spending.js) — loaded by the project and user pages after
   settings.css. Every value is a token from design-system/tokens.css; the
   green family is `pay`, and it stands nowhere else. */

/* ---------- The pay button ---------- */

/* The one control that takes a payment: filled in the green, its words on
   it, a hairline of its own light along its top edge and one of shade
   along its bottom, so it stands as a key does, and a soft glow under it
   in its own colour, so it stands lit — and nothing that moves. Under the
   pointer it answers: the glow rises and widens, in two layers, a close
   one and a far one, so it falls off as light does, and the edge lights in
   the green's light. Pressed, the fill sinks a step and the glow draws in
   with it. The glow is a shadow of the button itself, never a wrapper, so
   nothing around it shifts. */
.pay-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  margin: 0;
  border: var(--stroke-hairline) solid transparent;
  background: var(--pay);
  color: var(--on-pay);
  font-family: var(--font-sans);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  --pay-near: 0 0 10px -2px var(--pay-glow);
  --pay-far: 0 0 24px -10px var(--pay-glow);
  box-shadow:
    inset 0 var(--stroke-hairline) 0 color-mix(in srgb, var(--pay-light) 28%, transparent),
    inset 0 calc(-1 * var(--stroke-hairline)) 0 color-mix(in srgb, var(--pay-line) 75%, transparent),
    var(--pay-near),
    var(--pay-far);
  transition: border-color 160ms cubic-bezier(0.2, 0, 0, 1),
              background-color 140ms cubic-bezier(0.2, 0, 0, 1),
              color 140ms cubic-bezier(0.2, 0, 0, 1),
              box-shadow 240ms cubic-bezier(0.2, 0, 0, 1);
}

.pay-btn--md {
  min-height: 40px;
  padding: 0 var(--space-6);
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 21px;
}

/* A key of the settings panel: its height, its figures, square as the
   block it stands in, and a glow drawn in to its size. */
.pay-btn--key {
  height: var(--space-8);
  min-width: calc(var(--space-16) + var(--space-4));
  padding: 0 var(--space-3);
  border-radius: var(--radius-0);
  font-size: 13px;
  line-height: 19px;
  font-variant-numeric: tabular-nums;
  --pay-near: 0 0 8px -2px var(--pay-glow);
  --pay-far: 0 0 18px -8px var(--pay-glow);
}

.pay-btn__words {
  position: relative;
  z-index: 1;
}

/* Under the pointer, or with the keys: the edge lights, the glow rises. */
.pay-btn:hover:not(.pay-btn--quiet),
.pay-btn:focus-visible:not(.pay-btn--quiet) {
  border-color: color-mix(in srgb, var(--pay-light) 55%, transparent);
  --pay-near: 0 0 14px 0 var(--pay-glow);
  --pay-far: 0 0 40px 2px var(--pay-glow);
}

.pay-btn--key:hover:not(.pay-btn--quiet),
.pay-btn--key:focus-visible:not(.pay-btn--quiet) {
  --pay-near: 0 0 12px 0 var(--pay-glow);
  --pay-far: 0 0 30px 1px var(--pay-glow);
}

/* Pressed, the fill sinks one step, as a key goes down, and the glow
   draws in with it. */
.pay-btn:active:not(.pay-btn--quiet) {
  background: var(--pay-line);
  --pay-near: 0 0 10px -2px var(--pay-glow);
  --pay-far: 0 0 28px -6px var(--pay-glow);
}

.pay-btn:focus-visible {
  outline: var(--stroke-rule) solid var(--focus-ring);
  outline-offset: 2px;
}

/* Quiet: nothing to pay for, or Stripe's page being asked for. No green,
   no glow — a hairline ring holds its place, as Send's does. */
.pay-btn--quiet,
.pay-btn--quiet:active {
  border-color: var(--line-hairline);
  background: transparent;
  color: var(--ink-faint);
  box-shadow: none;
  cursor: default;
}

/* The keys to the sheet in the Credits block: Choose plan across its row,
   Upgrade plan beside the plan's name, as wide as the block's other side
   keys, so the displays beside them end on one line. */
.set-row__keys > .set-pay--wide {
  flex: 1 1 auto;
}

.set-group--credits .set-pay--side {
  flex: none;
  width: calc(var(--set-key) + var(--space-6));
}

/* ---------- What the credits went on ---------- */

/* A bar: what was spent in its period against what is left, filled from
   the left in ink-muted in a sunken well with a hairline edge; a share too
   small to see is drawn a rule wide, so a spend never vanishes. Square in
   the Credits block, as the block is. */
.spend-bar {
  position: relative;
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  box-sizing: border-box;
  height: var(--space-2);
  border: var(--stroke-hairline) solid var(--line-hairline);
  border-radius: var(--radius-xs);
  background: var(--bg-sunken);
  overflow: hidden;
}

.spend-bar__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  min-width: var(--stroke-rule);
  background: var(--ink-muted);
}

.set-group--credits .spend-bar {
  border-radius: var(--radius-0);
}

/* The figure spent, with its minus, in tabular figures, so the three end on
   one line — in the Credits block, the balance's. */
.spend-figure {
  flex: none;
  min-width: var(--space-16);
  color: var(--ink-strong);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* A row's bar and its figure, in the keys' column. */
.spend-line {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

/* An answer's figure in credits, a word pressed as a button: in the line's
   own colour, a hairline under its words under the pointer and while its
   card stands, a rule with the keys — never a fill, a frame or a ring. */
.spend-fig {
  flex: none;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  white-space: nowrap;
}

.spend-fig:hover,
.spend-fig--open {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: var(--stroke-hairline);
  text-underline-offset: 0.25em;
}

.spend-fig:focus-visible {
  outline: none;
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: var(--stroke-rule);
  text-underline-offset: 0.25em;
}

/* The card over it: soft and raised, as the chat's own panels are, since it
   lies over the conversation — the balance set large at its head, and
   under a hairline the three bars, their names, wells and figures each in
   a column of their own. */
.spend-card {
  position: fixed;
  z-index: 40;
  box-sizing: border-box;
  width: min(calc(var(--space-16) * 5), calc(100vw - 2 * var(--space-2)));
  border: var(--stroke-hairline) solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
  font-family: var(--font-sans);
  pointer-events: none;
  animation: app-arrive-down 120ms cubic-bezier(0.2, 0, 0, 1);
}

.spend-card--up {
  animation-name: app-arrive-up;
}

.spend-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.spend-card__balance {
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.spend-card__name {
  color: var(--ink-muted);
  white-space: nowrap;
}

.spend-card__bars {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: var(--stroke-hairline) solid var(--line-hairline);
}

.spend-card__row {
  display: contents;
}

.spend-card .spend-figure {
  min-width: 0;
}

/* ---------- The plan sheet ---------- */

/* A large soft card on the scrim, as the invitation to the goal interview
   is: raised, since it lies over the page. */
.pay-sheet {
  width: min(880px, 100% - var(--space-8));
  max-width: none;
  max-height: calc(100% - var(--space-8));
  margin: auto;
  padding: 0;
  overflow: auto;
  border: var(--stroke-hairline) solid var(--line-hairline);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  color: var(--ink);
  box-shadow: var(--shadow-raised);
  font-family: var(--font-sans);
}

.pay-sheet:focus-visible {
  outline: var(--stroke-rule) solid var(--focus-ring);
  outline-offset: 2px;
}

.pay-sheet::backdrop {
  background: var(--bg-scrim);
}

.pay-sheet__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-6);
}

/* The head: the title, the term's control at the right, the cross in the corner. */
.pay-sheet__head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--space-8);
  padding-right: var(--space-10);
}

.pay-sheet__title {
  flex: 1 1 auto;
  margin: 0;
  color: var(--ink-strong);
}

.pay-sheet__term-pick {
  flex: none;
}

.pay-sheet__close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
}

/* The packages, peers in one row from the least to the most: choice cards,
   the picked one filled solid. */
.pay-tiers {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
}

.pay-tier {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-4);
  border: var(--stroke-hairline) solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--ink);
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms cubic-bezier(0.2, 0, 0, 1),
              border-color 140ms cubic-bezier(0.2, 0, 0, 1);
}

.pay-tier:hover:not(.pay-tier--on) {
  background: var(--bg-hover);
  border-color: var(--line-strong);
}

.pay-tier:focus-visible {
  outline: var(--stroke-rule) solid var(--focus-ring);
  outline-offset: 2px;
}

.pay-tier--on {
  background: var(--select-solid);
  border-color: var(--select-solid);
  color: var(--ink-inverse);
  cursor: default;
}

/* Over the name, one line kept on every card — the badge where there is
   one, "Recommended" or "Current" — so the prices stand level across the row. */
.pay-tier__mark {
  display: flex;
  align-items: center;
  min-height: 20px;
}

.pay-tier__name {
  color: var(--ink-strong);
}

.pay-tier__price {
  margin-top: var(--space-2);
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
}

.pay-tier__term,
.pay-tier__use {
  color: var(--ink-muted);
}

.pay-tier__credits {
  margin-top: var(--space-2);
  color: var(--ink);
}

.pay-tier--on .pay-tier__name,
.pay-tier--on .pay-tier__price,
.pay-tier--on .pay-tier__term,
.pay-tier--on .pay-tier__credits,
.pay-tier--on .pay-tier__use {
  color: var(--ink-inverse);
}

/* The foot: the picked price large at the left, the one green at the right. */
.pay-sheet__foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
}

.pay-sheet__sum {
  min-width: 0;
}

.pay-sheet__figure {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  margin: 0;
  color: var(--ink-strong);
}

.pay-sheet__amount {
  font-variant-numeric: tabular-nums;
}

.pay-sheet__after {
  margin-left: var(--space-2);
  color: var(--ink-muted);
}

.pay-sheet__note {
  margin: var(--space-2) 0 0;
  color: var(--ink-muted);
}

.pay-sheet__note--failed {
  color: var(--danger);
}

/* It arrives as a panel does; with reduced motion it only fades. */
@media (prefers-reduced-motion: no-preference) {
  .pay-sheet[open] {
    animation: app-arrive-up 160ms cubic-bezier(0.2, 0, 0, 1);
  }

  .pay-sheet[open]::backdrop {
    animation: app-fade 160ms cubic-bezier(0.2, 0, 0, 1);
  }
}

/* A narrow screen: the cards stand in a column, each a row — the name and
   its line at the left, the price and the credits at the right — and the
   figure stands over its button. */
@media (max-width: 719px) {
  .pay-tiers {
    flex-direction: column;
  }

  .pay-tier {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'mark mark'
      'name price'
      'use credits';
    column-gap: var(--space-4);
    row-gap: var(--space-1);
    align-items: baseline;
    padding: var(--space-3) var(--space-4);
  }

  .pay-tier__mark {
    grid-area: mark;
    min-height: 0;
  }

  .pay-tier__mark:empty {
    display: none;
  }

  .pay-tier__name {
    grid-area: name;
  }

  .pay-tier__price {
    grid-area: price;
    margin-top: 0;
    justify-self: end;
  }

  .pay-tier__term {
    display: none;
  }

  .pay-tier__credits {
    grid-area: credits;
    margin-top: 0;
    justify-self: end;
  }

  .pay-tier__use {
    grid-area: use;
  }

  .pay-sheet__foot {
    flex-direction: column;
    align-items: stretch;
  }

  /* The title keeps its line; the term's control drops under it. */
  .pay-sheet__head {
    flex-wrap: wrap;
  }

  .pay-sheet__title {
    flex-basis: 100%;
  }
}

@media (hover: none) {
  .pay-btn--key {
    height: var(--space-10);
  }
}

/* With reduced motion the edge and the glow come at once. */
@media (prefers-reduced-motion: reduce) {
  .pay-btn,
  .pay-tier {
    transition: none;
  }

  .pay-sheet[open],
  .pay-sheet[open]::backdrop {
    animation: app-fade 160ms linear;
  }

  .spend-card,
  .spend-card--up {
    animation-name: app-fade;
  }
}
