:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-strong: #eef4ff;
  --text: #172033;
  --muted: #64748b;
  --border: #d8e0ea;
  --border-strong: #b8c4d4;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok: #047857;
  --warn: #b45309;
  --err: #b42318;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(120deg, rgba(37, 99, 235, 0.08), transparent 36%),
    radial-gradient(circle at 86% 8%, rgba(4, 120, 87, 0.12), transparent 24%),
    var(--bg);
  font-family:
    "PingFang SC",
    "Noto Sans SC",
    "Microsoft YaHei",
    sans-serif;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.debug-shell {
  width: min(100%, 1600px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) minmax(280px, 360px);
  grid-template-rows: auto minmax(520px, 1fr) 220px;
  grid-template-areas:
    "topbar topbar topbar"
    "sidebar workspace inspector"
    "console console console";
  gap: 12px;
}

.topbar,
.sidebar,
.workspace,
.inspector,
.console {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  grid-area: topbar;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill-running {
  border-color: #93c5fd;
  background: #eff6ff;
  color: var(--accent-dark);
}

.pill-ok {
  border-color: #86efac;
  background: #f0fdf4;
  color: var(--ok);
}

.pill-err {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--err);
}

.context-bar {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(150px, 1.1fr) 150px auto auto;
  gap: 10px;
  align-items: end;
  min-width: 0;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check {
  display: flex;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  white-space: nowrap;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 34px;
  padding: 6px 9px;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.sidebar {
  grid-area: sidebar;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav-item,
.nav-link,
.primary,
.ghost,
.secondary-link,
.action-btn {
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
}

.nav-item,
.nav-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
}

.nav-item:hover,
.nav-link:hover,
.nav-item.active {
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--accent-dark);
}

.workspace {
  grid-area: workspace;
  min-width: 0;
  border-radius: 10px;
  padding: 14px;
  overflow: hidden;
}

.view {
  display: none;
  min-width: 0;
}

.view.active {
  display: grid;
  gap: 12px;
}

.panel-block {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.view-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 15px;
}

p {
  margin: 5px 0 0;
  color: var(--muted);
}

.primary {
  padding: 8px 14px;
  border-color: var(--accent-dark);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary:hover {
  background: var(--accent-dark);
}

.primary:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.ghost {
  padding: 6px 10px;
  border-color: var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ghost:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.danger-btn {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--err);
}

.danger-btn:hover {
  border-color: #fca5a5;
  color: #991b1b;
}

.ghost:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.secondary-link,
.action-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-color: #bfdbfe;
  background: #eff6ff;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.raw-text {
  min-height: 180px;
  padding: 11px;
  line-height: 1.7;
}

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

.quick-grid > div,
.summary-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 10px;
}

.quick-grid h2 {
  display: inline-block;
  margin-right: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(180px, 0.7fr);
  gap: 12px;
  align-items: end;
}

.lab-switch {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

.lab-tab {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.lab-tab.active {
  background: rgba(15, 23, 42, 0.08);
  color: var(--text);
}

.product-lab-panel {
  display: none;
  gap: 14px;
}

.product-lab-panel.active {
  display: grid;
}

.product-lab-overview {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
}

.product-lab-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr);
  gap: 12px;
}

.product-lab-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.moon-grid {
  display: grid;
  gap: 12px;
}

.moon-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkbox-inline input {
  width: auto;
}

.wide-label {
  grid-column: 1 / -1;
}

.lineage-stage-chain {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.image-picker-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.image-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.image-preview-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.image-preview-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-strong);
}

.image-preview-meta {
  display: grid;
  gap: 3px;
  padding: 8px;
}

.image-preview-meta strong,
.image-preview-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-meta strong {
  color: var(--text);
  font-size: 12px;
}

.image-preview-meta span,
.mode-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-line {
  color: var(--muted);
  font-weight: 800;
}

.status-ok {
  color: var(--ok);
}

.status-err {
  color: var(--err);
}

.agent-flow-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 12px;
}

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

.phase-card {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 5px;
}

.phase-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.phase-card strong {
  color: var(--text);
  font-size: 15px;
}

.phase-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.agent-flow-grid > section {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 12px;
  display: grid;
  gap: 12px;
}

.memory-layout {
  display: grid;
  gap: 12px;
}

.memory-section {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 12px;
  display: grid;
  gap: 12px;
}

.memory-section-primary {
  background: #fff;
}

.section-head {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
}

.section-head p {
  font-size: 12px;
  font-weight: 800;
}

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

.product-card {
  min-width: 0;
  min-height: 72px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  cursor: pointer;
}

.product-card input {
  grid-row: span 2;
}

.product-card span {
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.product-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.disabled-panel {
  background: #f8fafc;
}

.mode-disabled-card {
  opacity: 0.48;
  cursor: not-allowed;
}

.muted-card {
  opacity: 0.62;
  cursor: not-allowed;
}

.flow-steps {
  display: grid;
  gap: 8px;
}

.flow-step {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 9px;
  cursor: pointer;
}

.flow-step[data-status="succeeded"] {
  border-color: #bbf7d0;
  background: #f7fff9;
}

.flow-step[data-status="running"] {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.flow-step[data-status="failed"] {
  border-color: #fecaca;
  background: #fff7f7;
}

.flow-step-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 900;
}

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

.workflow-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(0, 1.4fr);
  gap: 12px;
}

.workflow-layout > section {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.compact-actions {
  margin-top: 8px;
}

.summary-card {
  display: grid;
  gap: 4px;
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 800;
}

.graph-preview {
  min-height: 120px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: #fbfdff;
  padding: 12px;
  overflow: auto;
}

.workflow-node-chain {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
}

.workflow-node {
  min-width: 150px;
  max-width: 220px;
  min-height: 74px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 4px 7px;
  text-align: left;
  cursor: pointer;
}

.workflow-node:hover,
.workflow-node.active {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.workflow-node[data-status="succeeded"],
.workflow-node[data-status="success"],
.workflow-node[data-status="completed"] {
  border-color: #bbf7d0;
}

.workflow-node[data-status="failed"],
.workflow-node[data-status="error"] {
  border-color: #fecaca;
}

.node-order {
  grid-row: span 2;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.node-name,
.node-status {
  min-width: 0;
  overflow-wrap: anywhere;
}

.node-name {
  font-size: 12px;
  font-weight: 900;
}

.node-status {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.workflow-arrow {
  color: var(--muted);
  font-weight: 900;
}

.steps {
  display: grid;
  gap: 10px;
}

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

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

.retrieval-pipeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.pipeline-stage {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
}

.pipeline-stage:hover {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.pipeline-stage span {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 900;
}

.pipeline-stage strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.run-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
}

.run-item:hover,
.run-item.active {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.run-title {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 900;
}

.run-title-actions {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.run-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.selectable-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.check-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.check-item[data-status="pass"] {
  border-color: #bbf7d0;
  background: #f7fff9;
}

.check-item[data-status="warn"] {
  border-color: #fed7aa;
  background: #fffaf3;
}

.check-item[data-status="fail"] {
  border-color: #fecaca;
  background: #fff7f7;
}

.check-title {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 900;
}

.check-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
}

.check-item[data-status="pass"] .check-badge {
  background: #ecfdf5;
  color: var(--ok);
}

.check-item[data-status="warn"] .check-badge {
  background: #fffbeb;
  color: var(--warn);
}

.check-item[data-status="fail"] .check-badge {
  background: #fef2f2;
  color: var(--err);
}

.check-detail {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.step {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
}

.step:hover,
.step.active {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.step-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 800;
}

.step-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.step-preview {
  margin-top: 8px;
  color: #334155;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.step-status {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
}

.step-status.succeeded,
.step-status.success,
.step-status.completed {
  background: #ecfdf5;
  color: var(--ok);
}

.step-status.failed,
.step-status.error {
  background: #fef2f2;
  color: var(--err);
}

.code {
  margin: 8px 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 350px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  padding: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 12px;
  line-height: 1.55;
}

.code.tall {
  max-height: 560px;
}

.inspector {
  grid-area: inspector;
  min-width: 0;
  border-radius: 10px;
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.inspector-head {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: flex-start;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inspector-code {
  max-height: none;
  min-height: 0;
}

.console {
  grid-area: console;
  min-width: 0;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.console-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.event-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.event-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.event-item[data-level="error"] {
  border-color: #fecaca;
  background: #fff7f7;
}

.event-item[data-level="success"] {
  border-color: #bbf7d0;
  background: #f7fff9;
}

.event-title {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.event-time {
  color: var(--muted);
  font-weight: 700;
}

.event-summary {
  margin-top: 6px;
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}

.event-artifacts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.event-chip-label {
  color: var(--muted);
}

.event-glimpse-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.event-glimpse {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: rgba(248, 250, 252, 0.8);
}

.event-glimpse-label {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.event-detail {
  margin-top: 6px;
}

.event-detail summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .debug-shell {
    grid-template-columns: 128px minmax(0, 1fr);
    grid-template-rows: auto minmax(520px, auto) auto 220px;
    grid-template-areas:
      "topbar topbar"
      "sidebar workspace"
      "inspector inspector"
      "console console";
  }

  .context-bar,
  .summary-grid,
  .retrieval-pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .product-lab-grid,
  .lineage-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .debug-shell {
    padding: 8px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas:
      "topbar"
      "sidebar"
      "workspace"
      "inspector"
      "console";
  }

  .topbar,
  .view-head {
    align-items: stretch;
    flex-direction: column;
  }

  .context-bar,
  .quick-grid,
  .inline-form,
  .agent-flow-grid,
  .product-grid,
  .phase-grid,
  .workflow-layout,
  .summary-grid,
  .retrieval-pipeline {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    display: flex;
    overflow-x: auto;
  }

  .nav-item,
  .nav-link {
    white-space: nowrap;
  }
}
