:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687386;
  --line: #d9e0ea;
  --green: #1f8f5f;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #c2410c;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.segmented button,
.template-form button,
.icon-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segmented button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 3px 10px rgba(17, 24, 39, 0.08);
}

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

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

.metric {
  padding: 14px;
}

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

.metric strong {
  display: block;
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.layout.secondary {
  grid-template-columns: minmax(0, 1fr) 420px;
  margin-top: 12px;
}

.panel {
  min-width: 0;
  padding: 14px;
}

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

.panel-heading p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button,
.template-form button {
  background: var(--ink);
  color: white;
  font-weight: 800;
  padding: 0 12px;
}

.device-list,
.file-list,
.template-list {
  display: grid;
  gap: 8px;
  max-height: 460px;
  overflow: auto;
}

.device-card,
.file-card,
.template-card,
.flow-node {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.device-card,
.file-card,
.template-card {
  padding: 10px;
}

.device-card {
  cursor: pointer;
}

.device-card.active {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.device-card strong,
.file-card strong,
.template-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.device-card span,
.file-card span,
.template-card span {
  color: var(--muted);
  font-size: 12px;
}

.flow-panel {
  min-height: 520px;
}

.flow-canvas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.flow-node {
  position: relative;
  min-height: 132px;
  padding: 12px;
}

.flow-node::after {
  content: attr(data-index);
  position: absolute;
  top: 10px;
  right: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.flow-node h3 {
  max-width: calc(100% - 34px);
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.25;
}

.flow-node p {
  color: var(--muted);
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.chip {
  border-radius: 999px;
  background: #e9f5ef;
  color: #166342;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 7px;
}

.chip.scan,
.chip.tfLiteScan,
.chip.detection {
  background: #e8f0ff;
  color: #1d4ed8;
}

.chip.portValidation,
.chip.ledValidation {
  background: #fff4e1;
  color: var(--amber);
}

.chip.arTracking,
.chip.arAnchoredModel {
  background: #f1e9ff;
  color: #6b21a8;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.file-card {
  cursor: pointer;
}

.template-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px 96px;
  gap: 8px;
  margin-top: 12px;
}

.template-form input,
.template-form select {
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 0 10px;
}

.json-panel {
  margin-top: 12px;
}

pre {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101826;
  color: #e6edf7;
  padding: 14px;
  font-size: 12px;
  line-height: 1.5;
}

.empty,
.error {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
}

.error {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--red);
}

@media (max-width: 920px) {
  .topbar,
  .layout,
  .layout.secondary,
  .status-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .template-form {
    grid-template-columns: 1fr;
  }
}
