:root {
  --fg: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #ffffff;
  --accent: #2563eb;
  --pill-bg: #eef2ff;
  --pill-fg: #3730a3;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
}
.topbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.spacer { flex: 1; }
.user { color: var(--muted); font-size: .85rem; }
.logout { color: var(--accent); font-size: .8rem; text-decoration: none; margin-left: .75rem; }
.logout:hover { text-decoration: underline; }
.content { padding: 1.5rem 1.25rem; max-width: 1100px; margin: 0 auto; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
.lede { color: var(--muted); margin: 0 0 1.25rem; max-width: 70ch; }
.empty { color: var(--muted); }
table.specs { width: 100%; border-collapse: collapse; }
table.specs th, table.specs td {
  text-align: left;
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.specs thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr.fam td.name { font-weight: 600; }
/* Spec rows open the editor prefilled (GET /specs/{id}). Link styling matches the crumb. */
table.specs td.name a, table.versions td a { color: var(--accent); text-decoration: none; }
table.specs td.name a:hover, table.versions td a:hover { text-decoration: underline; }
.unnamed { color: var(--muted); font-weight: 400; font-style: italic; }
/* Keep unnamed one-off links muted — must out-specify the accent rule above (which is
   (0,2,3): table.specs td.name a), so scope this the same depth plus the .unnamed class. */
table.specs td.name a.unnamed { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.desc { color: var(--muted); }
/* The ID column: full-contrast (not muted like .desc/.when) — it is the one value on this page
   a caller copies into a submit call, so it reads as data, not as row chrome. */
td.specid { white-space: nowrap; }
.when { color: var(--muted); white-space: nowrap; font-size: .85rem; }
.pill {
  display: inline-block;
  padding: .05rem .45rem;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--pill-fg);
  font-size: .8rem;
  font-weight: 600;
}
tr.history-row td { padding-top: 0; border-bottom: 1px solid var(--border); }
details summary { cursor: pointer; color: var(--accent); font-size: .85rem; padding: .1rem 0; }
table.versions { width: auto; border-collapse: collapse; margin: .4rem 0 .6rem; }
table.versions th, table.versions td {
  padding: .3rem .8rem .3rem 0;
  border-bottom: 1px dotted var(--border);
  font-size: .85rem;
}
table.versions thead th { color: var(--muted); text-transform: uppercase; font-size: .72rem; }
.footer {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .8rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  max-width: 1100px;
  margin: 0 auto;
}

/* ── Spec editor ──────────────────────────────────────────────────────────────
   Severity colors. Declared here because the editor's lint findings are their main consumer,
   but they are :root tokens and the spec LIST also uses --sev-warn for its draft badges — so
   changing a value here changes both pages. */
:root {
  --sev-error: #b91c1c; --sev-error-bg: #fef2f2;
  --sev-warn: #a16207;  --sev-warn-bg: #fefce8;
  --sev-good: #15803d;  --sev-good-bg: #f0fdf4;
}
p.crumb { margin: 0 0 .5rem; font-size: .85rem; }
p.crumb a { color: var(--accent); text-decoration: none; }
p.crumb a:hover { text-decoration: underline; }
/* The loaded spec's id, directly under the editor's title. Sits ABOVE .lede (which has the
   1.25rem bottom gap), so it only needs a hair of separation from the h1. */
.specid-line { display: flex; align-items: baseline; flex-wrap: wrap; gap: .4rem; margin: .35rem 0 .35rem; }
.specid-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; color: var(--muted); }
.specid-note { font-size: .82rem; color: var(--muted); }
.lede code, .hint code, .lint-msg code, .specid-note code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .85em; background: var(--pill-bg); color: var(--pill-fg);
  padding: .05rem .3rem; border-radius: 4px;
}
/* Two columns on a wide viewport: the edit surface (Recipe + Output schema + Save) on the
   left, the Test-run panel pinned on the right so edit↔test isn't a long vertical scroll.
   align-items:start keeps the right cell from stretching, so its panel can stick within the
   (taller) grid row. Collapses to a single column < 640px (see the media query below). */
.editor { display: grid; grid-template-columns: 1fr 380px; gap: 1.25rem; align-items: start; }
.editor-main { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }
.editor-side { position: sticky; top: 1rem; }
.panel { border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.1rem; }
.panel-h { font-size: 1rem; margin: 0; }
/* A heading that is a DIRECT child of .panel has no .panel-head wrapper to supply the gap, so
   it needs its own — otherwise the first field sits flush against the title (the Test run
   panel). The direct-child selector leaves the wrapped case in .panel-head alone. */
.panel > .panel-h { margin-bottom: .75rem; }
.panel-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.panel-head .panel-h { flex: 1; }

/* Top-level section switch: Recipe ⟷ Output schema share one panel. Underline-style so it
   reads as the panel's title-level switch — deliberately distinct from the pill-style .tabs used for the Guided/Raw sub-views nested
   inside Output, which would otherwise look like a second peer switch. margin-right:auto
   pushes the status pill + Structured-output toggle to the right of the header. */
.section-tabs { display: inline-flex; gap: 1rem; margin-right: auto; }
.section-tab {
  border: none; background: transparent; cursor: pointer; font: inherit;
  font-size: 1rem; font-weight: 600; color: var(--muted);
  padding: .1rem 0 .35rem; border-bottom: 2px solid transparent;
}
.section-tab[aria-pressed="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.section-tab:hover { color: var(--fg); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1rem; }
.fld { display: flex; flex-direction: column; gap: .3rem; font-size: .82rem; color: var(--muted); }
/* One header line per field (label text + its optional descriptor). Collapsing these into a
   single flex item makes every .fld a uniform [header, input] pair, so inputs align across the
   two-column grid (a descriptor as a third stacked flex item would make them zigzag). */
.fld-h { display: block; }
.fld .opt { color: var(--muted); font-weight: 400; }
/* Live guidance under an input. No min-height/margin: an empty hint must collapse to nothing
   or it stretches the row and breaks .fld alignment across the grid. */
.fld-hint { font-size: .76rem; color: var(--muted); line-height: 1.4; }
.fld-hint.over { color: var(--sev-warn); font-weight: 600; }
.span2 { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .editor { grid-template-columns: 1fr; }
  .editor-side { position: static; }
  .grid2 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}

.in {
  width: 100%; padding: .4rem .55rem; border: 1px solid var(--border);
  border-radius: 7px; background: var(--bg); color: var(--fg); font-size: .9rem;
}
.in:focus { outline: none; border-color: var(--accent); }
textarea.in { resize: vertical; line-height: 1.5; }
.in.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.raw { min-height: 18rem; }

.toggle { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--muted); white-space: nowrap; }

.tabs { display: inline-flex; gap: .25rem; background: var(--pill-bg); border-radius: 8px; padding: .2rem; margin-bottom: .9rem; }
.tab { border: none; background: transparent; cursor: pointer; color: var(--muted); font: inherit; font-size: .82rem; font-weight: 600; padding: .3rem .7rem; border-radius: 6px; }
.tab[aria-pressed="true"] { background: var(--bg); color: var(--fg); }
.tab:disabled { opacity: .5; cursor: default; }

.field-row { border: 1px solid var(--border); border-radius: 8px; padding: .55rem .6rem; margin-bottom: .55rem; display: flex; flex-direction: column; gap: .45rem; }
.field-main { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.f-name { flex: 1; min-width: 9rem; }
.f-sel { width: auto; cursor: pointer; }
.req-toggle { border: 1px solid var(--border); background: var(--bg); color: var(--muted); font: inherit; font-size: .72rem; font-weight: 600; padding: .3rem .6rem; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.req-toggle[aria-pressed="true"] { background: var(--pill-bg); color: var(--pill-fg); border-color: var(--pill-fg); }
.f-remove { margin-left: auto; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: .95rem; padding: .2rem .35rem; border-radius: 6px; }
.f-remove:hover { color: var(--sev-error); background: var(--sev-error-bg); }
.field-extra { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.f-desc { flex: 1; min-width: 12rem; }
.f-x { flex: 1; min-width: 10rem; }
.f-item { font-size: .78rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }

.add-field { width: 100%; border: 1.5px dashed var(--border); background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: .5rem; border-radius: 8px; cursor: pointer; }
.add-field:hover { border-color: var(--accent); color: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); margin: .75rem 0 0; line-height: 1.5; }

/* The Validate button + its results form a zone below the schema (Guided/Raw), set off by a
   rule so it reads as "check this schema" rather than a third editing surface. */
.validate-bar { display: flex; align-items: center; gap: .6rem; margin: 0 0 .75rem; padding-top: .9rem; border-top: 1px solid var(--border); }
.validate-bar .prov { font-size: .82rem; color: var(--muted); }
.validation-result { margin-top: .25rem; }
.note { font-size: .82rem; color: var(--muted); background: var(--pill-bg); border: 1px solid var(--border); border-radius: 8px; padding: .55rem .7rem; margin: 0 0 .75rem; }
.note.stale { color: var(--sev-warn); background: var(--sev-warn-bg); border-color: var(--sev-warn); }

.pill.status { border: 1px solid transparent; cursor: pointer; font-weight: 600; }
.pill.status.neutral { background: var(--pill-bg); color: var(--muted); }
.pill.status.free { background: var(--pill-bg); color: var(--pill-fg); }
.pill.status.stale { background: var(--sev-warn-bg); color: var(--sev-warn); }
.pill.status.good { background: var(--sev-good-bg); color: var(--sev-good); }
.pill.status.warn { background: var(--sev-warn-bg); color: var(--sev-warn); }
.pill.status.crit { background: var(--sev-error-bg); color: var(--sev-error); }

.lint-list { list-style: none; margin: 0 0 .9rem; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.lint-item { display: flex; gap: .55rem; align-items: baseline; font-size: .85rem; }
.lint-sev { flex: none; text-transform: uppercase; font-size: .68rem; font-weight: 700; letter-spacing: .04em; padding: .1rem .4rem; border-radius: 5px; }
.lint-sev.good { background: var(--sev-good-bg); color: var(--sev-good); }
.lint-sev.warn { background: var(--sev-warn-bg); color: var(--sev-warn); }
.lint-sev.crit { background: var(--sev-error-bg); color: var(--sev-error); }
.lint-body { display: flex; flex-direction: column; gap: .1rem; }
.lint-path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; color: var(--muted); }
.lint-msg { color: var(--fg); }
.preview { background: var(--pill-bg); border: 1px solid var(--border); border-radius: 8px; padding: .7rem .8rem; overflow-x: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; line-height: 1.55; margin: 0; }

.btn { display: inline-flex; align-items: center; border: 1px solid var(--border); background: var(--bg); color: var(--fg); font: inherit; font-weight: 600; font-size: .88rem; padding: .45rem .9rem; border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
/* Discard. Muted until hovered rather than permanently red: it sits beside the two buttons an
   author uses constantly, and a standing red button next to Save reads as a warning about the
   page instead of an action. Uses the lint palette's error tokens so there is one red. */
.btn.danger { color: var(--sev-error); }
.btn.danger:hover { border-color: var(--sev-error); background: var(--sev-error-bg); }
.save-bar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.save-note { font-size: .8rem; color: var(--muted); }
/* A save-bar INSIDE a panel is the Test run one (the editor's own sits outside .panel, after it
   closes). Two fixes for the sidebar's narrow column: give the button row air from the field
   above it, and put the note on its own full-width line instead of letting it half-wrap around
   the button — at ~265px of usable width it can never fit beside one. */
.panel .save-bar { margin-top: .9rem; }
.panel .save-bar .save-note { flex-basis: 100%; }

/* Drafts. A draft is deliberately NOT styled like a version pill: versions are
   published facts callers can submit against, a draft is private work-in-progress, so it gets
   the warning palette instead of the indigo one. Same treatment on the list badge and the
   editor header so the two read as the same thing. */
.draft-pill { background: var(--sev-warn-bg); color: var(--sev-warn); text-decoration: none; }
a.draft-pill:hover { filter: brightness(.97); text-decoration: underline; }
.drafts-h { font-size: 1.05rem; margin: 1.75rem 0 .4rem; }
/* The badge follows the family name on a list row, so it needs to sit apart from the link. */
table.specs td.name .draft-pill { margin-left: .4rem; }

/* Test run — status + result under the run button. */
.run-result { margin-top: .9rem; }
.run-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.run-meta { font-size: .8rem; color: var(--muted); }
