:root {
  --ink: #1d2733;
  --muted: #5b6b7a;
  --accent: #b5651d;
  --accent-dark: #8f4f14;
  --paper: #ffffff;
  --bg: #f4f1ec;
  --line: #d8d2c7;
  --danger: #a31621;
  --warn-bg: #fff4d6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.site-header { background: var(--paper); border-bottom: 3px solid var(--accent); }
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-top: 18px; padding-bottom: 14px; }
h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.01em; }
.tagline { margin: 4px 0 0; color: var(--muted); }
#clean-toggle {
  flex: none; margin-top: 6px; padding: 6px 12px; border: 1px solid var(--line);
  background: var(--bg); border-radius: 999px; cursor: pointer; font-size: 0.85rem;
}
#clean-toggle[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

main.wrap { padding-top: 18px; padding-bottom: 30px; }

.ad-slot {
  border: 1.5px dashed var(--line); color: var(--muted); background: var(--paper);
  text-align: center; padding: 26px 10px; margin: 0 0 18px; font-size: 0.85rem;
  letter-spacing: 0.12em; text-transform: uppercase;
}

.tool { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.tool h2 { margin: 0 0 12px; font-size: 1.1rem; }
.tool h2 + .field-grid { margin-bottom: 20px; }
.hint { font-weight: normal; color: var(--muted); font-size: 0.85rem; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.field-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; font-weight: 600; }
input, select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 1rem; font-weight: normal; background: #fff; color: var(--ink); width: 100%;
}
input:disabled { background: var(--bg); color: var(--muted); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.cuts-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.cuts-table th { text-align: left; font-size: 0.82rem; color: var(--muted); padding: 4px 6px; }
.cuts-table td { padding: 3px 6px; }
.cuts-table .cut-qty { max-width: 76px; }
.row-remove {
  border: none; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 6px;
}
.row-remove:hover { color: var(--danger); }

.tool-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.btn {
  padding: 10px 18px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; font-size: 0.95rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.secondary:hover { border-color: var(--accent); }

.errors { margin-top: 16px; background: #fdeef0; border: 1px solid var(--danger); border-radius: 8px; padding: 10px 14px; }
.error-item { margin: 4px 0; color: var(--danger); font-weight: 600; }

.results { margin-top: 22px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; text-align: center; }
.stat-num { display: block; font-size: 1.5rem; font-weight: 800; color: var(--accent-dark); }
.stat-label { font-size: 0.82rem; color: var(--muted); }
.warn { background: var(--warn-bg); border: 1px solid #e0b73c; border-radius: 8px; padding: 10px 14px; font-weight: 600; }

.board { margin-bottom: 18px; }
.board-head { font-size: 0.92rem; margin-bottom: 6px; color: var(--ink); }
.board-diagram {
  position: relative; height: 46px; background: #efe9dd;
  border: 1.5px solid #8a7a5f; border-radius: 4px; overflow: hidden;
}
.seg {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid rgba(0,0,0,0.25); overflow: hidden;
}
.seg-label { color: #fff; font-size: 0.78rem; font-weight: 700; white-space: nowrap; padding: 0 4px; text-shadow: 0 1px 2px rgba(0,0,0,0.45); }
.kerf-mark { position: absolute; top: 0; bottom: 0; background: #222; min-width: 1px; }
.waste-seg {
  background: repeating-linear-gradient(45deg, #e5ddcb 0 8px, #d8cfb6 8px 16px);
  border-right: none;
}
.waste-seg .seg-label { color: var(--muted); text-shadow: none; }
.print-note { color: var(--muted); font-size: 0.88rem; }

.explainer { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-top: 18px; }
.explainer h2 { font-size: 1.05rem; margin: 14px 0 6px; }
.explainer h2:first-child { margin-top: 0; }
.explainer p { margin: 0 0 10px; color: #33424f; }

.site-footer { border-top: 1px solid var(--line); padding: 16px 0 26px; color: var(--muted); font-size: 0.9rem; }
.site-footer a { color: var(--accent-dark); font-weight: 700; }

/* Clean mode: strip everything but the tool itself */
body.clean .chrome { display: none !important; }
body.clean .explainer { display: none !important; }
body.clean .print-note { display: none; }

/* ---------- Print: a genuinely shop-ready cut list ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 11pt; }
  .site-header, .tool-actions, .ad-slot, .explainer, .site-footer, .print-note,
  #clean-toggle, .row-remove, .hint { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .tool { border: none; padding: 0; }
  .tool::before {
    content: "CutList Optimizer — shop cut list";
    display: block; font-size: 16pt; font-weight: 800; margin-bottom: 4mm;
  }
  input, select { border: none; padding: 2px 0; font-size: 11pt; -webkit-appearance: none; appearance: none; }
  .cuts-table input { border: none; }
  .results { margin-top: 6mm; }
  .stat { border: 1px solid #999; background: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .board { break-inside: avoid; page-break-inside: avoid; margin-bottom: 6mm; }
  .board-diagram, .seg, .waste-seg, .kerf-mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .seg-label { font-size: 8.5pt; }
}
