/* PathForge — machinist dark theme. Self-contained: no external fonts or CDNs. */

:root {
  /* palette */
  --gunmetal: #12161c;
  --panel: #181e26;
  --panel-2: #1d242e;
  --hairline: #29323f;
  --hairline-soft: #222a35;
  --trace: #38e1ff;        /* cutting moves */
  --trace-dim: #1d97ad;
  --rapid: #ffb02e;        /* rapid moves */
  --chalk: #e9eef5;
  --slate: #93a1b5;
  --slate-dim: #66748a;
  --danger: #ff5d5d;
  --sim-tool: #ffffff;

  /* viewport grid */
  --grid-minor: rgba(122, 144, 170, 0.09);
  --grid-major: rgba(122, 144, 170, 0.20);
  --grid-axis:  rgba(165, 186, 210, 0.45);
  --grid-axis3d: #48627e;
  --grid-minor3d: #223042;

  /* type */
  --font-display: "Bahnschrift", "Arial Narrow", "Segoe UI", system-ui, sans-serif;
  --font-body: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", ui-monospace, "Courier New", monospace;

  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--gunmetal);
  color: var(--chalk);
  font-family: var(--font-body);
  font-size: 14px;
}

body { display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; height: 56px; flex: 0 0 auto;
  border-bottom: 1px solid var(--hairline);
  background: linear-gradient(180deg, #1a212b, #161c24);
}

.wordmark { display: flex; align-items: center; gap: 10px; }
.mark { width: 26px; height: 26px; color: var(--trace); }
.wordmark-text {
  font-family: var(--font-display);
  font-size: 19px; letter-spacing: 0.22em; font-weight: 300; color: var(--chalk);
}
.wordmark-text b { font-weight: 700; color: var(--trace); }
.tagline {
  margin-left: 8px; padding-left: 12px; border-left: 1px solid var(--hairline);
  color: var(--slate-dim); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.08em;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

.file-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px; border: 1px solid var(--hairline); border-radius: 999px;
  background: var(--panel); font-family: var(--font-mono); font-size: 12px; color: var(--slate);
  max-width: 340px;
}
.file-badge-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dim-badge {
  padding: 1px 8px; border-radius: 999px; font-weight: 700; font-size: 11px; letter-spacing: 0.06em;
  background: rgba(56, 225, 255, 0.14); color: var(--trace); border: 1px solid rgba(56, 225, 255, 0.35);
}
.dim-badge.is3d { background: rgba(255, 176, 46, 0.12); color: var(--rapid); border-color: rgba(255, 176, 46, 0.4); }

/* ------------------------------------------------------------------ layout */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 308px minmax(0, 1fr); gap: 14px;
  padding: 14px;
}

.sidebar { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; min-height: 0; min-width: 0; }

.panel {
  background: var(--panel); border: 1px solid var(--hairline-soft);
  border-radius: var(--radius); padding: 14px;
}
.panel-title {
  margin: 0 0 12px; font-family: var(--font-display); font-weight: 600;
  font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--slate);
}

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--hairline); border-radius: var(--radius);
  padding: 20px 12px; text-align: center; color: var(--slate);
  cursor: pointer; transition: border-color .15s, background .15s, color .15s;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover {
  border-color: var(--trace); color: var(--chalk); background: rgba(56, 225, 255, 0.05);
}
.dz-icon { width: 40px; height: 40px; opacity: .8; }
.dz-title { margin: 8px 0 2px; font-weight: 600; color: inherit; }
.dz-sub { margin: 0; font-size: 12px; color: var(--slate-dim); }

.sample-row { display: flex; gap: 8px; margin-top: 10px; }
.sample-row .btn { flex: 1; }

/* buttons */
.btn {
  font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  padding: 8px 14px; transition: filter .12s, background .12s, border-color .12s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--chalk); background: var(--panel-2);
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--trace); color: #06222b; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-accent { background: var(--trace); color: #06222b; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--hairline); color: var(--slate); }
.btn-ghost:hover:not(:disabled) { color: var(--chalk); border-color: var(--slate-dim); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; margin-top: 10px; }

.btn-spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(6, 34, 43, 0.35); border-top-color: #06222b;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* switches */
.switch-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer;
  user-select: none; color: var(--chalk);
}
.switch-row input { display: none; }
.switch {
  width: 34px; height: 19px; border-radius: 999px; background: var(--hairline);
  position: relative; transition: background .15s; flex: 0 0 auto;
}
.switch::after {
  content: ""; position: absolute; top: 2.5px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%; background: var(--slate);
  transition: transform .15s, background .15s;
}
.switch-row input:checked + .switch { background: rgba(56, 225, 255, 0.35); }
.switch-row input:checked + .switch::after { transform: translateX(14px); background: var(--trace); }
.switch-label { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; }

.legend { display: flex; gap: 16px; margin-top: 8px; color: var(--slate); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 16px; height: 0; border-top: 2.5px solid; border-radius: 2px; display: inline-block; }
.key-cut { border-color: var(--trace); }
.key-rapid { border-top-style: dashed; border-color: var(--rapid); }

/* stats */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--panel-2); border: 1px solid var(--hairline-soft);
  border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px;
}
.stat-label { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--slate-dim); }
.stat-val { font-family: var(--font-mono); font-size: 14px; color: var(--chalk); }

/* convert */
.format-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden;
  margin-bottom: 12px;
}
.fmt {
  background: transparent; border: 0; cursor: pointer;
  padding: 7px 0; color: var(--slate);
  font-family: var(--font-display); font-size: 12.5px; font-weight: 700;
  letter-spacing: 0.18em; text-transform: uppercase;
  transition: background .12s, color .12s;
}

.field { margin-bottom: 10px; display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--slate); }
.field select, .field input[type="number"] {
  background: var(--panel-2); color: var(--chalk);
  border: 1px solid var(--hairline); border-radius: 8px; padding: 7px 9px;
  font-family: var(--font-body); font-size: 13.5px; outline: none;
}
.field select:focus, .field input:focus { border-color: var(--trace); }
.hint { margin: 10px 0 0; font-size: 12px; color: var(--slate-dim); }
.hint b { color: var(--slate); }

/* ------------------------------------------------------------------ stage */
.stage {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--panel); border: 1px solid var(--hairline-soft);
  border-radius: var(--radius); overflow: hidden;
}

.stage-tabs {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; border-bottom: 1px solid var(--hairline-soft);
}
.tab {
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--slate); font-family: var(--font-display); font-size: 12.5px;
  letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600;
  padding: 6px 14px; cursor: pointer; transition: color .12s, background .12s;
}
.tab:hover { color: var(--chalk); }
.tab.active { color: var(--trace); background: rgba(56, 225, 255, 0.08); border-color: rgba(56, 225, 255, 0.25); }
.stage-hint { margin-left: auto; font-size: 11.5px; color: var(--slate-dim); font-family: var(--font-mono); }

.viewport { position: relative; flex: 1 1 auto; min-height: 0; background: #0e1218; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.view canvas { display: block; }
#view3d canvas { width: 100%; height: 100%; }

.empty-state[hidden], .empty-state.is-hidden { display: none !important; }

.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; color: var(--slate-dim);
  pointer-events: none;
}
.empty-state svg { width: 72px; height: 72px; opacity: .5; margin-bottom: 6px; }
.empty-state p { margin: 0; font-weight: 600; color: var(--slate); }
.empty-state .empty-sub { font-weight: 400; font-size: 12.5px; color: var(--slate-dim); }

/* DRO — signature readout strip */
.dro {
  display: flex; align-items: stretch; gap: 0;
  border-top: 1px solid var(--hairline-soft);
  background: linear-gradient(180deg, #141a22, #10151c);
  font-family: var(--font-mono);
}
.dro-cell {
  padding: 8px 16px; font-size: 12.5px; color: var(--slate-dim);
  border-right: 1px solid var(--hairline-soft);
  display: inline-flex; align-items: baseline; gap: 8px;
}
.dro-cell b {
  color: var(--trace); font-weight: 600; font-size: 15px;
  min-width: 84px; text-align: right; font-variant-numeric: tabular-nums;
}
.dro-grid b { color: var(--slate); font-size: 12.5px; min-width: 0; }
.dro-units { margin-left: auto; border-right: 0; border-left: 1px solid var(--hairline-soft); color: var(--slate); }

/* ------------------------------------------------------------------ misc */
.footer {
  flex: 0 0 auto; text-align: center; padding: 6px 0 10px;
  color: var(--slate-dim); font-size: 11.5px; font-family: var(--font-mono);
}

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel-2); border: 1px solid var(--hairline); border-left: 3px solid var(--trace);
  color: var(--chalk); padding: 10px 14px; border-radius: 8px; font-size: 13px;
  max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toast-in .18s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--rapid); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}



/* ------------------------------------------------------------------ simulation */
.panel-heading-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.panel-heading-row .panel-title { margin-bottom: 12px; }
.sim-percent {
  font-family: var(--font-mono); color: var(--trace); font-size: 12px;
  padding: 2px 7px; border-radius: 999px; border: 1px solid rgba(56, 225, 255, .22);
  background: rgba(56, 225, 255, .07);
}
.sim-controls { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; gap: 8px; }
.sim-icon-btn { padding: 7px 0; font-size: 15px; }
.sim-play-btn { min-width: 0; padding: 7px 10px; }
.sim-progress {
  width: 100%; margin: 13px 0 8px; height: 5px; accent-color: var(--trace); cursor: pointer;
}
.sim-progress:disabled { opacity: .45; cursor: not-allowed; }
.sim-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  color: var(--slate-dim); font-size: 11.5px; min-height: 28px;
}
#simStatus { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-speed-label { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.sim-speed-label select {
  background: var(--panel-2); color: var(--chalk); border: 1px solid var(--hairline);
  border-radius: 7px; padding: 3px 5px; font-family: var(--font-mono); font-size: 11px;
}
.arrow-key { color: var(--trace); font-style: normal; font-size: 14px; line-height: 1; }

/* ------------------------------------------------------------------ responsive layout */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 286px minmax(0, 1fr); }
}

@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; min-height: auto; }
  .sidebar { order: 2; overflow: visible; }
  .stage { order: 1; min-height: 58vh; }
  .tagline, .stage-hint { display: none; }
  .topbar { padding: 0 10px; }
  .file-badge { display: none !important; }
}

@media (max-width: 560px) {
  .layout { padding: 8px; gap: 8px; }
  .wordmark-text { font-size: 16px; letter-spacing: .14em; }
  .mark { width: 23px; height: 23px; }
  .dro-cell { padding: 7px 8px; }
  .dro-cell b { min-width: 54px; font-size: 13px; }
  .dro-grid { display: none; }
  .stage-tabs { overflow-x: auto; }
  .tab { white-space: nowrap; padding: 6px 9px; }
}

/* ------------------------------------------------------------------ cutting calculator */
.cutting-panel .panel-heading-row .panel-title { margin-bottom: 12px; }
.calc-badge {
  margin-top: -10px; padding: 2px 6px; border-radius: 999px;
  border: 1px solid rgba(255,176,46,.28); background: rgba(255,176,46,.08);
  color: var(--rapid); font: 9px/1.4 var(--font-mono); letter-spacing: .06em;
}
.calc-badge-auto {
  border-color: rgba(56,225,255,.28); background: rgba(56,225,255,.075); color: var(--trace);
}
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 10px; }
.field-grid-3 .field { min-width: 0; margin-bottom: 0; }
.field-grid-3 .field input { width: 100%; min-width: 0; padding-left: 6px; padding-right: 4px; font-size: 11.5px; }
.calc-advanced {
  margin: 2px 0 12px; border: 1px solid var(--hairline-soft); border-radius: 8px;
  padding: 7px 9px; background: rgba(255,255,255,.012);
}
.calc-advanced summary { cursor: pointer; color: var(--slate); font-size: 11.5px; user-select: none; }
.optimal-setpoint {
  margin: 0 0 9px; padding: 10px 11px; border: 1px solid rgba(56,225,255,.30); border-radius: 9px;
  background: linear-gradient(135deg, rgba(56,225,255,.09), rgba(56,225,255,.025));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.015);
}
.optimal-setpoint span { display: block; color: var(--slate-dim); font-size: 9.5px; text-transform: uppercase; letter-spacing: .10em; }
.optimal-setpoint b { display: block; margin-top: 4px; color: var(--trace); font: 600 15px/1.35 var(--font-mono); overflow-wrap: anywhere; }
.optimal-setpoint small { display: block; margin-top: 4px; color: var(--slate); font-size: 10.5px; line-height: 1.35; }
.cut-results { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.cut-result {
  min-width: 0; padding: 8px 9px; border: 1px solid var(--hairline-soft); border-radius: 8px;
  background: var(--panel-2); display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto;
  column-gap: 6px; align-items: baseline;
}
.cut-result span { grid-column: 1 / -1; color: var(--slate-dim); font-size: 10px; text-transform: uppercase; letter-spacing: .09em; }
.cut-result b { overflow: hidden; text-overflow: ellipsis; color: var(--chalk); font: 600 15px/1.25 var(--font-mono); }
.cut-result small { color: var(--slate-dim); font: 9.5px/1 var(--font-mono); white-space: nowrap; }
.cut-result-primary { border-color: rgba(56,225,255,.20); background: rgba(56,225,255,.045); }
.cut-result-primary b { color: var(--trace); }
.cut-result-load-mid { border-color: rgba(255,176,46,.28); background: rgba(255,176,46,.055); }
.cut-result-load-mid b { color: var(--rapid); }
.cut-result-load-high { border-color: rgba(255,91,110,.32); background: rgba(255,91,110,.065); }
.cut-result-load-high b { color: #ff7c8d; }
.time-result { grid-column: 1 / -1; grid-template-columns: 1fr auto; }
.time-result b { color: var(--rapid); font-size: 17px; }
.cut-note { margin: 10px 0 0; color: var(--slate); font-size: 11.5px; line-height: 1.45; }
.cut-warnings {
  margin-top: 8px; padding: 8px 9px; border-radius: 8px; border: 1px solid rgba(255,176,46,.22);
  background: rgba(255,176,46,.055); color: #d7b273; font-size: 11px; line-height: 1.42;
}
.cut-warnings p { margin: 0 0 4px; }
.cut-warnings p:last-child { margin-bottom: 0; }
.calc-disclaimer { border-top: 1px solid var(--hairline-soft); padding-top: 9px; line-height: 1.45; }

@media (max-width: 560px) {
  .field-grid-2, .field-grid-3 { grid-template-columns: 1fr; }
}
