:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #667085;
  --accent: #1f6feb;
  --accent-soft: #e6f0ff;
  --ok: #1a7f37;
  --warn: #b26a00;
  --err: #c62828;
  --mono: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Roboto", "Helvetica", "Arial", sans-serif;
  --radius: 8px;
  --topbar-h: 64px;
  --sidebar-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --panel: #161c24; --border: #2a333f; --text: #e6ebf1; --muted: #93a0b0;
    --accent: #4c8dff; --accent-soft: #1b2a45;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
button { font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:disabled { opacity: .6; cursor: default; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.tiny { padding: 2px 8px; font-size: 12px; }
input, select { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; gap: 20px; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 11.5px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { display: flex; align-items: flex-end; gap: 10px; flex: 1; }
.field { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.field input, .field select { font-size: 13px; }
.field.grow { flex: 1; }
.token-wrap { display: flex; gap: 4px; }
.token-wrap input { flex: 1; font-family: var(--mono); }
.check { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); padding-bottom: 7px; white-space: nowrap; }
.status { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); min-width: 150px; justify-content: flex-end; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa4b2; flex: none; }
.status .status-text { max-width: 360px; text-align: right; } /* a proxy refusal's message wraps here, within the bar's height, rather than squeezing the form */
.status.ok .dot { background: var(--ok); } .status.err .dot { background: var(--err); } .status.busy .dot { background: var(--warn); }

/* layout */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: calc(100vh - var(--topbar-h)); }
.sidebar { border-right: 1px solid var(--border); background: var(--panel); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow: auto; }
.nav-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 12px 8px 4px; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 6px; color: var(--text); }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-path { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.nav-count { font-size: 11px; background: var(--bg); border: 1px solid var(--border); padding: 0 7px; border-radius: 10px; color: var(--muted); min-width: 22px; text-align: center; }
.nav-item.active .nav-count { border-color: var(--accent); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding: 10px 8px 0; font-size: 12px; border-top: 1px solid var(--border); }
.content { padding: 22px 26px 60px; min-width: 0; }

/* family page */
.family-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 14px; flex-wrap: wrap; }
.family-title { margin: 0 0 4px; font-size: 22px; }
.family-title code { font-size: 14px; color: var(--muted); margin-left: 8px; }
.family-desc { margin: 0; color: var(--muted); max-width: 900px; line-height: 1.45; }
.tabs { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.tab { border: none; background: transparent; padding: 5px 12px; border-radius: 6px; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.inline-field input { width: 190px; }
.inline-field input.by-id { width: 110px; }

.meta-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; min-height: 26px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); }
.chip b { color: var(--text); font-weight: 600; }
.chip.mono b { font-family: var(--mono); }
.chip.ok { border-color: #9fd7ae; color: var(--ok); } .chip.ok b { color: var(--ok); }
.chip.warn { border-color: #f0c674; color: var(--warn); } .chip.warn b { color: var(--warn); }
.chip.err { border-color: #f1a5a5; color: var(--err); } .chip.err b { color: var(--err); }
/* the Data tab's pager: the list's own pages, at the end of the meta strip */
.meta-strip .pager { display: inline-flex; gap: 6px; margin-left: auto; }
.pager button { padding: 3px 10px; font-size: 12px; }
.pager button:disabled { opacity: .45; cursor: default; }

.alert { padding: 10px 14px; border-radius: var(--radius); border: 1px solid #f1a5a5; background: #fff2f2; color: var(--err); margin-bottom: 10px; line-height: 1.5; }
@media (prefers-color-scheme: dark) { .alert { background: #3a1c1c; } }
.alert code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; }
.alert .alert-title { font-weight: 700; }

.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; cursor: help; }
tbody tr:hover { background: var(--bg); }
tr.clickable { cursor: pointer; }
td.key a { font-family: var(--mono); font-weight: 600; }
td .null { color: var(--muted); font-style: italic; }
td .bool-t { color: var(--ok); font-weight: 700; } td .bool-f { color: var(--muted); }
td .num, td .int64 { font-family: var(--mono); }
td .sub { display: block; color: var(--muted); font-size: 11px; }
.enum { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--border); background: var(--bg); }
.enum.e-active, .enum.e-verified { background: #e6f6ea; color: var(--ok); border-color: #9fd7ae; }
.enum.e-pending_approval, .enum.e-draft, .enum.e-discovered, .enum.e-unverified { background: #fff6e0; color: var(--warn); border-color: #f0c674; }
.enum.e-suspended, .enum.e-frozen, .enum.e-revoked, .enum.e-retired { background: #fdecec; color: var(--err); border-color: #f1a5a5; }
.enum.e-unknown, .enum.e-none { color: var(--muted); }
/* the order lifecycle (orders-domain.md 3.2): the live band, the proven terminals, the provisional one */
.enum.e-queued, .enum.e-instructed { background: #fff6e0; color: var(--warn); border-color: #f0c674; }
.enum.e-open, .enum.e-partially_filled, .enum.e-filled { background: #e6f6ea; color: var(--ok); border-color: #9fd7ae; }
.enum.e-canceled, .enum.e-rejected, .enum.e-expired, .enum.e-instruction_expired, .enum.e-not_found_at_venue { background: #fdecec; color: var(--err); border-color: #f1a5a5; }
.enum.e-expired_unconfirmed { background: #fff6e0; color: var(--err); border-color: #f0c674; }
.enum.e-buy { background: #e6f6ea; color: var(--ok); border-color: #9fd7ae; }
.enum.e-sell { background: #fdecec; color: var(--err); border-color: #f1a5a5; }
.empty-state { padding: 34px; text-align: center; color: var(--muted); }

/* docs */
.doc-section { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.doc-section h2 { margin: 0 0 6px; font-size: 15px; }
.doc-section h3 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.doc-section p { line-height: 1.5; margin: 6px 0; }
.op-line { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.method { font-family: var(--mono); font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 5px; background: #e6f6ea; color: var(--ok); }
.op-path { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.op-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); padding: 1px 7px; border-radius: 10px; }
.doc-table th, .doc-table td { white-space: normal; }
.doc-table td.name { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.doc-table td.type { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
.req { color: var(--err); font-size: 11px; font-weight: 700; margin-left: 4px; }
.enum-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.desc-long { color: var(--muted); font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; }
.code-block { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-family: var(--mono); font-size: 12px; overflow: auto; white-space: pre; margin: 6px 0 0; }
details.spec-desc summary { cursor: pointer; color: var(--accent); font-size: 12.5px; }

/* overview */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 12px 0 18px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.card:hover { border-color: var(--accent); }
.card-title { font-weight: 700; font-size: 15px; }
.card-path { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 12px; color: var(--muted); }
.card-count { font-size: 20px; font-weight: 700; color: var(--text); }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10,14,20,.35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(720px, 94vw); background: var(--panel); border-left: 1px solid var(--border); z-index: 31; overflow: auto; padding: 18px 22px 40px; box-shadow: -6px 0 24px rgba(0,0,0,.15); }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.drawer-head h2 code { color: var(--muted); font-size: 13px; margin-left: 6px; }
.detail-table td.name { font-family: var(--mono); font-weight: 600; width: 220px; }
.detail-table td.val { white-space: normal; word-break: break-all; }
.detail-table td .hint { display: block; color: var(--muted); font-size: 11.5px; white-space: normal; margin-top: 2px; }
.drawer .code-block { max-height: 360px; }

@media (max-width: 1100px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; }
  .conn { flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
}

/* the order ticket */
.ticket { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; max-width: 1100px; }
.ticket-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; align-items: end; }
.ticket .field span em { font-style: normal; color: var(--muted); font-weight: 400; }
.ticket .field input, .ticket .field select { font-family: var(--mono); font-size: 13px; }
.ticket-check { padding-bottom: 9px; }
.ticket-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.ticket-hint { color: var(--muted); font-size: 12px; }
.ticket-result { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.ticket-result .result-title { font-weight: 700; margin-bottom: 6px; }
.ticket-result.ok .result-title { color: var(--ok); }
.ticket-result.err .result-title { color: var(--err); }
.ticket-result.busy .result-title { color: var(--warn); }
.ticket-result .result-line { margin: 3px 0; }
.drawer-actions { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
button.danger { border-color: #f1a5a5; color: var(--err); }
button.danger:hover { background: #fdecec; }
.drawer .legs { margin-top: 14px; }
.drawer .legs h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.method.m-post { background: var(--accent-soft); color: var(--accent); }

/* the Users page (identity plan R7): the /me banner, the admission band, the capability grid */
.me-banner { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 6px 18px; background: var(--accent-soft); border-bottom: 1px solid var(--border); font-size: 12.5px; }
.me-banner.warn { background: #fff6e0; }
@media (prefers-color-scheme: dark) { .me-banner.warn { background: #3a2f14; } }
.me-banner .sub { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.band { padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 10px; font-size: 12.5px; line-height: 1.5; }
.band.warn { border-color: #f0c674; background: #fff6e0; color: var(--warn); }
@media (prefers-color-scheme: dark) { .band.warn { background: #3a2f14; color: #f0c674; } }
/* a band's rows, each a link that opens its drawer over the page on screen */
.band a { color: inherit; text-decoration: underline; }
tr.row-discovered td, tr.row-pending td { background: #fff9eb; }
@media (prefers-color-scheme: dark) { tr.row-discovered td, tr.row-pending td { background: #2f2812; } }
/* the Orgs page (identity plan R8): the pending band, the activation form, the approval-count warning */
.org-write { margin-top: 12px; }
.org-form .approvals-warn { margin-top: 10px; }
.user-write { margin-top: 12px; }
.user-form .caps-head { margin: 14px 0 6px; font-size: 12.5px; }
.caps { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 14px; }
.caps .cap { padding: 2px 0; font-family: var(--mono); font-size: 12px; color: var(--text); }
.caps .cap.platform { color: var(--muted); }
/* the Credentials page (local-testing plan rung 1): the Add credential form — the legs' inputs and the derived-group chip */
.credential-form .band { margin-top: 12px; }
.credential-form .chip.err { color: var(--err); }

/* the Algos page (plans/algos-domain.md A4d): the document text area and its byte gauge, the
   drawer's remark, the lifecycle and the document outcome as chips */
.algo-form textarea, .algo-reconfigure textarea { font-family: var(--mono); font-size: 12.5px; width: 100%; resize: vertical; color: inherit; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.algo-form textarea:focus, .algo-reconfigure textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.doc-gauge { font-style: normal; color: var(--muted); }
.doc-gauge.over { color: var(--err); font-weight: 600; }
.algo-form .spec-desc pre { max-height: 240px; }
.algo-refs { margin-top: 8px; line-height: 1.5; }
.drawer-actions .algo-remark { flex: 1 1 220px; min-width: 180px; font-family: var(--mono); font-size: 12.5px; }
.toolbar .algo-remark { width: 220px; font-family: var(--mono); font-size: 12.5px; }
.drawer .doc-text { max-height: 260px; white-space: pre-wrap; word-break: break-word; }
tr.row-applied td { background: #f1f8f3; }
@media (prefers-color-scheme: dark) { tr.row-applied td { background: #14281b; } }
.enum.e-created, .enum.e-staged { background: #fff6e0; color: var(--warn); border-color: #f0c674; }
.enum.e-started, .enum.e-applied { background: #e6f6ea; color: var(--ok); border-color: #9fd7ae; }
.enum.e-stopped { color: var(--muted); }
.enum.e-error, .enum.e-deleted, .enum.e-refused { background: #fdecec; color: var(--err); border-color: #f1a5a5; }

/* the generated command surface (schema-form.js): one collapsed section per unsafe route the
   document publishes — on the family's Commands tab for the creates, on a row's drawer for
   the routes that name it. Deliberately the ticket's own look: a generated form and a
   hand-written one are the same kind of thing to the person using them. */
.tab.tab-link { display: inline-flex; align-items: center; color: var(--accent); }
.tab.tab-link:hover { background: var(--panel); }
.command { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; }
.command > summary { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; list-style: none; }
.command > summary::-webkit-details-marker { display: none; }
.command > summary::before { content: "▸"; color: var(--muted); }
.command[open] > summary::before { content: "▾"; }
.command[open] > summary { border-bottom: 1px solid var(--border); }
.command > summary:hover { background: var(--bg); }
.command .op-summary { color: var(--muted); font-size: 12.5px; }
.command > .desc-long { margin: 10px 14px 0; }
/* the form inside a section carries the section's frame, not its own */
.command .ticket { border: none; padding: 14px; max-width: none; }
.command .ticket-grid { align-items: start; }
.command .field { min-width: 0; }
.command .field details.spec-desc { margin-top: 4px; }
.command .field details.spec-desc summary { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.command .field details.spec-desc[open] summary { white-space: normal; }
.field-wide { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
fieldset.gen-object { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px 12px; margin: 0; }
fieldset.gen-object legend { font-size: 11px; color: var(--muted); padding: 0 4px; }
.row-commands { margin-top: 18px; }
.commands-head { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.method.m-put { background: #fff6e0; color: var(--warn); }
