:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #1c2330; --muted: #66707f;
  --accent: #2563eb; --border: #dde2ea;
  --ok: #16a34a; --bad: #dc2626; --run: #2563eb; --warn: #eab308;
  /* washes: a tint that reads as a category on a card, not as an alert */
  --warn-wash: #fdf6dd; --bad-wash: #fdeaea;
  --viewer-surface: #8ea3c4; --viewer-vertex: #ea580c; --viewer-edge: #33415c;
  --viewer-fill: #dc2626;
  /* measure tool: green highlights the feature under the cursor, amber locks a
     selected one */
  --measure-hover: #16a34a; --measure-select: #d97706; --measure-leader: #2563eb;
  /* outcome-overlay palette (validated CVD-safe on white): plane recedes to a
     neutral grey-blue, features take distinct hues, leftover facets alarm red */
  --fate-plane: #8a94a6; --fate-cylinder: #2a78d6; --fate-cone: #1baf7a;
  --fate-torus: #eda100; --fate-facet: #e34948; --fate-sphere: #8c5bd8;
  --fate-bspline: #17a2b8;
  /* duplicate-filename group colours: one hue per set of same-named jobs, so
     sets are found by eye rather than by reading every row. Colour is only an
     accelerator here — the filename beside it is the ground truth — so eight
     cycling hues are enough and none of them needs to mean anything. Red is
     left out: on a job row it reads as a failure, not as a group. */
  --dup-1: #2563eb; --dup-2: #ea580c; --dup-3: #059669; --dup-4: #9333ea;
  --dup-5: #0891b2; --dup-6: #db2777; --dup-7: #a16207; --dup-8: #64748b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1a1f29; --text: #e7ebf2; --muted: #97a1b1;
    --accent: #60a5fa; --border: #2a3140;
    --ok: #4ade80; --bad: #f87171; --run: #60a5fa; --warn: #facc15;
    --warn-wash: #2a2413; --bad-wash: #2e1a1a;
    --viewer-surface: #55688a; --viewer-vertex: #fb923c; --viewer-edge: #10161f;
    --viewer-fill: #ef4444;
    --measure-hover: #22c55e; --measure-select: #f59e0b; --measure-leader: #60a5fa;
    --fate-plane: #5b6472; --fate-cylinder: #3987e5; --fate-cone: #199e70;
    --fate-torus: #c98500; --fate-facet: #e66767; --fate-sphere: #a07be0;
    --fate-bspline: #3bbdd0;
    --dup-1: #60a5fa; --dup-2: #fb923c; --dup-3: #34d399; --dup-4: #c084fc;
    --dup-5: #22d3ee; --dup-6: #f472b6; --dup-7: #d0a02a; --dup-8: #94a3b8;
  }
}
* { box-sizing: border-box; }
/* `hidden` is the attribute the JS toggles, but the UA rule behind it is only
   `display: none` at the lowest specificity — so any id rule stating a
   `display` (a flex row, say) silently outranks it and the element stays on
   screen. That is not theoretical: #overlay-legend and #units-bar were both
   painted while marked hidden. Say it once, here, so `.hidden = true` means
   the same thing everywhere. */
[hidden] { display: none !important; }
body {
  margin: 0 auto; max-width: 1040px; padding: 1.2rem;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text);
}
header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.02em; }
.pill {
  padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.8rem;
  background: var(--card); border: 1px solid var(--border); white-space: nowrap;
}
#dropzone {
  margin-top: 1.2rem; padding: 2.2rem 1rem; text-align: center; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 12px; background: var(--card);
  display: flex; flex-direction: column; gap: 0.3rem;
}
#dropzone span { color: var(--muted); font-size: 0.9rem; }
#dropzone.drag, #dropzone:hover, #dropzone:focus-visible { border-color: var(--accent); outline: none; }

/* Inch mode washes the dropzone, so the one control that changes what a
   dropped file *means* is visible from wherever the eye happens to be — the
   switch is small and the consequence is a 25.4x scale. */
#dropzone.inch { background: var(--warn-wash); border-color: var(--warn); }

/* ---- input-unit switch --------------------------------------------------
   Under the dropzone, above the job list.  Blue (the GUI accent) is mm, the
   default; yellow is inches, matching the yellow the page already reserves
   for "you are doing something that needs saying out loud". */
/* Units and Mode sit side by side in one centred row (wraps on narrow screens). */
#controls-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 1.4rem; flex-wrap: wrap;
  margin: 0.6rem 0 0;
}
#units-bar, #mode-bar, #decimate-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 0.55rem; flex-wrap: wrap;
}
.units-label { color: var(--muted); font-size: 0.85rem; }
/* Segmented two-label slider. Both switches read the same way: the default
   sits on the RIGHT in blue (the GUI accent), and the thumb slides LEFT and
   turns yellow (the page's "you're doing something worth announcing" colour)
   when the non-default is chosen. aria-checked == "changed from default":
   false = default (mm / quality), true = the yellow opt-in (in / fast). */
.seg-switch {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.seg-track {
  position: relative; display: flex;
  background: var(--border); border-radius: 8px; overflow: hidden;
}
.seg-thumb {
  position: absolute; top: 0; bottom: 0; left: 0; width: 50%;
  border-radius: 8px; background: var(--accent);   /* default: blue, right */
  transform: translateX(100%);
  transition: transform 0.16s ease, background 0.16s ease;
}
.seg-opt {
  position: relative; z-index: 1; flex: 1 1 0; text-align: center;
  padding: 0.32rem 0.85rem; font-weight: 600; font-size: 0.9rem;
  white-space: nowrap; color: var(--muted); transition: color 0.16s ease;
}
/* default state: right label active, white on blue */
.seg-switch .seg-right { color: #fff; }
/* changed: thumb slides left and turns yellow; left label active, dark on yellow */
.seg-switch[aria-checked="true"] .seg-thumb { transform: translateX(0); background: var(--warn); }
.seg-switch[aria-checked="true"] .seg-right { color: var(--muted); }
.seg-switch[aria-checked="true"] .seg-left { color: #1c2330; }
.seg-switch:focus-visible .seg-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg-switch[aria-checked="true"]:focus-visible .seg-track { outline-color: var(--warn); }
/* Decimate switch: red where the other two are blue/yellow — it governs the red
   Decimate button and red refusal text, so it wears the same colour. "Allow
   Decimate" is the default (right, red); "Do not Decimate" greys it out (left).
   aria-checked == changed-from-default, so false = Allow (red), true = greyed. */
#decimate-bar .seg-thumb { background: var(--bad); }
#decimate-bar .seg-switch[aria-checked="true"] .seg-thumb { background: var(--muted); }
#decimate-bar .seg-switch[aria-checked="true"] .seg-left { color: #fff; }
#decimate-bar .seg-switch:focus-visible .seg-track { outline-color: var(--bad); }
#decimate-bar .seg-switch[aria-checked="true"]:focus-visible .seg-track { outline-color: var(--muted); }
@media (prefers-reduced-motion: reduce) {
  .seg-thumb { transition: none; }
}
/* the job list marks inch conversions, so a row's numbers can be read back to
   what the file was taken to mean */
.pill.units { color: var(--warn); border-color: var(--warn); }
.pill.resolution.fast { color: var(--warn); border-color: var(--warn); }
.pill.resolution.quality { color: var(--accent); border-color: var(--accent); }
.pill.narrow { padding: 0.15rem 0.15rem; }
.pill.decimate.on { color: var(--bad); border-color: var(--bad); }
.pill.decimate.off { color: var(--muted); }
select {
  font: inherit; font-size: 0.9rem; background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 0.15rem 0.3rem;
}
button, .btn {
  font: inherit; font-size: 0.88rem; cursor: pointer; text-decoration: none;
  background: var(--accent); color: #fff; border: none;
  border-radius: 7px; padding: 0.3rem 0.7rem;
}
button.ghost, .btn.ghost {
  background: transparent; color: var(--accent); border: 1px solid var(--border);
}
button.danger, .btn.danger { background: var(--bad); color: #fff; }
/* Yellow needs dark text in both themes — white on yellow fails contrast. */
button.yellow, .btn.yellow { background: var(--warn); color: #1c2330; }
button.icon { display: inline-flex; align-items: center; padding: 0.3rem 0.5rem; }
button.icon svg { width: 1em; height: 1em; display: block; }
button:hover, .btn:hover { filter: brightness(1.12); }
#error-bar {
  border: 1px solid var(--bad); color: var(--bad);
  padding: 0.5rem 0.8rem; border-radius: 8px;
}
#preview {
  margin: 0 0 1.4rem; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
}
/* The close button pins to the head's top right: the head itself never wraps,
   the controls wrap inside their own flex box. */
.preview-head {
  display: flex; align-items: stretch; gap: 0.8rem;
  padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border);
}
/* file name on top, measure-tool toggle pinned to the bottom so it lines up
   with the last checkbox row on the right */
.preview-head-left {
  display: flex; flex-direction: column; justify-content: space-between;
  gap: 0.6rem; min-width: 0;
}
.preview-head-titles { display: flex; align-items: baseline; gap: 0.8rem;
  flex-wrap: wrap; }
.measure-tool {
  display: inline-flex; align-items: center; gap: 0.4rem; align-self: flex-start;
  padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); cursor: pointer;
  font: inherit; font-size: 0.9rem; white-space: nowrap;
}
.measure-tool:hover { border-color: var(--accent); }
.measure-tool[aria-pressed="true"] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.measure-tool svg { flex: none; }
/* one fixed row per control group, each right-aligned so the two sliders'
   tracks line up (equal slider width + equal value-span width). The column
   takes its widest row's natural width and the info line yields instead, so
   no row has to wrap. */
.preview-controls {
  flex: none; margin-left: auto; display: flex; flex-direction: column;
  align-items: flex-end; gap: 0.4rem;
}
.preview-row {
  display: flex; align-items: center; justify-content: flex-end; gap: 0.4rem 0.8rem;
}
/* a row whose every control is hidden must not spend a gap */
.preview-row:not(:has(> :not([hidden]))) { display: none; }
/* whole controls wrap; their labels never break mid-phrase */
.preview-controls .opt { white-space: nowrap; }
#preview-close { align-self: flex-start; }
#preview-title { flex: none; }
#preview-info { min-width: 0; }   /* the head never wraps, so this line yields first */
#preview-close { white-space: nowrap; }
#preview-info { color: var(--muted); font-size: 0.9rem; }
.opt.slider { display: inline-flex; align-items: center; gap: 0.5rem;
  color: var(--muted); font-size: 0.9rem; }
.opt.slider input[type="range"] { width: 9rem; accent-color: var(--accent); }
#vertex-size-val, #edge-size-val { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; }
#preview-canvas { display: block; width: 100%; height: 420px; }
/* the spinner is positioned against the canvas, not the card, so it stays
   centred on the view whatever the head above it wraps to */
.preview-stage { position: relative; }
/* buttons that float over the 3-D view (reset-view, top-right corner) */
.stage-btn {
  position: absolute; top: 0.6rem; right: 0.6rem; z-index: 3;
  padding: 0.3rem 0.7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text); cursor: pointer;
  font: inherit; font-size: 0.85rem; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.14);
}
.stage-btn:hover { border-color: var(--accent); }
#preview-spinner {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.spinner {
  width: 2.4rem; height: 2.4rem; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* a spinner that cannot spin would read as a frozen view, so state the wait
   in the one way that survives the preference */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}
#overlay-legend {
  display: flex; flex-wrap: wrap; gap: 0.4rem 1rem;
  padding: 0.5rem 0.9rem; border-top: 1px solid var(--border);
  font-size: 0.82rem; color: var(--muted);
}
#overlay-legend .swatch {
  display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap;
}
#overlay-legend .chip {
  width: 0.85rem; height: 0.85rem; border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
}
#overlay-legend .count { font-variant-numeric: tabular-nums; color: var(--text); }

/* measure tool: a popup floating over the top-left of the 3-D view while the
   tool is toggled on */
#measure-panel {
  position: absolute; top: 0.6rem; left: 0.6rem; z-index: 3;
  max-width: min(20rem, calc(100% - 1.2rem));
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.5rem 0.7rem; font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}
/* the value label floating at the midpoint of a dimension leader line */
.measure-label {
  position: absolute; z-index: 4; transform: translate(-50%, -50%);
  pointer-events: none; white-space: nowrap;
  padding: 0.05rem 0.4rem; border-radius: 6px;
  background: var(--measure-leader); color: #fff;
  font-size: 0.78rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.measure-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.measure-bar strong { color: var(--text); }
#measure-hint { color: var(--muted); margin-top: 0.3rem; }
#measure-readout { margin-top: 0.5rem; display: flex; flex-direction: column;
  gap: 0.25rem; }
.measure-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.measure-chip {
  background: var(--warn-wash); border: 1px solid var(--border);
  border-radius: 999px; padding: 0.05rem 0.55rem; color: var(--text);
  font-size: 0.78rem;
}
.measure-title { font-weight: 600; color: var(--text); }
.measure-row {
  display: flex; justify-content: space-between; max-width: 22rem;
  border-bottom: 1px dotted var(--border); padding: 0.1rem 0;
}
.measure-row .m-label { color: var(--muted); }
.measure-row .m-val {
  font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600;
}
.measure-note { color: var(--muted); font-style: italic; font-size: 0.8rem; }

#preview .hint {
  margin: 0; padding: 0.45rem 0.9rem; color: var(--muted); font-size: 0.82rem;
  border-top: 1px solid var(--border);
}
@media (max-width: 640px) {
  #preview-canvas { height: 300px; }
}

/* half a row of breathing space between the drop box and the file list */
.table-wrap { overflow-x: auto; margin-top: 1.3rem; }
table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
/* Auto layout: Status/Resolution/Actions size to their content (Actions holds
   up to six nowrap buttons, so it must never be pinned or the trash clips).
   We steer only the two flexible text columns — a preferred width the browser
   honours so Result stays wide and the file name isn't handed all the slack. */
th:nth-child(1) { width: 26%; }     /* File */
th:nth-child(4) { width: 30%; }     /* Result */
th, td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
th {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted);
}
/* File and Result get the leftover width (fixed layout splits it evenly). Both
   may hold long unbroken text, so let them wrap inside their column rather than
   overflow it; the pills inside the file cell stay nowrap by their own rule. */
td.result { color: var(--muted); font-size: 0.9rem; overflow-wrap: anywhere; }
/* a held row is a pending question — its note reads in the warning yellow */
td.result.held-note { color: var(--warn); }
/* a too-dense refusal offering a Decimate button reads in red, matching it */
td.result.decimate-note { color: var(--bad); }
td.file { overflow-wrap: anywhere; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn, td.actions button { margin-left: 0.35rem; }
.pill.status.queued { color: var(--muted); }
.pill.status.running { color: var(--run); border-color: var(--run); animation: pulse 1.2s infinite; }
.pill.status.done { color: var(--ok); border-color: var(--ok); }
.pill.status.failed, .pill.status.interrupted { color: var(--bad); border-color: var(--bad); }
.pill.status.cancelled { color: var(--muted); border-color: var(--muted); }
.pill.status.reference { color: var(--accent); border-color: var(--accent); }
.pill.status.held { color: var(--warn); border-color: var(--warn); }

/* Mode-choice popup: a real overlay (unlike #feedback-panel, which is an inline
   view) — it blocks the page for a yes/no decision the upload needs answered. */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex;
  align-items: center; justify-content: center; padding: 1rem;
  background: rgba(0, 0, 0, 0.45);
}
/* an author `display` beats the UA `[hidden]{display:none}`, so restore it —
   without this the popup would show even while hidden */
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(30rem, 100%); padding: 1.2rem 1.3rem;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.modal strong { display: block; margin-bottom: 0.5rem; }
.modal p { margin: 0 0 1rem; color: var(--text); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* a job whose filename another current job shares — a small dot after the
   name, not in its own column; its colour is the set's own (--dup-N, assigned
   in JS) so identical files are spotted as a group */
.dup-dot {
  display: inline-block; width: 0.5rem; height: 0.5rem; margin-left: 0.4rem;
  border-radius: 50%; background: var(--dup-1); vertical-align: middle;
}
@keyframes pulse { 50% { opacity: 0.55; } }
#empty-hint { color: var(--muted); text-align: center; padding: 1.2rem 0; }
.header-actions {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
#whoami { color: var(--muted); font-size: 0.9rem; }

/* One comment panel for both flows (row thumbs-down, header feedback). */
#feedback-panel, #admin-panel {
  margin: 0.8rem 0; padding: 0.9rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card);
}
#feedback-text {
  display: block; width: 100%; margin: 0.5rem 0; padding: 0.5rem;
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; resize: vertical;
}
#feedback-note {
  margin: 0.5rem 0 0; color: var(--muted); font-size: 0.85rem;
}
/* the row flow's send label is a sentence, so the actions wrap on narrow screens */
.feedback-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
#notice-bar {
  margin: 0.6rem 0; padding: 0.5rem 0.7rem; border-radius: 6px;
  background: var(--card); border: 1px solid var(--border);
}
button.vote { font-size: 1rem; line-height: 1; padding: 0.3rem 0.5rem; }
button.vote.chosen { outline: 2px solid var(--accent); }

#admin-entries { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.6rem; }
.log-entry {
  padding: 0.6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card);
}
/* Colour states what the entry *is*, so the log can be scanned rather than
   read: a general note, a conversion somebody was happy with, a problem
   report.  Tint plus a left bar — colour is never the only signal, since the
   pill and the id say the same thing in words. */
.log-entry.conversion { background: var(--card); border-left: 4px solid var(--border); }
.log-entry.note { background: var(--warn-wash); border-left: 4px solid var(--warn); }
.log-entry.report { background: var(--bad-wash); border-left: 4px solid var(--bad); }
.log-head {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  color: var(--muted); font-size: 0.85rem;
}
/* Fixed columns for the two leading cells, so the identifiers and the
   up/down/note pills line up down the page and the log can be scanned by
   category without reading a word of it. */
.log-id {
  font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text);
  flex: none; min-width: 3.5rem;
}
.log-head > .pill { flex: none; min-width: 5.5rem; text-align: center; }
.log-head > .pill.narrow { min-width: 0; }
#admin-filters {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin-top: 0.7rem; padding-bottom: 0.2rem;
}
.log-filter { font-size: 0.82rem; }
.log-filter.chosen { background: var(--accent); color: #fff; border-color: var(--accent); }
/* the row's own numbers (size, time, what the converter did), muted under the
   words somebody wrote — the comment is what the owner came to read */
.log-meta { margin: 0.3rem 0 0; color: var(--muted); font-size: 0.82rem; }
.log-drop { margin-left: auto; }   /* the destructive control sits apart */
.log-comment { margin: 0.45rem 0 0; white-space: pre-wrap; }
/* The log is a view of its own: full width, and the wordmark is the way back. */
#admin-panel { margin-top: 1.2rem; }
h1 a { color: inherit; text-decoration: none; }
h1 a:hover, h1 a:focus-visible { color: var(--accent); }

/* Terms page: long-form text, so it gets a comfortable measure. */
.prose { max-width: 40rem; }
.prose h2 { margin: 1.6rem 0 0.4rem; font-size: 1.05rem; }
.prose p { margin: 0; color: var(--muted); }
.prose strong, .prose em { color: var(--text); }

/* Sign-in page: the only view somebody without a session ever sees. */
.login-page main { max-width: 22rem; margin: 12vh auto 0; }
.login-card { display: flex; flex-direction: column; gap: 0.7rem;
  padding: 1.4rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); }
.login-card h1 { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
.login-card input {
  padding: 0.5rem; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
}
#login-error { margin: 0; color: var(--bad); }

footer {
  margin-top: 1.6rem; padding-top: 0.8rem; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap;
  color: var(--muted); font-size: 0.85rem;
}
footer a { color: var(--accent); }
@media (max-width: 640px) {
  header { flex-direction: column; }
}
