:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #162033;
  --muted: #64748b;
  --line: #d9e1ea;
  --accent: #0f766e;
  --accent-2: #4f46e5;
  --warn: #b45309;
  --bad: #b91c1c;
  --code: #111827;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 96px;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  margin: 0;
  padding-bottom: 78px;
}

header {
  align-items: center;
  background: rgba(246, 247, 249, 0.96);
  border-bottom: 1px solid rgba(217, 225, 234, 0.86);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 22px 28px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-block {
  min-width: 270px;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 30px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 13px;
  margin-top: 14px;
}

.kicker {
  color: var(--accent);
  font: 800 12px/1.4 var(--mono);
  margin: 0 0 7px;
}

.actions {
  display: flex;
  gap: 10px;
}

.top-menu,
.bottom-menu {
  background: #eef2f6;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 4px;
  padding: 4px;
}

.top-menu {
  flex: 1 1 auto;
  justify-content: center;
  min-width: 360px;
}

.bottom-menu {
  bottom: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  left: 50%;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  position: fixed;
  transform: translateX(-50%);
  z-index: 40;
}

button {
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 10px 14px;
}

button + button {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}

.menu-link,
.bottom-link,
button.menu-link + button.menu-link,
button.bottom-link + button.bottom-link {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  padding: 8px 10px;
  white-space: nowrap;
}

.menu-link.active,
.bottom-link.active {
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  color: var(--ink);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

main {
  display: grid;
  gap: 16px;
  padding: 0 28px 28px;
}

.panel,
.device-card,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 16px;
}

.nl-panel {
  display: grid;
  gap: 12px;
}

.nl-panel button {
  justify-self: start;
}

textarea,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  padding: 11px 12px;
}

textarea {
  min-height: 96px;
  resize: vertical;
  width: 100%;
}

textarea:focus,
input:focus {
  border-color: var(--accent-2);
  outline: 2px solid rgba(79, 70, 229, 0.14);
}

.demo-layout {
  display: grid;
  align-items: start;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}

.control-column,
.observe-column {
  min-width: 0;
}

.control-column {
  display: grid;
  grid-template-areas:
    "flow command"
    "devices command";
  grid-template-columns: minmax(320px, 0.8fr) minmax(520px, 1.2fr);
  gap: 14px;
}

.observe-column {
  position: static;
}

#flow-panel {
  grid-area: flow;
}

#command-workbench {
  grid-area: command;
}

#devices {
  grid-area: devices;
}

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

.metric {
  padding: 14px 16px;
}

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

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 4px;
}

.device-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.device-card {
  overflow: hidden;
  padding: 14px;
}

.device-card.offline {
  border-color: #f2c7c7;
}

.device-head {
  align-items: start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.device-head strong {
  display: block;
  font: 800 18px/1.2 var(--mono);
}

.device-head span,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.status,
.badge {
  border-radius: 999px;
  font: 800 11px/1 var(--mono);
  padding: 6px 8px;
  text-transform: uppercase;
}

.status {
  background: #dff8f2;
  color: var(--accent);
}

.offline .status,
.badge.locked {
  background: #fff1f2;
  color: var(--bad);
}

.badge.safe {
  background: #eefbf6;
  color: var(--accent);
}

dl {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 14px 0 0;
}

dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

table {
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 8px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 7px 5px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.installable {
  color: var(--muted);
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding-left: 18px;
}

.installable strong {
  color: var(--warn);
  display: block;
}

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

.panel-head.compact {
  margin-bottom: 10px;
}

.command-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.85fr);
  margin-top: 14px;
}

.route-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  max-height: 390px;
  overflow: auto;
}

.route-row {
  align-items: center;
  background: #fbfcfe;
  border-color: var(--line);
  color: var(--ink);
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 10px;
  text-align: left;
}

.route-row.active,
.route-row:hover {
  border-color: var(--accent-2);
  outline: 2px solid rgba(79, 70, 229, 0.12);
}

.route-row span:last-child {
  color: var(--muted);
  grid-column: 1 / -1;
  font-weight: 500;
}

.selected-command {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
}

.selected-command p {
  color: var(--muted);
  margin: 0;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
}

.payload-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.payload-field {
  display: grid;
  gap: 6px;
}

.payload-field.inline {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
}

.payload-field span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.payload-field small {
  color: var(--muted);
}

.payload-field input[type="checkbox"] {
  height: 18px;
  width: 18px;
}

.result-panel {
  min-height: 300px;
}

.view-tabs {
  background: #eef2f6;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  padding: 3px;
}

.tab-button,
button.tab-button + button.tab-button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  padding: 8px 11px;
}

.tab-button.active,
button.tab-button.active {
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  color: var(--ink);
}

.view-pane {
  display: none;
  margin-top: 14px;
}

.view-pane.active {
  display: block;
}

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

.novnc-card {
  background: #0b1020;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.novnc-head {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 12px;
}

.novnc-head strong {
  display: block;
  font: 800 14px/1.2 var(--mono);
}

.novnc-head span,
.novnc-head a {
  color: var(--muted);
  font-size: 12px;
}

.novnc-head a {
  font-weight: 800;
  text-decoration: none;
}

.novnc-card iframe {
  border: 0;
  display: block;
  height: 300px;
  width: 100%;
}

.novnc-empty {
  color: #cbd5e1;
  display: grid;
  gap: 8px;
  min-height: 300px;
  place-content: center;
  padding: 18px;
  text-align: center;
}

.activity-log {
  display: grid;
  gap: 8px;
  max-height: 720px;
  overflow: auto;
}

.log-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
}

.log-row.frontend-log {
  background: #f8fafc;
}

.log-row strong {
  display: block;
  font: 800 13px/1.2 var(--mono);
}

.log-row span {
  color: var(--muted);
  font-size: 12px;
}

.log-row code {
  background: transparent;
  color: var(--code);
  padding: 0;
}

.result-grid {
  display: grid;
  gap: 14px;
}

code,
pre {
  font-family: var(--mono);
}

code {
  background: #eef2ff;
  border-radius: 5px;
  color: #3730a3;
  overflow-wrap: anywhere;
  padding: 0.08rem 0.28rem;
}

pre {
  background: var(--code);
  border-radius: 8px;
  color: #e8eef8;
  font-size: 12px;
  line-height: 1.55;
  margin: 12px 0 0;
  max-height: 420px;
  overflow: auto;
  padding: 14px;
}

ol {
  color: var(--muted);
  margin: 12px 0 0;
  padding-left: 24px;
}

li + li {
  margin-top: 8px;
}

.ok {
  color: var(--accent);
  font-weight: 800;
}

.fail {
  color: var(--bad);
  font-weight: 800;
}

@media (max-width: 1180px) {
  .control-column,
  .demo-layout {
    grid-template-columns: 1fr;
  }

  .control-column {
    grid-template-areas:
      "flow"
      "command"
      "devices";
  }
}

@media (max-width: 980px) {
  header,
  .panel-head {
    align-items: start;
    flex-direction: column;
  }

  header,
  .panel-head,
  .actions {
    display: flex;
  }

  .brand-block,
  .top-menu {
    min-width: 0;
    width: 100%;
  }

  .top-menu {
    justify-content: start;
    overflow-x: auto;
  }

  .command-grid,
  .device-grid,
  .demo-layout,
  .novnc-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .view-tabs {
    width: 100%;
  }

  .bottom-menu {
    justify-content: start;
    width: calc(100vw - 24px);
  }

  dl {
    grid-template-columns: 1fr;
  }
}
