: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;
  /* 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;
    --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: 880px; 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-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 0.55rem; flex-wrap: wrap;
  margin: 0.6rem 0 0;
}
.units-label { color: var(--muted); font-size: 0.85rem; }
.unit-switch {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: inherit; cursor: pointer;
}
.unit-track {
  position: relative; width: 2.6rem; height: 1.4rem; border-radius: 999px;
  background: var(--accent); transition: background 0.15s ease;
  flex: 0 0 auto;
}
.unit-knob {
  position: absolute; top: 0.2rem; left: 0.2rem;
  width: 1rem; height: 1rem; border-radius: 50%; background: #fff;
  transition: transform 0.15s ease;
}
.unit-reading {
  font-size: 0.9rem; font-weight: 600; color: var(--accent);
  min-width: 2.1rem; text-align: left;   /* fixed width: the bar is centred, so
                                            an "mm"/"in" width change would
                                            otherwise shift the whole group */
}
.unit-switch[aria-checked="true"] .unit-track { background: var(--warn); }
.unit-switch[aria-checked="true"] .unit-knob { transform: translateX(1.2rem); }
.unit-switch[aria-checked="true"] .unit-reading { color: var(--warn); }
.unit-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.unit-switch[aria-checked="true"]:focus-visible { outline-color: var(--warn); }
@media (prefers-reduced-motion: reduce) {
  .unit-track, .unit-knob { 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); }
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: center; gap: 0.8rem;
  padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border);
}
/* 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-title, #preview-info, #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; }
#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); }
#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;
}
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);
}
td.result { color: var(--muted); font-size: 0.9rem; }
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); }

/* 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; }
#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; }
}
