/* ============================================================
   IsoForge — Drawing → 3D · Professional dark theme
   ============================================================ */

:root {
  /* Surface colors (depth 0..4) */
  --bg-0:     #0a0c10;
  --bg-1:     #0d1117;
  --bg-2:     #131820;
  --bg-3:     #1a212c;
  --bg-4:     #232c39;

  /* Border / lines */
  --line-1:   #1f2733;
  --line-2:   #2d3748;
  --line-3:   #3a4659;

  /* Text */
  --tx-1:     #e6edf3;     /* primary */
  --tx-2:     #b8c0c8;     /* secondary */
  --tx-3:     #8b949e;     /* muted */
  --tx-4:     #6e7681;     /* very muted */

  /* Accent */
  --acc-1:    #58a6ff;
  --acc-1h:   #4493f8;
  --acc-2:    #1f6feb;
  --acc-glow: rgba(88, 166, 255, 0.15);

  /* Semantic */
  --ok:       #3fb950;
  --warn:     #d29922;
  --err:      #f85149;
  --info:     #79c0ff;

  /* Effects */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.6);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.6), 0 2px 4px -2px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.7), 0 4px 6px -4px rgba(0,0,0,0.5);

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 10px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, 'Cascadia Code', monospace;

  --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
*::selection { background: var(--acc-1); color: var(--bg-0); }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--tx-1);
  font-family: var(--font-sans);
  font-size: 13px;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  letter-spacing: -0.005em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: 440px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar viewport";
  height: 100vh;
}

/* ====================== TOP BAR ====================== */
#topbar {
  grid-area: topbar;
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-bottom: 1px solid var(--line-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  user-select: none;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  color: var(--acc-1);
  filter: drop-shadow(0 0 8px var(--acc-glow));
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--tx-1);
}
.brand-sub {
  font-size: 10px;
  color: var(--tx-3);
  font-weight: 500;
  margin-top: 1px;
}
.ver-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--acc-1);
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.25);
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 8px;
  font-weight: 500;
}
.topbar-actions { display: flex; gap: 4px; align-items: center; }
.topbar-sep {
  width: 1px; height: 18px;
  background: var(--line-2);
  margin: 0 6px;
}

/* ====================== SIDEBAR ====================== */
#sidebar {
  grid-area: sidebar;
  background: var(--bg-1);
  border-right: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Tabs */
.tabs {
  display: flex;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line-1);
  flex-shrink: 0;
  padding: 0 4px;
}
.tab {
  flex: 1;
  padding: 10px 6px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--tx-3);
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color var(--transition), border-color var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin: 0 2px;
}
.tab:hover { color: var(--tx-1); }
.tab.active {
  color: var(--acc-1);
  border-bottom-color: var(--acc-1);
}
.tab-ico {
  width: 16px; height: 16px;
  stroke: currentColor;
}

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.tab-panel.active { display: flex; flex-direction: column; }
.panel-head { margin-bottom: 14px; }
.panel-head h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.section-h {
  margin: 12px 0 6px;
  font-size: 10px;
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* ====================== FORMS ====================== */
label {
  display: block;
  font-size: 11px;
  color: var(--tx-3);
  margin: 8px 0 4px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
textarea, input[type=text], input[type=number], select {
  width: 100%;
  background: var(--bg-0);
  color: var(--tx-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
textarea {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  resize: vertical;
}
textarea:focus, input:focus, select:focus {
  border-color: var(--acc-1);
  box-shadow: 0 0 0 3px var(--acc-glow);
}
input[type=range] {
  width: 100%;
  background: transparent;
  margin: 4px 0;
  -webkit-appearance: none;
  height: 4px;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--line-2);
  border-radius: 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--acc-1);
  border-radius: 50%;
  border: 2px solid var(--bg-0);
  margin-top: -5px;
  cursor: pointer;
  transition: transform var(--transition);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
.file-input {
  width: 100%;
  background: var(--bg-0);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 11px;
  color: var(--tx-3);
  cursor: pointer;
  transition: border-color var(--transition);
}
.file-input:hover { border-color: var(--acc-1); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.form-grid > div { min-width: 0; }
.form-grid > div:first-child { grid-column: 1 / -1; }

/* ====================== BUTTONS ====================== */
button {
  font-family: var(--font-sans);
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:active { transform: translateY(1px); }
button:disabled {
  opacity: 0.4;
  cursor: not-allowed !important;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(180deg, var(--acc-1), var(--acc-1h));
  color: #fff;
  border: 1px solid var(--acc-2);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.005em;
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset, var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, 0 0 0 3px var(--acc-glow);
}
/* Subtle "blocked" appearance for buttons whose action isn't available yet —
   not actually disabled (so user can click and get a helpful toast). */
.btn-primary.blocked {
  background: var(--bg-3);
  color: var(--tx-3);
  border-color: var(--line-2);
  box-shadow: none;
}
.btn-primary.blocked:hover { filter: none; box-shadow: none; }

.btn-secondary {
  background: var(--bg-3);
  color: var(--tx-1);
  border: 1px solid var(--line-2);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-4);
  border-color: var(--line-3);
}

.btn-ghost {
  background: transparent;
  color: var(--tx-2);
  border: 1px solid transparent;
  padding: 5px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--bg-3); color: var(--tx-1); }
.btn-ghost svg { color: var(--tx-3); }
.btn-ghost:hover svg { color: var(--acc-1); }

.btn-danger {
  background: var(--err);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 12px;
}

.link-btn {
  background: transparent;
  color: var(--acc-1);
  border: none;
  padding: 4px 0;
  text-align: left;
  font-size: 11px;
  cursor: pointer;
  display: block;
  width: 100%;
}
.link-btn:hover { text-decoration: underline; }

/* ====================== LAYOUT HELPERS ====================== */
.row {
  display: flex;
  gap: 6px;
  margin: 10px 0;
  flex-wrap: wrap;
}
hr {
  border: none;
  border-top: 1px solid var(--line-1);
  margin: 14px 0;
}
.muted { color: var(--tx-3); }
.small { font-size: 11px; }
.info {
  font-size: 11px;
  color: var(--tx-2);
  line-height: 1.6;
  padding: 6px 10px;
}
.info code {
  background: var(--bg-0);
  border: 1px solid var(--line-1);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--acc-1);
  font-family: var(--font-mono);
  font-size: 10px;
}

details {
  margin: 8px 0;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: hidden;
}
summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--tx-2);
  user-select: none;
  list-style: none;
  position: relative;
  padding-left: 26px;
}
summary::before {
  content: '▸';
  position: absolute;
  left: 10px;
  top: 8px;
  color: var(--tx-3);
  font-size: 10px;
  transition: transform var(--transition);
}
details[open] summary::before { transform: rotate(90deg); }
details[open] summary { border-bottom: 1px solid var(--line-1); color: var(--acc-1); }
details > div, details > p, details > .info { padding: 8px 10px; margin: 0; }
details > label,
details > input,
details > textarea { margin-left: 10px; margin-right: 10px; width: calc(100% - 20px); }
details > label { padding: 0; margin-top: 8px; }
details > .row { padding: 8px 10px; margin: 0; }
details > details { margin: 8px; }
.example-list { padding: 6px 10px 10px; }

/* ====================== MESSAGES ====================== */
.msg-area:empty { display: none; }
.msg {
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  margin-top: 8px;
  line-height: 1.45;
  border-left-width: 3px;
  border-left-style: solid;
}
.msg.ok   { background: rgba(63,185,80,0.08);  color: var(--ok);   border: 1px solid rgba(63,185,80,0.3);  border-left-color: var(--ok); }
.msg.err  { background: rgba(248,81,73,0.08);  color: var(--err);  border: 1px solid rgba(248,81,73,0.3);  border-left-color: var(--err); }
.msg.warn { background: rgba(210,153,34,0.08); color: var(--warn); border: 1px solid rgba(210,153,34,0.3); border-left-color: var(--warn); }
.msg.info { background: rgba(121,192,255,0.08);color: var(--info); border: 1px solid rgba(121,192,255,0.3);border-left-color: var(--info); }

/* ====================== VALIDATION ====================== */
.validate-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 12px 0;
}
.validate-summary .stat {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
}
.validate-summary .stat .num {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
.validate-summary .stat .lbl {
  font-size: 9px;
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
  font-weight: 500;
}
.validate-summary .stat.err  .num { color: var(--err); }
.validate-summary .stat.warn .num { color: var(--warn); }
.validate-summary .stat.ok   .num { color: var(--ok); }

.validate-results .issue {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-left: 3px solid var(--tx-4);
  padding: 7px 10px;
  margin: 4px 0;
  border-radius: 4px;
  font-size: 11px;
  line-height: 1.5;
}
.validate-results .issue.err  { border-left-color: var(--err); }
.validate-results .issue.warn { border-left-color: var(--warn); }
.validate-results .issue.info { border-left-color: var(--info); }
.validate-results .issue .id {
  font-family: var(--font-mono);
  color: var(--tx-3);
  font-size: 10px;
  margin-right: 8px;
  font-weight: 500;
}

/* ====================== WIZARD ====================== */
.wizard {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 0;
}
.wizard-header {
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line-1);
  margin-bottom: 14px;
}
.wizard-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.title-num {
  color: var(--acc-1);
  font-size: 16px;
  filter: drop-shadow(0 0 6px var(--acc-glow));
}
.wizard-progress {
  display: flex;
  align-items: center;
  gap: 0;
}
.step-dot {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}
.step-dot span {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 2px solid var(--line-2);
  color: var(--tx-3);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.step-dot label {
  font-size: 9px;
  color: var(--tx-3);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0;
  font-weight: 500;
}
.step-dot.active span {
  background: var(--acc-1);
  border-color: var(--acc-1);
  color: var(--bg-0);
  box-shadow: 0 0 0 4px var(--acc-glow);
}
.step-dot.active label { color: var(--tx-1); font-weight: 600; }
.step-dot.done span {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--bg-0);
}
.step-dot.done label { color: var(--tx-2); }
.step-line {
  flex: 1;
  height: 2px;
  background: var(--line-2);
  margin: 0 2px;
  margin-bottom: 14px;
  transition: background var(--transition);
}
.step-dot.done + .step-line { background: var(--ok); }

.wizard-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 14px;
}
.sum-item {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sum-lbl {
  font-size: 9px;
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.sum-val {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--tx-2);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sum-val.set { color: var(--ok); }

.kbd-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.55;
  margin-left: 4px;
}

.tool-toggle.on {
  background: var(--acc-1) !important;
  color: var(--bg-0) !important;
  border-color: var(--acc-2) !important;
}

/* Manual-edit mode toolbar */
.mode-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 4px;
  margin: 8px 0;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--tx-2);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}
.mode-btn svg { width: 18px; height: 18px; stroke: currentColor; }
.mode-btn:hover { background: var(--bg-3); color: var(--tx-1); }
.mode-btn.active {
  background: var(--acc-1);
  color: var(--bg-0);
  border-color: var(--acc-2);
  box-shadow: 0 1px 0 rgba(255,255,255,0.1) inset;
}

/* Action panel (selection / cleanup) */
.action-panel {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  margin: 8px 0;
  overflow: hidden;
}
.action-head {
  padding: 6px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line-1);
  font-size: 9px;
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.action-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-body.empty { padding: 14px 10px; }
.action-empty {
  font-size: 11px;
  color: var(--tx-3);
  text-align: center;
  line-height: 1.5;
}
.action-empty b { color: var(--tx-2); }

.action-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  font-size: 11px;
  margin-bottom: 2px;
}
.action-meta .lbl {
  color: var(--tx-3);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.action-meta .val {
  font-family: var(--font-mono);
  color: var(--tx-1);
}
.action-meta .val.x { color: #ff8888; }
.action-meta .val.y { color: #66dd88; }
.action-meta .val.z { color: #6ab8ff; }

.action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.action-buttons .btn-danger {
  flex: 1;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 600;
}
.cleanup-btn {
  width: 100%;
  justify-content: flex-start !important;
  padding: 8px 10px !important;
  font-size: 11px !important;
}
.axis-angle-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px;
}
.axis-angle-row {
  display: grid;
  grid-template-columns: 30px 1fr auto auto;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}
.axis-tag {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  padding: 4px 0;
  border-radius: 4px;
  font-size: 11px;
}
.axis-tag.x { background: rgba(255,100,100,0.18); color: #ff8888; }
.axis-tag.y { background: rgba(100,255,125,0.18); color: #66dd88; }
.axis-tag.z { background: rgba(106,184,255,0.18); color: #6ab8ff; }
.axis-pick.on {
  background: var(--acc-1) !important;
  color: var(--bg-0) !important;
}

/* ====================== EXPORT CARDS ====================== */
.export-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 14px;
}
.export-card {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color var(--transition);
}
.export-card:hover { border-color: var(--line-2); }
.export-card.disabled { opacity: 0.5; }
.export-icon {
  width: 38px; height: 38px;
  border-radius: 8px;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-1);
}
.export-icon svg { width: 22px; height: 22px; }
.export-meta { min-width: 0; }
.export-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--tx-1);
  display: flex;
  align-items: center;
  gap: 6px;
}
.export-desc {
  font-size: 11px;
  color: var(--tx-3);
  line-height: 1.45;
  margin-top: 2px;
}
.export-tags {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  flex-wrap: wrap;
}
.export-tags .tag {
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--bg-3);
  border: 1px solid var(--line-1);
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag-soon {
  background: rgba(210,153,34,0.15) !important;
  border-color: rgba(210,153,34,0.4) !important;
  color: var(--warn) !important;
}
.export-card .btn-primary,
.export-card .btn-secondary {
  white-space: nowrap;
  min-width: 92px;
  justify-content: center;
}
.check-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--tx-2);
  cursor: pointer;
}
.check-line input[type=checkbox] {
  margin: 0;
  accent-color: var(--acc-1);
}

/* Always-visible panel card (replaces collapsible details in Model tab) */
.panel-card {
  margin: 10px 0;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-card-head {
  margin: 0;
  padding: 8px 12px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--line-1);
  font-size: 11px;
  font-weight: 600;
  color: var(--acc-1);
  letter-spacing: 0.01em;
}
.panel-card-body {
  padding: 10px 12px;
}
.panel-card-body > .row:first-child { margin-top: 0; }

/* Transform grid (Model tab) */
.tf-grid {
  display: grid;
  grid-template-columns: 30px 1fr 1fr;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
}
.tf-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 11px;
  color: var(--tx-3);
}
.tf-grid label input {
  flex: 1;
  font-size: 11px;
  padding: 4px 6px;
  font-family: var(--font-mono);
}
.tf-axis {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  padding: 4px 0;
  border-radius: 3px;
  font-size: 11px;
}
.tf-axis.x { background: rgba(255,100,100,0.18); color: #ff8888; }
.tf-axis.y { background: rgba(100,255,125,0.18); color: #66dd88; }
.tf-axis.z { background: rgba(106,184,255,0.18); color: #6ab8ff; }
.tf-axis.muted { background: var(--bg-3); color: var(--tx-3); }

/* Custom labels manager */
.label-form {
  display: grid;
  grid-template-columns: 1fr auto 30px auto;
  gap: 6px;
  padding: 8px 10px;
  align-items: center;
}
.label-form input[type=text] { font-size: 11px; padding: 5px 8px; }
.label-form select { font-size: 11px; padding: 5px 6px; min-width: 90px; }
.label-form input[type=color] {
  width: 28px; height: 28px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}
.label-list {
  max-height: 200px;
  overflow-y: auto;
  margin: 8px 10px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.label-row {
  display: grid;
  grid-template-columns: 12px 1fr auto 24px;
  gap: 6px;
  align-items: center;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line-1);
  font-size: 11px;
}
.label-row:last-child { border-bottom: none; }
.label-row .swatch {
  width: 10px; height: 10px;
  border-radius: 50%;
}
.label-row .text {
  color: var(--tx-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.label-row .at {
  color: var(--tx-3);
  font-family: var(--font-mono);
  font-size: 10px;
}
.label-row button {
  background: transparent;
  border: none;
  color: var(--tx-3);
  cursor: pointer;
  padding: 2px;
  font-size: 14px;
}
.label-row button:hover { color: var(--err); }

/* Detection parameter presets */
.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px 4px;
}
.preset-btn {
  font-size: 10px;
  padding: 5px 4px;
  white-space: nowrap;
  font-weight: 500;
}
.preset-btn.active {
  background: var(--acc-1) !important;
  color: var(--bg-0) !important;
  border-color: var(--acc-2) !important;
}

/* Per-point pick rows (Step 2) */
.req {
  font-size: 9px;
  font-weight: 600;
  color: var(--err);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(248,81,73,0.12);
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: middle;
}
.pick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 6px;
  margin: 8px 0;
}
.pick-row {
  display: grid;
  grid-template-columns: 32px auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  transition: border-color var(--transition);
  font-size: 10px;
}
.pick-row.info-row {
  grid-template-columns: 32px auto 1fr;
  background: transparent;
  border: none;
}
.pick-row.captured { border-color: var(--ok); background: rgba(63,185,80,0.05); }
.pick-row.armed   { border-color: var(--acc-1); background: rgba(88,166,255,0.08); }
.pick-tag {
  font-family: var(--font-mono);
  font-weight: 700;
  text-align: center;
  padding: 4px 0;
  border-radius: 3px;
  font-size: 10px;
  letter-spacing: 0.02em;
}
.pick-tag.scale { background: rgba(52,211,153,0.18); color: #34d399; }
.pick-tag.x { background: rgba(255,100,100,0.18); color: #ff8888; }
.pick-tag.y { background: rgba(100,255,125,0.18); color: #66dd88; }
.pick-tag.z { background: rgba(106,184,255,0.18); color: #6ab8ff; }
.pick-tag.muted { background: var(--bg-3); color: var(--tx-3); }

.pick-btn {
  font-size: 10px;
  padding: 4px 8px;
  white-space: nowrap;
}
.pick-btn.armed {
  background: var(--acc-1) !important;
  color: var(--bg-0) !important;
  border-color: var(--acc-2) !important;
  box-shadow: 0 0 0 3px var(--acc-glow);
}
.pick-btn.captured {
  background: rgba(63,185,80,0.12) !important;
  color: var(--ok) !important;
  border-color: rgba(63,185,80,0.4) !important;
}
.pick-coord {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--tx-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.pick-coord.set { color: var(--ok); }

/* Cursor when an arm is active */
#viewport.armed-pick #traceCanvas { cursor: crosshair !important; }
.manual-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(88,166,255,0.08);
  border: 1px solid rgba(88,166,255,0.3);
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--info);
  margin-top: 8px;
}
.manual-hint b { font-weight: 600; }

.wizard-step {
  display: none;
  flex: 1;
  overflow-y: auto;
  animation: stepFade 0.22s ease-out;
}
.wizard-step.active { display: block; }
@keyframes stepFade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0);   }
}
.step-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--tx-1);
  letter-spacing: -0.005em;
}
.step-desc {
  margin: 0 0 14px;
  font-size: 11px;
  color: var(--tx-2);
  line-height: 1.6;
}
.wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 4px;
  border-top: 1px solid var(--line-1);
  margin-top: 12px;
  flex-shrink: 0;
}

/* Drop zone */
.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  border: 2px dashed var(--line-2);
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  cursor: pointer;
  transition: all 0.2s;
  margin: 8px 0;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--acc-1);
  background: rgba(88, 166, 255, 0.05);
  transform: translateY(-1px);
}
.drop-icon {
  width: 32px; height: 32px;
  color: var(--acc-1);
  margin-bottom: 10px;
}
.drop-text {
  color: var(--tx-1);
  font-size: 13px;
  font-weight: 500;
}
.drop-sub  {
  color: var(--tx-3);
  font-size: 10px;
  margin-top: 4px;
  font-family: var(--font-mono);
}

.upload-preview {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.upload-preview img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  display: block;
  margin: 0 auto;
}

/* PDF picker */
.pdf-picker {
  margin-top: 10px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: hidden;
}
.pdf-picker-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-1);
  font-size: 11px;
  color: var(--tx-2);
  background: var(--bg-3);
}
.pdf-thumbs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.pdf-thumb {
  border: 2px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-1);
  padding: 6px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.pdf-thumb:hover {
  border-color: var(--acc-1);
  transform: translateY(-1px);
}
.pdf-thumb.selected {
  border-color: var(--acc-1);
  background: rgba(88,166,255,0.05);
}
.pdf-thumb img {
  max-width: 100%;
  max-height: 140px;
  display: block;
  margin: 0 auto;
  border-radius: 3px;
}
.pdf-thumb-label {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--tx-3);
  margin-top: 4px;
}

.calib-state {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
}
.calib-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px;
  font-size: 11px;
  padding: 3px 0;
}
.calib-label {
  color: var(--tx-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10px;
}
.calib-val { font-family: var(--font-mono); color: var(--tx-1); }
.calib-result {
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  color: var(--tx-2);
}
.calib-result:empty { display: none; }
.calib-result.set {
  background: rgba(63,185,80,0.08);
  color: var(--ok);
  border-color: rgba(63,185,80,0.3);
}

.build-cta {
  width: 100%;
  padding: 14px;
  font-size: 14px;
  margin-top: 6px;
  background: linear-gradient(180deg, var(--acc-1), var(--acc-2));
}

/* Segment list */
.segment-list {
  max-height: 380px;
  overflow-y: auto;
  margin-top: 8px;
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.segment-row {
  display: grid;
  grid-template-columns: 28px 50px 1fr 70px;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-1);
  align-items: center;
  font-size: 11px;
  cursor: pointer;
  transition: background var(--transition);
}
.segment-row:hover { background: var(--bg-3); }
.segment-row.active { background: rgba(88,166,255,0.08); }
.segment-row .idx {
  font-family: var(--font-mono);
  color: var(--tx-3);
  font-size: 10px;
}
.segment-row .axis {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: center;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 3px;
}
.segment-row .axis.x { background: rgba(255,100,100,0.18); color: #ff8888; }
.segment-row .axis.y { background: rgba(100,255,125,0.18); color: #66dd88; }
.segment-row .axis.z { background: rgba(106,184,255,0.18); color: #6ab8ff; }
.segment-row input.dim {
  width: 100%;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 6px;
}

/* ====================== VIEWPORT ====================== */
#viewport {
  grid-area: viewport;
  position: relative;
  overflow: hidden;
  background: var(--bg-0);
}
#canvas-container { position: absolute; inset: 0; }

/* Empty-state hero shown when no model is loaded */
.empty-hero {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 4;
  opacity: 1;
  transition: opacity 0.35s ease-out;
}
.empty-hero.hidden { opacity: 0; pointer-events: none !important; }
.empty-hero-card {
  pointer-events: auto;
  text-align: center;
  max-width: 540px;
  padding: 36px 40px 32px;
  background: rgba(13, 17, 23, 0.85);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow-lg);
}
.empty-hero-mark {
  width: 56px; height: 56px;
  color: var(--acc-1);
  filter: drop-shadow(0 0 16px var(--acc-glow));
  margin-bottom: 14px;
}
.empty-hero-card h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 10px;
  color: var(--tx-1);
}
.empty-hero-card p {
  font-size: 13px;
  line-height: 1.65;
  color: var(--tx-2);
  margin: 0 0 22px;
}
.empty-hero-card .build-cta {
  margin: 0 auto;
  display: inline-flex;
  font-size: 14px;
  padding: 12px 24px;
  width: auto;
}
.empty-hero-steps {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
  gap: 0;
}
.hero-step {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tx-3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.hero-step-num {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--tx-3);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hero-step-line {
  flex: 0 0 18px;
  height: 1px;
  background: var(--line-2);
  margin: 0 6px;
}
@media (max-width: 720px) {
  .empty-hero-card { padding: 24px 20px; max-width: 92%; }
  .empty-hero-card h2 { font-size: 18px; }
  .empty-hero-steps { display: none; }
}

#trace-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: none;
  background: var(--bg-0);
  z-index: 50;
}
#trace-overlay.active {
  display: block;
  pointer-events: auto;
}
#traceCanvas {
  width: 100%; height: 100%;
  cursor: crosshair;
  display: block;
}
#viewport.trace-mode #canvas-container { visibility: hidden; }
#viewport.trace-mode #toolbar,
#viewport.trace-mode #legend,
#viewport.trace-mode #status { display: none; }

#toolbar {
  position: absolute; top: 14px; left: 14px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 4px;
  display: flex;
  gap: 2px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
}
.tool-btn {
  background: transparent;
  color: var(--tx-2);
  border: 1px solid transparent;
  padding: 5px 8px;
  font-size: 13px;
  border-radius: 4px;
  min-width: 30px;
  height: 28px;
}
.tool-btn svg {
  width: 16px; height: 16px;
  stroke: currentColor;
}
.tool-btn:hover { background: var(--bg-3); color: var(--tx-1); }
.tool-btn.on {
  background: var(--acc-1);
  color: var(--bg-0);
}
.tool-sep {
  width: 1px;
  background: var(--line-2);
  margin: 4px 4px;
}

#legend {
  position: absolute; top: 14px; right: 14px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 10px 12px;
  max-width: 280px;
  font-size: 11px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
}
#legend h3 {
  margin: 0 0 8px;
  font-size: 9px;
  color: var(--tx-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.swatch {
  width: 18px; height: 5px;
  border-radius: 2px;
  display: inline-block;
  flex-shrink: 0;
}

#status {
  position: absolute; bottom: 12px; left: 14px;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--tx-3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--shadow-md);
  letter-spacing: 0.02em;
}

/* ====================== SCROLLBARS ====================== */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 5px;
  border: 2px solid var(--bg-1);
}
::-webkit-scrollbar-thumb:hover { background: var(--line-3); }

/* ====================== MISC ====================== */
table { width: 100%; font-size: 11px; border-collapse: collapse; }
th, td { padding: 4px 6px; border-bottom: 1px solid var(--line-1); text-align: left; }
th {
  color: var(--tx-3);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
pre {
  background: var(--bg-0);
  border: 1px solid var(--line-1);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 10px;
  overflow-x: auto;
  line-height: 1.6;
  color: var(--tx-2);
}

/* ====================== HELP MODAL ====================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.18s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  width: min(720px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalRise 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes modalRise {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-1);
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.modal-title-main {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--tx-1);
}
.modal-title-sub {
  font-size: 11px;
  color: var(--tx-3);
  font-family: var(--font-mono);
  margin-top: 2px;
}
.modal-close {
  background: transparent;
  color: var(--tx-3);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  width: 28px;
  height: 28px;
  font-size: 18px;
  font-weight: 400;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.modal-close:hover {
  background: var(--err);
  color: #fff;
  border-color: var(--err);
}
.modal-body {
  overflow-y: auto;
  padding: 20px 24px 24px;
  flex: 1;
}

.help-section {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line-1);
}
.help-section:last-child { border-bottom: none; padding-bottom: 0; }
.help-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--acc-1);
  letter-spacing: -0.005em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.help-section p {
  font-size: 12px;
  color: var(--tx-2);
  line-height: 1.65;
  margin: 0 0 10px;
}
.help-section p.muted { color: var(--tx-3); }
.help-section ul, .help-section ol {
  font-size: 12px;
  color: var(--tx-2);
  line-height: 1.7;
  padding-left: 22px;
  margin: 0;
}
.help-section li { margin: 4px 0; }
.help-section li b { color: var(--tx-1); }

.help-steps {
  counter-reset: helpstep;
  padding-left: 0;
  list-style: none;
}
.help-steps li {
  position: relative;
  padding-left: 30px;
  margin: 8px 0;
  counter-increment: helpstep;
}
.help-steps li::before {
  content: counter(helpstep);
  position: absolute;
  left: 0; top: 1px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--acc-1);
  color: var(--bg-0);
  font-weight: 700;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 11px;
}
.help-table th {
  background: var(--bg-3);
  color: var(--tx-3);
  font-weight: 600;
  text-align: left;
  padding: 6px 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  border-bottom: 1px solid var(--line-2);
}
.help-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line-1);
  color: var(--tx-2);
}
.help-table td:first-child { color: var(--tx-1); font-weight: 500; }
.help-table tr:last-child td { border-bottom: none; }

.help-table kbd {
  font-family: var(--font-mono);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10px;
  color: var(--tx-1);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
  margin: 0 2px;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0;
}
.help-card {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.help-card-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--acc-1);
  margin-bottom: 4px;
}
.help-card p {
  font-size: 11px;
  color: var(--tx-2);
  margin: 0;
  line-height: 1.55;
}

@media (max-width: 600px) {
  .help-grid { grid-template-columns: 1fr; }
}

/* Global toast (top-center) */
.global-toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: var(--ok);
  color: var(--bg-0);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
  z-index: 9999;
  max-width: 70%;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.005em;
}
.global-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.global-toast.err  { background: var(--err);  color: #fff; }
.global-toast.warn { background: var(--warn); color: var(--bg-0); }
.global-toast.info { background: var(--info); color: var(--bg-0); }
.global-toast svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line-2);
  border-top-color: var(--acc-1);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
