/* ==========================================================================
   Clarity kit: the small shared blocks of the dashboard and auth pages. An
   icon, a status chip, a card head, stat tiles, a fact list, the "How it
   works" disclosure, a step tracker, a minimum meter, a callout and an
   action note. Markup for each is in the clarity spec and on the "kit"
   dashboard preview (lib/web-framework/dashboard_preview_test.go).

   Every layout links this sheet after its shell sheet (dashboard-v2.css,
   admin-v2.css or auth-v2.css), whose tokens it uses. Every selector is
   scoped to the two shells and names only ps-* classes, so the sheet never
   restyles existing markup. Same theming rules as the shell sheets: never a
   white, black or accent literal; washes are rgba(var(--ps-*-rgb), a).

   During a rolling update this sheet can 404 on an older pod. The markup
   stays usable without it: icons carry width and height, <details> and
   <progress> are native, steps read as a list and chips as icon and word.
   ========================================================================== */

/* ---- Icon (views/shared/icons.html.tmpl) ---- */
:is(body.ps-dashboard, body.ps-auth) .ps-icon {
  flex: none;
  vertical-align: -3px;
}

/* ---- Rhythm ----
   12px between blocks and 16px before an action: a block's 4px and the
   action's 12px, as on the Payouts cards. Cards are flex columns, so the
   two margins add up. A note qualifies the button above it, so a form
   that a note follows drops its last group's 16px bottom margin. */
:is(body.ps-dashboard, body.ps-auth) :is(.ps-figures, .ps-facts, .ps-steps, .ps-meter, .ps-callout):first-child {
  margin-top: 0;
}

:is(body.ps-dashboard, body.ps-auth) :is(.ps-figures, .ps-figures-caption, .ps-facts, .ps-steps, .ps-meter, .ps-callout, .ps-note):has(+ :is(form, .btn)) {
  margin-bottom: 4px;
}

:is(body.ps-dashboard, body.ps-auth) :is(.ps-figures, .ps-figures-caption, .ps-facts, .ps-steps, .ps-meter, .ps-callout, .ps-note) + :is(form, .btn) {
  margin-top: 12px;
}

:is(body.ps-dashboard, body.ps-auth) form:has(+ .ps-note) > .form-group:last-child {
  margin-bottom: 0;
}

/* ---- Status chip: icon, colour and one word ----
   The word stays --ps-text-high: tone text on the fill measured 4.28:1 in
   the light theme. The icon, fill and border carry the tone. */
:is(body.ps-dashboard, body.ps-auth) .ps-chip {
  --ps-chip-rgb: var(--ps-tint-rgb);
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border: 1px solid rgba(var(--ps-chip-rgb), .25);
  border-radius: 999px;
  background: rgba(var(--ps-chip-rgb), .08);
  color: var(--ps-text-high);
  font: 600 12px/1.4 var(--ps-ui);
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
}

:is(body.ps-dashboard, body.ps-auth) .ps-chip .ps-icon {
  width: 14px;
  height: 14px;
  color: rgb(var(--ps-chip-rgb));
}

:is(body.ps-dashboard, body.ps-auth) .ps-chip-neutral:not(:has(.ps-icon)) {
  padding-left: 10px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-chip-ok {
  --ps-chip-rgb: var(--ps-green-rgb);
}

:is(body.ps-dashboard, body.ps-auth) .ps-chip-wait {
  --ps-chip-rgb: var(--ps-amber-rgb);
}

:is(body.ps-dashboard, body.ps-auth) .ps-chip-stop {
  --ps-chip-rgb: var(--ps-red-rgb);
}

:is(body.ps-dashboard, body.ps-auth) a.ps-chip {
  text-decoration: none;
}

:is(body.ps-dashboard, body.ps-auth) a.ps-chip:hover {
  border-color: rgba(var(--ps-chip-rgb), .45);
  color: var(--ps-text-high);
  text-decoration: none;
}

:is(body.ps-dashboard, body.ps-auth) a.ps-chip:focus-visible {
  outline: 2px solid rgba(var(--ps-cyan-rgb), .85);
  outline-offset: 2px;
}

/* ---- Card head: title, chip and an optional right-aligned meta ---- */
:is(body.ps-dashboard, body.ps-auth) .ps-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-card-head > h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.02em;
  line-height: 1.3;
}

:is(body.ps-dashboard, body.ps-auth) .ps-card-meta {
  margin-left: auto;
  color: var(--ps-text-low);
  font-size: 12px;
}

@media (max-width: 460px) {
  :is(body.ps-dashboard, body.ps-auth) .ps-card-meta {
    flex-basis: 100%;
    margin-left: 0;
  }
}

/* ---- Stat tiles: a label above a figure, and a short sub-line ----
   Figures use the display serif, as the metric cards do. The id of a
   figure sits on .ps-figures-value, which holds only the figure. */
:is(body.ps-dashboard, body.ps-auth) .ps-figures {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  margin: 12px 0 0;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures > div {
  min-width: 0;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures dt {
  color: var(--ps-text-low);
  font: 500 12px/1.4 var(--ps-ui);
  letter-spacing: normal;
  text-transform: none;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures dd {
  margin: 4px 0 0;
  color: var(--ps-text-high);
  font: 400 26px/1.1 var(--ps-display);
  font-variant-numeric: tabular-nums;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures-value {
  display: block;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures-sub {
  display: block;
  max-width: 28ch;
  margin-top: 4px;
  color: var(--ps-text-low);
  font: 12px/1.4 var(--ps-ui);
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures-terms dd {
  font-size: 20px;
}

/* Term tiles stay compact: their sub-lines are sentences. */
:is(body.ps-dashboard, body.ps-auth) .ps-figures-terms .ps-figures-sub {
  max-width: 22ch;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures + .ps-note {
  margin-top: 12px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-figures-caption {
  margin: 12px 0 0;
  color: var(--ps-text-low);
  font-size: 12px;
}

@media (max-width: 460px) {
  :is(body.ps-dashboard, body.ps-auth) .ps-figures {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
  }

  :is(body.ps-dashboard, body.ps-auth) .ps-figures.ps-figures-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Three term tiles in a row leave about 100px each, too narrow for
     their sub-lines. */
  :is(body.ps-dashboard, body.ps-auth) .ps-figures.ps-figures-terms {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---- Fact list and receipt: a term and its value on one row ----
   Rows stay two columns on a phone; a long email wraps in its value. */
:is(body.ps-dashboard, body.ps-auth) .ps-facts {
  max-width: 520px;
  margin: 12px 0 0;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 3px 0;
  color: var(--ps-text);
  font-size: 13.5px;
  line-height: 1.5;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts dt {
  flex: none;
  font-weight: 400;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts dd {
  min-width: 0;
  margin: 0;
  color: var(--ps-text-high);
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts > .ps-facts-total {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--ps-line);
  font-weight: 600;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts > .ps-facts-total dt {
  color: var(--ps-text-high);
  font-weight: 600;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts-note {
  display: block;
  color: var(--ps-text-low);
  font-size: 12px;
  font-weight: 400;
}

/* Facts whose values are words, such as program terms: the value starts
   next to its term instead of at the far edge. */
:is(body.ps-dashboard, body.ps-auth) .ps-facts.ps-facts-text {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0 20px;
  max-width: 640px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts.ps-facts-text > div {
  display: contents;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts.ps-facts-text :is(dt, dd) {
  padding: 3px 0;
  color: var(--ps-text);
  font-size: 13.5px;
  line-height: 1.5;
}

:is(body.ps-dashboard, body.ps-auth) .ps-facts.ps-facts-text dd {
  color: var(--ps-text-high);
  text-align: left;
}

/* ---- "How it works" disclosure: native <details>, closed by default ----
   Holds only the why and the fine print; facts needed before acting stay
   next to the action. */
:is(body.ps-dashboard, body.ps-auth) .ps-details {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--ps-line);
}

:is(body.ps-dashboard, body.ps-auth) .ps-details > summary {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  color: var(--ps-text-high);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details > summary::-webkit-details-marker {
  display: none;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details > summary::before {
  width: 7px;
  height: 7px;
  flex: none;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  content: "";
  transform: rotate(-45deg);
  transition: transform .15s ease;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details[open] > summary::before {
  transform: rotate(45deg);
}

:is(body.ps-dashboard, body.ps-auth) .ps-details > summary:focus-visible {
  border-radius: 6px;
  outline: 2px solid rgba(var(--ps-cyan-rgb), .82);
  outline-offset: 4px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details > :not(summary) {
  max-width: 640px;
  margin: 10px 0 0;
  color: var(--ps-text);
  font-size: 13.5px;
  line-height: 1.55;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details ul {
  padding-left: 18px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-details li + li {
  margin-top: 6px;
}

/* In-flow variant, without the rule, such as "Show all". */
:is(body.ps-dashboard, body.ps-auth) .ps-details.ps-details-flush {
  margin-top: 12px;
  padding-top: 0;
  border-top: 0;
}

@media (max-width: 700px) {
  :is(body.ps-dashboard, body.ps-auth) .ps-details > summary {
    min-height: 44px;
  }
}

/* ---- Step tracker (the affiliate journey) ----
   Every step shows its word. A done step has a check and a visually hidden
   "(done)" (.ps-toast-sr, inline in every layout); the current step has
   aria-current="step". */
:is(body.ps-dashboard, body.ps-auth) .ps-steps {
  display: flex;
  max-width: 520px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps > li {
  position: relative;
  display: grid;
  flex: 1 1 0;
  align-content: start;
  min-width: 0;
  gap: 2px;
  padding-top: 30px;
  padding-right: 8px;
}

/* The track from the previous mark to this one, with 6px of air at each end. */
:is(body.ps-dashboard, body.ps-auth) .ps-steps > li + li::before {
  position: absolute;
  top: 10px;
  right: calc(100% + 6px);
  left: calc(-100% + 28px);
  height: 2px;
  border-radius: 2px;
  background: var(--ps-line-strong);
  content: "";
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps > li.is-done + li::before {
  background: rgba(var(--ps-green-rgb), .6);
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps-mark {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  box-sizing: border-box;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid var(--ps-line-strong);
  border-radius: 50%;
  background: var(--ps-surface);
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps .is-done .ps-steps-mark {
  border-color: rgb(var(--ps-green-rgb));
  background: rgba(var(--ps-green-rgb), .12);
  color: var(--ps-green);
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps .is-current .ps-steps-mark {
  border-color: rgb(var(--ps-amber-rgb));
  background: rgb(var(--ps-amber-rgb));
  box-shadow: inset 0 0 0 4px var(--ps-surface);
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps-mark .ps-icon {
  width: 14px;
  height: 14px;
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps-label {
  color: var(--ps-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps .is-current .ps-steps-label,
:is(body.ps-dashboard, body.ps-auth) .ps-steps .is-done .ps-steps-label {
  color: var(--ps-text-high);
}

:is(body.ps-dashboard, body.ps-auth) .ps-steps-meta {
  color: var(--ps-text-low);
  font-size: 12px;
  line-height: 1.4;
}

/* ---- Minimum meter: text first, the bar is decoration ----
   Rendered only in the server's below-minimum branch. Cyan, not green:
   green means done. */
:is(body.ps-dashboard, body.ps-auth) .ps-meter {
  max-width: 520px;
  margin: 12px 0 0;
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-text {
  margin: 0 0 6px;
  color: var(--ps-text);
  font-size: 13.5px;
  line-height: 1.5;
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-text strong {
  color: var(--ps-text-high);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-bar {
  display: block;
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: 999px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: rgba(var(--ps-tint-rgb), .08);
  color: var(--ps-cyan);
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-bar::-webkit-progress-bar {
  border-radius: 999px;
  background: rgba(var(--ps-tint-rgb), .08);
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-bar::-webkit-progress-value {
  border-radius: 999px;
  background: var(--ps-cyan);
}

:is(body.ps-dashboard, body.ps-auth) .ps-meter-bar::-moz-progress-bar {
  border-radius: 999px;
  background: var(--ps-cyan);
}

/* ---- Callout: an icon and one or two sentences in a tinted box ----
   A div, not a p: the dashboard sheet recolours every p. An inline form
   error is a .ps-callout-stop with role="alert". */
:is(body.ps-dashboard, body.ps-auth) .ps-callout {
  --ps-callout-rgb: var(--ps-cyan-rgb);
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border: 1px solid rgba(var(--ps-callout-rgb), .3);
  border-radius: var(--ps-radius-small);
  background: rgba(var(--ps-callout-rgb), .06);
  color: var(--ps-text-high);
  font-size: 13.5px;
  line-height: 1.5;
}

:is(body.ps-dashboard, body.ps-auth) .ps-callout > .ps-icon {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  color: rgb(var(--ps-callout-rgb));
}

:is(body.ps-dashboard, body.ps-auth) .ps-callout strong {
  font-weight: 650;
}

:is(body.ps-dashboard, body.ps-auth) .ps-callout-warn {
  --ps-callout-rgb: var(--ps-amber-rgb);
}

:is(body.ps-dashboard, body.ps-auth) .ps-callout-stop {
  --ps-callout-rgb: var(--ps-red-rgb);
}

:is(body.ps-dashboard, body.ps-auth) .ps-callout-ok {
  --ps-callout-rgb: var(--ps-green-rgb);
}

/* ---- Action note: up to two short sentences right under the button ----
   The list form holds three to five facts, one sentence a line. */
:is(body.ps-dashboard, body.ps-auth) .ps-note {
  margin: 8px 0 0;
  color: var(--ps-text);
  font-size: 13px;
  line-height: 1.5;
}

:is(body.ps-dashboard, body.ps-auth) .ps-note-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

:is(body.ps-dashboard, body.ps-auth) .ps-note-list > li + li {
  margin-top: 2px;
}

/* ---- Forced colours: keep the outlines that carry a block's shape ---- */
@media (forced-colors: active) {
  :is(body.ps-dashboard, body.ps-auth) :is(.ps-chip, .ps-callout, .ps-steps-mark) {
    border-color: CanvasText;
  }
}
