:root {
  --bg: #faf7f0;
  --panel: #ffffff;
  --ink: #2a2a2a;
  --muted: #6e6e6e;
  --line: #d8d4c8;
  --accent: #2e7d32;
  --accent-2: #2c7a4a;
  --warn: #b35d00;
  --bad: #b00020;
  --hi: #ff5722;
  --wood: #f5e6c8;
  --wood-line: #8b6f3a;
  --code-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, monospace;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  /* Layout — user-resizable via splitters; persist in localStorage as cutlist.layout.* */
  --inputs-width: 580px;
  --legend-width: 240px;
  --stock-card-height: auto;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 22px;
  background: linear-gradient(180deg, #fff, #f7f3e8);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.015em;
  font-weight: 800;
  color: var(--ink);
}
.topbar h1 .dot {
  color: #c0392b;
  display: inline-block;
  transform: translateY(-1px);
}
.topbar .tagline {
  font-family: var(--code-mono);
  font-size: 14px;
  color: var(--accent);
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.topbar .tagline::before { content: '“'; opacity: 0.6; margin-right: 2px; }
.topbar .tagline::after  { content: '”'; opacity: 0.6; margin-left: 2px; }
.topbar .subtitle { color: var(--muted); font-size: 13px; margin-left: auto; }

/* Sample-project cards row — shown when there's no result yet. Hidden once
   the user has solved, so the working view stays uncluttered. */
.samples-strip {
  padding: 14px 22px 4px;
  background: linear-gradient(180deg, #faf7f0, #f4ecd6);
  border-bottom: 1px solid var(--line);
}
.samples-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  padding-bottom: 10px;
}
.sample-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 90ms ease-out, border-color 90ms, box-shadow 90ms;
  font: inherit;
  color: var(--ink);
}
.sample-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.12);
  transform: translateY(-1px);
}
.sample-card:active { transform: translateY(0); }
.sample-icon {
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}
.sample-text { flex: 1; min-width: 0; }
.sample-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 2px;
}
.sample-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
@media print { .samples-strip { display: none !important; } }

.layout {
  display: grid;
  grid-template-columns: var(--inputs-width) 8px 1fr;
  gap: 0;
  padding: 18px;
  align-items: start;
}

/* ============ Splitters ============ */
.splitter {
  background: transparent;
  position: relative;
  z-index: 5;
  transition: background 120ms ease;
  align-self: stretch;
}
.splitter::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--line);
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.6;
}
.splitter-v {
  cursor: col-resize;
  width: 8px;
  min-width: 8px;
  align-self: stretch;
}
.splitter-v::before {
  left: 3px; right: 3px; top: 0; bottom: 0;
}
.splitter-h {
  cursor: row-resize;
  height: 10px;
  margin: 4px 0;
}
.splitter-h::before {
  top: 4px; bottom: 4px; left: 0; right: 0;
}
.splitter:hover::before,
.splitter.dragging::before {
  background: var(--accent);
  opacity: 1;
}
.splitter.disabled {
  pointer-events: none;
  opacity: 0;
}
body.splitter-dragging { user-select: none; cursor: col-resize; }
body.splitter-dragging.splitter-dragging-h { cursor: row-resize; }

/* ============ Inputs ============ */
.inputs { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-parts {
  display: flex;
  flex-direction: column;
  min-height: 200px;
}
.card-parts table.rows { flex: 1; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.card-h {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.card-h h2 { margin: 0; font-size: 15px; }

.row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.lbl { min-width: 130px; color: var(--muted); font-size: 13px; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  border: 0; background: #fff; padding: 6px 10px; cursor: pointer;
  font: inherit; color: var(--ink);
}
.seg button.active { background: var(--accent); color: #fff; }
.seg button + button { border-left: 1px solid var(--line); }

.btn-link {
  background: none; border: 0; color: var(--accent-2); cursor: pointer;
  font: inherit; padding: 0;
}
.btn-link:hover { text-decoration: underline; }

.rows {
  width: 100%; border-collapse: collapse;
  table-layout: auto;
}
.rows th, .rows td {
  padding: 4px 4px; font-size: 13px; vertical-align: middle;
}
.rows th {
  color: var(--muted); font-weight: 500; text-align: left;
  border-bottom: 1px solid var(--line);
}
.rows td .dim-input,
.rows td .name-input {
  width: 100%;
}
.rows td .dim-input { max-width: 88px; }
.rows td .name-input { min-width: 100px; }
.qty-col { width: 56px; text-align: right; }
.ctr { text-align: center; }
.dim-input, .qty-input, .name-input, select {
  font: inherit; padding: 4px 6px;
  border: 1px solid var(--line); border-radius: 5px; background: #fff;
  color: var(--ink);
}
.dim-input { font-family: var(--code-mono); font-size: 12px; }
.dim-input.err, .name-input.err { background: #fef0ee; border-color: var(--bad); }
.qty-input { width: 100%; }
.part-row select { font-size: 12px; padding: 2px 4px; max-width: 110px; }
.part-row td:nth-child(1) { min-width: 110px; }
.stock-row td:nth-child(1), .stock-row td:nth-child(2) { min-width: 70px; }
.btn-x {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 4px 6px;
}
.btn-x:hover { color: var(--bad); }

.actions { display: flex; gap: 8px; align-items: center; }
.btn-solve {
  background: var(--accent); color: #fff; border: 0;
  padding: 9px 18px; font-weight: 600; border-radius: 6px;
  font: inherit; cursor: pointer;
}
.btn-solve:disabled { background: #c8c4b8; cursor: not-allowed; }
.btn-solve.cancel { background: var(--warn); }
.btn-clear, .btn-print, .btn-csv {
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 6px; font: inherit; cursor: pointer;
}
.btn-clear:hover, .btn-print:hover, .btn-csv:hover { background: #f5f5f0; }
.btn-print:disabled { color: #bbb; cursor: not-allowed; }
/* Import CSV button — full-width, sits above the Stock card */
.actions-import {
  margin: -4px 0 2px;
}
.actions-import .btn-csv {
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  background: #fff;
  border: 1px dashed var(--line);
  color: var(--accent-2);
  font-weight: 600;
}
.actions-import .btn-csv:hover {
  background: #f5f5f0;
  border-style: solid;
}

/* Kerf preset chips — appear next to / below the kerf input on the same row */
.kerf-chips {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-left: 0;
  flex: 1;
}
.kerf-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 7px;
  font: 600 11px var(--code-mono);
  color: var(--muted);
  cursor: pointer;
  transition: background 80ms, color 80ms, border-color 80ms;
  min-width: 36px;
}
.kerf-chip::after { content: '″'; }
.kerf-chip:hover { background: #f5f5f0; color: var(--ink); }
.kerf-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Mixed-mode columns: thickness input, material select, plane checkbox */
.rows td .dim-input.thick { max-width: 70px; }
.rows td .mat-select { max-width: 80px; font-size: 11px; padding: 2px 4px; }

/* Thickness preset chips — below stock/parts tables in Mixed mode */
.thick-chips {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
  padding: 4px 0 0 4px;
  align-items: center;
}
.thick-chip-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-right: 4px;
}
.thick-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 8px;
  font: 600 11px var(--code-mono);
  color: var(--muted);
  cursor: pointer;
  transition: background 80ms;
}
.thick-chip:hover { background: #f5f5f0; color: var(--ink); }

/* Plane-waste chip in the stats banner */
.banner .plane-waste {
  background: #fff4e0;
  color: #7b4a14;
  padding: 1px 7px;
  border-radius: 3px;
  border: 1px dashed #c8a464;
}

/* Print sections card */
.print-options-card .card-h h2 { font-size: 14px; }
.print-options { display: flex; flex-direction: column; gap: 4px; }
.print-options label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
  padding: 2px 0;
}
.print-options input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }
.print-options-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.err-banner {
  background: #fef0ee; color: var(--bad);
  border: 1px solid #f3c4be; border-radius: 6px;
  padding: 8px 12px; font-size: 13px;
}

.progress { display: flex; gap: 10px; align-items: center; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid #ddd; border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Results ============ */
.results {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-height: 60vh;
  box-shadow: var(--shadow);
}
.empty {
  color: var(--muted);
  text-align: center; padding: 60px 20px;
}
.empty h3 { color: var(--ink); margin-top: 0; }
.empty .tip { font-size: 12px; margin-top: 30px; }
.empty code {
  font-family: var(--code-mono); background: #f0eddf;
  padding: 1px 5px; border-radius: 3px;
}

.result-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; flex-wrap: wrap; gap: 10px;
}
.tabs {
  display: inline-flex; border: 1px solid var(--line);
  border-radius: 6px; overflow: hidden;
}
.tabs button {
  background: #fff; border: 0; padding: 7px 14px;
  font: inherit; color: var(--ink); cursor: pointer;
}
.tabs button + button { border-left: 1px solid var(--line); }
.tabs button.active { background: var(--accent); color: #fff; }
.meta { color: var(--muted); font-size: 12px; }

.pareto { margin: 4px 0 10px; }
.pareto-svg { width: 100%; max-width: 360px; height: auto; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.sol-card {
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color 120ms, box-shadow 120ms;
}
.sol-card:hover { border-color: var(--accent-2); }
.sol-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(46, 125, 50, 0.15); }
.sol-card svg.thumbnail-svg { width: 100%; height: 100px; }
.sol-stats { margin-top: 6px; font-size: 12px; line-height: 1.4; color: var(--ink); }
.sol-stats .bad { color: var(--bad); }
.badges { margin-bottom: 4px; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600; margin-right: 4px;
  color: #fff;
}
.badge.waste { background: #2c7a4a; }
.badge.easy  { background: #1f6fb2; }
.badge.bal   { background: #6b5099; }

.detail-wrap {
  display: grid;
  grid-template-columns: 1fr 8px var(--legend-width);
  gap: 0;
  align-items: start;
}
.detail-wrap .splitter-legend { margin: 0 4px; }
.detail-wrap > #detail { padding-right: 8px; min-width: 0; }
.detail-wrap > #legendBox { padding-left: 8px; min-width: 0; }

.banner {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  display: flex; flex-wrap: wrap; gap: 16px;
}
.banner strong { color: var(--ink); }
.banner .bad { color: var(--bad); }

.unplaced-wrap {
  background: #fff8e6;
  border: 1px solid #e8c98a;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.unplaced-title { font-weight: 600; margin-bottom: 4px; color: var(--warn); }
.unplaced-row { font-size: 13px; color: var(--ink); padding: 2px 0; }
.btn-add-stock {
  margin-top: 8px;
  background: var(--accent); color: #fff; border: 0;
  padding: 6px 12px; border-radius: 5px; font: inherit; cursor: pointer;
}

.sheets {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 16px;
}
.sheet-svg {
  display: block;
  background: #fff;
}
.sheet-title { font-size: 11px; fill: var(--muted); font-family: var(--code-mono); }
.part-label { font-size: 10px; fill: #1a1a1a; font-family: inherit; pointer-events: none; }

.cut-sequence {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
}
.cs-title { font-weight: 600; margin-bottom: 6px; }
.cs-sheet { margin: 6px 0 10px; font-size: 13px; }
.cs-sheet ol { margin: 4px 0 4px 22px; padding: 0; }
.cs-sheet li { padding: 1px 0; font-family: var(--code-mono); font-size: 12px; }

.legend-box { position: sticky; top: 12px; }
.legend {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}
.legend-title { font-weight: 600; margin-bottom: 8px; }

/* Card grid: each part is [chip + name] on top, [dimensions · qty] below. */
.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}
.legend-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 7px 6px;
  background: #fff;
  font-size: 12px;
  break-inside: avoid;
  cursor: default;
}
.legend-card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.legend-name {
  font-weight: 600;
  color: var(--ink);
  word-break: break-word;
  line-height: 1.2;
}
.legend-dim {
  font-family: var(--code-mono);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}
.legend-dim-val { color: var(--ink); }
.legend-qty { color: var(--muted); }
.legend-qty-short { color: var(--bad); font-weight: 700; }

/* Scoped (per-sheet) legend lives inside each sheet-block. Hidden on screen
   (the main side legend covers all parts there); revealed for print. */
.sheet-scoped-legend { display: none; }

.legend-swatch {
  display: inline-block; width: 16px; height: 16px;
  border: 1px solid #555; border-radius: 3px;
  /* Force browsers to print background colors */
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.legend-row { cursor: default; transition: background 80ms ease; }
.legend-row:focus-within, .legend-row:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Hover-highlight — applies across legend rows, parts table rows, and SVG placements */
.sheet-svg rect.placement { transition: stroke 80ms ease, stroke-width 80ms ease, filter 80ms ease; }
.sheet-svg rect.placement.highlight,
.thumbnail-svg rect.placement.highlight {
  stroke: var(--hi);
  stroke-width: 3;
  filter: brightness(1.1);
}
.legend-row.highlight,
.part-row.highlight,
.part-row.highlight > td {
  background: #fff3e0 !important;
}
.legend-row.highlight { box-shadow: inset 3px 0 0 var(--hi); border-color: var(--hi); }
.part-row.highlight { box-shadow: inset 3px 0 0 var(--hi); }

/* Cut sequence numbers on the SVG overlay */
.sheet-svg .cut-num {
  font: 600 10px var(--code-mono);
  fill: #c0392b;
  pointer-events: none;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

/* Kerf strip — the material removed by the saw blade.
   Solid black fill with dashed red outline so it's unmistakable as waste. */
.sheet-svg rect.kerf-strip {
  fill: #111;
  stroke: #c0392b;
  stroke-width: 0.75;
  stroke-dasharray: 2,1.5;
  pointer-events: none;
}

/* Per-sheet block: SVG + zoom toolbar + cut sequence */
.sheet-block {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 14px;
}
.zoom-tools {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px; font-size: 12px;
}
.zoom-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 2px 10px; border-radius: 4px; cursor: pointer;
  font: 600 12px var(--code-mono);
  min-width: 30px;
}
.zoom-btn:hover { background: #f5f5f0; }
.zoom-label { color: var(--muted); margin-left: 4px; font-family: var(--code-mono); min-width: 40px; text-align: right; }
.svg-zoom-wrap {
  overflow: auto;
  max-height: 80vh;
  border: 1px dashed transparent;
  background: #fafaf6;
  border-radius: 4px;
  position: relative;
}
.svg-zoom-wrap.scrollable { border-color: var(--line); }
.zoomable-svg {
  display: block;
  width: calc(100% * var(--zoom, 1));
  height: auto;
  transform-origin: top left;
}

/* Per-sheet cut sequence (collapsible) */
.cs-sheet-details {
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.cs-summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  padding: 4px 6px;
  user-select: none;
  list-style: revert;
}
.cs-ref-tag {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
  margin-left: 4px;
}
.cs-summary:hover { color: var(--accent-2); }
.cs-list {
  margin: 6px 0 4px 22px;
  padding: 0;
  font-family: var(--code-mono);
  font-size: 12px;
  line-height: 1.55;
}
.cs-list li { padding: 1px 0; }
.cs-num { color: var(--muted); margin-right: 4px; }
.cs-verb { font-weight: 700; padding: 0 4px; border-radius: 3px; }
.cs-verb.cs-rip { background: #e1f0fe; color: #1f4f80; }
.cs-verb.cs-crosscut { background: #fde9c6; color: #7b4a14; }
.cs-list small { color: var(--muted); font-weight: normal; }
.cs-part { color: var(--ink); font-weight: 700; }
.cs-waste { color: var(--bad); font-style: italic; }

/* Piece labels — a styled letter badge so "piece A" is unmistakably distinct
   from the sheet title "Stock #1". */
.cs-piece-id {
  display: inline-block;
  font-family: var(--code-mono);
  font-weight: 700;
  font-size: 11px;
  background: var(--accent-2);
  color: #fff;
  border-radius: 3px;
  padding: 0 5px;
  letter-spacing: 0.04em;
  vertical-align: baseline;
  min-width: 14px;
  text-align: center;
}

/* Cut-preview strip — one mini-overlay per cut, sitting at the head of the
   cut sequence. Each card looks like the main sheet overlay but scoped to a
   single workpiece, showing where the next cut will land. */
.cut-preview-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin: 4px 0 12px;
}
.cp-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 6px 7px 7px;
  font-size: 11px;
}
.cp-title {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.cp-seq {
  font-family: var(--code-mono);
  color: #c0392b;
  font-weight: 700;
}
.cp-dim {
  color: var(--muted);
  font-family: var(--code-mono);
  font-size: 10px;
  margin-left: auto;
}
.piece-preview-svg {
  display: block;
  width: 100%;
  height: auto;
  background: #fafaf6;
  border-radius: 3px;
}
.cp-label {
  font-size: 9px;
  fill: #1a1a1a;
  font-family: -apple-system, sans-serif;
  pointer-events: none;
}
.cp-label-piece { fill: #6e6e6e; font-style: italic; }
.cp-sub {
  margin-top: 5px;
  color: var(--ink);
  font-size: 11px;
}

/* Piece-breakdown tree — sits at the head of a cut sequence */
.pt-wrap {
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #fbfbf4;
  border: 1px solid var(--line);
  border-radius: 5px;
}
.pt-summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}
.pt-summary:hover { color: var(--accent-2); }
.pt-root, .pt-children {
  list-style: none;
  margin: 4px 0 0;
  padding-left: 0;
}
.pt-children {
  margin-left: 16px;
  padding-left: 10px;
  border-left: 1px dashed #c8c4b6;
}
.pt-root > li, .pt-children > li {
  margin: 2px 0;
  font-size: 12px;
  font-family: var(--code-mono);
  position: relative;
}
.pt-children > li::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 9px;
  width: 7px;
  border-top: 1px dashed #c8c4b6;
}
.pt-dim { color: var(--muted); margin-left: 4px; font-size: 11px; }
.pt-via { color: var(--muted); margin-right: 4px; font-size: 10px; }

/* Display format select */
.fmt-select {
  font: inherit;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

/* SEO content section — always rendered server-side so crawlers see the rich
   description and FAQ. Visually subordinate to the main app. */
.seo-section {
  max-width: 920px;
  margin: 40px auto 8px;
  padding: 0 22px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}
.seo-section h2 {
  font-size: 22px;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
.seo-section h3 {
  font-size: 16px;
  margin: 24px 0 8px;
}
.seo-section p { margin: 8px 0; }
.seo-section .compare {
  list-style: none;
  margin: 6px 0 8px;
  padding: 0;
}
.seo-section .compare li {
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--accent-2);
  margin-left: 4px;
}
.seo-section .faq-q {
  border-top: 1px solid var(--line);
  padding: 6px 0;
}
.seo-section .faq-q:last-of-type { border-bottom: 1px solid var(--line); }
.seo-section .faq-q summary {
  cursor: pointer;
  font-weight: 600;
  list-style: revert;
  padding: 4px 0;
}
.seo-section .faq-q summary:hover { color: var(--accent-2); }
.seo-section .faq-q p { color: var(--muted); margin: 6px 0 4px 18px; }
.seo-section code {
  font-family: var(--code-mono);
  background: #f0eddf;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 22px;
}
footer a { color: var(--accent-2); text-decoration: none; margin: 0 4px; }
footer a:hover { text-decoration: underline; }

/* Hide the SEO section when printing — printout should be the cut plan only */
@media print {
  .seo-section, footer a { display: none !important; }
}

/* Self-test pre */
.self-test {
  position: fixed; right: 12px; bottom: 12px; max-width: 60vw;
  max-height: 40vh; overflow: auto;
  background: #111; color: #cfc; padding: 10px;
  border-radius: 6px; font-family: var(--code-mono);
  font-size: 11px; z-index: 9999;
}

/* Print */
@media print {
  /* Preserve background colors when printing — critical for the legend swatches,
     verb badges, kerf strips, etc. */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  .inputs, .topbar, footer, .actions, .tabs, .pareto, .gallery,
  .btn-x, .btn-add-stock, .splitter, .zoom-tools, .err-banner, .progress { display: none !important; }
  .layout { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .results { border: 0; box-shadow: none; padding: 0; }

  /* The main side legend is replaced by per-sheet scoped legends in print
     (each sheet block embeds its own parts list so the user sees only the
     parts produced from THAT stock piece). */
  .detail-wrap { display: block !important; }
  .legend-box  { display: none !important; }

  .legend-swatch {
    border: 1px solid #000;
    background-clip: padding-box;
  }

  /* Per-sheet block: overlay + cut-sequence on the left, scoped parts list on
     the right. The grid template-areas keeps the scoped legend visually
     anchored to the overlay even when the cut sequence below is long. */
  .sheet-block {
    display: grid !important;
    grid-template-columns: 1fr 240px;
    column-gap: 14px;
    row-gap: 8px;
    grid-template-areas:
      "overlay legend"
      "cuts    legend";
    align-items: start;
  }
  .sheet-block > .zoom-tools   { display: none !important; }
  .sheet-block > .svg-zoom-wrap     { grid-area: overlay; }
  .sheet-block > .cs-sheet-details  { grid-area: cuts; }
  .sheet-block > .sheet-scoped-legend { display: block !important; grid-area: legend; }
  /* Tighten the scoped legend to fit the narrow column */
  .sheet-scoped-legend .legend-grid { grid-template-columns: 1fr !important; }
  .sheet-scoped-legend .legend-card { padding: 4px 6px 5px; font-size: 11px; }
  .sheet-scoped-legend .legend-title { font-size: 11px; margin-bottom: 4px; }

  .sheet-block { page-break-inside: avoid; break-inside: avoid; border-color: #999; }
  .sheet-svg { page-break-inside: avoid; }
  .svg-zoom-wrap { max-height: none; overflow: visible; }
  .zoomable-svg { width: 100% !important; }  /* never print zoomed */
  /* Details elements are force-opened via beforeprint JS so their content prints */

  /* Selectable print sections — checkboxes in the inputs panel toggle these
     classes on .results so the user can include any combination of the three
     cut-instruction views in their printout. */
  .no-print-strip  .cut-preview-strip { display: none !important; }
  .no-print-tree   .pt-wrap            { display: none !important; }
  .no-print-list   .cs-list            { display: none !important; }
  .no-print-instr  .cs-sheet-details   { display: none !important; }
}

/* Mobile */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .detail-wrap { grid-template-columns: 1fr; }
  .legend-box { position: static; }
  .splitter-v { display: none; }
}
