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

:root {
  /* Zinc scale */
  --zinc-950: #09090b;
  --zinc-900: #18181b;
  --zinc-800: #27272a;
  --zinc-700: #3f3f46;
  --zinc-600: #52525b;
  --zinc-500: #71717a;
  --zinc-400: #a1a1aa;
  --zinc-300: #d4d4d8;
  --zinc-200: #e4e4e7;
  --zinc-100: #f4f4f5;
  --zinc-50:  #fafafa;

  /* Semantic surface tokens */
  --bg:         var(--zinc-950);
  --bg2:        var(--zinc-900);
  --bg3:        var(--zinc-800);
  --border:     var(--zinc-800);
  --border2:    var(--zinc-700);

  /* Text */
  --text:        var(--zinc-50);
  --text-dim:    var(--zinc-400);
  --text-faint:  var(--zinc-600);

  /* Electric lemon accent */
  --accent:      #c8ff00;
  --accent-dim:  #90b800;
  --accent-glow: rgba(200, 255, 0, 0.12);
  --accent-fg:   #09090b;

  /* Semantic colors */
  --green:   #4ade80;
  --blue:    #60a5fa;
  --yellow:  #fbbf24;
  --red:     #f87171;
  --purple:  #a78bfa;

  /* Layout */
  --header-h:  52px;
  --sidebar-w: 244px;
  --exec-w:    264px;
  --log-h:     196px;
  --radius:    8px;
  --radius-sm: 6px;
  --radius-xs: 4px;

  /* Typography */
  --font:      "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", ui-sans-serif, sans-serif;
  --font-mono: "Cascadia Code", "JetBrains Mono", "Fira Code", "Consolas", monospace;

  --ease: 0.15s ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Base resets ─────────────────────────────────────────────────────────── */
button {
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  border: none;
  background: none;
  line-height: 1;
}

input, select, textarea {
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  outline: none;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--zinc-700); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--zinc-600); }

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

/* ── Brand ───────────────────────────────────────────────────────────────── */
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 128px;
  flex-shrink: 0;
}
.brand-icon { width: 22px; height: 22px; flex-shrink: 0; }
.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--zinc-50);
  white-space: nowrap;
}
.brand-name em {
  font-style: normal;
  color: var(--accent);
}

/* ── Job bar ─────────────────────────────────────────────────────────────── */
.job-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Connection bar ──────────────────────────────────────────────────────── */
.connection-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

/* Segmented mode toggle */
.conn-mode-toggle {
  display: flex;
  background: var(--zinc-800);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}
.conn-mode-btn {
  background: transparent;
  color: var(--zinc-500);
  border: none;
  border-radius: var(--radius-xs);
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all var(--ease);
}
.conn-mode-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}
.conn-mode-btn:not(.active):hover { color: var(--zinc-200); }

.conn-controls { display: flex; align-items: center; gap: 6px; }

.connection-bar select {
  background: var(--zinc-800);
  color: var(--zinc-200);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  padding: 0 28px 0 10px;
  height: 30px;
  font-family: var(--font-mono);
  font-size: 12px;
  min-width: 170px;
  cursor: pointer;
  transition: border-color var(--ease);
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2352525b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.connection-bar select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.connection-bar select:hover { border-color: var(--zinc-600); }

.ip-input {
  background: var(--zinc-800);
  color: var(--zinc-200);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 30px;
  font-family: var(--font-mono);
  font-size: 12px;
  width: 145px;
  transition: border-color var(--ease);
}
.ip-input:focus { border-color: var(--accent); }

.conn-sep {
  color: var(--zinc-500);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  padding: 0 2px;
}

/* ── Status badge ────────────────────────────────────────────────────────── */
.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--zinc-500);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--zinc-700);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.status-badge.connected .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18), 0 0 8px rgba(74, 222, 128, 0.4);
}
.status-badge.connected #statusText {
  color: var(--green);
  font-weight: 500;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

/* Primary — electric lemon CTA */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 32px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--ease), opacity var(--ease);
}
.btn-primary:hover:not(:disabled) { background: #d8ff1a; }
.btn-primary:active:not(:disabled) { opacity: 0.85; }
.btn-primary:disabled {
  background: var(--zinc-800);
  color: var(--zinc-600);
  cursor: not-allowed;
}

.btn-primary.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

/* Secondary — surface elevated */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--zinc-800);
  color: var(--zinc-200);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 32px;
  font-size: 13px;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}
.btn-secondary:hover {
  background: var(--zinc-700);
  border-color: var(--zinc-600);
  color: var(--zinc-50);
}
.btn-secondary:active { background: var(--zinc-700); }
.btn-secondary.active-pen {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* Danger — destructive outline */
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 32px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.08);
  border-color: var(--red);
}

/* Disconnect — danger variant of primary (replaces Connect when active) */
.btn-disconnect {
  background: rgba(248, 113, 113, 0.12) !important;
  color: var(--red) !important;
  border: 1px solid rgba(248, 113, 113, 0.35) !important;
}
.btn-disconnect:hover {
  background: rgba(248, 113, 113, 0.2) !important;
  border-color: var(--red) !important;
}

/* Ghost — inline tertiary */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--zinc-500);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 8px;
  height: 28px;
  font-size: 12px;
  white-space: nowrap;
  transition: color var(--ease), background var(--ease);
}
.btn-ghost:hover {
  color: var(--zinc-200);
  background: var(--zinc-800);
}
.btn-ghost.btn-sm {
  height: 24px;
  padding: 0 6px;
  font-size: 11px;
  gap: 4px;
}

/* Icon button */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--zinc-800);
  color: var(--zinc-400);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  width: 30px; height: 30px;
  font-size: 15px;
  flex-shrink: 0;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}
.btn-icon:hover {
  background: var(--zinc-700);
  border-color: var(--zinc-600);
  color: var(--zinc-100);
}

/* ── Main layout ─────────────────────────────────────────────────────────── */
main {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0; bottom: 0;
  display: flex;
  overflow: hidden;
}

/* ── Sidebars ────────────────────────────────────────────────────────────── */
aside#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

aside#execSidebar {
  width: var(--exec-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Panel sections ──────────────────────────────────────────────────────── */
.panel {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--zinc-500);
  margin-bottom: 14px;
}

.panel-subtitle-small {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--zinc-500);
  margin-bottom: 10px;
}

.divider {
  height: 1px;
  background: var(--zinc-800);
  margin: 14px 0;
}

/* ── Select / input base ─────────────────────────────────────────────────── */
.select-input {
  flex: 1;
  background: var(--zinc-900);
  color: var(--zinc-100);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  padding: 0 28px 0 8px;
  height: 30px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--ease);
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2352525b' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}
.select-input:hover {
  border-color: var(--zinc-600);
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2371717a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.select-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Number inputs — border/bg live on .input-unit-group, not the input itself */
.input-unit-group input,
.feed-row input,
#brushSize {
  background: transparent;
  color: var(--zinc-100);
  border: none;
  padding: 0 6px;
  height: 30px;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  outline: none;
  min-width: 0;
}

/* ── Canvas toolbar ──────────────────────────────────────────────────────── */
.tool-bar {
  display: flex;
  gap: 3px;
  margin-bottom: 12px;
  background: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.tool-btn {
  flex: 1;
  background: transparent;
  color: var(--zinc-500);
  border: none;
  border-radius: var(--radius-xs);
  padding: 5px 4px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  transition: all 0.12s;
}
.tool-btn:hover { color: var(--zinc-200); background: var(--zinc-800); }
.tool-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}

/* ── Form row ────────────────────────────────────────────────────────────── */
.form-row-small {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.form-row-small:last-child { margin-bottom: 0; }
.form-row-small label {
  color: var(--zinc-400);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.input-unit-group {
  display: inline-flex;
  align-items: stretch;
  background: var(--zinc-900);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input-unit-group:hover { border-color: var(--zinc-600); }
.input-unit-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.input-unit-group input { width: 60px; }
.input-unit-group span {
  color: var(--zinc-600);
  font-size: 11px;
  white-space: nowrap;
  padding: 0 8px 0 7px;
  display: flex;
  align-items: center;
  border-left: 1px solid var(--zinc-800);
}

.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.checkbox-row input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--accent);
  width: 14px; height: 14px;
}

/* ── Artwork info panel ──────────────────────────────────────────────────── */
.artwork-info-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  border-radius: var(--radius-sm);
}
.art-dims, .art-pos {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--zinc-500);
  margin-bottom: 4px;
}
.art-dims span, .art-pos span {
  color: var(--zinc-200);
  font-weight: 600;
}
.art-action-btns {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.art-action-btns button {
  flex: 1;
  text-align: center;
  font-size: 11px;
  height: 26px;
  padding: 0 4px;
  min-width: 44px;
  border: 1px solid var(--zinc-700);
  background: var(--zinc-800);
  border-radius: var(--radius-xs);
}
.art-action-btns button:hover {
  border-color: var(--zinc-600);
  background: var(--zinc-700);
  color: var(--zinc-100);
}
.text-red { color: var(--red) !important; border-color: rgba(248,113,113,0.25) !important; }
.text-red:hover {
  background: rgba(248,113,113,0.08) !important;
  color: var(--red) !important;
  border-color: rgba(248,113,113,0.5) !important;
}

/* ── Jog pad ─────────────────────────────────────────────────────────────── */
.jog-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
  margin-bottom: 12px;
}
.jog-btn {
  background: var(--zinc-800);
  color: var(--zinc-300);
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  user-select: none;
}
.jog-btn:hover {
  background: var(--zinc-700);
  border-color: var(--accent);
  color: var(--accent);
}
.jog-btn:active { background: var(--zinc-600); }
.jog-btn.home-btn {
  font-size: 18px;
  color: var(--zinc-400);
  border-color: var(--zinc-700);
}
.jog-btn.home-btn:hover { color: var(--accent); }

#jogYp      { grid-column: 2; grid-row: 1; }
#jogXm      { grid-column: 1; grid-row: 2; }
#homeAllBtn { grid-column: 2; grid-row: 2; }
#jogXp      { grid-column: 3; grid-row: 2; }
#jogYm      { grid-column: 2; grid-row: 3; }

/* ── Pen controls ────────────────────────────────────────────────────────── */
.pen-btns { display: flex; gap: 8px; }
.pen-btns .btn-secondary { flex: 1; }

/* ── Disabled states ─────────────────────────────────────────────────────── */
.needs-connection { opacity: 0.3; pointer-events: none; }
.printing-disabled { opacity: 0.3 !important; pointer-events: none !important; }

/* ── Mobile floating delete button ───────────────────────────────────────── */
.mobile-delete-btn {
  display: none;
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 60;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: #dc2626;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.45);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
.mobile-delete-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ── Content area ────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  padding: 20px;
}

.canvas-area .canvas-container {
  border-radius: 6px;
  border: 1px solid var(--zinc-800);
  overflow: hidden;
  background: var(--bg2);
  box-shadow:
    0 0 0 1px var(--zinc-800),
    0 8px 24px rgba(0, 0, 0, 0.5),
    0 32px 64px rgba(0, 0, 0, 0.3);
}

/* ── Serial log ──────────────────────────────────────────────────────────── */
.log-container {
  height: var(--log-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: height 0.2s ease;
  flex-shrink: 0;
}
.log-container.collapsed { height: 36px; }

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 36px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--zinc-500);
  flex-shrink: 0;
}
.log-actions { display: flex; gap: 4px; }

.log-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.75;
}
.log-container.collapsed .log-body,
.log-container.collapsed .log-input-bar { display: none; }

.log-entry { display: flex; gap: 8px; }
.log-ts  { color: var(--zinc-600); flex-shrink: 0; font-size: 10.5px; }
.log-tag { flex-shrink: 0; width: 28px; font-weight: 700; font-size: 10px; letter-spacing: 0.04em; }
.log-tag.tx  { color: var(--blue); }
.log-tag.rx  { color: var(--green); }
.log-tag.sys { color: var(--yellow); }
.log-tag.err { color: var(--red); }
.log-data    { color: var(--zinc-300); word-break: break-all; }
.log-data.dim { color: var(--zinc-600); }

.log-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.log-prompt {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 14px;
  flex-shrink: 0;
}
.log-input-bar input {
  flex: 1;
  background: transparent;
  color: var(--zinc-100);
  border: none;
  font-family: var(--font-mono);
  font-size: 12px;
  height: 28px;
  padding: 0;
  outline: none;
}
.log-input-bar input::placeholder { color: var(--zinc-600); }

/* ── Print progress ──────────────────────────────────────────────────────── */
.print-card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.print-progress-container { display: flex; flex-direction: column; gap: 6px; }

.print-progress-bar-bg {
  background: var(--zinc-800);
  border: 1px solid var(--zinc-700);
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}

.print-progress-bar-fill {
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  height: 100%;
  width: 0%;
  transition: width 0.3s ease;
}

.print-progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--zinc-500);
  font-family: var(--font-mono);
}

.print-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--zinc-900);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--zinc-800);
}
.print-stat-item { display: flex; flex-direction: column; gap: 3px; }
.print-stat-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--zinc-500);
}
.print-stat-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--zinc-100);
  font-family: var(--font-mono);
  line-height: 1;
}

.print-controls { display: flex; gap: 8px; }
.print-controls button { flex: 1; height: 34px; }

/* ── Gcode metrics ───────────────────────────────────────────────────────── */
#gcodeMetrics {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--zinc-800);
}
#gcodeMetrics .art-dims { margin-bottom: 4px; }

/* ── Substate badges ─────────────────────────────────────────────────────── */
.substate-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.substate-preparing { background: rgba(96,165,250,0.08); color: var(--blue); border-color: rgba(96,165,250,0.22); }
.substate-homing    { background: rgba(167,139,250,0.08); color: var(--purple); border-color: rgba(167,139,250,0.22); }
.substate-plotting  { background: var(--accent-glow); color: var(--accent); border-color: rgba(200,255,0,0.25); }
.substate-ending    { background: rgba(74,222,128,0.08); color: var(--green); border-color: rgba(74,222,128,0.22); }
.substate-tool_change {
  background: rgba(251,191,36,0.08);
  color: var(--yellow);
  border-color: rgba(251,191,36,0.3);
  animation: pulse-border 1.5s ease-in-out infinite alternate;
}
@keyframes pulse-border {
  from { border-color: rgba(251,191,36,0.15); box-shadow: none; }
  to   { border-color: rgba(251,191,36,0.7); box-shadow: 0 0 8px rgba(251,191,36,0.2); }
}

/* ── Tool change prompt ──────────────────────────────────────────────────── */
#toolChangePrompt {
  padding: 12px;
  background: rgba(251,191,36,0.06);
  border: 1px solid rgba(251,191,36,0.3);
  border-radius: var(--radius-sm);
  text-align: center;
  margin-bottom: 10px;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-card {
  background: var(--zinc-900);
  border: 1px solid var(--zinc-700);
  border-radius: 12px;
  width: 420px;
  max-width: 92%;
  padding: 24px;
  box-shadow:
    0 24px 48px rgba(0, 0, 0, 0.7),
    0 0 0 1px rgba(255, 255, 255, 0.04);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--zinc-800);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--zinc-50);
  margin: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  border-top: 1px solid var(--zinc-800);
  padding-top: 16px;
}

/* ── Spinner ─────────────────────────────────────────────────────────────── */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.spinner { animation: spin 0.8s linear infinite; }

/* ── App mode switcher (header) ─────────────────────────────────────────── */
.app-mode-tabs {
  display: flex;
  gap: 2px;
  background: var(--zinc-900);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--zinc-800);
  flex-shrink: 0;
}

.app-mode-btn {
  padding: 6px 14px;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
}
.app-mode-btn:hover {
  color: var(--text);
  background: var(--zinc-800);
}
.app-mode-btn.active {
  background: var(--zinc-700);
  color: var(--accent);
}

/* ── Exec sidebar tab system ─────────────────────────────────────────────── */
.exec-tabs {
  display: flex;
  padding: 0 4px;
  border-bottom: 1px solid var(--zinc-800);
  flex-shrink: 0;
  background: var(--bg2);
}
.exec-tab-btn {
  flex: 1;
  padding: 11px 6px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--zinc-500);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--ease), border-color var(--ease);
  letter-spacing: 0.02em;
  margin-bottom: -1px;
}
.exec-tab-btn:hover { color: var(--zinc-200); }
.exec-tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.exec-tab-content {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* ── Pen Z field (2-row stacked) ─────────────────────────────────────────── */
.pen-z-field {
  margin-bottom: 12px;
}
.pen-z-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}
.pen-z-field-header label {
  font-size: 10px;
  font-weight: 600;
  color: var(--zinc-500);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pen-z-field .input-unit-group {
  display: flex;
  width: 100%;
}
.pen-z-field .input-unit-group input {
  flex: 1;
  width: auto;
}

/* ── Step selector ───────────────────────────────────────────────────────── */
.step-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.step-label {
  font-size: 11px;
  color: var(--text-dim);
}
.step-btns {
  display: flex;
  flex: 1;
  background: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  padding: 2px;
  border-radius: var(--radius-sm);
}
.step-btn {
  flex: 1;
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: color var(--ease), background var(--ease);
}
.step-btn:hover {
  color: var(--text);
}
.step-btn.active {
  background: var(--zinc-700);
  color: var(--accent);
}

/* ── Jog feed row ────────────────────────────────────────────────────────── */
.feed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.feed-row label {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Printing Progress UI ────────────────────────────────────────────────── */
.print-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  margin-bottom: 8px;
}

.substate-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--zinc-800);
  color: var(--text-dim);
}
.substate-badge.substate-preparing {
  background: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
}
.substate-badge.substate-printing,
.substate-badge.substate-plotting {
  background: rgba(200, 255, 0, 0.15);
  color: var(--accent);
}
.substate-badge.substate-tool_change {
  background: rgba(96, 165, 250, 0.15);
  color: var(--blue);
}
.substate-badge.substate-completed {
  background: rgba(74, 222, 128, 0.15);
  color: var(--green);
}

.print-progress-container {
  background: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
}

.print-progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--zinc-800);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.print-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.print-progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
}

.print-stats {
  display: flex;
  gap: 8px;
}

.print-stat-item {
  flex: 1;
  background: var(--zinc-900);
  border: 1px solid var(--zinc-800);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.print-stat-label {
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.print-stat-value {
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
}

.print-controls {
  display: flex;
  gap: 6px;
}
.print-controls button {
  flex: 1;
}

/* ── Portrait mode root ──────────────────────────────────────────────────── */
#mainPortrait {
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.portrait-layout {
  display: flex;
  width: 100%;
  height: 100%;
}

.portrait-col {
  height: 100%;
  overflow: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.portrait-cam-col  {
  width: 268px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg2);
}

.portrait-pipe-col {
  flex: 1;
  background: var(--bg);
}

.portrait-out-col  {
  width: 290px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg2);
  overflow-y: auto;
}

/* ── Portrait status indicator ───────────────────────────────────────────── */
.portrait-status { display: flex; align-items: center; gap: 7px; }

.portrait-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.portrait-status-dot.status-idle       { background: var(--zinc-600); }
.portrait-status-dot.status-loading    { background: var(--blue);   animation: p-pulse 1s    infinite; }
.portrait-status-dot.status-watching   { background: var(--yellow); animation: p-pulse 1.4s  infinite; }
.portrait-status-dot.status-detected   { background: var(--accent); animation: p-pulse 0.55s infinite; }
.portrait-status-dot.status-captured   { background: var(--accent); }
.portrait-status-dot.status-processing { background: var(--blue);   animation: p-pulse 0.75s infinite; }
.portrait-status-dot.status-done       { background: var(--green); }
.portrait-status-dot.status-error      { background: var(--red); }

@keyframes p-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ── Pipeline stage grid ─────────────────────────────────────────────────── */
.pipeline-stages {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 6px;
}

.pipeline-stage {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stage-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: center;
}

.stage-canvas {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  border-radius: var(--radius-xs);
  border: 1px solid var(--zinc-800);
  background: var(--zinc-900);
  image-rendering: pixelated;
}

/* ── SVG preview (white paper background) ────────────────────────────────── */
.svg-preview-box {
  width: 340px;
  height: 340px;
  border: 1px solid var(--zinc-700);
  border-radius: var(--radius-sm);
  background: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px auto;
}

.svg-preview-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.svg-preview-inner svg {
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
}

/* ── Portrait ghost canvas ──────────────────────────────────────────────── */
.portrait-ghost-canvas {
  width: 100%;
  display: block;
  image-rendering: auto;
}

/* Face-detection review: canvas fits contained, not stretched */
#cameraCanvasContainer.face-review-mode {
  display: flex;
  align-items: center;
  justify-content: center;
}
.face-review-mode .portrait-ghost-canvas {
  width: auto;
  max-width: 100%;
  max-height: 100%;
}

/* ── Portrait step breadcrumb ────────────────────────────────────────────── */
.portrait-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.portrait-step-chip {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  background: var(--zinc-900);
  border: 1px solid transparent;
  cursor: default;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
  letter-spacing: 0.02em;
}

.portrait-step-chip.active {
  color: var(--accent);
  background: var(--zinc-800);
  border-color: var(--zinc-700);
}

/* ══════════════════════════════════════════════════════════════════════════
   Mobile nav + overlay — hidden on desktop by default
   ══════════════════════════════════════════════════════════════════════════ */
.mobile-nav     { display: none; }
.mobile-overlay { display: none; }
.mobile-only    { display: none !important; }

/* ══════════════════════════════════════════════════════════════════════════
   Responsive — mobile (≤ 767 px)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  :root {
    --header-h:    52px;
    --mobile-nav-h: 58px;
  }

  /* ── Header — single row ─────────────────────────────────────────────── */
  header { padding: 0 12px; }

  .brand         { min-width: auto; }
  .brand-name    { display: none; }
  .app-mode-btn  { padding: 5px 12px; font-size: 12px; }
  .status-badge  { margin-left: auto; }
  #statusText    { display: none; }
  .status-dot    { width: 9px; height: 9px; }

  .job-bar { display: none; }
  .desktop-only { display: none !important; }
  .exec-tabs { display: none; }
  .ip-input { flex: 1; width: auto; min-width: 0; height: 40px; font-size: 14px; }

  /* ── Main design area — leave room for mobile nav ─────────────────── */
  main#mainDesign { bottom: var(--mobile-nav-h); }

  /* ── Sidebars → slide-up bottom sheets ──────────────────────────────── */
  aside#sidebar,
  aside#execSidebar {
    position: fixed;
    bottom: var(--mobile-nav-h);
    left: 0;
    right: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 14px 14px 0 0;
    border-right: none;
    border-left: none;
    border-top: 1px solid var(--border2);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 150;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  }
  aside#sidebar.mobile-open,
  aside#execSidebar.mobile-open { transform: translateY(0); }

  /* Drag handle pill */
  aside#sidebar::before,
  aside#execSidebar::before {
    content: '';
    display: block;
    width: 32px;
    height: 4px;
    background: var(--zinc-700);
    border-radius: 2px;
    margin: 10px auto 2px;
    flex-shrink: 0;
  }

  /* ── Canvas area ──────────────────────────────────────────────────────── */
  .content { flex: 1; min-height: 0; }
  .canvas-area { padding: 8px; }

  /* ── Log — always collapsed on mobile ───────────────────────────────── */
  .log-container { height: 36px !important; }

  /* ── Mobile overlay backdrop ─────────────────────────────────────────── */
  .mobile-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 149;
    pointer-events: none;
    transition: background 0.28s ease;
  }
  .mobile-overlay.active {
    background: rgba(0, 0, 0, 0.6);
    pointer-events: auto;
  }

  /* ── Mobile nav bar ──────────────────────────────────────────────────── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-h);
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 160;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: var(--zinc-500);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 8px 4px;
    cursor: pointer;
    transition: color var(--ease);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .mobile-nav-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
  .mobile-nav-btn.active { color: var(--accent); }

  /* ── Mobile-only elements ────────────────────────────────────────────── */
  .mobile-only { display: block !important; }

  /* ── Floating delete button — visible on mobile ──────────────────────── */
  .mobile-delete-btn { display: flex; }

  /* ── Touch-friendly button sizing ───────────────────────────────────── */
  .btn-primary, .btn-secondary, .btn-danger { min-height: 42px; }
  .btn-primary.btn-sm, .btn-secondary.btn-sm { min-height: 32px; }

  /* ── Jog pad — larger touch targets ─────────────────────────────────── */
  .jog-pad { grid-template-rows: repeat(3, 58px); gap: 6px; }
  .jog-btn { font-size: 22px; border-radius: var(--radius); }
  .step-btn { padding: 7px 6px; font-size: 12px; }

  /* ── Portrait mode — vertical stack ─────────────────────────────────── */
  #mainPortrait {
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .portrait-layout { flex-direction: column; height: auto; }
  .portrait-col { height: auto; overflow: visible; }
  .portrait-cam-col {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .portrait-pipe-col { flex: none; width: 100%; }
  .portrait-out-col {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
  }

  /* ── Portrait step chips — horizontal row on mobile ─────────────────── */
  .portrait-steps { flex-direction: row; gap: 4px; }
  .portrait-step-chip { flex: 1; text-align: center; font-size: 11px; padding: 6px 4px; }

  /* ── SVG preview — fluid width on mobile ────────────────────────────── */
  .svg-preview-box { width: 100%; height: auto; aspect-ratio: 1; max-width: 100%; }

  /* ── Modal card — full-width on mobile ──────────────────────────────── */
  .modal-card { width: 95%; padding: 20px 16px; }
}
