:root {
  color-scheme: dark;
  --bg: #08101c;
  --panel: #101a29;
  --panel-2: #131f31;
  --panel-3: #0d1624;
  --border: #233146;
  --text: #e8edf7;
  --muted: #92a0b8;
  --accent: #55b6ff;
  --green: #2ed3a7;
  --amber: #f2b24e;
  --red: #f87373;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #16243a, var(--bg) 35%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  background: rgba(9, 16, 28, 0.9);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
  margin: 22px 0;
}

.nav-link {
  display: block;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  background: rgba(8, 16, 28, 0.45);
}

.nav-link.active,
.nav-link:hover {
  border-color: var(--border);
  color: var(--text);
  background: rgba(85, 182, 255, 0.1);
}

.sidebar-header h1,
.hero h2 {
  margin: 4px 0 8px;
  font-size: 30px;
}

.sidebar-header p,
.panel-header p,
.muted {
  color: var(--muted);
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.stats-grid,
.card-grid {
  display: grid;
  gap: 12px;
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 20px 0;
}

.card-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 18px 0;
}

.sidebar-tools {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.split-controls {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.launch-shell {
  display: grid;
  gap: 24px;
}

.launch-panel {
  padding: 26px;
}

.launch-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.launch-full {
  grid-column: 1 / -1;
}

.launch-context,
.launch-workbench,
.launch-history-panel {
  display: grid;
  gap: 16px;
}

.launch-context {
  margin-bottom: 24px;
}

.panel-subheader h3,
.section-heading h2,
.panel-header h2 {
  margin: 6px 0 8px;
  font-size: 28px;
}

.panel-subheader p,
.section-heading p {
  margin: 0;
  color: var(--muted);
}

.panel-header-spacious {
  margin-bottom: 24px;
}

.context-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.context-card {
  border: 1px solid var(--border);
  background: rgba(11, 19, 31, 0.82);
  border-radius: 14px;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
}

.context-card code {
  color: var(--text);
  word-break: break-word;
}

.mode-switch {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(8, 16, 28, 0.6);
  margin-bottom: 22px;
}

.mode-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.mode-tab.active {
  background: rgba(85, 182, 255, 0.12);
  color: var(--text);
}

.editor-block {
  display: grid;
  gap: 12px;
}

.editor-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost-button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(8, 16, 28, 0.5);
  color: var(--text);
  cursor: pointer;
}

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

.cm-editor {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.launch-textarea {
  width: 100%;
  min-height: 120px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--text);
  resize: vertical;
}

.launch-taskarea {
  min-height: 132px;
}

.launch-env {
  min-height: 90px;
}

.launch-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 8px;
}

.action-button {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.action-button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.action-button:disabled {
  cursor: progress;
  opacity: 0.7;
  transform: none;
}

.action-button-primary {
  background: linear-gradient(180deg, rgba(85, 182, 255, 0.16), rgba(85, 182, 255, 0.08));
  border-color: rgba(85, 182, 255, 0.3);
}

.action-button-inline {
  min-width: 160px;
  width: auto;
  justify-self: start;
}

.card,
.panel,
.run-card,
.stage-row,
.activity-item,
.story-item,
.child-item {
  border: 1px solid var(--border);
  background: rgba(15, 26, 41, 0.88);
  border-radius: 16px;
}

.card {
  padding: 14px;
}

.card .value {
  margin-top: 6px;
  font-size: 20px;
  font-weight: 700;
}

.search {
  display: block;
  margin-bottom: 16px;
}

.search span {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.search input,
.compare-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--text);
}

.run-list {
  display: grid;
  gap: 10px;
}

.run-card {
  padding: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  text-align: left;
}

.run-card:hover,
.run-card.active {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: rgba(18, 31, 49, 0.96);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pill.complete {
  background: rgba(46, 211, 167, 0.12);
  color: var(--green);
}

.pill.failed,
.pill.error,
.pill.cancelled {
  background: rgba(248, 115, 115, 0.12);
  color: var(--red);
}

.pill.running {
  background: rgba(242, 178, 78, 0.12);
  color: var(--amber);
}

.main {
  padding: 30px 30px 48px;
  overflow: auto;
}

.main > :first-child {
  margin-top: 0;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.hero-meta {
  display: grid;
  gap: 8px;
  min-width: 240px;
}

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.empty-state {
  min-height: calc(100vh - 56px);
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.panel {
  padding: 20px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 14px;
}

.split {
  display: grid;
  gap: 20px;
  grid-template-columns: 1.1fr 0.9fr;
}

.split-tight {
  grid-template-columns: 1fr 1fr;
}

.compare-panel,
.table-like,
.activity-list,
.story-list,
.child-list,
.turn-list,
.flamegraph,
.policy-list,
.stage-debug {
  display: grid;
  gap: 10px;
}

.compare-summary {
  display: grid;
  gap: 12px;
}

.workspace-section {
  display: grid;
  gap: 18px;
  margin-top: 0;
}

.section-heading {
  padding: 0 2px;
}

.section-heading-inline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.empty-state-inline {
  min-height: 280px;
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: rgba(11, 19, 31, 0.55);
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 300px 1fr;
  }

  .launch-grid,
  .context-grid,
  .split-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 840px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .main {
    padding: 22px 18px 40px;
  }

  .mode-switch {
    display: grid;
    grid-template-columns: 1fr;
  }

  .editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

.compare-field {
  max-width: 740px;
}

.runs-page-panel {
  gap: 18px;
}

.runs-toolbar {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(280px, 1.8fr) repeat(3, minmax(140px, 0.7fr)) auto;
  align-items: end;
}

.runs-search {
  margin-bottom: 0;
}

.runs-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(11, 19, 31, 0.68);
}

.runs-table {
  width: 100%;
  border-collapse: collapse;
}

.runs-table th,
.runs-table td {
  padding: 14px 16px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.runs-table th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.runs-table tbody tr:hover {
  background: rgba(85, 182, 255, 0.05);
}

.table-primary {
  font-weight: 700;
}

.table-path {
  max-width: 340px;
  word-break: break-word;
}

.cost-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cost-sections {
  display: grid;
  gap: 24px;
}

.cost-trend-list {
  display: grid;
  gap: 10px;
}

.cost-trend-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 2fr) minmax(86px, auto);
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(11, 19, 31, 0.72);
}

.cost-bar {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.cost-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--accent));
}

.cost-amount {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.compare-row {
  display: grid;
  gap: 10px;
  grid-template-columns: 240px 1fr;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-3);
}

.stage-row,
.activity-item,
.story-item,
.child-item,
.turn-item,
.lineage-item,
.artifact-item,
.flow-item {
  padding: 14px;
}

.stage-row .meta,
.activity-item .meta,
.story-item .meta,
.child-item .meta,
.turn-item .meta,
.lineage-item .meta,
.artifact-item .meta,
.flow-item .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.turn-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
}

.turn-panel,
.lineage-item,
.artifact-item,
.flow-item,
.policy-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-3);
}

.turn-panel {
  padding: 12px;
}

.turn-panel h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.turn-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.turn-chip,
.run-card-link {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 11px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.compare-summary .search {
  margin-bottom: 0;
}

.activity-audit {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.activity-audit-reason {
  background: rgba(110, 168, 254, 0.14);
  border-color: rgba(110, 168, 254, 0.32);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-audit-layers {
  position: relative;
  cursor: help;
}

.activity-audit-receipt {
  text-decoration: none;
}

.activity-audit-receipt:hover {
  background: rgba(255, 255, 255, 0.12);
}

.activity-audit-tooltip {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  display: none;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  padding: 8px 10px;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 11px;
  color: var(--text);
  z-index: 5;
  pointer-events: none;
  white-space: normal;
}

.activity-audit-layers:hover .activity-audit-tooltip,
.activity-audit-layers:focus-within .activity-audit-tooltip {
  display: flex;
}

.activity-audit-tooltip-title {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
}

.activity-audit-tooltip-chain {
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
}

.run-card-link {
  margin-top: 10px;
  cursor: pointer;
}

.lineage-grid,
.flow-grid,
.policy-grid {
  display: grid;
  gap: 10px;
}

.policy-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.policy-item {
  padding: 14px;
}

.artifact-item details,
.flow-item details,
.story-item details,
.turn-item details,
.stage-row details {
  margin-top: 10px;
}

.artifact-item summary,
.flow-item summary,
.story-item summary,
.turn-item summary,
.stage-row summary {
  cursor: pointer;
  color: var(--accent);
}

.action-node-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.action-node-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}

.action-node-card strong {
  display: block;
  margin-top: 2px;
}

.action-node-card .eyebrow {
  margin-bottom: 2px;
}

.action-node-actions {
  margin-top: 10px;
}

.action-node-trigger {
  border-left: 4px solid var(--accent);
}

.action-node-predicate {
  border-left: 4px solid var(--amber);
}

.action-node-dispatch {
  border-left: 4px solid #6dd3ce;
}

.action-node-a2a {
  border: 1px dashed #7dd3fc;
  box-shadow: inset 0 0 0 1px rgba(125, 211, 252, 0.18);
}

.action-node-worker {
  border-left: 4px solid #7ee081;
}

.action-node-retry {
  border-left: 4px solid #f59e0b;
}

.action-node-approval {
  border-left: 4px solid #c084fc;
}

.action-node-dlq {
  border-left: 4px solid #ef4444;
}

.turn-message {
  border-left: 2px solid var(--accent);
  padding-left: 10px;
  margin-top: 10px;
}

.turn-message .role {
  font-size: 11px;
  font-weight: 700;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.lane {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-2);
  padding: 12px;
}

.lane-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.track {
  position: relative;
  min-height: 56px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  overflow: hidden;
}

.grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
}

.grid span {
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.bar {
  position: absolute;
  height: 36px;
  border-radius: 10px;
  padding: 6px 8px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.bar.stage {
  background: rgba(85, 182, 255, 0.12);
  color: #cde7ff;
}

.bar.llm_call {
  background: rgba(124, 146, 255, 0.16);
  color: #d7ddff;
}

.bar.tool_call {
  background: rgba(46, 211, 167, 0.14);
  color: #cbf8eb;
}

.bar.pipeline {
  background: rgba(242, 178, 78, 0.14);
  color: #ffe2b3;
}

.bar.other {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
}

@media (max-width: 1100px) {
  .shell,
  .split {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .hero {
    flex-direction: column;
  }

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

  .compare-row {
    grid-template-columns: 1fr;
  }

  .runs-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .cost-summary-grid,
  .cost-trend-row {
    grid-template-columns: 1fr;
  }

  .cost-amount {
    text-align: left;
  }

  .pagination-bar,
  .section-heading-inline {
    flex-direction: column;
    align-items: flex-start;
  }
}

.skill-timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skill-timeline-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 3fr auto;
  align-items: center;
  gap: 12px;
}

.skill-timeline-label strong {
  display: block;
}

.skill-timeline-track {
  position: relative;
  height: 24px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
  overflow: hidden;
}

.skill-timeline-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #5fc4ff, #7a8dff);
  color: #051028;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding: 0 8px;
  white-space: nowrap;
  border-radius: 3px;
  overflow: hidden;
}

.skill-timeline-meta {
  min-width: 64px;
  text-align: right;
}

.tool-waterfall {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-waterfall-row {
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.match-expand {
  background: transparent;
  border: none;
  color: inherit;
  width: 100%;
  text-align: left;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.match-detail {
  margin-top: 8px;
}

.match-candidates {
  margin: 4px 0 0;
  padding-left: 16px;
  list-style: disc;
}

.match-candidates li {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}

.dlq-panel {
  display: grid;
  gap: 16px;
}

.dlq-summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.subpanel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(8, 16, 28, 0.45);
  padding: 14px;
  min-width: 0;
}

.subpanel h3,
.subpanel h4 {
  margin: 0 0 10px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill.danger {
  border-color: rgba(248, 115, 115, 0.35);
  background: rgba(248, 115, 115, 0.12);
  color: #ffc6c6;
}

.dlq-bulk-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.dlq-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.48fr);
  gap: 16px;
  align-items: start;
}

.selected-row {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
  background: rgba(85, 182, 255, 0.08);
}

.dlq-error-cell {
  max-width: 320px;
  white-space: normal;
}

.dlq-detail-panel {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 12px;
}

.dlq-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.danger-button {
  border-color: rgba(248, 115, 115, 0.35);
  color: #ffc6c6;
}

.dlq-detail-panel pre {
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-3);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 1100px) {
  .dlq-layout,
  .dlq-summary-grid {
    grid-template-columns: 1fr;
  }

  .dlq-detail-panel {
    position: static;
  }
}
