:root {
  color-scheme: light;
  --ink: #17202b;
  --muted: #657282;
  --line: #d8dee8;
  --panel: #f7f9fc;
  --nav: #111827;
  --blue: #1f6fb2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #ffffff;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
a {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  background: var(--nav);
  color: #f9fafb;
  padding: 24px 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 32px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: #111827;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #aeb8c7;
  font-size: 13px;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 4px;
}

nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 7px;
}

nav a.active {
  color: #ffffff;
  background: #263244;
}

.page-header,
.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow,
.breadcrumbs {
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 10px;
  font-size: 42px;
  line-height: 1.08;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  font-size: 17px;
}

.ghost-button,
.toolbar-actions button,
.export-menu summary,
.close-panel {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
}

.mission-control {
  min-width: 0;
  padding: 34px;
  background:
    linear-gradient(#eef2f7 1px, transparent 1px),
    linear-gradient(90deg, #eef2f7 1px, transparent 1px),
    #ffffff;
  background-size: 44px 44px;
}

.twin-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 0 28px;
}

.twin-title {
  display: grid;
  justify-items: start;
}

.system-label {
  font-size: 14px;
  font-weight: 900;
  color: #1f6fb2;
  letter-spacing: 0.12em;
}

.twin-title h1 {
  margin: 3px 0 8px;
  font-size: 54px;
}

.health-line {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: #176b3a;
  font-weight: 800;
  font-size: 16px;
}

.pulse {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 7px rgba(34, 197, 94, 0.16);
}

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

.system-panel {
  min-height: 245px;
  grid-column: span 4;
  position: relative;
  text-align: left;
  border: 1px solid #cfd8e3;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 8px;
  padding: 26px;
  cursor: pointer;
  box-shadow: 0 18px 45px rgba(20, 29, 42, 0.1);
  overflow: hidden;
}

.system-panel:nth-child(1),
.system-panel:nth-child(2) {
  grid-column: span 6;
}

.system-panel:hover {
  border-color: #1f6fb2;
  transform: translateY(-2px);
}

.system-panel::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 5px;
  background: #1f6fb2;
}

.panel-status {
  position: absolute;
  top: 18px;
  right: 18px;
  color: #176b3a;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: #1f6fb2;
  margin-bottom: 22px;
}

.panel-icon svg {
  width: 48px;
  height: 48px;
}

.system-panel strong {
  display: block;
  font-size: 31px;
  line-height: 1.05;
  margin-bottom: 10px;
}

.panel-question {
  display: block;
  color: #475569;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 20px;
}

.system-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  color: #334155;
  font-size: 18px;
  font-weight: 750;
}

.system-lines span {
  display: block;
}

.twin-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
  padding: 14px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
}

.twin-strip button {
  border: 1px solid #d8dee8;
  background: #ffffff;
  color: #263244;
  border-radius: 7px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
}

.twin-strip button:hover {
  border-color: #1f6fb2;
  color: #1f6fb2;
}

.mission-dashboard {
  min-height: 100vh;
}

.mission-hero {
  align-items: stretch;
}

.sync-card {
  align-self: flex-start;
  min-width: 235px;
  border: 1px solid #cfd8e3;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 12px 30px rgba(20, 29, 42, 0.08);
}

.sync-card span,
.sync-card strong,
.sync-card code {
  display: block;
}

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

.sync-card strong {
  margin: 5px 0 10px;
  font-size: 16px;
  line-height: 1.3;
}

.sync-card code {
  color: #334155;
  font-size: 13px;
}

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

.metric-card,
.control-panel {
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 12px 30px rgba(20, 29, 42, 0.08);
}

.metric-card {
  min-height: 128px;
  padding: 18px;
}

.metric-card span,
.metric-card strong,
.metric-card small {
  display: block;
}

.metric-card span {
  color: #475569;
  font-weight: 850;
}

.metric-card strong {
  margin: 8px 0 4px;
  color: #0f172a;
  font-size: 36px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
  font-size: 13px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
  align-items: start;
}

.control-panel {
  min-width: 0;
  overflow: hidden;
}

.control-panel.wide {
  grid-row: span 2;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.panel-heading span {
  color: #17202b;
  font-size: 15px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-heading a {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.app-list,
.workstream-list,
.estate-list,
.service-list,
.dashboard-list {
  display: grid;
}

.app-status-row {
  display: grid;
  grid-template-columns: auto minmax(135px, 0.9fr) minmax(120px, 0.75fr) 82px minmax(180px, 1.35fr);
  gap: 12px;
  align-items: center;
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: 1px solid #edf1f6;
  color: inherit;
  text-decoration: none;
}

.app-status-row:hover {
  background: #f8fafc;
}

.app-status-row strong,
.compact-row strong,
.workstream-row strong {
  color: #17202b;
}

.app-status-row span,
.app-status-row em,
.compact-row span,
.workstream-row span,
.workstream-row em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.35;
}

.app-status-row code {
  color: #334155;
  font-size: 12px;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #94a3b8;
  box-shadow: 0 0 0 5px rgba(148, 163, 184, 0.14);
}

.status-dot.ok {
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.15);
}

.status-dot.warn {
  background: #eab308;
  box-shadow: 0 0 0 5px rgba(234, 179, 8, 0.16);
}

.status-dot.bad {
  background: #ef4444;
  box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.15);
}

.workstream-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px 72px;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 13px 16px;
  border-bottom: 1px solid #edf1f6;
}

.workstream-row div:first-child {
  display: grid;
  gap: 4px;
}

.progress-rail {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.progress-rail span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #1f6fb2;
}

.compact-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 62px;
  padding: 13px 16px;
  border-bottom: 1px solid #edf1f6;
}

.compact-row div {
  display: grid;
  gap: 4px;
}

.diagram-shell {
  height: 100dvh;
  overflow: hidden;
}

.diagram-content {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--panel);
}

.toolbar {
  min-height: 72px;
  padding: 14px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.toolbar h1 {
  font-size: 24px;
  margin: 6px 0 0;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  align-items: center;
}

.toolbar-actions button,
.export-menu summary {
  min-width: 42px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  font-weight: 800;
}

.export-menu {
  position: relative;
}

.export-menu summary {
  list-style: none;
  cursor: pointer;
}

.export-menu summary::-webkit-details-marker {
  display: none;
}

.export-menu[open] {
  z-index: 5;
}

.export-menu[open]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
}

.export-menu button {
  width: 100%;
  justify-content: start;
  border-radius: 0;
  border-width: 0 0 1px;
}

.export-menu button:first-of-type {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 130px;
  border: 1px solid var(--line);
  border-radius: 7px 7px 0 0;
  background: #ffffff;
}

.export-menu button:last-of-type {
  position: absolute;
  top: calc(100% + 43px);
  right: 0;
  width: 130px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 7px 7px;
  background: #ffffff;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
}

.breadcrumbs button {
  color: var(--blue);
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font-weight: 700;
}

.chevron {
  color: #94a3b8;
}

.canvas-wrap {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  height: 100%;
}

.diagram-canvas {
  width: 100%;
  height: 100%;
  background: #ffffff;
  cursor: grab;
  touch-action: none;
}

.diagram-canvas:active {
  cursor: grabbing;
}

.group-title {
  font-size: 23px;
  font-weight: 800;
  fill: #334155;
}

.group-subtitle {
  font-size: 15px;
  fill: #6b7280;
}

.link {
  fill: none;
  stroke: #6b7280;
  stroke-width: 3;
}

.link-label {
  font-size: 14px;
  fill: #475569;
  font-weight: 700;
}

.node {
  cursor: pointer;
}

.node.selected rect {
  stroke-width: 4;
}

.node-title {
  font-size: 19px;
  font-weight: 800;
  fill: #17202b;
}

.node-type {
  font-size: 13px;
  fill: #657282;
  font-weight: 700;
  text-transform: uppercase;
}

.node-badge {
  font-size: 13px;
  fill: #334155;
  font-weight: 650;
}

.inspector {
  background: #ffffff;
  border-left: 1px solid var(--line);
  padding: 22px;
  overflow: auto;
}

.empty-inspector {
  min-height: 180px;
  display: grid;
  align-content: center;
  gap: 8px;
  color: var(--muted);
}

.empty-inspector strong {
  color: var(--ink);
  font-size: 18px;
}

.close-panel {
  float: right;
}

.node-kicker {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.inspector h2 {
  margin: 8px 0 20px;
  font-size: 26px;
  letter-spacing: 0;
}

dt {
  color: #334155;
  font-weight: 800;
  margin-top: 18px;
}

dd {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

dd ul {
  padding-left: 18px;
  margin: 0;
}

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

  .sidebar {
    display: none;
  }

  .mission-control {
    padding: 22px;
  }

  .twin-title h1 {
    font-size: 40px;
  }

  .system-panel,
  .system-panel:nth-child(1),
  .system-panel:nth-child(2) {
    grid-column: span 12;
  }

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

  .control-panel.wide {
    grid-row: auto;
  }

  .canvas-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, calc(100dvh - 86px)) auto;
  }

  .inspector {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 700px) {
  .diagram-shell {
    height: 100dvh;
  }

  .toolbar {
    min-height: 58px;
    padding: 8px 10px;
    gap: 8px;
  }

  .toolbar h1 {
    font-size: 18px;
    margin: 2px 0 0;
  }

  .breadcrumbs {
    font-size: 12px;
    gap: 5px;
  }

  .toolbar-actions {
    gap: 5px;
  }

  .toolbar-actions button,
  .export-menu summary {
    min-width: 34px;
    height: 34px;
    padding: 0 9px;
    font-size: 13px;
  }

  .toolbar-actions [data-fit] {
    font-size: 0;
  }

  .toolbar-actions [data-fit]::before {
    content: "Fit";
    font-size: 13px;
  }

  .export-menu summary {
    font-size: 0;
  }

  .export-menu summary::before {
    content: "Export";
    font-size: 13px;
  }

  .mobile-twin {
    min-height: 100dvh;
    background:
      linear-gradient(#eef2f7 1px, transparent 1px),
      linear-gradient(90deg, #eef2f7 1px, transparent 1px),
      #ffffff;
    background-size: 36px 36px;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
  }

  .mobile-header button {
    border: 1px solid var(--line);
    background: #ffffff;
    border-radius: 7px;
    padding: 8px 10px;
    font-weight: 800;
  }

  .mobile-header h1 {
    margin: 2px 0 0;
    font-size: 24px;
  }

  .mobile-stack {
    display: grid;
    gap: 12px;
    padding: 14px;
  }

  .machine-card {
    width: 100%;
    min-height: 172px;
    position: relative;
    text-align: left;
    border: 1px solid #cfd8e3;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 12px 30px rgba(20, 29, 42, 0.09);
  }

  .machine-card strong,
  .machine-card span {
    display: block;
  }

  .machine-card strong {
    font-size: 26px;
    line-height: 1.05;
    margin-bottom: 8px;
  }

  .machine-status {
    position: absolute;
    right: 16px;
    top: 16px;
    color: #176b3a;
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  .machine-role {
    color: #475569;
    font-weight: 800;
    padding-right: 84px;
  }

  .machine-systems {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 14px 0 12px;
  }

  .machine-systems span {
    border: 1px solid #d8dee8;
    border-radius: 7px;
    background: #f7f9fc;
    padding: 6px 8px;
    font-size: 13px;
    font-weight: 800;
  }

  .machine-summary {
    color: #657282;
    line-height: 1.35;
  }

  .mobile-detail {
    margin: 0 14px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 18px;
  }

  .mission-hero {
    display: grid;
  }

  .sync-card {
    width: 100%;
  }

  .control-metrics {
    gap: 10px;
  }

  .metric-card {
    min-height: 96px;
  }

  .app-status-row {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 7px 12px;
  }

  .app-status-row span:not(.status-dot),
  .app-status-row code,
  .app-status-row em {
    grid-column: 2;
  }

  .workstream-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media print {
  .sidebar,
  .toolbar-actions,
  .inspector,
  .page-header button {
    display: none;
  }

  .shell,
  .canvas-wrap,
  .diagram-content {
    display: block;
  }

  .toolbar {
    border: 0;
    padding: 0 0 12px;
  }

  .diagram-canvas {
    width: 100vw;
    height: 80vh;
  }
}
