:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d8dee9;
  --panel: #ffffff;
  --soft: #f4f7fb;
  --blue: #1455d9;
  --blue-dark: #0d3eaa;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 0; background: var(--soft); color: var(--ink); }
body { min-height: 100vh; }
button, input, textarea { font: inherit; }
button, .file-button {
  border: 1px solid #b8c2d1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: .65rem .85rem;
}
button:hover, .file-button:hover { border-color: var(--blue); }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.primary:hover { background: var(--blue-dark); }
button.danger { color: var(--danger); border-color: #f0b5ae; }
input, textarea, select {
  min-width: 0;
  border: 1px solid #b8c2d1;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: .68rem .75rem;
}
input:focus, textarea:focus, select:focus, button:focus-visible {
  outline: 3px solid rgba(20, 85, 217, .2);
  outline-offset: 1px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.4rem clamp(1rem, 4vw, 3rem);
  background: #111a2e;
  color: #fff;
}
.site-header h1 { margin: .1rem 0; font-size: clamp(1.8rem, 4vw, 2.7rem); }
.site-header p { margin: .25rem 0 0; color: #cbd5e1; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 800; }
.header-actions, .button-row { display: flex; flex-wrap: wrap; gap: .55rem; }
.header-actions button, .header-actions .file-button { color: #fff; background: #1f2d4a; border-color: #425274; }
#import-json { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; pointer-events: none; }

.mode-banner {
  padding: .75rem clamp(1rem, 4vw, 3rem);
  background: #e8f0ff;
  border-bottom: 1px solid #bfd0f5;
  color: #173b7a;
}
.mode-banner.manual { background: #fff3cd; border-color: #ead38a; color: #694d00; }
main { display: grid; gap: 1rem; padding: 1rem clamp(.75rem, 3vw, 2rem) 3rem; }
.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(23, 32, 51, .05);
  padding: 1rem;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.panel-heading > div:first-child { display: flex; align-items: center; gap: .65rem; min-width: 0; }
h2, h3 { margin: 0; }
h2 { font-size: 1.12rem; }
h3 { font-size: .95rem; margin-bottom: .6rem; }
.step {
  display: grid;
  place-items: center;
  flex: 0 0 1.7rem;
  inline-size: 1.7rem;
  block-size: 1.7rem;
  margin: 0;
  border-radius: 999px;
  background: #e8f0ff;
  color: var(--blue);
  font-size: .8rem;
  font-weight: 800;
}
.badge { white-space: nowrap; border-radius: 999px; background: #eef2f7; padding: .35rem .6rem; color: #465267; font-size: .78rem; }
.muted, .status-line { color: var(--muted); }
.scan-controls { display: grid; grid-template-columns: auto minmax(14rem, 1fr) auto auto; align-items: center; gap: .6rem; }
.scan-controls label { font-weight: 700; }
.progress-block { margin-top: 1rem; }
.progress-copy { display: flex; justify-content: space-between; gap: 1rem; font-size: .86rem; }
progress { display: block; inline-size: 100%; block-size: .75rem; margin-top: .45rem; accent-color: var(--blue); }
.status-line { min-height: 1.4em; margin: .7rem 0 0; }
.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: .65rem .55rem; text-align: left; border-bottom: 1px solid #e9edf3; vertical-align: top; }
th { color: #536075; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.empty-cell { padding: 1.5rem; text-align: center; color: var(--muted); }
.device-name { font-weight: 750; }
.provenance { display: block; margin-top: .2rem; color: var(--muted); font-size: .72rem; }
.workspace { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(20rem, .65fr); gap: 1rem; }
.canvas { display: grid; place-items: center; min-height: 25rem; overflow: auto; background: #fbfcfe; border: 1px solid #e9edf3; border-radius: 8px; padding: 1rem; }
.canvas svg { display: block; max-width: 100%; height: auto; }
.canvas .node, .canvas .flowchart-link { cursor: pointer; }
.canvas-error { white-space: pre-wrap; color: var(--danger); overflow-wrap: anywhere; }
.legend { color: var(--muted); font-size: .75rem; }
.legend i { display: inline-block; width: 1.5rem; border-top: 2px dashed #9ca3af; vertical-align: middle; margin-right: .3rem; }
#source-view { width: 100%; min-height: 25rem; resize: vertical; font: .78rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.manual-grid { display: grid; grid-template-columns: minmax(14rem, .45fr) minmax(18rem, 1fr); gap: 1rem; }
.palette { display: flex; flex-wrap: wrap; gap: .45rem; }
.inspector { min-width: 0; border-left: 1px solid var(--line); padding-left: 1rem; }
.field-row { display: grid; grid-template-columns: 7rem 1fr; gap: .5rem; align-items: center; margin: .5rem 0; }

@media (max-width: 850px) {
  .workspace, .manual-grid { grid-template-columns: 1fr; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); padding: 1rem 0 0; }
  .scan-controls { grid-template-columns: 1fr 1fr; }
  .scan-controls label, .scan-controls input { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .site-header { align-items: flex-start; flex-direction: column; gap: 1rem; }
  .header-actions { width: 100%; }
  .header-actions > * { flex: 1 1 auto; text-align: center; }
  main { padding-inline: .55rem; }
  .panel { padding: .8rem; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .scan-controls { grid-template-columns: 1fr; }
  .scan-controls > * { grid-column: 1; width: 100%; }
  .progress-copy { flex-direction: column; gap: .25rem; }
  .canvas, #source-view { min-height: 18rem; }
  .button-row { width: 100%; }
  .button-row button { flex: 1; }
  .field-row { grid-template-columns: 1fr; }
}
