:root {
  --bg: #f5f5f7;
  --bg-secondary: #eef1f6;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --line: rgba(17, 24, 39, 0.08);
  --line-strong: rgba(17, 24, 39, 0.14);
  --accent: #0a7f63;
  --accent-soft: rgba(10, 127, 99, 0.12);
  --danger: #d04949;
  --danger-soft: rgba(208, 73, 73, 0.12);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shell-max: 1480px;
  --gap-lg: 20px;
  --gap-md: 14px;
  --gap-sm: 10px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--text);
  background:
    radial-gradient(circle at 14% -4%, rgba(255, 255, 255, 0.85), transparent 28%),
    linear-gradient(180deg, #f8f9fb 0%, var(--bg) 52%, var(--bg-secondary) 100%);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue",
    "Microsoft YaHei", Arial, sans-serif;
  line-height: 1.5;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.06));
}

.shell {
  position: relative;
  z-index: 1;
  width: min(var(--shell-max), calc(100% - 40px));
  margin: 0 auto;
  padding: 18px 0 26px;
}

.masthead,
.stats-strip,
.workspace-grid {
  margin-bottom: var(--gap-md);
}

.brand-panel,
.command-panel,
.panel,
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.brand-panel,
.command-panel,
.panel,
.metric-card {
  padding: 22px;
}

.eyebrow,
.label {
  margin: 0;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

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

h1,
h2,
h3 {
  color: #0f172a;
  font-weight: 700;
  line-height: 1.15;
}

h1 {
  margin-top: 8px;
  font-size: clamp(46px, 4.1vw, 68px);
}

.hero-text {
  margin-top: 12px;
  max-width: 42ch;
  color: #475569;
  font-size: 18px;
  line-height: 1.6;
}

.masthead {
  display: grid;
  grid-template-columns: 1.18fr 1fr;
  gap: var(--gap-md);
  align-items: stretch;
}

.brand-panel {
  display: grid;
  align-content: start;
  min-height: 294px;
}

.command-panel {
  display: grid;
  gap: 14px;
  min-height: 294px;
}

.status-strip {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--gap-sm);
}

.status-chip {
  display: grid;
  align-content: center;
  gap: 6px;
  min-height: 84px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.7);
}

.status-chip-live {
  background: linear-gradient(135deg, rgba(10, 127, 99, 0.09), rgba(255, 255, 255, 0.74));
  border-color: rgba(10, 127, 99, 0.24);
}

.command-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 14px;
}

.command-head h2 {
  margin-top: 6px;
  font-size: 42px;
  font-weight: 650;
}

.metric-tally {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.metric-tally strong {
  font-size: 40px;
  line-height: 1;
}

.command-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1.35fr) repeat(4, minmax(112px, 1fr));
  gap: var(--gap-sm);
}

.scanner-brief {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.config-pre {
  min-height: 90px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(248, 250, 252, 0.9);
  color: #475569;
  white-space: pre-wrap;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--gap-sm);
}

.metric-card {
  min-height: 150px;
  display: grid;
  align-content: start;
  gap: 10px;
  border-radius: var(--radius-lg);
}

.metric-card h2 {
  font-size: 42px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.metric-card-lead {
  grid-column: span 1;
}

.summary-copy {
  color: #64748b;
  font-size: 15px;
  line-height: 1.52;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(360px, 1fr);
  grid-template-areas:
    "feed control"
    "orders stable"
    "runs risk"
    "runs positions"
    "runs diagnostics";
  gap: var(--gap-md);
  align-items: stretch;
}

.primary-stack,
.side-stack {
  display: contents;
}

.panel-feed {
  grid-area: feed;
}

.panel-orders {
  grid-area: orders;
}

.panel-runs {
  grid-area: runs;
}

.panel-emphasis {
  grid-area: control;
}

.panel-stable {
  grid-area: stable;
}

.panel-risk {
  grid-area: risk;
}

.panel-positions {
  grid-area: positions;
}

.panel-diagnostics {
  grid-area: diagnostics;
}

.panel {
  display: grid;
  gap: 14px;
  border-radius: var(--radius-lg);
  min-height: 220px;
}

.panel-runs {
  min-height: 640px;
}

.panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 0.9fr);
  gap: 12px;
  align-items: end;
}

.panel-head h2 {
  margin-top: 6px;
  font-size: 34px;
  font-weight: 650;
}

.panel-note {
  margin-left: auto;
  max-width: 34ch;
  color: #64748b;
  font-size: 15px;
  line-height: 1.54;
}

.candidate-stack,
.durable-list,
.position-stack,
.reason-list {
  min-height: 96px;
  align-content: start;
  overflow: auto;
  padding-right: 4px;
}

.candidate-stack {
  max-height: 420px;
}

.durable-list,
.position-stack {
  max-height: 360px;
}

.reason-list {
  max-height: 190px;
}

.candidate-card,
.durable-item,
.position-card,
.risk-stat,
.reason-panel,
.reason-item,
.empty,
.subpanel,
.diag-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
}

.candidate-card,
.durable-item,
.position-card,
.risk-stat,
.reason-panel,
.subpanel,
.diag-box {
  padding: 16px;
}

.candidate-card,
.durable-item,
.position-card {
  display: grid;
  gap: 10px;
}

.candidate-head,
.candidate-foot,
.durable-top,
.durable-grid,
.position-top,
.position-grid,
.position-flags,
.reason-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

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

.candidate-engine {
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.candidate-head h3,
.durable-item h3,
.position-title {
  font-size: 24px;
  font-weight: 650;
  line-height: 1.24;
}

.candidate-metrics {
  display: grid;
  justify-items: end;
  gap: 8px;
  font-weight: 600;
}

.candidate-metrics span {
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.05);
}

.candidate-key,
.position-key {
  color: var(--text-muted);
}

.leg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.leg-list li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(10, 127, 99, 0.2);
  border-radius: 999px;
  background: var(--accent-soft);
  color: #066c52;
}

.candidate-foot,
.durable-grid,
.position-grid {
  color: #64748b;
  font-size: 13px;
}

.risk-copy {
  color: #64748b;
  font-size: 13px;
  line-height: 1.48;
}

.config-form,
.subpanels,
.risk-grid,
.reason-columns {
  display: grid;
  gap: var(--gap-sm);
}

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

.risk-stat {
  display: grid;
  gap: 8px;
}

.risk-stat strong {
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.02em;
}

.risk-stat span {
  color: #64748b;
  font-size: 14px;
}

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

.reason-panel {
  display: grid;
  gap: 10px;
}

.reason-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding: 11px 12px;
  background: rgba(248, 250, 252, 0.92);
}

.reason-label {
  font-size: 14px;
}

.reason-key {
  margin-top: 3px;
  color: #94a3b8;
  font-size: 12px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.92);
  overflow: auto;
}

.panel-orders .table-wrap {
  min-height: 190px;
  max-height: 340px;
}

.panel-runs .table-wrap {
  min-height: 560px;
  max-height: calc(100vh - 182px);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  border-top: none;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}

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

.field span {
  color: #1f2937;
}

.field input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: #111827;
  font: inherit;
}

.field-inline {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.field-toggle input {
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
}

.btn {
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #111827;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(17, 24, 39, 0.24);
}

.btn-solid {
  color: #f8fafc;
  background: linear-gradient(135deg, #111827, #0f2847);
  border-color: #111827;
}

.btn-outline {
  background: rgba(255, 255, 255, 0.94);
}

.btn-ghost {
  background: rgba(248, 250, 252, 0.88);
}

.btn-block {
  width: 100%;
}

.compact-pre {
  margin-top: 4px;
  min-height: 72px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: #f8fafc;
  color: #334155;
  overflow: auto;
  white-space: pre-wrap;
}

.diag-box {
  display: grid;
  gap: 10px;
}

.error-box {
  min-height: 110px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: #0f172a;
  color: #e2e8f0;
  overflow: auto;
  white-space: pre-wrap;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(248, 250, 252, 0.9);
  color: #64748b;
  font-size: 12px;
}

.pill-live {
  color: #066c52;
  border-color: rgba(10, 127, 99, 0.28);
  background: var(--accent-soft);
}

.pill-bad {
  color: #b4232f;
  border-color: rgba(208, 73, 73, 0.3);
  background: var(--danger-soft);
}

.pill-idle {
  color: #64748b;
}

.metric-positive {
  color: #087a5d;
}

.metric-negative {
  color: #cf2f45;
}

.empty {
  display: flex;
  align-items: center;
  min-height: 96px;
  padding: 14px;
  color: #64748b;
}

.empty-tight {
  min-height: 78px;
}

@media (max-width: 1280px) {
  .shell {
    width: min(var(--shell-max), calc(100% - 24px));
  }

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

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

  .workspace-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "control"
      "feed"
      "stable"
      "risk"
      "orders"
      "positions"
      "runs"
      "diagnostics";
  }

  .panel-head {
    grid-template-columns: 1fr;
  }

  .panel-note {
    margin-left: 0;
    max-width: none;
  }

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

  .candidate-stack,
  .durable-list,
  .position-stack,
  .reason-list,
  .panel-orders .table-wrap,
  .panel-runs .table-wrap {
    max-height: none;
  }

  .panel-runs {
    min-height: 320px;
  }

  .panel-runs .table-wrap {
    min-height: 220px;
  }
}

@media (max-width: 900px) {
  .stats-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

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

  .risk-grid,
  .reason-columns {
    grid-template-columns: 1fr;
  }

  .metric-card h2,
  .risk-stat strong {
    font-size: 38px;
  }

  .panel-head h2,
  .candidate-head h3,
  .durable-item h3,
  .position-title {
    font-size: 24px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(var(--shell-max), calc(100% - 14px));
    padding: 10px 0 18px;
  }

  .brand-panel,
  .command-panel,
  .panel,
  .metric-card {
    padding: 16px;
  }

  .stats-strip,
  .command-grid {
    grid-template-columns: 1fr;
  }

  .command-head,
  .candidate-head,
  .candidate-foot,
  .durable-top,
  .durable-grid,
  .position-top,
  .position-grid,
  .position-flags {
    display: grid;
  }

  .candidate-metrics {
    justify-items: start;
  }

  h1 {
    font-size: 44px;
  }
}
