/* ── Theme: Light (default) ── */
:root {
  --bg: #f8f9fa;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --panel-hover: #e9ecef;
  --ink: #1a1a2e;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-2: #f59e0b;
  --accent-3: #3b82f6;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --success: #10b981;
  --grid: rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.05), 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --transition: 180ms ease;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "Fira Code", "Consolas", monospace;
  --brand-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --canvas-bg: #fafbfc;
  --entity-default: #17211d;
  --entity-active: #0f7b6c;
  --entity-current: #d75f35;
  --entity-selected: #2d5f9a;
  --entity-highlight: #b45309;
  --entity-centerline: #c2410c;
  color-scheme: light;
}

/* ── Theme: Dark ── */
[data-theme="dark"] {
  --bg: #0f1117;
  --panel: #1a1b23;
  --panel-2: #21222d;
  --panel-hover: #282938;
  --ink: #e4e4e7;
  --muted: #9ca3af;
  --line: #2d2e3b;
  --line-strong: #3f4050;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-2: #fbbf24;
  --accent-3: #60a5fa;
  --danger: #f87171;
  --danger-bg: #2d1b1b;
  --success: #34d399;
  --grid: rgba(255, 255, 255, 0.03);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.3);
  --brand-gradient: linear-gradient(135deg, #818cf8, #a78bfa);
  --canvas-bg: #16171f;
  --entity-default: #8b949e;
  --entity-active: #34d399;
  --entity-current: #f59e0b;
  --entity-selected: #60a5fa;
  --entity-highlight: #fbbf24;
  --entity-centerline: #fb923c;
  color-scheme: dark;
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

/* ── Typography ── */
h2 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* ── Form Elements ── */
button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius-sm);
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  white-space: nowrap;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--panel-hover);
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

button svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

input,
select,
textarea {
  font: inherit;
  font-size: 13px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 10px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

input[type="number"] {
  font-variant-numeric: tabular-nums;
}

textarea {
  min-height: 100%;
  resize: none;
  font-family: var(--font-mono);
  line-height: 1.5;
}

select {
  cursor: pointer;
}

/* ── Layout ── */
.app-shell {
  display: grid;
  grid-template-columns: 270px minmax(360px, 1fr) 330px;
  grid-template-rows: 52px 40px minmax(0, 1fr);
  gap: 8px;
  height: 100vh;
  padding: 8px;
}

/* ── Topbar ── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--brand-gradient);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.toolbar-sep {
  width: 1px;
  height: 22px;
  margin: 0 6px;
  background: var(--line);
}

.toolbar button,
.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  border-radius: var(--radius-sm);
  min-height: 32px;
  padding: 0 10px;
}

.toolbar .icon-button svg,
.toolbar button svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.toolbar button:hover,
.icon-button:hover {
  background: var(--panel-2);
  color: var(--ink);
  border-color: var(--line);
}

.primary-action {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 600 !important;
}

.primary-action:hover {
  background: var(--accent-hover) !important;
  border-color: var(--accent-hover) !important;
  color: #fff !important;
}

.icon-button input {
  display: none;
}

/* Theme toggle */
#themeToggle {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
}

#themeToggle .icon-sun,
#themeToggle .icon-moon {
  width: 18px;
  height: 18px;
  transition: transform var(--transition), opacity var(--transition);
}

[data-theme="dark"] #themeToggle .icon-moon { display: none; }
[data-theme="dark"] #themeToggle .icon-sun { display: block; }
#themeToggle .icon-sun { display: none; }
#themeToggle .icon-moon { display: block; }

/* ── Panels ── */
.panel {
  min-height: 0;
  overflow: auto;
  background: var(--panel);

  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.panel section + section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.left-panel {
  grid-column: 1;
  grid-row: 3 / 4;
}

.right-panel {
  grid-column: 3;
  grid-row: 3 / 4;
}

.step-scroll {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-scroll > section + .step-sections,
.step-scroll > .step-sections + .step-sections {
  margin-top: 4px;
}

/* ── Collapsible sections ── */
.collapsible-section > h2 {
  margin-bottom: 8px;
}

.section-toggle {
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: 0 !important;
  background: transparent !important;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.section-toggle:hover {
  color: var(--ink) !important;
}

.section-toggle-icon::before {
  content: "▾";
  display: block;
  font-size: 10px;
  line-height: 1;
  transition: transform var(--transition);
}

.collapsible-section.collapsed .section-toggle-icon::before {
  content: "▸";
}

.collapsible-section.collapsed .collapsible-content {
  display: none;
}

/* ── Stepper ── */
.stepper {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stepper-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.stepper-step:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.stepper-num {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 700;
}

.stepper-step.active {
  color: #fff;
  background: var(--accent);
}

.stepper-step.active .stepper-num {
  background: rgba(255, 255, 255, 0.2);
  border-color: transparent;
}

.stepper-step.done {
  color: var(--ink);
}

.stepper-step.done .stepper-num {
  background: var(--success);
  border-color: transparent;
  color: #fff;
  font-size: 0;
}

.stepper-step.done .stepper-num::after {
  content: "✓";
  font-size: 12px;
  font-weight: 800;
}

.stepper-link {
  width: 26px;
  height: 1px;
  background: var(--line-strong);
}

/* ── Step sections (right panel) ── */
.step-sections[hidden],
.step-hint[hidden] {
  display: none;
}

.step-sections > section + section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.step-hint {
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 14px;
}

.step-hint strong {
  display: block;
  color: var(--ink);
  margin-bottom: 2px;
}

/* ── Generate panel (krok 4) ── */
.generate-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.generate-panel[hidden] {
  display: none;
}

.generate-description {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.generate-actions {
  display: flex;
  gap: 6px;
}

.generate-actions button {
  flex: 1;
  min-height: 36px;
}

.action-summary {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  min-height: 15px;
}

.action-summary .summary-warn {
  color: var(--danger);
  font-weight: 600;
}

.action-summary .summary-ok {
  color: var(--success);
  font-weight: 600;
}

/* ── Workspace ── */
.workspace {
  grid-column: 2;
  grid-row: 3 / 4;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 34px;
  gap: 6px;
}

.drop-zone {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background-color: var(--canvas-bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.drop-zone.dragging {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  pointer-events: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ruler {
  position: absolute;
  background: rgba(128, 128, 128, 0.06);
  pointer-events: none;
}

.ruler-x {
  left: 0; right: 0; top: 0;
  height: 22px;
  border-bottom: 1px solid var(--line);
}

.ruler-y {
  top: 0; bottom: 0; left: 0;
  width: 22px;
  border-right: 1px solid var(--line);
}

/* ── Statusbar ── */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.statusbar span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  min-height: 36px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  background: transparent;
  font-weight: 600;
}

.tab:hover {
  color: var(--ink);
  background: var(--panel-2);
}

.tab-page {
  display: none;
  min-height: 0;
}

.tab-page.active {
  display: block;
  height: 100%;
}

/* ── NC panel (krok 5, prawy panel) ── */
.nc-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.nc-panel[hidden] {
  display: none;
}

.nc-tabs {
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
}

.nc-panel .tab-page.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.nc-panel #gcodeTab.active {
  height: 52vh;
  min-height: 280px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.nc-panel #reportTab.active,
.nc-panel #batchTab.active {
  height: 52vh;
  min-height: 280px;
  flex: 0 0 auto;
  overflow: auto;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 10px 12px;
}

.nc-panel #reportTab.active {
  padding: 0;
}

.nc-panel #reportTab.active pre {
  margin: 0;
  padding: 10px 12px;
}

/* ── G-code pane ── */
.gcode-pane {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas-bg);
}

.gcode-pane textarea,
.gcode-pane pre {
  position: absolute;
  inset: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 10px 12px;
  overflow: auto;
  white-space: pre;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  tab-size: 2;
}

.gcode-pane textarea {
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: var(--ink);
  resize: none;
}

.gcode-pane textarea::selection {
  background: rgba(99, 102, 241, 0.2);
}

.gcode-pane pre {
  z-index: 1;
  pointer-events: none;
  color: var(--ink);
}

.gc-row {
  display: block;
  min-height: 1.55em;
}

.gc-row.active {
  background: rgba(245, 158, 11, 0.12);
  box-shadow: inset 3px 0 0 var(--accent-2);
}

.gc-comment { color: var(--muted); font-style: italic; }
.gc-line   { color: #b45309; }
.gc-rapid  { color: var(--danger); font-weight: 700; }
.gc-feed   { color: var(--success); font-weight: 700; }
.gc-arc    { color: var(--accent-3); font-weight: 700; }
.gc-cycle  { color: #a855f7; font-weight: 700; }
.gc-mcode  { color: var(--accent-2); font-weight: 700; }
.gc-word   { color: var(--ink); }

[data-theme="dark"] .gc-comment { color: #6b7280; }
[data-theme="dark"] .gc-line   { color: #fbbf24; }
[data-theme="dark"] .gc-rapid  { color: #f87171; }
[data-theme="dark"] .gc-feed   { color: #34d399; }
[data-theme="dark"] .gc-arc    { color: #60a5fa; }
[data-theme="dark"] .gc-cycle  { color: #c084fc; }
[data-theme="dark"] .gc-mcode  { color: #fbbf24; }
[data-theme="dark"] .gc-word   { color: #e4e4e7; }

/* ── Lists: workflow, layers, stats, contours, zones, batch ── */
.workflow {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 6px;
}

.workflow li,
.list-row,
.operation-row,
.contour-row,
.batch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  transition: all var(--transition);
}

.workflow li:hover,
.list-row:hover,
.contour-row:hover {
  border-color: var(--line-strong);
}

.workflow li.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
  font-weight: 600;
}

.workflow li.done {
  border-color: var(--success);
}

.workflow li.done::after {
  content: "✓";
  color: var(--success);
  font-weight: 700;
  font-size: 12px;
}

/* ── Warstwy ── */
.layers-list {
  display: grid;
  gap: 6px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  transition: border-color var(--transition), opacity var(--transition);
}

.layer-row:hover {
  border-color: var(--line-strong);
}

.layer-row.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.07);
}

.layer-row.layer-off {
  opacity: 0.55;
}

.layer-row-left {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.layer-radio {
  accent-color: var(--accent);
  cursor: pointer;
}

.layer-visibility {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin: 0;
}

.layer-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(127, 127, 127, 0.4);
  display: inline-block;
}

.layer-name {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 2px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  min-width: 18px;
  text-align: right;
}

.layer-delete {
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--danger, #b3261e);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 3px 6px;
}

.layer-delete:hover {
  border-color: var(--danger, #b3261e);
}

.add-layer-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.add-layer-row input {
  flex: 1;
  min-width: 0;
}

.contour-row {
  align-items: center;
  position: relative;
  cursor: pointer;
}

.contour-row.active {
  border-color: var(--entity-highlight);
  background: rgba(180, 83, 9, 0.08);
}

.contour-row.editing {
  border-color: var(--entity-selected);
  background: rgba(45, 95, 154, 0.1);
  outline: 1px dashed var(--entity-selected);
  outline-offset: -3px;
}

.contour-edit-bar {
  margin-bottom: 10px;
  border-radius: 8px;
}

.contour-edit-bar .contour-row {
  border-color: var(--entity-selected);
  background: rgba(45, 95, 154, 0.1);
}

.contour-row-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.contour-row-actions button {
  min-height: 24px;
  padding: 0 7px;
  font-size: 10px;
}

.contour-name-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.contour-name-form input {
  flex: 1;
  min-width: 0;
}

.contour-name-editor {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
}

.contour-name-editor input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 6px;
}

.contour-name-editor .rename-ok {
  flex-shrink: 0;
  min-height: 26px;
  padding: 0 8px;
  font-size: 11px;
}

.contour-name-editor .rename-cancel {
  flex-shrink: 0;
  min-height: 26px;
  padding: 0 8px;
  font-size: 11px;
}

.contour-row input[type="checkbox"] {
  width: auto;
  flex-shrink: 0;
}

.contour-row .contour-meta {
  flex: 1;
  min-width: 0;
}

.contour-row .contour-meta strong,
.contour-row .contour-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contour-row .contour-meta span {
  color: var(--muted);
  font-size: 11px;
}

.contour-row select {
  width: 132px;
}

.operation-select-row {
  align-items: center;
}

.operation-select-row.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.operation-row.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.operation-actions {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.operation-actions button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 11px;
}

/* ── Batch ── */
.batch-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  padding: 10px 12px 0;
}

.batch-list {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
}

.batch-row {
  align-items: center;
}

.batch-row.done {
  border-color: rgba(16, 185, 129, 0.35);
}

.batch-row.error {
  border-color: rgba(239, 68, 68, 0.35);
}

.batch-meta {
  min-width: 0;
}

.batch-meta strong,
.batch-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-meta span {
  color: var(--muted);
  font-size: 11px;
}

/* ── Zones ── */
.zones-list {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.zone-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.zone-row button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
}

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.stat {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  transition: border-color var(--transition);
}

.stat:hover {
  border-color: var(--line-strong);
}

.stat span {
  color: var(--muted);
  font-size: 11px;
  display: block;
}

.stat strong {
  display: block;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 2px;
}

.muted-box {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0;
}

/* ── Form grid ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.checkbox-field {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.checkbox-field input {
  width: auto;
}

.wide-field {
  grid-column: 1 / -1;
}

.wide-field textarea {
  min-height: 72px;
}

/* ── Metric & tool rows ── */
.metric-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-top: 10px;
}

.segmented {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-row {
  margin-top: 8px;
  flex-wrap: wrap;
}

.tool-row button.active {
  border-color: var(--accent-3);
  background: rgba(59, 130, 246, 0.08);
  color: var(--accent-3);
  font-weight: 700;
}

.new-tool-hint {
  font-size: 10px;
  color: var(--muted);
  line-height: 1.4;
  max-width: 240px;
}

.edit-options {
  margin-top: 8px;
}

.metric {
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* ── Operations thumbnail grid ── */
.operations-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.operation-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: all var(--transition);
  position: relative;
}

.operation-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.operation-card[draggable="true"] {
  cursor: grab;
}

.operation-card.dragging {
  opacity: 0.45;
}

.operation-card.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 1px;
}

.operation-card.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.04);
}

.operation-card-header {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.operation-card-header input[type="checkbox"] {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin: 2px 0 0;
}

.operation-card-header .card-title {
  flex: 1 1 120px;
  min-width: 0;
  overflow: hidden;
}

.operation-card-header .card-title strong {
  display: block;
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-card-header .card-title span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-card-body {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
}

.operation-thumb {
  display: grid;
  place-items: center;
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  position: relative;
  overflow: hidden;
}

.operation-thumb svg {
  width: 46px;
  height: 46px;
  color: var(--muted);
  opacity: 0.6;
}

.operation-thumb .thumb-label {
  position: absolute;
  bottom: 3px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.operation-tool-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  min-width: 0;
}

.operation-tool-info .tool-name,
.tool-edit .tool-name {
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-tool-info .tool-params,
.tool-edit .tool-params {
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-continue {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 4px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
}

.tool-edit {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: all var(--transition);
}

.tool-edit:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.tool-edit:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.operation-tool-select {
  width: 100%;
  min-height: 24px;
  margin-top: 4px;
  padding: 2px 4px;
  font-size: 11px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.operation-card-footer {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.operation-card-footer button {
  flex: 1;
  min-height: 26px;
  padding: 0 8px;
  font-size: 11px;
  justify-content: center;
}

.operation-card-meta {
  font-size: 10px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

.op-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.op-badge-ok {
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
}

.op-badge-warn {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
}

.operation-card.is-disabled {
  opacity: 0.55;
}

.operation-card.is-disabled .operation-thumb {
  filter: grayscale(1);
}

.operation-card.is-missing .operation-card-header .card-title strong::after {
  content: " — brak konturow";
  color: var(--danger);
  font-weight: 600;
}

/* ── Operations grouped by tool ── */
.tool-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.tool-group-toggle input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

.operation-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 11px;
  min-width: 0;
}

.operation-group-head:not(:first-child) {
  margin-top: 6px;
}

.operation-group-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.operation-group-title strong {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-group-title span {
  color: var(--muted);
  flex-shrink: 0;
}

.operation-group-tool {
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  animation: fadeIn 200ms ease;
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  width: min(960px, 100%);
  max-height: min(86vh, 860px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-lg);
  animation: slideUp 250ms ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

#operationDialog {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.modal-header,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 15px;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.modal-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.operation-modal-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 18px 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.operation-tab-button {
  min-height: 34px;
  border-bottom-color: transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.operation-tab-button.active {
  border-color: var(--line);
  border-bottom-color: var(--panel);
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
}

.operation-tab-button .tab-check {
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 10px;
  font-weight: 700;
  color: transparent;
  vertical-align: middle;
}

.operation-tab-button.done .tab-check {
  background: var(--success);
  border-color: transparent;
  color: #fff;
}

.modal-body {
  overflow: auto;
  padding: 18px;
}

.modal-body section + section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.modal-body .operation-tab-panel {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.operation-tab-panel h2 + .form-grid,
.operation-tab-panel .form-grid + h2 {
  margin-top: 14px;
}

.contour-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 8px;
  margin-top: 12px;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.project-modal-card {
  width: min(640px, 100%);
}

/* ── Projects list ── */
.projects-list {
  display: grid;
  gap: 6px;
  min-height: 80px;
}

.project-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  transition: all var(--transition);
}

.project-row:hover {
  border-color: var(--line-strong);
}

.project-row.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.06);
}

.project-meta {
  min-width: 0;
}

.project-meta strong,
.project-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-meta strong {
  font-size: 13px;
}

.project-meta span {
  color: var(--muted);
  font-size: 11px;
}

.project-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Scrollbar ── */
.panel::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.gcode-pane textarea::-webkit-scrollbar,
.gcode-pane pre::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.panel::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb,
.gcode-pane textarea::-webkit-scrollbar-thumb,
.gcode-pane pre::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

.panel::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--line-strong);
}

/* ── Responsive ── */
@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto 56vh auto;
    height: auto;
    min-height: 100vh;
  }

  .topbar,
  .stepper,
  .left-panel,
  .workspace,
  .right-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .topbar,
  .toolbar {
    flex-wrap: wrap;
  }

  .stepper {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .left-panel,
  .right-panel {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .form-grid,
  .operations-grid,
  .contour-summary,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .empty-state strong {
    font-size: 20px;
  }
}
