:root {
  --night: #1e2348;
  --night-2: #2a3060;
  --night-ink: #c9cce6;
  --stone: #f2f3f6;
  --paper: #ffffff;
  --ink: #1b1e2a;
  --ink-2: #565b6e;
  --rule: #dfe1e8;
  --jade: #2e7a5f;
  --turmeric: #c08a16;
  --sindoor: #b3261e;
  --slate: #6b7080;
  --action: #343c8a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.55 var(--sans);
  color: var(--ink);
  background: var(--stone);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
a { color: var(--action); }

/* ---------- shell ---------- */
.shell {
  display: grid; grid-template-columns: 216px 1fr; min-height: 100vh;
  background: linear-gradient(var(--night), var(--night)) left top / 216px 100% no-repeat, var(--stone);
}
.nav {
  background: var(--night);
  color: var(--night-ink);
  padding: 28px 18px;
  display: flex; flex-direction: column; gap: 28px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.brand svg { flex: none; }
.brand span { font: 600 22px/1 var(--serif); letter-spacing: .01em; }
.nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav a.item {
  display: block; padding: 8px 12px; border-radius: 6px;
  color: var(--night-ink); text-decoration: none;
}
.nav a.item:hover { background: var(--night-2); color: #fff; }
.nav a.item[aria-current="page"] { background: var(--night-2); color: #fff; box-shadow: inset 3px 0 0 #fff; }
.nav .who { margin-top: auto; font-size: 13px; line-height: 1.4; }
.nav .who strong { display: block; color: #fff; font-weight: 600; }
.nav .who button { margin-top: 8px; background: none; border: 0; padding: 0; color: var(--night-ink); text-decoration: underline; cursor: pointer; }

main { padding: 36px 44px 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
h1 { font: 600 30px/1.15 var(--serif); margin: 0; }
h2 { font: 600 19px/1.3 var(--serif); margin: 0 0 12px; }
.sub { color: var(--ink-2); margin: 4px 0 0; }
section { margin-bottom: 40px; }

/* ---------- threshold band (the signature) ---------- */
.band {
  display: flex; height: 56px; border-radius: 4px; overflow: hidden;
  background: var(--rule);
}
.band > div { min-width: 3px; transition: flex-grow .6s ease; }
.band .allowed { background: var(--jade); }
.band .masked { background: var(--turmeric); }
.band .blocked { background: var(--sindoor); }
.band .error { background: var(--slate); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 28px; margin-top: 12px; }
.legend .k { display: flex; align-items: baseline; gap: 8px; }
.legend .k b { font: 600 22px/1 var(--serif); font-variant-numeric: tabular-nums; }
.legend .k i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; align-self: center; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 36px; color: var(--ink-2); padding-top: 14px; border-top: 1px solid var(--rule); margin-top: 18px; }
.stats b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- chart ---------- */
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis { fill: var(--ink-2); font: 11px var(--sans); }
.chart .grid { stroke: var(--rule); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; font-size: 13px; color: var(--ink-2); background: #fafafc; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sql { font: 13px/1.45 var(--mono); color: var(--ink); word-break: break-word; }
.muted { color: var(--ink-2); }
.bar-cell { position: relative; }
.bar-cell .fill { position: absolute; inset: 6px auto 6px 0; background: #f6dcd9; border-radius: 3px; z-index: 0; }
.bar-cell span { position: relative; z-index: 1; }

/* decision marks: the threshold edge on each audit row */
tr.ev td:first-child { box-shadow: inset 4px 0 0 var(--edge, var(--rule)); padding-left: 18px; }
tr.ev.allowed { --edge: var(--jade); }
tr.ev.masked { --edge: var(--turmeric); }
tr.ev.blocked { --edge: var(--sindoor); }
tr.ev.error { --edge: var(--slate); }
tr.ev { cursor: pointer; }
tr.ev:hover td { background: #fafafc; }
tr.ev.fresh td { animation: arrive 1.4s ease-out; }
@keyframes arrive { from { background: #eef0fb; } to { background: transparent; } }
tr.detail td { background: #fafafc; font-size: 14px; }
.detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.detail dt { color: var(--ink-2); }
.detail dd { margin: 0; }

.decision { font-weight: 600; }
td.agent { white-space: nowrap; }
td.why { min-width: 170px; }
.warn-text { color: #8a6210; font-size: 13px; }
.decision.allowed { color: var(--jade); }
.decision.masked { color: #8a6210; }
.decision.blocked { color: var(--sindoor); }
.decision.error { color: var(--slate); }

.status { display: inline-flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--slate); }
.status.online::before { background: var(--jade); }
.status.offline::before { background: var(--sindoor); }
.status.pending::before { background: var(--turmeric); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--action); background: var(--action); color: #fff;
  padding: 8px 14px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: #2a3175; }
.btn.quiet { background: var(--paper); color: var(--action); border-color: var(--rule); }
.btn.quiet:hover { border-color: var(--action); }
.btn.danger { background: var(--paper); color: var(--sindoor); border-color: #ecc9c6; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 14px; }
.toolbar label { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); }
input[type=text], input[type=password], select, textarea {
  background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { border-color: var(--action); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field .hint { color: var(--ink-2); font-size: 13px; }

.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 20px 22px; margin-bottom: 20px; }
.notice { border-left: 4px solid var(--turmeric); background: #fbf5e6; padding: 12px 16px; border-radius: 0 6px 6px 0; margin: 0 0 16px; }
.err { border-left: 4px solid var(--sindoor); background: #fbeceb; padding: 12px 16px; border-radius: 0 6px 6px 0; margin: 0 0 16px; white-space: pre-wrap; }
.ok { border-left: 4px solid var(--jade); background: #e9f4ef; padding: 12px 16px; border-radius: 0 6px 6px 0; margin: 0 0 16px; }
pre.code { background: var(--night); color: #e7e9f7; padding: 14px 16px; border-radius: 6px; overflow-x: auto; font: 13px/1.5 var(--mono); margin: 0; }
.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow code { flex: 1; font: 13px var(--mono); background: var(--stone); padding: 8px 10px; border-radius: 6px; overflow-x: auto; white-space: nowrap; }

.empty { padding: 36px; text-align: center; background: var(--paper); border: 1px dashed var(--rule); border-radius: 6px; color: var(--ink-2); }
.empty p { margin: 0 0 14px; }

/* ---------- policy editor ---------- */
.policy { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; }
.versions { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); }
.versions li { padding: 12px 14px; border-bottom: 1px solid var(--rule); display: grid; gap: 4px; }
.versions li:last-child { border-bottom: 0; }
.versions li.sel { background: #eef0fb; }
.versions .vhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.versions .vnum { font: 600 17px var(--serif); background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink); }
.versions .active-tag { color: var(--jade); font-weight: 600; font-size: 13px; }
.versions .note { color: var(--ink-2); font-size: 13px; }
.versions .actions { display: flex; gap: 6px; margin-top: 4px; }
textarea.yaml { width: 100%; min-height: 300px; font: 13px/1.55 var(--mono); resize: vertical; tab-size: 2; }
.diff { font: 13px/1.5 var(--mono); background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 0; overflow-x: auto; }
.diff div { padding: 0 14px; white-space: pre; }
.diff .add { background: #e6f3ec; color: #1f5a44; }
.diff .del { background: #fbeceb; color: #8d1d17; }

/* ---------- sign in ---------- */
.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    linear-gradient(var(--night), var(--night)) left / 50% 100% no-repeat,
    var(--stone);
}
.gate .door { width: min(880px, 100%); display: grid; grid-template-columns: 1fr 1fr; background: var(--paper); border-radius: 8px; overflow: hidden; border: 1px solid var(--rule); }
.gate .left { background: var(--night-2); color: #fff; padding: 48px 40px; display: grid; align-content: space-between; gap: 40px; }
.gate .left h1 { font-size: 40px; margin-bottom: 14px; }
.gate .left p { color: var(--night-ink); max-width: 30ch; margin: 0; }
.gate .right { padding: 48px 40px; }
.gate .right h2 { font-size: 22px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 16px; gap: 14px; }
  .nav ul { display: flex; flex-wrap: wrap; }
  .nav .who { margin: 0 0 0 auto; font-size: 12px; }
  .nav .who .plan { display: none; }
  .chart { overflow-x: auto; }
  .chart svg { min-width: 680px; }
  main { padding: 24px 18px 48px; }
  .two, .policy { grid-template-columns: 1fr; }
  .gate { background: var(--stone); }
  .gate .door { grid-template-columns: 1fr; }
  table { font-size: 14px; }
  th, td { padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
