:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2330;
  --muted: #5f6878;
  --line: #d5d9e0;
  --line-strong: #8a93a3;
  --accent: #2463b6;
  --accent-ink: #ffffff;
  --error: #b42318;
  --error-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --info: #31588f;
  --info-bg: #e8f0fb;
  --ok: #17703a;
  --ok-bg: #e3f5e9;
  --drop: #dbe8fb;
  --radius: 6px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 20px; background: #1d2330; color: #fff;
}
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 16px; }
.topbar nav a { color: #c9d1de; text-decoration: none; margin-right: 16px; }
.topbar nav a.active { color: #fff; border-bottom: 2px solid #fff; padding-bottom: 2px; }
/* Logins (user, 2026-10-08) */
.topbar .who { display: flex; align-items: center; gap: 10px; }
.topbar .who a { color: #c9d1de; text-decoration: none; }
.topbar .who a.active { color: #fff; }
.login { max-width: 340px; margin: 60px auto; }
.login form { display: flex; flex-direction: column; gap: 10px; }
.login .err { color: #b00020; margin: 0; }
[hidden] { display: none !important; }

main { padding: 16px 20px 60px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: #fff; color: var(--ink); cursor: pointer;
}
button:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--error); border-color: #e3a29c; }
button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; padding: 5px 7px; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--ink); }
textarea { width: 100%; font-family: var(--mono); font-size: 12px; }
label.field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.field input, label.field select { font-size: 14px; color: var(--ink); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #f6f8fb; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 12px 0 14px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border: 1px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; }
.tabs a.active { background: var(--panel); color: var(--ink); border-color: var(--line); margin-bottom: -1px; }

/* Pieces grid */
.grid-wrap { overflow-x: auto; }
table.grid { border-collapse: collapse; font-size: 13px; }
table.grid th { font-size: 11px; color: var(--muted); text-align: left; padding: 4px; white-space: nowrap; }
table.grid td { padding: 1px 2px; border-bottom: 1px solid #eef0f3; }
table.grid input { width: 100%; min-width: 50px; padding: 3px 5px; font-size: 13px; border-color: var(--line); }
table.grid input.w-xs { min-width: 44px; width: 52px; }
table.grid input.w-s { min-width: 70px; width: 80px; }
table.grid input.w-m { min-width: 90px; width: 100px; }
table.grid input[type=checkbox] { width: auto; min-width: 0; }
table.grid input::placeholder { color: #a8afbb; }
table.grid tr.bad td { background: var(--error-bg); }

/* Badges / messages */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.error { background: var(--error-bg); color: var(--error); }
.badge.warning { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
ul.msgs { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
ul.msgs li { padding: 4px 8px; border-radius: 4px; margin-bottom: 3px; display: flex; gap: 8px; align-items: baseline; }
ul.msgs li.error { background: var(--error-bg); color: var(--error); }
ul.msgs li.warning { background: var(--warn-bg); color: var(--warn); }
ul.msgs li.info { background: var(--info-bg); color: var(--info); }
ul.msgs li.overridden { background: #f1f2f4; color: var(--muted); text-decoration: line-through; }
ul.msgs li .msg { flex: 1; }
ul.msgs li .why { text-decoration: none; display: inline-block; font-style: italic; }

/* Package workspace */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 14px; align-items: start; }
.remaining { position: sticky; top: 10px; max-height: calc(100vh - 20px); overflow: auto; }
.remaining .piece { display: flex; justify-content: space-between; gap: 6px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 4px; background: #fff; cursor: grab; font-size: 12px; }
.remaining.drop-ok { outline: 2px dashed var(--accent); }

.pkg { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.pkg-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); background: #fafbfc; border-radius: var(--radius) var(--radius) 0 0; font-size: 12px; }
.pkg-attrs { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
.pkg-attrs select { padding: 2px 4px; font-size: 12px; }
.pkg-body { padding: 8px 10px 10px; overflow-x: auto; }

/* Package Sheet: 12 columns, Bottom A-F | Top G-L. Narrow enough for portrait Legal:
   billet names (and the job label) wrap, the figures don't. */
table.sheet { border-collapse: collapse; width: 100%; font-size: 13px; font-family: Arial, Helvetica, sans-serif; }
table.sheet td { padding: 2px 4px; white-space: nowrap; height: 22px; vertical-align: top; }
table.sheet col.c-job { width: 7%; }
table.sheet col.c-name { width: 27%; }
table.sheet tr.billet td.name, table.sheet tr.billet td.cell:first-child, table.sheet tr.billet td.split.cell { white-space: normal; }
table.sheet tr.billet .chip { margin-bottom: 2px; }
/* Certification on the job header (Package Sheet print): CSA blue, ANSI red */
.cert { padding: 0 6px; }
.cert-csa { background: #00b0f0; }
.cert-ansi { background: #ff0000; color: #fff; }
table.sheet .side-label { border-bottom: 1px solid var(--ink); }
table.sheet .pkgno { border: 2px solid var(--ink); font-weight: 700; text-align: center; font-size: 14px; }
table.sheet .lams { color: var(--muted); }
table.sheet tr.billet td { font-weight: 700; }
table.sheet td.split { border-left: 2px solid var(--ink); }
table.sheet td.num { text-align: right; }
table.sheet tr.foot td { border-top: 1px solid var(--ink); font-weight: 600; }
table.sheet td.cell { cursor: grab; }
table.sheet td.empty-side { color: #b0b6c0; font-weight: 400; font-style: italic; }
table.sheet tr.billet td.drop-ok { background: var(--drop); }
table.sheet tr.add td { font-weight: 400; color: #9aa2ae; font-size: 12px; }
table.sheet tr.add td.target { border: 1px dashed transparent; }
table.sheet tr.add td.target.drop-ok { background: var(--drop); border-color: var(--accent); color: var(--accent); }
table.sheet .flag-err { background: var(--error-bg); }
table.sheet td.raised { text-decoration: underline dotted; }
table.sheet .flag-warn { background: var(--warn-bg); }
table.sheet td.len { cursor: text; }
table.sheet input.len-edit { width: 3.2em; padding: 0 3px; font: inherit; font-weight: 700; text-align: right; }
table.sheet tr.billet td.custom { background: #ffff00; } /* hand-set length; not printed */

/* Package Sheet colours (sample-packaged.xlsm): columns in red, grade and fire rating highlighted */
table.sheet tr.billet td.col-member, table.sheet tr.billet td.col-member .chip { color: #d00000; }
/* highlights sit inside their cell so they never cover the dividers (screen and print) */
table.sheet .grade-beam, table.sheet .grade-column, table.sheet .fire, table.sheet .layup {
  display: inline-block; padding: 0 6px; line-height: 1.3; margin: 1px 2px; vertical-align: middle; }
table.sheet tr.foot td { padding-top: 3px; padding-bottom: 2px; vertical-align: middle; }
table.sheet tr.billet .fire { color: var(--ink); }
table.sheet .grade-beam { background: #ffff00; }
table.sheet .grade-column { background: #f2dcdb; color: #d00000; }
table.sheet .fire { background: #ffc000; }
table.sheet .layup { background: #ffc000; color: var(--ink); font-weight: 700; }

.chip { display: inline-block; padding: 0 5px; margin: 0 2px 0 0; border-radius: 3px; background: #eef1f6; border: 1px solid #d6dbe4; cursor: grab; font-weight: 700; }
.chip.qc { background: #fff1c2; border-color: #e8cf7a; cursor: pointer; }
.qc-btn { font-size: 11px; padding: 0 5px; margin-left: 4px; border-radius: 3px; border: 1px dashed #c9cfd8; background: transparent; color: #8d95a2; cursor: pointer; font-weight: 400; }
.qc-btn:hover { border-color: var(--accent); color: var(--accent); }

.new-pkg { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 14px; text-align: center; color: var(--muted); }
.new-pkg.drop-ok { background: var(--drop); border-color: var(--accent); color: var(--accent); }

.folder { font-family: var(--mono); background: #f1f3f6; padding: 3px 8px; border-radius: 4px; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2330; color: #fff; padding: 8px 16px; border-radius: var(--radius); opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; }
.toast.error { background: var(--error); }

/* Settings */
table.rules td { vertical-align: top; }
table.rules textarea { min-height: 60px; font-size: 12px; min-width: 380px; }
table.rules .note { font-size: 12px; color: var(--muted); max-width: 420px; }
tr.overridden td:first-child { border-left: 3px solid var(--accent); }

@media (max-width: 900px) {
  main { padding: 12px 16px 40px; }
  .workspace { grid-template-columns: 1fr; }
  .remaining { position: static; max-height: none; }
}

/* Lumber Room (sample LumberRoom (3)) */
table.lumberroom { border-collapse: collapse; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: 13px; }
table.lumberroom th { text-align: left; border-bottom: 1px solid var(--ink); padding: 3px 6px; white-space: nowrap; }
table.lumberroom td { padding: 2px 6px; white-space: nowrap; }
table.lumberroom .num { text-align: right; }
table.lumberroom tr.thk td { color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
table.lumberroom tr.thk td.planed { color: var(--ink); font-weight: 700; }
table.lumberroom td.planed { background: #ffff00; } /* planed centre lams (sample LumberRoom) */
table.lumberroom tr.gap td { background: #d9d9d9; height: 8px; padding: 0; }
table.lumberroom tr.tot td { border-top: 2px solid var(--ink); font-weight: 700; }

/* Layup tables under the lumber room (user's sheets) */
.layups { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; margin-top: 18px; }
table.layup { border-collapse: collapse; font-family: Arial, Helvetica, sans-serif; font-size: 12px; break-inside: avoid; }
table.layup th, table.layup td { border: 1px solid #555; padding: 1px 6px; }
table.layup th { text-align: left; font-weight: 700; white-space: nowrap; }
table.layup td { text-align: center; min-width: 38px; }
table.layup th.ttl { text-align: center; }
table.layup tr.pkg th, table.layup tr.pkg td { background: #ffff00; }
table.layup tr.sep td { border-left: none; border-right: none; height: 10px; }
table.layup td.lg-t1 { background: #dce6f1; }
table.layup td.lg-b { background: #e6b8b7; }
table.layup td.lg-c { background: #d8e4bc; }
table.layup td.lg-l140, table.layup td.lg-bf { background: #e4dfec; }
table.layup td.planed { background: #ffff00; }
/* Hand-set lam thickness (user, 2026-10-08): on screen only, so the print shows the normal colour */
@media screen {
  table.layup td.lay-custom { background: #ffff00 !important; outline: 2px solid #d00000; outline-offset: -2px; font-weight: 700; }
  table.layup td.lay-edit-cell { cursor: pointer; }
  table.layup td.lay-edit-cell:hover { outline: 1px dashed #555; outline-offset: -2px; }
  table.layup td.lay-custom:hover { outline: 2px solid #d00000; }
}
table.layup input.lay-edit { width: 3.2em; padding: 0 3px; font: inherit; text-align: center; }

/* Tracking export (preview only) */
.export-warn { background: var(--info-bg); color: var(--info); padding: 8px 12px; border-radius: var(--radius); }
table.dbsheet td, table.dbsheet th { white-space: pre; font-size: 12px; padding: 2px 6px; }
pre.json { background: #f6f8fa; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; max-height: 480px; overflow: auto; font-size: 12px; }
.pkg-layups { margin-top: 16px; }
.pkg-layups .layups { margin-top: 6px; }

/* Pbook labels (PBook-Input rows) */
table.pbook td { font-size: 12px; padding: 2px 6px; }
table.pbook tr.pkg-start td { border-top: 2px solid var(--line-strong); }

/* Pieces import: Project / Dealer format tabs */
.tabs.imp-tabs { margin: 0 0 0 12px; border-bottom: none; }

/* Planed lams: one shade per thickness, thickest first (yellow, orange, brown...) */
table.lumberroom td.planed-1, table.layup td.planed-1 { background: #ffc000; }
table.lumberroom td.planed-2, table.layup td.planed-2 { background: #c8a27a; }
table.lumberroom td.planed-3, table.layup td.planed-3 { background: #f4b183; }
table.lumberroom td.planed-4, table.layup td.planed-4 { background: #d9a6e8; }
table.lumberroom td.planed-5, table.layup td.planed-5 { background: #b4a7a0; }

/* Package comments on the Packages page: highlighted yellow (user, 2026-10-07) */
.pkg-comment { background: #ffff00; color: #1d2330; padding: 2px 6px; display: inline-block; border-radius: 3px; }
