:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: #ffffff;
  --line: rgba(31, 42, 55, 0.1);
  --line-strong: rgba(31, 42, 55, 0.18);
  --text: #111827;
  --muted: #6b7280;
  --blue: #3a6ea5;
  --cyan: #2ca9b7;
  --green: #2f7d63;
  --amber: #a36d20;
  --red: #9b6a63;
  --ink: #1f2937;
  --ink-soft: #334155;
  --champagne: #d8c7a1;
  --shadow: 0 18px 46px rgba(31, 42, 55, 0.08);
  --shadow-strong: 0 28px 80px rgba(31, 42, 55, 0.12);
  --radius: 8px;
  --font-main: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  font-family: var(--font-main);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(253,254,255,0.99) 0, rgba(243,247,251,0.96) 360px, var(--bg) 100%),
    radial-gradient(circle at 84% 0, rgba(216, 199, 161, 0.16), transparent 30%),
    repeating-linear-gradient(90deg, rgba(31,42,55,0.026) 0 1px, transparent 1px 82px),
    repeating-linear-gradient(0deg, rgba(31,42,55,0.018) 0 1px, transparent 1px 64px);
  color: var(--text);
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 76% 12%, rgba(255,255,255,0.9), transparent 24%),
    url("assets/bioprocess-plant-background.svg") no-repeat right 88px top 120px / min(1120px, 86vw) auto;
  opacity: 0.13;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.factory-unit:focus-visible,
.stream-label:focus-visible {
  outline: 2px solid rgba(58, 110, 165, 0.72);
  outline-offset: 3px;
}

select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 34px 0 12px;
  background:
    linear-gradient(135deg, transparent 50%, var(--muted) 50%) right 14px center / 7px 7px no-repeat,
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(247,250,252,0.92));
  color: var(--text);
  appearance: none;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.control-panel,
.panel,
.metric,
.hero-surface,
.topbar {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.control-panel {
  position: sticky;
  top: 18px;
  align-self: start;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 20px;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(249,251,253,0.92)),
    repeating-linear-gradient(90deg, rgba(31,42,55,0.02) 0 1px, transparent 1px 52px);
}

.control-panel::-webkit-scrollbar {
  width: 8px;
}

.control-panel::-webkit-scrollbar-thumb {
  background: rgba(22, 22, 26, 0.16);
  border-radius: 8px;
}

.workspace {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.site-attribution {
  position: relative;
  z-index: 1;
  display: block;
  width: calc(100% - 36px);
  margin: -6px 18px 12px auto;
  padding: 0 4px;
  color: rgba(102, 112, 133, 0.24);
  filter: blur(0.28px);
  font-size: 9px;
  line-height: 1.2;
  font-weight: 450;
  letter-spacing: 0;
  text-align: right;
  user-select: none;
}

.topbar {
  position: relative;
  top: auto;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(247,251,253,0.9)),
    repeating-linear-gradient(90deg, rgba(16,24,32,0.024) 0 1px, transparent 1px 54px);
  box-shadow: 0 18px 46px rgba(17, 24, 31, 0.075), inset 0 1px 0 rgba(255,255,255,0.84);
}

.topbar h2,
.panel-title h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  font-weight: 700;
}

.panel-title h1 {
  max-width: 210px;
  font-size: 23px;
  line-height: 1.12;
}

.brand-lockup {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: linear-gradient(180deg, #526a86, #334155);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18), 0 14px 28px rgba(31,42,55,0.13);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.view-tabs {
  position: relative;
  top: auto;
  z-index: 19;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 36px rgba(20, 20, 30, 0.08);
  backdrop-filter: blur(24px);
}

.view-tab {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}

.view-tab.active {
  background: linear-gradient(180deg, #ffffff, #eef4f8);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(58, 110, 165, 0.52), 0 8px 18px rgba(58, 110, 165, 0.12);
}

.view-panel:not(.active) {
  display: none !important;
}

.view-panel {
  scroll-margin-top: 76px;
}

.metric-grid.view-panel.active,
.hero-surface.view-panel.active,
.analysis-grid.view-panel.active,
.bottom-grid.view-panel.active {
  display: grid;
}

.factory-control.view-panel.active,
.reference-values.view-panel.active,
.export-center.view-panel.active,
.reference-panel.view-panel.active {
  display: block;
}

.primary-button,
.secondary-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 16px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.preset-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  background: linear-gradient(180deg, #526a86, #334155);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 12px 28px rgba(31, 42, 55, 0.16);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.factory-control {
  min-height: 640px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(244,248,251,0.9)),
    repeating-linear-gradient(90deg, rgba(20,28,36,0.028) 0 1px, transparent 1px 54px);
  box-shadow: var(--shadow-strong);
}

.factory-control .panel-heading h2 {
  margin-top: 2px;
}

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

.plant-insight-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.plant-insight-card {
  min-width: 0;
  min-height: 96px;
  padding: 12px;
  border: 1px solid rgba(13, 23, 33, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(245,249,252,0.86));
  box-shadow: 0 12px 30px rgba(17, 24, 31, 0.055);
}

.plant-insight-card::before {
  content: "";
  display: block;
  width: 34px;
  height: 3px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: var(--blue);
}

.plant-insight-card.watch::before {
  background: var(--amber);
}

.plant-insight-card.critical::before {
  background: var(--red);
}

.plant-insight-card span,
.plant-insight-card small {
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.plant-insight-card strong {
  display: block;
  margin: 4px 0;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 20px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.plant-insight-card small {
  font-size: 11px;
  font-weight: 560;
  line-height: 1.3;
  text-transform: none;
}

.factory-map {
  position: relative;
  min-height: 640px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255,255,255,0.92), rgba(234,238,243,0.84)),
    repeating-linear-gradient(0deg, rgba(23,23,28,0.035) 0 1px, transparent 1px 38px),
    repeating-linear-gradient(90deg, rgba(23,23,28,0.03) 0 1px, transparent 1px 52px);
  overflow: auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.72);
}

.factory-map::-webkit-scrollbar {
  height: 9px;
  width: 9px;
}

.factory-map::-webkit-scrollbar-thumb {
  border: 2px solid rgba(255,255,255,0.75);
  border-radius: 999px;
  background: rgba(16,24,32,0.22);
}

.factory-svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 640px;
}

.factory-svg.detailed {
  aspect-ratio: 1400 / 920;
  min-width: 0;
  min-height: 700px;
}

.factory-floor {
  fill: rgba(255, 255, 255, 0.58);
  stroke: rgba(23, 23, 28, 0.1);
}

.factory-zone {
  fill: rgba(255, 255, 255, 0.34);
  stroke: rgba(13, 23, 33, 0.08);
}

.factory-pipe {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.factory-pipe.main {
  stroke: url(#pipeFlow);
  stroke-width: 16;
  opacity: 0.36;
}

.factory-pipe.return {
  stroke: rgba(23, 23, 28, 0.16);
  stroke-width: 10;
}

.factory-pipe.waste-line {
  stroke: rgba(155, 106, 99, 0.24);
  stroke-width: 8;
  stroke-dasharray: 10 10;
}

.factory-pipe.utility-line {
  stroke: rgba(58, 110, 165, 0.22);
  stroke-width: 6;
  stroke-dasharray: 14 10;
}

.factory-zone-label {
  fill: rgba(23, 23, 28, 0.58);
  font-size: 15px;
  font-weight: 780;
  text-transform: uppercase;
}

.factory-unit {
  cursor: pointer;
  outline: none;
}

.factory-unit.detail .unit-card {
  fill: rgba(255, 255, 255, 0.96);
}

.unit-card {
  fill: rgba(255, 255, 255, 0.96);
  stroke: rgba(23, 23, 28, 0.14);
  filter: url(#softShadow);
}

.unit-platform {
  fill: rgba(23, 23, 28, 0.08);
}

.factory-unit:hover .unit-card,
.factory-unit.selected .unit-card {
  stroke: var(--unit-color);
  stroke-width: 2;
}

.factory-unit.active .unit-card {
  stroke: var(--blue);
  stroke-width: 2;
}

.factory-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--unit-color) 86%, white), var(--unit-color));
  color: white;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.24), 0 8px 18px rgba(16,24,32,0.12);
}

.factory-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.factory-icon.compact {
  width: 38px;
  height: 38px;
  border-radius: 7px;
}

.factory-icon.compact svg {
  width: 21px;
  height: 21px;
}

.unit-title {
  fill: #111827;
  font-size: 14px;
  font-weight: 750;
}

.unit-title.compact {
  font-size: 15px;
  font-weight: 800;
}

.unit-badge {
  fill: rgba(23, 23, 28, 0.55);
  font-size: 11px;
}

.unit-badge.compact {
  font-size: 12px;
}

.stream-path {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.62;
  cursor: pointer;
  stroke-dasharray: 16 10;
  stroke-dashoffset: 0;
  animation: streamFlow 1.8s linear infinite;
}

.stream-path.media {
  stroke: var(--blue);
}

.stream-path.cells {
  stroke: var(--green);
}

.stream-path.energy {
  stroke: var(--amber);
  stroke-dasharray: 9 8;
  animation-duration: 1.25s;
}

.stream-path.utility {
  stroke: #7b79b8;
  stroke-dasharray: 10 8;
  animation-duration: 1.45s;
}

.stream-path.waste {
  stroke: var(--red);
  stroke-dasharray: 8 7;
  animation-duration: 1.1s;
}

.stream-path.product {
  stroke: #1d8f83;
  stroke-dasharray: 18 8;
}

.stream-path:hover,
.stream-path.selected {
  opacity: 1;
  stroke-width: 8;
}

.stream-path.legend-line,
.stream-path.legend-line:hover {
  stroke-width: 5;
  opacity: 0.78;
  pointer-events: none;
  animation: none;
}

@keyframes streamFlow {
  to {
    stroke-dashoffset: -52;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stream-path {
    animation: none;
  }
}

.factory-legend rect {
  fill: rgba(255, 255, 255, 0.88);
  stroke: rgba(23, 23, 28, 0.12);
}

.factory-legend text {
  fill: #111827;
  font-size: 10px;
  font-weight: 650;
}

.factory-legend .legend-title {
  font-size: 12px;
  font-weight: 800;
}

.stream-label {
  cursor: pointer;
}

.stream-label rect {
  fill: rgba(15, 22, 30, 0.9);
  stroke: rgba(255, 255, 255, 0.52);
}

.stream-label.selected rect,
.stream-label:hover rect {
  fill: #ffffff;
  stroke: var(--blue);
  stroke-width: 2;
}

.stream-label text {
  fill: #ffffff;
  font-size: 13px;
  font-weight: 820;
}

.stream-label.selected text,
.stream-label:hover text {
  fill: #111827;
}

.stream-popover {
  fill: rgba(255, 255, 255, 0.96) !important;
  stroke: rgba(58, 110, 165, 0.34) !important;
}

.stream-popover-title,
.stream-popover-value {
  fill: #111827 !important;
  font-size: 10px !important;
  font-weight: 760 !important;
}

.stream-popover-value {
  fill: rgba(16, 20, 24, 0.62) !important;
  font-weight: 650 !important;
}

.active-pulse {
  fill: var(--blue);
  opacity: 0.92;
}

.factory-callout rect {
  fill: rgba(255, 255, 255, 0.86);
  stroke: rgba(23, 23, 28, 0.12);
}

.factory-callout text {
  fill: #111827;
  font-size: 13px;
  font-weight: 650;
}

.factory-callout.compact text {
  font-size: 12px;
}

.unit-inspector {
  min-height: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  overflow: auto;
  display: grid;
  grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.28fr);
  gap: 14px 18px;
  align-items: start;
}

.inspector-top {
  display: flex;
  align-items: center;
  gap: 12px;
  grid-column: 1;
  min-width: 0;
}

.inspector-top > div {
  min-width: 0;
}

.inspector-icon {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--unit-color);
  color: white;
}

.inspector-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.inspector-top span,
.unit-inspector p,
.unit-inspector h4,
.inspector-columns li span {
  color: var(--muted);
}

.unit-inspector p,
.inspector-actions {
  grid-column: 1;
}

.unit-inspector p {
  margin: 0;
}

.inspector-top h3 {
  margin: 2px 0 0;
  font-size: 21px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.inspector-value {
  display: block;
  margin: 12px 0;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.inspector-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.inspector-columns h4,
.unit-inspector h4 {
  margin: 14px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
}

.inspector-columns ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inspector-columns li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.unit-inspector code {
  display: block;
  margin-bottom: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(245, 245, 247, 0.88);
  overflow-wrap: anywhere;
  white-space: normal;
}

.inspector-section {
  min-width: 0;
  margin-top: 0;
}

.inspector-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inspector-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.inspector-list span {
  color: var(--muted);
}

.stream-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: currentColor;
}

.inspector-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.inspector-summary {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 8px;
  min-width: 0;
}

.inspector-mini {
  min-width: 0;
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 249, 251, 0.88);
}

.inspector-mini span,
.equation-preview span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.18;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.inspector-mini strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.equation-preview {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  min-width: 0;
}

.equation-preview span {
  grid-column: 1 / -1;
}

.equation-preview code {
  min-width: 0;
  margin: 0;
  padding: 9px;
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.32;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.reference-delta-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.reference-pill {
  min-height: 54px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.reference-pill span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.reference-pill strong,
.delta-status {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 750;
}

.reference-pill.near strong,
.delta-status.near {
  color: var(--green);
}

.reference-pill.offset strong,
.delta-status.offset {
  color: var(--amber);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  font-size: 12px;
  font-weight: 800;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 18px 0 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(245, 245, 247, 0.86);
}

.preset-button {
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.preset-button.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(20, 20, 30, 0.08);
}

.control-group {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.control-group:first-of-type {
  border-top: 0;
}

.control-group h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

label output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--blue);
}

.hero-surface {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  gap: 16px;
  min-height: 0;
  overflow: visible;
  padding: 20px;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(252,253,254,0.96) 0%, rgba(237,242,246,0.92) 100%),
    repeating-linear-gradient(0deg, rgba(20,28,36,0.03) 0 1px, transparent 1px 42px);
}

.hero-copy {
  grid-column: 1 / -1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.hero-copy h3 {
  margin: 0;
  font-size: 28px;
  line-height: 1.04;
}

.utility-rail {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.utility-pill {
  display: grid;
  gap: 2px;
  min-width: 92px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.utility-pill span {
  color: var(--muted);
  font-size: 11px;
}

.utility-pill strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.process-stage {
  position: relative;
  display: grid;
  gap: 14px;
  align-self: stretch;
  min-height: 310px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
  overflow: hidden;
}

.process-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 10%, rgba(58, 110, 165, 0.07) 10% 10.4%, transparent 10.4% 50%, rgba(47, 125, 99, 0.07) 50% 50.4%, transparent 50.4% 100%),
    repeating-linear-gradient(0deg, rgba(23, 23, 28, 0.045) 0 1px, transparent 1px 52px),
    repeating-linear-gradient(90deg, rgba(23, 23, 28, 0.035) 0 1px, transparent 1px 70px);
  pointer-events: none;
}

.process-stage::after {
  display: none;
}

.diagram-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 12px;
  min-height: 0;
  z-index: 1;
}

.process-node {
  position: relative;
  min-height: 108px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 32px rgba(20, 20, 30, 0.08);
  display: grid;
  gap: 8px;
  align-content: space-between;
  transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.process-node::before {
  content: "";
  position: absolute;
  inset: -1px auto -1px -1px;
  width: 4px;
  border-radius: 8px 0 0 8px;
  background: var(--node-color, var(--blue));
}

.process-node.active {
  transform: translateY(-3px);
  border-color: rgba(58, 110, 165, 0.48);
  box-shadow: 0 18px 42px rgba(58, 110, 165, 0.14);
}

.process-node.waste {
  border-style: dashed;
}

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

.node-index {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--node-color, var(--blue));
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.node-index svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.process-node h4 {
  margin: 8px 0 4px;
  font-size: 15px;
}

.process-node p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.node-value {
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.node-equation {
  display: none;
  min-height: 34px;
  padding: 7px 8px;
  border: 1px solid rgba(22, 22, 26, 0.08);
  border-radius: 7px;
  background: rgba(245, 245, 247, 0.86);
  color: #3a3d46;
  font-size: 10.5px;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
}

.node-export {
  display: none;
  justify-self: start;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.node-export:hover {
  border-color: rgba(58, 110, 165, 0.38);
  background: rgba(58, 110, 165, 0.08);
}

.node-arrow {
  display: none;
  position: absolute;
  right: -28px;
  top: 54px;
  width: 28px;
  height: 2px;
  background: var(--line-strong);
}

.node-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -4px;
  border-left: 7px solid var(--line-strong);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.process-node.break .node-arrow {
  display: none;
}

.side-stream {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.stream-chip {
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.76);
}

.stream-chip span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stream-chip strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.plant-preview {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-column: 1 / -1;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
  overflow: hidden;
}

.plant-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 30%),
    repeating-linear-gradient(90deg, rgba(23, 23, 28, 0.035) 0 1px, transparent 1px 54px);
  pointer-events: none;
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 0;
  color: var(--muted);
  font-size: 12px;
}

.preview-heading strong {
  color: var(--text);
  font-size: 13px;
}

#processCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 500px;
}

.time-strip {
  grid-column: 1 / -1;
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(18px);
}

.time-strip label {
  margin: 0;
}

.time-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.time-meta strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

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

.metric {
  min-height: 82px;
  padding: 14px;
  border-radius: var(--radius);
  display: grid;
  align-content: space-between;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(246,250,252,0.84));
  box-shadow: 0 12px 30px rgba(17,24,31,0.06);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric strong {
  font-size: 22px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

.bottom-grid {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
}

.panel {
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 17px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

#timelineCanvas {
  width: 100%;
  height: 320px;
  display: block;
}

.timeline-metric-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.timeline-metric-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.timeline-metric-controls input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--text);
}

.timeline-metric-controls label:has(input:checked) {
  border-color: rgba(31, 42, 55, 0.26);
  background: #1f2937;
  color: #fff;
}

.time-balance-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.time-balance-strip div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.88), rgba(246,250,252,0.78));
}

.time-balance-strip span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.time-balance-strip strong {
  display: block;
  margin-top: 5px;
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.time-balance-strip .total {
  border-color: rgba(58, 110, 165, 0.28);
  background: linear-gradient(180deg, rgba(238,245,251,0.96), rgba(248,251,253,0.9));
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th:first-child,
td:first-child {
  text-align: left;
  color: var(--muted);
}

.equation-list,
.stage-list {
  display: grid;
  gap: 10px;
}

.equation {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.equation code {
  display: block;
  margin-top: 6px;
  color: #24262d;
  white-space: normal;
  overflow-wrap: anywhere;
}

.stage-card {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.stage-card strong {
  font-size: 14px;
}

.stage-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.stage-chip {
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 12px;
  font-weight: 600;
}

.stage-value {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.export-center {
  padding: 18px;
}

.download-scenario {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.84), rgba(246,249,252,0.76)),
    repeating-linear-gradient(90deg, rgba(16,24,32,0.025) 0 1px, transparent 1px 42px);
}

.download-scenario label {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 260px);
  align-items: center;
  gap: 12px;
  margin: 0;
}

.download-scenario span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.download-scenario select {
  grid-column: auto;
  width: 100%;
}

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

.download-summary article {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(247, 249, 251, 0.86);
}

.download-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.download-summary strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

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

.step-export-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px 10px;
  align-items: center;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.step-export-card:hover {
  border-color: var(--unit-color);
  box-shadow: 0 10px 28px rgba(20, 20, 30, 0.08);
}

.step-export-card span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--unit-color);
  color: white;
  grid-row: span 2;
}

.step-export-card span svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.step-export-card strong {
  font-size: 13px;
}

.step-export-card small {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.reference-panel {
  overflow: hidden;
}

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

.reference-tile {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 4px 10px;
  align-items: center;
  min-width: 0;
  min-height: 64px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.86), rgba(246,250,252,0.78));
  color: var(--text);
  text-decoration: none;
}

.reference-tile:hover {
  border-color: rgba(58, 110, 165, 0.28);
  box-shadow: 0 10px 26px rgba(17, 24, 31, 0.08);
}

.reference-tile.reference-paper {
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(239,246,249,0.88));
  border-color: rgba(58, 110, 165, 0.2);
}

.reference-tile span {
  grid-row: span 2;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(180deg, #526a86, #334155);
  color: #fff;
}

.reference-tile strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-tile small {
  color: var(--muted);
  font-size: 11px;
}

.context-menu {
  position: fixed;
  z-index: 40;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 46px rgba(20, 20, 30, 0.18);
  backdrop-filter: blur(24px);
}

.context-menu button {
  display: block;
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.context-menu button:hover {
  background: rgba(58, 110, 165, 0.1);
}

.hover-tooltip {
  position: fixed;
  z-index: 80;
  display: grid;
  gap: 7px;
  width: min(360px, calc(100vw - 28px));
  padding: 12px;
  border: 1px solid rgba(13, 23, 33, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(244,249,252,0.94));
  box-shadow: 0 24px 70px rgba(13, 23, 33, 0.18);
  color: var(--text);
  pointer-events: none;
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.hover-tooltip[hidden] {
  display: none;
}

.hover-tooltip strong {
  font-size: 13px;
  line-height: 1.25;
}

.hover-tooltip span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.hover-tooltip small {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.export-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(58, 110, 165, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 46px rgba(20, 20, 30, 0.18);
  color: var(--text);
  font-size: 13px;
  backdrop-filter: blur(24px);
}

.download-shelf {
  position: fixed;
  right: 18px;
  bottom: 72px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(620px, calc(100vw - 36px));
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 18px 54px rgba(20, 20, 30, 0.16);
  backdrop-filter: blur(24px);
}

.download-shelf[hidden] {
  display: none;
}

.download-shelf div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.download-shelf span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.download-shelf strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-shelf a,
.download-shelf button {
  min-height: 32px;
  padding: 7px 10px;
  border-radius: 7px;
  text-decoration: none;
  white-space: nowrap;
}

.download-shelf .shelf-close {
  width: 32px;
  padding: 0;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: relative;
    top: 0;
    max-height: none;
    order: 2;
  }

  .workspace {
    order: 1;
  }

  .analysis-grid,
  .bottom-grid,
  .metric-grid,
  .reference-grid,
  .reference-delta-strip,
  .step-export-list,
  .download-summary {
    grid-template-columns: 1fr;
  }

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

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

  .hero-surface {
    grid-template-columns: 1fr;
  }

  .factory-svg.detailed {
    min-width: 1040px;
  }

  .factory-layout {
    grid-template-columns: 1fr;
  }

  .unit-inspector {
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .inspector-summary,
  .equation-preview,
  .unit-inspector p,
  .inspector-actions,
  .inspector-top {
    grid-column: 1;
  }

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

  .equation-preview {
    grid-template-columns: 1fr;
  }

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

  .plant-preview {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .view-tabs {
    grid-template-columns: repeat(4, minmax(72px, 1fr));
    overflow-x: auto;
  }

  .topbar h2,
  .panel-title h1 {
    font-size: 24px;
  }

  .stage-card {
    grid-template-columns: 1fr;
  }

  #processCanvas {
    min-height: 360px;
  }

  .hero-surface {
    padding: 12px;
  }

  .hero-copy {
    display: grid;
  }

  .hero-copy h3 {
    font-size: 22px;
  }

  .process-stage {
    padding: 12px;
    min-height: 0;
  }

  .factory-control {
    min-height: 0;
    padding: 12px;
  }

  .factory-map,
  .factory-svg {
    min-height: 560px;
  }

  .factory-svg.detailed {
    min-width: 920px;
  }

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

  .diagram-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

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

  .inspector-summary {
    grid-template-columns: 1fr;
  }

  .download-scenario label {
    grid-template-columns: 1fr;
  }

  .process-node {
    min-height: 98px;
  }

  .node-arrow {
    display: none;
  }

  .side-stream {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    margin-top: 12px;
    grid-template-columns: 1fr;
  }

  .time-meta {
    display: grid;
  }

  .time-meta strong {
    white-space: normal;
  }
}
