:root {
  --bg: #f4f1e8;
  --paper: #ffffff;
  --ink: #1c1c1c;
  --muted: #6b6b6b;
  --line: #e0dbcd;
  --new: #2f6fb0;
  --old: #9c3587;
  --alnoor: #d99a2b;
  --seg-vertical-bit: #b8430f;
  --seg-arc: #d99a2b;
  --seg-top-bit: #7a9e3a;
  --seg-dome-1: #3f7d4e;
  --seg-dome-2: #2f9e9e;
  --seg-dome-3: #8a5bb0;
  --m: #3f7d4e;
  --e: #8a5bb0;
  --joint: #c0392b;
  --waste: #d9d4c6;
  --hot: #b8430f;
  --ok: #2f7d4e;
  --bad: #c0392b;
  --maxw: 1060px;
  --pad: 24px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --font: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0 auto; max-width: var(--maxw); padding: 0 var(--pad) 48px;
  background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 13px; line-height: 1.45;
}
.dim { color: var(--muted); }

header { padding: var(--s5) 0 var(--s2); }
h1 { margin: 0; font-size: 18px; font-weight: 600; }
.sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
h2 {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 var(--s3); padding-bottom: var(--s1);
  border-bottom: 1px solid var(--line);
}
h3 { font-size: 11px; margin: 0 0 var(--s1); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* sections group by air + a heading rule, not boxes */
.panel { background: none; border: none; margin: 0 0 var(--s6); padding: 0; }

/* tucked-away disclosures (set-once / reference) */
.tuck { margin: 0 0 var(--s4); }
.tuck > summary {
  cursor: pointer; list-style: none; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: var(--s2) 0; border-bottom: 1px solid var(--line);
}
.tuck > summary::-webkit-details-marker { display: none; }
.tuck > summary::before { content: "\25B8\00a0"; }
.tuck[open] > summary::before { content: "\25BE\00a0"; }
.tuck > summary .dim { font-weight: 400; text-transform: none; letter-spacing: 0; }
.tuck > *:not(summary) { margin-top: var(--s3); }

.ctrl-cols { display: flex; gap: var(--s6); flex-wrap: wrap; }
.ctrl-group { min-width: 240px; }
.ctrl-group label { display: inline-block; margin: 2px 10px 2px 0; color: var(--muted); }
.ctrl-group input, .al-row input { width: 60px; padding: 2px 5px; border: 1px solid var(--line); border-radius: 0; font: inherit; }
.ctrl-group select { font: inherit; padding: 2px 5px; border: 1px solid var(--line); border-radius: 0; max-width: 100%; }
.al-name { display: inline-block; width: 86px; }
.al-cm { color: var(--muted); font-size: 11px; margin-left: 6px; }
.hint, .legend, .al-row { color: var(--muted); }
.hint { margin: 2px 0 var(--s2); font-size: 12px; }
button {
  font: inherit; padding: 3px 9px; border: 1px solid var(--line);
  background: none; border-radius: 0; cursor: pointer; color: var(--ink);
}
button:hover { background: var(--bg); }
button.mini { padding: 2px 8px; font-size: 12px; }
.al-row { margin: 4px 0; }
.al-row button { margin-left: 6px; padding: 1px 7px; }

/* stats — one compact line; the two live facts are joints + coverage */
.stats {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px;
  margin: 0 0 var(--s5); padding: var(--s2) 0; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.stats b { font-weight: 600; }
.stats b.hot { color: var(--hot); }
.stats b.ok { color: var(--ok); }
.stats b.bad { color: var(--bad); }

/* legend */
.legend { font-size: 12px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 var(--s2); }
.legend .key { display: inline-flex; align-items: center; white-space: nowrap; }
.legend .dim { color: var(--muted); margin-left: 4px; }
.sw { display: inline-block; width: 14px; height: 12px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }
.sw.k-new { background: var(--new); }
.sw.k-alnoor { background: var(--alnoor); }
.sw.k-old { background: var(--old); }
.sw.k-m { background: var(--m); }
.sw.k-e { background: var(--e); }
.sw.waste { background: var(--waste); border: 1px solid var(--line); }
.jdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--joint); box-shadow: 0 0 0 1.5px var(--paper); margin-right: 6px; vertical-align: -1px; }
.sw.cutmark { position: relative; background: #c9c9c9; }
.sw.cutmark::after { content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 3px; background: repeating-linear-gradient(to bottom, var(--ink) 0 3px, #fff 3px 6px); }

/* progress + two-stage key */
.progress-row { display: flex; align-items: center; gap: 10px; margin: 0 0 var(--s2); font-size: 13px; }
.progress-track { flex: 1; max-width: 320px; height: 8px; background: var(--bg); border: 1px solid var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ok); transition: width 0.15s; }
#done-total { font-weight: 600; white-space: nowrap; }
.donecount { color: var(--muted); font-weight: 400; font-size: 12px; }
.sheet-link { font-size: 12px; color: var(--new); text-decoration: none; white-space: nowrap; }
.sheet-link:hover { text-decoration: underline; }
.check-key { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 0 0 var(--s2); font-size: 12px; }
.ck-key { display: inline-flex; align-items: center; gap: 5px; }
.ck { width: 12px; height: 12px; border: 1px solid var(--line); border-radius: 3px; display: inline-block; }
.ck-measure { background: var(--muted); }
.ck-solder { background: var(--ok); }

/* demand — single column, E after M */
.demand-cols { display: block; }
.demand-col { min-width: 0; }
.demand-col + .demand-col { margin-top: var(--s4); }
.demand-col h3 { margin-bottom: var(--s2); }

/* ---- per-tube row: fixed columns frame a hero bar ---- */
.run { display: flex; align-items: center; gap: 8px; margin: 0; padding: 1px 4px; min-height: 20px; }
.run:hover { background: #faf8f1; }
.run-checks { flex: none; display: inline-flex; gap: 4px; }
.run-checks .stage { display: inline-flex; margin: 0; cursor: pointer; }
.run-check { flex: none; margin: 0; cursor: pointer; width: 15px; height: 15px; }
.stage-measure .run-check { accent-color: var(--muted); }
.stage-solder .run-check { accent-color: var(--ok); }
.run-label { flex: none; width: 60px; font-family: var(--mono); font-size: 11px; color: var(--ink); white-space: nowrap; }
.run-len { flex: none; width: 56px; text-align: right; font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted); }
.run-bar { flex: 1; min-width: 0; display: flex; align-items: center; height: 16px; }
.run-joints { flex: none; width: 20px; text-align: center; font-size: 10px; font-variant-numeric: tabular-nums; color: var(--muted); }
.run-joints.hot { color: var(--hot); font-weight: 700; }
.run-pool { flex: none; font-size: 9px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 1px 4px; border-radius: 3px; }
.run-pool.pool-old { background: var(--old); color: #fff; }
.run-who { flex: none; font: inherit; font-size: 11px; padding: 1px 2px; border: 1px solid var(--line); border-radius: 0; background: #fff; max-width: 72px; color: var(--muted); }
.run-cutspec { display: none; }

/* pieces — the cut, with two distinct marks: round red bead = joint, dashed tick = cut */
.piece { position: relative; height: 16px; color: #fff; font-size: 10px; line-height: 16px; text-align: center; overflow: hidden; border-radius: 2px; }
.piece.k-new { background: var(--new); }
.piece.k-old { background: var(--old); }
.piece.k-alnoor { background: var(--alnoor); }
.piece.seg-vertical-bit, .sw.seg-vertical-bit, .segsw.seg-vertical-bit { background: var(--seg-vertical-bit); }
.piece.seg-arc, .sw.seg-arc, .segsw.seg-arc { background: var(--seg-arc); }
.piece.seg-top-bit, .sw.seg-top-bit, .segsw.seg-top-bit { background: var(--seg-top-bit); }
.piece.seg-dome-1, .sw.seg-dome-1, .segsw.seg-dome-1 { background: var(--seg-dome-1); }
.piece.seg-dome-2, .sw.seg-dome-2, .segsw.seg-dome-2 { background: var(--seg-dome-2); }
.piece.seg-dome-3, .sw.seg-dome-3, .segsw.seg-dome-3 { background: var(--seg-dome-3); }
.piece.cut::after { content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 3px; z-index: 1; background: repeating-linear-gradient(to bottom, var(--ink) 0 3px, #fff 3px 6px); }
.segsw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.piece.nofit { background: repeating-linear-gradient(45deg, #f3d3cb, #f3d3cb 5px, #e9b9ad 5px, #e9b9ad 10px); color: var(--bad); font-size: 10px; line-height: 16px; text-align: center; border-radius: 2px; }
/* joint = solder bead straddling the seam (also the piece-boundary marker) */
.joint { flex: none; align-self: center; position: relative; z-index: 2; width: 7px; height: 7px; margin: 0 -3px; background: var(--joint); border-radius: 50%; box-shadow: 0 0 0 1.5px var(--paper); }

/* done / partial */
.run.done { opacity: 0.4; }
.run.done .run-label, .run.done .run-len { text-decoration: line-through; }
.run.partial { opacity: 0.8; }
.run.failed .run-label { color: var(--bad); font-weight: 700; }

/* cut list */
.cut-cols { display: flex; gap: var(--s5); flex-wrap: wrap; }
.cut-col { flex: 1; min-width: 360px; }
.strips { display: flex; flex-direction: column; gap: 2px; }
.strip { display: flex; align-items: center; gap: 8px; }
.strip-label { width: 130px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.strip-bar { display: flex; height: 16px; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.strip-note { font-size: 11px; white-space: nowrap; margin-left: 8px; }
.strip-note.whole { color: var(--ok); }
.strip-note.iscut { color: var(--hot); }
.cut { height: 16px; color: #fff; font-size: 9px; line-height: 16px; text-align: center; overflow: hidden; border-right: 1px solid rgba(255,255,255,.5); }
.cut.k-m { background: var(--m); }
.cut.k-e { background: var(--e); }
.cut.waste { background: var(--waste); color: var(--muted); background-image: repeating-linear-gradient(45deg, transparent, transparent 3px, #c7c1b0 3px, #c7c1b0 4px); }

/* spare table */
.spare-tbl { border-collapse: collapse; font-size: 12px; min-width: 520px; }
.spare-tbl th, .spare-tbl td { text-align: left; padding: 4px 14px 4px 0; border-bottom: 1px solid var(--line); }
.spare-tbl th { color: var(--muted); font-weight: 600; }
.spare-tbl tr.tot td { border-top: 2px solid var(--line); border-bottom: none; padding-top: 6px; }

code { background: var(--bg); padding: 1px 4px; border-radius: 3px; }

/* running header (print only) */
.print-header { display: none; }

/* ---- print: only the suggested cut; dense, colours kept, exact cut lengths shown ---- */
@media print {
  @page { margin: 14mm 8mm 8mm; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { font-size: 9px; line-height: 1.25; max-width: none; padding: 0; }
  header, #stats, .progress-row, .check-key, .tuck, .no-print { display: none !important; }
  .print-header {
    display: flex !important; position: fixed; top: -12mm; left: 0; right: 0;
    justify-content: space-between; align-items: baseline; font-size: 8px;
    border-bottom: .5px solid #999; padding-bottom: 1px;
  }
  #cut-panel { border: none; padding: 0; margin: 0; }
  #cut-panel > h2 { display: none; }
  .legend { margin: 0 0 5px; font-size: 8px; gap: 3px 9px; }
  .demand-cols { display: block; }
  .demand-col + .demand-col { margin-top: 5px; }
  .demand-col h3 { margin: 5px 0 2px; font-size: 9px; break-after: avoid; }
  .run { gap: 5px; margin: 0; padding: .4px 0; min-height: 0; align-items: center; break-inside: avoid; page-break-inside: avoid; }
  .run:hover { background: none; }
  .run-checks { gap: 3px; }
  .run-check { width: 9px; height: 9px; }
  .run-label { width: 42px; font-size: 8px; }
  .run-len { width: 42px; font-size: 8px; }
  .run-joints { width: 14px; font-size: 8px; }
  .run-bar { height: 11px; }
  .piece { height: 11px; line-height: 11px; font-size: 7.5px; }
  .joint { width: 6px; height: 6px; }
  .run-who { display: none !important; }
  .run-cutspec { display: inline !important; font-size: 7.5px; margin-left: 6px; color: var(--ink); font-variant-numeric: tabular-nums; }
  .demand-col { break-inside: auto; }
}

/* ---- directions / install page (directions.html) ---- */
.dir-map { display: block; width: 100%; max-width: 560px; height: auto; margin: 4px auto 10px; }
.dir-tube { cursor: pointer; }
.dir-tube .dir-stroke { opacity: 0.4; transition: opacity 0.15s; }
.dir-tube:hover .dir-stroke { opacity: 0.85; }
/* focus: one tube pops, everything else fades hard */
.has-focus .dir-tube:not(.focus) .dir-stroke { opacity: 0.06; }
.has-focus .dir-tube:not(.focus) .dir-feed { opacity: 0.1; }
.dir-tube.focus .dir-stroke { opacity: 1; stroke-width: 6; }
.dir-feed { stroke: #fff; stroke-width: 2; transition: opacity 0.15s; }
.dir-poslbl { font: 700 20px/1 var(--mono); fill: var(--ink); text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: #fff; stroke-width: 4px; pointer-events: none; }
/* map numbers only show for the focused tube — keeps the default view clean */
.dir-map .dir-poslbl { display: none; }
.dir-map .dir-tube.focus .dir-poslbl { display: block; }
.dir-focusnote { color: var(--ink); font-weight: 700; font-family: var(--mono); }
.dir-row { padding: 2px 4px; }
.dir-row.focus { background: #fff3cf; box-shadow: inset 2px 0 0 var(--ok); }
.dir-lbl { width: auto; min-width: 150px; cursor: pointer; }
.dir-arrow { flex: none; width: 68px; font-family: var(--mono); font-size: 11px; font-weight: 700; }
.dir-arrow.away { color: #2f7d4e; }
.dir-arrow.back { color: #b4541f; }
.dir-chain { flex: none; font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.dir-chainhead { margin: 8px 0 2px; font-weight: 600; }
.dir-samewarn { margin: 6px 0 0; color: #b4541f; font-weight: 600; }
.dir-case h2 { margin-top: 0; }
.dir-page header a { font-size: 12px; }
.dir-schematic { display: block; width: 100%; max-width: 640px; margin: 2px auto 8px; }
.dir-schlbl { font-size: 13px; }
