* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: #1e2229; color: #d7dae0;
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
}

header {
  background: #15181d; border-bottom: 1px solid #2c3138;
  padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
header h1 { font-size: 16px; margin: 0; color: #e6e8eb; font-weight: 600; }
header h1 span { color: #7cc7ff; font-family: monospace; }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.controls button {
  background: #2b3138; color: #e6e8eb; border: 1px solid #3a4048;
  padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 13px;
  transition: background .15s;
}
.controls button:hover { background: #39404a; }
.controls button:disabled { opacity: .4; cursor: not-allowed; }
.controls .sep { width: 1px; height: 20px; background: #2c3138; margin: 0 4px; }
.controls .speed {
  font-size: 12px; color: #98a0aa;
  display: flex; gap: 6px; align-items: center;
}
.controls label.opt {
  font-size: 12px; color: #98a0aa;
  display: flex; gap: 6px; align-items: center;
}
.controls label.opt input[type="number"] {
  width: 76px; background: #15181d; color: #d7dae0;
  border: 1px solid #2c3138; border-radius: 3px;
  font-family: monospace; font-size: 12px; padding: 3px 5px;
}
.controls label.opt input[type="checkbox"] { accent-color: #7cc7ff; }
.status {
  font-size: 12px; color: #7cc7ff;
  background: #182430; padding: 4px 10px; border-radius: 4px;
  border: 1px solid #234052;
}

main {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr 300px 14%;
  grid-template-rows: 1fr 320px;
  gap: 1px; background: #2c3138;
}
aside, section {
  background: #1e2229; padding: 10px 14px;
  overflow: auto; min-height: 0;
}
aside h2, section h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: #98a0aa; margin: 10px 0 8px; font-weight: 600;
}
aside h2:first-child, section h2:first-child { margin-top: 0; }

#leftPanel  { grid-column: 1; grid-row: 1; }
#viewerPanel { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; }
#varsPanel  { grid-column: 3; grid-row: 1; }
#motionPanel { grid-column: 1 / 4; grid-row: 2; padding: 8px 14px; overflow: hidden; }
#logPanel {
  grid-column: 4; grid-row: 1 / 3; padding: 10px 12px;
  overflow: hidden; display: flex; flex-direction: column;
  background: #15181d; border-left: 1px solid #2c3138;
}
#logPanel h2 { flex: 0 0 auto; }

/* dwa okna kodu: program główny | program wywoływany */
#codeSplit {
  display: flex; gap: 6px; flex: 1 1 auto; min-height: 0;
}
.code-pane {
  flex: 1 1 50%; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
}
.code-pane h2 { flex: 0 0 auto; margin: 0 0 4px; display: flex; align-items: center; gap: 6px; }
.pane-empty { padding: 16px 10px; color: #7d8794; font-size: 12px; font-family: "Segoe UI", Roboto, Arial, sans-serif; }
.pane-empty.warn { color: #f0b94a; }

/* ręczne zakresy osi – w pasku nad wizualizacją */
.lim-group {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 2px 6px; border: 1px solid #2c3138; border-radius: 4px; background: #1e2228;
}
.lim-cap { color: #98a0aa; font-size: 11.5px; }
.lim-item {
  display: inline-flex; align-items: center; gap: 3px;
  color: #8d959f; font-size: 11.5px;
  font-family: "Consolas", "Courier New", monospace;
}
.lim-item input[type="number"] {
  width: 52px; min-width: 0; background: #171b21; color: #e6e8eb;
  border: 1px solid #333941; border-radius: 3px; padding: 1px 3px; font-size: 11.5px;
}
.lim-item input[type="number"]:focus { border-color: #7cc7ff; outline: none; }
.lim-item input[type="number"]::placeholder { color: #4e5661; }

/* powiększenie wizualizacji: duże 3D + okna programów obok (ESC wraca) */
body.zoom-view main { grid-template-columns: 1fr 460px; grid-template-rows: 1fr; }
body.zoom-view #leftPanel,
body.zoom-view #varsPanel,
body.zoom-view #logPanel { display: none; }
body.zoom-view #motionPanel { grid-column: 1; grid-row: 1; }
body.zoom-view #motionPanel .motion-body { grid-template-columns: 1fr 300px; }
body.zoom-view #viewerPanel { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; min-width: 0; }
/* przy powiększeniu oba programy stoją jeden pod drugim – tak jest czytelniej */
body.zoom-view #codeSplit { flex-direction: column; }
body.zoom-view .code-pane { flex: 1 1 50%; }

.prog-list {
  list-style: none; padding: 0; margin: 0 0 12px;
  max-height: 140px; overflow: auto;
  font-family: monospace; font-size: 12px;
}
.prog-list li {
  padding: 3px 6px; border-left: 3px solid #3a4048;
  background: #232830; margin-bottom: 3px; border-radius: 3px;
  cursor: pointer; color: #cfd4dc;
  display: flex; justify-content: space-between; gap: 8px;
}
.prog-list li:hover { background: #2a3038; }
.prog-list li.active { border-left-color: #7cc7ff; }
.prog-list li .fn { color: #7d8794; font-size: 11px; }

#stack {
  list-style: none; padding: 0; margin: 0 0 12px;
  font-family: monospace; font-size: 12px;
}
#stack li {
  padding: 4px 8px; border-left: 3px solid #7cc7ff;
  background: #232830; margin-bottom: 4px; border-radius: 3px;
  color: #cfd4dc; word-break: break-all;
}
#stack li .via { color: #7cc7ff; }
#stack li .ln { color: #7d8794; }
#stack li.caller { border-left-color: #f0b94a; }

.hint { font-size: 11px; color: #7d8794; margin: 6px 0 10px; }

#initVars {
  width: 100%; background: #15181d; color: #d7dae0;
  border: 1px solid #2c3138; border-radius: 3px;
  font-family: monospace; font-size: 12px; padding: 6px;
  resize: vertical;
}
#startProg {
  width: 80px; background: #15181d; color: #d7dae0;
  border: 1px solid #2c3138; border-radius: 3px;
  font-family: monospace; font-size: 12px; padding: 4px 6px;
}
button.small { padding: 3px 8px; font-size: 12px; background: #2b3138;
  color: #e6e8eb; border: 1px solid #3a4048; border-radius: 3px; cursor: pointer; }
button.small:hover { background: #39404a; }

/* viewer */
.viewer {
  position: relative;   /* offsetTop linii liczony względem kontenera kodu */
  font-family: "Consolas", "Fira Mono", monospace;
  font-size: 12.5px; line-height: 1.45;
  white-space: pre; background: #15181d;
  border: 1px solid #2c3138; border-radius: 4px;
  padding: 6px 0; overflow: auto; flex: 1 1 auto;
}
.viewer .line { display: flex; }
.viewer .ln {
  flex: 0 0 46px; text-align: right; padding-right: 10px;
  color: #4b535e; user-select: none;
  border-right: 1px solid #232830;
}
.viewer .src { padding: 0 10px; color: #cbd1d9; white-space: pre; }
.viewer .line.current { background: #2b3a4a; }
.viewer .line.current .src { color: #ffffff; font-weight: 600; }
.viewer .line.current .ln { color: #7cc7ff; }
.viewer .line.header { color: #4b535e; font-style: italic; }
.viewer .line.empty { opacity: .3; }
.viewer .line.comment .src { color: #6a7581; }
/* linie „!” – wykonuje je tylko tracer; do produkcji nie trafiają */
.viewer .line.tracer-only { background: #2a2416; box-shadow: inset 3px 0 0 #f0b94a; }
.viewer .line.tracer-only .src { color: #f0c46a; }
.viewer .line.tracer-only .ln { color: #f0b94a; }
.viewer .line.tracer-only.current { background: #3a3320; }
.viewer .line.tracer-only.current .src { color: #ffe0a3; }
.only-badge {
  background: #3a2f16; border: 1px solid #6b5520; color: #f0b94a;
  border-radius: 3px; padding: 0 5px; font-size: 10.5px; font-weight: 600;
  font-family: "Consolas", "Courier New", monospace;
}

/* ---------- edytor kodu w oknie programu ---------- */
.code-pane h2 .pane-edit { margin-left: auto; }
.code-pane h2 .only-badge { margin-left: 4px; }
.pane-editor {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 4px;
  font-family: "Consolas", "Courier New", monospace;
}
.ed-tools {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap; flex: 0 0 auto;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}
.ed-prog { color: #7cc7ff; font-weight: 600; font-size: 11.5px; }
.ed-hint { color: #8d959f; font-size: 10.5px; }
.ed-src {
  flex: 1 1 auto; min-height: 0; width: 100%; resize: none;
  background: #10141a; color: #d7dde5; border: 1px solid #7cc7ff; border-radius: 4px;
  padding: 6px 8px; font-family: "Consolas", "Courier New", monospace;
  font-size: 12px; line-height: 1.45; white-space: pre; overflow: auto;
}
.ed-src:focus { outline: none; box-shadow: 0 0 0 1px #7cc7ff55; }

/* edytor z numeracją – ta sama siatka linii co okno przebiegu (18 px/linia) */
.ed-body {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; gap: 0;
  background: #10141a; border: 1px solid #7cc7ff; border-radius: 4px;
  overflow: hidden;
}
.ed-gutter {
  flex: 0 0 44px; overflow: hidden; padding: 6px 6px 6px 0;
  text-align: right; user-select: none;
  color: #5a6470; font-family: "Consolas", "Courier New", monospace;
  font-size: 12px; line-height: 18px;
  background: #0d1117; border-right: 1px solid #232a33;
}
.ed-gutter .ed-ln { height: 18px; }
.ed-gutter .ed-ln.caret { color: #cbd1d9; }
.ed-gutter .ed-ln.current {
  color: #7cc7ff; font-weight: 700;
  background: #1b2a3a; box-shadow: inset -2px 0 0 #7cc7ff;
}
.ed-band {
  position: absolute; left: 44px; right: 0; height: 18px;
  background: #2b3a4a; border-radius: 2px; display: none;
  pointer-events: none; z-index: 0;
}
.ed-body .ed-src {
  flex: 1 1 auto; min-width: 0; border: 0; border-radius: 0;
  background: transparent; position: relative; z-index: 1;
  padding: 6px 8px; line-height: 18px; font-size: 12px;
}
.ed-body .ed-src:focus { box-shadow: none; }

.view-banner {
  background: #2b3a4a; border: 1px solid #3a5a7a;
  padding: 6px 10px; border-radius: 4px; margin-bottom: 6px;
  font-size: 12px; display: flex; justify-content: space-between; align-items: center;
  color: #cfd4dc;
}
.view-banner button {
  background: #3a4a5a; color: #d7dae0; border: 1px solid #4a5a6a;
  padding: 2px 8px; border-radius: 3px; cursor: pointer; font-size: 11px;
}
.view-banner button:hover { background: #4a5a6a; }

/* baner wykrytej pętli nieskończonej */
.loop-banner {
  background: #3a2b16; border: 1px solid #7a5a20;
  border-radius: 4px; margin-bottom: 6px; padding: 6px 10px;
  font-size: 12px; color: #f0c07a;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.loop-banner .loop-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.loop-banner button {
  background: #4a3a1a; color: #f0c07a; border: 1px solid #7a5a20;
  padding: 2px 8px; border-radius: 3px; cursor: pointer; font-size: 11px;
}
.loop-banner button:hover { background: #5a4a24; }
.loop-banner button:disabled { opacity: .5; cursor: not-allowed; }

/* baner pauzy na ruchu G0/G1 */
.motion-banner {
  background: #1b2b33; border: 1px solid #2b5566;
  border-radius: 4px; margin-bottom: 6px; padding: 5px 10px;
  font-size: 12px; color: #9fd8e8;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.motion-banner button {
  background: #22414d; color: #9fd8e8; border: 1px solid #2b5566;
  padding: 2px 8px; border-radius: 3px; cursor: pointer; font-size: 11px;
}
.motion-banner button:hover { background: #2b5364; }

.badge {
  font-family: monospace; color: #7cc7ff;
  background: #182430; border: 1px solid #234052;
  padding: 1px 6px; border-radius: 3px; margin-left: 6px;
  text-transform: none; letter-spacing: 0;
}

/* vars */
.vars { font-family: monospace; font-size: 12px; }
.vars .row {
  display: flex; justify-content: space-between;
  padding: 2px 6px; border-bottom: 1px solid #232830;
}
.vars .row .k { color: #f0b94a; }
.vars .row .v { color: #cbd1d9; }
.vars .vempty { color: #7d8794; padding: 3px 6px; }

/* przełącznik „ukryj zmienne = 0” – w panelu i w oknie powiększenia */
.zero-opt {
  display: flex; align-items: center; gap: 4px;
  text-transform: none; letter-spacing: 0;
  color: #8d959f; font-size: 11px; cursor: pointer; margin-bottom: 6px;
}

/* Okno „Zmienne w bieżącej sesji” w powiększeniu – pod zmiennymi bieżącej linii.
   W normalnym widoku tę listę pokazuje panel #varsPanel, więc tu jest schowane. */
#sessionVarsBox { display: none; }
body.zoom-view #sessionVarsBox {
  display: flex; flex-direction: column; gap: 3px;
  flex: 1 1 auto; min-height: 0;
}
#sessionVarsBox .vars-head {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 3px 8px;
}
#sessionVarsBox .vars-head > span { flex: 1 1 auto; min-width: 0; }
#sessionVarsBox .zero-opt { margin-bottom: 0; font-size: 10.5px; }
#sessionVarsBox .vars {
  flex: 1 1 auto; overflow: auto; min-height: 60px;
  background: #15181d; border: 1px solid #2c3138; border-radius: 4px;
  padding: 2px 0;
}

/* motion panel */
#motionPanel {
  display: flex; flex-direction: column;
}
.motion-head {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 6px; flex-wrap: wrap;
}
.motion-head h2 { margin: 0; }
.motion-head .sep { width: 1px; height: 20px; background: #2c3138; margin: 0 4px; }
.motion-head .speed {
  font-size: 12px; color: #98a0aa;
  display: flex; gap: 6px; align-items: center;
}
.motion-head .speed input[type="range"] { width: 120px; accent-color: #7cc7ff; }
.motion-head button {
  background: #2b3138; color: #e6e8eb; border: 1px solid #3a4048;
  padding: 5px 10px; border-radius: 4px; cursor: pointer; font-size: 12.5px;
}
.motion-head button:hover { background: #39404a; }
.motion-head button:disabled { opacity: .4; cursor: not-allowed; }
.motion-head .view-opts { display: flex; gap: 4px; }
.motion-head label.opt {
  font-size: 11.5px; color: #98a0aa;
  display: flex; gap: 5px; align-items: center;
}
.motion-head label.opt select,
.motion-head label.opt input[type="number"] {
  background: #15181d; color: #d7dae0; border: 1px solid #2c3138;
  border-radius: 3px; font-family: monospace; font-size: 11.5px; padding: 2px 4px;
}
.motion-head label.opt input[type="number"] { width: 64px; }
.motion-head label.opt input[type="checkbox"] { accent-color: #7cc7ff; }
.motion-head label.opt input:disabled { opacity: .4; }
.motion-legend {
  display: flex; gap: 10px; font-size: 11px; color: #98a0aa;
}
.motion-legend i {
  display: inline-block; width: 14px; height: 3px;
  vertical-align: middle; margin-right: 4px; border-radius: 2px;
}
.motion-legend .sw-rapid { background: #f0b94a; }
.motion-legend .sw-feed  { background: #7cc7ff; }
.motion-pos {
  font-family: monospace; font-size: 12px; color: #cfd4dc;
  background: #182430; border: 1px solid #234052;
  padding: 3px 8px; border-radius: 3px; margin-left: auto;
}
.motion-body {
  display: grid; grid-template-columns: 1fr 300px;
  gap: 10px; flex: 1 1 auto; min-height: 0;
}
.canvas-wrap {
  position: relative; background: #15181d;
  border: 1px solid #2c3138; border-radius: 4px;
  overflow: hidden; min-height: 0;
}
.canvas-wrap canvas { display: block; width: 100%; height: 100%; }

/* etykiety: współrzędne (bezwzględne/względne) i zmienne bieżącej linii */
.readouts {
  display: flex; flex-direction: column; gap: 6px;
  overflow: auto; min-height: 0;
  font-family: monospace; font-size: 12px;
}
.rd-row {
  background: #182430; border: 1px solid #234052; border-radius: 4px;
  padding: 4px 8px; display: flex; flex-direction: column; gap: 2px;
}
.rd-label { color: #7d8794; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; }
.rd-val { color: #cbd1d9; white-space: nowrap; }
.rd-val b { color: #7cc7ff; font-weight: 600; }
.rd-val i { color: #f0b94a; font-style: normal; }
.vars-head { margin-top: 2px; }
.cur-vars {
  background: #15181d; border: 1px solid #2c3138; border-radius: 4px;
  padding: 4px 6px; flex: 1 1 auto; overflow: auto; min-height: 40px;
  display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px;
}
.cur-vars .vchip {
  background: #232830; border: 1px solid #2c3138; border-radius: 3px;
  padding: 1px 5px; color: #cbd1d9; font-size: 11.5px;
}
.cur-vars .vchip .nm { color: #f0b94a; }
.cur-vars .vchip.mach { border-color: #4a3a1a; }
.cur-vars .vchip.mach .nm { color: #c9a6ff; }
.cur-vars .vchip.undef { opacity: .6; }
.cur-vars .vempty { color: #4b535e; font-size: 11.5px; }

/* log wykonania – prawa kolumna, 20% szerokości */
.log { font-family: monospace; font-size: 12px; line-height: 1.5; flex: 1 1 auto; overflow: auto; min-height: 0; }
.hint-inline {
  text-transform: none; letter-spacing: 0; color: #4b535e;
  font-weight: 400; margin-left: 6px;
}
.log { font-family: monospace; font-size: 12px; line-height: 1.5; }
.log .entry {
  padding: 1px 4px; color: #cbd1d9; border-radius: 3px;
  white-space: pre-wrap; word-break: break-word;
}
.log .entry.info { color: #7cc7ff; }
.log .entry.warn { color: #f0b94a; }
.log .entry.error { color: #ff7b7b; }
.log .entry .prog { color: #7d8794; margin-right: 6px; }
.log .entry.clickable { cursor: pointer; }
.log .entry.clickable:hover { background: #232830; }
.log .entry.clickable:active { background: #2b3a4a; }

/* drop overlay */
.drop-overlay {
  position: fixed; inset: 0; display: none;
  background: rgba(10,14,20,.72);
  align-items: center; justify-content: center; z-index: 9999;
  backdrop-filter: blur(2px);
}
.drop-overlay.visible { display: flex; }
.drop-box {
  border: 2px dashed #7cc7ff; border-radius: 10px;
  padding: 40px 60px; color: #d7dae0; text-align: center;
  background: #1a2029; font-size: 15px;
}
.drop-icon { font-size: 42px; color: #7cc7ff; margin-bottom: 8px; }
.drop-hint { font-size: 12px; color: #7d8794; margin-top: 8px; }