:root {
  --bg: #f6f4f0; --panel: #fbfaf8; --line: #e4e0d8; --text: #2f3337; --muted: #6d7279; --accent: #e0782f; --accent-soft: #fbe9dc;
  --btn: #ffffff; --btn-line: #d9d4ca; --danger: #b8463a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; font-size: 13px; color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  display: grid; height: 100vh;
  grid-template-columns: 268px minmax(0, 1fr) 260px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top top" "left view right" "left status right";
}
#toolbar {
  grid-area: top; display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0;
}
.brand { display: flex; align-items: baseline; gap: 8px; margin-right: 8px; white-space: nowrap; }
.brand .title { font-weight: 650; font-size: 14px; }
.brand .sub { color: var(--muted); }
.spacer { flex: 1; }
button, select {
  font: inherit; color: var(--text); background: var(--btn); border: 1px solid var(--btn-line); border-radius: 7px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap; line-height: 18px;
}
button:hover, select:hover { border-color: #bdb6a9; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.quiet { color: var(--muted); }
button.danger { color: var(--danger); }
#modalOk.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--btn-line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 14px; }
.seg button + button { border-left: 1px solid var(--btn-line); }
button[aria-pressed="true"] { background: var(--accent-soft); color: #9a4a12; font-weight: 600; }
.toggle[aria-pressed="false"] { color: var(--muted); }

aside { background: var(--panel); overflow-y: auto; padding: 12px; min-height: 0; }
#left { grid-area: left; border-right: 1px solid var(--line); }
#right { grid-area: right; border-left: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 2px 0 8px; font-weight: 650; }
.note { color: var(--muted); margin: 0 0 10px; line-height: 1.4; }

#catalog { display: flex; flex-direction: column; gap: 6px; }
.card {
  display: grid; grid-template-columns: 14px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 9px; row-gap: 1px;
  text-align: left; padding: 7px 9px; border-radius: 8px; cursor: grab; background: #fff; white-space: normal;
}
.card:active { cursor: grabbing; }
.card .sw { grid-row: 1 / 3; width: 14px; height: 14px; border-radius: 4px; align-self: center; border: 1px solid rgba(0,0,0,.12); }
.card .cname { font-weight: 600; line-height: 17px; }
.card .csize { color: var(--muted); font-size: 12px; line-height: 15px; }

#viewport { grid-area: view; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #eeebe5; }
#viewport canvas { position: absolute; left: 0; top: 0; display: block; }
#gl { touch-action: none; }
#labels { pointer-events: none; z-index: 1; }
#loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--muted);
  background: rgba(255,255,255,.85); padding: 8px 14px; border-radius: 8px; z-index: 2;
}

#inspBody .row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; min-height: 28px; }
#inspBody .row > span, .dims span, .rot label span { color: var(--muted); width: 70px; flex: none; white-space: nowrap; }
#inspBody .row b { font-weight: 600; }
#inspBody input[type="text"], #inspBody input[type="number"] {
  font: inherit; color: var(--text); border: 1px solid var(--btn-line); border-radius: 6px; padding: 4px 6px; width: 100%; min-width: 0; background: #fff;
}
.dims { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.dims label { display: flex; flex-direction: column; gap: 3px; }
.dims span { width: auto; font-size: 12px; }
.rot .grow { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.rot button { padding: 3px 8px; }
#iColor { width: 52px; height: 28px; padding: 0 2px; border: 1px solid var(--btn-line); border-radius: 6px; background: #fff; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.keys-h { margin-top: 22px; }
.keys { list-style: none; padding: 0; margin: 0; color: var(--muted); line-height: 1.9; }
kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; background: #fff; border: 1px solid var(--btn-line);
  border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--text);
}

#status {
  grid-area: status; display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; padding: 5px 12px;
  border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 12px; line-height: 16px;
}
#modal { position: fixed; inset: 0; background: rgba(40, 38, 34, .28); display: grid; place-items: center; z-index: 10; }
#modal[hidden] { display: none; }
.dialog { background: #fff; border-radius: 12px; padding: 18px 20px 16px; width: min(400px, 90vw); box-shadow: 0 12px 40px rgba(0,0,0,.18); }
.dialog p { margin: 0 0 6px; line-height: 1.45; }
.dialog .actions { justify-content: flex-end; }

@media (max-width: 1360px) {
  .brand .sub { display: none; }
  body { grid-template-columns: 250px minmax(0, 1fr) 244px; }
}

#help { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 12px; line-height: 18px; }
.drawer-button { display: none; }
#roomSelect { max-width: 180px; }
#inspBody .row b { min-width: 0; overflow-wrap: anywhere; }
body[data-view="walk"] #btnGrid, body[data-view="walk"] #btnMeasure { opacity: .6; }
@media (max-width: 1099px) {
  body { grid-template-columns: 0 minmax(600px, 1fr) 0; }
  #left, #right { display: none; }
  .drawer-button { display: inline-block; }
  body[data-drawer="catalog"] { grid-template-columns: 250px minmax(600px, 1fr) 0; }
  body[data-drawer="inspector"] { grid-template-columns: 0 minmax(600px, 1fr) 250px; }
  body[data-drawer="catalog"] #left, body[data-drawer="inspector"] #right { display: block; }
  #toolbar { gap: 6px; }
  .spacer { display: none; }
}

/* ---- version 2: the designer's schedule */
.brand .count { color: var(--muted); font-weight: 600; font-size: 12px; background: #f0ece4; border-radius: 10px; padding: 1px 8px; }
.cat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.cat-head h2 { margin: 0; }
button.small { padding: 2px 9px; font-size: 12px; }
#catalog { gap: 8px; }
.sec { border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.sec[hidden] { display: none; }
.sec > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 7px 10px; font-weight: 650; border-radius: 9px; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::before { content: '\25B8'; color: var(--muted); margin-right: 6px; font-size: 11px; }
.sec[open] > summary::before { content: '\25BE'; }
.sec > summary .sname { flex: 1; min-width: 0; }
.sec > summary .scount { font-size: 11px; font-weight: 600; white-space: nowrap; }
.sec .cards { display: flex; flex-direction: column; gap: 6px; padding: 0 6px 8px; }
.sec.other > summary { font-weight: 600; color: var(--muted); }
.card[hidden] { display: none; }
.card.pc { grid-template-columns: 52px minmax(0, 1fr); grid-template-rows: auto auto auto auto; padding: 6px 8px 6px 6px; row-gap: 1px; }
.card.pc .th { grid-row: 1 / 4; grid-column: 1; width: 52px; height: 52px; object-fit: contain; border-radius: 6px; background: #f3f1ed; align-self: start; }
.card.pc .cname { grid-row: 1; grid-column: 2; line-height: 16px; }
.card.pc .csize { grid-row: 2; grid-column: 2; font-size: 11.5px; line-height: 14px; }
.card.pc .ccount { grid-row: 3; grid-column: 2; }
.card.pc .cfin { grid-row: 4; grid-column: 1 / 3; color: var(--muted); font-size: 11px; line-height: 13px; margin-top: 3px; }
.ccount, .scount { font-size: 11.5px; line-height: 15px; font-weight: 600; }
.done { color: #2e7d32; } .short { color: #b26a00; } .over { color: #c62828; }
#state.warn { color: #c62828; font-weight: 600; }
#iSched .photo { background: #f3f1ed; border-radius: 8px; margin-bottom: 8px; height: 132px; display: flex; align-items: center; justify-content: center; }
#iSched .photo img { max-width: 100%; max-height: 132px; object-fit: contain; display: block; }
.pname { font-weight: 650; font-size: 14px; line-height: 18px; margin-bottom: 2px; }
.pitem { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.placement { margin: 4px 0 8px; }
.placement span, .note-box span, .dims-note { color: var(--muted); font-size: 12px; }
.placement p { margin: 2px 0 0; line-height: 1.4; background: #f6f3ee; border-radius: 6px; padding: 6px 8px; }
a.maker { display: inline-block; margin-bottom: 10px; color: #9a4a12; font-weight: 600; }
.dims-note { margin: 2px 0 4px; }
#iWallState.ok { color: #2e7d32; } #iWallState.bad { color: #c62828; }
.note-box { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.note-box textarea { font: inherit; color: var(--text); border: 1px solid var(--btn-line); border-radius: 6px; padding: 5px 7px; resize: vertical; min-height: 52px; background: #fff; }
.dims input[readonly] { background: #f3f1ed; color: var(--text); }
#inspBody .row > span { width: 78px; }
@media (max-width: 1099px) {
  body[data-drawer="catalog"] { grid-template-columns: 262px minmax(600px, 1fr) 0; }
  body[data-drawer="inspector"] { grid-template-columns: 0 minmax(600px, 1fr) 262px; }
}
#inspBody .stack { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
#inspBody .stack > span { color: var(--muted); font-size: 12px; }
#inspBody .stack > .val { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
#inspBody [hidden], #right [hidden], #left [hidden] { display: none !important; }

/* ---- version 5: Save and send to Wyatt */
#sendBar { flex-basis: 100%; display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; min-width: 0; }
button.primary { background: #b3541a; border-color: #9a4513; color: #fff; font-weight: 650; padding: 6px 16px; }
button.primary:hover { background: #9f4a16; border-color: #853b10; }
button.primary:disabled { background: #c9b7a8; border-color: #c9b7a8; cursor: default; }
#sendState { flex: 1 1 260px; min-width: 0; font-weight: 600; line-height: 18px; color: var(--muted); padding-left: 16px; position: relative; }
#sendState::before { content: ''; position: absolute; left: 0; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: #b9b3a8; }
#sendState[data-state="sent"] { color: #256b29; } #sendState[data-state="sent"]::before { background: #2e7d32; }
#sendState[data-state="changed"] { color: #8a5200; } #sendState[data-state="changed"]::before { background: #d08a00; }
#sendState[data-state="failed"] { color: #a3261d; } #sendState[data-state="failed"]::before { background: #c62828; }
#sendState[data-state="sending"] { color: #1f5f70; } #sendState[data-state="sending"]::before { background: #216c80; }
button.linkish { border: 0; background: none; padding: 2px 0; color: #9a4a12; font-weight: 600; text-decoration: underline; }
button.linkish[hidden] { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(40, 38, 34, .34); display: grid; place-items: center; z-index: 11; padding: 12px; }
.overlay[hidden] { display: none; }
.dialog.send { width: min(520px, 100%); max-height: calc(100vh - 24px); overflow-y: auto; font-size: 14px; }
.dialog.send h3 { margin: 0 0 8px; font-size: 18px; line-height: 24px; }
.dialog.send[data-mode="sent"] h3 { color: #256b29; } .dialog.send[data-mode="failed"] h3 { color: #a3261d; }
.dialog.send p { margin: 0 0 8px; line-height: 1.45; }
.dialog.send p.detail { color: var(--muted); } .dialog.send p.detail:empty { display: none; }
.dialog.send p.keep { font-weight: 650; }
.dialog.send ol { margin: 4px 0 6px; padding-left: 22px; }
.dialog.send li { margin-bottom: 10px; line-height: 1.45; }
.dialog.send li button, .dialog.send li a.btn { display: inline-block; margin: 0 0 4px; }
.dialog.send li span { display: block; }
.dialog.send b { overflow-wrap: anywhere; }
a.btn { font: inherit; color: var(--text); background: var(--btn); border: 1px solid var(--btn-line); border-radius: 7px; padding: 5px 11px;
  cursor: pointer; white-space: nowrap; line-height: 18px; text-decoration: none; }
a.btn:hover { border-color: #bdb6a9; }
.dialog.send [hidden] { display: none !important; }
#sendNote { font: inherit; color: var(--text); background: #fff; border: 1px solid var(--btn-line); border-radius: 7px; padding: 5px 9px; line-height: 18px; width: 300px; max-width: 100%; }
#sendNote[hidden], #btnSend[hidden] { display: none; }
.seg[hidden], .keys li[hidden] { display: none; }

/* ---- version 5b: the bar over the plan for the selected piece; Undo and Zoom; the simple copy */
#pieceBar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 20px); background: rgba(255, 255, 255, .96); border: 1px solid var(--btn-line); border-radius: 10px; padding: 6px 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, .12); }
#pieceBar[hidden] { display: none; }
#pieceBar #pbName { font-weight: 650; padding: 0 6px 0 4px; max-width: 220px; overflow-wrap: anywhere; }
#pieceBar button[hidden] { display: none; }
button:disabled { color: #b0aba1; cursor: default; }
.rowbreak { display: none; }
body.simple .rowbreak { display: block; flex-basis: 100%; height: 0; order: 2; }
body.simple #toolbar .brand { order: 0; }
body.simple #help { order: 1; flex: 1 1 320px; font-size: 13px; color: var(--text); }
body.simple #toolbar > button, body.simple #toolbar > select { order: 3; }
body.simple #sendBar { order: 4; }
body.simple #toolbar { row-gap: 8px; }
#pieceBar.dragging { opacity: 0; pointer-events: none; }
