:root {
  --bg: #14171a; --panel: #1c2024; --ink: #e8eaed; --muted: #9aa4ae;
  --line: #2c3238; --accent: #5b9ce8; --accent-bg: #1a2a3e;
  --ok: #5fd39b; --warn: #e0b464; --stop: #f08b8b; --stage: #f6f7f9;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

header, footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
footer { border-bottom: none; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.brand { font-weight: 600; letter-spacing: .01em; }
.mark {
  display: inline-block; width: 22px; height: 22px; line-height: 22px;
  text-align: center; border-radius: 6px; background: var(--accent);
  color: #0d1117; font-weight: 700; margin-right: 6px;
}
.tag {
  font-size: 11px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 99px; padding: 1px 8px; margin-left: 6px;
}

button {
  font: inherit; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: #0d1117; border-color: var(--accent); font-weight: 600; }
button.wide { width: 100%; margin-top: 8px; }

/* The toolbar sits between the header and the work area, the way an estimator
   expects a drawing tool to be laid out. Everything in it is wired to something;
   nothing here is a placeholder. */
#toolbar {
  display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
  padding: 8px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
#toolbar button { padding: 6px 12px; white-space: nowrap; }
#toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 3px; flex: 0 0 auto; }
#toolbar .count {
  font-size: 10px; font-weight: 700; background: var(--accent-bg); color: var(--accent);
  border-radius: 99px; padding: 1px 6px; margin-left: 3px;
}

main { flex: 1; display: flex; min-height: 0; }

#stage {
  flex: 1; min-width: 0; position: relative; overflow: auto;
  background: var(--stage); display: flex; align-items: center; justify-content: center;
}
#stage.hot { outline: 3px dashed var(--accent); outline-offset: -8px; }
#preview { max-width: 100%; max-height: 100%; display: block; }
#pdfView { width: 100%; height: 100%; border: none; }
#drop { flex: 0 0 auto; text-align: center; color: #5c6670; padding: 40px; }
#drop .glyph { font-size: 44px; color: #93a3b5; }
#drop .big { font-size: 17px; font-weight: 600; margin-top: 6px; color: #3a4450; }
#drop .hint { font-size: 13px; margin-top: 2px; }

#panel { flex: 0 0 420px; min-width: 0; overflow-y: auto; border-left: 1px solid var(--line); padding: 14px; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.pane h2 { margin: 0 0 8px; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field .row { display: flex; gap: 6px; align-items: center; }
.field input {
  font: inherit; width: 100%; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.field .src { font-size: 11px; color: var(--muted); margin-top: 3px; font-family: Consolas, monospace; word-break: break-word; }

.badge { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.b-read { background: #163024; color: var(--ok); }
.b-edit { background: var(--accent-bg); color: var(--accent); }
.b-miss { background: #3a2e18; color: var(--warn); }

#gaps { margin: 0; padding-left: 18px; color: var(--warn); font-size: 12.5px; }
#gaps li { margin-bottom: 4px; }

#work { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#work td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
#work td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
#work tr:last-child td { border-bottom: none; font-weight: 600; }
#work .calc { color: var(--muted); font-family: Consolas, monospace; font-size: 11.5px; }

.total { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.total .unit { font-size: 14px; color: var(--muted); font-weight: 400; }
.state { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.state.provisional { color: var(--warn); }
.state.confirmed { color: var(--ok); }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 460px; }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 6px; font-size: 16px; }
dialog input { font: inherit; width: 100%; margin-top: 10px; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; margin: 14px 0 0; padding: 0; }
code { font-family: Consolas, monospace; font-size: 12px; }

.builder { margin: -4px 0 12px; padding: 8px 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; }
.builder .row { gap: 5px; }
.builder input { width: 96px; }
.builder select { font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; }
.builder button { padding: 5px 11px; }
.builderOut { display: block; margin-top: 5px; font-family: Consolas, monospace; font-size: 12px; color: var(--accent); }

/* A projector, a laptop and a half-width window are all likely. Below 900px the
   fixed 420px panel squeezes the drawing into a scrollbar, so stack instead. */
@media (max-width: 900px) {
  main { flex-direction: column; }
  #stage { flex: 1 1 45%; min-height: 220px; }
  #panel { flex: 1 1 55%; border-left: none; border-top: 1px solid var(--line); }
}
@media (max-width: 1100px) and (min-width: 901px) {
  #panel { flex: 0 0 360px; }
}
.field input, .builder input { min-width: 0; }

#sheet {
  margin: 0 0 8px; padding: 10px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; overflow-x: auto; font-family: Consolas, monospace;
  font-size: 11px; line-height: 1.45; white-space: pre; color: var(--ink);
}

/* The saved key must be obvious without opening anything, and unmistakable once
   opened. Showing the last four is enough to tell two keys apart. */
.keystate {
  padding: 9px 11px; border-radius: 7px; margin: 10px 0 4px;
  font-size: 13px; border: 1px solid var(--line); background: var(--bg);
}
.keystate.set { border-color: var(--ok); color: var(--ok); }
.keystate.unset { border-color: var(--warn); color: var(--warn); }
.keystate b { font-family: Consolas, monospace; }
.keylabel { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; }
#btnKey.set { border-color: var(--ok); color: var(--ok); }

/* One click to give the drawing or the numbers the room. A split that suits
   reading a drawing does not suit checking a column of figures. */
main.mode-drawing #stage { flex: 0 0 80%; }
main.mode-drawing #panel { flex: 1 1 20%; }
main.mode-numbers #stage { flex: 0 0 22%; }
main.mode-numbers #panel { flex: 1 1 78%; }
@media (max-width: 900px) {
  main.mode-drawing #stage, main.mode-numbers #stage { flex: 1 1 45%; }
  main.mode-drawing #panel, main.mode-numbers #panel { flex: 1 1 55%; }
}

/* Canadian bar sizes. Same eight sizes and the same kg/m as the estimator's own
   tables - this block is here because it is what he reaches for first. */
.bargrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bargrid button {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 7px 4px; line-height: 1.25;
}
.bargrid button b { font-weight: 650; font-size: 13px; }
.bargrid button span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bargrid button.on { border-color: var(--accent); background: var(--accent-bg); }
.bargrid button.on b { color: var(--accent); }
.unitnote { float: right; text-transform: none; letter-spacing: 0; font-weight: 400; }

/* The bend chart. 70 codes is too many for a list, so it is a grid you filter. */
#bendDlg { max-width: 720px; width: calc(100vw - 48px); }
#bendFind { margin-bottom: 10px; }
.bendgrid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 5px; max-height: 250px; overflow-y: auto; padding: 2px;
}
.bendgrid button { padding: 7px 2px; text-align: center; font-variant-numeric: tabular-nums; }
.bendgrid button.on { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 650; }
.bendgrid button.spiral { color: var(--muted); }

.benddetail { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.benddetail h3 { margin: 0 0 3px; font-size: 15px; }
.benddetail .note { font-size: 12px; color: var(--muted); margin-bottom: 9px; }
.benddetail .note.warn { color: var(--warn); }
.dimrow { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 7px; }
.dim { display: flex; align-items: center; gap: 5px; }
.dim label { font-family: Consolas, monospace; font-weight: 700; width: 13px; flex: 0 0 auto; }
.dim.sums label { color: var(--accent); }
.dim.check label { color: var(--muted); }
.dim input { font: inherit; width: 100%; min-width: 0; background: var(--bg); color: var(--ink);
             border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }
.dim.check input { opacity: .65; }
.bendtotal {
  margin-top: 11px; padding: 9px 11px; border-radius: 7px;
  background: var(--bg); border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.bendtotal b { font-size: 17px; color: var(--accent); }
.bendtotal .calc { display: block; font-family: Consolas, monospace; font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* Openings are read facts, not decisions. Each one shows the words it came from
   and any trim bars called up, and deducting is a deliberate tick. */
.opening { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; margin-bottom: 7px; background: var(--bg); }
.opening b { font-variant-numeric: tabular-nums; }
.opening .src { font-size: 11px; color: var(--muted); font-family: Consolas, monospace; margin-top: 3px; word-break: break-word; }
.opening .trim { font-size: 12px; color: var(--accent); margin-top: 3px; }
.checkrow { display: flex; align-items: center; gap: 7px; font-size: 13px; margin-top: 2px; }
.checkrow input { width: 15px; height: 15px; }
