:root {
  --bg: #f5f2ea;
  --surface: #fffdf8;
  --sunk: #efebe1;
  --ink: #17150f;
  --ink-2: #47433a;
  --muted: #7d776a;
  --line: #e2dccd;
  --line-2: #cfc7b4;
  --red: #b3261e;
  --red-ink: #8c1d17;
  --red-bg: #f9e9e6;
  --green: #2d6a39;
  --green-bg: #e5efe3;
  --amber: #85590a;
  --amber-bg: #f6ecd3;
  --sim: #545a83;
  --sim-bg: #e9e9f1;
  --focus: #1f4fd1;
  --r: 6px;
  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
code, .mono, pre, textarea.code { font-family: var(--mono); font-size: 12.5px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
p { margin: 0 0 8px; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--surface); padding: 20px 14px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand .mark { width: 22px; height: 22px; border: 2px solid var(--ink); border-radius: 4px; position: relative; }
.brand .mark::after { content: ""; position: absolute; inset: 4px 4px auto auto; width: 6px; height: 6px; background: var(--red); border-radius: 1px; }
.brand b { font-size: 15px; letter-spacing: 0.08em; }
.nav { display: flex; flex-direction: column; gap: 1px; }
.nav a { display: flex; justify-content: space-between; padding: 7px 10px; border-radius: var(--r); text-decoration: none; color: var(--ink-2); }
.nav a:hover { background: var(--sunk); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--surface); }
.nav .count { font-family: var(--mono); font-size: 11.5px; }
.nav a[aria-current="page"] .count { color: var(--surface); }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 6px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--bg);
  position: sticky; top: 0; z-index: 5; }
.top .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 64px; max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 4px 0 0; max-width: 70ch; }

/* primitives */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.card > .hd { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card > .bd { padding: 14px 16px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.kpi { padding: 14px 16px; border-right: 1px solid var(--line); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .v { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi.alert .v { color: var(--red); }

.btn { font: inherit; font-size: 13px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); padding: 6px 12px;
  border-radius: var(--r); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.primary:hover { background: #000; }
.btn.danger { color: var(--red-ink); border-color: #e2b4ad; }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.sm { padding: 3px 8px; font-size: 12px; }

input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 9px; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(31, 79, 209, 0.15); }
textarea.code { width: 100%; min-height: 460px; line-height: 1.55; resize: vertical; background: #fffef9; tab-size: 2; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: #fbf9f3; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #faf7ef; }
tr.sel td { background: #f3efe4; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; padding: 1px 7px;
  border-radius: 999px; border: 1px solid var(--line-2); color: var(--ink-2); background: var(--surface); white-space: nowrap; line-height: 18px; }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-red { color: var(--red-ink); background: var(--red-bg); border-color: #efc5bf; }
.b-green { color: var(--green); background: var(--green-bg); border-color: #c5dbc2; }
.b-amber { color: var(--amber); background: var(--amber-bg); border-color: #e9d5a6; }
.b-sim { color: var(--sim); background: var(--sim-bg); border-color: #cfd0e0; }
.b-ink { color: var(--surface); background: var(--ink); border-color: var(--ink); }
.b-muted { color: var(--muted); background: var(--sunk); border-color: var(--line); }
.lvl { font-family: var(--mono); font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 3px; border: 1px solid var(--line-2); background: var(--surface); }
.lvl-shadow { color: var(--muted); border-style: dashed; }
.lvl-suggest { color: var(--ink-2); }
.lvl-propose { color: var(--ink); border-color: var(--ink); }
.lvl-act { color: var(--surface); background: var(--ink); border-color: var(--ink); }
.lvl-prohibited { color: var(--red-ink); border-color: #efc5bf; background: var(--red-bg); }

.banner { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px;
  border: 1px solid #cfd0e0; background: var(--sim-bg); border-radius: var(--r); color: #2f3358; margin-bottom: 18px; }
.banner.red { border-color: #efc5bf; background: var(--red-bg); color: var(--red-ink); }
.mode { font-family: var(--mono); font-size: 11.5px; padding: 2px 8px; border-radius: 3px; border: 1px solid var(--sim); color: var(--sim); }
.mode.live { border-color: var(--ink); color: var(--ink); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.bar { display: flex; height: 10px; border-radius: 3px; overflow: hidden; background: var(--sunk); border: 1px solid var(--line); }
.bar span { display: block; height: 100%; }
.bar .s-shadow { background: #d9d3c4; }
.bar .s-suggest { background: #a9a293; }
.bar .s-propose { background: #5f5a4f; }
.bar .s-act { background: var(--ink); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
.list li:last-child { border-bottom: 0; }

.reasons { display: flex; flex-direction: column; gap: 6px; }
.reason { display: grid; grid-template-columns: 26px 150px 1fr; gap: 10px; align-items: baseline; padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--r); background: #fffef9; }
.reason .layer { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.reason code { font-weight: 600; }
.reason.deny { border-left: 3px solid var(--red); }
.reason.require_approval { border-left: 3px solid var(--amber); }
.reason.require_evidence { border-left: 3px solid var(--sim); }
.reason.info { border-left: 3px solid var(--line-2); }

.chain { display: flex; flex-wrap: wrap; gap: 0; align-items: stretch; }
.chain .node { border: 1px solid var(--line-2); background: var(--surface); padding: 8px 12px; border-radius: var(--r); min-width: 120px; }
.chain .node small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.chain .arrow { align-self: center; padding: 0 6px; color: var(--muted); }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); align-items: baseline; }
.steps li:last-child { border-bottom: 0; }
.steps li::before { counter-increment: s; content: counter(s); font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: right; }
.steps li.done::before { content: "✓"; color: var(--green); }
.steps li.next { font-weight: 600; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }

pre.json { background: #fbf9f3; border: 1px solid var(--line); border-radius: var(--r); padding: 12px; overflow: auto; max-height: 420px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
pre.diff { background: #fbf9f3; border: 1px solid var(--line); border-radius: var(--r); padding: 10px; overflow: auto; max-height: 360px; margin: 0; }
pre.diff .add { color: var(--green); }
pre.diff .del { color: var(--red-ink); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.toolbar input[type="search"] { min-width: 220px; flex: 1; max-width: 360px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.loading { padding: 28px 16px; color: var(--muted); }
.loading::after { content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 8px; border: 2px solid var(--line-2); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { padding: 12px 16px; border: 1px solid #efc5bf; background: var(--red-bg); color: var(--red-ink); border-radius: var(--r); display: flex; justify-content: space-between; gap: 10px; align-items: center; }

.matrix td { white-space: nowrap; }
.req { font-size: 12px; color: var(--ink-2); margin: 2px 0 0; padding-left: 16px; }
.req li { margin: 1px 0; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: var(--r); font-size: 13px; max-width: 420px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); animation: rise 0.18s ease-out; }
.toast.err { background: var(--red-ink); }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }

dialog { border: 1px solid var(--line-2); border-radius: 8px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2); }
dialog::backdrop { background: rgba(23, 21, 15, 0.35); }
dialog .hd { padding: 14px 18px; border-bottom: 1px solid var(--line); }
dialog .bd { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
dialog .ft { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(440px, 100%); }
.login .bd { display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi:nth-child(3n) { border-right: 0; }
  .kpi:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform 0.18s; box-shadow: 0 0 40px rgba(0, 0, 0, 0.15); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 18px 16px 48px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { border-right: 0; border-bottom: 1px solid var(--line); }
  .kpi:nth-child(odd) { border-right: 1px solid var(--line); }
  .reason { grid-template-columns: 22px 1fr; }
  .reason .detail { grid-column: 1 / -1; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* spacing utilities (CSP forbids inline style attributes) */
.mt { margin-top: 16px; }
.mt-s { margin-top: 12px; }
.mt-xs { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.mb-xs { margin-bottom: 10px; }
.my { margin: 14px 0; }
.gap { margin: 14px 0 8px; }
.m0 { margin: 2px 0 0; }
.m-b0 { margin-bottom: 0; }
.t-red { color: var(--red-ink); }
.t-amber { color: var(--amber); }
.legend i.s-shadow { background: #d9d3c4; }
.legend i.s-suggest { background: #a9a293; }
.legend i.s-propose { background: #5f5a4f; }
.legend i.s-act { background: var(--ink); }
.grid > *, .stack > * { min-width: 0; }
.containment pre.json { max-height: 150px; }
pre.json.obs { max-height: 150px; font-size: 11.5px; }
td.small, td.mono { overflow-wrap: anywhere; }
td code { white-space: nowrap; }
textarea.code { white-space: pre; overflow-wrap: normal; }
