:root {
  --paper: #eef1f4;
  --surface: #ffffff;
  --ink: #1b2533;
  --muted: #5f6b7a;
  --line: #d5dbe2;
  --primary: #2f5d50;
  --primary-ink: #ffffff;
  --primary-hover: #24493f;
  --side: #1d3630;
  --side-ink: #e6eeeb;
  --side-muted: #9fb5ae;
  --brass: #c79a4a;
  --danger: #a3352b;
  --ok: #2e7d4f;
  --warn: #9a6a12;
  --focus: #3b7bd6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #12181f;
    --surface: #1a222b;
    --ink: #e4e9ee;
    --muted: #9aa6b3;
    --line: #2d3843;
    --primary: #4f8f7c;
    --primary-ink: #0d1512;
    --primary-hover: #63a38f;
    --side: #0e1a17;
    --side-ink: #dfe9e5;
    --side-muted: #85a097;
    --danger: #e0786d;
    --ok: #6cc28f;
    --warn: #e2b45a;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.6 Manrope, "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--primary); text-underline-offset: 3px; }
h1 { font-size: 30px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 10px; }
h2 { font-size: 17px; font-weight: 700; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 700; margin: 24px 0 10px; }
code { font-size: 13px; background: var(--paper); padding: 1px 5px; border-radius: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- Public shell ---------- */
.shell { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink);
  padding: 40px 36px; display: flex; flex-direction: column; gap: 28px;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: -0.01em; color: inherit; text-decoration: none; }
.side-lede { margin: 0; color: var(--side-muted); max-width: 30ch; }
.side-foot { margin-top: auto; font-size: 13px; color: var(--side-muted); }
.side-foot a { color: var(--side-ink); }

/* The step rail: the one deliberate visual element */
.rail { list-style: none; margin: 8px 0 0; padding: 0; position: relative; }
.rail::before {
  content: ""; position: absolute; left: 15px; top: 16px; bottom: 16px;
  width: 2px; background: color-mix(in srgb, var(--side-muted) 35%, transparent);
}
.rail li { position: relative; display: flex; align-items: center; gap: 14px; padding: 9px 0; }
.rail-dot {
  position: relative; z-index: 1; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--side); border: 2px solid color-mix(in srgb, var(--side-muted) 50%, transparent); color: var(--side-muted);
}
.rail-label { color: var(--side-muted); }
.rail-done .rail-dot { background: var(--side-muted); border-color: var(--side-muted); color: var(--side); }
.rail-done .rail-label { color: var(--side-ink); }
.rail-now .rail-dot { border-color: var(--brass); color: var(--side); background: var(--brass); box-shadow: 0 0 0 5px color-mix(in srgb, var(--brass) 22%, transparent); }
.rail-now .rail-label { color: var(--side-ink); font-weight: 700; }

.main { padding: 56px clamp(20px, 6vw, 88px); }
.panel { max-width: 520px; }
.lede { color: var(--muted); font-size: 16px; margin: 0 0 28px; max-width: 60ch; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.label { font-weight: 600; font-size: 14px; }
.optional { font-weight: 400; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
input, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 5px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { border-color: var(--primary); outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); outline-offset: 0; }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
.field-error { margin: 0; color: var(--danger); font-size: 13px; font-weight: 600; }
.code-input { font-size: 26px; font-weight: 700; letter-spacing: 0.4em; max-width: 240px; padding: 10px 14px; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: auto; }
.hp { position: absolute; left: -9999px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
  padding: 11px 20px; border-radius: 5px; border: 1px solid transparent; text-decoration: none;
  justify-self: start;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--primary); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.resend { margin-top: 22px; color: var(--muted); font-size: 14px; }

.notice { padding: 12px 14px; border-radius: 5px; margin: 0 0 20px; border-left: 4px solid; background: var(--surface); }
.notice-error { border-color: var(--danger); }
.notice-success { border-color: var(--ok); }

.next { margin-top: 8px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.next ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; min-height: 0; }
  .side { padding: 24px 20px; gap: 16px; }
  .side-lede, .side-foot { display: none; }
  .rail { display: flex; gap: 6px; margin: 0; }
  .rail::before { display: none; }
  .rail li { flex: 1; flex-direction: column; align-items: flex-start; gap: 6px; padding: 0; }
  .rail-label { font-size: 12px; line-height: 1.3; }
  .rail-dot { width: 26px; height: 26px; font-size: 12px; }
  .main { padding: 28px 20px 48px; }
  h1 { font-size: 26px; }
}

/* ---------- Admin ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px clamp(16px, 3vw, 32px); background: var(--side); color: var(--side-ink);
}
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.topbar .btn-ghost { color: var(--side-ink); border-color: color-mix(in srgb, var(--side-muted) 50%, transparent); }
.admin-main { padding: 24px clamp(16px, 3vw, 32px) 64px; }
.login { max-width: 400px; margin: 40px auto; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tab { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; display: flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--ink); }
.tab-on { color: var(--ink); border-color: var(--brass); }
.tab-right { margin-left: auto; }
.count { font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; color: var(--muted); }

.search { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; max-width: 560px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: left; font-size: 13px; font-weight: 700; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid.compact td, .grid.compact th { padding: 8px 10px; }
.reason { max-width: 36ch; font-size: 13px; margin-top: 2px; }
.details { max-width: 40ch; font-size: 12px; color: var(--muted); word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 36px 14px; }
.ok { color: var(--ok); font-weight: 700; }
.warn { color: var(--warn); font-size: 12px; }
.col-actions { white-space: nowrap; }
.col-actions > * { margin: 0 4px 4px 0; vertical-align: top; }
.inline { display: inline-block; }

.act { display: inline-block; vertical-align: top; }
.act[open] { display: block; }
.act summary { list-style: none; }
.act summary::-webkit-details-marker { display: none; }
.popover {
  margin-top: 8px; width: 280px; max-width: 100%;
  display: grid; gap: 10px; padding: 14px; white-space: normal;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
}

.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 3px; background: var(--paper); white-space: nowrap; }
.tag-approved { color: var(--ok); }
.tag-rejected, .tag-revoked, [class*="-failed"] { color: var(--danger); }

.pager { display: flex; gap: 6px; margin-top: 16px; }
.pager a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; }
.pager a.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; align-items: start; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 22px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.doclist { margin: 4px 0 0; padding-left: 16px; font-size: 12px; color: var(--muted); max-width: 34ch; }
.libpick { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.libpick legend { margin-bottom: 4px; }
.libpick .check { align-items: flex-start; font-size: 13px; line-height: 1.4; }
.libpick .check input { margin-top: 2px; }
.req { font-size: 11px; font-weight: 700; color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); padding: 0 6px; border-radius: 3px; white-space: nowrap; }
.libtags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; max-width: 40ch; }
.libtag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 3px; background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); }
