/* An e-ink panel, not a web page.
 *
 * The constraint is deliberate and it is doing work: paper white, one ink,
 * hairline rules, no shadows, no gradients, no filled buttons. On a display
 * with no backlight you get contrast and position, so hierarchy has to come
 * from type size and whitespace — which happens to be exactly right for a wall
 * panel you glance at from across a room.
 *
 * Colour is rationed to state, and only to state: a machine that is running, a
 * fault that needs someone. Everything else is ink and grey. If a colour ever
 * appears here for decoration, this rule has been broken.
 */

:root {
  --paper: #f2f1ec;   /* the sheet */
  --card: #fbfaf7;    /* a lighter panel, still paper */
  --ink: #17170f;     /* full black is harsh on warm paper; this is not */
  --ink-2: #5c5a52;   /* labels, units, anything you read second */
  --ink-3: #918e84;   /* dividers of meaning, not of layout */
  --rule: #dcd8cf;    /* hairlines */
  --rule-2: #ebe8e1;
  --run: #2f6b46;     /* the one green: something is making a thing */
  --warn: #8a6218;
  --bad: #9d3324;
  --fill: #17170f;    /* progress and glyph fills */
  color-scheme: light;
  font-synthesis: none;
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  /* SF Pro where it exists, which on the machines this runs on is everywhere. */
  font: 400 14px/1.5 -apple-system, "SF Pro Text", "SF Pro Display", BlinkMacSystemFont,
        "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
           env(safe-area-inset-left);
}

main { max-width: 1400px; margin: 0 auto; padding: 20px 20px 72px; }

/* Queue left, machines right. The queue is a list you scan and reorder; the
   machines are a thing you look at. Different jobs, different columns.
   On a phone there is room for one of them, so they become tabs — a drawer
   would be a second navigation model for the same two destinations, and one
   you have to open before you can see whether it was worth opening. */
.split { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 26px;
         align-items: start; }
.split > .queue h2:first-child { margin-top: 0; }
.queue, .fleet { min-width: 0; }         /* or long job names widen the grid */

@media (min-width: 901px) { #tab-queue { display: none; } }

@media (max-width: 900px) {
  main { padding: 14px 14px 64px; }
  .split { grid-template-columns: minmax(0, 1fr); gap: 0; }
  body[data-panel="fleet"] .queue { display: none; }
  body[data-panel="queue"] .fleet { display: none; }
  body[data-panel="queue"] .queue h2:first-child { margin-top: 0; }
  /* Thumb-sized, and the header stops competing for the row. */
  button { padding: 7px 12px; }
  .bar { flex-wrap: wrap; gap: 8px 10px; }
  .bar nav { width: 100%; margin-left: 0; }
  .relay { order: 3; }
  h2 .hint { float: none; display: block; }
}

h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: -0.015em; }
h2 {
  font-size: 11px; font-weight: 590; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-3); margin: 34px 0 12px;
}
h2 .hint { float: right; text-transform: none; letter-spacing: 0; font-weight: 400;
           opacity: 0.75; }

.bar {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 14px; border-bottom: 1px solid var(--rule); margin-bottom: 22px;
}
.bar nav { margin-left: auto; display: flex; gap: 4px; align-items: center; }

/* Buttons are text with a hairline. Filled controls read as ink blots on paper. */
button {
  font: inherit; font-size: 13px; color: var(--ink); background: none;
  border: 1px solid var(--rule); border-radius: 7px; padding: 5px 11px; cursor: pointer;
}
button:hover { border-color: var(--ink-3); }
button:active { background: var(--rule-2); }
button:disabled { color: var(--ink-3); border-color: var(--rule-2); cursor: default; }
.tab.on { border-color: var(--ink); }
.ghost { border-color: transparent; color: var(--ink-2); }
.ghost:hover { border-color: var(--rule); }

/* The relay heartbeat: a filled dot when live, hollow when not. */
.relay { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 7px;
         font-variant-numeric: tabular-nums; }
.relay::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--run); border: 1px solid var(--run);
}
.relay.stale { color: var(--warn); }
.relay.stale::before { background: none; border-color: var(--warn); }
.relay.down { color: var(--bad); }
.relay.down::before { background: none; border-color: var(--bad); }

/* --- machine tiles -------------------------------------------------------- */

/* min() so a 320px minimum can never be wider than the screen it is on —
   that is what was pushing the whole page sideways on a phone. */
.grid { display: grid; gap: 16px; align-items: stretch;
        grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }

.machine {
  background: var(--card); border: 1px solid var(--rule); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column;
}
.machine.is-stale { opacity: 0.5; }

/* The camera comes first because it is the only thing on the tile that answers
   "is the bed actually clear" — every other row is the printer's own opinion. */
.shot { position: relative; aspect-ratio: 16 / 9; background: var(--rule-2);
        border-bottom: 1px solid var(--rule); }
.shot img { position: absolute; inset: 0; width: 100%; height: 100%;
             object-fit: cover; display: block; }
/* The hour meter sits on the frame, not in the data rows: it is a number you
   check once a week, and it must never compete with what is happening now. */
.hours {
  position: absolute; right: 8px; bottom: 8px; font-size: 10.5px;
  color: #fff; background: rgba(0,0,0,0.42); border-radius: 5px; padding: 1px 6px;
  font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
}
.shot .none {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 11px; color: var(--ink-3); text-align: center; padding: 0 18px;
}

.body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 10px;
        flex: 1; }

.head { display: flex; align-items: center; gap: 9px; }
.glyph { color: var(--ink-2); flex: none; }
.machine.is-running .glyph { color: var(--run); }
.head b { font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
          overflow: hidden; text-overflow: ellipsis; }
.head .class { flex: none; }
.head .class {
  font-size: 10px; font-weight: 590; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-2); border: 1px solid var(--rule); border-radius: 4px; padding: 1px 5px;
}
/* State is a word, not a badge. Weight and letterspacing carry it. */
.state {
  margin-left: auto; font-size: 10px; font-weight: 650; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--ink-2);
}
.state.running { color: var(--run); }
.state.error, .state.offline { color: var(--bad); }
.state.paused { color: var(--warn); }

.job { font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis;
       white-space: nowrap; min-width: 0; }
.job.none { color: var(--ink-3); }

.track { height: 3px; background: var(--rule-2); border-radius: 2px; overflow: hidden; }
.fill { height: 100%; background: var(--fill); transition: width 400ms ease-out; }

/* One line of figures, aligned, tabular, no decoration. */
.figures {
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.figures b { color: var(--ink); font-weight: 560; }

.slots { display: flex; gap: 5px; flex-wrap: wrap; padding-top: 2px; }
.slot {
  display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--ink-2);
  border: 1px solid var(--rule); border-radius: 5px; padding: 2px 6px;
  font-variant-numeric: tabular-nums;
}
.swatch { width: 9px; height: 9px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.22); }
.slot .unknown { color: var(--warn); }

/* Sentences, not hex. Maintenance is grey and quiet on purpose — see faults()
   in app.js for why rendering it red would be a design failure. */
.faults { display: flex; flex-direction: column; gap: 3px; }
.fault { font-size: 11.5px; line-height: 1.35; cursor: help; }
.fault.error { color: var(--bad); }
.fault.warning { color: var(--warn); }
.fault.maintenance { color: var(--ink-3); }
.fault.maintenance::before { content: "\00b7\00a0"; }

/* The bed, and the only thing that clears it until the camera interlock lands. */
.bed { display: flex; align-items: center; gap: 8px; font-size: 11.5px;
       color: var(--warn); margin-top: auto; padding-top: 2px; }
.bed.clear { color: var(--ink-3); }
.bed button { padding: 2px 8px; font-size: 12px; margin-left: auto; }

/* --- the queue ------------------------------------------------------------ */

.jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.jobs:empty::after {
  content: "Nothing queued."; color: var(--ink-3); font-size: 12px;
}
.jobs li {
  display: flex; align-items: baseline; gap: 8px; padding: 8px 10px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 9px;
  cursor: grab; user-select: none;
}
/* Dragging: the row you picked up dims, the seam you would drop into is a rule.
   No animation — a list you reorder ten times in a row should feel instant. */
.jobs li.dragging { opacity: 0.4; cursor: grabbing; }
.jobs li.over { box-shadow: 0 -2px 0 var(--ink) inset; }
.jobs li.printing { border-color: var(--run); cursor: default; }
.jobs li .n { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums;
              min-width: 1.2em; }
.jobs li .what { flex: 1; min-width: 0; font-size: 13px; overflow: hidden;
                 text-overflow: ellipsis; white-space: nowrap; }
.jobs li .what small { display: block; color: var(--ink-3); font-size: 11px; }
.jobs li .when { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.jobs li .drop { border: none; color: var(--ink-3); padding: 0 2px; font-size: 14px;
                 line-height: 1; }
.jobs li .drop:hover { color: var(--bad); }

/* Dropping a model anywhere on this column queues it. */
.queue { border-radius: 12px; transition: none; }
.queue.dropping { outline: 2px dashed var(--ink-3); outline-offset: 8px; }

.addjob { display: flex; gap: 6px; margin-top: 10px; }
.addjob input { flex: 1; min-width: 0; }
.addjob select { width: 84px; }

/* --- the shelf ------------------------------------------------------------ */

.stock { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.lot {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: var(--card); border: 1px solid var(--rule); border-radius: 9px;
}
.lot .swatch { width: 15px; height: 15px; border-radius: 3px; }
.lot .what { font-size: 13px; }
.lot .what small { display: block; color: var(--ink-3); font-size: 11px; }
.lot .count { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums;
              color: var(--ink-2); }
.lot button { padding: 2px 7px; font-size: 12px; }

.addstock { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-top: 12px; }
.addstock label { display: flex; flex-direction: column; gap: 4px; font-size: 11px;
                  color: var(--ink-3); letter-spacing: 0.04em; text-transform: uppercase; }
.addstock input[type="color"] { padding: 2px; width: 44px; height: 34px; cursor: pointer; }
.addstock input[name="count"] { width: 68px; }
.addstock select, .addstock input { height: 34px; }

.empty { color: var(--ink-3); padding: 26px; text-align: center;
         border: 1px dashed var(--rule); border-radius: 12px; }
.note { color: var(--ink-2); font-size: 12px; max-width: 62ch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 560; color: var(--ink-3); font-size: 10px;
     text-transform: uppercase; letter-spacing: 0.09em; padding: 6px 8px; }
td { padding: 8px; border-top: 1px solid var(--rule-2); }

.row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
input, select {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--card);
  border: 1px solid var(--rule); border-radius: 7px; padding: 7px 9px; min-width: 0;
}
input:focus-visible, button:focus-visible, select:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 1px;
}

.token { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px;
         background: var(--card); border: 1px solid var(--rule); border-radius: 8px;
         padding: 11px; overflow-wrap: anywhere; }

/* --- the gate ------------------------------------------------------------- */

.gate { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px;
  padding: 28px; width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px;
}
.card > div { display: flex; flex-direction: column; gap: 6px; }
.card label { font-size: 11px; color: var(--ink-3); letter-spacing: 0.05em;
              text-transform: uppercase; }
.card input { font-size: 15px; width: 100%; }
.card button { padding: 10px; font-weight: 560; border-color: var(--ink); }
.card .mark { color: var(--ink-2); line-height: 0; }
.card h1 { font-size: 21px; margin-bottom: 2px; }
.card .small { font-size: 12px; padding: 2px; align-self: flex-start; text-transform: none;
               letter-spacing: 0; }
/* Four digits, read off a screen and typed once. */
.digits { font-size: 27px; letter-spacing: 0.5em; text-align: center;
          padding: 10px 0 10px 0.5em; font-variant-numeric: tabular-nums; }
#sentto { color: var(--ink); text-transform: none; letter-spacing: 0; }
.msg { font-size: 12px; color: var(--ink-2); min-height: 1.4em; margin: 0; }
.msg.bad { color: var(--bad); }

@media (prefers-reduced-motion: reduce) { .fill { transition: none; } }
