/* No build step, no framework, no dependencies (ADR-0018). The viewer exists to
   make the lineage graph and the audit chain legible during a demo; it is not a
   product surface, and a second toolchain in the repository would cost more
   than it returns. */

:root {
  --bg: #10151c;
  --panel: #171e27;
  --panel-2: #1e2733;
  --line: #2a3543;
  --text: #dde5ee;
  --muted: #8494a6;
  --accent: #5ab0f0;
  --ok: #4ec98a;
  --warn: #e0b552;
  --bad: #ef6b6b;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

header {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 2px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.auth {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.auth label {
  color: var(--muted);
  font-size: 12px;
}

input,
select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 9px;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
}

input[type='password'] {
  min-width: 260px;
  font-family: var(--mono);
}

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

button:hover {
  border-color: var(--accent);
}

/* The one call to action on the page. Distinct enough that a stranger finds it
   without reading the token field first, quiet enough that it does not compete
   with the data. */
button.primary {
  border-color: var(--accent);
  color: var(--accent);
}

.demo-banner {
  margin: 12px 0 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

nav {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--line);
}

nav button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 8px 14px;
  color: var(--muted);
}

nav button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main {
  padding: 20px 24px 60px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.filters {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tbody tr:hover {
  background: var(--panel);
  cursor: pointer;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--bad);
}

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.badge.OPEN {
  color: var(--accent);
}
.badge.SEALED,
.badge.PROCESSED,
.badge.VERIFIED {
  color: var(--ok);
}
.badge.PROCESSING,
.badge.UPLOADING,
.badge.DECLARED {
  color: var(--warn);
}
.badge.QUARANTINED,
.badge.PROCESSING_FAILED,
.badge.REJECTED,
.badge.ABANDONED {
  color: var(--bad);
}

#run-detail,
#lineage-detail {
  margin-top: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px 12px;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* `.graph` is the same container under another name: the sandbox draws its
   lineage inside the timeline step that produced it, using the same renderer. */
#lineage-graph,
.graph {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: auto;
  min-height: 220px;
}

#lineage-graph svg,
.graph svg {
  display: block;
}

.node-artifact rect {
  fill: var(--panel-2);
  stroke: var(--accent);
}

.node-activity rect {
  fill: var(--panel-2);
  stroke: var(--ok);
}

.node-agent rect {
  fill: var(--panel-2);
  stroke: var(--warn);
}

.node text {
  fill: var(--text);
  font-size: 11px;
  font-family: var(--mono);
}

.node .node-sub {
  fill: var(--muted);
  font-size: 10px;
}

.edge {
  stroke: var(--line);
  stroke-width: 1.5;
  fill: none;
}

.edge-label {
  fill: var(--muted);
  font-size: 9px;
  font-family: var(--mono);
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 8px 24px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   The explainer, and the per-view orientation lines.

   A visitor arriving at a table of UUIDs cannot tell what this is or what to
   press. These are the smallest thing that fixes that: prose before there is
   data, one line above each view, and both out of the way once the data is
   speaking for itself.
   --------------------------------------------------------------------------- */

.intro {
  max-width: 62rem;
}

.intro h2 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.intro h2:not(:first-child) {
  margin-top: 18px;
}

.intro p {
  margin: 0 0 10px;
  max-width: 70ch;
}

.intro-steps {
  margin: 0;
  padding-left: 20px;
}

.intro-steps li {
  margin-bottom: 8px;
  max-width: 70ch;
}

.intro a {
  color: var(--accent);
}

.view-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  max-width: 78ch;
}

/* The credential inputs are noise for the visitor the demo button is for, and
   the only way in for everyone else. Collapsed, not removed. */
#own-credentials {
  color: var(--muted);
  font-size: 12px;
}

#own-credentials summary {
  cursor: pointer;
  padding: 6px 0;
}

#own-credentials .auth {
  margin-top: 8px;
}

/* The provenance graph is wider than the viewport by design -- it grows with
   the depth of the chain. Make the fact that it scrolls visible rather than
   leaving the rightmost nodes looking clipped. */
#lineage-graph,
.graph {
  scrollbar-color: var(--line) transparent;
}

#lineage-graph::after,
.graph::after {
  content: '';
  position: sticky;
  right: 0;
  display: block;
  width: 28px;
  margin-left: auto;
  margin-top: -100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(to right, transparent, var(--panel));
}

/* ---------------------------------------------------------------------------
   The sandbox (ADR-0021)

   The only view that writes, and the only one whose job is to be watched rather
   than read. Everything below exists to make three things legible: which step is
   happening now, which have finished, and which one refused and why.
   --------------------------------------------------------------------------- */

/* The timeline hides whole steps, and several of the elements it hides carry a
   `display` of their own, which the `hidden` attribute alone loses to. */
[hidden] {
  display: none !important;
}

.sandbox-banner {
  border-left: 2px solid var(--accent);
  padding-left: 12px;
  color: var(--muted);
  max-width: 78ch;
}

.countdown {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--warn);
}

.countdown.expired {
  color: var(--bad);
}

.artifact-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: flex-start;
}

/* Drawn at half size. The canvas is 512x384 because that is what gets hashed;
   how large it appears is a presentation choice and must not change the bytes. */
#sandbox-canvas {
  max-width: 256px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #04070c;
}

.artifact-row .kv {
  flex: 1 1 320px;
  margin: 0;
}

.digest {
  font-family: var(--mono);
  font-size: 11px;
  word-break: break-all;
  color: var(--accent);
}

/* The second half of a digest comparison. Colouring only the computed one says
   which of the two is the surprise. */
.digest.mismatch {
  color: var(--bad);
}

.warn {
  color: var(--warn);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

/* Armed, not merely checked. This toggle deliberately breaks the next run, and
   a visitor should not be able to trip it without noticing. */
.toggle.armed {
  color: var(--warn);
}

.timeline {
  list-style: none;
  margin: 18px 0 0;
  padding: 0 0 0 20px;
  /* The spine. Steps hang off it so a glance shows how far the run got. */
  border-left: 1px solid var(--line);
}

.step {
  position: relative;
  padding: 0 0 18px;
}

/* The bead on the spine, coloured by outcome. This is the only status indicator
   that survives being read peripherally while the run is in flight. */
.step::before {
  content: '';
  position: absolute;
  left: -25px;
  top: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
}

.step.active::before {
  border-color: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.step.done::before {
  background: var(--ok);
  border-color: var(--ok);
}

.step.failed::before {
  background: var(--bad);
  border-color: var(--bad);
}

/* Pending and skipped read the same on the spine and differently in the text:
   the bead says "nothing happened here", the body says whether it still might. */
.step.pending,
.step.skipped {
  color: var(--muted);
}

@keyframes pulse {
  50% {
    background: var(--accent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .step.active::before {
    animation: none;
    background: var(--accent);
  }
}

.step-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.step-title {
  font-weight: 600;
}

/* The call each step made, beside the plain-English title. A reader should be
   able to map every line of this view onto an operation in the API reference. */
.step-call {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}

.step-body {
  margin-top: 6px;
  font-size: 13px;
  max-width: 82ch;
}

.step-body p {
  margin: 8px 0 0;
}

.step-body code {
  font-family: var(--mono);
  font-size: 11px;
}

.step-body .kv {
  margin: 6px 0 0;
}

.step-body table {
  margin-top: 8px;
}

.step-body tbody tr:hover {
  cursor: default;
}

.step-body .graph {
  margin-top: 10px;
}

/* An RFC 9457 document, rendered as one. The extension members are the part
   worth reading, so they get the same treatment as the standard ones. */
.problem {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: 5px;
  background: var(--panel-2);
}

.problem p {
  margin: 6px 0 0;
}

.problem-head {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}

/* Whatever the object store said, verbatim. It is XML from somebody else's
   service and paraphrasing it would lose the one detail that identifies it. */
.raw {
  margin: 8px 0 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--muted);
}
