:root {
  color-scheme: dark;
  --bg: #0b1014;
  --bg-2: #101820;
  --surface: #151b22;
  --surface-2: #1b232c;
  --surface-3: #222d37;
  --line: #32404d;
  --line-soft: rgba(173, 190, 210, 0.18);
  --text: #f3f7fb;
  --muted: #9fb0bf;
  --blue: #48a7ff;
  --cyan: #7dd3fc;
  --green: #30d158;
  --yellow: #f4c542;
  --orange: #ff9f0a;
  --red: #ff453a;
  --magenta: #ff5db1;
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(11, 16, 20, 0.96), rgba(11, 16, 20, 1)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 96px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 96px);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 24px 12px 112px;
  background: rgba(11, 16, 20, 0.92);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 240px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(72, 167, 255, 0.55);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(72, 167, 255, 0.22), rgba(255, 93, 177, 0.14));
  color: var(--text);
  font-family: var(--mono);
  font-weight: 800;
}

.brand-block h1,
.brand-block p,
.section-heading h2,
.section-heading p,
.panel-heading h3,
.panel-heading p,
.risk-summary,
.approval-readout h3,
.approval-readout p {
  margin: 0;
}

.brand-block h1 {
  font-size: 1.08rem;
  line-height: 1.2;
}

.brand-block p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
}

.topbar-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.field span,
.eyebrow {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field select {
  min-height: 38px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 32px 0 10px;
}

.field.compact select {
  width: 230px;
}

.field.tiny select {
  width: 84px;
}

.tool-button,
.rail-button,
.ghost-action,
.primary-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.tool-button {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 800;
}

.tool-button:hover,
.rail-button:hover,
.ghost-action:hover {
  border-color: var(--blue);
}

.side-rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 88px;
  padding: 86px 12px 12px;
  background: rgba(15, 24, 32, 0.94);
  border-right: 1px solid var(--line-soft);
  backdrop-filter: blur(18px);
}

.rail-button {
  display: grid;
  justify-items: center;
  gap: 6px;
  width: 100%;
  min-height: 70px;
  margin-bottom: 10px;
  border-radius: 8px;
  color: var(--muted);
}

.rail-button.active {
  color: var(--text);
  border-color: rgba(72, 167, 255, 0.62);
  background: rgba(72, 167, 255, 0.14);
}

.rail-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--mono);
  font-weight: 800;
}

.rail-button span:last-child {
  font-size: 0.72rem;
  font-weight: 700;
}

.workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px 24px 48px 112px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.status-strip,
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.status-strip h2,
.section-heading h2 {
  margin: 4px 0 0;
  font-size: 1.45rem;
  line-height: 1.2;
}

.scrubber-block {
  display: grid;
  grid-template-columns: auto minmax(180px, 320px);
  align-items: center;
  gap: 12px;
  min-width: 320px;
}

input[type="range"] {
  accent-color: var(--blue);
}

.data-value,
.data-pill {
  font-family: var(--mono);
  color: var(--cyan);
}

.data-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid rgba(125, 211, 252, 0.3);
  border-radius: 999px;
  background: rgba(125, 211, 252, 0.08);
  font-size: 0.72rem;
}

.panel {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(27, 35, 44, 0.94), rgba(18, 25, 32, 0.96));
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.panel-heading h3 {
  margin-top: 4px;
  font-size: 1rem;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(350px, 0.95fr);
  gap: 16px;
}

.map-panel,
.risk-panel,
.trend-panel,
.audit-panel,
.causal-panel,
.factors-panel,
.barrier-panel,
.interventions-panel,
.approval-panel,
.metrics-panel,
.evaluation-summary {
  min-width: 0;
}

#plantMap {
  display: block;
  width: 100%;
  height: auto;
  min-height: 420px;
  padding: 10px;
}

.map-floor {
  fill: #0f171f;
  stroke: #2a3642;
}

.route-line {
  fill: none;
  stroke: rgba(125, 211, 252, 0.72);
  stroke-width: 4;
  stroke-dasharray: 9 8;
}

.zone rect {
  fill: #17212b;
  stroke: #394957;
  stroke-width: 2;
}

.zone text {
  fill: var(--text);
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 800;
}

.zone .zone-sub {
  fill: var(--muted);
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 600;
}

.zone.safe rect {
  fill: rgba(48, 209, 88, 0.1);
  stroke: rgba(48, 209, 88, 0.52);
}

.zone.watch rect {
  fill: rgba(244, 197, 66, 0.14);
  stroke: rgba(244, 197, 66, 0.72);
}

.zone.warning rect,
.zone.high rect {
  fill: rgba(255, 159, 10, 0.16);
  stroke: rgba(255, 159, 10, 0.78);
}

.zone.critical rect {
  fill: rgba(255, 69, 58, 0.16);
  stroke: rgba(255, 69, 58, 0.88);
}

.zone.muster rect {
  fill: rgba(125, 211, 252, 0.1);
  stroke: rgba(125, 211, 252, 0.5);
}

.hazard-plume {
  transform-origin: center;
  opacity: 0.72;
  transition: all 260ms ease;
}

.hazard-plume.safe {
  fill: rgba(48, 209, 88, 0.08);
  stroke: rgba(48, 209, 88, 0.34);
}

.hazard-plume.watch,
.hazard-plume.warning,
.hazard-plume.high {
  fill: rgba(255, 159, 10, 0.2);
  stroke: rgba(255, 159, 10, 0.72);
}

.hazard-plume.critical {
  fill: rgba(255, 69, 58, 0.25);
  stroke: rgba(255, 69, 58, 0.86);
}

.worker {
  display: none;
}

.worker.visible {
  display: block;
}

.worker circle {
  fill: #f3f7fb;
  stroke: #111820;
  stroke-width: 4;
}

.worker text {
  fill: #0b1014;
  text-anchor: middle;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 900;
}

.permit-marker {
  display: none;
}

.permit-marker.visible {
  display: block;
}

.permit-marker rect {
  fill: rgba(255, 159, 10, 0.95);
}

.permit-marker text {
  fill: #17120a;
  text-anchor: middle;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 900;
}

.vent-marker circle {
  fill: rgba(48, 209, 88, 0.16);
  stroke: rgba(48, 209, 88, 0.72);
  stroke-width: 3;
}

.vent-marker path {
  stroke: var(--text);
  stroke-width: 4;
  stroke-linecap: round;
}

.vent-marker.degraded circle {
  fill: rgba(255, 159, 10, 0.16);
  stroke: rgba(255, 159, 10, 0.82);
}

.vent-marker.failed circle {
  fill: rgba(255, 69, 58, 0.18);
  stroke: rgba(255, 69, 58, 0.9);
}

.risk-panel {
  padding: 18px;
}

.risk-score-block {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
}

.risk-score {
  font-family: var(--mono);
  font-size: 4.5rem;
  font-weight: 900;
  line-height: 1;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 900;
}

.status-badge.safe {
  color: var(--green);
  background: rgba(48, 209, 88, 0.08);
}

.status-badge.watch {
  color: var(--yellow);
  background: rgba(244, 197, 66, 0.08);
}

.status-badge.warning,
.status-badge.high {
  color: var(--orange);
  background: rgba(255, 159, 10, 0.09);
}

.status-badge.critical {
  color: var(--red);
  background: rgba(255, 69, 58, 0.11);
}

.meter {
  height: 12px;
  overflow: hidden;
  background: #0c1218;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange), var(--red));
  transition: width 240ms ease;
}

.risk-summary {
  margin-top: 12px;
  min-height: 44px;
  color: var(--muted);
  line-height: 1.45;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.comparison-card {
  min-height: 126px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.comparison-card.accent {
  border-color: rgba(72, 167, 255, 0.36);
  background: rgba(72, 167, 255, 0.08);
}

.comparison-card strong {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 1.2rem;
}

.comparison-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

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

.sensor-grid div {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(11, 16, 20, 0.46);
}

.sensor-grid strong {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 1.02rem;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(330px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.trend-chart {
  display: block;
  width: 100%;
  min-height: 240px;
  padding: 10px;
}

.grid-lines line {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1;
}

.trend-chart text {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.gas-line,
.risk-line {
  fill: none;
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.gas-line {
  stroke: var(--cyan);
}

.risk-line {
  stroke: var(--red);
}

.timeline {
  display: grid;
  gap: 10px;
  max-height: 267px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  list-style: none;
}

.timeline li {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.timeline time {
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.timeline strong {
  display: block;
  font-size: 0.88rem;
}

.timeline span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.explain-grid,
.simulate-grid,
.evaluation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(350px, 0.8fr);
  gap: 16px;
}

#causalGraph {
  display: block;
  width: 100%;
  min-height: 390px;
  padding: 14px;
}

.causal-edge path {
  fill: none;
  stroke: rgba(159, 176, 191, 0.34);
  stroke-width: 5;
  stroke-linecap: round;
}

.causal-edge.active path {
  stroke: rgba(72, 167, 255, 0.78);
}

.causal-node rect {
  fill: rgba(21, 27, 34, 0.98);
  stroke: #40515f;
  stroke-width: 2;
}

.causal-node.active rect {
  fill: rgba(255, 159, 10, 0.12);
  stroke: rgba(255, 159, 10, 0.78);
}

.causal-node.critical rect {
  fill: rgba(255, 69, 58, 0.14);
  stroke: rgba(255, 69, 58, 0.88);
}

.causal-node text {
  fill: var(--text);
  text-anchor: middle;
  font-size: 15px;
  font-weight: 800;
}

.causal-node .node-sub {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.contributor-list,
.barrier-list,
.intervention-grid {
  display: grid;
  gap: 10px;
  padding: 16px;
}

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

.contributor-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.9rem;
}

.contributor-top span:last-child {
  color: var(--cyan);
  font-family: var(--mono);
}

.bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #0d141a;
  border: 1px solid var(--line);
}

.bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--orange));
}

.barrier-panel {
  margin-top: 16px;
}

.barrier-list {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.barrier {
  min-height: 132px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.barrier strong {
  display: block;
  min-height: 40px;
}

.barrier span {
  display: inline-flex;
  margin-top: 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.barrier.healthy {
  border-color: rgba(48, 209, 88, 0.36);
}

.barrier.degraded {
  border-color: rgba(255, 159, 10, 0.42);
}

.barrier.failed {
  border-color: rgba(255, 69, 58, 0.48);
}

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

.workflow-step {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.035);
  font-weight: 800;
}

.workflow-step.active,
.workflow-step.done {
  color: var(--text);
  border-color: rgba(72, 167, 255, 0.58);
  background: rgba(72, 167, 255, 0.12);
}

.workflow-step.verified {
  border-color: rgba(48, 209, 88, 0.52);
  background: rgba(48, 209, 88, 0.1);
}

.intervention-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 96px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  text-align: left;
  color: var(--text);
}

.intervention-card.selected {
  border-color: rgba(72, 167, 255, 0.76);
  background: rgba(72, 167, 255, 0.11);
}

.intervention-card.recommended {
  border-color: rgba(48, 209, 88, 0.56);
}

.intervention-card h4,
.intervention-card p {
  margin: 0;
}

.intervention-card h4 {
  font-size: 0.98rem;
}

.intervention-card p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.residual-risk {
  display: grid;
  justify-items: end;
  gap: 4px;
  font-family: var(--mono);
}

.residual-risk strong {
  font-size: 1.45rem;
}

.approval-panel {
  padding: 18px;
}

.approval-readout h3 {
  margin-top: 6px;
  font-size: 1.2rem;
}

.approval-readout p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.before-after {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.before-after div {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.before-after strong {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 1.6rem;
}

.approval-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.primary-action,
.ghost-action {
  min-height: 46px;
  border-radius: 6px;
  font-weight: 900;
}

.primary-action {
  border-color: rgba(255, 69, 58, 0.7);
  background: linear-gradient(180deg, #d53d35, #9b251f);
}

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

.ghost-action {
  padding: 0 18px;
}

.verification-box {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(11, 16, 20, 0.46);
}

.verification-box p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.metrics-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.metrics-table th,
.metrics-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}

.metrics-table th {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metrics-table td {
  font-family: var(--mono);
}

.evaluation-summary {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.summary-number,
.sample-profile {
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
}

.summary-number strong {
  display: block;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 2rem;
}

.summary-number p,
.sample-profile p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.42;
}

@media (max-width: 1180px) {
  .control-grid,
  .lower-grid,
  .explain-grid,
  .simulate-grid,
  .evaluation-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .topbar {
    position: relative;
    padding: 14px 14px 12px;
    align-items: stretch;
    flex-direction: column;
  }

  .side-rail {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .rail-button {
    min-height: 58px;
    margin: 0;
  }

  .workspace {
    padding: 16px;
  }

  .topbar-controls,
  .status-strip,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .field.compact select,
  .field.tiny select {
    width: 100%;
  }

  .scrubber-block {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .comparison-grid,
  .sensor-grid,
  .before-after,
  .workflow-strip {
    grid-template-columns: 1fr;
  }

  .risk-score {
    font-size: 3.5rem;
  }

  #plantMap {
    min-height: 300px;
  }

  .metrics-table {
    display: block;
    overflow-x: auto;
  }
}
