/* Drawer Insert Planner
   Look: a drafting table. Cool grey-blue paper, deep petrol ink, plywood-coloured sheet stock,
   engineering lettering for headings and mono figures for every measurement.
   One deliberate light palette, all colours defined here. */
:root {
  color-scheme: light;
  --paper: #e6ebef;          /* desk */
  --sheet: #f9fafb;          /* cards */
  --ink: #10283a;            /* petrol */
  --ink-2: #4a6071;          /* secondary text */
  --rule: #c9d3da;
  --accent: #0e7c72;         /* teal: selection, links */
  --accent-soft: #dff1ee;
  --ply: #c8a06b;            /* sheet stock */
  --ply-edge: #8f6d3f;
  --amber: #f0a22e;          /* grabbed / hovered divider */
  --danger: #b3261e;
  --font-head: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
svg path, svg circle { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- masthead ---------- */
.masthead { background: var(--ink); color: #eef3f6; padding: 14px clamp(16px, 3vw, 32px); }
.brand { display: flex; align-items: center; gap: 14px; }
.brand b { display: block; font: 600 26px/1 var(--font-head); letter-spacing: 0.03em; text-transform: uppercase; }
.brand span { display: block; margin-top: 3px; font-size: 13px; color: #9fb3c0; }
.mark { width: 36px; height: 36px; flex: none; }
.mark rect { fill: #17384f; stroke: none; }
.mark path { stroke: var(--amber); stroke-width: 2; }

/* ---------- layout ---------- */
.bench {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 20px;
  padding: 20px clamp(16px, 3vw, 32px);
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}
.rail { display: grid; gap: 14px; min-width: 0; }
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 14px 16px 16px; min-width: 0; }
.card h2 { margin: 0 0 6px; font: 600 18px/1.1 var(--font-head); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); }
.note { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }

/* ---------- fields ---------- */
.fields { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px; }
.fields label { font-weight: 500; }
.fields small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-2); }
select {
  font: 600 17px var(--font-mono);
  color: var(--ink);
  background: #fff;
  border: 1px solid #aebcc6;
  border-radius: 4px;
  padding: 8px 28px 8px 10px;
  min-width: 132px;
}

.dec-input {
  font: 600 17px var(--font-mono);
  color: var(--ink);
  background: #fff;
  border: 1px solid #aebcc6;
  border-radius: 4px;
  padding: 8px 10px;
  width: 132px;
  box-sizing: border-box;
  text-align: right;
}
.dec-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.link-btn { display: inline-block; margin: 0 0 12px; padding: 6px 12px; font: 600 13px var(--font-body); color: var(--accent); background: #fff; border: 1px solid var(--accent); border-radius: 999px; cursor: pointer; }
.link-btn:hover { background: var(--accent-soft); }
select:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- facts list ---------- */
.facts { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; text-align: right; font: 500 14px var(--font-mono); }
.facts.small { font-size: 13px; margin-top: 8px; }

/* ---------- estimate ---------- */
.estimate .total { font: 500 40px/1 var(--font-mono); letter-spacing: -0.02em; margin: 4px 0 2px; }
.estimate .note { margin: 10px 0 12px; }

/* ---------- buttons ---------- */
.btn {
  font: 600 14px var(--font-body);
  color: var(--ink);
  background: #fff;
  border: 1px solid #9fb0bc;
  border-radius: 4px;
  padding: 9px 14px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn.primary { width: 100%; background: var(--ink); color: #fff; border-color: var(--ink); letter-spacing: 0.02em; padding: 11px 14px; }
.btn.primary:hover:not(:disabled) { background: #1b4560; }
.btn.danger { color: var(--danger); border-color: #d9aaa6; }
.btn.danger:hover:not(:disabled) { background: #fdeeec; border-color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.note.small { font-size: 12px; margin: 0; }

/* ---------- help ---------- */
.help summary { cursor: pointer; font: 600 16px var(--font-head); letter-spacing: 0.06em; text-transform: uppercase; }
.help ul, .help ol { margin: 10px 0 0; padding-left: 20px; color: var(--ink-2); font-size: 13.5px; }
.help li + li { margin-top: 6px; }

/* ---------- plan ---------- */
.plan { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; min-width: 0; display: flex; flex-direction: column; }
.plan-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.tools { display: flex; gap: 6px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 13px var(--font-body); color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 7px 10px; cursor: pointer;
}
.tool svg { width: 17px; height: 17px; }
.tool:hover:not(:disabled) { background: var(--accent-soft); border-color: #b5d9d3; }
.tool:disabled { color: #9aabb7; cursor: default; }
.status { margin: 0; font: 500 13px var(--font-mono); color: var(--ink-2); }

.stage {
  position: relative;
  height: clamp(460px, calc(100vh - 190px), 860px);
  background-color: #f3f6f8;
  background-image: radial-gradient(#c3cfd8 1px, transparent 1.2px);
  background-size: 18px 18px;
  border-radius: 0 0 6px 6px;
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }

/* zoom controls, bottom right of the plan */
.zoom-ctl { position: absolute; z-index: 3; right: 10px; bottom: 10px; display: flex; align-items: stretch; background: #fff; border: 1px solid var(--rule); border-radius: 6px; box-shadow: 0 2px 8px rgba(16, 40, 58, 0.15); overflow: hidden; }
.zoom-ctl button { border: 0; background: transparent; color: var(--ink); min-width: 38px; min-height: 36px; padding: 0 8px; cursor: pointer; font: 600 13px var(--font-mono); display: inline-flex; align-items: center; justify-content: center; }
.zoom-ctl button + button { border-left: 1px solid var(--rule); }
.zoom-ctl button:hover:not(:disabled) { background: var(--accent-soft); }
.zoom-ctl button:disabled { color: #9aabb7; cursor: default; }
.zoom-ctl svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.zoom-ctl .zoom-pct { min-width: 56px; }
.stage.zoomed #canvas { cursor: grab; }
/* the embedded planner has a fixed "Use this design" bar at the bottom right: keep the zoom controls clear of it */
body.embed .zoom-ctl { right: auto; left: 10px; }
/* on a phone the controls move up into the toolbar, clear of the plan and of that bar */
.zoom-ctl.in-bar { position: static; box-shadow: none; }

/* drawing parts */
.wall { fill: var(--ply); stroke: var(--ply-edge); stroke-width: 1; }
.outline { fill: none; stroke: var(--ink); stroke-width: 2; pointer-events: none; }
.cell { fill: #fff; cursor: pointer; }
.cell:hover { fill: var(--accent-soft); }
.hit { fill: transparent; }
.hit[data-axis="v"] { cursor: ew-resize; }
.hit[data-axis="h"] { cursor: ns-resize; }
.hit:hover, .hit.active { fill: var(--amber); fill-opacity: 0.9; }
.dimline { stroke: #6f8594; stroke-width: 1; fill: none; }
.dim-text { font: 500 13px var(--font-mono); fill: var(--ink-2); }
.cell-label { font-family: var(--font-mono); font-weight: 500; fill: var(--ink); pointer-events: none; }
.front-text { font: 600 12px var(--font-head); letter-spacing: 0.18em; fill: var(--ink-2); text-transform: uppercase; }
.hint-ring { fill: #fff; stroke: var(--accent); stroke-width: 1.5; pointer-events: none; }
.hint-plus { stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.hint-text { font: 500 14px var(--font-body); fill: var(--ink-2); pointer-events: none; }

.num-hit { fill: transparent; cursor: pointer; }
.num-hit:hover { fill: var(--accent); fill-opacity: 0.14; }
.num-hit.sel { fill: #fff3c9; stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 4 2; fill-opacity: 1; }
.num-chip { stroke-width: 1.5; }
.num-chip.g0 { fill: #dff1ee; stroke: #0e7c72; } .num-lock.g0 { fill: #0e7c72; stroke: #0e7c72; }
.num-chip.g1 { fill: #fdecc8; stroke: #c98a12; } .num-lock.g1 { fill: #c98a12; stroke: #c98a12; }
.num-chip.g2 { fill: #e9e3fa; stroke: #6b4fc4; } .num-lock.g2 { fill: #6b4fc4; stroke: #6b4fc4; }
.num-chip.g3 { fill: #fbe1e7; stroke: #c43d5a; } .num-lock.g3 { fill: #c43d5a; stroke: #c43d5a; }
.num-lock path { fill: none; stroke-width: 1.4; }
.num-lock rect { stroke: none; }

.note-bar { position: absolute; z-index: 4; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 999px; font: 500 13.5px var(--font-body); box-shadow: 0 6px 18px rgba(16, 40, 58, 0.2); }
.note-bar.pending { background: var(--ink); color: #fff; }
.note-bar.warn { background: #fdeeec; color: var(--danger); border: 1px solid #e8b9b4; }
.note-bar.info { background: #fff; color: var(--ink); border: 1px solid var(--rule); }

/* divide popover */
.popover {
  position: absolute; z-index: 5; width: 250px; background: #fff; border: 1px solid #9fb0bc; border-radius: 6px;
  box-shadow: 0 10px 30px rgba(16, 40, 58, 0.22);
}
.pop-title { padding: 9px 12px; font: 600 15px var(--font-head); letter-spacing: 0.08em; text-transform: uppercase; background: var(--ink); color: #fff; border-radius: 5px 5px 0 0; }
.pop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
.pop-grid button {
  display: grid; justify-items: center; gap: 4px; padding: 8px 6px;
  font: 500 12.5px var(--font-body); color: var(--ink); background: #fff; border: 1px solid var(--rule); border-radius: 4px; cursor: pointer;
}
.pop-grid button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.pop-grid button:disabled { opacity: 0.4; cursor: not-allowed; }
.pop-grid svg { width: 38px; height: 26px; color: var(--ink-2); }
.pop-grid svg rect, .pop-grid svg line { fill: none; stroke: currentColor; stroke-width: 1.6; }
.divpop-body { padding: 12px; display: grid; gap: 6px; }
.divpop-body .btn { width: 100%; }
.divpop-sizes { margin: 0; font: 500 14px var(--font-mono); }
.divpop-body .note { margin: 0 0 6px; }
.pop-cancel { display: block; width: 100%; padding: 8px; background: none; border: 0; border-top: 1px solid var(--rule); font: 500 13px var(--font-body); color: var(--ink-2); cursor: pointer; }

.foot { padding: 6px clamp(16px, 3vw, 32px) 24px; text-align: center; color: var(--ink-2); font-size: 12.5px; }

/* ---------- plan sheet modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(16, 40, 58, 0.6); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal { background: var(--sheet); border-radius: 8px; width: min(800px, 100%); padding: 22px 24px; max-height: calc(100vh - 32px); overflow-y: auto; border-top: 6px solid var(--ink); }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font: 600 30px var(--font-head); letter-spacing: 0.05em; text-transform: uppercase; }
.icon-btn { width: 36px; height: 36px; border: 0; background: #e3eaee; border-radius: 50%; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink); }
.modal-foot .btn.primary { width: auto; padding: 9px 16px; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
#rev-body h3 { margin: 22px 0 8px; font: 600 15px var(--font-head); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); }
#rev-body table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
#rev-body th, #rev-body td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--rule); font-size: 14px; }
#rev-body td:last-child:not(:first-child) { font-family: var(--font-mono); }
#rev-body th { font-size: 12px; color: var(--ink-2); font-weight: 500; }
#rev-body .total td { font-weight: 700; border-bottom: 0; }
#rev-body .drawing { border: 1px solid var(--rule); border-radius: 6px; padding: 8px; background: #fff; overflow-x: auto; }
#rev-body .drawing svg { display: block; width: 100%; max-width: 100%; height: auto; margin: 0 auto; }
#rev-body .hint { margin: 6px 0 0; font-size: 12px; color: var(--ink-2); }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .bench { grid-template-columns: minmax(0, 1fr); }
  .plan { order: -1; }
  .stage { height: 62vh; min-height: 380px; }
  .brand span { display: none; }
}

@media print {
  @page { margin: 0.5in; }
  body > *:not(#review) { display: none !important; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; border-top: 0; max-height: none; padding: 0; }
  .modal-foot, .icon-btn { display: none; }
  #rev-body .drawing { border: 0; padding: 0; }
  #rev-body .drawing svg { width: auto; max-width: none; height: auto; }
}

/* ---------- embedded in the store's order form (?embed=1) ---------- */
body.embed .masthead, body.embed .foot, body.embed #open-review { display: none; }
body.embed { padding-bottom: 84px; }
.estimate .btn { width: 100%; }

/* upload progress shown while the order form stores the plan files */
#upload-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(16, 40, 58, .6); }
#upload-overlay[hidden] { display: none; }
#upload-overlay .ov-card { width: min(380px, 88vw); background: #fff; border-radius: 8px; padding: 26px 28px; text-align: center; box-shadow: 0 16px 40px rgba(0, 0, 0, .35); }
#upload-overlay .ov-title { font-size: 20px; font-weight: 700; color: var(--ink); }
#upload-overlay .ov-bar { height: 10px; margin: 16px 0 10px; background: #e1e8ed; border-radius: 6px; overflow: hidden; }
#upload-overlay .ov-bar i { display: block; height: 100%; width: 4%; background: var(--accent); border-radius: 6px; transition: width .25s; }
#upload-overlay[data-state="done"] .ov-bar i { background: #2e9d57; }
#upload-overlay[data-state="failed"] .ov-bar i { background: #c0392b; }
#upload-overlay .ov-sub { min-height: 18px; font-size: 14px; color: var(--ink-2); }
#upload-overlay .ov-retry { margin-top: 16px; }

/* ---------- expanded layout editor ---------- */
.bar-end { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.plan-price { display: none; font: 700 15px var(--font-mono); color: var(--ink); }
body.editor-full { overflow: hidden; }
body.editor-full .masthead, body.editor-full .foot { display: none; }
body.editor-full .plan { position: fixed; inset: 0; z-index: 60; border: 0; border-radius: 0; }
body.editor-full .stage { flex: 1; height: auto; min-height: 0; border-radius: 0; }
body.editor-full .plan-price { display: inline; }
/* the side panels give way; the price and "Use this design" bar of the embedded planner stays */
body.editor-full .rail { display: none; }
@media (max-width: 900px) { body.editor-full .stage { height: auto; min-height: 0; } }

/* the drawer label field */
.text-input { width: 100%; box-sizing: border-box; margin-top: 10px; padding: 10px 12px; font: 500 15px var(--font-body); color: var(--ink); background: #fff; border: 1px solid #aebdc8; border-radius: 4px; }
.text-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* the insert size, after the safety gap */
.insert-box { margin-top: 12px; padding: 10px 12px; border: 1px solid #b5d9d3; background: var(--accent-soft); border-radius: 4px; display: grid; gap: 2px; }
.insert-box span { font: 600 12px var(--font-body); color: var(--ink-2); letter-spacing: .04em; text-transform: uppercase; }
.insert-box b { font: 700 19px var(--font-mono); color: var(--ink); }
.insert-box small { font-size: 12px; color: var(--ink-2); line-height: 1.35; }

/* "this layout is empty" confirmation in the embedded planner */
#confirm-overlay { position: fixed; inset: 0; z-index: 110; display: flex; align-items: center; justify-content: center; background: rgba(16, 40, 58, .6); }
#confirm-overlay[hidden] { display: none; }
#confirm-overlay .ov-card { width: min(420px, 90vw); background: #fff; border-radius: 8px; padding: 26px 28px; text-align: center; box-shadow: 0 16px 40px rgba(0, 0, 0, .35); }
#confirm-overlay .ov-title { font-size: 20px; font-weight: 700; color: var(--ink); }
#confirm-overlay .ov-sub { margin: 10px 0 18px; font-size: 14px; color: var(--ink-2); line-height: 1.45; }
#confirm-overlay .ask-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#confirm-overlay .ask-buttons .btn { width: auto; padding: 10px 16px; }

/* the embedded planner's bar: your price next to "Use this design", always in view */
.finish-bar { display: none; }
body.embed .finish-bar { display: flex; align-items: center; gap: 14px; position: fixed; right: 20px; bottom: 18px; z-index: 70; padding: 8px 8px 8px 16px; background: #fff; border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 8px 22px rgba(16, 40, 58, .3); }
.finish-bar .fb-total { display: grid; line-height: 1.1; text-align: right; }
.finish-bar .fb-total small { font: 600 11px var(--font-body); letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); }
.finish-bar .fb-total b { font: 700 21px var(--font-mono); color: var(--ink); }
body.embed #finish { width: auto; margin: 0; padding: 13px 24px; font-size: 16px; border-radius: 6px; }
@media (max-width: 600px) { body.embed .finish-bar { left: 10px; right: 10px; bottom: 10px; justify-content: space-between; } body.embed #finish { padding: 12px 16px; } }
