:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #d6d9de; --text: #1b1f24; --muted: #5f6873; --accent: #c2410c; --accent-bg: #fff3e8;
  --ok: #19703a; --bad: #b3261e; --warn: #8a5a00; --view: #e9ecf0;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181c; --panel: #1d2126; --line: #343a42; --text: #e6e9ed; --muted: #9aa3ad; --accent: #f59e4b; --accent-bg: #3a2a17;
    --ok: #5fd08a; --bad: #ff8a80; --warn: #f0c060; --view: #101317; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 system-ui, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 270px minmax(0, 1fr) 360px; }
aside { background: var(--panel); overflow: auto; padding: 12px; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
#view { position: relative; background: var(--view); min-width: 0; }
#canvas { width: 100%; height: 100%; display: block; }
#hint { position: absolute; left: 12px; bottom: 10px; pointer-events: none; }
#status { position: absolute; left: 12px; top: 10px; right: 12px; white-space: pre-wrap; }
#status.error { color: var(--bad); }
#item-flag { color: var(--bad); font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 2px; }
h3 { font-size: 12px; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list { list-style: none; margin: 0; padding: 0; }
#records li { padding: 7px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
#records li:hover { border-color: var(--line); }
#records li.open { background: var(--accent-bg); border-color: var(--accent); }
#records .pn { font-weight: 600; }
input, textarea, button { font: inherit; color: inherit; }
input, textarea { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
input.changed { border-color: var(--accent); background: var(--accent-bg); }
label { display: block; margin: 8px 0 3px; color: var(--muted); font-size: 12.5px; }
button { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.field { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 6px; margin: 4px 0; }
.field label { margin: 0; }
.group { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.group > b { display: block; margin-bottom: 4px; }
dl { display: grid; grid-template-columns: 110px 1fr; gap: 3px 8px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
#checks li { padding: 3px 0; border-bottom: 1px solid var(--line); }
#checks .ok { color: var(--ok); }
#checks .bad { color: var(--bad); }
#checks .warn { color: var(--warn); }
#pending li { padding: 2px 0; }
code { font-size: 12px; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; grid-auto-rows: minmax(260px, auto); } #view { height: 50vh; } }
.row .field { flex: 1; min-width: 0; grid-template-columns: auto 1fr; }
.row .field input { width: 100%; min-width: 0; }
#new-open { margin-bottom: 8px; }
#new-plate { margin: 0 0 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
#p-add button, .group button { margin-top: 6px; }

/* model-based release: what a station sees on the model (touch first: a tablet at the machine) */
#stations { position: absolute; left: 12px; right: 12px; bottom: 34px; gap: 6px; }
#stations button { min-height: 40px; min-width: 64px; font-weight: 600; }
#stations button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#labels .label { position: absolute; left: 0; top: 0; padding: 2px 6px; border-radius: 5px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
#labels .label.size { border-color: var(--accent); font-weight: 600; }
#labels .label.bend { border-color: #7c3aed; }
#labels .label.joint { border-color: var(--ok); }
#labels .label.warn { border-color: var(--bad); color: var(--bad); font-weight: 600; }
#labels .dot { position: absolute; left: 0; top: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 1px solid var(--panel); }
#notes { position: absolute; left: 12px; top: 64px; max-width: 46%; pointer-events: none; }
#notes li { padding: 2px 6px; margin: 2px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 5px; display: table; }
#measure-out { position: absolute; right: 12px; top: 64px; max-width: 46%; padding: 8px 10px; background: var(--panel); border: 2px solid var(--accent); border-radius: 8px; font-size: 15px; font-weight: 600; white-space: pre-wrap; }

/* the welds' legend, and the shop view: read only, the model first */
#stations .legend { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; font-weight: 600; }
#stations .legend::before { content: ""; width: 26px; height: 12px; border-radius: 6px; background: repeating-linear-gradient(90deg, #f59e0b 0 6px, #b45309 6px 9px); }
#shop-link { margin-top: 8px; }
#shop-state { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); padding: 4px 12px; border-radius: 6px; background: var(--panel); border: 2px solid currentColor; font-weight: 700; z-index: 2; }
#shop-state.ok { color: var(--ok); }
#shop-state.bad { color: var(--bad); }
body.shop #p-life, body.shop #p-cost, body.shop #p-add, body.shop #p-dims, body.shop #p-save, body.shop #p-pick, body.shop #p-report, body.shop #new-open, body.shop #new-plate, body.shop #buy-open, body.shop #new-buy, body.shop #shop-link { display: none !important; }
body.shop main { grid-template-columns: 220px minmax(0, 1fr) 280px; }
@media (max-width: 900px) { body.shop #view { height: 70vh; } }

/* the flat pattern view, and what a tapped label or weld says */
#flat { position: absolute; inset: 0; width: 100%; height: 100%; background: var(--view); }
#flat .sheet { fill: #cfd5dc; stroke: #1b1f24; stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
#flat .bend { stroke-width: 2px; vector-effect: non-scaling-stroke; stroke-dasharray: 8 5; }
#flat .bend.up { stroke: #1d4ed8; }
#flat .bend.down { stroke: #b3261e; }
#flat .bend-text { font-weight: 700; }
#flat .bend-text.up { fill: #1d4ed8; }
#flat .bend-text.down { fill: #b3261e; }
#flat .flat-size { fill: var(--text); font-weight: 600; }
#labels .label { pointer-events: auto; cursor: pointer; }
#labels .label.lit { outline: 3px solid #9333ea; }
#detail { position: absolute; left: 12px; bottom: 92px; max-width: 60%; padding: 8px 10px; background: var(--panel); border: 2px solid #9333ea; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; z-index: 2; }
/* review, release, and posting to Business Central: the buttons a person presses (the AI has none of them) */
#life-body > * { margin: 6px 0; }
#cost-body > * { margin: 6px 0; }
#cost-body .blocked { color: var(--bad); }
#life-body ul { margin: 4px 0; }
#life-body table { width: 100%; border-collapse: collapse; }
#life-body th, #life-body td { text-align: left; padding: 2px 6px 2px 0; border-bottom: 1px solid var(--line); }
#life-body .added { color: var(--ok); }
#life-body .removed { color: var(--bad); }
#life-body .changed { color: var(--warn); }
#life-body .blocked { color: var(--bad); font-weight: 600; }
button.sure { background: var(--bad); border-color: var(--bad); color: #fff; }

/* the workspace (Adam, 2026-11-17): the logo, the tree of the open file, the open files along the bottom, all of them
   side by side, a right-click menu, and what a click selects */
#logo img { display: block; height: 22px; width: auto; }
#priority button.on, #arrange.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#priority button { padding: 3px 9px; }
footer { display: flex; align-items: center; gap: 8px; padding: 5px 10px; background: var(--panel); border-top: 1px solid var(--line); min-height: 40px; }
#tabs { flex-wrap: nowrap; overflow-x: auto; gap: 4px; }
#tabs .tab { display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; white-space: nowrap; max-width: 260px; }
#tabs .tab.on { background: var(--accent-bg); border-color: var(--accent); }
#tabs .tab b { font-weight: 600; }
#tabs .tab span { overflow: hidden; text-overflow: ellipsis; }
.x { border: 0; background: none; padding: 0 5px; font-size: 16px; line-height: 1; color: var(--muted); border-radius: 4px; }
.x:hover { background: var(--line); color: var(--text); }
#records-box > summary { cursor: pointer; margin: 4px 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
#tree-box { margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
#tree-box h3 { margin-top: 0; }
#tree li { padding: 3px 6px; border-radius: 5px; border: 1px solid transparent; }
#tree li.pickable { cursor: pointer; }
#tree li.pickable:hover { border-color: var(--line); }
#tree li.on { background: var(--accent-bg); border-color: var(--accent); }
#tree li.head { font-weight: 600; margin-top: 6px; padding-left: 0; }
#tree li.sub { padding-left: 18px; }
#tree li.off { color: var(--muted); text-decoration: line-through; }
#tree li.clear { font-style: italic; }
#tiles { position: absolute; inset: 0; z-index: 6; display: grid; gap: 8px; padding: 8px; background: var(--view); grid-auto-rows: minmax(0, 1fr); overflow: auto; }
#tiles[hidden] { display: none; }
#tiles .tile { position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; overflow: hidden; }
#tiles .tile.on { border-color: var(--accent); }
#tiles .tile:hover { border-color: var(--muted); }
#tiles .tile .pic { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: var(--view); }
#tiles .tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
#tiles .tile .cap { padding: 5px 34px 5px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tiles .tile .x { position: absolute; right: 5px; bottom: 4px; font-size: 20px; }
#menu { position: fixed; z-index: 20; min-width: 190px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
#menu button { display: block; width: 100%; text-align: left; border: 0; border-radius: 5px; padding: 6px 10px; }
#menu button:hover { background: var(--accent-bg); }
body.shop footer, body.shop #priority, body.shop #tree-box { display: none; }
@media (max-width: 900px) { #priority .muted { display: none; } }

/* the AI box: say what to change, about what is selected (Adam, 2026-11-17) */
#ask { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--panel); border-top: 1px solid var(--line); }
#ask[hidden] { display: none; }
#ask input { flex: 1; min-width: 0; }
#ask-about { max-width: 34%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#ai-body .group .blocked { color: var(--bad); }
#ai-body .group .answer { white-space: pre-wrap; margin-top: 4px; }
body.shop #ask, body.shop #p-ai { display: none; }

/* The middle row is exactly the height left between the header and the bars below it. Without this the row grew to the
   canvas's own height and the view lay over the Ask bar (Adam, 2026-11-17) */
main { grid-template-rows: minmax(0, 1fr); overflow: hidden; }
#view { overflow: hidden; min-height: 0; }
#ask, footer { position: relative; z-index: 3; flex: none; }
@media (max-width: 900px) { main { grid-template-rows: none; overflow: auto; } }
