:root {
  color-scheme: light;
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  --ink: #223b31;
  --muted: #53665b;
  --green: #245641;
  --line: #d7dfd6;
  --paper: #fff;
  --accent: #c57832;
  color: var(--ink);
  background: #edf1ec;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
h1, h2, h3, p, dl { margin: 0; }
:focus-visible { outline: 2px solid #aa631e; outline-offset: 3px; }
.topbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; min-height: 65px; padding: 10px clamp(16px, 3vw, 42px); background: #193e30; color: #fff; }
.brand { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; line-height: 1.1; }
.brand span { display: grid; gap: 2px; }
.brand small { font-size: 9px; font-weight: 650; letter-spacing: .13em; color: #d2e0d7; }
.brand strong { font-size: 18px; font-weight: 650; }
.top-actions, .inline-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px; background: #fff; color: var(--ink); font-weight: 550; text-decoration: none; }
.button:hover:enabled, a.button:hover { border-color: #9bab9f; background: #edf3ed; }
.button:disabled { opacity: .43; cursor: default; }
.button.subtle, .button.centre { background: transparent; border-color: #5b7a6c; color: #f3f8f4; }
.button.subtle:hover, .button.centre:hover { background: #2b5946; }
.button.centre { border-color: transparent; }
.button.primary { min-height: 40px; background: var(--green); color: #fff; border-color: var(--green); }
.button.primary:hover:enabled { background: #1b4332; }
.button.compact, .button.minimal { font-size: 12px; min-height: 33px; white-space: nowrap; }
.button.minimal { background: transparent; }
main { max-width: 1540px; margin: auto; padding: 22px clamp(12px, 3vw, 38px) 40px; }
.intro { display: flex; gap: 12px; justify-content: space-between; align-items: end; margin-bottom: 17px; }
.intro h1 { font-size: clamp(26px, 3vw, 38px); line-height: 1.1; letter-spacing: -.025em; }
.intro p { color: var(--muted); margin-top: 6px; }
.workspace { display: grid; grid-template-columns: minmax(430px, .82fr) minmax(0, 1fr); align-items: start; gap: 16px; }
.panel { min-width: 0; padding: clamp(13px, 1.6vw, 22px); border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.panel-top, .section-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 7px; }
.panel-top h2 { font-size: 19px; font-weight: 650; }
.section-top h3 { font-size: 15px; font-weight: 650; }
.input-section { margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line); }
.field { display: grid; align-content: start; min-width: 0; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 550; }
.field input, .field select, .sheet-navigation select { width: 100%; min-width: 0; height: 34px; padding: 4px 7px; border: 1px solid #c9d4ca; border-radius: 5px; background: #fff; color: var(--ink); font-size: 13px; font-weight: 400; }
.title-field { margin-top: 10px; }
.settings, .material-row, .part-row { display: grid; gap: 6px; align-items: end; }
.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.5fr); margin-top: 10px; }
.material-row { grid-template-columns: minmax(95px, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto; margin: 8px 0; }
.part-row { grid-template-columns: minmax(62px, 1.4fr) minmax(42px, .75fr) minmax(46px, .75fr) minmax(36px, .63fr) minmax(62px, 1.15fr) auto auto; padding-block: 7px; border-bottom: 1px solid #e8eee8; }
.part-row .button, .material-row .button { padding: 0; width: 30px; min-height: 34px; font-size: 17px; }
.grain-field { min-height: 34px; display: flex; align-items: center; white-space: nowrap; color: var(--muted); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--green); }
.hint { margin: 6px 0 2px; font-size: 11px; color: var(--muted); }
.add-part { margin-top: 9px; width: 100%; border-style: dashed; }
.calculate { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.status { min-width: 0; flex: 1 1 145px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.status.error { color: #973d24; }
.empty-view { display: grid; min-height: 400px; justify-items: center; align-content: center; gap: 5px; padding: 18px; text-align: center; }
.empty-view img { width: min(100%, 460px); height: auto; margin-bottom: 8px; }
.empty-view h3 { font-size: 16px; }
.empty-view p { color: var(--muted); font-size: 13px; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 12px 0; }
.summary div { min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #f5f8f4; }
.summary dt { color: var(--muted); font-size: 11px; }
.summary dd { margin: 3px 0 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.unplaced { margin-bottom: 12px; border: 1px solid #e9c9ad; border-radius: 6px; padding: 8px 11px; background: #fff5eb; color: #743916; }
.unplaced h3 { font-size: 14px; }
.unplaced p, .unplaced ul { font-size: 12px; margin: 4px 0; }
.unplaced ul { padding-left: 18px; max-height: 125px; overflow: auto; overflow-wrap: anywhere; }
.sheet-controls, .sheet-navigation { display: flex; align-items: center; gap: 5px; }
.sheet-controls { flex-wrap: wrap; justify-content: space-between; margin-block: 10px; }
.sheet-navigation { min-width: 0; flex: 1; }
.sheet-navigation select { min-width: 0; flex: 1; }
.cut-toggle { display: inline-flex; align-items: center; font-size: 12px; white-space: nowrap; }
.sheet-info { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; margin: 7px 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.sheet-info strong { color: var(--ink); }
.diagram { display: block; width: 100%; aspect-ratio: 1.42; max-height: 495px; border: 1px solid var(--line); border-radius: 7px; background: #f5f7f3; }
.diagram .stock { fill: #e8ede7; stroke: #93a294; }
.diagram .inside { fill: #fcfdfb; stroke: #a4b1a3; stroke-dasharray: 4 3; }
.diagram .offcut { fill: #f3f5ef; stroke: #a2b1a5; stroke-dasharray: 3 2; }
.diagram .piece { stroke: #637e6b; }
.diagram .piece.selected { stroke: #ab591b; stroke-width: 3; }
.diagram .cuts { stroke: #ad663f; stroke-dasharray: 5 3; fill: none; }
.diagram text { fill: #21382b; text-anchor: middle; dominant-baseline: middle; font-weight: 650; pointer-events: none; }
.diagram rect, .diagram line { vector-effect: non-scaling-stroke; }
.sheet-table { width: 100%; margin-top: 8px; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
.sheet-table :is(th, td) { padding: 4px 5px; text-align: left; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.sheet-table th:first-child { width: 36px; }
.sheet-table th:nth-child(3) { width: 30%; }
.sheet-table th:last-child { width: 60px; }
.sheet-table button { padding: 1px 3px; border: 0; color: var(--green); background: transparent; text-align: left; text-decoration: underline; }
.print-results { display: none; }
@media (max-width: 950px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .empty-view { min-height: 290px; }
}
@media (max-width: 510px) {
  .intro { align-items: start; }
  .topbar { gap: 8px; }
  .topbar .button { min-height: 31px; font-size: 11px; padding-inline: 5px; }
  .topbar .centre { display: none; }
  .intro p { font-size: 12px; }
  .part-row { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
  .part-row .part-name { grid-column: span 2; }
  .part-row .part-material { grid-column: 3 / span 2; grid-row: 1; }
  .part-row .remove-part { grid-column: 5; grid-row: 1; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media print {
  @page { size: A4 landscape; margin: 9mm; }
  body { background: white; }
  .topbar, main { display: none !important; }
  .print-results { display: block; color: #102017; print-color-adjust: exact; }
  .print-sheet { break-before: page; }
  .print-sheet h2 { font-size: 17px; }
  .print-sheet .diagram { width: 63%; max-height: 135mm; }
  .print-sheet .sheet-table { width: 34%; margin-top: 0; }
  .print-sheet .sheet-body { display: flex; gap: 3%; align-items: start; }
  .sheet-table tr { break-inside: avoid; }
  .print-results .unplaced ul { max-height: none; overflow: visible; }
}
