:root {
  /* Shared ATOP_Dev design tokens — kept identical to the index.html :root so
     all three pages (Console / Cockpit / EngineLab) share one visual language. */
  --bg: #f4f5f2;
  --panel: #ffffff;
  --panel-soft: #f9faf7;
  --ink: #17211f;
  --muted: #5d6966;
  --line: #dfe4dd;
  --accent: #126b61;
  --accent-soft: #e5f1ee;
  --ok: #186a4f;
  --warn: #936217;
  --danger: #a9432b;
  --shadow: 0 10px 24px rgba(19, 34, 34, 0.08);
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-sans);
}

.shell {
  width: min(1280px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
  gap: 24px;
  align-items: end;
  padding: 24px 0;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.lead,
.muted,
.queue-item p,
.table-row small,
.result-box,
.system-note {
  color: var(--muted);
}

.lead {
  margin-top: 8px;
  line-height: 1.5;
}

.topbar-actions {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: end;
}

.auth-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.system-note {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  font-size: 13px;
}

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

.is-hidden,
.secondary-panel {
  display: none !important;
}

.overview-grid,
.work-grid,
.split-grid {
  display: grid;
  gap: 16px;
}

.overview-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

.work-grid {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
}

.split-grid {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.92fr);
  align-items: start;
}

.section-head,
.detail-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.compact-head {
  margin-bottom: 8px;
}

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

.compact-metrics {
  margin-top: 10px;
}

.metric-card {
  min-height: 84px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 28px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.metric-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-transform: none;
  overflow-wrap: anywhere;
}

.action-list,
.queue-list,
.table-list {
  display: grid;
  gap: 8px;
}

.action-list p {
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  line-height: 1.45;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(8, minmax(82px, 1fr));
  gap: 8px;
}

.pipeline span {
  min-height: 38px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.factory-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.operations-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.operations-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.operation-column {
  min-height: 116px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.operation-column-head,
.operation-card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.operation-column-head {
  margin-bottom: 8px;
}

.operation-column-head span {
  color: var(--muted);
  font-weight: 800;
}

.operation-card {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.operation-card.healthy {
  border-left: 4px solid var(--ok);
}

.operation-card.attention {
  border-left: 4px solid var(--warn);
}

.operation-card.critical {
  border-left: 4px solid var(--danger);
}

.operation-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.operation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-button {
  min-height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.status-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--muted);
}

.status-dot.running {
  background: var(--ok);
}

.status-dot.event_waiting,
.status-dot.idle {
  background: var(--accent);
}

.status-dot.paused,
.status-dot.stopped,
.status-dot.unknown {
  background: #8b949e;
}

.status-dot.degraded {
  background: var(--warn);
}

.status-dot.failed {
  background: var(--danger);
}

.interaction-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.interaction-map,
.interaction-detail {
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.interaction-map {
  overflow: auto;
}

.primary-graph-panel .interaction-map,
.primary-graph-panel .interaction-detail {
  min-height: 520px;
}

.interaction-detail {
  padding: 14px;
  overflow: auto;
}

.agent-graph {
  display: block;
  min-width: 900px;
  width: 100%;
}

.graph-edge {
  fill: none;
  stroke: rgba(23, 32, 42, 0.28);
  stroke-width: 1.6;
}

.graph-edge.data_flow,
.graph-edge.selection_gate {
  stroke: rgba(20, 95, 90, 0.7);
  stroke-width: 2;
}

.graph-edge.qa_gate {
  stroke: rgba(154, 90, 31, 0.62);
}

.graph-edge.external_bridge {
  stroke-dasharray: 6 4;
}

.graph-arrow {
  fill: rgba(23, 32, 42, 0.42);
}

.graph-edge-label {
  fill: var(--muted);
  font-size: 10px;
  font-weight: 800;
  paint-order: stroke;
  stroke: var(--panel-soft);
  stroke-width: 4px;
  text-anchor: middle;
}

.graph-node {
  width: 160px;
  height: 68px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: default;
  text-align: left;
  box-shadow: 0 6px 14px rgba(19, 34, 34, 0.08);
}

.graph-detail-page {
  min-height: calc(100vh - 140px);
}

.detail-page-body {
  min-height: 520px;
  background: #ffffff;
}

.graph-node[data-graph-agent],
.graph-node[data-graph-candidate] {
  cursor: pointer;
}

.graph-node[data-graph-node] {
  cursor: pointer;
}

.graph-node.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(20, 95, 90, 0.14), 0 6px 14px rgba(19, 34, 34, 0.08);
}

.graph-node.running,
.graph-node.event_waiting,
.graph-node.idle {
  border-left: 5px solid var(--ok);
}

.graph-node.event_waiting,
.graph-node.idle {
  border-left-color: var(--accent);
}

.graph-node.paused,
.graph-node.stopped,
.graph-node.unknown {
  border-left: 5px solid #8b949e;
}

.graph-node.degraded,
.graph-node.attention {
  border-left: 5px solid var(--warn);
}

.graph-node.failed,
.graph-node.critical {
  border-left: 5px solid var(--danger);
}

.graph-node strong,
.graph-node span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-node strong {
  font-size: 12px;
}

.graph-node span {
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.graph-node.platform {
  border-color: rgba(20, 95, 90, 0.5);
  background: #e5f1ee;
}

.graph-node.factory {
  border-color: rgba(24, 106, 79, 0.35);
  background: #edf6ef;
}

.graph-node.operator_agent {
  border-color: rgba(154, 90, 31, 0.32);
  background: #fff7ed;
}

.graph-node.candidate,
.graph-node.build_session {
  background: #f8f9fb;
}

.development-platform-page {
  display: grid;
  gap: 16px;
}

.development-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
  border-color: rgba(20, 95, 90, 0.24);
  background: linear-gradient(135deg, #ffffff 0%, #f6fbf8 62%, #e5f1ee 100%);
}

.development-hero h2 {
  font-size: 25px;
  line-height: 1.28;
  text-wrap: pretty;
}

.development-hero-actions {
  display: grid;
  gap: 10px;
  min-width: 210px;
}

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

.stage-card {
  min-height: 148px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.stage-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(20, 95, 90, 0.12), var(--shadow);
}

.stage-card span {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.stage-card strong {
  display: block;
  margin-bottom: 8px;
  font-size: 17px;
}

.stage-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.development-guidance {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.development-guidance article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
}

.development-guidance strong {
  display: block;
  margin-bottom: 6px;
}

.development-guidance p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.revenue-builder-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
}

.revenue-agent-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

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

.questionnaire-grid .field:nth-last-child(-n + 5) {
  grid-column: span 2;
}

.development-panel {
  scroll-margin-top: 16px;
}

.qa-toolbar {
  margin-bottom: 12px;
}

.candidate-window {
  width: min(1120px, calc(100vw - 28px));
  max-height: min(820px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(19, 34, 34, 0.22);
}

.candidate-window::backdrop {
  background: rgba(23, 32, 42, 0.38);
}

.candidate-window-shell {
  display: grid;
  gap: 16px;
  padding: 18px;
}

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

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

.candidate-window-grid section {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 0 12px 12px;
  color: var(--muted);
  font-size: 12px;
}

.graph-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--muted);
}

.legend-dot.platform,
.legend-dot.factory,
.legend-dot.public_agent {
  background: var(--accent);
}

.legend-dot.operator_agent {
  background: var(--warn);
}

.legend-dot.candidate,
.legend-dot.build_session {
  background: #7b8794;
}

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

.relationship-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.relationship-section h3 {
  margin-bottom: 8px;
}

.relationship-section ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.relationship-section p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.relationship-section p span {
  color: var(--accent);
  font-weight: 800;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 8px;
}

.graph-detail-actions {
  margin-top: 12px;
}

.table-row,
.queue-item {
  width: 100%;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px auto;
  gap: 12px;
  align-items: center;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.table-row.active {
  border-color: rgba(20, 95, 90, 0.5);
  background: var(--accent-soft);
}

.table-row span,
.queue-main,
.detail-block {
  min-width: 0;
}

.table-row strong,
.queue-item strong,
.detail-title strong {
  display: block;
  overflow-wrap: anywhere;
}

.table-row small,
.queue-item p {
  display: block;
  margin-top: 4px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

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

.queue-item.stacked {
  align-items: flex-start;
}

.queue-actions {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef1ec;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  white-space: nowrap;
}

.pill.ok {
  background: #e2f0ea;
  color: var(--ok);
}

.pill.warn {
  background: #f5eadc;
  color: var(--warn);
}

.workspace-head {
  align-items: start;
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-tab {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

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

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

.task-form {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 13px;
  font-weight: 800;
}

textarea,
input,
button {
  font: inherit;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

/* Buttons follow the Console (index.html) reference: bordered white pill,
   teal accent on hover, solid teal for primary. */
.button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

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

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.button.primary:hover {
  opacity: 0.9;
}

.button.secondary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

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

.compact-button {
  min-height: 34px;
  white-space: nowrap;
}

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

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

.result-box,
.json-view,
.detail-block {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.result-box {
  margin-bottom: 10px;
}

.result-box.slim {
  margin-bottom: 8px;
}

.json-view {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  background: #17202a;
  color: #d9eee8;
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.detail-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.command-line {
  color: var(--muted);
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
}

.review-block {
  margin-top: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) auto;
  gap: 8px;
}

.diagnostic-grid {
  display: none;
}

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

a {
  color: var(--accent);
  font-weight: 800;
}

@media (max-width: 980px) {
  .topbar,
  .overview-grid,
  .work-grid,
  .split-grid,
  .factory-grid,
  .operations-grid,
  .interaction-shell,
  .development-hero,
  .development-stage-grid,
  .development-guidance,
  .revenue-builder-grid,
  .questionnaire-grid,
  .candidate-window-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .auth-form {
    grid-template-columns: 1fr;
  }

  .pipeline {
    grid-template-columns: repeat(4, minmax(82px, 1fr));
  }
}

@media (max-width: 680px) {
  .shell {
    width: min(100vw - 18px, 1280px);
    padding-top: 12px;
  }

  h1 {
    font-size: 28px;
  }

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

  .queue-item,
  .inline-form {
    grid-template-columns: 1fr;
    display: grid;
  }

  .development-hero-actions {
    min-width: 0;
  }

  .stage-card {
    min-height: auto;
  }

  .questionnaire-grid .field:nth-last-child(-n + 5) {
    grid-column: auto;
  }

  .pipeline {
    grid-template-columns: repeat(2, minmax(82px, 1fr));
  }
}
