:root {
  color-scheme: dark;
  --bg: #070a0f;
  --bg2: #0b111a;
  --panel: #111822;
  --panel2: #151f2b;
  --panel3: #0e151e;
  --line: #263545;
  --line2: #34495e;
  --text: #e7eef7;
  --muted: #91a3b8;
  --muted2: #607287;
  --accent: #6ed3ff;
  --accent2: #9fe870;
  --warn: #ffcf66;
  --high: #ff9d57;
  --critical: #ff5d6c;
  --ok: #8ff0c5;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.38);
  --radius: 16px;
  --gap: 18px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background:
    radial-gradient(circle at 18% 8%, rgba(69, 142, 198, 0.18), transparent 34rem),
    radial-gradient(circle at 90% 22%, rgba(128, 232, 170, 0.08), transparent 30rem),
    linear-gradient(180deg, var(--bg2), var(--bg));
  color: var(--text);
}
button, select, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1860px, calc(100vw - 24px));
  min-height: calc(100vh - 24px);
  margin: 12px auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 20px;
  align-items: end;
  padding: 22px 24px;
  background: linear-gradient(135deg, rgba(20, 31, 45, 0.96), rgba(11, 17, 25, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.title-block h1, .panel h2, .graph-header h2, .landing-card h1 { margin: 0; }
.title-block h1 { font-size: clamp(1.65rem, 3vw, 2.75rem); letter-spacing: -0.03em; }
.title-block p, .graph-header p, .panel-header p { margin: 0.35rem 0 0; color: var(--muted); }
.eyebrow { color: var(--accent); font-size: 0.76rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.16em; }

.menu-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.menu-button, .tab, .workspace-tab, .small-button, .time-window button, .scenario-buttons button {
  border: 1px solid var(--line2);
  background: linear-gradient(180deg, #172231, #0f1722);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}
.menu-button:hover, .tab:hover, .workspace-tab:hover, .small-button:hover, .time-window button:hover, .scenario-buttons button:hover,
.menu-button:focus-visible, .tab:focus-visible, .workspace-tab:focus-visible, .small-button:focus-visible, .time-window button:focus-visible, .scenario-buttons button:focus-visible {
  outline: none;
  border-color: var(--accent);
  transform: translateY(-1px);
}
.menu-popover {
  position: absolute;
  right: 20px;
  top: calc(100% - 10px);
  z-index: 10;
  width: min(340px, calc(100vw - 40px));
  padding: 12px;
  border: 1px solid var(--line2);
  border-radius: 14px;
  background: rgba(9, 14, 21, 0.98);
  box-shadow: var(--shadow);
}
.menu-popover h3 { margin: 0 0 8px; }
.menu-popover ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.menu-popover li { color: var(--muted); padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,0.03); }

.status-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(12, 18, 28, 0.92);
}
.status-fill { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 4px 8px;
  border: 1px solid rgba(110, 211, 255, 0.35);
  border-radius: 999px;
  color: #cdefff;
  background: rgba(110, 211, 255, 0.08);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.status-badge.strong { border-color: rgba(143, 240, 197, 0.7); color: #d8ffee; background: rgba(143, 240, 197, 0.12); }
.status-badge.warn { border-color: rgba(255, 207, 102, 0.65); color: #ffe3a1; background: rgba(255, 207, 102, 0.12); }
.status-badge.high { border-color: rgba(255, 157, 87, 0.70); color: #ffd0b0; background: rgba(255, 157, 87, 0.12); }
.status-badge.critical { border-color: rgba(255, 93, 108, 0.80); color: #ffd1d6; background: rgba(255, 93, 108, 0.14); }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(560px, 1fr) minmax(290px, 380px);
  gap: var(--gap);
  align-items: stretch;
  flex: 1;
  min-height: 0;
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(19, 28, 40, 0.96), rgba(11, 17, 25, 0.96));
  box-shadow: 0 12px 32px rgba(0,0,0,0.22);
}
.left-panel, .right-panel {
  min-height: 720px;
  max-height: calc(100vh - 176px);
  overflow: auto;
  padding: 14px;
}
.center-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 230px;
  min-width: 0;
  min-height: 720px;
  max-height: calc(100vh - 176px);
  gap: 12px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.panel-header h2 { font-size: 1.05rem; }
.panel-header span { color: var(--muted2); font-size: 0.78rem; }
.panel-header.large { margin-bottom: 20px; align-items: flex-start; }
.panel-header.large h2 { font-size: clamp(1.3rem, 2vw, 2rem); }
.panel-header.compact { margin: 0; padding: 10px 12px 6px; }

.mini-tabs, .workspace-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}
.tab, .workspace-tab { padding: 7px 9px; font-size: 0.82rem; }
.tab.active, .workspace-tab.active, .time-window button.active, .scenario-buttons button.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(49, 114, 151, 0.48), rgba(18, 37, 52, 0.92));
}
.workspace-tabs { margin: 0; }
.workspace-view { display: none; min-height: 0; }
.workspace-view.active { display: block; min-height: 0; }
#workspace-operate.active { height: 100%; }

.left-tab-body { display: none; }
.left-tab-body.active { display: grid; gap: 10px; }
.list-card, .mapping-row, .trace-row, .info-tile, .device-card, .signal-card {
  border: 1px solid rgba(120, 148, 176, 0.23);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
}
.device-card, .signal-card, .mapping-row { padding: 10px; }
.device-card h3, .signal-card h3, .right-section h3 { margin: 0 0 6px; font-size: 0.9rem; }
.device-meta, .mapping-meta, .trace-meta { color: var(--muted); font-size: 0.78rem; display: flex; gap: 8px; flex-wrap: wrap; }
.point-list { margin-top: 8px; color: var(--muted2); font-size: 0.78rem; line-height: 1.45; }
.mapping-row { display: grid; gap: 5px; font-size: 0.84rem; }
.mapping-arrow { color: var(--accent); font-weight: 900; padding: 0 4px; }

.graph-card { height: 100%; display: grid; grid-template-rows: auto minmax(300px, 1fr) auto; padding: 14px; }
.graph-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; padding: 2px 2px 10px; }
.graph-header h2 { font-size: clamp(1.25rem, 2vw, 2rem); }
.time-window { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.time-window button { font-size: 0.78rem; padding: 7px 9px; }
.graph-stage {
  position: relative;
  min-height: 350px;
  border: 1px solid rgba(92, 126, 158, 0.28);
  border-radius: 14px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px),
    radial-gradient(circle at 60% 18%, rgba(110,211,255,0.08), transparent 30rem),
    #080d14;
  background-size: 100% 46px, 56px 100%, auto, auto;
}
#trend-canvas { width: 100%; height: 100%; display: block; }
.graph-overlay { position: absolute; display: grid; gap: 4px; color: rgba(222, 236, 250, 0.72); font-size: 0.76rem; pointer-events: none; }
.graph-overlay.top-left { left: 14px; top: 12px; }
.alarm-band-label {
  position: absolute;
  right: 12px;
  top: 12px;
  color: rgba(255, 207, 102, 0.78);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.legend-row { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; }
.legend-chip {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  border: 1px solid rgba(120, 148, 176, 0.25);
  border-radius: 999px;
  padding: 6px 9px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 0.78rem;
}
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px currentColor; }

.event-console { overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.event-log { overflow: auto; padding: 8px 12px 12px; display: flex; flex-direction: column-reverse; gap: 5px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.78rem; color: #c8d8ea; }
.event-line { padding: 5px 7px; border-radius: 8px; background: rgba(255,255,255,0.035); border-left: 3px solid rgba(110,211,255,0.55); }
.event-line.warn { border-left-color: var(--warn); }
.event-line.high { border-left-color: var(--high); }
.event-line.critical { border-left-color: var(--critical); }

.right-section { border-top: 1px solid rgba(120, 148, 176, 0.18); padding: 12px 0; }
.right-section:first-of-type { border-top: 0; padding-top: 0; }
.right-section h3 { color: #d9e8f7; }
.scenario-buttons { display: grid; gap: 8px; }
.scenario-buttons button { text-align: left; }
#lens-select {
  width: 100%;
  border: 1px solid var(--line2);
  border-radius: 10px;
  background: #101823;
  color: var(--text);
  padding: 9px 10px;
}
.helper-text { color: var(--muted); font-size: 0.83rem; line-height: 1.45; }
.trace-list { display: grid; gap: 8px; }
.trace-row { padding: 9px; display: grid; gap: 4px; }
.trace-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.trace-top label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.trace-top span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace-value { font-variant-numeric: tabular-nums; color: #dcecff; }
input[type="checkbox"] { accent-color: #6ed3ff; }
.blocked-controls {
  border: 1px solid rgba(255, 207, 102, 0.24);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 207, 102, 0.05);
}
.disabled-action {
  width: 100%;
  margin-top: 7px;
  border: 1px solid rgba(255, 207, 102, 0.28);
  background: rgba(255, 255, 255, 0.04);
  color: #b7a986;
  border-radius: 10px;
  padding: 9px;
  cursor: not-allowed;
}
.notes-box {
  min-height: 88px;
  border: 1px solid rgba(120,148,176,0.2);
  border-radius: 12px;
  padding: 10px;
  color: var(--muted);
  background: rgba(255,255,255,0.035);
  line-height: 1.45;
}

.logic-board, .review-board, .system-board { height: 100%; padding: 22px; }
.node-canvas {
  min-height: 260px;
  border: 1px solid rgba(120,148,176,0.18);
  border-radius: 16px;
  display: grid;
  grid-template-columns: 1fr 0.45fr 1fr 0.45fr 1fr 0.45fr 1fr 0.45fr 1fr;
  align-items: center;
  gap: 8px;
  padding: 22px;
  background:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
    rgba(0,0,0,0.14);
  background-size: 26px 26px;
}
.logic-node {
  min-height: 100px;
  border: 1px solid rgba(110,211,255,0.42);
  border-radius: 16px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 12px;
  background: rgba(110,211,255,0.08);
  font-weight: 800;
}
.logic-node span { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.logic-node.alarm { border-color: rgba(255,207,102,0.55); background: rgba(255,207,102,0.08); }
.logic-node.gate { border-color: rgba(255,157,87,0.55); background: rgba(255,157,87,0.08); }
.logic-node.disabled { border-color: rgba(255,93,108,0.5); background: rgba(255,93,108,0.08); color: #ffd2d8; }
.wire { height: 4px; background: linear-gradient(90deg, rgba(110,211,255,0.1), rgba(110,211,255,0.75), rgba(110,211,255,0.1)); border-radius: 999px; }
.wire.disabled { background: linear-gradient(90deg, rgba(255,93,108,0.1), rgba(255,93,108,0.65), rgba(255,93,108,0.1)); }
.grid-two, .checkpoint-grid, .diagnostic-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.diagnostic-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.info-tile { padding: 13px; display: grid; gap: 5px; }
.info-tile b { color: #eaf4ff; }
.info-tile span { color: var(--muted); }
.timeline { margin-top: 18px; display: grid; gap: 8px; }
.timeline-row { border-left: 3px solid rgba(110,211,255,0.55); padding: 8px 10px; background: rgba(255,255,255,0.035); border-radius: 8px; color: var(--muted); }

.landing-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.landing-card {
  width: min(820px, 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(19,28,40,0.96), rgba(11,17,25,0.98));
  box-shadow: var(--shadow);
  padding: clamp(24px, 5vw, 46px);
}
.landing-card h1 { font-size: clamp(2rem, 5vw, 4rem); letter-spacing: -0.04em; }
.landing-card p { color: var(--muted); line-height: 1.55; }
.landing-status { margin: 22px 0; }
.launch-link {
  display: inline-flex;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid rgba(110,211,255,0.55);
  background: rgba(110,211,255,0.1);
  color: #e5f8ff;
  text-decoration: none;
  font-weight: 800;
}
code { color: #d8ffee; background: rgba(255,255,255,0.06); padding: 2px 5px; border-radius: 5px; }

@media (max-width: 1240px) {
  .dashboard-grid { grid-template-columns: 280px minmax(520px, 1fr); }
  .right-panel { grid-column: 1 / -1; min-height: auto; max-height: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .right-panel > .panel-header { grid-column: 1 / -1; margin-bottom: 0; }
  .right-section { border-top: 0; padding: 0; }
}
@media (max-width: 900px) {
  .top-shell { grid-template-columns: 1fr; align-items: start; }
  .menu-bar { justify-content: flex-start; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .left-panel, .right-panel, .center-panel { min-height: auto; max-height: none; }
  .center-panel { grid-template-rows: auto minmax(520px, auto) 240px; }
  .right-panel { grid-template-columns: 1fr; }
  .graph-header { flex-direction: column; }
  .node-canvas { grid-template-columns: 1fr; }
  .wire { height: 38px; width: 4px; justify-self: center; }
  .grid-two, .checkpoint-grid { grid-template-columns: 1fr; }
}
