/* Layout: size summary on top, settings on the left and the workbench on the right.
   The 3D view sits on a green cutting mat; the accent is brass. */
:root {
  --bg: #e9ece6;
  --surface: #f7f8f4;
  --sunken: #dde2d9;
  --ink: #19211d;
  --ink-2: #55615a;
  --line: #c6cec4;
  --accent: #b5811f;
  --accent-text: #7d5408;
  --on-accent: #1a1304;
  --ok: #2f7d43;
  --warn: #9a620c;
  --bad: #b0332b;
  --mat: #1d4a3d;
  --mat-ink: #cfe6da;
  --mat-ink-2: #9cc4b3;
  --mat-well: #24584a;
  --mat-bad: #ffb4ab;
  --wood: #cdb891;
  --paper: #ffffff;
  --shadow: rgba(20, 30, 25, 0.22);
  --display: 'Cinzel', 'Trajan Pro', Georgia, serif;
  --sans: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', Consolas, 'Courier New', monospace;
  color-scheme: light;
}
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121715;
    --surface: #1a211e;
    --sunken: #242d29;
    --ink: #e4eae5;
    --ink-2: #9aa79f;
    --line: #343f39;
    --accent: #d4a03c;
    --accent-text: #e2b65c;
    --on-accent: #1a1304;
    --ok: #63b877;
    --warn: #dba54a;
    --bad: #ec7b72;
    --mat: #163a30;
    --mat-ink: #cfe6da;
    --mat-ink-2: #8fb8a6;
    --mat-well: #1d4a3d;
    --mat-bad: #ffb4ab;
    --wood: #8d7a58;
    --paper: #ffffff;
    --shadow: rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121715;
  --surface: #1a211e;
  --sunken: #242d29;
  --ink: #e4eae5;
  --ink-2: #9aa79f;
  --line: #343f39;
  --accent: #d4a03c;
  --accent-text: #e2b65c;
  --on-accent: #1a1304;
  --ok: #63b877;
  --warn: #dba54a;
  --bad: #ec7b72;
  --mat: #163a30;
  --mat-ink: #cfe6da;
  --mat-ink-2: #8fb8a6;
  --mat-well: #1d4a3d;
  --mat-bad: #ffb4ab;
  --wood: #8d7a58;
  --paper: #ffffff;
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
}
h1, h2, h3, p, figure, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- controls ---------- */

.btn {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--ink-2); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.link {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}
.link:hover { text-decoration: underline; }
.icon-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: none;
  color: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { opacity: 1; background: color-mix(in srgb, currentColor 14%, transparent); }
input[type="number"], input:not([type]), input[type="text"], select, textarea {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  min-width: 0;
}
input[type="color"] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
.num { display: inline-flex; align-items: center; gap: 5px; }
.num input { width: 76px; text-align: right; font-family: var(--mono); font-size: 13px; }
.num i { width: 22px; font-style: normal; font-size: 12px; color: var(--ink-2); }

/* ---------- header and summary ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  padding: 14px 20px;
}
.brand h1 { font: 700 21px/1.1 var(--display); letter-spacing: 0.04em; }
.brand p { color: var(--ink-2); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.summary { background: var(--surface); border-block: 1px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.stat { display: flex; flex-direction: column; gap: 1px; padding: 10px 20px; border-right: 1px solid var(--line); }
.stat .k { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
.stat .v { font: 500 19px/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--ink-2); }
.stat .s { font-size: 12px; color: var(--ink-2); }
.alert { padding: 7px 20px; border-top: 1px solid var(--line); font-weight: 500; }
.alert::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: currentColor; }
.alert.bad { color: var(--bad); }
.alert.warn { color: var(--warn); }

/* ---------- layout ---------- */

.layout { display: grid; grid-template-columns: 318px minmax(0, 1fr); align-items: start; }
.work { min-width: 0; padding: 0 20px 48px; }
.settings {
  order: -1;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 8px 16px 32px 20px;
  border-right: 1px solid var(--line);
}

.tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  padding: 12px 14px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-2);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

/* ---------- settings ---------- */

.group { border-bottom: 1px solid var(--line); }
.group summary {
  padding: 11px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.fields { display: flex; flex-direction: column; gap: 9px; padding-bottom: 14px; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 3px 10px; }
.field > label { font-size: 13px; }
.field select { max-width: 158px; }
.field.check, .field.action { grid-template-columns: minmax(0, 1fr); }
.field.action .btn { justify-self: start; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.hint { grid-column: 1 / -1; font-size: 12px; color: var(--ink-2); }

/* ---------- 3D view ---------- */

.stage {
  --ink: var(--mat-ink);
  --ink-2: var(--mat-ink-2);
  --surface: var(--mat-well);
  position: relative;
  height: clamp(340px, 60vh, 660px);
  border-radius: 6px;
  background: var(--mat);
  overflow: hidden;
}
#stage-3d { position: absolute; inset: 0; }
#stage-3d canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: pan-y; }
#stage-3d canvas:active { cursor: grabbing; }
#stage-flat { display: none; }
.stage.flat #stage-3d, .stage.flat .stage-tools, .stage.flat .stage-hint { display: none; }
.stage.flat #stage-flat { display: flex; justify-content: center; height: 100%; padding: 12px; }
.stage.flat .dwg { height: 100%; width: auto; max-width: 100%; }
.stage-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
.stage-tools button {
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--mat-ink-2);
  border-radius: 4px;
  background: var(--mat);
  color: var(--mat-ink);
  font-size: 13px;
  cursor: pointer;
}
.stage-tools button:hover { border-color: var(--mat-ink); }
.stage-hint { position: absolute; left: 12px; top: 10px; max-width: 44%; font-size: 12px; color: var(--mat-ink-2); pointer-events: none; }
.stage-tip {
  position: absolute;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--on-accent);
  font: 500 12px var(--mono);
  white-space: nowrap;
  pointer-events: none;
}
/* What is selected in the 3D view, editable in place. */
.stage-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--mat-ink-2);
  border-radius: 5px;
  background: color-mix(in srgb, var(--mat) 88%, transparent);
  color: var(--mat-ink);
  font-size: 13px;
}
.bar-scope { display: contents; }
.stage-bar .crumb { padding: 3px 8px; border-radius: 3px; background: var(--mat-well); font-weight: 600; white-space: nowrap; }
.stage-bar .sep { color: var(--mat-ink-2); }
.stage-bar i { font-style: normal; font-size: 12px; color: var(--mat-ink-2); }
.stage-bar input { padding: 4px 7px; border-color: var(--mat-ink-2); }
.stage-bar .bar-name { width: 150px; }
.stage-bar .bar-num { width: 66px; text-align: right; font-family: var(--mono); }
.stage-bar button {
  padding: 4px 10px;
  border: 1px solid var(--mat-ink-2);
  border-radius: 4px;
  background: var(--mat);
  color: var(--mat-ink);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.stage-bar button:hover { border-color: var(--mat-ink); }
.stage-bar button.danger { color: var(--mat-bad); }
.bar-hint { margin-left: 4px; font-size: 12px; color: var(--mat-ink-2); }
.lane.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.div-row[data-sel], .cell[data-sel] { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ---------- lanes ---------- */

.section-head { margin: 22px 0 12px; }
.section-head h2, #cut-body h2 { font: 700 16px/1.2 var(--display); letter-spacing: 0.04em; }
.section-head p { max-width: 78ch; margin-top: 4px; color: var(--ink-2); font-size: 13px; }

.floors { margin-bottom: 14px; }
.floor-tabs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 4px; }
.floor-tabs [data-floor] {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  border-bottom-color: transparent;
  background: none;
  color: var(--ink-2);
  font-weight: 500;
  cursor: pointer;
}
.floor-tabs [data-floor][aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: inset 0 2px 0 var(--accent); }
.floor-tabs small { margin-left: 6px; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.floor-tabs .link { margin-left: 8px; }
.floor-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0 4px 4px 4px;
  background: var(--surface);
}
.floor-form #floor-name { width: 150px; }
.floor-form .hint { flex-basis: 100%; }

.lanes { display: flex; align-items: flex-start; gap: 12px; padding-bottom: 12px; overflow-x: auto; }
.lane { flex: 1 0 248px; max-width: 320px; min-width: 0; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }
.lane.drop-end { border-color: var(--accent); }
/* The header mimics a divider tab, in the lane's color. */
.lane-head {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 4px 4px 0 0;
  background: var(--lane);
  color: var(--lane-ink);
}
.swatch { position: relative; width: 18px; height: 18px; border: 2px solid var(--lane-ink); border-radius: 50%; cursor: pointer; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.lane-name {
  width: 100%;
  padding: 2px 4px !important;
  border-color: transparent !important;
  background: transparent !important;
  color: inherit;
  font: 700 14px/1.3 var(--display);
  letter-spacing: 0.03em;
}
.lane-name:hover, .lane-name:focus { border-color: var(--lane-ink) !important; }
.lane-tools, .div-extra, .bulk { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--sunken); }
.lane-tools label, .div-extra label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.lane-tools label.inline, .div-extra label.inline { flex-direction: row; align-items: center; gap: 8px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.meter { padding: 9px 10px 7px; border-bottom: 1px solid var(--line); }
.bar { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--ok); }
.bar.tight span { background: var(--warn); }
.bar.over span { background: var(--bad); }
.bar + .meter-note { margin-top: 5px; }
.meter-note { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bar.over + .meter-note { color: var(--bad); font-weight: 600; }
.bar.tight + .meter-note { color: var(--warn); }

.divs { min-height: 6px; }
.div { border-bottom: 1px solid var(--line); }
.div.dragging { opacity: 0.4; }
.div.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.div.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.div-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) 52px 24px 24px; align-items: center; gap: 4px; padding: 3px 6px 3px 8px; }
/* The grip carries the color the divider is printed in. */
.grip { width: 10px; height: 20px; border-radius: 3px 3px 1px 1px; background: var(--c); cursor: grab; }
.div-row input { padding: 4px 5px; border-color: transparent; background: transparent; }
.div-row input:hover { border-color: var(--line); }
.div-row input:focus { border-color: var(--ink-2); background: var(--bg); }
.div-count { text-align: right; font-family: var(--mono); font-size: 13px; appearance: textfield; -moz-appearance: textfield; }
.div-count::-webkit-outer-spin-button, .div-count::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.lane-foot { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; }
.foot-note { font-size: 11px; color: var(--ink-2); }
.meter-note.over { color: var(--bad); font-weight: 600; }
.cell { display: grid; grid-template-columns: minmax(0, 1fr) 62px 24px; align-items: center; gap: 4px; padding: 3px 6px 3px 8px; border-bottom: 1px solid var(--line); }
.cell input { padding: 4px 5px; border-color: transparent; background: transparent; }
.cell input:hover { border-color: var(--line); }
.cell input:focus { border-color: var(--ink-2); background: var(--bg); }
.cell-len { text-align: right; font-family: var(--mono); font-size: 13px; appearance: textfield; -moz-appearance: textfield; }
.cell-len::-webkit-outer-spin-button, .cell-len::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.lane.spare { --lane: var(--sunken); --lane-ink: var(--ink-2); border-style: dashed; flex: 0 0 180px; }
.lane.spare .lane-name { padding: 2px 4px; }
.bulk textarea { width: 100%; resize: vertical; font-size: 13px; }
.lane-new { flex: 0 0 190px; display: flex; flex-direction: column; gap: 8px; }

/* ---------- plans ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 14px; }
.tool { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.tool select, .tool input { color: var(--ink); }
.note-line { max-width: 86ch; margin: 6px 0; color: var(--ink-2); font-size: 13px; }
#cut-body { display: flex; flex-direction: column; gap: 30px; }
#cut-body h2 { margin-bottom: 10px; }
#cut-body h3 { margin: 16px 0 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
#cut-body .alert { padding-inline: 0; border: 0; }
.table-wrap { overflow-x: auto; }
table.cut { width: 100%; max-width: 860px; border-collapse: collapse; }
table.cut th, table.cut td { padding: 7px 14px 7px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.cut th { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); }
table.cut .n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.cut td:last-child { color: var(--ink-2); font-size: 13px; }
.area { display: flex; flex-wrap: wrap; gap: 4px 28px; font-family: var(--mono); font-size: 13px; }
.dwg-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; align-items: start; }
figcaption { margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.pieces { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 18px 0; max-width: 720px; }
.piece-fig { min-width: 110px; max-width: 100%; }

.dwg { display: block; width: 100%; height: auto; max-height: 520px; }
.dwg path, .dwg rect { vector-effect: non-scaling-stroke; }
.dwg text { fill: var(--ink); font-family: var(--mono); }
.dwg .dim path { fill: none; stroke: var(--ink-2); stroke-width: 1px; }
.dwg .wall { fill: var(--wood); stroke: var(--ink); stroke-width: 1px; }
.dwg .well { fill: var(--surface); stroke: var(--ink-2); stroke-width: 0.5px; }
.dwg .stack { fill-opacity: 0.25; }
.dwg .lane-t { font-family: var(--sans); font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.dwg .note { fill: var(--ink-2); font-family: var(--sans); }
.dwg .card { fill: none; stroke: var(--ink-2); stroke-width: 1px; stroke-dasharray: 4 3; }
.dwg .ghost { fill-opacity: 0.35; stroke: var(--ink-2); stroke-width: 1px; }
.dwg .piece { fill: var(--wood); fill-opacity: 0.5; stroke: var(--ink); stroke-width: 1px; }

/* ---------- divider sheets ---------- */

.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; margin-top: 14px; }
.sheet figcaption { display: flex; justify-content: space-between; align-items: center; margin: 0 0 6px; }
.sheet svg { display: block; width: 100%; height: auto; background: var(--paper); box-shadow: 0 1px 4px var(--shadow); }
.empty { color: var(--ink-2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 4px 16px var(--shadow);
  z-index: 10;
}
.toast .link { color: var(--accent); }

#print-root { display: none; }

@media (max-width: 920px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .settings { order: 0; position: static; max-height: none; border-right: 0; border-top: 1px solid var(--line); padding: 8px 20px 32px; }
  .stat { border-bottom: 1px solid var(--line); }
}

@media print {
  body { background: #ffffff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  #print-root .page { break-after: page; page-break-after: always; }
  #print-root .page:last-child { break-after: auto; page-break-after: auto; }
  #print-root .sheet-svg { display: block; }
  .print-doc h1 { margin-bottom: 14px; font: 700 18px var(--display); }
  .print-doc section { margin-bottom: 22px; break-inside: avoid; }
  .print-doc h2 { margin-bottom: 8px; font: 700 14px var(--display); }
  .print-doc h3 { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
  .print-doc .dwg { max-height: 150mm; }
}
