:root {
  --background: hsl(222 47% 6%);
  --background-soft: hsl(222 47% 8%);
  --card: hsl(222 44% 8%);
  --card-alt: hsl(222 40% 10%);
  --muted: hsl(222 30% 12%);
  --muted-2: hsl(222 28% 16%);
  --border: hsla(222, 30%, 18%, 0.88);
  --border-soft: hsla(222, 30%, 18%, 0.55);
  --foreground: hsl(210 40% 92%);
  --secondary: hsl(210 32% 83%);
  --muted-foreground: hsl(215 20% 58%);
  --primary: hsl(199 89% 48%);
  --primary-soft: hsla(199, 89%, 48%, 0.18);
  --success: hsl(142 76% 36%);
  --warning: hsl(38 92% 50%);
  --danger: hsl(0 72% 51%);
  --radius: 4px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--foreground);
  font-family: var(--font-sans);
  background:
    radial-gradient(circle at top left, rgba(12, 74, 110, 0.18), transparent 24%),
    linear-gradient(180deg, rgba(8, 12, 22, 0.98), rgba(8, 12, 22, 1)),
    var(--background);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(88, 119, 168, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88, 119, 168, 0.05) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(180deg, rgba(255, 255, 255, 0.32), transparent 70%);
}

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

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 11, 23, 0.78);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.brand-mark span {
  width: 2px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(191, 219, 254, 0.95), rgba(34, 211, 238, 0.8));
}

.brand-mark span:nth-child(1) {
  height: 16px;
  opacity: 0.7;
}

.brand-mark span:nth-child(2) {
  height: 20px;
}

.brand-mark span:nth-child(3) {
  height: 12px;
  opacity: 0.55;
}

.eyebrow,
.panel-label,
.section-label,
.meta-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.brand h1,
.view-title,
.card-title,
.context-title,
p,
h2,
h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ghost-button,
.panel-button,
.link-card,
.nav-card {
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.ghost-button,
.panel-button {
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
}

.ghost-button {
  padding: 9px 14px;
  border-radius: var(--radius);
  color: var(--secondary);
}

.ghost-button:hover,
.panel-button:hover {
  background: rgba(80, 119, 177, 0.08);
  border-color: rgba(80, 119, 177, 0.26);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--muted-foreground);
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-ui {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--muted);
  border: 1px solid var(--border);
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(226, 235, 243, 0.95);
  transition: transform 180ms ease, background-color 180ms ease;
}

.mode-toggle input:checked + .toggle-ui {
  background: rgba(16, 34, 58, 0.92);
}

.mode-toggle input:checked + .toggle-ui::after {
  transform: translateX(20px);
  background: var(--primary);
}

.workspace {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr) 320px;
  min-height: calc(100vh - 67px);
}

.panel {
  min-width: 0;
  border-right: 1px solid var(--border);
}

.panel-summary {
  border-right: 0;
}

.panel-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 11, 23, 0.38);
}

.panel-scroll {
  padding: 10px;
}

.nav-list {
  display: flex;
  flex-direction: column;
}

.nav-card {
  display: flex;
  gap: 12px;
  width: 100%;
  padding: 12px 10px;
  border: 0;
  border-bottom: 1px solid rgba(26, 38, 59, 0.78);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.nav-card:hover,
.nav-card-active {
  background: linear-gradient(90deg, rgba(5, 35, 61, 0.9), rgba(3, 16, 34, 0.55));
}

.nav-card-active {
  box-shadow: inset 2px 0 0 var(--primary);
}

.nav-icon {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.nav-icon-home {
  background: var(--primary);
}

.nav-icon-agent {
  background: hsl(38 92% 50%);
}

.nav-icon-sandbox {
  background: hsl(142 76% 36%);
}

.nav-icon-model {
  background: hsl(185 92% 46%);
}

.nav-icon-experiment {
  background: hsl(355 78% 60%);
}

.nav-icon-trace {
  background: hsl(270 70% 65%);
}

.nav-copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-title {
  font-size: 16px;
  line-height: 1.2;
}

.nav-meta,
.helper-text,
.status-meta,
.timestamp,
.empty-text {
  font-size: 12px;
  color: var(--muted-foreground);
}

.panel-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted-foreground);
}

.surface-card,
.link-card,
.status-chip,
.context-card,
.placeholder-list,
.placeholder-item {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(8, 14, 28, 0.98), rgba(7, 13, 25, 0.95));
  box-shadow: var(--shadow);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.surface-card {
  padding: 14px;
}

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

.view-title {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.05;
}

.view-subtitle {
  margin-top: 6px;
  color: var(--muted-foreground);
  max-width: 56ch;
}

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

.agent-library-grid,
.two-up-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
}

.two-up-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.link-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(8, 14, 28, 0.98), rgba(7, 13, 25, 0.95)),
    var(--card);
}

.link-card:hover {
  border-color: rgba(80, 119, 177, 0.26);
  background:
    linear-gradient(180deg, rgba(8, 18, 34, 0.98), rgba(8, 17, 31, 0.98)),
    var(--card);
}

.card-kicker,
.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card-kicker {
  width: fit-content;
  color: var(--primary);
  background: var(--primary-soft);
}

.card-title,
.context-title {
  font-size: 18px;
  font-weight: 600;
}

.card-text {
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.45;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.status-chip {
  padding: 12px;
}

.status-value {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--foreground);
}

.status-meta {
  margin-top: 4px;
}

.placeholder-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 12px;
}

.placeholder-list {
  padding: 12px;
}

.placeholder-item {
  padding: 12px;
}

.placeholder-item + .placeholder-item {
  margin-top: 10px;
}

.item-title-row,
.context-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.item-title {
  font-size: 15px;
  font-weight: 600;
}

.item-copy {
  margin-top: 6px;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.45;
}

.context-card {
  padding: 12px;
}

.context-card + .context-card {
  margin-top: 10px;
}

.context-value,
.mono {
  font-family: var(--font-mono);
}

.context-value {
  margin-top: 10px;
  color: var(--foreground);
}

.panel-button {
  padding: 10px 12px;
  border-radius: var(--radius);
}

.panel-button-active {
  background: rgba(10, 25, 44, 0.48);
  border-color: rgba(80, 119, 177, 0.28);
  color: var(--foreground);
}

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

.pill {
  color: var(--primary);
  background: var(--primary-soft);
}

.pill-success {
  color: hsl(142 82% 74%);
  background: rgba(38, 100, 58, 0.32);
}

.pill-warning {
  color: hsl(38 100% 72%);
  background: rgba(109, 72, 13, 0.28);
}

.pill-danger {
  color: hsl(355 91% 77%);
  background: rgba(106, 26, 26, 0.3);
}

.pill-neutral {
  color: var(--secondary);
  background: rgba(66, 77, 95, 0.26);
}

.list-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.agent-list,
.version-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.objective-group-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 12px;
}

.objective-group {
  padding-top: 2px;
}

.agent-row {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(8, 14, 28, 0.7);
  text-align: left;
  cursor: pointer;
}

.agent-row:hover,
.agent-row-active {
  border-color: rgba(80, 119, 177, 0.32);
  background: rgba(10, 25, 44, 0.46);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

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

.field-label {
  font-size: 12px;
  color: var(--muted-foreground);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field input,
.field textarea,
.field select,
.diff-selectors select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(7, 13, 25, 0.95);
  color: var(--foreground);
}

.field textarea {
  resize: vertical;
  min-height: 96px;
}

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

.selection-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.checkbox-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(8, 14, 28, 0.72);
  color: var(--secondary);
}

.checkbox-card input {
  margin: 0;
}

.top-gap {
  margin-top: 12px;
}

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

.chart-card {
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(8, 14, 28, 0.72);
}

.chart-card-wide {
  grid-column: 1 / -1;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 10px;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}

.trace-section + .trace-section {
  margin-top: 12px;
}

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

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

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(33, 44, 63, 0.9);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  color: var(--muted-foreground);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.data-table td {
  color: var(--secondary);
  font-size: 13px;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.restriction-grid {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.preview-output {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(7, 13, 25, 0.95);
  color: var(--foreground);
  line-height: 1.55;
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.meta-tile {
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(8, 14, 28, 0.7);
}

.rationale-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.rationale-item {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(10, 25, 44, 0.32);
  color: var(--secondary);
  line-height: 1.45;
}

.version-card {
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: rgba(8, 14, 28, 0.72);
}

.diff-selectors {
  display: flex;
  gap: 8px;
}

.diff-section + .diff-section {
  margin-top: 14px;
}

.diff-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(26, 38, 59, 0.78);
}

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

.diff-row span {
  min-height: 38px;
  padding: 9px 10px;
  background: rgba(7, 13, 25, 0.95);
  color: var(--secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-header span {
  color: var(--foreground);
  background: rgba(10, 25, 44, 0.72);
}

.diff-added span:last-child,
.diff-changed span:last-child {
  background: rgba(10, 66, 42, 0.38);
}

.diff-removed span:first-child,
.diff-changed span:first-child {
  background: rgba(88, 33, 33, 0.34);
}

.divider {
  height: 1px;
  margin: 4px 0;
  background: rgba(26, 38, 59, 0.78);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .panel-summary {
    grid-column: 1 / -1;
    border-top: 1px solid var(--border);
    border-right: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .agent-library-grid,
  .two-up-grid {
    grid-template-columns: 1fr;
  }

  .metadata-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-field-grid {
    grid-template-columns: 1fr;
  }

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

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

  .trace-inline-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: space-between;
  }

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

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .grid-cards,
  .metric-grid,
  .placeholder-grid {
    grid-template-columns: 1fr;
  }

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

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

  .diff-selectors {
    flex-direction: column;
  }
}
