:root {
  --ground: #f6f5fb;
  --sheet: #ffffff;
  --ink: #14121f;
  --sub: #4f4a63;
  --muted: #76708a;
  --line: #d9d6e6;
  --hair: #ebe8f4;
  --soft: #eeeafd;
  --indigo: #5535c9;
  --indigo-hover: #3f27a3;
  --hero: #231d36;
  --hero-ink: #fbf9ff;
  --hero-sub: #cfc8e0;
  --hero-rule: #4b4363;
  --good: #0d7a5f;
  --good-bg: #e7f6f1;
  --amber: #9a5b08;
  --amber-bg: #fdf5e7;
  --red: #9e2a2b;
  --red-bg: #fdf1f1;
  --display: "Bricolage Grotesque", -apple-system, sans-serif;
  --body: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, a, select, summary { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.visually-hidden, .skip {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
}
.skip:focus { position: fixed; left: 16px; top: 16px; width: auto; height: auto; clip: auto; background: #fff; padding: 8px 14px; border: 1px solid var(--indigo); z-index: 999; }

.wrap { width: min(1280px, calc(100% - 56px)); margin: 0 auto; }

/* Header */
.ap-header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.ap-top { min-height: 64px; display: flex; align-items: center; gap: 14px; }
.brand {
  display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0;
  text-decoration: none; color: var(--ink);
  font: 700 25px/1 var(--display); letter-spacing: -0.045em; white-space: nowrap;
}
.brand .dot { color: var(--indigo); }
.product-name {
  border-left: 1px solid var(--line); padding-left: 14px;
  font-weight: 600; font-size: 14px; color: var(--sub); white-space: nowrap; flex-shrink: 0;
}
.lens-pill {
  background: var(--soft); color: var(--indigo); border: 1px solid #d7cef8; border-radius: 3px;
  padding: 5px 10px; font: 600 11.5px/1.2 var(--mono); max-width: 240px;
}
.ap-nav { display: flex; gap: 4px; margin-left: auto; flex-shrink: 0; }
.nav-link {
  border: 0; background: transparent; white-space: nowrap;
  padding: 8px 12px; border-radius: 3px; font-size: 13.5px; font-weight: 600; color: var(--sub);
}
.nav-link:hover { color: var(--ink); background: var(--ground); }
.nav-link.active { color: var(--indigo); background: var(--soft); }

.ap-right {
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  padding-left: 14px; border-left: 1px solid var(--line);
}
.enclave-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--sub); white-space: nowrap;
}
.enclave-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; }

.quiet-btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink);
  border-radius: 3px; padding: 7px 12px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.quiet-btn:hover { border-color: var(--indigo); color: var(--indigo); }
.primary-btn {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  border: 1px solid var(--indigo); background: var(--indigo); color: #fff;
  border-radius: 3px; padding: 8px 14px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.primary-btn:hover { background: var(--indigo-hover); border-color: var(--indigo-hover); }

/* Main & Status */
.ap-main { padding: 24px 0 36px; }
.status-banner {
  display: flex; align-items: center; gap: 9px; min-height: 20px; margin-bottom: 12px;
  font-size: 13px; font-weight: 500; color: var(--sub);
}
.status-banner:empty { display: none; }
.status-banner.error {
  background: var(--red-bg); color: var(--red); border: 1px solid #f0c2c2;
  border-radius: 4px; padding: 9px 14px;
}
.busy-mark {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(85, 53, 201, 0.25); border-top-color: var(--indigo);
  animation: spin 0.7s linear infinite; display: inline-block; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Typography & Layout Primitives */
.eyebrow {
  font: 600 10.5px/1.2 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--indigo);
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 {
  margin: 4px 0 0; font: 700 clamp(28px, 3.2vw, 38px)/1.06 var(--display); letter-spacing: -0.035em;
}
.page-sub { margin: 5px 0 0; font-size: 14.5px; color: var(--sub); max-width: 72ch; }

.sheet {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 4px; padding: 20px 22px;
}
.sheet + .sheet { margin-top: 18px; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.sheet-head h2, .sheet h3 {
  margin: 0; font: 700 19px/1.2 var(--display); letter-spacing: -0.02em; color: var(--ink);
}
.muted { color: var(--sub); font-size: 13.5px; margin: 4px 0 0; }

/* Dark Indigo Hero */
.hero {
  display: grid; grid-template-columns: 1.15fr 0.85fr;
  background: var(--hero); color: var(--hero-ink);
  border-radius: 5px; overflow: hidden; margin-bottom: 18px;
}
.hero-main { padding: 26px 32px; display: flex; flex-direction: column; justify-content: center; }
.hero .eyebrow { color: #b9aed4; }
.hero h2 { margin: 6px 0 0; font: 600 21px/1.18 var(--display); color: #fff; letter-spacing: -0.02em; }
.hero-stat {
  margin: 10px 0 6px; font: 700 clamp(40px, 4.4vw, 60px)/1 var(--display);
  letter-spacing: -0.04em; font-variant-numeric: tabular-nums; color: #fff;
}
.hero-copy { margin: 0; font-size: 14px; line-height: 1.48; color: var(--hero-sub); max-width: 54ch; }
.hero-pills { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.hero-pill {
  font: 600 11.5px/1.2 var(--mono); padding: 4px 9px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.10); border: 1px solid rgba(255, 255, 255, 0.18); color: #eae4ff;
}
.hero-pill.good {
  background: rgba(13, 122, 95, 0.28); border-color: rgba(154, 230, 201, 0.35); color: #9ae6c9;
}
.hero-side {
  border-left: 1px solid var(--hero-rule); margin: 22px 0; padding: 0 28px;
  display: flex; flex-direction: column; justify-content: center; gap: 8px;
}
.hero-kv {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  font-size: 13.5px; color: #e2dcef; padding: 4px 0;
}
.hero-kv strong { font: 600 15px/1 var(--mono); color: #fff; font-variant-numeric: tabular-nums; }
.hero-kv.sep { border-top: 1px solid var(--hero-rule); padding-top: 10px; margin-top: 4px; }
.hero-kv.sep strong { color: #c7b8ff; font-size: 19px; }

/* Grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.split-lab { display: grid; grid-template-columns: 0.92fr 1.08fr; gap: 18px; align-items: start; }

/* Workflow Runner Strip */
.wf-card {
  background: #faf9fd; border: 1px solid var(--line); border-radius: 4px;
  padding: 13px 14px; text-align: left; display: flex; flex-direction: column; gap: 5px;
}
.wf-card:hover { border-color: var(--indigo); background: var(--soft); }
.wf-card.running { border-color: var(--indigo); }
.wf-num { font: 600 10px var(--mono); color: var(--indigo); text-transform: uppercase; letter-spacing: 0.06em; }
.wf-card b { font: 700 14px/1.2 var(--display); color: var(--ink); }
.wf-card small { font-size: 12px; color: var(--sub); line-height: 1.35; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--hair); border-radius: 3px; }
.ap-table {
  width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums;
}
.ap-table th, .ap-table td {
  padding: 8px 11px; border-bottom: 1px solid var(--hair); text-align: left; vertical-align: top;
}
.ap-table thead th {
  background: #faf9fd; font: 600 10.5px/1.2 var(--mono); text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); white-space: nowrap;
}
.ap-table td.num, .ap-table th.num { text-align: right; white-space: nowrap; }
.ap-table tbody tr:last-child td { border-bottom: 0; }
.ap-table tbody tr.clickable:hover { background: var(--soft); cursor: pointer; }

/* Badges & Chips */
.badge {
  display: inline-block; font: 600 10px/1.2 var(--mono); text-transform: uppercase;
  padding: 3px 6px; border-radius: 2px; white-space: nowrap;
}
.badge.hit { background: var(--good-bg); color: var(--good); }
.badge.miss { background: var(--amber-bg); color: var(--amber); }
.badge.abstain, .badge.open { background: var(--soft); color: var(--indigo); }
.badge.mcp { background: var(--ink); color: #c7b8ff; }

.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip {
  border: 1px solid var(--line); background: var(--sheet); color: var(--sub);
  border-radius: 3px; padding: 5px 10px; font-size: 12px; font-weight: 600;
}
.chip:hover { border-color: var(--indigo); color: var(--indigo); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* Code / SQL / JSON */
.code-block, .code-editor {
  width: 100%; background: #14121f; color: #f4f3fa; border: 1px solid #2a263e; border-radius: 4px;
  padding: 12px 14px; font: 500 12px/1.5 var(--mono); overflow-x: auto;
  white-space: pre-wrap; word-break: break-word; margin: 6px 0 10px;
}
textarea.code-editor {
  min-height: 180px; resize: vertical; white-space: pre; overflow-x: auto; tab-size: 2;
}
.result-json {
  background: #faf9fd; border: 1px solid var(--line); border-radius: 4px;
  padding: 12px 14px; font: 500 11.8px/1.48 var(--mono); color: var(--ink);
  max-height: 440px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.meta-bar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 8px 0;
  font: 600 11px var(--mono); color: var(--sub);
}
.meta-bar span {
  background: var(--ground); border: 1px solid var(--line); border-radius: 2px; padding: 3px 7px;
}

/* Form controls */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 10px 0 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 3px; padding: 7px 10px;
  background: var(--sheet); font-size: 13.5px;
}

/* Simple inline bars for SQL histograms */
.bar-track { width: 120px; height: 8px; background: var(--hair); border-radius: 2px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.bar-fill { height: 100%; background: var(--indigo); }

/* Footer */
.ap-footer {
  padding: 16px 0 28px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  font: 500 11.5px var(--mono); color: var(--muted);
}

/* Dialog */
dialog {
  max-width: min(680px, calc(100vw - 24px)); width: 100%;
  border: 1px solid var(--line); border-radius: 5px; padding: 0;
  background: var(--sheet); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 18, 31, 0.45); }
.dialog-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 3px 0 0; font: 700 19px/1.2 var(--display); }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 3px; width: 32px; height: 32px; font-size: 18px; }
.dialog-body { padding: 18px 20px; max-height: 75vh; overflow-y: auto; }

@media (max-width: 1020px) {
  .wrap { width: calc(100% - 28px); }
  .hero, .grid-2, .grid-3, .grid-5, .split-lab, .form-grid { grid-template-columns: 1fr; }
  .hero-side { border-left: 0; border-top: 1px solid var(--hero-rule); margin: 0 24px 20px; padding: 16px 0 0; }
  .product-name, .enclave-badge { display: none; }
}
