:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --ink: #1c1a17;
  --ink-soft: #55504a;
  --line: #e4ded5;
  --accent: #7a5c3e;
  --accent-ink: #ffffff;
  --ready: #2f6b3f;
  --ready-bg: #e7f2e9;
  --needs: #8a5a12;
  --needs-bg: #fbeed9;
  --deferred: #5a5650;
  --deferred-bg: #eceae6;
  --phase1: #7a5c3e;
  --phase2: #3e6b7a;
  --phase3: #6b5c9e;
  --phase4: #3f7a5c;
  --radius: 10px;
  --choice: #3e6b7a;
  --choice-bg: #e7eef2;
  --ref: #6b5c9e;
  --ref-bg: #efebf9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --surface: #211e1a;
    --ink: #f1ede6;
    --ink-soft: #b9b0a4;
    --line: #3a352d;
    --accent: #d8b487;
    --accent-ink: #1c1a17;
    --ready: #7fd694;
    --ready-bg: #1e2f22;
    --needs: #f0b25f;
    --needs-bg: #332711;
    --deferred: #b7b0a4;
    --deferred-bg: #2a2822;
    --phase1: #d8b487;
    --phase2: #8fc4d6;
    --phase3: #b7a6e8;
    --phase4: #8fd6b4;
    --choice: #8fc4d6;
    --choice-bg: #1c2a30;
    --ref: #b7a6e8;
    --ref-bg: #2a2438;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}

a { color: var(--accent); }

.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.site-header .inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-header .brand {
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--ink);
}

.site-header .brand span {
  color: var(--ink-soft);
  font-weight: 400;
}

.site-header nav a {
  text-decoration: none;
  font-size: 0.9rem;
  margin-left: 18px;
  color: var(--ink-soft);
}

.site-header nav a:hover { color: var(--accent); }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.intro h1 {
  font-size: 1.9rem;
  margin: 0 0 8px;
}

.intro p.lede {
  color: var(--ink-soft);
  max-width: 68ch;
  font-size: 1.02rem;
}

.meta-strip {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 18px 0 8px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.phase-section { margin-top: 40px; }

.phase-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  margin-bottom: 4px;
}

.phase-title .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.phase-desc {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 16px;
  max-width: 68ch;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: border-color .15s ease, transform .15s ease;
}

.card:hover {
  border-color: var(--accent);
}

.card .card-num {
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.card h3 {
  margin: 4px 0 8px;
  font-size: 1.02rem;
}

.status-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2px 9px;
  border-radius: 999px;
  text-transform: uppercase;
}

.status-ready { color: var(--ready); background: var(--ready-bg); }
.status-needs { color: var(--needs); background: var(--needs-bg); }
.status-deferred { color: var(--deferred); background: var(--deferred-bg); }

/* Procedure detail page */

.proc-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.phase-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--accent-ink);
}

.phase-badge.p1 { background: var(--phase1); }
.phase-badge.p2 { background: var(--phase2); }
.phase-badge.p3 { background: var(--phase3); }
.phase-badge.p4 { background: var(--phase4); }

article h1 {
  font-size: 1.7rem;
  margin: 4px 0 20px;
}

.facts {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 28px;
}

.facts dt {
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.facts dd {
  margin: 0;
  font-size: 0.95rem;
}

article h2 {
  font-size: 1.1rem;
  margin: 30px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

article ol, article ul {
  padding-left: 22px;
}

article li {
  margin-bottom: 8px;
}

.needs-input {
  background: var(--needs-bg);
  color: var(--needs);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 600;
  font-size: 0.92em;
}

/* Same shape as .needs-input, for the parts that now exist in the file. */
.built {
  background: var(--ready-bg);
  color: var(--ready);
  border-radius: 6px;
  padding: 1px 6px;
  font-weight: 600;
  font-size: 0.92em;
}

.note-box {
  border-left: 3px solid var(--accent);
  background: var(--surface);
  padding: 12px 16px;
  margin: 20px 0;
  font-size: 0.92rem;
  color: var(--ink-soft);
  border-radius: 0 6px 6px 0;
}

.prevnext {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.prevnext a { text-decoration: none; }

footer.site-footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.8rem;
  padding: 30px 24px 50px;
}

/* Grist field-reference tables */

.legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 18px 0 28px;
}

article h3 {
  font-size: 1.15rem;
  margin: 32px 0 4px;
}

article h3 code {
  font-size: 0.85em;
}

.table-note {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 0 10px;
  max-width: 68ch;
}

.field-table-wrap {
  overflow-x: auto;
  margin: 0 0 28px;
}

.field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.field-table th,
.field-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.field-table tr:last-child td { border-bottom: none; }

.field-table th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--bg);
}

.field-table td.field-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  white-space: nowrap;
}

.tag {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.tag-formula { color: var(--deferred); background: var(--deferred-bg); }
.tag-choice { color: var(--choice); background: var(--choice-bg); }
.tag-ref { color: var(--ref); background: var(--ref-bg); }
.tag-required { color: var(--needs); background: var(--needs-bg); }

.workflow-list {
  counter-reset: workflow;
  list-style: none;
  padding-left: 0;
}

.workflow-list > li {
  counter-increment: workflow;
  position: relative;
  padding-left: 38px;
  margin-bottom: 14px;
}

.workflow-list > li::before {
  content: counter(workflow);
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.id-example {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 0.9em;
}

/* ---- Data-model map (reference/grist-data-model.html) ---- */

.model-figure {
  margin: 26px 0 34px;
}

.model-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}

.model-map {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.model-map text {
  font-family: inherit;
  text-anchor: middle;
  fill: var(--ink);
}

.model-map .n-name { font-size: 13px; font-weight: 650; }
.model-map .n-role { font-size: 9.5px; fill: var(--ink-soft); }
.model-map .e-label { font-size: 10px; fill: var(--ink-soft); }

.model-map .node rect {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.5;
}

.model-map .node.is-core rect {
  stroke: var(--ink-soft);
  stroke-width: 2;
}

.model-map .node.is-new rect {
  fill: var(--ref-bg);
  stroke: var(--ref);
  stroke-width: 2;
}

.model-map .edge {
  fill: none;
  stroke: var(--ink-soft);
  stroke-width: 1.4;
  marker-end: url(#mm-arrow);
}

.model-map .edge.spine { marker-end: none; }

.model-map .edge.optional {
  stroke: var(--ref);
  stroke-dasharray: 5 4;
  marker-end: url(#mm-arrow-opt);
}

.model-map .edge.optional.spine { marker-end: none; }

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  align-items: center;
  margin: 14px 2px 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.map-legend span { display: inline-flex; align-items: center; gap: 7px; }

.legend-box {
  width: 22px;
  height: 13px;
  border-radius: 3px;
  border: 1.5px solid var(--line);
  background: var(--surface);
}

.legend-box.core { border: 2px solid var(--ink-soft); }
.legend-box.new { border: 2px solid var(--ref); background: var(--ref-bg); }

.legend-line {
  width: 26px;
  height: 0;
  border-top: 1.5px solid var(--ink-soft);
}

.legend-line.dashed { border-top: 1.5px dashed var(--ref); }

.money-example {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
  margin: 0 0 16px;
}

.money-example h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.money-example .who {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.money-example table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.money-example td {
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
}

.money-example td.amt {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-left: 12px;
}

.money-example tr.total td {
  border-bottom: none;
  border-top: 2px solid var(--line);
  font-weight: 700;
  padding-top: 8px;
}

.money-example .note {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}
