/* ============================================================
   components.css — the one component system
   ------------------------------------------------------------
   Loaded AFTER a page's own stylesheet, so equal-specificity
   declarations here win by source order. Selectors that must beat
   older two-class rules are prefixed with `body` for one extra
   point of specificity rather than reaching for !important.

   House rules for this file:
     - No colour literals. Every value is a token from tokens.css.
     - No gradients, no coloured shadows, no coloured card strips.
     - Hierarchy comes from size and weight first, colour last.
     - Contrast: --text and --muted both clear 4.5:1 on --white and
       --surface.
   ============================================================ */

/* ============================================================
   BUTTONS — four variants, one geometry
   primary   solid accent, one per view area
   secondary white + line border
   ghost     accent text, no chrome
   danger    outline; fill only inside a confirmation dialog
   ============================================================ */

body .btn,
body button.btn,
body a.btn,
body input[type="submit"].btn,
body .btn-primary,
body .btn-secondary,
body .btn-ghost,
body .btn-danger,
body .btn-success,
body .btn-info,
body .btn-warning,
body .btn-orange,
body .btn-purple {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background-image: none;
  box-shadow: none;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  text-transform: none;
  letter-spacing: normal;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
  transition: background-color var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}

body .btn:disabled,
body .btn[aria-disabled="true"],
body .btn.is-disabled {
  opacity: 0.55;
  pointer-events: none;
  box-shadow: none;
}

/* Primary */
body .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
}

body .btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Secondary */
body .btn-secondary {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}

body .btn-secondary:hover {
  background: var(--surface);
}

/* Ghost */
body .btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}

body .btn-ghost:hover {
  background: var(--accent-tint);
}

/* Danger — outline by default. */
body .btn-danger {
  background: var(--white);
  border-color: var(--danger);
  color: var(--danger);
}

body .btn-danger:hover {
  background: var(--danger-tint);
}

/* Legacy colour variants are mapped, not merely neutralised: the important
   ones read as primary, the rest as secondary. The class names stay in the
   markup because JS/PHP targets them. */
body .btn-success,
body .btn-info,
body .btn-warning,
body .btn-orange,
body .btn-purple {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}

body .btn-success:hover,
body .btn-info:hover,
body .btn-warning:hover,
body .btn-orange:hover,
body .btn-purple:hover {
  background: var(--surface);
}

/* Shared states */
body .btn:focus-visible,
body .btn-primary:focus-visible,
body .btn-secondary:focus-visible,
body .btn-ghost:focus-visible,
body .btn-danger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body .btn:active {
  transform: none;
  box-shadow: none;
}

/* Loading state that does not change width: the label stays in the flow,
   only its colour drops out, and a neutral ring sits over the centre. */
body .btn.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

body .btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: ui-spin 0.7s linear infinite;
}

@keyframes ui-spin {
  to { transform: rotate(360deg); }
}

/* Compact variant for table row actions. */
body .btn-sm {
  min-height: 40px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

/* Icon-only buttons keep a 40px hit area and stay neutral. */
body .btn-icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: var(--line);
  background: var(--white);
  color: var(--muted);
}

body .btn-icon:hover {
  background: var(--surface);
  color: var(--ink);
}

/* ============================================================
   CARDS — one surface, one border, one radius, no strips
   ============================================================ */

body .card,
body .mk-card,
body .job-section,
body .job-card-side,
body .job-owner-card,
body .caution,
body .inst-fact {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: none;
}

/* Coloured side/top/bottom strips are decoration: normalise every edge to
   the same hairline instead of recolouring them. */
body .card,
body .mk-card,
body .job-section,
body .job-card-side,
body .job-owner-card,
body .caution,
body .inst-fact {
  border-top-color: var(--line);
  border-bottom-color: var(--line);
  border-left: 1px solid var(--line);
  border-right-color: var(--line);
}

/* The bulk-terms block on the retail page carried a 4px teal side bar. */
body .ws-terms {
  border: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

body .card:hover,
body .mk-card:hover {
  border-color: var(--neutral-300);
  box-shadow: var(--shadow-sm);
}

/* Coloured icon circles become plain glyphs. */
body .card .icon-circle,
body .stat-card .icon-circle,
body .icon-badge {
  background: transparent;
  border: 0;
  color: var(--muted);
}

/* ============================================================
   BADGES / TAGS — neutral by default, semantic only for status
   ============================================================ */

body .badge,
body .mk-chip,
body .job-chip,
body .attr-chip,
body .tag,
body .pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.04em;
  line-height: 1.3;
}

/* A promoted/featured listing is still an offer, not an error: accent tint,
   not a second semantic colour. */
body .mk-chip.feat,
body .mk-chip.deal {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--ink);
}

/* Status only. Always paired with a text label in the markup. */
body .badge-success,
body .badge--paid,
body .badge--active {
  background: var(--success-tint);
  border-color: var(--success);
  color: var(--success);
}

body .badge-warning,
body .badge--pending {
  background: var(--warning-tint);
  border-color: var(--warning);
  color: var(--warning);
}

body .badge-danger,
body .badge--failed,
body .badge--closed {
  background: var(--danger-tint);
  border-color: var(--danger);
  color: var(--danger);
}

/* ============================================================
   TABLES
   ============================================================ */

body .ui-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

body .ui-table th {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  background: var(--white);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  text-align: left;
  white-space: nowrap;
}

body .ui-table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: var(--text-sm);
  vertical-align: middle;
}

body .ui-table tbody tr:last-child td { border-bottom: 0; }
body .ui-table tbody tr:hover { background: var(--surface); }

/* Numeric columns line up. */
body .ui-table .is-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   STAT CARDS — hierarchy from size and weight
   ============================================================ */

body .stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  align-items: stretch;
}

body .stat-card {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-4);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: none;
}

body .stat-card .stat-label {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  letter-spacing: normal;
  text-transform: none;
}

body .stat-card .stat-value {
  color: var(--ink);
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

body .stat-card .stat-note {
  color: var(--muted);
  font-size: var(--text-xs);
}

/* A trend is text, not a coloured arrow. */
body .stat-card .stat-note.is-warning { color: var(--warning); }
body .stat-card .stat-note.is-danger { color: var(--danger); }

@media (max-width: 1024px) {
  body .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  body .stat-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ============================================================
   FORMS
   ============================================================ */

body .ui-field { display: grid; gap: var(--space-2); margin-bottom: var(--space-4); }

body .ui-label {
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

body .ui-input,
body .ui-select,
body .ui-textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--text-base);
  line-height: 1.5;
}

body .ui-textarea { min-height: 96px; resize: vertical; }

body .ui-input:focus,
body .ui-select:focus,
body .ui-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

body .ui-help {
  color: var(--muted);
  font-size: var(--text-xs);
}

body .ui-error {
  color: var(--danger);
  font-size: var(--text-xs);
}

/* ============================================================
   LAYOUT + SPACING UTILITIES
   ============================================================ */

body .page-container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

@media (min-width: 900px) {
  body .page-container { padding-inline: var(--space-6); }
}

body .u-stack > * + * { margin-top: var(--space-4); }
body .u-section + .u-section { margin-top: var(--space-7); }
body .u-gap-2 { gap: var(--space-2); }
body .u-gap-4 { gap: var(--space-4); }
body .u-gap-5 { gap: var(--space-5); }

body .u-truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body .u-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   MOTION + ACCESSIBILITY
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  body .btn,
  body .card,
  body .mk-card { transition: none; }
  body .btn.is-loading::after { animation: none; }
}

@media (forced-colors: active) {
  body .btn,
  body .card,
  body .mk-card,
  body .badge,
  body .mk-chip,
  body .ui-table { border: 1px solid CanvasText; }
}
