:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #fbfcfc;
  --panel-strong: #f5f8f7;
  --text: #17202a;
  --muted: #667180;
  --quiet: #8a95a3;
  --border: #dce4e2;
  --border-strong: #c8d4d1;
  --teal: #00746d;
  --teal-strong: #005f5a;
  --teal-soft: #e4f5f2;
  --green: #087f37;
  --amber: #f47b20;
  --coral: #d94834;
  --shadow: 0 18px 42px rgba(31, 42, 52, 0.09);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100vh;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
}

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

button {
  font: inherit;
  border: 0;
}

.site-shell {
  min-height: 100vh;
  overflow-x: hidden;
  background: #fff;
}

.app-shell {
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 324px minmax(0, 1fr) 324px;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  background: #fff;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-width: 0;
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
}

.brand-block,
.topbar-actions,
.metric-row {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--teal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 13px;
  font-weight: 850;
}

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

.brand-block strong {
  display: block;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: 0;
}

.brand-block span span,
.topbar-title span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.topbar-title {
  min-width: 0;
  flex: 1;
}

.topbar-title h1 {
  color: var(--text);
  font-size: 15px;
  line-height: 1.2;
}

.topbar-actions {
  gap: 12px;
}

.topbar-actions a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

.run-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--quiet);
}

.is-ready .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(18, 166, 74, 0.12);
}

.panel {
  min-width: 0;
  padding: 14px 18px;
  background: var(--panel);
}

.control-panel {
  grid-column: 1;
  grid-row: 2;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.metrics-panel {
  grid-column: 3;
  grid-row: 2;
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.field-group,
.metrics-section {
  padding-bottom: 17px;
  margin-bottom: 17px;
  border-bottom: 1px solid var(--border);
}

.field-group:last-child,
.metrics-section:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

label,
.metrics-section h2 {
  display: block;
  margin-bottom: 8px;
  color: #263241;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
}

.field-group p,
.insight-copy {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tab-stack {
  display: grid;
  gap: 7px;
}

.tab-stack button,
.segment,
.community-filter button {
  min-height: 38px;
  padding: 0 12px;
  color: #243143;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
}

.tab-stack button {
  text-align: left;
}

.tab-stack button.active,
.tab-stack button.is-active,
.segment.is-active,
.community-filter button.is-active {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(0, 139, 131, 0.16);
}

.segmented,
.community-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.visual-panel {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  background:
    linear-gradient(90deg, rgba(219, 228, 226, 0.45) 1px, transparent 1px),
    linear-gradient(180deg, rgba(219, 228, 226, 0.45) 1px, transparent 1px),
    #fff;
  background-size: 48px 48px;
}

.canvas-toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 18px;
}

.canvas-toolbar h2 {
  color: var(--text);
  font-size: 18px;
  line-height: 1.15;
}

.canvas-toolbar span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
}

.view-controls {
  display: flex;
  gap: 10px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.main-figure {
  min-width: 0;
  min-height: 0;
  display: grid;
  margin: 0 18px 18px;
  padding: 18px;
  border: 1px solid rgba(220, 228, 226, 0.78);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.network-explorer,
.network-stage,
.main-chart {
  width: 100%;
  min-width: 0;
  min-height: 0;
}

.network-stage {
  position: relative;
  height: 100%;
  min-height: 430px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(219, 228, 226, 0.62) 1px, transparent 1px),
    linear-gradient(90deg, rgba(219, 228, 226, 0.62) 1px, transparent 1px),
    #fff;
  background-size: 36px 36px;
}

.network-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 430px;
}

.network-edge {
  stroke: #aeb8c5;
  stroke-opacity: 0.42;
  stroke-width: 1.1;
  transition: stroke-opacity 140ms ease, stroke-width 140ms ease;
}

.network-node {
  cursor: pointer;
  stroke: #fff;
  stroke-width: 2;
  transition: opacity 140ms ease, r 140ms ease, stroke-width 140ms ease;
}

.network-node.is-dim,
.network-edge.is-dim {
  opacity: 0.16;
}

.network-node.is-active {
  stroke: #10151d;
  stroke-width: 3;
}

.network-label {
  fill: #10151d;
  font-size: 12px;
  font-weight: 850;
  pointer-events: none;
}

.node-tooltip {
  position: absolute;
  min-width: 210px;
  padding: 12px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
  pointer-events: none;
}

.node-tooltip strong {
  display: block;
  margin-bottom: 5px;
  font-size: 15px;
}

.node-tooltip span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 5px;
  margin-top: 5px;
  border-top: 1px solid var(--border);
}

.main-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.main-chart {
  align-self: stretch;
  display: grid;
  align-content: center;
  padding: 12px 22px;
}

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

.metrics-section h3 {
  color: var(--text);
  font-size: 20px;
  line-height: 1.16;
}

.stat-list {
  margin: 0;
  border-top: 1px solid var(--border);
}

.stat-list div {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.stat-list dt {
  color: var(--muted);
  font-size: 15px;
}

.stat-list dd {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 850;
  text-align: right;
}

.run-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  color: var(--teal-strong);
  font-size: 13px;
  line-height: 1.35;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--teal-soft);
}

.run-status {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(0, 116, 109, 0.12);
}

.run-card span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.insight-bar {
  grid-column: 1 / -1;
  grid-row: 3;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(220px, 430px);
  gap: 22px;
  align-items: center;
  padding: 20px 34px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.insight-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  color: var(--teal);
  border: 2px solid var(--teal);
  border-radius: 50%;
  background: var(--teal-soft);
  font-size: 22px;
  font-weight: 800;
}

.insight-bar h2 {
  margin-bottom: 7px;
  font-size: 18px;
}

.insight-bar p,
.tip span {
  color: #334155;
  font-size: 15px;
  line-height: 1.45;
}

.tip {
  min-width: 0;
  padding-left: 22px;
  border-left: 1px solid var(--border);
}

.tip strong {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
  text-transform: uppercase;
}

.chart-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.chart-svg {
  display: block;
  width: 100%;
  height: min(58vh, 460px);
  overflow: visible;
}

.chart-svg.is-large {
  height: min(66vh, 560px);
  max-height: 100%;
}

.chart-grid-line {
  stroke: #dfe5eb;
  stroke-dasharray: 3 4;
  stroke-width: 1;
}

.chart-bar {
  filter: drop-shadow(0 5px 8px rgba(0, 116, 109, 0.08));
  outline: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.chart-bar:hover,
.chart-bar:focus {
  opacity: 0.82;
  transform: translateY(-1px);
}

.chart-axis-text,
.chart-value-text {
  fill: #596473;
  font-size: 13px;
  font-weight: 700;
}

.chart-value-text {
  fill: #10151d;
  font-weight: 850;
}

.chart-caption {
  margin: 8px 0 0;
  padding: 9px 10px;
  color: var(--teal-strong);
  font-size: 13px;
  line-height: 1.35;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--teal-soft);
}

button:focus-visible,
a:focus-visible,
.network-node:focus {
  outline: 3px solid rgba(0, 139, 131, 0.2);
  outline-offset: 2px;
}

.primary-panel.is-expanded {
  grid-column: 1 / -1;
  z-index: 2;
}

.primary-panel.is-expanded .network-stage {
  min-height: 580px;
}

@media (max-width: 1120px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    grid-template-columns: 292px minmax(0, 1fr);
    grid-template-rows: 64px minmax(560px, auto) auto auto;
  }

  .metrics-panel {
    grid-column: 1 / -1;
    grid-row: 3;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .metrics-section {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .insight-bar {
    grid-row: 4;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px 14px;
    min-height: 64px;
  }

  .topbar-title,
  .run-state {
    display: none;
  }

  .control-panel,
  .metrics-panel {
    width: 100%;
    max-width: 100%;
    border: 0;
    border-bottom: 1px solid var(--border);
  }

  .visual-panel {
    width: 100%;
    max-width: 100%;
    min-height: 560px;
  }

  .canvas-toolbar {
    align-items: flex-start;
  }

  .main-figure {
    min-height: 470px;
    margin: 0 12px 14px;
  }

  .network-stage,
  .network-svg {
    min-height: 430px;
  }

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

  .insight-bar {
    grid-template-columns: 1fr;
    padding: 22px 18px;
  }

  .tip {
    padding-left: 0;
    padding-top: 16px;
    border-left: 0;
    border-top: 1px solid var(--border);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
