/* step to vr — Formation Design Group visual language.
   Near-black ladder (#080808 → #222), brand red-orange #ff3300 for
   everything actionable, DM Sans display over JetBrains Mono UI,
   rounded-square geometry (16 / 8 / 4) echoing the F. mark.
   Engineering register kept: title block, corner marks on the
   viewport, baseline strip stating the conversion contract. */

/* ---- vendored brand fonts (repo policy: no CDN) ----------------------- */

@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url(fonts/dm-sans-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 400 500;
  font-display: swap;
  src: url(fonts/dm-sans-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 300 600;
  font-display: swap;
  src: url(fonts/jetbrains-mono-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 300 600;
  font-display: swap;
  src: url(fonts/jetbrains-mono-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

:root {
  --bg:        #080808;
  --surface:   #0e0e0e;
  --raised:    #161616;
  --line:      #2a2a2a;
  --line-soft: #1f1f1f;
  --text:      #c8c8c8;
  --bright:    #ececec;
  --dim:       #666666;
  --muted:     #444444;
  --accent:      #ff3300;
  --accent-down: #e62e00;
  --accent-dim:  #b32e0c;
  --accent-soft: rgba(255, 51, 0, .1);
  --ok:       #44aa88;
  --ok-soft:  rgba(68, 170, 136, .12);
  --bad:      #cc4444;
  --bad-soft: rgba(204, 68, 68, .1);
  --r-card: 16px;
  --r:      8px;
  --r-tag:  4px;
  --font-ui: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SF Mono",
             Consolas, "DejaVu Sans Mono", monospace;
  --font-display: "DM Sans", Futura, "Century Gothic", "URW Gothic",
                  "Avenir Next", system-ui, sans-serif;
  --topbar-h: 52px;
  --baseline-h: 32px;
  --pad: 24px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 12px/1.6 var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--text); text-decoration-color: var(--dim); text-underline-offset: 3px; }
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

::selection { background: var(--accent); color: #fff; }

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

/* ---- chrome: top bar + baseline strip -------------------------------- */

.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0 var(--pad);
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.brand {
  display: inline-flex; align-items: center; gap: .6rem;
  font-family: var(--font-display);
  font-size: 15px; font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--bright); text-decoration: none;
}
.brand:hover { color: var(--bright); }
.brand-mark { height: 18px; width: auto; flex: none; }
.topbar-ctx {
  display: flex; align-items: center; gap: 1rem;
  min-width: 0; overflow: hidden;
  color: var(--dim); font-size: 11px;
}
.topbar-ctx span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .logout { margin-left: auto; flex: none; }

.baseline {
  height: var(--baseline-h);
  display: flex; align-items: center; gap: 2rem;
  padding: 0 var(--pad);
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  flex: none;
}
.baseline-copyright { margin-left: auto; text-transform: none; letter-spacing: 0; }

main {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: var(--pad);
}

/* ---- type ------------------------------------------------------------ */

h1 {
  font-family: var(--font-display);
  font-size: 17px; font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--bright);
  margin: 0 0 1.2rem;
}
h2, .label {
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 .6rem;
}
.label { display: block; margin: 0 0 .25rem; }
small, .muted { color: var(--dim); }
.error {
  color: var(--bad);
  background: var(--bad-soft);
  border: 1px solid var(--bad);
  border-radius: var(--r);
  padding: .6rem .8rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* ---- plates (surfaces) ------------------------------------------------ */

.plate {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.6rem;
}
main > .plate + .plate { margin-top: var(--pad); }
.plate.narrow { max-width: 400px; margin: 12vh auto 0; padding: 2rem; }
.plate.narrow input { width: 100%; margin-bottom: 1rem; }
.plate.narrow .error { margin-bottom: 1rem; }

/* auth card: F. mark top-left, sans title, dim subtitle */
.auth-mark { height: 44px; width: auto; display: block; margin-bottom: 1.2rem; }
.plate.narrow h1 { margin-bottom: .4rem; }
.auth-sub { color: var(--dim); margin: 0 0 1.4rem; }

/* drawing-sheet corner registration marks (viewport only) */
#viewport.marks::after {
  content: "";
  position: absolute;
  inset: 10px;
  pointer-events: none;
}
.marks, #viewport.marks::after {
  --tick: 14px;
  background-image:
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted)),
    linear-gradient(var(--muted), var(--muted));
  background-repeat: no-repeat;
  background-size:
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick),
    var(--tick) 1px, 1px var(--tick);
  background-position:
    0 0, 0 0,
    100% 0, 100% 0,
    0 100%, 0 100%,
    100% 100%, 100% 100%;
}

/* ---- controls ---------------------------------------------------------- */

button, .button {
  font: 500 12px/1 var(--font-ui);
  letter-spacing: .04em;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .6rem 1.1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
button:hover, .button:hover { border-color: var(--dim); color: var(--bright); }
button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover, .button.primary:hover {
  background: var(--accent-down);
  border-color: var(--accent-down);
}
button.block { display: block; width: 100%; }
.button.small, button.small { padding: .35rem .7rem; font-size: 11px; }

input[type=text], input[type=number], input[type=password] {
  font: 12px/1.4 var(--font-ui);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .55rem .75rem;
}
input:focus-visible { outline: none; border-color: var(--accent-dim); }
input::placeholder { color: var(--muted); }

fieldset { border: 0; margin: 0; padding: 0; }
legend {
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--dim);
  padding: 0; margin-bottom: .6rem;
}

/* ---- status chips ------------------------------------------------------ */

.status {
  display: inline-block;
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  padding: .25rem .55rem;
  border-radius: var(--r-tag);
  border: 1px solid var(--line);
  color: var(--dim);
}
.status.queued  { color: var(--dim); }
.status.running {
  color: var(--accent); border-color: var(--accent);
  background: var(--accent-soft);
}
.status.done   { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.status.failed { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }

@keyframes pulse { 50% { opacity: .45; } }
.status.running { animation: pulse 1.6s ease-in-out infinite; }

/* ---- index: workbench -------------------------------------------------- */

.workbench {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: var(--pad);
  align-items: start;
}

.dropzone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .35rem;
  min-height: 180px;
  padding: 1.6rem;
  margin-bottom: 1.4rem;
  background-color: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s ease;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent-dim); }
.dropzone input[type=file] {
  position: absolute; width: 1px; height: 1px;
  opacity: 0; overflow: hidden;
}
.dropzone:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.dz-shape {
  width: 26px; height: 26px;
  border: 1px solid var(--dim);
  border-radius: var(--r-tag);
  margin-bottom: .8rem;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover .dz-shape, .dropzone.drag .dz-shape {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dz-title { font-size: 12px; color: var(--bright); }
.dz-sub { font-size: 11px; color: var(--dim); }
.dz-file { font-size: 12px; color: var(--accent); word-break: break-all; }
.dz-file:empty { display: none; }

.presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5rem;
}
.preset {
  position: relative;
  display: block;
  padding: .55rem .7rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  transition: border-color .15s ease;
}
.preset:hover { border-color: var(--dim); }
.preset input { position: absolute; opacity: 0; pointer-events: none; }
.preset-name { display: block; font-weight: 500; font-size: 12px; }
.preset-spec { display: block; font-size: 10px; color: var(--dim); margin-top: .15rem; }
.preset:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.preset:has(input:checked) .preset-name { color: var(--accent); }
.preset:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.custom-fields {
  display: none;
  gap: .8rem;
  margin-top: .7rem;
}
.quality:has(input[value=custom]:checked) .custom-fields { display: flex; }
.custom-fields label {
  display: flex; align-items: center; gap: .45rem;
  font-size: 11px; color: var(--dim);
}
.custom-fields input { width: 6.5rem; padding: .35rem .5rem; }

form.upload button[type=submit] { margin-top: 1.4rem; }

/* ---- tables ------------------------------------------------------------ */

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th {
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--dim);
  text-align: left;
  padding: 0 1rem .5rem 0;
  border-bottom: 1px solid var(--line);
}
td {
  padding: .55rem 1rem .55rem 0;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; }
td.actions a { margin-left: .6rem; }
td.actions a:first-child { margin-left: 0; }

table.kv td:first-child {
  color: var(--dim);
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  width: 12rem;
  vertical-align: top;
  padding-top: .7rem;
}

.empty {
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: var(--r);
  padding: 2.2rem 1rem;
  text-align: center;
}

/* ---- job page: title block ---------------------------------------------- */

.titleblock {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--bg);
  margin-bottom: 1.4rem;
}
.titleblock > div {
  padding: .8rem 1rem;
  border-left: 1px solid var(--line-soft);
  min-width: 0;
}
.titleblock > div:first-child { border-left: 0; }
.titleblock h1 {
  font-size: 14px; margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.titleblock .value {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: block;
}

.filelist { margin: 1.2rem 0 0; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* ---- preview editor ------------------------------------------------------ */

#editor {
  display: flex; gap: var(--pad);
  height: calc(100vh - var(--topbar-h) - var(--baseline-h) - 2 * var(--pad));
  min-height: 420px;
}
#viewport {
  flex: 1; min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  overflow: hidden;
  background: var(--surface);
  position: relative;
}
#viewport canvas { display: block; }
#panel {
  width: 320px; flex: none;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 1rem;
}
#panel section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.1rem;
}
#panel h2 { margin-top: 0; }
#panel h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; }

.tgrid {
  display: grid;
  grid-template-columns: 3.2rem 1fr 1fr 1fr;
  gap: .45rem;
  align-items: center;
}
.tgrid label {
  font-size: 10px; font-weight: 500;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--dim);
}
.tgrid input { width: 100%; padding: .35rem .45rem; font-size: 12px; }

#parts {
  list-style: none; margin: 0; padding: 0;
  max-height: 38vh; overflow-y: auto;
}
#parts li {
  display: flex; align-items: center; gap: .6rem;
  padding: .3rem 0;
  border-bottom: 1px solid var(--line-soft);
}
#parts li:last-child { border-bottom: 0; }
#parts li span {
  flex: 1; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; color: var(--dim);
}
#parts input[type=color] {
  width: 26px; height: 18px; padding: 0; flex: none;
  border: 1px solid var(--line); border-radius: var(--r-tag);
  background: none; cursor: pointer;
}

#pubname { width: 100%; margin-bottom: .8rem; }
.panel-actions { display: flex; gap: .6rem; }
.panel-actions .primary { flex: 1; }
#pubresult { margin: .8rem 0 0; font-size: 11px; word-break: break-all; }
#pubresult:empty { display: none; }
#savestate { color: var(--accent); }
#savestate:empty { display: none; }

/* ---- scrollbars ----------------------------------------------------------- */

* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--line); }
::-webkit-scrollbar-track { background: transparent; }

/* ---- responsive / motion ---------------------------------------------------- */

@media (max-width: 960px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .titleblock { grid-template-columns: 1fr 1fr; }
  .titleblock > div:nth-child(odd) { border-left: 0; }
  .titleblock > div { border-top: 1px solid var(--line-soft); }
  .titleblock > div:nth-child(-n+2) { border-top: 0; }
  #editor { flex-direction: column; height: auto; }
  #viewport { height: 55vh; }
  #panel { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
