:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --line: #e3e6ea;
  --line-strong: #c8ccd2;
  --ink: #1f2329;
  --ink-soft: #5b626b;
  --accent: #c0392b;
  --black-marker: #383737;
  --shadow: 0 1px 3px rgba(20, 24, 31, .08), 0 6px 18px rgba(20, 24, 31, .06);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 18px; color: var(--ink-soft); }
.brand h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.brand sup { font-size: 10px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
.topbar-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 12.5px; }
.field select {
  font: inherit; font-size: 13px; color: var(--ink); padding: 5px 8px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); cursor: pointer;
}
.btn {
  font: inherit; font-size: 13px; color: var(--ink); padding: 6px 12px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel); border-color: var(--ink-soft); }
.btn-round { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-weight: 700; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 9px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.modes { display: flex; gap: 18px; font-size: 13px; color: var(--ink); }
.modes label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.flows-toggle { color: var(--ink-soft); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 13px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink);
  cursor: pointer; padding: 2px 4px; border-radius: 5px; user-select: none;
}
.chip .swatch { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }

/* ---------- stage ---------- */
.stage { flex: 1; display: flex; min-height: 0; }
.barcode-pane { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; background: var(--bg); }
.barcode { flex: 1; min-height: 0; }
.barcode svg { display: block; width: 100%; height: 100%; cursor: crosshair; }
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 12px; color: var(--ink-soft); background: rgba(255,255,255,.85);
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); pointer-events: none;
  text-align: center; max-width: 90%;
}

/* barcode marks */
.fill { cursor: pointer; }
.flow { pointer-events: none; }
.xaxis path, .xaxis line { stroke: var(--line-strong); }
.xaxis text { fill: var(--ink-soft); font-size: 12px; }
.marker { cursor: grab; }
.marker.dragging { cursor: grabbing; }
.marker-line { stroke-width: 2px; fill: none; }
.marker-flag text { fill: #fff; font-weight: 600; font-size: 12px; pointer-events: none; }

/* ---------- node-link pane ---------- */
.nl-pane {
  width: 300px; flex: none; border-left: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; position: relative;
}
.nl-pane[hidden] { display: none; }
.nl-close {
  position: absolute; top: 4px; right: 6px; z-index: 3; width: 22px; height: 22px;
  border: none; background: transparent; color: var(--ink-soft); font-size: 18px; cursor: pointer; line-height: 1;
}
.nl-close:hover { color: var(--accent); }
.nl-card { flex: 1; min-height: 0; display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
.nl-card:last-child { border-bottom: none; }
.nl-card.center { box-shadow: inset 3px 0 0 var(--black-marker); }
.nl-card:not(.center) { box-shadow: inset 3px 0 0 var(--accent); }
.nl-card header {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px 5px 12px;
  font-size: 12px; color: var(--ink-soft); background: var(--bg); border-bottom: 1px solid var(--line);
}
.nl-card .nl-name { font-variant-numeric: tabular-nums; white-space: nowrap; }
.nl-card .nl-time {
  width: 62px; font: inherit; font-size: 12px; padding: 2px 5px;
  border: 1px solid var(--line-strong); border-radius: 5px;
}
.nl-card .nl-ok {
  font: inherit; font-size: 12px; padding: 2px 10px; border: 1px solid var(--line-strong);
  border-radius: 5px; background: var(--bg); cursor: pointer;
}
.nl-card .nl-ok:hover { background: var(--panel); border-color: var(--ink-soft); }
.nl-canvas { flex: 1; min-height: 0; position: relative; }
.nl-canvas svg { display: block; width: 100%; height: 100%; cursor: grab; }
.nlnode { stroke: #111; stroke-width: 1.1px; cursor: pointer; }
.nl-edge { stroke: #c9ced4; stroke-width: 1px; }

/* empty state: the pane is always present; cards appear on double-click */
.nl-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 0 22px; color: var(--ink-soft); font-size: 13px; line-height: 1.6;
}
.nl-pane.open .nl-empty { display: none; }
.nl-pane:not(.open) .nl-card { display: none; }
.nl-pane:not(.open) #nl-close { display: none; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: #1f2329; color: #fff;
  font-size: 12px; padding: 6px 9px; border-radius: 6px; box-shadow: var(--shadow);
  white-space: nowrap; transform: translate(-50%, -130%);
}
.tooltip .tt-sub { color: #c8ccd2; }

/* ---------- help ---------- */
.help-panel[hidden] { display: none; }
.help-panel {
  position: fixed; inset: 0; background: rgba(20, 24, 31, .35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.help-card {
  position: relative; background: var(--bg); max-width: 640px; width: calc(100% - 40px);
  max-height: calc(100% - 60px); overflow-y: auto; border-radius: 12px; box-shadow: var(--shadow); padding: 26px 30px;
}
.help-card h2 { margin: 0 0 12px; font-size: 18px; }
.help-card p { line-height: 1.6; }
.help-card a { color: var(--accent); }
.help-table { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 12.5px; }
.help-table th, .help-table td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.help-table th { background: var(--panel); }
.help-table kbd { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 4px; font-size: 11px; }
.help-cite { font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 16px; }
.help-x { position: absolute; top: 14px; right: 14px; }

/* ---------- loading ---------- */
.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--ink-soft); font-size: 15px; z-index: 200; transition: opacity .3s;
}
.loading.hidden { opacity: 0; pointer-events: none; }
