* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, "Segoe UI", sans-serif;
  color: #1a1a1a;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------- toolbar */
#toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: #2b2f36; color: #e8e8ea;
  font-size: 13px;
  flex: 0 0 auto;
}
#toolbar .brand { font-weight: 700; letter-spacing: 0.4px; margin-right: 6px; }
#toolbar .sep { width: 1px; height: 20px; background: #4a4f58; margin: 0 4px; }
#toolbar label.inline { display: flex; align-items: center; gap: 5px; cursor: pointer; }
#toolbar select { font: inherit; }
#status { margin-left: auto; color: #9fd3a8; font-size: 12px; }

.btn {
  background: #3d434d; color: #e8e8ea; border: 1px solid #565d68;
  border-radius: 6px; padding: 5px 11px; font-size: 13px;
  cursor: pointer; text-decoration: none; display: inline-block;
}
.btn:hover { background: #4a525e; }
.btn.primary { background: #2f6fdd; border-color: #2f6fdd; color: white; }
.btn.primary:hover { background: #3d7ef0; }
.btn.danger { background: #8c2f28; border-color: #8c2f28; color: white; }

/* ------------------------------------------------------------- layout */
main.layer-page {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: var(--lw, 320px) 6px 1fr 6px var(--rw, 400px);
}
main.layer-page[hidden] { display: none; }
/* workflow-layer controls (open / parse / LLM / chart options / exports):
   laid out as if unwrapped; hidden in the Digital twin and motion layers */
#toolbar .wf-only { display: contents; }
body.layer-twin #toolbar .wf-only { display: none; }
#toolbar .layers { display: inline-flex; border: 1px solid #565d68; border-radius: 6px; overflow: hidden; }
#toolbar .layer { background: #3d434d; color: #c9ccd2; border: none; padding: 5px 12px; font-size: 13px; cursor: pointer; }
#toolbar .layer.active { background: #2f6fdd; color: white; }
#toolbar .layer:not(.active):hover { background: #4a525e; }
/* drag handles between the panes (drag to the screen edge to collapse) */
.col-resize { cursor: col-resize; background: #e6e8ec; }
.col-resize:hover, .col-resize.dragging { background: #2f6fdd; }
#drag-left { grid-column: 2; grid-row: 1; }
#drag-right { grid-column: 4; grid-row: 1; }
#left {
  grid-column: 1; min-width: 0; overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid #ddd; background: #fafafa;
}
#left h2, #right h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: #777; margin: 10px 12px 6px;
}
#sop {
  flex: 3 1 0; min-height: 0; resize: none;
  margin: 0 10px; padding: 8px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5;
  border: 1px solid #ccc; border-radius: 6px; background: white;
}
#warnings {
  flex: 2 1 0; min-height: 60px; overflow: auto;
  margin: 0 10px 10px; padding: 6px 6px 6px 22px;
  border: 1px solid #e3e3e3; border-radius: 6px; background: white;
  font-size: 12px;
}
#warnings li { margin: 3px 0; }
#warnings li.ok { color: #1e9e50; list-style: none; margin-left: -16px; }

#center { grid-column: 3; min-width: 0; min-height: 0; display: flex; position: relative; }
#chart { flex: 1; overflow: auto; background: white; cursor: grab; }
#chart:active { cursor: grabbing; }
#chart svg { display: block; }
/* label info: shown iff the label carries .open (app.js computes it from
   the global 'Full label info' mode XOR per-name clicks — spec §5) */
#chart g.label.linfo:not(.open) { display: none; }
#chart g.label:not(.open) .linfo { display: none; }
/* transfer leader variants: tie to the visible words — the whole box in
   full mode (.lfull), the name lines in names-only mode (.lsimp) */
#chart g.label:not(.open) .lfull { display: none; }
#chart g.label.open .lsimp { display: none; }

/* busy overlay (parse in flight) */
#busy {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.66);
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  font-size: 14px; color: #444;
}
#busy[hidden] { display: none; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid #d5dbe7; border-top-color: #2f6fdd;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* while parsing, grey out everything that could interfere */
body.busy #toolbar, body.busy #left, body.busy #right { pointer-events: none; }
body.busy #toolbar .btn, body.busy #toolbar select, body.busy #toolbar label.inline { opacity: 0.45; }
body.busy #left, body.busy #right { opacity: 0.55; }
#warnings li.muted { color: #999; list-style: none; margin-left: -16px; }

/* ------------------------------------------------------------- right */
#right { grid-column: 5; min-width: 0; overflow: hidden; border-left: 1px solid #ddd; display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid #ddd; flex: 0 0 auto; }
.tab {
  flex: 1; padding: 9px 0; border: none; background: #f4f5f7; cursor: pointer;
  font-size: 13px; color: #555;
}
.tab.active { background: white; color: #1a1a1a; font-weight: 600; box-shadow: inset 0 -2px 0 #2f6fdd; }
.tabpage { display: none; flex: 1 1 auto; min-height: 0; overflow: auto; padding: 8px; }
.tabpage.active { display: block; }

#prim-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
#prim-list li {
  padding: 6px 8px; border-radius: 5px; cursor: pointer;
  font-family: ui-monospace, Consolas, monospace;
  border-bottom: 1px solid #f0f0f2;
}
#prim-list li:hover { background: #eef3fd; }
#prim-list li.selected { background: #dbe7fd; }

/* editor */
#ed-empty { color: #888; font-size: 13px; padding: 12px 4px; }
#ed-form .row, #tab-containers .row {
  display: grid; grid-template-columns: 110px 1fr; align-items: center;
  gap: 8px; margin: 6px 0; font-size: 12.5px;
}
#ed-form label { color: #666; text-align: right; }
#ed-form input, #ed-form select {
  width: 100%; padding: 5px 7px; font: inherit;
  border: 1px solid #ccc; border-radius: 5px;
}
#ed-form .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#ed-form fieldset { border: 1px solid #e0e0e4; border-radius: 6px; margin: 8px 0; padding: 4px 8px 8px; }
#ed-form legend { font-size: 11px; color: #999; text-transform: uppercase; }
.row.buttons { display: flex; gap: 8px; grid-template-columns: none; margin-top: 12px; }
#ed-id { font-family: ui-monospace, Consolas, monospace; font-weight: 600; }

/* settings modal */
#settings-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
}
#settings-modal[hidden] { display: none; }
.modal-card {
  width: 460px; background: white; border-radius: 10px; padding: 18px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); font-size: 13px;
}
.modal-card h3 { margin: 0 0 12px; }
.modal-card .row {
  display: grid; grid-template-columns: 90px 1fr; align-items: center;
  gap: 8px; margin: 8px 0;
}
.modal-card .row label { color: #666; text-align: right; }
.modal-card input, .modal-card select {
  width: 100%; padding: 6px 8px; font: inherit;
  border: 1px solid #ccc; border-radius: 5px;
}
.modal-card .row.buttons { display: flex; gap: 8px; grid-template-columns: none; margin-top: 14px; }
.modal-card .hint { color: #999; font-size: 11.5px; margin: 12px 0 0; }
#set-result { min-height: 18px; font-size: 12px; margin-top: 6px; }
#set-result.ok { color: #1e9e50; }
#set-result.err { color: #c0392b; }

/* containers table */
#container-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#container-table th {
  text-align: left; color: #777; font-size: 11px; text-transform: uppercase;
  border-bottom: 1px solid #ddd; padding: 4px;
}
#container-table td { padding: 2px 3px; }
#container-table input { width: 100%; padding: 4px 5px; font: inherit; border: 1px solid #ddd; border-radius: 4px; }
#container-table .row-del {
  border: none; background: none; color: #999; cursor: pointer; font-size: 13px; padding: 2px 4px;
}
#container-table .row-del:hover { color: #c0392b; }

/* PUBLIC MODE (2026-11-01, web/public.py): the real harness, the settings and the files kept on the server are
   blocked in the backend (403); their controls are hidden here — hidden, never deleted (one codebase, two uses). */
body.public #settings-btn, body.public #settings-modal, body.public #harness-modal,
body.public #mo-harness, body.public #mo-teach, body.public #mo-cards,
body.public #mo-flow-real, body.public #mo-flow-stop,
body.public #mo-pick-real, body.public #mo-pick-stop, body.public #mo-weigh-real,
body.public #mo-hotplate-real, body.public #mo-dose-real,
body.public #tw-it-real-row, body.public #mo-restore { display: none !important; }
/* NO DEMOS (operator 2026-11-02, tester 031: "digital twin里面，把demo都删掉"): the Digital twin tab's whole Demo box
   (its buttons, its hide / show toggle, Export for harness) — its Stop moves to Run workflow (twin.js); the public
   server refuses the demo endpoints too (server.py) */
body.public #mo-demo-box, body.embed #mo-demo-box { display: none !important; }
/* EMBED (?embed=1, framed by railab.io): no brand chrome; ?layers=0 also hides the tab switch */
body.embed #toolbar .brand { display: none; }
body.embed.no-layers #toolbar .layers { display: none; }
/* EMBED TOOLBAR (tester 028, operator 2026-11-02: "不要 quick demo。三个export放到角落。open workflow, open sop, save
   workflow放到另一个角落"): no Quick demo; Open workflow / Open SOP / Save workflow at the left after the tab switch,
   Parse + the view options in the middle, Export text / SVG / PNG at the right end (the status line just before them).
   .wf-only is display: contents, so `order` places its children among the toolbar's own; the lab's toolbar is as it
   was. Wraps on a phone (no horizontal scroll). */
body.embed .quick-demo, body.public .quick-demo { display: none !important; }   /* 2026-11-02: no Quick demo on the site */
body.embed #toolbar .sep { display: none; }
body.embed #toolbar .layers { order: -3; }
body.embed #toolbar .tb-file { order: -2; }
body.embed #toolbar #parse-btn { margin-left: 10px; }
body.embed #status { order: 1; min-width: 0; overflow-wrap: anywhere; }
body.embed #toolbar .tb-export { order: 2; }
@media (max-width: 600px) {
  body.embed #toolbar { gap: 6px; padding: 6px 8px; }
  body.embed #toolbar #parse-btn { margin-left: 0; }
  body.embed #toolbar .btn { padding: 4px 8px; }
}
