/* ============================================================================
   Forge Marketplace — design tokens and base styles
   ============================================================================

   NO BUILD STEP, DELIBERATELY. `MARKETPLACE_UI_DIST` points at this directory
   in source (blueforge.config.json), and the API serves it statically. Adopting
   Tailwind would mean a build, a dist directory, and changes to the deploy
   config, CI, and that serving assumption — for a UI that is eight static HTML
   pages and one script. Custom properties give the same tokens natively.

   Every colour below is a token. Nothing downstream hardcodes a hex value, so
   the dark theme is a token swap rather than a second stylesheet.
   ========================================================================== */

:root {
  /* Neutrals, slightly cool — chosen against the accent rather than pure grey */
  --bg:            #fbfcfd;
  --surface:       #ffffff;
  --surface-2:     #f2f5f8;
  --line:          #dfe5ec;
  --line-soft:     #edf1f5;
  --ink:           #17212b;
  --ink-soft:      #3d4b5a;
  --muted:         #66727f;

  /* One accent. Deep steel blue — this is developer tooling, not a consumer app */
  --accent:        #1f5f8b;
  --accent-ink:    #17496b;
  --accent-wash:   #e8f1f8;
  /* Text on a filled accent surface. A token because the accent inverts in
     dark mode — white on the dark-mode accent is barely legible. */
  --on-accent:     #ffffff;

  /* Semantic, kept separate from the accent */
  --ok:            #06603a;
  --ok-wash:       #e6f4ee;
  --warn:          #8a6100;
  --warn-wash:     #fdf4e0;
  --bad:           #a4161a;
  --bad-wash:      #fbecec;

  /* Type scale, 1.25 ratio */
  --text-xs:   0.78rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.2rem;
  --text-xl:   1.5rem;
  --text-2xl:  1.95rem;
  --text-3xl:  2.6rem;

  /* Spacing, 4px base */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;

  --radius:    6px;
  --radius-lg: 10px;

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgb(23 33 43 / 0.05);
  --shadow:    0 1px 3px rgb(23 33 43 / 0.08), 0 4px 12px rgb(23 33 43 / 0.05);

  --measure: 68ch;
}

/* The viewer's OS preference. Tokens only — no component styles live in here,
   so nothing can be defined for one theme and missing in the other. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0e151c;
    --surface:     #151f29;
    --surface-2:   #1c2833;
    --line:        #27343f;
    --line-soft:   #1f2b36;
    --ink:         #e8edf2;
    --ink-soft:    #c3cdd7;
    --muted:       #8d9aa7;

    --accent:      #5aa9dc;
    --accent-ink:  #86c3e9;
    --accent-wash: #16293a;
    --on-accent:   #0c1620;

    --ok:          #5cbf92;
    --ok-wash:     #10241c;
    --warn:        #d9ab4c;
    --warn-wash:   #261f0f;
    --bad:         #f2807e;
    --bad-wash:    #2a1719;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow:    0 1px 3px rgb(0 0 0 / 0.4), 0 4px 12px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 1040px;
  padding: 0 var(--s-5);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: var(--text-lg); margin: 0; letter-spacing: -0.01em; }
/* The wordmark is a link home, so it is a standalone control too. The padding
   is derived from this stylesheet's own type scale — --text-lg at line-height
   1.6 is ~31px, so 7px each side reaches 44. PR #34 used 3px against the older,
   smaller heading; the design system changed the number this has to clear. */
header h1 a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  display: inline-block;
  padding: 7px 0;
}
header nav { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
/* Vertical padding needs a box to apply to, hence inline-block. The header
   aligns on the baseline, so the padding is symmetric to keep the row centred.
   13px is calculated to land the control at 44px — not a spacing token. */
header nav a,
header nav button {
  display: inline-block;
  padding: 13px 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: var(--text-sm);
}
header nav a:hover { color: var(--accent); }
header nav span { color: var(--line); }
/* Sign-out is a <button> because it performs an action rather than navigating
   (PR #33). Reset so the markup change stays semantic and it still reads as a
   sibling of the nav links. */
/* Sign-out is a <button> because it performs an action rather than navigating
   (PR #33). Reset so the markup change stays semantic. */
header nav button { background: none; border: 0; font: inherit; cursor: pointer; }
header nav button:hover { color: var(--accent); background: none; }

main { padding: var(--s-6) 0 var(--s-8); }

h2 { font-size: var(--text-2xl); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 var(--s-3); text-wrap: balance; }
h3 { font-size: var(--text-lg); line-height: 1.3; margin: 0 0 var(--s-2); text-wrap: balance; }
p  { margin: 0 0 var(--s-3); max-width: var(--measure); text-wrap: pretty; }

a { color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ── Landing ──────────────────────────────────────────────────────────────── */

.hero { padding: var(--s-7) 0 var(--s-6); }
.hero h2 { font-size: var(--text-3xl); max-width: 20ch; }
.hero .lede { font-size: var(--text-lg); color: var(--ink-soft); max-width: 56ch; margin-bottom: var(--s-5); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

.install-line {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-soft);
  overflow-x: auto;
}
.install-line .prompt { color: var(--muted); user-select: none; }

.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--s-4);
  margin: var(--s-6) 0 var(--s-7);
}
.pillar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s-4) var(--s-5) var(--s-5);
  box-shadow: var(--shadow-sm);
}
.pillar h3 { font-size: var(--text-base); }
.pillar p { font-size: var(--text-sm); color: var(--muted); margin: 0; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-4);
  margin-bottom: var(--s-4);
}
.section-head h2 { font-size: var(--text-xl); margin: 0; }

/* ── Forms and controls ───────────────────────────────────────────────────── */

/* ── Tap targets ────────────────────────────────────────────────────────────
   Apple's HIG asks for 44px, and WCAG 2.5.5 (AAA) agrees. WCAG 2.5.8 (AA) is
   the looser 24px, and carries an explicit exemption for targets inline in a
   block of text.

   That exemption is why this is not a blanket rule. Links inside page content —
   a package name in a table cell, `pub_acme` in a row, a link mid-sentence —
   are inline targets sitting in a line box; padding them to 44px would push
   their own text apart and change how the table reads. They are left alone
   deliberately.

   What is covered is the standalone controls: form fields and buttons, which
   measured 38px (and one signup field at 21px), and the header nav, whose links
   measured 18px. Those are discrete controls, not prose.       (from PR #34) */
button,
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea { min-height: 44px; }

button, .button {
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  min-height: 44px;              /* tap target */
  padding: var(--s-2) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: default; }
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
button.primary:hover:not(:disabled) { background: var(--accent-ink); border-color: var(--accent-ink); }
button.danger { border-color: var(--bad); color: var(--bad); }
button.danger:hover:not(:disabled) { background: var(--bad-wash); }

input, textarea, select {
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { min-height: 6rem; font-family: var(--font-mono); font-size: var(--text-xs); }

#search { display: flex; gap: var(--s-2); margin-bottom: var(--s-5); }
#search input[type="search"] { flex: 1; }

/* ── Tables ───────────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { text-align: left; padding: var(--s-3); border-bottom: 1px solid var(--line-soft); }
th {
  background: var(--surface-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
tbody tr:hover { background: var(--surface-2); }
td { font-variant-numeric: tabular-nums; }

.paid { color: var(--bad); font-weight: 600; }
.free { color: var(--ok); font-weight: 500; }

/* ── Cards, badges, figures ───────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--s-4) var(--s-5) var(--s-5);
  margin: 0 0 var(--s-4);
  box-shadow: var(--shadow-sm);
}
.card h3 { margin-top: 0; }
.card.not-configured { opacity: 0.7; }
/* Absence is muted; a failure keeps full weight and borrows the alarm colour
   for its edge, so the two are never read as the same state at a glance. */
.card.failed { border-color: var(--bad); }

.muted { color: var(--muted); font-size: var(--text-sm); }
.alert {
  color: var(--bad);
  background: var(--bad-wash);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  padding: var(--s-2) var(--s-3);
  font-size: var(--text-sm);
}

.badge { display: inline-block; padding: var(--s-1) var(--s-3); border-radius: 999px; font-size: var(--text-xs); font-weight: 600; }
.badge.ok   { background: var(--ok-wash);   color: var(--ok); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.bad  { background: var(--bad-wash);  color: var(--bad); }
.badge-cell.ok   { color: var(--ok); font-weight: 500; }
.badge-cell.warn { color: var(--warn); font-weight: 500; }
.badge-cell.bad  { color: var(--bad); font-weight: 600; }

.figures { display: flex; flex-wrap: wrap; gap: var(--s-5); margin: var(--s-3) 0; }
.figure-value { font-size: var(--text-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.figure.primary .figure-value { color: var(--ok); }
.figure-label { font-size: var(--text-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.template-entitlement { display: inline-block; padding: var(--s-1) var(--s-3); border-radius: 999px; font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--s-3); }
.template-entitlement.owned    { background: var(--ok-wash);   color: var(--ok); }
.template-entitlement.refunded { background: var(--warn-wash); color: var(--warn); }
.template-entitlement.free     { background: var(--ok-wash);   color: var(--ok); }

/* One bar per day. A row of divs rather than a chart library: this is a
   sparkline, not a visualisation, and the whole UI ships without a bundler. */
.sales-chart {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 72px;
  margin: var(--s-3) 0 var(--s-1);
}
.sales-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 3px; }
.sales-bar-fill { width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; }
/* An empty day keeps a baseline, so the row reads as a timeline rather than
   as missing data. */
.sales-bar-fill.empty { background: var(--line); }
.sales-axis { font-size: var(--text-sm); margin-top: 0; }

/* Tags read as navigation, so they stay links — but an underlined run of bare
   words beside the pricing pill looks like an accident rather than a control.
   Same pill shape, quieter colour, because pricing is the thing to notice
   first on this page. */
.tags { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: var(--s-2) 0 var(--s-3); }
.tag {
  display: inline-block;
  padding: var(--s-1) var(--s-3);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-sm);
  text-decoration: none;
  border: 1px solid var(--line);
}
.tag:hover { background: var(--surface); text-decoration: underline; }

.download-link { font-size: var(--text-sm); font-weight: 500; }

/* ── Auth + admin ─────────────────────────────────────────────────────────── */

.login-form { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin: var(--s-3) 0; }
.login-form input { flex: 1; min-width: 12rem; max-width: 22rem; }

.admin-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--s-3); }
.admin-actions { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.count-badge { display: inline-block; margin-left: var(--s-2); padding: var(--s-1) var(--s-2); border-radius: 999px; background: var(--surface-2); font-size: var(--text-xs); font-weight: 600; }
.count-badge.bad { background: var(--bad-wash); color: var(--bad); }

.chargeback { border-top: 1px solid var(--line-soft); padding: var(--s-3) 0; }
.chargeback .actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); flex-wrap: wrap; }
.chargeback button { font-size: var(--text-xs); min-height: 38px; }

.notes-input { width: 100%; margin-top: var(--s-2); }
.notes-input.invalid, .fee-input.invalid { border-color: var(--bad); background: var(--bad-wash); }
.fee-input { width: 6rem; }
.unpublish-form { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-2); }
.unpublish-form .notes-input { width: auto; flex: 1 1 11rem; margin-top: 0; }

/* A field is a label above its control, everywhere. This lived only under
   `.publish-form`, so `field()` used anywhere else rendered the label and the
   input side by side and the input at its intrinsic width — which on the
   webhook panel meant a URL box too narrow to show a URL. Found by looking at
   the page; happy-dom has no layout, so no test could have caught it. */
.field { margin: var(--s-3) 0; }
.field label { display: block; font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--s-1); }
.field input, .field select, .field textarea { width: 100%; max-width: 32rem; }

/* ── Publish form ─────────────────────────────────────────────────────────── */

.publish-form .field { margin: var(--s-3) 0; }
.publish-form label { display: block; font-weight: 600; font-size: var(--text-sm); margin-bottom: var(--s-1); }
.publish-form input[type="text"], .publish-form input[type="number"], .publish-form select { width: 100%; max-width: 26rem; }
.sha-box { margin: var(--s-2) 0 var(--s-4); word-break: break-all; }
.sha-box code, code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
pre {
  max-width: 100%;
  overflow-x: auto;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
}
.sig-help pre { white-space: pre-wrap; word-break: break-all; }

/* ── Small screens ────────────────────────────────────────────────────────── */

@media (max-width: 40rem) {
  :root { --text-3xl: 2rem; --text-2xl: 1.6rem; }
  body { padding: 0 var(--s-3); }
  /* `display: block` is what makes overflow-x apply to a table element, so a
     wide table scrolls inside itself instead of widening the document. */
  table { display: block; overflow-x: auto; }
  .hero { padding: var(--s-5) 0 var(--s-4); }
  #search { flex-direction: column; }
  #search button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Catalogue rows: the name leads, the id sits under it as the thing you type.
   Before the publish path stored a name these were the same string in two
   columns, so neither carried its weight. */
.row-id {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.125rem;
}

/* The description is the column a stranger reads first. Give it room, cap it
   so one verbose publisher cannot push the price off a narrow screen. */
.row-desc {
  color: var(--text);
  max-width: 42ch;
}
