:root {
  --flow-bg: #071018;
  --flow-surface: rgba(9, 23, 34, 0.9);
  --flow-surface-strong: rgba(12, 30, 43, 0.96);
  --flow-line: var(--border, rgba(147, 197, 253, 0.15));
  --flow-text: var(--text, #e8f1f8);
  --flow-muted: var(--muted, #90a7b8);
  --flow-accent: var(--accent, #4fd1c5);
  --flow-blue: #63b3ed;
  --flow-green: var(--executed, #68d391);
  --flow-warn: var(--pending, #f6ad55);
  --flow-danger: var(--failed, #fc8181);
  --flow-ink: #d9f7ff;
}

body {
  background:
    radial-gradient(circle at 86% 0%, rgba(79, 209, 197, 0.12), transparent 30%),
    radial-gradient(circle at 10% 8%, rgba(99, 179, 237, 0.12), transparent 28%),
    var(--flow-bg);
}

.lifecycle-shell {
  width: min(100%, var(--page-shell-max-wide, 100%));
  max-width: var(--page-shell-max-wide, 100%);
  padding-top: 14px;
}

.lifecycle-shell .panel,
.lifecycle-shell .status-card {
  border: var(--page-card-border, 1px solid var(--flow-line));
  border-radius: var(--page-card-radius, var(--radius-lg, 16px));
  background: var(--page-card-bg, linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.012)), var(--flow-surface));
  box-shadow: var(--page-card-shadow-strong, 0 20px 46px rgba(2, 8, 23, 0.28));
  backdrop-filter: blur(18px);
}

.panel {
  display: block;
  min-height: auto;
}

.lifecycle-head {
  max-width: none;
  min-height: auto;
  margin: 12px 0 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
}

.lifecycle-title-block {
  min-width: 0;
}

.hero-kicker,
.card-kicker,
.detail-kicker {
  color: var(--flow-accent);
  font: 700 10px/1 var(--font-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.lifecycle-head h1 {
  margin: 7px 0 0;
  color: var(--flow-text);
  font-size: clamp(22px, 2.6vw, 34px);
  line-height: 1.05;
  letter-spacing: -0.055em;
}

.lifecycle-head p,
.panel-copy,
.stage-copy,
.warning-copy,
.detail-subtitle,
.timeline-copy,
.event-copy,
.price-copy {
  color: var(--flow-muted);
  font-size: 12px;
  line-height: 1.55;
}

.lifecycle-head p {
  max-width: 980px;
  margin: 7px 0 0;
}

.lifecycle-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: min(100%, 300px);
}

.lifecycle-meta span,
.flow-chip,
.fill-pill,
.warning-chip,
.event-chip,
.event-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 26px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--flow-muted);
  font: 700 10.5px/1.2 var(--font-mono, 'JetBrains Mono', monospace);
  overflow-wrap: anywhere;
}

.filter-panel,
.graph-panel,
.detail-panel {
  padding: 14px;
  margin-top: 12px;
}

.filter-panel {
  display: block;
  max-width: none;
  min-height: auto;
  margin-left: 0;
  margin-right: 0;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.field {
  display: grid;
  grid-column: span 2;
  gap: 7px;
  min-width: 0;
}

.wide-field {
  grid-column: span 3;
}

.field label {
  color: var(--flow-muted);
  font: 700 10px/1 var(--font-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  min-height: 36px;
  border: 1px solid rgba(147, 197, 253, 0.16);
  border-radius: var(--radius-md, 12px);
  background: var(--page-input-bg, rgba(4, 13, 22, 0.72));
  color: var(--flow-text);
  outline: none;
  padding: 0 11px;
  font-family: var(--font-body, 'Sora', sans-serif);
  font-size: 13px;
  line-height: 1.2;
}

.field input:focus,
.field select:focus {
  border-color: rgba(79, 209, 197, 0.42);
  box-shadow: 0 0 0 3px rgba(79, 209, 197, 0.09);
}

.readonly-mode-field {
  min-height: 36px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.advanced-filter {
  grid-column: span 2;
  min-height: 36px;
  border: 1px solid rgba(147, 197, 253, 0.13);
  border-radius: var(--radius-md, 12px);
  background: rgba(255,255,255,0.025);
  color: var(--flow-muted);
}

.advanced-filter summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  cursor: pointer;
  font: 700 11px/1 var(--font-body, 'Sora', sans-serif);
}

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

.advanced-filter .field {
  grid-column: auto;
}

.filter-actions {
  display: flex;
  grid-column: span 2;
  gap: 8px;
}

.flow-btn {
  min-height: 36px;
  border: var(--page-button-border, 1px solid rgba(147, 197, 253, 0.15));
  border-radius: var(--radius-md, 12px);
  padding: 0 13px;
  background: var(--page-button-bg, linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.025)));
  color: var(--flow-text);
  font: 700 12px/1 var(--font-body, 'Sora', sans-serif);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.flow-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(79, 209, 197, 0.34);
}

.flow-btn:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.flow-btn.primary {
  border-color: rgba(79, 209, 197, 0.38);
  background: var(--page-button-bg-active, linear-gradient(180deg, rgba(79, 209, 197, 0.24), rgba(79, 209, 197, 0.07)));
}

.flow-btn.compact {
  min-height: 30px;
  padding-inline: 10px;
  border-radius: var(--radius-md, 12px);
  font-size: 11px;
}

.insight-strip {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 12px;
  margin-top: 12px;
}

.status-card {
  min-height: 112px;
  padding: 14px;
  overflow: hidden;
}

.stage-title {
  margin-top: 7px;
  color: var(--flow-text);
  font-size: clamp(19px, 2vw, 26px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.stage-placeholder,
.warning-placeholder {
  margin-top: 8px;
  color: var(--flow-muted);
  font-size: 12px;
  line-height: 1.55;
}

.stage-chip-row,
.warning-list,
.detail-chip-row,
.event-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.warning-card {
  border-color: rgba(246, 173, 85, 0.2);
}

.warning-list {
  display: grid;
  gap: 7px;
}

.warning-item {
  padding: 9px 10px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(4, 13, 22, 0.46);
}

.warning-title {
  color: var(--flow-text);
  font-size: 12px;
  font-weight: 800;
}

.warning-item.severity-high { border-color: rgba(252, 129, 129, 0.32); }
.warning-item.severity-medium { border-color: rgba(246, 173, 85, 0.32); }
.warning-item.severity-low { border-color: rgba(99, 179, 237, 0.22); }

.fill-pill.actual_ibkr { color: var(--flow-green); border-color: rgba(104,211,145,0.34); background: rgba(104,211,145,0.09); }
.fill-pill.paper_ibkr { color: var(--flow-blue); border-color: rgba(99,179,237,0.34); background: rgba(99,179,237,0.09); }
.fill-pill.backtest_simulated { color: var(--flow-warn); border-color: rgba(246,173,85,0.34); background: rgba(246,173,85,0.09); }
.fill-pill.unknown { color: var(--flow-muted); border-color: rgba(144,167,184,0.28); background: rgba(144,167,184,0.08); }
.fill-pill.price_kind { color: var(--flow-ink); border-color: rgba(94,234,212,0.24); background: rgba(94,234,212,0.07); }
.fill-pill.order_detail_unverified_fill { color: var(--flow-danger); border-color: rgba(252,129,129,0.26); background: rgba(252,129,129,0.06); }

.flow-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 12px;
}

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

.panel-header,
.graph-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title {
  color: var(--flow-text);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.panel-copy {
  margin-top: 5px;
}

.panel-tools,
.graph-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.lane-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 7px;
  margin: 12px 0 10px;
}

.lane-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px 9px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.035);
}

.lane-chip-name,
.lane-chip-count {
  color: var(--flow-text);
  font: 700 10.5px/1.1 var(--font-mono, 'JetBrains Mono', monospace);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane-chip-count {
  color: var(--flow-muted);
}

.lane-chip.lane-selection { border-color: rgba(244, 114, 182, 0.34); background: linear-gradient(135deg, rgba(244, 114, 182, 0.12), rgba(244, 114, 182, 0.035)); }
.lane-chip.lane-confirmation { border-color: rgba(251, 191, 36, 0.34); background: linear-gradient(135deg, rgba(251, 191, 36, 0.12), rgba(251, 191, 36, 0.035)); }
.lane-chip.lane-compute { border-color: rgba(34, 211, 238, 0.32); background: linear-gradient(135deg, rgba(34, 211, 238, 0.11), rgba(34, 211, 238, 0.032)); }
.lane-chip.lane-execution { border-color: rgba(96, 165, 250, 0.34); background: linear-gradient(135deg, rgba(96, 165, 250, 0.12), rgba(96, 165, 250, 0.035)); }
.lane-chip.lane-protection { border-color: rgba(251, 113, 133, 0.34); background: linear-gradient(135deg, rgba(251, 113, 133, 0.12), rgba(251, 113, 133, 0.035)); }
.lane-chip.lane-risk_adjustment,
.lane-chip.lane-risk { border-color: rgba(251, 146, 60, 0.34); background: linear-gradient(135deg, rgba(251, 146, 60, 0.12), rgba(251, 146, 60, 0.035)); }
.lane-chip.lane-scale { border-color: rgba(167, 139, 250, 0.34); background: linear-gradient(135deg, rgba(167, 139, 250, 0.12), rgba(167, 139, 250, 0.035)); }
.lane-chip.lane-exit,
.lane-chip.lane-interrupt { border-color: rgba(248, 113, 113, 0.34); background: linear-gradient(135deg, rgba(248, 113, 113, 0.12), rgba(248, 113, 113, 0.035)); }
.lane-chip.lane-universe { border-color: rgba(163, 230, 53, 0.3); background: linear-gradient(135deg, rgba(163, 230, 53, 0.11), rgba(163, 230, 53, 0.032)); }
.lane-chip.lane-market_data { border-color: rgba(56, 189, 248, 0.32); background: linear-gradient(135deg, rgba(56, 189, 248, 0.11), rgba(56, 189, 248, 0.032)); }
.lane-chip.lane-account { border-color: rgba(52, 211, 153, 0.32); background: linear-gradient(135deg, rgba(52, 211, 153, 0.11), rgba(52, 211, 153, 0.032)); }
.lane-chip.lane-backtest { border-color: rgba(246, 173, 85, 0.34); background: linear-gradient(135deg, rgba(246, 173, 85, 0.12), rgba(246, 173, 85, 0.035)); }
.lane-chip.lane-system { border-color: rgba(148, 163, 184, 0.3); background: linear-gradient(135deg, rgba(148, 163, 184, 0.1), rgba(148, 163, 184, 0.03)); }

.graph-frame {
  position: relative;
  min-height: 560px;
  overflow: hidden;
  border-radius: var(--radius-lg, 16px);
  border: 1px solid rgba(147, 197, 253, 0.12);
  background:
    linear-gradient(rgba(79,209,197,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,209,197,0.025) 1px, transparent 1px),
    radial-gradient(circle at top left, rgba(79,209,197,0.07), transparent 34%),
    rgba(3, 10, 18, 0.58);
  background-size: 34px 34px, 34px 34px, auto, auto;
}

.cy-graph,
.graph-guide,
.timeline-fallback {
  width: 100%;
  height: 560px;
  min-height: 560px;
}

.graph-guide {
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 26px;
  text-align: center;
}

.graph-guide-kicker {
  color: var(--flow-accent);
  font: 700 11px/1 var(--font-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.graph-guide-title {
  color: var(--flow-text);
  font-size: clamp(20px, 2.4vw, 30px);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.graph-guide-copy {
  max-width: 680px;
  color: var(--flow-muted);
  font-size: 13px;
  line-height: 1.65;
}

.timeline-fallback {
  overflow: auto;
  padding: 16px;
}

.timeline-fallback[hidden],
.cy-graph[hidden] {
  display: none;
}

.timeline-track,
.event-list {
  display: grid;
  gap: 10px;
}

.timeline-item,
.event-item {
  position: relative;
  display: grid;
  gap: 7px;
  padding: 12px 13px 12px 17px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(147, 197, 253, 0.12);
  background: rgba(9, 23, 34, 0.72);
}

.timeline-item::before,
.event-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 999px;
  background: var(--flow-accent);
}

.timeline-item.fill-actual_ibkr::before,
.event-item.fill-actual_ibkr::before { background: var(--flow-green); }
.timeline-item.fill-paper_ibkr::before,
.event-item.fill-paper_ibkr::before { background: var(--flow-blue); }
.timeline-item.fill-backtest_simulated::before,
.event-item.fill-backtest_simulated::before { background: var(--flow-warn); }
.timeline-item.fill-unknown::before,
.event-item.fill-unknown::before { background: var(--flow-muted); }

.timeline-title,
.event-title {
  color: var(--flow-text);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

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

.node-details {
  margin-top: 12px;
}

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

.detail-title {
  color: var(--flow-text);
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.price-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(147, 197, 253, 0.13);
  background: rgba(4, 13, 22, 0.56);
}

.price-panel.is-real { border-color: rgba(104, 211, 145, 0.28); background: rgba(104, 211, 145, 0.07); }
.price-panel.is-paper { border-color: rgba(99, 179, 237, 0.28); background: rgba(99, 179, 237, 0.07); }
.price-panel.is-sim { border-color: rgba(246, 173, 85, 0.3); background: rgba(246, 173, 85, 0.07); }
.price-panel.is-unverified { border-color: rgba(252, 129, 129, 0.24); background: rgba(252, 129, 129, 0.06); }
.price-panel.is-reference { border-color: rgba(94, 234, 212, 0.2); background: rgba(94, 234, 212, 0.045); }

.change-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(94, 234, 212, 0.18);
  background: rgba(94, 234, 212, 0.045);
}

.change-title {
  color: var(--flow-text);
  font-size: 13px;
  font-weight: 800;
}

.change-list {
  display: grid;
  gap: 7px;
}

.change-row {
  display: grid;
  grid-template-columns: minmax(54px, 0.5fr) minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 9px;
  border-radius: var(--radius-md, 12px);
  background: rgba(4, 13, 22, 0.38);
}

.change-label,
.change-before,
.change-after,
.change-arrow {
  font: 700 11px/1.25 var(--font-mono, 'JetBrains Mono', monospace);
  overflow-wrap: anywhere;
}

.change-label,
.change-arrow {
  color: var(--flow-muted);
}

.change-before {
  color: var(--flow-warn);
}

.change-after {
  color: var(--flow-green);
}

.price-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--flow-text);
  font-size: 13px;
  font-weight: 800;
}

.price-value {
  font: 800 22px/1 var(--font-mono, 'JetBrains Mono', monospace);
  color: var(--flow-ink);
}

.detail-grid {
  display: grid;
  gap: 7px;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border-radius: var(--radius-md, 12px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.028);
}

.detail-label {
  color: var(--flow-muted);
  font: 700 10px/1 var(--font-mono, 'JetBrains Mono', monospace);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.detail-value {
  color: var(--flow-text);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.raw-details,
.events-drawer {
  border-radius: var(--radius-lg, 16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(2, 8, 14, 0.48);
  overflow: hidden;
}

.raw-details summary,
.events-drawer summary {
  cursor: pointer;
  padding: 11px 12px;
  color: var(--flow-muted);
  font: 700 11px/1 var(--font-mono, 'JetBrains Mono', monospace);
}

.events-drawer {
  margin-top: 12px;
}

.events-drawer summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.events-drawer .panel-copy,
.events-drawer .event-list {
  padding: 0 12px 12px;
}

.events-drawer .event-list {
  max-height: 520px;
  overflow: auto;
}

.raw-details pre {
  max-height: 300px;
  overflow: auto;
  margin: 0;
  padding: 0 12px 12px;
  color: #b9d7e8;
  font: 11px/1.55 var(--font-mono, 'JetBrains Mono', monospace);
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state,
.loading-state,
.error-state {
  padding: 16px;
  border-radius: var(--radius-md, 12px);
  border: 1px dashed rgba(147, 197, 253, 0.18);
  background: rgba(4, 13, 22, 0.46);
  color: var(--flow-muted);
  font-size: 13px;
  line-height: 1.6;
}

.error-state {
  border-color: rgba(252, 129, 129, 0.3);
  color: #ffc7c7;
}

.mono {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
}

@media (max-width: 1180px) {
  .filter-form {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .field,
  .wide-field,
  .advanced-filter,
  .filter-actions {
    grid-column: span 3;
  }

  .lifecycle-head,
  .filter-panel {
    max-width: none;
  }

  .flow-workspace,
  .insight-strip {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  .lifecycle-shell {
    padding-inline: 10px;
  }

  .lifecycle-head,
  .panel-header,
  .graph-panel-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .lifecycle-meta,
  .graph-tools {
    justify-content: flex-start;
  }

  .filter-form,
  .advanced-filter-grid {
    grid-template-columns: 1fr;
  }

  .field input,
  .field select {
    font-size: 16px;
  }

  .field,
  .wide-field,
  .advanced-filter,
  .filter-actions {
    grid-column: auto;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filter-actions .flow-btn.primary {
    grid-column: span 2;
  }

  .graph-frame,
  .cy-graph,
  .graph-guide,
  .timeline-fallback {
    min-height: 520px;
    height: 520px;
  }
}
