/* AJS Software: documentation layout
   1 tokens  2 base  3 top bar  4 sidebar  5 article  6 blocks  7 tool  8 form  9 footer  10 narrow */

/* 1 tokens */
:root {
  --paper: #FFFFFF;
  --wash: #F6F8FA;
  --purple: #6F42C1;
  --purple-soft: #F3EEFB;
  --ink: #1F2328;
  --green: #1A7F37;
  --green-soft: #E9F6EC;
  --grey: #59636E;
  --hair: #D8DEE4;
  --danger: #B42318;
  --danger-soft: #FDEEEC;
  --ui: "Ubuntu", "Segoe UI", system-ui, -apple-system, sans-serif;
  --code: "Ubuntu Mono", ui-monospace, Consolas, "Liberation Mono", monospace;
  --bar: 58px;
}

/* 2 base */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--bar) + 18px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--code);
  font-size: 1.125rem;
  line-height: 1.6;
}
a { color: var(--purple); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { font-family: var(--ui); line-height: 1.25; overflow-wrap: anywhere; }
p { margin: 0 0 1.05em; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 3 top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--hair);
  font-family: var(--ui);
}
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  min-width: 0;
}
.topbar-brand svg { width: 30px; height: 30px; flex: none; }
.topbar-brand:hover { color: var(--purple); }
.topbar-crumb { color: var(--grey); font-size: .92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-crumb b { color: var(--ink); font-weight: 500; }
.topbar-cta {
  margin-left: auto;
  flex: none;
  padding: 8px 16px;
  border: 1px solid var(--purple);
  border-radius: 6px;
  color: var(--purple);
  font-weight: 500;
  font-size: .95rem;
  text-decoration: none;
}
.topbar-cta:hover { background: var(--purple); color: #fff; }
.drawer-btn {
  display: none;
  flex: none;
  width: 46px;
  height: 46px;
  margin-left: -10px;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
}
.drawer-btn:hover { background: var(--wash); border-color: var(--hair); }
.drawer-btn svg { width: 24px; height: 24px; }
.drawer-btn .x { display: none; }
.drawer-btn[aria-expanded="true"] .x { display: block; }
.drawer-btn[aria-expanded="true"] .bars { display: none; }

/* 4 sidebar */
.docs { display: grid; grid-template-columns: 276px minmax(0, 1fr); }
.sidenav {
  position: sticky;
  top: var(--bar);
  align-self: start;
  height: calc(100vh - var(--bar));
  overflow-y: auto;
  padding: 28px 16px 40px 22px;
  background: var(--wash);
  border-right: 1px solid var(--hair);
  font-family: var(--ui);
}
.sidenav-label {
  margin: 0 0 8px;
  padding-left: 12px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--grey);
}
.sidenav ul { list-style: none; margin: 0 0 26px; padding: 0; }
.sidenav a {
  display: block;
  padding: 9px 12px;
  border-left: 3px solid transparent;
  border-radius: 0 6px 6px 0;
  color: var(--ink);
  font-size: 1rem;
  text-decoration: none;
}
.sidenav a:hover { background: #ECEFF3; }
.sidenav a[aria-current="page"] {
  border-left-color: var(--purple);
  background: var(--purple-soft);
  color: var(--purple);
  font-weight: 700;
}
.sidenav-note { margin: 0; padding: 14px 12px 0; border-top: 1px solid var(--hair); font-size: .9rem; color: var(--grey); }
.scrim { position: fixed; inset: var(--bar) 0 0 0; z-index: 20; background: rgba(31, 35, 40, .45); }

/* 5 article */
.page {
  display: grid;
  grid-template-columns: minmax(0, 770px) 210px;
  column-gap: 60px;
  justify-content: start;
  padding: 38px clamp(20px, 4.5vw, 64px) 0;
  min-width: 0;
}
.article { min-width: 0; }
.trail { margin: 0 0 18px; font-family: var(--ui); font-size: .9rem; color: var(--grey); }
.trail a { color: var(--grey); }
.article h1 { margin: 0 0 .5em; font-size: clamp(1.9rem, 5vw, 2.7rem); font-weight: 700; letter-spacing: -.015em; }
.article h2 {
  margin: 2.3em 0 .7em;
  padding-bottom: .35em;
  border-bottom: 1px solid var(--hair);
  font-size: clamp(1.3rem, 3vw, 1.6rem);
  font-weight: 700;
}
.article h3 { margin: 1.6em 0 .5em; font-size: 1.1rem; font-weight: 700; }
.anchor { margin-left: .3em; color: var(--hair); text-decoration: none; font-weight: 400; }
h2:hover .anchor, .anchor:focus-visible { color: var(--purple); }
.standfirst { font-family: var(--ui); font-size: clamp(1.12rem, 2.2vw, 1.3rem); line-height: 1.55; color: #3A424B; }
.article ul, .article ol { margin: 0 0 1.1em; padding-left: 1.4em; }
.article li { margin-bottom: .45em; }
.article li::marker { color: var(--purple); }
code { font-family: var(--code); background: var(--wash); border: 1px solid var(--hair); border-radius: 4px; padding: 0 .3em; }

.toc { position: sticky; top: calc(var(--bar) + 38px); align-self: start; font-family: var(--ui); font-size: .92rem; min-width: 0; }
.toc-title { margin: 0 0 10px; font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--grey); }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--hair); }
.toc a { display: block; margin-left: -1px; padding: 6px 0 6px 14px; border-left: 2px solid transparent; color: var(--grey); text-decoration: none; }
.toc a:hover { color: var(--ink); }
.toc a.here { color: var(--purple); border-left-color: var(--purple); font-weight: 500; }

/* 6 blocks */
.callout {
  margin: 1.5em 0;
  padding: 16px 18px 16px 20px;
  border: 1px solid var(--hair);
  border-left: 5px solid var(--purple);
  border-radius: 6px;
  background: var(--purple-soft);
}
.callout > :last-child { margin-bottom: 0; }
.callout-title { margin: 0 0 4px; font-family: var(--ui); font-weight: 700; font-size: .95rem; color: var(--purple); }
.callout.tip { border-left-color: var(--green); background: var(--green-soft); }
.callout.tip .callout-title { color: var(--green); }
.callout.caution { border-left-color: var(--danger); background: var(--danger-soft); }
.callout.caution .callout-title { color: var(--danger); }

.codeblock {
  margin: 1.4em 0;
  border: 1px solid var(--hair);
  border-radius: 8px;
  background: var(--wash);
  overflow: hidden;
}
.codeblock-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--hair);
  background: #EEF1F4;
  font-family: var(--ui);
  font-size: .82rem;
  color: var(--grey);
}
.codeblock pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--code);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
}
.codeblock .k { color: var(--purple); }
.codeblock .s { color: var(--green); }
.codeblock .c { color: var(--grey); }

.ref { width: 100%; margin: 1.3em 0; border-collapse: collapse; font-size: 1.05rem; }
.ref th, .ref td { padding: 12px 14px; border: 1px solid var(--hair); text-align: left; vertical-align: top; }
.ref thead th { background: var(--wash); font-family: var(--ui); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; color: var(--grey); }
.ref tbody th { font-family: var(--ui); font-weight: 700; white-space: nowrap; }

.steps { list-style: none; margin: 1.4em 0; padding: 0; counter-reset: s; }
.steps > li {
  counter-increment: s;
  position: relative;
  margin: 0;
  padding: 0 0 22px 52px;
  border-left: 2px solid var(--hair);
  margin-left: 16px;
}
.steps > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.steps > li::before {
  content: counter(s);
  position: absolute;
  left: -17px; top: -2px;
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-family: var(--ui);
  font-weight: 700;
  font-size: .95rem;
}
.steps b { font-family: var(--ui); display: block; margin-bottom: 2px; }

.stage {
  display: grid;
  grid-template-columns: 9.5em minmax(0, 1fr);
  gap: 6px 20px;
  padding: 16px 0;
  border-bottom: 1px solid var(--hair);
}
.stage:first-of-type { border-top: 1px solid var(--hair); }
.stage p { margin: 0; }
.badge {
  justify-self: start;
  align-self: start;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--purple);
  color: #fff;
  font-family: var(--ui);
  font-size: .85rem;
  font-weight: 500;
}
.badge.done { background: var(--green); }
.badge.plain { background: var(--wash); color: var(--ink); border: 1px solid var(--hair); }

.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 3em 0 0; font-family: var(--ui); }
.pager a { display: block; padding: 14px 18px; border: 1px solid var(--hair); border-radius: 8px; text-decoration: none; color: var(--ink); min-width: 0; }
.pager a:hover { border-color: var(--purple); box-shadow: 0 0 0 1px var(--purple); }
.pager small { display: block; color: var(--grey); font-size: .8rem; }
.pager span { color: var(--purple); font-weight: 700; overflow-wrap: anywhere; }
.pager .fwd { text-align: right; grid-column: 2; }

/* 7 tool */
.tool { margin: 1.4em 0; border: 1px solid var(--hair); border-radius: 8px; overflow: hidden; }
.tool-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; background: var(--wash); border-bottom: 1px solid var(--hair); font-family: var(--ui); }
.tool-bar button, .tool-bar select {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: .95rem;
  cursor: pointer;
}
.tool-bar button:hover { border-color: var(--purple); color: var(--purple); }
.tool-bar button.primary { background: var(--purple); border-color: var(--purple); color: #fff; font-weight: 500; }
.tool-bar button.primary:hover { background: #5A32A3; color: #fff; }
.tool-indent { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.tool-bar label { font-size: .9rem; color: var(--grey); }
.ref .nowrap { white-space: nowrap; }
.tool-panes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tool-pane { min-width: 0; display: flex; flex-direction: column; }
.tool-pane + .tool-pane { border-left: 1px solid var(--hair); }
.tool-pane > label, .tool-pane > .pane-label { padding: 8px 14px; font-family: var(--ui); font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--grey); border-bottom: 1px solid var(--hair); }
.tool textarea, .tool-out {
  flex: 1 1 auto;
  width: 100%;
  height: 300px;
  margin: 0;
  padding: 14px;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--code);
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
}
.tool textarea:focus-visible { outline-offset: -3px; }
.tool-out { overflow: auto; white-space: pre; background: var(--wash); resize: none; }
.tool-out:focus-visible { outline-offset: -3px; }
.tool-status { margin: 0; padding: 12px 14px; border-top: 1px solid var(--hair); font-family: var(--ui); font-size: .98rem; color: var(--grey); overflow-wrap: anywhere; }
.tool-status.ok { background: var(--green-soft); color: var(--green); font-weight: 500; }
.tool-status.bad { background: var(--danger-soft); color: var(--danger); font-weight: 500; }

/* 8 form */
.details { margin: 1.2em 0; border: 1px solid var(--hair); border-radius: 8px; overflow: hidden; }
.details-row { display: grid; grid-template-columns: 11em minmax(0, 1fr); border-bottom: 1px solid var(--hair); }
.details-row:last-child { border-bottom: 0; }
.details dt { padding: 12px 14px; background: var(--wash); font-family: var(--ui); font-weight: 500; }
.details dd { margin: 0; padding: 12px 14px; overflow-wrap: anywhere; }

.docform { margin: 1.3em 0; padding: 22px; border: 1px solid var(--hair); border-radius: 8px; background: var(--wash); }
.docform .row { margin-bottom: 18px; }
.docform label { display: block; margin-bottom: 6px; font-family: var(--ui); font-weight: 500; font-size: 1rem; }
.docform input, .docform select, .docform textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #AAB4BE;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--code);
  font-size: 1.05rem;
}
.docform textarea { min-height: 160px; resize: vertical; }
.docform .invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.docform .problem { margin: 6px 0 0; font-family: var(--ui); font-size: .92rem; color: var(--danger); }
.docform button {
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 6px;
  background: var(--purple);
  color: #fff;
  font-family: var(--ui);
  font-size: 1.02rem;
  font-weight: 500;
  cursor: pointer;
}
.docform button:hover { background: #5A32A3; }
.docform .after { margin: 12px 0 0; font-size: 1rem; color: var(--grey); }
.docform .handoff { margin: 14px 0 0; padding: 10px 14px; border-left: 4px solid var(--green); background: var(--green-soft); font-family: var(--ui); font-size: .98rem; }

/* 9 footer */
.docfoot {
  grid-column: 1 / -1;
  margin-top: 64px;
  padding: 30px 0 44px;
  border-top: 1px solid var(--hair);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  gap: 30px;
  font-family: var(--ui);
  font-size: .95rem;
  max-width: 1040px;
}
.docfoot > * { min-width: 0; }
.docfoot-brand { margin: 0 0 4px; font-weight: 700; font-size: 1.05rem; }
.docfoot-line { margin: 0 0 14px; color: var(--grey); }
.docfoot ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 20px; }
.docfoot li { margin-bottom: 8px; break-inside: avoid; }
.docfoot dl { margin: 0; }
.docfoot dl div { display: grid; grid-template-columns: 9.5em minmax(0, 1fr); gap: 10px; padding: 5px 0; }
.docfoot dt { color: var(--grey); }
.docfoot dd { margin: 0; overflow-wrap: anywhere; }

/* 10 narrow */
@media (max-width: 1180px) {
  .page { grid-template-columns: minmax(0, 770px); }
  .toc { display: none; }
}
@media (max-width: 900px) {
  .docs { grid-template-columns: minmax(0, 1fr); }
  .drawer-btn { display: inline-flex; }
  .topbar { padding: 0 16px; }
  .topbar-crumb { display: none; }
  .sidenav {
    display: none;
    position: fixed;
    z-index: 30;
    top: var(--bar);
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    height: auto;
    box-shadow: 12px 0 30px -12px rgba(31, 35, 40, .35);
  }
  .sidenav.open { display: block; }
  .sidenav a { padding: 12px; }
}
@media (max-width: 640px) {
  body { font-size: 1.0625rem; }
  .page { padding: 26px 16px 0; }
  .tool-panes { grid-template-columns: minmax(0, 1fr); }
  .tool-pane + .tool-pane { border-left: 0; border-top: 1px solid var(--hair); }
  .tool textarea, .tool-out { height: 210px; }
  .tool-indent { margin-left: 0; }
  .codeblock pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  .ref .nowrap { white-space: normal; }
  .ref thead { display: none; }
  .ref, .ref tbody, .ref tr, .ref th, .ref td { display: block; }
  .ref tr { border: 1px solid var(--hair); border-radius: 6px; margin-bottom: 12px; overflow: hidden; }
  .ref th, .ref td { border: 0; padding: 10px 14px; }
  .ref tbody th { background: var(--wash); white-space: normal; }
  .ref td + td { padding-top: 0; }
  .stage { grid-template-columns: minmax(0, 1fr); }
  .details-row { grid-template-columns: minmax(0, 1fr); }
  .details dt { padding-bottom: 4px; }
  .docfoot { grid-template-columns: minmax(0, 1fr); }
  .docfoot ul { columns: 1; }
  .docfoot dl div { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 7px 0; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .fwd { grid-column: 1; }
  .topbar-cta { padding: 8px 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
