:root {
  --sim-blue: #155c91;
  --sim-blue-dark: #10466e;
  --sim-green: #2b765a;
  --sim-red: #c4493f;
  --sim-gray: #aab4bc;
  --sim-grid: rgba(21, 92, 145, 0.055);
}

.simulator-page {
  min-height: 100vh;
  background: #f5f7f8;
  color: #17202a;
}

.sim-shell {
  width: min(1420px, calc(100vw - 40px));
  margin-inline: auto;
}

.simulator-header {
  position: sticky;
  z-index: 50;
  top: 0;
  border-bottom: 1px solid #dfe4e8;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.simulator-nav {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.sim-brand {
  display: grid;
  line-height: 1.25;
}

.sim-brand span { font-size: 0.82rem; font-weight: 750; }
.sim-brand small { color: #7a858f; font-family: var(--mono); font-size: 0.5rem; text-transform: uppercase; }
.sim-byline { margin: 0; color: #6b7781; font-size: 0.66rem; }

.simulator { padding: 24px 0 28px; }

.sim-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 0.5fr);
  align-items: end;
  gap: 50px;
  margin-bottom: 18px;
}

.sim-eyebrow {
  margin-bottom: 10px;
  color: var(--sim-blue);
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sim-intro h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  font-weight: 670;
  letter-spacing: -0.05em;
}

.sim-intro > p {
  margin: 0 0 4px;
  color: #63707b;
  font-size: 0.76rem;
}

.scenario-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 14px;
  overflow: hidden;
  border: 1px solid #d5dce1;
  border-radius: 10px;
  background: white;
}

.scenario-tabs button {
  min-height: 68px;
  display: grid;
  grid-template-columns: 35px auto;
  grid-template-rows: auto auto;
  align-content: center;
  justify-content: start;
  column-gap: 13px;
  padding: 12px 20px;
  border: 0;
  border-right: 1px solid #dfe4e8;
  background: white;
  color: #17202a;
  cursor: pointer;
  text-align: left;
  transition: background 160ms ease;
}

.scenario-tabs button:last-child { border-right: 0; }
.scenario-tabs button:hover { background: #f7fafc; }
.scenario-tabs button[aria-selected="true"] { background: #edf5fa; box-shadow: inset 0 -3px var(--sim-blue); }
.scenario-tabs button > span { grid-row: 1 / 3; align-self: center; color: #a0abb4; font-family: var(--mono); font-size: 0.58rem; }
.scenario-tabs strong { align-self: end; font-size: 0.82rem; }
.scenario-tabs small { color: #7a858f; font-size: 0.62rem; }

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

.network-panel,
.control-panel {
  overflow: hidden;
  border: 1px solid #d5dce1;
  border-radius: 10px;
  background: white;
}

.network-panel { min-width: 0; display: flex; flex-direction: column; }

.network-toolbar,
.network-footer {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 16px;
  color: #71808b;
  font-family: var(--mono);
  font-size: 0.53rem;
  text-transform: uppercase;
}

.network-toolbar { border-bottom: 1px solid #dfe4e8; }
.network-footer { min-height: 42px; border-top: 1px solid #dfe4e8; }
.network-toolbar > div:first-child { display: flex; align-items: center; gap: 8px; color: var(--sim-green); }
.network-toolbar > div:first-child > i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgba(43, 118, 90, 0.1); }
.network-toolbar > div:first-child > i.is-fault { color: var(--sim-red); }

.network-legend { display: flex; gap: 16px; }
.network-legend span { display: inline-flex; align-items: center; gap: 6px; }
.network-legend i { width: 16px; height: 3px; display: block; background: var(--sim-blue); }
.network-legend .legend-open { height: 8px; border: 2px solid var(--sim-gray); background: white; }
.network-legend .legend-fault { background: var(--sim-red); }

.network-canvas-wrap {
  min-height: 460px;
  flex: 1;
  display: grid;
  place-items: center;
  overflow: auto;
  background:
    linear-gradient(var(--sim-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--sim-grid) 1px, transparent 1px),
    #fbfcfd;
  background-size: 25px 25px;
}

#network-canvas { width: 100%; min-width: 700px; height: 100%; min-height: 460px; }

.grid-edge {
  stroke: var(--sim-blue);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke 260ms ease, opacity 260ms ease, stroke-width 260ms ease;
}

.grid-edge.deenergized { stroke: #bcc5cc; opacity: 0.7; }
.grid-edge.faulted { stroke: var(--sim-red); stroke-width: 6; stroke-dasharray: 9 7; animation: fault-flow 0.8s linear infinite; }

@keyframes fault-flow { to { stroke-dashoffset: -16; } }

.grid-node .node-shape {
  fill: white;
  stroke: var(--sim-blue);
  stroke-width: 3;
  transition: fill 240ms ease, stroke 240ms ease, opacity 240ms ease;
}

.grid-node.source .node-shape { fill: var(--sim-blue); }
.grid-node.source .node-id { fill: white; }
.grid-node.junction .node-shape { fill: var(--sim-blue); }
.grid-node.open .node-shape { fill: white; stroke: var(--sim-gray); stroke-dasharray: 5 3; }
.grid-node.deenergized { opacity: 0.47; }
.grid-node.lockout .node-shape { fill: #f9e4e2; stroke: var(--sim-red); }
.grid-node.restored .node-shape { fill: #e3f2eb; stroke: var(--sim-green); }

.node-id { fill: #24404f; font-family: var(--mono); font-size: 12px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.node-caption { fill: #74818b; font-family: var(--mono); font-size: 9px; text-anchor: middle; text-transform: uppercase; }
.node-state-badge { fill: var(--sim-blue); }
.node-state-text { fill: white; font-family: var(--mono); font-size: 8px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }

.fault-label rect { fill: var(--sim-red); rx: 4; }
.fault-label text { fill: white; font-family: var(--mono); font-size: 9px; font-weight: 700; text-anchor: middle; }

.control-panel { display: flex; flex-direction: column; padding: 22px; }

.control-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.control-heading p,
.message-card > p { margin-bottom: 5px; color: #7a858f; font-family: var(--mono); font-size: 0.52rem; font-weight: 700; text-transform: uppercase; }
.control-heading h2 { margin: 0; font-size: 1.5rem; }
.step-count { padding: 5px 8px; border-radius: 5px; background: #eef2f4; color: #65737e; font-family: var(--mono); font-size: 0.52rem; }

.scenario-description { min-height: 58px; margin: 14px 0 18px; color: #66737d; font-size: 0.7rem; }

.message-card {
  min-height: 195px;
  padding: 17px;
  border: 1px solid #dce2e6;
  border-radius: 8px;
  background: #f8fafb;
}

.message-card h3 { margin-bottom: 14px; font-size: 0.93rem; line-height: 1.35; letter-spacing: -0.02em; }
.message-card ul { margin: 0; padding-left: 16px; color: #64717c; font-size: 0.67rem; }
.message-card li + li { margin-top: 4px; }

.step-progress { height: 4px; margin: 17px 0; overflow: hidden; border-radius: 4px; background: #e6eaed; }
.step-progress span { width: 0; height: 100%; display: block; border-radius: inherit; background: var(--sim-blue); transition: width 220ms ease; }

.run-controls,
.step-controls { display: grid; grid-template-columns: 1fr 0.62fr; gap: 8px; }
.step-controls { grid-template-columns: 1fr 1fr; margin-top: 8px; }

.sim-button {
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid #d0d7dc;
  border-radius: 6px;
  background: white;
  color: #25313a;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 700;
  transition: background 150ms ease, border-color 150ms ease;
}

.sim-button:hover:not(:disabled) { border-color: var(--sim-blue); background: #f3f8fb; }
.sim-button:disabled { cursor: not-allowed; opacity: 0.42; }
.sim-primary { border-color: var(--sim-blue); background: var(--sim-blue); color: white; }
.sim-primary:hover:not(:disabled) { background: var(--sim-blue-dark); color: white; }

.control-tip { margin-top: auto; padding-top: 18px; border-top: 1px solid #e0e5e8; }
.control-tip strong { font-size: 0.68rem; }
.control-tip p { margin: 4px 0 0; color: #79848e; font-size: 0.6rem; }

@media (max-width: 1050px) {
  .simulation-workspace { grid-template-columns: 1fr; }
  .control-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 15px 22px; }
  .control-heading,
  .scenario-description,
  .message-card,
  .step-progress { grid-column: 1 / -1; }
  .scenario-description { min-height: 0; margin-bottom: 0; }
  .message-card { min-height: 150px; }
  .control-tip { margin-top: 0; padding: 0 0 0 20px; border-top: 0; border-left: 1px solid #e0e5e8; }
}

@media (max-width: 760px) {
  .sim-shell { width: min(100% - 24px, 650px); }
  .sim-byline { display: none; }
  .sim-intro { grid-template-columns: 1fr; gap: 13px; }
  .scenario-tabs { grid-template-columns: 1fr; }
  .scenario-tabs button { min-height: 65px; border-right: 0; border-bottom: 1px solid #dfe4e8; }
  .scenario-tabs button:last-child { border-bottom: 0; }
  .scenario-tabs button[aria-selected="true"] { box-shadow: inset 3px 0 var(--sim-blue); }
  .network-toolbar { align-items: flex-start; flex-direction: column; justify-content: center; gap: 7px; padding-block: 10px; }
  .network-legend { flex-wrap: wrap; gap: 10px; }
  .network-footer { align-items: flex-start; flex-direction: column; justify-content: center; gap: 3px; padding-block: 8px; }
  .network-canvas-wrap { min-height: 430px; }
  #network-canvas { min-height: 430px; }
  .control-panel { display: flex; }
  .control-tip { margin-top: 18px; padding: 15px 0 0; border-top: 1px solid #e0e5e8; border-left: 0; }
}

@media (max-width: 480px) {
  .simulator { padding-top: 24px; }
  .sim-intro h1 { font-size: 2.2rem; }
  .network-canvas-wrap { min-height: 380px; }
  #network-canvas { min-height: 380px; }
}
