:root {
  --wood: #7a4a2b;
  --wood-dark: #4e2f1a;
  --cream: #faf5ee;
  --accent: #c1440e;
  --border: #ddd0c0;
  --text: #2b2117;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--text);
}

.topbar {
  background: var(--wood-dark);
  color: #fff;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar nav { display: flex; gap: 8px; }

.tab-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

.tab { display: none; }
.tab.active { display: block; }

.panel-row { display: flex; gap: 20px; align-items: flex-start; }

.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-width: 260px;
}
.panel.wide { flex: 1; }

h2 { margin-top: 0; color: var(--wood-dark); }

.list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.list li {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 4px;
}
.list li:hover { background: #f2e9dd; }
.list li.selected { background: var(--wood); color: #fff; }
.list .bid-status { font-size: 11px; text-transform: uppercase; opacity: 0.7; }
.list .bid-client { font-size: 13px; opacity: 0.85; margin-top: 1px; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { opacity: 0.9; }
button.secondary { background: var(--wood); }
button.danger { background: #a33; }

#new-bid-btn { margin-top: 10px; width: 100%; }

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.inline-form input {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  min-width: 100px;
}

table { width: 100%; border-collapse: collapse; margin-top: 8px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--wood-dark); }
tr.low-stock td { color: var(--accent); font-weight: 600; }

.empty-state { color: #999; }

.bid-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.bid-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.bid-fields label { display: flex; flex-direction: column; font-size: 12px; color: #666; gap: 4px; }
.bid-fields input, .bid-fields select { padding: 6px; border: 1px solid var(--border); border-radius: 6px; }

.totals { background: #f2e9dd; border-radius: 8px; padding: 12px 16px; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-weight: 700; font-size: 18px; color: var(--wood-dark); border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; }

.summary { display: flex; gap: 24px; margin-bottom: 16px; }
.summary .stat { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 12px 20px; }
.summary .stat .value { font-size: 22px; font-weight: 700; color: var(--wood-dark); }
.summary .stat .label { font-size: 12px; color: #777; }

.add-item-form { display: flex; gap: 8px; margin: 10px 0; }
.add-item-form select, .add-item-form input { padding: 6px; border: 1px solid var(--border); border-radius: 6px; }

.icon-btn {
  background: transparent;
  color: #a33;
  padding: 2px 8px;
  font-size: 12px;
}

.project-name-input {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
}

.hint { font-size: 12px; color: #888; margin: -4px 0 8px; }

.preset-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.preset-row span { font-size: 12px; color: #777; }
.preset-btn { background: #fff; border: 1px solid var(--wood); color: var(--wood-dark); padding: 4px 10px; font-size: 13px; }
.preset-btn:hover { background: var(--wood); color: #fff; }

#pieces-table input, #stock-table input { width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
#pieces-table td:first-child, #stock-table td:first-child { width: 300px; }

.picker { position: relative; }
.picker.linked input { border-color: #b9cfb0; background: #f6fbf3; }
.picker.unlinked input { border-color: #e0b070; background: #fff8ec; }
.picker-list {
  position: absolute;
  left: 0;
  top: 100%;
  z-index: 30;
  min-width: 320px;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--wood);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.picker-opt { padding: 9px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid #f0e8dc; }
.picker-opt:last-child { border-bottom: 0; }
.picker-opt b { font-size: 14px; color: var(--text); }
.picker-opt span { font-size: 12px; color: #857560; }
.picker-opt.active, .picker-opt:hover { background: #f2e9dd; }
.picker-empty { padding: 12px; font-size: 13px; color: #857560; }
.stock-price-auto { font-size: 13px; color: var(--wood-dark); white-space: nowrap; }
.stock-price-auto.warn { color: var(--accent); }
.stock-length:disabled { background: #f3eee6; color: #6d5e49; }
#pieces-table td:nth-child(3), #stock-table td:nth-child(3) { width: 110px; }
#pieces-table td:last-child, #stock-table td:last-child { width: 70px; }

.button-row { display: flex; gap: 10px; margin: 14px 0; }
.button-row button { flex: 1; font-size: 15px; padding: 10px; }

.profile-heading {
  color: var(--wood-dark);
  margin: 18px 0 6px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--wood);
}

.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.dash-head h2 { margin: 0; }
.dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 14px 0 18px; }
.dash-tile { border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; background: #fff; }
.dash-tile .value { font-size: 34px; font-weight: 700; color: var(--wood-dark); line-height: 1.1; }
.dash-tile .label { font-size: 13px; color: #7a6a55; margin-top: 2px; }
.dash-tile.needs { border-left: 5px solid var(--accent); }
.dash-tile.accepted { border-left: 5px solid #3c8a3c; }
.dash-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.dash-col h3 { margin: 0 0 8px; color: var(--wood-dark); font-size: 15px; }
.dash-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dash-list li[data-bid] {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.dash-list li[data-bid]:hover, .dash-list li[data-bid]:focus { background: #f6ede2; border-color: var(--wood); outline: none; }
.dash-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.dash-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-main span { font-size: 13px; }
.dash-main small { font-size: 12px; color: #8a7a64; }
.dash-side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: 0 0 auto; }
.dash-side .unpriced { color: var(--accent); font-size: 12px; }
.dash-tag { font-size: 11px; background: #f2e9dd; color: var(--wood-dark); border-radius: 4px; padding: 1px 6px; }
.dash-empty { color: #9a8a74; font-size: 13px; padding: 10px 2px; }
@media (max-width: 980px) { .dash-cols { grid-template-columns: 1fr; } }

.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin-top: 1px; flex: 0 0 auto; }

.sketch-panel { display: flex; gap: 16px; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 12px 0; }
.sketch-thumb { width: 200px; min-height: 110px; flex: 0 0 auto; border: 1px dashed var(--border); border-radius: 6px; background: #fff; display: grid; place-items: center; overflow: hidden; cursor: pointer; color: #9a8a74; font-size: 13px; text-align: center; padding: 4px; }
.sketch-thumb img { max-width: 100%; max-height: 160px; display: block; }
.sketch-actions h3 { margin: 0 0 4px; }
.sketch-actions .hint { margin: 0 0 10px; }
@media (max-width: 640px) { .sketch-panel { flex-direction: column; } .sketch-thumb { width: 100%; } }

.table-scroll { overflow-x: auto; }
#materials-table td { padding: 4px 4px; }
#materials-table input {
  width: 100%;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  color: inherit;
}
#materials-table select {
  width: 100%;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  font: inherit;
  color: inherit;
}
#materials-table input:hover, #materials-table select:hover { border-color: var(--border); }
#materials-table input:focus, #materials-table select:focus { border-color: var(--wood); background: #fff; outline: none; }
#materials-table tr.low-stock input, #materials-table tr.low-stock select { color: var(--accent); font-weight: 600; }
.inline-form select {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex: 1;
  min-width: 100px;
  background: #fff;
  color: var(--text);
}

.line-input { width: 72px; padding: 5px; border: 1px solid var(--border); border-radius: 4px; }
.cutlist-tag { font-size: 10px; text-transform: uppercase; background: #f2e9dd; color: var(--wood-dark); border-radius: 4px; padding: 1px 5px; margin-left: 6px; }
.cutlist-panel { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 12px 0; }
.cutlist-panel h3 { margin: 0 0 8px; }
.cutlist-panel select { padding: 6px; border: 1px solid var(--border); border-radius: 6px; max-width: 260px; }
.notice { background: #eef6ee; border: 1px solid #bcd9bc; border-radius: 6px; padding: 8px 12px; margin-top: 8px; font-size: 13px; }

.settings-panel { max-width: 560px; }
.settings-card { border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin-bottom: 16px; }
.settings-card h3 { margin: 0 0 6px; color: var(--wood-dark); }
.settings-card h4 { margin: 20px 0 8px; color: var(--wood-dark); font-size: 14px; }
.settings-meta { color: #666; margin: 0; }
.settings-form label { display: block; font-size: 13px; color: #666; margin-bottom: 12px; }
.settings-form input { width: 100%; padding: 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; font-size: 15px; }
.form-msg { min-height: 20px; margin: 4px 0 10px; font-size: 14px; }
.form-msg.ok { color: #2a7a2a; }
.form-msg.error { color: #a33; }

.print-only { display: none; }
.print-date { font-size: 12px; color: #777; margin-bottom: 12px; }

.cutlist-summary {
  background: #f2e9dd;
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 16px;
}
.cutlist-summary .buy-line { font-size: 17px; font-weight: 700; color: var(--wood-dark); margin-bottom: 8px; }
.cutlist-summary .stat-row { display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; }
.cutlist-summary .stat-row b { color: var(--wood-dark); }

.board-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.board-card h4 { margin: 0 0 8px; color: var(--wood-dark); font-size: 14px; }
.board-card .board-meta { font-size: 12px; color: #777; margin-bottom: 6px; }

.board-bar {
  display: flex;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.board-bar .segment {
  background: var(--wood);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 2px solid #fff;
  overflow: hidden;
  white-space: nowrap;
}
.board-bar .leftover {
  background: repeating-linear-gradient(45deg, #f4ede0, #f4ede0 5px, #e8ddc9 5px, #e8ddc9 10px);
  font-size: 10px;
  color: #a3906f;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tight-warning {
  margin-top: 8px;
  font-size: 12px;
  color: var(--accent);
  background: #fdf0ea;
  border: 1px solid #f0c9b3;
  border-radius: 6px;
  padding: 6px 10px;
}

#print-parts-list { display: none; }

.parts-list-table th, .parts-list-table td { font-size: 16px; padding: 10px 14px; }
.parts-list-table tfoot td { font-weight: 700; border-top: 2px solid var(--wood); color: var(--wood-dark); }
.print-list-heading { color: var(--wood-dark); margin: 20px 0 4px; }
.print-list-heading:first-child { margin-top: 0; }

@media print {
  .topbar, .panel:not(.wide), .hint, datalist,
  #cutproj-label, #cutproj-save-btn, #cutproj-delete-btn,
  #pieces-table, #add-piece-row,
  .preset-row, #stock-table, #add-stock-row,
  .bid-fields, .button-row,
  .section-heading { display: none !important; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .panel.wide { border: none; padding: 0; }
  .print-only { display: block; }
  .board-card { break-inside: avoid; border-color: #999; }
  .board-bar { border-color: #000; }
  .board-bar .segment { color: #000; background: #eee; border-right: 2px dashed #000; }
  .board-bar .leftover { background: #fff; border-left: 2px dashed #000; }

  /* Parts-list-only print mode: swap the full cut diagrams for a plain buy list */
  body.print-parts-mode #cutlist-results { display: none !important; }
  body.print-parts-mode #print-parts-list { display: block !important; }
  .cutlist-summary { background: #fff; border: 1px solid #999; }
}
