:root {
  --bg-top: #f6f8ef;
  --bg-bottom: #e4efe8;
  --card-bg: rgba(255, 255, 255, 0.92);
  --ink: #1f2a24;
  --muted: #52635a;
  --accent: #11795f;
  --accent-2: #c75c14;
  --line: #d6e3db;
  --chip: #dff3ea;
  --danger: #a22a2a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.background-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(2px);
  pointer-events: none;
  z-index: -1;
}

.shape-a {
  width: 34rem;
  height: 34rem;
  top: -10rem;
  right: -8rem;
  background: radial-gradient(circle at center, rgba(17, 121, 95, 0.18), rgba(17, 121, 95, 0.02));
}

.shape-b {
  width: 28rem;
  height: 28rem;
  bottom: -8rem;
  left: -6rem;
  background: radial-gradient(circle at center, rgba(199, 92, 20, 0.15), rgba(199, 92, 20, 0.02));
}

.layout {
  width: min(1200px, 96vw);
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
  display: grid;
  gap: 1rem;
}

.hero {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 1.2rem 1.4rem;
  box-shadow: 0 10px 24px rgba(30, 40, 34, 0.06);
  animation: rise 320ms ease-out;
}

.eyebrow {
  margin: 0;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

h1 {
  margin: 0.2rem 0 0;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
}

.subtitle {
  margin: 0.5rem 0 0;
  color: var(--muted);
  max-width: 70ch;
}

.tabs {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 0.6rem;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.panel {
  display: none;
  gap: 1rem;
}

.panel.active {
  display: grid;
}

.panel-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  padding: 0.9rem 1rem 1rem;
  animation: rise 320ms ease-out;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
}

.action-row {
  display: flex;
  gap: 0.45rem;
}

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 0.55rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn.secondary {
  background: #fff;
  color: var(--accent);
}

.btn.warn {
  border-color: var(--accent-2);
  background: var(--accent-2);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

th,
td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid #eef4f0;
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #f8fbf9;
}

td code,
pre {
  font-family: "IBM Plex Mono", monospace;
}

td input,
td select,
.policy-form input,
.policy-form textarea {
  width: 100%;
  border: 1px solid #cddcd2;
  border-radius: 0.45rem;
  padding: 0.4rem 0.5rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
}

.policy-form {
  display: grid;
  gap: 0.7rem;
}

.policy-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  gap: 0.6rem;
  align-items: end;
  margin-bottom: 0.8rem;
}

.policy-controls label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.policy-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.json-view {
  margin: 0.7rem 0 0;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #0f1d17;
  color: #d9f3e8;
  padding: 0.75rem;
  max-height: 22rem;
  overflow: auto;
  font-size: 0.76rem;
  line-height: 1.45;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
}

.chip {
  background: var(--chip);
  border: 1px solid #c5e4d5;
  color: #225844;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.76rem;
}

.microcopy {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.diagram-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 0.8rem;
}

.diagram-title {
  margin: 0 0 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.vertical-diagram {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.7rem;
  background: #fbfdfb;
}

.diagram-node {
  border: 1px solid #ccddd2;
  border-left: 4px solid var(--accent);
  background: #fff;
  border-radius: 0.6rem;
  padding: 0.55rem 0.6rem;
  box-shadow: 0 1px 0 rgba(24, 42, 31, 0.04);
}

.diagram-node.event {
  border-left-color: #11795f;
}

.diagram-node.work-unit {
  border-left-color: #c75c14;
}

.diagram-node-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.diagram-node-title {
  font-weight: 700;
  font-size: 0.88rem;
}

.diagram-node-type {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diagram-node-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  color: #3e5548;
}

.diagram-node-detail {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #425c4f;
}

.diagram-link {
  text-align: center;
  color: #7f9a8b;
  font-size: 0.9rem;
  margin: 0.12rem 0;
}

.diagram-node.canonical {
  border-left-color: #2a5da8;
}

.diagram-node.canonical.unseen {
  opacity: 0.65;
}

.subgraph-grid {
  display: grid;
  gap: 0.5rem;
}

.subgraph-card {
  border: 1px solid #cbded2;
  border-radius: 0.65rem;
  background: #fff;
  padding: 0.52rem 0.58rem;
}

.subgraph-card.active {
  border-color: #8cc3a9;
  background: #effaf3;
}

.subgraph-name {
  font-size: 0.82rem;
  font-weight: 700;
}

.subgraph-meta {
  margin-top: 0.2rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: #3f594d;
}

.foldout summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.6rem;
}

#status-banner {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: rgba(16, 30, 22, 0.95);
  color: #fff;
  border-radius: 0.6rem;
  padding: 0.6rem 0.8rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

#status-banner.show {
  opacity: 1;
  transform: translateY(0);
}

#status-banner.error {
  background: var(--danger);
}

#policies-table tbody tr {
  cursor: pointer;
}

#policies-table tbody tr.selected {
  background: #e8f4ee;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 860px) {
  .layout {
    width: min(98vw, 760px);
    padding: 1rem 0 2.2rem;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .action-row {
    width: 100%;
  }

  .action-row .btn {
    flex: 1;
  }

  .policy-controls {
    grid-template-columns: 1fr;
  }

  .diagram-columns {
    grid-template-columns: 1fr;
  }
}
