:root {
  --bg: #f5f1e9;
  --surface: #fff;
  --surface2: #faf8f4;
  --border: #e0d8cc;
  --border2: #c8bfb0;
  --text: #1a1612;
  --text2: #6b6258;
  --accent: #795033;
  --accent2: #c5a16b;
  --green: #2d7a4e;
  --green-light: #e8f5ee;
  --wood: #d4a866;
  --wood-light: #f5ead8;
  --radius: 10px;
  --mono: 'Courier New', monospace;
  --sans: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button, input, select, textarea { touch-action: manipulation; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); min-height: 100vh; }

/* WOODBER identity and workshop */
html { scroll-behavior: smooth; }
button, input, textarea { font: inherit; }
button { transition: background .18s, border-color .18s, transform .18s; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid #a87945; outline-offset: 4px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 16px max(28px, calc((100vw - 1400px) / 2)); background: #302218; border: 0; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #f8efdf; }
.brand strong { display: block; font: 700 25px Georgia, serif; letter-spacing: 3px; }
.brand small { display: block; margin-top: 5px; font-size: 8px; letter-spacing: 2px; color: #cfb992; }
.brand-emblem { display: block; width: 52px; height: 52px; border-radius: 50%; overflow: hidden; border: 1px solid #b19367; position: relative; background: #ddc5a5; flex-shrink: 0; }
.brand-emblem img { position: absolute; width: 157px; max-width: none; left: -52px; top: -6px; }
.header-label { color: #bdab94; font-size: 10px; letter-spacing: 1.5px; }
.header-label span { margin: 0 14px; color: #79634d; }
.local-badge { color: #e0d3c0; font-size: 11px; white-space: nowrap; }
.local-badge i { display: inline-block; width: 6px; height: 6px; background: #a6b98b; border-radius: 50%; margin-right: 7px; }
.hero { max-width: 1400px; margin: 28px auto 0; display: grid; grid-template-columns: .9fr 1.1fr; background: #eae1d2; border: 1px solid #ddd0bc; border-radius: 14px; overflow: hidden; }
.hero-copy { padding: 36px 42px; align-self: center; }
.eyebrow { color: #8a6847; font-size: 9px; font-weight: 700; letter-spacing: 2px; }
h1 { font: 400 clamp(30px, 3.1vw, 47px)/1.12 Georgia, serif; letter-spacing: -1.3px; margin: 16px 0; color: #34261c; }
h1 em { color: #87613d; font-weight: 400; }
.hero-copy p { max-width: 365px; color: #756555; font-size: 12px; line-height: 1.8; }
.hero-link { display: inline-flex; align-items: center; gap: 28px; color: #523a27; font-size: 11px; text-decoration: none; border-bottom: 1px solid #ad9070; padding-bottom: 8px; margin-top: 24px; }
.hero-image { min-width: 0; background: #e6d5bb; }
.hero-image img { width: 100%; height: 100%; display: block; object-fit: cover; }
.workspace-heading { max-width: 1400px; margin: 34px auto 20px; display: flex; justify-content: space-between; align-items: center; gap: 16px; scroll-margin-top: 20px; }
h2 { font: 400 28px Georgia, serif; margin-top: 7px; color: #3f2e20; }
.project-tools { display: flex; gap: 8px; }
.btn-save { background: #38291d; color: #f8efe1; border: 1px solid #38291d; border-radius: 6px; padding: 10px 15px; font-size: 11px; cursor: pointer; }
.btn-save:hover { background: #63452d; }
.section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.step { font-size: 10px; color: #90663e; background: #f3ecdf; border: 1px solid #e4d6bf; border-radius: 5px; padding: 5px 6px; }
.section-heading h3 { font-size: 14px; font-weight: 600; }
.unit-tag { margin-left: auto; font-size: 8px; color: #948572; letter-spacing: 1px; }
.project-field { margin-bottom: 16px; }
.panel { padding: 22px; background: #fffdf9; border: 1px solid #e0d8cb; border-radius: 10px; }
.csv-section { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 15px; }
.csv-section summary { font-size: 11px; color: #786652; cursor: pointer; }
.csv-section summary span { float: right; font-size: 9px; }
.csv-section[open] summary { margin-bottom: 12px; }
.csv-section .csv-hint { display: block; }
.action-foot { display: flex; align-items: center; justify-content: space-between; color: #948572; font-size: 9px; margin-top: 5px; }
.text-button { background: none; border: 0; color: #7b6854; font-size: 10px; cursor: pointer; padding: 5px 0; }
.result-heading { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.result-heading h3 { font: 400 23px Georgia, serif; margin-top: 7px; }
.result-heading .btn-sec { flex: 0; }
.board-illustration { width: 180px; height: 135px; display: grid; grid-template-columns: 1.1fr 1fr; grid-template-rows: 1fr .65fr; gap: 5px; padding: 7px; background: #f6edde; border: 1px solid #bea17a; border-radius: 3px; transform: rotate(-5deg); box-shadow: 8px 10px 0 #eee5d7; margin: 6px 0 25px; }
.board-illustration div { background: repeating-linear-gradient(0deg, #dac19b88 0, #dac19b88 2px, #e5cfb0 3px, #e5cfb0 13px); border: 1px solid #b99a70; color: #8e6d45; display: grid; place-items: center; font: 14px Georgia, serif; }
.board-illustration div:first-child { grid-row: span 2; }
.board-illustration div:last-child { display: none; }
.empty-state h3 { font: 400 23px Georgia, serif; color: #57412e; }
.empty-example { flex: none !important; margin: 6px 0 18px; }
.workshop-note { display: flex; gap: 13px; padding: 16px 20px; background: #eee7da; border-radius: 8px; margin-top: auto; color: #88725a; }
.workshop-note > span { font-size: 26px; color: #ab8751; }
.workshop-note p { font-size: 10px; line-height: 1.8; }
.workshop-note strong { font-weight: 600; color: #675039; }
footer { max-width: 1400px; margin: 30px auto 0; border-top: 1px solid #dfd4c3; padding: 22px 0; display: flex; align-items: center; gap: 20px; color: #9a8770; font-size: 9px; }
footer strong { font: 700 15px Georgia, serif; letter-spacing: 2px; color: #65503c; }
footer span:last-child { margin-left: auto; }

/* HEADER */
header { background: var(--text); color: var(--bg); padding: 14px 24px; border-bottom: 3px solid var(--accent); }
.logo { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; }
.logo span { color: var(--accent2); }

/* LAYOUT */
.app { display: grid; grid-template-columns: 370px 1fr; min-height: calc(100vh - 57px); }

/* SIDEBAR */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  height: calc(100vh - 57px); position: sticky; top: 0;
}
.sec-title {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text2);
  padding-bottom: 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.config-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.field label {
  display: block; font-family: var(--mono); font-size: 9px;
  letter-spacing: 0.5px; color: var(--text2); margin-bottom: 3px; text-transform: uppercase;
}
.field input, .field select {
  width: 100%; font-family: var(--mono); font-size: 12px;
  border: 1px solid var(--border2); border-radius: 4px;
  padding: 6px 8px; background: var(--surface); color: var(--text);
}
.field input:focus { outline: none; border-color: var(--accent); }

.toggle-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.toggle-label { font-family: var(--mono); font-size: 9px; color: var(--text2); text-transform: uppercase; }
.toggle { position: relative; width: 34px; height: 19px; cursor: pointer; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border2); border-radius: 19px; transition: background 0.2s; }
.slider:before {
  content: ''; position: absolute; width: 13px; height: 13px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider:before { transform: translateX(15px); }

/* PIECES */
.pieces-hdr {
  display: grid; grid-template-columns: 1fr 55px 55px 50px 30px; gap: 4px; padding: 0 2px;
}
.pieces-hdr span {
  font-family: var(--mono); font-size: 9px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px;
}
#pieces-list { display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow-y: auto; }
.piece-row {
  display: grid; grid-template-columns: 1fr 55px 55px 50px 30px; gap: 4px; align-items: center;
}
.piece-row.has-veta { grid-template-columns: 1fr 55px 55px 50px 18px 30px; }
.piece-row input {
  font-family: var(--mono); font-size: 11px; border: 1px solid var(--border);
  border-radius: 4px; padding: 5px 6px; background: var(--surface); color: var(--text); width: 100%;
}
.piece-row input:focus { outline: none; border-color: var(--accent); }
.veta-check { width: 15px !important; height: 15px !important; padding: 0 !important; cursor: pointer; accent-color: var(--wood); }
.btn-del {
  background: none; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text2); cursor: pointer; width: 28px; height: 32px;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.btn-del:hover { border-color: var(--accent); color: var(--accent); background: #fff0ec; }
.btn-add {
  display: flex; align-items: center; gap: 6px; background: none;
  border: 1px dashed var(--border2); border-radius: var(--radius);
  padding: 8px 10px; font-family: var(--mono); font-size: 11px;
  color: var(--text2); cursor: pointer; width: 100%;
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); background: #fff0ec; }

/* CSV */
.csv-hint { font-family: var(--mono); font-size: 9px; color: var(--text2); margin-bottom: 4px; }
textarea {
  width: 100%; font-family: var(--mono); font-size: 10px;
  border: 1px solid var(--border); border-radius: 4px;
  padding: 6px; height: 52px; resize: none; color: var(--text); background: var(--surface);
}
textarea:focus { outline: none; border-color: var(--accent); }

/* ACTIONS */
.actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.btn-calc {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius);
  padding: 12px; font-size: 13px; font-weight: 700; cursor: pointer;
  width: 100%; letter-spacing: 0.5px;
}
.btn-calc:hover { background: #b04a10; }
.btn-calc:active { transform: scale(0.98); }
.btn-row { display: flex; gap: 5px; }
.btn-sec {
  background: none; border: 1px solid var(--border2); border-radius: var(--radius);
  padding: 6px 8px; font-family: var(--mono); font-size: 10px;
  color: var(--text2); cursor: pointer; flex: 1; text-align: center; white-space: nowrap;
}
.btn-sec:hover { border-color: var(--text2); color: var(--text); background: var(--surface2); }
.info-txt {
  font-family: var(--mono); font-size: 9px; color: var(--text2);
  background: var(--green-light); border: 1px solid #b8dfc8;
  border-radius: 4px; padding: 6px 8px; margin-bottom: 4px;
}

/* MAIN */
.main { padding: 22px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }

/* STATS */
.stats-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat-val { font-size: 20px; font-weight: 800; line-height: 1; margin-bottom: 3px; }
.stat-lbl { font-family: var(--mono); font-size: 9px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.accent { border-color: var(--accent); }
.stat-card.accent .stat-val { color: var(--accent); }
.stat-card.good .stat-val { color: var(--green); }
.stat-card.warn .stat-val { color: #b06010; }

/* SHEETS */
.sheets-grid { display: flex; flex-direction: column; gap: 14px; }
.sheet-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.sheet-hdr {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: var(--surface2); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.sheet-num { background: var(--text); color: var(--bg); font-family: var(--mono); font-size: 10px; padding: 2px 7px; border-radius: 3px; }
.sheet-title { font-size: 12px; font-weight: 700; }
.sheet-stats { display: flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.sheet-stat { font-family: var(--mono); font-size: 10px; color: var(--text2); }
.sheet-stat strong { color: var(--text); }
.eff-bar { height: 3px; background: var(--border); }
.eff-fill { height: 3px; background: var(--green); transition: width 0.6s; }
.sheet-body { padding: 14px; display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.sheet-canvas-wrap { flex-shrink: 0; }
.sheet-pieces-list { flex: 1; min-width: 200px; }
.sheet-pieces-list table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 10px; }
.sheet-pieces-list th {
  text-align: left; padding: 4px 6px; color: var(--text2);
  border-bottom: 1px solid var(--border); font-weight: 500; text-transform: uppercase; font-size: 9px;
}
.sheet-pieces-list td { padding: 4px 6px; border-bottom: 1px solid var(--border); }
.pdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.rot-badge { font-family: var(--mono); font-size: 9px; background: #f0e8ff; border: 1px solid #c8a8e8; color: #5a3080; border-radius: 2px; padding: 1px 3px; margin-left: 3px; }

/* UNPLACED */
.unplaced-card { background: #fff8f5; border: 1px solid #f0b090; border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }
.unplaced-title { font-size: 12px; font-weight: 700; color: #b04010; margin-bottom: 6px; }

/* EMPTY */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 70px 40px; color: var(--text2); text-align: center; flex: 1;
}
.empty-icon { font-size: 42px; opacity: 0.22; }
.empty-state p { font-size: 14px; line-height: 1.7; }
.empty-hint {
  font-family: var(--mono); font-size: 10px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 4px; padding: 6px 12px;
}

/* TOAST */
.toast {
  position: fixed; bottom: 18px; right: 18px; background: var(--text); color: #fff;
  font-family: var(--mono); font-size: 12px; padding: 9px 16px; border-radius: 4px;
  z-index: 9999; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

/* Workspace refinements */
.app { max-width: 1400px; margin: 0 auto; grid-template-columns: 390px minmax(0, 1fr); gap: 24px; min-height: 0; }
.sidebar { background: transparent; border: 0; padding: 0; gap: 16px; height: auto; position: static; overflow: visible; }
.config-card { background: transparent; border: 0; padding: 0; }
.field-row { gap: 12px; margin-bottom: 14px; }
.field label { font-family: var(--sans); text-transform: none; font-size: 10px; letter-spacing: 0; margin-bottom: 6px; }
.field input { padding: 10px 11px; border-color: #dfd6c9; background: #fcfaf6; font-size: 12px; }
.settings-bottom { margin-bottom: 0; }
.toggle-row { padding-left: 7px; gap: 10px; }
.toggle-label { font: 10px/1.5 var(--sans); text-transform: none; }
.pieces-hdr, .piece-row { grid-template-columns: minmax(65px, 1fr) 57px 57px 40px 25px; gap: 5px; }
.pieces-hdr:has(#veta-col-hdr:not([style*="none"])), .piece-row.has-veta { grid-template-columns: minmax(55px, 1fr) 51px 51px 35px 16px 23px; }
.pieces-hdr { margin-bottom: 9px; }
#pieces-list { gap: 7px; max-height: 350px; }
.piece-row input { padding: 9px 4px; min-width: 0; font-size: 11px; background: #fcfaf6; }
.btn-del { width: 24px; border: 0; }
.btn-add { margin-top: 10px; justify-content: center; padding: 10px; font: 11px var(--sans); color: #795a3b; }
.btn-add:hover { background: #f2e9dc; }
.btn-sec { padding: 9px 12px; font: 11px var(--sans); background: #fffdf8; border-color: #d8cbb8; }
textarea { height: 75px; padding: 10px; font-size: 11px; resize: vertical; margin-bottom: 8px; }
.actions { margin-top: 20px; }
.btn-calc { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; background: #795033; font: 600 12px var(--sans); letter-spacing: .2px; }
.btn-calc:hover { background: #5c3c25; }
.btn-calc span:last-child { font-size: 20px; }
.main { padding: 22px; border: 1px solid #dfd6c8; border-radius: 10px; background: #fbf9f4; min-width: 0; overflow: visible; }
.empty-state { padding: 45px 10px; min-height: 450px; gap: 14px; }
.empty-state p { font-size: 12px; color: #8b7a67; }
.empty-hint { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; font: 9px var(--sans); background: none; border: 0; color: #9b8871; padding: 0; }
#results-area { min-width: 0; }
.result-project { font: 500 13px var(--sans); color: #755b40; margin-bottom: 15px; overflow-wrap: anywhere; }
.stats-bar { margin-bottom: 18px; }
.stat-card { padding: 17px 12px; background: #fffdf8; }
.stat-val { font: 400 27px Georgia, serif; margin-bottom: 7px; }
.stat-lbl { font: 8px var(--sans); letter-spacing: 1px; }
.sheet-body { flex-direction: column; padding: 20px; }
.sheet-canvas-wrap { width: 100%; }
.sheet-canvas-wrap canvas { display: block; max-width: 100%; height: auto; margin: auto; }
.sheet-pieces-list { width: 100%; min-width: 0; overflow-x: auto; }
.sheet-pieces-list td { padding: 8px 6px; }
.sheet-pieces-list th { padding: 8px 6px; }
.sheet-title { font-size: 11px; }
.sheet-stat { font-size: 9px; }
.rot-badge { background: #e8eedf; border-color: #becda8; color: #5c6b46; }
.toast { font: 12px var(--sans); background: #38291d; max-width: calc(100vw - 36px); }
@media (max-width: 1460px) { .hero, .workspace-heading, .app, footer { margin-left: 28px; margin-right: 28px; } }
@media (max-width: 1100px) { .header-label { display: none; } .hero-copy { padding: 30px; } .app { grid-template-columns: 355px minmax(0, 1fr); gap: 16px; } .panel { padding: 17px; } .main { padding: 17px; } .empty-hint { gap: 10px; } .stat-val { font-size: 23px; } }

/* RESPONSIVE */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: static; }
}

@media print {
  header, .sidebar { display: none !important; }
  .app { display: block; }
  .main { height: auto; overflow: visible; padding: 0; }
  .sheet-card { page-break-inside: avoid; border: 1px solid #ccc; margin-bottom: 14px; }
}
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero-copy { padding: 25px; }
  .hero-image img { object-fit: contain; }
  .workspace-heading { align-items: flex-start; }
  .project-tools { flex-wrap: wrap; justify-content: flex-end; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .app { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar { padding: 13px 18px; }
  .brand strong { font-size: 22px; }
  .local-badge { font-size: 0; }
  .local-badge i { width: 8px; height: 8px; }
  .hero, .workspace-heading, .app, footer { margin-left: 14px; margin-right: 14px; }
  .hero { grid-template-columns: 1fr; margin-top: 14px; }
  .hero-copy { padding: 27px; }
  .hero-image img { height: auto; }
  .hero-link { margin-top: 16px; }
  .workspace-heading { flex-direction: column; margin-top: 25px; }
  h2 { font-size: 26px; }
  .project-tools { width: 100%; justify-content: flex-start; }
  .project-tools button { padding: 10px 8px; font-size: 10px; flex: 1; }
  .sidebar { display: flex; }
  .panel { padding: 18px; }
  .main { padding: 15px; }
  .empty-state { min-height: 410px; padding: 35px 0; }
  .empty-state h3 { font-size: 21px; }
  .empty-state p br { display: none; }
  .result-heading h3 { font-size: 21px; }
  .result-heading .eyebrow { font-size: 8px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .sheet-body { padding: 10px; }
  footer { flex-wrap: wrap; gap: 10px; line-height: 1.7; }
  footer span:last-child { margin-left: 0; }
}
@media print {
  .topbar, .hero, .workspace-heading, .sidebar, .result-heading button, .workshop-note, footer, .toast { display: none !important; }
  body { background: white; }
  .app { display: block; margin: 0; }
  .main { border: 0; background: white; }
  .result-heading::before { content: 'WOODBER'; font: bold 22px Georgia, serif; }
  .result-heading { margin-bottom: 20px; }
  .sheet-card, .stats-bar { break-inside: avoid; }
  canvas { max-height: 160mm; object-fit: contain; }
  * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
